From d26907c2201066bc261cb18e965e8cbce917e5f6 Mon Sep 17 00:00:00 2001 From: Ian Bell <ian.bell@nist.gov> Date: Thu, 1 Apr 2021 12:34:36 -0400 Subject: [PATCH] Sightly more efficient sumproduct I think Maybe a bug in Eigen that it can't figure out the type promotion --- include/teqp/models/pcsaft.hpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/teqp/models/pcsaft.hpp b/include/teqp/models/pcsaft.hpp index 3e0a4f1..bdb5ba4 100644 --- a/include/teqp/models/pcsaft.hpp +++ b/include/teqp/models/pcsaft.hpp @@ -150,11 +150,7 @@ Sum up the coefficient-wise product of three array-like objects that can each ha template<typename VecType1, typename VecType2, typename VecType3> auto sumproduct(const VecType1& v1, const VecType2& v2, const VecType3& v3) { using ResultType = decltype(forceeval(v1[0] * v2[0] * v3[0])); - ResultType summer = 0.0; - for (auto i = 0; i < v1.size(); ++i) { - summer = summer + v1[i] * v2[i] * v3[i]; - } - return summer; + return (v1.cast<ResultType>() * v2.cast<ResultType>() * v3.cast<ResultType>()).sum(); } /// Parameters for model evaluation -- GitLab