Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 715 lines (591 sloc) 28.663 kb
a18880a @ViralBShah Rework sparse matmul to a simpler algorithm as per #942
ViralBShah authored
1 require("linalg_sparse.jl")
7346a78 @ViralBShah Move all the consts from linalg_suitesparse.jl to suitesparse_h.jl
ViralBShah authored
2 require("suitesparse_h.jl")
a18880a @ViralBShah Rework sparse matmul to a simpler algorithm as per #942
ViralBShah authored
3
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
4 const _jl_libsuitesparse_wrapper = dlopen("libsuitesparse_wrapper")
5 const _jl_libcholmod = dlopen("libcholmod")
6 const _jl_libumfpack = dlopen("libumfpack")
7 const _chm_aat = dlsym(_jl_libcholmod, :cholmod_aat)
8 const _chm_amd = dlsym(_jl_libcholmod, :cholmod_amd)
9 const _chm_analyze = dlsym(_jl_libcholmod, :cholmod_analyze)
10 const _chm_colamd = dlsym(_jl_libcholmod, :cholmod_colamd)
11 const _chm_copy = dlsym(_jl_libcholmod, :cholmod_copy)
12 const _chm_factorize = dlsym(_jl_libcholmod, :cholmod_factorize)
13 const _chm_free_dn = dlsym(_jl_libcholmod, :cholmod_free_dense)
14 const _chm_free_fa = dlsym(_jl_libcholmod, :cholmod_free_factor)
15 const _chm_free_sp = dlsym(_jl_libcholmod, :cholmod_free_sparse)
16 const _chm_print_dn = dlsym(_jl_libcholmod, :cholmod_print_dense)
17 const _chm_print_fa = dlsym(_jl_libcholmod, :cholmod_print_factor)
18 const _chm_print_sp = dlsym(_jl_libcholmod, :cholmod_print_sparse)
19 const _chm_solve = dlsym(_jl_libcholmod, :cholmod_solve)
20 const _chm_sort = dlsym(_jl_libcholmod, :cholmod_sort)
21 const _chm_submatrix = dlsym(_jl_libcholmod, :cholmod_submatrix)
b4554bd @mlubin Add destructive version of sparse lufact
mlubin authored
22
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
23 type MatrixIllConditionedException <: Exception end
b4554bd @mlubin Add destructive version of sparse lufact
mlubin authored
24
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
25 function _jl_convert_to_0_based_indexing!(S::SparseMatrixCSC)
26 for i=1:(S.colptr[end]-1); S.rowval[i] -= 1; end
27 for i=1:length(S.colptr); S.colptr[i] -= 1; end
28 return S
b4554bd @mlubin Add destructive version of sparse lufact
mlubin authored
29 end
30
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
31 function _jl_convert_to_1_based_indexing!(S::SparseMatrixCSC)
32 for i=1:length(S.colptr); S.colptr[i] += 1; end
33 for i=1:(S.colptr[end]-1); S.rowval[i] += 1; end
34 return S
613ba83 @ViralBShah Prepare to use CHOLMOD
ViralBShah authored
35 end
36
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
37 _jl_convert_to_0_based_indexing(S) = _jl_convert_to_0_based_indexing!(copy(S))
38 _jl_convert_to_1_based_indexing(S) = _jl_convert_to_1_based_indexing!(copy(S))
53c2d30 @mlubin Add opaque sparse LU factorization objects.
mlubin authored
39
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
40 ## CHOLMOD
53c2d30 @mlubin Add opaque sparse LU factorization objects.
mlubin authored
41
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
42 CHMVTypes = Union(Complex64, Complex128, Float32, Float64)
43 CHMITypes = Union(Int32, Int64)
613ba83 @ViralBShah Prepare to use CHOLMOD
ViralBShah authored
44
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
45 function chm_itype{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti})
46 if !(Ti<:CHMITypes) error("chm_itype: indtype(S) must be in CHMITypes") end
47 Ti == Int32 ? _jl_CHOLMOD_INT : _jl_CHOLMOD_LONG
48 end
49
50 function chm_xtype{T}(S::SparseMatrixCSC{T})
51 if !(T <: CHMVTypes) error("chm_xtype: eltype(S) must be in CHMVTypes") end
52 T <: Complex ? _JL_CHOLMOD_COMPLEX : _jl_CHOLMOD_REAL
53 end
54
55 function chm_dtype{T}(S::SparseMatrixCSC{T})
56 if !(T <: CHMVTypes) error("chm_dtype: eltype(S) must be in CHMVTypes") end
57 T <: Union(Float32, Complex64) ? _jl_CHOLMOD_SINGLE : _jl_CHOLMOD_DOUBLE
58 end
59
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
60 # Wrapper for memory allocated by CHOLMOD. Carry along the value and index types.
61 ## FIXME: CholmodPtr and UmfpackPtr should be amalgamated
62 type CholmodPtr{Tv<:CHMVTypes,Ti<:CHMITypes}
63 val::Vector{Ptr{Void}}
64 end
65
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
66 eltype{Tv,Ti}(P::CholmodPtr{Tv,Ti}) = Tv
67 indtype{Tv,Ti}(P::CholmodPtr{Tv,Ti}) = Ti
68
389a559 @dmbates clean up SuiteSparse interface
dmbates authored
69 function _jl_cholmod_common_finalizer(x::Vector{Ptr{Void}})
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
70 st = ccall(dlsym(_jl_libcholmod, :cholmod_finish), Int32, (Ptr{Void},), x[1])
71 if st != _jl_CHOLMOD_TRUE error("Error calling cholmod_finish") end
a15d6e9 @StefanKarpinski rename: _c_free => c_free.
StefanKarpinski authored
72 c_free(x[1])
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
73 end
74
75 type CholmodCommon
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
76 pt::Vector{Ptr{Void}}
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
77 function CholmodCommon()
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
78 pt = Array(Ptr{Void}, 1)
79 ccall(dlsym(_jl_libsuitesparse_wrapper, :jl_cholmod_common), Void,
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
80 (Ptr{Void},), pt)
81 st = ccall(dlsym(_jl_libcholmod, :cholmod_start), Int, (Ptr{Void}, ), pt[1])
82 if st != _jl_CHOLMOD_TRUE error("Error calling cholmod_start") end
389a559 @dmbates clean up SuiteSparse interface
dmbates authored
83 finalizer(pt, _jl_cholmod_common_finalizer)
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
84 new(pt)
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
85 end
86 end
87
88 function show(io, cm::CholmodCommon)
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
89 st = ccall(dlsym(_jl_libcholmod, :cholmod_print_common), Int32,
90 (Ptr{Uint8},Ptr{Void}), "", cm.pt[1])
91 if st != _jl_CHOLMOD_TRUE error("Error calling cholmod_print_common") end
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
92 end
93
94 type CholmodSparse{Tv<:CHMVTypes,Ti<:CHMITypes}
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
95 pt::CholmodPtr{Tv,Ti}
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
96 ## cp contains a copy of the original matrix but with 0-based indices
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
97 cp::SparseMatrixCSC{Tv,Ti}
98 stype::Int
99 cm::CholmodCommon
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
100 function CholmodSparse(S::SparseMatrixCSC{Tv,Ti}, stype::Int, cm::CholmodCommon)
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
101 pt = CholmodPtr{Tv,Ti}(Array(Ptr{Void}, 1))
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
102 cp = _jl_convert_to_0_based_indexing(S)
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
103
104 ccall(dlsym(_jl_libsuitesparse_wrapper, :jl_cholmod_sparse), Void,
105 (Ptr{Void}, Uint, Uint, Uint, Ptr{Void}, Ptr{Void}, Ptr{Void},
106 Ptr{Void}, Ptr{Void}, Int32, Int32, Int32, Int32, Int32, Int32),
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
107 pt.val, S.m, S.n, nnz(S), cp.colptr, cp.rowval, C_NULL,
108 cp.nzval, C_NULL, stype, chm_itype(S), chm_xtype(S), chm_dtype(S),
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
109 _jl_CHOLMOD_TRUE, _jl_CHOLMOD_TRUE)
a15d6e9 @StefanKarpinski rename: _c_free => c_free.
StefanKarpinski authored
110 finalizer(pt, x->c_free(x.val[1]))
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
111 new(pt, cp, int(stype), cm)
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
112 end
113 end
114
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
115 CholmodSparse{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti}, stype::Int) = CholmodSparse{Tv,Ti}(S, stype, CholmodCommon())
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
116
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
117 function CholmodSparse{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti}, cm::CholmodCommon)
118 stype = S.m == S.n && ishermitian(m)
119 CholmodSparse{Tv,Ti}(stype ? triu(S) : S, int(stype), cm)
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
120 end
121
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
122 CholmodSparse(S::SparseMatrixCSC) = CholmodSparse(S, CholmodCommon())
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
123
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
124 function show(io, cs::CholmodSparse)
125 ccall(_chm_print_sp,
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
126 Int32, (Ptr{Void}, Ptr{Uint8},Ptr{Void}), cs.pt.val[1], "", cs.cm.pt[1])
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
127 end
128
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
129 size(cs::CholmodSparse) = size(cs.cp)
130 nnz(cs::CholmodSparse) = cs.cp.colptr[end]
131 eltype{T}(cs::CholmodSparse{T}) = T
132 indtype{Tv,Ti}(cs::CholmodSparse{Tv,Ti}) = Ti
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
133
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
134 SparseMatrixCSC(cs::CholmodSparse) = _jl_convert_to_1_based_indexing(cs.cp)
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
135
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
136 ## For testing only. The infinity and 1 norms of a sparse matrix are simply
137 ## the same norm applied to its nzval field.
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
138 function norm(cs::CholmodSparse, p::Number)
8f07832 @dmbates Allow 32-bit and 64-bit CHOLMOD objects on 64-bit systems
dmbates authored
139 ccall(dlsym(_jl_libcholmod, :cholmod_norm_sparse), Float64,
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
140 (Ptr{Void}, Int32, Ptr{Void}), cs.pt.val[1], p == Inf ? 0 : 1, cs.cm.pt[1])
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
141 end
613ba83 @ViralBShah Prepare to use CHOLMOD
ViralBShah authored
142
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
143 norm(cs::CholmodSparse) = norm(cs, Inf)
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
144
145 ## Approximate minimal degree ordering
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
146 function chm_amd(cs::CholmodSparse)
8f07832 @dmbates Allow 32-bit and 64-bit CHOLMOD objects on 64-bit systems
dmbates authored
147 aa = Array(Int32, cs.cp.m)
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
148 st = cs.stype == 0 ? ccall(_chm_colamd, Int32,
8f07832 @dmbates Allow 32-bit and 64-bit CHOLMOD objects on 64-bit systems
dmbates authored
149 (Ptr{Void}, Ptr{Void}, Uint, Int32, Ptr{Int32}, Ptr{Void}),
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
150 cs.pt.val[1], C_NULL, 0, 1, aa, cs.cm.pt[1]) :
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
151 ccall(_chm_amd, Int32, (Ptr{Void}, Ptr{Void}, Uint, Ptr{Int32}, Ptr{Void}),
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
152 cs.pt.val[1], C_NULL, 0, aa, cs.cm.pt[1])
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
153 if st != _jl_CHOLMOD_TRUE error("Error in cholmod_amd") end
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
154 aa
155 end
156
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
157 type CholmodFactor{Tv<:CHMVTypes,Ti<:CHMITypes} <: Factorization{Tv}
158 pt::CholmodPtr{Tv,Ti}
159 cs::CholmodSparse{Tv,Ti}
160 function CholmodFactor(pt::CholmodPtr{Tv,Ti}, cs::CholmodSparse{Tv,Ti})
161 ff = new(pt, cs)
389a559 @dmbates clean up SuiteSparse interface
dmbates authored
162 finalizer(ff, _jl_cholmod_factor_finalizer)
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
163 ff
164 end
165 end
166
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
167 function _jl_cholmod_factor_finalizer(x::CholmodFactor)
168 if ccall(_chm_free_fa, Int32, (Ptr{Void}, Ptr{Void}), x.pt.val, x.cs.cm[1]) != _jl_CHOLMOD_TRUE
169 error("CHOLMOD error in cholmod_free_factor")
170 end
171 end
172
173 function size(F::CholmodFactor)
174 n = size(F.cs,1)
175 (n, n)
176 end
177
178 eltype{T}(F::CholmodFactor{T}) = T
179 indtype{Tv,Ti}(F::CholmodFactor{Tv,Ti}) = Ti
180
181 function CholmodFactor{Tv,Ti}(cs::CholmodSparse{Tv,Ti})
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
182 pt = CholmodPtr{Tv,Ti}(Array(Ptr{Void}, 1))
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
183 pt.val[1] = ccall(_chm_analyze, Ptr{Void},
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
184 (Ptr{Void}, Ptr{Void}), cs.pt.val[1], cs.cm.pt[1])
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
185 st = ccall(_chm_factorize, Int32,
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
186 (Ptr{Void}, Ptr{Void}, Ptr{Void}), cs.pt.val[1], pt.val[1], cs.cm.pt[1])
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
187 if st != _jl_CHOLMOD_TRUE error("CHOLMOD failure in factorize") end
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
188 CholmodFactor{Tv,Ti}(pt, cs)
189 end
190
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
191 function show(io, cf::CholmodFactor)
192 st = ccall(_chm_print_fa, Int32, (Ptr{Void}, Ptr{Uint8}, Ptr{Void}), cf.pt.val[1], "", cf.cs.cm.pt[1])
193 if st != _jl_CHOLMOD_TRUE error("Cholmod error in print_factor") end
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
194 end
195
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
196 type CholmodDense{T<:CHMVTypes}
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
197 pt::Vector{Ptr{Void}}
198 m::Int
199 n::Int
200 aa::VecOrMat{T} # original array
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
201 cm::CholmodCommon
202 end
203
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
204 function CholmodDense{T<:CHMVTypes}(b::VecOrMat{T}, cm::CholmodCommon)
205 m = size(b, 1)
206 n = isa(b, Matrix) ? size(b, 2) : 1
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
207
208 xtype = T <: Complex ? _jl_CHOLMOD_COMPLEX : _jl_CHOLMOD_REAL
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
209 dtype = T <: Float32 || T == Complex64 ? _jl_CHOLMOD_SINGLE : _jl_CHOLMOD_DOUBLE
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
210
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
211 pt = Array(Ptr{Void}, 1)
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
212
213 ccall(dlsym(_jl_libsuitesparse_wrapper, :jl_cholmod_dense), Void,
214 (Ptr{Void}, Uint, Uint, Uint, Uint, Ptr{Void}, Ptr{Void}, Int32, Int32),
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
215 pt, m, n, length(b), m, b, C_NULL, xtype, dtype)
a15d6e9 @StefanKarpinski rename: _c_free => c_free.
StefanKarpinski authored
216 finalizer(pt, x->c_free(pt[1]))
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
217 CholmodDense{T}(pt, m, n, copy(b), cm)
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
218 end
219
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
220 CholmodDense{T<:Integer}(B::VecOrMat{T}, cm::CholmodCommon) = CholmodDense(float64(B), cm)
221
222 size(cd::CholmodDense) = (cd.m, cd.n)
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
223
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
224 function show(io, cd::CholmodDense)
225 st = ccall(_chm_print_dn, Int32, (Ptr{Void},Ptr{Uint8},Ptr{Void}), cd.pt[1], "", cd.cm.pt[1])
226 if st != _jl_CHOLMOD_TRUE error("Cholmod error in print_dense") end
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
227 end
228
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
229 type CholmodDenseOut{Tv<:CHMVTypes,Ti<:CHMITypes}
230 pt::CholmodPtr{Tv,Ti}
231 m::Int
232 n::Int
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
233 cm::CholmodCommon
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
234 function CholmodDenseOut(pt::CholmodPtr{Tv,Ti}, m::Int, n::Int, cm::CholmodCommon)
235 dd = new(pt, m, n, cm)
389a559 @dmbates clean up SuiteSparse interface
dmbates authored
236 finalizer(dd, _jl_cholmod_denseout_finalizer)
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
237 dd
238 end
239 end
240
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
241 function _jl_cholmod_denseout_finalizer(cd::CholmodDenseOut)
242 st = ccall(_chm_free_dn, Int32, (Ptr{Void}, Ptr{Void}), cd.pt.val, cd.cm.pt[1])
243 if st != _jl_CHOLMOD_TRUE error("Error in cholmod_free_dense") end
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
244 end
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
245
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
246 eltype{T}(cdo::CholmodDenseOut{T}) = T
247 indtype{Tv,Ti}(cdo::CholmodDenseOut{Tv,Ti}) = Ti
248 size(cd::CholmodDenseOut) = (cd.m, cd.n)
249
250 function convert{T}(::Type{Array{T}}, cdo::CholmodDenseOut{T})
251 mm = Array(T, size(cdo))
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
252 ccall(dlsym(_jl_libsuitesparse_wrapper, :jl_cholmod_dense_copy_out), Void,
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
253 (Ptr{Void}, Ptr{T}), cdo.pt.val[1], mm)
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
254 mm
255 end
256
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
257 function solve{Tv,Ti}(cf::CholmodFactor{Tv,Ti}, B::CholmodDense{Tv}, solv::Integer)
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
258 m, n = size(B)
259 cdo = CholmodPtr{Tv,Ti}(Array(Ptr{Void},1))
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
260 cdo.val[1] = ccall(_chm_solve, Ptr{Void},
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
261 (Int32, Ptr{Void}, Ptr{Void}, Ptr{Void}),
262 solv, cf.pt.val[1], B.pt[1], cf.cs.cm.pt[1])
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
263 return cdo, m, n, cf.cs.cm
264 CholmodDenseOut(cdo, m, n, cf.cs.cm)
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
265 end
266
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
267 solve(cf::CholmodFactor, B::CholmodDense) = solve(cf, B, _jl_CHOLMOD_A)
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
268
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
269 (\){Tf,Tb}(cf::CholmodFactor{Tf}, b::VecOrMat{Tb}) = solve(cf, CholmodDense{Tf}(convert(Array{Tf},b), cf.cs.cm), _jl_CHOLMOD_A)
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
270
271 type CholmodSparseOut{Tv<:CHMVTypes,Ti<:CHMITypes}
272 pt::CholmodPtr{Tv,Ti}
273 m::Int
274 n::Int
275 cm::CholmodCommon
276 function CholmodSparseOut(pt::CholmodPtr{Tv,Ti}, m::Int, n::Int, cm::CholmodCommon)
277 cso = new(pt, m, n, cm)
389a559 @dmbates clean up SuiteSparse interface
dmbates authored
278 finalizer(cso, _jl_cholmod_sparseout_finalizer)
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
279 cso
280 end
281 end
282
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
283 function _jl_cholmod_sparseout_finalizer(cso::CholmodSparseOut)
284 st = ccall(_chm_free_sp, Int32,
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
285 (Ptr{Void}, Ptr{Void}), cso.pt.val, cso.cm.pt[1])
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
286 if st != _jl_CHOLMOD_TRUE error("Error in cholmod_free_sparse") end
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
287 end
288
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
289 function nnz(cso::CholmodSparseOut)
8f07832 @dmbates Allow 32-bit and 64-bit CHOLMOD objects on 64-bit systems
dmbates authored
290 ccall(dlsym(_jl_libcholmod, :cholmod_nnz), Int32,
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
291 (Ptr{Void}, Ptr{Void}), cso.pt.val[1], cso.cm.pt[1])
292 end
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
293 size(cso::CholmodSparseOut) = (cso.m, cso.n)
294 eltype{T}(cso::CholmodSparseOut{T}) = T
295 indtype{Tv,Ti}(cso::CholmodSparseOut{Tv,Ti}) = Ti
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
296
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
297 function solve{Tv,Ti}(cf::CholmodFactor{Tv,Ti}, B::CholmodSparse{Tv,Ti}, solv::Integer)
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
298 m, n = size(B)
299 cso = CholmodPtr{Tv,Ti}(Array(Ptr{Void},1))
8f07832 @dmbates Allow 32-bit and 64-bit CHOLMOD objects on 64-bit systems
dmbates authored
300 cso.val[1] = ccall(dlsym(_jl_libcholmod, :cholmod_spsolve), Ptr{Void},
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
301 (Int32, Ptr{Void}, Ptr{Void}, Ptr{Void}),
302 solv, cf.pt.val[1], B.pt[1], B.cm.pt[1])
303 CholmodSparseOut{Tv,Ti}(cso, m, n, cf.cs.cm)
304 end
305
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
306 function CholmodSparseOut{Tv,Ti}(cf::CholmodFactor{Tv,Ti})
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
307 n = size(cf.cs)[1]
308 cso = CholmodPtr{Tv,Ti}(Array(Ptr{Void},1))
8f07832 @dmbates Allow 32-bit and 64-bit CHOLMOD objects on 64-bit systems
dmbates authored
309 cso.val[1] = ccall(dlsym(_jl_libcholmod, :cholmod_factor_to_sparse), Ptr{Void},
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
310 (Ptr{Void}, Ptr{Void}), cf.pt.val[1], cf.cs.cm.pt[1])
4496c10 @dmbates Extend Cholmod* types and methods
dmbates authored
311 CholmodSparseOut{Tv,Ti}(cso, n, n, cf.cs.cm)
312 end
613ba83 @ViralBShah Prepare to use CHOLMOD
ViralBShah authored
313
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
314 function SparseMatrixCSC{Tv,Ti}(cso::CholmodSparseOut{Tv,Ti})
389a559 @dmbates clean up SuiteSparse interface
dmbates authored
315 nz = nnz(cso)
316 sp = SparseMatrixCSC{Tv,Ti}(cso.m, cso.n, Array(Ti, cso.n + 1), Array(Ti, nz), Array(Tv, nz))
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
317 st = ccall(dlsym(_jl_libsuitesparse_wrapper, :jl_cholmod_sparse_copy_out), Int32,
389a559 @dmbates clean up SuiteSparse interface
dmbates authored
318 (Ptr{Void}, Ptr{Ti}, Ptr{Ti}, Ptr{Tv}),
319 cso.pt.val[1], sp.colptr, sp.rowval, sp.nzval)
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
320 if st == 1 error("CholmodSparseOut object is not packed") end
321 if st == 2 error("CholmodSparseOut object is not sorted") end # Should not occur
322 if st == 3 error("CholmodSparseOut object has INTLONG itype") end
389a559 @dmbates clean up SuiteSparse interface
dmbates authored
323 _jl_convert_to_1_based_indexing!(sp)
324 end
325
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
326 function show(io, cso::CholmodSparseOut)
327 sp = ccall(_chm_print_sp, Int32, (Ptr{Void}, Ptr{Uint8},Ptr{Void}), cso.pt.val[1], "", cso.cm.pt[1])
328 if sp != _jl_CHOLMOD_TRUE error("Cholmod error in print_sparse") end
329 end
330
331 function chm_aat{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, symm::Bool)
332 cs = CholmodSparse(A, 0)
333 aa = CholmodPtr{Tv,Ti}(Array(Ptr{Void},1))
334 aa.val[1] = ccall(_chm_aat, Ptr{Void}, (Ptr{Void},Ptr{Int},Int32,Int32,Ptr{Void}),
335 cs.pt.val[1], C_NULL, 0, 1, cs.cm.pt[1])
336 if ccall(_chm_sort, Int32, (Ptr{Void}, Ptr{Void}), aa.val[1], cs.cm.pt[1]) != _jl_CHOLMOD_TRUE
337 error("Cholmod error in sort")
338 end
339 if symm
340 pt = ccall(_chm_copy, Ptr{Void}, (Ptr{Void}, Int32, Int32, Ptr{Void}),
341 aa.val[1], 1, 1, cs.cm.pt[1])
342 if ccall(_chm_free_sp, Int32, (Ptr{Void}, Ptr{Void}), aa.val, cs.cm.pt[1]) != _jl_CHOLMOD_TRUE
343 error("Cholmod error in free_sparse")
344 end
345 aa.val[1] = pt
346 end
347 m = size(A, 1)
348 CholmodSparseOut{Tv,Ti}(aa, m, m, cs.cm)
389a559 @dmbates clean up SuiteSparse interface
dmbates authored
349 end
350
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
351 chm_aat{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}) = chm_aat(A, false)
352
389a559 @dmbates clean up SuiteSparse interface
dmbates authored
353 ## call wrapper function to create cholmod_sparse objects
f385871 @ViralBShah wip: Introduce stype in cholmod_sparse objects.
ViralBShah authored
354 _jl_cholmod_sparse(S) = _jl_cholmod_sparse(S, 0)
355
356 function _jl_cholmod_sparse{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti}, stype::Int)
50b468d @ViralBShah Get basic CHOLMOD calling sequence to work.
ViralBShah authored
357 cs = Array(Ptr{Void}, 1)
358
613ba83 @ViralBShah Prepare to use CHOLMOD
ViralBShah authored
359 if Ti == Int32; itype = _jl_CHOLMOD_INT;
360 elseif Ti == Int64; itype = _jl_CHOLMOD_LONG; end
64f2f8e @ViralBShah Working sparse \
ViralBShah authored
361
613ba83 @ViralBShah Prepare to use CHOLMOD
ViralBShah authored
362 if Tv == Float64 || Tv == Float32; xtype = _jl_CHOLMOD_REAL;
363 elseif Tv == Complex128 || Tv == Complex64 ; xtype = _jl_CHOLMOD_COMPLEX; end
364
365 if Tv == Float64 || Tv == Complex128; dtype = _jl_CHOLMOD_DOUBLE;
366 elseif Tv == Float32 || Tv == Complex64 ; dtype = _jl_CHOLMOD_SINGLE; end
367
90beb8b @dmbates Use correct name of dlopen result.
dmbates authored
368 ccall(dlsym(_jl_libsuitesparse_wrapper, :jl_cholmod_sparse),
d27ebda @ViralBShah wip: CHOLMOD integration
ViralBShah authored
369 Ptr{Void},
9792554 @ViralBShah _jl_cholmod_transpose() now returns a julia sparse matrix.
ViralBShah authored
370 (Ptr{Void}, Int, Int, Int, Ptr{Void}, Ptr{Void}, Ptr{Void}, Ptr{Void}, Ptr{Void},
f385871 @ViralBShah wip: Introduce stype in cholmod_sparse objects.
ViralBShah authored
371 Int32, Int32, Int32, Int32, Int32, Int32),
9792554 @ViralBShah _jl_cholmod_transpose() now returns a julia sparse matrix.
ViralBShah authored
372 cs, int(S.m), int(S.n), int(length(S.nzval)), S.colptr, S.rowval, C_NULL, S.nzval, C_NULL,
59d3515 @ViralBShah Cholesky factorization of sparse matrix works. I had not understood
ViralBShah authored
373 int32(stype), itype, xtype, dtype, _jl_CHOLMOD_TRUE, _jl_CHOLMOD_TRUE
d27ebda @ViralBShah wip: CHOLMOD integration
ViralBShah authored
374 )
613ba83 @ViralBShah Prepare to use CHOLMOD
ViralBShah authored
375
376 return cs
377 end
378
f385871 @ViralBShah wip: Introduce stype in cholmod_sparse objects.
ViralBShah authored
379 ## Call wrapper function to create cholmod_dense objects
d95e95f @ViralBShah wip: Implement cholmod_dense objects for cholmod
ViralBShah authored
380 function _jl_cholmod_dense{T}(B::VecOrMat{T})
381 m = size(B, 1)
382 n = isa(B, Matrix) ? size(B, 2) : 1
383
384 cd = Array(Ptr{Void}, 1)
385
386 if T == Float64 || T == Float32; xtype = _jl_CHOLMOD_REAL;
387 elseif T == Complex128 || T == Complex64 ; xtype = _jl_CHOLMOD_COMPLEX; end
388
389 if T == Float64 || T == Complex128; dtype = _jl_CHOLMOD_DOUBLE;
390 elseif T == Float32 || T == Complex64 ; dtype = _jl_CHOLMOD_SINGLE; end
391
90beb8b @dmbates Use correct name of dlopen result.
dmbates authored
392 ccall(dlsym(_jl_libsuitesparse_wrapper, :jl_cholmod_dense),
d95e95f @ViralBShah wip: Implement cholmod_dense objects for cholmod
ViralBShah authored
393 Ptr{Void},
394 (Ptr{Void}, Int, Int, Int, Int, Ptr{T}, Ptr{Void}, Int32, Int32),
a378b75 @JeffBezanson ccall improvements for issue #132
JeffBezanson authored
395 cd, m, n, numel(B), m, B, C_NULL, xtype, dtype
d95e95f @ViralBShah wip: Implement cholmod_dense objects for cholmod
ViralBShah authored
396 )
397
398 return cd
50b468d @ViralBShah Get basic CHOLMOD calling sequence to work.
ViralBShah authored
399 end
400
2e047df @ViralBShah Copy result of sparse cholesky solve from cholmod_dense object to
ViralBShah authored
401 function _jl_cholmod_dense_copy_out{T}(x::Ptr{Void}, sol::VecOrMat{T})
90beb8b @dmbates Use correct name of dlopen result.
dmbates authored
402 ccall(dlsym(_jl_libsuitesparse_wrapper, :jl_cholmod_dense_copy_out),
2e047df @ViralBShah Copy result of sparse cholesky solve from cholmod_dense object to
ViralBShah authored
403 Void,
404 (Ptr{Void}, Ptr{T}),
405 x, sol
406 )
407 return sol
408 end
409
9792554 @ViralBShah _jl_cholmod_transpose() now returns a julia sparse matrix.
ViralBShah authored
410 function _jl_cholmod_transpose_unsym{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti}, cm::Array{Ptr{Void}, 1})
411 S_t = SparseMatrixCSC(Tv, S.n, S.m, nnz(S)+1)
412
50b468d @ViralBShah Get basic CHOLMOD calling sequence to work.
ViralBShah authored
413 # Allocate space for a cholmod_sparse object
414 cs = _jl_cholmod_sparse(S)
9792554 @ViralBShah _jl_cholmod_transpose() now returns a julia sparse matrix.
ViralBShah authored
415 cs_t = _jl_cholmod_sparse(S_t)
416
4496973 @ViralBShah Install various suitesparse libraries as individual libraries.
ViralBShah authored
417 status = ccall(dlsym(_jl_libcholmod, :cholmod_transpose_unsym),
9792554 @ViralBShah _jl_cholmod_transpose() now returns a julia sparse matrix.
ViralBShah authored
418 Int32,
419 (Ptr{Void}, Int32, Ptr{Int32}, Ptr{Int32}, Int32, Ptr{Void}, Ptr{Void}),
420 cs[1], int32(1), C_NULL, C_NULL, int32(-1), cs_t[1], cm[1]);
50b468d @ViralBShah Get basic CHOLMOD calling sequence to work.
ViralBShah authored
421
9792554 @ViralBShah _jl_cholmod_transpose() now returns a julia sparse matrix.
ViralBShah authored
422 # Deallocate space for cholmod_sparse objects
a15d6e9 @StefanKarpinski rename: _c_free => c_free.
StefanKarpinski authored
423 c_free(cs[1])
424 c_free(cs_t[1])
50b468d @ViralBShah Get basic CHOLMOD calling sequence to work.
ViralBShah authored
425
9792554 @ViralBShah _jl_cholmod_transpose() now returns a julia sparse matrix.
ViralBShah authored
426 return S_t
613ba83 @ViralBShah Prepare to use CHOLMOD
ViralBShah authored
427 end
428
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
429 function _jl_cholmod_analyze{Tv<:Union(Float64,Complex128), Ti<:CHMITypes}(cs::Array{Ptr{Void},1}, cm::Array{Ptr{Void},1})
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
430 ccall(_chm_analyze, Ptr{Void}, (Ptr{Void}, Ptr{Void}), cs[1], cm[1])
413509d @ViralBShah wip: wrappers for sparse cholesky solve
ViralBShah authored
431 end
432
7f03c72 @dmbates Julia types for CHOLMOD structs
dmbates authored
433 function _jl_cholmod_factorize{Tv<:Union(Float64,Complex128), Ti<:CHMITypes}(cs::Array{Ptr{Void},1}, cs_factor::Ptr{Void}, cm::Array{Ptr{Void},1})
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
434 st = ccall(_chm_factorize, Int32, (Ptr{Void}, Ptr{Void}, Ptr{Void}), cs[1], cs_factor, cm[1])
435 if st != _jl_CHOLMOD_TRUE error("CHOLMOD could not factorize the matrix") end
413509d @ViralBShah wip: wrappers for sparse cholesky solve
ViralBShah authored
436 end
437
d95e95f @ViralBShah wip: Implement cholmod_dense objects for cholmod
ViralBShah authored
438 function _jl_cholmod_solve(cs_factor::Ptr{Void}, cd_rhs::Array{Ptr{Void},1}, cm::Array{Ptr{Void},1})
6681db8 @dmbates Reorganize Cholmod* types.
dmbates authored
439 ccall(_chm_solve, Ptr{Void}, (Int32, Ptr{Void}, Ptr{Void}, Ptr{Void}),
440 _jl_CHOLMOD_A, cs_factor, cd_rhs[1], cm[1])
413509d @ViralBShah wip: wrappers for sparse cholesky solve
ViralBShah authored
441 end
442
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
443 ## UMFPACK
c6f822a @ViralBShah Finally tracked down all UMFPACK issues.
ViralBShah authored
444
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
445 # Wrapper for memory allocated by umfpack. Carry along the value and index types.
446 type UmfpackPtr{Tv<:Union(Float64,Complex128),Ti<:CHMITypes}
447 val::Vector{Ptr{Void}}
c6f822a @ViralBShah Finally tracked down all UMFPACK issues.
ViralBShah authored
448 end
449
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
450 type UmfpackLU{Tv<:Union(Float64,Complex128),Ti<:CHMITypes} <: Factorization{Tv}
451 numeric::UmfpackPtr{Tv,Ti}
452 mat::SparseMatrixCSC{Tv,Ti}
453 end
454
455 function show(io, f::UmfpackLU)
04f542d @StefanKarpinski @printf, @sprintf macros: new printf-like interface.
StefanKarpinski authored
456 @printf("UMFPACK LU Factorization of a %d-by-%d sparse matrix\n",
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
457 size(f.mat,1), size(f.mat,2))
458 println(f.numeric)
459 _jl_umfpack_report(f)
460 end
461
462 type UmfpackLUTrans{Tv<:Union(Float64,Complex128),Ti<:CHMITypes} <: Factorization{Tv}
463 numeric::UmfpackPtr{Tv,Ti}
464 mat::SparseMatrixCSC{Tv,Ti}
465 end
466
467 function show(io, f::UmfpackLUTrans)
04f542d @StefanKarpinski @printf, @sprintf macros: new printf-like interface.
StefanKarpinski authored
468 @printf("UMFPACK LU Factorization of a transposed %d-by-%d sparse matrix\n",
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
469 size(f.mat,1), size(f.mat,2))
470 println(f.numeric)
471 _jl_umfpack_report(f)
472 end
473
474 function UmfpackLU{Tv<:Union(Float64,Complex128),Ti<:CHMITypes}(S::SparseMatrixCSC{Tv,Ti})
475 Scopy = copy(S)
476 Scopy = _jl_convert_to_0_based_indexing!(Scopy)
477 numeric = []
478
479 try
480 symbolic = _jl_umfpack_symbolic(Scopy)
481 numeric = _jl_umfpack_numeric(Scopy, symbolic)
482 catch e
483 if is(e,MatrixIllConditionedException)
484 error("Input matrix is ill conditioned or singular");
485 else
486 error("Error calling UMFPACK")
487 end
488 end
489
490 return UmfpackLU(numeric,Scopy)
491 end
492
493 function UmfpackLU!{Tv<:Union(Float64,Complex128),Ti<:CHMITypes}(S::SparseMatrixCSC{Tv,Ti})
494 Sshallow = SparseMatrixCSC(S.m,S.n,S.colptr,S.rowval,S.nzval)
495 Sshallow = _jl_convert_to_0_based_indexing!(Sshallow)
496 numeric = []
497
498 try
499 symbolic = _jl_umfpack_symbolic(Sshallow)
500 numeric = _jl_umfpack_numeric(Sshallow, symbolic)
501 catch e
502 Sshallow = _jl_convert_to_1_based_indexing!(Sshallow)
503 if is(e,MatrixIllConditionedException)
504 error("Input matrix is ill conditioned or singular");
505 else
506 error("Error calling UMFPACK")
507 end
508 end
509
510 S.rowval = []
511 S.nzval = []
512 S.colptr = ones(S.n+1)
513
514 return UmfpackLU(numeric,Sshallow)
515 end
516
517 function UmfpackLUTrans(S::SparseMatrixCSC)
518 x = UmfpackLU(S)
519 return UmfpackLUTrans(x.numeric, x.mat)
c6f822a @ViralBShah Finally tracked down all UMFPACK issues.
ViralBShah authored
520 end
521
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
522 # Solve with Factorization
523
524 (\){T}(fact::UmfpackLU{T}, b::Vector) = fact \ convert(Array{T,1}, b)
525 (\){T}(fact::UmfpackLU{T}, b::Vector{T}) = _jl_umfpack_solve(fact.mat,b,fact.numeric)
526
527 (\){T}(fact::UmfpackLUTrans{T}, b::Vector) = fact \ convert(Array{T,1}, b)
528 (\){T}(fact::UmfpackLUTrans{T}, b::Vector{T}) = _jl_umfpack_transpose_solve(fact.mat,b,fact.numeric)
529
530 ctranspose(fact::UmfpackLU) = UmfpackLUTrans(fact.numeric, fact.mat)
531
532 # Solve directly with matrix
533
534 (\)(S::SparseMatrixCSC, b::Vector) = UmfpackLU(S) \ b
535 At_ldiv_B(S::SparseMatrixCSC, b::Vector) = UmfpackLUTrans(S) \ b
536 Ac_ldiv_B(S::SparseMatrixCSC, b::Vector) = UmfpackLUTrans(S) \ b
537
c6f822a @ViralBShah Finally tracked down all UMFPACK issues.
ViralBShah authored
538 ## Wrappers around UMFPACK routines
64f2f8e @ViralBShah Working sparse \
ViralBShah authored
539
0a29305 @JeffBezanson replacing more function-generating macros
JeffBezanson authored
540 for (f_sym_r, f_sym_c, inttype) in
541 (("umfpack_di_symbolic","umfpack_zi_symbolic",:Int32),
542 ("umfpack_dl_symbolic","umfpack_zl_symbolic",:Int64))
543 @eval begin
c45f746 @ViralBShah Allow S and b to have different nz types in sparse S \ b
ViralBShah authored
544
b62331a @ViralBShah Complex sparse \
ViralBShah authored
545 function _jl_umfpack_symbolic{Tv<:Float64,Ti<:$inttype}(S::SparseMatrixCSC{Tv,Ti})
4865eb0 @ViralBShah Sparse matrices can use Int32 or Int64 indices. The default is to use In...
ViralBShah authored
546 # Pointer to store the symbolic factorization returned by UMFPACK
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
547 Symbolic = UmfpackPtr{Tv,Ti}(Array(Ptr{Void},1))
4496973 @ViralBShah Install various suitesparse libraries as individual libraries.
ViralBShah authored
548 status = ccall(dlsym(_jl_libumfpack, $f_sym_r),
4865eb0 @ViralBShah Sparse matrices can use Int32 or Int64 indices. The default is to use In...
ViralBShah authored
549 Ti,
c0d0faf @ViralBShah Make sparse linear algebra part of the default build, and make
ViralBShah authored
550 (Ti, Ti,
551 Ptr{Ti}, Ptr{Ti}, Ptr{Float64}, Ptr{Void}, Ptr{Float64}, Ptr{Float64}),
a378b75 @JeffBezanson ccall improvements for issue #132
JeffBezanson authored
552 S.m, S.n,
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
553 S.colptr, S.rowval, S.nzval, Symbolic.val, C_NULL, C_NULL)
554 if status != _jl_UMFPACK_OK; error("Error in symbolic factorization"); end
555 finalizer(Symbolic,_jl_umfpack_free_symbolic)
4865eb0 @ViralBShah Sparse matrices can use Int32 or Int64 indices. The default is to use In...
ViralBShah authored
556 return Symbolic
557 end
64f2f8e @ViralBShah Working sparse \
ViralBShah authored
558
b62331a @ViralBShah Complex sparse \
ViralBShah authored
559 function _jl_umfpack_symbolic{Tv<:Complex128,Ti<:$inttype}(S::SparseMatrixCSC{Tv,Ti})
560 # Pointer to store the symbolic factorization returned by UMFPACK
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
561 Symbolic = UmfpackPtr{Tv,Ti}(Array(Ptr{Void},1))
4496973 @ViralBShah Install various suitesparse libraries as individual libraries.
ViralBShah authored
562 status = ccall(dlsym(_jl_libumfpack, $f_sym_c),
b62331a @ViralBShah Complex sparse \
ViralBShah authored
563 Ti,
c0d0faf @ViralBShah Make sparse linear algebra part of the default build, and make
ViralBShah authored
564 (Ti, Ti,
565 Ptr{Ti}, Ptr{Ti}, Ptr{Float64}, Ptr{Float64}, Ptr{Void},
566 Ptr{Float64}, Ptr{Float64}),
a378b75 @JeffBezanson ccall improvements for issue #132
JeffBezanson authored
567 S.m, S.n,
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
568 S.colptr, S.rowval, real(S.nzval), imag(S.nzval), Symbolic.val,
c0d0faf @ViralBShah Make sparse linear algebra part of the default build, and make
ViralBShah authored
569 C_NULL, C_NULL)
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
570 if status != _jl_UMFPACK_OK; error("Error in symbolic factorization"); end
571 finalizer(Symbolic,_jl_umfpack_free_symbolic) # Check: do we need to free if there was an error?
b62331a @ViralBShah Complex sparse \
ViralBShah authored
572 return Symbolic
573 end
574
575 end
576 end
577
0a29305 @JeffBezanson replacing more function-generating macros
JeffBezanson authored
578 for (f_num_r, f_num_c, inttype) in
579 (("umfpack_di_numeric","umfpack_zi_numeric",:Int32),
580 ("umfpack_dl_numeric","umfpack_zl_numeric",:Int64))
581 @eval begin
b62331a @ViralBShah Complex sparse \
ViralBShah authored
582
583 function _jl_umfpack_numeric{Tv<:Float64,Ti<:$inttype}(S::SparseMatrixCSC{Tv,Ti}, Symbolic)
4865eb0 @ViralBShah Sparse matrices can use Int32 or Int64 indices. The default is to use In...
ViralBShah authored
584 # Pointer to store the numeric factorization returned by UMFPACK
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
585 Numeric = UmfpackPtr{Tv,Ti}(Array(Ptr{Void},1))
4496973 @ViralBShah Install various suitesparse libraries as individual libraries.
ViralBShah authored
586 status = ccall(dlsym(_jl_libumfpack, $f_num_r),
4865eb0 @ViralBShah Sparse matrices can use Int32 or Int64 indices. The default is to use In...
ViralBShah authored
587 Ti,
c0d0faf @ViralBShah Make sparse linear algebra part of the default build, and make
ViralBShah authored
588 (Ptr{Ti}, Ptr{Ti}, Ptr{Float64}, Ptr{Void}, Ptr{Void},
589 Ptr{Float64}, Ptr{Float64}),
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
590 S.colptr, S.rowval, S.nzval, Symbolic.val[1], Numeric.val,
c0d0faf @ViralBShah Make sparse linear algebra part of the default build, and make
ViralBShah authored
591 C_NULL, C_NULL)
4b1de4d @ViralBShah Fix some issues with building sparse matrices
ViralBShah authored
592 if status > 0; throw(MatrixIllConditionedException); end
b62331a @ViralBShah Complex sparse \
ViralBShah authored
593 if status != _jl_UMFPACK_OK; error("Error in numeric factorization"); end
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
594 finalizer(Numeric,_jl_umfpack_free_numeric)
b62331a @ViralBShah Complex sparse \
ViralBShah authored
595 return Numeric
596 end
597
598 function _jl_umfpack_numeric{Tv<:Complex128,Ti<:$inttype}(S::SparseMatrixCSC{Tv,Ti}, Symbolic)
599 # Pointer to store the numeric factorization returned by UMFPACK
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
600 Numeric = UmfpackPtr{Tv,Ti}(Array(Ptr{Void},1))
4496973 @ViralBShah Install various suitesparse libraries as individual libraries.
ViralBShah authored
601 status = ccall(dlsym(_jl_libumfpack, $f_num_c),
b62331a @ViralBShah Complex sparse \
ViralBShah authored
602 Ti,
c0d0faf @ViralBShah Make sparse linear algebra part of the default build, and make
ViralBShah authored
603 (Ptr{Ti}, Ptr{Ti}, Ptr{Float64}, Ptr{Float64}, Ptr{Void}, Ptr{Void},
604 Ptr{Float64}, Ptr{Float64}),
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
605 S.colptr, S.rowval, real(S.nzval), imag(S.nzval), Symbolic.val[1], Numeric.val,
c0d0faf @ViralBShah Make sparse linear algebra part of the default build, and make
ViralBShah authored
606 C_NULL, C_NULL)
4b1de4d @ViralBShah Fix some issues with building sparse matrices
ViralBShah authored
607 if status > 0; throw(MatrixIllConditionedException); end
b62331a @ViralBShah Complex sparse \
ViralBShah authored
608 if status != _jl_UMFPACK_OK; error("Error in numeric factorization"); end
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
609 finalizer(Numeric,_jl_umfpack_free_numeric)
4865eb0 @ViralBShah Sparse matrices can use Int32 or Int64 indices. The default is to use In...
ViralBShah authored
610 return Numeric
611 end
64f2f8e @ViralBShah Working sparse \
ViralBShah authored
612
b62331a @ViralBShah Complex sparse \
ViralBShah authored
613 end
614 end
615
0a29305 @JeffBezanson replacing more function-generating macros
JeffBezanson authored
616 for (f_sol_r, f_sol_c, inttype) in
617 (("umfpack_di_solve","umfpack_zi_solve",:Int32),
618 ("umfpack_dl_solve","umfpack_zl_solve",:Int64))
619 @eval begin
b62331a @ViralBShah Complex sparse \
ViralBShah authored
620
c0d0faf @ViralBShah Make sparse linear algebra part of the default build, and make
ViralBShah authored
621 function _jl_umfpack_solve{Tv<:Float64,Ti<:$inttype}(S::SparseMatrixCSC{Tv,Ti},
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
622 b::Vector{Tv}, Numeric::UmfpackPtr{Tv,Ti})
4865eb0 @ViralBShah Sparse matrices can use Int32 or Int64 indices. The default is to use In...
ViralBShah authored
623 x = similar(b)
4496973 @ViralBShah Install various suitesparse libraries as individual libraries.
ViralBShah authored
624 status = ccall(dlsym(_jl_libumfpack, $f_sol_r),
4865eb0 @ViralBShah Sparse matrices can use Int32 or Int64 indices. The default is to use In...
ViralBShah authored
625 Ti,
c0d0faf @ViralBShah Make sparse linear algebra part of the default build, and make
ViralBShah authored
626 (Ti, Ptr{Ti}, Ptr{Ti}, Ptr{Float64},
627 Ptr{Float64}, Ptr{Float64}, Ptr{Void}, Ptr{Float64}, Ptr{Float64}),
a378b75 @JeffBezanson ccall improvements for issue #132
JeffBezanson authored
628 _jl_UMFPACK_A, S.colptr, S.rowval, S.nzval,
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
629 x, b, Numeric.val[1], C_NULL, C_NULL)
b62331a @ViralBShah Complex sparse \
ViralBShah authored
630 if status != _jl_UMFPACK_OK; error("Error in solve"); end
4865eb0 @ViralBShah Sparse matrices can use Int32 or Int64 indices. The default is to use In...
ViralBShah authored
631 return x
632 end
8ef61a2 @ViralBShah Free memory from UMFPACK solves.
ViralBShah authored
633
c0d0faf @ViralBShah Make sparse linear algebra part of the default build, and make
ViralBShah authored
634 function _jl_umfpack_solve{Tv<:Complex128,Ti<:$inttype}(S::SparseMatrixCSC{Tv,Ti},
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
635 b::Vector{Tv}, Numeric::UmfpackPtr{Tv,Ti})
b62331a @ViralBShah Complex sparse \
ViralBShah authored
636 xr = similar(b, Float64)
637 xi = similar(b, Float64)
4496973 @ViralBShah Install various suitesparse libraries as individual libraries.
ViralBShah authored
638 status = ccall(dlsym(_jl_libumfpack, $f_sol_c),
b62331a @ViralBShah Complex sparse \
ViralBShah authored
639 Ti,
c0d0faf @ViralBShah Make sparse linear algebra part of the default build, and make
ViralBShah authored
640 (Ti, Ptr{Ti}, Ptr{Ti}, Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, Ptr{Float64},
641 Ptr{Float64}, Ptr{Float64}, Ptr{Void}, Ptr{Float64}, Ptr{Float64}),
a378b75 @JeffBezanson ccall improvements for issue #132
JeffBezanson authored
642 _jl_UMFPACK_A, S.colptr, S.rowval, real(S.nzval), imag(S.nzval),
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
643 xr, xi, real(b), imag(b), Numeric.val[1], C_NULL, C_NULL)
b62331a @ViralBShah Complex sparse \
ViralBShah authored
644 if status != _jl_UMFPACK_OK; error("Error in solve"); end
645 return complex(xr,xi)
646 end
647
53c2d30 @mlubin Add opaque sparse LU factorization objects.
mlubin authored
648 function _jl_umfpack_transpose_solve{Tv<:Float64,Ti<:$inttype}(S::SparseMatrixCSC{Tv,Ti},
649 b::Vector{Tv}, Numeric::UmfpackPtr{Tv,Ti})
650 x = similar(b)
651 status = ccall(dlsym(_jl_libumfpack, $f_sol_r),
652 Ti,
653 (Ti, Ptr{Ti}, Ptr{Ti}, Ptr{Float64},
654 Ptr{Float64}, Ptr{Float64}, Ptr{Void}, Ptr{Float64}, Ptr{Float64}),
655 _jl_UMFPACK_At, S.colptr, S.rowval, S.nzval,
656 x, b, Numeric.val[1], C_NULL, C_NULL)
657 if status != _jl_UMFPACK_OK; error("Error in solve"); end
658 return x
659 end
660
661 function _jl_umfpack_transpose_solve{Tv<:Complex128,Ti<:$inttype}(S::SparseMatrixCSC{Tv,Ti},
662 b::Vector{Tv}, Numeric::UmfpackPtr{Tv,Ti})
663 xr = similar(b, Float64)
664 xi = similar(b, Float64)
665 status = ccall(dlsym(_jl_libumfpack, $f_sol_c),
666 Ti,
667 (Ti, Ptr{Ti}, Ptr{Ti}, Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, Ptr{Float64},
668 Ptr{Float64}, Ptr{Float64}, Ptr{Void}, Ptr{Float64}, Ptr{Float64}),
669 _jl_UMFPACK_At, S.colptr, S.rowval, real(S.nzval), imag(S.nzval),
670 xr, xi, real(b), imag(b), Numeric.val[1], C_NULL, C_NULL)
671 if status != _jl_UMFPACK_OK; error("Error in solve"); end
672 return complex(xr,xi)
673 end
674
b62331a @ViralBShah Complex sparse \
ViralBShah authored
675 end
676 end
677
6e8088d @ViralBShah show(S::SparseLU) shows the UMFPACK analysis of the factorization.
ViralBShah authored
678 for (f_report, elty, inttype) in
679 (("umfpack_di_report_numeric", :Float64, :Int32),
680 ("umfpack_zi_report_numeric", :Complex128, :Int32),
681 ("umfpack_dl_report_numeric", :Float64, :Int64),
682 ("umfpack_zl_report_numeric", :Complex128, :Int64))
683 @eval begin
684
d29209e @ViralBShah Re-enable sparse tests
ViralBShah authored
685 function _jl_umfpack_report{Tv<:$elty,Ti<:$inttype}(slu::UmfpackLU{Tv,Ti})
6e8088d @ViralBShah show(S::SparseLU) shows the UMFPACK analysis of the factorization.
ViralBShah authored
686
687 control = zeros(Float64, _jl_UMFPACK_CONTROL)
688 control[_jl_UMFPACK_PRL] = 4
689
690 ccall(dlsym(_jl_libumfpack, $f_report),
691 Ti,
692 (Ptr{Void}, Ptr{Float64}),
693 slu.numeric.val[1], control)
694 end
695
696 end
697 end
698
699
0a29305 @JeffBezanson replacing more function-generating macros
JeffBezanson authored
700 for (f_symfree, f_numfree, elty, inttype) in
701 (("umfpack_di_free_symbolic","umfpack_di_free_numeric",:Float64,:Int32),
702 ("umfpack_zi_free_symbolic","umfpack_zi_free_numeric",:Complex128,:Int32),
703 ("umfpack_dl_free_symbolic","umfpack_dl_free_numeric",:Float64,:Int64),
704 ("umfpack_zl_free_symbolic","umfpack_zl_free_numeric",:Complex128,:Int64))
705 @eval begin
b62331a @ViralBShah Complex sparse \
ViralBShah authored
706
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
707 _jl_umfpack_free_symbolic{Tv<:$elty,Ti<:$inttype}(Symbolic::UmfpackPtr{Tv,Ti}) =
708 ccall(dlsym(_jl_libumfpack, $f_symfree), Void, (Ptr{Void},), Symbolic.val)
4865eb0 @ViralBShah Sparse matrices can use Int32 or Int64 indices. The default is to use In...
ViralBShah authored
709
8e047d3 @mlubin Reorganization of how memory allocated by umfpack is handled.
mlubin authored
710 _jl_umfpack_free_numeric{Tv<:$elty,Ti<:$inttype}(Numeric::UmfpackPtr{Tv,Ti}) =
711 ccall(dlsym(_jl_libumfpack, $f_numfree), Void, (Ptr{Void},), Numeric.val)
4865eb0 @ViralBShah Sparse matrices can use Int32 or Int64 indices. The default is to use In...
ViralBShah authored
712
b62331a @ViralBShah Complex sparse \
ViralBShah authored
713 end
714 end
Something went wrong with that request. Please try again.