DenseMatrix64F
org.ejml.data

Class DenseMatrix64F

  • All Implemented Interfaces:
    Serializable


    public class DenseMatrix64Fextends RowD1Matrix64F

    DenseMatrix64F is a dense matrix with elements that are 64-bit floats (doubles). A matrix is the fundamental data structure in linear algebra. Unlike a sparse matrix, there is no compression in a dense matrix and every element is stored in memory. This allows for fast reads and writes to the matrix.

    To keep the code manageable and the library easier to use only basic functions for accessing and editing elements are provided in this class. The numerous operations which can be performed on DenseMatrix64F are contained in various other classes, where the most common operations can be found in the CommonOps and SpecializedOps classes.

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

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

    For example:
    data =

    a11 a12 a13 a14 a21 a22 a23 a24 a31 a32 a33 a34 a41 a42 a43 a44

    An alternative to working directly with DenseMatrix64 is SimpleMatrix. SimpleMatrix is a wrapper around DenseMatrix64F that provides an easier to use object oriented way of manipulating matrices, at the cost of efficiency.

    See Also:
    CommonOps, SpecializedOps, SimpleMatrix, Serialized Form
    • Constructor Summary

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

      Methods 
      Modifier and TypeMethod and Description
      voidadd(int row, int col, double value)
      Adds 'value' to the specified element in the matrix.

      aij = aij + value
      DenseMatrix64Fcopy()
      Creates and returns a matrix which is idential to this one.
      doubleget(int row, int col)
      Returns the value of the specified matrix element.
      intgetIndex(int row, int col)
      Returns the internal array index for the specified row and column.
      intgetNumElements()
      Returns the number of elements in this matrix, which is equal to the number of rows times the number of columns.
      booleanisInBounds(int row, int col)
      Determins if the specified element is inside the bounds of the Matrix.
      voidprint()
      Prints the value of this matrix to the screen.
      voidprint(String format)
      Prints the value of this matrix to the screen using the same format as {@link java.io.PrintStream#printf).
      voidreshape(int numRows, int numCols, boolean saveValues)
      Changes the number of rows and columns in the matrix, allowing its size to grow or shrink.
      voidset(int numRows, int numCols, boolean rowMajor, double... data)
      Sets this matrix equal to the matrix encoded in the array.
      voidset(int row, int col, double value)
      Assigns the element in the Matrix to the specified value.
      voidsetReshape(DenseMatrix64F b)
      Sets the value and shape of this matrix to be identical to the specified matrix.
      StringtoString()
      Converts the array into a string format for display purposes.
      doubleunsafe_get(int row, int col)
      Same as Matrix64F.get(int, int) but does not perform bounds check on input parameters.
      voidunsafe_set(int row, int col, double value)
      Same as Matrix64F.set(int, int, double) but does not perform bounds check on input parameters.
      static DenseMatrix64Fwrap(int numRows, int numCols, double[] data)
      Creates a new DenseMatrix64F around the provided data.
      voidzero()
      Sets all elements equal to zero.
    • Constructor Detail

      • DenseMatrix64F

        public DenseMatrix64F(int numRows,              int numCols,              boolean rowMajor,              double... 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 double[]{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.
      • DenseMatrix64F

        public DenseMatrix64F(double[][] 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.
      • DenseMatrix64F

        public DenseMatrix64F(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.
      • DenseMatrix64F

        public DenseMatrix64F(DenseMatrix64F 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.
      • DenseMatrix64F

        public DenseMatrix64F(int length)
        This declares an array that can store a matrix up to the specified length. This is usefull 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.
      • DenseMatrix64F

        public DenseMatrix64F()
        Default constructor where nothing is assigned. In general this should not be used.
      • DenseMatrix64F

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

      • wrap

        public static DenseMatrix64F wrap(int numRows,                  int numCols,                  double[] data)
        Creates a new DenseMatrix64F 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: Matrix64F

        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 Matrix64F
        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,       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.

        aij = value

        Specified by:
        set in class Matrix64F
        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,              double value)
        Description copied from class: Matrix64F
        Same as Matrix64F.set(int, int, double) 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_set in class Matrix64F
        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,       double 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 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.
        Specified by:
        get in class Matrix64F
        Parameters:
        row - The row of the element.
        col - The column of the element.
        Returns:
        The value of the element.
      • unsafe_get

        public double unsafe_get(int row,                int col)
        Description copied from class: Matrix64F
        Same as Matrix64F.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 class Matrix64F
        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: D1Matrix64F
        Returns the internal array index for the specified row and column.
        Specified by:
        getIndex in class D1Matrix64F
        Parameters:
        row - Row index.
        col - Column index.
        Returns:
        Internal array index.
      • isInBounds

        public boolean isInBounds(int row,                 int col)
        Determins if the specified element is inside the bounds of the Matrix.
        Parameters:
        row - The element's row.
        col - The elements' column.
        Returns:
        True if it is inside the matrices bound, false otherwise.
      • 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.
        Specified by:
        getNumElements in class Matrix64F
        Returns:
        The number of elements in the matrix.
      • setReshape

        public void setReshape(DenseMatrix64F b)

        Sets the value and shape of this matrix to be identical to the specified matrix. The width and height are changed to match the matrix that has been provided. If more memory is needed then a new data array is declared.

        a.numRows = b.numRows
        a.numCols = b.numCols

        aij = bij

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

        public void set(int numRows,       int numCols,       boolean rowMajor,       double... 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.
      • copy

        public DenseMatrix64F copy()
        Creates and returns a matrix which is idential to this one.
        Specified by:
        copy in class Matrix64F
        Returns:
        A new identical matrix.
      • print

        public void print()
        Prints the value of this matrix to the screen. For more options see UtilEjml
        Specified by:
        print in class Matrix64F
      • print

        public void print(String format)

        Prints the value of this matrix to the screen using the same format as {@link java.io.PrintStream#printf).

        Parameters:
        format - The format which each element is printed uses.

SCaVis 2.2 © jWork.ORG