/** * {@inheritDoc} */ public double add(int row, int col, double delta) { double old = get(row, col); set(row, col, old+delta); return old; }
/** * Create a {@code ArrayMatrix} from a two dimensional array. * * @param matrix2d The two dimensional array this {@code ArrayMatrix} will * represent. * @throws IllegalArgumentExceptiona if matrix2d is invalid. */ public ArrayMatrix(double[][] matrix2d) { if (matrix2d == null) throw new IllegalArgumentException("invalid matrix dimensions"); rows = matrix2d.length; if (rows < 1) throw new IllegalArgumentException("invalid matrix dimensions"); cols = matrix2d[0].length; if (cols < 1) throw new IllegalArgumentException("invalid matrix dimensions"); matrix = new double[rows*cols]; for (int i = 0; i < rows; ++i) { if (cols != matrix2d[i].length) throw new IllegalArgumentException("invalid matrix dimensions"); for (int j = 0; j < cols; ++j) set(i, j, matrix2d[i][j]); } }
/** * Create a {@code ArrayMatrix} from a two dimensional array. * * @param matrix2d The two dimensional array this {@code ArrayMatrix} will * represent. * @throws IllegalArgumentExceptiona if matrix2d is invalid. */ public ArrayMatrix(double[][] matrix2d) { if (matrix2d == null) throw new IllegalArgumentException("invalid matrix dimensions"); rows = matrix2d.length; if (rows < 1) throw new IllegalArgumentException("invalid matrix dimensions"); cols = matrix2d[0].length; if (cols < 1) throw new IllegalArgumentException("invalid matrix dimensions"); matrix = new double[rows*cols]; for (int i = 0; i < rows; ++i) { if (cols != matrix2d[i].length) throw new IllegalArgumentException("invalid matrix dimensions"); for (int j = 0; j < cols; ++j) set(i, j, matrix2d[i][j]); } }