Package org.ejml.data

Class FMatrixSparseTriplet

java.lang.Object
org.ejml.data.FMatrixSparseTriplet
All Implemented Interfaces:
Serializable, FMatrix, FMatrixSparse, Matrix, MatrixSparse, ReshapeMatrix

@Generated("org.ejml.data.DMatrixSparseTriplet") public class FMatrixSparseTriplet extends Object implements FMatrixSparse
A sparse matrix format that is designed to act as an intermediate step for other matrix types. Constructing FMatrixSparseCSC from scratch is difficult, but if a triplet is first defined then it is much easier. Inside this class elements are stored in an unsorted list. Adding an element to the list with addItem(int, int, float) is an O(1) operation but reading a specific element is O(N) operation, making it impractical for operations like matrix multiplications.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.ejml.data.FMatrixSparse

    FMatrixSparse.CoordinateRealValue
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    Number of columns in the matrix
    int
    Number of rows in the matrix
    int
    Number of non-zero elements in this matrix
    Storage for row and column coordinate for non-zero elements
    Storage for value of a non-zero element
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    FMatrixSparseTriplet(int numRows, int numCols, int arrayLength)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addItem(int row, int col, float value)
    Adds a triplet of (row,vol,value) to the end of the list.
    void
    addItemCheck(int row, int col, float value)
    Adds a triplet of (row,vol,value) to the end of the list and performs a bounds check to make sure it is a legal value.
    <T extends Matrix>
    T
    Creates an exact copy of the matrix
    <T extends Matrix>
    T
    create(int numRows, int numCols)
    Creates a new matrix of the same type with the specified shape
    Creates an iterator which will go through each non-zero value in the sparse matrix.
    <T extends Matrix>
    T
    Creates a new matrix with the same shape as this matrix
    float
    get(int row, int col)
    Searches the list to see if the element at (row,col) has been assigned.
    float
    get(int row, int col, float fallBackValue)
    Searches the list to see if the element at (row,col) has been assigned.
    int
     
    int
    Returns the number of non-zero elements.
    int
    Returns the number of columns in this matrix.
    int
    Returns the number of rows in this matrix.
    Returns the type of matrix
    boolean
    isAssigned(int row, int col)
    Is the specified element explicitly assigned a value
    int
    nz_index(int row, int col)
     
    void
    Prints the matrix to standard out using standard formatting.
    void
    print(String format)
    Prints the matrix to standard out with the specified formatting.
    void
    Prints to standard out the non-zero elements only.
    void
    remove(int row, int col)
    If the specified element is non-zero it is removed from the structure
    void
     
    void
    reshape(int numRows, int numCols)
    Changes the number of rows and columns in the matrix.
    void
    reshape(int numRows, int numCols, int arrayLength)
    Reshapes the matrix so that it can store a matrix with the specified dimensions and the number of non-zero elements.
    void
    set(int row, int col, float value)
    Sets the element's value at (row,col).
    void
    setTo(Matrix original)
    Sets this matrix to be identical to the 'original' matrix passed in.
    void
    Reduces the size of internal data structures to their minimal size.
    float
    unsafe_get(int row, int col)
    Same as FMatrix.get(int, int) but does not perform bounds check on input parameters.
    float
    unsafe_get(int row, int col, float fallBackValue)
    Same as FMatrixSparse.get(int, int, float) but does not perform bounds check on input parameters.
    void
    unsafe_set(int row, int col, float value)
    Same as set(int, int, float) but does not check to see if row and column are within bounds.
    void
    Sets all values inside the matrix to zero

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.ejml.data.FMatrix

    getNumElements
  • Field Details

    • nz_rowcol

      public IGrowArray nz_rowcol
      Storage for row and column coordinate for non-zero elements
    • nz_value

      public FGrowArray nz_value
      Storage for value of a non-zero element
    • nz_length

      public int nz_length
      Number of non-zero elements in this matrix
    • numRows

      public int numRows
      Number of rows in the matrix
    • numCols

      public int numCols
      Number of columns in the matrix
  • Constructor Details

    • FMatrixSparseTriplet

      public FMatrixSparseTriplet()
    • FMatrixSparseTriplet

      public FMatrixSparseTriplet(int numRows, int numCols, int arrayLength)
      Parameters:
      numRows - Number of rows in the matrix
      numCols - Number of columns in the matrix
      arrayLength - Initial maximum length of data array.
    • FMatrixSparseTriplet

      public FMatrixSparseTriplet(FMatrixSparseTriplet orig)
  • Method Details

    • reset

      public void reset()
    • reshape

      public void reshape(int numRows, int numCols)
      Description copied from interface: MatrixSparse
      Changes the number of rows and columns in the matrix. The graph structure is flushed and the matrix will be empty/all zeros. Similar to MatrixSparse.reshape(int, int, int), but the storage for non-zero elements is not changed
      Specified by:
      reshape in interface MatrixSparse
      Specified by:
      reshape in interface ReshapeMatrix
      Parameters:
      numRows - number of rows
      numCols - number of columns
    • reshape

      public void reshape(int numRows, int numCols, int arrayLength)
      Description copied from interface: MatrixSparse
      Reshapes the matrix so that it can store a matrix with the specified dimensions and the number of non-zero elements. The reshaped matrix will be empty.
      Specified by:
      reshape in interface MatrixSparse
      Parameters:
      numRows - number of rows
      numCols - number of columns
      arrayLength - Array length for storing non-zero elements.
    • addItem

      public void addItem(int row, int col, float value)

      Adds a triplet of (row,vol,value) to the end of the list. This is the preferred way to add elements into this array type as it has a runtime complexity of O(1).

      One potential problem with using this function instead of set(int, int, float) is that it does not check to see if a (row,col) has already been assigned a value. If a (row,col) is defined multiple times how this is handled is not defined.
      Parameters:
      row - Row the element belongs in
      col - Column the element belongs in
      value - The value of the element
    • addItemCheck

      public void addItemCheck(int row, int col, float value)
      Adds a triplet of (row,vol,value) to the end of the list and performs a bounds check to make sure it is a legal value.
      Parameters:
      row - Row the element belongs in
      col - Column the element belongs in
      value - The value of the element
      See Also:
    • set

      public void set(int row, int col, float value)
      Sets the element's value at (row,col). It first checks to see if the element already has a value and if it does that value is changed. As a result this operation is O(N), where N is the number of elements in the matrix.
      Specified by:
      set in interface FMatrix
      Parameters:
      row - Matrix element's row index.
      col - Matrix element's column index.
      value - value of element.
      See Also:
    • unsafe_set

      public void unsafe_set(int row, int col, float value)
      Same as set(int, int, float) but does not check to see if row and column are within bounds.
      Specified by:
      unsafe_set in interface FMatrix
      Parameters:
      row - Matrix element's row index.
      col - Matrix element's column index.
      value - value of element.
    • get

      public float get(int row, int col)
      Searches the list to see if the element at (row,col) has been assigned. The worst case runtime for this operation is O(N), where N is the number of elements in the matrix.
      Specified by:
      get in interface FMatrix
      Parameters:
      row - Matrix element's row index.
      col - Matrix element's column index.
      Returns:
      Value at (row,col)
    • get

      public float get(int row, int col, float fallBackValue)
      Searches the list to see if the element at (row,col) has been assigned. The worst case runtime for this operation is O(N), where N is the number of elements in the matrix.
      Specified by:
      get in interface FMatrixSparse
      Parameters:
      row - Matrix element's row index.
      col - Matrix element's column index.
      fallBackValue - Value to return, if the element is not assigned
      Returns:
      Value at (row,col) or the fallBackValue, if the element is not assigned.
    • unsafe_get

      public float unsafe_get(int row, int col)
      Description copied from interface: FMatrix
      Same as FMatrix.get(int, int) but does not perform bounds check on input parameters. This results in about a 25% speed increase but potentially sacrifices stability and makes it more difficult to track down simple errors. It is not recommended that this function be used, except in highly optimized code where the bounds are implicitly being checked.
      Specified by:
      unsafe_get in interface FMatrix
      Parameters:
      row - Matrix element's row index..
      col - Matrix element's column index.
      Returns:
      The specified element's value.
    • unsafe_get

      public float unsafe_get(int row, int col, float fallBackValue)
      Description copied from interface: FMatrixSparse
      Same as FMatrixSparse.get(int, int, float) but does not perform bounds check on input parameters. This results in about a 25% speed increase but potentially sacrifices stability and makes it more difficult to track down simple errors. It is not recommended that this function be used, except in highly optimized code where the bounds are implicitly being checked.
      Specified by:
      unsafe_get in interface FMatrixSparse
      Parameters:
      row - Matrix element's row index..
      col - Matrix element's column index.
      fallBackValue - Value to return, if the matrix element is not assigned
      Returns:
      The specified element's value or the fallBackValue, if the element is not assigned.
    • nz_index

      public int nz_index(int row, int col)
    • getLength

      public int getLength()
    • getNumRows

      public int getNumRows()
      Description copied from interface: Matrix
      Returns the number of rows in this matrix.
      Specified by:
      getNumRows in interface Matrix
      Returns:
      Number of rows.
    • getNumCols

      public int getNumCols()
      Description copied from interface: Matrix
      Returns the number of columns in this matrix.
      Specified by:
      getNumCols in interface Matrix
      Returns:
      Number of columns.
    • copy

      public <T extends Matrix> T copy()
      Description copied from interface: Matrix
      Creates an exact copy of the matrix
      Specified by:
      copy in interface Matrix
    • createLike

      public <T extends Matrix> T createLike()
      Description copied from interface: Matrix
      Creates a new matrix with the same shape as this matrix
      Specified by:
      createLike in interface Matrix
    • create

      public <T extends Matrix> T create(int numRows, int numCols)
      Description copied from interface: Matrix
      Creates a new matrix of the same type with the specified shape
      Specified by:
      create in interface Matrix
    • setTo

      public void setTo(Matrix original)
      Description copied from interface: Matrix
      Sets this matrix to be identical to the 'original' matrix passed in.
      Specified by:
      setTo in interface Matrix
    • shrinkArrays

      public void shrinkArrays()
      Description copied from interface: MatrixSparse
      Reduces the size of internal data structures to their minimal size. No information is lost but the arrays will change
      Specified by:
      shrinkArrays in interface MatrixSparse
    • remove

      public void remove(int row, int col)
      Description copied from interface: MatrixSparse
      If the specified element is non-zero it is removed from the structure
      Specified by:
      remove in interface MatrixSparse
      Parameters:
      row - the row
      col - the column
    • isAssigned

      public boolean isAssigned(int row, int col)
      Description copied from interface: MatrixSparse
      Is the specified element explicitly assigned a value
      Specified by:
      isAssigned in interface MatrixSparse
      Parameters:
      row - the row
      col - the column
      Returns:
      true if it has been assigned a value or false if not
    • zero

      public void zero()
      Description copied from interface: Matrix
      Sets all values inside the matrix to zero
      Specified by:
      zero in interface Matrix
      Specified by:
      zero in interface MatrixSparse
    • getNonZeroLength

      public int getNonZeroLength()
      Description copied from interface: MatrixSparse
      Returns the number of non-zero elements.
      Specified by:
      getNonZeroLength in interface MatrixSparse
    • print

      public void print()
      Description copied from interface: Matrix
      Prints the matrix to standard out using standard formatting. This is the same as calling print("%e")
      Specified by:
      print in interface Matrix
    • print

      public void print(String format)
      Description copied from interface: Matrix
      Prints the matrix to standard out with the specified formatting.
      Specified by:
      print in interface Matrix
      Parameters:
      format - printf style formatting for a float. E.g. "%f"
      See Also:
    • printNonZero

      public void printNonZero()
      Description copied from interface: MatrixSparse
      Prints to standard out the non-zero elements only.
      Specified by:
      printNonZero in interface MatrixSparse
    • getType

      public MatrixType getType()
      Description copied from interface: Matrix
      Returns the type of matrix
      Specified by:
      getType in interface Matrix
    • createCoordinateIterator

      public Iterator<FMatrixSparse.CoordinateRealValue> createCoordinateIterator()
      Description copied from interface: FMatrixSparse
      Creates an iterator which will go through each non-zero value in the sparse matrix. Order is not defined and is implementation specific
      Specified by:
      createCoordinateIterator in interface FMatrixSparse