mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-13 01:43:13 +08:00
Extended the reduction code so that reducing an empty set returns the neural element for the operation
This commit is contained in:
parent
1b0685d09a
commit
0d7a23d34e
@ -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; } };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user