No known expression from value to value&… Why?

后端 未结 3 561
长发绾君心
长发绾君心 2021-01-22 01:14

I have tried writing a function which takes a ColXpr value as input:

typedef Eigen::Array Signal2D;

vo         


        
3条回答
  •  时光说笑
    2021-01-22 01:52

    To add to the answer above:

    Eigen return expressions are temporaries. E.g. ColXpr is just a small copyable object that gives you access to the array data. It is returned by value, ColXpr col(...). You can capture the ColXpr temporary with const reference but not otherwise.

    However you can write:

    void Threshold(Matrix::ColXpr col);
    

    Generally, it is frowned upon to modify Eigen expression in functions. The preferred way is to write unary/binary functors/lambdas eg:

    array.col(i) = array.col(i).unaryExpr(
      [](const float &value) {
        return float(value >= 0); 
      }
    );
    

    Btw, if you intend to write generic Eigen functions, use Eigen::EigenBase as arguments to capture any eigen expression, see http://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html

    Boost serialization requires non-temporary reference as well, even the operand is being written to an archive.

提交回复
热议问题