Package org.flag4j.core
Interface TensorOperationsMixin<T,U,W,Z,Y,X extends Number>
- Type Parameters:
T
- Tensor type.U
- Dense tensor type.W
- Complex tensor type.Z
- Dense complex tensor type.Y
- Real tensor type.X
- Tensor entry type.
- All Known Implementing Classes:
CMatrix
,ComplexDenseTensorBase
,ComplexSparseTensorBase
,CooCMatrix
,CooCTensor
,CooCVector
,CooMatrix
,CooTensor
,CooVector
,CsrCMatrix
,CsrMatrix
,CTensor
,CVector
,DenseTensorBase
,Matrix
,RealDenseTensorBase
,RealSparseTensorBase
,SparseTensorBase
,Tensor
,TensorBase
,Vector
interface TensorOperationsMixin<T,U,W,Z,Y,X extends Number>
This interface specifies operations which all tensors (i.e. matrices and vectors) should implement.
-
Method Summary
Modifier and TypeMethodDescriptionabs()
Computes the element-wise absolute value/magnitude of a tensor.add
(double a) Adds specified value to all entries of this tensor.Adds specified value to all entries of this tensor.Computes the element-wise addition between two tensors of the same rank.copy()
Creates a copy of this tensor.div
(double divisor) Computes the scalar division of a tensor.Computes the scalar division of a tensor.Computes the element-wise division between two tensors.Computes the element-wise multiplication between two tensors.get
(int... indices) Gets the element in this tensor at the specified indices.mult
(double factor) Computes scalar multiplication of a tensor.Computes scalar multiplication of a tensor.recip()
Computes the reciprocals, element-wise, of a tensor.sqrt()
Computes the element-wise square root of a tensor.sub
(double a) Adds specified value to all entries of this tensor.Subtracts a specified value from all entries of this tensor.Computes the element-wise subtraction between two tensors of the same rank.sum()
Sums together all entries in the tensor.T()
Computes the transpose of a tensor.default T
Computes the transpose of a tensor.
-
Method Details
-
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
Adds specified value to all entries of this tensor.- Parameters:
a
- Value to add to all entries of this tensor.- Returns:
- The result of adding the specified value to each entry of this tensor.
-
add
-
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
Adds specified value to all entries of this tensor.- Parameters:
a
- Value to add to all entries of this tensor.- Returns:
- The result of adding the specified value to each entry of this tensor.
-
sub
-
mult
Computes scalar multiplication of a tensor.- Parameters:
factor
- Scalar value to multiply with tensor.- Returns:
- The result of multiplying this tensor by the specified scalar.
-
mult
-
div
Computes the scalar division of a tensor.- Parameters:
divisor
- The scalar value to divide tensor by.- Returns:
- The result of dividing this tensor by the specified scalar.
- Throws:
ArithmeticException
- If divisor is zero.
-
div
Computes the scalar division of a tensor.- Parameters:
divisor
- The scalar value to divide tensor by.- Returns:
- The result of dividing this tensor by the specified scalar.
- Throws:
ArithmeticException
- If divisor is zero.
-
sum
-
sqrt
T sqrt()Computes the element-wise square root of a tensor.- Returns:
- The result of applying an element-wise square root to this tensor. Note, this method will compute the principle square root i.e. the square root with positive real part.
-
abs
Y abs()Computes the element-wise absolute value/magnitude of a tensor. If the tensor contains complex values, the magnitude will be computed.- Returns:
- The result of applying an element-wise absolute value/magnitude to this tensor.
-
transpose
-
T
T T()Computes the transpose of a tensor. Same astranspose()
.- Returns:
- The transpose of this tensor.
-
recip
T recip()Computes the reciprocals, element-wise, of a tensor.- Returns:
- A tensor containing the reciprocal elements of this tensor.
- Throws:
ArithmeticException
- If this tensor contains any zeros.
-
get
Gets the element in this tensor at the specified indices.- Parameters:
indices
- Indices of element.- Returns:
- The element at the specified indices.
- Throws:
IllegalArgumentException
- If the number of indices does not match the rank of this tensor.
-
copy
-
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 this tensor andB
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 multiplication.
- Throws:
IllegalArgumentException
- If this tensor andB
do not have the same shape.
-