TiledArray  0.7.0
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 = decltype(dot(std::declval<Left>(),
43  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 { return result; }
54 
55  // Reduce two result objects
56  void operator()(result_type& result, const result_type& arg) const {
57  result += arg;
58  }
59 
60  // Reduce an argument pair
61  void operator()(result_type& result, const first_argument_type& left,
62  const second_argument_type& right) const {
63  using TiledArray::dot;
64  result += dot(left, right);
65  }
66 
67  }; // class DotReduction
68 
70 
74  template <typename Left, typename Right>
76  public:
77  // typedefs
78  using result_type = decltype(inner_product(std::declval<Left>(),
79  std::declval<Right>()));
80  typedef Left first_argument_type;
81  typedef Right second_argument_type;
82 
83  // Reduction functions
84 
85  // Make an empty result object
86  result_type operator()() const { return result_type(0); }
87 
88  // Post process the result
89  const result_type& operator()(const result_type& result) const { return result; }
90 
91  // Reduce two result objects
92  void operator()(result_type& result, const result_type& arg) const {
93  result += arg;
94  }
95 
96  // Reduce an argument pair
97  void operator()(result_type& result, const first_argument_type& left,
98  const second_argument_type& right) const {
100  result += inner_product(left, right);
101  }
102 
103  }; // class InnerProductReduction
104 
105 } // namespace TiledArray
106 
107 #endif // TILEDARRAY_TILE_OP_BINARY_REDUCTION_H__INCLUDED
void operator()(result_type &result, const result_type &arg) const
const result_type & operator()(const result_type &result) const
Vector inner product tile reduction.
result_type operator()() const
decltype(inner_product(std::declval< Left >(), std::declval< Right >())) result_type
Vector dot product tile reduction.
TiledArray::expressions::ExprTrait< Left >::scalar_type dot(const TiledArray::expressions::Expr< Left > &a1, const TiledArray::expressions::Expr< Right > &a2)
Definition: utils.h:96
void operator()(result_type &result, const first_argument_type &left, const second_argument_type &right) const
void operator()(result_type &result, const first_argument_type &left, const second_argument_type &right) const
const result_type & operator()(const result_type &result) const
decltype(dot(std::declval< Left >(), std::declval< Right >())) result_type
auto inner_product(const Left &left, const Right &right)
Vector inner product of two tiles.
void operator()(result_type &result, const result_type &arg) const