Interface VectorMixin<T extends VectorMixin<T,U,V,W>,U extends MatrixMixin<U,V,T,W>,V extends MatrixMixin<V,V,?,W>,W>
- Type Parameters:
T
- Type of this vector.U
- Type of matrix which is similar toT
.V
- Type of dense matrix which is similar toU
. IfT
is dense, thenU
andT
should be the same type.W
- Type (or wrapper of) an individual element of the vector.
- All Known Implementing Classes:
AbstractCooFieldVector
,AbstractCooRingVector
,AbstractCooSemiringVector
,AbstractDenseFieldVector
,AbstractDenseRingVector
,AbstractDenseSemiringVector
,CooCVector
,CooFieldVector
,CooRingVector
,CooSemiringVector
,CooVector
,CVector
,FieldVector
,RingVector
,SemiringVector
,Vector
-
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.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.default int
size()
Gets the size/length of a vector.default U
Stacks two vectors vertically as if they were row vectors to form a matrix with two rows.Stacks two vectors along specified axis.default U
toMatrix()
Converts a vector to an equivalent matrix representing the vector as a column vector.toMatrix
(boolean columVector) Converts a vector to an equivalent matrix representing either a row or column vector.
-
Method Details
-
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
.- 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.
Note: this method is distinct from
dot(VectorMixin)
. The inner product is equivalent to the dot product of this tensor with the conjugation ofb
.- 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(VectorMixin)
. The inner product is equivalent to the dot product of this tensor with the conjugation ofb
.- 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
int length()Gets the length of a vector. Same assize()
.- Returns:
- The length, i.e. the number of data, in this vector.
-
size
default int size()Gets the size/length of a vector. Same aslength()
.- 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.- Parameters:
n
- Number of times to repeat vector.axis
- Axis along which to repeat vector:- 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 vertically as if they were row vectors to form a matrix with two rows.- Parameters:
b
- Vector to stack below this vector.- Returns:
- The result of stacking this vector and vector
b
. - Throws:
IllegalArgumentException
- If the number of data in this vector is different from the number of data in the vectorb
.
-
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×n
matrix.Stacking two vectors of length
n
along axis 1 stacks the vectors as if they were column vectors resulting in an×2
matrix.- 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.- 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 the vector as a column vector.- Returns:
- A matrix equivalent to this vector as if it were a column vector.
-
toMatrix
Converts a vector to an equivalent matrix representing either a row or column vector.- 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
T normalize()Normalizes this vector to a unit length vector.- Returns:
- This vector normalized to a unit length.
-
mag
-
get
Gets the element of this vector at the specified index.- Parameters:
idx
- Index of the element to get within this vector.- Returns:
- The element of this vector at index
idx
.
-