TiledArray  0.7.0
permute.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2016 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  * permute.h
22  * Jan 10, 2016
23  *
24  */
25 
26 #ifndef TILEDARRAY_TILE_INTERFACE_PERMUTE_H__INCLUDED
27 #define TILEDARRAY_TILE_INTERFACE_PERMUTE_H__INCLUDED
28 
29 #include "../type_traits.h"
30 #include "../tile_interface/cast.h"
31 
32 namespace TiledArray {
33 
34  class Permutation;
35 
37 
42  template <typename Arg>
43  inline auto permute(const Arg& arg, const Permutation& perm)
44  { return arg.permute(perm); }
45 
46  template <typename> struct permute_trait;
47 
48  namespace tile_interface {
49 
50  using TiledArray::permute;
51 
52  template <typename T>
53  using result_of_permute_t = typename std::decay<
54  decltype(permute(std::declval<T>(),
55  std::declval<Permutation>()))>::type;
56 
57  template <typename Tile, typename Enabler = void>
58  struct permute_trait {
59  typedef Tile type;
60  };
61 
62  template <typename Arg>
63  struct permute_trait<Arg,
64  typename std::enable_if<
65  TiledArray::detail::is_type<result_of_permute_t<Arg> >::value
66  >::type>
67  {
69  };
70 
71  template <typename Result, typename Arg, typename Enabler = void>
72  class Permute {
73  public:
74 
75  typedef Result result_type;
76  typedef Arg argument_type;
77 
79  const Permutation& perm) const
80  {
81  using TiledArray::permute;
82  return permute(arg, perm);
83  }
84  };
85 
86  template <typename Result, typename Arg>
87  class Permute<Result, Arg,
88  typename std::enable_if<
89  ! std::is_same<Result, result_of_permute_t<Arg> >::value
90  >::type> :
91  public TiledArray::Cast<Result, result_of_permute_t<Arg> >
92  {
93  private:
95  public:
96 
97  typedef Result result_type;
98  typedef Arg argument_type;
99 
101  const Permutation& perm) const
102  {
103  using TiledArray::permute;
104  return Cast_::operator()(permute(arg, perm));
105  }
106 
107  };
108 
109  } // namespace tile_interface
110 
111 
113 
118  template <typename Arg>
119  struct permute_trait :
121  { };
122 
123 
125 
129  template <typename Result, typename Arg>
130  class Permute : public TiledArray::tile_interface::Permute<Result, Arg> { };
131 
132 } // namespace TiledArray
133 
134 #endif // TILEDARRAY_TILE_INTERFACE_PERMUTE_H__INCLUDED
Tile cast operation.
Definition: cast.h:34
STL namespace.
Permute trait.
Definition: permute.h:46
Permute a tile.
Definition: permute.h:130
typename std::decay< decltype(permute(std::declval< T >(), std::declval< Permutation >()))>::type result_of_permute_t
Definition: permute.h:55
result_type operator()(const argument_type &arg, const Permutation &perm) const
Definition: permute.h:78
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:119
Arg argument_type
Argument tile type.
Definition: permute.h:76
Result result_type
Result tile type.
Definition: permute.h:75
TiledArray::Range permute(const TiledArray::Range &r, const Perm &p)
Definition: btas.h:285
An N-dimensional shallow copy wrapper for tile objects.
Definition: tile.h:80