shift.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  * shift.h
22  * Jan 10, 2016
23  *
24  */
25 
26 #ifndef TILEDARRAY_TILE_INTERFACE_SHIFT_H__INCLUDED
27 #define TILEDARRAY_TILE_INTERFACE_SHIFT_H__INCLUDED
28 
29 #include "../type_traits.h"
30 #include "cast.h"
31 
32 namespace TiledArray {
33 
35 
41 template <typename Arg, typename Index,
42  typename = std::enable_if_t<detail::is_integral_range_v<Index>>>
43 inline auto shift(const Arg& arg, const Index& range_shift) {
44  return arg.shift(range_shift);
45 }
46 
48 
54 template <typename Arg, typename Index,
55  typename = std::enable_if_t<std::is_integral_v<Index>>>
56 inline auto shift(const Arg& arg,
57  const std::initializer_list<Index>& range_shift) {
58  return arg.shift(range_shift);
59 }
60 
62 
68 template <typename Arg, typename Index,
69  typename = std::enable_if_t<detail::is_integral_range_v<Index>>>
70 inline auto shift_to(Arg& arg, const Index& range_shift) {
71  return arg.shift_to(range_shift);
72 }
73 
75 
81 template <typename Arg, typename Index,
82  typename = std::enable_if_t<std::is_integral_v<Index>>>
83 inline auto shift_to(Arg& arg,
84  const std::initializer_list<Index>& range_shift) {
85  return arg.shift_to(range_shift);
86 }
87 
88 namespace tile_interface {
89 
90 using TiledArray::shift;
92 
93 template <typename T>
94 using result_of_shift_t = typename std::decay<decltype(
95  shift(std::declval<T>(), std::declval<std::vector<long>>()))>::type;
96 
97 template <typename T>
98 using result_of_shift_to_t = typename std::decay<decltype(
99  shift_to(std::declval<T>(), std::declval<std::vector<long>>()))>::type;
100 
101 template <typename Result, typename Arg, typename Enabler = void>
102 class Shift {
103  public:
104  typedef Result result_type;
105  typedef Arg argument_type;
106 
107  template <typename Index>
109  const Index& range_shift) const {
110  return shift(arg, range_shift);
111  }
112 };
113 
114 template <typename Result, typename Arg>
115 class Shift<Result, Arg,
116  typename std::enable_if<
117  !std::is_same<Result, result_of_shift_t<Arg>>::value>::type>
118  : public TiledArray::Cast<Result, result_of_shift_t<Arg>> {
119  private:
121 
122  public:
123  typedef Result result_type;
124  typedef Arg argument_type;
125 
126  template <typename Index>
128  const Index& range_shift) const {
129  return Cast_::operator()(shift(arg, range_shift));
130  }
131 };
132 
133 template <typename Result, typename Arg, typename Enabler = void>
134 class ShiftTo {
135  public:
136  typedef Result result_type;
137  typedef Arg argument_type;
138 
139  template <typename Index>
140  result_type operator()(argument_type& arg, const Index& range_shift) const {
141  return shift_to(arg, range_shift);
142  }
143 };
144 
145 template <typename Result, typename Arg>
146 class ShiftTo<Result, Arg,
147  typename std::enable_if<!std::is_same<
148  Result, result_of_shift_to_t<Arg>>::value>::type>
149  : public TiledArray::Cast<Result, result_of_shift_to_t<Arg>> {
150  private:
152 
153  public:
154  typedef Result result_type;
155  typedef Arg argument_type;
156 
157  template <typename Index>
158  result_type operator()(argument_type& arg, const Index& range_shift) const {
159  return Cast_::operator()(shift_to(arg, range_shift));
160  }
161 };
162 
163 template <typename Arg, typename Enabler = void>
164 struct shift_trait {
165  typedef Arg type;
166 };
167 
168 template <typename Arg>
169 struct shift_trait<Arg, typename std::enable_if<TiledArray::detail::is_type<
170  result_of_shift_t<Arg>>::value>::type> {
172 };
173 
174 } // namespace tile_interface
175 
177 
182 template <typename Result, typename Arg>
183 class Shift : public TiledArray::tile_interface::Shift<Result, Arg> {};
184 
186 
191 template <typename Result, typename Arg>
192 class ShiftTo : public TiledArray::tile_interface::ShiftTo<Result, Arg> {};
193 
194 } // namespace TiledArray
195 
196 #endif // TILEDARRAY_TILE_INTERFACE_SHIFT_H__INCLUDED
Tile< Arg > & shift_to(Tile< Arg > &arg, const Index &range_shift)
Shift the range of arg in place.
Definition: tile.h:704
Shift the range of tile.
Definition: shift.h:183
result_type operator()(const argument_type &arg, const Index &range_shift) const
Definition: shift.h:108
Arg argument_type
Argument tile type.
Definition: shift.h:137
detail::ShiftWrapper< T > shift(T &tensor)
Shift a tensor from one range to another.
result_type operator()(argument_type &arg, const Index &range_shift) const
Definition: shift.h:140
typename std::decay< decltype(shift_to(std::declval< T >(), std::declval< std::vector< long > >()))>::type result_of_shift_to_t
Definition: shift.h:99
Tile cast operation.
Definition: cast.h:168
Shift the range of tile in place.
Definition: shift.h:192
typename std::decay< decltype(shift(std::declval< T >(), std::declval< std::vector< long > >()))>::type result_of_shift_t
Definition: shift.h:95
Result result_type
Result tile type.
Definition: shift.h:136
Arg argument_type
Argument tile type.
Definition: shift.h:105
Result result_type
Result tile type.
Definition: shift.h:104