Package org.flag4j.core
Interface TensorExclusiveMixin<T extends TensorBase<T,U,W,?,?,?,?>,U,V,W>
- Type Parameters:
T
- Tensor type.U
- Dense tensor type.V
- Sparse tensor type.W
- Complex tensor type.
- All Known Subinterfaces:
ComplexTensorExclusiveMixin<T>
- All Known Implementing Classes:
CooCTensor
,CooTensor
,CTensor
,Tensor
public interface TensorExclusiveMixin<T extends TensorBase<T,U,W,?,?,?,?>,U,V,W>
This interface contains several methods which should be implemented by all tensors which are NOT a matrix or
vector.
-
Method Summary
Modifier and TypeMethodDescriptionComputes the element-wise addition between two tensors of the same rank.Computes the element-wise addition between two tensors of the same rank.add
(CooCTensor B) Computes the element-wise addition between two tensors of the same rank.Computes the element-wise addition between two tensors of the same rank.Computes the element-wise division between two tensors.Computes the element-wise division between two tensors.Computes the element-wise multiplication between two tensors.Computes the element-wise multiplication between two tensors.Computes the element-wise multiplication between two tensors.Computes the element-wise multiplication between two tensors.int
getRank()
Gets the rank of this tensor.Computes the element-wise subtraction between two tensors of the same rank.Computes the element-wise addition between two tensors of the same rank.sub
(CooCTensor B) Computes the element-wise subtraction between two tensors of the same rank.Computes the element-wise subtraction between two tensors of the same rank.T
(int... axes) Computes the transpose of this tensor.T
(int axis1, int axis2) Computes the transpose of a tensor.default U
Computes the tensor dot product of this tensor with a second tensor.default U
Computes the tensor contraction of this tensor with a specified tensor over the specified axes.Computes the tensor contraction of this tensor with a specified tensor over the specified set of axes.default U
Computes the tensor contraction of this tensor with a specified tensor over the specified axes.default U
Computes the 'inverse' of this tensor.tensorInv
(int numIndices) Computes the 'inverse' of this tensor.default T
transpose
(int... axes) Computes the transpose of this tensor.default T
transpose
(int axis1, int axis2) Computes the transpose of a tensor.
-
Method Details
-
tensorDot
Computes the tensor contraction of this tensor with a specified tensor over the specified axes. Ifaxes=N
, then the product sums will be computed along the lastN
dimensions of this tensor and the firstN
dimensions of thesrc2
tensor.- Parameters:
src2
- Tensor to contract with this tensor.axes
- Axes specifying the number of axes to compute the tensor dot product over. Ifaxes=N
, then the product sums will be computed along the lastN
dimensions of this tensor and the firstN
dimensions of.- Returns:
- The tensor dot product over the specified axes.
- Throws:
IllegalArgumentException
- If the two tensors shapes do not match along the specified axesaAxis
andbAxis
.IllegalArgumentException
- If either axis is out of bounds of the corresponding tensor.
-
tensorDot
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 forsrc2
tensor.- Returns:
- The tensor dot product over the specified axes.
- Throws:
IllegalArgumentException
- If the two tensors shapes do not match along the specified axesaAxis
andbAxis
.IllegalArgumentException
- If either axis is out of bounds of the corresponding tensor.
-
tensorDot
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 forsrc2
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 inaAxes
andbAxes
.IllegalArgumentException
- IfaAxes
andbAxes
do not match in length, or if any of the axes are out of bounds for the corresponding tensor.
-
tensorDot
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 ofsrc2
. 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 matchsrc2
shape along the second-to-last axis.
-
transpose
Computes the transpose of a tensor. Same asT(int, int)
. In the context of a tensor, this exchanges the specified axes. Also seetranspose()
andT()
to exchange first and last axes.- Parameters:
axis1
- First axis to exchange.axis2
- Second axis to exchange.- Returns:
- The transpose of this tensor.
-
T
Computes the transpose of a tensor. Same astranspose(int, int)
. In the context of a tensor, this exchanges the specified axes. Also seeTensorOperationsMixin.transpose()
andTensorOperationsMixin.T()
to exchange first and last axes.- Parameters:
axis1
- First axis to exchange.axis2
- Second axis to exchange.- Returns:
- The transpose of this tensor.
-
transpose
Computes the transpose of this tensor. That is, interchanges the axes of this tensor so that it matches the specified axes permutation. Same asT(int[])
.- Parameters:
axes
- Permutation of tensor axis. If the tensor has rankN
, then this must be an array of lengthN
which is a permutation of{0, 1, 2, ..., N-1}
.- Returns:
- The transpose of this tensor with its axes permuted by the
axes
array. - Throws:
IllegalArgumentException
- Ifaxes
is not a permutation of{1, 2, 3, ... N-1}
.
-
T
Computes the transpose of this tensor. That is, interchanges the axes of this tensor so that it matches the specified axes permutation. Same astranspose(int[])
.- Parameters:
axes
- Permutation of tensor axis. If the tensor has rankN
, then this must be an array of lengthN
which is a permutation of{0, 1, 2, ..., N-1}
.- Returns:
- The transpose of this tensor with its axes permuted by the
axes
array. - Throws:
IllegalArgumentException
- Ifaxes
is not a permutation of{1, 2, 3, ... N-1}
.
-
add
Computes the element-wise addition between two tensors of the same rank.- Parameters:
B
- Second tensor in the addition.- Returns:
- The result of adding the tensor B to this tensor element-wise.
- Throws:
IllegalArgumentException
- If this tensor and B have different shapes.
-
add
Computes the element-wise addition between two tensors of the same rank.- Parameters:
B
- Second tensor in the addition.- Returns:
- The result of adding the tensor B to this tensor element-wise.
- Throws:
IllegalArgumentException
- If this tensor and B have different shapes.
-
sub
Computes the element-wise addition between two tensors of the same rank.- Parameters:
B
- Second tensor in the addition.- Returns:
- The result of adding the tensor B to this tensor element-wise.
- Throws:
IllegalArgumentException
- If this tensor and B have different shapes.
-
add
Computes the element-wise addition between two tensors of the same rank.- Parameters:
B
- Second tensor in the addition.- Returns:
- The result of adding the tensor B to this tensor element-wise.
- Throws:
IllegalArgumentException
- If this tensor and B have different shapes.
-
add
Computes the element-wise addition between two tensors of the same rank.- Parameters:
B
- Second tensor in the addition.- Returns:
- The result of adding the tensor B to this tensor element-wise.
- Throws:
IllegalArgumentException
- If this tensor and B have different shapes.
-
sub
Computes the element-wise subtraction between two tensors of the same rank.- Parameters:
B
- Second tensor in element-wise subtraction.- Returns:
- The result of subtracting the tensor B from this tensor element-wise.
- Throws:
IllegalArgumentException
- If this tensor and B have different shapes.
-
sub
Computes the element-wise subtraction between two tensors of the same rank.- Parameters:
B
- Second tensor in element-wise subtraction.- Returns:
- The result of subtracting the tensor B from this tensor element-wise.
- Throws:
IllegalArgumentException
- If this tensor and B have different shapes.
-
sub
Computes the element-wise subtraction between two tensors of the same rank.- Parameters:
B
- Second tensor in element-wise subtraction.- Returns:
- The result of subtracting the tensor B from this tensor element-wise.
- Throws:
IllegalArgumentException
- If this tensor and B have different shapes.
-
elemMult
Computes the element-wise multiplication between two tensors.- Parameters:
B
- Tensor to element-wise multiply to this tensor.- Returns:
- The result of the element-wise tensor multiplication.
- Throws:
IllegalArgumentException
- If the tensors do not have the same shape.
-
elemMult
Computes the element-wise multiplication between two tensors.- Parameters:
B
- Tensor to element-wise multiply to this tensor.- Returns:
- The result of the element-wise tensor multiplication.
- Throws:
IllegalArgumentException
- If the tensors do not have the same shape.
-
elemMult
Computes the element-wise multiplication between two tensors.- Parameters:
B
- Tensor to element-wise multiply to this tensor.- Returns:
- The result of the element-wise tensor multiplication.
- Throws:
IllegalArgumentException
- If the tensors do not have the same shape.
-
elemMult
Computes the element-wise multiplication between two tensors.- Parameters:
B
- Tensor to element-wise multiply to this tensor.- Returns:
- The result of the element-wise tensor multiplication.
- Throws:
IllegalArgumentException
- If the tensors do not have the same shape.
-
elemDiv
Computes the element-wise division between two tensors.- Parameters:
B
- Tensor to element-wise divide with this tensor.- Returns:
- The result of the element-wise tensor division.
- Throws:
IllegalArgumentException
- If the tensors do not have the same shape.
-
elemDiv
Computes the element-wise division between two tensors.- Parameters:
B
- Tensor to element-wise divide from this tensor.- Returns:
- The result of the element-wise tensor division.
- Throws:
IllegalArgumentException
- If the tensors do not have the same shape.
-
tensorInv
Computes the 'inverse' of this tensor. That is, computes the tensorX=this.tensorInv()
such thatthis.tensorDot(X, 2)
is the 'identity' tensor for the tensor dot product operation. A tensorI
is the identity for a tensor dot product ifthis.tensorDot(I, 2).equals(this)
.- Returns:
- The 'inverse' of this tensor as defined in the above sense.
- See Also:
-
tensorInv
Computes the 'inverse' of this tensor. That is, computes the tensorX=this.tensorInv()
such thatthis.tensorDot(X, numIndices)
is the 'identity' tensor for the tensor dot product operation. A tensorI
is the identity for a tensor dot product ifthis.tensorDot(I, numIndices).equals(this)
.- Parameters:
numIndices
- The number of first numIndices which are involved in the inverse sum.- Returns:
- The 'inverse' of this tensor as defined in the above sense.
- See Also:
-
getRank
int getRank()Gets the rank of this tensor. The rank is the number of indices required to uniquely identify an element in the tensor.
Note, this differs from matrix rank.
- Returns:
- The rank of this tensor.
-