scal_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  * scal_engine.h
22  * Apr 1, 2014
23  *
24  */
25 
26 #ifndef TILEDARRAY_EXPRESSIONS_SCAL_ENGINE_H__INCLUDED
27 #define TILEDARRAY_EXPRESSIONS_SCAL_ENGINE_H__INCLUDED
28 
32 
33 namespace TiledArray {
34 namespace expressions {
35 
36 // Forward declarations
37 template <typename, typename>
38 class ScalExpr;
39 template <typename, typename, typename>
40 class ScalEngine;
41 
42 template <typename Arg, typename Scalar, typename Result>
43 struct EngineTrait<ScalEngine<Arg, Scalar, Result>> {
44  // Argument typedefs
45  typedef Arg argument_type;
46 
47  // Operational typedefs
48  typedef Scalar scalar_type;
55  typedef typename op_type::result_type value_type;
56  typedef typename eval_trait<value_type>::type
58  typedef typename argument_type::policy policy;
61 
62  // Meta data typedefs
63  typedef typename policy::ordinal_type size_type;
64  typedef typename policy::trange_type trange_type;
65  typedef typename policy::shape_type shape_type;
66  typedef typename policy::pmap_interface
68 
69  static constexpr bool consumable = true;
70  static constexpr unsigned int leaves = EngineTrait<Arg>::leaves;
71 };
72 
74 
76 template <typename Arg, typename Scalar, typename Result>
77 class ScalEngine : public UnaryEngine<ScalEngine<Arg, Scalar, Result>> {
78  public:
79  // Class hierarchy typedefs
83  typedef typename UnaryEngine_::ExprEngine_
85 
86  // Argument typedefs
89 
90  // Operational typedefs
95  typedef typename EngineTrait<ScalEngine_>::op_type
97  typedef typename EngineTrait<ScalEngine_>::policy
101 
102  // Meta data typedefs
103  typedef
107  typedef
111 
112  private:
113  scalar_type factor_;
114 
115  public:
117 
121  template <typename A, typename S>
123  : UnaryEngine_(expr), factor_(expr.factor()) {}
124 
126 
129  return UnaryEngine_::arg_.shape().scale(factor_);
130  }
131 
133 
136  shape_type make_shape(const Permutation& perm) const {
137  return UnaryEngine_::arg_.shape().scale(factor_, perm);
138  }
139 
141 
143  op_type make_tile_op() const { return op_type(factor_); }
144 
146 
149  template <typename Perm, typename = std::enable_if_t<
150  TiledArray::detail::is_permutation_v<Perm>>>
151  op_type make_tile_op(const Perm& perm) const {
152  return op_type(perm, factor_);
153  }
154 
156 
158  std::string make_tag() const {
159  std::stringstream ss;
160  ss << "[" << factor_ << "] ";
161  return ss.str();
162  }
163 
164 }; // class ScalEngine
165 
166 } // namespace expressions
167 } // namespace TiledArray
168 
169 #endif // TILEDARRAY_EXPRESSIONS_SCAL_ENGINE_H__INCLUDED
std::string make_tag() const
Expression identification tag.
Definition: scal_engine.h:158
Scaling expression engine.
Definition: scal_engine.h:77
TiledArray::detail::UnaryWrapper< op_base_type > op_type
The tile operation type.
Definition: scal_engine.h:54
ScalEngine< Arg, Scalar, Result > ScalEngine_
This class type.
Definition: scal_engine.h:80
argument_type arg_
The argument.
Definition: unary_engine.h:81
EngineTrait< ScalEngine_ >::argument_type argument_type
The argument expression engine type.
Definition: scal_engine.h:88
UnaryEngine_::ExprEngine_ ExprEngine_
Expression engine base type.
Definition: scal_engine.h:84
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:130
EngineTrait< ScalEngine_ >::policy policy
The result policy type.
Definition: scal_engine.h:98
EngineTrait< ScalEngine_ >::dist_eval_type dist_eval_type
The distributed evaluator type.
Definition: scal_engine.h:100
UnaryEngine< ScalEngine_ > UnaryEngine_
Unary expression engine base type.
Definition: scal_engine.h:82
policy::pmap_interface pmap_interface
Process map interface type.
Definition: scal_engine.h:67
TiledArray::detail::DistEval< value_type, policy > dist_eval_type
The distributed evaluator type.
Definition: scal_engine.h:60
EngineTrait< ScalEngine_ >::trange_type trange_type
Tiled range type.
Definition: scal_engine.h:106
EngineTrait< ScalEngine_ >::size_type size_type
Size type.
Definition: scal_engine.h:104
EngineTrait< ScalEngine_ >::shape_type shape_type
Shape type.
Definition: scal_engine.h:108
EngineTrait< ScalEngine_ >::pmap_interface pmap_interface
Process map interface type.
Definition: scal_engine.h:110
TiledArray::detail::Scal< Result, typename EngineTrait< Arg >::eval_type, scalar_type, EngineTrait< Arg >::consumable > op_base_type
The tile base operation type.
Definition: scal_engine.h:52
EngineTrait< ScalEngine_ >::op_type op_type
The tile operation type.
Definition: scal_engine.h:96
shape_type make_shape() const
Non-permuting shape factory function.
Definition: scal_engine.h:128
shape_type make_shape(const Permutation &perm) const
Permuting shape factory function.
Definition: scal_engine.h:136
Unary tile operation wrapper.
Definition: unary_wrapper.h:83
op_type make_tile_op(const Perm &perm) const
Permuting tile operation factory function.
Definition: scal_engine.h:151
op_type make_tile_op() const
Non-permuting tile operation factory function.
Definition: scal_engine.h:143
Determine the object type used in the evaluation of tensor expressions.
Definition: type_traits.h:580
EngineTrait< ScalEngine_ >::value_type value_type
The result tile type.
Definition: scal_engine.h:92
Tile scaling operation.
Definition: scal.h:46
ScalEngine(const ScalExpr< A, S > &expr)
Constructor.
Definition: scal_engine.h:122
Tensor expression object.
Definition: dist_eval.h:247
EngineTrait< ScalEngine_ >::scalar_type scalar_type
Tile scalar type.
Definition: scal_engine.h:94
eval_trait< value_type >::type eval_type
Evaluation tile type.
Definition: scal_engine.h:57
Op::result_type result_type
The result tile type.
Definition: unary_wrapper.h:87