8#include <dune/common/typeutilities.hh>
9#include <amdis/common/ForEach.hpp>
10#include <amdis/common/StaticSize.hpp>
31template <
class In1,
class In2,
class T,
class BinaryOp1,
class BinaryOp2>
32T innerProduct (In1
const& in1, In2
const& in2, T init, BinaryOp1 op1, BinaryOp2 op2)
34 return InnerProduct<In1>::impl(in1, in2, std::move(init), op1, op2);
48template <
class In1,
class In2,
class T>
49T innerProduct (In1
const& in1, In2
const& in2, T init)
51 return InnerProduct<In1>::impl(in1, in2, std::move(init), std::plus<>{}, std::multiplies<>{});
61 template <
class In1,
class In2,
class T,
class BinOp1,
class BinOp2,
62 class =
decltype(std::begin(std::declval<In1>())),
63 class =
decltype(std::end(std::declval<In1>())),
64 class =
decltype(std::begin(std::declval<In2>()))>
65 static T impl2 (Dune::PriorityTag<2>, In1
const& in1, In2
const& in2, T init,
66 BinOp1 op1, BinOp2 op2)
68 auto first1 = std::begin(in1);
69 auto first2 = std::begin(in2);
70 for (; first1 != std::end(in1); ++first1, ++first2)
71 init = Recursive::innerProduct(*first1, *first2, std::move(init), op1, op2);
76 template <
class In1,
class In2,
class T,
class BinOp1,
class BinOp2,
77 class =
decltype(std::declval<In1>()[std::integral_constant<std::size_t,0>{}])>
78 static T impl2 (Dune::PriorityTag<1>, In1
const& in1, In2
const& in2, T init,
79 BinOp1 op1, BinOp2 op2)
81 static_assert(static_size_v<In1> == static_size_v<In2>);
82 Ranges::forIndices<static_size_v<In1>>([&](
auto ii) {
83 init = Recursive::innerProduct(in1[ii], in2[ii], std::move(init), op1, op2);
89 template <
class In1,
class In2,
class T,
class BinOp1,
class BinOp2>
90 static T impl2 (Dune::PriorityTag<0>, In1
const& in1, In2
const& in2, T init,
91 BinOp1 op1, BinOp2 op2)
93 return op1(std::move(init), op2(in1, in2));
97 template <
class In1,
class In2,
class T,
class BinOp1,
class BinOp2>
98 static T impl (In1
const& in1, In2
const& in2, T init, BinOp1 op1, BinOp2 op2)
100 return impl2(Dune::PriorityTag<5>{}, in1, in2, init, op1, op2);
General implementation of recursive inner-product.
Definition: InnerProduct.hpp:58