samedi 2 janvier 2016

invalid initialization of non-const reference of type from an rvalue of type for arma::subvec

The vector y_long_name has 100 members and I plan to manipulate only a subvector of it made of first three members. The subvector function is used in my code like a left value:

y_long_name.subvec(0,2)=A*x1;

However C++ does not recognize it as a left value. How can I define yr to be used instead of y_long_name.subvec(0,2)?

#include <iostream>
#include <armadillo>

int main()
{
    const arma::vec::fixed<3> x1={1.2,3.5,-0.27};   
    arma::mat::fixed<3,3> A={{5,3,6},{8,2,11},{7,5,9}};

    arma::vec::fixed<3> y1=A*x1; // ok

    arma::vec::fixed<100> y_long_name;
    y_long_name.subvec(0,2)=A*x1; // ok

    arma::vec::fixed<3>& yr=y_long_name.subvec(0,2)
    yr=A*x1;

    y_long_name.print();

    return 0;
}

Error:

test.cpp: In function ‘int main()’:
test.cpp:14:48: error: invalid initialization of non-const reference of type ‘arma::Col<double>::fixed<3ull>&’ from an rvalue of type ‘arma::subview_col<double>’
  arma::vec::fixed<3>& yr=y_long_name.subvec(0,2)

Aucun commentaire:

Enregistrer un commentaire