Class SemiringVector<T extends Semiring<T>>
java.lang.Object
org.flag4j.arrays.backend.AbstractTensor<SemiringVector<T>,T[],T>
org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor<SemiringVector<T>,T>
org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringVector<SemiringVector<T>,SemiringMatrix<T>,T>
org.flag4j.arrays.dense.SemiringVector<T>
- Type Parameters:
T
- Type of thesemiring
element for the matrix.
- All Implemented Interfaces:
Serializable
,SemiringTensorMixin<SemiringVector<T>,
,SemiringVector<T>, T> TensorOverSemiring<SemiringVector<T>,
,SemiringVector<T>, T[], T> VectorMixin<SemiringVector<T>,
SemiringMatrix<T>, SemiringMatrix<T>, T>
public class SemiringVector<T extends Semiring<T>>
extends AbstractDenseSemiringVector<SemiringVector<T>,SemiringMatrix<T>,T>
Instances of this class represents a dense vector backed by a Semiring
array. The SemiringVector
class
provides functionality for matrix operations whose elements are members of a semiring, supporting mutable data with a fixed shape.
A SemiringVector
is essentially equivalent to a rank-1 tensor but includes extended functionality
and may offer improved performance for certain operations compared to general rank-n tensors.
Key Features:
- Support for standard vector operations like addition, subtraction, and inner/outer products.
- Conversion methods to other representations, such as
SemiringMatrix
,SemiringTensor
, or COO (Coordinate). - Utility methods for checking properties like being the zero vector.
Example Usage:
// Constructing a complex matrix from an array of complex numbers
BoolSemiring[] data = {
new BoolSemiring(true), new BoolSemiring(false),
new BoolSemiring(true), new BoolSemiring(true)
};
SemiringVector<BoolSemiring> vector = new SemiringVector(data);
// Performing vector inner/outer product.
RealInt32 inner = vector.inner(vector);
SemiringMatrix<BoolSemiring> outer = vector.outer(vector);
// Checking if the vector only contains zeros (i.e. false).
boolean isZero = vector.isZeros();
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringVector
size
Fields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
zeroElement
Fields inherited from class org.flag4j.arrays.backend.AbstractTensor
data, rank, shape
-
Constructor Summary
ConstructorsConstructorDescriptionSemiringVector
(Shape shape, T[] data) Creates a semiring vector with the specified data and shape.SemiringVector
(T[] data) Creates a semiring vector with the specified data and shape. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if an object is equal to this vector object.int
hashCode()
protected CooSemiringVector
<T> makeLikeCooTensor
(Shape shape, T[] data, int[][] indices) Constructs a sparse COO tensor which is of a similar type as this dense tensor.protected SemiringMatrix
<T> makeLikeMatrix
(Shape shape, T[] entries) Constructs a matrix of similar type to this vector with the specifiedshape
anddata
.makeLikeTensor
(Shape shape, T[] entries) Constructs a tensor of the same type as this tensor with the given theshape
anddata
.makeLikeTensor
(T[] entries) Constructs a dense vector with the specifieddata
of the same type as the vector.toString()
Converts this vector to a human-readable string format.Methods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringVector
dot, get, inner, join, length, mag, normalize, outer, repeat, stack, toMatrix
Methods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
add, addEq, argmax, argmin, copy, elemMult, flatten, flatten, get, getZeroElement, max, min, reshape, set, setZeroElement, T, T, tensorDot, tensorTr, toCoo, toCoo
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.semiring_arrays.SemiringTensorMixin
add, addEq, isOnes, isZeros, makeEmptyDataArray, mult, multEq, prod, sum
Methods inherited from interface org.flag4j.arrays.backend.semiring_arrays.TensorOverSemiring
getData, getRank, getShape, tensorDot, tensorDot, tensorDot, tensorTr
Methods inherited from interface org.flag4j.arrays.backend.VectorMixin
size, stack, toMatrix
-
Constructor Details
-
SemiringVector
Creates a semiring vector with the specified data and shape.- Parameters:
data
- Entries of the vector.
-
SemiringVector
-
-
Method Details
-
makeLikeTensor
Constructs a dense vector with the specifieddata
of the same type as the vector.- Specified by:
makeLikeTensor
in classAbstractDenseSemiringVector<SemiringVector<T extends Semiring<T>>,
SemiringMatrix<T extends Semiring<T>>, T extends Semiring<T>> - Parameters:
entries
- Entries of the dense vector to construct.
-
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<SemiringVector<T extends Semiring<T>>,
SemiringVector<T extends Semiring<T>>, T extends Semiring<T>[], T extends Semiring<T>> - Specified by:
makeLikeTensor
in classAbstractTensor<SemiringVector<T extends Semiring<T>>,
T extends Semiring<T>[], T extends Semiring<T>> - 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
.
-
makeLikeMatrix
Constructs a matrix of similar type to this vector with the specifiedshape
anddata
.- Specified by:
makeLikeMatrix
in classAbstractDenseSemiringVector<SemiringVector<T extends Semiring<T>>,
SemiringMatrix<T extends Semiring<T>>, T extends Semiring<T>> - Parameters:
shape
- Shape of the matrix to construct.entries
- Entries of the matrix to construct.- Returns:
- A matrix of similar type to this vector with the specified
shape
anddata
.
-
makeLikeCooTensor
Constructs a sparse COO tensor which is of a similar type as this dense tensor.- Specified by:
makeLikeCooTensor
in classAbstractDenseSemiringTensor<SemiringVector<T extends Semiring<T>>,
T extends Semiring<T>> - Parameters:
shape
- Shape of the COO tensor.data
- Non-zero data of the COO tensor.indices
-- Returns:
- A sparse COO tensor which is of a similar type as this dense tensor.
-
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 typeSemiringVector
.false
otherwise.
-
hashCode
-
toString
Converts this vector to a human-readable string format. To specify the maximum number of data to print, usePrintOptions.setMaxColumns(int)
.
-