This forum has been archived. All content is frozen. Please use KDE Discuss instead.

coefficient wise product - random crash

Tags: None
(comma "," separated)
dominiquegross
Registered Member
Posts
5
Karma
0
Hi everybody,

I'm currently debugging my mex file and i'm still facing an issue which is related with the coefficient wise product. As I am not completely comfortable with Eigen, I cannot find the solution. Here is my simplified function (it's a part of a Runge-Kutta algorithm) :

Code: Select all
VectorXd RK4(VectorXd X, struct matrices Par_mat, struct geometrie Par_geo)
{
   int N=Par_geo.Nutiles;
   VectorXd Deplacement(N);
   Deplacement<<X.segment(0,N);
   VectorXd test(N);

   test=Par_mat.Ouv.array()*(1/(Par_geo.heq+Deplacement.array())).array();
   return test;
}


Par_mat.Ouv is a structure variable of type MatrixXd (size (N x 1) ).
Par_geo.heq is a structure variable of type double.
Par_geo.Nutiles is a structure variable of type int.

I believe that the problem is due to the coefficient wise product. I do not understand the reason because both left and right hands are matrix when is use
Code: Select all
m.cwiseProduct(n)
or arrays (in the above example) when i use
Code: Select all
m.array()*n.array()
. There is maybe an issue about the
Code: Select all
double + VectoXd
operation since eigen told me that the type of this sum is 'Const'.

Moreover, the crash is not systematic. Sometimes the code works, and sometimes I have a popup window in Matlab ('Assertion failed ! Program: d:\...\eigen\CwiseBinaryOp.h Line:131 Expression : lhs.rows()==rhs.rows() && lhrs.cols()==rhs.cols()). I guess it is related to a problem of dimension but I checked all my variables and I still do not understand.


Thank you for your help I hope i'm near the end...
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
yes this means that Ouv and Deplacement do not have the same size. Two suggestions though: (unrelated to your issue)

- Ouv should be a VectorXf
- you can write your expression like this (simpler and better):
Code: Select all
test = Par_mat.Ouv.array() / (Deplacement.array() + Par_geo.heq);
dominiquegross
Registered Member
Posts
5
Karma
0
Yes it was a really sneaky problem of size....
It took two hours to find out the solution.

Thank you!


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]