/** * <p> * Returns the result of matrix subtraction:<br> * <br> * c = a - b <br> * <br> * where c is the returned matrix, a is this matrix, and b is the passed in matrix. * </p> * * @see CommonOps#subtract(org.ejml.data.D1Matrix64F , org.ejml.data.D1Matrix64F , org.ejml.data.D1Matrix64F) * * @param b m by n matrix. Not modified. * * @return The results of this operation. */ public T minus( T b ) { T ret = copy(); CommonOps.subtract(getMatrix(), b.getMatrix(), ret.getMatrix()); return ret; }
/** * Creates and returns a matrix which is idential to this one. * * @return A new identical matrix. */ public T copy() { T ret = createMatrix(mat.numRows,mat.numCols); ret.getMatrix().set(this.getMatrix()); return ret; }
/** * Computes the dot product (a.k.a. inner product) between this vector and vector 'v'. * * @param v The second vector in the dot product. Not modified. * @return dot product */ public double dot( T v ) { if( !isVector() ) { throw new IllegalArgumentException("'this' matrix is not a vector."); } else if( !v.isVector() ) { throw new IllegalArgumentException("'v' matrix is not a vector."); } return VectorVectorMult.innerProd(mat,v.getMatrix()); }
/** * <p> * Computes the Kronecker product between this matrix and the provided B matrix:<br> * <br> * C = kron(A,B) * </p> * @see CommonOps#kron(DenseMatrix64F, DenseMatrix64F, DenseMatrix64F) * * @param B The right matrix in the operation. Not modified. * @return Kronecker product between this matrix and B. */ public T kron( T B ) { T ret = createMatrix(mat.numRows*B.numRows(),mat.numCols*B.numCols()); CommonOps.kron(mat,B.getMatrix(),ret.getMatrix()); return ret; }
int maxRow = insertRow + B.numRows(); int maxCol = insertCol + B.numCols(); int N = Math.max(maxCol,mat.numCols); ret = createMatrix(M,N); ret.insertIntoThis(0,0,this); } else { ret = copy(); ret.insertIntoThis(insertRow,insertCol,B);
/** * Checks to see if matrix 'a' is the same as this matrix within the specified * tolerance. * * @param a The matrix it is being compared against. * @param tol How similar they must be to be equals. * @return If they are equal within tolerance of each other. */ public boolean isIdentical(T a, double tol) { return MatrixFeatures.isIdentical(mat,a.getMatrix(),tol); }
/** * <p> * Loads a new matrix from a CSV file. For the file format see {@link MatrixIO}. * </p> * * @see MatrixIO#loadCSV(String) * * @param fileName File which is to be loaded. * @return The matrix. * @throws IOException */ public T loadCSV( String fileName ) throws IOException { RealMatrix64F mat = MatrixIO.loadCSV(fileName); T ret = createMatrix(1,1); // see if its a DenseMatrix64F if( mat instanceof DenseMatrix64F ) { ret.mat = (DenseMatrix64F)mat; } else { // if not convert it into one and wrap it ret.mat = new DenseMatrix64F(mat); } return ret; }
/** * <p> * Computes the Kronecker product between this matrix and the provided B matrix:<br> * <br> * C = kron(A,B) * </p> * @see CommonOps#kron(DenseMatrix64F, DenseMatrix64F, DenseMatrix64F) * * @param B The right matrix in the operation. Not modified. * @return Kronecker product between this matrix and B. */ public T kron( T B ) { T ret = createMatrix(mat.numRows*B.numRows(),mat.numCols*B.numCols()); CommonOps.kron(mat,B.getMatrix(),ret.getMatrix()); return ret; }
int maxRow = insertRow + B.numRows(); int maxCol = insertCol + B.numCols(); int N = Math.max(maxCol,mat.numCols); ret = createMatrix(M,N); ret.insertIntoThis(0,0,this); } else { ret = copy(); ret.insertIntoThis(insertRow,insertCol,B);
/** * Sets the elements in this matrix to be equal to the elements in the passed in matrix. * Both matrix must have the same dimension. * * @param a The matrix whose value this matrix is being set to. */ public void set( T a ) { mat.set(a.getMatrix()); }
/** * Creates and returns a matrix which is idential to this one. * * @return A new identical matrix. */ public T copy() { T ret = createMatrix(mat.numRows,mat.numCols); ret.getMatrix().set(this.getMatrix()); return ret; }
/** * <p> * Returns the result of matrix subtraction:<br> * <br> * c = a - b <br> * <br> * where c is the returned matrix, a is this matrix, and b is the passed in matrix. * </p> * * @see CommonOps#subtract(org.ejml.data.D1Matrix64F , org.ejml.data.D1Matrix64F , org.ejml.data.D1Matrix64F) * * @param b m by n matrix. Not modified. * * @return The results of this operation. */ public T minus( T b ) { T ret = copy(); CommonOps.subtract(getMatrix(), b.getMatrix(), ret.getMatrix()); return ret; }
/** * <p> * Computes the Kronecker product between this matrix and the provided B matrix:<br> * <br> * C = kron(A,B) * </p> * @see CommonOps#kron(DenseMatrix64F, DenseMatrix64F, DenseMatrix64F) * * @param B The right matrix in the operation. Not modified. * @return Kronecker product between this matrix and B. */ public T kron( T B ) { T ret = createMatrix(mat.numRows*B.numRows(),mat.numCols*B.numCols()); CommonOps.kron(mat,B.getMatrix(),ret.getMatrix()); return ret; }
int maxRow = insertRow + B.numRows(); int maxCol = insertCol + B.numCols(); int N = Math.max(maxCol,mat.numCols); ret = createMatrix(M,N); ret.insertIntoThis(0,0,this); } else { ret = copy(); ret.insertIntoThis(insertRow,insertCol,B);
/** * Computes the dot product (a.k.a. inner product) between this vector and vector 'v'. * * @param v The second vector in the dot product. Not modified. * @return dot product */ public double dot( T v ) { if( !isVector() ) { throw new IllegalArgumentException("'this' matrix is not a vector."); } else if( !v.isVector() ) { throw new IllegalArgumentException("'v' matrix is not a vector."); } return VectorVectorMult.innerProd(mat,v.getMatrix()); }
/** * Copy matrix B into this matrix at location (insertRow, insertCol). * * @param insertRow First row the matrix is to be inserted into. * @param insertCol First column the matrix is to be inserted into. * @param B The matrix that is being inserted. */ public void insertIntoThis(int insertRow, int insertCol, T B) { CommonOps.insert(B.getMatrix(), mat, insertRow,insertCol); }
/** * Creates and returns a matrix which is idential to this one. * * @return A new identical matrix. */ public T copy() { T ret = createMatrix(mat.numRows,mat.numCols); ret.getMatrix().set(this.getMatrix()); return ret; }