Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

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.



view as:

That makes sense, thanks! I figured the template was being used to magically substitute some sort of meta-type or container for temporaries.

Legal | privacy