Skip to content

Commit 5a68314

Browse files
committed
Fix 32 bit issue with cholmod.jl
1 parent 7993601 commit 5a68314

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

base/sparse/cholmod.jl

+18-18
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using Base.SparseMatrix: AbstractSparseMatrix, SparseMatrixCSC, increment, indty
2222
include("cholmod_h.jl")
2323

2424
## macro to generate the name of the C function according to the integer type
25-
macro cholmod_name(nm,typ) string("cholmod_", eval(typ) == Int64 ? "l_" : "", nm) end
25+
macro cholmod_name(nm,typ) string("cholmod_", eval(typ) == Int ? "l_" : "", nm) end
2626

2727
for Ti in IndexTypes
2828
@eval begin
@@ -197,54 +197,54 @@ end
197197

198198
### cholmod_core_h ###
199199
function allocate_dense(nrow::Integer, ncol::Integer, d::Integer, ::Type{Float64})
200-
d = Dense(ccall((:cholmod_allocate_dense, :libcholmod), Ptr{C_Dense{Float64}},
200+
d = Dense(ccall((:cholmod_l_allocate_dense, :libcholmod), Ptr{C_Dense{Float64}},
201201
(Csize_t, Csize_t, Csize_t, Cint, Ptr{Void}),
202-
nrow, ncol, d, REAL, common(Cint)))
202+
nrow, ncol, d, REAL, common(Int)))
203203
finalizer(d, free!)
204204
d
205205
end
206206
function allocate_dense(nrow::Integer, ncol::Integer, d::Integer, ::Type{Complex{Float64}})
207-
d = Dense(ccall((:cholmod_allocate_dense, :libcholmod), Ptr{C_Dense{Complex{Float64}}},
207+
d = Dense(ccall((:cholmod_l_allocate_dense, :libcholmod), Ptr{C_Dense{Complex{Float64}}},
208208
(Csize_t, Csize_t, Csize_t, Cint, Ptr{Void}),
209-
nrow, ncol, d, COMPLEX, common(Cint)))
209+
nrow, ncol, d, COMPLEX, common(Int)))
210210
finalizer(d, free!)
211211
d
212212
end
213213

214-
free_dense!{T}(p::Ptr{C_Dense{T}}) = ccall((:cholmod_free_dense, :libcholmod), Cint, (Ptr{Ptr{C_Dense{T}}}, Ptr{Void}), &p, common(Cint))
214+
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))
215215

216216
function zeros{T<:VTypes}(m::Integer, n::Integer, ::Type{T})
217-
d = Dense(ccall((:cholmod_zeros, :libcholmod), Ptr{C_Dense{T}},
217+
d = Dense(ccall((:cholmod_l_zeros, :libcholmod), Ptr{C_Dense{T}},
218218
(Csize_t, Csize_t, Cint, Ptr{UInt8}),
219-
m, n, xtyp(T), common(Cint)))
219+
m, n, xtyp(T), common(Int)))
220220
finalizer(d, free!)
221221
d
222222
end
223223
zeros(m::Integer, n::Integer) = zeros(m, n, Float64)
224224

225225
function ones{T<:VTypes}(m::Integer, n::Integer, ::Type{T})
226-
d = Dense(ccall((:cholmod_ones, :libcholmod), Ptr{C_Dense{T}},
226+
d = Dense(ccall((:cholmod_l_ones, :libcholmod), Ptr{C_Dense{T}},
227227
(Csize_t, Csize_t, Cint, Ptr{UInt8}),
228-
m, n, xtyp(T), common(Cint)))
228+
m, n, xtyp(T), common(Int)))
229229
finalizer(d, free!)
230230
d
231231
end
232232
ones(m::Integer, n::Integer) = ones(m, n, Float64)
233233

234234
function eye{T<:VTypes}(m::Integer, n::Integer, ::Type{T})
235-
d = Dense(ccall((:cholmod_eye, :libcholmod), Ptr{C_Dense{T}},
235+
d = Dense(ccall((:cholmod_l_eye, :libcholmod), Ptr{C_Dense{T}},
236236
(Csize_t, Csize_t, Cint, Ptr{UInt8}),
237-
m, n, xtyp(T), common(Cint)))
237+
m, n, xtyp(T), common(Int)))
238238
finalizer(d, free!)
239239
d
240240
end
241241
eye(m::Integer, n::Integer) = eye(m, n, Float64)
242242
eye(n::Integer) = eye(n, n, Float64)
243243

244244
function copy_dense{Tv<:VTypes}(A::Dense{Tv})
245-
d = Dense(ccall((:cholmod_copy_dense, :libcholmod), Ptr{C_Dense{Tv}},
245+
d = Dense(ccall((:cholmod_l_copy_dense, :libcholmod), Ptr{C_Dense{Tv}},
246246
(Ptr{C_Dense{Tv}}, Ptr{UInt8}),
247-
A.p, common(Cint)))
247+
A.p, common(Int)))
248248
finalizer(d, free!)
249249
d
250250
end
@@ -259,16 +259,16 @@ function norm_dense{Tv<:VTypes}(D::Dense{Tv}, p::Integer)
259259
elseif p != 0 && p != 1
260260
throw(ArgumentError("second argument must be either 0 (Inf norm), 1, or 2"))
261261
end
262-
ccall((:cholmod_norm_dense, :libcholmod), Cdouble,
262+
ccall((:cholmod_l_norm_dense, :libcholmod), Cdouble,
263263
(Ptr{C_Dense{Tv}}, Cint, Ptr{UInt8}),
264-
D.p, p, common(Cint))
264+
D.p, p, common(Int))
265265
end
266266

267267
### cholmod_check.h ###
268268
function check_dense{T<:VTypes}(A::Dense{T})
269-
bool(ccall((:cholmod_check_dense, :libcholmod), Cint,
269+
bool(ccall((:cholmod_l_check_dense, :libcholmod), Cint,
270270
(Ptr{C_Dense{T}}, Ptr{UInt8}),
271-
A.p, common(Cint)))
271+
A.p, common(Int)))
272272
end
273273

274274
# Non-Dense wrappers (which all depend on IType)

test/sparsedir/cholmod.jl

+15-15
Original file line numberDiff line numberDiff line change
@@ -192,51 +192,51 @@ run(`rm tmp.mtx`)
192192
# test that Sparse(Ptr) constructor throws the right places
193193
## The struct pointer must be constructed by the library constructor and then modified afterwards to checks that the method throws
194194
### illegal dtype (for now but should be supprted at some point)
195-
p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid},
195+
p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid},
196196
(Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}),
197-
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Cint))
197+
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int))
198198
puint = convert(Ptr{Uint32}, p)
199199
unsafe_store!(puint, CHOLMOD.SINGLE, 3*div(sizeof(Csize_t), 4) + 5*div(sizeof(Ptr{Void}), 4) + 4)
200200
@test_throws CHOLMOD.CHOLMODException CHOLMOD.Sparse(p)
201201

202202
### illegal dtype
203-
p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid},
203+
p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid},
204204
(Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}),
205-
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Cint))
205+
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int))
206206
puint = convert(Ptr{Uint32}, p)
207207
unsafe_store!(puint, 5, 3*div(sizeof(Csize_t), 4) + 5*div(sizeof(Ptr{Void}), 4) + 4)
208208
@test_throws CHOLMOD.CHOLMODException CHOLMOD.Sparse(p)
209209

210210
### illegal xtype
211-
p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid},
211+
p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid},
212212
(Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}),
213-
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Cint))
213+
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int))
214214
puint = convert(Ptr{Uint32}, p)
215215
unsafe_store!(puint, 3, 3*div(sizeof(Csize_t), 4) + 5*div(sizeof(Ptr{Void}), 4) + 3)
216216
@test_throws CHOLMOD.CHOLMODException CHOLMOD.Sparse(p)
217217

218218
### illegal itype
219-
p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid},
219+
p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid},
220220
(Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}),
221-
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Cint))
221+
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int))
222222
puint = convert(Ptr{Uint32}, p)
223223
unsafe_store!(puint, CHOLMOD.INTLONG, 3*div(sizeof(Csize_t), 4) + 5*div(sizeof(Ptr{Void}), 4) + 2)
224224
@test_throws CHOLMOD.CHOLMODException CHOLMOD.Sparse(p)
225225

226226
### illegal itype
227-
p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid},
227+
p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid},
228228
(Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}),
229-
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Cint))
229+
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int))
230230
puint = convert(Ptr{Uint32}, p)
231231
unsafe_store!(puint, 5, 3*div(sizeof(Csize_t), 4) + 5*div(sizeof(Ptr{Void}), 4) + 2)
232232
@test_throws CHOLMOD.CHOLMODException CHOLMOD.Sparse(p)
233233

234234
# test that Sparse(Ptr) works for SuiteSparse_long (on 64 bit systems)
235235
if CHOLMOD.SuiteSparse_long == Int64
236-
p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid},
236+
p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_SparseVoid},
237237
(Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}),
238-
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(CHOLMOD.SuiteSparse_long))
239-
@test isa(CHOLMOD.Sparse(p), CHOLMOD.Sparse{Float64,CHOLMOD.SuiteSparse_long})
238+
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int32))
239+
@test isa(CHOLMOD.Sparse(p), CHOLMOD.Sparse{Float64,Int32})
240240
end
241241

242242
# Test Dense wrappers (only Float64 supported a present)
@@ -281,9 +281,9 @@ end
281281

282282
# Test Sparse and Factor
283283
## test free_sparse!
284-
p = ccall((:cholmod_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_Sparse{Float64,Cint}},
284+
p = ccall((:cholmod_l_allocate_sparse, :libcholmod), Ptr{CHOLMOD.C_Sparse{Float64,Cint}},
285285
(Csize_t, Csize_t, Csize_t, Cint, Cint, Cint, Cint, Ptr{Void}),
286-
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Cint))
286+
1, 1, 1, true, true, 0, CHOLMOD.REAL, CHOLMOD.common(Int))
287287
@test CHOLMOD.free_sparse!(p)
288288

289289
for elty in (Float64, Complex{Float64})

0 commit comments

Comments
 (0)