/** * */ protected int m() { return LU.rows(); }
public void setMatrix(DoubleMatrix2D A) { if (A.rows() != invdiag.length) throw new IllegalArgumentException("Matrix size differs from preconditioner size"); for (int i = 0; i < invdiag.length; ++i) { invdiag[i] = A.getQuick(i, i); if (invdiag[i] == 0) // Avoid zero-division throw new RuntimeException("Zero diagonal on row " + (i + 1)); else invdiag[i] = 1 / invdiag[i]; } }
/** * A matrix <tt>A</tt> is <i>square</i> if it has the same number of rows * and columns. */ public boolean isSquare(DoubleMatrix2D A) { return A.rows() == A.columns(); }
public WrapperDoubleMatrix2D(DoubleMatrix2D newContent) { if (newContent != null) try { setUp(newContent.rows(), newContent.columns()); } catch (IllegalArgumentException exc) { // we can hold rows*columns>Integer.MAX_VALUE cells ! if (!"matrix too large".equals(exc.getMessage())) throw exc; } this.content = newContent; }
/** * Returns a string representations of all cells; no alignment considered. */ public String[][] format(DoubleMatrix2D matrix) { String[][] strings = new String[matrix.rows()][matrix.columns()]; for (int row = matrix.rows(); --row >= 0;) strings[row] = formatRow(matrix.viewRow(row)); return strings; }
/** * Checks whether the given matrix <tt>A</tt> is <i>square</i>. * * @throws IllegalArgumentException * if <tt>A.rows() != A.columns()</tt>. */ public void checkSquare(DoubleMatrix2D A) { if (A.rows() != A.columns()) throw new IllegalArgumentException("Matrix must be square: " + AbstractFormatter.shape(A)); }
/** * Returns the infinity norm of matrix <tt>A</tt>, which is the maximum * absolute row sum. */ public double normInfinity(DoubleMatrix2D A) { double max = 0; for (int row = A.rows(); --row >= 0;) { max = Math.max(max, norm1(A.viewRow(row))); } return max; }
/** * Checks whether the given matrix <tt>A</tt> is <i>rectangular</i>. * * @throws IllegalArgumentException * if <tt>A.rows() < A.columns()</tt>. */ public void checkRectangular(DoubleMatrix2D A) { if (A.rows() < A.columns()) { throw new IllegalArgumentException("Matrix must be rectangular: " + AbstractFormatter.shape(A)); } }
/** * Returns the sum of the diagonal elements of matrix <tt>A</tt>; * <tt>Sum(A[i,i])</tt>. */ public double trace(DoubleMatrix2D A) { double sum = 0; for (int i = Math.min(A.rows(), A.columns()); --i >= 0;) { sum += A.getQuick(i, i); } return sum; }
protected void checkSizes(DoubleMatrix2D A, DoubleMatrix1D b, DoubleMatrix1D x) { if (b.size() != A.rows()) throw new IllegalArgumentException("b.size() != A.rows()"); if (x.size() != A.columns()) throw new IllegalArgumentException("x.size() != A.columns()"); }
public void setMatrix(DoubleMatrix2D A) { if (A.rows() != n) { throw new IllegalArgumentException("A.rows() != n"); } LU = new SparseRCDoubleMatrix2D(n, n); LU.assign(A); if (!LU.hasColumnIndexesSorted()) { LU.sortColumnIndexes(); } factor(); }
public void setMatrix(DoubleMatrix2D A) { DoubleProperty.DEFAULT.isSquare(A); if (A.rows() != n) { throw new IllegalArgumentException("A.rows() != n"); } LU = new SparseRCMDoubleMatrix2D(n, n); LU.assign(A); LU.trimToSize(); factor(); }
public void dswap(DoubleMatrix2D A, DoubleMatrix2D B) { A.checkShape(B); int rows = A.rows(); for (int i = 0; i < rows; i++) A.viewRow(i).swap(B.viewRow(i)); }
public void dger(double alpha, DoubleMatrix1D x, DoubleMatrix1D y, DoubleMatrix2D A) { cern.jet.math.tdouble.DoublePlusMultSecond fun = cern.jet.math.tdouble.DoublePlusMultSecond.plusMult(0); int rows = A.rows(); for (int i = 0; i < rows; i++) { fun.multiplicator = alpha * x.getQuick(i); A.viewRow(i).assign(y, fun); } }
public void setMatrix(DoubleMatrix2D A) { DoubleProperty.DEFAULT.isSquare(A); if (A.rows() != n) { throw new IllegalArgumentException("A.rows() != n"); } R = new SparseRCDoubleMatrix2D(n, n); R.assign(A); if (!R.hasColumnIndexesSorted()) { R.sortColumnIndexes(); } factor(); }
/** * Fills all cells of the given matrix into the given histogram. * * @return <tt>histo</tt> (for convenience only). */ public static hep.aida.tdouble.DoubleIHistogram1D histogram(final hep.aida.tdouble.DoubleIHistogram1D histo, final DoubleMatrix2D matrix) { histo.fill_2D((double[]) matrix.elements(), matrix.rows(), matrix.columns(), (int) matrix.index(0, 0), matrix .rowStride(), matrix.columnStride()); return histo; }
public void run() { DoubleMatrix2D view = null; for (int r = firstRow; r < lastRow; r++) { for (int c = 0; c < n; c++) { view = matrix.viewPart(r * row_size, c * col_size, height[r], width[c]); histo[r][c].fill_2D((double[]) view.elements(), view.rows(), view.columns(), (int) view .index(0, 0), view.rowStride(), view.columnStride()); } } } });
public static DoubleMatrix2D delete(DoubleMatrix2D m, int idx, int axis) { int[] irow, icol; if (axis == 0) { irow = icat(irange(idx), irange(idx + 1, m.rows())); icol = null; } else { irow = null; icol = icat(irange(idx), irange(idx + 1, m.columns())); } return m.viewSelection(irow, icol).copy(); }
public static DoubleMatrix2D delete(DoubleMatrix2D m, int idx, int axis) { int[] irow, icol; if (axis == 0) { irow = icat(irange(idx), irange(idx + 1, m.rows())); icol = null; } else { irow = null; icol = icat(irange(idx), irange(idx + 1, m.columns())); } return m.viewSelection(irow, icol).copy(); }
public static DoubleMatrix2D delete(DoubleMatrix2D m, int idx, int axis) { int[] irow, icol; if (axis == 0) { irow = icat(irange(idx), irange(idx + 1, m.rows())); icol = null; } else { irow = null; icol = icat(irange(idx), irange(idx + 1, m.columns())); } return m.viewSelection(irow, icol).copy(); }