Class CooDataSorter<T>

java.lang.Object
org.flag4j.linalg.ops.sparse.coo.CooDataSorter<T>

public class CooDataSorter<T> extends Object

A class which can be used to sort the indices, along with data values, in lexicographical order.

This class is not thread safe.

Specifically, if a sparse tensor has shape (10, 15, 5, 2) and the following indices and non-zero values,

      - Indices: {{4, 1, 2, 0}, {4, 0, 1, 2},
                  {1, 2, 3, 0}, {2, 3, 5, 1},
                  {9, 10, 4, 1}, {1, 2, 1, 1}}
      - Values: {1.1, 2.2, 3.3, 4.4, 5.5, 6.6}
 
then the sorted indices and non-zero values will be,
      - Indices: {{1, 2, 1, 1}, {1, 2, 3, 0},
                  {2, 3, 5, 1}, {4, 0, 1, 2},
                  {4, 1, 2, 0}, {9, 10, 4, 1}}
      - Values: {6.6, 3.3, 4.4, 2.2, 1.1, 5.5}
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    CooDataSorter(List<T> values, List<Integer> rowIndices, List<Integer> colIndices)
    Creates a sorter which can sort the indices and values of a COO matrix lexicographically.
  • Method Summary

    Modifier and Type
    Method
    Description
    Sorts the wrapped indices in lexicographical order while maintaining the order of the non-zero values so that their order matches the order of the indices.
    void
    unwrap(double[] values, int[] indices)
    Unwraps sparse data values and indices.
    void
    unwrap(double[] values, int[][] indices)
    Unwraps sparse data values and indices.
    void
    unwrap(double[] values, int[] rowIndices, int[] colIndices)
    Unwraps sparse data values and indices.
    void
    unwrap(Object[] values, int[] indices)
    Unwraps sparse data values and indices.
    void
    unwrap(Object[] values, int[][] indices)
    Unwraps sparse data values and indices.
    void
    unwrap(Object[] values, int[] rowIndices, int[] colIndices)
    Unwraps sparse data values and indices.
    wrap(double[] values, int[] indices)
    Factory method which wraps data in an instance of CooDataSorter and returns that instance.
    wrap(double[] values, int[][] indices)
    Factory method which wraps data in an instance of CooDataSorter and returns that instance.
    wrap(double[] values, int[] rowIndices, int[] colIndices)
    Factory method which wraps data in an instance of CooDataSorter and returns that instance.
    wrap(Object[] values, int[] indices)
    Factory method which wraps data in an instance of CooDataSorter and returns that instance.
    wrap(Object[] values, int[][] indices)
    Factory method which wraps data in an instance of CooDataSorter and returns that instance.
    wrap(Object[] values, int[] rowIndices, int[] colIndices)
    Factory method which wraps data in an instance of CooDataSorter and returns that instance.

    Methods inherited from class java.lang.Object

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

    • CooDataSorter

      public CooDataSorter(List<T> values, List<Integer> rowIndices, List<Integer> colIndices)

      Creates a sorter which can sort the indices and values of a COO matrix lexicographically.

      When sparseSort() is called on an instance created with this constructor, the sorting will be done in place.

      Parameters:
      values - Non-zero values of the sparse COO matrix.
      rowIndices - Row indices of the sparse COO matrix.
      colIndices - Row indices of the sparse COO matrix.
  • Method Details

    • wrap

      public static CooDataSorter wrap(Object[] values, int[][] indices)
      Factory method which wraps data in an instance of CooDataSorter and returns that instance.
      Parameters:
      values - Non-zero values of the sparse tensor.
      indices - Indices of non-zero values in the sparse tensor.
      Returns:
      A new instance of CooDataSorter which wraps the specified values and indices.
    • wrap

      public static CooDataSorter wrap(Object[] values, int[] indices)
      Factory method which wraps data in an instance of CooDataSorter and returns that instance.
      Parameters:
      values - Non-zero values of the sparse tensor.
      indices - Indices of non-zero values in the sparse tensor.
      Returns:
      A new instance of CooDataSorter which wraps the specified values and indices.
    • wrap

      public static CooDataSorter wrap(double[] values, int[][] indices)
      Factory method which wraps data in an instance of CooDataSorter and returns that instance.
      Parameters:
      values - Non-zero values of the sparse tensor.
      indices - Indices of non-zero values in the sparse tensor.
      Returns:
      A new instance of CooDataSorter which wraps the specified values and indices.
    • wrap

      public static CooDataSorter wrap(double[] values, int[] indices)
      Factory method which wraps data in an instance of CooDataSorter and returns that instance.
      Parameters:
      values - Non-zero values of the sparse tensor.
      indices - Indices of non-zero values in the sparse tensor.
      Returns:
      A new instance of CooDataSorter which wraps the specified values and indices.
    • wrap

      public static CooDataSorter wrap(double[] values, int[] rowIndices, int[] colIndices)
      Factory method which wraps data in an instance of CooDataSorter and returns that instance.
      Parameters:
      values - Non-zero values of the sparse tensor.
      rowIndices - Row indices of non-zero data of the sparse tensor.
      colIndices - Column indices of non-zero data of the sparse tensor.
      Returns:
      A new instance of CooDataSorter which wraps the specified values and indices.
    • wrap

      public static CooDataSorter wrap(Object[] values, int[] rowIndices, int[] colIndices)
      Factory method which wraps data in an instance of CooDataSorter and returns that instance.
      Parameters:
      values - Non-zero values of the sparse tensor.
      rowIndices - Row indices of non-zero data of the sparse tensor.
      colIndices - Column indices of non-zero data of the sparse tensor.
      Returns:
      A new instance of CooDataSorter which wraps the specified values and indices.
    • sparseSort

      public CooDataSorter sparseSort()
      Sorts the wrapped indices in lexicographical order while maintaining the order of the non-zero values so that their order matches the order of the indices.
      Returns:
      A reference to this sparse data wrapper.
    • unwrap

      public void unwrap(Object[] values, int[][] indices)
      Unwraps sparse data values and indices.
      Parameters:
      values - Storage for unwrapped values. Must have the same length as that passed to the constructor. Modified.
      indices - Storage for unwrapped indices. Must have the same shape as that passed to the constructor. Modified.
    • unwrap

      public void unwrap(Object[] values, int[] indices)
      Unwraps sparse data values and indices.
      Parameters:
      values - Storage for unwrapped values. Must have the same length as that passed to the constructor. Modified.
      indices - Storage for unwrapped indices. Must have the same shape as that passed to the constructor. Modified.
    • unwrap

      public void unwrap(double[] values, int[][] indices)
      Unwraps sparse data values and indices.
      Parameters:
      values - Storage for unwrapped values. Must have the same length as that passed to the constructor. Modified.
      indices - Storage for unwrapped indices. Must have the same shape as that passed to the constructor. Modified.
    • unwrap

      public void unwrap(double[] values, int[] rowIndices, int[] colIndices)
      Unwraps sparse data values and indices.
      Parameters:
      values - Storage for unwrapped values. Must have the same length as that passed to the constructor. Modified.
      rowIndices - Storage for unwrapped row indices. Must have the same shape as that passed to the constructor. Modified.
      colIndices - Storage for unwrapped column indices. Must have the same shape as that passed to the constructor. Modified.
    • unwrap

      public void unwrap(Object[] values, int[] rowIndices, int[] colIndices)
      Unwraps sparse data values and indices.
      Parameters:
      values - Storage for unwrapped values. Must have the same length as that passed to the constructor. Modified.
      rowIndices - Storage for unwrapped row indices. Must have the same shape as that passed to the constructor. Modified.
      colIndices - Storage for unwrapped column indices. Must have the same shape as that passed to the constructor. Modified.
    • unwrap

      public void unwrap(double[] values, int[] indices)
      Unwraps sparse data values and indices.
      Parameters:
      values - Storage for unwrapped values. Must have the same length as that passed to the constructor. Modified.
      indices - Storage for unwrapped indices. Must have the same shape as that passed to the constructor. Modified.