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 thesemiringelement 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
sizeFields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
zeroElementFields 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 TypeMethodDescriptionbooleanChecks if an object is equal to this vector object.inthashCode()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 specifiedshapeanddata.makeLikeTensor(Shape shape, T[] entries) Constructs a tensor of the same type as this tensor with the given theshapeanddata.makeLikeTensor(T[] entries) Constructs a dense vector with the specifieddataof 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, toMatrixMethods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
add, addEq, argmax, argmin, copy, dataLength, elemMult, flatten, flatten, get, getZeroElement, max, min, reshape, set, setZeroElement, T, T, tensorDot, tensorTr, toCoo, toCooMethods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, reshape, sameShape, T, totalEntriesMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.flag4j.arrays.backend.semiring_arrays.SemiringTensorMixin
add, addEq, isOnes, isZeros, makeEmptyDataArray, mult, multEq, prod, sumMethods inherited from interface org.flag4j.arrays.backend.semiring_arrays.TensorOverSemiring
getData, getRank, getShape, tensorDot, tensorDot, tensorDot, tensorTrMethods 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 specifieddataof the same type as the vector.- Specified by:
makeLikeTensorin 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 theshapeanddata. The resulting tensor will also have the same non-zero indices as this tensor.- Specified by:
makeLikeTensorin interfaceTensorOverSemiring<SemiringVector<T extends Semiring<T>>,SemiringVector<T extends Semiring<T>>, T extends Semiring<T>[], T extends Semiring<T>> - Specified by:
makeLikeTensorin 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
shapeanddata.
-
makeLikeMatrix
Constructs a matrix of similar type to this vector with the specifiedshapeanddata.- Specified by:
makeLikeMatrixin 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
shapeanddata.
-
makeLikeCooTensor
Constructs a sparse COO tensor which is of a similar type as this dense tensor.- Specified by:
makeLikeCooTensorin 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:
equalsin classObject- Parameters:
object- Object to check equality with this vector.- Returns:
trueif the two vectors have the same shape, are numerically equivalent, and are of typeSemiringVector.falseotherwise.
-
hashCode
-
toString
Converts this vector to a human-readable string format. To specify the maximum number of data to print, usePrintOptions.setMaxColumns(int).
-