Interface TensorOverSemiring<T extends TensorOverSemiring<T,U,V,W>,U extends TensorOverSemiring<U,U,V,W>,V,W>
- Type Parameters:
T
- Type of this tensor.U
- Type of dense tensor equivalent toT
. IfT
is dense, then this should be the same type asT
. This parameter required because some ops between two sparse tensors may result in a dense tensor.V
- Storage for data of this tensor.W
- Type (or wrapper) of an element of this tensor. Should satisfy the axioms of a semiring as stated.
- All Known Subinterfaces:
FieldTensorMixin<T,
,U, V> RingTensorMixin<T,
,U, V> SemiringTensorMixin<T,
,U, V> TensorOverField<T,
,U, V, W> TensorOverRing<T,
U, V, W>
- All Known Implementing Classes:
AbstractCooFieldMatrix
,AbstractCooFieldTensor
,AbstractCooFieldVector
,AbstractCooRingMatrix
,AbstractCooRingTensor
,AbstractCooRingVector
,AbstractCooSemiringMatrix
,AbstractCooSemiringTensor
,AbstractCooSemiringVector
,AbstractCsrFieldMatrix
,AbstractCsrRingMatrix
,AbstractCsrSemiringMatrix
,AbstractDenseDoubleTensor
,AbstractDenseFieldMatrix
,AbstractDenseFieldTensor
,AbstractDenseFieldVector
,AbstractDenseRingMatrix
,AbstractDenseRingTensor
,AbstractDenseRingVector
,AbstractDenseSemiringMatrix
,AbstractDenseSemiringTensor
,AbstractDenseSemiringVector
,AbstractDoubleTensor
,CMatrix
,CooCMatrix
,CooCTensor
,CooCVector
,CooFieldMatrix
,CooFieldTensor
,CooFieldVector
,CooMatrix
,CooRingMatrix
,CooRingTensor
,CooRingVector
,CooSemiringMatrix
,CooSemiringTensor
,CooSemiringVector
,CooTensor
,CooVector
,CsrCMatrix
,CsrFieldMatrix
,CsrMatrix
,CsrRingMatrix
,CsrSemiringMatrix
,CTensor
,CVector
,FieldMatrix
,FieldTensor
,FieldVector
,Matrix
,RingMatrix
,RingTensor
,RingVector
,SemiringMatrix
,SemiringTensor
,SemiringVector
,Tensor
,Vector
To allow for primitive types, the elements of this tensor do not necessarily have to implement
Semiring
.
Formally, an semiring is a set R with the binary ops addition (+) and multiplication (*) defined such that for elements a, b, c in R the following are satisfied:
- Addition and multiplication are associative: a + (b + c) = (a + b) + c and a * (b * c) = (a * b) * c.
- Addition is commutative: a + b = b + a
- Existence of additive and multiplicative identities: There exists two distinct elements 0 and 1 in R such that a + 0 = 0 and a * 1 = 1 (called the additive and multiplicative identities respectively).
- Distributivity of multiplication over addition: a * (b + c) = (a * b) + (a * c).
-
Method Summary
Modifier and TypeMethodDescriptionComputes the element-wise sum between two tensors of the same shape.Adds a scalar value to each entry of this tensor.void
Adds a scalar value to each entry of this tensor and stores the result in this tensor.Computes the element-wise multiplication of two tensors of the same shape.getData()
Gets the data of this tensor.int
getRank()
Gets the rank of this tensor.getShape()
Gets the shape of this tensor.boolean
isOnes()
Checks if this tensor only contains ones.boolean
isZeros()
Checks if this tensor only contains zeros.makeLikeTensor
(Shape shape, V entries) Constructs a tensor of the same type as this tensor with the given theshape
anddata
.Multiplies a scalar value to each entry of this tensor.void
Multiplies a scalar value to each entry of this tensor and stores the result in this tensor.prod()
Computes the product of all values in this tensor.sum()
Computes the sum of all values in this tensor.default AbstractTensor
<?, V, W> Computes the tensor dot product of this tensor with a second tensor.default AbstractTensor
<?, V, W> Computes the tensor contraction of this tensor with a specified tensor over the specified axes.AbstractTensor
<?, V, W> Computes the tensor contraction of this tensor with a specified tensor over the specified set of axes.default AbstractTensor
<?, V, W> Computes the tensor contraction of this tensor with a specified tensor over the specified axes.default TensorOverSemiring
<?, ?, ?, W> tensorTr()
Computes the generalized tensor trace of this tensor along first and second axes.TensorOverSemiring
<?, ?, ?, W> tensorTr
(int axis1, int axis2) Computes the generalized trace of this tensor along the specified axes.
-
Method Details
-
getData
-
makeLikeTensor
Constructs a tensor of the same type as this tensor with the given theshape
anddata
. The resulting tensor will also have the same non-zero indices as this tensor.- Parameters:
shape
- Shape of the tensor to construct.entries
- Entries of the tensor to construct.- Returns:
- A tensor of the same type and with the same non-zero indices as this tensor with the given the
shape
anddata
.
-
getShape
-
getRank
int getRank()Gets the rank of this tensor.- Returns:
- The rank of this tensor.
-
add
-
addEq
Adds a scalar value to each entry of this tensor and stores the result in this tensor.- Parameters:
b
- Scalar field value in sum.
-
add
Computes the element-wise sum between two tensors of the same shape.- Parameters:
b
- Second tensor in the element-wise sum.- Returns:
- The sum of this tensor with
b
. - Throws:
TensorShapeException
- If this tensor andb
do not have the same shape.
-
mult
-
multEq
Multiplies a scalar value to each entry of this tensor and stores the result in this tensor.- Parameters:
b
- Scalar value in product.
-
elemMult
Computes the element-wise multiplication of two tensors of the same shape.- Parameters:
b
- Second tensor in the element-wise product.- Returns:
- The element-wise product between this tensor and
b
. - Throws:
IllegalArgumentException
- If this tensor andb
do not have the same shape.
-
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.
-
tensorTr
Computes the generalized tensor trace of this tensor along first and second axes.
The generalized tensor trace is the sum along the diagonal values of the 2D sub-arrays of this tensor specified by the first and second axes. The shape of the resulting tensor is equal to this tensor with the first and second axes removed.
- Returns:
- The generalized trace of this tensor along first and second axes.
-
tensorTr
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
axis1
andaxis2
. The shape of the resulting tensor is equal to this tensor with theaxis1
andaxis2
removed.- Parameters:
axis1
- First axis for 2D sub-array.axis2
- Second axis for 2D sub-array.- Returns:
- The generalized trace of this tensor along
axis1
andaxis2
. - Throws:
IndexOutOfBoundsException
- If the two axes are not both larger than zero and less than this tensors rank.IllegalArgumentException
- Ifaxis1 == axis2
orthis.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.)
-
isZeros
boolean isZeros()Checks if this tensor only contains zeros.- Returns:
true
if this tensor only contains zeros;false
otherwise.
-
isOnes
boolean isOnes()Checks if this tensor only contains ones. If this tensor is sparse, only the non-zero data are considered.- Returns:
true
if this tensor only contains ones;false
otherwise.
-
sum
W sum()Computes the sum of all values in this tensor.- Returns:
- The sum of all values in this tensor.
-
prod
W prod()Computes the product of all values in this tensor.- Returns:
- The product of all values in this tensor.
-