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 TypeMethodDescriptioncopy()Returns a copy of this Tensor.voidApplies aDoubleUnaryOperatorelementwise to thisTensor.int[]getShape()Returns an int array specifying the shape of thisTensor.default voidhadamardProductInPlace(Tensor other) Same ashadamardProductInPlace(org.tribuo.math.la.Tensor, java.util.function.DoubleUnaryOperator), but applies the identity function.voidhadamardProductInPlace(Tensor other, DoubleUnaryOperator f) Updates thisTensorwith the Hadamard product (i.e., a term by term multiply) of this andother.default voidintersectAndAddInPlace(Tensor other) Same asintersectAndAddInPlace(org.tribuo.math.la.Tensor, java.util.function.DoubleUnaryOperator), but applies the identity function.voidintersectAndAddInPlace(Tensor other, DoubleUnaryOperator f) Updates thisTensorby adding all the values from the intersection withother.reshape(int[] shape) Reshapes the Tensor to the supplied shape.default voidscalarAddInPlace(double scalar) Addsscalarto each element of thisTensor.default voidscaleInPlace(double coefficient) Scales each element of thisTensorbycoefficient.static booleanshapeCheck(Tensor first, Tensor second) Checks that the two tensors have compatible shapes.static intshapeSum(int[] shape) The number of elements in this shape, i.e., the product of the shape array.doubletwoNorm()Calculates the euclidean norm for this vector.
-
Method Details
-
shapeSum
static int shapeSum(int[] shape) The number of elements in this shape, i.e., the product of the shape array.- Parameters:
shape- The tensor shape.- Returns:
- The total number of elements.
-
shapeCheck
Checks that the two tensors have compatible shapes.Compatible shapes are those which are exactly equal, as Tribuo does not support broadcasting.
- Parameters:
first- The first tensor.second- The second tensor.- Returns:
- True if the shapes are the same.
-
getShape
-
reshape
Reshapes the Tensor to the supplied shape. ThrowsIllegalArgumentExceptionif the shape isn't compatible.- Parameters:
shape- The desired shape.- Returns:
- A Tensor of the desired shape.
-
copy
-
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 aDoubleUnaryOperatorelementwise to thisTensor.- Parameters:
f- The function to apply.
-
scaleInPlace
default void scaleInPlace(double coefficient) Scales each element of thisTensorbycoefficient.- Parameters:
coefficient- The coefficient of scaling.
-
scalarAddInPlace
default void scalarAddInPlace(double scalar) Addsscalarto each element of thisTensor.- Parameters:
scalar- The scalar to add.
-
twoNorm
double twoNorm()Calculates the euclidean norm for this vector.- Returns:
- The euclidean norm.
-