26 #ifndef TILEDARRAY_TILE_OP_ADD_H__INCLUDED 27 #define TILEDARRAY_TILE_OP_ADD_H__INCLUDED 30 #include "../tile_interface/add.h" 31 #include "../tile_interface/scale.h" 32 #include "../tile_interface/permute.h" 33 #include "../tile_interface/clone.h" 34 #include "../zero_tensor.h" 52 template <
typename Result,
typename Left,
typename Right,
53 bool LeftConsumable,
bool RightConsumable>
65 LeftConsumable && std::is_same<result_type, left_type>::value;
68 RightConsumable && std::is_same<result_type, right_type>::value;
80 return add(first, second, perm);
101 template <
bool LC,
bool RC,
102 typename std::enable_if<!(LC || RC)>::type* =
nullptr>
106 return add(first, second);
109 template <
bool LC,
bool RC,
110 typename std::enable_if<LC>::type* =
nullptr>
113 return add_to(first, second);
116 template <
bool LC,
bool RC,
117 typename std::enable_if<!LC && RC>::type* =
nullptr>
120 return add_to(second, first);
123 template <
bool LC,
bool RC,
124 typename std::enable_if<!RC>::type* =
nullptr>
127 return clone(second);
130 template <
bool LC,
bool RC,
131 typename std::enable_if<RC>::type* =
nullptr>
136 template <
bool LC,
bool RC,
137 typename std::enable_if<!LC>::type* =
nullptr>
143 template <
bool LC,
bool RC,
144 typename std::enable_if<LC>::type* =
nullptr>
162 template <
typename L,
typename R>
165 return eval(std::forward<L>(left), std::forward<R>(right), perm);
178 template <
typename L,
typename R>
180 return Add_::template eval<left_is_consumable, right_is_consumable>(
181 std::forward<L>(left), std::forward<R>(right));
193 template <
typename R>
195 constexpr
bool can_consume_left =
197 std::is_same<result_type, left_type>::value;
199 ! (std::is_const<R>::value || can_consume_left);
200 return Add_::template eval<can_consume_left, can_consume_right>(left,
201 std::forward<R>(right));
213 template <
typename L>
215 constexpr
bool can_consume_right =
217 std::is_same<result_type, right_type>::value;
219 ! (std::is_const<L>::value || can_consume_right);
220 return Add_::template eval<can_consume_left, can_consume_right>(
221 std::forward<L>(left), right);
241 template <
typename Result,
typename Left,
typename Right,
typename Scalar,
242 bool LeftConsumable,
bool RightConsumable>
246 typedef ScalAdd<Result, Left, Right, Scalar, LeftConsumable,
255 LeftConsumable && std::is_same<result_type, left_type>::value;
258 RightConsumable && std::is_same<result_type, right_type>::value;
272 return add(first, second, factor_, perm);
279 return scale(second, factor_, perm);
286 return scale(first, factor_, perm);
293 template <
bool LC,
bool RC,
294 typename std::enable_if<!(LC || RC)>::type* =
nullptr>
297 return add(first, second, factor_);
300 template <
bool LC,
bool RC,
301 typename std::enable_if<LC>::type* =
nullptr>
304 return add_to(first, second, factor_);
307 template <
bool LC,
bool RC,
308 typename std::enable_if<!LC && RC>::type* =
nullptr>
311 return add_to(second, first, factor_);
314 template <
bool LC,
bool RC,
315 typename std::enable_if<!RC>::type* =
nullptr>
318 return scale(second, factor_);
321 template <
bool LC,
bool RC,
322 typename std::enable_if<RC>::type* =
nullptr>
328 template <
bool LC,
bool RC,
329 typename std::enable_if<!LC>::type* =
nullptr>
332 return scale(first, factor_);
335 template <
bool LC,
bool RC,
336 typename std::enable_if<LC>::type* =
nullptr>
354 explicit ScalAdd(
const Scalar factor) : factor_(factor) { }
367 template <
typename L,
typename R>
370 return eval(std::forward<L>(left), std::forward<R>(right), perm);
383 template <
typename L,
typename R>
398 template <
typename R>
400 constexpr
bool can_consume_left =
402 std::is_same<result_type, left_type>::value;
404 ! (std::is_const<R>::value || can_consume_left);
405 return ScalAdd_::template eval<can_consume_left, can_consume_right>(left,
406 std::forward<R>(right));
418 template <
typename L>
420 constexpr
bool can_consume_right =
422 std::is_same<result_type, right_type>::value;
424 ! (std::is_const<L>::value || can_consume_right);
425 return ScalAdd_::template eval<can_consume_left, can_consume_right>(
426 std::forward<L>(left), right);
434 #endif // TILEDARRAY_TILE_OP_ADD_H__INCLUDED Right right_type
Right-hand argument base type.
static constexpr bool left_is_consumable
Indicates whether it is possible to consume the left tile.
ScalAdd(const Scalar factor)
Constructor.
Tile scale-addition operation.
void permute(InputOp &&input_op, OutputOp &&output_op, Result &result, const Permutation &perm, const Arg0 &arg0, const Args &... args)
Construct a permuted tensor copy.
Left left_type
Left-hand argument base type.
Tile< Result > & scale_to(Tile< Result > &result, const Scalar factor)
Scale to the result tile.
static constexpr bool left_is_consumable
Indicates whether it is possible to consume the left tile.
void scale(DistArray< Tile, Policy > &a, typename DistArray< Tile, Policy >::element_type scaling_factor)
result_type consume_right(L &&left, right_type &right) const
Add left to right.
Right right_type
Right-hand argument base type.
Place-holder object for a zero tensor.
Add< Result, Left, Right, LeftConsumable, RightConsumable > Add_
This class type.
Tile< Result > & add_to(Tile< Result > &result, const Tile< Arg > &arg)
Add to the result tile.
result_type operator()(L &&left, R &&right, const Permutation &perm) const
Scale-add-and-permute operator.
Left left_type
Left-hand argument base type.
Result result_type
Result tile type.
decltype(auto) add(const Tile< Left > &left, const Tile< Right > &right)
Add tile arguments.
ScalAdd_ & operator=(const ScalAdd_ &)=default
result_type operator()(L &&left, R &&right) const
Scale-and-add operator.
DistArray< Tile, Policy > clone(const DistArray< Tile, Policy > &arg)
Create a deep copy of an array.
static constexpr bool right_is_consumable
Indicates whether it is possible to consume the right tile.
ScalAdd(const ScalAdd_ &)=default
Scalar scalar_type
Scaling factor type.
result_type consume_left(left_type &left, R &&right) const
Add right to left and scale the result.
result_type operator()(L &&left, R &&right) const
Add operator.
result_type consume_left(left_type &left, R &&right) const
Add right to left.
Result result_type
The result tile type.
Consumable tile type trait.
Permutation of a sequence of objects indexed by base-0 indices.
static constexpr bool right_is_consumable
Indicates whether it is possible to consume the right tile.
ScalAdd< Result, Left, Right, Scalar, LeftConsumable, RightConsumable > ScalAdd_
This class type.
result_type operator()(L &&left, R &&right, const Permutation &perm) const
Add-and-permute operator.
result_type consume_right(L &&left, right_type &right) const
Add left to right and scale the result.
Create a deep copy of a tile.