26 #ifndef TILEDARRAY_TILE_OP_ADD_H__INCLUDED
27 #define TILEDARRAY_TILE_OP_ADD_H__INCLUDED
29 #include "../tile_interface/add.h"
30 #include "../tile_interface/clone.h"
31 #include "../tile_interface/permute.h"
32 #include "../tile_interface/scale.h"
33 #include "../zero_tensor.h"
52 template <
typename Result,
typename Left,
typename Right,
bool LeftConsumable,
64 LeftConsumable && std::is_same<result_type, left_type>::value;
67 RightConsumable && std::is_same<result_type, right_type>::value;
74 template <
typename Perm,
typename = std::enable_if_t<
75 TiledArray::detail::is_permutation_v<Perm>>>
79 return add(first, second, perm);
82 template <
typename Perm,
typename = std::enable_if_t<
83 TiledArray::detail::is_permutation_v<Perm>>>
90 template <
typename Perm,
typename = std::enable_if_t<
91 TiledArray::detail::is_permutation_v<Perm>>>
102 template <
bool LC,
bool RC,
103 typename std::enable_if<!(LC || RC)>::type* =
nullptr>
106 return add(first, second);
109 template <bool LC, bool RC, typename std::enable_if<LC>::type* =
nullptr>
112 return add_to(first, second);
115 template <
bool LC,
bool RC,
116 typename std::enable_if<!LC && RC>::type* =
nullptr>
119 return add_to(second, first);
122 template <bool LC, bool RC, typename std::enable_if<!RC>::type* =
nullptr>
125 return clone(second);
128 template <bool LC, bool RC, typename std::enable_if<RC>::type* =
nullptr>
133 template <bool LC, bool RC, typename std::enable_if<!LC>::type* =
nullptr>
139 template <bool LC, bool RC, typename std::enable_if<LC>::type* =
nullptr>
157 typename L,
typename R,
typename Perm,
158 typename = std::enable_if_t<TiledArray::detail::is_permutation_v<Perm>>>
160 return eval(std::forward<L>(left), std::forward<R>(right), perm);
173 template <
typename L,
typename R>
175 return Add_::template eval<left_is_consumable, right_is_consumable>(
176 std::forward<L>(left), std::forward<R>(right));
188 template <
typename R>
190 constexpr
bool can_consume_left =
192 std::is_same<result_type, left_type>::value;
193 constexpr
bool can_consume_right =
195 return Add_::template eval<can_consume_left, can_consume_right>(
196 left, std::forward<R>(right));
208 template <
typename L>
210 constexpr
bool can_consume_right =
212 std::is_same<result_type, right_type>::value;
213 constexpr
bool can_consume_left =
215 return Add_::template eval<can_consume_left, can_consume_right>(
216 std::forward<L>(left), right);
236 template <
typename Result,
typename Left,
typename Right,
typename Scalar,
237 bool LeftConsumable,
bool RightConsumable>
240 typedef ScalAdd<Result, Left, Right, Scalar, LeftConsumable,
250 LeftConsumable && std::is_same<result_type, left_type>::value;
253 RightConsumable && std::is_same<result_type, right_type>::value;
262 template <
typename Perm,
typename = std::enable_if_t<
263 TiledArray::detail::is_permutation_v<Perm>>>
265 const Perm& perm)
const {
267 return add(first, second, factor_, perm);
270 template <
typename Perm,
typename = std::enable_if_t<
271 TiledArray::detail::is_permutation_v<Perm>>>
273 const Perm& perm)
const {
275 return scale(second, factor_, perm);
278 template <
typename Perm,
typename = std::enable_if_t<
279 TiledArray::detail::is_permutation_v<Perm>>>
282 return scale(first, factor_, perm);
289 template <
bool LC,
bool RC,
290 typename std::enable_if<!(LC || RC)>::type* =
nullptr>
293 return add(first, second, factor_);
296 template <bool LC, bool RC, typename std::enable_if<LC>::type* =
nullptr>
299 return add_to(first, second, factor_);
302 template <
bool LC,
bool RC,
303 typename std::enable_if<!LC && RC>::type* =
nullptr>
306 return add_to(second, first, factor_);
309 template <bool LC, bool RC, typename std::enable_if<!RC>::type* =
nullptr>
312 return scale(second, factor_);
315 template <bool LC, bool RC, typename std::enable_if<RC>::type* =
nullptr>
321 template <bool LC, bool RC, typename std::enable_if<!LC>::type* =
nullptr>
324 return scale(first, factor_);
327 template <bool LC, bool RC, typename std::enable_if<LC>::type* =
nullptr>
344 explicit ScalAdd(
const Scalar factor) : factor_(factor) {}
358 typename L,
typename R,
typename Perm,
359 typename = std::enable_if_t<TiledArray::detail::is_permutation_v<Perm>>>
361 return eval(std::forward<L>(left), std::forward<R>(right), perm);
374 template <
typename L,
typename R>
376 return ScalAdd_::template eval<left_is_consumable, right_is_consumable>(
377 std::forward<L>(left), std::forward<R>(right));
389 template <
typename R>
391 constexpr
bool can_consume_left =
393 std::is_same<result_type, left_type>::value;
394 constexpr
bool can_consume_right =
396 return ScalAdd_::template eval<can_consume_left, can_consume_right>(
397 left, std::forward<R>(right));
409 template <
typename L>
411 constexpr
bool can_consume_right =
413 std::is_same<result_type, right_type>::value;
414 constexpr
bool can_consume_left =
416 return ScalAdd_::template eval<can_consume_left, can_consume_right>(
417 std::forward<L>(left), right);
425 #endif // TILEDARRAY_TILE_OP_ADD_H__INCLUDED