TiledArray  0.7.0
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> class ScalExpr;
38  template <typename, typename, typename> class ScalEngine;
39 
40 
41  template <typename Arg, typename Scalar, typename Result>
42  struct EngineTrait<ScalEngine<Arg, Scalar, Result> > {
43  // Argument typedefs
44  typedef Arg argument_type;
45 
46  // Operational typedefs
47  typedef Scalar scalar_type;
48  typedef TiledArray::detail::Scal<Result,
54  typedef typename op_type::result_type
56  typedef typename eval_trait<value_type>::type
58  typedef typename argument_type::policy
62 
63  // Meta data typedefs
64  typedef typename policy::size_type size_type;
65  typedef typename policy::trange_type trange_type;
66  typedef typename policy::shape_type shape_type;
67  typedef typename policy::pmap_interface
69 
70  static constexpr bool consumable = true;
71  static constexpr unsigned int leaves = EngineTrait<Arg>::leaves;
72  };
73 
74 
76 
78  template <typename Arg, typename Scalar, typename Result>
79  class ScalEngine : public UnaryEngine<ScalEngine<Arg, Scalar, Result> > {
80  public:
81  // Class hierarchy typedefs
85 
86  // Argument typedefs
88 
89  // Operational typedefs
95 
96  // Meta data typedefs
101 
102  private:
103 
104  scalar_type factor_;
105 
106  public:
107 
109 
113  template <typename A, typename S>
114  ScalEngine(const ScalExpr<A, S>& expr) : UnaryEngine_(expr), factor_(expr.factor()) { }
115 
117 
120  return UnaryEngine_::arg_.shape().scale(factor_);
121  }
122 
124 
128  return UnaryEngine_::arg_.shape().scale(factor_, perm);
129  }
130 
132 
134  op_type make_tile_op() const { return op_type(factor_); }
135 
137 
140  op_type make_tile_op(const Permutation& perm) const { return op_type(perm, factor_); }
141 
143 
145  std::string make_tag() const {
146  std::stringstream ss;
147  ss << "[" << factor_ << "] ";
148  return ss.str();
149  }
150 
151  }; // class ScalEngine
152 
153 
154  } // namespace expressions
155 } // namespace TiledArray
156 
157 #endif // TILEDARRAY_EXPRESSIONS_SCAL_ENGINE_H__INCLUDED
EngineTrait< ScalEngine_ >::size_type size_type
Size type.
Definition: scal_engine.h:97
TiledArray::detail::UnaryWrapper< op_base_type > op_type
The tile operation type.
Definition: scal_engine.h:53
const Permutation & perm() const
Permutation accessor.
Definition: expr_engine.h:204
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:51
UnaryEngine_::ExprEngine_ ExprEngine_
Expression engine base type.
Definition: scal_engine.h:84
EngineTrait< ScalEngine_ >::pmap_interface pmap_interface
Process map interface type.
Definition: scal_engine.h:100
shape_type make_shape() const
Non-permuting shape factory function.
Definition: scal_engine.h:119
Scaling expression engine.
Definition: scal_engine.h:38
op_type make_tile_op(const Permutation &perm) const
Permuting tile operation factory function.
Definition: scal_engine.h:140
Unary tile operation wrapper.
Definition: unary_wrapper.h:82
argument_type arg_
The argument.
Definition: unary_engine.h:77
EngineTrait< ScalEngine_ >::op_type op_type
The tile operation type.
Definition: scal_engine.h:92
shape_type make_shape(const Permutation &perm) const
Permuting shape factory function.
Definition: scal_engine.h:127
Tile scaling operation.
Definition: scal.h:46
EngineTrait< ScalEngine_ >::shape_type shape_type
Shape type.
Definition: scal_engine.h:99
Op::result_type result_type
The result tile type.
Definition: unary_wrapper.h:86
ScalEngine< Arg, Scalar, Result > ScalEngine_
This class type.
Definition: scal_engine.h:82
Tensor expression object.
Definition: dist_eval.h:241
EngineTrait< ScalEngine_ >::scalar_type scalar_type
Tile scalar type.
Definition: scal_engine.h:91
op_type make_tile_op() const
Non-permuting tile operation factory function.
Definition: scal_engine.h:134
EngineTrait< ScalEngine_ >::trange_type trange_type
Tiled range type.
Definition: scal_engine.h:98
EngineTrait< ScalEngine_ >::policy policy
The result policy type.
Definition: scal_engine.h:93
TiledArray::detail::DistEval< value_type, policy > dist_eval_type
The distributed evaluator type.
Definition: scal_engine.h:61
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:119
eval_trait< value_type >::type eval_type
Evaluation tile type.
Definition: scal_engine.h:57
EngineTrait< ScalEngine_ >::value_type value_type
The result tile type.
Definition: scal_engine.h:90
EngineTrait< ScalEngine_ >::argument_type argument_type
The argument expression engine type.
Definition: scal_engine.h:87
EngineTrait< ScalEngine_ >::dist_eval_type dist_eval_type
The distributed evaluator type.
Definition: scal_engine.h:94
policy::pmap_interface pmap_interface
Process map interface type.
Definition: scal_engine.h:68
std::string make_tag() const
Expression identification tag.
Definition: scal_engine.h:145
ScalEngine(const ScalExpr< A, S > &expr)
Constructor.
Definition: scal_engine.h:114
UnaryEngine< ScalEngine_ > UnaryEngine_
Unary expression engine base type.
Definition: scal_engine.h:83