# Calculate return type of lu!(A)

**URL:** https://discourse.julialang.org/t/calculate-return-type-of-lu-a/137210
**Category:** General Usage
**Tags:** question
**Created:** [May 20, 2026, 9:45am UTC](https://discourse.julialang.org/t/calculate-return-type-of-lu-a/137210 "2026-05-20T09:45:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [May 20, 2026, 9:45am UTC](https://discourse.julialang.org/t/calculate-return-type-of-lu-a/137210/1 "2026-05-20T09:45:47Z")

</div>

For a given `A::M` where `M <: AbstractMatrix`, I would like to calculate `typeof(lu!(A))` in the least brittle way. That is,

1. without exposing internals if possible,

2. without performing the calculation if possible,

3. working well at least for usual suspects (eg `M = Matrix{Float64}`), but ideally for all type stable calls.

4. returning `Any` for calls that are not type stable.

(To avoid XY problems: the objective is to build a dictionary, hence I need value types)

---

<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: [May 20, 2026, 12:03pm UTC](https://discourse.julialang.org/t/calculate-return-type-of-lu-a/137210/2 "2026-05-20T12:03:23Z")

</div>

> [@Tamas\_Papp](#):
>
> typeof(lu!(A))

`typeof(lu!(oneunit(similar(A,1,1))))`, maybe?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [May 20, 2026, 12:19pm UTC](https://discourse.julialang.org/t/calculate-return-type-of-lu-a/137210/3 "2026-05-20T12:19:07Z")

</div>

Thanks! That would tick all boxes except (2), right? **EDIT** I just saw the dimensions and that the calculation is trivial.

Is

```julia
Base.promote_typejoin_union(Base.promote_op(lu!, Matrix{Float64}))

```

iffy? So many warnings in the docstrings.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [May 20, 2026, 12:41pm UTC](https://discourse.julialang.org/t/calculate-return-type-of-lu-a/137210/4 "2026-05-20T12:41:52Z")

</div>

ArrayInterface.jl has `lu_instance` which gives you an empty object of the right type.

---

<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: [May 20, 2026, 2:20pm UTC](https://discourse.julialang.org/t/calculate-return-type-of-lu-a/137210/5 "2026-05-20T14:20:25Z")

</div>

> [@Tamas\_Papp](#):
>
> iffy? So many warnings in the docstrings.

I tried a handful of simple cases and wasn’t able to make `Base.promote_typejoin_union(Base.promote_op(lu!, typeof(A)))` fail. However, it relies on type inference (which can be fragile), and on not one but two non-public `Base` functions.
