Does your own library assign matrix elements?

I came across the following assignment for a matrix in the Eigen Library here

Matrix3f m; m << 1, 2, 3, 4, 5, 6, 7, 8, 9; 

as an alternative method of drilling ( m(0,0) = 1; ... etc.). My question is any considerations, should I pay attention to using the first method? because I know that any simplifications come at cost.

0
c ++ variable-assignment matrix
May 24 '14 at 5:44
source share
1 answer

In the first case, m(0,0)=1 calls operator(Index, Index) and operator=(const Scalar& s) , which is probably pretty fast. While m << 1,2, ... calls the overloaded operator<< and the chain of the overloaded comma operator,(const Scalar& s) , see here the code: http://eigen.tuxfamily.org/dox/CommaInitializer_8h_source. html

I would suggest that the second initialization is a bit slower, but if you don't initialize huge matrices manually, this should not change. In any case, you cannot use comma initialization to initialize in a loop, so the comma form is used only for small matrices (where you can actually write elements manually).

+2
May 24 '14 at 7:54
source share



All Articles