Class AbstractCooFieldTensor<T extends AbstractCooFieldTensor<T,U,V>,U extends AbstractDenseFieldTensor<U,V>,V extends Field<V>>
- Type Parameters:
T
- Type of this sparse COO tensor.U
- Type of dense tensor equivalent toT
. This type parameter is required because some operations (e.g.AbstractCooSemiringTensor.tensorDot(AbstractCooSemiringTensor, int[], int[])
between two sparse tensors results in a dense tensor.V
- Type of theField
which the data of this tensor belong to.
- All Implemented Interfaces:
Serializable
,FieldTensorMixin<T,
,T, V> TensorOverField<T,
,T, V[], V> RingTensorMixin<T,
,T, V> TensorOverRing<T,
,T, V[], V> SemiringTensorMixin<T,
,T, V> TensorOverSemiring<T,
T, V[], V>
- Direct Known Subclasses:
CooCTensor
,CooFieldTensor
Base class for all sparse Field
tensors stored in coordinate list (COO) format. The data of this COO tensor are
elements of a Field
.
The non-zero data
and non-zero indices
of a COO tensor are mutable but the AbstractTensor.shape
and total number of non-zero data
is fixed.
Sparse tensors allow for the efficient storage of and ops on tensors that contain many zero values.
COO tensors are optimized for hyper-sparse tensors (i.e. tensors which contain almost all zeros relative to the size of the tensor).
A sparse COO tensor is stored as:
- The full
shape
of the tensor. - The non-zero
AbstractTensor.data
of the tensor. All other data in the tensor are assumed to be zero. Zero value can also explicitly be stored inAbstractTensor.data
. The
AbstractCooSemiringTensor.indices
of the non-zero value in the sparse tensor. Many ops assume indices to be sorted in a row-major format (i.e. last index increased fastest) but often this is not explicitly verified.The
AbstractCooSemiringTensor.indices
array has shape(nnz, rank)
whereAbstractCooSemiringTensor.nnz
is the number of non-zero data in this sparse tensor andrank
is thetensor rank
of the tensor. This meansindices[i]
is the ND index ofdata[i]
.
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractCooSemiringTensor
indices, nnz, sparsity, zeroElement
Fields inherited from class org.flag4j.arrays.backend.AbstractTensor
data, rank, shape
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractCooFieldTensor
(Shape shape, V[] entries, int[][] indices) Creates a tensor with the specified data and shape. -
Method Summary
Modifier and TypeMethodDescriptionabs()
Computes the element-wise absolute value of this tensor.Computes the element-wise quotient between two tensors.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
.boolean
isFinite()
Checks if this tensor only contains finite values.boolean
Checks if this tensor contains at least one infinite value.boolean
isNaN()
Checks if this tensor contains at least one NaN value.sqrt()
Computes the element-wise square root of this tensor.Methods inherited from class org.flag4j.arrays.backend.ring_arrays.AbstractCooRingTensor
sub
Methods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractCooSemiringTensor
add, argmax, argmin, coalesce, coalesce, copy, density, dropZeros, elemMult, flatten, flatten, get, getZeroElement, makeLikeDenseTensor, makeLikeTensor, makeLikeTensor, max, min, reshape, set, setZeroElement, sortIndices, sparsity, T, T, T, tensorDot, tensorTr, toDense
Methods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, makeLikeTensor, reshape, sameShape, totalEntries
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.flag4j.arrays.backend.field_arrays.FieldTensorMixin
add, add, addEq, addEq, argmax, argmaxAbs, argmin, argminAbs, conj, div, div, divEq, divEq, isOnes, isZeros, makeEmptyDataArray, max, maxAbs, min, minAbs, mult, mult, multEq, multEq, norm, norm, prod, recip, sub, sub, subEq, subEq, sum
Methods inherited from interface org.flag4j.arrays.backend.ring_arrays.TensorOverRing
H, sub
-
Constructor Details
-
AbstractCooFieldTensor
Creates a tensor with the specified data and shape.- Parameters:
shape
- Shape of this tensor.entries
- Entries of this tensor. If this tensor is dense, this specifies all data within the tensor. If this tensor is sparse, this specifies only the non-zero data of the tensor.
-
-
Method Details
-
abs
Computes the element-wise absolute value of this tensor. -
H
Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1
andaxis2
.- Specified by:
H
in interfaceTensorOverRing<T extends AbstractCooFieldTensor<T,
U, V>, T extends AbstractCooFieldTensor<T, U, V>, V extends Field<V>[], V extends Field<V>> - Overrides:
H
in classAbstractCooRingTensor<T extends AbstractCooFieldTensor<T,
U, V>, U extends AbstractDenseFieldTensor<U, V>, V extends Field<V>> - 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
.- Specified by:
H
in interfaceTensorOverRing<T extends AbstractCooFieldTensor<T,
U, V>, T extends AbstractCooFieldTensor<T, U, V>, V extends Field<V>[], V extends Field<V>> - Overrides:
H
in classAbstractCooRingTensor<T extends AbstractCooFieldTensor<T,
U, V>, U extends AbstractDenseFieldTensor<U, V>, V extends Field<V>> - 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:
-
div
Computes the element-wise quotient between two tensors.
WARNING: This method is not supported for sparse tensors. If called on a sparse tensor, an
UnsupportedOperationException
will be thrown. Element-wise division is undefined for sparse matrices as it would almost certainly result in a division by zero.- Specified by:
div
in interfaceTensorOverField<T extends AbstractCooFieldTensor<T,
U, V>, T extends AbstractCooFieldTensor<T, U, V>, V extends Field<V>[], V extends Field<V>> - Parameters:
b
- Second tensor in the element-wise quotient.- Returns:
- The element-wise quotient of this tensor with
b
. - Throws:
UnsupportedOperationException
- if this method is ever invoked on a sparse tensor.
-
sqrt
-
isFinite
public boolean isFinite()Checks if this tensor only contains finite values. -
isInfinite
public boolean isInfinite()Checks if this tensor contains at least one infinite value.- Specified by:
isInfinite
in interfaceTensorOverField<T extends AbstractCooFieldTensor<T,
U, V>, T extends AbstractCooFieldTensor<T, U, V>, V extends Field<V>[], V extends Field<V>> - Returns:
true
if this tensor contains at least one infinite value;false
otherwise.- See Also:
-
isNaN
public boolean isNaN()Checks if this tensor contains at least one NaN value.
-