/** * Finds the number of diagonals below the main diagonal. Useful for * converting a general matrix into a banded matrix */ public static int getNumSubDiagonals(Matrix A) { int kl = 0; for (MatrixEntry e : A) kl = Math.max(kl, e.row() - e.column()); return kl; }
/** * Finds the number of diagonals above the main diagonal. Useful for * converting a general matrix into a banded matrix */ public static int getNumSuperDiagonals(Matrix A) { int ku = 0; for (MatrixEntry e : A) ku = Math.max(ku, e.column() - e.row()); return ku; }
/** * Computes the 1 norm */ protected double norm1() { double[] rowSum = new double[numRows]; for (MatrixEntry e : this) rowSum[e.row()] += Math.abs(e.get()); return max(rowSum); }
public ArpackSym(Matrix matrix) { if (!matrix.isSquare()) throw new IllegalArgumentException("matrix must be square"); if (EXPENSIVE_CHECKS) for (MatrixEntry entry : matrix) { if (entry.get() != matrix.get(entry.column(), entry.row())) throw new IllegalArgumentException( "matrix must be symmetric"); } this.matrix = matrix; }
@Override void copy(Matrix A) { for (MatrixEntry e : A) set(e.row(), e.column(), e.get()); }
@Override public Matrix scale(double alpha) { if (alpha == 0) zero(); else if (alpha != 1) for (MatrixEntry e : this) set(e.row(), e.column(), e.get() * alpha); return this; }
public Matrix add(double alpha, Matrix B) { checkSize(B); if (alpha != 0) for (MatrixEntry e : B) add(e.row(), e.column(), alpha * e.get()); return this; }
/** * Returns an array of arrays containing a copy of the given matrix. Each * array contains one row. */ public static double[][] getArray(Matrix A) { double[][] Ad = new double[A.numRows()][A.numColumns()]; for (MatrixEntry e : A) Ad[e.row()][e.column()] = e.get(); return Ad; }
public Vector transMultAdd(double alpha, Vector x, Vector y) { checkTransMultAdd(x, y); if (alpha != 0) for (MatrixEntry e : this) y.add(e.column(), alpha * e.get() * x.get(e.row())); return y; }
public Matrix set(double alpha, Matrix B) { checkSize(B); if (alpha == 0.) return zero(); if (B == this) return scale(alpha); zero(); for (MatrixEntry e : B) if (e.get() != 0) set(e.row(), e.column(), alpha * e.get()); return this; }