public double getQuick(int row, int column) { return elements[column].getQuick(row); }
public double getQuick(int row, int column) { return elements[row].getQuick(column); }
public double getQuick(int row, int column) { return elements[column].getQuick(row); }
public double getQuick(int row, int column) { return elements[row].getQuick(column); }
public String toString() { StringBuilder builder = new StringBuilder(); builder.append("1 x ").append(size).append(" sparse matrix, nnz = ").append(cardinality()).append('\n'); for (int i = 0; i < size; i++) { double elem = getQuick(i); if (elem != 0) { builder.append('(').append(i).append(')').append('\t').append(elem).append('\n'); } } return builder.toString(); }
public String toString() { StringBuilder builder = new StringBuilder(); builder.append("1 x ").append(size).append(" sparse matrix, nnz = ").append(cardinality()).append('\n'); for (int i = 0; i < size; i++) { double elem = getQuick(i); if (elem != 0) { builder.append('(').append(i).append(')').append('\t').append(elem).append('\n'); } } return builder.toString(); }
public DoubleMatrix2D reshape(int rows, int columns) { if (rows * columns != size) { throw new IllegalArgumentException("rows*columns != size"); } DoubleMatrix2D M = new SparseDoubleMatrix2D(rows, columns); int idx = 0; for (int c = 0; c < columns; c++) { for (int r = 0; r < rows; r++) { double elem = getQuick(idx++); if (elem != 0) { M.setQuick(r, c, elem); } } } return M; }
public DoubleMatrix3D reshape(int slices, int rows, int columns) { if (slices * rows * columns != size) { throw new IllegalArgumentException("slices*rows*columns != size"); } DoubleMatrix3D M = new SparseDoubleMatrix3D(slices, rows, columns); int idx = 0; for (int s = 0; s < slices; s++) { for (int c = 0; c < columns; c++) { for (int r = 0; r < rows; r++) { double elem = getQuick(idx++); if (elem != 0) { M.setQuick(s, r, c, elem); } } } } return M; }
public DoubleMatrix2D reshape(int rows, int columns) { if (rows * columns != size) { throw new IllegalArgumentException("rows*columns != size"); } DoubleMatrix2D M = new SparseDoubleMatrix2D(rows, columns); int idx = 0; for (int c = 0; c < columns; c++) { for (int r = 0; r < rows; r++) { double elem = getQuick(idx++); if (elem != 0) { M.setQuick(r, c, elem); } } } return M; }
private void factor() { int n = LU.rows(); for (int i = 1; i < n; ++i) { // Get row i SparseDoubleMatrix1D rowi = LU.viewRow(i); // Drop tolerance on current row double taui = DenseDoubleAlgebra.DEFAULT.norm(rowi, Norm.Two) * tau; for (int k = 0; k < i; ++k) { // Get row k SparseDoubleMatrix1D rowk = LU.viewRow(k); if (rowk.getQuick(k) == 0) throw new RuntimeException("Zero diagonal entry on row " + (k + 1) + " during ILU process"); double LUik = rowi.getQuick(k) / rowk.getQuick(k); // Check for small elimination entry if (Math.abs(LUik) <= taui) continue; // Traverse the sparse row k, reducing row i int rowUsed = (int) rowk.size(); for (int j = k + 1; j < rowUsed; ++j) rowi.setQuick(j, rowi.getQuick(j) - LUik * rowk.getQuick(j)); // The above has overwritten LUik, so remedy that rowi.setQuick(k, LUik); } // Store back into the LU matrix, dropping as needed gather(rowi, taui, i); } // System.out.println(LU.toString()); }
public DoubleMatrix3D reshape(int slices, int rows, int columns) { if (slices * rows * columns != size) { throw new IllegalArgumentException("slices*rows*columns != size"); } DoubleMatrix3D M = new SparseDoubleMatrix3D(slices, rows, columns); int idx = 0; for (int s = 0; s < slices; s++) { for (int c = 0; c < columns; c++) { for (int r = 0; r < rows; r++) { double elem = getQuick(idx++); if (elem != 0) { M.setQuick(s, r, c, elem); } } } } return M; }
private void factor() { int n = LU.rows(); for (int i = 1; i < n; ++i) { // Get row i SparseDoubleMatrix1D rowi = LU.viewRow(i); // Drop tolerance on current row double taui = DenseDoubleAlgebra.DEFAULT.norm(rowi, Norm.Two) * tau; for (int k = 0; k < i; ++k) { // Get row k SparseDoubleMatrix1D rowk = LU.viewRow(k); if (rowk.getQuick(k) == 0) throw new RuntimeException("Zero diagonal entry on row " + (k + 1) + " during ILU process"); double LUik = rowi.getQuick(k) / rowk.getQuick(k); // Check for small elimination entry if (Math.abs(LUik) <= taui) continue; // Traverse the sparse row k, reducing row i int rowUsed = (int) rowk.size(); for (int j = k + 1; j < rowUsed; ++j) rowi.setQuick(j, rowi.getQuick(j) - LUik * rowk.getQuick(j)); // The above has overwritten LUik, so remedy that rowi.setQuick(k, LUik); } // Store back into the LU matrix, dropping as needed gather(rowi, taui, i); } // System.out.println(LU.toString()); }
private DoubleMatrix1D upperSolve(DoubleMatrix1D b, DoubleMatrix1D x) { double[] bd = ((DenseDoubleMatrix1D) b).elements(); double[] xd = ((DenseDoubleMatrix1D) x).elements(); int rows = LU.rows(); for (int i = rows - 1; i >= 0; --i) { // Get row i SparseDoubleMatrix1D row = LU.viewRow(i); int used = (int) row.size(); // xi = (bi - sum[j>i] Uij * xj) / Uii double sum = 0; for (int j = i + 1; j < used; ++j) sum += row.getQuick(j) * xd[j]; xd[i] = (bd[i] - sum) / row.getQuick(i); } return x; }
private DoubleMatrix1D upperTransSolve(DoubleMatrix1D b, DoubleMatrix1D x) { x.assign(b); double[] xd = ((DenseDoubleMatrix1D) x).elements(); int rows = LU.rows(); for (int i = 0; i < rows; ++i) { // Get row i SparseDoubleMatrix1D row = LU.viewRow(i); int used = (int) row.size(); // Solve for the current entry xd[i] /= row.getQuick(i); // Move this known solution over to the right hand side for the // remaining equations for (int j = i + 1; j < used; ++j) xd[j] -= row.getQuick(j) * xd[i]; } return x; }
private DoubleMatrix1D upperSolve(DoubleMatrix1D b, DoubleMatrix1D x) { double[] bd = ((DenseDoubleMatrix1D) b).elements(); double[] xd = ((DenseDoubleMatrix1D) x).elements(); int rows = LU.rows(); for (int i = rows - 1; i >= 0; --i) { // Get row i SparseDoubleMatrix1D row = LU.viewRow(i); int used = (int) row.size(); // xi = (bi - sum[j>i] Uij * xj) / Uii double sum = 0; for (int j = i + 1; j < used; ++j) sum += row.getQuick(j) * xd[j]; xd[i] = (bd[i] - sum) / row.getQuick(i); } return x; }
private DoubleMatrix1D upperTransSolve(DoubleMatrix1D b, DoubleMatrix1D x) { x.assign(b); double[] xd = ((DenseDoubleMatrix1D) x).elements(); int rows = LU.rows(); for (int i = 0; i < rows; ++i) { // Get row i SparseDoubleMatrix1D row = LU.viewRow(i); int used = (int) row.size(); // Solve for the current entry xd[i] /= row.getQuick(i); // Move this known solution over to the right hand side for the // remaining equations for (int j = i + 1; j < used; ++j) xd[j] -= row.getQuick(j) * xd[i]; } return x; }
private DoubleMatrix1D unitLowerTransSolve(DoubleMatrix1D b, DoubleMatrix1D x) { x.assign(b); double[] xd = ((DenseDoubleMatrix1D) x).elements(); int rows = LU.rows(); for (int i = rows - 1; i >= 0; --i) { // Get row i SparseDoubleMatrix1D row = LU.viewRow(i); // At this stage, x[i] is known, so move it over to the right // hand side for the remaining equations for (int j = 0; j < i; ++j) xd[j] -= row.getQuick(j) * xd[i]; } return x; }
private DoubleMatrix1D unitLowerTransSolve(DoubleMatrix1D b, DoubleMatrix1D x) { x.assign(b); double[] xd = ((DenseDoubleMatrix1D) x).elements(); int rows = LU.rows(); for (int i = rows - 1; i >= 0; --i) { // Get row i SparseDoubleMatrix1D row = LU.viewRow(i); // At this stage, x[i] is known, so move it over to the right // hand side for the remaining equations for (int j = 0; j < i; ++j) xd[j] -= row.getQuick(j) * xd[i]; } return x; }
private DoubleMatrix1D unitLowerSolve(DoubleMatrix1D b, DoubleMatrix1D x) { double[] bd = ((DenseDoubleMatrix1D) b).elements(); double[] xd = ((DenseDoubleMatrix1D) x).elements(); int rows = LU.rows(); for (int i = 0; i < rows; ++i) { // Get row i SparseDoubleMatrix1D row = LU.viewRow(i); // xi = bi - sum[j<i] Lij * xj double sum = 0; for (int j = 0; j < i; ++j) sum += row.getQuick(j) * xd[j]; xd[i] = bd[i] - sum; } return x; }
private DoubleMatrix1D unitLowerSolve(DoubleMatrix1D b, DoubleMatrix1D x) { double[] bd = ((DenseDoubleMatrix1D) b).elements(); double[] xd = ((DenseDoubleMatrix1D) x).elements(); int rows = LU.rows(); for (int i = 0; i < rows; ++i) { // Get row i SparseDoubleMatrix1D row = LU.viewRow(i); // xi = bi - sum[j<i] Lij * xj double sum = 0; for (int j = 0; j < i; ++j) sum += row.getQuick(j) * xd[j]; xd[i] = bd[i] - sum; } return x; }