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

MatrixBase<T> concept for user defined types?

Tags: None
(comma "," separated)
Tal
Registered Member
Posts
30
Karma
0
Can I inherit my own classes from MatrixBase<T> with stable concept? (i.e. stable, public requirements)

If yes, where can I find the concept details?
Is it a good idea in general?


User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Probably not a good idea as the evaluation mechanism of Eigen's expressions will change from 3.2 to 3.3. What was your motivation for doing so? Maybe there is a better alternative...
Tal
Registered Member
Posts
30
Karma
0
ggael wrote:Probably not a good idea as the evaluation mechanism of Eigen's expressions will change from 3.2 to 3.3. What was your motivation for doing so? Maybe there is a better alternative...


This is why: https://forum.kde.org/viewtopic.php?f=74&t=127454

I wanted that the user can make any type he wants to be an Eigne Matrix expression, without extra conversion/copy.

I ended up copy data and converting manually, but I think it could be a nice feature. (I know that making a stable template concept is hard)

So, do you think it's a good idea?


User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
oh, so you essentially wanted to write wrappers from non standard storage layout? Note that if the storage layer is such that the (i,j) can be accessed as:

*(base_ptr + i*row_stride + j*col_stride)

then you can use Map for that, no need to write a wrapper. If that's not the case, then the minimum to implement is something like:

Code: Select all
template<> Eigen::internal::traits<MyWrapper> {
 : public traits<Eigen::Matrix<list of options that are as close as possible to MyWrapper> >
  enum {
    Flags = 0 or RowMajorBit;
 };
};
class MyWrapper : public MatrixBase<MyWrapper> {
public:
  typedef MatrixBase<MyWrapper> Base;
  EIGEN_GENERIC_PUBLIC_INTERFACE(MyWrapper)
  Index rows() const;
  Index cols() const;
  Scalar coeff(i,j) const;
};


and of course, MyWrapper can be a template class too.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar