KUMI v5.0.0
Gorgeous Garnet
Loading...
Searching...
No Matches

Callable object computing the inner product (i.e. sum of products). More...

Variables

constexpr inner_product_t kumi::inner_product {}

Detailed Description

Callable object computing the inner product (i.e. sum of products).

Variable Documentation

◆ inner_product

inner_product_t kumi::inner_product {}
inlineconstexprnodiscardnoexcept

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.

Header file

#include <kumi/kumi.hpp>

Call Signature

namespace kumi
{
template<concepts::product_type S1, concepts::product_type S2, typename T, typename Sum, typename Prod>
constexpr auto inner_product(S1 && s1, S2 && s2, T init, Sum sum, Prod prod) noexcept;
template<concepts::product_type S1, concepts::product_type S2, typename T>
constexpr auto inner_product(S1 && s1, S2 && s2, T init) noexcept;
}
constexpr inner_product_t inner_product
Definition inner_product.hpp:140
constexpr prod_t prod
Definition reduce.hpp:449
constexpr sum_t sum
Definition reduce.hpp:376
Main KUMI namespace.
Definition algorithm.hpp:11

Parameters

  • 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

Return value

  • The inner product of s1 and s2 using the provided binary operations.

Helper type

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))
using inner_product_t = decltype(kumi::inner_product(
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

Examples

  • Tuple
    #include <kumi/kumi.hpp>
    #include <iostream>
    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
  • 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";
    std::cout << kumi::inner_product(bits, base, 0) << "\n";
    }
    Fixed-size collection of heterogeneous fields with distinct labels.
    Definition record.hpp:36