[eigen] (Const)FixedSegmentReturnType with Compile-time known offset

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

Hello all,

not sure whether this is of general interest (and whether it is worthwhile pursuing at all).

I built a NamedVector on top of fixed size Eigen vectors. This class has a method which translates
names (which are represented by types) to compile-time known indices

// pseudo-code, the real lookup produces the index differently
template<class Arg>
T &operator[](const Arg &arg)
   return _eigenVec[Arg::Index];

so I can do something like
namedVec[Pressure] = 0.5;

Then, I did the same for tuples of names (types)

  template<typename FirstIndexType, typename ...MoreIndexTypes>
  decltype(std::declval<BaseVector>().template segment<1+sizeof...(MoreIndexTypes)>(0u))
    operator[](const std::tuple<FirstIndexType, MoreIndexTypes ...> &i)
    constexpr auto firstIndex = TH::FirstIndexOfKeyInTuple<FirstIndexType, FormatT>::value;
      std::tuple<FirstIndexType, MoreIndexTypes ...>,
      TH::TupleNElementsAtOffset<1+sizeof...(MoreIndexTypes), firstIndex, FormatT>
      >::value, "Cannot access non-contiguous values as sub-vector!");
    return BaseVector::template segment<1+sizeof...(MoreIndexTypes)>(firstIndex);

which returns a FixedSegmentReturnType<N>.

Now I can do something like
// MomentumVector is an instance of std::tuple<MomentumX, MomentumY, MomentumZ>
namedVec[MomentumVector] = Vector3d::Zero(); 
which is sort of nifty.

But in my case, even the offset could be a template parameter of FixedSegmentReturnType.
Would this be worthwhile pursuing in your opinion?
Some testing shows that replacing the explicit references to MomentumX with the vector
variant can sometimes lead to slower code (or at least hit inlining limits earlier).

Best regards

Daniel Vollmer

Deutsches Zentrum für Luft- und Raumfahrt e.V. (DLR)
German Aerospace Center
Institute of Aerodynamics and Flow Technology | Lilienthalplatz 7 | 38108 Braunschweig | Germany

Daniel Vollmer | AS C²A²S²E

Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/