Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 492
picµ Avatar asked Aug 04 '26 00:08

picµ


1 Answers

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).

like image 72
chtz Avatar answered Aug 05 '26 14:08

chtz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!