Class CsrConversions

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

public final class CsrConversions extends Object
Utility class for converting CSR matrices to flat matrices, dense matrices, etc.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Shape
    flatten(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, int axis, int[] destRowPointers, int[] destColIndices)
    Computes the new row pointers and column indices for a sparse CSR matrix flattened along some axis.
    static <T> void
    toCoo(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, T[] destEntries, int[] destRowIndices, int[] destColIndices)
    Converts a sparse CSR matrix to an equivalent sparse COO matrix.
    static <T> void
    toDense(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, T[] dest, T zero)
    Converts a sparse CSR matrix to a dense matrix.

    Methods inherited from class java.lang.Object

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

    • flatten

      public static <T> Shape flatten(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, int axis, int[] destRowPointers, int[] destColIndices)
      Computes the new row pointers and column indices for a sparse CSR matrix flattened along some axis.
      Parameters:
      shape - Shape of the CSR matrix to be flattened.
      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.
      axis - Axis along which to flatten matrix. Must be 0 or 1.
      • If axis==0 then the matrix will be flattened to a single row.
      • If axis==1 then the matrix will be flattened to a single column.
      destRowPointers - Array to store the non-zero row pointers resulting from flattening the CSR matrix along the specified axis.
      destColIndices - Array to store the non-zero column indices resulting from flattening the CSR matrix along the specified axis.
      Returns:
      The shape of the flattened matrix.
      Throws:
      LinearAlgebraException - If axis != 0 || axis != 1.
    • toDense

      public static <T> void toDense(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, T[] dest, T zero)
      Converts a sparse CSR matrix to a dense matrix.
      Parameters:
      shape - Shape of the CSR matrix. Must be rank 2.
      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.
      dest - Array to store the dense result in.
      zero - Zero element to fill zero value of the sparse matrix with.
      Throws:
      IllegalArgumentException - If dest.length < shape.totalEntriesIntValueExact()
    • toCoo

      public static <T> void toCoo(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, T[] destEntries, int[] destRowIndices, int[] destColIndices)
      Converts a sparse CSR matrix to an equivalent sparse COO 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.
      destEntries - Array to store the non-zero data of the COO matrix.
      destColIndices - Array to store the non-zero column indices of the COO matrix.
      rowIndices - Array to store the non-zero row indices of the COO matrix.