Class AbstractDenseSemiringVector<T extends AbstractDenseSemiringVector<T,U,V>,U extends AbstractDenseSemiringMatrix<U,T,V>,V extends Semiring<V>>
- Type Parameters:
T
- Type of the vector.U
- Type of matrix equivalent to this vector.V
- Type of thefield
element of this vector.
- All Implemented Interfaces:
Serializable
,SemiringTensorMixin<T,
,T, V> TensorOverSemiring<T,
,T, V[], V> VectorMixin<T,
U, U, V>
- Direct Known Subclasses:
AbstractDenseRingVector
,SemiringVector
The base class for all dense vectors whose data are Semiring
elements.
Vectors are 1D tensors (i.e. rank 1 tensor).
AbstractDenseSemiringVector vectors have mutable AbstractTensor.data
but a fixed AbstractTensor.shape
.
- See Also:
-
Field Summary
FieldsFields 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
ConstructorsModifierConstructorDescriptionprotected
AbstractDenseSemiringVector
(Shape shape, V[] data) Constructs a dense semiring vector with the specified data and shape. -
Method Summary
Modifier and TypeMethodDescriptionComputes the dot product between two vectors.get
(int idx) Gets the element of this vector at the specified index.Computes the inner product between two vectors.Joints specified vector with this vector.int
length()
Gets the length of a vector.mag()
Computes the magnitude of this vector.protected abstract U
makeLikeMatrix
(Shape shape, V[] entries) Constructs a matrix of similar type to this vector with the specifiedshape
anddata
.abstract T
makeLikeTensor
(V[] entries) Constructs a dense vector with the specifieddata
of the same type as the vector.Normalizes this vector to a unit length vector.Computes the outer product of two vectors.repeat
(int n, int axis) Repeats a vectorn
times along a certain axis to create a matrix.Stacks two vectors along specified axis.toMatrix
(boolean columVector) Converts a vector to an equivalent matrix representing either a row or column vector.Methods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
add, addEq, argmax, argmin, copy, elemMult, flatten, flatten, get, getZeroElement, makeLikeCooTensor, max, min, reshape, set, setZeroElement, T, T, tensorDot, tensorTr, toCoo, toCoo
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.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, makeLikeTensor, tensorDot, tensorDot, tensorDot, tensorTr
Methods inherited from interface org.flag4j.arrays.backend.VectorMixin
size, stack, toMatrix
-
Field Details
-
size
public final int sizeThe size of this vector. This is the total number of data stored in this vector.
-
-
Constructor Details
-
AbstractDenseSemiringVector
Constructs a dense semiring vector with the specified data and shape.- Parameters:
shape
- Shape of this tensor.data
- Entries of this tensor. If this tensor is dense, this specifies all data within the tensor. If this tensor is sparse, this specifies only the non-zero data of the tensor.- Throws:
LinearAlgebraException
- Ifshape.getRank() != 1
.
-
-
Method Details
-
makeLikeTensor
-
makeLikeMatrix
Constructs a matrix of similar type to this vector with the specifiedshape
anddata
.- 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
.
-
join
Joints specified vector with this vector. That is, creates a vector of lengththis.length() + b.length()
containing first the elements of this vector followed by the elements ofb
.- Specified by:
join
in interfaceVectorMixin<T extends AbstractDenseSemiringVector<T,
U, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, V extends Semiring<V>> - Parameters:
b
- Vector to join with this vector.- Returns:
- A vector resulting from joining the specified vector with this vector.
-
inner
Computes the inner product between two vectors.
- Specified by:
inner
in interfaceVectorMixin<T extends AbstractDenseSemiringVector<T,
U, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, V extends Semiring<V>> - Parameters:
b
- Second vector in the inner product.- Returns:
- The inner product between this vector and the vector
b
. - Throws:
IllegalArgumentException
- If this vector and vectorb
do not have the same number of data.- See Also:
-
dot
Computes the dot product between two vectors.
Note: this method is distinct from
inner(AbstractDenseSemiringVector)
. The inner product is equivalent to the dot product of this tensor with the conjugation ofb
.- Specified by:
dot
in interfaceVectorMixin<T extends AbstractDenseSemiringVector<T,
U, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, V extends Semiring<V>> - Parameters:
b
- Second vector in the dot product.- Returns:
- The dot product between this vector and the vector
b
. - Throws:
IllegalArgumentException
- If this vector and vectorb
do not have the same number of data.- See Also:
-
length
public int length()Gets the length of a vector. Same asVectorMixin.size()
.- Specified by:
length
in interfaceVectorMixin<T extends AbstractDenseSemiringVector<T,
U, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, V extends Semiring<V>> - Returns:
- The length, i.e. the number of data, in this vector.
-
repeat
Repeats a vectorn
times along a certain axis to create a matrix.- Specified by:
repeat
in interfaceVectorMixin<T extends AbstractDenseSemiringVector<T,
U, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, V extends Semiring<V>> - Parameters:
n
- Number of times to repeat vector. Must be positive.axis
- Axis along which to repeat vector. Must be either 1 or 0.- If
axis=0
, then the vector will be treated as a row vector and stacked verticallyn
times. - If
axis=1
then the vector will be treated as a column vector and stacked horizontallyn
times.
- If
- Returns:
- A matrix whose rows/columns are this vector repeated.
-
stack
Stacks two vectors along specified axis.
Stacking two vectors of length
n
along axis 0 stacks the vectors as if they were row vectors resulting in a2-by-n
matrix.Stacking two vectors of length
n
along axis 1 stacks the vectors as if they were column vectors resulting in an-by-2
matrix.- Specified by:
stack
in interfaceVectorMixin<T extends AbstractDenseSemiringVector<T,
U, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, V extends Semiring<V>> - Parameters:
b
- Vector to stack with this vector.axis
- Axis along which to stack vectors. Ifaxis=0
, then vectors are stacked as if they are row vectors. Ifaxis=1
, then vectors are stacked as if they are column vectors.- Returns:
- The result of stacking this vector and the vector
b
. - Throws:
IllegalArgumentException
- If the number of data in this vector is different from the number of data in the vectorb
.IllegalArgumentException
- If axis is not either 0 or 1.
-
outer
Computes the outer product of two vectors.- Specified by:
outer
in interfaceVectorMixin<T extends AbstractDenseSemiringVector<T,
U, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, V extends Semiring<V>> - Parameters:
b
- Second vector in the outer product.- Returns:
- The result of the vector outer product between this vector and
b
. - Throws:
IllegalArgumentException
- If the two vectors do not have the same number of data.
-
toMatrix
Converts a vector to an equivalent matrix representing either a row or column vector.- Specified by:
toMatrix
in interfaceVectorMixin<T extends AbstractDenseSemiringVector<T,
U, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, V extends Semiring<V>> - Parameters:
columVector
- Flag indicating whether to convert this vector to a matrix representing a row or column vector:If
true
, the vector will be converted to a matrix representing a column vector.If
false
, The vector will be converted to a matrix representing a row vector.- Returns:
- A matrix equivalent to this vector.
-
normalize
Normalizes this vector to a unit length vector.- Specified by:
normalize
in interfaceVectorMixin<T extends AbstractDenseSemiringVector<T,
U, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, V extends Semiring<V>> - Returns:
- This vector normalized to a unit length.
-
mag
-
get
Gets the element of this vector at the specified index.- Specified by:
get
in interfaceVectorMixin<T extends AbstractDenseSemiringVector<T,
U, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, U extends AbstractDenseSemiringMatrix<U, T, V>, V extends Semiring<V>> - Parameters:
idx
- Index of the element to get within this vector.- Returns:
- The element of this vector at index
idx
.
-