matlab2cpp
matlab2cpp copied to clipboard
crash
Matlab:
dRdm1 = zeros(9,21); dRdm1([1 5 9],1) = ones(3,1);
Errors:
Traceback (most recent call last):
File "/usr/local/bin/m2cpp", line 9, in
I used your /dev branch. But I have seen it and the previous bug #125 when using the master branch.
Oh, this crash only happens when I set "dRdm1" : "mat", # mat in the test.m.py file
If leave it blank, like "dRdm1" : "", # mat then it won't crash.
However, the generated code will compile with errors.
Generated code:
int main(int argc, char** argv)
{
TYPE dRdm1;
rowvec _aux_rowvec_1;
dRdm1 = arma::zeros
Try to change TYPE to mat:
int main(int argc, char** argv)
{
mat dRdm1;
rowvec _aux_rowvec_1;
dRdm1 = arma::zeros
Get the following compiler errors:
1>test.m.cpp
1>......\samples\cpp\tutorial_code\ImgTrans\test.m.cpp(14): error C2664: 'const arma::subview_row<eT> arma::Mat<eT>::row(const arma::uword) const': cannot convert argument 1 from 'const arma::eOp<arma::Op<arma::Row
Manually to fix the compile error and get the following correct C++ code:
int main(int argc, char** argv)
{
mat dRdm1;
uvec _aux_uvec_1;
dRdm1 = arma::zeros
return 0;
}
I am using Armadillo v8. So there may be new syntax for doing subview and it's actually simpler.
For example, mat M; uvec a; urowvec b; // initialize M, a, b ... // then subview of M can be M(a, b);
two issues here:
-
the generated code line dRdm1(arma::strans(_aux_urowvec_1) - 1, 0 ) should be dRdm1(arma::strans(_aux_urowvec_1) - 1, urowvec({ 0 }))
-
if it's possible to declare the aux variable as 'vec' rather than 'rowvec' and the transpose to 'vec'? Usually Armadillo uses column vector for 1st argument indexing, row vector for second argument indexing. Will this provide a clue for the converter? Thanks.
well, if transpose column vector to row vector doesn't require data movement, then please ignore the second request. Thanks.