/** * 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; }
/** * 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); }
/** * Sparse matrix times dense column vector, y = A*x+y. * * @param A * column-compressed matrix * @param x * size n, vector x * @param y * size m, vector y * @return true if successful, false on error */ public static boolean cs_gaxpy(Dcs A, double[] x, double[] y) { int p, j, n, Ap[], Ai[]; double Ax[]; if (!Dcs_util.CS_CSC(A) || x == null || y == null) return (false); /* check inputs */ n = A.n; Ap = A.p; Ai = A.i; Ax = A.x; for (j = 0; j < n; j++) { for (p = Ap[j]; p < Ap[j + 1]; p++) { y[Ai[p]] += Ax[p] * x[j]; } } return (true); }
/** * Solves an upper triangular system Ux=b, where x and b are dense vectors. * The diagonal of U must be the last entry of each column. * * @param U * upper triangular matrix in column-compressed form * @param x * size n, right hand side on input, solution on output * @return true if successful, false on error */ public static boolean cs_usolve(Dcs U, double[] x) { int p, j, n, Up[], Ui[]; double Ux[]; if (!Dcs_util.CS_CSC(U) || x == null) return (false); /* check inputs */ n = U.n; Up = U.p; Ui = U.i; Ux = U.x; for (j = n - 1; j >= 0; j--) { x[j] /= Ux[Up[j + 1] - 1]; for (p = Up[j]; p < Up[j + 1] - 1; p++) { x[Ui[p]] -= Ux[p] * x[j]; } } return (true); }
/** * Solves a lower triangular system U'x=b, where x and b are dense vectors. * The diagonal of U must be the last entry of each column. * * @param U * upper triangular matrix in column-compressed form * @param x * size n, right hand side on input, solution on output * @return true if successful, false on error */ public static boolean cs_utsolve(Dcs U, double[] x) { int p, j, n, Up[], Ui[]; double Ux[]; if (!Dcs_util.CS_CSC(U) || x == null) return (false); /* check inputs */ n = U.n; Up = U.p; Ui = U.i; Ux = U.x; for (j = 0; j < n; j++) { for (p = Up[j]; p < Up[j + 1] - 1; p++) { x[j] -= Ux[p] * x[Ui[p]]; } x[j] /= Ux[Up[j + 1] - 1]; } return (true); }
int p, Vp[], Vi[]; double Vx[], tau = 0; if (!Dcs_util.CS_CSC(V) || x == null) return (false); /* check inputs */ Vp = V.p;
if (!Dcs_util.CS_CSC(A)) return (null); /* check inputs */ m = A.m;
/** * Computes the 1-norm of a sparse matrix = max (sum (abs (A))), largest * column sum. * * @param A * column-compressed matrix * @return the 1-norm if successful, -1 on error */ public static double cs_norm(Dcs A) { int p, j, n, Ap[]; double Ax[], norm = 0, s; if (!Dcs_util.CS_CSC(A) || A.x == null) return (-1); /* check inputs */ n = A.n; Ap = A.p; Ax = A.x; for (j = 0; j < n; j++) { for (s = 0, p = Ap[j]; p < Ap[j + 1]; p++) s += Math.abs(Ax[p]); norm = Math.max(norm, s); } return (norm); } }
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);
int i, j, p, q, nz = 0, n, m, Ap[], Ai[], w[]; double Ax[]; if (!Dcs_util.CS_CSC(A)) return (false);
double Cx[], Ax[]; Dcs C; if (!Dcs_util.CS_CSC(A)) return (null); /* check inputs */ m = A.m;
int j, p, nz = 0, n, Ap[], Ai[]; double Ax[]; if (!Dcs_util.CS_CSC(A)) return (-1); /* check inputs */ n = A.n;
double Cx[], Ax[]; Dcs C; if (!Dcs_util.CS_CSC(A)) return (null); /* check inputs */ m = A.m;
int n; boolean ok; if (!Dcs_util.CS_CSC(A) || b == null) return (false); /* check inputs */ n = A.n;
int n; boolean ok; if (!Dcs_util.CS_CSC(A) || b == null) return (false); /* check inputs */ n = A.n;
/** * 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); } }
Dcss S; boolean ok = true; if (!Dcs_util.CS_CSC(A)) return (null); /* check inputs */ n = A.n;
int k, m, n; boolean ok; if (!Dcs_util.CS_CSC(A) || b == null) return (false); /* check inputs */ n = A.n;