Class CsrOps

java.lang.Object
org.flag4j.linalg.ops.sparse.csr.CsrOps

public final class CsrOps extends Object
Utility class for computing ops on sparse CSR matrices.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> SparseMatrixData<T>
    applyBinOpp(Shape shape1, T[] src1Entries, int[] src1RowPointers, int[] src1ColIndices, Shape shape2, T[] src2Entries, int[] src2RowPointers, int[] src2ColIndices, BinaryOperator<T> opp, UnaryOperator<T> uOpp)
    Applies an element-wise binary operation to two csr matrices.
    static <T> SparseMatrixData<T>
    getSlice(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, int rowStart, int rowEnd, int colStart, int colEnd)
    Gets a specified slice of a CSR matrix.
    static <T extends Field<T>>
    void
    hermTranspose(T[] srcEntries, int[] srcRowPointers, int[] srcColIndices, T[] destEntries, int[] destRowPointers, int[] destColIndices)
    Computes herniation transpose of complex CSR matrix.
    static <T> void
    insertNewValue(T[] srcEntries, int[] srcRowPointers, int[] srcColIndices, T[] destEntries, int[] destRowPointers, int[] destColIndices, int row, int col, int insertionPoint, T value)
    Copies and inserts a new value into a sparse CSR matrix.
    static <T> void
    swapCols(T[] entries, int[] rowPointers, int[] colIndices, int colIdx1, int colIdx2)
    Swaps two columns in a sparse CSR matrix.
    static <T> void
    swapRows(T[] entries, int[] rowPointers, int[] colIndices, int rowIdx1, int rowIdx2)
    Swaps two rows in a sparse CSR matrix.
    static <T> void
    transpose(T[] srcEntries, int[] srcRowPointers, int[] srcColIndices, T[] destEntries, int[] destRowPointers, int[] destColIndices)
    Computes transpose of complex CSR matrix.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • transpose

      public static <T> void transpose(T[] srcEntries, int[] srcRowPointers, int[] srcColIndices, T[] destEntries, int[] destRowPointers, int[] destColIndices)
      Computes transpose of complex CSR matrix.
      Parameters:
      src - The matrix to transpose.
    • hermTranspose

      public static <T extends Field<T>> void hermTranspose(T[] srcEntries, int[] srcRowPointers, int[] srcColIndices, T[] destEntries, int[] destRowPointers, int[] destColIndices)
      Computes herniation transpose of complex CSR matrix.
      Parameters:
      src - The matrix to transpose.
    • applyBinOpp

      public static <T> SparseMatrixData<T> applyBinOpp(Shape shape1, T[] src1Entries, int[] src1RowPointers, int[] src1ColIndices, Shape shape2, T[] src2Entries, int[] src2RowPointers, int[] src2ColIndices, BinaryOperator<T> opp, UnaryOperator<T> uOpp)

      Applies an element-wise binary operation to two csr matrices.

      Note, this methods efficiency relies heavily on the assumption that both operand matrices are very large and very sparse. If the two matrices are not large and very sparse, this method will likely be significantly slower than simply converting the matrices to dene matrices and using a dense matrix addition algorithm.

      Parameters:
      shape1 - Shape of the first CSR matrix.
      src1Entries - Non-zero data of the first CSR matrix.
      src1RowPointers - Non-zero row pointers of the first CSR matrix.
      src1ColIndices - Non-zero column indices of the first CSR matrix.
      shape2 - Shape of the second CSR matrix.
      src2Entries - Non-zero data of the second CSR matrix.
      src2RowPointers - Non-zero row pointers of the second CSR matrix.
      src2ColIndices - Non-zero column indices of the second CSR matrix.
      opp - Binary operator to apply element-wise to src1 and src2.
      uOpp - Unary operator for use with binary ops which are not commutative such as subtraction. If the operation is commutative this should be null. If the binary operation is not commutative, it needs to be decomposable to one commutative binary operation opp and one unary operation uOpp such that it is equivalent to opp.apply(x, uOpp.apply(y)).
      Returns:
      The result of applying the specified binary operation to src1 and src2 element-wise.
      Throws:
      IllegalArgumentException - If src1 and src2 do not have the same shape.
    • insertNewValue

      public static <T> void insertNewValue(T[] srcEntries, int[] srcRowPointers, int[] srcColIndices, T[] destEntries, int[] destRowPointers, int[] destColIndices, int row, int col, int insertionPoint, T value)
      Copies and inserts a new value into a sparse CSR matrix. This method assumes that a non-zero value is not already present at the specified indices.
      Parameters:
      srcEntries - Non-zero data of the original CSR matrix.
      srcRowPointers - Non-zero row pointers of the original CSR matrix.
      srcColIndices - Non-zero column indices of the original CSR matrix.
      destEntries - Array to store the new data in.
      destRowPointers - Array to store the new row pointers in.
      destColIndices - Array to store the new column indices in.
      row - Row index of the point to insert.
      col - Column index of the point to insert.
      insertionPoint - Index within srcEntries that the new value should be inserted at.
      value - New value to insert into the CSR matrix.
    • swapRows

      public static <T> void swapRows(T[] entries, int[] rowPointers, int[] colIndices, int rowIdx1, int rowIdx2)
      Swaps two rows in a sparse CSR matrix. This is done in place.
      Parameters:
      entries - Non-zero data of the CSR matrix.
      rowPointers - Non-zero row pointers of the CSR matrix.
      colIndices - Non-zero column indices of the CSR matrix.
      rowIdx1 - Index of the first row to swap.
      rowIdx2 - Index of the second row to swap.
      Throws:
      IndexOutOfBoundsException - If either rowIdx1 or rowIdx2 is out of bounds of the rows of this matrix.
    • swapCols

      public static <T> void swapCols(T[] entries, int[] rowPointers, int[] colIndices, int colIdx1, int colIdx2)
      Swaps two columns in a sparse CSR matrix. This is done in place.
      Parameters:
      entries - Non-zero data of the CSR matrix.
      rowPointers - Non-zero row pointers of the CSR matrix.
      colIndices - Non-zero column indices of the CSR matrix.
      colIdx1 - Index of the first column to swap.
      colIdx2 - Index of the second column to swap.
      Throws:
      IndexOutOfBoundsException - If either colIndex1 or colIndex2 is out of bounds of the columns of this matrix.
    • getSlice

      public static <T> SparseMatrixData<T> getSlice(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, int rowStart, int rowEnd, int colStart, int colEnd)
      Gets a specified slice of a CSR matrix.
      Parameters:
      shape - Shape of the CSR matrix.
      entries - Non-zero data of the CSR matrix.
      rowPointers - Non-zero row pointers of the CSR matrix.
      colIndices - Non-zero column indices of the CSR matrix.
      rowStart - Starting row index of slice (inclusive).
      rowEnd - Ending row index of slice (exclusive).
      colStart - Starting column index of slice (inclusive).
      colEnd - Ending row index of slice (exclusive).
      Returns:
      The specified slice of this matrix. This is a completely new matrix and NOT a view into the matrix.
      Throws:
      ArrayIndexOutOfBoundsException - If any of the indices are out of bounds of this matrix.
      IllegalArgumentException - If rowEnd is not greater than rowStart or if colEnd is not greater than colStart.