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

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


Hi Ilja,

> I recently published a paper where the same API is used for simulation
> development (dx.doi.org/10.5194/gmd-8-473-2015) so I'd say this is
> definitely worth pursuing :)

My question was mainly aimed at whether this may or may not improve
performance / make aliasing analysis for the compiler easier if FixedSegment
also could encode the offsets into the source vector / pointer.
Using a Map with a manually offset data() pointer seemed slower.

> But why use index calculations at all?
> Can't you just overload [] for each type to return the data
> corresponding to that type without needing any indices, as done in
> listing 1 in the above paper?

I did, but I am using an Eigen::Vector as underlying type (so subsequent
elements are contiguous, I can work with all of them as a vector, etc.), so for
normal (non-tuple, single-element) indexing, I'm relying on the compiler
optimizing (inlining) Eigen::Dense operator[](constant value).

> Does operator [] return a reference to the data or is that hidden
> elsewhere? I've been thinking about how to return a tuple of references
> to the partial contents of another tuple and the above looks interesting
> but it's not the same thing is it?

As all the elements I want to index into are contiguous, I'm returning
Eigen::Vector::template segment<1+sizeof...(MoreIndexTypes)>(compileTimeKnownFirstIndex)
so, for example if I ask for the MomentumVector I get something that is
compatible with a Eigen::Matrix<T, 3, 1>.

If you just want to work with tuples of single values C++11 std::tie works just fine
(but there all the elements are separate and cannot be treated as a vector-like type.


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
www.DLR.de


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