ldiv for vector-of-vectors RHS #1446
Open
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.
Close #904 to allow the right-hand-side for$Ax=b$ where the elements of $b$ and $x$ are themselves vectors (e.g. arrays, or elements of some arbitrary vector field).
ldiv
calls to be a vector of vectors: i.e. solvingMostly, this was a straightforward matter of changing
oneunit
tozero
(vector fields should supportzero
but need not haveone
), with two caveats:zero
, e.g. it works forVector{<:SVector}
but notVector{<:Vector}
becausezero(Vector{T})
fails (it doesn't know the size). This seems like a reasonable limitation to me.ldiv(F::Factorization, B::AbstractVecOrMat)
, for some reason the code first converts the factorizationF
itself to a typeTFB
based on promotion withB
. I don't actually understand why this conversion is necessary — it dates back to Make adjoint and solve work for most factorizations julia#40899 by @andreasnoack. Andreas, any comments? If we keep that conversion, however, then it needs to know the "scalar" type ofeltype(B)
. We don't currently provide a generic function for this. In this PR, I make my best guess via a new function_scalartype
that callseltype
recursively until it hits aNumber
type, or until it hits a type withEltypeUnknown
. (This should at least be backwards-compatible?) I would rather just remove theFF = Factorization{TFB}(F)
conversion entirely, if possible, since it makes this code less generic.(A workaround to the latter issue is to call
ldiv!
, since the in-place routines don't convert the factorization type.)To do:
FF = Factorization{TFB}(F)
— remove this conversion, keep the_scalartype
workaround, or do something else?b = [@SVector rand(2) for _=1:2]; A = rand(2,2); x = A \ b; @test A*x ≈ b
, but to avoid a StaticArrays dependency we may need to add a dummySVector
-like type totest/testhelpers.jl