Callable object computing the inner product (i.e. sum of products).
Computes the generalized sum of products of the elements of two product types. By default, + and * are used.
On record types, operates by pair of fields sharing the same label.
- Note
- Does not participate in overload resolution if product types' size are not equal or if any of the binary operations can't be applied on the product types' elements. Similarly, doesn't participate in overload resolution if the two inputs are not compatible.
- See also
- concepts::compatible_product_types.
#include <kumi/algorithm/inner_product.hpp>
template<product_type S1, product_type S2, typename T, typename Sum, typename Prod>
constexpr sum_t sum
Callable object computing the sum of all elements.
Definition reduce.hpp:384
constexpr prod_t prod
Callable object computing the product of all elements.
Definition reduce.hpp:453
constexpr inner_product_t inner_product
Callable object computing the inner product (i.e. sum of products).
Definition inner_product.hpp:136
template<product_type S1, product_type S2, typename T>
constexpr auto inner_product(S1 && s1, S2 && s2, T init)
noexcept;
- s1: First product type to operate on
- s2: Second product type to operate on
- init: Initial value
- sum: Binary callable function to use as the sum operations
- prod: Binary callable function to use as the product operations
- The inner product of s1 and s2 using the provided binary operations.
template<kumi::concepts::product_type S1,
kumi::concepts::sized_product_type<kumi::size_v<S1>> S2,
typename T,
typename... Operators>
requires((sizeof...(Operators) == 0) || (sizeof...(Operators) == 2))
std::declval<S1>(), std::declval<S2>(), std::declval<T>(), std::declval<Operators>()...));
template<kumi::concepts::product_type S1,
kumi::concepts::sized_product_type<kumi::size_v<S1>> S2,
typename T,
typename... Operators>
requires((sizeof...(Operators) == 0) || (sizeof...(Operators) == 2))
struct inner_product
{
using type = kumi::result::inner_product_t<S1, S2, T, Operators...>;
};
Computes the return type of a call to kumi::inner_product
- Tuple
#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
std::cout << 0b101001L << "\n";
}
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:35
- Record
#include <kumi/kumi.hpp>
#include <iostream>
#include <vector>
int main()
{
using namespace kumi::literals;
auto bits =
kumi::record{
"a"_id = 1,
"b"_id = 0,
"c"_id = 1,
"d"_id = 0,
"e"_id = 0,
"f"_id = 1};
auto base =
kumi::record{
"f"_id = 32,
"e"_id = 16,
"d"_id = 8,
"c"_id = 4,
"b"_id = 2,
"a"_id = 1};
std::cout << 0b101001L << "\n";
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36