Skip to content

Commit

Permalink
Fix sparse cholesky to return Vector when the RHS is a Vector (#30416)
Browse files Browse the repository at this point in the history
Fixes #28985
  • Loading branch information
raghav9-97 authored and ViralBShah committed Dec 17, 2018
1 parent 64133f6 commit b451001
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion stdlib/SuiteSparse/src/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1686,10 +1686,18 @@ end
(\)(L::Factor, B::SparseVecOrMat) = sparse(spsolve(CHOLMOD_A, L, Sparse(B, 0)))

\(adjL::Adjoint{<:Any,<:Factor}, B::Dense) = (L = adjL.parent; solve(CHOLMOD_A, L, B))
\(adjL::Adjoint{<:Any,<:Factor}, B::VecOrMat) = (L = adjL.parent; Matrix(solve(CHOLMOD_A, L, Dense(B))))
\(adjL::Adjoint{<:Any,<:Factor}, B::Sparse) = (L = adjL.parent; spsolve(CHOLMOD_A, L, B))
\(adjL::Adjoint{<:Any,<:Factor}, B::SparseVecOrMat) = (L = adjL.parent; \(adjoint(L), Sparse(B)))

function \(adjL::Adjoint{<:Any,<:Factor}, b::StridedVector)
L = adjL.parent
return Vector(solve(CHOLMOD_A, L, Dense(b)))
end
function \(adjL::Adjoint{<:Any,<:Factor}, B::StridedMatrix)
L = adjL.parent
return Matrix(solve(CHOLMOD_A, L, Dense(B)))
end

const RealHermSymComplexHermF64SSL = Union{
Symmetric{Float64,SparseMatrixCSC{Float64,SuiteSparse_long}},
Hermitian{Float64,SparseMatrixCSC{Float64,SuiteSparse_long}},
Expand Down
5 changes: 5 additions & 0 deletions stdlib/SuiteSparse/test/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,11 @@ end
@test_throws ArgumentError logdet(Fnew)
end

@testset "Issue #28985" begin
@test typeof(cholesky(sparse(I, 4, 4))'\rand(4)) == Array{Float64, 1}
@test typeof(cholesky(sparse(I, 4, 4))'\rand(4,1)) == Array{Float64, 2}
end

@testset "Issue with promotion during conversion to CHOLMOD.Dense" begin
@test CHOLMOD.Dense(fill(1, 5)) == fill(1, 5, 1)
@test CHOLMOD.Dense(fill(1f0, 5)) == fill(1, 5, 1)
Expand Down

0 comments on commit b451001

Please sign in to comment.