Do not use zero(...) in generic_lu! algorithm to support Unitful #38659
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a minimal effort attempt to work around the bigger problem that factorizations only define a single number type.
Suppose
eltype(A) == typeof(1.0u"kg")
, then by design of the algorithm the LU factorization should end up withA = L * U
whereeltype(L) = Float64
andeltype(U) == eltype(A) == typeof(1.0u"kg")
.In julia the algorithm assumes it can work in-place, so we have to promote/union number types of L and U:
and in this case
zero(promote_type(Float64, typeof(1.0u"kg")))
will error. This PR tries to avoid using zero then.A better solution IMHO is to allocate L and U separately (or at the very least parametrize the eltype of L and U separately in the factorization) to avoid having to work with non-concrete number types. It's nice to get a unitful LU-factorization, but pretty much any linalg operation
\
,*
,+
, etc will runoneunit(eltype(factorization))
and throw: