noop.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  * noop.h
22  * June 27, 2013
23  *
24  */
25 
26 #ifndef TILEDARRAY_TILE_OP_NOOP_H__INCLUDED
27 #define TILEDARRAY_TILE_OP_NOOP_H__INCLUDED
28 
29 #include "../tile_interface/clone.h"
30 #include "../tile_interface/permute.h"
31 
32 namespace TiledArray {
33 namespace detail {
34 
36 
43 template <typename Result, typename Arg, bool Consumable>
44 class Noop {
45  public:
47  typedef Arg argument_type;
48  typedef Result result_type;
49 
50  static constexpr bool is_consumable = Consumable;
51 
52  private:
53  // Permuting tile evaluation function
54  // These operations cannot consume the argument tile since this operation
55  // requires temporary storage space.
56  template <typename Perm,
57  typename = std::enable_if_t<detail::is_permutation_v<Perm>>>
58  result_type eval(const Arg& arg, const Perm& perm) const {
60  return permute(arg, perm);
61  }
62 
63  // Non-permuting tile evaluation functions
64  // The compiler will select the correct functions based on the
65  // consumability of the arguments.
66 
67  template <bool C, typename std::enable_if<!C>::type* = nullptr>
68  result_type eval(const Arg& arg) const {
70  return clone(arg);
71  }
72 
73  template <bool C, typename std::enable_if<C>::type* = nullptr>
74  result_type eval(Arg& arg) const {
75  return arg;
76  }
77 
78  public:
80 
85  template <typename Perm,
86  typename = std::enable_if_t<detail::is_permutation_v<Perm>>>
87  result_type operator()(const argument_type& arg, const Perm& perm) const {
88  return eval(arg, perm);
89  }
90 
92 
96  template <typename A>
97  result_type operator()(A&& arg) const {
98  return Noop_::template eval<is_consumable>(arg);
99  }
100 
102 
106  constexpr bool can_consume =
108  std::is_same<result_type, argument_type>::value;
109  return Noop_::template eval<can_consume>(arg);
110  }
111 
112 }; // class Noop
113 
114 } // namespace detail
115 } // namespace TiledArray
116 
117 #endif // TILEDARRAY_TILE_OP_NOOP_H__INCLUDED
Consumable tile type trait.
Definition: type_traits.h:611
Result result_type
The result tile type.
Definition: noop.h:48
void permute(InputOp &&input_op, OutputOp &&output_op, Result &result, const Perm &perm, const Arg0 &arg0, const Args &... args)
Construct a permuted tensor copy.
Definition: permute.h:117
result_type operator()(const argument_type &arg, const Perm &perm) const
Permute operator.
Definition: noop.h:87
DistArray< Tile, Policy > clone(const DistArray< Tile, Policy > &arg)
Create a deep copy of an array.
Definition: clone.h:43
Arg argument_type
The argument type.
Definition: noop.h:47
result_type operator()(A &&arg) const
Clone operator.
Definition: noop.h:97
Noop< Result, Arg, Consumable > Noop_
This object type.
Definition: noop.h:46
Permute a tile.
Definition: permute.h:134
result_type consume(argument_type &arg) const
Pass-through operations (shallow copy)
Definition: noop.h:105
static constexpr bool is_consumable
Definition: noop.h:50
Create a deep copy of a tile.
Definition: clone.h:128
Tile no operation (noop)
Definition: noop.h:44