Skip to content

Commit

Permalink
Introduce cholesky and qr hooks for wrapped sparse matrices (#51220)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
dkarrasch authored Sep 7, 2023
1 parent 1305f40 commit 27fa5de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 6 additions & 4 deletions stdlib/LinearAlgebra/src/cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion stdlib/LinearAlgebra/src/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

2 comments on commit 27fa5de

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

Please sign in to comment.