CustomVector assigment not working

Issue #393 wontfix
Pedro Alves created an issue

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)

  1. Klaus Iglberger

    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 a StaticVector can be initialized by means of a scalar value (see here), a CustomVector can only be created by means of associating it with an existing array (see here). Since a CustomVector 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:

    void test2()
    {
       bVector blaze_v;
       const auto difference = evaluate( blaze_v - mean(blaze_v) );
    }
    

    Since the size of the vector is not known at compile time, in this example auto will be deduced to DynamicVector. See here for a detailed explanation of the evaluate() operation.

    I hope this explains the problem. Thanks again,

    Best regards,

    Klaus!

  2. Pedro Alves 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

  3. Log in to comment