From 3355e946e817e24464ba7d0d1619507bd08e09e1 Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Wed, 6 Sep 2023 17:41:01 +0200 Subject: [PATCH 1/2] Introduce cholesky and qr hooks for wrapped sparse matrices --- stdlib/LinearAlgebra/src/cholesky.jl | 10 ++++++---- stdlib/LinearAlgebra/src/qr.jl | 5 ++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/stdlib/LinearAlgebra/src/cholesky.jl b/stdlib/LinearAlgebra/src/cholesky.jl index 82f138db7d7b9..04ef0ebc9f67f 100644 --- a/stdlib/LinearAlgebra/src/cholesky.jl +++ b/stdlib/LinearAlgebra/src/cholesky.jl @@ -399,14 +399,16 @@ true ``` """ cholesky(A::AbstractMatrix, ::NoPivot=NoPivot(); check::Bool = true) = - cholesky!(cholcopy(A); check) + _cholesky(cholcopy(A); check) @deprecate cholesky(A::Union{StridedMatrix,RealHermSymComplexHerm{<:Real,<:StridedMatrix}}, ::Val{false}; check::Bool = true) cholesky(A, NoPivot(); check) false function cholesky(A::AbstractMatrix{Float16}, ::NoPivot=NoPivot(); check::Bool = true) - X = cholesky!(cholcopy(A); check = check) + X = _cholesky(cholcopy(A); check = check) return Cholesky{Float16}(X) end @deprecate cholesky(A::Union{StridedMatrix{Float16},RealHermSymComplexHerm{Float16,<:StridedMatrix}}, ::Val{false}; check::Bool = true) cholesky(A, NoPivot(); check) false +# allow packages like SparseArrays.jl to hook into here and redirect to out-of-place `cholesky` +_cholesky(A::AbstractMatrix, args...; kwargs) = cholesky!(A, args...; kwargs...) ## With pivoting """ @@ -465,11 +467,11 @@ true ``` """ cholesky(A::AbstractMatrix, ::RowMaximum; tol = 0.0, check::Bool = true) = - cholesky!(cholcopy(A), RowMaximum(); tol, check) + _cholesky(cholcopy(A), RowMaximum(); tol, check) @deprecate cholesky(A::Union{StridedMatrix,RealHermSymComplexHerm{<:Real,<:StridedMatrix}}, ::Val{true}; tol = 0.0, check::Bool = true) cholesky(A, RowMaximum(); tol, check) false function cholesky(A::AbstractMatrix{Float16}, ::RowMaximum; tol = 0.0, check::Bool = true) - X = cholesky!(cholcopy(A), RowMaximum(); tol, check) + X = _cholesky(cholcopy(A), RowMaximum(); tol, check) return CholeskyPivoted{Float16}(X) end diff --git a/stdlib/LinearAlgebra/src/qr.jl b/stdlib/LinearAlgebra/src/qr.jl index fe40fec78e801..563fa7c049c65 100644 --- a/stdlib/LinearAlgebra/src/qr.jl +++ b/stdlib/LinearAlgebra/src/qr.jl @@ -417,12 +417,15 @@ true function qr(A::AbstractMatrix{T}, arg...; kwargs...) where T require_one_based_indexing(A) AA = copy_similar(A, _qreltype(T)) - return qr!(AA, arg...; kwargs...) + return _qr(AA, arg...; kwargs...) end # TODO: remove in Julia v2.0 @deprecate qr(A::AbstractMatrix, ::Val{false}; kwargs...) qr(A, NoPivot(); kwargs...) @deprecate qr(A::AbstractMatrix, ::Val{true}; kwargs...) qr(A, ColumnNorm(); kwargs...) +# allow packages like SparseArrays.jl to hook into here and redirect to out-of-place `qr` +_qr(A::AbstractMatrix, args...; kwargs...) = qr!(A, args...; kwargs...) + qr(x::Number) = qr(fill(x,1,1)) function qr(v::AbstractVector) require_one_based_indexing(v) From 4b55c4af8e9ef97fc09bee41e60827789c7ce419 Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Thu, 7 Sep 2023 13:24:01 +0200 Subject: [PATCH 2/2] fix signature typo --- stdlib/LinearAlgebra/src/cholesky.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/LinearAlgebra/src/cholesky.jl b/stdlib/LinearAlgebra/src/cholesky.jl index 04ef0ebc9f67f..528eca5c3d8a3 100644 --- a/stdlib/LinearAlgebra/src/cholesky.jl +++ b/stdlib/LinearAlgebra/src/cholesky.jl @@ -408,7 +408,7 @@ function cholesky(A::AbstractMatrix{Float16}, ::NoPivot=NoPivot(); check::Bool = end @deprecate cholesky(A::Union{StridedMatrix{Float16},RealHermSymComplexHerm{Float16,<:StridedMatrix}}, ::Val{false}; check::Bool = true) cholesky(A, NoPivot(); check) false # allow packages like SparseArrays.jl to hook into here and redirect to out-of-place `cholesky` -_cholesky(A::AbstractMatrix, args...; kwargs) = cholesky!(A, args...; kwargs...) +_cholesky(A::AbstractMatrix, args...; kwargs...) = cholesky!(A, args...; kwargs...) ## With pivoting """