Blaze 3.9
Loading...
Searching...
No Matches
Scalar Multiplication

The scalar multiplication is the multiplication of vector or a matrix with a scalar value. Alternatively it is also possible to divide a vector or a matrix by a scalar value. In Blaze it is possible to use all built-in/fundamental data types except bool as scalar values. Additionally, it is possible to use std::complex values with the same built-in data types as element type.

blaze::DynamicVector<double> v2 = v1 * 1.2; // Scalar multiplication
blaze::CompressedVector<float> v3 = -0.3F * v1; // Scalar multiplication
blaze::DynamicVector<double> v4 = v1 / 1.2; // Scalar division
blaze::CompressedVector<float> v5 = 12.0F / v1; // Scalar division (only dense vectors)
blaze::DynamicVector<double> v6 = mult( v1, 1.2 ); // Alternative syntax
blaze::DynamicVector<double> v7 = div( v1, 1.2 ); // Alternative syntax
Efficient implementation of an arbitrary sized sparse vector.
Definition CompressedVector.h:220
Efficient implementation of an arbitrary sized vector.
Definition DynamicVector.h:223
Efficient implementation of a fixed-sized vector.
Definition StaticVector.h:230
blaze::StaticMatrix<int,3UL,2UL> M1{ { 1, 2 }, { 3, 4 }, { 5, 6 } };
blaze::DynamicMatrix<double> M2 = M1 * 1.2; // Scalar multiplication
blaze::CompressedMatrix<float> M3 = -0.3F * M1; // Scalar multiplication
blaze::DynamicMatrix<double> M4 = M1 / 1.2; // Scalar division
blaze::CompressedMatrix<float> M5 = 12.0F / M1; // Scalar division (only dense matrices)
blaze::DynamicMatrix<double> M6 = mult( M1, 1.2 ); // Alternative syntax
blaze::DynamicMatrix<double> M7 = div( M1, 1.2 ); // Alternative syntax
Efficient implementation of a compressed matrix.
Definition CompressedMatrix.h:239
Efficient implementation of a dynamic matrix.
Definition DynamicMatrix.h:242
Efficient implementation of a fixed-sized matrix.
Definition StaticMatrix.h:249
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
BLAZE_ALWAYS_INLINE constexpr decltype(auto) div(T1 &&lhs, T2 &&rhs) noexcept(noexcept(lhs/rhs))
Division of the two given arguments.
Definition Div.h:66

Vectors and matrices cannot be used for as scalar value for scalar multiplications or divisions (see the following example). However, each vector and matrix provides the scale() function, which can be used to scale a vector or matrix element-wise with arbitrary scalar data types:

M1 * scalar; // No scalar multiplication, but matrix/matrix multiplication
M1.scale( scalar ); // Scalar multiplication


Previous: Subtraction     Next: Componentwise Multiplication