Class AbstractCooRingTensor<T extends AbstractCooRingTensor<T,U,V>,U extends AbstractDenseRingTensor<U,V>,V extends Ring<V>>
- Type Parameters:
T
- Type of this sparse COO tensor.U
- Type of dense tensor equivalent toT
. This type parameter is required because some ops (e.g.invalid reference
#tensorDot(AbstractCooRingTensor, int[], int[])
V
- Type of theRing
which the data of this tensor belong to.
- All Implemented Interfaces:
Serializable
,RingTensorMixin<T,
,T, V> TensorOverRing<T,
,T, V[], V> SemiringTensorMixin<T,
,T, V> TensorOverSemiring<T,
T, V[], V>
- Direct Known Subclasses:
AbstractCooFieldTensor
,CooRingTensor
Base class for all sparse Ring
tensors stored in coordinate list (COO) format. The data of this COO tensor are
elements of a Ring
.
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
AbstractCooRingTensor
(Shape shape, V[] data, int[][] indices) Creates a tensor with the specified data and shape. -
Method Summary
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.ring_arrays.RingTensorMixin
add, addEq, argmax, argmaxAbs, argmin, argminAbs, conj, isOnes, isZeros, makeEmptyDataArray, max, maxAbs, min, minAbs, mult, multEq, norm, norm, prod, sub, subEq, sum
Methods inherited from interface org.flag4j.arrays.backend.ring_arrays.TensorOverRing
abs, H
-
Constructor Details
-
AbstractCooRingTensor
Creates a tensor with the specified data and shape.- Parameters:
shape
- Shape of this tensor.data
- 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
-
sub
Computes the element-wise difference between two tensors of the same shape.- Specified by:
sub
in interfaceTensorOverRing<T extends AbstractCooRingTensor<T,
U, V>, T extends AbstractCooRingTensor<T, U, V>, V extends Ring<V>[], V extends Ring<V>> - Parameters:
b
- Second tensor in the element-wise difference.- Returns:
- The difference of this tensor with
b
. - Throws:
TensorShapeException
- If this tensor andb
do not have the same shape.
-
H
Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1
andaxis2
.- Specified by:
H
in interfaceTensorOverRing<T extends AbstractCooRingTensor<T,
U, V>, T extends AbstractCooRingTensor<T, U, V>, V extends Ring<V>[], V extends Ring<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 AbstractCooRingTensor<T,
U, V>, T extends AbstractCooRingTensor<T, U, V>, V extends Ring<V>[], V extends Ring<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:
-