# How to promote a factorization?

**URL:** <https://discourse.julialang.org/t/how-to-promote-a-factorization/77715>\
**Category:** Numerics\
**Tags:** question\
**Created:** [March 10, 2022, 7:34pm UTC](https://discourse.julialang.org/t/how-to-promote-a-factorization/77715 "2022-03-10T19:34:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [March 10, 2022, 7:34pm UTC](https://discourse.julialang.org/t/how-to-promote-a-factorization/77715/1 "2022-03-10T19:34:57Z")

</div>

I’m trying to promote an LU factorization in one precision to a higher  
precision. The permutation vector does not map correctly and I can’t  
figure out why.

Any ideas?

MWE:

```julia
julia> A=rand(Float32,3,3);

julia> AF=lu!(A);

julia> AF64=LU(Float64.(A), AF.p, AF.info);

julia> norm(AF64.L - AF.L)
0.00000e+00

julia> norm(AF64.U - AF.U)
0.00000e+00

julia> # so the factors look good, but

julia> AF.p
3-element Vector{Int64}:
 2
 1
 3

julia> AF64.p
3-element Vector{Int64}:
 1
 2
 3

```

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [March 10, 2022, 8:16pm UTC](https://discourse.julialang.org/t/how-to-promote-a-factorization/77715/2 "2022-03-10T20:16:29Z")

</div>

Too me these look like permutation vectors, for which `Int` should be perfect on 64-bit systems…

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 10, 2022, 9:16pm UTC](https://discourse.julialang.org/t/how-to-promote-a-factorization/77715/3 "2022-03-10T21:16:19Z")

</div>

> [@ctkelley](#):
>
> `AF64=LU(Float64.(A), AF.p, AF.info);`

You want:

```julia
AF64=LU(Float64.(A), AF.ipiv, AF.info)

```

(The `p` property is not actually stored, but rather is computed by `LinearAlgebra.ipiv2perm`.)

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [March 10, 2022, 9:59pm UTC](https://discourse.julialang.org/t/how-to-promote-a-factorization/77715/4 "2022-03-10T21:59:59Z")

</div>

Sorry, I’m too stupid (I didn’t even realize the intent of original question). So what are you trying to do here: solving in `Float32` and pretending to have it solved in `Float64`?

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [March 10, 2022, 10:11pm UTC](https://discourse.julialang.org/t/how-to-promote-a-factorization/77715/5 "2022-03-10T22:11:58Z")

</div>

I’m computing a factorization in low precision (Float16 is the target) and using that factorization as a preconditioner for GMRES in a higher precision (Float32 is the target). This only works right if I promote the factorization before I use it in the preconditioner.

I could define the preconditioiner via brute force using L, U, and P, but it is far cleaner if I can simply promote the factorization. @stevengj fixed me up, as he as done in the past.

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [March 10, 2022, 10:12pm UTC](https://discourse.julialang.org/t/how-to-promote-a-factorization/77715/6 "2022-03-10T22:12:29Z")

</div>

That’s it! Thanks.
