Class DenseSemiringOps

java.lang.Object
org.flag4j.linalg.ops.dense.semiring_ops.DenseSemiringOps

public final class DenseSemiringOps extends Object
This class provides low level methods for computing ops on dense semiring tensors.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends Semiring<T>>
    T[]
    add(T[] src1, Shape shape1, T[] src2, Shape shape2, T[] dest)
    Computes the element-wise addition of two tensors.
    static <T extends Semiring<T>>
    T[]
    elemMult(T[] src1, Shape shape1, T[] src2, Shape shape2, T[] dest)
    Computes the element-wise product of two tensors.
    static Shape
    getTrShape(Shape shape, int axis1, int axis2)
    Computes the shape of the tensor resulting from the generalized tensor trace along the specified axes for a tensor with the specified shape.
    static <T extends Semiring<T>>
    void
    tensorTr(Shape shape, T[] src, int axis1, int axis2, Shape destShape, T[] dest)
    Computes the generalized trace of this tensor along the specified axes.

    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>> T[] add(T[] src1, Shape shape1, T[] src2, Shape shape2, T[] dest)
      Computes the element-wise addition of two tensors.
      Parameters:
      src1 - Entries of first tensor.
      shape1 - Shape of first tensor.
      src2 - Entries of second tensor.
      shape2 - Shape of second tensor.
      dest - Array to store result in. May be null or the same array as src1 or src2.
      Returns:
      The dest array if dest != null. If dest != null
      Throws:
      IllegalArgumentException - If entry arrays are not the same size.
    • elemMult

      public static <T extends Semiring<T>> T[] elemMult(T[] src1, Shape shape1, T[] src2, Shape shape2, T[] dest)
      Computes the element-wise product of two tensors.
      Parameters:
      src1 - Entries of first tensor.
      shape1 - Shape of first tensor.
      src2 - Entries of second tensor.
      shape2 - Shape of second tensor.
      dest - Array to store result in. May be null.
      Returns:
      The dest array if dest != null. If dest != null
      Throws:
      IllegalArgumentException - If shape1.equals(shape2).
    • tensorTr

      public static <T extends Semiring<T>> void tensorTr(Shape shape, T[] src, int axis1, int axis2, Shape destShape, T[] dest)

      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:
      shape - Shape of the tensor to compute the trace of.
      src - Entries of the tensor to compute the trace of.
      axis1 - First axis for 2D sub-array.
      axis2 - Second axis for 2D sub-array.
      destShape - The resulting shape of the tensor trace. Use getTrShape(Shape, int, int) to compute this.
      dest - Array to store the result of the generalized tensor trace of. Must satisfy dest.length == destShape.totalEntriesIntValueExact().
      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.)
      IllegalArgumentException - If dest.length == destShape.totalEntriesIntValueExact().
    • getTrShape

      public static Shape getTrShape(Shape shape, int axis1, int axis2)
      Computes the shape of the tensor resulting from the generalized tensor trace along the specified axes for a tensor with the specified shape.
      Parameters:
      shape - Shape of the tensor to compute the generalized tensor trace of.
      axis1 - First axis to compute the tensor trace along.
      axis2 - Second axis to compute the tensor trace along.
      Returns: