TiledArray  0.7.0
operators.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2015 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  * operators.h
22  * Jun 16, 2015
23  *
24  */
25 
26 #ifndef TILEDARRAY_TENSOR_OPERATORS_H__INCLUDED
27 #define TILEDARRAY_TENSOR_OPERATORS_H__INCLUDED
28 
30 
31 namespace TiledArray {
32 
33  // Tensor arithmetic operators
34 
36 
43  template <typename T1, typename T2,
44  typename std::enable_if<
45  detail::is_tensor<T1, T2>::value ||
46  detail::is_tensor_of_tensor<T1, T2>::value>::type* = nullptr>
47  inline auto
48  operator+(const T1& left, const T2& right)
49  { return left.add(right); }
50 
52 
59  template <typename T1, typename T2,
60  typename std::enable_if<
61  detail::is_tensor<T1, T2>::value ||
62  detail::is_tensor_of_tensor<T1, T2>::value>::type* = nullptr>
63  inline auto
64  operator-(const T1& left, const T2& right)
65  { return left.subt(right); }
66 
68 
75  template <typename T1, typename T2,
76  typename std::enable_if<
77  detail::is_tensor<T1, T2>::value||
78  detail::is_tensor_of_tensor<T1, T2>::value>::type* = nullptr>
79  inline auto
80  operator*(const T1& left, const T2& right)
81  { return left.mult(right); }
82 
83 
85 
92  template <typename T, typename N,
93  typename std::enable_if<
96  detail::is_numeric<N>::value>::type* = nullptr>
97  inline auto operator*(const T& left, N right)
98  { return left.scale(right); }
99 
101 
107  template <typename N, typename T,
108  typename std::enable_if<
109  detail::is_numeric<N>::value &&
111  detail::is_tensor_of_tensor<T>::value)>::type* = nullptr>
112  inline auto operator*(N left, const T& right)
113  { return right.scale(left); }
114 
116 
120  template <typename T,
121  typename std::enable_if<
123  detail::is_tensor_of_tensor<T>::value>::type* = nullptr>
124  inline auto operator-(const T& arg) -> decltype(arg.neg())
125  { return arg.neg(); }
126 
128 
132  template <typename T,
133  typename std::enable_if<
135  detail::is_tensor_of_tensor<T>::value>::type* = nullptr>
136  inline auto
137  operator*(const Permutation& perm, const T& arg)
138  { return arg.permute(perm); }
139 
141 
148  template <typename T1, typename T2,
149  typename std::enable_if<
150  detail::is_tensor<T1, T2>::value ||
151  detail::is_tensor_of_tensor<T1, T2>::value>::type* = nullptr>
152  inline auto
153  operator+=(T1& left, const T2& right)
154  { return left.add_to(right); }
155 
157 
164  template <typename T1, typename T2,
165  typename std::enable_if<
166  detail::is_tensor<T1, T2>::value ||
167  detail::is_tensor_of_tensor<T1, T2>::value>::type* = nullptr>
168  inline auto
169  operator-=(T1& left, const T2& right)
170  { return left.subt_to(right); }
171 
173 
180  template <typename T1, typename T2,
181  typename std::enable_if<
182  detail::is_tensor<T1, T2>::value||
183  detail::is_tensor_of_tensor<T1, T2>::value>::type* = nullptr>
184  inline auto
185  operator*=(T1& left, const T2& right)
186  { return left.mult_to(right); }
187 
188 
190 
197  template <typename T, typename N,
198  typename std::enable_if<
201  detail::is_numeric<N>::value>::type* = nullptr>
202  inline auto operator+=(T& left, N right)
203  { return left.add_to(right); }
204 
206 
213  template <typename T, typename N,
214  typename std::enable_if<
217  detail::is_numeric<N>::value>::type* = nullptr>
218  inline auto operator-=(T& left, N right)
219  { return left.subt_to(right); }
220 
222 
229  template <typename T, typename N,
230  typename std::enable_if<
233  detail::is_numeric<N>::value>::type* = nullptr>
234  inline auto operator*=(T& left, N right)
235  { return left.scale_to(right); }
236 
237 } // namespace TiledArray
238 
239 #endif // TILEDARRAY_TENSOR_OPERATORS_H__INCLUDED
auto operator+(const T1 &left, const T2 &right)
Tensor plus operator.
Definition: operators.h:48
std::array< T, N > operator*(const Permutation &, const std::array< T, N > &)
Permute a std::array.
Definition: permutation.h:484
auto operator+=(T1 &left, const T2 &right)
Tensor plus operator.
Definition: operators.h:153
Permutation operator-(const Permutation &perm)
Inverse permutation operator.
Definition: permutation.h:440
std::array< T, N > & operator*=(std::array< T, N > &, const Permutation &)
In-place permute a std::array.
Definition: permutation.h:501
auto operator-=(T1 &left, const T2 &right)
Tensor minus operator.
Definition: operators.h:169
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:119
static constexpr bool value
Definition: type_traits.h:92