26 #ifndef TILEDARRAY_TILE_OP_SUBT_H__INCLUDED 27 #define TILEDARRAY_TILE_OP_SUBT_H__INCLUDED 30 #include "../tile_interface/scale.h" 31 #include "../tile_interface/permute.h" 32 #include "../tile_interface/clone.h" 51 template <
typename Result,
typename Left,
typename Right,
52 bool LeftConsumable,
bool RightConsumable>
63 LeftConsumable && std::is_same<result_type, left_type>::value;
66 RightConsumable && std::is_same<result_type, right_type>::value;
78 return subt(first, second, perm);
85 return neg(second, perm);
99 template <
bool LC,
bool RC,
100 typename std::enable_if<!(LC || RC)>::type* =
nullptr>
103 return subt(first, second);
106 template <
bool LC,
bool RC,
107 typename std::enable_if<LC>::type* =
nullptr>
113 template <
bool LC,
bool RC,
114 typename std::enable_if<!LC && RC>::type* =
nullptr>
117 return subt_to(second, first, -1);
120 template <
bool LC,
bool RC,
121 typename std::enable_if<!RC>::type* =
nullptr>
127 template <
bool LC,
bool RC,
128 typename std::enable_if<RC>::type* =
nullptr>
134 template <
bool LC,
bool RC,
135 typename std::enable_if<!LC>::type* =
nullptr>
141 template <
bool LC,
bool RC,
142 typename std::enable_if<LC>::type* =
nullptr>
160 template <
typename L,
typename R>
162 return eval(std::forward<L>(left), std::forward<R>(right), perm);
175 template <
typename L,
typename R>
177 return Subt_::template eval<left_is_consumable, right_is_consumable>(
178 std::forward<L>(left), std::forward<R>(right));
190 template <
typename R>
192 constexpr
bool can_consume_left =
194 std::is_same<result_type, left_type>::value;
196 ! (std::is_const<R>::value || can_consume_left);
197 return Subt_::template eval<can_consume_left, can_consume_right>(left,
198 std::forward<R>(right));
210 template <
typename L>
212 constexpr
bool can_consume_right =
214 std::is_same<result_type, right_type>::value;
216 ! (std::is_const<L>::value || can_consume_right);
217 return Subt_::template eval<can_consume_left, can_consume_right>(
218 std::forward<L>(left), right);
238 template <
typename Result,
typename Left,
typename Right,
typename Scalar,
239 bool LeftConsumable,
bool RightConsumable>
243 typedef ScalSubt<Result, Left, Right, Scalar, LeftConsumable,
251 LeftConsumable && std::is_same<result_type, left_type>::value;
253 RightConsumable && std::is_same<result_type, right_type>::value;
267 return subt(first, second, factor_, perm);
274 return scale(second, -factor_, perm);
281 return scale(first, factor_, perm);
288 template <
bool LC,
bool RC,
289 typename std::enable_if<!(LC || RC)>::type* =
nullptr>
292 return subt(first, second, factor_);
295 template <
bool LC,
bool RC,
296 typename std::enable_if<LC>::type* =
nullptr>
299 return subt_to(first, second, factor_);
302 template <
bool LC,
bool RC,
303 typename std::enable_if<!LC && RC>::type* =
nullptr>
306 return subt_to(second, first, -factor_);
309 template <
bool LC,
bool RC,
310 typename std::enable_if<!RC>::type* =
nullptr>
313 return scale(second, -factor_);
316 template <
bool LC,
bool RC,
317 typename std::enable_if<RC>::type* =
nullptr>
323 template <
bool LC,
bool RC,
324 typename std::enable_if<!LC>::type* =
nullptr>
327 return scale(first, factor_);
330 template <
bool LC,
bool RC,
331 typename std::enable_if<LC>::type* =
nullptr>
349 explicit ScalSubt(
const Scalar factor) : factor_(factor) { }
362 template <
typename L,
typename R>
365 return eval(std::forward<L>(left), std::forward<R>(right), perm);
378 template <
typename L,
typename R>
380 return ScalSubt_::template eval<left_is_consumable, right_is_consumable>(
381 std::forward<L>(left), std::forward<R>(right));
393 template <
typename R>
395 constexpr
bool can_consume_left =
397 std::is_same<result_type, left_type>::value;
399 ! (std::is_const<R>::value || can_consume_left);
400 return ScalSubt_::template eval<can_consume_left, can_consume_right>(
401 left, std::forward<R>(right));
413 template <
typename L>
415 constexpr
bool can_consume_right =
417 std::is_same<result_type, right_type>::value;
419 ! (std::is_const<L>::value || can_consume_right);
420 return ScalSubt_::template eval<can_consume_left, can_consume_right>(
421 std::forward<L>(left), right);
429 #endif // TILEDARRAY_TILE_OP_SUBT_H__INCLUDED Result result_type
The result tile type.
static constexpr bool left_is_consumable
decltype(auto) subt(const Tile< Left > &left, const Tile< Right > &right)
Subtract tile arguments.
Tile subtraction 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.
result_type operator()(L &&left, R &&right) const
Scale-and-subtract operator.
Tile< Result > & scale_to(Tile< Result > &result, const Scalar factor)
Scale to the result tile.
result_type consume_left(left_type &left, R &&right) const
Subtract right to left.
result_type consume_left(left_type &left, R &&right) const
Subtract right to left and scale the result.
void scale(DistArray< Tile, Policy > &a, typename DistArray< Tile, Policy >::element_type scaling_factor)
Scalar scalar_type
Scaling factor type.
result_type consume_right(L &&left, right_type &right) const
Subtract left to right and scale the result.
Place-holder object for a zero tensor.
ScalSubt_ & operator=(const ScalSubt_ &)=default
static constexpr bool right_is_consumable
Tile scale-subtraction operation.
result_type operator()(L &&left, R &&right) const
Subtract operator.
static constexpr bool right_is_consumable
Indicates whether it is possible to consume the right tile.
Left left_type
Left-hand argument base type.
DistArray< Tile, Policy > clone(const DistArray< Tile, Policy > &arg)
Create a deep copy of an array.
ScalSubt< Result, Left, Right, Scalar, LeftConsumable, RightConsumable > ScalSubt_
This class type.
static constexpr bool left_is_consumable
Indicates whether it is possible to consume the left tile.
Subt< Result, Left, Right, LeftConsumable, RightConsumable > Subt_
Result result_type
The result tile type.
ScalSubt(const Scalar factor)
Constructor.
Right right_type
Right-hand argument base type.
Tile< Result > & neg_to(Tile< Result > &result)
Multiplication constant scalar to a tile.
result_type operator()(L &&left, R &&right, const Permutation &perm) const
Scale-subtract-and-permute operator.
Consumable tile type trait.
Left left_type
Left-hand argument base type.
decltype(auto) neg(const Tile< Arg > &arg)
Negate the tile argument.
ScalSubt(const ScalSubt_ &)=default
Right right_type
Right-hand argument base type.
Permutation of a sequence of objects indexed by base-0 indices.
TiledArray::Range permute(const TiledArray::Range &r, const Perm &p)
Tile< Result > & subt_to(Tile< Result > &result, const Tile< Arg > &arg)
Subtract from the result tile.
result_type operator()(L &&left, R &&right, const Permutation &perm) const
Subtract-and-permute operator.
Create a deep copy of a tile.
result_type consume_right(L &&left, right_type &right) const
Subtract left to right.