From a86d6237351f4890f72144bedc03a808e4008938 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 1 Apr 2024 21:23:08 -0600 Subject: [PATCH] Provide a default implementation for VectorizedArray::dot_product(). --- include/deal.II/base/vectorization.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/deal.II/base/vectorization.h b/include/deal.II/base/vectorization.h index 58ad2e09e7..9511a853a1 100644 --- a/include/deal.II/base/vectorization.h +++ b/include/deal.II/base/vectorization.h @@ -334,6 +334,25 @@ public: return VectorizedArrayIterator( static_cast(*this), width); } + + /** + * A default implementation for computing the dot product between two + * vectorized arrays. It first forms the lane-by-lane product between + * the current object and the argument, and then the across-lanes + * sum of the product. The function returns the kind of object that + * the VectorizedArray::sum() function returns. + * + * This function is inherited by all derived classes and provides + * the dot product to them unless they override it with their own + * implementation (presumably using a more efficient approach). + */ + auto + dot_product(const VectorizedArrayType &v) const + { + VectorizedArrayType p = static_cast(*this); + p *= v; + return p.sum(); + } }; -- 2.39.5