Class DenseSemiringOps
java.lang.Object
org.flag4j.linalg.ops.dense.semiring_ops.DenseSemiringOps
This class provides low level methods for computing ops on dense semiring tensors.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Semiring<T>>
T[]Computes the element-wise addition of two tensors.static <T extends Semiring<T>>
T[]Computes the element-wise product of two tensors.static ShapegetTrShape(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>>
voidComputes the generalized trace of this tensor along the specified axes.
-
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 benullor the same array assrc1orsrc2.- Returns:
- The
destarray ifdest != null. Ifdest != 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 benull.- Returns:
- The
destarray ifdest != null. Ifdest != null - Throws:
IllegalArgumentException- Ifshape1.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
axis1andaxis2. The shape of the resulting tensor is equal to this tensor with theaxis1andaxis2removed.- 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. UsegetTrShape(Shape, int, int)to compute this.dest- Array to store the result of the generalized tensor trace of. Must satisfydest.length == destShape.totalEntriesIntValueExact().- Throws:
IndexOutOfBoundsException- If the two axes are not both larger than zero and less than this tensors rank.IllegalArgumentException- Ifaxis1 == axis2orthis.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- Ifdest.length == destShape.totalEntriesIntValueExact().
-
getTrShape
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:
-