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>
38 class SubtExpr;
39 template <typename, typename, typename>
40 class ScalSubtExpr;
41 template <typename, typename, typename>
42 class SubtEngine;
43 template <typename, typename, typename, typename>
44 class ScalSubtEngine;
45 
46 template <typename Left, typename Right, typename Result>
47 struct EngineTrait<SubtEngine<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
59  Result, typename EngineTrait<Left>::eval_type,
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 = is_consumable_tile<eval_type>::value;
80  static constexpr unsigned int leaves =
82 }; // struct EngineTrait<SubtEngine<Left, Right> >
83 
84 template <typename Left, typename Right, typename Scalar, typename Result>
85 struct EngineTrait<ScalSubtEngine<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 }; // struct EngineTrait<ScalSubtEngine<Left, Right, Scalar> >
122 
124 
128 template <typename Left, typename Right, typename Result>
129 class SubtEngine : public BinaryEngine<SubtEngine<Left, Right, Result>> {
130  public:
131  // Class hierarchy typedefs
134  typedef typename BinaryEngine_::ExprEngine_
136 
137  // Argument typedefs
138  typedef typename EngineTrait<SubtEngine_>::left_type
140  typedef typename EngineTrait<SubtEngine_>::right_type
142 
143  // Operational typedefs
144  typedef typename EngineTrait<SubtEngine_>::value_type
148  typedef typename EngineTrait<SubtEngine_>::op_type
150  typedef typename EngineTrait<SubtEngine_>::policy
154 
155  // Meta data typedefs
156  typedef
160  typedef
164 
166 
170  template <typename L, typename R>
171  SubtEngine(const SubtExpr<L, R>& expr) : BinaryEngine_(expr) {}
172 
174 
177  return BinaryEngine_::left_.shape().subt(BinaryEngine_::right_.shape());
178  }
179 
181 
184  shape_type make_shape(const Permutation& perm) const {
185  return BinaryEngine_::left_.shape().subt(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 SubtEngine
210 
212 
217 template <typename Left, typename Right, typename Scalar, typename Result>
219  : public BinaryEngine<ScalSubtEngine<Left, Right, Scalar, Result>> {
220  public:
221  // Class hierarchy typedefs
226  typedef typename BinaryEngine_::ExprEngine_
228 
229  // Argument typedefs
234 
235  // Operational typedefs
244  typedef typename EngineTrait<ScalSubtEngine_>::policy
248 
249  // Meta data typedefs
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().subt(BinaryEngine_::right_.shape(),
278  factor_);
279  }
280 
282 
285  shape_type make_shape(const Permutation& perm) const {
286  return BinaryEngine_::left_.shape().subt(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  std::string make_tag() const {
309  std::stringstream ss;
310  ss << "[-] [" << factor_ << "] ";
311  return ss.str();
312  }
313 
314 }; // class ScalSubtEngine
315 
316 } // namespace expressions
317 } // namespace TiledArray
318 
319 #endif // TILEDARRAY_SUBT_ENGINE_H__INCLUDED
EngineTrait< SubtEngine_ >::shape_type shape_type
Shape type.
Definition: subt_engine.h:161
EngineTrait< SubtEngine_ >::value_type value_type
The result tile type.
Definition: subt_engine.h:145
shape_type make_shape(const Permutation &perm) const
Permuting shape factory function.
Definition: subt_engine.h:184
Consumable tile type trait.
Definition: type_traits.h:611
EngineTrait< ScalSubtEngine_ >::scalar_type scalar_type
Tile scalar type.
Definition: subt_engine.h:239
Tile subtraction operation.
Definition: subt.h:53
shape_type make_shape() const
Non-permuting shape factory function.
Definition: subt_engine.h:276
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:130
op_type make_tile_op() const
Non-permuting tile operation factory function.
Definition: subt_engine.h:293
std::string make_tag() const
Expression identification tag.
Definition: subt_engine.h:308
static op_type make_tile_op(const Perm &perm)
Permuting tile operation factory function.
Definition: subt_engine.h:200
shape_type make_shape() const
Non-permuting shape factory function.
Definition: subt_engine.h:176
Subtraction expression.
Definition: subt_expr.h:88
EngineTrait< SubtEngine_ >::size_type size_type
Size type.
Definition: subt_engine.h:157
EngineTrait< SubtEngine_ >::op_base_type op_base_type
The tile operation type.
Definition: subt_engine.h:147
eval_trait< value_type >::type eval_type
Evaluation tile type.
Definition: subt_engine.h:67
SubtEngine< Left, Right, Result > SubtEngine_
This class type.
Definition: subt_engine.h:132
EngineTrait< ScalSubtEngine_ >::op_type op_type
The tile operation type.
Definition: subt_engine.h:243
EngineTrait< ScalSubtEngine_ >::pmap_interface pmap_interface
Process map interface type.
Definition: subt_engine.h:257
EngineTrait< ScalSubtEngine_ >::dist_eval_type dist_eval_type
The distributed evaluator type.
Definition: subt_engine.h:247
BinaryEngine< SubtEngine_ > BinaryEngine_
Binary base class type.
Definition: subt_engine.h:133
EngineTrait< SubtEngine_ >::right_type right_type
The right-hand expression type.
Definition: subt_engine.h:141
Binary tile operation wrapper.
policy::pmap_interface pmap_interface
Process map interface type.
Definition: subt_engine.h:77
EngineTrait< ScalSubtEngine_ >::shape_type shape_type
Shape type.
Definition: subt_engine.h:255
ScalSubtEngine(const ScalSubtExpr< L, R, S > &expr)
Constructor.
Definition: subt_engine.h:270
right_type right_
The right-hand argument.
Definition: binary_engine.h:87
Subtraction expression engine.
Definition: subt_engine.h:219
BinaryEngine_::ExprEngine_ ExprEngine_
Expression engine base type.
Definition: subt_engine.h:227
static op_type make_tile_op()
Non-permuting tile operation factory function.
Definition: subt_engine.h:192
EngineTrait< ScalSubtEngine_ >::value_type value_type
The result tile type.
Definition: subt_engine.h:237
left_type left_
The left-hand argument.
Definition: binary_engine.h:86
TiledArray::detail::DistEval< value_type, policy > dist_eval_type
The distributed evaluator type.
Definition: subt_engine.h:109
EngineTrait< SubtEngine_ >::pmap_interface pmap_interface
Process map interface type.
Definition: subt_engine.h:163
BinaryEngine< ScalSubtEngine_ > BinaryEngine_
Binary expression engine base type.
Definition: subt_engine.h:225
EngineTrait< ScalSubtEngine_ >::size_type size_type
Size type.
Definition: subt_engine.h:251
Tile scale-subtraction operation.
Definition: subt.h:237
TiledArray::detail::BinaryWrapper< op_base_type > op_type
The tile operation type.
Definition: subt_engine.h:103
EngineTrait< SubtEngine_ >::policy policy
The result policy type.
Definition: subt_engine.h:151
ScalSubtEngine< Left, Right, Scalar, Result > ScalSubtEngine_
This class type.
Definition: subt_engine.h:223
EngineTrait< ScalSubtEngine_ >::right_type right_type
The right-hand expression type.
Definition: subt_engine.h:233
TiledArray::detail::BinaryWrapper< op_base_type > op_type
The tile operation type.
Definition: subt_engine.h:64
Op::result_type result_type
The result tile type.
const char * make_tag() const
Expression identification tag.
Definition: subt_engine.h:207
EngineTrait< SubtEngine_ >::trange_type trange_type
Tiled range type.
Definition: subt_engine.h:159
EngineTrait< ScalSubtEngine_ >::policy policy
The result policy type.
Definition: subt_engine.h:245
Subtraction expression.
Definition: subt_expr.h:120
Subtraction expression engine.
Definition: subt_engine.h:129
EngineTrait< ScalSubtEngine_ >::op_base_type op_base_type
The tile operation type.
Definition: subt_engine.h:241
EngineTrait< SubtEngine_ >::op_type op_type
The tile operation type.
Definition: subt_engine.h:149
op_type make_tile_op(const Perm &perm) const
Permuting tile operation factory function.
Definition: subt_engine.h:301
SubtEngine(const SubtExpr< L, R > &expr)
Constructor.
Definition: subt_engine.h:171
Determine the object type used in the evaluation of tensor expressions.
Definition: type_traits.h:580
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:101
EngineTrait< SubtEngine_ >::left_type left_type
The left-hand expression type.
Definition: subt_engine.h:139
EngineTrait< SubtEngine_ >::dist_eval_type dist_eval_type
The distributed evaluator type.
Definition: subt_engine.h:153
Tensor expression object.
Definition: dist_eval.h:247
shape_type make_shape(const Permutation &perm) const
Permuting shape factory function.
Definition: subt_engine.h:285
EngineTrait< ScalSubtEngine_ >::trange_type trange_type
Tiled range type.
Definition: subt_engine.h:253
EngineTrait< ScalSubtEngine_ >::left_type left_type
The left-hand expression type.
Definition: subt_engine.h:231
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:62
BinaryEngine_::ExprEngine_ ExprEngine_
Expression engine base type.
Definition: subt_engine.h:135
TiledArray::detail::DistEval< value_type, policy > dist_eval_type
The distributed evaluator type.
Definition: subt_engine.h:70