Class CCSMatrix

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.Double>

    public class CCSMatrix
    extends ColumnMajorSparseMatrix
    This is a CCS (Compressed Column Storage) matrix class.
    • Field Detail

      • values

        private double[] values
      • rowIndices

        private int[] rowIndices
      • columnPointers

        private int[] columnPointers
    • Constructor Detail

      • CCSMatrix

        public CCSMatrix()
      • CCSMatrix

        public CCSMatrix​(int rows,
                         int columns)
      • CCSMatrix

        public CCSMatrix​(int rows,
                         int columns,
                         int capacity)
      • CCSMatrix

        public CCSMatrix​(int rows,
                         int columns,
                         int cardinality,
                         double[] values,
                         int[] rowIndices,
                         int[] columnPointers)
    • Method Detail

      • zero

        public static CCSMatrix zero​(int rows,
                                     int columns)
        Creates a zero CCSMatrix of the given shape: rows x columns.
      • zero

        public static CCSMatrix zero​(int rows,
                                     int columns,
                                     int capacity)
        Creates a zero CCSMatrix of the given shape: rows x columns with the given capacity.
      • diagonal

        public static CCSMatrix diagonal​(int size,
                                         double diagonal)
        Creates a diagonal CCSMatrix of the given size whose diagonal elements are equal to diagonal.
      • identity

        public static CCSMatrix identity​(int size)
        Creates an identity CCSMatrix of the given size.
      • random

        public static CCSMatrix random​(int rows,
                                       int columns,
                                       double density,
                                       java.util.Random random)
        Creates a random CCSMatrix of the given shape: rows x columns.
      • randomSymmetric

        public static CCSMatrix randomSymmetric​(int size,
                                                double density,
                                                java.util.Random random)
        Creates a random symmetric CCSMatrix of the given size.
      • from1DArray

        public static CCSMatrix from1DArray​(int rows,
                                            int columns,
                                            double[] array)
        Creates a new CCSMatrix from the given 1D array with compressing (copying) the underlying array.
      • from2DArray

        public static CCSMatrix from2DArray​(double[][] array)
        Creates a new CCSMatrix from the given 2D array with compressing (copying) the underlying array.
      • fromBinary

        public static CCSMatrix fromBinary​(byte[] array)
        Decodes CCSMatrix from the given byte array.
        Parameters:
        array - the byte array representing a matrix
        Returns:
        a decoded matrix
      • fromCSV

        public static CCSMatrix fromCSV​(java.lang.String csv)
        Parses CCSMatrix from the given CSV string.
        Parameters:
        csv - the CSV string representing a matrix
        Returns:
        a parsed matrix
      • fromMatrixMarket

        public static CCSMatrix fromMatrixMarket​(java.lang.String mm)
        Parses CCSMatrix from the given Matrix Market string.
        Parameters:
        mm - the string in Matrix Market format
        Returns:
        a parsed matrix
      • getOrElse

        public double getOrElse​(int i,
                                int j,
                                double defaultValue)
        Description copied from class: SparseMatrix
        Gets the specified element, or a defaultValue if there is no actual element at (i, j) in this sparse matrix.
        Specified by:
        getOrElse in class SparseMatrix
        Parameters:
        i - the element's row index
        j - the element's column index
        defaultValue - the default value
        Returns:
        the element of this vector or a default value
      • set

        public void set​(int i,
                        int j,
                        double value)
        Description copied from class: Matrix
        Sets the specified element of this matrix to given value.
        Specified by:
        set in class Matrix
        Parameters:
        i - element's row index
        j - element's column index
        value - element's new value
      • setAll

        public void setAll​(double value)
        Description copied from class: Matrix
        Sets all elements of this matrix to the given value.
        Overrides:
        setAll in class Matrix
        Parameters:
        value - the element's new value
      • getColumn

        public Vector getColumn​(int j)
        Description copied from class: Matrix
        Copies the specified column of this matrix into the vector.
        Overrides:
        getColumn in class SparseMatrix
        Parameters:
        j - the column index
        Returns:
        the column represented as vector
      • getRow

        public Vector getRow​(int i)
        Description copied from class: Matrix
        Copies the specified row of this matrix into the vector.
        Overrides:
        getRow in class SparseMatrix
        Parameters:
        i - the row index
        Returns:
        the row represented as vector
      • copyOfShape

        public Matrix copyOfShape​(int rows,
                                  int columns)
        Description copied from class: Matrix
        Copies this matrix into the new matrix with specified dimensions: rows and columns.
        Specified by:
        copyOfShape in class Matrix
        Parameters:
        rows - the number of rows in new matrix
        columns - the number of columns in new matrix
        Returns:
        the copy of this matrix with new size
      • eachNonZero

        public void eachNonZero​(MatrixProcedure procedure)
        Description copied from class: SparseMatrix
        Applies given procedure to each non-zero element of this matrix.
        Overrides:
        eachNonZero in class SparseMatrix
        Parameters:
        procedure - the matrix procedure
      • each

        public void each​(MatrixProcedure procedure)
        Description copied from class: Matrix
        Applies given procedure to each element of this matrix.
        Overrides:
        each in class Matrix
        Parameters:
        procedure - the matrix procedure
      • eachInColumn

        public void eachInColumn​(int j,
                                 VectorProcedure procedure)
        Description copied from class: Matrix
        Applies given procedure to each element of specified column of this matrix.
        Overrides:
        eachInColumn in class Matrix
        Parameters:
        j - the column index
        procedure - the vector procedure
      • updateAt

        public void updateAt​(int i,
                             int j,
                             MatrixFunction function)
        Description copied from class: Matrix
        Updates the specified element of this matrix by applying given function.
        Overrides:
        updateAt in class Matrix
        Parameters:
        i - the row index
        j - the column index
        function - the matrix function
      • nonZeroAt

        public boolean nonZeroAt​(int i,
                                 int j)
        Description copied from class: SparseMatrix
        Whether or not the specified element is not zero.
        Specified by:
        nonZeroAt in class SparseMatrix
        Parameters:
        i - element's row index
        j - element's column index
        Returns:
        true if specified element is not zero, false otherwise
      • searchForRowIndex

        private int searchForRowIndex​(int i,
                                      int left,
                                      int right)
      • insert

        private void insert​(int k,
                            int i,
                            int j,
                            double value)
      • remove

        private void remove​(int k,
                            int j)
      • growUp

        private void growUp()
      • align

        private int align​(int cardinality)
      • max

        public double max()
        Description copied from class: Matrix
        Searches for the maximum value of the elements of this matrix.
        Overrides:
        max in class Matrix
        Returns:
        maximum value of this matrix
      • min

        public double min()
        Description copied from class: Matrix
        Searches for the minimum value of the elements of this matrix.
        Overrides:
        min in class Matrix
        Returns:
        minimum value of this matrix
      • maxInColumn

        public double maxInColumn​(int j)
        Description copied from class: Matrix
        Searches for the maximum value of specified column in this matrix.
        Overrides:
        maxInColumn in class Matrix
        Parameters:
        j - the column index
        Returns:
        maximum value of specified column in this matrix
      • minInColumn

        public double minInColumn​(int j)
        Description copied from class: Matrix
        Searches for the minimum value of specified column in this matrix.
        Overrides:
        minInColumn in class Matrix
        Parameters:
        j - the column index
        Returns:
        minimum value of specified column in this matrix
      • select

        public Matrix select​(int[] rowIndices,
                             int[] columnIndices)
        Returns a CCSMatrix with the selected rows and columns.
        Overrides:
        select in class Matrix
        Parameters:
        rowIndices - the array of row indices
        columnIndices - the array of column indices
        Returns:
        the new matrix with the selected rows and columns
      • to

        public <T extends Matrix> T to​(MatrixFactory<T> factory)
        Description copied from class: Matrix
        Converts this matrix using the given factory.
        Overrides:
        to in class Matrix
        Type Parameters:
        T - type of the result matrix
        Parameters:
        factory - the factory that creates an output matrix
        Returns:
        converted matrix
      • blankOfShape

        public Matrix blankOfShape​(int rows,
                                   int columns)
        Description copied from class: Matrix
        Creates the blank matrix (a zero matrix with same size) of this matrix of the given shape: rows x columns.
        Specified by:
        blankOfShape in class Matrix
        Returns:
        blank matrix
      • iteratorOfColumn

        public VectorIterator iteratorOfColumn​(int j)
        Description copied from class: Matrix
        Returns a vector iterator of the given column {code j}.
        Overrides:
        iteratorOfColumn in class Matrix
        Returns:
        a vector iterator
      • toBinary

        public byte[] toBinary()
        Description copied from class: Matrix
        Encodes this matrix into a byte array.
        Specified by:
        toBinary in class Matrix
        Returns:
        a byte array representing this matrix