/** * Compute this minus <code>m</code>. * * @param m matrix to be subtracted * @return this + m * @throws IllegalArgumentException if m is not the same size as this */ public Array2DRowFieldMatrix<T> subtract(final Array2DRowFieldMatrix<T> m) throws IllegalArgumentException { // safety check checkSubtractionCompatible(m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final T[][] outData = buildArray(getField(), rowCount, columnCount); for (int row = 0; row < rowCount; row++) { final T[] dataRow = data[row]; final T[] mRow = m.data[row]; final T[] outDataRow = outData[row]; for (int col = 0; col < columnCount; col++) { outDataRow[col] = dataRow[col].subtract(mRow[col]); } } return new Array2DRowFieldMatrix<T>(outData, false); }
/** {@inheritDoc} */ @Override public FieldMatrix<T> add(final FieldMatrix<T> m) throws IllegalArgumentException { try { return add((Array2DRowFieldMatrix<T>) m); } catch (ClassCastException cce) { return super.add(m); } }
/** * Compute the sum of this and <code>m</code>. * * @param m matrix to be added * @return this + m * @throws IllegalArgumentException if m is not the same size as this */ public Array2DRowFieldMatrix<T> add(final Array2DRowFieldMatrix<T> m) throws IllegalArgumentException { // safety check checkAdditionCompatible(m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final T[][] outData = buildArray(getField(), rowCount, columnCount); for (int row = 0; row < rowCount; row++) { final T[] dataRow = data[row]; final T[] mRow = m.data[row]; final T[] outDataRow = outData[row]; for (int col = 0; col < columnCount; col++) { outDataRow[col] = dataRow[col].add(mRow[col]); } } return new Array2DRowFieldMatrix<T>(outData, false); }
/** {@inheritDoc} */ @Override public FieldMatrix<T> copy() { return new Array2DRowFieldMatrix<T>(copyOut(), false); }
/** {@inheritDoc} */ @Override public FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension) throws IllegalArgumentException { return new Array2DRowFieldMatrix<T>(getField(), rowDimension, columnDimension); }
/** * Create a new (column) FieldMatrix<T> using <code>v</code> as the * data for the unique column of the <code>v.length x 1</code> matrix * created. * <p>The input array is copied, not referenced.</p> * * @param v column vector holding data for new matrix */ public Array2DRowFieldMatrix(final T[] v) { super(extractField(v)); final int nRows = v.length; data = buildArray(getField(), nRows, 1); for (int row = 0; row < nRows; row++) { data[row][0] = v[row]; } }
/** * Returns a fresh copy of the underlying data array. * * @return a copy of the underlying data array. */ private T[][] copyOut() { final int nRows = this.getRowDimension(); final T[][] out = buildArray(getField(), nRows, getColumnDimension()); // can't copy 2-d array in one shot, otherwise get row references for (int i = 0; i < nRows; i++) { System.arraycopy(data[i], 0, out[i], 0, data[i].length); } return out; }
/** * Returns the result of postmultiplying this by <code>m</code>. * @param m matrix to postmultiply by * @return this*m * @throws IllegalArgumentException * if columnDimension(this) != rowDimension(m) */ public Array2DRowFieldMatrix<T> multiply(final Array2DRowFieldMatrix<T> m) throws IllegalArgumentException { // safety check checkMultiplicationCompatible(m); final int nRows = this.getRowDimension(); final int nCols = m.getColumnDimension(); final int nSum = this.getColumnDimension(); final T[][] outData = buildArray(getField(), nRows, nCols); for (int row = 0; row < nRows; row++) { final T[] dataRow = data[row]; final T[] outDataRow = outData[row]; for (int col = 0; col < nCols; col++) { T sum = getField().getZero(); for (int i = 0; i < nSum; i++) { sum = sum.add(dataRow[i].multiply(m.data[i][col])); } outDataRow[col] = sum; } } return new Array2DRowFieldMatrix<T>(outData, false); }
/** {@inheritDoc} */ @Override public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); visitor.start(getRowDimension(), getColumnDimension(), startRow, endRow, startColumn, endColumn); for (int i = startRow; i <= endRow; ++i) { final T[] rowI = data[i]; for (int j = startColumn; j <= endColumn; ++j) { visitor.visit(i, j, rowI[j]); } } return visitor.end(); }
/** {@inheritDoc} */ public FieldMatrix<T> getU() { if ((cachedU == null) && !singular) { final int m = pivot.length; cachedU = new Array2DRowFieldMatrix<T>(field, m, m); for (int i = 0; i < m; ++i) { final T[] luI = lu[i]; for (int j = i; j < m; ++j) { cachedU.setEntry(i, j, luI[j]); } } } return cachedU; }
/** * Create a new FieldMatrix<T> using the input array as the underlying * data array. * <p>The input array is copied, not referenced. This constructor has * the same effect as calling {@link #Array2DRowFieldMatrix(FieldElement[][], boolean)} * with the second argument set to <code>true</code>.</p> * * @param d data for new matrix * @throws IllegalArgumentException if <code>d</code> is not rectangular * (not all rows have the same length) or empty * @throws NullPointerException if <code>d</code> is null * @see #Array2DRowFieldMatrix(FieldElement[][], boolean) */ public Array2DRowFieldMatrix(final T[][] d) throws IllegalArgumentException, NullPointerException { super(extractField(d)); copyIn(d); }
new Array2DRowFieldMatrix<Complex>(cfft); final FieldLUDecompositionImpl<Complex> luDecomp = new FieldLUDecompositionImpl<Complex>(cmat); final Complex det = luDecomp.getDeterminant(); cmat.scalarMultiply(new Complex(1d / det.abs(), 0)); cfft = cmat.getData(); for (int y = 0; y < h; y++)
AT_LEAST_ONE_COLUMN_MESSAGE); data = buildArray(getField(), subMatrix.length, nCols); for (int i = 0; i < data.length; ++i) { if (subMatrix[i].length != nCols) {
/** {@inheritDoc} */ @Override public T[][] getData() { return copyOut(); }
/** * Create a new FieldMatrix<T> with the supplied row and column dimensions. * * @param field field to which the elements belong * @param rowDimension the number of rows in the new matrix * @param columnDimension the number of columns in the new matrix * @throws IllegalArgumentException if row or column dimension is not * positive */ public Array2DRowFieldMatrix(final Field<T> field, final int rowDimension, final int columnDimension) throws IllegalArgumentException { super(field, rowDimension, columnDimension); data = buildArray(field, rowDimension, columnDimension); }
/** * Returns a fresh copy of the underlying data array. * * @return a copy of the underlying data array. */ private T[][] copyOut() { final int nRows = this.getRowDimension(); final T[][] out = buildArray(getField(), nRows, getColumnDimension()); // can't copy 2-d array in one shot, otherwise get row references for (int i = 0; i < nRows; i++) { System.arraycopy(data[i], 0, out[i], 0, data[i].length); } return out; }
/** * Returns the result of postmultiplying this by <code>m</code>. * @param m matrix to postmultiply by * @return this*m * @throws IllegalArgumentException * if columnDimension(this) != rowDimension(m) */ public Array2DRowFieldMatrix<T> multiply(final Array2DRowFieldMatrix<T> m) throws IllegalArgumentException { // safety check checkMultiplicationCompatible(m); final int nRows = this.getRowDimension(); final int nCols = m.getColumnDimension(); final int nSum = this.getColumnDimension(); final T[][] outData = buildArray(getField(), nRows, nCols); for (int row = 0; row < nRows; row++) { final T[] dataRow = data[row]; final T[] outDataRow = outData[row]; for (int col = 0; col < nCols; col++) { T sum = getField().getZero(); for (int i = 0; i < nSum; i++) { sum = sum.add(dataRow[i].multiply(m.data[i][col])); } outDataRow[col] = sum; } } return new Array2DRowFieldMatrix<T>(outData, false); }
/** {@inheritDoc} */ @Override public T walkInColumnOrder(final FieldMatrixPreservingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws MatrixIndexException, MatrixVisitorException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); visitor.start(getRowDimension(), getColumnDimension(), startRow, endRow, startColumn, endColumn); for (int j = startColumn; j <= endColumn; ++j) { for (int i = startRow; i <= endRow; ++i) { visitor.visit(i, j, data[i][j]); } } return visitor.end(); }
/** {@inheritDoc} */ public FieldMatrix<T> getU() { if ((cachedU == null) && !singular) { final int m = pivot.length; cachedU = new Array2DRowFieldMatrix<T>(field, m, m); for (int i = 0; i < m; ++i) { final T[] luI = lu[i]; for (int j = i; j < m; ++j) { cachedU.setEntry(i, j, luI[j]); } } } return cachedU; }
/** * Create a new (column) FieldMatrix<T> using <code>v</code> as the * data for the unique column of the <code>v.length x 1</code> matrix * created. * <p>The input array is copied, not referenced.</p> * * @param v column vector holding data for new matrix */ public Array2DRowFieldMatrix(final T[] v) { super(extractField(v)); final int nRows = v.length; data = buildArray(getField(), nRows, 1); for (int row = 0; row < nRows; row++) { data[row][0] = v[row]; } }