Skip to content
Browse files

Trim unused C functions, comment out show() calls in tests

  • Loading branch information...
1 parent 3e16bb5 commit cecd879dc407ac3b6caba7da68e85705f8058d46 @dmbates dmbates committed
Showing with 13 additions and 139 deletions.
  1. +0 −125 deps/SuiteSparse_wrapper.c
  2. +13 −14 test/suitesparse.jl
View
125 deps/SuiteSparse_wrapper.c
@@ -26,128 +26,3 @@ extern void jl_cholmod_common_offsets(size_t *vv) {
vv[17] = offsetof(cholmod_common, itype);
vv[18] = offsetof(cholmod_common, dtype);
}
-
-extern void
-jl_cholmod_common(void **cm)
-{
- cholmod_common *c = (cholmod_common *) malloc (sizeof(cholmod_common));
- *cm = c;
-}
-
-extern void
-jl_cholmod_dense( void **cd, /* Store return value in here */
- size_t nrow, /* the matrix is nrow-by-ncol */
- size_t ncol,
- size_t nzmax, /* maximum number of entries in the matrix */
- size_t d, /* leading dimension (d >= nrow must hold) */
- void *x, /* size nzmax or 2*nzmax, if present */
- void *z, /* size nzmax, if present */
- int xtype, /* pattern, real, complex, or zomplex */
- int dtype /* x and z double or float */
- )
-{
- cholmod_dense *mat = (cholmod_dense *) malloc (sizeof(cholmod_dense));
- mat->nrow = nrow;
- mat->ncol = ncol;
- mat->nzmax = nzmax;
- mat->d = d;
- mat->x = x;
- mat->z = z;
- mat->xtype = xtype;
- mat->dtype = dtype;
-
- *cd = mat;
-}
-
-extern void
-jl_cholmod_dense_copy_out(cholmod_dense *cd,
- void *p
- )
-{
- size_t elsize = (cd->xtype == CHOLMOD_COMPLEX ? 2 : 1) *
- (cd->dtype == CHOLMOD_DOUBLE ? sizeof(double) : sizeof(float));
-
- memcpy(p, cd->x, cd->nzmax*elsize);
-}
-
-extern void
-jl_cholmod_sparse( void **cs, /* Store return value in here */
- size_t nrow, /* # of rows of A */
- size_t ncol, /* # of columns of A */
- size_t nzmax, /* max # of nonzeros of A */
- void *p, /* p [0..ncol], the column pointers */
- void *i, /* i [0..nzmax-1], the row indices */
- void *nz, /* nz [0..ncol-1], the # of nonzeros in each col if unpacked */
- void *x, /* size nzmax or 2*nzmax, if present */
- void *z, /* size nzmax, if present */
- int stype, /* 0: matrix is unsymmetric and possibly rectangular
- >0: matrix is square and upper triangular
- <0: matrix is square and lower triangular
- */
- int itype, /* CHOLMOD_INT: p, i, and nz are int.
- * CHOLMOD_INTLONG: p is UF_long, i and nz are int.
- * CHOLMOD_LONG: p, i, and nz are UF_long. */
- int xtype, /* pattern, real, complex, or zomplex */
- int dtype, /* x and z are double or float */
- int sorted, /* TRUE if columns are sorted, FALSE otherwise */
- int packed /* TRUE if packed (nz ignored), FALSE if unpacked
- * (nz is required) */
-)
-{
- cholmod_sparse *s = (cholmod_sparse *) malloc (sizeof(cholmod_sparse));
- s->nrow = nrow;
- s->ncol = ncol;
- s->nzmax = nzmax;
- s->p = p;
- s->i = i;
- s->nz = nz;
- s->x = x;
- s->z = z;
- s->stype = stype;
- s->itype = itype;
- s->xtype = xtype;
- s->dtype = dtype;
- s->sorted = sorted;
- s->packed = packed;
-
- *cs = s;
- return;
-}
-
-extern int
-jl_cholmod_sparse_copy_out(cholmod_sparse *cs,
- void *cp, /* column pointers */
- void *ri, /* row indices */
- void *nzp,
- cholmod_common *cm) /* non-zero values */
-{
- /* error return if cs is not packed */
- if (!cs->packed) return 1; /* FIXME: If non-packed becomes a problem, write code to do packing */
- if (!cs->sorted) /* sort it */
- if (!cholmod_sort(cs, cm)) return 2;
-
- size_t isize;
- switch(cs->itype) {
- case CHOLMOD_INT:
- case CHOLMOD_INTLONG:
- isize = sizeof(int); break;
- case CHOLMOD_LONG:
- isize = sizeof(SuiteSparse_long); break;
- default:
- return 3;
- }
- size_t elsize = (cs->xtype == CHOLMOD_COMPLEX ? 2 : 1) *
- (cs->dtype == CHOLMOD_DOUBLE ? sizeof(double) : sizeof(float));
-
- if (cs->itype == CHOLMOD_INTLONG) {
- int i, *dpt = (int *) cp;
- SuiteSparse_long *spt = (SuiteSparse_long *) cs->p;
- for (i = 0; i <= cs->ncol; ++i) dpt[i] = spt[i];
- } else {
- memcpy(cp, cs->p, (cs->ncol + 1) * isize);
- }
-
- memcpy(ri, cs->i, cs->nzmax * isize);
- memcpy(nzp, cs->x, cs->nzmax * elsize);
- return 0;
-}
View
27 test/suitesparse.jl
@@ -2,16 +2,17 @@ se33 = speye(3)
do33 = ones(3)
@test isequal(se33 \ do33, do33)
-using Base.LinAlg.UMFPACK
-import Base.(*)
-
# based on deps/Suitesparse-4.0.2/UMFPACK/Demo/umfpack_di_demo.c
+using Base.LinAlg.UMFPACK.increment!
+
A = sparse(increment!([0,4,1,1,2,2,0,1,2,3,4,4]),
increment!([0,4,0,2,1,2,1,4,3,2,1,2]),
[2.,1.,3.,4.,-1.,-3.,3.,6.,2.,1.,4.,2.], 5, 5)
lua = lufact(A)
-#umf_lunz(lua)
+L,U,P,Q,Rs = lua[:(:)]
+@test_approx_eq diagmm(Rs,A)[P,Q] L*U
+
@test_approx_eq det(lua) det(full(A))
b = [8., 45., -3., 3., 19.]
@@ -20,9 +21,6 @@ x = lua\b
@test norm(A*x-b,1) < eps(1e4)
-L,U,P,Q,Rs = lua[:(:)]
-@test_approx_eq diagmm(Rs,A)[P,Q] L*U
-
using Base.LinAlg.CHOLMOD
# based on deps/SuiteSparse-4.0.2/CHOLMOD/Demo/
@@ -109,15 +107,15 @@ A = CholmodSparse!(int32([0,1,2,3,6,9,12,15,18,20,25,30,34,36,39,43,47,52,58,62,
2.29724661236e8,-5.57173510779e7,-833333.333333,-1.25e6,2.5e8,2.39928529451e6,
9.61679848804e8,275828.470683,-5.57173510779e7,1.09411960038e7,2.08333333333e6,
1.0e8,-2.5e6,140838.195984,-1.09779731332e8,5.31278103775e8], 48, 48, 1)
-show(A)
+#show(A)
@test_approx_eq norm(A,Inf) 3.570948074697437e9
@test_approx_eq norm(A) 3.570948074697437e9
B = A * ones(size(A,2))
chma = cholfact(A)
-show(chma)
+#show(chma)
x = chma\B
-show(x)
+#show(x)
@test_approx_eq x.mat ones(size(x))
#lp_afiro example
@@ -135,8 +133,9 @@ afiro = CholmodSparse!(int32([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,1.0,-0.43,1.0,1.0,0.109,-0.43,1.0,1.0,0.108,
-0.39,1.0,1.0,0.108,-0.37,1.0,1.0,0.107,-1.0,2.191,-1.0,2.219,-1.0,2.249,
-1.0,2.279,1.4,-1.0,1.0,-1.0,1.0,1.0,1.0], 27, 51, 0)
-show(afiro)
+#show(afiro)
chmaf = cholfact(afiro)
-show(chmaf)
-sol = solve(chmaf,afiro * ones(size(afiro,2))) # least squares solution
-show(sol)
+#show(chmaf)
+sol = solve(chmaf, afiro*ones(size(afiro,2))) # least squares solution
+# ToDo: check for the residual being orthogonal to the rows of afiro
+#show(sol)

0 comments on commit cecd879

Please sign in to comment.
Something went wrong with that request. Please try again.