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>
38 class AddExpr;
39 template <typename, typename, typename>
40 class ScalAddExpr;
41 template <typename, typename, typename>
42 class AddEngine;
43 template <typename, typename, typename, typename>
44 class ScalAddEngine;
45 
46 template <typename Left, typename Right, typename Result>
47 struct EngineTrait<AddEngine<Left, Right, Result>> {
48  static_assert(
49  std::is_same<typename EngineTrait<Left>::policy,
50  typename EngineTrait<Right>::policy>::value,
51  "The left- and right-hand expressions must use the same policy class");
52 
53  // Argument typedefs
54  typedef Left left_type;
55  typedef Right right_type;
56 
57  // Operational typedefs
65  typedef typename op_type::result_type value_type;
66  typedef typename eval_trait<value_type>::type
68  typedef typename Left::policy policy;
71 
72  // Meta data typedefs
73  typedef typename policy::ordinal_type size_type;
74  typedef typename policy::trange_type trange_type;
75  typedef typename policy::shape_type shape_type;
76  typedef typename policy::pmap_interface
78 
79  static constexpr bool consumable = true;
80  static constexpr unsigned int leaves =
82 };
83 
84 template <typename Left, typename Right, typename Scalar, typename Result>
85 struct EngineTrait<ScalAddEngine<Left, Right, Scalar, Result>> {
86  static_assert(
87  std::is_same<typename EngineTrait<Left>::policy,
88  typename EngineTrait<Right>::policy>::value,
89  "The left- and right-hand expressions must use the same policy class");
90 
91  // Argument typedefs
92  typedef Left left_type;
93  typedef Right right_type;
94 
95  // Operational typedefs
96  typedef Scalar scalar_type;
98  Result, typename EngineTrait<Left>::eval_type,
104  typedef typename op_type::result_type value_type;
105  typedef typename eval_trait<value_type>::type
107  typedef typename Left::policy policy;
110 
111  // Meta data typedefs
112  typedef typename policy::ordinal_type size_type;
113  typedef typename policy::trange_type trange_type;
114  typedef typename policy::shape_type shape_type;
115  typedef typename policy::pmap_interface
117 
118  static constexpr bool consumable = is_consumable_tile<eval_type>::value;
119  static constexpr unsigned int leaves =
121 };
122 
124 
128 template <typename Left, typename Right, typename Result>
129 class AddEngine : public BinaryEngine<AddEngine<Left, Right, Result>> {
130  public:
131  // Class hierarchy typedefs
135  typedef typename BinaryEngine_::ExprEngine_
137 
138  // Argument typedefs
139  typedef typename EngineTrait<AddEngine_>::left_type
141  typedef typename EngineTrait<AddEngine_>::right_type
143 
144  // Operational typedefs
145  typedef typename EngineTrait<AddEngine_>::value_type
149  typedef typename EngineTrait<AddEngine_>::op_type
151  typedef typename EngineTrait<AddEngine_>::policy
155 
156  // Meta data typedefs
158  typedef typename EngineTrait<AddEngine_>::trange_type
160  typedef
164 
166 
170  template <typename L, typename R>
171  AddEngine(const AddExpr<L, R>& expr) : BinaryEngine_(expr) {}
172 
174 
177  return BinaryEngine_::left_.shape().add(BinaryEngine_::right_.shape());
178  }
179 
181 
184  shape_type make_shape(const Permutation& perm) const {
185  return BinaryEngine_::left_.shape().add(BinaryEngine_::right_.shape(),
186  perm);
187  }
188 
190 
192  static op_type make_tile_op() { return op_type(op_base_type()); }
193 
195 
198  template <typename Perm, typename = std::enable_if_t<
199  TiledArray::detail::is_permutation_v<Perm>>>
200  static op_type make_tile_op(const Perm& perm) {
201  return op_type(op_base_type(), perm);
202  }
203 
205 
207  const char* make_tag() const { return "[+] "; }
208 
209 }; // class AddEngine
210 
212 
217 template <typename Left, typename Right, typename Scalar, typename Result>
219  : public BinaryEngine<ScalAddEngine<Left, Right, Scalar, Result>> {
220  public:
221  // Class hierarchy typedefs
228 
229  // Argument typedefs
234 
235  // Operational typedefs
242  typedef typename EngineTrait<ScalAddEngine_>::op_type
244  typedef typename EngineTrait<ScalAddEngine_>::policy
248 
249  // Meta data typedefs
250  typedef
258 
259  private:
260  scalar_type factor_;
261 
262  public:
264 
269  template <typename L, typename R, typename S>
271  : BinaryEngine_(expr), factor_(expr.factor()) {}
272 
274 
277  return BinaryEngine_::left_.shape().add(BinaryEngine_::right_.shape(),
278  factor_);
279  }
280 
282 
285  shape_type make_shape(const Permutation& perm) const {
286  return BinaryEngine_::left_.shape().add(BinaryEngine_::right_.shape(),
287  factor_, perm);
288  }
289 
291 
293  op_type make_tile_op() const { return op_type(op_base_type(factor_)); }
294 
296 
299  template <typename Perm, typename = std::enable_if_t<
300  TiledArray::detail::is_permutation_v<Perm>>>
301  op_type make_tile_op(const Perm& perm) const {
302  return op_type(op_base_type(factor_), perm);
303  }
304 
306 
308  scalar_type factor() { return factor_; }
309 
311 
313  std::string make_tag() const {
314  std::stringstream ss;
315  ss << "[+] [" << factor_ << "] ";
316  return ss.str();
317  }
318 
319 }; // class ScalAddEngine
320 
321 } // namespace expressions
322 } // namespace TiledArray
323 
324 #endif // TILEDARRAY_EXPRESSIONS_ADD_ENGINE_H__INCLUDED
policy::pmap_interface pmap_interface
Process map interface type.
Definition: add_engine.h:77
EngineTrait< ScalAddEngine_ >::left_type left_type
The left-hand expression type.
Definition: add_engine.h:231
Add-then-scale expression.
Definition: add_expr.h:120
TiledArray::detail::DistEval< value_type, policy > dist_eval_type
The distributed evaluator type.
Definition: add_engine.h:109
EngineTrait< ScalAddEngine_ >::size_type size_type
Size type.
Definition: add_engine.h:251
BinaryEngine< ScalAddEngine_ > BinaryEngine_
Binary expression engine base type.
Definition: add_engine.h:225
EngineTrait< AddEngine_ >::value_type value_type
The result tile type.
Definition: add_engine.h:146
shape_type make_shape(const Permutation &perm) const
Permuting shape factory function.
Definition: add_engine.h:184
Consumable tile type trait.
Definition: type_traits.h:611
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:62
op_type make_tile_op(const Perm &perm) const
Permuting tile operation factory function.
Definition: add_engine.h:301
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:130
Tile scale-addition operation.
Definition: add.h:238
const char * make_tag() const
Expression identification tag.
Definition: add_engine.h:207
EngineTrait< AddEngine_ >::policy policy
The result policy type.
Definition: add_engine.h:152
Tile addition operation.
Definition: add.h:54
BinaryEngine< AddEngine_ > BinaryEngine_
Binary expression engine base type.
Definition: add_engine.h:134
EngineTrait< ScalAddEngine_ >::pmap_interface pmap_interface
Process map interface type.
Definition: add_engine.h:257
EngineTrait< ScalAddEngine_ >::scalar_type scalar_type
Tile scalar type.
Definition: add_engine.h:239
shape_type make_shape(const Permutation &perm) const
Permuting shape factory function.
Definition: add_engine.h:285
AddEngine< Left, Right, Result > AddEngine_
This class type.
Definition: add_engine.h:132
EngineTrait< AddEngine_ >::left_type left_type
The left-hand expression type.
Definition: add_engine.h:140
TiledArray::detail::DistEval< value_type, policy > dist_eval_type
The distributed evaluator type.
Definition: add_engine.h:70
EngineTrait< ScalAddEngine_ >::op_type op_type
The tile operation type.
Definition: add_engine.h:243
EngineTrait< ScalAddEngine_ >::policy policy
The result policy type.
Definition: add_engine.h:245
Addition expression engine.
Definition: add_engine.h:219
EngineTrait< ScalAddEngine_ >::shape_type shape_type
Shape type.
Definition: add_engine.h:255
EngineTrait< ScalAddEngine_ >::value_type value_type
The result tile type.
Definition: add_engine.h:237
eval_trait< value_type >::type eval_type
Evaluation tile type.
Definition: add_engine.h:67
EngineTrait< ScalAddEngine_ >::trange_type trange_type
Tiled range type.
Definition: add_engine.h:253
ScalAddEngine< Left, Right, Scalar, Result > ScalAddEngine_
This class type.
Definition: add_engine.h:223
EngineTrait< AddEngine_ >::trange_type trange_type
Tiled range type.
Definition: add_engine.h:159
EngineTrait< AddEngine_ >::size_type size_type
Size type.
Definition: add_engine.h:157
Binary tile operation wrapper.
EngineTrait< ScalAddEngine_ >::right_type right_type
The right-hand expression type.
Definition: add_engine.h:233
ScalAddEngine(const ScalAddExpr< L, R, S > &expr)
Constructor.
Definition: add_engine.h:270
EngineTrait< AddEngine_ >::right_type right_type
The right-hand expression type.
Definition: add_engine.h:142
Addition expression.
Definition: add_expr.h:88
EngineTrait< AddEngine_ >::dist_eval_type dist_eval_type
The distributed evaluator type.
Definition: add_engine.h:154
right_type right_
The right-hand argument.
Definition: binary_engine.h:87
EngineTrait< AddEngine_ >::op_base_type op_base_type
The tile operation type.
Definition: add_engine.h:148
left_type left_
The left-hand argument.
Definition: binary_engine.h:86
ExprEngine< ScalAddEngine_ > ExprEngine_
Expression engine base type.
Definition: add_engine.h:227
AddEngine(const AddExpr< L, R > &expr)
Constructor.
Definition: add_engine.h:171
scalar_type factor()
Scaling factor accessor.
Definition: add_engine.h:308
EngineTrait< AddEngine_ >::op_type op_type
The tile operation type.
Definition: add_engine.h:150
TiledArray::detail::BinaryWrapper< op_base_type > op_type
The tile operation type.
Definition: add_engine.h:103
BinaryEngine_::ExprEngine_ ExprEngine_
Expression engine base type.
Definition: add_engine.h:136
TiledArray::detail::BinaryWrapper< op_base_type > op_type
The tile operation type.
Definition: add_engine.h:64
Op::result_type result_type
The result tile type.
EngineTrait< AddEngine_ >::shape_type shape_type
Shape type.
Definition: add_engine.h:161
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:101
std::string make_tag() const
Expression identification tag.
Definition: add_engine.h:313
EngineTrait< AddEngine_ >::pmap_interface pmap_interface
Process map interface type.
Definition: add_engine.h:163
static op_type make_tile_op(const Perm &perm)
Permuting tile operation factory function.
Definition: add_engine.h:200
Addition expression engine.
Definition: add_engine.h:129
Determine the object type used in the evaluation of tensor expressions.
Definition: type_traits.h:580
shape_type make_shape() const
Non-permuting shape factory function.
Definition: add_engine.h:176
shape_type make_shape() const
Non-permuting shape factory function.
Definition: add_engine.h:276
Tensor expression object.
Definition: dist_eval.h:247
EngineTrait< ScalAddEngine_ >::op_base_type op_base_type
The tile operation type.
Definition: add_engine.h:241
static op_type make_tile_op()
Non-permuting tile operation factory function.
Definition: add_engine.h:192
EngineTrait< ScalAddEngine_ >::dist_eval_type dist_eval_type
The distributed evaluator type.
Definition: add_engine.h:247
op_type make_tile_op() const
Non-permuting tile operation factory function.
Definition: add_engine.h:293