Class SimpleBase<T extends SimpleBase<T>>

java.lang.Object
org.ejml.simple.SimpleBase<T>
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
SimpleMatrix

public abstract class SimpleBase<T extends SimpleBase<T>>
extends java.lang.Object
implements java.io.Serializable
Parent of SimpleMatrix implements all the standard matrix operations and uses generics to allow the returned matrix type to be changed. This class should be extended instead of SimpleMatrix.
See Also:
Serialized Form
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected AutomaticSimpleMatrixConvert convertType  
    protected org.ejml.data.Matrix mat
    Internal matrix which this is a wrapper around.
    protected SimpleOperations ops  
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected SimpleBase()  
    protected SimpleBase​(int numRows, int numCols)  
  • Method Summary

    Modifier and Type Method Description
    int bits()
    Size of internal array elements.
    T cols​(int begin, int end)
    Extracts the specified rows from the matrix.
    T combine​(int insertRow, int insertCol, T B)
    Creates a new matrix that is a combination of this matrix and matrix B.
    T concatColumns​(SimpleBase... matrices)
    Concatinates all the matrices together along their columns.
    T concatRows​(SimpleBase... matrices)
    Concatinates all the matrices together along their columns.
    double conditionP2()
    The condition p = 2 number of a matrix is used to measure the sensitivity of the linear system Ax=b.
    void convertToDense()
    Switches from a sparse to dense matrix
    void convertToSparse()
    Switches from a dense to sparse matrix
    T copy()
    Creates and returns a matrix which is idential to this one.
    T createLike()
    Creates a matrix that is the same type and shape
    protected abstract T createMatrix​(int numRows, int numCols, org.ejml.data.MatrixType type)
    Used internally for creating new instances of SimpleMatrix.
    double determinant()
    Computes the determinant of the matrix.
    T diag()
    If a vector then a square matrix is returned if a matrix then a vector of diagonal ements is returned
    T divide​(double val)
    Returns the result of dividing each element by 'val': bi,j = ai,j/val
    double dot​(T v)
    Computes the dot product (a.k.a.
    SimpleEVD<T> eig()
    Returns the Eigen Value Decomposition (EVD) of this matrix.
    T elementDiv​(T b)
    Returns a matrix which is the result of an element by element division of 'this' and 'b': ci,j = ai,j/bi,j
    T elementExp()
    Returns a matrix which is the result of an element by element exp of 'this' ci,j = Math.exp(ai,j)
    T elementLog()
    Returns a matrix which is the result of an element by element exp of 'this' ci,j = Math.log(ai,j)
    double elementMaxAbs()
    Returns the maximum absolute value of all the elements in this matrix.
    double elementMinAbs()
    Returns the minimum absolute value of all the elements in this matrix.
    T elementMult​(T b)
    Returns a matrix which is the result of an element by element multiplication of 'this' and 'b': ci,j = ai,j*bi,j
    T elementPower​(double b)
    Returns a matrix which is the result of an element by element power of 'this' and 'b': ci,j = ai,j ^ b
    T elementPower​(T b)
    Returns a matrix which is the result of an element by element power of 'this' and 'b': ci,j = ai,j ^ bi,j
    double elementSum()
    Computes the sum of all the elements in the matrix.
    void equation​(java.lang.String equation, java.lang.Object... variables)
    Allows you to perform an equation in-place on this matrix by specifying the right hand side.
    T extractMatrix​(int y0, int y1, int x0, int x1)
    Creates a new SimpleMatrix which is a submatrix of this matrix.
    T extractVector​(boolean extractRow, int element)
    Extracts a row or column from this matrix.
    void fill​(double val)
    Sets all the elements in this matrix equal to the specified value.

    aij = val
    double get​(int index)
    Returns the value of the matrix at the specified index of the 1D row major array.
    double get​(int row, int col)
    Returns the value of the specified matrix element.
    void get​(int row, int col, org.ejml.data.Complex_F64 output)
    Used to get the complex value of a matrix element.
    org.ejml.data.CMatrixRMaj getCDRM()  
    org.ejml.data.DMatrixRMaj getDDRM()  
    org.ejml.data.DMatrixSparseCSC getDSCC()  
    org.ejml.data.FMatrixRMaj getFDRM()  
    org.ejml.data.FMatrixSparseCSC getFSCC()  
    int getIndex​(int row, int col)
    Returns the index in the matrix's array.
    <InnerType extends org.ejml.data.Matrix>
    InnerType
    getMatrix()
    Returns a reference to the matrix that it uses internally.
    int getNumElements()
    Returns the number of elements in this matrix, which is equal to the number of rows times the number of columns.
    org.ejml.data.MatrixType getType()
    Returns the type of matrix is is wrapping.
    org.ejml.data.ZMatrixRMaj getZDRM()  
    boolean hasUncountable()
    Checks to see if any of the elements in this matrix are either NaN or infinite.
    void insertIntoThis​(int insertRow, int insertCol, T B)
    Copy matrix B into this matrix at location (insertRow, insertCol).
    T invert()
    Returns the inverse of this matrix.

    b = a-1
    void invoke​(java.lang.reflect.Method m, java.lang.Object... inputs)  
    boolean isIdentical​(T a, double tol)
    Checks to see if matrix 'a' is the same as this matrix within the specified tolerance.
    boolean isInBounds​(int row, int col)
    Returns true of the specified matrix element is valid element inside this matrix.
    boolean isVector()
    Returns true if this matrix is a vector.
    org.ejml.data.DMatrixIterator iterator​(boolean rowMajor, int minRow, int minCol, int maxRow, int maxCol)
    Creates a new iterator for traversing through a submatrix inside this matrix.
    T kron​(T B)
    Computes the Kronecker product between this matrix and the provided B matrix:

    C = kron(A,B)
    static SimpleMatrix loadBinary​(java.lang.String fileName)
    Loads a new matrix from a serialized binary file.
    T loadCSV​(java.lang.String fileName)
    Loads a new matrix from a CSV file.
    protected static SimpleOperations lookupOps​(org.ejml.data.MatrixType type)  
    T minus​(double b)
    Returns the result of matrix-double subtraction:

    c = a - b

    where c is the returned matrix, a is this matrix, and b is the passed in double.
    T minus​(T B)
    Returns the result of matrix subtraction:

    c = a - b

    where c is the returned matrix, a is this matrix, and b is the passed in matrix.
    T mult​(T B)
    Returns a matrix which is the result of matrix multiplication:

    c = a * b

    where c is the returned matrix, a is this matrix, and b is the passed in matrix.
    T negative()
    Returns a new matrix whose elements are the negative of 'this' matrix's elements.

    bij = -aij
    double normF()
    Computes the Frobenius normal of the matrix:

    normF = Sqrt{ ∑i=1:mj=1:n { aij2} }
    int numCols()
    Returns the number of columns in this matrix.
    int numRows()
    Returns the number of rows in this matrix.
    T plus​(double b)
    Returns the result of scalar addition:

    c = a + b

    where c is the returned matrix, a is this matrix, and b is the passed in double.
    T plus​(double beta, T B)
    Performs a matrix addition and scale operation.

    c = a + β*b

    where c is the returned matrix, a is this matrix, and b is the passed in matrix.
    T plus​(T B)
    Returns the result of matrix addition:

    c = a + b

    where c is the returned matrix, a is this matrix, and b is the passed in matrix.
    void print()
    Prints the matrix to standard out.
    void print​(java.lang.String format)
    Prints the matrix to standard out given a PrintStream.printf(java.lang.String, java.lang.Object...) style floating point format, e.g.
    void printDimensions()
    Prints the number of rows and column in this matrix.
    T pseudoInverse()
    Computes the Moore-Penrose pseudo-inverse
    void reshape​(int numRows, int numCols)
    Reshapes the matrix to the specified number of rows and columns.
    T rows​(int begin, int end)
    Extracts the specified rows from the matrix.
    void saveToFileBinary​(java.lang.String fileName)
    Saves this matrix to a file as a serialized binary object.
    void saveToFileCSV​(java.lang.String fileName)
    Saves this matrix to a file in a CSV format.
    T scale​(double val)
    Returns the result of scaling each element by 'val':
    bi,j = val*ai,j
    void set​(int index, double value)
    Assigns an element a value based on its index in the internal array..
    void set​(int row, int col, double value)
    Assigns the element in the Matrix to the specified value.
    void set​(int row, int col, double real, double imaginary)
    Used to set the complex value of a matrix element.
    void set​(T a)
    Sets the elements in this matrix to be equal to the elements in the passed in matrix.
    void setColumn​(int column, int startRow, double... values)
    Assigns consecutive elements inside a column to the provided array.

    A(offset:(offset + values.length),column) = values
    protected void setMatrix​(org.ejml.data.Matrix mat)  
    void setRow​(int row, int startColumn, double... values)
    Assigns consecutive elements inside a row to the provided array.

    A(row,offset:(offset + values.length)) = values
    T solve​(T B)
    Solves for X in the following equation:

    x = a-1b

    where 'a' is this matrix and 'b' is an n by p matrix.
    SimpleSVD<T> svd()
    Computes a full Singular Value Decomposition (SVD) of this matrix with the eigenvalues ordered from largest to smallest.
    SimpleSVD<T> svd​(boolean compact)
    Computes the SVD in either compact format or full format.
    java.lang.String toString()
    Converts the array into a string format for display purposes.
    double trace()
    Computes the trace of the matrix.
    T transpose()
    Returns the transpose of this matrix.
    aT
    protected abstract T wrapMatrix​(org.ejml.data.Matrix m)  
    void zero()
    Sets all the elements in the matrix equal to zero.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • SimpleBase

      protected SimpleBase​(int numRows, int numCols)
    • SimpleBase

      protected SimpleBase()
  • Method Details

    • createMatrix

      protected abstract T createMatrix​(int numRows, int numCols, org.ejml.data.MatrixType type)
      Used internally for creating new instances of SimpleMatrix. If SimpleMatrix is extended by another class this function should be overridden so that the returned matrices are of the correct type.
      Parameters:
      numRows - number of rows in the new matrix.
      numCols - number of columns in the new matrix.
      type - Type of matrix it should create
      Returns:
      A new matrix.
    • wrapMatrix

      protected abstract T wrapMatrix​(org.ejml.data.Matrix m)
    • getMatrix

      public <InnerType extends org.ejml.data.Matrix> InnerType getMatrix()

      Returns a reference to the matrix that it uses internally. This is useful when an operation is needed that is not provided by this class.

      Returns:
      Reference to the internal DMatrixRMaj.
    • getDDRM

      public org.ejml.data.DMatrixRMaj getDDRM()
    • getFDRM

      public org.ejml.data.FMatrixRMaj getFDRM()
    • getZDRM

      public org.ejml.data.ZMatrixRMaj getZDRM()
    • getCDRM

      public org.ejml.data.CMatrixRMaj getCDRM()
    • getDSCC

      public org.ejml.data.DMatrixSparseCSC getDSCC()
    • getFSCC

      public org.ejml.data.FMatrixSparseCSC getFSCC()
    • lookupOps

      protected static SimpleOperations lookupOps​(org.ejml.data.MatrixType type)
    • transpose

      public T transpose()

      Returns the transpose of this matrix.
      aT

      Returns:
      A matrix that is n by m.
      See Also:
      CommonOps_DDRM.transpose(DMatrixRMaj, DMatrixRMaj)
    • mult

      public T mult​(T B)

      Returns a matrix which is the result of matrix multiplication:

      c = a * b

      where c is the returned matrix, a is this matrix, and b is the passed in matrix.

      Parameters:
      B - A matrix that is n by bn. Not modified.
      Returns:
      The results of this operation.
      See Also:
      CommonOps_DDRM.mult(DMatrix1Row, DMatrix1Row, DMatrix1Row)
    • kron

      public T kron​(T B)

      Computes the Kronecker product between this matrix and the provided B matrix:

      C = kron(A,B)

      Parameters:
      B - The right matrix in the operation. Not modified.
      Returns:
      Kronecker product between this matrix and B.
      See Also:
      CommonOps_DDRM.kron(DMatrixRMaj, DMatrixRMaj, DMatrixRMaj)
    • plus

      public T plus​(T B)

      Returns the result of matrix addition:

      c = a + b

      where c is the returned matrix, a is this matrix, and b is the passed in matrix.

      Parameters:
      B - m by n matrix. Not modified.
      Returns:
      The results of this operation.
      See Also:
      CommonOps_DDRM.mult(DMatrix1Row, DMatrix1Row, DMatrix1Row)
    • minus

      public T minus​(T B)

      Returns the result of matrix subtraction:

      c = a - b

      where c is the returned matrix, a is this matrix, and b is the passed in matrix.

      Parameters:
      B - m by n matrix. Not modified.
      Returns:
      The results of this operation.
      See Also:
      CommonOps_DDRM.subtract(DMatrixD1, DMatrixD1, DMatrixD1)
    • minus

      public T minus​(double b)

      Returns the result of matrix-double subtraction:

      c = a - b

      where c is the returned matrix, a is this matrix, and b is the passed in double.

      Parameters:
      b - Value subtracted from each element
      Returns:
      The results of this operation.
      See Also:
      CommonOps_DDRM.subtract(DMatrixD1, double, DMatrixD1)
    • plus

      public T plus​(double b)

      Returns the result of scalar addition:

      c = a + b

      where c is the returned matrix, a is this matrix, and b is the passed in double.

      Parameters:
      b - Value added to each element
      Returns:
      A matrix that contains the results.
      See Also:
      CommonOps_DDRM.add(DMatrixD1, double, DMatrixD1)
    • plus

      public T plus​(double beta, T B)

      Performs a matrix addition and scale operation.

      c = a + β*b

      where c is the returned matrix, a is this matrix, and b is the passed in matrix.

      Parameters:
      B - m by n matrix. Not modified.
      Returns:
      A matrix that contains the results.
      See Also:
      CommonOps_DDRM.add(DMatrixD1, double, DMatrixD1, DMatrixD1)
    • dot

      public double dot​(T v)
      Computes the dot product (a.k.a. inner product) between this vector and vector 'v'.
      Parameters:
      v - The second vector in the dot product. Not modified.
      Returns:
      dot product
    • isVector

      public boolean isVector()
      Returns true if this matrix is a vector. A vector is defined as a matrix that has either one row or column.
      Returns:
      Returns true for vectors and false otherwise.
    • scale

      public T scale​(double val)

      Returns the result of scaling each element by 'val':
      bi,j = val*ai,j

      Parameters:
      val - The multiplication factor.
      Returns:
      The scaled matrix.
      See Also:
      CommonOps_DDRM.scale(double, DMatrixD1)
    • divide

      public T divide​(double val)

      Returns the result of dividing each element by 'val': bi,j = ai,j/val

      Parameters:
      val - Divisor.
      Returns:
      Matrix with its elements divided by the specified value.
      See Also:
      CommonOps_DDRM.divide(DMatrixD1, double)
    • invert

      public T invert()

      Returns the inverse of this matrix.

      b = a-1

      If the matrix could not be inverted then SingularMatrixException is thrown. Even if no exception is thrown the matrix could still be singular or nearly singular.

      Returns:
      The inverse of this matrix.
      See Also:
      CommonOps_DDRM.invert(DMatrixRMaj, DMatrixRMaj)
    • pseudoInverse

      public T pseudoInverse()

      Computes the Moore-Penrose pseudo-inverse

      Returns:
      inverse computed using the pseudo inverse.
    • solve

      public T solve​(T B)

      Solves for X in the following equation:

      x = a-1b

      where 'a' is this matrix and 'b' is an n by p matrix.

      If the system could not be solved then SingularMatrixException is thrown. Even if no exception is thrown 'a' could still be singular or nearly singular.

      Parameters:
      B - n by p matrix. Not modified.
      Returns:
      The solution for 'x' that is n by p.
      See Also:
      CommonOps_DDRM.solve(DMatrixRMaj, DMatrixRMaj, DMatrixRMaj)
    • set

      public void set​(T a)
      Sets the elements in this matrix to be equal to the elements in the passed in matrix. Both matrix must have the same dimension.
      Parameters:
      a - The matrix whose value this matrix is being set to.
    • fill

      public void fill​(double val)

      Sets all the elements in this matrix equal to the specified value.

      aij = val

      Parameters:
      val - The value each element is set to.
      See Also:
      CommonOps_DDRM.fill(DMatrixD1, double)
    • zero

      public void zero()
      Sets all the elements in the matrix equal to zero.
      See Also:
      CommonOps_DDRM.fill(DMatrixD1, double)
    • normF

      public double normF()

      Computes the Frobenius normal of the matrix:

      normF = Sqrt{ ∑i=1:mj=1:n { aij2} }

      Returns:
      The matrix's Frobenius normal.
      See Also:
      NormOps_DDRM.normF(DMatrixD1)
    • conditionP2

      public double conditionP2()

      The condition p = 2 number of a matrix is used to measure the sensitivity of the linear system Ax=b. A value near one indicates that it is a well conditioned matrix.

      Returns:
      The condition number.
      See Also:
      NormOps_DDRM.conditionP2(DMatrixRMaj)
    • determinant

      public double determinant()
      Computes the determinant of the matrix.
      Returns:
      The determinant.
      See Also:
      CommonOps_DDRM.det(DMatrixRMaj)
    • trace

      public double trace()

      Computes the trace of the matrix.

      Returns:
      The trace of the matrix.
      See Also:
      CommonOps_DDRM.trace(DMatrix1Row)
    • reshape

      public void reshape​(int numRows, int numCols)

      Reshapes the matrix to the specified number of rows and columns. If the total number of elements is ≤ number of elements it had before the data is saved. Otherwise a new internal array is declared and the old data lost.

      This is equivalent to calling A.getMatrix().reshape(numRows,numCols,false).

      Parameters:
      numRows - The new number of rows in the matrix.
      numCols - The new number of columns in the matrix.
      See Also:
      DMatrixRMaj.reshape(int, int, boolean)
    • set

      public void set​(int row, int col, double value)
      Assigns the element in the Matrix to the specified value. Performs a bounds check to make sure the requested element is part of the matrix.
      Parameters:
      row - The row of the element.
      col - The column of the element.
      value - The element's new value.
    • set

      public void set​(int index, double value)
      Assigns an element a value based on its index in the internal array..
      Parameters:
      index - The matrix element that is being assigned a value.
      value - The element's new value.
    • set

      public void set​(int row, int col, double real, double imaginary)
      Used to set the complex value of a matrix element.
      Parameters:
      row - The row of the element.
      col - The column of the element.
      real - Real component of assigned value
      imaginary - Imaginary component of assigned value
    • setRow

      public void setRow​(int row, int startColumn, double... values)

      Assigns consecutive elements inside a row to the provided array.

      A(row,offset:(offset + values.length)) = values

      Parameters:
      row - The row that the array is to be written to.
      startColumn - The initial column that the array is written to.
      values - Values which are to be written to the row in a matrix.
    • setColumn

      public void setColumn​(int column, int startRow, double... values)

      Assigns consecutive elements inside a column to the provided array.

      A(offset:(offset + values.length),column) = values

      Parameters:
      column - The column that the array is to be written to.
      startRow - The initial column that the array is written to.
      values - Values which are to be written to the row in a matrix.
    • get

      public double get​(int row, int col)
      Returns the value of the specified matrix element. Performs a bounds check to make sure the requested element is part of the matrix. NOTE: Complex matrices will throw an exception
      Parameters:
      row - The row of the element.
      col - The column of the element.
      Returns:
      The value of the element.
    • get

      public double get​(int index)
      Returns the value of the matrix at the specified index of the 1D row major array.
      Parameters:
      index - The element's index whose value is to be returned
      Returns:
      The value of the specified element.
      See Also:
      DMatrixD1.get(int)
    • get

      public void get​(int row, int col, org.ejml.data.Complex_F64 output)
      Used to get the complex value of a matrix element.
      Parameters:
      row - The row of the element.
      col - The column of the element.
      output - Storage for the value
    • getIndex

      public int getIndex​(int row, int col)
      Returns the index in the matrix's array.
      Parameters:
      row - The row number.
      col - The column number.
      Returns:
      The index of the specified element.
      See Also:
      DMatrixRMaj.getIndex(int, int)
    • iterator

      public org.ejml.data.DMatrixIterator iterator​(boolean rowMajor, int minRow, int minCol, int maxRow, int maxCol)
      Creates a new iterator for traversing through a submatrix inside this matrix. It can be traversed by row or by column. Range of elements is inclusive, e.g. minRow = 0 and maxRow = 1 will include rows 0 and 1. The iteration starts at (minRow,minCol) and ends at (maxRow,maxCol)
      Parameters:
      rowMajor - true means it will traverse through the submatrix by row first, false by columns.
      minRow - first row it will start at.
      minCol - first column it will start at.
      maxRow - last row it will stop at.
      maxCol - last column it will stop at.
      Returns:
      A new MatrixIterator
    • copy

      public T copy()
      Creates and returns a matrix which is idential to this one.
      Returns:
      A new identical matrix.
    • numRows

      public int numRows()
      Returns the number of rows in this matrix.
      Returns:
      number of rows.
    • numCols

      public int numCols()
      Returns the number of columns in this matrix.
      Returns:
      number of columns.
    • getNumElements

      public int getNumElements()
      Returns the number of elements in this matrix, which is equal to the number of rows times the number of columns.
      Returns:
      The number of elements in the matrix.
    • print

      public void print()
      Prints the matrix to standard out.
    • print

      public void print​(java.lang.String format)

      Prints the matrix to standard out given a PrintStream.printf(java.lang.String, java.lang.Object...) style floating point format, e.g. print("%f").

    • toString

      public java.lang.String toString()

      Converts the array into a string format for display purposes. The conversion is done using MatrixIO.print(java.io.PrintStream, DMatrix).

      Overrides:
      toString in class java.lang.Object
      Returns:
      String representation of the matrix.
    • extractMatrix

      public T extractMatrix​(int y0, int y1, int x0, int x1)

      Creates a new SimpleMatrix which is a submatrix of this matrix.

      si-y0 , j-x0 = oij for all y0 ≤ i < y1 and x0 ≤ j < x1

      where 'sij' is an element in the submatrix and 'oij' is an element in the original matrix.

      If any of the inputs are set to SimpleMatrix.END then it will be set to the last row or column in the matrix.

      Parameters:
      y0 - Start row.
      y1 - Stop row + 1.
      x0 - Start column.
      x1 - Stop column + 1.
      Returns:
      The submatrix.
    • extractVector

      public T extractVector​(boolean extractRow, int element)

      Extracts a row or column from this matrix. The returned vector will either be a row or column vector depending on the input type.

      Parameters:
      extractRow - If true a row will be extracted.
      element - The row or column the vector is contained in.
      Returns:
      Extracted vector.
    • diag

      public T diag()

      If a vector then a square matrix is returned if a matrix then a vector of diagonal ements is returned

      Returns:
      Diagonal elements inside a vector or a square matrix with the same diagonal elements.
      See Also:
      CommonOps_DDRM.extractDiag(DMatrixRMaj, DMatrixRMaj)
    • isIdentical

      public boolean isIdentical​(T a, double tol)
      Checks to see if matrix 'a' is the same as this matrix within the specified tolerance.
      Parameters:
      a - The matrix it is being compared against.
      tol - How similar they must be to be equals.
      Returns:
      If they are equal within tolerance of each other.
    • hasUncountable

      public boolean hasUncountable()
      Checks to see if any of the elements in this matrix are either NaN or infinite.
      Returns:
      True of an element is NaN or infinite. False otherwise.
    • svd

      public SimpleSVD<T> svd()
      Computes a full Singular Value Decomposition (SVD) of this matrix with the eigenvalues ordered from largest to smallest.
      Returns:
      SVD
    • svd

      public SimpleSVD<T> svd​(boolean compact)
      Computes the SVD in either compact format or full format.
      Returns:
      SVD of this matrix.
    • eig

      public SimpleEVD<T> eig()
      Returns the Eigen Value Decomposition (EVD) of this matrix.
    • insertIntoThis

      public void insertIntoThis​(int insertRow, int insertCol, T B)
      Copy matrix B into this matrix at location (insertRow, insertCol).
      Parameters:
      insertRow - First row the matrix is to be inserted into.
      insertCol - First column the matrix is to be inserted into.
      B - The matrix that is being inserted.
    • combine

      public T combine​(int insertRow, int insertCol, T B)

      Creates a new matrix that is a combination of this matrix and matrix B. B is written into A at the specified location if needed the size of A is increased by growing it. A is grown by padding the new area with zeros.

      While useful when adding data to a matrix which will be solved for it is also much less efficient than predeclaring a matrix and inserting data into it.

      If insertRow or insertCol is set to SimpleMatrix.END then it will be combined at the last row or column respectively.

      Parameters:
      insertRow - Row where matrix B is written in to.
      insertCol - Column where matrix B is written in to.
      B - The matrix that is written into A.
      Returns:
      A new combined matrix.
    • elementMaxAbs

      public double elementMaxAbs()
      Returns the maximum absolute value of all the elements in this matrix. This is equivalent the the infinite p-norm of the matrix.
      Returns:
      Largest absolute value of any element.
    • elementMinAbs

      public double elementMinAbs()
      Returns the minimum absolute value of all the elements in this matrix.
      Returns:
      Smallest absolute value of any element.
    • elementSum

      public double elementSum()
      Computes the sum of all the elements in the matrix.
      Returns:
      Sum of all the elements.
    • elementMult

      public T elementMult​(T b)

      Returns a matrix which is the result of an element by element multiplication of 'this' and 'b': ci,j = ai,j*bi,j

      Parameters:
      b - A simple matrix.
      Returns:
      The element by element multiplication of 'this' and 'b'.
    • elementDiv

      public T elementDiv​(T b)

      Returns a matrix which is the result of an element by element division of 'this' and 'b': ci,j = ai,j/bi,j

      Parameters:
      b - A simple matrix.
      Returns:
      The element by element division of 'this' and 'b'.
    • elementPower

      public T elementPower​(T b)

      Returns a matrix which is the result of an element by element power of 'this' and 'b': ci,j = ai,j ^ bi,j

      Parameters:
      b - A simple matrix.
      Returns:
      The element by element power of 'this' and 'b'.
    • elementPower

      public T elementPower​(double b)

      Returns a matrix which is the result of an element by element power of 'this' and 'b': ci,j = ai,j ^ b

      Parameters:
      b - Scalar
      Returns:
      The element by element power of 'this' and 'b'.
    • elementExp

      public T elementExp()

      Returns a matrix which is the result of an element by element exp of 'this' ci,j = Math.exp(ai,j)

      Returns:
      The element by element power of 'this' and 'b'.
    • elementLog

      public T elementLog()

      Returns a matrix which is the result of an element by element exp of 'this' ci,j = Math.log(ai,j)

      Returns:
      The element by element power of 'this' and 'b'.
    • negative

      public T negative()

      Returns a new matrix whose elements are the negative of 'this' matrix's elements.

      bij = -aij

      Returns:
      A matrix that is the negative of the original.
    • equation

      public void equation​(java.lang.String equation, java.lang.Object... variables)

      Allows you to perform an equation in-place on this matrix by specifying the right hand side. For information on how to define an equation see Equation. The variable sequence alternates between variable and it's label String. This matrix is by default labeled as 'A', but is a string is the first object in 'variables' then it will take on that value. The variable passed in can be any data type supported by Equation can be passed in. This includes matrices and scalars.

      Examples:
       perform("A = A + B",matrix,"B");     // Matrix addition
       perform("A + B",matrix,"B");         // Matrix addition with implicit 'A = '
       perform("A(5,:) = B",matrix,"B");    // Insert a row defined by B into A
       perform("[A;A]");                    // stack A twice with implicit 'A = '
       perform("Q = B + 2","Q",matrix,"B"); // Specify the name of 'this' as Q
      
       
      Parameters:
      equation - String representing the symbol equation
      variables - List of variable names and variables
    • saveToFileBinary

      public void saveToFileBinary​(java.lang.String fileName) throws java.io.IOException

      Saves this matrix to a file as a serialized binary object.

      Throws:
      java.io.IOException
      See Also:
      MatrixIO.saveBin(DMatrix, String)
    • loadBinary

      public static SimpleMatrix loadBinary​(java.lang.String fileName) throws java.io.IOException

      Loads a new matrix from a serialized binary file.

      Parameters:
      fileName - File which is to be loaded.
      Returns:
      The matrix.
      Throws:
      java.io.IOException
      See Also:
      MatrixIO.loadBin(String)
    • saveToFileCSV

      public void saveToFileCSV​(java.lang.String fileName) throws java.io.IOException

      Saves this matrix to a file in a CSV format. For the file format see MatrixIO.

      Throws:
      java.io.IOException
      See Also:
      MatrixIO.saveBin(DMatrix, String)
    • loadCSV

      public T loadCSV​(java.lang.String fileName) throws java.io.IOException

      Loads a new matrix from a CSV file. For the file format see MatrixIO.

      Parameters:
      fileName - File which is to be loaded.
      Returns:
      The matrix.
      Throws:
      java.io.IOException
      See Also:
      MatrixIO.loadCSV(String, boolean)
    • isInBounds

      public boolean isInBounds​(int row, int col)
      Returns true of the specified matrix element is valid element inside this matrix.
      Parameters:
      row - Row index.
      col - Column index.
      Returns:
      true if it is a valid element in the matrix.
    • printDimensions

      public void printDimensions()
      Prints the number of rows and column in this matrix.
    • bits

      public int bits()
      Size of internal array elements. 32 or 64 bits
    • concatColumns

      public T concatColumns​(SimpleBase... matrices)

      Concatinates all the matrices together along their columns. If the rows do not match the upper elements are set to zero.

      A = [ this, m[0] , ... , m[n-1] ]
      Parameters:
      matrices - Set of matrices
      Returns:
      Resulting matrix
    • concatRows

      public T concatRows​(SimpleBase... matrices)

      Concatinates all the matrices together along their columns. If the rows do not match the upper elements are set to zero.

      A = [ this; m[0] ; ... ; m[n-1] ]
      Parameters:
      matrices - Set of matrices
      Returns:
      Resulting matrix
    • rows

      public T rows​(int begin, int end)
      Extracts the specified rows from the matrix.
      Parameters:
      begin - First row. Inclusive.
      end - Last row + 1.
      Returns:
      Submatrix that contains the specified rows.
    • cols

      public T cols​(int begin, int end)
      Extracts the specified rows from the matrix.
      Parameters:
      begin - First row. Inclusive.
      end - Last row + 1.
      Returns:
      Submatrix that contains the specified rows.
    • getType

      public org.ejml.data.MatrixType getType()
      Returns the type of matrix is is wrapping.
    • createLike

      public T createLike()
      Creates a matrix that is the same type and shape
      Returns:
      New matrix
    • setMatrix

      protected void setMatrix​(org.ejml.data.Matrix mat)
    • invoke

      public void invoke​(java.lang.reflect.Method m, java.lang.Object... inputs)
    • convertToSparse

      public void convertToSparse()
      Switches from a dense to sparse matrix
    • convertToDense

      public void convertToDense()
      Switches from a sparse to dense matrix