jonathf/matlab2cpp

vectorise vs vectorize bug

taiwuchiang opened this issue · 1 comments

Matlab code:

a = rand(5,5);
b = sum(a(:));

Generated C++ code:
int main(int argc, char** argv)
{
double b ;
mat a ;
a = arma::randu(5, 5) ;
b = double(arma::as_scalar(arma::sum(arma:vectorize(a(span(0, a.n_rows-1)))))) ;
return 0 ;
}

Corrected C++ code:

int main(int argc, char** argv)
{
double b;
mat a;
a = arma::randu(5, 5);
b = double(arma::as_scalar(arma::sum(arma::vectorise(a))));
return 0;
}

There are 3 issues here:

  1. Armadillo uses 'vectorise' instead of 'vectorize' as the function name. I guess it's a typo but ...
  2. the generated code missed one column ':' after arma. It should be arma::vectorise().
  3. a(span(0, a.n_rows-1)) is not right since it's a mat. You can simply use a, doesn't need indexing. Like:
    arma::vectorise(a)

Thanks.

fixed in /dev2 branch.