TiledArray  0.7.0
scal_tsr_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  * scal_tsr_expr.h
22  * Apr 1, 2014
23  *
24  */
25 
26 
27 #ifndef TILEDARRAY_EXPRESSIONS_SCAL_TSR_EXPR_H__INCLUDED
28 #define TILEDARRAY_EXPRESSIONS_SCAL_TSR_EXPR_H__INCLUDED
29 
31 
32 namespace TiledArray {
33  namespace expressions {
34 
35  template <typename Array>
37 
38  template <typename Array, typename Scalar>
40 
44 
45  template <typename, typename> class ScalTsrExpr;
46 
47  template <typename Array, typename Scalar>
48  struct ExprTrait<ScalTsrExpr<Array, Scalar> > {
49  typedef Array array_type;
50  typedef Scalar scalar_type;
52  typename Array::eval_type, scalar_type>
58  };
59 
61 
64  template <typename Array, typename Scalar>
65  class ScalTsrExpr : public Expr<ScalTsrExpr<Array, Scalar> > {
66  public:
72 
73  private:
74 
75  const array_type& array_;
76  std::string vars_;
77  scalar_type factor_;
78 
79  // Not allowed
80  ScalTsrExpr_& operator=(ScalTsrExpr_&);
81 
82  public:
83 
84  // Compiler generated functions
85  ScalTsrExpr(const ScalTsrExpr_&) = default;
86  ScalTsrExpr(ScalTsrExpr_&&) = default;
87  ~ScalTsrExpr() = default;
88  ScalTsrExpr_& operator=(const ScalTsrExpr_&) = delete;
89  ScalTsrExpr_& operator=(ScalTsrExpr_&&) = delete;
90 
92 
96  ScalTsrExpr(const array_type& array, const std::string& vars,
97  const scalar_type factor) :
98  Expr_(), array_(array), vars_(vars), factor_(factor)
99  { }
100 
102 
104  const array_type& array() const { return array_; }
105 
107 
109  const std::string& vars() const { return vars_; }
110 
111 
113 
115  scalar_type factor() const { return factor_; }
116 
117  }; // class ScalTsrExpr
118 
120 
126  template <typename Array, typename Scalar,
127  typename std::enable_if<
129  >::type* = nullptr>
130  inline ScalTsrExpr<typename std::remove_const<Array>::type, Scalar>
131  operator*(const TsrExpr<Array, true>& expr, const Scalar& factor) {
133  expr.array(), expr.vars(), factor);
134  }
135 
137 
143  template <typename Array, typename Scalar,
144  typename std::enable_if<
146  >::type* = nullptr>
147  inline ScalTsrExpr<typename std::remove_const<Array>::type, Scalar>
148  operator*(const Scalar& factor, const TsrExpr<Array, true>& expr) {
150  expr.array(), expr.vars(), factor);
151  }
152 
154 
161  template <typename Array, typename Scalar1, typename Scalar2,
162  typename std::enable_if<
164  >::type* = nullptr>
165  inline ScalTsrExpr<Array, mult_t<Scalar1, Scalar2> >
166  operator*(const ScalTsrExpr<Array, Scalar1>& expr, const Scalar2& factor) {
168  expr.vars(), expr.factor() * factor);
169  }
170 
172 
179  template <typename Array, typename Scalar1, typename Scalar2,
180  typename std::enable_if<
182  >::type* = nullptr>
183  inline ScalTsrExpr<Array, mult_t<Scalar2, Scalar1> >
184  operator*(const Scalar1& factor, const ScalTsrExpr<Array, Scalar2>& expr) {
186  expr.vars(), expr.factor() * factor);
187  }
188 
190 
194  template <typename Array>
195  inline ScalTsrExpr<typename std::remove_const<Array>::type,
196  typename ExprTrait<TsrExpr<Array, true> >::numeric_type>
199  typename ExprTrait<TsrExpr<Array, true> >::numeric_type>(
200  expr.array(), expr.vars(), -1);
201  }
202 
204 
209  template <typename Array, typename Scalar>
210  inline ScalTsrExpr<Array, Scalar>
212  return ScalTsrExpr<Array, Scalar>(expr.array(), expr.vars(), -expr.factor());
213  }
214 
216 
220  template <typename Array>
221  inline ConjTsrExpr<typename std::remove_const<Array>::type>
222  conj(const TsrExpr<Array, true>& expr) {
224  expr.vars(), conj_op());
225  }
226 
228 
232  template <typename Array>
234  return TsrExpr<const Array, true>(expr.array(), expr.vars());
235  }
236 
238 
243  template <typename Array, typename Scalar>
245  return ScalConjTsrExpr<Array, Scalar>(expr.array(), expr.vars(),
247  }
248 
250 
255  template <typename Array, typename Scalar>
256  inline ScalTsrExpr<Array, Scalar>
258  return ScalTsrExpr<Array, Scalar>(expr.array(), expr.vars(),
259  TiledArray::detail::conj(expr.factor().factor()));
260  }
261 
263 
269  template <typename Array, typename Scalar,
270  typename std::enable_if<
272  >::type* = nullptr>
273  inline ScalConjTsrExpr<Array, Scalar>
274  operator*(const ConjTsrExpr<const Array>& expr, const Scalar& factor) {
275  return ScalConjTsrExpr<Array, Scalar>(expr.array(), expr.vars(),
276  conj_op(factor));
277  }
278 
280 
286  template <typename Array, typename Scalar,
287  typename std::enable_if<
289  >::type* = nullptr>
290  inline ScalConjTsrExpr<Array, Scalar>
291  operator*(const Scalar& factor, const ConjTsrExpr<Array>& expr) {
292  return ScalConjTsrExpr<Array, Scalar>(expr.array(), expr.vars(),
293  conj_op(factor));
294  }
295 
297 
303  template <typename Array, typename Scalar1, typename Scalar2,
304  typename std::enable_if<
306  >::type* = nullptr>
307  inline ScalConjTsrExpr<Array, mult_t<Scalar1, Scalar2> >
308  operator*(const ScalConjTsrExpr<Array, Scalar1>& expr, const Scalar2& factor) {
310  expr.vars(), conj_op(expr.factor().factor() * factor));
311  }
312 
314 
320  template <typename Array, typename Scalar1, typename Scalar2,
321  typename std::enable_if<
323  >::type* = nullptr>
324  inline ScalConjTsrExpr<Array, mult_t<Scalar2, Scalar1> >
325  operator*(const Scalar1& factor, const ScalConjTsrExpr<Array, Scalar2>& expr) {
327  expr.vars(), conj_op(expr.factor().factor() * factor));
328  }
329 
331 
335  template <typename Array>
336  inline ScalConjTsrExpr<Array, typename ExprTrait<ConjTsrExpr<Array> >::numeric_type>
338  typedef typename ExprTrait<ConjTsrExpr<Array> >::numeric_type
339  numeric_type;
340  return ScalConjTsrExpr<Array, numeric_type>(expr.array(), expr.vars(),
341  conj_op<numeric_type>(-1));
342  }
343 
345 
350  template <typename Array, typename Scalar>
351  inline ScalConjTsrExpr<Array, Scalar>
353  return ScalConjTsrExpr<Array, Scalar>(expr.array(), expr.vars(),
354  conj_op(-expr.factor().factor()));
355  }
356 
357  } // namespace expressions
358 } // namespace TiledArray
359 
360 #endif // TILEDARRAY_EXPRESSIONS_SCAL_TSR_EXPR_H__INCLUDED
Expression wrapper for scaled array objects.
const std::string & vars() const
Tensor variable string accessor.
Definition: tsr_expr.h:239
ExprTrait< ScalTsrExpr_ >::engine_type engine_type
Expression engine type.
Definition: scal_tsr_expr.h:70
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
Scaled tensor expression engine.
decltype(std::declval< Scalar1 >() *std::declval< Scalar2 >()) mult_t
Definition: type_traits.h:748
decltype(scale(std::declval< T >()...)) result_of_scale_t
Definition: scale.h:76
ScalTsrEngine< Array, scalar_type, result_type > engine_type
Expression engine type.
Definition: scal_tsr_expr.h:55
typename TiledArray::detail::numeric_type< T >::type numeric_t
Definition: type_traits.h:525
ScalTsrExpr< Array, Scalar > ScalTsrExpr_
This class type.
Definition: scal_tsr_expr.h:67
Expression wrapper for array objects.
Definition: dist_array.h:39
const array_type & array() const
Array accessor.
Forward declarations.
Definition: clone.h:32
ExprTrait< ScalTsrExpr_ >::scalar_type scalar_type
Scalar type.
Definition: scal_tsr_expr.h:71
Expr< ScalTsrExpr_ > Expr_
Expression base type.
Definition: scal_tsr_expr.h:68
scalar_type factor() const
Scaling factor accessor.
Base class for expression evaluation.
Definition: expr.h:81
ConjAddExpr< Left, Right > conj(const AddExpr< Left, Right > &expr)
Conjugated addition expression factory.
Definition: add_expr.h:292
ScalTsrExpr(const array_type &array, const std::string &vars, const scalar_type factor)
Construct a scaled tensor expression.
Definition: scal_tsr_expr.h:96
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
const std::string & vars() const
Tensor variable string accessor.
TILEDARRAY_FORCE_INLINE R conj(const R r)
Wrapper function for std::conj
Definition: complex.h:44
Expression wrapper for const array objects.
Definition: tsr_expr.h:248
ComplexConjugate< S > conj_op(const S factor)
ComplexConjugate operator factory function.
Definition: complex.h:181
ExprTrait< ScalTsrExpr_ >::array_type array_type
The array type.
Definition: scal_tsr_expr.h:69
TiledArray::tile_interface::result_of_scale_t< typename Array::eval_type, scalar_type > result_type
Result tile type.
Definition: scal_tsr_expr.h:53
ScalTsrExpr(const ScalTsrExpr_ &)=default
impl_type::eval_type eval_type
The tile evaluation type.
Definition: dist_array.h:65
array_type & array() const
Array accessor.
Definition: tsr_expr.h:173
DistArray< Tile, Policy > Array
TiledArray::detail::numeric_t< Array > numeric_type
Array base numeric type.
Definition: scal_tsr_expr.h:57