Interface TensorOverSemiring<T extends TensorOverSemiring<T,U,V,W>,U extends TensorOverSemiring<U,U,V,W>,V,W>

Type Parameters:
T - Type of this tensor.
U - Type of dense tensor equivalent to T. If T is dense, then this should be the same type as T. This parameter required because some ops between two sparse tensors may result in a dense tensor.
V - Storage for data of this tensor.
W - Type (or wrapper) of an element of this tensor. Should satisfy the axioms of a semiring as stated.
All Known Subinterfaces:
FieldTensorMixin<T,U,V>, RingTensorMixin<T,U,V>, SemiringTensorMixin<T,U,V>, TensorOverField<T,U,V,W>, TensorOverRing<T,U,V,W>
All Known Implementing Classes:
AbstractCooFieldMatrix, AbstractCooFieldTensor, AbstractCooFieldVector, AbstractCooRingMatrix, AbstractCooRingTensor, AbstractCooRingVector, AbstractCooSemiringMatrix, AbstractCooSemiringTensor, AbstractCooSemiringVector, AbstractCsrFieldMatrix, AbstractCsrRingMatrix, AbstractCsrSemiringMatrix, AbstractDenseDoubleTensor, AbstractDenseFieldMatrix, AbstractDenseFieldTensor, AbstractDenseFieldVector, AbstractDenseRingMatrix, AbstractDenseRingTensor, AbstractDenseRingVector, AbstractDenseSemiringMatrix, AbstractDenseSemiringTensor, AbstractDenseSemiringVector, AbstractDoubleTensor, CMatrix, CooCMatrix, CooCTensor, CooCVector, CooFieldMatrix, CooFieldTensor, CooFieldVector, CooMatrix, CooRingMatrix, CooRingTensor, CooRingVector, CooSemiringMatrix, CooSemiringTensor, CooSemiringVector, CooTensor, CooVector, CsrCMatrix, CsrFieldMatrix, CsrMatrix, CsrRingMatrix, CsrSemiringMatrix, CTensor, CVector, FieldMatrix, FieldTensor, FieldVector, Matrix, RingMatrix, RingTensor, RingVector, SemiringMatrix, SemiringTensor, SemiringVector, Tensor, Vector

public interface TensorOverSemiring<T extends TensorOverSemiring<T,U,V,W>,U extends TensorOverSemiring<U,U,V,W>,V,W>
This interface specifies methods which any tensor whose data are elements of a semiring should implement. This includes primitive values.

To allow for primitive types, the elements of this tensor do not necessarily have to implement Semiring.

Formally, an semiring is a set R with the binary ops addition (+) and multiplication (*) defined such that for elements a, b, c in R the following are satisfied:

  • Addition and multiplication are associative: a + (b + c) = (a + b) + c and a * (b * c) = (a * b) * c.
  • Addition is commutative: a + b = b + a
  • Existence of additive and multiplicative identities: There exists two distinct elements 0 and 1 in R such that a + 0 = 0 and a * 1 = 1 (called the additive and multiplicative identities respectively).
  • Distributivity of multiplication over addition: a * (b + c) = (a * b) + (a * c).
  • Method Summary

    Modifier and Type
    Method
    Description
    add(T b)
    Computes the element-wise sum between two tensors of the same shape.
    add(W b)
    Adds a scalar value to each entry of this tensor.
    void
    addEq(W b)
    Adds a scalar value to each entry of this tensor and stores the result in this tensor.
    Computes the element-wise multiplication of two tensors of the same shape.
    Gets the data of this tensor.
    int
    Gets the rank of this tensor.
    Gets the shape of this tensor.
    boolean
    Checks if this tensor only contains ones.
    boolean
    Checks if this tensor only contains zeros.
    makeLikeTensor(Shape shape, V entries)
    Constructs a tensor of the same type as this tensor with the given the shape and data.
    mult(W b)
    Multiplies a scalar value to each entry of this tensor.
    void
    multEq(W b)
    Multiplies a scalar value to each entry of this tensor and stores the result in this tensor.
    Computes the product of all values in this tensor.
    sum()
    Computes the sum of all values in this tensor.
    default AbstractTensor<?,V,W>
    tensorDot(T src2)
    Computes the tensor dot product of this tensor with a second tensor.
    default AbstractTensor<?,V,W>
    tensorDot(T src2, int axes)
    Computes the tensor contraction of this tensor with a specified tensor over the specified axes.
    tensorDot(T src2, int[] aAxes, int[] bAxes)
    Computes the tensor contraction of this tensor with a specified tensor over the specified set of axes.
    default AbstractTensor<?,V,W>
    tensorDot(T src2, int aAxis, int bAxis)
    Computes the tensor contraction of this tensor with a specified tensor over the specified axes.
    default TensorOverSemiring<?,?,?,W>
    Computes the generalized tensor trace of this tensor along first and second axes.
    tensorTr(int axis1, int axis2)
    Computes the generalized trace of this tensor along the specified axes.
  • Method Details

    • getData

      V getData()
      Gets the data of this tensor.
      Returns:
      The data of this tensor.
    • makeLikeTensor

      T makeLikeTensor(Shape shape, V entries)
      Constructs a tensor of the same type as this tensor with the given the shape and data. The resulting tensor will also have the same non-zero indices as this tensor.
      Parameters:
      shape - Shape of the tensor to construct.
      entries - Entries of the tensor to construct.
      Returns:
      A tensor of the same type and with the same non-zero indices as this tensor with the given the shape and data.
    • getShape

      Shape getShape()
      Gets the shape of this tensor.
      Returns:
      The shape of this tensor.
    • getRank

      int getRank()
      Gets the rank of this tensor.
      Returns:
      The rank of this tensor.
    • add

      T add(W b)
      Adds a scalar value to each entry of this tensor. If the tensor is sparse, the scalar will only be added to the non-zero data of the tensor.
      Parameters:
      b - Scalar field value in sum.
      Returns:
      The sum of this tensor with the scalar b.
    • addEq

      void addEq(W b)
      Adds a scalar value to each entry of this tensor and stores the result in this tensor.
      Parameters:
      b - Scalar field value in sum.
    • add

      T add(T b)
      Computes the element-wise sum between two tensors of the same shape.
      Parameters:
      b - Second tensor in the element-wise sum.
      Returns:
      The sum of this tensor with b.
      Throws:
      TensorShapeException - If this tensor and b do not have the same shape.
    • mult

      T mult(W b)
      Multiplies a scalar value to each entry of this tensor.
      Parameters:
      b - Scalar value in product.
      Returns:
      The product of this tensor with b.
    • multEq

      void multEq(W b)
      Multiplies a scalar value to each entry of this tensor and stores the result in this tensor.
      Parameters:
      b - Scalar value in product.
    • elemMult

      T elemMult(T b)
      Computes the element-wise multiplication of two tensors of the same shape.
      Parameters:
      b - Second tensor in the element-wise product.
      Returns:
      The element-wise product between this tensor and b.
      Throws:
      IllegalArgumentException - If this tensor and b do not have the same shape.
    • tensorDot

      default AbstractTensor<?,V,W> tensorDot(T src2, int axes)
      Computes the tensor contraction of this tensor with a specified tensor over the specified axes. If axes=N, then the product sums will be computed along the last N dimensions of this tensor and the first N dimensions of the src2 tensor.
      Parameters:
      src2 - Tensor to contract with this tensor.
      axes - Axes specifying the number of axes to compute the tensor dot product over. If axes=N, then the product sums will be computed along the last N dimensions of this tensor and the first N dimensions of.
      Returns:
      The tensor dot product over the specified axes.
      Throws:
      IllegalArgumentException - If the two tensors shapes do not match along the specified axes aAxis and bAxis.
      IllegalArgumentException - If either axis is out of bounds of the corresponding tensor.
    • tensorDot

      default AbstractTensor<?,V,W> tensorDot(T src2, int aAxis, int bAxis)
      Computes the tensor contraction of this tensor with a specified tensor over the specified axes. That is, computes the sum of products between the two tensors along the specified axes.
      Parameters:
      src2 - Tensor to contract with this tensor.
      aAxis - Axis along which to compute products for this tensor.
      bAxis - Axis along which to compute products for src2 tensor.
      Returns:
      The tensor dot product over the specified axes.
      Throws:
      IllegalArgumentException - If the two tensors shapes do not match along the specified axes aAxis and bAxis.
      IllegalArgumentException - If either axis is out of bounds of the corresponding tensor.
    • tensorDot

      AbstractTensor<?,V,W> tensorDot(T src2, int[] aAxes, int[] bAxes)
      Computes the tensor contraction of this tensor with a specified tensor over the specified set of axes. That is, computes the sum of products between the two tensors along the specified set of axes.
      Parameters:
      src2 - Tensor to contract with this tensor.
      aAxes - Axes along which to compute products for this tensor.
      bAxes - Axes along which to compute products for src2 tensor.
      Returns:
      The tensor dot product over the specified axes.
      Throws:
      IllegalArgumentException - If the two tensors shapes do not match along the specified axes pairwise in aAxes and bAxes.
      IllegalArgumentException - If aAxes and bAxes do not match in length, or if any of the axes are out of bounds for the corresponding tensor.
    • tensorDot

      default AbstractTensor<?,V,W> tensorDot(T src2)
      Computes the tensor dot product of this tensor with a second tensor. That is, sums the product of two tensor elements over the last axis of this tensor and the second-to-last axis of src2. If both tensors are rank 2, this is equivalent to matrix multiplication.
      Parameters:
      src2 - Tensor to compute dot product with this tensor.
      Returns:
      The tensor dot product over the last axis of this tensor and the second to last axis of src2.
      Throws:
      IllegalArgumentException - If this tensors shape along the last axis does not match src2 shape along the second-to-last axis.
    • tensorTr

      default TensorOverSemiring<?,?,?,W> tensorTr()

      Computes the generalized tensor trace of this tensor along first and second axes.

      The generalized tensor trace is the sum along the diagonal values of the 2D sub-arrays of this tensor specified by the first and second axes. The shape of the resulting tensor is equal to this tensor with the first and second axes removed.

      Returns:
      The generalized trace of this tensor along first and second axes.
    • tensorTr

      TensorOverSemiring<?,?,?,W> tensorTr(int axis1, int axis2)

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

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

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

      boolean isZeros()
      Checks if this tensor only contains zeros.
      Returns:
      true if this tensor only contains zeros; false otherwise.
    • isOnes

      boolean isOnes()
      Checks if this tensor only contains ones. If this tensor is sparse, only the non-zero data are considered.
      Returns:
      true if this tensor only contains ones; false otherwise.
    • sum

      W sum()
      Computes the sum of all values in this tensor.
      Returns:
      The sum of all values in this tensor.
    • prod

      W prod()
      Computes the product of all values in this tensor.
      Returns:
      The product of all values in this tensor.