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

Using GSL and other Libraries with Eigen

Tags: None
(comma "," separated)
Brett
Registered Member
Posts
4
Karma
0
I am using the minimization routines in the GSL like BFGS and the library makes callbacks to functions passing them a gsl_vector*. These do not necessarily represent contiguous blocks of memory and thus I don't know how to Map an Eigen matrix on top of them. Is there a way to make an Eigen matrix out of something that simply supports some set of needed operators, like operator[], size(), etc? That way I could wrap gsl_vector* with a C++ class and pass that to Eigen. If not, any suggestions on how to use the GSL with Eigen in these sorts of cases?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You can use a Map with an OuterStride (for matrices), or an InnerStride for vectors with increment != 1, some examples there:

http://eigen.tuxfamily.org/dox/classEigen_1_1Map.html
Brett
Registered Member
Posts
4
Karma
0
ggael wrote:You can use a Map with an OuterStride (for matrices), or an InnerStride for vectors with increment != 1, some examples there:

http://eigen.tuxfamily.org/dox/classEigen_1_1Map.html


With a gsl_vector I may not have access to knowing what strides to use. Is there a way I could have a matrix that had some alternative storage method. Suppose I did something silly like storing my matrices in a std::map with keys that are pair<int,int>. Is there a way I could get Eigen to use this storage as the matrix data and wrap it so I could leverage the algorithms and other code expecting a MatrixBase<T>.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
To this end you would have to write a matrix expression (i.e., a class inheriting MatrixBase<YourClass> and implementing cols(), rows(), coeff(), coeffRef() with internal::traits<YourClass> properly defined). However don't expect good performance if the storage is too fancy.
Brett
Registered Member
Posts
4
Karma
0
ggael wrote:To this end you would have to write a matrix expression (i.e., a class inheriting MatrixBase<YourClass> and implementing cols(), rows(), coeff(), coeffRef() with internal::traits<YourClass> properly defined). However don't expect good performance if the storage is too fancy.


Is there a place where I can see how to properly define internal::traits<MyClass>?


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]