From 23fff4a65a187c4d8a70d074c5c8dce671ac6b52 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 4 Nov 2015 17:10:16 +1100 Subject: [PATCH] coord/ops: expand dot product to accept arrays --- coord/ops.hpp | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/coord/ops.hpp b/coord/ops.hpp index 5d8d5c55..a60c880b 100644 --- a/coord/ops.hpp +++ b/coord/ops.hpp @@ -285,6 +285,18 @@ namespace util { //------------------------------------------------------------------------- + template < + size_t S, + typename T + > + T dot (const T (&a)[S], const T (&b)[S]) + { + T sum = 0; + for (size_t i = 0; i < S; ++i) + sum += a[i] * b[i]; + return sum; + } + template < size_t S, typename T, @@ -293,12 +305,31 @@ namespace util { > T dot (A a, B b) { - T sum { 0 }; - for (size_t i = 0; i < S; ++i) - sum += a[i] * b[i]; - return sum; + return dot (a.data, b.data); } + + template < + size_t S, + typename T, + template class K + > + T dot (K a, const T (&b)[S]) + { + return dot (a.data, b); + } + + template < + size_t S, + typename T, + template class K + > + T dot (const T (&a)[S], K b) + { + return dot (a, b.data); + } + + //------------------------------------------------------------------------- template < size_t S,