expr.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2013 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  * expr.h
22  * Apr 1, 2014
23  *
24  */
25 
26 #ifndef TILEDARRAY_EXPRESSIONS_EXPR_H__INCLUDED
27 #define TILEDARRAY_EXPRESSIONS_EXPR_H__INCLUDED
28 
29 #include "../reduce_task.h"
30 #include "../tile_interface/cast.h"
31 #include "../tile_interface/scale.h"
32 #include "../tile_op/binary_reduction.h"
33 #include "../tile_op/reduce_wrapper.h"
34 #include "../tile_op/shift.h"
35 #include "../tile_op/unary_reduction.h"
36 #include "../tile_op/unary_wrapper.h"
37 #include "TiledArray/config.h"
38 #include "TiledArray/tile.h"
40 #include "expr_engine.h"
41 #ifdef TILEDARRAY_HAS_CUDA
44 #endif
45 
47 
48 namespace TiledArray {
49 namespace expressions {
50 
51 // Forward declaration
52 template <typename>
53 struct ExprTrait;
54 template <typename, bool>
55 class TsrExpr;
56 template <typename, bool>
57 class BlkTsrExpr;
58 template <typename>
59 struct is_aliased;
60 
61 template <typename Engine>
63  EngineParamOverride() : world(nullptr), pmap(), shape(nullptr) {}
64 
65  typedef
67  typedef typename EngineTrait<Engine>::shape_type
71 
72  World* world;
73  std::shared_ptr<pmap_interface> pmap;
74  const shape_type* shape;
75 };
76 
79 template <class E>
80 class has_array {
82  template <class U>
83  static auto __test(U* p) -> decltype(p->array(), std::true_type());
85  template <class>
86  static std::false_type __test(...);
87 
88  public:
89  static constexpr const bool value =
90  std::is_same<std::true_type, decltype(__test<E>(0))>::value;
91 };
92 
94 
96 template <typename Derived>
97 class Expr {
98  public:
99  template <typename Derived_ = Derived>
101  template <typename Derived_ = Derived>
103 
105  typedef Derived derived_type;
107 
108  private:
109  template <typename D>
110  friend class ExprEngine;
111 
113  override_type;
114  std::shared_ptr<override_type> override_ptr_;
115 
116  public:
122  if (override_ptr_ != nullptr) {
123  override_ptr_->shape = &shape;
124  } else {
125  override_ptr_ = std::make_shared<override_type>();
126  override_ptr_->shape = &shape;
127  }
128  return derived();
129  }
131  Expr<Derived>& set_world(World& world) {
132  if (override_ptr_ != nullptr) {
133  override_ptr_->world = &world;
134  } else {
135  override_ptr_ = std::make_shared<override_type>();
136  override_ptr_->world = &world;
137  }
138  return derived();
139  }
142  const std::shared_ptr<typename override_type::pmap_interface> pmap) {
143  if (override_ptr_) {
144  override_ptr_->pmap = pmap;
145  } else {
146  override_ptr_ = std::make_shared<override_type>();
147  override_ptr_->pmap = pmap;
148  }
149  return derived();
150  }
151 
152  private:
154 
162  template <typename R, typename T, typename C, typename Op>
163  static auto eval_tile(T&& tile, const C& cast,
164  const std::shared_ptr<Op>& op) {
165  auto&& cast_tile = cast(std::forward<T>(tile));
166  return (*op)(cast_tile);
167  }
168 
170 
177  template <typename T, typename Op>
178  static auto eval_tile(T&& tile, const std::shared_ptr<Op>& op) {
179  return (*op)(std::forward<T>(tile));
180  }
181 
183 
192  template <
193  typename A, typename I, typename T,
194  typename std::enable_if<!std::is_same<typename A::value_type, T>::value &&
195  is_lazy_tile<T>::value
196 #ifdef TILEDARRAY_HAS_CUDA
197  && !::TiledArray::detail::is_cuda_tile_v<T>
198 #endif
199  >::type* = nullptr>
200  void set_tile(A& array, const I& index, const Future<T>& tile) const {
201  array.set(index, array.world().taskq.add(
203  }
204 
205 #ifdef TILEDARRAY_HAS_CUDA
206 
216  template <typename A, typename I, typename T,
217  typename std::enable_if<
218  !std::is_same<typename A::value_type, T>::value &&
219  is_lazy_tile<T>::value &&
220  ::TiledArray::detail::is_cuda_tile_v<T>>::type* = nullptr>
221  void set_tile(A& array, const I& index, const Future<T>& tile) const {
222  array.set(index, madness::add_cuda_task(
223  array.world(),
225  }
226 #endif
227 
229 
236  template <typename A, typename I, typename T,
237  typename std::enable_if<std::is_same<typename A::value_type,
238  T>::value>::type* = nullptr>
239  void set_tile(A& array, const I& index, const Future<T>& tile) const {
240  array.set(index, tile);
241  }
242 
244 
253  template <
254  typename A, typename I, typename T, typename Op,
255  typename std::enable_if<!std::is_same<typename A::value_type, T>::value
256 #ifdef TILEDARRAY_HAS_CUDA
257  && !::TiledArray::detail::is_cuda_tile_v<T>
258 #endif
259  >::type* = nullptr>
260  void set_tile(A& array, const I index, const Future<T>& tile,
261  const std::shared_ptr<Op>& op) const {
262  auto eval_tile_fn =
263  &Expr_::template eval_tile<typename A::value_type, const T&,
265  Op>;
266  array.set(index, array.world().taskq.add(
267  eval_tile_fn, tile,
269  }
270 
271 #ifdef TILEDARRAY_HAS_CUDA
272 
282  template <typename A, typename I, typename T, typename Op,
283  typename std::enable_if<
284  !std::is_same<typename A::value_type, T>::value &&
285  ::TiledArray::detail::is_cuda_tile_v<T>>::type* = nullptr>
286  void set_tile(A& array, const I index, const Future<T>& tile,
287  const std::shared_ptr<Op>& op) const {
288  auto eval_tile_fn =
289  &Expr_::template eval_tile<typename A::value_type, const T&,
291  Op>;
292  array.set(index, madness::add_cuda_task(
293  array.world(), eval_tile_fn, tile,
295  }
296 #endif
297 
299 
310  template <
311  typename A, typename I, typename T, typename Op,
312  typename std::enable_if<std::is_same<typename A::value_type, T>::value
313 #ifdef TILEDARRAY_HAS_CUDA
314  && !::TiledArray::detail::is_cuda_tile_v<T>
315 #endif
316  >::type* = nullptr>
317  void set_tile(A& array, const I index, const Future<T>& tile,
318  const std::shared_ptr<Op>& op) const {
319  auto eval_tile_fn_ptr = &Expr_::template eval_tile<const T&, Op>;
320  using fn_ptr_type = decltype(eval_tile_fn_ptr);
321  static_assert(madness::detail::function_traits<fn_ptr_type(
322  const T&, const std::shared_ptr<Op>&)>::value,
323  "ouch");
324  array.set(index, array.world().taskq.add(eval_tile_fn_ptr, tile, op));
325  }
326 
327 #ifdef TILEDARRAY_HAS_CUDA
328 
339  template <typename A, typename I, typename T, typename Op,
340  typename std::enable_if<
341  std::is_same<typename A::value_type, T>::value&& ::TiledArray::
342  detail::is_cuda_tile_v<T>>::type* = nullptr>
343  void set_tile(A& array, const I index, const Future<T>& tile,
344  const std::shared_ptr<Op>& op) const {
345  auto eval_tile_fn_ptr = &Expr_::template eval_tile<const T&, Op>;
346  using fn_ptr_type = decltype(eval_tile_fn_ptr);
347  static_assert(madness::detail::function_traits<fn_ptr_type(
348  const T&, const std::shared_ptr<Op>&)>::value,
349  "ouch");
350  array.set(index, madness::add_cuda_task(array.world(), eval_tile_fn_ptr,
351  tile, op));
352  }
353 #endif
354 
355  public:
356  // Compiler generated functions
357  Expr() = default;
358  Expr(const Expr_&) = default;
359  Expr(Expr_&&) = default;
360  ~Expr() = default;
361  Expr_& operator=(const Expr_&) = delete;
362  Expr_& operator=(Expr_&&) = delete;
363 
365  derived_type& derived() { return *static_cast<derived_type*>(this); }
366 
368  const derived_type& derived() const {
369  return *static_cast<const derived_type*>(this);
370  }
371 
373 
380  template <typename A, bool Alias>
381  void eval_to(TsrExpr<A, Alias>& tsr) const {
383  "Assignment to an array of lazy tiles is not supported.");
384 
385  // Get the target world
386  // 1. result's world is assigned, use it
387  // 2. if this expression's world was assigned by set_world(), use it
388  // 3. otherwise revert to the TA default for the MADNESS world
389  const auto has_set_world = override_ptr_ && override_ptr_->world;
390  World& world = (tsr.array().is_initialized()
391  ? tsr.array().world()
392  : (has_set_world ? *override_ptr_->world
394 
395  // Get the output process map.
396  // If result's pmap is assigned use it as the initial guess
397  // it will be assigned in engine.init
398  std::shared_ptr<typename TsrExpr<A, Alias>::array_type::pmap_interface>
399  pmap;
400  if (tsr.array().is_initialized()) pmap = tsr.array().pmap();
401 
402  // Get result index list.
403  BipartiteIndexList target_indices(tsr.annotation());
404 
405  // Construct the expression engine
406  engine_type engine(derived());
407  engine.init(world, pmap, target_indices);
408 
409  // Create the distributed evaluator from this expression
410  typename engine_type::dist_eval_type dist_eval = engine.make_dist_eval();
411  dist_eval.eval();
412 
413  // Create the result array
414  A result(dist_eval.world(), dist_eval.trange(), dist_eval.shape(),
415  dist_eval.pmap());
416 
417  // Move the data from dist_eval into the result array. There is no
418  // communication in this step.
419  for (const auto index : *dist_eval.pmap()) {
420  if (dist_eval.is_zero(index)) continue;
421  auto tile_contents = dist_eval.get(index);
422  set_tile(result, index, tile_contents);
423  }
424 
425  // Wait for child expressions of dist_eval
426  dist_eval.wait();
427  // Swap the new array with the result array object.
428  result.swap(tsr.array());
429  }
430 
432 
439  template <typename A, bool Alias>
440  void eval_to(BlkTsrExpr<A, Alias>& tsr) const {
442  typename std::decay<A>::type::value_type,
445  shift_op_type;
448  "Assignment to an array of lazy tiles is not supported.");
449 
450 #ifndef NDEBUG
451  // Check that the array has been initialized.
452  if (!tsr.array().is_initialized()) {
453  if (TiledArray::get_default_world().rank() == 0) {
455  "Assignment to an uninitialized array sub-block is not supported.");
456  }
457 
458  TA_EXCEPTION(
459  "Assignment to an uninitialized array sub-block is not supported.");
460  }
461 
462  // Note: Unfortunately we cannot check that the array tiles have been
463  // set even though this is a requirement.
464 #endif // NDEBUG
465 
466  // Get the target world.
467  World& world = tsr.array().world();
468 
469  // Get the output process map.
470  std::shared_ptr<typename BlkTsrExpr<A, Alias>::array_type::pmap_interface>
471  pmap;
472 
473  // Get result index list.
474  BipartiteIndexList target_indices(tsr.annotation());
475 
476  // Construct the expression engine
477  engine_type engine(derived());
478  engine.init(world, pmap, target_indices);
479 
480  // Create the distributed evaluator from this expression
481  typename engine_type::dist_eval_type dist_eval = engine.make_dist_eval();
482  dist_eval.eval();
483 
484  // Create the result array
485  A result(world, tsr.array().trange(),
486  tsr.array().shape().update_block(
487  tsr.lower_bound(), tsr.upper_bound(), dist_eval.shape()),
488  tsr.array().pmap());
489 
490  // NOTE: The tiles from the original array and the sub-block are copied
491  // in two separate steps because the two tensors have different data
492  // distribution.
493 
494  // Copy tiles from the original array to the result array that are not
495  // included in the sub-block assignment. There is no communication in
496  // this step.
497  const BlockRange blk_range(tsr.array().trange().tiles_range(),
498  tsr.lower_bound(), tsr.upper_bound());
499  for (const auto index : *tsr.array().pmap()) {
500  if (!tsr.array().is_zero(index)) {
501  if (!blk_range.includes(tsr.array().trange().tiles_range().idx(index)))
502  result.set(index, tsr.array().find(index));
503  }
504  }
505 
506  // Move the data from dist_eval into the sub-block of result array.
507  // This step may involve communication when the tiles are moved from the
508  // sub-block distribution to the array distribution.
509  {
510  const std::vector<long> shift =
511  tsr.array().trange().make_tile_range(tsr.lower_bound()).lobound();
512 
513  std::shared_ptr<op_type> shift_op =
514  std::make_shared<op_type>(shift_op_type(shift));
515 
516  for (const auto index : *dist_eval.pmap()) {
517  if (!dist_eval.is_zero(index))
518  set_tile(result, blk_range.ordinal(index), dist_eval.get(index),
519  shift_op);
520  }
521  }
522 
523  // Wait for child expressions of dist_eval
524  dist_eval.wait();
525  // Swap the new array with the result array object.
526  result.swap(tsr.array());
527  }
528 
530 
533  void print(ExprOStream& os, const BipartiteIndexList& target_indices) const {
534  // Construct the expression engine
535  engine_type engine(derived());
536  engine.init_indices(target_indices);
537  engine.init_struct(target_indices);
538  engine.print(os, target_indices);
539  }
540 
541  private:
542  struct ExpressionReduceTag {};
543 
544  template <typename D, typename Enabler = void>
545  struct default_world_helper {
546  default_world_helper(const D&) {}
547  World& get() const { return TiledArray::get_default_world(); }
548  };
549  template <typename D>
550  struct default_world_helper<
551  D, typename std::enable_if<has_array<D>::value>::type> {
552  default_world_helper(const D& d) : derived_(d) {}
553  World& get() const { return derived_.array().world(); }
554  const D& derived_;
555  };
556  World& default_world() const {
557  return default_world_helper<Derived>(this->derived()).get();
558  }
559 
560  public:
561  template <typename Op>
562  Future<typename Op::result_type> reduce(const Op& op, World& world) const {
563  // Typedefs
564  typedef madness::TaggedKey<madness::uniqueidT, ExpressionReduceTag>
565  key_type;
567  typename engine_type::value_type, Op>
568  reduction_op_type;
569 
570  // Construct the expression engine
571  engine_type engine(derived());
572  engine.init(world, std::shared_ptr<typename engine_type::pmap_interface>(),
574 
575  // Create the distributed evaluator from this expression
576  typename engine_type::dist_eval_type dist_eval = engine.make_dist_eval();
577  dist_eval.eval();
578 
579  // Create a local reduction task
580  reduction_op_type wrapped_op(op);
582  wrapped_op);
583 
584  // Move the data from dist_eval into the local reduction task
585  typename engine_type::dist_eval_type::pmap_interface::const_iterator it =
586  dist_eval.pmap()->begin();
587  const typename engine_type::dist_eval_type::pmap_interface::const_iterator
588  end = dist_eval.pmap()->end();
589  for (; it != end; ++it)
590  if (!dist_eval.is_zero(*it)) reduce_task.add(dist_eval.get(*it));
591 
592  // All reduce the result of the expression
593  auto result = world.gop.all_reduce(key_type(dist_eval.id()),
594  reduce_task.submit(), op);
595  dist_eval.wait();
596  return result;
597  }
598 
599  template <typename Op>
601  return reduce(op, default_world());
602  }
603 
604  template <typename D, typename Op>
606  const Op& op, World& world) const {
607  static_assert(
609  "no_alias() expressions are not allowed on the right-hand side of "
610  "the assignment operator.");
611 
612  // Typedefs
613  typedef madness::TaggedKey<madness::uniqueidT, ExpressionReduceTag>
614  key_type;
616  typename engine_type::value_type, typename D::engine_type::value_type,
617  Op>
618  reduction_op_type;
619 
620  // Evaluate this expression
621  engine_type left_engine(derived());
622  left_engine.init(world,
623  std::shared_ptr<typename engine_type::pmap_interface>(),
625 
626  // Create the distributed evaluator for this expression
627  typename engine_type::dist_eval_type left_dist_eval =
628  left_engine.make_dist_eval();
629  left_dist_eval.eval();
630 
631  // Evaluate the right-hand expression
632  typename D::engine_type right_engine(right_expr.derived());
633  right_engine.init(world, left_engine.pmap(), left_engine.indices());
634 
635  // Create the distributed evaluator for the right-hand expression
636  typename D::engine_type::dist_eval_type right_dist_eval =
637  right_engine.make_dist_eval();
638  right_dist_eval.eval();
639 
640 #ifndef NDEBUG
641  if (left_dist_eval.trange() != right_dist_eval.trange()) {
642  if (TiledArray::get_default_world().rank() == 0) {
644  "The TiledRanges of the left- and right-hand arguments the binary "
645  "reduction are not equal:"
646  << "\n left = " << left_dist_eval.trange()
647  << "\n right = " << right_dist_eval.trange());
648  }
649 
650  TA_EXCEPTION(
651  "The TiledRange objects of a binary expression are not equal.");
652  }
653 #endif // NDEBUG
654 
655  // Create a local reduction task
656  reduction_op_type wrapped_op(op);
658  world, wrapped_op);
659 
660  // Move the data from dist_eval into the local reduction task
661  typename engine_type::dist_eval_type::pmap_interface::const_iterator it =
662  left_dist_eval.pmap()->begin();
663  const typename engine_type::dist_eval_type::pmap_interface::const_iterator
664  end = left_dist_eval.pmap()->end();
665  for (; it != end; ++it) {
666  const auto index = *it;
667  const bool left_not_zero = !left_dist_eval.is_zero(index);
668  const bool right_not_zero = !right_dist_eval.is_zero(index);
669 
670  if (left_not_zero && right_not_zero) {
671  local_reduce_task.add(left_dist_eval.get(index),
672  right_dist_eval.get(index));
673  } else {
674  if (left_not_zero) left_dist_eval.get(index);
675  if (right_not_zero) right_dist_eval.get(index);
676  }
677  }
678 
679  auto result = world.gop.all_reduce(key_type(left_dist_eval.id()),
680  local_reduce_task.submit(), op);
681  left_dist_eval.wait();
682  right_dist_eval.wait();
683  return result;
684  }
685 
686  template <typename D, typename Op>
688  const Op& op) const {
689  return reduce(right_expr, op, default_world());
690  }
691 
692  template <
693  typename TileType = typename EngineTrait<engine_type>::eval_type,
696  typedef typename EngineTrait<engine_type>::eval_type value_type;
698  }
699 
700  template <
701  typename TileType = typename EngineTrait<engine_type>::eval_type,
704  return trace(default_world());
705  }
706 
708  typename EngineTrait<engine_type>::eval_type>::result_type>
709  sum(World& world) const {
710  typedef typename EngineTrait<engine_type>::eval_type value_type;
712  }
713 
715  typename EngineTrait<engine_type>::eval_type>::result_type>
716  sum() const {
717  return sum(default_world());
718  }
719 
721  typename EngineTrait<engine_type>::eval_type>::result_type>
722  product(World& world) const {
723  typedef typename EngineTrait<engine_type>::eval_type value_type;
725  }
726 
728  typename EngineTrait<engine_type>::eval_type>::result_type>
729  product() const {
730  return product(default_world());
731  }
732 
734  typename EngineTrait<engine_type>::eval_type>::result_type>
735  squared_norm(World& world) const {
736  typedef typename EngineTrait<engine_type>::eval_type value_type;
738  }
739 
741  typename EngineTrait<engine_type>::eval_type>::result_type>
742  squared_norm() const {
743  return squared_norm(default_world());
744  }
745 
746  private:
747  template <typename T>
748  static T sqrt(const T t) {
749  return std::sqrt(t);
750  }
751 
752  public:
754  typename EngineTrait<engine_type>::eval_type>::result_type>
755  norm(World& world) const {
756  return world.taskq.add(
757  Expr_::template sqrt<typename TiledArray::SquaredNormReduction<
758  typename EngineTrait<engine_type>::eval_type>::result_type>,
759  squared_norm(world));
760  }
762  typename EngineTrait<engine_type>::eval_type>::result_type>
763  norm() const {
764  return norm(default_world());
765  }
766 
767  template <typename Derived_ = Derived>
768  std::enable_if_t<
771  typename ExprTrait<Derived_>::engine_type>::eval_type>>::value,
772  Future<typename TiledArray::MinReduction<typename EngineTrait<
773  typename ExprTrait<Derived_>::engine_type>::eval_type>::result_type>>
774  min(World& world) const {
775  typedef typename EngineTrait<engine_type>::eval_type value_type;
777  }
778 
779  template <typename Derived_ = Derived>
780  std::enable_if_t<
783  typename ExprTrait<Derived_>::engine_type>::eval_type>>::value,
784  Future<typename TiledArray::MinReduction<typename EngineTrait<
785  typename ExprTrait<Derived_>::engine_type>::eval_type>::result_type>>
786  min() const {
787  return min(default_world());
788  }
789 
790  template <typename Derived_ = Derived>
791  std::enable_if_t<
794  typename ExprTrait<Derived_>::engine_type>::eval_type>>::value,
795  Future<typename TiledArray::MaxReduction<typename EngineTrait<
796  typename ExprTrait<Derived_>::engine_type>::eval_type>::result_type>>
797  max(World& world) const {
798  typedef typename EngineTrait<engine_type>::eval_type value_type;
800  }
801 
802  template <typename Derived_ = Derived>
803  std::enable_if_t<
806  typename ExprTrait<Derived_>::engine_type>::eval_type>>::value,
807  Future<typename TiledArray::MaxReduction<typename EngineTrait<
808  typename ExprTrait<Derived_>::engine_type>::eval_type>::result_type>>
809  max() const {
810  return max(default_world());
811  }
812 
814  typename EngineTrait<engine_type>::eval_type>::result_type>
815  abs_min(World& world) const {
816  typedef typename EngineTrait<engine_type>::eval_type value_type;
818  }
819 
821  typename EngineTrait<engine_type>::eval_type>::result_type>
822  abs_min() const {
823  return abs_min(default_world());
824  }
825 
827  typename EngineTrait<engine_type>::eval_type>::result_type>
828  abs_max(World& world) const {
829  typedef typename EngineTrait<engine_type>::eval_type value_type;
831  }
832 
834  typename EngineTrait<engine_type>::eval_type>::result_type>
835  abs_max() const {
836  return abs_max(default_world());
837  }
838 
839  template <typename D>
843  dot(const Expr<D>& right_expr, World& world) const {
844  typedef typename EngineTrait<engine_type>::eval_type left_value_type;
846  right_value_type;
847  return reduce(right_expr,
849  world);
850  }
851 
852  template <typename D>
856  dot(const Expr<D>& right_expr) const {
857  return dot(right_expr, default_world());
858  }
859 
860  template <typename D>
864  inner_product(const Expr<D>& right_expr, World& world) const {
865  typedef typename EngineTrait<engine_type>::eval_type left_value_type;
867  right_value_type;
868  return reduce(
869  right_expr,
871  world);
872  }
873 
874  template <typename D>
878  inner_product(const Expr<D>& right_expr) const {
879  return inner_product(right_expr, default_world());
880  }
881 
882 }; // class Expr
883 
884 } // namespace expressions
885 } // namespace TiledArray
886 
887 #endif // TILEDARRAY_EXPRESSIONS_EXPR_H__INCLUDED
Expr(const Expr_ &)=default
void add(const L &left, const R &right, madness::CallbackInterface *callback=nullptr)
Add a pair of arguments to the reduction task.
Definition: reduce_task.h:966
::blas::Op Op
Definition: blas.h:46
std::enable_if_t< TiledArray::detail::is_strictly_ordered< TiledArray::detail::numeric_t< typename EngineTrait< typename ExprTrait< Derived_ >::engine_type >::eval_type > >::value, Future< typename TiledArray::MaxReduction< typename EngineTrait< typename ExprTrait< Derived_ >::engine_type >::eval_type >::result_type > > max() const
Definition: expr.h:809
Vector dot product tile reduction.
Future< typename TiledArray::AbsMinReduction< typename EngineTrait< engine_type >::eval_type >::result_type > abs_min(World &world) const
Definition: expr.h:815
typename TiledArray::detail::numeric_type< T >::type numeric_t
numeric_t<T> is an alias for numeric_type<T>::type
Definition: type_traits.h:730
array_type & array() const
Array accessor.
Definition: tsr_expr.h:175
Future< typename TiledArray::AbsMaxReduction< typename EngineTrait< engine_type >::eval_type >::result_type > abs_max() const
Definition: expr.h:835
Future< result_of_trace_t< TileType > > trace() const
Definition: expr.h:703
std::enable_if_t< TiledArray::detail::is_strictly_ordered< TiledArray::detail::numeric_t< typename EngineTrait< typename ExprTrait< Derived_ >::engine_type >::eval_type > >::value, Future< typename TiledArray::MinReduction< typename EngineTrait< typename ExprTrait< Derived_ >::engine_type >::eval_type >::result_type > > min(World &world) const
Definition: expr.h:774
detail::ShiftWrapper< T > shift(T &tensor)
Shift a tensor from one range to another.
Expression wrapper for array objects.
Definition: tsr_expr.h:83
auto get(T &&t)
Definition: type_traits.h:858
std::enable_if_t< trace_is_defined_v< T >, U > enable_if_trace_is_defined_t
SFINAE type for enabling code when the trace operation is defined.
Definition: trace.h:61
Future< typename TiledArray::ProductReduction< typename EngineTrait< engine_type >::eval_type >::result_type > product() const
Definition: expr.h:729
Future< typename Op::result_type > reduce(const Expr< D > &right_expr, const Op &op, World &world) const
Definition: expr.h:605
Derived derived_type
The derived object type.
Definition: expr.h:105
Expr< Derived > & set_world(World &world)
Definition: expr.h:131
Future< typename TiledArray::SquaredNormReduction< typename EngineTrait< engine_type >::eval_type >::result_type > norm() const
Definition: expr.h:763
Maxabs tile reduction.
Tile trace reduction.
Base class for expression evaluation.
Definition: expr.h:97
Future< typename TiledArray::DotReduction< typename EngineTrait< engine_type >::eval_type, typename EngineTrait< typename D::engine_type >::eval_type >::result_type > dot(const Expr< D > &right_expr) const
Definition: expr.h:856
std::enable_if_t< TiledArray::detail::is_strictly_ordered< TiledArray::detail::numeric_t< typename EngineTrait< typename ExprTrait< Derived_ >::engine_type >::eval_type > >::value, Future< typename TiledArray::MaxReduction< typename EngineTrait< typename ExprTrait< Derived_ >::engine_type >::eval_type >::result_type > > max(World &world) const
Definition: expr.h:797
Maximum tile reduction.
#define TA_EXCEPTION(m)
Definition: error.h:83
Minimum tile reduction.
Range that references a subblock of another range.
Definition: block_range.h:34
Tile product reduction.
auto rank(const DistArray< Tile, Policy > &a)
Definition: dist_array.h:1617
engine_t< derived_type > engine_type
Expression engine type.
Definition: expr.h:106
type trait checks if T has array() member Useful to determine if an Expr is a TsrExpr or a related ty...
Definition: expr.h:80
Unary reduction wrapper class that handles lazy tile evaluation.
Future< typename TiledArray::SquaredNormReduction< typename EngineTrait< engine_type >::eval_type >::result_type > norm(World &world) const
Definition: expr.h:755
void eval_to(BlkTsrExpr< A, Alias > &tsr) const
Evaluate this object and assign it to tsr.
Definition: expr.h:440
Future< typename TiledArray::ProductReduction< typename EngineTrait< engine_type >::eval_type >::result_type > product(World &world) const
Definition: expr.h:722
Tile cast operation.
Definition: cast.h:168
World & get_default_world()
Definition: madness.h:90
typename ExprTrait< Derived_ >::engine_type engine_t
Definition: expr.h:100
Future< result_type > submit()
Submit the reduction task to the task queue.
Definition: reduce_task.h:803
Future< typename Op::result_type > reduce(const Expr< D > &right_expr, const Op &op) const
Definition: expr.h:687
bool includes(const Index &index) const
Check the coordinate to make sure it is within the range.
Definition: range.h:826
Future< typename TiledArray::SquaredNormReduction< typename EngineTrait< engine_type >::eval_type >::result_type > squared_norm(World &world) const
Definition: expr.h:735
ordinal_type ordinal(const Index &index) const
calculate the ordinal index of i
Definition: block_range.h:312
Expr_ & operator=(Expr_ &&)=delete
int add(const Arg &arg, madness::CallbackInterface *callback=nullptr)
Add an argument to the reduction task.
Definition: reduce_task.h:786
std::enable_if_t< TiledArray::detail::is_strictly_ordered< TiledArray::detail::numeric_t< typename EngineTrait< typename ExprTrait< Derived_ >::engine_type >::eval_type > >::value, Future< typename TiledArray::MinReduction< typename EngineTrait< typename ExprTrait< Derived_ >::engine_type >::eval_type >::result_type > > min() const
Definition: expr.h:786
Expr< Derived > & set_pmap(const std::shared_ptr< typename override_type::pmap_interface > pmap)
Definition: expr.h:141
Expression output stream.
Definition: expr_trace.h:41
Future< typename TiledArray::SumReduction< typename EngineTrait< engine_type >::eval_type >::result_type > sum() const
Definition: expr.h:716
EngineTrait< Engine >::shape_type shape_type
Tensor shape type.
Definition: expr.h:68
Future< typename TiledArray::AbsMaxReduction< typename EngineTrait< engine_type >::eval_type >::result_type > abs_max(World &world) const
Definition: expr.h:828
static constexpr const bool value
Definition: expr.h:89
Squared norm tile reduction.
Expr_ & operator=(const Expr_ &)=delete
Binary reduction wrapper class that handles lazy tile evaluation.
Minabs tile reduction.
Unary tile operation wrapper.
Definition: unary_wrapper.h:83
const std::string & annotation() const
Tensor annotation accessor.
Definition: tsr_expr.h:304
Tile sum reduction.
Future< result_of_trace_t< TileType > > trace(World &world) const
Definition: expr.h:695
Future< typename TiledArray::InnerProductReduction< typename EngineTrait< engine_type >::eval_type, typename EngineTrait< typename D::engine_type >::eval_type >::result_type > inner_product(const Expr< D > &right_expr) const
Definition: expr.h:878
Expr< Derived > & set_shape(typename override_type::shape_type const &shape)
Definition: expr.h:121
Vector inner product tile reduction.
EngineTrait< Engine >::policy policy
The result policy type.
Definition: expr.h:66
EngineTrait< Engine >::pmap_interface pmap_interface
Process map interface type.
Definition: expr.h:70
#define TA_USER_ERROR_MESSAGE(m)
Definition: error.h:93
Future< typename Op::result_type > reduce(const Op &op) const
Definition: expr.h:600
Future< typename TiledArray::AbsMinReduction< typename EngineTrait< engine_type >::eval_type >::result_type > abs_min() const
Definition: expr.h:822
Future< typename Op::result_type > reduce(const Op &op, World &world) const
Definition: expr.h:562
Future< typename TiledArray::DotReduction< typename EngineTrait< engine_type >::eval_type, typename EngineTrait< typename D::engine_type >::eval_type >::result_type > dot(const Expr< D > &right_expr, World &world) const
Definition: expr.h:843
Future< typename TiledArray::SquaredNormReduction< typename EngineTrait< engine_type >::eval_type >::result_type > squared_norm() const
Definition: expr.h:742
const derived_type & derived() const
Cast this object to its derived type.
Definition: expr.h:368
Tile shift operation.
Definition: shift.h:46
Detect lazy evaluation tiles.
Definition: type_traits.h:591
typename engine_t< Derived_ >::eval_type eval_type_t
Definition: expr.h:102
std::shared_ptr< pmap_interface > pmap
Definition: expr.h:73
void print(ExprOStream &os, const BipartiteIndexList &target_indices) const
Expression print.
Definition: expr.h:533
Future< typename TiledArray::InnerProductReduction< typename EngineTrait< engine_type >::eval_type, typename EngineTrait< typename D::engine_type >::eval_type >::result_type > inner_product(const Expr< D > &right_expr, World &world) const
Definition: expr.h:864
Expr< Derived > Expr_
This class type.
Definition: expr.h:104
derived_type & derived()
Cast this object to its derived type.
Definition: expr.h:365
void eval_to(TsrExpr< A, Alias > &tsr) const
Evaluate this object and assign it to tsr.
Definition: expr.h:381
Future< typename TiledArray::SumReduction< typename EngineTrait< engine_type >::eval_type >::result_type > sum(World &world) const
Definition: expr.h:709