Skip to content

Commit

Permalink
generalize cholesky!
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch committed Feb 12, 2022
1 parent 08ffb3e commit 554ac18
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions stdlib/LinearAlgebra/src/cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ function cholesky!(A::RealHermSymComplexHerm, ::NoPivot = NoPivot(); check::Bool
return Cholesky(C.data, A.uplo, info)
end

### for StridedMatrices, check that matrix is symmetric/Hermitian
### for AbstractMatrix, check that matrix is symmetric/Hermitian
"""
cholesky!(A::StridedMatrix, NoPivot(); check = true) -> Cholesky
cholesky!(A::AbstractMatrix, NoPivot(); check = true) -> Cholesky
The same as [`cholesky`](@ref), but saves space by overwriting the input `A`,
instead of creating a copy. An [`InexactError`](@ref) exception is thrown if
Expand All @@ -293,7 +293,7 @@ Stacktrace:
[...]
```
"""
function cholesky!(A::StridedMatrix, ::NoPivot = NoPivot(); check::Bool = true)
function cholesky!(A::AbstractMatrix, ::NoPivot = NoPivot(); check::Bool = true)
checksquare(A)
if !ishermitian(A) # return with info = -1 if not Hermitian
check && checkpositivedefinite(-1)
Expand Down Expand Up @@ -322,16 +322,16 @@ cholesky!(A::RealHermSymComplexHerm{<:Real}, ::RowMaximum; tol = 0.0, check::Boo
throw(ArgumentError("generic pivoted Cholesky factorization is not implemented yet"))
@deprecate cholesky!(A::RealHermSymComplexHerm{<:Real}, ::Val{true}; kwargs...) cholesky!(A, RowMaximum(); kwargs...) false

### for StridedMatrices, check that matrix is symmetric/Hermitian
### for AbstractMatrix, check that matrix is symmetric/Hermitian
"""
cholesky!(A::StridedMatrix, RowMaximum(); tol = 0.0, check = true) -> CholeskyPivoted
cholesky!(A::AbstractMatrix, RowMaximum(); tol = 0.0, check = true) -> CholeskyPivoted
The same as [`cholesky`](@ref), but saves space by overwriting the input `A`,
instead of creating a copy. An [`InexactError`](@ref) exception is thrown if the
factorization produces a number not representable by the element type of `A`,
e.g. for integer types.
"""
function cholesky!(A::StridedMatrix, ::RowMaximum; tol = 0.0, check::Bool = true)
function cholesky!(A::AbstractMatrix, ::RowMaximum; tol = 0.0, check::Bool = true)
checksquare(A)
if !ishermitian(A)
C = CholeskyPivoted(A, 'U', Vector{BlasInt}(),convert(BlasInt, 1),
Expand Down Expand Up @@ -601,7 +601,7 @@ function ldiv!(C::CholeskyPivoted{T}, B::StridedMatrix{T}) where T<:BlasFloat
B
end

function ldiv!(C::CholeskyPivoted, B::StridedVector)
function ldiv!(C::CholeskyPivoted, B::AbstractVector)
if C.uplo == 'L'
ldiv!(adjoint(LowerTriangular(C.factors)),
ldiv!(LowerTriangular(C.factors), permute!(B, C.piv)))
Expand All @@ -612,7 +612,7 @@ function ldiv!(C::CholeskyPivoted, B::StridedVector)
invpermute!(B, C.piv)
end

function ldiv!(C::CholeskyPivoted, B::StridedMatrix)
function ldiv!(C::CholeskyPivoted, B::AbstractMatrix)
n = size(C, 1)
for i in 1:size(B, 2)
permute!(view(B, 1:n, i), C.piv)
Expand All @@ -630,15 +630,15 @@ function ldiv!(C::CholeskyPivoted, B::StridedMatrix)
B
end

function rdiv!(B::StridedMatrix, C::Cholesky{<:Any,<:AbstractMatrix})
function rdiv!(B::AbstractMatrix, C::Cholesky{<:Any,<:AbstractMatrix})
if C.uplo == 'L'
return rdiv!(rdiv!(B, adjoint(LowerTriangular(C.factors))), LowerTriangular(C.factors))
else
return rdiv!(rdiv!(B, UpperTriangular(C.factors)), adjoint(UpperTriangular(C.factors)))
end
end

function LinearAlgebra.rdiv!(B::StridedMatrix, C::CholeskyPivoted)
function LinearAlgebra.rdiv!(B::AbstractMatrix, C::CholeskyPivoted)
n = size(C, 2)
for i in 1:size(B, 1)
permute!(view(B, i, 1:n), C.piv)
Expand Down

0 comments on commit 554ac18

Please sign in to comment.