Class CooRingVector<T extends Ring<T>>

Type Parameters:
T - The type of elements stored in this vector, constrained by the Ring interface.
All Implemented Interfaces:
Serializable, RingTensorMixin<CooRingVector<T>,RingVector<T>,T>, TensorOverRing<CooRingVector<T>,RingVector<T>,T[],T>, SemiringTensorMixin<CooRingVector<T>,RingVector<T>,T>, TensorOverSemiring<CooRingVector<T>,RingVector<T>,T[],T>, VectorMixin<CooRingVector<T>,CooRingMatrix<T>,RingMatrix<T>,T>

public class CooRingVector<T extends Ring<T>> extends AbstractCooRingVector<CooRingVector<T>,RingVector<T>,CooRingMatrix<T>,RingMatrix<T>,T>
Represents a sparse vector whose non-zero elements are stored in Coordinate List (COO) format, with all data elements belonging to a specified Ring type.

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

A sparse COO vector is stored as:

The total number of non-zero elements (AbstractCooSemiringVector.nnz) and the shape/size is fixed for a given instance, but the values in AbstractTensor.data and their corresponding AbstractCooSemiringVector.indices may be updated. Many operations assume that the indices are sorted lexicographically, 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 AbstractCooSemiringVector.sortIndices() to ensure they are sorted. COO tensors may also store multiple entries for the same index (referred to as an uncoalesced tensor). To combine all duplicated entries use AbstractCooSemiringVector.coalesce() or AbstractCooSemiringVector.coalesce(BinaryOperator).

COO vectors 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.

Example Usage:


 // shape, data, and indices for COO vector.
 Shape shape = new Shape(512);
 RealInt32[] data = {
      new RealInt32(1), new RealInt32(2), new RealInt32(3),
      new RealInt32(4), new RealInt32(5), new RealInt32(6)
 };
 int[] indices = {0, 4, 128, 128, 128, 256};

 // Create COO vector.
 CooRingVector<RealInt32> vector = new CooRingVector(shape, data, indices);

 // Sum vectors.
 CooRingVector<RealInt32> sum = vector.add(vector);

 // Compute vector inner product.
 RealInt32 prod = vector.inner(vector);

 // Compute vector outer product.
 RingMatrix<RealInt32> prod = vector.outer(vector);
 
See Also:
  • Constructor Details

    • CooRingVector

      public CooRingVector(int size, T[] entries, int[] indices)
      Creates a tensor with the specified data and shape.
      Parameters:
      size -
      entries - Entries of this tensor. If this tensor is dense, this specifies all data within the tensor. If this tensor is sparse, this specifies only the non-zero data of the tensor.
      indices -
    • CooRingVector

      public CooRingVector(Shape shape, T[] entries, int[] indices)
      Creates a tensor with the specified data and shape.
      Parameters:
      entries - Entries of this tensor. If this tensor is dense, this specifies all data within the tensor. If this tensor is sparse, this specifies only the non-zero data of the tensor.
      indices -
      size -
    • CooRingVector

      public CooRingVector(Shape shape, List<T> entries, List<Integer> indices)
      Creates sparse COO vector with the specified size, non-zero data, and non-zero indices.
      Parameters:
      entries - The non-zero data of this vector.
      indices - The indices of the non-zero values.
      Shape - The shape of this vector. Must be rank-1.
    • CooRingVector

      public CooRingVector(int size)
      Creates a zero vector of the specified size.
    • CooRingVector

      public CooRingVector(int size, List<T> entries, List<Integer> indices)
      Creates sparse COO vector with the specified size, non-zero data, and non-zero indices.
      Parameters:
      size - The size of this vector.
      entries - The non-zero data of this vector.
      indices - The indices of the non-zero values.
  • Method Details