Class CooSemiringVectorOps

java.lang.Object
org.flag4j.linalg.ops.sparse.coo.semiring_ops.CooSemiringVectorOps

public final class CooSemiringVectorOps extends Object

Utility class for computing ops between sparse COO Semiring vectors.

Methods in this class assume that non-zero data are sorted lexicographically by index.

  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends Semiring<T>>
    SparseVectorData<T>
    add(Shape shape1, T[] src1, int[] src1Indices, Shape shape2, T[] src2, int[] src2Indices)
    Computes the element-wise vector addition between two real sparse vectors.
    static <T extends Semiring<T>>
    T
    dot(Shape shape1, T[] src1, int[] src1Indices, Shape shape2, T[] src2, int[] src2Indices)
    Computes the dot product between two sparse COO vectors.
    static <T extends Semiring<T>>
    SparseVectorData<T>
    elemMult(Shape shape1, T[] src1, int[] src1Indices, Shape shape2, T[] src2, int[] src2Indices)
    Computes the element-wise vector multiplication between two real sparse vectors.
    static <T extends Semiring<T>>
    void
    outerProduct(T[] src1, int[] src1Indices, int src1Size, T[] src2, int[] src2Indices, T[] dest)
    Computes the vector outer product between two sparse COO vectors.

    Methods inherited from class java.lang.Object

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

    • add

      public static <T extends Semiring<T>> SparseVectorData<T> add(Shape shape1, T[] src1, int[] src1Indices, Shape shape2, T[] src2, int[] src2Indices)
      Computes the element-wise vector addition between two real sparse vectors. Both sparse vectors are assumed to have their indices sorted lexicographically.
      Parameters:
      src1 - First sparse vector in the addition. Indices assumed to be sorted lexicographically.
      src2 - Second sparse vector in the addition. Indices assumed to be sorted lexicographically.
      Returns:
      A data class containing the non-zero data and indices of the sparse COO vector resulting from the vector addition.
      Throws:
      IllegalArgumentException - If the two vectors do not have the same size (full size including zeros).
    • elemMult

      public static <T extends Semiring<T>> SparseVectorData<T> elemMult(Shape shape1, T[] src1, int[] src1Indices, Shape shape2, T[] src2, int[] src2Indices)
      Computes the element-wise vector multiplication between two real sparse vectors. Both sparse vectors are assumed to have their indices sorted lexicographically.
      Parameters:
      shape1 - Shape of the first vector.
      src1 - Non-zero data of the first vector in the element-wise product.
      src1Indices - Non-zero indices of the first vector in the element-wise product.
      shape2 - Shape of the second vector.
      src2 - Non-zero data of the second vector in the element-wise product.
      src2Indices - Non-zero indices of the second vector in the element-wise product.
      Returns:
      A data class containing the non-zero data and indices of the sparse COO vector resulting from the element-wise product.
      Throws:
      IllegalArgumentException - If the two vectors do not have the same size (full size including zeros).
    • dot

      public static <T extends Semiring<T>> T dot(Shape shape1, T[] src1, int[] src1Indices, Shape shape2, T[] src2, int[] src2Indices)
      Computes the dot product between two sparse COO vectors.
      Parameters:
      shape1 - The shape of the first vector.
      src1 - The non-zero data of the first vector.
      src1Indices - The non-zero indices of the first vector.
      shape2 - The shape of the second vector.
      src2 - The non-zero data of the second vector.
      src2Indices - The non-zero indices of the second vector.
      Returns:
      The result of the dot product between the two specified COO vectors.
      Throws:
      TensorShapeException - If !shape1.equals(shape2).
    • outerProduct

      public static <T extends Semiring<T>> void outerProduct(T[] src1, int[] src1Indices, int src1Size, T[] src2, int[] src2Indices, T[] dest)
      Computes the vector outer product between two sparse COO vectors.
      Parameters:
      src1 - Non-zero data of the first vector.
      src1Indices - Non-zero indices in the first vector.
      src1Size - The full size of the first vector.
      src2 - Non-zero data of the second vector.
      src2Indices - Non-zero indices of the second vector.
      dest - Array to store the dense matrix resulting from the vector outer product.