/** * Check if a matrix is multiplication compatible with the instance. * * @param m Matrix to check. * @throws DimensionMismatchException if the matrix is not * multiplication-compatible with instance. */ protected void checkMultiplicationCompatible(final FieldMatrix<T> m) throws DimensionMismatchException { if (getColumnDimension() != m.getRowDimension()) { throw new DimensionMismatchException(m.getRowDimension(), getColumnDimension()); } } }
/** {@inheritDoc} */ public void setRowMatrix(final int row, final FieldMatrix<T> matrix) throws OutOfRangeException, MatrixDimensionMismatchException { checkRowIndex(row); final int nCols = getColumnDimension(); if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { throw new MatrixDimensionMismatchException(matrix.getRowDimension(), matrix.getColumnDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, matrix.getEntry(0, i)); } }
/** {@inheritDoc} */ public void setColumnMatrix(final int column, final FieldMatrix<T> matrix) throws OutOfRangeException, MatrixDimensionMismatchException { checkColumnIndex(column); final int nRows = getRowDimension(); if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { throw new MatrixDimensionMismatchException(matrix.getRowDimension(), matrix.getColumnDimension(), nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, matrix.getEntry(i, 0)); } }
/** * Check if a matrix is addition compatible with the instance. * * @param m Matrix to check. * @throws MatrixDimensionMismatchException if the matrix is not * addition-compatible with instance. */ protected void checkAdditionCompatible(final FieldMatrix<T> m) throws MatrixDimensionMismatchException { if ((getRowDimension() != m.getRowDimension()) || (getColumnDimension() != m.getColumnDimension())) { throw new MatrixDimensionMismatchException(m.getRowDimension(), m.getColumnDimension(), getRowDimension(), getColumnDimension()); } }
/** * Check if a matrix is subtraction compatible with the instance. * * @param m Matrix to check. * @throws MatrixDimensionMismatchException if the matrix is not * subtraction-compatible with instance. */ protected void checkSubtractionCompatible(final FieldMatrix<T> m) throws MatrixDimensionMismatchException { if ((getRowDimension() != m.getRowDimension()) || (getColumnDimension() != m.getColumnDimension())) { throw new MatrixDimensionMismatchException(m.getRowDimension(), m.getColumnDimension(), getRowDimension(), getColumnDimension()); } }
/** * Generic copy constructor. * * @param other Instance to copy. */ public SparseFieldMatrix(FieldMatrix<T> other){ super(other.getField(), other.getRowDimension(), other.getColumnDimension()); rows = other.getRowDimension(); columns = other.getColumnDimension(); entries = new OpenIntToFieldHashMap<T>(getField()); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { setEntry(i, j, other.getEntry(i, j)); } } }
final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (m.getColumnDimension() != nCols || m.getRowDimension() != nRows) { return false;
if (b.getRowDimension() != m) { throw new DimensionMismatchException(b.getRowDimension(), m);
final int m = HBigFraction.getRowDimension();
int sign = predictedNordsieck.getRowDimension() % 2 == 0 ? -1 : 1; for (int k = predictedNordsieck.getRowDimension() - 1; k >= 0; --k) { variation = variation.add(predictedNordsieck.getEntry(k, i).multiply(sign)); sign = -sign;
throw new NonSquareMatrixException(matrix.getRowDimension(), matrix.getColumnDimension());
/** * Check if a matrix is multiplication compatible with the instance. * * @param m Matrix to check. * @throws DimensionMismatchException if the matrix is not * multiplication-compatible with instance. */ protected void checkMultiplicationCompatible(final FieldMatrix<T> m) throws DimensionMismatchException { if (getColumnDimension() != m.getRowDimension()) { throw new DimensionMismatchException(m.getRowDimension(), getColumnDimension()); } } }
/** * Check if a matrix is addition compatible with the instance. * * @param m Matrix to check. * @throws MatrixDimensionMismatchException if the matrix is not * addition-compatible with instance. */ protected void checkAdditionCompatible(final FieldMatrix<T> m) throws MatrixDimensionMismatchException { if ((getRowDimension() != m.getRowDimension()) || (getColumnDimension() != m.getColumnDimension())) { throw new MatrixDimensionMismatchException(m.getRowDimension(), m.getColumnDimension(), getRowDimension(), getColumnDimension()); } }
/** {@inheritDoc} */ public void setRowMatrix(final int row, final FieldMatrix<T> matrix) throws OutOfRangeException, MatrixDimensionMismatchException { checkRowIndex(row); final int nCols = getColumnDimension(); if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { throw new MatrixDimensionMismatchException(matrix.getRowDimension(), matrix.getColumnDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, matrix.getEntry(0, i)); } }
/** {@inheritDoc} */ public void setColumnMatrix(final int column, final FieldMatrix<T> matrix) throws OutOfRangeException, MatrixDimensionMismatchException { checkColumnIndex(column); final int nRows = getRowDimension(); if ((matrix.getRowDimension() != nRows) || (matrix.getColumnDimension() != 1)) { throw new MatrixDimensionMismatchException(matrix.getRowDimension(), matrix.getColumnDimension(), nRows, 1); } for (int i = 0; i < nRows; ++i) { setEntry(i, column, matrix.getEntry(i, 0)); } }
/** * Check if a matrix is subtraction compatible with the instance. * * @param m Matrix to check. * @throws MatrixDimensionMismatchException if the matrix is not * subtraction-compatible with instance. */ protected void checkSubtractionCompatible(final FieldMatrix<T> m) throws MatrixDimensionMismatchException { if ((getRowDimension() != m.getRowDimension()) || (getColumnDimension() != m.getColumnDimension())) { throw new MatrixDimensionMismatchException(m.getRowDimension(), m.getColumnDimension(), getRowDimension(), getColumnDimension()); } }
/** * Generic copy constructor. * * @param other Instance to copy. */ public SparseFieldMatrix(FieldMatrix<T> other){ super(other.getField(), other.getRowDimension(), other.getColumnDimension()); rows = other.getRowDimension(); columns = other.getColumnDimension(); entries = new OpenIntToFieldHashMap<T>(getField()); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { setEntry(i, j, other.getEntry(i, j)); } } }
final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (m.getColumnDimension() != nCols || m.getRowDimension() != nRows) { return false;
/** * Converts a FieldMatrix to the list expression representation. * * @param matrix * @return */ public static IAST matrix2List(final FieldMatrix<ExprFieldElement> matrix) { if (matrix == null) { return null; } final int rowSize = matrix.getRowDimension(); final int colSize = matrix.getColumnDimension(); final IAST out = F.List(); IAST currOutRow; for (int i = 0; i < rowSize; i++) { currOutRow = F.List(); out.add(currOutRow); for (int j = 0; j < colSize; j++) { IExpr expr = matrix.getEntry(i, j).getExpr(); if (expr instanceof INumber) { currOutRow.add(expr); } else { currOutRow.add(F.eval(F.Together(expr))); } } } out.addEvalFlags(IAST.IS_MATRIX); return out; }
@Override public ExprFieldElement matrixEval(final FieldMatrix<ExprFieldElement> matrix) { if (matrix.getRowDimension() == 2 && matrix.getColumnDimension() == 2) { // 2x2 matrix ExprFieldElement[] row1 = matrix.getRow(0); ExprFieldElement[] row2 = matrix.getRow(1); return row1[0].multiply(row2[1]).subtract((row1[1].multiply(row2[0]))); } if (matrix.getRowDimension() == 3 && matrix.getColumnDimension() == 3) { // 3x3 matrix ExprFieldElement[] row1 = matrix.getRow(0); ExprFieldElement[] row2 = matrix.getRow(1); ExprFieldElement[] row3 = matrix.getRow(2); return row1[0].multiply(row2[1].multiply(row3[2])).subtract( (row1[0].multiply(row2[2].multiply(row3[1])))).subtract( (row1[1].multiply(row2[0].multiply(row3[2])))).add( (row1[1].multiply(row2[2].multiply(row3[0])))).add( (row1[2].multiply(row2[0].multiply(row3[1])))).subtract( (row1[2].multiply(row2[1].multiply(row3[0])))); } final FieldLUDecomposition<ExprFieldElement> lu = new FieldLUDecomposition<ExprFieldElement>(matrix); return lu.getDeterminant(); }