Skip to content

Commit

Permalink
Hook into new factorization dispatch mechanisms (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch authored Oct 6, 2023
1 parent 713ab9b commit 034d234
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/solvers/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1433,10 +1433,16 @@ true
[^DavisHager2009]: Davis, Timothy A., & Hager, W. W. (2009). Dynamic Supernodes in Sparse Cholesky Update/Downdate and Triangular Solves. ACM Trans. Math. Softw., 35(4). [doi:10.1145/1462173.1462176](https://doi.org/10.1145/1462173.1462176)
"""
cholesky(A::Union{SparseMatrixCSC{T}, SparseMatrixCSC{Complex{T}},
Symmetric{T, <:SparseMatrixCSC{T}},
Hermitian{Complex{T}, <:SparseMatrixCSC{Complex{T}}},
Hermitian{T, <:SparseMatrixCSC{T}}};
kws...) where {T<:Real} = cholesky(Sparse(A); kws...)
RealHermSymComplexHerm{T,<:SparseMatrixCSC}}; kws...) where {T<:Real} =
cholesky(Sparse(A); kws...)

LinearAlgebra._cholesky(A::Union{SparseMatrixCSC{T}, SparseMatrixCSC{Complex{T}},
RealHermSymComplexHerm{T,<:SparseMatrixCSC}};
kws...) where {T<:Real} = cholesky(A; kws...)
LinearAlgebra._cholesky(A::Union{SparseMatrixCSC{T}, SparseMatrixCSC{Complex{T}},
RealHermSymComplexHerm{T,<:SparseMatrixCSC}}, ::LinearAlgebra.PivotingStrategy;
kws...) where {T<:Real} =
error("Pivoting strategies are not supported for `SparseMatrixCSC`s")

function ldlt!(F::Factor{Tv}, A::Sparse{Tv};
shift::Real=0.0, check::Bool = true) where Tv
Expand Down
5 changes: 5 additions & 0 deletions src/solvers/spqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ LinearAlgebra.qr(A::FixedSparseCSC; tol=_default_tol(A), ordering=ORDERING_DEFAU
let B=A
qr(_unsafe_unfix(B); tol, ordering)
end

LinearAlgebra._qr(A::SparseMatrixCSC; kwargs...) = qr(A; kwargs...)
LinearAlgebra._qr(::SparseMatrixCSC, ::LinearAlgebra.PivotingStrategy; kwargs...) =
error("Pivoting Strategies are not supported for `SparseMatrixCSC`s")

function LinearAlgebra.lmul!(Q::QRSparseQ, A::StridedVecOrMat)
if size(A, 1) != size(Q, 1)
throw(DimensionMismatch("size(Q) = $(size(Q)) but size(A) = $(size(A))"))
Expand Down
5 changes: 5 additions & 0 deletions src/solvers/umfpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ lu(A::AbstractSparseMatrixCSC; check::Bool = true) = lu(float(A); check = check)
lu(A::AdjOrTrans{T,S}; check::Bool = true) where {T<:UMFVTypes, S<:AbstractSparseMatrixCSC{T}} =
lu(copy(A); check)

LinearAlgebra._lu(A::AbstractSparseMatrixCSC; kwargs...) =
lu(A; kwargs...)
LinearAlgebra._lu(::AbstractSparseMatrixCSC, ::LinearAlgebra.PivotingStrategy; kwargs...) =
error("Pivoting Strategies are not supported by `SparseMatrixCSC`s")

"""
lu!(F::UmfpackLU, A::AbstractSparseMatrixCSC; check=true, reuse_symbolic=true, q=nothing) -> F::UmfpackLU
Expand Down
12 changes: 11 additions & 1 deletion test/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using Serialization
using LinearAlgebra:
I, cholesky, cholesky!, det, diag, eigmax, ishermitian, isposdef, issuccess,
issymmetric, ldlt, ldlt!, logdet, norm, opnorm, Diagonal, Hermitian, Symmetric,
PosDefException, ZeroPivotException
PosDefException, ZeroPivotException, RowMaximum
using SparseArrays
using SparseArrays: getcolptr
using SparseArrays.LibSuiteSparse
Expand Down Expand Up @@ -972,6 +972,16 @@ end
@test residual < 1e-6
end

@testset "wrapped sparse matrices" begin
A = I + sprand(10, 10, 0.1); A = A'A
@test issuccess(cholesky(view(A, :, :)))
@test issuccess(cholesky(Symmetric(view(A, :, :))))
@test_throws ErrorException cholesky(view(A, :, :), RowMaximum())
# turn on once two-arg cholesky is made to forward any PivotingStrategy argument
# @test_throws ErrorException cholesky(A, NoPivot())
# @test_throws ErrorException cholesky(view(A, :, :), NoPivot())
end

end # Base.USE_GPL_LIBS

end # module

0 comments on commit 034d234

Please sign in to comment.