![]() |
Blaze 3.9
|
The addition of vectors is as intuitive as the addition of scalar values. For the addition of any two vectors the addition operator (i.e. operator+()
) can be used. It even enables the addition of dense and sparse vectors:
Note that it is necessary that both operands have exactly the same dimensions. Violating this precondition results in an exception. Also note that it is only possible to add vectors with the same transpose flag:
Also note that the addition of two vectors with the same element type is favorable due to possible vectorization of the operation:
The addition between a column vector and a row vector results in the outer sum of the two vectors:
The trans()
function can be used to transpose a vector as necessary:
For the addition of any two matrices the addition operator (i.e. operator+()
) can be used. It even enables the addition of dense and sparse matrices:
Note that it is necessary that both operands have exactly the same dimensions. Violating this precondition results in an exception. It is possible to add row-major and column-major matrices. Note however that in favor of performance the addition of two matrices with the same storage order is favorable. The same argument holds for the element type: In case two matrices with the same element type are added, the performance can be much higher due to vectorization of the operation.
For convenience it is also possible to add a scalar value to a dense vector or dense matrix, which has the same effect as adding a uniform vector or matrix. 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. Examples:
Previous: Arithmetic Operations Next: Subtraction