kumi v3.1.0
Exquisite Epidote
 
Loading...
Searching...
No Matches

◆ inner_product()

template<product_type S1, sized_product_type< S1::size()> S2, typename T , typename Sum , typename Prod >
constexpr auto kumi::inner_product ( S1 const &  s1,
S2 const &  s2,
init,
Sum  sum,
Prod  prod 
)
constexprnoexcept

Computes inner product (i.e. sum of products)

Computes the generalized sum of products of the elements of two product types. By default, + and * is used.

Note
Does not participate in overload resolution if tuples' size are not equal or if any of the binary operations can't be applied on the tuples' elements.
Parameters
s1First tuple to operate on
s2Second tuple to operate on
initInitial value
sumBinary callable function to use as the sum operations
prodBinary callable function to use as the product operations
Returns
The inner product of s1 and s2 using the provided binary operations.

Helper type

namespace kumi::result
{
template<product_type S1, sized_product_type<S1::size()> S2, typename T>
struct inner_product;
template<product_type S1, sized_product_type<S1::size()> S2, typename T
, typename Sum, typename Prod
>
struct inner_product;
template<product_type S1, sized_product_type<S1::size()> S2, typename T>
using inner_product_t = typename inner_product<S1,S2,T>::type;
template< product_type S1, sized_product_type<S1::size()> S2, typename T
, typename Sum, typename Prod
>
using inner_product_t = typename inner_product<S1,S2,T,Sum,Prod>::type;
}
constexpr auto inner_product(S1 const &s1, S2 const &s2, T init, Sum sum, Prod prod) noexcept
Computes inner product (i.e. sum of products)
Definition: inner_product.hpp:85

Computes the return type of a call to kumi::map

Example

#include <kumi/tuple.hpp>
#include <iostream>
#include <vector>
int main()
{
auto bits = kumi::tuple{ 1, 0,1,0,0,1};
auto base = kumi::tuple{32,16,8,4,2,1};
std::cout << 0b101001L << "\n";
std::cout << kumi::inner_product(bits, base, 0) << "\n";
}
Fixed-size collection of heterogeneous values.
Definition: tuple.hpp:35