Skip to content

Commit 05366dc

Browse files
committed
Merge pull request #16426 from pabloferz/pz/cholmod
Making `\` work with SparseMatrix.CHOLMOD.Factor and SubArrays
2 parents 17bc2a4 + dc59cac commit 05366dc

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

base/sparse/cholmod.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -809,15 +809,15 @@ get_perm(FC::FactorComponent) = get_perm(Factor(FC))
809809
#########################
810810

811811
# Convertion/construction
812-
function convert{T<:VTypes}(::Type{Dense{T}}, A::VecOrMat)
812+
function convert{T<:VTypes}(::Type{Dense{T}}, A::StridedVecOrMat)
813813
d = allocate_dense(size(A, 1), size(A, 2), stride(A, 2), T)
814814
s = unsafe_load(d.p)
815815
for i in eachindex(A)
816816
unsafe_store!(s.x, A[i], i)
817817
end
818818
d
819819
end
820-
function convert(::Type{Dense}, A::VecOrMat)
820+
function convert(::Type{Dense}, A::StridedVecOrMat)
821821
T = promote_type(eltype(A), Float64)
822822
return convert(Dense{T}, A)
823823
end
@@ -1464,8 +1464,8 @@ Ac_ldiv_B(L::FactorComponent, B) = ctranspose(L)\B
14641464

14651465
(\){T}(L::Factor{T}, B::Dense{T}) = solve(CHOLMOD_A, L, B)
14661466
(\)(L::Factor{Float64}, B::VecOrMat{Complex{Float64}}) = L\real(B) + L\imag(B)
1467-
(\)(L::Factor, b::Vector) = Vector(L\convert(Dense{eltype(L)}, b))
1468-
(\)(L::Factor, B::Matrix) = Matrix(L\convert(Dense{eltype(L)}, B))
1467+
(\)(L::Factor, b::StridedVector) = Vector(L\convert(Dense{eltype(L)}, b))
1468+
(\)(L::Factor, B::StridedMatrix) = Matrix(L\convert(Dense{eltype(L)}, B))
14691469
(\)(L::Factor, B::Sparse) = spsolve(CHOLMOD_A, L, B)
14701470
# When right hand side is sparse, we have to ensure that the rhs is not marked as symmetric.
14711471
(\)(L::Factor, B::SparseVecOrMat) = sparse(spsolve(CHOLMOD_A, L, Sparse(B, 0)))

test/sparsedir/cholmod.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,10 @@ Fnew = deserialize(b)
632632
@test_throws MethodError cholfact(speye(BigFloat, 5))
633633
@test_throws MethodError cholfact(Symmetric(speye(BigFloat, 5)))
634634
@test_throws MethodError cholfact(Hermitian(speye(Complex{BigFloat}, 5)))
635+
636+
# test \ for Factor and StridedVecOrMat
637+
let x = rand(5)
638+
A = cholfact(sparse(diagm(x.\1)))
639+
@test_approx_eq A\sub(ones(10),1:2:10) x
640+
@test_approx_eq A\slice(eye(5,5),:,:) diagm(x)
641+
end

0 commit comments

Comments
 (0)