Package org.flag4j.core.sparse_base
Class SparseTensorBase<T,U,W,Z,Y,D extends Serializable,X extends Number>
java.lang.Object
org.flag4j.core.TensorBase<T,U,W,Z,Y,D,X>
org.flag4j.core.sparse_base.SparseTensorBase<T,U,W,Z,Y,D,X>
- Type Parameters:
T
- Type of this tensor.U
- Dense Tensor type.W
- Complex Tensor type.Z
- Dense complex tensor type.Y
- Real Tensor type.D
- Type of the storage data structure for the tensor. This common use case will be an array or list-like data structure.X
- The type of individual entry within theD
data structure
- All Implemented Interfaces:
Serializable
,SparseTensorMixin
,TensorComparisonsMixin
,TensorManipulationsMixin<T>
,TensorOperationsMixin<T,
,U, W, Z, Y, X> TensorPropertiesMixin
- Direct Known Subclasses:
ComplexSparseTensorBase
,RealSparseTensorBase
public abstract class SparseTensorBase<T,U,W,Z,Y,D extends Serializable,X extends Number>
extends TensorBase<T,U,W,Z,Y,D,X>
implements SparseTensorMixin
The base class for all sparse tensors. This includes sparse matrices and vectors.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionfinal int[][]
Indices for non-zero entries of this tensor.final int
The number of non-zero entries in this sparse tensor.Fields inherited from class org.flag4j.core.TensorBase
DEFAULT_ROUND_TO_ZERO_THRESHOLD, entries, shape
-
Constructor Summary
ModifierConstructorDescriptionprotected
SparseTensorBase
(Shape shape, int nnz, D entries, int[][] indices) Creates a sparse tensor with specified shape, non-zero entries, and non-zero indices.protected
SparseTensorBase
(Shape shape, int nnz, D entries, int[] initIndices, int[]... restIndices) Creates a sparse tensor with specified shape, non-zero entries, and non-zero indices. -
Method Summary
Modifier and TypeMethodDescriptiondouble
density()
Gets the density of this tensor as a decimal percentage.int
Gets the number of non-zero entries in this sparse tensor.double
sparsity()
Gets the sparsity of this tensor as a decimal percentage.abstract U
toDense()
Converts this sparse tensor to an equivalent dense tensor.Methods inherited from class org.flag4j.core.TensorBase
allClose, allClose, getEntries, getRank, getSelf, getShape, sameLength, sameShape, tensorEquals, 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.core.sparse_base.SparseTensorMixin
sortIndices
Methods inherited from interface org.flag4j.core.TensorComparisonsMixin
equals, isOnes, isZeros
Methods inherited from interface org.flag4j.core.TensorManipulationsMixin
flatten, flatten, reshape, reshape, round, round, roundToZero, roundToZero, set
-
Field Details
-
indices
public final int[][] indicesIndices for non-zero entries of this tensor. Will have shape(nonZeroEntries-by-rank)
. -
nnz
public final int nnzThe number of non-zero entries in this sparse tensor.
-
-
Constructor Details
-
SparseTensorBase
Creates a sparse tensor with specified shape, non-zero entries, and non-zero indices.- Parameters:
shape
- Shape of this tensor.entries
- Non-zero entries of this tensor.indices
- Indices of non-zero entries in this tensor. Must have shape(nonZeroEntries-by-rank)
.- Throws:
IllegalArgumentException
- If the rank ofshape
does not match the number of columns inindices
.
-
SparseTensorBase
protected SparseTensorBase(Shape shape, int nnz, D entries, int[] initIndices, int[]... restIndices) Creates a sparse tensor with specified shape, non-zero entries, and non-zero indices.- Parameters:
shape
- Shape of this tensor.entries
- Non-zero entries of this tensor.initIndices
- Indices of the zero axis of the tensor.restIndices
- Indices for the rest of this tensor's axes.- Throws:
IllegalArgumentException
- If the rank ofshape
does not match the number of columns inindices
.
-
-
Method Details
-
nonZeroEntries
public int nonZeroEntries()Gets the number of non-zero entries in this sparse tensor.- Returns:
- The number of non-zero entries in this sparse tensor.
-
sparsity
public double sparsity()Gets the sparsity of this tensor as a decimal percentage.- Returns:
- The sparsity of this tensor.
-
density
public double density()Gets the density of this tensor as a decimal percentage.- Returns:
- The density of this tensor.
-
toDense
Converts this sparse tensor to an equivalent dense tensor.- Returns:
- A dense tensor which is equivalent to this sparse tensor.
-