Thrill  0.1
sum.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * thrill/api/sum.hpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2016 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
9  ******************************************************************************/
10 
11 #pragma once
12 #ifndef THRILL_API_SUM_HEADER
13 #define THRILL_API_SUM_HEADER
14 
17 
18 namespace thrill {
19 namespace api {
20 
21 template <typename ValueType, typename Stack>
22 template <typename SumFunction>
23 ValueType DIA<ValueType, Stack>::Sum(const SumFunction& sum_function) const {
24  assert(IsValid());
25 
27 
28  static_assert(
29  std::is_convertible<
30  ValueType,
32  "SumFunction has the wrong input type");
33 
34  static_assert(
35  std::is_convertible<
36  ValueType,
38  "SumFunction has the wrong input type");
39 
40  static_assert(
41  std::is_convertible<
43  ValueType>::value,
44  "SumFunction has the wrong input type");
45 
46  auto node = tlx::make_counting<SumNode>(
47  *this, "Sum", ValueType(), /* with_initial_value */ false,
48  sum_function);
49 
50  node->RunScope();
51 
52  return node->result();
53 }
54 
55 template <typename ValueType, typename Stack>
56 template <typename SumFunction>
58  const SumFunction& sum_function, const ValueType& initial_value) const {
59  assert(IsValid());
60 
62 
63  static_assert(
64  std::is_convertible<
65  ValueType,
67  "SumFunction has the wrong input type");
68 
69  static_assert(
70  std::is_convertible<
71  ValueType,
73  "SumFunction has the wrong input type");
74 
75  static_assert(
76  std::is_convertible<
78  ValueType>::value,
79  "SumFunction has the wrong input type");
80 
81  auto node = tlx::make_counting<SumNode>(
82  *this, "Sum", initial_value, /* with_initial_value */ true,
83  sum_function);
84 
85  node->RunScope();
86 
87  return node->result();
88 }
89 
90 template <typename ValueType, typename Stack>
91 template <typename SumFunction>
93  const SumFunction& sum_function, const ValueType& initial_value) const {
94  assert(IsValid());
95 
97 
98  static_assert(
99  std::is_convertible<
100  ValueType,
101  typename FunctionTraits<SumFunction>::template arg<0> >::value,
102  "SumFunction has the wrong input type");
103 
104  static_assert(
105  std::is_convertible<
106  ValueType,
107  typename FunctionTraits<SumFunction>::template arg<1> >::value,
108  "SumFunction has the wrong input type");
109 
110  static_assert(
111  std::is_convertible<
113  ValueType>::value,
114  "SumFunction has the wrong input type");
115 
116  auto node = tlx::make_counting<SumNode>(
117  *this, "Sum", initial_value, /* with_initial_value */ true,
118  sum_function);
119 
120  return Future<ValueType>(node);
121 }
122 
123 } // namespace api
124 } // namespace thrill
125 
126 #endif // !THRILL_API_SUM_HEADER
127 
128 /******************************************************************************/
int value
Definition: gen_data.py:41
common::FunctionTraits< Function > FunctionTraits
alias for convenience.
Definition: dia.hpp:147
The return type class for all ActionFutures.
Definition: action_node.hpp:83
Future< ValueType > SumFuture(const SumFunction &sum_function=SumFunction(), const ValueType &initial_value=ValueType()) const
Sum is an ActionFuture, which computes the sum of all elements globally.
Definition: sum.hpp:92
ValueType Sum(const SumFunction &sum_function=SumFunction()) const
Sum is an Action, which computes the sum of all elements globally.
Definition: sum.hpp:23