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 #ifndef TILEDARRAY_EXPRESSIONS_SCAL_TSR_EXPR_H__INCLUDED
27 #define TILEDARRAY_EXPRESSIONS_SCAL_TSR_EXPR_H__INCLUDED
28 
30 
31 namespace TiledArray {
32 namespace expressions {
33 
34 template <typename Array>
35 using ConjTsrExpr =
37 
38 template <typename Array, typename Scalar>
41 
45 
46 template <typename, typename>
47 class ScalTsrExpr;
48 
49 template <typename Array, typename Scalar>
50 struct ExprTrait<ScalTsrExpr<Array, Scalar> > {
51  typedef Array array_type;
52  typedef Scalar scalar_type;
54  typename Array::eval_type, scalar_type>
60 };
61 
63 
66 template <typename Array, typename Scalar>
67 class ScalTsrExpr : public Expr<ScalTsrExpr<Array, Scalar> > {
68  public:
77 
78  private:
79  const array_type& array_;
80  std::string annotation_;
81  scalar_type factor_;
82 
83  // Not allowed
84  ScalTsrExpr_& operator=(ScalTsrExpr_&);
85 
86  public:
87  // Compiler generated functions
88  ScalTsrExpr(const ScalTsrExpr_&) = default;
89  ScalTsrExpr(ScalTsrExpr_&&) = default;
90  ~ScalTsrExpr() = default;
91  ScalTsrExpr_& operator=(const ScalTsrExpr_&) = delete;
93 
95 
99  ScalTsrExpr(const array_type& array, const std::string& annotation,
100  const scalar_type factor)
101  : Expr_(), array_(array), annotation_(annotation), factor_(factor) {}
102 
104 
106  const array_type& array() const { return array_; }
107 
109 
111  const std::string& annotation() const { return annotation_; }
112 
114 
116  scalar_type factor() const { return factor_; }
117 
118 }; // class ScalTsrExpr
119 
121 
127 template <typename Array, typename Scalar,
128  typename std::enable_if<
129  TiledArray::detail::is_numeric_v<Scalar> >::type* = nullptr>
131  const TsrExpr<Array, true>& expr, const Scalar& factor) {
133  expr.array(), expr.annotation(), factor);
134 }
135 
137 
143 template <typename Array, typename Scalar,
144  typename std::enable_if<
145  TiledArray::detail::is_numeric_v<Scalar> >::type* = nullptr>
147  const Scalar& factor, const TsrExpr<Array, true>& expr) {
149  expr.array(), expr.annotation(), factor);
150 }
151 
153 
160 template <typename Array, typename Scalar1, typename Scalar2,
161  typename std::enable_if<
162  TiledArray::detail::is_numeric_v<Scalar2> >::type* = nullptr>
164  const ScalTsrExpr<Array, Scalar1>& expr, const Scalar2& factor) {
166  expr.array(), expr.annotation(), expr.factor() * factor);
167 }
168 
170 
177 template <typename Array, typename Scalar1, typename Scalar2,
178  typename std::enable_if<
179  TiledArray::detail::is_numeric_v<Scalar1> >::type* = nullptr>
181  const Scalar1& factor, const ScalTsrExpr<Array, Scalar2>& expr) {
183  expr.array(), expr.annotation(), expr.factor() * factor);
184 }
185 
187 
191 template <typename Array>
192 inline ScalTsrExpr<typename std::remove_const<Array>::type,
193  typename ExprTrait<TsrExpr<Array, true> >::numeric_type>
196  typename ExprTrait<TsrExpr<Array, true> >::numeric_type>(
197  expr.array(), expr.annotation(), -1);
198 }
199 
201 
206 template <typename Array, typename Scalar>
208  const ScalTsrExpr<Array, Scalar>& expr) {
209  return ScalTsrExpr<Array, Scalar>(expr.array(), expr.annotation(),
210  -expr.factor());
211 }
212 
214 
218 template <typename Array>
220  const TsrExpr<Array, true>& expr) {
222  expr.array(), expr.annotation(), conj_op());
223 }
224 
226 
230 template <typename Array>
232  return TsrExpr<const Array, true>(expr.array(), expr.annotation());
233 }
234 
236 
241 template <typename Array, typename Scalar>
243  const ScalTsrExpr<Array, Scalar>& expr) {
245  expr.array(), expr.annotation(),
247 }
248 
250 
255 template <typename Array, typename Scalar>
257  const ScalConjTsrExpr<Array, Scalar>& expr) {
259  expr.array(), expr.annotation(),
260  TiledArray::detail::conj(expr.factor().factor()));
261 }
262 
264 
270 template <typename Array, typename Scalar,
271  typename std::enable_if<
272  TiledArray::detail::is_numeric_v<Scalar> >::type* = nullptr>
274  const ConjTsrExpr<const Array>& expr, const Scalar& factor) {
275  return ScalConjTsrExpr<Array, Scalar>(expr.array(), expr.annotation(),
276  conj_op(factor));
277 }
278 
280 
286 template <typename Array, typename Scalar,
287  typename std::enable_if<
288  TiledArray::detail::is_numeric_v<Scalar> >::type* = nullptr>
290  const Scalar& factor, const ConjTsrExpr<Array>& expr) {
291  return ScalConjTsrExpr<Array, Scalar>(expr.array(), expr.annotation(),
292  conj_op(factor));
293 }
294 
296 
302 template <typename Array, typename Scalar1, typename Scalar2,
303  typename std::enable_if<
304  TiledArray::detail::is_numeric_v<Scalar2> >::type* = nullptr>
306  const ScalConjTsrExpr<Array, Scalar1>& expr, const Scalar2& factor) {
308  expr.array(), expr.annotation(),
309  conj_op(expr.factor().factor() * factor));
310 }
311 
313 
319 template <typename Array, typename Scalar1, typename Scalar2,
320  typename std::enable_if<
321  TiledArray::detail::is_numeric_v<Scalar1> >::type* = nullptr>
323  const Scalar1& factor, const ScalConjTsrExpr<Array, Scalar2>& expr) {
325  expr.array(), expr.annotation(),
326  conj_op(expr.factor().factor() * factor));
327 }
328 
330 
334 template <typename Array>
335 inline ScalConjTsrExpr<Array,
336  typename ExprTrait<ConjTsrExpr<Array> >::numeric_type>
338  typedef typename ExprTrait<ConjTsrExpr<Array> >::numeric_type numeric_type;
340  conj_op<numeric_type>(-1));
341 }
342 
344 
349 template <typename Array, typename Scalar>
351  const ScalConjTsrExpr<Array, Scalar>& expr) {
352  return ScalConjTsrExpr<Array, Scalar>(expr.array(), expr.annotation(),
353  conj_op(-expr.factor().factor()));
354 }
355 
356 } // namespace expressions
357 } // namespace TiledArray
358 
359 #endif // TILEDARRAY_EXPRESSIONS_SCAL_TSR_EXPR_H__INCLUDED
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
Expr< ScalTsrExpr_ > Expr_
Expression base type.
Definition: scal_tsr_expr.h:70
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
array_type & array() const
Array accessor.
Definition: tsr_expr.h:175
Expression wrapper for array objects.
Definition: tsr_expr.h:83
TiledArray::tile_interface::result_of_scale_t< typename Array::eval_type, scalar_type > result_type
Result tile type.
Definition: scal_tsr_expr.h:55
ScalTsrExpr(const array_type &array, const std::string &annotation, const scalar_type factor)
Construct a scaled tensor expression.
Definition: scal_tsr_expr.h:99
ScalTsrEngine< Array, scalar_type, result_type > engine_type
Expression engine type.
Definition: scal_tsr_expr.h:57
Base class for expression evaluation.
Definition: expr.h:97
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
ExprTrait< ScalTsrExpr_ >::engine_type engine_type
Expression engine type.
Definition: scal_tsr_expr.h:74
decltype(scale(std::declval< T >()...)) result_of_scale_t
Definition: scale.h:80
const array_type & array() const
Array accessor.
impl_type::eval_type eval_type
The tile evaluation type.
Definition: dist_array.h:88
ConjAddExpr< Left, Right > conj(const AddExpr< Left, Right > &expr)
Conjugated addition expression factory.
Definition: add_expr.h:281
ExprTrait< ScalTsrExpr_ >::array_type array_type
The array type.
Definition: scal_tsr_expr.h:72
ScalTsrExpr_ & operator=(ScalTsrExpr_ &&)=delete
const std::string & annotation() const
Tensor annotation accessor.
DistArray< Tile, Policy > Array
Scaled tensor expression engine.
Forward declarations.
Definition: dist_array.h:57
ScalTsrExpr_ & operator=(const ScalTsrExpr_ &)=delete
ExprTrait< ScalTsrExpr_ >::scalar_type scalar_type
Scalar type.
Definition: scal_tsr_expr.h:76
ScalTsrExpr< Array, TiledArray::detail::ComplexConjugate< Scalar > > ScalConjTsrExpr
Definition: scal_tsr_expr.h:40
Expression wrapper for scaled array objects.
Definition: scal_tsr_expr.h:67
const std::string & annotation() const
Tensor annotation accessor.
Definition: tsr_expr.h:304
ScalTsrExpr(const ScalTsrExpr_ &)=default
ComplexConjugate< S > conj_op(const S factor)
ComplexConjugate operator factory function.
Definition: complex.h:204
TiledArray::detail::numeric_t< Array > numeric_type
Array base numeric type.
Definition: scal_tsr_expr.h:59
scalar_type factor() const
Scaling factor accessor.
Expression wrapper for const array objects.
Definition: tsr_expr.h:312
TILEDARRAY_FORCE_INLINE R conj(const R r)
Wrapper function for std::conj
Definition: complex.h:45
ScalTsrExpr< Array, Scalar > ScalTsrExpr_
This class type.
Definition: scal_tsr_expr.h:69
ScalTsrExpr(ScalTsrExpr_ &&)=default