Does there exist information relating to Eigen::Matrix<> constexpr constructor?
Asked Answered
C

1

7

I would like to know if it is possible to automatically construct/initialize at compilation a static const Eigen::Matrix ? I guess this mandatorily requires a constexpr CTOR for all Eigen::Matrix types, among other things. However, I found in the Eigen3 doxy no information about any constexpr methods.

Can anybody quote or answer these statement/question ?

Catabolite answered 4/3, 2018 at 14:48 Comment(0)
C
7

Currently, there are no constexpr constructors/methods in Eigen. And implementing this would be very complicated (for any non-trivial methods), e.g., because SIMD functions are not constexpr.

You can of course initialize static const Eigen types, e.g., using assignment:

using namespace Eigen;
static const Matrix2d A0 = Matrix2d::Identity();
static const Matrix2d A1 = (Matrix2d() << 1,2,3,4).finished();
static const Matrix2d A2 = [](){ /* some complicated function */
                                 return A0 + A1;
                           }();

If you compile expressions like these with optimization, the compiler often will already evaluate these at compile-time (depends on how complicated your calculations are).

Cartwright answered 13/3, 2018 at 8:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.