@@ -8,6 +8,40 @@ function ArrayInterface.lu_instance(x::ComponentMatrix)
88 return LU {luT} (similar (x), ipiv, info)
99end
1010
11+ # The generic `lu`/`qr` copy through `similar(A, T, dims)`, which drops the axes
12+ # and returns a plain `Matrix`, whereas the in-place `lu!`/`qr!` (ComponentMatrix
13+ # is strided, so they hit LAPACK directly) keep the ComponentMatrix wrapper on the
14+ # factors. Make the out-of-place versions and the `ArrayInterface` instance
15+ # functions preserve the wrapper too, so callers that type a cache from the
16+ # instance functions and later store either variant (e.g. LinearSolve) don't hit
17+ # a cache type mismatch.
18+ function LinearAlgebra. lu (
19+ A:: ComponentMatrix , pivot:: Union{NoPivot, RowNonZero, RowMaximum} = RowMaximum ();
20+ kwargs... ,
21+ )
22+ F = LinearAlgebra. lu (getdata (A), pivot; kwargs... )
23+ return LU (ComponentArray (F. factors, getaxes (A)), F. ipiv, F. info)
24+ end
25+
26+ function LinearAlgebra. qr (
27+ A:: ComponentMatrix , pivot:: Union{NoPivot, ColumnNorm} = NoPivot ();
28+ kwargs... ,
29+ )
30+ F = LinearAlgebra. qr (getdata (A), pivot; kwargs... )
31+ return _rewrap_qr (F, getaxes (A))
32+ end
33+
34+ function ArrayInterface. qr_instance (A:: ComponentMatrix , pivot = NoPivot ())
35+ F = ArrayInterface. qr_instance (getdata (A), pivot)
36+ return _rewrap_qr (F, getaxes (A))
37+ end
38+
39+ function _rewrap_qr (F:: LinearAlgebra.QRCompactWY , ax)
40+ return LinearAlgebra. QRCompactWY (ComponentArray (F. factors, ax), F. T)
41+ end
42+ _rewrap_qr (F:: LinearAlgebra.QRPivoted , ax) = LinearAlgebra. QRPivoted (ComponentArray (F. factors, ax), F. τ, F. jpvt)
43+ _rewrap_qr (F, ax) = F
44+
1145# Helpers for dealing with adjoints and such
1246_first_axis (x:: AbstractComponentVecOrMat ) = getaxes (x)[1 ]
1347
0 commit comments