Extended the reduction code so that reducing an empty set returns the neural element for the operation

This commit is contained in:
Benoit Steiner 2015-10-29 17:29:49 -07:00
parent 1b0685d09a
commit 0d7a23d34e

View File

@ -252,6 +252,13 @@ template<
typename... Ts typename... Ts
> struct reduce; > struct reduce;
template<
typename Reducer
> struct reduce<Reducer>
{
constexpr static inline int run() { return Reducer::Identity; }
};
template< template<
typename Reducer, typename Reducer,
typename A, typename A,
@ -275,8 +282,14 @@ template<
/* generic binary operations */ /* generic binary operations */
struct sum_op { template<typename A, typename B> constexpr static inline auto run(A a, B b) -> decltype(a + b) { return a + b; } }; struct sum_op {
struct product_op { template<typename A, typename B> constexpr static inline auto run(A a, B b) -> decltype(a * b) { return a * b; } }; template<typename A, typename B> constexpr static inline auto run(A a, B b) -> decltype(a + b) { return a + b; }
static constexpr int Identity = 0;
};
struct product_op {
template<typename A, typename B> constexpr static inline auto run(A a, B b) -> decltype(a * b) { return a * b; }
static constexpr int Identity = 1;
};
struct logical_and_op { template<typename A, typename B> constexpr static inline auto run(A a, B b) -> decltype(a && b) { return a && b; } }; struct logical_and_op { template<typename A, typename B> constexpr static inline auto run(A a, B b) -> decltype(a && b) { return a && b; } };
struct logical_or_op { template<typename A, typename B> constexpr static inline auto run(A a, B b) -> decltype(a || b) { return a || b; } }; struct logical_or_op { template<typename A, typename B> constexpr static inline auto run(A a, B b) -> decltype(a || b) { return a || b; } };