- edited description
blaze::max with ZeroVector does not compile
Hi!
The below example fails to compile on g++ 9.2.1, blaze revision cc8016:
#include <blaze/Math.h>
int main() {
blaze::StaticVector<double, 3> a = {-1.0d, 2.0d, 3.0d};
blaze::ZeroVector<double> zv(3);
a = blaze::max(a, zv);
return 0;
}
producing
blaze_tmp.cpp:6:25: error: no matching function for call to 'max(blaze::StaticVector<double, 3>&, blaze::ZeroVector<double>&)'
Comments (5)
-
reporter -
- changed status to wontfix
Hi Anton!
Thanks for taking the time to create this issue. You are correct, it is not possible to use the
max()
function with a dense vector (e.g.blaze::StaticVector
) and a sparse vector (e.g.blaze::ZeroVector
). The wiki explicitly states:… If passed two or more dense vectors, the
min()
andmax()
functions compute the componentwise minimum or maximum of the given vectors, respectively. ...There is, however, a very convenient and due to vectorization even much more efficient alternative:
int main() { blaze::StaticVector<double, 3> a = {-1.0, 2.0, 3.0}; blaze::UniformVector<double> u(3UL, 0.0); a = blaze::max(a, u); }
The
uniform()
function provides an even more convenient shortcut:int main() { blaze::StaticVector<double, 3> a = {-1.0, 2.0, 3.0}; a = blaze::max(a, blaze::uniform(3UL, 0.0)); }
See the wiki section about Scalar Expansion to learn more about the
uniform()
function. Thanks again for creating this issue,Best regards,
Klaus!
-
reporter Ok, I see. It is a bit counter-intuitive that a zero vector is considered sparse while a general uniform vector isn’t (although I understand the logic). Maybe you could mention this on the page about Vector Types (although I now see where this is stated in the wiki
).
Anyway, thx for clearing things up.
-
You are correct, the wiki is not complete in this sense. I apologize for this and promise that the wiki page for the Vector Types and the wiki page for the Matrix Types will be updated to clearly distinguish between dense and sparse data structures. And you are also correct that it is desirable to be able to use zero vectors in the
min()
andmax()
functions (from a readability point of view alone). We will consider the necessary changes for Blaze 3.7. Thanks again! -
Hi Anton!
With the last push it is now possible to use the
min()
andmax()
function with a dense vector or matrix and a scalar:blaze::StaticVector<int,4UL,rowVector> a{ -5, 2, 7, -4 }; min( a, 0 ); // Results in ( -5, 0, 0, -4 ) min( 0, a ); // Results in ( -5, 0, 0, -4 ) max( a, 0 ); // Results in ( 0, 2, 7, 0 ) max( 0, a ); // Results in ( 0, 2, 7, 0 )
Additionally, the tutorial has been updated accordingly. The wiki will be updated with the release of Blaze 3.7. Hopefully this is to your liking and you agree that this is even more convenient and easier to use.
Best regards,
Klaus!
- Log in to comment