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.AbstractCooSemiringTensor.tensorDot(AbstractCooSemiringTensor, int[], int[])) between two sparse tensors results in a dense tensor.V- Type of theRingwhich 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
shapeof the tensor. - The non-zero
AbstractTensor.dataof the tensor. All other data in the tensor are assumed to be zero. Zero value can also explicitly be stored inAbstractTensor.data. The
AbstractCooSemiringTensor.indicesof 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.indicesarray has shape(nnz, rank)whereAbstractCooSemiringTensor.nnzis the number of non-zero data in this sparse tensor andrankis thetensor rankof 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, zeroElementFields inherited from class org.flag4j.arrays.backend.AbstractTensor
data, rank, shape -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractCooRingTensor(Shape shape, V[] data, int[][] indices) Creates a tensor with the specified data and shape.protectedAbstractCooRingTensor(Shape shape, V[] data, int[][] indices, Object dummy) Constructor useful for avoiding parameter validation while constructing COO tensors. -
Method Summary
Methods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractCooSemiringTensor
add, argmax, argmin, coalesce, coalesce, copy, dataLength, density, dropZeros, elemMult, flatten, flatten, get, getZeroElement, makeLikeDenseTensor, makeLikeTensor, makeLikeTensor, max, min, reshape, set, setZeroElement, sortIndices, sparsity, T, T, T, tensorDot, tensorTr, toDenseMethods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, makeLikeTensor, reshape, sameShape, totalEntriesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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, sumMethods 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.
-
AbstractCooRingTensor
Constructor useful for avoiding parameter validation while constructing COO tensors.- Parameters:
shape- The shape of the tensor to construct.data- The non-zero data of this tensor.indices- The indices of the non-zero data.dummy- Dummy object to distinguish this constructor from the safe variant. It is completely ignored in this constructor.
-
-
Method Details
-
sub
Computes the element-wise difference between two tensors of the same shape.- Specified by:
subin 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 andbdo not have the same shape.
-
H
Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1andaxis2.- Specified by:
Hin 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 eitheraxis1oraxis2are 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:
Hin 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 lengthNwhich is a permutation of{0, 1, 2, ..., N-1}.- Returns:
- The conjugate transpose of this tensor with its axes permuted by the
axesarray. - Throws:
IndexOutOfBoundsException- If any element ofaxesis out of bounds for the rank of this tensor.IllegalArgumentException- Ifaxesis not a permutation of{1, 2, 3, ... N-1}.- See Also:
-