Interface Tensor
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
DenseMatrix
,DenseSparseMatrix
,DenseVector
,ShrinkingMatrix
,ShrinkingVector
,SparseVector
An interface for Tensors, currently Vectors and Matrices.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Applies aDoubleUnaryOperator
elementwise to thisTensor
.int[]
getShape()
Returns an int array specifying the shape of thisTensor
.default void
hadamardProductInPlace
(Tensor other) Same ashadamardProductInPlace(org.tribuo.math.la.Tensor, java.util.function.DoubleUnaryOperator)
, but applies the identity function.void
hadamardProductInPlace
(Tensor other, DoubleUnaryOperator f) Updates thisTensor
with the Hadamard product (i.e., a term by term multiply) of this andother
.default void
intersectAndAddInPlace
(Tensor other) Same asintersectAndAddInPlace(org.tribuo.math.la.Tensor, java.util.function.DoubleUnaryOperator)
, but applies the identity function.void
intersectAndAddInPlace
(Tensor other, DoubleUnaryOperator f) Updates thisTensor
by adding all the values from the intersection withother
.reshape
(int[] shape) Reshapes the Tensor to the supplied shape.default void
scalarAddInPlace
(double scalar) Addsscalar
to each element of thisTensor
.default void
scaleInPlace
(double coefficient) Scales each element of thisTensor
bycoefficient
.static boolean
shapeCheck
(Tensor first, Tensor second) static int
shapeSum
(int[] shape) double
twoNorm()
Calculates the euclidean norm for this vector.
-
Method Details
-
shapeSum
static int shapeSum(int[] shape) -
shapeCheck
-
getShape
-
reshape
Reshapes the Tensor to the supplied shape. ThrowsIllegalArgumentException
if the shape isn't compatible.- Parameters:
shape
- The desired shape.- Returns:
- A Tensor of the desired shape.
-
intersectAndAddInPlace
-
intersectAndAddInPlace
Same asintersectAndAddInPlace(org.tribuo.math.la.Tensor, java.util.function.DoubleUnaryOperator)
, but applies the identity function.Each value is updated as value += otherValue.
- Parameters:
other
- The otherTensor
.
-
hadamardProductInPlace
-
hadamardProductInPlace
Same ashadamardProductInPlace(org.tribuo.math.la.Tensor, java.util.function.DoubleUnaryOperator)
, but applies the identity function.Each value is updated as value *= otherValue.
- Parameters:
other
- The otherTensor
.
-
foreachInPlace
Applies aDoubleUnaryOperator
elementwise to thisTensor
.- Parameters:
f
- The function to apply.
-
scaleInPlace
default void scaleInPlace(double coefficient) Scales each element of thisTensor
bycoefficient
.- Parameters:
coefficient
- The coefficient of scaling.
-
scalarAddInPlace
default void scalarAddInPlace(double scalar) Addsscalar
to each element of thisTensor
.- Parameters:
scalar
- The scalar to add.
-
twoNorm
double twoNorm()Calculates the euclidean norm for this vector.- Returns:
- The euclidean norm.
-