Registered Member
|
Dear All,
Is it possible to sort the values in VectorXd? (I didn't find any sort() method) If not, then is it possible to use VectorXd as an STL container to use STL sort() ? |
Moderator
|
no, and yes:
std::sort(v.data(), v.data()+v.size()); |
Registered Member
|
Hi,
I would like to write a function to sort an Eigen::MatrixBase<Derived>. Something like:
but of course this is not working, because "data" is defined in Matrix and not MatrixBase (I guess). Is there a way to get around this? This is probably a very basic question but I'm just starting to get into Eigen internal mechanisms . Thanks for your help! |
Registered Member
|
When you have a MatrixBase object x, you can get the "derived" object as:
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
|
|
Registered Member
|
I actually have another question. Could you please post the "EIGEN_MATRIXBASE_PLUGIN" version of this simple function?
I would like to use your example as a template to modify many functions that I have written. This would also be useful in order to combine the "sort" function with colwise() and rowwise(). Thanks for your quick replies! |
Registered Member
|
What you're asking for is exactly to see the implementation of derived(). It is implemented inline inside the MatrixBase class definition: open Eigen/src/Core/MatrixBase.h and search for derived(). Also search for EIGEN_MATRIXBASE_PLUGIN, you'll see what this macro does: just add stuff inside MatrixBase!
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
|
oh.
You meant the sort() function? sorry. Here your go:
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
|
I see, now I understand how to modify MatrixBase using EIGEN_MATRIXBASE_PLUGIN.
Just for the record I'm going to write down what I did:
One things is not clear to me now: what if I would like to use sort with rowwise()/colwise()? Thanks again. |
Registered Member
|
Strange, i dont understand what's going on. It seems that this should work.
these functions return an object of type PartialRedux. See Eigen/src/Array/PartialRedux.h. (in the development branch it's renamed to VectorwiseOp). Unfortunately this class doesnt have a PLUGIN macro. You'll have to edit this file manually. If you want we can add a plugin macro in the next minor release. Then open a feature request on the issue tracker.
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
|
Hi,
1- I actually edited my previous post because in the meanwhile I solved the problem (I had two files with the same name) 2- ok, I will open a feature request. Thank you. |
Registered Member
|
Hi, I'm want to sort the Eigen:: VectorXf using std:: sort , and I use your method "std::sort(v.data(), v.data()+v.size());", but I failed .
error is reference to non-static member function must be called std::sort(temp.data(),temp.data() + temp.size(),Compare); How i get it work? Thank you |
Registered Member
|
I guess this means that Compare is a non-static member function. As the error message says, you cannot pass such a function as an argument. Perhaps you can convert it to a static function, or a function outside the class. I think that this has nothing to do with Eigen, this is just how C++ works. |
Registered Member
|
I put the compare function outside the class, and it works . Thank you! |
Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]