Package org.ejml.data

Class FMatrixRMaj

All Implemented Interfaces:
Serializable, FMatrix, Matrix, ReshapeMatrix

@Generated("org.ejml.data.DMatrixRMaj") public class FMatrixRMaj extends FMatrix1Row

FMatrixRMaj is a row matrix with real elements that are 32-bit floats. A matrix is the fundamental data structure in linear algebra. Unlike a sparse matrix, there is no compression in a row matrix and every element is stored in memory. This allows for fast reads and writes to the matrix.

The matrix is stored internally in a row-major 1D array format:

data[ y*numCols + x ] = data[y][x]

For example:
data =

 a[0]  a[1]   a[2]   a[3]
 a[4]  a[5]   a[6]   a[7]
 a[8]  a[9]   a[10]  a[11]
 a[12] a[13]  a[14]  a[15]
 
See Also:
  • Field Summary

    Fields inherited from class org.ejml.data.FMatrixD1

    data, numCols, numRows
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor that creates a 0 by 0 matrix.
    FMatrixRMaj(float[] data)
    Creates a column vector the same length as this array
    FMatrixRMaj(float[][] data)
    Creates a matrix with the values and shape defined by the 2D array 'data'.
    FMatrixRMaj(int length)
    This declares an array that can store a matrix up to the specified length.
    FMatrixRMaj(int numRows, int numCols)
    Creates a new Matrix with the specified shape whose elements initially have the value of zero.
    FMatrixRMaj(int numRows, int numCols, boolean rowMajor, float... data)
    Creates a new matrix which has the same value as the matrix encoded in the provided array.
    Creates a new FMatrixRMaj which contains the same information as the provided Matrix64F.
    Creates a new matrix which is equivalent to the provided matrix.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int row, int col, float value)
    Adds 'value' to the specified element in the matrix.

    aij = aij + value
    Creates and returns a matrix which is identical to this one.
    create(int numRows, int numCols)
    Creates a new matrix of the same type with the specified shape
    Creates a new matrix with the same shape as this matrix
    void
    fill(float value)
    Sets all elements equal to the specified value.
    float
    get(int row, int col)
    Returns the value of the specified matrix element.
    int
    getIndex(int row, int col)
    Returns the internal array index for the specified row and column.
    Returns the type of matrix
    boolean
    isInBounds(int row, int col)
    Determines if the specified element is inside the bounds of the Matrix.
    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.
    void
    set(float[][] input)
    Assigns this matrix using a 2D array representation
    void
    set(int numRows, int numCols, boolean rowMajor, float... data)
    Sets this matrix equal to the matrix encoded in the array.
    void
    set(int row, int col, float value)
    Assigns the element in the Matrix to the specified value.
    void
    setTo(Matrix original)
    Sets this matrix to be identical to the 'original' matrix passed in.
    Converts the array into a string format for display purposes.
    float
    unsafe_get(int row, int col)
    Same as FMatrix.get(int, int) but does not perform bounds check on input parameters.
    void
    unsafe_set(int row, int col, float value)
    Same as Matrix.setTo(org.ejml.data.Matrix) but does not perform bounds check on input parameters.
    wrap(int numRows, int numCols, float[] data)
    Creates a new FMatrixRMaj around the provided data.
    void
    Sets all elements equal to zero.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface org.ejml.data.FMatrix

    getNumElements
  • Constructor Details

    • FMatrixRMaj

      public FMatrixRMaj(int numRows, int numCols, boolean rowMajor, float... data)

      Creates a new matrix which has the same value as the matrix encoded in the provided array. The input matrix's format can either be row-major or column-major.

      Note that 'data' is a variable argument type, so either 1D arrays or a set of numbers can be passed in:
      DenseMatrix a = new DenseMatrix(2,2,true,new float[]{1,2,3,4});
      DenseMatrix b = new DenseMatrix(2,2,true,1,2,3,4);

      Both are equivalent.

      Parameters:
      numRows - The number of rows.
      numCols - The number of columns.
      rowMajor - If the array is encoded in a row-major or a column-major format.
      data - The formatted 1D array. Not modified.
    • FMatrixRMaj

      public FMatrixRMaj(float[][] data)

      Creates a matrix with the values and shape defined by the 2D array 'data'. It is assumed that 'data' has a row-major formatting:

      data[ row ][ column ]

      Parameters:
      data - 2D array representation of the matrix. Not modified.
    • FMatrixRMaj

      public FMatrixRMaj(float[] data)
      Creates a column vector the same length as this array
      Parameters:
      data - elements in vector. copied
    • FMatrixRMaj

      public FMatrixRMaj(int numRows, int numCols)
      Creates a new Matrix with the specified shape whose elements initially have the value of zero.
      Parameters:
      numRows - The number of rows in the matrix.
      numCols - The number of columns in the matrix.
    • FMatrixRMaj

      public FMatrixRMaj(FMatrixRMaj orig)
      Creates a new matrix which is equivalent to the provided matrix. Note that the length of the data will be determined by the shape of the matrix.
      Parameters:
      orig - The matrix which is to be copied. This is not modified or saved.
    • FMatrixRMaj

      public FMatrixRMaj(int length)
      This declares an array that can store a matrix up to the specified length. This is use full when a matrix's size will be growing and it is desirable to avoid reallocating memory.
      Parameters:
      length - The size of the matrice's data array.
    • FMatrixRMaj

      public FMatrixRMaj()
      Default constructor that creates a 0 by 0 matrix.
    • FMatrixRMaj

      public FMatrixRMaj(FMatrix mat)
      Creates a new FMatrixRMaj which contains the same information as the provided Matrix64F.
      Parameters:
      mat - Matrix whose values will be copied. Not modified.
  • Method Details

    • wrap

      public static FMatrixRMaj wrap(int numRows, int numCols, float[] data)
      Creates a new FMatrixRMaj around the provided data. The data must encode a row-major matrix. Any modification to the returned matrix will modify the provided data.
      Parameters:
      numRows - Number of rows in the matrix.
      numCols - Number of columns in the matrix.
      data - Data that is being wrapped. Referenced Saved.
      Returns:
      A matrix which references the provided data internally.
    • reshape

      public void reshape(int numRows, int numCols, boolean saveValues)
      Description copied from class: FMatrixD1

      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 ]

      Specified by:
      reshape in class FMatrixD1
      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.
    • set

      public void set(int row, int col, float 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.

      aij = value

      Parameters:
      row - The row of the element.
      col - The column of the element.
      value - The element's new value.
    • unsafe_set

      public void unsafe_set(int row, int col, float value)
      Description copied from interface: FMatrix
      Same as Matrix.setTo(org.ejml.data.Matrix) 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.
      Parameters:
      row - Matrix element's row index..
      col - Matrix element's column index.
      value - The element's new value.
    • add

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

      Adds 'value' to the specified element in the matrix.

      aij = aij + value

      Parameters:
      row - The row of the element.
      col - The column of the element.
      value - The value that is added to the element
    • get

      public float 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.
      Parameters:
      row - The row of the element.
      col - The column of the element.
      Returns:
      The value of the element.
    • 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.
      Parameters:
      row - Matrix element's row index..
      col - Matrix element's column index.
      Returns:
      The specified element's value.
    • getIndex

      public int getIndex(int row, int col)
      Description copied from class: FMatrixD1
      Returns the internal array index for the specified row and column.
      Specified by:
      getIndex in class FMatrixD1
      Parameters:
      row - Row index.
      col - Column index.
      Returns:
      Internal array index.
    • isInBounds

      public boolean isInBounds(int row, int col)
      Determines if the specified element is inside the bounds of the Matrix.
      Parameters:
      row - The element's row.
      col - The element's column.
      Returns:
      True if it is inside the matrices bound, false otherwise.
    • set

      public void set(int numRows, int numCols, boolean rowMajor, float... data)
      Sets this matrix equal to the matrix encoded in the array.
      Parameters:
      numRows - The number of rows.
      numCols - The number of columns.
      rowMajor - If the array is encoded in a row-major or a column-major format.
      data - The formatted 1D array. Not modified.
    • zero

      public void zero()
      Sets all elements equal to zero.
    • fill

      public void fill(float value)
      Sets all elements equal to the specified value.
    • copy

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

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

      public String toString()

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

      Overrides:
      toString in class Object
      Returns:
      String representation of the matrix.
    • createLike

      public FMatrixRMaj createLike()
      Description copied from interface: Matrix
      Creates a new matrix with the same shape as this matrix
    • create

      public FMatrixRMaj create(int numRows, int numCols)
      Description copied from interface: Matrix
      Creates a new matrix of the same type with the specified shape
    • getType

      public MatrixType getType()
      Description copied from interface: Matrix
      Returns the type of matrix
    • set

      public void set(float[][] input)
      Assigns this matrix using a 2D array representation
      Parameters:
      input - 2D array which this matrix will be set to