diff --git a/base/sparse/cholmod.jl b/base/sparse/cholmod.jl index f031e243b8aad..31d0c64cdfecf 100644 --- a/base/sparse/cholmod.jl +++ b/base/sparse/cholmod.jl @@ -22,7 +22,7 @@ using Base.SparseMatrix: AbstractSparseMatrix, SparseMatrixCSC, increment, indty include("cholmod_h.jl") ## macro to generate the name of the C function according to the integer type -macro cholmod_name(nm,typ) string("cholmod_", eval(typ) == Int64 ? "l_" : "", nm) end +macro cholmod_name(nm,typ) string("cholmod_", eval(typ) == Int ? "l_" : "", nm) end for Ti in IndexTypes @eval begin @@ -198,44 +198,44 @@ end ### cholmod_core_h ### function allocate_dense(nrow::Integer, ncol::Integer, d::Integer, ::Type{Float64}) - d = Dense(ccall((:cholmod_allocate_dense, :libcholmod), Ptr{C_Dense{Float64}}, + d = Dense(ccall((:cholmod_l_allocate_dense, :libcholmod), Ptr{C_Dense{Float64}}, (Csize_t, Csize_t, Csize_t, Cint, Ptr{Void}), - nrow, ncol, d, REAL, common(Cint))) + nrow, ncol, d, REAL, common(Int))) finalizer(d, free!) d end function allocate_dense(nrow::Integer, ncol::Integer, d::Integer, ::Type{Complex{Float64}}) - d = Dense(ccall((:cholmod_allocate_dense, :libcholmod), Ptr{C_Dense{Complex{Float64}}}, + d = Dense(ccall((:cholmod_l_allocate_dense, :libcholmod), Ptr{C_Dense{Complex{Float64}}}, (Csize_t, Csize_t, Csize_t, Cint, Ptr{Void}), - nrow, ncol, d, COMPLEX, common(Cint))) + nrow, ncol, d, COMPLEX, common(Int))) finalizer(d, free!) d end -free_dense!{T}(p::Ptr{C_Dense{T}}) = ccall((:cholmod_free_dense, :libcholmod), Cint, (Ptr{Ptr{C_Dense{T}}}, Ptr{Void}), &p, common(Cint)) +free_dense!{T}(p::Ptr{C_Dense{T}}) = ccall((:cholmod_l_free_dense, :libcholmod), Cint, (Ptr{Ptr{C_Dense{T}}}, Ptr{Void}), &p, common(Cint)) function zeros{T<:VTypes}(m::Integer, n::Integer, ::Type{T}) - d = Dense(ccall((:cholmod_zeros, :libcholmod), Ptr{C_Dense{T}}, + d = Dense(ccall((:cholmod_l_zeros, :libcholmod), Ptr{C_Dense{T}}, (Csize_t, Csize_t, Cint, Ptr{UInt8}), - m, n, xtyp(T), common(Cint))) + m, n, xtyp(T), common(Int))) finalizer(d, free!) d end zeros(m::Integer, n::Integer) = zeros(m, n, Float64) function ones{T<:VTypes}(m::Integer, n::Integer, ::Type{T}) - d = Dense(ccall((:cholmod_ones, :libcholmod), Ptr{C_Dense{T}}, + d = Dense(ccall((:cholmod_l_ones, :libcholmod), Ptr{C_Dense{T}}, (Csize_t, Csize_t, Cint, Ptr{UInt8}), - m, n, xtyp(T), common(Cint))) + m, n, xtyp(T), common(Int))) finalizer(d, free!) d end ones(m::Integer, n::Integer) = ones(m, n, Float64) function eye{T<:VTypes}(m::Integer, n::Integer, ::Type{T}) - d = Dense(ccall((:cholmod_eye, :libcholmod), Ptr{C_Dense{T}}, + d = Dense(ccall((:cholmod_l_eye, :libcholmod), Ptr{C_Dense{T}}, (Csize_t, Csize_t, Cint, Ptr{UInt8}), - m, n, xtyp(T), common(Cint))) + m, n, xtyp(T), common(Int))) finalizer(d, free!) d end @@ -243,9 +243,9 @@ eye(m::Integer, n::Integer) = eye(m, n, Float64) eye(n::Integer) = eye(n, n, Float64) function copy_dense{Tv<:VTypes}(A::Dense{Tv}) - d = Dense(ccall((:cholmod_copy_dense, :libcholmod), Ptr{C_Dense{Tv}}, + d = Dense(ccall((:cholmod_l_copy_dense, :libcholmod), Ptr{C_Dense{Tv}}, (Ptr{C_Dense{Tv}}, Ptr{UInt8}), - A.p, common(Cint))) + A.p, common(Int))) finalizer(d, free!) d end @@ -260,16 +260,16 @@ function norm_dense{Tv<:VTypes}(D::Dense{Tv}, p::Integer) elseif p != 0 && p != 1 throw(ArgumentError("second argument must be either 0 (Inf norm), 1, or 2")) end - ccall((:cholmod_norm_dense, :libcholmod), Cdouble, + ccall((:cholmod_l_norm_dense, :libcholmod), Cdouble, (Ptr{C_Dense{Tv}}, Cint, Ptr{UInt8}), - D.p, p, common(Cint)) + D.p, p, common(Int)) end ### cholmod_check.h ### function check_dense{T<:VTypes}(A::Dense{T}) - bool(ccall((:cholmod_check_dense, :libcholmod), Cint, + bool(ccall((:cholmod_l_check_dense, :libcholmod), Cint, (Ptr{C_Dense{T}}, Ptr{UInt8}), - A.p, common(Cint))) + A.p, common(Int))) end # Non-Dense wrappers (which all depend on IType) diff --git a/test/sparsedir/cholmod.jl b/test/sparsedir/cholmod.jl index 3f94894f345ad..8408a73bb0c2a 100644 --- a/test/sparsedir/cholmod.jl +++ b/test/sparsedir/cholmod.jl @@ -194,51 +194,51 @@ run(`rm tmp.mtx`) # test that Sparse(Ptr) constructor throws the right places ## The struct pointer must be constructed by the library constructor and then modified afterwards to checks that the method throws ### illegal dtype (for now but should be supprted at some point) -p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid}, +p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid}, (Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}), - 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Cint)) + 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int)) puint = convert(Ptr{Uint32}, p) unsafe_store!(puint, CHOLMOD.SINGLE, 3*div(sizeof(Csize_t), 4) + 5*div(sizeof(Ptr{Void}), 4) + 4) @test_throws CHOLMOD.CHOLMODException CHOLMOD.Sparse(p) ### illegal dtype -p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid}, +p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid}, (Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}), - 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Cint)) + 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int)) puint = convert(Ptr{Uint32}, p) unsafe_store!(puint, 5, 3*div(sizeof(Csize_t), 4) + 5*div(sizeof(Ptr{Void}), 4) + 4) @test_throws CHOLMOD.CHOLMODException CHOLMOD.Sparse(p) ### illegal xtype -p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid}, +p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid}, (Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}), - 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Cint)) + 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int)) puint = convert(Ptr{Uint32}, p) unsafe_store!(puint, 3, 3*div(sizeof(Csize_t), 4) + 5*div(sizeof(Ptr{Void}), 4) + 3) @test_throws CHOLMOD.CHOLMODException CHOLMOD.Sparse(p) ### illegal itype -p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid}, +p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid}, (Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}), - 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Cint)) + 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int)) puint = convert(Ptr{Uint32}, p) unsafe_store!(puint, CHOLMOD.INTLONG, 3*div(sizeof(Csize_t), 4) + 5*div(sizeof(Ptr{Void}), 4) + 2) @test_throws CHOLMOD.CHOLMODException CHOLMOD.Sparse(p) ### illegal itype -p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid}, +p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid}, (Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}), - 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Cint)) + 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int)) puint = convert(Ptr{Uint32}, p) unsafe_store!(puint, 5, 3*div(sizeof(Csize_t), 4) + 5*div(sizeof(Ptr{Void}), 4) + 2) @test_throws CHOLMOD.CHOLMODException CHOLMOD.Sparse(p) # test that Sparse(Ptr) works for SuiteSparse_long (on 64 bit systems) if CHOLMOD.SuiteSparse_long == Int64 - p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid}, + p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid}, (Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}), - 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(CHOLMOD.SuiteSparse_long)) - @test isa(CHOLMOD.Sparse(p), CHOLMOD.Sparse{Float64,CHOLMOD.SuiteSparse_long}) + 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int32)) + @test isa(CHOLMOD.Sparse(p), CHOLMOD.Sparse{Float64,Int32}) end # Test Dense wrappers (only Float64 supported a present) @@ -283,9 +283,9 @@ end # Test Sparse and Factor ## test free_sparse! -p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_Sparse{Float64,Cint}}, +p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_Sparse{Float64,Cint}}, (Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}), - 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Cint)) + 1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int)) @test CHOLMOD.free_sparse!(p) for elty in (Float64, Complex{Float64})