Skip to content

Commit

Permalink
Working sparse \
Browse files Browse the repository at this point in the history
  • Loading branch information
ViralBShah committed Dec 25, 2011
1 parent 9a92dac commit 64f2f8e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
4 changes: 2 additions & 2 deletions external/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ $(SUITESPARSE_OBJ_TARGET): SuiteSparse-$(SUITESPARSE_VER)/Makefile
cd SuiteSparse-$(SUITESPARSE_VER) && \
$(MAKE) && \
mkdir -p lib && \
cp `find . -name *.a` lib && cd lib && \
cp `find UMFPACK CHOLMOD *AMD BTF -name *.a` lib && cd lib && \
for i in *.a; do ar x $$i; done && \
g++ -shared -fPIC *.o -o libSuiteSparse.$(SHLIB_EXT) $(EXTROOTLIB)/libLAPACK.$(SHLIB_EXT) && \
gcc -shared -fPIC *.o -o libSuiteSparse.$(SHLIB_EXT) $(EXTROOTLIB)/libLAPACK.$(SHLIB_EXT) && \
cp libSuiteSparse.$(SHLIB_EXT) $(EXTROOTLIB)
touch $@

Expand Down
60 changes: 60 additions & 0 deletions j/linalg_suitesparse.j
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
_jl_libSuiteSparse = dlopen("libSuiteSparse")

const _jl_UMFPACK_A = int64(0) # Ax=b
const _jl_UMFPACK_At = int64(1) # A'x=b
const _jl_UMFPACK_Aat = int64(2) # A.'x=b
const _jl_UMFPACK_Pt_L = int64(3) # P'Lx=b
const _jl_UMFPACK_L = int64(4) # Lx=b
const _jl_UMFPACK_Lt_P = int64(5) # L'Px=b
const _jl_UMFPACK_Lat_P = int64(6) # L.'Px=b
const _jl_UMFPACK_Lt = int64(7) # L'x=b
const _jl_UMFPACK_Lat = int64(8) # L.'x=b
const _jl_UMFPACK_U_Qt = int64(9) # UQ'x=b
const _jl_UMFPACK_U = int64(10) # Ux=b
const _jl_UMFPACK_Q_Ut = int64(11) # QU'x=b
const _jl_UMFPACK_Q_Uat = int64(12) # QU.'x=b
const _jl_UMFPACK_Ut = int64(13) # U'x=b
const _jl_UMFPACK_Uat = int64(14) # U.'x=b

function _jl_umfpack_dl_symbolic(S::SparseMatrixCSC)
Symbolic = pointer([0])
ccall(dlsym(_jl_libSuiteSparse, :umfpack_dl_symbolic),
Int,
(Int, Int, Ptr{Int}, Ptr{Int}, Ptr{Float64}, Ptr{Void}, Ptr{Void}, Ptr{Void}),
S.m, S.n, S.colptr, S.rowval, S.nzval, Symbolic, C_NULL, C_NULL)
return Symbolic
end

function _jl_umfpack_dl_numeric(S::SparseMatrixCSC, Symbolic::Ptr)
Numeric = pointer([0])
ccall(dlsym(_jl_libSuiteSparse, :umfpack_dl_numeric),
Int,
(Ptr{Int}, Ptr{Int}, Ptr{Float64}, Ptr{Void}, Ptr{Void}, Ptr{Void}, Ptr{Void}),
S.colptr, S.rowval, S.nzval, Symbolic, Numeric, C_NULL, C_NULL)
return Numeric
end

function _jl_umfpack_dl_solve(S::SparseMatrixCSC, b::Vector, Numeric::Ptr)
x = similar(b)
ccall(dlsym(_jl_libSuiteSparse, :umfpack_dl_solve),
Int,
(Int, Ptr{Int}, Ptr{Int}, Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, Ptr{Void}, Ptr{Void}, Ptr{Void}),
_jl_UMFPACK_A, S.colptr, S.rowval, S.nzval, x, b, Numeric, C_NULL, C_NULL)
return b
end

_jl_umfpack_dl_free_symbolic(Symbolic::Ptr) =
ccall(dlsym(_jl_libSuiteSparse, :umfpack_dl_free_symbolic), Void, (Ptr{Void},), Symbolic)

_jl_umfpack_dl_free_numeric(Numeric::Ptr) =
ccall(dlsym(_jl_libSuiteSparse, :umfpack_dl_free_numeric), Void, (Ptr{Void},), Numeric)

function (\)(S::SparseMatrixCSC, b::Vector)
symbolic = _jl_umfpack_dl_symbolic(S)
numeric = _jl_umfpack_dl_numeric(S, symbolic)
_jl_umfpack_dl_free_symbolic(symbolic)
x = _jl_umfpack_dl_solve(S, b, numeric)
_jl_umfpack_dl_free_numeric(numeric)

return x
end
6 changes: 3 additions & 3 deletions j/sparse.j
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Compressed sparse columns data structure
# Assumes that no zeros are stored in the data structure
type SparseMatrixCSC{T,T_int} <: AbstractMatrix{T}
m::Int # Number of rows
n::Int # Number of columns
colptr::Vector{Int} # Column i is in colptr[i]:(colptr[i+1]-1)
m::Int # Number of rows
n::Int # Number of columns
colptr::Vector{Int} # Column i is in colptr[i]:(colptr[i+1]-1)
rowval::Vector{T_int} # Row values of nonzeros
nzval::Vector{T} # Nonzero values
end
Expand Down

0 comments on commit 64f2f8e

Please sign in to comment.