Skip to content

Instantly share code, notes, and snippets.

@tkelman
Created December 2, 2014 22:35
Show Gist options
  • Select an option

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

Select an option

Save tkelman/fd94ae290db6ede5178d to your computer and use it in GitHub Desktop.
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "help()" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.4.0-dev+1914 (2014-12-02 11:07 UTC)
_/ |\__'_|_|_|\__'_| | (detached from acroy/cholmod)/dd2c6a3* (fork: 6 commit
s, 1 day)
|__/ | i686-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 11 Float64 entries:
[2 , 1] = 0.891829
[4 , 1] = 0.889445
[6 , 2] = 0.892188
[7 , 2] = 0.583762
[2 , 3] = 0.46573
[4 , 4] = 0.901548
[8 , 6] = 0.140028
[3 , 7] = 0.974316
[1 , 8] = 0.665734
[3 , 8] = 0.0608261
[8 , 8] = 0.479401
julia> colptr = copy(S.colptr)-1
11-element Array{Int32,1}:
0
2
4
5
6
6
7
8
11
11
11
julia> rowval = copy(S.rowval)-1
11-element Array{Int32,1}:
1
3
5
6
1
3
7
2
0
2
7
julia> nzval = copy(S.nzval)
11-element Array{Float64,1}:
0.891829
0.889445
0.892188
0.583762
0.46573
0.901548
0.140028
0.974316
0.665734
0.0608261
0.479401
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,Int32}(0x0000000a,0x0000000a,0x00000
00b,Ptr{Int32} @0x147fe700,Ptr{Int32} @0x15185990,Ptr{Void} @0x00000000,Ptr{Floa
t64} @0x14d35cd0,Ptr{Void} @0x00000000,0,2,1,0,0,1)
julia> print_sparse(cCS, 5)
CHOLMOD sparse: : 10-by-10, nz 11, up/lo.
nzmax 11, unsorted, packed,
scalar types: SuiteSparse_long, real, double
CHOLMOD ERROR: sparse: : integer and real type must match routine
CHOLMOD error: invalid
0
julia> CHOLMOD.CholmodSparse(S)
CHOLMOD sparse: : 10-by-10, nz 11, up/lo.
nzmax 11, sorted, packed,
scalar types: int, real, double
col 0: nz 2 start 0 end 2:
1: 0.89183
3: 0.88944
col 1: nz 2 start 2 end 4:
5: 0.89219
6: 0.58376
col 2: nz 1 start 4 end 5:
1: 0.46573
...
col 9: nz 0 start 11 end 11:
nnz on diagonal: 2
OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment