Skip to content

Commit 25d9196

Browse files
authored
Allow SparseArrays to catch lu(::WrappedSparseMatrix) (#51161)
Over the `AbstractMatrix` relaxation in v1.9, we missed a potential indirection for wrapped sparse matrices. Instead, by default, a `similar` copy is created (hence a sparse matrix) and then `lu!` with a pivot argument is called. Such a method, however, does not exist in SparseArrays.jl, which means that the `generic_lufact!` method gets called, which is probably really bad performance-wise, due to heavy reading and writing into the sparse matrix. This PR introduces one more level at which SparseArrays.jl (and perhaps other external packages) may interfere and redirect to their own implementations, in-place or out-of-place.
1 parent 20478c6 commit 25d9196

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/lu.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,13 @@ julia> l == F.L && u == F.U && p == F.p
296296
true
297297
```
298298
"""
299-
function lu(A::AbstractMatrix{T}, pivot::Union{RowMaximum,NoPivot,RowNonZero} = lupivottype(T); check::Bool = true) where {T}
300-
lu!(_lucopy(A, lutype(T)), pivot; check = check)
301-
end
299+
lu(A::AbstractMatrix{T}, args...; kwargs...) where {T} =
300+
_lu(_lucopy(A, lutype(T)), args...; kwargs...)
302301
# TODO: remove for Julia v2.0
303302
@deprecate lu(A::AbstractMatrix, ::Val{true}; check::Bool = true) lu(A, RowMaximum(); check=check)
304303
@deprecate lu(A::AbstractMatrix, ::Val{false}; check::Bool = true) lu(A, NoPivot(); check=check)
304+
# allow packages like SparseArrays.jl to interfere here and call their own `lu`
305+
_lu(A::AbstractMatrix, args...; kwargs...) = lu!(A, args...; kwargs...)
305306

306307
_lucopy(A::AbstractMatrix, T) = copy_similar(A, T)
307308
_lucopy(A::HermOrSym, T) = copymutable_oftype(A, T)

0 commit comments

Comments
 (0)