TiledArray  0.7.0
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/permute.h"
30 #include "../tile_interface/clone.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 
54  // Permuting tile evaluation function
55  // These operations cannot consume the argument tile since this operation
56  // requires temporary storage space.
57 
58  result_type eval(const Arg& arg, const Permutation& 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 { return arg; }
75 
76  public:
77 
79 
85  operator()(const argument_type& arg, const Permutation& perm) const {
86  return eval(arg, perm);
87  }
88 
90 
94  template <typename A>
95  result_type operator()(A&& arg) const {
96  return Noop_::template eval<is_consumable>(arg);
97  }
98 
100 
104  constexpr bool can_consume = is_consumable_tile<argument_type>::value &&
105  std::is_same<result_type, argument_type>::value;
106  return Noop_::template eval<can_consume>(arg);
107  }
108 
109  }; // class Noop
110 
111  } // namespace detail
112 } // namespace TiledArray
113 
114 #endif // TILEDARRAY_TILE_OP_NOOP_H__INCLUDED
void permute(InputOp &&input_op, OutputOp &&output_op, Result &result, const Permutation &perm, const Arg0 &arg0, const Args &... args)
Construct a permuted tensor copy.
Definition: permute.h:122
result_type operator()(const argument_type &arg, const Permutation &perm) const
Permute operator.
Definition: noop.h:85
Result result_type
The result tile type.
Definition: noop.h:48
Permute a tile.
Definition: permute.h:130
DistArray< Tile, Policy > clone(const DistArray< Tile, Policy > &arg)
Create a deep copy of an array.
Definition: clone.h:43
Noop< Result, Arg, Consumable > Noop_
This object type.
Definition: noop.h:46
Tile no operation (noop)
Definition: noop.h:44
Arg argument_type
The argument type.
Definition: noop.h:47
static constexpr bool is_consumable
Definition: noop.h:50
Consumable tile type trait.
Definition: type_traits.h:406
result_type operator()(A &&arg) const
Clone operator.
Definition: noop.h:95
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:119
result_type consume(argument_type &arg) const
Pass-through operations (shallow copy)
Definition: noop.h:103
Create a deep copy of a tile.
Definition: clone.h:138