Class CooCVector
- All Implemented Interfaces:
Serializable
,FieldTensorMixin<CooCVector,
,CVector, Complex128> TensorOverField<CooCVector,
,CVector, Complex128[], Complex128> RingTensorMixin<CooCVector,
,CVector, Complex128> TensorOverRing<CooCVector,
,CVector, Complex128[], Complex128> SemiringTensorMixin<CooCVector,
,CVector, Complex128> TensorOverSemiring<CooCVector,
,CVector, Complex128[], Complex128> VectorMixin<CooCVector,
CooCMatrix, CMatrix, Complex128>
A complex sparse vector stored in coordinate list (COO) format. The AbstractTensor.data
of this COO vector are
Complex128
's.
The non-zero data
and non-zero indices
of a COO vector are mutable but the AbstractTensor.shape
and total number of non-zero data is fixed.
Sparse vectors allow for the efficient storage of and ops on vectors that contain many zero values.
COO vectors are optimized for hyper-sparse vectors (i.e. vectors which contain almost all zeros relative to the size of the vector).
A sparse COO vector is stored as:
- The full
AbstractTensor.shape
/VectorMixin.size()
of the vector. - The non-zero
AbstractTensor.data
of the vector. All other data in the vector are assumed to be zero. Zero values can also explicitly be stored inAbstractTensor.data
. - The
AbstractCooSemiringVector.indices
of the non-zero values in the sparse vector.
Note: many ops assume that the data of the COO vector are sorted lexicographically. However, this is not explicitly verified. Every operation implemented in this class will preserve the lexicographical sorting.
If indices need to be sorted for any reason, call AbstractCooSemiringVector.sortIndices()
.
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractCooSemiringVector
indices, nnz, size, sparsity
Fields inherited from class org.flag4j.arrays.backend.AbstractTensor
data, rank, shape
-
Constructor Summary
ConstructorsConstructorDescriptionCooCVector
(int size) Constructs a zero vector of the specifiedsize
.CooCVector
(int size, double[] entries, int[] indices) Constructs a sparse complex COO vector from an array of double values.CooCVector
(int size, List<Complex128> entries, List<Integer> indices) Constructs a complex COO vector with the specified size, non-zero data, and non-zero indices.CooCVector
(int size, Complex128[] entries, int[] indices) Creates a tensor with the specified data and shape.CooCVector
(Shape shape, List<Complex128> entries, List<Integer> indices) Constructs a complex COO vector with the specified size, non-zero data, and non-zero indices.CooCVector
(Shape shape, Complex128[] entries, int[] indices) Creates a tensor with the specified data and shape.Constructs a copy of the specified vector. -
Method Summary
Modifier and TypeMethodDescriptionComputes the element-wise sum of two vectors.boolean
Checks if an object is equal to this vector 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.mag()
Computes the magnitude of this vector.double
Computes the magnitude of this vector as a double value.makeEmptyDataArray
(int length) Creates an empty array of the same type as the data array of this tensor.makeLikeDenseMatrix
(Shape shape, Complex128... entries) Constructs a dense matrix of a similar type as this vector with the specified shape and data.makeLikeDenseTensor
(Shape shape, Complex128... entries) Constructs a dense vector of a similar type as this vector with the specified shape and data.makeLikeMatrix
(Shape shape, Complex128[] entries, int[] rowIndices, int[] colIndices) Constructs a COO matrix with the specified shape, non-zero data, and row and column indices.makeLikeTensor
(Shape shape, List<Complex128> entries, List<Integer> indices) Constructs a COO vector with the specified shape, non-zero data, and non-zero indices.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 sparse COO vector of the same type as this vector with the specified non-zero data and indices.Normalizes this vector to a unit length vector.round
(int precision) Rounds all data within this vector to the specified precision.roundToZero
(double tolerance) Sets all elements of this vector to zero if they are withintol
of zero.toReal()
Converts this complex vector to a real vector.toString()
Formats this tensor as a human-readable string.toTensor()
Converts this matrix to an equivalent rank 1 tensor.Converts this vector to an equivalent tensor with the specified shape.Methods inherited from class org.flag4j.arrays.backend.field_arrays.AbstractCooFieldVector
abs, div, H, H, isFinite, isInfinite, isNaN, sqrt
Methods inherited from class org.flag4j.arrays.backend.ring_arrays.AbstractCooRingVector
inner, sub
Methods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractCooSemiringVector
add, coalesce, coalesce, copy, density, dot, dropZeros, elemMult, flatten, flatten, get, get, getZeroElement, join, length, outer, repeat, reshape, set, setZeroElement, sortIndices, sparsity, stack, T, T, tensorDot, tensorTr, toDense, toMatrix
Methods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, reshape, sameShape, T, 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.semiring_arrays.SemiringTensorMixin
argmax, argmin, max, min
Methods inherited from interface org.flag4j.arrays.backend.ring_arrays.TensorOverRing
H, sub
-
Constructor Details
-
CooCVector
Creates a tensor with the specified data and shape.- Parameters:
size
- Full size of the vector.entries
- Non-zero data of the sparse vector.indices
- Non-zero indices of the sparse vector.
-
CooCVector
Creates a tensor with the specified data and shape.- Parameters:
shape
- Full shape of the vector. Must be rank 1.entries
- Non-zero data of the sparse vector.indices
- Non-zero indices of the sparse vector.
-
CooCVector
Constructs a complex COO vector with the specified size, non-zero data, and non-zero indices.- Parameters:
size
- Full size of the vector.entries
- The non-zero data of the vector.indices
- The indices of the non-zero data.
-
CooCVector
Constructs a complex COO vector with the specified size, non-zero data, and non-zero indices.- Parameters:
shape
- Full shape of the sparse vector. Must be rank 1.entries
- The non-zero data of the vector.indices
- The indices of the non-zero data.
-
CooCVector
public CooCVector(int size) Constructs a zero vector of the specifiedsize
.- Parameters:
size
- Full size of the vector.
-
CooCVector
public CooCVector(int size, double[] entries, int[] indices) Constructs a sparse complex COO vector from an array of double values.- Parameters:
size
- Full size of the vector.entries
- Non-zero data of the sparse vector.indices
- Non-zero indices of the sparse vector.
-
CooCVector
Constructs a copy of the specified vector.- Parameters:
b
- The vector to create a 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 sparse COO vector of the same type as this vector with the specified non-zero data and indices.- Specified by:
makeLikeTensor
in classAbstractCooSemiringVector<CooCVector,
CVector, CooCMatrix, CMatrix, Complex128> - Parameters:
shape
- Shape of the vector to construct.entries
- Non-zero data of the vector to construct.indices
- Non-zero row indices of the vector to construct.- Returns:
- A sparse COO vector of the same type as this vector with the specified non-zero data and indices.
-
makeLikeDenseTensor
Constructs a dense vector of a similar type as this vector with the specified shape and data.- Specified by:
makeLikeDenseTensor
in classAbstractCooSemiringVector<CooCVector,
CVector, CooCMatrix, CMatrix, Complex128> - Parameters:
shape
- Shape of the vector to construct.entries
- Entries of the vector to construct.- Returns:
- A dense vector of a similar type as this vector with the specified data.
-
makeLikeDenseMatrix
Constructs a dense matrix of a similar type as this vector with the specified shape and data.- Specified by:
makeLikeDenseMatrix
in classAbstractCooSemiringVector<CooCVector,
CVector, CooCMatrix, CMatrix, Complex128> - Parameters:
shape
- Shape of the matrix to construct.entries
- Entries of the matrix to construct.- Returns:
- A dense matrix of a similar type as this vector with the specified data.
-
makeLikeTensor
Constructs a COO vector with the specified shape, non-zero data, and non-zero indices.- Specified by:
makeLikeTensor
in classAbstractCooSemiringVector<CooCVector,
CVector, CooCMatrix, CMatrix, Complex128> - Parameters:
shape
- Shape of the vector.entries
- Non-zero values of the vector.indices
- Indices of the non-zero values in the vector.- Returns:
- A COO vector of the same type as this vector with the specified shape, non-zero data, and non-zero indices.
-
makeLikeMatrix
public CooCMatrix makeLikeMatrix(Shape shape, Complex128[] entries, int[] rowIndices, int[] colIndices) Constructs a COO matrix with the specified shape, non-zero data, and row and column indices.- Specified by:
makeLikeMatrix
in classAbstractCooSemiringVector<CooCVector,
CVector, CooCMatrix, CMatrix, Complex128> - Parameters:
shape
- Shape of the matrix to construct.entries
- Non-zero data of the matrix.rowIndices
- Row indices of the matrix.colIndices
- Column indices of the matrix.- Returns:
- A COO matrix of similar type as this vector with the specified shape, non-zero data, and non-zero row/col indices.
-
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<CooCVector,
CVector, Complex128[], Complex128> - Specified by:
makeLikeTensor
in classAbstractTensor<CooCVector,
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
.
-
toTensor
Converts this matrix to an equivalent rank 1 tensor.- Specified by:
toTensor
in classAbstractCooSemiringVector<CooCVector,
CVector, CooCMatrix, CMatrix, Complex128> - Returns:
- A tensor which is equivalent to this matrix.
-
toTensor
Converts this vector to an equivalent tensor with the specified shape.- Specified by:
toTensor
in classAbstractCooSemiringVector<CooCVector,
CVector, CooCMatrix, CMatrix, Complex128> - Parameters:
newShape
- New shape for the tensor. Can be any rank but must be broadcastable tothis.shape
.- Returns:
- A tensor equivalent to this matrix which has been reshaped to
newShape
-
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 vector 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 vector containing the data of this vector rounded to the specified precision.
-
roundToZero
Sets all elements of this vector 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 vector with all data within
tol
of zero set to zero.
-
add
Computes the element-wise sum of two vectors.- Parameters:
b
- Second vector in the sum.- Returns:
- The element-wise sum of this vector and
b
.
-
normalize
Normalizes this vector to a unit length vector.- Specified by:
normalize
in interfaceVectorMixin<CooCVector,
CooCMatrix, CMatrix, Complex128> - Overrides:
normalize
in classAbstractCooFieldVector<CooCVector,
CVector, CooCMatrix, CMatrix, Complex128> - Returns:
- This vector normalized to a unit length.
-
mag
Computes the magnitude of this vector.- Specified by:
mag
in interfaceVectorMixin<CooCVector,
CooCMatrix, CMatrix, Complex128> - Overrides:
mag
in classAbstractCooFieldVector<CooCVector,
CVector, CooCMatrix, CMatrix, Complex128> - Returns:
- The magnitude of this vector.
-
magAsDouble
public double magAsDouble()Computes the magnitude of this vector as a double value.- Returns:
- The magnitude of this vector as a double value.
-
equals
Checks if an object is equal to this vector object.- Overrides:
equals
in classObject
- Parameters:
object
- Object to check equality with this vector.- Returns:
- True if the two vectors have the same shape, are numerically equivalent, and are of type
CooCVector
. False otherwise.
-
hashCode
-
toString
-