Class AbstractCooFieldVector<T extends AbstractCooFieldVector<T,U,V,W,Y>,U extends AbstractDenseFieldVector<U,W,Y>,V extends AbstractCooFieldMatrix<V,W,T,Y>,W extends AbstractDenseFieldMatrix<W,U,Y>,Y extends Field<Y>>
- Type Parameters:
T
- Type of this vector.U
- Type of equivalent dense vector.V
- Type of matrix equivalent toT
.W
- Type of dense matrix equivalent toU
.Y
- Type of the field element in this vector.
- All Implemented Interfaces:
Serializable
,FieldTensorMixin<T,
,U, Y> TensorOverField<T,
,U, Y[], Y> RingTensorMixin<T,
,U, Y> TensorOverRing<T,
,U, Y[], Y> SemiringTensorMixin<T,
,U, Y> TensorOverSemiring<T,
,U, Y[], Y> VectorMixin<T,
V, W, Y>
- Direct Known Subclasses:
CooCVector
,CooFieldVector
A sparse vector stored in coordinate list (COO) format. The AbstractTensor.data
of this COO vector are
elements of a Field
.
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 large vectors that contain many zero values.
COO vectors are optimized for large 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
ConstructorsModifierConstructorDescriptionprotected
AbstractCooFieldVector
(Shape shape, Y[] data, int[] indices) Creates a tensor with the specified data and shape.protected
AbstractCooFieldVector
(Shape shape, Y[] data, int[] indices, Object dummy) Creates a tensor with the specified data and shape without performing any validation on the parameters. -
Method Summary
Modifier and TypeMethodDescriptionabs()
Computes the element-wise absolute value of this tensor.Computes the element-wise quotient between two tensors.H
(int... axes) Computes the conjugate transpose of this tensor.H
(int axis1, int axis2) Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1
andaxis2
.boolean
isFinite()
Checks if this tensor only contains finite values.boolean
Checks if this tensor contains at least one infinite value.boolean
isNaN()
Checks if this tensor contains at least one NaN value.mag()
Computes the magnitude of this vector.Normalizes this vector to a unit length vector.sqrt()
Computes the element-wise square root of this tensor.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, dataLength, density, dot, dropZeros, elemMult, flatten, flatten, get, get, getZeroElement, join, length, makeLikeDenseMatrix, makeLikeDenseTensor, makeLikeMatrix, makeLikeTensor, makeLikeTensor, outer, repeat, reshape, set, setZeroElement, sortIndices, sparsity, stack, T, T, tensorDot, tensorTr, toDense, toMatrix, toTensor, toTensor
Methods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, makeLikeTensor, reshape, sameShape, T, 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.arrays.backend.field_arrays.FieldTensorMixin
add, add, addEq, addEq, argmax, argmaxAbs, argmin, argminAbs, conj, div, div, divEq, divEq, isOnes, isZeros, makeEmptyDataArray, 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
-
AbstractCooFieldVector
-
AbstractCooFieldVector
Creates a tensor with the specified data and shape without performing any validation on the parameters.- Parameters:
shape
- Shape of this tensor.data
- Non-zero entries of the tensor.indices
- Non-zero entries of the tensor.dummy
- Dummy object to distinguish this constructor from the safe variant.
-
-
Method Details
-
abs
Computes the element-wise absolute value of this tensor.- Specified by:
abs
in interfaceTensorOverRing<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>> - Returns:
- The element-wise absolute value of this tensor.
-
H
Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1
andaxis2
.- Specified by:
H
in interfaceTensorOverRing<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>> - Overrides:
H
in classAbstractCooRingVector<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>, Y extends Field<Y>> - 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 eitheraxis1
oraxis2
are 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:
H
in interfaceTensorOverRing<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>> - Overrides:
H
in classAbstractCooRingVector<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>, Y extends Field<Y>> - Parameters:
axes
- Permutation of tensor axis. If the tensor has rankN
, then this must be an array of lengthN
which is a permutation of{0, 1, 2, ..., N-1}
.- Returns:
- The conjugate transpose of this tensor with its axes permuted by the
axes
array. - Throws:
IndexOutOfBoundsException
- If any element ofaxes
is out of bounds for the rank of this tensor.IllegalArgumentException
- Ifaxes
is not a permutation of{1, 2, 3, ... N-1}
.- See Also:
-
div
Computes the element-wise quotient between two tensors.
WARNING: This method is not supported for sparse tensors. If called on a sparse tensor, an
UnsupportedOperationException
will be thrown. Element-wise division is undefined for sparse matrices as it would almost certainly result in a division by zero.- Specified by:
div
in interfaceTensorOverField<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>> - Parameters:
b
- Second tensor in the element-wise quotient.- Returns:
- The element-wise quotient of this tensor with
b
. - Throws:
UnsupportedOperationException
- if this method is ever invoked on a sparse tensor.
-
sqrt
Computes the element-wise square root of this tensor.- Specified by:
sqrt
in interfaceTensorOverField<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>> - Returns:
- The element-wise square root of this tensor.
-
isFinite
public boolean isFinite()Checks if this tensor only contains finite values.- Specified by:
isFinite
in interfaceTensorOverField<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>> - Returns:
true
if this tensor only contains finite values;false
otherwise.- See Also:
-
isInfinite
public boolean isInfinite()Checks if this tensor contains at least one infinite value.- Specified by:
isInfinite
in interfaceTensorOverField<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>> - Returns:
true
if this tensor contains at least one infinite value;false
otherwise.- See Also:
-
isNaN
public boolean isNaN()Checks if this tensor contains at least one NaN value.- Specified by:
isNaN
in interfaceTensorOverField<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>> - Returns:
true
if this tensor contains at least one NaN value;false
otherwise.- See Also:
-
normalize
Normalizes this vector to a unit length vector.- Specified by:
normalize
in interfaceVectorMixin<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>> - Overrides:
normalize
in classAbstractCooSemiringVector<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>, Y extends Field<Y>> - Returns:
- This vector normalized to a unit length.
-
mag
Computes the magnitude of this vector.- Specified by:
mag
in interfaceVectorMixin<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>> - Overrides:
mag
in classAbstractCooSemiringVector<T extends AbstractCooFieldVector<T,
U, V, W, Y>, U extends AbstractDenseFieldVector<U, W, Y>, V extends AbstractCooFieldMatrix<V, W, T, Y>, W extends AbstractDenseFieldMatrix<W, U, Y>, Y extends Field<Y>> - Returns:
- The magnitude of this vector.
-