CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
op_types.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_op_types_h__
13#define __cxz_op_types_h__
14
15#include "base/base.h"
16#include "xpr/xpr_base.h"
17#include "array/array_base.h"
18
19namespace CNORXZ
20{
21
22
23 template <class OpT>
24 class COpInterface : public XprInterface<OpT>
25 {
26 public:
27 constexpr COpInterface() = default;
28
29 OpT& THIS() { return static_cast<OpT&>(*this); }
30 const OpT& THIS() const { return static_cast<const OpT&>(*this); }
31
32 constexpr decltype(auto) r() { return THIS(); }
33 constexpr decltype(auto) r() const { return THIS(); }
34
35 template <class F, class IndexT>
36 constexpr decltype(auto) c(F&& f, const Sptr<IndexT>& ind) const;
37
38 template <class IndexT>
39 constexpr decltype(auto) c(const Sptr<IndexT>& ind) const;
40
41 template <class F, class... Args>
42 constexpr decltype(auto) o(F&& f, Args&&... args) const;
43
44 };
45
46 template <class OpT>
47 class OpInterface : public COpInterface<OpT>
48 {
49 public:
51
52 constexpr OpInterface() = default;
53
54 OpT& THIS() { return static_cast<OpT&>(*this); }
55 const OpT& THIS() const { return static_cast<const OpT&>(*this); }
56
57 template <class IndexT, class F, class... Args>
58 constexpr decltype(auto) ax(const Sptr<IndexT>& ind, F&& f, const Args&... args);
59
60 template <class IndexT, class F, class... Args>
61 inline void a(const Sptr<IndexT>& ind, F&& f, const Args&... args);
62 };
63
64 template <class T>
66 { static constexpr bool value = std::is_base_of<COpInterface<T>,T>::value; };
67
68 template <class T>
70 { static constexpr bool value = std::is_base_of<OpInterface<T>,T>::value; };
71
72 template <class T>
73 struct op_size
74 { static constexpr SizeT value = is_operation<T>::value ? 1 : 0; };
75
76 template <typename T, class IndexT>
77 class COpRoot : public COpInterface<COpRoot<T,IndexT>>
78 {
79 public:
81
82 constexpr COpRoot() = default;
83
84 constexpr COpRoot(const CArrayBase<T>& a, const Sptr<IndexT>& ind);
85 constexpr COpRoot(const T* data, const Sptr<IndexT>& ind);
86 constexpr COpRoot& init(const T* data, const Sptr<IndexT>& ind);
87
88 template <class PosT>
89 constexpr decltype(auto) operator()(const PosT& pos) const;
90
91 constexpr decltype(auto) operator()() const;
92
93 template <SizeT I>
94 constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
95
96 const T* data() const;
97
98 private:
99 const T* mData = nullptr;
100 Sptr<IndexT> mIndex;
101 };
102
103 template <typename T, class IndexT>
104 constexpr decltype(auto) coproot(const CArrayBase<T>& a, const Sptr<IndexT>& ind);
105
106 template <typename T, class IndexT>
107 constexpr decltype(auto) coproot(const T* a, const Sptr<IndexT>& ind);
108
109 template <class IndexT, class Op>
110 class POpRoot : public COpInterface<POpRoot<IndexT,Op>>
111 {
112 public:
114
115 constexpr POpRoot() = default;
116
117 constexpr POpRoot(const Sptr<IndexT>& ind, const SizeT* parts, Op&& op);
118
119 template <class PosT>
120 constexpr decltype(auto) operator()(const PosT& pos) const;
121
122 constexpr decltype(auto) operator()() const;
123
124 template <SizeT I>
125 constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
126
127 constexpr decltype(auto) data() const;
128
129 private:
130
131 Sptr<IndexT> mIndex;
132 FPos mFp;
133 Op mOp;
134 };
135
136 template <class IndexT, class Op>
137 constexpr decltype(auto) poproot(const Sptr<IndexT>& ind, const SizeT* parts, Op&& op);
138
139 template <typename T, class IndexT>
140 class OpCont : public OpInterface<OpCont<T,IndexT>>
141 {
142 public:
146
147 constexpr OpCont() = default;
148
149 constexpr OpCont(const Sptr<IndexT>& ind);
150 constexpr OpCont& init(const Sptr<IndexT>& ind);
151 constexpr OpCont& init(const Sptr<IndexT>& ind, const Vector<T>& c);
152
153 constexpr decltype(auto) r();
154 constexpr decltype(auto) r() const;
155
156 template <class Op>
157 constexpr OpCont& operator=(const Op& in);
158
159 template <class Op>
160 constexpr OpCont& operator+=(const Op& in);
161
162 constexpr OpCont& operator=(const OpCont& in);
163
164 template <class PosT>
165 constexpr decltype(auto) operator()(const PosT& pos) const;
166
167 constexpr decltype(auto) operator()() const;
168
169 template <SizeT I>
170 constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
171
172 T* data();
173 const T* data() const;
174
175 private:
176 Sptr<IndexT> mIndex;
177 CT mC;
178 };
179
180
181 template <typename T, class IndexT>
182 class OpRoot : public OpInterface<OpRoot<T,IndexT>>
183 {
184 public:
186
187 constexpr OpRoot() = default;
188
189 constexpr OpRoot(ArrayBase<T>& a, const Sptr<IndexT>& ind);
190 constexpr OpRoot(T* data, const Sptr<IndexT>& ind);
191 constexpr OpRoot& init(T* data, const Sptr<IndexT>& ind);
192
193 template <class Op>
194 constexpr OpRoot& operator=(const Op& in);
195
196 template <class Op>
197 constexpr OpRoot& operator+=(const Op& in);
198
199 constexpr OpRoot& operator=(const OpRoot& in);
200
201 template <class PosT>
202 constexpr decltype(auto) operator()(const PosT& pos) const;
203
204 constexpr decltype(auto) operator()() const;
205
206 template <SizeT I>
207 constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
208
209 T* data() const;
210
211 private:
212 T* mData = nullptr;
213 Sptr<IndexT> mIndex;
214
215 };
216
217 template <typename T, class IndexT>
218 constexpr decltype(auto) oproot(ArrayBase<T>& a, const Sptr<IndexT>& ind);
219
220 template <class F, class... Ops>
221 class Operation : public OpInterface<Operation<F,Ops...>>
222 {
223 public:
225
226 constexpr Operation() = default;
227
228 constexpr Operation(F&& f, const Ops&... ops);
229
230 template <class PosT>
231 constexpr decltype(auto) operator()(const PosT& pos) const;
232
233 constexpr decltype(auto) operator()() const;
234
235 template <SizeT I>
236 constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
237
238 private:
239 template <SizeT... Is>
240 constexpr decltype(auto) exec(std::index_sequence<Is...> is) const;
241
242 template <SizeT I, SizeT... Is>
243 constexpr decltype(auto) rootStepsi(const IndexId<I>& id,
244 std::index_sequence<Is...> is) const;
245
246 Tuple<Ops...> mOps;
247 F mF;
248
249 };
250
251 template <class F, class... Ops>
252 constexpr decltype(auto) operation(F&& f, const Ops&... ops);
253
254 template <class Tar, class Src>
255 constexpr decltype(auto) assignxpr(const Tar& tar, const Src& src);
256
257 template <class Tar, class Src>
258 constexpr decltype(auto) assignxpr(Tar& tar, const Src& src);
259
260 template <class F, class... Ops>
261 struct op_size<Operation<F,Ops...>>
262 { static constexpr SizeT value = ( op_size<Ops>::value + ... ); };
263
264 template <class CXpr>
265 class Contraction : public OpInterface<Contraction<CXpr>>
266 {
267 public:
269
270 constexpr Contraction() = default;
271
272 constexpr Contraction(CXpr&& cxpr);
273
274 template <class PosT>
275 constexpr decltype(auto) operator()(const PosT& pos) const;
276
277 constexpr decltype(auto) operator()() const;
278
279 template <SizeT I>
280 constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
281
282 private:
283 CXpr mCXpr;
284 };
285
286 template <class CXpr>
288 { static constexpr SizeT value = op_size<CXpr>::value; };
289
290 template <class F, class Op, class IndexT>
291 constexpr decltype(auto) contraction(F&& f, Op&& op, const Sptr<IndexT>& i);
292
293 template <class IndexT>
294 constexpr decltype(auto) indexOp(const Sptr<IndexT>& i);
295
296}
297
298#endif
Array base class declarations.
basic headers
constexpr decltype(auto) c(const Sptr< IndexT > &ind) const
constexpr decltype(auto) o(F &&f, Args &&... args) const
constexpr decltype(auto) r() const
Definition op_types.h:33
constexpr decltype(auto) c(F &&f, const Sptr< IndexT > &ind) const
const OpT & THIS() const
Definition op_types.h:30
constexpr COpInterface()=default
constexpr decltype(auto) r()
Definition op_types.h:32
constexpr COpRoot & init(const T *data, const Sptr< IndexT > &ind)
Definition op_types.cc.h:85
constexpr decltype(auto) rootSteps(const IndexId< I > &id) const
constexpr COpRoot()=default
const T * data() const
OpInterface< COpRoot< T, IndexT > > OI
Definition op_types.h:80
constexpr Contraction()=default
constexpr decltype(auto) rootSteps(const IndexId< I > &id) const
OpInterface< Contraction< CXpr > > OI
Definition op_types.h:268
constexpr OpCont & operator+=(const Op &in)
OpInterface< OpCont< T, IndexT > > OI
Definition op_types.h:143
constexpr OpCont & operator=(const Op &in)
Container< T, index_const_size< IndexT >::value, index_has_const_size< IndexT >::value >::type CT
Definition op_types.h:145
constexpr decltype(auto) rootSteps(const IndexId< I > &id) const
constexpr OpCont & init(const Sptr< IndexT > &ind)
constexpr OpCont()=default
constexpr decltype(auto) r()
constexpr decltype(auto) ax(const Sptr< IndexT > &ind, F &&f, const Args &... args)
COpInterface< OpT > OI
Definition op_types.h:50
constexpr OpInterface()=default
void a(const Sptr< IndexT > &ind, F &&f, const Args &... args)
Definition op_types.cc.h:62
const OpT & THIS() const
Definition op_types.h:55
T * data() const
constexpr OpRoot & operator+=(const Op &in)
constexpr decltype(auto) rootSteps(const IndexId< I > &id) const
constexpr OpRoot()=default
constexpr OpRoot & init(T *data, const Sptr< IndexT > &ind)
constexpr OpRoot & operator=(const Op &in)
OpInterface< OpRoot< T, IndexT > > OI
Definition op_types.h:185
OpInterface< Operation< F, Ops... > > OI
Definition op_types.h:224
constexpr decltype(auto) rootSteps(const IndexId< I > &id) const
constexpr Operation()=default
constexpr decltype(auto) rootSteps(const IndexId< I > &id) const
constexpr decltype(auto) data() const
constexpr POpRoot()=default
COpInterface< POpRoot< IndexT, Op > > OI
Definition op_types.h:113
constexpr decltype(auto) indexOp(const Sptr< IndexT > &i)
constexpr decltype(auto) poproot(const Sptr< IndexT > &ind, const SizeT *parts, Op &&op)
uint64_t SizeT
Definition types.h:38
constexpr decltype(auto) coproot(const CArrayBase< T > &a, const Sptr< IndexT > &ind)
std::vector< T, Allocator< T > > Vector
Definition types.h:310
constexpr decltype(auto) contraction(F &&f, Op &&op, const Sptr< IndexT > &i)
Sptr< Range > rangeCast(const RangePtr r)
std::tuple< T... > Tuple
Definition types.h:60
constexpr decltype(auto) operation(F &&f, const Ops &... ops)
constexpr decltype(auto) assignxpr(const Tar &tar, const Src &src)
std::shared_ptr< T > Sptr
Definition types.h:48
constexpr decltype(auto) oproot(ArrayBase< T > &a, const Sptr< IndexT > &ind)
static constexpr bool value
Definition op_types.h:70
static constexpr bool value
Definition op_types.h:66
static constexpr SizeT value
Definition op_types.h:74
Xpression base declarations.