boolean values; Dcs C; if (!Dcs_util.CS_CSC(A) || !Dcs_util.CS_CSC(B)) return (null); /* check inputs */ if (A.n != B.m) values = (A.x != null) && (Bx != null); x = values ? new double[m] : null; /* get workspace */ C = Dcs_util.cs_spalloc(m, n, anz + bnz, values, false); /* allocate result */ Cp = C.p; for (j = 0; j < n; j++) { if (nz + m > C.nzmax) { Dcs_util.cs_sprealloc(C, 2 * (C.nzmax) + m); Dcs_util.cs_sprealloc(C, 0); /* remove extra space from C */ return C;
protected static void CS_MARK(int[] w, int j) { w[j] = CS_FLIP(w[j]); }
int i, p, p2, jnew, head = 0, Gp[], Gi[]; boolean done; if (!Dcs_util.CS_CSC(G) || xi == null || pstack == null) return (-1); /* check inputs */ Gp = G.p; if (!Dcs_util.CS_MARKED(Gp, j)) { Dcs_util.CS_MARK(Gp, j); /* mark node j as visited */ pstack[pstack_offset + head] = (jnew < 0) ? 0 : Dcs_util.CS_UNFLIP(Gp[jnew]); p2 = (jnew < 0) ? 0 : Dcs_util.CS_UNFLIP(Gp[jnew + 1]); for (p = pstack[pstack_offset + head]; p < p2; p++) /* examine all neighbors of j */ if (Dcs_util.CS_MARKED(Gp, i)) continue; /* skip visited node i */
int i, j, p, q, nz = 0, n, m, Ap[], Ai[], w[]; double Ax[]; if (!Dcs_util.CS_CSC(A)) return (false); return Dcs_util.cs_sprealloc(A, 0); /* remove extra space from A */
double Cx[], Ax[]; Dcs C; if (!Dcs_util.CS_CSC(A)) return (null); /* check inputs */ m = A.m; Ai = A.i; Ax = A.x; C = Dcs_util.cs_spalloc(m, n, Ap[n], values && Ax != null, false); /* alloc result */ Cp = C.p; Ci = C.i;
if (!Dcs_util.CS_CSC(A) || parent == null || s == null || w == null) return (-1); /* check inputs */ top = n = A.n; Ap = A.p; Ai = A.i; Dcs_util.CS_MARK(w, k); /* mark node k as visited */ for (p = Ap[k]; p < Ap[k + 1]; p++) { for (len = 0; !Dcs_util.CS_MARKED(w, i); i = parent[i]) /* traverse up etree*/ Dcs_util.CS_MARK(w, i); /* mark i as visited */ Dcs_util.CS_MARK(w, s[s_offset + p]); /* unmark all nodes */ Dcs_util.CS_MARK(w, k); /* unmark node k */ return (top); /* s [top..n-1] contains pattern of L(k,:)*/
/** * Constructs a matrix with a given number of rows and columns. All entries * are initially <tt>0</tt>. * * @param rows * the number of rows the matrix shall have. * @param columns * the number of columns the matrix shall have. * @param nzmax * maximum number of nonzero elements * @throws IllegalArgumentException * if <tt>rows<0 || columns<0</tt> . */ public SparseCCDoubleMatrix2D(int rows, int columns, int nzmax) { super(null); try { setUp(rows, columns); } catch (IllegalArgumentException exc) { // we can hold rows*columns>Integer.MAX_VALUE cells ! if (!"matrix too large".equals(exc.getMessage())) throw exc; } dcs = Dcs_util.cs_spalloc(rows, columns, nzmax, true, false); }
Dcs AT; Dcsd D; if (!Dcs_util.CS_CSC(A)) return (null); /* check inputs */ n = A.n; Ap = A.p; D = Dcs_util.cs_dalloc(n, 0); /* allocate result */ AT = Dcs_transpose.cs_transpose(A, false); /* AT = A' */ xi = new int[2 * n + 1]; /* get workspace */ for (i = 0; i < n; i++) /* first dfs(A) to find finish times (xi) */ if (!Dcs_util.CS_MARKED(Ap, i)) top = Dcs_dfs.cs_dfs(i, A, top, xi, 0, pstack, pstack_offset, null, 0); Dcs_util.CS_MARK(Ap, i); /* restore A; unmark all nodes*/ top = n; nb = n; if (Dcs_util.CS_MARKED(ATp, i)) continue; /* skip node i if already ordered */
if (!Dcs_util.CS_CSC(A) || order <= 0 || order > 3) return (null); /* check */ AT = Dcs_transpose.cs_transpose(A, false); /* compute A' */ W = new int[8 * (n + 1)]; /* get workspace */ t = cnz + cnz / 5 + 2 * n; /* add elbow room to C */ Dcs_util.cs_sprealloc(C, t); len = W; nv = W; elen[elen_offset + i] = -1; /* node i is dead */ nel++; Cp[i] = Dcs_util.CS_FLIP(n); nv[nv_offset + n]++; } else { Ci[p] = Dcs_util.CS_FLIP(j); /* first entry is now CS_FLIP(j) */ if ((j = Dcs_util.CS_FLIP(Ci[p++])) >= 0) /* found object j */ Cp[e] = Dcs_util.CS_FLIP(k); /* absorb e into k */ w[w_offset + e] = 0; /* e is now a dead element */ Cp[e] = Dcs_util.CS_FLIP(k); /* aggressive absorb. e.k */ w[w_offset + e] = 0; /* e is a dead element */ Cp[i] = Dcs_util.CS_FLIP(k); /* absorb i into k */ nvi = -nv[nv_offset + i];
/** * Solves a lower triangular system Lx=b where x and b are dense. x=b on * input, solution on output. * * @param L * column-compressed, lower triangular matrix * @param x * size n, right hand side on input, solution on output * @return true if successful, false on error */ public static boolean cs_lsolve(Dcs L, double[] x) { int p, j, n, Lp[], Li[]; double Lx[]; if (!Dcs_util.CS_CSC(L) || x == null) return (false); /* check inputs */ n = L.n; Lp = L.p; Li = L.i; Lx = L.x; for (j = 0; j < n; j++) { x[j] /= Lx[Lp[j]]; for (p = Lp[j] + 1; p < Lp[j + 1]; p++) { x[Li[p]] -= Lx[p] * x[j]; } } return true; }
/** * Adds an entry to a triplet matrix. Memory-space and dimension of T are * increased if necessary. * * @param T * triplet matrix; new entry added on output * @param i * row index of new entry * @param j * column index of new entry * @param x * numerical value of new entry * @return true if successful, false otherwise */ public static boolean cs_entry(Dcs T, int i, int j, double x) { if (!Dcs_util.CS_TRIPLET(T) || i < 0 || j < 0) return (false); /* check inputs */ if (T.nz >= T.nzmax) { Dcs_util.cs_sprealloc(T, 2 * (T.nzmax)); } if (T.x != null) T.x[T.nz] = x; T.i[T.nz] = i; T.p[T.nz++] = j; T.m = Math.max(T.m, i + 1); T.n = Math.max(T.n, j + 1); return (true); } }
double Cx[], Tx[]; Dcs C; if (!Dcs_util.CS_TRIPLET(T)) return (null); /* check inputs */ m = T.m; Tx = T.x; nz = T.nz; C = Dcs_util.cs_spalloc(m, n, nz, Tx != null, false); /* allocate result */ w = new int[n]; /* get workspace */ Cp = C.p;
public void trimToSize() { Dcs_util.cs_sprealloc(dcs, 0); }
return (false); if (nzmax <= 0) nzmax = (Dcs_util.CS_CSC(A)) ? (A.p[A.n]) : A.nz; int[] Ainew = new int[nzmax]; int length = Math.min(nzmax, A.i.length); System.arraycopy(A.i, 0, Ainew, 0, length); A.i = Ainew; if (Dcs_util.CS_TRIPLET(A)) { int[] Apnew = new int[nzmax]; length = Math.min(nzmax, A.p.length);
double Cx[], Ax[]; Dcs C; if (!Dcs_util.CS_CSC(A)) return (null); /* check inputs */ m = A.m; Ai = A.i; Ax = A.x; C = Dcs_util.cs_spalloc(n, m, Ap[n], values && (Ax != null), false); /* allocate result */ w = new int[m]; /* get workspace */ Cp = C.p;
/** * Constructs a matrix with a given number of rows and columns. All entries * are initially <tt>0</tt>. * * @param rows * the number of rows the matrix shall have. * @param columns * the number of columns the matrix shall have. * @param nzmax * maximum number of nonzero elements * @throws IllegalArgumentException * if <tt>rows<0 || columns<0</tt> . */ public SparseCCDoubleMatrix2D(int rows, int columns, int nzmax) { super(null); try { setUp(rows, columns); } catch (IllegalArgumentException exc) { // we can hold rows*columns>Integer.MAX_VALUE cells ! if (!"matrix too large".equals(exc.getMessage())) throw exc; } dcs = Dcs_util.cs_spalloc(rows, columns, nzmax, true, false); }
/** * Solves an upper triangular system L'x=b where x and b are dense. x=b on * input, solution on output. * * @param L * column-compressed, lower triangular matrix * @param x * size n, right hand side on input, solution on output * @return true if successful, false on error */ public static boolean cs_ltsolve(Dcs L, double[] x) { int p, j, n, Lp[], Li[]; double Lx[]; if (!Dcs_util.CS_CSC(L) || x == null) return (false); /* check inputs */ n = L.n; Lp = L.p; Li = L.i; Lx = L.x; for (j = n - 1; j >= 0; j--) { for (p = Lp[j] + 1; p < Lp[j + 1]; p++) { x[j] -= Lx[p] * x[Li[p]]; } x[j] /= Lx[Lp[j]]; } return (true); }
int j, p, nz = 0, n, Ap[], Ai[]; double Ax[]; if (!Dcs_util.CS_CSC(A)) return (-1); /* check inputs */ n = A.n; Dcs_util.cs_sprealloc(A, 0); /* remove extra space from A */ return (nz);