I am trying to write a new Eigen expression following the latest documentation https://eigen.tuxfamily.org/dox-devel/TopicNewExpressionType.html . Basically, what I want is part of a form-changing function that is still missing from Eigen. Thus chop_expr (expression for the vector) here must convert the input vector to the matrix n times.
Unfortunately, what I implemented does not work with expressions allocated on the heap, for example, the code below does not work, but after changing MAXV to 10 everything goes perfectly.
Another question about
enum {Flags = EvalBeforeNestingBit}
I found that I need it otherwise, when I interrupt matrix multiplication, Eigen does not create temporary numbers, but I assume that in this way I force chop_expr to create temporary numbers for any other expressions. So the question is, how should I do it right?
namespace Eigen { template <int chunk, typename Derived> struct ChoppedExpression; namespace internal { template <int chunk, typename Derived> struct traits<ChoppedExpression<chunk, Derived>> : traits<Derived> { enum {Flags = EvalBeforeNestingBit}; enum {IsRowMajor = 0}; enum { RowsAtCompileTime = chunk}; enum {MaxRowsAtCompileTime = chunk}; enum {ColsAtCompileTime = (Derived::RowsAtCompileTime == Eigen::Dynamic ? Eigen::Dynamic : Derived::RowsAtCompileTime / chunk)}; enum {MaxColsAtCompileTime = (Derived::MaxRowsAtCompileTime == Eigen::Dynamic ? Eigen::Dynamic : (Derived::MaxRowsAtCompileTime + chunk - 1) / chunk)}; }; }
Update
Finally, I found a way to make it work. The solution is to remove DerivedNested and DerivedNestedCleaned typedefs (I obviously don't need them in my expression, as it just rebuilds, but I can't explain why it is causing the wrong results). So, the only question remains, what should I do with EvalBeforeNestingBit?
source share