Summary: | Generic assignement mechanism | ||
---|---|---|---|
Product: | Eigen | Reporter: | Gael Guennebaud <gael.guennebaud> |
Component: | Core - general | Assignee: | Nobody <eigen.nobody> |
Status: | RESOLVED FIXED | ||
Severity: | enhancement | CC: | gael.guennebaud, jacob.benoit.1 |
Priority: | --- | ||
Version: | 3.0 | ||
Hardware: | All | ||
OS: | All | ||
Whiteboard: | |||
Bug Depends on: | |||
Bug Blocks: | 558, 984 |
Description
Gael Guennebaud
2010-11-08 12:59:48 UTC
Some updates on this entry. In the devel branch one can specialize internal::Assignment class for this purpose. Here is an example: class MyFancyExpression : EigenBase<MyFancyExpression>{ /* ... */ }; struct MyFancy2Dense {}; template<> struct AssignmentKind<DenseShape,MyFancyShape> { typedef MyFancy2Dense Kind; }; template<typename DstXprType, typename Functor, typename Scalar> struct Assignment<DstXprType, MyFancyExpression, Functor, MyFancy2Dense, Scalar> { EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const Functor &func) { eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); // do something } }; It can be easily specialized for a given scalar type (via the Scalar template parameter) and assignment operators (via Functor for =, +=, /=, swap, etc.). One difficulty is that since it is a templated class, we cannot specialize for MatrixBase<Derived> as the source or destination types because Assignment will be instantiated with 'Derived'. This limitation is mitigated by the "AssignmentKind" that is extracted from the shapes of the source/destinations. But again, we need to specialize for an exact combination of shapes. Perhaps, it would be better to refactor this class to a function allowing for more flexibility? In this case, one could even build a hierarchy of assignment-kinds allowing to specialize at different levels? For instance, a generic fallback for MyFancy2EigenBase and a specialized version for MyFancy2Sparse. At this stage it is also not possible to distinguish between "array" and "matrix" worlds, but I don't think this is necessary. Alright, at this stage I consider the current mechanism as good enough, and using template functions will introduce other difficulties anyways. -- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/110. |