![]() Registered Member ![]()
|
Very short question ^^
I wonder how much runtime overhead is incurred in topLeftCorner(6,2) instead of topLeftCorner<6,2>()? In particular, are there any dynamic memory allocations involved ? Thanks in advance. |
![]() Registered Member ![]()
|
This depends on the context. Like many functions, topLeftCorner returns a proxy object, and the actual work is done when you do something with that proxy object (e.g., assign to a matrix, add to another matrix, multiply with another matrix). The difference is that topLeftCorner<6,2>() returns something that acts like a static-size matrix and topLeftCorner(6,2) returns something that acts like a dynamic-size matrix. Loops may be unrolled when using static-size matrices, so you can some on loop overhead. If a temporary static-size matrix is created, then that does not cause a memory allocation, while temporary dynamic-size matrices do cause a memory allocation. But it is hard to give a definite answer; if it is important to you then you need to do some profiling yourself.
For example: MatrixXd A = MatrixXd::Random(100,100); Matrix<double,6,2> staticMatrix; MatrixXd dynamicMatrix; // Assignment staticMatrix = A.topLeftCorner<6,2>(); // no memory allocation dynamicMatrix = A.topLeftCorner(6,2); // dynamicMatrix has to be resized, so this will cause a memory allocation (if dynamicMatrix had the right size this would not cause a memory allocation). // Addition staticMatrix += A.topLeftCorner<6,2>(); // no memory allocation dynamicMatrix += A.topLeftCorner(6,2); // no memory allocation // Matrix mulitplication statiocMatrix = staticMatrix * A.topLeftCorner<6,2>(); // no memory allocation dynamicMatrix = dynamicMatrix * A.topLeftCorner(6,2); // I don't know; Eigen usually evaluates matrices that appear in a product into a temporary object, which would cause a memory allocation, but I am not sure that Eigen would use a temporary object in this case. |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]