diff --git a/src/solvers/cholmod.jl b/src/solvers/cholmod.jl index d77093e3..fb469d0a 100644 --- a/src/solvers/cholmod.jl +++ b/src/solvers/cholmod.jl @@ -1947,8 +1947,20 @@ for TI in IndexTypes # `cholmod_dense_struct`s in CHOLMOD. Instead, we want to reuse # the existing memory. We can do this by creating new # `cholmod_dense_struct`s and filling them manually. - dense_x = wrap_dense(x) - dense_b = wrap_dense(b) + # We need to use a special handling for the case of `Dense` + # input arrays since the `pointer` refers to the pointer to the + # `cholmod_dense`, not to the array values themselves as for + # standard arrays. + if x isa Dense + dense_x = unsafe_load(pointer(x)) + else + dense_x = wrap_dense(x) + end + if b isa Dense + dense_b = unsafe_load(pointer(b)) + else + dense_b = wrap_dense(b) + end X_Handle = Ptr{cholmod_dense_struct}(pointer_from_objref(dense_x)) Y_Handle = Ptr{cholmod_dense_struct}(C_NULL) diff --git a/test/cholmod.jl b/test/cholmod.jl index b241e37e..ce6afdae 100644 --- a/test/cholmod.jl +++ b/test/cholmod.jl @@ -22,7 +22,8 @@ using SparseArrays.LibSuiteSparse: cholmod_l_allocate_sparse, cholmod_allocate_s # CHOLMOD tests itypes = sizeof(Int) == 4 ? (Int32,) : (Int32, Int64) -for Ti ∈ itypes, Tv ∈ (Float32, Float64) +# for Ti ∈ itypes, Tv ∈ (Float32, Float64) +for Ti ∈ (Int64,), Tv ∈ (Float64,) Random.seed!(123) @testset "based on deps/SuiteSparse-4.0.2/CHOLMOD/Demo/ index type $Ti" begin @@ -284,6 +285,26 @@ end end end +@testset "ldiv! $Tv $Ti" begin + local A, x, x2, b, X, X2, B + A = sprand(10, 10, 0.1) + A = I + A * A' + A = convert(SparseMatrixCSC{Tv,Ti}, A) + factor = cholesky(A) + + x = fill(Tv(1), 10) + b = A * x + x2 = zero(x) + @inferred ldiv!(x2, factor, b) + @test x2 ≈ x + + X = fill(Tv(1), 10, 5) + B = A * X + X2 = zero(X) + @inferred ldiv!(X2, factor, B) + @test X2 ≈ X +end + end #end for Ti ∈ itypes for Tv ∈ (Float32, Float64)