Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
24  const SumFunction& sum_function, const ValueType& initial_value) const {
25  assert(IsValid());
26 
28 
29  static_assert(
30  std::is_convertible<
31  ValueType,
33  "SumFunction has the wrong input type");
34 
35  static_assert(
36  std::is_convertible<
37  ValueType,
39  "SumFunction has the wrong input type");
40 
41  static_assert(
42  std::is_convertible<
44  ValueType>::value,
45  "SumFunction has the wrong input type");
46 
47  auto node = tlx::make_counting<SumNode>(
48  *this, "Sum", initial_value, 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, sum_function);
83 
84  return Future<ValueType>(node);
85 }
86 
87 } // namespace api
88 } // namespace thrill
89 
90 #endif // !THRILL_API_SUM_HEADER
91 
92 /******************************************************************************/
ValueType_ ValueType
Definition: dia.hpp:152
ValueType Sum(const SumFunction &sum_function=SumFunction(), const ValueType &initial_value=ValueType()) const
Sum is an Action, which computes the sum of all elements globally.
Definition: sum.hpp:23
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:57