Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vectorise vs vectorize bug #128

Closed
taiwuchiang opened this issue Oct 20, 2017 · 1 comment
Closed

vectorise vs vectorize bug #128

taiwuchiang opened this issue Oct 20, 2017 · 1 comment

Comments

@taiwuchiang
Copy link
Collaborator

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.

jonathf added a commit that referenced this issue Oct 21, 2017
jonathf added a commit that referenced this issue Oct 21, 2017
@taiwuchiang
Copy link
Collaborator Author

fixed in /dev2 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant