java.lang.Object
org.flag4j.arrays.backend.AbstractTensor<FieldTensor<T>,Field<T>[],T>
org.flag4j.arrays.backend.TensorOverSemiRing<FieldTensor<T>,FieldTensor<T>,Field<T>[],T>
org.flag4j.arrays.backend.TensorOverRing<FieldTensor<T>,FieldTensor<T>,Field<T>[],T>
org.flag4j.arrays.backend.TensorOverField<FieldTensor<T>,FieldTensor<T>,Field<T>[],T>
org.flag4j.arrays.backend.FieldTensorBase<FieldTensor<T>,FieldTensor<T>,T>
org.flag4j.arrays.backend.DenseFieldTensorBase<FieldTensor<T>,CooFieldTensor<T>,T>
org.flag4j.arrays.dense.FieldTensor<T>
- Type Parameters:
T
- Type of the field element for the tensor.
- All Implemented Interfaces:
Serializable
,DenseTensorMixin<FieldTensor<T>,
,CooFieldTensor<T>> TensorBinaryOpsMixin<FieldTensor<T>,
,FieldTensor<T>> TensorMixin<FieldTensor<T>,
Field<T>[], T>
public class FieldTensor<T extends Field<T>>
extends DenseFieldTensorBase<FieldTensor<T>,CooFieldTensor<T>,T>
A dense tensor whose entries are Field
elements.
The AbstractTensor.entries
of a field tensor are mutable but the AbstractTensor.shape
is fixed.
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.arrays.backend.AbstractTensor
entries, rank, shape
-
Constructor Summary
ConstructorDescriptionFieldTensor
(Shape shape, Field<T>[] entries) Creates a tensor with the specified entries and shape.FieldTensor
(Shape shape, T fillValue) Creates a tensor with the specified shape filled withfillValue
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if an object is equal to this tensor object.H
(int... axes) Computes the conjugate transpose of this tensor.H
(int axis1, int axis2) Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1
andaxis2
.int
hashCode()
makeLikeTensor
(Shape shape, Field<T>[] entries) Constructs a tensor of the same type as this tensor with the given the shape and entries.T
(int... axes) Computes the transpose of this tensor.T
(int axis1, int axis2) Computes the transpose of a tensor by exchangingaxis1
andaxis2
.tensorDot
(FieldTensor<T> src2) Computes the tensor dot product of this tensor with a second tensor.tensorDot
(FieldTensor<T> src2, int[] aAxes, int[] bAxes) Computes the tensor contraction of this tensor with a specified tensor over the specified set of axes.toCoo()
Converts this dense tensor to an equivalent sparse tensor.toMatrix()
Converts this tensor to an equivalent matrix.Converts this tensor to a matrix with the specified shape.toVector()
Converts this tensor to an equivalent vector.Methods inherited from class org.flag4j.arrays.backend.DenseFieldTensorBase
abs, addEq, allClose, div, divEq, elemMultEq, set, subEq
Methods inherited from class org.flag4j.arrays.backend.FieldTensorBase
add, add, add, addEq, conj, copy, div, div, divEq, elemMult, flatten, flatten, get, getZeroElement, H, isOnes, isZeros, mult, mult, multEq, prod, recip, reshape, setZeroElement, sqrt, sub, sub, sub, subEq, sum, T, tensorTr
Methods inherited from class org.flag4j.arrays.backend.TensorOverSemiRing
tensorDot, tensorDot, tensorTr
Methods inherited from class org.flag4j.arrays.backend.AbstractTensor
getEntries, getRank, getShape, reshape, sameShape, totalEntries
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.flag4j.arrays.backend.DenseTensorMixin
allClose
-
Constructor Details
-
FieldTensor
Creates a tensor with the specified entries and shape.- Parameters:
shape
- Shape of this tensor.entries
- Entries of this tensor. If this tensor is dense, this specifies all entries within the tensor. If this tensor is sparse, this specifies only the non-zero entries of the tensor.
-
FieldTensor
-
-
Method Details
-
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.- Overrides:
tensorDot
in classDenseFieldTensorBase<FieldTensor<T extends Field<T>>,
CooFieldTensor<T extends Field<T>>, T extends Field<T>> - Parameters:
src2
- TensorOld 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.- Overrides:
tensorDot
in classTensorOverSemiRing<FieldTensor<T extends Field<T>>,
FieldTensor<T extends Field<T>>, Field<T extends Field<T>>[], T extends Field<T>> - Parameters:
src2
- TensorOld 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.
-
H
Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1
andaxis2
.- Overrides:
H
in classDenseFieldTensorBase<FieldTensor<T extends Field<T>>,
CooFieldTensor<T extends Field<T>>, T extends Field<T>> - Parameters:
axis1
- First axis to exchange and conjugate.axis2
- Second axis to exchange and conjugate.- Returns:
- The conjugate transpose of this tensor according to the specified axes.
- Throws:
IndexOutOfBoundsException
- If eitheraxis1
oraxis2
are out of bounds for the rank of this tensor.- See Also:
-
H
Computes the conjugate transpose of this tensor. That is, conjugates and permutes the axes of this tensor so that it matches the permutation specified byaxes
.- Overrides:
H
in classDenseFieldTensorBase<FieldTensor<T extends Field<T>>,
CooFieldTensor<T extends Field<T>>, T extends Field<T>> - 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 conjugate transpose of this tensor with its axes permuted by the
axes
array. - Throws:
IndexOutOfBoundsException
- If any element ofaxes
is out of bounds for the rank of this tensor.IllegalArgumentException
- Ifaxes
is not a permutation of{1, 2, 3, ... N-1}
.- See Also:
-
makeLikeTensor
Constructs a tensor of the same type as this tensor with the given the shape and entries.- Specified by:
makeLikeTensor
in interfaceTensorMixin<FieldTensor<T extends Field<T>>,
Field<T extends Field<T>>[], T extends Field<T>> - Specified by:
makeLikeTensor
in classAbstractTensor<FieldTensor<T extends Field<T>>,
Field<T extends Field<T>>[], T extends Field<T>> - Parameters:
shape
- Shape of the tensor to construct.entries
- Entries of the tensor to construct.- Returns:
- A tensor of the same type as this tensor with the given the shape and entries.
-
T
Computes the transpose of a tensor by exchangingaxis1
andaxis2
.- Specified by:
T
in interfaceTensorMixin<FieldTensor<T extends Field<T>>,
Field<T extends Field<T>>[], T extends Field<T>> - Overrides:
T
in classDenseFieldTensorBase<FieldTensor<T extends Field<T>>,
CooFieldTensor<T extends Field<T>>, T extends Field<T>> - Parameters:
axis1
- First axis to exchange.axis2
- Second axis to exchange.- Returns:
- The transpose of this tensor according to the specified axes.
- Throws:
IndexOutOfBoundsException
- If eitheraxis1
oraxis2
are out of bounds for the rank of this tensor.- See Also:
-
T
Computes the transpose of this tensor. That is, permutes the axes of this tensor so that it matches the permutation specified byaxes
.- Specified by:
T
in interfaceTensorMixin<FieldTensor<T extends Field<T>>,
Field<T extends Field<T>>[], T extends Field<T>> - Overrides:
T
in classDenseFieldTensorBase<FieldTensor<T extends Field<T>>,
CooFieldTensor<T extends Field<T>>, T extends Field<T>> - 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:
IndexOutOfBoundsException
- If any element ofaxes
is out of bounds for the rank of this tensor.IllegalArgumentException
- Ifaxes
is not a permutation of{1, 2, 3, ... N-1}
.- See Also:
-
toCoo
Converts this dense tensor to an equivalent sparse tensor.- Returns:
- A sparse tensor equivalent to this dense tensor.
-
toVector
Converts this tensor to an equivalent vector. If this tensor is not rank 1, then it will be flattened.- Returns:
- A vector equivalent of this tensor.
-
toMatrix
Converts this tensor to a matrix with the specified shape.- Parameters:
matShape
- Shape of the resulting matrix. Must bebroadcastable
with the shape of this tensor.- Returns:
- A matrix of shape
matShape
with the values of this tensor. - Throws:
LinearAlgebraException
- IfmatShape
is not of rank 2.
-
toMatrix
Converts this tensor to an equivalent matrix.- Returns:
- If this tensor is rank 2, then the equivalent matrix will be returned. If the tensor is rank 1, then a matrix with a single row will be returned. If the rank of this tensor is larger than 2, it will be flattened to a single row.
-
equals
Checks if an object is equal to this tensor object.- Overrides:
equals
in classObject
- Parameters:
object
- Object to check equality with this tensor.- Returns:
- True if the two tensors have the same shape, are numerically equivalent, and are of type
FieldTensor
. False otherwise.
-
hashCode
-