4 ms·
While 'Derived::Scalar' could very well be replaced by 'double' in that case, you need the templated function to catch the temporary type (expression template)
by pbsd 14y ago
While 'Derived::Scalar' could very well be replaced by 'double' in that case, you need the templated function to catch the temporary type (expression template) that represents the u-v computation. This lets Eigen compute u[i]-v[i] and the dot product inside the same inner loop.
Without the templated function, the compiler would first generate the subtraction into a temporary vector, and then compute the dot product on that vector.
- kevingadd 14y agoThat makes sense, thanks! I figured the template was being used to magically substitute some sort of meta-type or container for temporaries.