/** * Constructs a new matrix and copies the initial values from the parameter matrix. * * @param matrix The matrix to copy. */ public GeneralMatrix(final GeneralMatrix matrix) { mat = new DMatrixRMaj(matrix.mat); }
/** * Extract col to provided array. * * @param col * @param array */ public void getColumn(int col, double[] array) { for (int j = 0; j < array.length; j++) { array[j] = mat.get(j, col); } }
/** Sets each value of the matrix to 0.0. */ @Override public void setZero() { mat.zero(); }
public void setRow(int row, double... values) { if (values.length != mat.getNumCols()) { throw new IllegalArgumentException( "Call setRow received an array of length " + values.length + ". " + "The dimensions of the matrix is " + mat.getNumRows() + " by " + mat.getNumCols() + "."); } for (int i = 0; i < values.length; i++) { mat.set(row, i, values[i]); } }
/** * Sets the value of the row, column position in the matrix. * * @param row * @param column * @param value */ @Override public void setElement(int row, int column, double value) { mat.set(row, column, value); }
/** Creates a new matrix initialized to the specified values. */ public Matrix3( double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22) { mat = new DMatrix3x3(m00, m01, m02, m10, m11, m12, m20, m21, m22); }
/** * Gets the number of rows in the matrix. * * @return The number of rows in the matrix. */ @Override public int getNumRow() { return mat.getNumRows(); }
/** * Gets the number of columns in the matrix. * * @return The number of columns in the matrix. */ @Override public int getNumCol() { return mat.getNumCols(); }
/** * Extract row to provided array * * @param row * @param array */ public void getRow(int row, double[] array) { for (int i = 0; i < array.length; i++) { array[i] = mat.get(row, i); } }
/** * Sets the value of the row, column position in the matrix. * * @param row * @param column * @param value */ @Override public void setElement(int row, int column, double value) { mat.set(row, column, value); }
/** * Update in place to the provided matrix (row-order). * * @param matrix */ public void set(double[] matrix) { mat.setData(matrix); }
/** * Constructs a square identity matrix of size {@code size} × {@code size}. * * @param size The number of rows and columns. */ public GeneralMatrix(final int size) { mat = new DMatrixRMaj(size, size); setIdentity(); }
/** * Returns the value at the row, column position in the matrix. * * @param row * @param column * @return Matrix value at the given row and column. */ @Override public double getElement(int row, int column) { return mat.get(row, column); }
/** Constructs a 3×3 matrix from the specified affine transform. */ public Matrix3(final AffineTransform transform) { mat = new DMatrix3x3(); setMatrix(transform); }
/** * Extract col to provided array. * * @param col * @param array */ public void getColumn(int col, double[] array) { for (int j = 0; j < array.length; j++) { array[j] = mat.get(j, col); } }
/** * Creates a matrix of size {@code numRow} × {@code numCol}. Elements on the * diagonal <var>j==i</var> are set to 1. * * @param numRow Number of rows. * @param numCol Number of columns. */ public GeneralMatrix(final int numRow, final int numCol) { mat = new DMatrixRMaj(numRow, numCol); setIdentity(); }
/** * Extract row to provided array * * @param row * @param array */ public void getRow(int row, double[] array) { for (int i = 0; i < array.length; i++) { array[i] = mat.get(row, i); } }
@Override public void mul(double scalar, Matrix matrix) { DMatrix3x3 ret = new DMatrix3x3(); CommonOps_DDF3.scale(scalar, internal(matrix), ret); mat = ret; }
/** * Returns the value at the row, column position in the matrix. * * @param row * @param column * @return Matrix value at the given row and column. */ @Override public double getElement(int row, int column) { return mat.get(row, column); }
/** * Resize the matrix to the specified number of rows and columns (preserving remaining * elements). * * @param numRows The new number of rows in the matrix. * @param numCols The new number of columns in the matrix. */ public void setSize(int numRows, int numCols) { if (numRows != mat.numCols || numCols != mat.numCols) { // grow or shrink DMatrixRMaj ret = new DMatrixRMaj(numRows, numCols); CommonOps_DDRM.extract(mat, 0, numRows, 0, numCols, ret, 0, 0); mat = ret; } }