TiledArray  0.7.0
subt_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  * subt_engine.h
22  * Mar 31, 2014
23  *
24  */
25 
26 #ifndef TILEDARRAY_SUBT_ENGINE_H__INCLUDED
27 #define TILEDARRAY_SUBT_ENGINE_H__INCLUDED
28 
32 
33 namespace TiledArray {
34  namespace expressions {
35 
36  // Forward declarations
37  template <typename, typename> class SubtExpr;
38  template <typename, typename, typename> class ScalSubtExpr;
39  template <typename, typename, typename> class SubtEngine;
40  template <typename, typename, typename, typename> class ScalSubtEngine;
41 
42  template <typename Left, typename Right, typename Result>
43  struct EngineTrait<SubtEngine<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
53  typedef TiledArray::detail::Subt<Result,
60  typedef typename op_type::result_type
62  typedef typename eval_trait<value_type>::type
64  typedef typename Left::policy policy;
67 
68  // Meta data typedefs
69  typedef typename policy::size_type size_type;
70  typedef typename policy::trange_type trange_type;
71  typedef typename policy::shape_type shape_type;
72  typedef typename policy::pmap_interface
74 
75  static constexpr bool consumable = is_consumable_tile<eval_type>::value;
76  static constexpr unsigned int leaves =
78  }; // struct EngineTrait<SubtEngine<Left, Right> >
79 
80  template <typename Left, typename Right, typename Scalar, typename Result>
81  struct EngineTrait<ScalSubtEngine<Left, Right, Scalar, Result> > {
82  static_assert(std::is_same<typename EngineTrait<Left>::policy,
83  typename EngineTrait<Right>::policy>::value,
84  "The left- and right-hand expressions must use the same policy class");
85 
86  // Argument typedefs
87  typedef Left left_type;
88  typedef Right right_type;
89 
90  // Operational typedefs
91  typedef Scalar scalar_type;
92  typedef TiledArray::detail::ScalSubt<Result,
99  typedef typename op_type::result_type
101  typedef typename eval_trait<value_type>::type
103  typedef typename Left::policy policy;
106 
107  // Meta data typedefs
108  typedef typename policy::size_type size_type;
109  typedef typename policy::trange_type trange_type;
110  typedef typename policy::shape_type shape_type;
111  typedef typename policy::pmap_interface
113 
114  static constexpr bool consumable = is_consumable_tile<eval_type>::value;
115  static constexpr unsigned int leaves =
117  }; // struct EngineTrait<ScalSubtEngine<Left, Right, Scalar> >
118 
119 
121 
125  template <typename Left, typename Right, typename Result>
126  class SubtEngine : public BinaryEngine<SubtEngine<Left, Right, Result> > {
127  public:
128  // Class hierarchy typedefs
132  typedef typename BinaryEngine_::ExprEngine_
134 
135  // Argument typedefs
136  typedef typename EngineTrait<SubtEngine_>::left_type
138  typedef typename EngineTrait<SubtEngine_>::right_type
140 
141  // Operational typedefs
142  typedef typename EngineTrait<SubtEngine_>::value_type
146  typedef typename EngineTrait<SubtEngine_>::op_type
148  typedef typename EngineTrait<SubtEngine_>::policy
152 
153  // Meta data typedefs
154  typedef typename EngineTrait<SubtEngine_>::size_type
158  typedef typename EngineTrait<SubtEngine_>::shape_type
162 
164 
168  template <typename L, typename R>
169  SubtEngine(const SubtExpr<L, R>& expr) : BinaryEngine_(expr) { }
170 
172 
175  return BinaryEngine_::left_.shape().subt(BinaryEngine_::right_.shape());
176  }
177 
179 
183  return BinaryEngine_::left_.shape().subt(BinaryEngine_::right_.shape(), perm);
184  }
185 
187 
189  static op_type make_tile_op() { return op_type(op_base_type()); }
190 
192 
196 
198 
200  const char* make_tag() const { return "[-] "; }
201 
202  }; // class SubtEngine
203 
204 
206 
211  template <typename Left, typename Right, typename Scalar, typename Result>
212  class ScalSubtEngine :
213  public BinaryEngine<ScalSubtEngine<Left, Right, Scalar, Result> >
214  {
215  public:
216  // Class hierarchy typedefs
217  typedef ScalSubtEngine<Left, Right, Scalar, Result>
221  typedef typename BinaryEngine_::ExprEngine_
223 
224  // Argument typedefs
229 
230  // Operational typedefs
239  typedef typename EngineTrait<ScalSubtEngine_>::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().subt(BinaryEngine_::right_.shape(),
276  factor_);
277  }
278 
280 
284  return BinaryEngine_::left_.shape().subt(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  std::string make_tag() const {
305  std::stringstream ss;
306  ss << "[-] [" << factor_ << "] ";
307  return ss.str();
308  }
309 
310  }; // class ScalSubtEngine
311 
312  } // namespace expressions
313 } // namespace TiledArray
314 
315 #endif // TILEDARRAY_SUBT_ENGINE_H__INCLUDED
EngineTrait< SubtEngine_ >::op_base_type op_base_type
The tile operation type.
Definition: subt_engine.h:145
EngineTrait< ScalSubtEngine_ >::op_type op_type
The tile operation type.
Definition: subt_engine.h:238
right_type right_
The right-hand argument.
Definition: binary_engine.h:78
Subtraction expression engine.
Definition: subt_engine.h:39
eval_trait< value_type >::type eval_type
Evaluation tile type.
Definition: subt_engine.h:63
Op::result_type result_type
The result tile type.
TiledArray::detail::DistEval< value_type, policy > dist_eval_type
The distributed evaluator type.
Definition: subt_engine.h:105
Tile subtraction operation.
Definition: subt.h:53
EngineTrait< SubtEngine_ >::op_type op_type
The tile operation type.
Definition: subt_engine.h:147
SubtEngine< Left, Right, Result > SubtEngine_
This class type.
Definition: subt_engine.h:129
EngineTrait< SubtEngine_ >::trange_type trange_type
Tiled range type.
Definition: subt_engine.h:157
const Permutation & perm() const
Permutation accessor.
Definition: expr_engine.h:204
shape_type make_shape(const Permutation &perm) const
Permuting shape factory function.
Definition: subt_engine.h:283
EngineTrait< ScalSubtEngine_ >::pmap_interface pmap_interface
Process map interface type.
Definition: subt_engine.h:252
std::string make_tag() const
Expression identification tag.
Definition: subt_engine.h:304
TiledArray::detail::BinaryWrapper< op_base_type > op_type
The tile operation type.
Definition: subt_engine.h:98
Tile scale-subtraction operation.
Definition: subt.h:240
Subtraction expression.
Definition: subt_engine.h:38
const char * make_tag() const
Expression identification tag.
Definition: subt_engine.h:200
BinaryEngine< ScalSubtEngine_ > BinaryEngine_
Binary expression engine base type.
Definition: subt_engine.h:220
EngineTrait< ScalSubtEngine_ >::op_base_type op_base_type
The tile operation type.
Definition: subt_engine.h:236
EngineTrait< ScalSubtEngine_ >::trange_type trange_type
Tiled range type.
Definition: subt_engine.h:248
EngineTrait< ScalSubtEngine_ >::right_type right_type
The right-hand expression type.
Definition: subt_engine.h:228
BinaryEngine_::ExprEngine_ ExprEngine_
Expression engine base type.
Definition: subt_engine.h:222
EngineTrait< SubtEngine_ >::size_type size_type
Size type.
Definition: subt_engine.h:155
Subtraction expression engine.
Definition: subt_engine.h:40
EngineTrait< SubtEngine_ >::value_type value_type
The result tile type.
Definition: subt_engine.h:143
ScalSubtEngine(const ScalSubtExpr< L, R, S > &expr)
Constructor.
Definition: subt_engine.h:267
EngineTrait< ScalSubtEngine_ >::policy policy
The result policy type.
Definition: subt_engine.h:240
op_type make_tile_op() const
Non-permuting tile operation factory function.
Definition: subt_engine.h:291
EngineTrait< ScalSubtEngine_ >::size_type size_type
Size type.
Definition: subt_engine.h:246
Tensor expression object.
Definition: dist_eval.h:241
shape_type make_shape(const Permutation &perm) const
Permuting shape factory function.
Definition: subt_engine.h:182
shape_type make_shape() const
Non-permuting shape factory function.
Definition: subt_engine.h:274
EngineTrait< ScalSubtEngine_ >::shape_type shape_type
Shape type.
Definition: subt_engine.h:250
TiledArray::detail::BinaryWrapper< op_base_type > op_type
The tile operation type.
Definition: subt_engine.h:59
policy::pmap_interface pmap_interface
Process map interface type.
Definition: subt_engine.h:73
Binary tile operation wrapper.
ScalSubtEngine< Left, Right, Scalar, Result > ScalSubtEngine_
This class type.
Definition: subt_engine.h:218
BinaryEngine_::ExprEngine_ ExprEngine_
Expression engine base type.
Definition: subt_engine.h:133
op_type make_tile_op(const Permutation &perm) const
Permuting tile operation factory function.
Definition: subt_engine.h:297
EngineTrait< SubtEngine_ >::shape_type shape_type
Shape type.
Definition: subt_engine.h:159
TiledArray::detail::Subt< 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: subt_engine.h:57
TiledArray::detail::DistEval< value_type, policy > dist_eval_type
The distributed evaluator type.
Definition: subt_engine.h:66
SubtEngine(const SubtExpr< L, R > &expr)
Constructor.
Definition: subt_engine.h:169
BinaryEngine< SubtEngine_ > BinaryEngine_
Binary base class type.
Definition: subt_engine.h:131
static op_type make_tile_op()
Non-permuting tile operation factory function.
Definition: subt_engine.h:189
Consumable tile type trait.
Definition: type_traits.h:406
EngineTrait< SubtEngine_ >::pmap_interface pmap_interface
Process map interface type.
Definition: subt_engine.h:161
TiledArray::detail::ScalSubt< 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: subt_engine.h:96
Subtraction expression.
Definition: subt_engine.h:37
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:119
static op_type make_tile_op(const Permutation &perm)
Permuting tile operation factory function.
Definition: subt_engine.h:195
EngineTrait< SubtEngine_ >::right_type right_type
The right-hand expression type.
Definition: subt_engine.h:139
EngineTrait< SubtEngine_ >::policy policy
The result policy type.
Definition: subt_engine.h:149
EngineTrait< ScalSubtEngine_ >::left_type left_type
The left-hand expression type.
Definition: subt_engine.h:226
EngineTrait< ScalSubtEngine_ >::value_type value_type
The result tile type.
Definition: subt_engine.h:232
EngineTrait< ScalSubtEngine_ >::dist_eval_type dist_eval_type
The distributed evaluator type.
Definition: subt_engine.h:242
shape_type make_shape() const
Non-permuting shape factory function.
Definition: subt_engine.h:174
left_type left_
The left-hand argument.
Definition: binary_engine.h:77
EngineTrait< SubtEngine_ >::left_type left_type
The left-hand expression type.
Definition: subt_engine.h:137
EngineTrait< SubtEngine_ >::dist_eval_type dist_eval_type
The distributed evaluator type.
Definition: subt_engine.h:151
EngineTrait< ScalSubtEngine_ >::scalar_type scalar_type
Tile scalar type.
Definition: subt_engine.h:234