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

crash #126

Open
taiwuchiang opened this issue Oct 19, 2017 · 6 comments
Open

crash #126

taiwuchiang opened this issue Oct 19, 2017 · 6 comments

Comments

@taiwuchiang
Copy link
Collaborator

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
load_entry_point('matlab2cpp==2.0.1', 'console_scripts', 'm2cpp')()
File "/Library/Python/2.7/site-packages/matlab2cpp-2.0.1-py2.7.egg/matlab2cpp/init.py", line 62, in m2cpp
execute_parser(args)
File "/Library/Python/2.7/site-packages/matlab2cpp-2.0.1-py2.7.egg/matlab2cpp/frontend.py", line 180, in execute_parser
builder.project.translate(args)
File "/Library/Python/2.7/site-packages/matlab2cpp-2.0.1-py2.7.egg/matlab2cpp/node/frontend.py", line 190, in translate
backend.translate(self, opt)
File "/Library/Python/2.7/site-packages/matlab2cpp-2.0.1-py2.7.egg/matlab2cpp/node/backend.py", line 481, in translate
map(translate, node)
File "/Library/Python/2.7/site-packages/matlab2cpp-2.0.1-py2.7.egg/matlab2cpp/node/backend.py", line 495, in translate
translate_one(node, opt)
File "/Library/Python/2.7/site-packages/matlab2cpp-2.0.1-py2.7.egg/matlab2cpp/node/backend.py", line 565, in translate_one
value = value(node)
File "/Library/Python/2.7/site-packages/matlab2cpp-2.0.1-py2.7.egg/matlab2cpp/rules/mat.py", line 198, in Set
index = node[0].str.index('(')
ValueError: substring not found

@taiwuchiang
Copy link
Collaborator Author

I used your /dev branch. But I have seen it and the previous bug #125 when using the master branch.

@taiwuchiang
Copy link
Collaborator Author

taiwuchiang commented Oct 19, 2017

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(9, 21);
double __aux_rowvec_1[] = { 1, 5, 9 };
_aux_rowvec_1 = rowvec(__aux_rowvec_1, 3, false);
dRdm1.row(arma::strans(_aux_rowvec_1) - 1).cols(0) = arma::ones(3);
return 0;
}

Try to change TYPE to mat:

int main(int argc, char** argv)
{
mat dRdm1;
rowvec _aux_rowvec_1;
dRdm1 = arma::zeros(9, 21);
double __aux_rowvec_1[] = { 1, 5, 9 };
_aux_rowvec_1 = rowvec(__aux_rowvec_1, 3, false);
dRdm1.row(arma::strans(_aux_rowvec_1) - 1).cols(0) = arma::ones(3);
return 0;
}

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 arma::Mat::row(const arma::uword) const': cannot convert argument 1 from 'const arma::eOp<arma::Op<arma::Row,arma::op_htrans>,arma::eop_scalar_minus_post>' to 'const arma::uword'
1> with
1> [
1> eT=double
1> ]
1>......\samples\cpp\tutorial_code\ImgTrans\test.m.cpp(14): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>......\samples\cpp\tutorial_code\ImgTrans\test.m.cpp(14): error C2228: left of '.cols' must have class/struct/union
1>Done building project "tutorial_CannyDetector_Demo.vcxproj" -- FAILED.

@taiwuchiang
Copy link
Collaborator Author

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(9, 21);
uword __aux_rowvec_1[] = { 1, 5, 9 };
_aux_uvec_1 = uvec(__aux_rowvec_1, 3, false);
dRdm1(_aux_uvec_1 - 1, urowvec({ 1-1 })) = arma::ones(3);

return 0;

}

@taiwuchiang
Copy link
Collaborator Author

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);

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

two issues here:

  1. the generated code line dRdm1(arma::strans(_aux_urowvec_1) - 1, 0 ) should be
    dRdm1(arma::strans(_aux_urowvec_1) - 1, urowvec({ 0 }))

  2. 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.

@taiwuchiang
Copy link
Collaborator Author

well, if transpose column vector to row vector doesn't require data movement, then please ignore the second request. Thanks.

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