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 #ifndef TILEDARRAY_EXPRESSIONS_SUBT_EXPR_H__INCLUDED
27 #define TILEDARRAY_EXPRESSIONS_SUBT_EXPR_H__INCLUDED
28 
31 
32 namespace TiledArray {
33 namespace expressions {
34 
35 template <typename Left, typename Right>
36 using ConjSubtExpr =
38 
39 template <typename Left, typename Right, typename Scalar>
42 
47 
48 template <typename Left, typename Right>
49 struct ExprTrait<SubtExpr<Left, Right> > {
50  typedef Left left_type;
51  typedef Right right_type;
52  typedef result_of_subt_t<
59  typedef numeric_t<typename EngineTrait<engine_type>::eval_type>
61  typedef scalar_t<typename EngineTrait<engine_type>::eval_type>
63 };
64 
65 template <typename Left, typename Right, typename Scalar>
66 struct ExprTrait<ScalSubtExpr<Left, Right, Scalar> > {
67  typedef Left left_type;
68  typedef Right right_type;
69  typedef Scalar scalar_type;
70  typedef result_of_subt_t<
76  typename ExprTrait<Right>::engine_type, Scalar,
79  typedef numeric_t<typename EngineTrait<engine_type>::eval_type>
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;
105 
107 
110  SubtExpr(const left_type& left, const right_type& right)
111  : BinaryExpr_(left, right) {}
112 
113 }; // class SubtExpr
114 
116 
119 template <typename Left, typename Right, typename Scalar>
120 class ScalSubtExpr : public BinaryExpr<ScalSubtExpr<Left, Right, Scalar> > {
121  public:
124  typedef typename ExprTrait<ScalSubtExpr_>::left_type
126  typedef typename ExprTrait<ScalSubtExpr_>::right_type
132 
133  private:
134  scalar_type factor_;
135 
136  public:
137  // Compiler generated functions
138  ScalSubtExpr(const ScalSubtExpr_&) = default;
140  ~ScalSubtExpr() = default;
143 
145 
149  ScalSubtExpr(const left_type& left, const right_type& right,
150  const scalar_type factor)
151  : BinaryExpr_(left, right), factor_(factor) {}
152 
154 
156  scalar_type factor() const { return factor_; }
157 
158 }; // class ScalSubtExpr
159 
161 
163 
169 template <typename Left, typename Right>
171  const Expr<Right>& right) {
172  static_assert(
174  "no_alias() expressions are not allowed on the right-hand side of "
175  "the assignment operator.");
176  static_assert(
178  "no_alias() expressions are not allowed on the right-hand side of "
179  "the assignment operator.");
180  return SubtExpr<Left, Right>(left.derived(), right.derived());
181 }
182 
184 
191 template <typename Left, typename Right, typename Scalar,
192  typename std::enable_if<
193  TiledArray::detail::is_numeric_v<Scalar> >::type* = nullptr>
195  const SubtExpr<Left, Right>& expr, const Scalar& factor) {
196  return ScalSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(), factor);
197 }
198 
200 
207 template <typename Left, typename Right, typename Scalar,
208  typename std::enable_if<
209  TiledArray::detail::is_numeric_v<Scalar> >::type* = nullptr>
211  const Scalar& factor, const SubtExpr<Left, Right>& expr) {
212  return ScalSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(), factor);
213 }
214 
216 
224 template <typename Left, typename Right, typename Scalar1, typename Scalar2,
225  typename std::enable_if<
226  TiledArray::detail::is_numeric_v<Scalar2> >::type* = nullptr>
228  const ScalSubtExpr<Left, Right, Scalar1>& expr, const Scalar2& factor) {
230  expr.left(), expr.right(), expr.factor() * factor);
231 }
232 
234 
242 template <typename Left, typename Right, typename Scalar1, typename Scalar2,
243  typename std::enable_if<
244  TiledArray::detail::is_numeric_v<Scalar1> >::type* = nullptr>
246  const Scalar1& factor, const ScalSubtExpr<Left, Right, Scalar2>& expr) {
248  expr.left(), expr.right(), expr.factor() * factor);
249 }
250 
252 
257 template <typename Left, typename Right>
258 inline ScalSubtExpr<Left, Right,
259  typename ExprTrait<SubtExpr<Left, Right> >::numeric_type>
261  return ScalSubtExpr<Left, Right,
262  typename ExprTrait<SubtExpr<Left, Right> >::numeric_type>(
263  expr.left(), expr.right(), -1);
264 }
265 
267 
272 template <typename Left, typename Right, typename Scalar>
274  const ScalSubtExpr<Left, Right, Scalar>& expr) {
275  return ScalSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(), -1);
276 }
277 
279 
284 template <typename Left, typename Right>
286  return ConjSubtExpr<Left, Right>(expr.left(), expr.right(), conj_op());
287 }
288 
290 
295 template <typename Left, typename Right>
297  return SubtExpr<Left, Right>(expr.left(), expr.right());
298 }
299 
301 
307 template <typename Left, typename Right, typename Scalar>
309  const ScalSubtExpr<Left, Right, Scalar>& expr) {
311  expr.left(), expr.right(),
313 }
314 
316 
322 template <typename Left, typename Right, typename Scalar>
326  expr.left(), expr.right(),
327  TiledArray::detail::conj(expr.factor().factor()));
328 }
329 
331 
338 template <typename Left, typename Right, typename Scalar,
339  typename std::enable_if<
340  TiledArray::detail::is_numeric_v<Scalar> >::type* = nullptr>
342  const ConjSubtExpr<Left, Right>& expr, const Scalar& factor) {
343  return ScalConjSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(),
344  conj_op(factor));
345 }
346 
348 
355 template <typename Left, typename Right, typename Scalar,
356  typename std::enable_if<
357  TiledArray::detail::is_numeric_v<Scalar> >::type* = nullptr>
359  const Scalar& factor, const ConjSubtExpr<Left, Right>& expr) {
360  return ScalConjSubtExpr<Left, Right, Scalar>(expr.left(), expr.right(),
361  conj_op(factor));
362 }
363 
365 
373 template <typename Left, typename Right, typename Scalar1, typename Scalar2,
374  typename std::enable_if<
375  TiledArray::detail::is_numeric_v<Scalar2> >::type* = nullptr>
377  const ScalConjSubtExpr<Left, Right, Scalar1>& expr, const Scalar2& factor) {
379  expr.left(), expr.right(), conj_op(expr.factor().factor() * factor));
380 }
381 
383 
391 template <typename Left, typename Right, typename Scalar1, typename Scalar2,
392  typename std::enable_if<
393  TiledArray::detail::is_numeric_v<Scalar1> >::type* = nullptr>
395  const Scalar1& factor, const ScalConjSubtExpr<Left, Right, Scalar2>& expr) {
397  expr.left(), expr.right(), conj_op(expr.factor().factor() * factor));
398 }
399 
401 
406 template <typename Left, typename Right>
407 inline ScalConjSubtExpr<
408  Left, Right, typename ExprTrait<ConjSubtExpr<Left, Right> >::numeric_type>
410  typedef
411  typename ExprTrait<ConjSubtExpr<Left, Right> >::numeric_type scalar_type;
412  return ScalConjSubtExpr<Left, Right, scalar_type>(expr.left(), expr.right(),
413  conj_op<scalar_type>(-1));
414 }
415 
417 
423 template <typename Left, typename Right, typename Scalar>
427  expr.left(), expr.right(), conj_op(-expr.factor().factor()));
428 }
429 
430 } // namespace expressions
431 } // namespace TiledArray
432 
433 #endif // TILEDARRAY_EXPRESSIONS_SUBT_EXPR_H__INCLUDED
numeric_t< typename EngineTrait< engine_type >::eval_type > numeric_type
Subtraction result numeric type.
Definition: subt_expr.h:60
ScalSubtExpr_ & operator=(const ScalSubtExpr_ &)=delete
Right right_type
The right-hand expression type.
Definition: subt_expr.h:51
ScalAddExpr< Left, Right, typename ExprTrait< AddExpr< Left, Right > >::numeric_type > operator-(const AddExpr< Left, Right > &expr)
Negated addition expression factor.
Definition: add_expr.h:255
ScalSubtExpr(ScalSubtExpr_ &&)=default
ScalSubtExpr_ & operator=(ScalSubtExpr_ &&)=delete
typename TiledArray::detail::numeric_type< T >::type numeric_t
numeric_t<T> is an alias for numeric_type<T>::type
Definition: type_traits.h:730
decltype(std::declval< Scalar1 >() *std::declval< Scalar2 >()) mult_t
Definition: type_traits.h:1159
SubtExpr(const left_type &left, const right_type &right)
Expression constructor.
Definition: subt_expr.h:110
BinaryExpr< SubtExpr_ > BinaryExpr_
Binary base class type.
Definition: subt_expr.h:91
SubtExpr(SubtExpr_ &&)=default
ExprTrait< SubtExpr_ >::right_type right_type
The right-hand expression type.
Definition: subt_expr.h:95
SubtEngine< typename ExprTrait< Left >::engine_type, typename ExprTrait< Right >::engine_type, result_type > engine_type
Expression engine type.
Definition: subt_expr.h:58
Subtraction expression.
Definition: subt_expr.h:88
Base class for expression evaluation.
Definition: expr.h:97
numeric_t< typename EngineTrait< engine_type >::eval_type > numeric_type
Subtraction result numeric type.
Definition: subt_expr.h:80
Binary expression object.
Definition: binary_expr.h:39
std::enable_if< TiledArray::detail::is_numeric_v< Scalar >, ScalAddExpr< Left, Right, Scalar > >::type operator*(const AddExpr< Left, Right > &expr, const Scalar &factor)
Scaled-addition expression factor.
Definition: add_expr.h:191
scalar_type factor() const
Scaling factor accessor.
Definition: subt_expr.h:156
SubtExpr_ & operator=(SubtExpr_ &&)=delete
BinaryExpr< ScalSubtExpr_ > BinaryExpr_
Binary base class type.
Definition: subt_expr.h:123
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:55
ScalSubtExpr< Left, Right, TiledArray::detail::ComplexConjugate< Scalar > > ScalConjSubtExpr
Definition: subt_expr.h:41
SubtExpr< Left, Right > SubtExpr_
Definition: subt_expr.h:90
ConjAddExpr< Left, Right > conj(const AddExpr< Left, Right > &expr)
Conjugated addition expression factory.
Definition: add_expr.h:281
ExprTrait< ScalSubtExpr_ >::scalar_type scalar_type
Scalar type.
Definition: subt_expr.h:131
typename TiledArray::detail::scalar_type< T >::type scalar_t
scalar_t<T> is an alias for scalar_type<T>::type
Definition: type_traits.h:760
scalar_t< typename EngineTrait< engine_type >::eval_type > scalar_type
Subtraction result scalar type.
Definition: subt_expr.h:62
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(const ScalSubtExpr_ &)=default
Subtraction expression engine.
Definition: subt_engine.h:219
ExprTrait< ScalSubtExpr_ >::right_type right_type
The right-hand expression type.
Definition: subt_expr.h:127
ScalSubtExpr(const left_type &left, const right_type &right, const scalar_type factor)
Expression constructor.
Definition: subt_expr.h:149
SubtExpr(const SubtExpr_ &)=default
ExprTrait< ScalSubtExpr_ >::engine_type engine_type
Expression engine type.
Definition: subt_expr.h:129
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
ScalSubtExpr< Left, Right, Scalar > ScalSubtExpr_
This class type.
Definition: subt_expr.h:122
ExprTrait< SubtExpr_ >::engine_type engine_type
Expression engine type.
Definition: subt_expr.h:97
ComplexConjugate< S > conj_op(const S factor)
ComplexConjugate operator factory function.
Definition: complex.h:204
Subtraction expression.
Definition: subt_expr.h:120
Subtraction expression engine.
Definition: subt_engine.h:129
SubtExpr_ & operator=(const SubtExpr_ &)=delete
ScalSubtEngine< typename ExprTrait< Left >::engine_type, typename ExprTrait< Right >::engine_type, Scalar, result_type > engine_type
Expression engine type.
Definition: subt_expr.h:78
TILEDARRAY_FORCE_INLINE R conj(const R r)
Wrapper function for std::conj
Definition: complex.h:45
derived_type & derived()
Cast this object to its derived type.
Definition: expr.h:365
ExprTrait< ScalSubtExpr_ >::left_type left_type
The left-hand expression type.
Definition: subt_expr.h:125