- changed status to wontfix
CustomVector assigment not working
Issue #393
wontfix
Hi!
Using Blaze I ran into this issue. The test1
function compiles fine while the test2
does not.
#include "blaze/Math.h"
using blaze::StaticVector;
using blaze::CustomVector;
using blaze::unaligned;
using blaze::unpadded;
using blaze::columnVector;
using bVector = CustomVector<float, unaligned, unpadded, columnVector>;
float test1() {
StaticVector<float, 5UL> blaze_v;
StaticVector<float, 5UL> difference = blaze_v - mean(blaze_v);
}
float test2() {
bVector blaze_v;
bVector difference = blaze_v - mean(blaze_v);
}
The compiler error is:
<source>: In function 'float test2()':
<source>:17:34: error: conversion from 'ReturnType {aka const blaze::DVecMapExpr<blaze::CustomVector<float, (blaze::AlignmentFlag)0, (blaze::PaddingFlag)0, false>, blaze::Bind2nd<blaze::Sub, float>, false>}' to non-scalar type 'bVector {aka blaze::CustomVector<float, (blaze::AlignmentFlag)0, (blaze::PaddingFlag)0, false>}' requested
bVector difference = blaze_v - mean(blaze_v);
~~~~~~~~^~~~~~~~~~~~~~~
StaticVector
assigment compiles fine while the CustomVector
does not. Is this expected behaviour?
Thanks in advance
Comments (2)
-
-
reporter Perfect! In insight it was a stupid question.
Thank you for the help. Everything is working flawlessly now. Sorry for the inconvenience.
Best regards
- Log in to comment
Hi Pedro!
Thanks for taking the time to report this potential defect. In this particular case it is a misunderstanding about what you can do with a
CustomVector
. Whereas aStaticVector
can be initialized by means of a scalar value (see here), aCustomVector
can only be created by means of associating it with an existing array (see here). Since aCustomVector
doesn't own the array, but only represents it as a Blaze vector, it cannot be initialized with the temporary result of an operation.What you can do to fix the
test2()
function is to evaluate the operation into a vector that holds the result:Since the size of the vector is not known at compile time, in this example
auto
will be deduced toDynamicVector
. See here for a detailed explanation of theevaluate()
operation.I hope this explains the problem. Thanks again,
Best regards,
Klaus!