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
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
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 TypeMethodDescriptionbooleanChecks if an object is equal to this tensor object.inthashCode()booleanChecks if any entry within this matrix has non-zero imaginary component.booleanisReal()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 theshapeanddata.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 withintolof 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.static CooCTensorunsafeMake(Shape shape, Complex128[] data, int[][] indices) Factory to construct a COO tensor which bypasses any validation checks on the data and indices.Methods inherited from class org.flag4j.arrays.backend.field_arrays.AbstractCooFieldTensor
abs, div, H, H, isFinite, isInfinite, isNaN, sqrtMethods inherited from class org.flag4j.arrays.backend.ring_arrays.AbstractCooRingTensor
subMethods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractCooSemiringTensor
add, argmax, argmin, coalesce, coalesce, copy, dataLength, density, dropZeros, elemMult, flatten, flatten, get, getZeroElement, max, min, reshape, set, setZeroElement, sortIndices, sparsity, T, T, T, tensorDot, tensorTr, toDenseMethods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, reshape, sameShape, totalEntriesMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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, sumMethods 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
-
unsafeMake
Factory to construct a COO tensor which bypasses any validation checks on the data and indices.
Warning: This method should be used with extreme caution. It primarily exists for internal use. Only use this factory if you are 100% certain the parameters are valid as some methods may throw exceptions or exhibit undefined behavior.
- Parameters:
shape- The full size of the COO tensor.data- The non-zero data of the COO tensor.indices- The non-zero indices of the COO tensor.- Returns:
- A COO tensor constructed from the provided parameters.
-
makeEmptyDataArray
Description copied from interface:SemiringTensorMixinCreates 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 theshapeanddata. The resulting tensor will also have the same non-zero indices as this tensor.- Specified by:
makeLikeTensorin interfaceTensorOverSemiring<CooCTensor,CooCTensor, Complex128[], Complex128> - Specified by:
makeLikeTensorin 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
shapeanddata.
-
makeLikeTensor
Constructs a tensor of the same type as this tensor with the specified shape and non-zero data.- Specified by:
makeLikeTensorin 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:
makeLikeTensorin 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:
makeLikeDenseTensorin 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:
trueif all data of this matrix are real;falseotherwise.
-
isComplex
public boolean isComplex()Checks if any entry within this matrix has non-zero imaginary component.- Returns:
trueif 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 withintolof 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
tolof 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- Iftargetis not within the bounds of this tensor.
-
equals
Checks if an object is equal to this tensor object.- Overrides:
equalsin 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
-