TiledArray  0.7.0
tile_interface.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2014 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  * Justusu Calvin
19  * Department of Chemistry, Virginia Tech
20  *
21  * tile_interface.h
22  * Sep 29, 2014
23  *
24  */
25 
26 #ifndef TILEDARRAY_NONINTRUSIVE_API_TENSOR_H__INCLUDED
27 #define TILEDARRAY_NONINTRUSIVE_API_TENSOR_H__INCLUDED
28 
29 #include <TiledArray/type_traits.h>
30 #include <vector>
31 
32 namespace TiledArray {
33 
34  // Forward declaration
35  class Permutation;
36  namespace math {
37  class GemmHelper;
38  } // namespace math
39  namespace detail {
40  template <typename, typename> class LazyArrayTile;
41  } // namespace detail
42 
259  // Empty operations ----------------------------------------------------------
260 
262 
266  template <typename Arg>
267  inline bool empty(const Arg& arg) {
268  return arg.empty();
269  }
270 
271 
272  // Subtraction ---------------------------------------------------------------
273 
275 
281  template <typename Left, typename Right>
282  inline auto subt(const Left& left, const Right& right)
283  { return left.subt(right); }
284 
286 
294  template <typename Left, typename Right, typename Scalar,
295  typename std::enable_if<detail::is_numeric<Scalar>::value>::type* = nullptr>
296  inline auto subt(const Left& left, const Right& right, const Scalar factor)
297  { return left.subt(right, factor); }
298 
300 
307  template <typename Left, typename Right>
308  inline auto
309  subt(const Left& left, const Right& right, const Permutation& perm)
310  { return left.subt(right, perm); }
311 
313 
322  template <typename Left, typename Right, typename Scalar,
323  typename std::enable_if<detail::is_numeric<Scalar>::value>::type* = nullptr>
324  inline auto subt(const Left& left, const Right& right, const Scalar factor,
325  const Permutation& perm)
326  { return left.subt(right, factor, perm); }
327 
329 
335  template <typename Arg, typename Scalar,
336  typename std::enable_if<detail::is_numeric<Scalar>::value>::type* = nullptr>
337  inline auto subt(const Arg& arg, const Scalar value)
338  { return arg.subt(value); }
339 
341 
348  template <typename Arg, typename Scalar,
349  typename std::enable_if<detail::is_numeric<Scalar>::value>::type* = nullptr>
350  inline auto
351  subt(const Arg& arg, const Scalar value, const Permutation& perm)
352  { return arg.subt(value,perm); }
353 
355 
361  template <typename Result, typename Arg>
362  inline Result& subt_to(Result& result, const Arg& arg)
363  { return result.subt_to(arg); }
364 
366 
374  template <typename Result, typename Arg, typename Scalar,
375  typename std::enable_if<detail::is_numeric<Scalar>::value>::type* = nullptr>
376  inline Result& subt_to(Result& result, const Arg& arg, const Scalar factor)
377  { return result.subt_to(arg, factor); }
378 
380 
386  template <typename Result, typename Scalar,
387  typename std::enable_if<detail::is_numeric<Scalar>::value>::type* = nullptr>
388  inline Result& subt_to(Result& result, const Scalar value)
389  { return result.subt_to(value); }
390 
391 
392  template <typename... T>
393  using result_of_subt_t = decltype(subt(std::declval<T>()...));
394 
395  template <typename... T>
396  using result_of_subt_to_t = decltype(subt_to(std::declval<T>()...));
397 
398  // Multiplication operations -------------------------------------------------
399 
400 
402 
408  template <typename Left, typename Right>
409  inline auto mult(const Left& left, const Right& right)
410  { return left.mult(right); }
411 
413 
421  template <typename Left, typename Right, typename Scalar,
422  typename std::enable_if<TiledArray::detail::is_numeric<Scalar>::value>::type* = nullptr>
423  inline auto mult(const Left& left, const Right& right, const Scalar factor)
424  { return left.mult(right, factor); }
425 
427 
434  template <typename Left, typename Right>
435  inline auto
436  mult(const Left& left, const Right& right, const Permutation& perm)
437  { return left.mult(right, perm); }
438 
440 
449  template <typename Left, typename Right, typename Scalar,
450  typename std::enable_if<TiledArray::detail::is_numeric<Scalar>::value>::type* = nullptr>
451  inline auto mult(const Left& left, const Right& right, const Scalar factor,
452  const Permutation& perm)
453  { return left.mult(right, factor, perm); }
454 
456 
462  template <typename Result, typename Arg>
463  inline Result& mult_to(Result& result, const Arg& arg)
464  { return result.mult_to(arg); }
465 
467 
475  template <typename Result, typename Arg, typename Scalar,
476  typename std::enable_if<TiledArray::detail::is_numeric<Scalar>::value>::type* = nullptr>
477  inline Result& mult_to(Result& result, const Arg& arg,
478  const Scalar factor)
479  { return result.mult_to(arg, factor); }
480 
481 
482  template <typename... T>
483  using result_of_mult_t = decltype(mult(std::declval<T>()...));
484 
485  template <typename... T>
486  using result_of_mult_to_t = decltype(mult_to(std::declval<T>()...));
487 
488  // Scaling operations --------------------------------------------------------
489 
490  // Negation operations -------------------------------------------------------
491 
493 
497  template <typename Arg>
498  inline auto neg(const Arg& arg)
499  { return arg.neg(); }
500 
502 
507  template <typename Arg>
508  inline auto neg(const Arg& arg, const Permutation& perm)
509  { return arg.neg(perm); }
510 
512 
516  template <typename Result>
517  inline Result& neg_to(Result& result)
518  { return result.neg_to(); }
519 
520 
521  template <typename... T>
522  using result_of_neg_t = decltype(neg(std::declval<T>()...));
523 
524  template <typename... T>
525  using result_of_neg_to_t = decltype(neg_to(std::declval<T>()...));
526 
527 
528  // Complex conjugate operations ---------------------------------------------
529 
531 
535  template <typename Arg>
536  inline auto conj(const Arg& arg)
537  { return arg.conj(); }
538 
540 
546  template <typename Arg, typename Scalar,
547  typename std::enable_if<
549  >::type* = nullptr>
550  inline auto conj(const Arg& arg, const Scalar factor)
551  { return arg.conj(factor); }
552 
554 
559  template <typename Arg>
560  inline auto conj(const Arg& arg, const Permutation& perm)
561  { return arg.conj(perm); }
562 
564 
571  template <typename Arg, typename Scalar,
572  typename std::enable_if<
574  >::type* = nullptr>
575  inline auto conj(const Arg& arg, const Scalar factor, const Permutation& perm)
576  { return arg.conj(factor, perm); }
577 
579 
583  template <typename Result>
584  inline Result& conj_to(Result& result) {
585  return result.conj_to();
586  }
587 
589 
595  template <typename Result, typename Scalar,
596  typename std::enable_if<
598  >::type* = nullptr>
599  inline Result& conj_to(Result& result, const Scalar factor) {
600  return result.conj_to(factor);
601  }
602 
603 
604  template <typename... T>
605  using result_of_conj_t = decltype(conj(std::declval<T>()...));
606 
607  template <typename... T>
608  using result_of_conj_to_t = decltype(conj_to(std::declval<T>()...));
609 
610  // Contraction operations ----------------------------------------------------
611 
612 
614 
625  template <typename Left, typename Right, typename Scalar,
626  typename std::enable_if<TiledArray::detail::is_numeric<Scalar>::value>::type* = nullptr>
627  inline auto gemm(const Left& left, const Right& right, const Scalar factor,
628  const math::GemmHelper& gemm_config)
629  { return left.gemm(right, factor, gemm_config); }
630 
632 
645  template <typename Result, typename Left, typename Right, typename Scalar,
646  typename std::enable_if<TiledArray::detail::is_numeric<Scalar>::value>::type* = nullptr>
647  inline Result& gemm(Result& result, const Left& left, const Right& right,
648  const Scalar factor, const math::GemmHelper& gemm_config)
649  {
650  return result.gemm(left, right, factor, gemm_config);
651  }
652 
653 
654  template <typename... T>
655  using result_of_gemm_t = decltype(gemm(std::declval<T>()...));
656 
657  // Reduction operations ------------------------------------------------------
658 
660 
664  template <typename Arg>
665  inline auto trace(const Arg& arg)
666  { return arg.trace(); }
667 
669 
673  template <typename Arg>
674  inline auto sum(const Arg& arg)
675  { return arg.sum(); }
676 
678 
682  template <typename Arg>
683  inline auto product(const Arg& arg)
684  { return arg.product(); }
685 
687 
692  template <typename Arg>
693  inline auto squared_norm(const Arg& arg)
694  { return arg.squared_norm(); }
695 
697 
701  template <typename Arg>
702  inline auto norm(const Arg& arg)
703  { return arg.norm(); }
704 
706 
710  template <typename Arg>
711  inline auto max(const Arg& arg)
712  { return arg.max(); }
713 
715 
719  template <typename Arg>
720  inline auto min(const Arg& arg)
721  { return arg.min(); }
722 
724 
728  template <typename Arg>
729  inline auto abs_max(const Arg& arg)
730  { return arg.abs_max(); }
731 
733 
737  template <typename Arg>
738  inline auto abs_min(const Arg& arg)
739  { return arg.abs_min(); }
740 
742 
748  template <typename Left, typename Right>
749  inline auto dot(const Left& left, const Right& right)
750  { return left.dot(right); }
751 
753 
759  template <typename Left, typename Right>
760  inline auto inner_product(const Left& left, const Right& right)
761  { return left.inner_product(right); }
762 
763  template <typename T>
764  using result_of_trace_t = decltype(mult(std::declval<T>()));
765 
766  template <typename T>
767  using result_of_sum_t = decltype(sum(std::declval<T>()));
768 
769  template <typename T>
770  using result_of_product_t = decltype(product(std::declval<T>()));
771 
772  template <typename T>
773  using result_of_squared_norm_t = decltype(squared_norm(std::declval<T>()));
774 
775  template <typename T>
776  using result_of_norm_t = decltype(norm(std::declval<T>()));
777 
778  template <typename T>
779  using result_of_max_t = decltype(max(std::declval<T>()));
780 
781  template <typename T>
782  using result_of_min_t = decltype(min(std::declval<T>()));
783 
784  template <typename T>
785  using result_of_abs_max_t = decltype(abs_max(std::declval<T>()));
786 
787  template <typename T>
788  using result_of_abs_min_t = decltype(abs_min(std::declval<T>()));
789 
790  template <typename L, typename R>
791  using result_of_dot_t = decltype(dot(std::declval<L>(), std::declval<R>()));
792 
795 } // namespace TiledArray
796 
797 #endif /* TILEDARRAY_NONINTRUSIVE_API_TENSOR_H__INCLUDED */
decltype(neg(std::declval< T >()...)) result_of_neg_t
decltype(mult_to(std::declval< T >()...)) result_of_mult_to_t
decltype(auto) product(const Tile< Arg > &arg)
Multiply the elements of a tile.
Definition: tile.h:911
decltype(abs_min(std::declval< T >())) result_of_abs_min_t
decltype(auto) subt(const Tile< Left > &left, const Tile< Right > &right)
Subtract tile arguments.
Definition: tile.h:489
decltype(auto) min(const Tile< Arg > &arg)
Minimum element of a tile.
Definition: tile.h:948
decltype(gemm(std::declval< T >()...)) result_of_gemm_t
decltype(auto) squared_norm(const Tile< Arg > &arg)
Squared vector 2-norm of the elements of a tile.
Definition: tile.h:921
decltype(conj_to(std::declval< T >()...)) result_of_conj_to_t
decltype(abs_max(std::declval< T >())) result_of_abs_max_t
decltype(subt_to(std::declval< T >()...)) result_of_subt_to_t
Tile< Result > & mult_to(Tile< Result > &result, const Tile< Arg > &arg)
Multiply to the result tile.
Definition: tile.h:668
decltype(auto) norm(const Tile< Arg > &arg)
Vector 2-norm of a tile.
Definition: tile.h:930
decltype(auto) conj(const Tile< Arg > &arg)
Create a complex conjugated copy of a tile.
Definition: tile.h:772
decltype(mult(std::declval< T >()...)) result_of_mult_t
decltype(auto) abs_min(const Tile< Arg > &arg)
Absolute mainimum element of a tile.
Definition: tile.h:966
decltype(auto) abs_max(const Tile< Arg > &arg)
Absolute maximum element of a tile.
Definition: tile.h:957
TiledArray::expressions::ExprTrait< Left >::scalar_type dot(const TiledArray::expressions::Expr< Left > &a1, const TiledArray::expressions::Expr< Right > &a2)
Definition: utils.h:96
decltype(conj(std::declval< T >()...)) result_of_conj_t
decltype(product(std::declval< T >())) result_of_product_t
Tile< Result > & neg_to(Tile< Result > &result)
Multiplication constant scalar to a tile.
Definition: tile.h:758
decltype(min(std::declval< T >())) result_of_min_t
decltype(auto) max(const Tile< Arg > &arg)
Maximum element of a tile.
Definition: tile.h:939
decltype(auto) neg(const Tile< Arg > &arg)
Negate the tile argument.
Definition: tile.h:739
Contraction to *GEMM helper.
Definition: gemm_helper.h:39
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:119
bool empty(const Tile< Arg > &arg)
Check that arg is empty (no data)
Definition: tile.h:305
decltype(auto) sum(const Tile< Arg > &arg)
Sum the elements of a tile.
Definition: tile.h:902
decltype(neg_to(std::declval< T >()...)) result_of_neg_to_t
decltype(auto) mult(const Tile< Left > &left, const Tile< Right > &right)
Multiplication tile arguments.
Definition: tile.h:614
decltype(sum(std::declval< T >())) result_of_sum_t
auto inner_product(const Left &left, const Right &right)
Vector inner product of two tiles.
decltype(max(std::declval< T >())) result_of_max_t
decltype(mult(std::declval< T >())) result_of_trace_t
decltype(dot(std::declval< L >(), std::declval< R >())) result_of_dot_t
decltype(subt(std::declval< T >()...)) result_of_subt_t
Tile< Result > & subt_to(Tile< Result > &result, const Tile< Arg > &arg)
Subtract from the result tile.
Definition: tile.h:568
decltype(squared_norm(std::declval< T >())) result_of_squared_norm_t
decltype(norm(std::declval< T >())) result_of_norm_t
decltype(auto) gemm(const Tile< Left > &left, const Tile< Right > &right, const Scalar factor, const math::GemmHelper &gemm_config)
Contract and scale tile arguments.
Definition: tile.h:857
Result & conj_to(Tile< Result > &result)
In-place complex conjugate a tile.
Definition: tile.h:820
decltype(auto) trace(const Tile< Arg > &arg)
Sum the hyper-diagonal elements a tile.
Definition: tile.h:893