tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
inner_product.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2#ifndef TETL_NUMERIC_INNER_PRODUCT_HPP
3#define TETL_NUMERIC_INNER_PRODUCT_HPP
4
6
7namespace etl {
8
13template <typename InputIt1, typename InputIt2, typename T>
14[[nodiscard]] constexpr auto inner_product(InputIt1 first1, InputIt1 last1, InputIt2 first2, T init) -> T
15{
16 for (; first1 != last1; ++first1, ++first2) {
17 init = etl::move(init) + *first1 * *first2;
18 }
19 return init;
20}
21
23template <typename InputIt1, typename InputIt2, typename T, typename BinaryOperation1, typename BinaryOperation2>
24[[nodiscard]] constexpr auto
25inner_product(InputIt1 first1, InputIt1 last1, InputIt2 first2, T init, BinaryOperation1 op1, BinaryOperation2 op2) -> T
26{
27 for (; first1 != last1; ++first1, ++first2) {
28 init = op1(etl::move(init), op2(*first1, *first2));
29 }
30 return init;
31}
32
33} // namespace etl
34
35#endif // TETL_NUMERIC_INNER_PRODUCT_HPP
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
constexpr auto inner_product(InputIt1 first1, InputIt1 last1, InputIt2 first2, T init) -> T
Computes inner product (i.e. sum of products) or performs ordered map/reduce operation on the range [...
Definition inner_product.hpp:14
Definition adjacent_find.hpp:8