Skip to content

Commit 27fa5de

Browse files
authored
Introduce cholesky and qr hooks for wrapped sparse matrices (#51220)
This is a follow-up to #51161. It introduces one level in the promotion pipeline which allows to call out-of-place versions of `cholesky` and `qr` for arguments whose `similar` copy yields a `SparseMatrixCSC`.
1 parent 1305f40 commit 27fa5de

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

stdlib/LinearAlgebra/src/cholesky.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,16 @@ true
399399
```
400400
"""
401401
cholesky(A::AbstractMatrix, ::NoPivot=NoPivot(); check::Bool = true) =
402-
cholesky!(cholcopy(A); check)
402+
_cholesky(cholcopy(A); check)
403403
@deprecate cholesky(A::Union{StridedMatrix,RealHermSymComplexHerm{<:Real,<:StridedMatrix}}, ::Val{false}; check::Bool = true) cholesky(A, NoPivot(); check) false
404404

405405
function cholesky(A::AbstractMatrix{Float16}, ::NoPivot=NoPivot(); check::Bool = true)
406-
X = cholesky!(cholcopy(A); check = check)
406+
X = _cholesky(cholcopy(A); check = check)
407407
return Cholesky{Float16}(X)
408408
end
409409
@deprecate cholesky(A::Union{StridedMatrix{Float16},RealHermSymComplexHerm{Float16,<:StridedMatrix}}, ::Val{false}; check::Bool = true) cholesky(A, NoPivot(); check) false
410+
# allow packages like SparseArrays.jl to hook into here and redirect to out-of-place `cholesky`
411+
_cholesky(A::AbstractMatrix, args...; kwargs...) = cholesky!(A, args...; kwargs...)
410412

411413
## With pivoting
412414
"""
@@ -465,11 +467,11 @@ true
465467
```
466468
"""
467469
cholesky(A::AbstractMatrix, ::RowMaximum; tol = 0.0, check::Bool = true) =
468-
cholesky!(cholcopy(A), RowMaximum(); tol, check)
470+
_cholesky(cholcopy(A), RowMaximum(); tol, check)
469471
@deprecate cholesky(A::Union{StridedMatrix,RealHermSymComplexHerm{<:Real,<:StridedMatrix}}, ::Val{true}; tol = 0.0, check::Bool = true) cholesky(A, RowMaximum(); tol, check) false
470472

471473
function cholesky(A::AbstractMatrix{Float16}, ::RowMaximum; tol = 0.0, check::Bool = true)
472-
X = cholesky!(cholcopy(A), RowMaximum(); tol, check)
474+
X = _cholesky(cholcopy(A), RowMaximum(); tol, check)
473475
return CholeskyPivoted{Float16}(X)
474476
end
475477

stdlib/LinearAlgebra/src/qr.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,15 @@ true
417417
function qr(A::AbstractMatrix{T}, arg...; kwargs...) where T
418418
require_one_based_indexing(A)
419419
AA = copy_similar(A, _qreltype(T))
420-
return qr!(AA, arg...; kwargs...)
420+
return _qr(AA, arg...; kwargs...)
421421
end
422422
# TODO: remove in Julia v2.0
423423
@deprecate qr(A::AbstractMatrix, ::Val{false}; kwargs...) qr(A, NoPivot(); kwargs...)
424424
@deprecate qr(A::AbstractMatrix, ::Val{true}; kwargs...) qr(A, ColumnNorm(); kwargs...)
425425

426+
# allow packages like SparseArrays.jl to hook into here and redirect to out-of-place `qr`
427+
_qr(A::AbstractMatrix, args...; kwargs...) = qr!(A, args...; kwargs...)
428+
426429
qr(x::Number) = qr(fill(x,1,1))
427430
function qr(v::AbstractVector)
428431
require_one_based_indexing(v)

0 commit comments

Comments
 (0)