Class CooCTensor
- All Implemented Interfaces:
Serializable
,FieldTensorMixin<CooCTensor,
,CooCTensor, Complex128> TensorOverField<CooCTensor,
,CooCTensor, Complex128[], Complex128> RingTensorMixin<CooCTensor,
,CooCTensor, Complex128> TensorOverRing<CooCTensor,
,CooCTensor, Complex128[], Complex128> SemiringTensorMixin<CooCTensor,
,CooCTensor, Complex128> TensorOverSemiring<CooCTensor,
CooCTensor, Complex128[], Complex128>
Sparse complex tensor stored in coordinate list (COO) format. The data of this COO tensor are of type Complex128
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
ConstructorsConstructorDescriptionCooCTensor
(Shape shape) Creates a tensor with the specified data and shape.CooCTensor
(Shape shape, double[] entries, int[][] indices) Creates a tensor with the specified data and shape.CooCTensor
(Shape shape, List<Complex128> entries, List<int[]> indices) Creates a tensor with the specified data and shape.CooCTensor
(Shape shape, Complex128[] entries, int[][] indices) Creates a tensor with the specified data and shape.CooCTensor
(Shape shape, Complex64[] entries, int[][] indices) Creates a tensor with the specified data and shape.Constructs a copy of a sparse COO tensor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if an object is equal to this tensor object.int
hashCode()
boolean
Checks if any entry within this matrix has non-zero imaginary component.boolean
isReal()
Checks if all data of this matrix are real.makeEmptyDataArray
(int length) Creates an empty array of the same type as the data array of this tensor.makeLikeDenseTensor
(Shape shape, Complex128[] entries) Constructs a dense tensor that is a similar type as this sparse COO tensor.makeLikeTensor
(Shape shape, List<Complex128> entries, List<int[]> indices) Constructs a tensor of the same type as this tensor with the specified shape and non-zero data.makeLikeTensor
(Shape shape, Complex128[] entries) Constructs a tensor of the same type as this tensor with the given theshape
anddata
.makeLikeTensor
(Shape shape, Complex128[] entries, int[][] indices) Constructs a tensor of the same type as this tensor with the specified shape and non-zero data.round
(int precision) Rounds all data within this tensor to the specified precision.roundToZero
(double tolerance) Sets all elements of this tensor to zero if they are withintol
of zero.set
(double value, int... target) Sets the element of this tensor at the specified target index.Converts this tensor to a matrix with specified shape.toReal()
Converts this complex vector to a real vector.toString()
Formats this sparse COO tensor as a human-readable string specifying the full shape, non-zero data, and non-zero indices.Methods inherited from class org.flag4j.arrays.backend.field_arrays.AbstractCooFieldTensor
abs, div, H, H, isFinite, isInfinite, isNaN, sqrt
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, 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, reshape, sameShape, totalEntries
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, 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, 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
-
CooCTensor
Creates a tensor with the specified data and shape.- Parameters:
shape
- Shape of this tensor.entries
- Non-zero data of this tensor of this tensor.indices
- Indices of the non-zero data of this tensor.
-
CooCTensor
Creates a tensor with the specified data and shape.- Parameters:
shape
- Shape of this tensor.entries
- Non-zero data of this tensor of this tensor.indices
- Indices of the non-zero data of this tensor.
-
CooCTensor
-
CooCTensor
Creates a tensor with the specified data and shape.- Parameters:
shape
- Shape of this tensor.entries
- Non-zero data of this tensor of this tensor.indices
- Indices of the non-zero data of this tensor.
-
CooCTensor
Creates a tensor with the specified data and shape.- Parameters:
shape
- Shape of this tensor.entries
- Non-zero data of this tensor of this tensor.indices
- Indices of the non-zero data of this tensor.
-
CooCTensor
Constructs a copy of a sparse COO tensor.- Parameters:
b
- Tensor to construct copy of.
-
-
Method Details
-
makeEmptyDataArray
Description copied from interface:SemiringTensorMixin
Creates an empty array of the same type as the data array of this tensor.- Parameters:
length
- The length of the array to construct.- Returns:
- An empty array of the same type as the data array of this tensor.
-
makeLikeTensor
Constructs a tensor of the same type as this tensor with the given theshape
anddata
. The resulting tensor will also have the same non-zero indices as this tensor.- Specified by:
makeLikeTensor
in interfaceTensorOverSemiring<CooCTensor,
CooCTensor, Complex128[], Complex128> - Specified by:
makeLikeTensor
in classAbstractTensor<CooCTensor,
Complex128[], Complex128> - Parameters:
shape
- Shape of the tensor to construct.entries
- Entries of the tensor to construct.- Returns:
- A tensor of the same type and with the same non-zero indices as this tensor with the given the
shape
anddata
.
-
makeLikeTensor
Constructs a tensor of the same type as this tensor with the specified shape and non-zero data.- Specified by:
makeLikeTensor
in classAbstractCooSemiringTensor<CooCTensor,
CTensor, Complex128> - Parameters:
shape
- Shape of the tensor to construct.entries
- Non-zero data of the tensor to construct.indices
- Indices of the non-zero data of the tensor.- Returns:
- A tensor of the same type as this tensor with the specified shape and non-zero data.
-
makeLikeTensor
Constructs a tensor of the same type as this tensor with the specified shape and non-zero data.- Specified by:
makeLikeTensor
in classAbstractCooSemiringTensor<CooCTensor,
CTensor, Complex128> - Parameters:
shape
- Shape of the tensor to construct.entries
- Non-zero data of the tensor to construct.indices
- Indices of the non-zero data of the tensor.- Returns:
- A tensor of the same type as this tensor with the specified shape and non-zero data.
-
makeLikeDenseTensor
Constructs a dense tensor that is a similar type as this sparse COO tensor.- Specified by:
makeLikeDenseTensor
in classAbstractCooSemiringTensor<CooCTensor,
CTensor, Complex128> - Parameters:
shape
- Shape of the tensor to construct.entries
- The data of the dense tensor to construct.- Returns:
- A dense tensor that is a similar type as this sparse COO tensor.
-
toReal
Converts this complex vector to a real vector.- Returns:
- A real vector containing the real components of all non-zero values in this vector. The imaginary components are ignored.
-
isReal
public boolean isReal()Checks if all data of this matrix are real.- Returns:
true
if all data of this matrix are real;false
otherwise.
-
isComplex
public boolean isComplex()Checks if any entry within this matrix has non-zero imaginary component.- Returns:
true
if any entry of this matrix has a non-zero imaginary component.
-
round
Rounds all data within this tensor to the specified precision.- Parameters:
precision
- The precision to round to (i.e. the number of decimal places to round to). Must be non-negative.- Returns:
- A new tensor containing the data of this tensor rounded to the specified precision.
-
roundToZero
Sets all elements of this tensor to zero if they are withintol
of zero. This is not done in place.- Parameters:
precision
- The precision to round to (i.e. the number of decimal places to round to). Must be non-negative.- Returns:
- A copy of this tensor with all data within
tol
of zero set to zero.
-
toMatrix
Converts this tensor to a matrix with specified shape.- Parameters:
newShape
- Shape of matrix to convert this tensor to. Shape must be broadcastable with this tensors shape and have rank 2.- Returns:
- A matrix of the specified shape with the same non-zero data as this tensor.
-
set
Sets the element of this tensor at the specified target index.- Parameters:
value
- New value to set the specified index of this tensor to.target
- Index of the element to set.- Returns:
- If this tensor is dense, a reference to this tensor is returned. If this tensor is sparse, a copy of this tensor with the updated value is returned.
- Throws:
IndexOutOfBoundsException
- Iftarget
is not within the bounds of this tensor.
-
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
CooCTensor
. False otherwise.
-
hashCode
-
toString
-