Class CooSemiringMatrix<T extends Semiring<T>>

Type Parameters:
T - The type of elements stored in this matrix, constrained by the Semiring interface.
All Implemented Interfaces:
Serializable, MatrixMixin<CooSemiringMatrix<T>,SemiringMatrix<T>,CooSemiringVector<T>,T>, SemiringTensorMixin<CooSemiringMatrix<T>,SemiringMatrix<T>,T>, TensorOverSemiring<CooSemiringMatrix<T>,SemiringMatrix<T>,T[],T>

public class CooSemiringMatrix<T extends Semiring<T>> extends AbstractCooSemiringMatrix<CooSemiringMatrix<T>,SemiringMatrix<T>,CooSemiringVector<T>,T>
Represents a sparse matrix whose non-zero elements are stored in Coordinate List (COO) format, with all data elements belonging to a specified Semiring type.

The COO format stores sparse matrix data as a list of coordinates (row and column indices) coupled with their corresponding non-zero values, rather than allocating memory for every element in the full matrix shape. This allows efficient representation and manipulation of large matrices containing a substantial number of zeros.

COO Representation:

A sparse COO matrix is stored as:

The total number of non-zero elements (AbstractCooSemiringMatrix.nnz) and the shape are fixed for a given instance, but the values in AbstractTensor.data and their corresponding AbstractCooSemiringMatrix.rowIndices and AbstractCooSemiringMatrix.colIndices may be updated. Many operations assume that the indices are sorted lexicographically by row, and then by column, but this is not strictly enforced. All provided operations preserve the lexicographical sorting of indices. If there is any doubt about the ordering of indices, use AbstractCooSemiringMatrix.sortIndices() to ensure they are explicitly sorted. COO tensors may also store multiple entries for the same index (referred to as an uncoalesced tensor). To combine all duplicated entries use AbstractCooSemiringMatrix.coalesce() or AbstractCooSemiringMatrix.coalesce(BinaryOperator).

COO matrices are optimized for "hyper-sparse" scenarios where the proportion of non-zero elements is extremely low, offering significant memory savings and potentially more efficient computational operations than equivalent dense representations.


 // shape, data, and indices for COO matrix.
 Shape shape = new Shape(512, 1024);
 BoolSemiring[] data = {
      new BoolSemiring(true), new BoolSemiring(false), new BoolSemiring(false),
      new BoolSemiring(true), new BoolSemiring(true),  new BoolSemiring(false),
 };
 int[] rowIndices = {0, 4, 128, 128, 128, 256};
 int[] colIndices = {16, 2, 5, 512, 1000, 28};

 // Create COO matrix.
 CooSemiringMatrix<BoolSemiring> matrix = new CooSemiringMatrix(
      shape, data, rowIndices, colIndices
 );

 // Sum matrices.
 CooSemiringMatrix<BoolSemiring> sum = matrix.add(matrix);

 // Multiply matrix to it's transpose.
 SemiringMatrix<BoolSemiring> prod = matrix.mult(matrix.T());
 prod = matrix.multTranspose(matrix);
 
See Also:
  • Constructor Details

    • CooSemiringMatrix

      public CooSemiringMatrix(Shape shape, T[] entries, int[] rowIndices, int[] colIndices)
      Creates a sparse coo matrix with the specified non-zero data, non-zero indices, and shape.
      Parameters:
      shape - Shape of this tensor.
      entries - Non-zero data of this sparse matrix.
      rowIndices - Non-zero row indices of this sparse matrix.
      colIndices - Non-zero column indies of this sparse matrix.
    • CooSemiringMatrix

      public CooSemiringMatrix(Shape shape, List<T> entries, List<Integer> rowIndices, List<Integer> colIndices)
      Creates a sparse coo matrix with the specified non-zero data, non-zero indices, and shape.
      Parameters:
      shape - Shape of this tensor.
      entries - Non-zero data of this sparse matrix.
      rowIndices - Non-zero row indices of this sparse matrix.
      colIndices - Non-zero column indies of this sparse matrix.
    • CooSemiringMatrix

      public CooSemiringMatrix(int rows, int cols, T[] entries, int[] rowIndices, int[] colIndices)
      Creates a sparse coo matrix with the specified non-zero data, non-zero indices, and shape.
      Parameters:
      rows - Rows in the coo matrix.
      cols - Columns in the coo matrix.
      entries - Non-zero data of this sparse matrix.
      rowIndices - Non-zero row indices of this sparse matrix.
      colIndices - Non-zero column indies of this sparse matrix.
    • CooSemiringMatrix

      public CooSemiringMatrix(int rows, int cols, List<T> entries, List<Integer> rowIndices, List<Integer> colIndices)
      Creates a sparse coo matrix with the specified non-zero data, non-zero indices, and shape.
      Parameters:
      rows - Rows in the coo matrix.
      cols - Columns in the coo matrix.
      entries - Non-zero data of this sparse matrix.
      rowIndices - Non-zero row indices of this sparse matrix.
      colIndices - Non-zero column indies of this sparse matrix.
  • Method Details