TiledArray  0.7.0
add_engine.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  * add_engine.h
22  * Mar 31, 2014
23  *
24  */
25 
26 #ifndef TILEDARRAY_EXPRESSIONS_ADD_ENGINE_H__INCLUDED
27 #define TILEDARRAY_EXPRESSIONS_ADD_ENGINE_H__INCLUDED
28 
30 #include <TiledArray/tile_op/add.h>
32 
33 namespace TiledArray {
34  namespace expressions {
35 
36  // Forward declarations
37  template <typename, typename> class AddExpr;
38  template <typename, typename, typename> class ScalAddExpr;
39  template <typename, typename, typename> class AddEngine;
40  template <typename, typename, typename, typename> class ScalAddEngine;
41 
42  template <typename Left, typename Right, typename Result>
43  struct EngineTrait<AddEngine<Left, Right, Result> > {
44  static_assert(std::is_same<typename EngineTrait<Left>::policy,
45  typename EngineTrait<Right>::policy>::value,
46  "The left- and right-hand expressions must use the same policy class");
47 
48  // Argument typedefs
49  typedef Left left_type;
50  typedef Right right_type;
51 
52  // Operational typedefs
59  typedef typename op_type::result_type
61  typedef typename eval_trait<value_type>::type
63  typedef typename Left::policy policy;
66 
67  // Meta data typedefs
68  typedef typename policy::size_type size_type;
69  typedef typename policy::trange_type trange_type;
70  typedef typename policy::shape_type shape_type;
71  typedef typename policy::pmap_interface
73 
74  static constexpr bool consumable = true;
75  static constexpr unsigned int leaves =
77  };
78 
79  template <typename Left, typename Right, typename Scalar, typename Result>
80  struct EngineTrait<ScalAddEngine<Left, Right, Scalar, Result> > {
81  static_assert(std::is_same<typename EngineTrait<Left>::policy,
82  typename EngineTrait<Right>::policy>::value,
83  "The left- and right-hand expressions must use the same policy class");
84 
85  // Argument typedefs
86  typedef Left left_type;
87  typedef Right right_type;
88 
89  // Operational typedefs
90  typedef Scalar scalar_type;
91  typedef TiledArray::detail::ScalAdd<Result,
98  typedef typename op_type::result_type
100  typedef typename eval_trait<value_type>::type
102  typedef typename Left::policy policy;
105 
106  // Meta data typedefs
107  typedef typename policy::size_type size_type;
108  typedef typename policy::trange_type trange_type;
109  typedef typename policy::shape_type shape_type;
110  typedef typename policy::pmap_interface
112 
113  static constexpr bool consumable = is_consumable_tile<eval_type>::value;
114  static constexpr unsigned int leaves =
116  };
117 
119 
123  template <typename Left, typename Right, typename Result>
124  class AddEngine : public BinaryEngine<AddEngine<Left, Right, Result> > {
125  public:
126  // Class hierarchy typedefs
130  typedef typename BinaryEngine_::ExprEngine_
132 
133  // Argument typedefs
134  typedef typename EngineTrait<AddEngine_>::left_type
136  typedef typename EngineTrait<AddEngine_>::right_type
138 
139  // Operational typedefs
140  typedef typename EngineTrait<AddEngine_>::value_type
144  typedef typename EngineTrait<AddEngine_>::op_type
146  typedef typename EngineTrait<AddEngine_>::policy
150 
151  // Meta data typedefs
152  typedef typename EngineTrait<AddEngine_>::size_type
154  typedef typename EngineTrait<AddEngine_>::trange_type
156  typedef typename EngineTrait<AddEngine_>::shape_type
160 
162 
166  template <typename L, typename R>
167  AddEngine(const AddExpr<L, R>& expr) : BinaryEngine_(expr) { }
168 
170 
173  return BinaryEngine_::left_.shape().add(BinaryEngine_::right_.shape());
174  }
175 
177 
181  return BinaryEngine_::left_.shape().add(BinaryEngine_::right_.shape(), perm);
182  }
183 
185 
187  static op_type make_tile_op() { return op_type(op_base_type()); }
188 
190 
194  return op_type(op_base_type(), perm);
195  }
196 
198 
200  const char* make_tag() const { return "[+] "; }
201 
202  }; // class AddEngine
203 
204 
206 
211  template <typename Left, typename Right, typename Scalar, typename Result>
212  class ScalAddEngine :
213  public BinaryEngine<ScalAddEngine<Left, Right, Scalar, Result> >
214  {
215  public:
216  // Class hierarchy typedefs
217  typedef ScalAddEngine<Left, Right, Scalar, Result>
223 
224  // Argument typedefs
229 
230  // Operational typedefs
237  typedef typename EngineTrait<ScalAddEngine_>::op_type
239  typedef typename EngineTrait<ScalAddEngine_>::policy
243 
244  // Meta data typedefs
253 
254  private:
255 
256  scalar_type factor_;
257 
258  public:
259 
261 
266  template <typename L, typename R, typename S>
268  BinaryEngine_(expr), factor_(expr.factor())
269  { }
270 
272 
275  return BinaryEngine_::left_.shape().add(BinaryEngine_::right_.shape(),
276  factor_);
277  }
278 
280 
284  return BinaryEngine_::left_.shape().add(BinaryEngine_::right_.shape(),
285  factor_, perm);
286  }
287 
289 
291  op_type make_tile_op() const { return op_type(op_base_type(factor_)); }
292 
294 
298  return op_type(op_base_type(factor_), perm);
299  }
300 
302 
304  scalar_type factor() { return factor_; }
305 
307 
309  std::string make_tag() const {
310  std::stringstream ss;
311  ss << "[+] [" << factor_ << "] ";
312  return ss.str();
313  }
314 
315  }; // class ScalAddEngine
316 
317  } // namespace expressions
318 } // namespace TiledArray
319 
320 #endif // TILEDARRAY_EXPRESSIONS_ADD_ENGINE_H__INCLUDED
static op_type make_tile_op(const Permutation &perm)
Permuting tile operation factory function.
Definition: add_engine.h:193
shape_type make_shape(const Permutation &perm) const
Permuting shape factory function.
Definition: add_engine.h:180
EngineTrait< ScalAddEngine_ >::right_type right_type
The right-hand expression type.
Definition: add_engine.h:228
TiledArray::detail::BinaryWrapper< op_base_type > op_type
The tile operation type.
Definition: add_engine.h:97
right_type right_
The right-hand argument.
Definition: binary_engine.h:78
Op::result_type result_type
The result tile type.
Tile scale-addition operation.
Definition: add.h:243
EngineTrait< ScalAddEngine_ >::op_type op_type
The tile operation type.
Definition: add_engine.h:238
EngineTrait< ScalAddEngine_ >::op_base_type op_base_type
The tile operation type.
Definition: add_engine.h:236
EngineTrait< AddEngine_ >::op_base_type op_base_type
The tile operation type.
Definition: add_engine.h:143
const Permutation & perm() const
Permutation accessor.
Definition: expr_engine.h:204
eval_trait< value_type >::type eval_type
Evaluation tile type.
Definition: add_engine.h:62
EngineTrait< AddEngine_ >::shape_type shape_type
Shape type.
Definition: add_engine.h:157
shape_type make_shape() const
Non-permuting shape factory function.
Definition: add_engine.h:274
EngineTrait< AddEngine_ >::value_type value_type
The result tile type.
Definition: add_engine.h:141
EngineTrait< AddEngine_ >::left_type left_type
The left-hand expression type.
Definition: add_engine.h:135
EngineTrait< AddEngine_ >::dist_eval_type dist_eval_type
The distributed evaluator type.
Definition: add_engine.h:149
EngineTrait< AddEngine_ >::op_type op_type
The tile operation type.
Definition: add_engine.h:145
policy::pmap_interface pmap_interface
Process map interface type.
Definition: add_engine.h:72
EngineTrait< ScalAddEngine_ >::dist_eval_type dist_eval_type
The distributed evaluator type.
Definition: add_engine.h:242
BinaryEngine< ScalAddEngine_ > BinaryEngine_
Binary expression engine base type.
Definition: add_engine.h:220
Addition expression.
Definition: add_engine.h:37
TiledArray::detail::BinaryWrapper< op_base_type > op_type
The tile operation type.
Definition: add_engine.h:58
Tile addition operation.
Definition: add.h:54
EngineTrait< AddEngine_ >::pmap_interface pmap_interface
Process map interface type.
Definition: add_engine.h:159
AddEngine(const AddExpr< L, R > &expr)
Constructor.
Definition: add_engine.h:167
op_type make_tile_op(const Permutation &perm) const
Permuting tile operation factory function.
Definition: add_engine.h:297
const char * make_tag() const
Expression identification tag.
Definition: add_engine.h:200
Tensor expression object.
Definition: dist_eval.h:241
TiledArray::detail::Add< Result, typename EngineTrait< Left >::eval_type, typename EngineTrait< Right >::eval_type, EngineTrait< Left >::consumable, EngineTrait< Right >::consumable > op_base_type
The base tile operation type.
Definition: add_engine.h:56
EngineTrait< ScalAddEngine_ >::size_type size_type
Size type.
Definition: add_engine.h:246
Binary tile operation wrapper.
Add-then-scale expression.
Definition: add_engine.h:38
EngineTrait< ScalAddEngine_ >::shape_type shape_type
Shape type.
Definition: add_engine.h:250
TiledArray::detail::DistEval< value_type, policy > dist_eval_type
The distributed evaluator type.
Definition: add_engine.h:104
TiledArray::detail::DistEval< value_type, policy > dist_eval_type
The distributed evaluator type.
Definition: add_engine.h:65
EngineTrait< AddEngine_ >::size_type size_type
Size type.
Definition: add_engine.h:153
std::string make_tag() const
Expression identification tag.
Definition: add_engine.h:309
EngineTrait< AddEngine_ >::right_type right_type
The right-hand expression type.
Definition: add_engine.h:137
EngineTrait< ScalAddEngine_ >::scalar_type scalar_type
Tile scalar type.
Definition: add_engine.h:234
EngineTrait< AddEngine_ >::policy policy
The result policy type.
Definition: add_engine.h:147
AddEngine< Left, Right, Result > AddEngine_
This class type.
Definition: add_engine.h:127
EngineTrait< AddEngine_ >::trange_type trange_type
Tiled range type.
Definition: add_engine.h:155
shape_type make_shape(const Permutation &perm) const
Permuting shape factory function.
Definition: add_engine.h:283
Consumable tile type trait.
Definition: type_traits.h:406
EngineTrait< ScalAddEngine_ >::value_type value_type
The result tile type.
Definition: add_engine.h:232
shape_type make_shape() const
Non-permuting shape factory function.
Definition: add_engine.h:172
op_type make_tile_op() const
Non-permuting tile operation factory function.
Definition: add_engine.h:291
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:119
EngineTrait< ScalAddEngine_ >::policy policy
The result policy type.
Definition: add_engine.h:240
static op_type make_tile_op()
Non-permuting tile operation factory function.
Definition: add_engine.h:187
scalar_type factor()
Scaling factor accessor.
Definition: add_engine.h:304
EngineTrait< ScalAddEngine_ >::trange_type trange_type
Tiled range type.
Definition: add_engine.h:248
TiledArray::detail::ScalAdd< Result, typename EngineTrait< Left >::eval_type, typename EngineTrait< Right >::eval_type, scalar_type, EngineTrait< Left >::consumable, EngineTrait< Right >::consumable > op_base_type
The base tile operation type.
Definition: add_engine.h:95
ScalAddEngine< Left, Right, Scalar, Result > ScalAddEngine_
This class type.
Definition: add_engine.h:218
eval_trait< value_type >::type eval_type
Evaluation tile type.
Definition: add_engine.h:101
BinaryEngine< AddEngine_ > BinaryEngine_
Binary expression engine base type.
Definition: add_engine.h:129
ExprEngine< ScalAddEngine_ > ExprEngine_
Expression engine base type.
Definition: add_engine.h:222
EngineTrait< ScalAddEngine_ >::left_type left_type
The left-hand expression type.
Definition: add_engine.h:226
EngineTrait< ScalAddEngine_ >::pmap_interface pmap_interface
Process map interface type.
Definition: add_engine.h:252
ScalAddEngine(const ScalAddExpr< L, R, S > &expr)
Constructor.
Definition: add_engine.h:267
Addition expression engine.
Definition: add_engine.h:39
Addition expression engine.
Definition: add_engine.h:40
BinaryEngine_::ExprEngine_ ExprEngine_
Expression engine base type.
Definition: add_engine.h:131
left_type left_
The left-hand argument.
Definition: binary_engine.h:77