Re: [eigen] Tensor Module: Index mapping support

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


Hello,

> In particular, it would make a lot of sense to be able to construct a tensor from an Eigen matrix.
> This means that in the case of the constructor, we should find a way to write
> EIGEN_SFINAE_ENABLE_IF(isCollectionOfIndices<CustomDimension>::value).
> I'll try to find a way to do this, but if you have a solution feel free to send another patch.

I have some recent personal experience with a FixedSizeVector<T, N> class based on
Eigen::Matrix, to which I added a templated constructor to initialize the vector with the
given values (as Eigen only accepts up to 4 values), which I want to relate..
This constructor essentially performs
  *this[0] = arg0;
  *this[1] = arg1;
  ...

In the case of a 1D vector, a choice between the "1 value" constructor and the "from
Eigen-expression" constructor needs to be made. My value constructor was always
the best match (as its argument are entirely unconstrained), but in the case
where *this[i] = arg (i.e. the assignment of one constructor argument) was not a
well-formed expression the instantiation would SFINAE-fail and the Eigen-expression
constructor would be attempted.

The real problem now occurred when we started using a
FixedVector<Eigen::Matrix<T, 3, 1>, 5>, i.e. the Scalar type is now an Eigen-expression
as well, and this is when things went awry, as now the one-scalar value assignment
operator of the inner type is attempted with an argument intended to be an Eigen-expression
for the complete FixedVector, which leads to a compile-time "incorrect dimensions" +
"incompatible scalar types" failures, instead of just silently attempting other instantiations.

A check for is_assignable<Scalar, ConstructorArg> is not enough to prevent this from
happening as that check doesn't instantiate templated assignment operators.... :(


In either case, I don't know whether this can happen with tensor-indices, but I ended up
explicitly tag dispatching to the value-constructor (required for size=1, optional for size>1)
to avoid the problem. The real problem may just be that one might want the — usually
helpful — checking expression-constructor or assignment operator to SFINAE-fail instead
of hard-fail on some occasions.


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/