TiledArray  0.7.0
subt_expr.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2013 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_expr.h
22  * Apr 1, 2014
23  *
24  */
25 
26 
27 #ifndef TILEDARRAY_EXPRESSIONS_SUBT_EXPR_H__INCLUDED
28 #define TILEDARRAY_EXPRESSIONS_SUBT_EXPR_H__INCLUDED
29 
32 
33 namespace TiledArray {
34  namespace expressions {
35 
36  template <typename Left, typename Right>
37  using ConjSubtExpr =
39 
40  template <typename Left, typename Right, typename Scalar>
41  using ScalConjSubtExpr =
43 
48 
49  template <typename Left, typename Right>
50  struct ExprTrait<SubtExpr<Left, Right> > {
51  typedef Left left_type;
52  typedef Right right_type;
53  typedef result_of_subt_t<
60  typedef numeric_t<typename EngineTrait<engine_type>::eval_type>
62  typedef scalar_t<typename EngineTrait<engine_type>::eval_type>
64  };
65 
66  template <typename Left, typename Right, typename Scalar>
67  struct ExprTrait<ScalSubtExpr<Left, Right, Scalar> > {
68  typedef Left left_type;
69  typedef Right right_type;
70  typedef Scalar scalar_type;
71  typedef result_of_subt_t<
78  typedef numeric_t<typename EngineTrait<engine_type>::eval_type>
80  };
81 
82 
84 
87  template <typename Left, typename Right>
88  class SubtExpr : public BinaryExpr<SubtExpr<Left, Right> > {
89  public:
92  typedef typename ExprTrait<SubtExpr_>::left_type
94  typedef typename ExprTrait<SubtExpr_>::right_type
96  typedef typename ExprTrait<SubtExpr_>::engine_type
98 
99  // Compiler generated functions
100  SubtExpr(const SubtExpr_&) = default;
101  SubtExpr(SubtExpr_&&) = default;
102  ~SubtExpr() = default;
103  SubtExpr_& operator=(const SubtExpr_&) = delete;
104  SubtExpr_& operator=(SubtExpr_&&) = delete;
105 
107 
111 
112  }; // class SubtExpr
113 
114 
116 
119  template <typename Left, typename Right, typename Scalar>
120  class ScalSubtExpr : public BinaryExpr<ScalSubtExpr<Left, Right, Scalar> > {
121  public:
128 
129  private:
130 
131  scalar_type factor_;
132 
133  public:
134 
135  // Compiler generated functions
136  ScalSubtExpr(const ScalSubtExpr_&) = default;
137  ScalSubtExpr(ScalSubtExpr_&&) = default;
138  ~ScalSubtExpr() = default;
139  ScalSubtExpr_& operator=(const ScalSubtExpr_&) = delete;
141 
142 
144 
149  const scalar_type factor) :
150  BinaryExpr_(left, right), factor_(factor)
151  { }
152 
154 
156  scalar_type factor() const { return factor_; }
157 
158  }; // class ScalSubtExpr
159 
160 
162 
164 
170  template <typename Left, typename Right>
171  inline SubtExpr<Left, Right>
172  operator-(const Expr<Left>& left, const Expr<Right>& right) {
174  "no_alias() expressions are not allowed on the right-hand side of "
175  "the assignment operator.");
177  "no_alias() expressions are not allowed on the right-hand side of "
178  "the assignment operator.");
179  return SubtExpr<Left, Right>(left.derived(), right.derived());
180  }
181 
183 
190  template <typename Left, typename Right, typename Scalar,
191  typename std::enable_if<
193  >::type* = nullptr>
194  inline ScalSubtExpr<Left, Right, Scalar>
195  operator*(const SubtExpr<Left, Right>& expr, const Scalar& factor) {
196  return ScalSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(),
197  factor);
198  }
199 
201 
208  template <typename Left, typename Right, typename Scalar,
209  typename std::enable_if<
211  >::type* = nullptr>
212  inline ScalSubtExpr<Left, Right, Scalar>
213  operator*(const Scalar& factor, const SubtExpr<Left, Right>& expr) {
214  return ScalSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(),
215  factor);
216  }
217 
219 
227  template <typename Left, typename Right, typename Scalar1, typename Scalar2,
228  typename std::enable_if<
230  >::type* = nullptr>
231  inline ScalSubtExpr<Left, Right, mult_t<Scalar1, Scalar2> >
233  const Scalar2& factor)
234  {
236  expr.right(), expr.factor() * factor);
237  }
238 
240 
248  template <typename Left, typename Right, typename Scalar1, typename Scalar2,
249  typename std::enable_if<
251  >::type* = nullptr>
252  inline ScalSubtExpr<Left, Right, mult_t<Scalar2, Scalar1> >
253  operator*(const Scalar1& factor, const ScalSubtExpr<Left, Right, Scalar2>& expr) {
255  expr.right(), expr.factor() * factor);
256  }
257 
258 
260 
265  template <typename Left, typename Right>
266  inline ScalSubtExpr<Left, Right,
267  typename ExprTrait<SubtExpr<Left, Right> >::numeric_type>
269  return ScalSubtExpr<Left, Right,
270  typename ExprTrait<SubtExpr<Left, Right> >::numeric_type>(expr.left(),
271  expr.right(), -1);
272  }
273 
275 
280  template <typename Left, typename Right, typename Scalar>
281  inline ScalSubtExpr<Left, Right, Scalar>
283  return ScalSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(), -1);
284  }
285 
287 
292  template <typename Left, typename Right>
294  return ConjSubtExpr<Left, Right>(expr.left(), expr.right(), conj_op());
295  }
296 
298 
303  template <typename Left, typename Right>
305  return SubtExpr<Left, Right>(expr.left(), expr.right());
306  }
307 
309 
315  template <typename Left, typename Right, typename Scalar>
316  inline ScalConjSubtExpr<Left, Right, Scalar>
318  return ScalConjSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(),
319  conj_op(TiledArray::detail::conj(expr.factor())));
320  }
321 
323 
329  template <typename Left, typename Right, typename Scalar>
330  inline ScalSubtExpr<Left, Right, Scalar>
332  return ScalSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(),
333  TiledArray::detail::conj(expr.factor().factor()));
334  }
335 
337 
344  template <typename Left, typename Right, typename Scalar,
345  typename std::enable_if<
347  >::type* = nullptr>
348  inline ScalConjSubtExpr<Left, Right, Scalar>
349  operator*(const ConjSubtExpr<Left, Right>& expr, const Scalar& factor) {
350  return ScalConjSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(),
351  conj_op(factor));
352  }
353 
355 
362  template <typename Left, typename Right, typename Scalar,
363  typename std::enable_if<
365  >::type* = nullptr>
366  inline ScalConjSubtExpr<Left, Right, Scalar>
367  operator*(const Scalar& factor, const ConjSubtExpr<Left, Right>& expr) {
368  return ScalConjSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(),
369  conj_op(factor));
370  }
371 
373 
381  template <typename Left, typename Right, typename Scalar1, typename Scalar2,
382  typename std::enable_if<
384  >::type* = nullptr>
385  inline ScalConjSubtExpr<Left, Right, mult_t<Scalar1, Scalar2> >
386  operator*(const ScalConjSubtExpr<Left, Right, Scalar1>& expr, const Scalar2& factor) {
388  expr.right(), conj_op(expr.factor().factor() * factor));
389  }
390 
392 
400  template <typename Left, typename Right, typename Scalar1, typename Scalar2,
401  typename std::enable_if<
403  >::type* = nullptr>
404  inline ScalConjSubtExpr<Left, Right, mult_t<Scalar2, Scalar1> >
405  operator*(const Scalar1& factor, const ScalConjSubtExpr<Left, Right, Scalar2>& expr) {
407  expr.left(), expr.right(), conj_op(expr.factor().factor() * factor));
408  }
409 
411 
416  template <typename Left, typename Right>
417  inline ScalConjSubtExpr<Left, Right,
418  typename ExprTrait<ConjSubtExpr<Left, Right> >::numeric_type>
420  typedef typename ExprTrait<ConjSubtExpr<Left, Right> >::numeric_type
421  scalar_type;
423  expr.right(), conj_op<scalar_type>(-1));
424  }
425 
427 
433  template <typename Left, typename Right, typename Scalar>
434  inline ScalConjSubtExpr<Left, Right, Scalar>
436  return ScalConjSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(),
437  conj_op(-expr.factor().factor()));
438  }
439 
440  } // namespace expressions
441 } // namespace TiledArray
442 
443 #endif // TILEDARRAY_EXPRESSIONS_SUBT_EXPR_H__INCLUDED
Right right_type
The right-hand expression type.
Definition: subt_expr.h:52
ExprTrait< ScalSubtExpr_ >::engine_type engine_type
Expression engine type.
Definition: subt_expr.h:126
Subtraction expression engine.
Definition: subt_engine.h:39
SubtExpr_ & operator=(const SubtExpr_ &)=delete
ScalSubtExpr< Left, Right, Scalar > ScalSubtExpr_
This class type.
Definition: subt_expr.h:122
SubtExpr(const left_type &left, const right_type &right)
Expression constructor.
Definition: subt_expr.h:110
result_of_subt_t< typename EngineTrait< typename ExprTrait< Left >::engine_type >::eval_type, typename EngineTrait< typename ExprTrait< Right >::engine_type >::eval_type > result_type
Result tile type.
Definition: subt_expr.h:56
numeric_t< typename EngineTrait< engine_type >::eval_type > numeric_type
Subtraction result numeric type.
Definition: subt_expr.h:79
ScalSubtExpr< Left, Right, TiledArray::detail::ComplexConjugate< Scalar > > ScalConjSubtExpr
Definition: subt_expr.h:42
ExprTrait< SubtExpr_ >::right_type right_type
The right-hand expression type.
Definition: subt_expr.h:95
std::enable_if< TiledArray::detail::is_numeric< Scalar >::value, ScalAddExpr< Left, Right, Scalar > >::type operator*(const AddExpr< Left, Right > &expr, const Scalar &factor)
Scaled-addition expression factor.
Definition: add_expr.h:198
SubtExpr(const SubtExpr_ &)=default
BinaryExpr< ScalSubtExpr_ > BinaryExpr_
Binary base class type.
Definition: subt_expr.h:123
Subtraction expression.
Definition: subt_engine.h:38
decltype(std::declval< Scalar1 >() *std::declval< Scalar2 >()) mult_t
Definition: type_traits.h:748
const right_type & right() const
Right-hand expression argument accessor.
Definition: binary_expr.h:71
typename TiledArray::detail::numeric_type< T >::type numeric_t
Definition: type_traits.h:525
ExprTrait< ScalSubtExpr_ >::left_type left_type
The left-hand expression type.
Definition: subt_expr.h:124
ExprTrait< SubtExpr_ >::engine_type engine_type
Expression engine type.
Definition: subt_expr.h:97
ExprTrait< ScalSubtExpr_ >::scalar_type scalar_type
Scalar type.
Definition: subt_expr.h:127
SubtExpr< Left, Right > SubtExpr_
Definition: subt_expr.h:90
Subtraction expression engine.
Definition: subt_engine.h:40
BinaryExpr< SubtExpr_ > BinaryExpr_
Binary base class type.
Definition: subt_expr.h:91
const left_type & left() const
Left-hand expression argument accessor.
Definition: binary_expr.h:66
Binary expression object.
Definition: binary_engine.h:36
ExprTrait< ScalSubtExpr_ >::right_type right_type
The right-hand expression type.
Definition: subt_expr.h:125
typename TiledArray::detail::scalar_type< T >::type scalar_t
Definition: type_traits.h:555
SubtEngine< typename ExprTrait< Left >::engine_type, typename ExprTrait< Right >::engine_type, result_type > engine_type
Expression engine type.
Definition: subt_expr.h:59
ScalSubtExpr(const ScalSubtExpr_ &)=default
numeric_t< typename EngineTrait< engine_type >::eval_type > numeric_type
Subtraction result numeric type.
Definition: subt_expr.h:61
scalar_type factor() const
Scaling factor accessor.
Definition: subt_expr.h:156
Base class for expression evaluation.
Definition: expr.h:81
derived_type & derived()
Cast this object to it&#39;s derived type.
Definition: expr.h:273
ConjAddExpr< Left, Right > conj(const AddExpr< Left, Right > &expr)
Conjugated addition expression factory.
Definition: add_expr.h:292
ScalSubtExpr_ & operator=(const ScalSubtExpr_ &)=delete
ScalAddExpr< Left, Right, typename ExprTrait< AddExpr< Left, Right > >::numeric_type > operator-(const AddExpr< Left, Right > &expr)
Negated addition expression factor.
Definition: add_expr.h:266
TILEDARRAY_FORCE_INLINE R conj(const R r)
Wrapper function for std::conj
Definition: complex.h:44
Subtraction expression.
Definition: subt_engine.h:37
scalar_t< typename EngineTrait< engine_type >::eval_type > scalar_type
Subtraction result scalar type.
Definition: subt_expr.h:63
ComplexConjugate< S > conj_op(const S factor)
ComplexConjugate operator factory function.
Definition: complex.h:181
ScalSubtEngine< typename ExprTrait< Left >::engine_type, typename ExprTrait< Right >::engine_type, Scalar, result_type > engine_type
Expression engine type.
Definition: subt_expr.h:77
ScalSubtExpr(const left_type &left, const right_type &right, const scalar_type factor)
Expression constructor.
Definition: subt_expr.h:148
decltype(subt(std::declval< T >()...)) result_of_subt_t
ExprTrait< SubtExpr_ >::left_type left_type
The left-hand expression type.
Definition: subt_expr.h:93
ScalSubtExpr< Left, Right, TiledArray::detail::ComplexConjugate< void > > ConjSubtExpr
Definition: subt_expr.h:38
result_of_subt_t< typename EngineTrait< typename ExprTrait< Left >::engine_type >::eval_type, typename EngineTrait< typename ExprTrait< Right >::engine_type >::eval_type, scalar_type > result_type
Result tile type.
Definition: subt_expr.h:74