binary_reduction.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2014 Virginia Tech
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Justus Calvin
19  * Department of Chemistry, Virginia Tech
20  *
21  * binary_reduction.h
22  * Apr 2, 2014
23  *
24  */
25 
26 #ifndef TILEDARRAY_TILE_OP_BINARY_REDUCTION_H__INCLUDED
27 #define TILEDARRAY_TILE_OP_BINARY_REDUCTION_H__INCLUDED
28 
30 
31 namespace TiledArray {
32 
34 
38 template <typename Left, typename Right>
39 class DotReduction {
40  public:
41  // typedefs
42  using result_type =
43  decltype(dot(std::declval<Left>(), std::declval<Right>()));
44  typedef Left first_argument_type;
45  typedef Right second_argument_type;
46 
47  // Reduction functions
48 
49  // Make an empty result object
50  result_type operator()() const { return result_type(0); }
51 
52  // Post process the result
53  const result_type& operator()(const result_type& result) const {
54  return result;
55  }
56 
57  // Reduce two result objects
58  void operator()(result_type& result, const result_type& arg) const {
59  result += arg;
60  }
61 
62  // Reduce an argument pair
63  void operator()(result_type& result, const first_argument_type& left,
64  const second_argument_type& right) const {
65  using TiledArray::dot;
66  result += dot(left, right);
67  }
68 
69 }; // class DotReduction
70 
72 
76 template <typename Left, typename Right>
78  public:
79  // typedefs
80  using result_type =
81  decltype(inner_product(std::declval<Left>(), std::declval<Right>()));
82  typedef Left first_argument_type;
83  typedef Right second_argument_type;
84 
85  // Reduction functions
86 
87  // Make an empty result object
88  result_type operator()() const { return result_type(0); }
89 
90  // Post process the result
91  const result_type& operator()(const result_type& result) const {
92  return result;
93  }
94 
95  // Reduce two result objects
96  void operator()(result_type& result, const result_type& arg) const {
97  result += arg;
98  }
99 
100  // Reduce an argument pair
101  void operator()(result_type& result, const first_argument_type& left,
102  const second_argument_type& right) const {
104  result += inner_product(left, right);
105  }
106 
107 }; // class InnerProductReduction
108 
109 } // namespace TiledArray
110 
111 #endif // TILEDARRAY_TILE_OP_BINARY_REDUCTION_H__INCLUDED
void operator()(result_type &result, const result_type &arg) const
result_type operator()() const
Vector dot product tile reduction.
auto inner_product(const DistArray< Tile, Policy > &a, const DistArray< Tile, Policy > &b)
Definition: dist_array.h:1647
decltype(dot(std::declval< Left >(), std::declval< Right >())) result_type
void operator()(result_type &result, const first_argument_type &left, const second_argument_type &right) const
auto dot(const DistArray< Tile, Policy > &a, const DistArray< Tile, Policy > &b)
Definition: dist_array.h:1640
void operator()(result_type &result, const first_argument_type &left, const second_argument_type &right) const
decltype(inner_product(std::declval< Left >(), std::declval< Right >())) result_type
const result_type & operator()(const result_type &result) const
Vector inner product tile reduction.
void operator()(result_type &result, const result_type &arg) const
const result_type & operator()(const result_type &result) const