Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook into new factorization dispatch mechanisms #437

Merged
merged 8 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
let B=A
qr(_unsafe_unfix(B); tol, ordering)
end

LinearAlgebra._qr(A::SparseMatrixCSC; kwargs...) = qr(A; kwargs...)
LinearAlgebra._qr(::SparseMatrixCSC, ::LinearAlgebra.PivotingStrategy; kwargs...) =

Check warning on line 235 in src/solvers/spqr.jl

View check run for this annotation

Codecov / codecov/patch

src/solvers/spqr.jl#L234-L235

Added lines #L234 - L235 were not covered by tests
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::AdjOrTrans{T,S}; check::Bool = true) where {T<:UMFVTypes, S<:AbstractSparseMatrixCSC{T}} =
lu(copy(A); check)

LinearAlgebra._lu(A::AbstractSparseMatrixCSC; kwargs...) =

Check warning on line 410 in src/solvers/umfpack.jl

View check run for this annotation

Codecov / codecov/patch

src/solvers/umfpack.jl#L410

Added line #L410 was not covered by tests
lu(A; kwargs...)
LinearAlgebra._lu(::AbstractSparseMatrixCSC, ::LinearAlgebra.PivotingStrategy; kwargs...) =

Check warning on line 412 in src/solvers/umfpack.jl

View check run for this annotation

Codecov / codecov/patch

src/solvers/umfpack.jl#L412

Added line #L412 was not covered by tests
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
Loading