Module ojalgo

Class R064CSC

    • Constructor Detail

      • R064CSC

        public R064CSC​(int nbRows,
                       int nbCols,
                       double[] elementValues,
                       int[] rowIndices,
                       int[] columnPointers)
        Creates a new CSC matrix store.
        Parameters:
        rows - The number of rows in the matrix
        cols - The number of columns in the matrix
        elementValues - The non-zero values
        rowIndices - The row index for each non-zero value
        columnPointers - The starting position in elementValues/rowIndices for each column
      • R064CSC

        public R064CSC​(int nbRows,
                       int nbCols,
                       int capacity)
        Parameters:
        nbRows - The number of rows
        nbCols - The number of columns
        capacity - The maximum number of non-zero elements
    • Method Detail

      • btran

        public static void btran​(R064CSC mtrxL,
                                 int r,
                                 PhysicalStore<java.lang.Double> arg)
        Assumes mtrxL is unit lower/left triangular, with the unit diagonal not stored.
      • calculateInfinityColumnNorms

        public static void calculateInfinityColumnNorms​(R064CSC matrix,
                                                        double[] norms)
      • calculateInfinityRowNorms

        public static void calculateInfinityRowNorms​(R064CSC matrix,
                                                     double[] norms)
      • calculateInfinitySymmetricNorms

        public static void calculateInfinitySymmetricNorms​(R064CSC matrix,
                                                           double[] norms)
        Algorithm assumes that the matrix is symmetric, and only a triangular part is stored.

        This implementation does NOT reset the norms array! If that array contains non-zero values those will be taken into account when calculating the norms.

      • ftran

        public static void ftran​(R064CSC mtrxL,
                                 int r,
                                 PhysicalStore<java.lang.Double> arg)
        Assumes mtrxL is unit lower/left triangular, with the unit diagonal not stored.
      • multiply

        public static void multiply​(double[] data,
                                    double[] left,
                                    R064CSC right)
        Transposed matrix-vector multiplication: data' = left' * right (A'x = y <-> x'A = y')
      • multiply

        public static void multiply​(double[] data,
                                    R064CSC left,
                                    double[] right)
        General matrix-vector multiplication: data = left * right

        The data array will be completely overwritten. No need to pre-fill it with zeros.

        Parameters:
        data - The array to store the result
        left - The left matrix in CSC format
        right - The right vector
      • multiplySymmetric

        public static void multiplySymmetric​(double[] data,
                                             R064CSC matrix,
                                             double[] vector)
        For a symmetric matrix A, the matrix-vector products A * x and x * A are equal. This method implements that assuming the matrix is symmetric but only stores the upper/right triangle.
      • newBuilder

        public static R064CSC.Builder newBuilder​(int nbRows,
                                                 int nbCols)
      • scale

        public static void scale​(R064CSC matrix,
                                 double scalar)
        Scales all non-zero entries of a sparse matrix by a scalar.
      • scaleColumns

        public static void scaleColumns​(R064CSC matrix,
                                        double[] scalars)
      • scaleRows

        public static void scaleRows​(R064CSC matrix,
                                     double[] scalars)
      • copyCSC

        public R064CSC copyCSC()
        Creates a deep copy of this CSC matrix store.
      • doubleValue

        public double doubleValue​(int row,
                                  int col)
        Gets the value at the specified row and column. Returns 0.0 if the element is not stored (i.e., is zero).
        Parameters:
        row - The row index
        col - The column index
        Returns:
        The value at the specified position, or 0.0 if not stored
      • firstInColumn

        public int firstInColumn​(int col)
        Description copied from interface: Structure2D
        The default value is simply 0, and if all elements are zeros then this.countRows().
        Parameters:
        col - The column index
        Returns:
        The row index of the first non-zero element in the specified column
      • firstInRow

        public int firstInRow​(int row)
        Description copied from interface: Structure2D
        The default value is simply 0, and if all elements are zeros then this.countColumns().
        Returns:
        The column index of the first non-zero element in the specified row
      • limitOfColumn

        public int limitOfColumn​(int col)
        Description copied from interface: Structure2D
        The default value is simply this.countRows(), and if all elements are zeros then 0.
        Specified by:
        limitOfColumn in interface Structure2D
        Overrides:
        limitOfColumn in class AbstractStore<java.lang.Double>
        Returns:
        The row index of the first zero element, after all non-zeros, in the specified column (index of the last non-zero + 1)
      • limitOfRow

        public int limitOfRow​(int row)
        Description copied from interface: Structure2D
        The default value is simply this.countColumns(), and if all elements are zeros then 0.
        Specified by:
        limitOfRow in interface Structure2D
        Overrides:
        limitOfRow in class AbstractStore<java.lang.Double>
        Returns:
        The column index of the first zero element, after all non-zeros, in the specified row (index of the last non-zero + 1)
      • multiply

        public void multiply​(Access1D<java.lang.Double> right,
                             TransformableRegion<java.lang.Double> target)
        Performs matrix-vector multiplication using the CSC format. This implementation is optimized for the CSC format by iterating over non-zero elements column by column and accumulating the results.
        Parameters:
        right - The vector to multiply with
        target - The target vector to store the result
      • nonzeros

        public R064CSC.NonZeroView nonzeros()
        Description copied from interface: Access1D
        Similar to Access1D.elements() but avoids elements that are structurally known to be zero. (That does not eliminate all zero-values from this view.) With an arbitrary (dense) unstructured implementation the Access1D.nonzeros() and Access1D.elements() methods do the same thing! Only some specific implementations are able to actually exploit structure/sparsity to view fewer elements.
      • transpose

        public R064CSR transpose()
        Returns:
        A transposed matrix instance.