Registered Member
|
Hi everyone,
I'm currently discovering Eigen since I'm trying to convert a matlab script in mex file to spare calculation time. I'm not very used to code in c++ and i'm facing an issue which is, i'm sure, a piece of cake for you... I have a problem with one variable which make matlab crash without any error message. i guess it's a problem of type but i do not understand. Hetre is the function where the problem occurs :
The code crashes because of the
Same effect: Matlab crashed ! And for the moment i can't use a debbuging mode... I don't really know if i'm allowed to do this:
Are the coefficients of my matrix z0 really of type double ? However Visual c++ Express doesn't tell me it's wrong.... Thank you for your help and please excuse my english skills... |
Moderator
|
hm, I see that the matrix z0 is used without being initialized. You need to explicitly resize it before calling the .row(i) function. Also note that in c/c++ the first row has index 0 and the last one mat.rows()-1.
|
Registered Member
|
Yes you're right, there is a mistake about my indexation. I knew this point but old habits are persistent... Thank you.
Is this really mandatory to initialize the size of a matrix ? Because in my while loop its size changes with the index (the "in" variable changes in each iteration and i have something like "f0.row(in)=...." in my loop... Maybe i could find a better way to code this part but for the moment i just have time to translate this matlab function in mex file. I can't spend time to improve the code... However matlab really crashes because of the "ecart" variable. I know that i can't return its value without crash and the condition with this variable in my while loop causes crash. Could you please confirm that the coefficient of a Eigen Xd matrix (like RowVectorXd, MatrixXd, etc...) is a type double ? Can I use "double ecart = z0(i,j)" ? As I use a free version of Visual C++ Express, i can't import debugging information from the matlab "mex" function into Visual C++ Express... So I need to comment/Uncomment and rebuild continuously my program to find out the reason of the crash. It's not really easy and for the moment it's the reason why I can't solve this issue. Thank you for your precious help. |
Moderator
|
you really have to resize it before using it. What you are currently doing is like:
If you don't always see the crash that's probably because the compiler optimize the code away. Btw, I recommend you to first try your code without -DNDEBUG so that you get nice assertion on bad matrix usage. |
Registered Member
|
I checked my code and you were right I had a real problem of initialization. Everything works fine now and my coding speed increases cintinuously !
Thank you very much ! Just a last little question : is there a function to compute the sum in one dimension of a matrix ? Something like :
Thank you again. |
Moderator
|
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]