Componentwise Multiplication
Multiplying two vectors with the same transpose flag (i.e. either blaze::columnVector or blaze::rowVector) via the multiplication operator results in a componentwise multiplication of the two vectors:
CompressedVector<int,columnVector> v1( 17UL );
DynamicVector<int,columnVector> v2( 17UL );
StaticVector<double,10UL,rowVector> v3;
DynamicVector<double,rowVector> v4( 10UL );
CompressedVector<int,columnVector> v5( v1 * v2 );
DynamicVector<double,rowVector> v6( v3 * v4 );
CompressedVector<int,columnVector> v7(
mult( v1, v2 ) );
DynamicVector<double,rowVector> v8(
mult( v3, v4 ) );
Efficient implementation of an arbitrary sized sparse vector.
Definition: CompressedVector.h:220
Efficient implementation of an arbitrary sized vector.
Definition: DynamicVector.h:223
BLAZE_ALWAYS_INLINE constexpr decltype(auto) mult(T1 &&lhs, T2 &&rhs) noexcept(noexcept(lhs *rhs))
Multiplication of the two given arguments.
Definition: Mult.h:66
Inner Product / Scalar Product / Dot Product
The multiplication between a row vector and a column vector results in an inner product between the two vectors:
int result1 = v1 * v2;
int result2 =
mult( v1, v2 );
Efficient implementation of a fixed-sized vector.
Definition: StaticVector.h:230
The trans()
function can be used to transpose a vector as necessary:
int result = v1 *
trans( v2 );
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
Alternatively, either the inner()
function, the dot()
function or the comma operator can be used for any combination of vectors (row or column vectors) to perform an inner product:
int result2 =
inner( v1, v2 );
int result3 =
dot( v1, v2 );
int result4 = (v1,v2);
decltype(auto) inner(const Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Scalar product (dot/inner product) of two vectors ( ).
Definition: Vector.h:248
decltype(auto) dot(const Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Scalar product (dot/inner product) of two vectors ( ).
Definition: Vector.h:283
When using the comma operator, please note the brackets embracing the inner product expression. Due to the low precedence of the comma operator (lower even than the assignment operator) these brackets are strictly required for a correct evaluation of the inner product.
Outer Product
The multiplication between a column vector and a row vector results in the outer product of the two vectors:
Efficient implementation of a fixed-sized matrix.
Definition: StaticMatrix.h:249
The trans()
function can be used to transpose a vector as necessary:
Alternatively, the outer()
function can be used for any combination of vectors (row or column vectors) to perform an outer product:
decltype(auto) outer(const Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Outer product of two vectors ( ).
Definition: Vector.h:352
Cross Product
Two vectors with the same transpose flag can be multiplied via the cross product. The cross product between two vectors
and
is defined as
Due to the absence of a
operator in the C++ language, the cross product is realized via the cross()
function. Alternatively, the modulo operator (i.e. operator%
) can be used in case infix notation is required:
decltype(auto) cross(const Vector< VT1, TF > &lhs, const Vector< VT2, TF > &rhs)
Cross product of two vectors ( ).
Definition: Vector.h:387
Please note that the cross product is restricted to three dimensional (dense and sparse) column vectors.
Kronecker Product
The Kronecker product of two vectors with the same transpose flag can be computed via the kron() function:
DynamicVector<double> v1( 28UL );
CompressedVector<float> v2( 17UL );
CompressedVector<double> v3 =
kron( v1, v2 );
decltype(auto) kron(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the Kronecker product of two dense matrices ( ).
Definition: DMatDMatKronExpr.h:957
Both dense and sparse vectors can be used for a Kronecker product. It is possible to multiply two vectors with different element type, as long as the element types themselves can be multiplied.
Previous: Scalar Multiplication Next: Vector/Vector Division