Package org.ejml.data

Class FMatrixSparseCSC

  • All Implemented Interfaces:
    java.io.Serializable, FMatrix, FMatrixSparse, Matrix, MatrixSparse, ReshapeMatrix

    public class FMatrixSparseCSC
    extends java.lang.Object
    implements FMatrixSparse

    Compressed Column (CC) sparse matrix format. Only non-zero elements are stored.

    Format:
    Row indexes for column j are stored in rol_idx[col_idx[j]] to rol_idx[col_idx[j+1]-1]. The values for the corresponding elements are stored at data[col_idx[j]] to data[col_idx[j+1]-1].

    Row indexes must be specified in chronological order.

    TODO fully describe
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int[] col_idx
      Stores the range of indexes in the non-zero lists that belong to each column.
      boolean indicesSorted
      Flag that's used to indicate of the row indices are sorted or not.
      int numCols
      Number of columns in the matrix
      int numRows
      Number of rows in the matrix
      int nz_length
      Length of data.
      int[] nz_rows
      Specifies which row a specific non-zero value corresponds to.
      float[] nz_values
      Storage for non-zero values.
    • Constructor Summary

      Constructors 
      Constructor Description
      FMatrixSparseCSC​(int numRows, int numCols)
      Constructor with a default arrayLength of zero.
      FMatrixSparseCSC​(int numRows, int numCols, int arrayLength)
      Specifies shape and number of non-zero elements that can be stored.
      FMatrixSparseCSC​(FMatrixSparseCSC original)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      FMatrixSparseCSC copy()
      Creates an exact copy of the matrix
      void copyStructure​(FMatrixSparseCSC orig)
      Copies the non-zero structure of orig into "this"
      FMatrixSparseCSC create​(int numRows, int numCols)
      Creates a new matrix of the same type with the specified shape
      java.util.Iterator<FMatrixSparse.CoordinateRealValue> createCoordinateIterator()
      Creates an iterator which will go through each non-zero value in the sparse matrix.
      FMatrixSparseCSC createLike()
      Creates a new matrix with the same shape as this matrix
      float get​(int row, int col)
      Returns the value of value of the specified matrix element.
      int getNonZeroLength()
      Returns the number of non-zero elements.
      int getNumCols()
      Returns the number of columns in this matrix.
      int getNumElements()
      Returns the number of elements in this matrix, which is the number of rows times the number of columns.
      int getNumRows()
      Returns the number of rows in this matrix.
      MatrixType getType()
      Returns the type of matrix
      void growMaxColumns​(int desiredColumns, boolean preserveValue)
      Increases the maximum number of columns in the matrix.
      void growMaxLength​(int arrayLength, boolean preserveValue)
      Increases the maximum size of the data array so that it can store sparse data up to 'length'.
      void histogramToStructure​(int[] histogram)
      Given the histogram of columns compute the col_idx for the matrix.
      boolean isAssigned​(int row, int col)
      Is the specified element explicitly assigned a value
      boolean isFull()
      Returns true if number of non-zero elements is the maximum size
      boolean isIndicesSorted()
      If the indices has been sorted or not
      int nz_index​(int row, int col)
      Returns the index in nz_rows for the element at (row,col) if it already exists in the matrix.
      void print()
      Prints the matrix to standard out using standard formatting.
      void print​(java.lang.String format)
      Prints the matrix to standard out with the specified formatting.
      void printNonZero()
      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 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 val)
      Sets the value of the specified matrix element.
      void set​(Matrix original)
      Sets this matrix to be identical to the 'original' matrix passed in.
      void shrinkArrays()
      Reduces the size of internal data structures to their minimal size.
      void sortIndices​(SortCoupledArray_F32 sorter)
      Sorts the row indices in ascending order.
      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 val)
      Same as FMatrix.set(int, int, float) but does not perform bounds check on input parameters.
      void zero()
      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
    • Field Detail

      • nz_values

        public float[] nz_values
        Storage for non-zero values. Only valid up to length-1.
      • nz_length

        public int nz_length
        Length of data. Number of non-zero values in the matrix
      • nz_rows

        public int[] nz_rows
        Specifies which row a specific non-zero value corresponds to. If they are sorted or not with in each column is specified by the indicesSorted flag.
      • col_idx

        public int[] col_idx
        Stores the range of indexes in the non-zero lists that belong to each column. Column 'i' corresponds to indexes col_idx[i] to col_idx[i+1]-1, inclusive.
      • numRows

        public int numRows
        Number of rows in the matrix
      • numCols

        public int numCols
        Number of columns in the matrix
      • indicesSorted

        public boolean indicesSorted
        Flag that's used to indicate of the row indices are sorted or not.
    • Constructor Detail

      • FMatrixSparseCSC

        public FMatrixSparseCSC​(int numRows,
                                int numCols)
        Constructor with a default arrayLength of zero.
        Parameters:
        numRows - Number of rows
        numCols - Number of columns
      • FMatrixSparseCSC

        public FMatrixSparseCSC​(int numRows,
                                int numCols,
                                int arrayLength)
        Specifies shape and number of non-zero elements that can be stored.
        Parameters:
        numRows - Number of rows
        numCols - Number of columns
        arrayLength - Initial maximum number of non-zero elements that can be in the matrix
    • Method Detail

      • 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.
      • createLike

        public FMatrixSparseCSC createLike()
        Description copied from interface: Matrix
        Creates a new matrix with the same shape as this matrix
        Specified by:
        createLike in interface Matrix
      • set

        public void set​(Matrix original)
        Description copied from interface: Matrix
        Sets this matrix to be identical to the 'original' matrix passed in.
        Specified by:
        set in interface Matrix
      • 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​(java.lang.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:
        Formatter
      • printNonZero

        public void printNonZero()
        Description copied from interface: MatrixSparse
        Prints to standard out the non-zero elements only.
        Specified by:
        printNonZero in interface MatrixSparse
      • 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
      • get

        public float get​(int row,
                         int col)
        Description copied from interface: FMatrix
        Returns the value of value of the specified matrix element.
        Specified by:
        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)
        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.
      • nz_index

        public int nz_index​(int row,
                            int col)
        Returns the index in nz_rows for the element at (row,col) if it already exists in the matrix. If not then -1 is returned.
        Parameters:
        row - row coordinate
        col - column coordinate
        Returns:
        nz_row index or -1 if the element does not exist
      • set

        public void set​(int row,
                        int col,
                        float val)
        Description copied from interface: FMatrix
        Sets the value of the specified matrix element.
        Specified by:
        set in interface FMatrix
        Parameters:
        row - Matrix element's row index..
        col - Matrix element's column index.
        val - The element's new value.
      • unsafe_set

        public void unsafe_set​(int row,
                               int col,
                               float val)
        Description copied from interface: FMatrix
        Same as FMatrix.set(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_set in interface FMatrix
        Parameters:
        row - Matrix element's row index..
        col - Matrix element's column index.
        val - The element's new value.
      • 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
      • 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
      • create

        public FMatrixSparseCSC 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
      • getNumElements

        public int getNumElements()
        Description copied from interface: FMatrix
        Returns the number of elements in this matrix, which is the number of rows times the number of columns.
        Specified by:
        getNumElements in interface FMatrix
        Returns:
        Number of elements in this matrix.
      • 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.
      • 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
      • 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
      • growMaxLength

        public void growMaxLength​(int arrayLength,
                                  boolean preserveValue)
        Increases the maximum size of the data array so that it can store sparse data up to 'length'. The class parameter nz_length is not modified by this function call.
        Parameters:
        arrayLength - Desired maximum length of sparse data
        preserveValue - If true the old values will be copied into the new arrays. If false that step will be skipped.
      • growMaxColumns

        public void growMaxColumns​(int desiredColumns,
                                   boolean preserveValue)
        Increases the maximum number of columns in the matrix.
        Parameters:
        desiredColumns - Desired number of columns.
        preserveValue - If the array needs to be expanded should it copy the previous values?
      • histogramToStructure

        public void histogramToStructure​(int[] histogram)
        Given the histogram of columns compute the col_idx for the matrix. nz_length is automatically set and nz_values will grow if needed.
        Parameters:
        histogram - histogram of column values in the sparse matrix. modified, see above.
      • sortIndices

        public void sortIndices​(SortCoupledArray_F32 sorter)
        Sorts the row indices in ascending order.
        Parameters:
        sorter - (Optional) Used to sort rows. If null a new instance will be declared internally.
      • copyStructure

        public void copyStructure​(FMatrixSparseCSC orig)
        Copies the non-zero structure of orig into "this"
        Parameters:
        orig - Matrix who's structure is to be copied
      • isIndicesSorted

        public boolean isIndicesSorted()
        If the indices has been sorted or not
        Returns:
        true if sorted or false if not sorted
      • isFull

        public boolean isFull()
        Returns true if number of non-zero elements is the maximum size
        Returns:
        true if no more non-zero elements can be added
      • getType

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