vectorise vs vectorize bug
taiwuchiang opened this issue · 1 comments
taiwuchiang commented
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:
- Armadillo uses 'vectorise' instead of 'vectorize' as the function name. I guess it's a typo but ...
- the generated code missed one column ':' after arma. It should be arma::vectorise().
- 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.
taiwuchiang commented
fixed in /dev2 branch.