MPQC  3.0.0-alpha
functional.hpp
1 #ifndef MPQC_MATH_TENSOR_FUNCTIONAL_HPP
2 #define MPQC_MATH_TENSOR_FUNCTIONAL_HPP
3 
4 #include "mpqc/math/tensor/forward.hpp"
5 #include "mpqc/math/tensor/exception.hpp"
6 
7 #include <boost/mpl/int.hpp>
8 #include <boost/fusion/include/vector.hpp>
9 
10 namespace mpqc {
11 namespace detail {
12 namespace Tensor {
13 
14  template<class F, typename T, typename U, size_t N, class Order, class Seq>
15  void apply(F f, TensorBase<T,N,Order> t, TensorBase<U,N,Order> u,
16  const integral_tie<Seq> &idx) {
17  f(t(idx), u(idx));
18  }
19 
20  template<class F, typename T, typename U, size_t N, class Order, class Seq>
21  void apply(F f, TensorBase<T,N,Order> t, TensorBase<U,N,Order> u,
22  boost::mpl::int_<0>, const Seq &idx) {
23  typedef integral_tie<Seq> tie;
24  f(t(tie(idx)), u(tie(idx)));
25  }
26 
27  template<class F, typename T, typename U, size_t N, class Order,
28  class Seq, int I>
29  void apply(F f, TensorBase<T,N,Order> t, TensorBase<U,N,Order> u,
30  boost::mpl::int_<I>, const Seq &idx) {
31 #ifndef NDEBUG
32  if (t.dims()[I-1] != u.dims()[I-1]) {
33  throw TensorDimensionsException(I-1, t.dims()[I-1], u.dims()[I-1]);
34  }
35 #endif
36  int n = t.dims()[I-1];
37  for (int i = 0; i < n; ++i) {
38  apply(f, t, u, boost::mpl::int_<I-1>(),
39  boost::fusion::push_front(idx, boost::cref(i)));
40  }
41  }
42 
43  template<class F, typename T, typename U, size_t N, class Order>
44  void apply(F f, TensorBase<T,N,Order> t, TensorBase<U,N,Order> u) {
45  apply(f, t, u, boost::mpl::int_<N>(), boost::fusion::vector<>());
46  }
47 
50 
51  struct assign {
52  template <typename T, typename U>
53  void operator()(T &t, const U &u) const {
54  t = u;
55  }
56  };
57 
58  template<typename S>
59  struct multiply_assign {
60  multiply_assign(const S &s) : value_(s) {}
61  template <typename T>
62  void operator()(T &t) const {
63  t *= value_;
64  }
65  private:
66  S value_;
67  };
68 
69  template<typename S>
70  struct divide_assign {
71  divide_assign(const S &s) : value_(s) {}
72  template <typename T>
73  void operator()(T &t) const {
74  t /= value_;
75  }
76  private:
77  S value_;
78  };
79 
80  struct plus_assign {
81  template <typename T, typename S>
82  void operator()(T &t, const S &s) const {
83  t += s;
84  }
85  };
86 
87  struct minus_assign {
88  template <typename T, typename S>
89  void operator()(T &t, const S &s) const {
90  t -= s;
91  }
92  };
93 
95 
96 }
97 }
98 }
99 
100 #endif /* MPQC_MATH_TENSOR_FUNCTIONAL_HPP */
mpqc
Contains new MPQC code since version 3.
Definition: integralenginepool.hpp:37
mpqc::detail::Tensor::divide_assign
Definition: functional.hpp:70
mpqc::detail::Tensor::assign
Definition: functional.hpp:51
mpqc::detail::Tensor::minus_assign
Definition: functional.hpp:87
mpqc::detail::Tensor::multiply_assign
Definition: functional.hpp:59
mpqc::detail::Tensor::plus_assign
Definition: functional.hpp:80

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.