# ERROR: LoadError: MethodError: no method matching \_init\_identity\_matrix(::ComponentVector{Float32, Vector{Float32}, Tuple{Axis{…}}}, ::Float64)

**URL:** <https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-init-identity-matrix-componentvector-float32-vector-float32-tuple-axis-float64/112211>\
**Category:** Optimization (Mathematical)\
**Created:** [March 28, 2024, 5:13am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-init-identity-matrix-componentvector-float32-vector-float32-tuple-axis-float64/112211 "2024-03-28T05:13:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![KianH](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@KianH](https://discourse.julialang.org/u/KianH)\
**Post date:** [March 28, 2024, 5:13am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-init-identity-matrix-componentvector-float32-vector-float32-tuple-axis-float64/112211/1 "2024-03-28T05:13:34Z")

</div>

Hi,

When using BFGS from Optim.jl I _occasionally_ get the following error message:

`ERROR: LoadError: MethodError: no method matching _init_identity_matrix(::ComponentVector{Float32, Vector{Float32}, Tuple{Axis{…}}}, ::Float64)`

What I don’t understand is why I am getting this error message when running BFGS when the function, `_init_identity_matrix(...)` exists in Optim.jl and why am I only _sometimes_ getting this error message and not all the time.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [March 28, 2024, 5:22am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-init-identity-matrix-componentvector-float32-vector-float32-tuple-axis-float64/112211/2 "2024-03-28T05:22:36Z")

</div>

Do you have a reproducible example?

It looks like it might be related to mixing `Float32` and `Float64` number types.

---

<div class="post-metadata">

**Author:** ![KianH](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@KianH](https://discourse.julialang.org/u/KianH)\
**Post date:** [March 28, 2024, 5:54am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-init-identity-matrix-componentvector-float32-vector-float32-tuple-axis-float64/112211/3 "2024-03-28T05:54:55Z")

</div>

I don’t really have a reproducible example to share since the error only occurs occasionally, I get the error maybe 1 in 200 simulations.

It’s strange that it would have to do with the floating point format since I don’t change the floating point formats. Why do you think it has to do with that?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [March 28, 2024, 6:09am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-init-identity-matrix-componentvector-float32-vector-float32-tuple-axis-float64/112211/4 "2024-03-28T06:09:37Z")

</div>

Do you have the full error message and stack trace?

I’m guessing this is a bug in Optim, and that it points to:

> <https://github.com/JuliaNLSolvers/Optim.jl/blob/7cc8328a590a0c815e23005321459712382b5b42/src/utilities/perform_linesearch.jl#L18-L19>

It probably needs to be `_init_identity_matrix(state.x, T(initial_scale))`, but your error message will confirm it.

It make sense why it only occasionally happens: because this code is run only when the search direction fails for some reason.

---

<div class="post-metadata">

**Author:** ![KianH](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@KianH](https://discourse.julialang.org/u/KianH)\
**Post date:** [March 28, 2024, 6:14am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-init-identity-matrix-componentvector-float32-vector-float32-tuple-axis-float64/112211/5 "2024-03-28T06:14:50Z")

</div>

Sure, here is the full error message.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/9/d946b93ebfdf49c41bb2fcf332f6b1df389f1a37.jpeg)

Is there a way to fix this bug?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [March 28, 2024, 6:20am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-init-identity-matrix-componentvector-float32-vector-float32-tuple-axis-float64/112211/6 "2024-03-28T06:20:50Z")

</div>

> Is there a way to fix this bug?

A fix will require a PR and a new release.

In the mean time, to work around the issue, use `Float64` as your data type. It looks like your `x` is a ComponentVector with `Float32` elements?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [March 28, 2024, 6:26am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-init-identity-matrix-componentvector-float32-vector-float32-tuple-axis-float64/112211/7 "2024-03-28T06:26:06Z")

</div>

> A fix will require a PR and a new release.

See [Fix \_init\_identity\_matrix in bfgs.jl by odow · Pull Request #1089 · JuliaNLSolvers/Optim.jl · GitHub](https://github.com/JuliaNLSolvers/Optim.jl/pull/1089)

---

<div class="post-metadata">

**Author:** ![KianH](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@KianH](https://discourse.julialang.org/u/KianH)\
**Post date:** [April 25, 2024, 5:41am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-init-identity-matrix-componentvector-float32-vector-float32-tuple-axis-float64/112211/8 "2024-04-25T05:41:45Z")

</div>

I have the latest updates of all my packages that I am using and I’m still getting the same error. Did you say that the bug was fixed?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 25, 2024, 5:43am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-init-identity-matrix-componentvector-float32-vector-float32-tuple-axis-float64/112211/9 "2024-04-25T05:43:04Z")

</div>

> Did you say that the bug was fixed?

Nope: [Fix \_init\_identity\_matrix in bfgs.jl by odow · Pull Request #1089 · JuliaNLSolvers/Optim.jl · GitHub](https://github.com/JuliaNLSolvers/Optim.jl/pull/1089)
