/** * Removes numerically zero entries from a matrix. * * @param A * column-compressed matrix * @return nz, new number of entries in A, -1 on error */ public static int cs_dropzeros(Dcs A) { return (Dcs_fkeep.cs_fkeep(A, new Cs_nonzero(), null)); /* keep all nonzero entries */ }
/** * Removes entries from a matrix with absolute value <= tol. * * @param A * column-compressed matrix * @param tol * drop tolerance * @return nz, new number of entries in A, -1 on error */ public static int cs_droptol(Dcs A, double tol) { return (Dcs_fkeep.cs_fkeep(A, new Cs_tol(), tol)); /* keep all large entries */ } }
/** * Loads a triplet matrix T from a file. The file is zero-based. */ public static Dcs cs_load(InputStream in) { return cs_load(in, 0) ; } }
int n; boolean ok; if (!Dcs_util.CS_CSC(A) || b == null) return (false); /* check inputs */ n = A.n; S = Dcs_schol.cs_schol(order, A); /* ordering and symbolic analysis */ N = Dcs_chol.cs_chol(A, S); /* numeric Cholesky factorization */ x = new double[n]; /* get workspace */ ok = (S != null && N != null); if (ok) { Dcs_ipvec.cs_ipvec(S.pinv, b, x, n); /* x = P*b */ Dcs_lsolve.cs_lsolve(N.L, x); /* x = L\x */ Dcs_ltsolve.cs_ltsolve(N.L, x); /* x = L'\x */ Dcs_pvec.cs_pvec(S.pinv, x, b, n); /* b = P'*x */
/** * Ordering and symbolic analysis for a Cholesky factorization. * * @param order * ordering option (0 or 1) * @param A * column-compressed matrix * @return symbolic analysis for Cholesky, null on error */ public static Dcss cs_schol(int order, Dcs A) { int n, c[], post[], P[]; Dcs C; Dcss S; if (!Dcs_util.CS_CSC(A)) return (null); /* check inputs */ n = A.n; S = new Dcss(); /* allocate result S */ P = Dcs_amd.cs_amd(order, A); /* P = amd(A+A'), or natural */ S.pinv = Dcs_pinv.cs_pinv(P, n); /* find inverse permutation */ if (order != 0 && S.pinv == null) return null; C = Dcs_symperm.cs_symperm(A, S.pinv, false); /* C = spones(triu(A(P,P))) */ S.parent = Dcs_etree.cs_etree(C, false); /* find etree of C */ post = Dcs_post.cs_post(S.parent, n); /* postorder the etree */ c = Dcs_counts.cs_counts(C, S.parent, post, false); /* find column counts of chol(C) */ S.cp = new int[n + 1]; /* allocate result S.cp */ S.unz = S.lnz = Dcs_cumsum.cs_cumsum(S.cp, c, n); /* find column pointers for L */ return ((S.lnz >= 0) ? S : null); } }
/** * Sorts row indexes */ public void sortRowIndexes() { dcs = Dcs_transpose.cs_transpose(dcs, true); dcs = Dcs_transpose.cs_transpose(dcs, true); if (dcs == null) { throw new IllegalArgumentException("Exception occured in cs_transpose()!"); } rowIndexesSorted = true; }
public void trimToSize() { Dcs_util.cs_sprealloc(dcs, 0); }
public Dcss getSymbolicAnalysis() { Dcss S2 = new Dcss(); S2.cp = S.cp != null ? S.cp.clone() : null; S2.leftmost = S.leftmost != null ? S.leftmost.clone() : null; S2.lnz = S.lnz; S2.m2 = S.m2; S2.parent = S.parent != null ? S.parent.clone() : null; S2.pinv = S.pinv != null ? S.pinv.clone() : null; S2.q = S.q != null ? S.q.clone() : null; S2.unz = S.unz; return S2; }
/** * Removes zero entries (if any) */ public void removeZeroes() { Dcs_dropzeros.cs_dropzeros(dcs); //remove zeroes }
protected static void CS_MARK(int[] w, int j) { w[j] = CS_FLIP(w[j]); }
/** * Removes (sums) duplicate entries (if any} */ public void removeDuplicates() { if (!Dcs_dupl.cs_dupl(dcs)) { //remove duplicates throw new IllegalArgumentException("Exception occured in cs_dupl()!"); } }
/** * Allocate a Dcsd object (a Dulmage-Mendelsohn decomposition). * * @param m * number of rows of the matrix A to be analyzed * @param n * number of columns of the matrix A to be analyzed * @return Dulmage-Mendelsohn decomposition */ public static Dcsd cs_dalloc(int m, int n) { Dcsd D; D = new Dcsd(); D.p = new int[m]; D.r = new int[m + 6]; D.q = new int[n]; D.s = new int[n + 6]; D.cc = new int[5]; D.rr = new int[5]; return D; }
/** * Sorts row indexes */ public void sortRowIndexes() { dcs = Dcs_transpose.cs_transpose(dcs, true); dcs = Dcs_transpose.cs_transpose(dcs, true); if (dcs == null) { throw new IllegalArgumentException("Exception occured in cs_transpose()!"); } rowIndexesSorted = true; }
public void trimToSize() { Dcs_util.cs_sprealloc(dcs, 0); }
public Dcss getSymbolicAnalysis() { Dcss S2 = new Dcss(); S2.cp = S.cp != null ? S.cp.clone() : null; S2.leftmost = S.leftmost != null ? S.leftmost.clone() : null; S2.lnz = S.lnz; S2.m2 = S.m2; S2.parent = S.parent != null ? S.parent.clone() : null; S2.pinv = S.pinv != null ? S.pinv.clone() : null; S2.q = S.q != null ? S.q.clone() : null; S2.unz = S.unz; return S2; }
/** * Removes zero entries (if any) */ public void removeZeroes() { Dcs_dropzeros.cs_dropzeros(dcs); //remove zeroes }
protected static int CS_UNFLIP(int i) { return (((i) < 0) ? CS_FLIP(i) : (i)); }
/** * Removes (sums) duplicate entries (if any} */ public void removeDuplicates() { if (!Dcs_dupl.cs_dupl(dcs)) { //remove duplicates throw new IllegalArgumentException("Exception occured in cs_dupl()!"); } }
/** * Returns a new matrix that is the transpose of this matrix. This method * creates a new object (not a view), so changes in the returned matrix are * NOT reflected in this matrix. * * @return the transpose of this matrix */ public SparseCCDoubleMatrix2D getTranspose() { Dcs dcst = Dcs_transpose.cs_transpose(dcs, true); SparseCCDoubleMatrix2D tr = new SparseCCDoubleMatrix2D(columns, rows); tr.dcs = dcst; return tr; }
/** * Returns a new matrix that is the transpose of this matrix. This method * creates a new object (not a view), so changes in the returned matrix are * NOT reflected in this matrix. * * @return the transpose of this matrix */ public SparseCCDoubleMatrix2D getTranspose() { Dcs dcst = Dcs_transpose.cs_transpose(dcs, true); SparseCCDoubleMatrix2D tr = new SparseCCDoubleMatrix2D(columns, rows); tr.dcs = dcst; return tr; }