StaticSymmetry.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2013 Christian Seiler <christian@iwakd.de>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_CXX11_TENSORSYMMETRY_STATICSYMMETRY_H
11 #define EIGEN_CXX11_TENSORSYMMETRY_STATICSYMMETRY_H
12 
13 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
20 template <typename list>
22 
23 template <int... nn>
25  constexpr static std::size_t N = sizeof...(nn);
26 
27  template <typename T>
28  constexpr static inline std::array<T, N> run(const std::array<T, N>& indices) {
29  return {{indices[nn]...}};
30  }
31 };
32 
33 template <typename indices_, int flags_>
35  typedef indices_ indices;
36  constexpr static int flags = flags_;
37 };
38 
39 template <typename Gen, int N>
42  Gen::Flags>
44 };
45 
46 template <int N>
49 };
50 
51 template <typename iib>
53  template <int... iia>
56  }
57 };
58 
59 template <typename A, typename B>
61  private:
62  typedef typename A::indices iia;
63  typedef typename B::indices iib;
64  constexpr static int ffa = A::flags;
65  constexpr static int ffb = B::flags;
66 
67  public:
68  static_assert(iia::count == iib::count, "Cannot multiply symmetry elements with different number of indices.");
69 
71  ffa ^ ffb>
73 };
74 
75 template <typename A, typename B>
77  typedef typename A::indices iia;
78  typedef typename B::indices iib;
79  constexpr static int ffa = A::flags;
80  constexpr static int ffb = B::flags;
81  static_assert(iia::count == iib::count, "Cannot compare symmetry elements with different number of indices.");
82 
83  constexpr static bool value = is_same<iia, iib>::value;
84 
85  private:
86  /* this should be zero if they are identical, or else the tensor
87  * will be forced to be pure real, pure imaginary or even pure zero
88  */
89  constexpr static int flags_cmp_ = ffa ^ ffb;
90 
91  /* either they are not equal, then we don't care whether the flags
92  * match, or they are equal, and then we have to check
93  */
94  constexpr static bool is_zero = value && flags_cmp_ == NegationFlag;
95  constexpr static bool is_real = value && flags_cmp_ == ConjugationFlag;
96  constexpr static bool is_imag = value && flags_cmp_ == (NegationFlag | ConjugationFlag);
97 
98  public:
99  constexpr static int global_flags =
101 };
102 
103 template <std::size_t NumIndices, typename... Gen>
105  typedef StaticSGroup<Gen...> type;
106  constexpr static std::size_t size = type::static_size;
107 };
108 
109 template <typename Index, std::size_t N, int... ii, int... jj>
110 constexpr static inline std::array<Index, N> tensor_static_symgroup_index_permute(std::array<Index, N> idx,
113  return {{idx[ii]..., idx[jj]...}};
114 }
115 
116 template <typename Index, int... ii>
117 static inline std::vector<Index> tensor_static_symgroup_index_permute(std::vector<Index> idx,
119  std::vector<Index> result{{idx[ii]...}};
120  std::size_t target_size = idx.size();
121  for (std::size_t i = result.size(); i < target_size; i++) result.push_back(idx[i]);
122  return result;
123 }
124 
125 template <typename T>
127 
128 template <typename first, typename... next>
130  template <typename Op, typename RV, std::size_t SGNumIndices, typename Index, std::size_t NumIndices,
131  typename... Args>
132  static inline RV run(const std::array<Index, NumIndices>& idx, RV initial, Args&&... args) {
133  static_assert(NumIndices >= SGNumIndices,
134  "Can only apply symmetry group to objects that have at least the required amount of indices.");
135  typedef typename internal::gen_numeric_list<int, NumIndices - SGNumIndices, SGNumIndices>::type remaining_indices;
136  initial = Op::run(tensor_static_symgroup_index_permute(idx, typename first::indices(), remaining_indices()),
137  first::flags, initial, std::forward<Args>(args)...);
138  return tensor_static_symgroup_do_apply<internal::type_list<next...>>::template run<Op, RV, SGNumIndices>(
139  idx, initial, args...);
140  }
141 
142  template <typename Op, typename RV, std::size_t SGNumIndices, typename Index, typename... Args>
143  static inline RV run(const std::vector<Index>& idx, RV initial, Args&&... args) {
144  eigen_assert(idx.size() >= SGNumIndices &&
145  "Can only apply symmetry group to objects that have at least the required amount of indices.");
146  initial = Op::run(tensor_static_symgroup_index_permute(idx, typename first::indices()), first::flags, initial,
147  std::forward<Args>(args)...);
148  return tensor_static_symgroup_do_apply<internal::type_list<next...>>::template run<Op, RV, SGNumIndices>(
149  idx, initial, args...);
150  }
151 };
152 
153 template <EIGEN_TPL_PP_SPEC_HACK_DEF(typename, empty)>
154 struct tensor_static_symgroup_do_apply<internal::type_list<EIGEN_TPL_PP_SPEC_HACK_USE(empty)>> {
155  template <typename Op, typename RV, std::size_t SGNumIndices, typename Index, std::size_t NumIndices,
156  typename... Args>
157  static inline RV run(const std::array<Index, NumIndices>&, RV initial, Args&&...) {
158  // do nothing
159  return initial;
160  }
161 
162  template <typename Op, typename RV, std::size_t SGNumIndices, typename Index, typename... Args>
163  static inline RV run(const std::vector<Index>&, RV initial, Args&&...) {
164  // do nothing
165  return initial;
166  }
167 };
168 
169 } // end namespace internal
170 
171 template <typename... Gen>
173  constexpr static std::size_t NumIndices = internal::tensor_symmetry_num_indices<Gen...>::value;
179  typedef typename group_elements::type ge;
180 
181  public:
182  constexpr inline StaticSGroup() {}
183  constexpr inline StaticSGroup(const StaticSGroup<Gen...>&) {}
184  constexpr inline StaticSGroup(StaticSGroup<Gen...>&&) {}
185 
186  template <typename Op, typename RV, typename Index, std::size_t N, typename... Args>
187  static inline RV apply(const std::array<Index, N>& idx, RV initial, Args&&... args) {
188  return internal::tensor_static_symgroup_do_apply<ge>::template run<Op, RV, NumIndices>(idx, initial, args...);
189  }
190 
191  template <typename Op, typename RV, typename Index, typename... Args>
192  static inline RV apply(const std::vector<Index>& idx, RV initial, Args&&... args) {
193  eigen_assert(idx.size() == NumIndices);
194  return internal::tensor_static_symgroup_do_apply<ge>::template run<Op, RV, NumIndices>(idx, initial, args...);
195  }
196 
197  constexpr static std::size_t static_size = ge::count;
198 
199  constexpr static inline std::size_t size() { return ge::count; }
200  constexpr static inline int globalFlags() { return group_elements::global_flags; }
201 
202  template <typename Tensor_, typename... IndexTypes>
204  Tensor_& tensor, typename Tensor_::Index firstIndex, IndexTypes... otherIndices) const {
205  static_assert(sizeof...(otherIndices) + 1 == Tensor_::NumIndices,
206  "Number of indices used to access a tensor coefficient must be equal to the rank of the tensor.");
207  return operator()(tensor, std::array<typename Tensor_::Index, Tensor_::NumIndices>{{firstIndex, otherIndices...}});
208  }
209 
210  template <typename Tensor_>
212  Tensor_& tensor, std::array<typename Tensor_::Index, Tensor_::NumIndices> const& indices) const {
213  return internal::tensor_symmetry_value_setter<Tensor_, StaticSGroup<Gen...>>(tensor, *this, indices);
214  }
215 };
216 
217 } // end namespace Eigen
218 
219 #endif // EIGEN_CXX11_TENSORSYMMETRY_STATICSYMMETRY_H
220 
221 /*
222  * kate: space-indent on; indent-width 2; mixedindent off; indent-mode cstyle;
223  */
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define eigen_assert(x)
Definition: Macros.h:910
Static symmetry group.
Definition: StaticSymmetry.h:172
constexpr static std::size_t static_size
Definition: StaticSymmetry.h:197
static RV apply(const std::array< Index, N > &idx, RV initial, Args &&... args)
Definition: StaticSymmetry.h:187
internal::tensor_symmetry_value_setter< Tensor_, StaticSGroup< Gen... > > operator()(Tensor_ &tensor, typename Tensor_::Index firstIndex, IndexTypes... otherIndices) const
Definition: StaticSymmetry.h:203
constexpr static std::size_t size()
Definition: StaticSymmetry.h:199
constexpr static std::size_t NumIndices
Definition: StaticSymmetry.h:173
group_elements::type ge
Definition: StaticSymmetry.h:179
internal::group_theory::enumerate_group_elements< internal::tensor_static_symgroup_multiply, internal::tensor_static_symgroup_equality, typename internal::tensor_static_symgroup_identity_ctor< NumIndices >::type, internal::type_list< typename internal::tensor_static_symgroup_element_ctor< Gen, NumIndices >::type... > > group_elements
Definition: StaticSymmetry.h:178
constexpr StaticSGroup(const StaticSGroup< Gen... > &)
Definition: StaticSymmetry.h:183
internal::tensor_symmetry_value_setter< Tensor_, StaticSGroup< Gen... > > operator()(Tensor_ &tensor, std::array< typename Tensor_::Index, Tensor_::NumIndices > const &indices) const
Definition: StaticSymmetry.h:211
constexpr StaticSGroup()
Definition: StaticSymmetry.h:182
static RV apply(const std::vector< Index > &idx, RV initial, Args &&... args)
Definition: StaticSymmetry.h:192
constexpr StaticSGroup(StaticSGroup< Gen... > &&)
Definition: StaticSymmetry.h:184
constexpr static int globalFlags()
Definition: StaticSymmetry.h:200
@ N
Definition: constructor.cpp:22
return int(ret)+1
constexpr static std::array< Index, N > tensor_static_symgroup_index_permute(std::array< Index, N > idx, internal::numeric_list< int, ii... >, internal::numeric_list< int, jj... >)
Definition: StaticSymmetry.h:110
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
squared absolute value
Definition: GlobalFunctions.h:87
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
@ GlobalZeroFlag
Definition: Symmetry.h:20
@ GlobalRealFlag
Definition: Symmetry.h:20
@ GlobalImagFlag
Definition: Symmetry.h:20
@ NegationFlag
Definition: Symmetry.h:18
@ ConjugationFlag
Definition: Symmetry.h:18
args
Definition: compute_granudrum_aor.py:143
type
Definition: compute_granudrum_aor.py:141
Definition: Eigen_Colamd.h:49
Definition: MoreMeta.h:55
Enumerate all elements in a finite group.
Definition: TemplateGroupTheory.h:480
Definition: Meta.h:205
Definition: MoreMeta.h:33
static RV run(const std::vector< Index > &, RV initial, Args &&...)
Definition: StaticSymmetry.h:163
static RV run(const std::array< Index, NumIndices > &, RV initial, Args &&...)
Definition: StaticSymmetry.h:157
static RV run(const std::array< Index, NumIndices > &idx, RV initial, Args &&... args)
Definition: StaticSymmetry.h:132
static RV run(const std::vector< Index > &idx, RV initial, Args &&... args)
Definition: StaticSymmetry.h:143
Definition: StaticSymmetry.h:126
tensor_static_symgroup_element< typename gen_numeric_list_swapped_pair< int, N, Gen::One, Gen::Two >::type, Gen::Flags > type
Definition: StaticSymmetry.h:43
indices_ indices
Definition: StaticSymmetry.h:35
constexpr static int flags
Definition: StaticSymmetry.h:36
constexpr static bool is_imag
Definition: StaticSymmetry.h:96
A::indices iia
Definition: StaticSymmetry.h:77
constexpr static int global_flags
Definition: StaticSymmetry.h:99
constexpr static int ffb
Definition: StaticSymmetry.h:80
constexpr static bool is_real
Definition: StaticSymmetry.h:95
constexpr static bool is_zero
Definition: StaticSymmetry.h:94
B::indices iib
Definition: StaticSymmetry.h:78
constexpr static int ffa
Definition: StaticSymmetry.h:79
constexpr static int flags_cmp_
Definition: StaticSymmetry.h:89
constexpr static bool value
Definition: StaticSymmetry.h:83
tensor_static_symgroup_element< typename gen_numeric_list< int, N >::type, 0 > type
Definition: StaticSymmetry.h:48
constexpr static numeric_list< int, get< iia, iib >::value... > helper(numeric_list< int, iia... >)
Definition: StaticSymmetry.h:54
B::indices iib
Definition: StaticSymmetry.h:63
tensor_static_symgroup_element< decltype(tensor_static_symgroup_multiply_helper< iib >::helper(iia())), ffa ^ ffb > type
Definition: StaticSymmetry.h:68
constexpr static int ffb
Definition: StaticSymmetry.h:65
constexpr static int ffa
Definition: StaticSymmetry.h:64
A::indices iia
Definition: StaticSymmetry.h:62
constexpr static std::array< T, N > run(const std::array< T, N > &indices)
Definition: StaticSymmetry.h:28
Definition: StaticSymmetry.h:104
StaticSGroup< Gen... > type
Definition: StaticSymmetry.h:105
constexpr static std::size_t size
Definition: StaticSymmetry.h:106
Definition: MoreMeta.h:22
void run(const string &dir_name, LinearSolver *linear_solver_pt, const unsigned nel_1d, bool mess_up_order)
Definition: two_d_poisson_compare_solvers.cc:317