Interface SemiringTensorMixin<T extends SemiringTensorMixin<T,U,V>,U extends SemiringTensorMixin<U,U,V>,V extends Semiring<V>>

Type Parameters:
T - Type of this tensor.
U - Dense equivalent of this tensor. If this tensor is dense, this should be the same type as T
V - Type of an element of this tensor. Satisfies semiring axioms.
All Superinterfaces:
TensorOverSemiring<T,U,V[],V>
All Known Subinterfaces:
FieldTensorMixin<T,U,V>, RingTensorMixin<T,U,V>
All Known Implementing Classes:
AbstractCooFieldMatrix, AbstractCooFieldTensor, AbstractCooFieldVector, AbstractCooRingMatrix, AbstractCooRingTensor, AbstractCooRingVector, AbstractCooSemiringMatrix, AbstractCooSemiringTensor, AbstractCooSemiringVector, AbstractCsrFieldMatrix, AbstractCsrRingMatrix, AbstractCsrSemiringMatrix, AbstractDenseFieldMatrix, AbstractDenseFieldTensor, AbstractDenseFieldVector, AbstractDenseRingMatrix, AbstractDenseRingTensor, AbstractDenseRingVector, AbstractDenseSemiringMatrix, AbstractDenseSemiringTensor, AbstractDenseSemiringVector, CMatrix, CooCMatrix, CooCTensor, CooCVector, CooFieldMatrix, CooFieldTensor, CooFieldVector, CooRingMatrix, CooRingTensor, CooRingVector, CooSemiringMatrix, CooSemiringTensor, CooSemiringVector, CsrCMatrix, CsrFieldMatrix, CsrRingMatrix, CsrSemiringMatrix, CTensor, CVector, FieldMatrix, FieldTensor, FieldVector, RingMatrix, RingTensor, RingVector, SemiringMatrix, SemiringTensor, SemiringVector

public interface SemiringTensorMixin<T extends SemiringTensorMixin<T,U,V>,U extends SemiringTensorMixin<U,U,V>,V extends Semiring<V>> extends TensorOverSemiring<T,U,V[],V>
This interface provides default functionality for all tensors whose data are elements of a Semiring. This includes both sparse and dense tensors.
  • Method Summary

    Modifier and Type
    Method
    Description
    default T
    add(V b)
    Adds a scalar value to each entry of this tensor.
    default void
    addEq(V b)
    Adds a scalar value to each entry of this tensor and stores the result in this tensor.
    default int[]
    Finds the indices of the maximum value in this tensor.
    default int[]
    Finds the indices of the minimum value in this tensor.
    default boolean
    Checks if this tensor only contains ones.
    default boolean
    Checks if this tensor only contains zeros.
    default V[]
    makeEmptyDataArray(int length)
    Creates an empty array of the same type as the data array of this tensor.
    default V
    max()
    Finds the maximum value in this tensor.
    default V
    min()
    Finds the minimum value in this tensor.
    default T
    mult(V b)
    Multiplies a scalar value to each entry of this tensor.
    default void
    multEq(V b)
    Multiplies a scalar value to each entry of this tensor and stores the result in this tensor.
    default V
    Computes the product of all values in this tensor (or non-zero values if this tensor is sparse).
    default V
    sum()
    Computes the sum of all values in this tensor.

    Methods inherited from interface org.flag4j.arrays.backend.semiring_arrays.TensorOverSemiring

    add, elemMult, getData, getRank, getShape, makeLikeTensor, tensorDot, tensorDot, tensorDot, tensorDot, tensorTr, tensorTr
  • Method Details

    • makeEmptyDataArray

      default V[] makeEmptyDataArray(int length)
      Creates an empty array of the same type as the data array of this tensor.
      Parameters:
      length - The length of the array to construct.
      Returns:
      An empty array of the same type as the data array of this tensor.
    • add

      default T add(V 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.
      Specified by:
      add in interface TensorOverSemiring<T extends SemiringTensorMixin<T,U,V>,U extends SemiringTensorMixin<U,U,V>,V extends Semiring<V>[],V extends Semiring<V>>
      Parameters:
      b - Scalar field value in sum.
      Returns:
      The sum of this tensor with the scalar b.
    • addEq

      default void addEq(V b)
      Adds a scalar value to each entry of this tensor and stores the result in this tensor.
      Specified by:
      addEq in interface TensorOverSemiring<T extends SemiringTensorMixin<T,U,V>,U extends SemiringTensorMixin<U,U,V>,V extends Semiring<V>[],V extends Semiring<V>>
      Parameters:
      b - Scalar field value in sum.
    • mult

      default T mult(V b)
      Multiplies a scalar value to each entry of this tensor.
      Specified by:
      mult in interface TensorOverSemiring<T extends SemiringTensorMixin<T,U,V>,U extends SemiringTensorMixin<U,U,V>,V extends Semiring<V>[],V extends Semiring<V>>
      Parameters:
      b - Scalar value in product.
      Returns:
      The product of this tensor with b.
    • multEq

      default void multEq(V b)
      Multiplies a scalar value to each entry of this tensor and stores the result in this tensor.
      Specified by:
      multEq in interface TensorOverSemiring<T extends SemiringTensorMixin<T,U,V>,U extends SemiringTensorMixin<U,U,V>,V extends Semiring<V>[],V extends Semiring<V>>
      Parameters:
      b - Scalar value in product.
    • isZeros

      default boolean isZeros()
      Checks if this tensor only contains zeros.
      Specified by:
      isZeros in interface TensorOverSemiring<T extends SemiringTensorMixin<T,U,V>,U extends SemiringTensorMixin<U,U,V>,V extends Semiring<V>[],V extends Semiring<V>>
      Returns:
      true if this tensor only contains zeros; false otherwise.
    • isOnes

      default boolean isOnes()
      Checks if this tensor only contains ones. If this tensor is sparse, only the non-zero data are considered.
      Specified by:
      isOnes in interface TensorOverSemiring<T extends SemiringTensorMixin<T,U,V>,U extends SemiringTensorMixin<U,U,V>,V extends Semiring<V>[],V extends Semiring<V>>
      Returns:
      true if this tensor only contains ones; false otherwise.
    • sum

      default V sum()
      Computes the sum of all values in this tensor.
      Specified by:
      sum in interface TensorOverSemiring<T extends SemiringTensorMixin<T,U,V>,U extends SemiringTensorMixin<U,U,V>,V extends Semiring<V>[],V extends Semiring<V>>
      Returns:
      The sum of all values in this tensor.
    • prod

      default V prod()
      Computes the product of all values in this tensor (or non-zero values if this tensor is sparse).
      Specified by:
      prod in interface TensorOverSemiring<T extends SemiringTensorMixin<T,U,V>,U extends SemiringTensorMixin<U,U,V>,V extends Semiring<V>[],V extends Semiring<V>>
      Returns:
      The product of all values (or non-zero values if sparse) in this tensor.
    • min

      default V min()
      Finds the minimum value in this tensor. If this tensor is complex, then this method finds the smallest value in magnitude.
      Returns:
      The minimum value (smallest in magnitude for a complex valued tensor) in this tensor.
    • max

      default V max()
      Finds the maximum value in this tensor. If this tensor is complex, then this method finds the largest value in magnitude.
      Returns:
      The maximum value (largest in magnitude for a complex valued tensor) in this tensor.
    • argmin

      default int[] argmin()
      Finds the indices of the minimum value in this tensor.
      Returns:
      The indices of the minimum value in this tensor. If this value occurs multiple times, the indices of the first entry (in row-major ordering) are returned.
    • argmax

      default int[] argmax()
      Finds the indices of the maximum value in this tensor.
      Returns:
      The indices of the maximum value in this tensor. If this value occurs multiple times, the indices of the first entry (in row-major ordering) are returned.