Package org.ejml.data

Class FMatrixD1

java.lang.Object
org.ejml.data.FMatrixD1
All Implemented Interfaces:
Serializable, FMatrix, Matrix, ReshapeMatrix
Direct Known Subclasses:
FMatrix1Row, FMatrixRBlock

@Generated("org.ejml.data.DMatrixD1") public abstract class FMatrixD1 extends Object implements ReshapeMatrix, FMatrix
A generic abstract class for matrices whose data is stored in a single 1D array of floats. The format of the elements in this array is not specified. For example row major, column major, and block row major are all common formats.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    float[]
    Where the raw data for the matrix is stored.
    int
    Number of columns in the matrix.
    int
    Number of rows in the matrix.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    assignShape(int rows, int cols)
    Sets the matrix's shape while checking that it's valid
    float
    div(int index, float val)
    Divides the specified value to the internal data array at the specified index.

    Equivalent to: this.data[index] /= val;
    float
    get(int index)
    Returns the value of the matrix at the specified internal array index.
    float[]
    Used to get a reference to the internal data.
    abstract int
    getIndex(int row, int col)
    Returns the internal array index for the specified row and column.
    int
    Returns the number of columns in this matrix.
    int
    Returns the number of rows in this matrix.
    iterator(boolean rowMajor, int minRow, int minCol, int maxRow, int maxCol)
    Creates a new iterator for traversing through a submatrix inside this matrix.
    float
    minus(int index, float val)
    Subtracts the specified value to the internal data array at the specified index.

    Equivalent to: this.data[index] -= val;
    float
    plus(int index, float val)
    Adds the specified value to the internal data array at the specified index.

    Equivalent to: this.data[index] += val;
    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
    reshape(int numRows, int numCols)
    Equivalent to invoking reshape(numRows,numCols,false);
    abstract void
    reshape(int numRows, int numCols, boolean saveValues)
    Changes the number of rows and columns in the matrix, allowing its size to grow or shrink.
    float
    set(int index, float val)
    Sets the element's value at the specified index.
    void
    setData(float[] data)
    Changes the internal array reference.
    void
    setNumCols(int numCols)
    Sets the number of columns.
    void
    setNumRows(int numRows)
    Sets the number of rows.
    void
    Sets the value of this matrix to be the same as the value of the provided matrix.
    float
    times(int index, float val)
    Multiplies the specified value to the internal data array at the specified index.

    Equivalent to: this.data[index] *= val;

    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

    get, getNumElements, set, unsafe_get, unsafe_set

    Methods inherited from interface org.ejml.data.Matrix

    copy, create, createLike, getType, setTo, zero
  • Field Details

    • data

      public float[] data
      Where the raw data for the matrix is stored. The format is type dependent.
    • numRows

      public int numRows
      Number of rows in the matrix.
    • numCols

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

    • FMatrixD1

      public FMatrixD1()
  • Method Details

    • assignShape

      protected void assignShape(int rows, int cols)
      Sets the matrix's shape while checking that it's valid
    • getData

      public float[] getData()
      Used to get a reference to the internal data.
      Returns:
      Reference to the matrix's data.
    • setData

      public void setData(float[] data)
      Changes the internal array reference.
    • getIndex

      public abstract int getIndex(int row, int col)
      Returns the internal array index for the specified row and column.
      Parameters:
      row - Row index.
      col - Column index.
      Returns:
      Internal array index.
    • setTo

      public void setTo(FMatrixD1 b)
      Sets the value of this matrix to be the same as the value of the provided matrix. Both matrices must have the same shape:

      aij = bij

      Parameters:
      b - The matrix that this matrix is to be set equal to.
    • get

      public float get(int index)
      Returns the value of the matrix at the specified internal array index. The element at which row and column returned by this function depends upon the matrix's internal structure, e.g. row-major, column-major, or block.
      Parameters:
      index - Internal array index.
      Returns:
      Value at the specified index.
    • set

      public float set(int index, float val)
      Sets the element's value at the specified index. The element at which row and column modified by this function depends upon the matrix's internal structure, e.g. row-major, column-major, or block.
      Parameters:
      index - Index of element that is to be set.
      val - The new value of the index.
    • plus

      public float plus(int index, float val)

      Adds the specified value to the internal data array at the specified index.

      Equivalent to: this.data[index] += val;

      Intended for use in highly optimized code. The row/column coordinate of the modified element is dependent upon the matrix's internal structure.

      Parameters:
      index - The index which is being modified.
      val - The value that is being added.
    • minus

      public float minus(int index, float val)

      Subtracts the specified value to the internal data array at the specified index.

      Equivalent to: this.data[index] -= val;

      Intended for use in highly optimized code. The row/column coordinate of the modified element is dependent upon the matrix's internal structure.

      Parameters:
      index - The index which is being modified.
      val - The value that is being subtracted.
    • times

      public float times(int index, float val)

      Multiplies the specified value to the internal data array at the specified index.

      Equivalent to: this.data[index] *= val;

      Intended for use in highly optimized code. The row/column coordinate of the modified element is dependent upon the matrix's internal structure.

      Parameters:
      index - The index which is being modified.
      val - The value that is being multiplied.
    • div

      public float div(int index, float val)

      Divides the specified value to the internal data array at the specified index.

      Equivalent to: this.data[index] /= val;

      Intended for use in highly optimized code. The row/column coordinate of the modified element is dependent upon the matrix's internal structure.

      Parameters:
      index - The index which is being modified.
      val - The value that is being divided.
    • reshape

      public abstract void reshape(int numRows, int numCols, boolean saveValues)

      Changes the number of rows and columns in the matrix, allowing its size to grow or shrink. If the saveValues flag is set to true, then the previous values will be maintained, but reassigned to new elements in a row-major ordering. If saveValues is false values will only be maintained when the requested size is less than or equal to the internal array size. The primary use for this function is to encourage data reuse and avoid unnecessarily declaring and initialization of new memory.

      Examples:
      [ 1 2 ; 3 4 ] → reshape( 2 , 3 , true ) = [ 1 2 3 ; 4 0 0 ]
      [ 1 2 ; 3 4 ] → reshape( 1 , 2 , true ) = [ 1 2 ]
      [ 1 2 ; 3 4 ] → reshape( 1 , 2 , false ) = [ 1 2 ]
      [ 1 2 ; 3 4 ] → reshape( 2 , 3 , false ) = [ 0 0 0 ; 0 0 0 ]

      Parameters:
      numRows - The new number of rows in the matrix.
      numCols - The new number of columns in the matrix.
      saveValues - If true then the value of each element will be save using a row-major reordering. Typically this should be false.
    • reshape

      public void reshape(int numRows, int numCols)
      Equivalent to invoking reshape(numRows,numCols,false);
      Specified by:
      reshape in interface ReshapeMatrix
      Parameters:
      numRows - The new number of rows in the matrix.
      numCols - The new number of columns in the matrix.
    • iterator

      public FMatrixIterator 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
    • 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:
    • getNumRows

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

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

      public void setNumRows(int numRows)
      Sets the number of rows.
      Parameters:
      numRows - Number of rows
    • setNumCols

      public void setNumCols(int numCols)
      Sets the number of columns.
      Parameters:
      numCols - Number of columns