Skip to content

Instantly share code, notes, and snippets.

@tkelman
Created December 2, 2014 21:52
Show Gist options
  • Select an option

  • Save tkelman/c4d7677471c787ab4f32 to your computer and use it in GitHub Desktop.

Select an option

Save tkelman/c4d7677471c787ab4f32 to your computer and use it in GitHub Desktop.
| | |_| | | | (_| | | Version 0.4.0-dev+1914 (2014-12-02 11:07 UTC)
_/ |\__'_|_|_|\__'_| | (detached from acroy/cholmod)/dd2c6a3* (fork: 6 commit
s, 1 day)
|__/ | x86_64-w64-mingw32
julia> const CHOLMOD = Base.LinAlg.CHOLMOD
Base.LinAlg.CHOLMOD
julia> function print_sparse{Tv<:Float64}(ccs::CHOLMOD.c_CholmodSparse{Tv,Int},
lev=int32(5), nm="")
cm = CHOLMOD.cmn(Int)
orig = cm[CHOLMOD.chm_prt_inds]
cm[CHOLMOD.chm_prt_inds] = reinterpret(UInt8, [int32(lev)])
b= ccall((CHOLMOD.@chm_nm "print_sparse" Int
,:libcholmod), Cint,
(Ptr{CHOLMOD.c_CholmodSparse{Tv,Int}}, Ptr{UIn
t8}, Ptr{UInt8}),
&ccs, nm, cm)
cm[CHOLMOD.chm_prt_inds] = orig
b
end
print_sparse (generic function with 3 methods)
julia>
julia> S = sprand(10,10,0.1)
10x10 sparse matrix with 9 Float64 entries:
[6 , 2] = 0.440932
[9 , 2] = 0.773512
[8 , 3] = 0.502232
[1 , 5] = 0.0392066
[3 , 5] = 0.393238
[3 , 6] = 0.637359
[5 , 10] = 0.163432
[6 , 10] = 0.426301
[8 , 10] = 0.802963
julia> colptr = copy(S.colptr)-1
11-element Array{Int64,1}:
0
0
2
3
3
5
6
6
6
6
9
julia> rowval = copy(S.rowval)-1
9-element Array{Int64,1}:
5
8
7
0
2
2
4
5
7
julia> nzval = copy(S.nzval)
9-element Array{Float64,1}:
0.440932
0.773512
0.502232
0.0392066
0.393238
0.637359
0.163432
0.426301
0.802963
julia> cCS = CHOLMOD.c_CholmodSparse{eltype(S),Int}(S.m, S.n, colptr[end], conve
rt(Ptr{Int},colptr), convert(Ptr{Int},rowval), C_NULL, convert(Ptr{eltype(S)},nz
val), C_NULL, 0, CHOLMOD.CHOLMOD_LONG, CHOLMOD.CHOLMOD_REAL, CHOLMOD.CHOLMOD_DOU
BLE, 0, 1)
Base.LinAlg.CHOLMOD.c_CholmodSparse{Float64,Int64}(0x000000000000000a,0x00000000
0000000a,0x0000000000000009,Ptr{Int64} @0x0000000020f84f10,Ptr{Int64} @0x0000000
0212b2560,Ptr{Void} @0x0000000000000000,Ptr{Float64} @0x00000000212b28e0,Ptr{Voi
d} @0x0000000000000000,0,2,1,0,0,1)
julia> print_sparse(cCS, 5)
CHOLMOD sparse: : 10-by-10, nz 9, up/lo.
nzmax 9, unsorted, packed,
scalar types: SuiteSparse_long, real, double
col 0: nz 0 start 0 end 0:
col 1: nz 2 start 0 end 2:
5: 0.44093
8: 0.77351
col 2: nz 1 start 2 end 3:
7: 0.50223
col 3: nz 0 start 3 end 3:
col 4: nz 2 start 3 end 5:
0: 0.039207
2: 0.39324
col 5: nz 1 start 5 end 6:
2: 0.63736
col 6: nz 0 start 6 end 6:
col 7: nz 0 start 6 end 6:
col 8: nz 0 start 6 end 6:
col 9: nz 3 start 6 end 9:
4: 0.16343
5: 0.4263
7: 0.80296
nnz on diagonal: 0
OK
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment