All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Vector/Vector Multiplication
Previous: Scalar Multiplication     Next: Matrix/Vector Multiplication



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 );
// ... Initialization of the vectors
CompressedVector<int,columnVector> v5( v1 * v2 ); // Componentwise multiplication of a sparse and
// a dense column vector. The result is a sparse
// column vector.
DynamicVector<double,rowVector> v6( v3 * v4 ); // Componentwise multiplication of two dense row
// vectors. The result is a dense row vector.


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:

v2[0] = -1;
v2[1] = 3;
v2[2] = -2;
int result = v1 * v2; // Results in the value 15

The trans() function can be used to transpose a vector as necessary:

int result = v1 * trans( v2 ); // Also results in the value 15

Alternatively, the comma operator can used for any combination of vectors (row or column vectors) to perform an inner product:

int result = (v1,v2); // Inner product between two row vectors

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:

v2[0] = -1;
v2[1] = 3;
v2[2] = -2;
StaticMatrix<int,3UL,3UL> M1 = v1 * v2;

The trans() function can be used to transpose a vector as necessary:

int result = trans( v1 ) * v2;


Cross Product


Two column vectors can be multiplied via the cross product. The cross product between two vectors $ a $ and $ b $ is defined as

\[ \left(\begin{array}{*{1}{c}} c_0 \\ c_1 \\ c_2 \\ \end{array}\right) = \left(\begin{array}{*{1}{c}} a_1 b_2 - a_2 b_1 \\ a_2 b_0 - a_0 b_2 \\ a_0 b_1 - a_1 b_0 \\ \end{array}\right). \]

Due to the absence of a $ \times $ operator in the C++ language, the cross product is realized via the modulo operator (i.e. operator%):

v2[0] = -1;
v2[1] = 3;
v2[2] = -2;

Please note that the cross product is restricted to three dimensional (dense and sparse) vectors.


Previous: Scalar Multiplication     Next: Matrix/Vector Multiplication