MPQC  3.0.0-alpha
ref.hpp
1 #ifndef MPQC_MATH_TENSOR_REF_HPP
2 #define MPQC_MATH_TENSOR_REF_HPP
3 
4 #include "mpqc/math/tensor/base.hpp"
5 #include "mpqc/math/tensor/functional.hpp"
6 
7 namespace mpqc {
8 
11 
14  template<typename T, size_t N, class Order = TensorColumnMajor >
15  struct TensorRef : TensorBase<T,N,Order> {
16 
17  public:
18 
19  TensorRef(T *data, const size_t (&dims)[N])
20  : TensorBase<T,N,Order>(data, dims) {}
21 
22  T* data() { return this->data_; }
23  const T* data() const { return this->data_; }
24 
25  public:
26 
29  size_t size = this->size();
30  std::copy(u.data(), u.data()+size, this->data());
31  }
32 
34  template<typename U>
36  size_t size = this->size();
37  std::copy(u.data(), u.data()+size, this->data());
38  }
39 
41  template<typename U>
43  this->apply(detail::Tensor::plus_assign(), u.data());
44  }
45 
47  template<typename U>
49  this->apply(detail::Tensor::minus_assign(), u.data());
50  }
51 
53  template<typename U>
54  TensorRef& operator*=(const U &u) {
55  this->apply(detail::Tensor::multiply_assign<U>(u));
56  }
57 
59  template<typename U>
60  TensorRef& operator/=(const U &u) {
61  this->apply(detail::Tensor::divide_assign<U>(u));
62  }
63 
64  protected:
65 
66  template<class F>
67  F apply(F f) {
68  size_t size = this->size();
69  for (size_t i = 0; i < size; ++i) {
70  f(this->data_[i]);
71  }
72  return f;
73  }
74 
75  template<class F, typename Iterator>
76  F apply(F f, Iterator it) {
77  size_t size = this->size();
78  for (size_t i = 0; i < size; ++i) {
79  f(this->data_[i], *it++);
80  }
81  return f;
82  }
83 
84  };
85 
87 
88 }
89 
90 
91 #endif /* MPQC_MATH_TENSOR_REF_HPP */
mpqc
Contains new MPQC code since version 3.
Definition: integralenginepool.hpp:37
mpqc::detail::Tensor::divide_assign
Definition: functional.hpp:70
mpqc::TensorRef::operator=
TensorRef & operator=(const TensorRef< U, N, Order > &u)
fast assignment operator
Definition: ref.hpp:35
mpqc::TensorRef::operator-=
TensorRef & operator-=(const TensorRef< U, N, Order > &u)
fast -= operator
Definition: ref.hpp:48
mpqc::TensorRef
Tensor reference class.
Definition: ref.hpp:15
mpqc::TensorRef::operator/=
TensorRef & operator/=(const U &u)
fast /= operator
Definition: ref.hpp:60
mpqc::TensorRef::operator*=
TensorRef & operator*=(const U &u)
fast *= operator
Definition: ref.hpp:54
mpqc::detail::Tensor::minus_assign
Definition: functional.hpp:87
mpqc::TensorRef::operator+=
TensorRef & operator+=(const TensorRef< U, N, Order > &u)
fast += operator
Definition: ref.hpp:42
mpqc::TensorBase
Tensor base class.
Definition: base.hpp:32
mpqc::detail::Tensor::multiply_assign
Definition: functional.hpp:59
mpqc::detail::Tensor::plus_assign
Definition: functional.hpp:80
mpqc::TensorRef::operator=
TensorRef & operator=(const TensorRef &u)
fast assignment operator
Definition: ref.hpp:28

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