Class CooSemiringTensorOps

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

public final class CooSemiringTensorOps extends Object
This utility class contains methods for computing ops on two Semiring tensors.
  • Method Details

    • add

      public static <V extends Semiring<V>> SparseTensorData<V> add(Shape shape1, V[] src1Entries, int[][] src1Indices, Shape shape2, V[] src2Entries, int[][] src2Indices)
      Sums two complex sparse COO tensors and stores result in a new COO tensor.
      Parameters:
      shape1 - Shape of the first tensor.
      src1Entries - Non-zero data of the first tensor.
      src1Indices - Non-zero indices of the first tensor.
      shape2 - Shape of the second tensor.
      src2Entries - Non-zero data of the second tensor.
      src2Indices - Non-zero indices of the second tensor.
      Returns:
      The element-wise tensor sum of the two tensors.
      Throws:
      LinearAlgebraException - If the tensors src1 and src2 do not have the same shape.
    • elemMult

      public static <V extends Semiring<V>> SparseTensorData<V> elemMult(Shape shape1, V[] src1Entries, int[][] src1Indices, Shape shape2, V[] src2Entries, int[][] src2Indices)

      Computes the element-wise multiplication between two complex sparse COO tensors.

      Assumes indices of both tensors are sorted lexicographically by their indices.

      Parameters:
      shape1 - Shape of the first tensor.
      src1Entries - Non-zero data of the first tensor.
      src1Indices - Non-zero indices of the first tensor.
      shape2 - Shape of the second tensor.
      src2Entries - Non-zero data of the second tensor.
      src2Indices - Non-zero indices of the second tensor.
      Returns:
      The element-wise product of the two specified tensors.
      Throws:
      TensorShapeException - If !shape1.equals(shape2).
    • tensorTr

      public static <T extends Semiring<T>> SparseTensorData<T> tensorTr(Shape shape, T[] entries, int[][] indices, int axis1, int axis2)

      Computes the generalized trace of a tensor along the specified axes.

      The generalized tensor trace is the sum along the diagonal values of the 2D sub-arrays of the src tensor specified by axis1 and axis2. The shape of the resulting tensor is equal to the src tensor with the axis1 and axis2 removed.

      Parameters:
      axis1 - First axis for 2D sub-array.
      axis2 - Second axis for 2D sub-array.
      shape1 - Shape of the tensor.
      src1Entries - Non-zero data of the tensor.
      src1Indices - Non-zero indices of the tensor.
      Returns:
      The generalized trace of the src tensor along axis1 and axis2.
      Throws:
      IndexOutOfBoundsException - If the two axes are not both larger than zero and less than the src tensors rank.
      IllegalArgumentException - If axis1 == axis2 or src.shape.get(axis1) != src.shape.get(axis1) (i.e. the axes are equal or the tensor does not have the same length along the two axes.)