![]() |
Blaze
3.6
|
One of the prime features of the Blaze library is the automatic intra-statement optimization. In order to optimize the overall performance of every single statement Blaze attempts to rearrange the operands based on their types. For instance, the following addition of dense and sparse vectors
is automatically rearranged and evaluated as
This order of operands is highly favorable for the overall performance since the addition of the two dense vectors d1
and d2
can be handled much more efficiently in a vectorized fashion.
This intra-statement optimization can have a tremendous effect on the performance of a statement. Consider for instance the following computation:
Since multiplications are evaluated from left to right, this statement would result in a matrix/matrix multiplication, followed by a matrix/vector multiplication. However, if the right subexpression is evaluated first, the performance can be dramatically improved since the matrix/matrix multiplication can be avoided in favor of a second matrix/vector multiplication. The Blaze library exploits this by automatically restructuring the expression such that the right multiplication is evaluated first:
Note however that although this intra-statement optimization may result in a measurable or even significant performance improvement, this behavior may be undesirable for several reasons, for instance because of numerical stability. Therefore, in case the order of evaluation matters, the best solution is to be explicit and to separate a statement into several statements:
Alternatively, it is also possible to use the eval()
function to fix the order of evaluation:
Previous: Block Vectors and Matrices Next: Frequently Asked Questions (FAQ)