Registered Member
|
Hi there,
I was wondering if there is a quick way to reproduce the Matlab/blitz++ function find() for vectors and matrixes. I wrote my own function but it looks a bit cumbersome. Any help is appreciated. Btw, Eigen is by far the best library I've ever used, thank you!
|
Moderator
|
hi,
I guess this function could fit in the Array module, find() being a member function of MatrixBase returning the coordinates, so that you would write: F = (A.cwise()>0.5).find(); Note that you can already do that using EIGEN_MATRIXBASE_PLUGIN (see http://eigen.tuxfamily.org/api/Customiz ... MatrixBase). At the same time this will remove the creation of an unnecessary temporary. Also it should return a Matrix<int,Dynamic,2> instead of a MatrixXi. If we include it in Eigen this way we'll add a convenient: typedef Matrix<int,Dynamic,2> MatricX2i; Another problem is that the boolean matrix is evaluated twice, so 2 options: - you return a std::vector<Vector2i> instead of a MatrixX2i and use std::vector::push(), - you wait we add a conservativeResize() function in Matrix which will preserve the data while resizing. Another option would be to allocate a big MatrixX2i of the same size than the input and return a VectorBlock expression of the meaningful part, but unfortunately this cannot be done easily because we cannot return an expression of a temporary object. |
Registered Member
|
Hi, I'm trying to use my find() functionality with EIGEN_MATRIXBASE_PLUGIN but I'm having a problem. The problem is with "cast" and, I suppose, M being template (?). I'm aware of the following topics:
viewtopic.php?f=74&t=62606&hilit=cast viewtopic.php?f=74&t=57882&hilit=cast but I think that doesn't apply to my case. I tried using the template keyword in many combinations but still receive ...
... at the "F.resize( (M.cast<int>()).sum() );" line. Can anybody please tell me what I'm doing wrong? The following is the function-form of the implementation that is giving me troubles.
Last edited by n2k on Thu Oct 22, 2009 8:20 pm, edited 1 time in total.
|
Registered Member
|
Have you tried:
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Well... I thought I did, but apparently I didn't
Now it's working, thank you! Btw, the correct line is: F.resize( (M.template cast<int>()).sum(), 2 ); otherwise the compiler says: YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX' is not a member of 'Eigen::ei_static_assert<false>' Can the "2" in M.resize(*,2) be understood from the definition of MatrixX2i? |
Registered Member
|
Ah, with the development branch you can do: resize(newsize, NoChange); not sure about the 2.0 branch.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]