For Eigen vectors of a fixed size (eg Eigen::Vector3d, Eigen::Vector4f) there is the option to initialize the vector using the constructor as follows:
Eigen::Vector3d a(0.0, 1.0, 2.0);
However, Eigen also offers a way to use comma initialization of a general Eigen matrix that can be used in this case:
Eigen::Vector3d b;
b << 0.0, 1.0, 2.0;
Is one of the two methods preferable for speed or some other reasons? Or are they equal?
One advantage of the first version is that it will fail at compile time if you pass the wrong number of arguments, e.g. because you misstyped Vector2d as Vector3d.
Performance-wise, the compiler is able to optimize both the same. Checked it with GCC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With