CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
for.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_for_h__
13#define __cxz_for_h__
14
15#include "base/base.h"
16#include "xpr_base.h"
17#include "func.h"
18
19namespace CNORXZ
20{
21
22 template <SizeT L, class Xpr, class F = NoF>
23 class For : public XprInterface<For<L,Xpr,F>>
24 {
25 public:
27
28 constexpr For(SizeT size, const IndexId<L>& id, const Xpr& xpr, F&& f);
29
30 template <class PosT>
31 inline decltype(auto) operator()(const PosT& last) const;
32
33 inline decltype(auto) operator()() const;
34
35 template <SizeT I>
36 inline decltype(auto) rootSteps(const IndexId<I>& id) const;
37
38 private:
39 SizeT mSize = 0;
40 IndexId<L> mId;
41 Xpr mXpr;
42 typedef decltype(mXpr.rootSteps(mId)) XPosT;
43 XPosT mExt;
44 F mF;
45 };
46
47 template <SizeT L, class Xpr, class F>
48 constexpr decltype(auto) mkFor(SizeT size, const IndexId<L>& id, const Xpr& xpr, F&& f);
49
50 template <SizeT L, class Xpr>
51 constexpr decltype(auto) mkFor(SizeT size, const IndexId<L>& id, const Xpr& xpr);
52
53 // unrolled loop:
54 template <SizeT N, SizeT L, class Xpr, class F = NoF>
55 class SFor : public XprInterface<SFor<N,L,Xpr,F>>
56 {
57 public:
59
60 constexpr SFor(const IndexId<L>& id, const Xpr& xpr, F&& f);
61
62 template <class PosT>
63 constexpr decltype(auto) operator()(const PosT& last) const;
64
65 constexpr decltype(auto) operator()() const;
66
67 template <SizeT I>
68 constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
69
70 private:
71
72 template <SizeT I, class PosT>
73 constexpr decltype(auto) exec(const PosT& last) const;
74
75 template <SizeT I>
76 constexpr decltype(auto) exec() const;
77
78 template <SizeT I, class PosT>
79 inline void exec2(const PosT& last) const;
80
81 template <SizeT I>
82 inline void exec2() const;
83
84 IndexId<L> mId;
85 Xpr mXpr;
86 typedef decltype(mXpr.rootSteps(mId)) XPosT;
87 XPosT mExt;
88 F mF;
89
90 };
91
92 template <SizeT N, SizeT L, class Xpr, class F>
93 constexpr decltype(auto) mkSFor(const IndexId<L>& id, const Xpr& xpr, F&& f);
94
95 template <SizeT N, SizeT L, class Xpr>
96 constexpr decltype(auto) mkSFor(const IndexId<L>& id, const Xpr& xpr);
97
98 // partial for:
99 template <SizeT L1, SizeT L2, class Xpr, class F = NoF>
100 class PFor : public XprInterface<PFor<L1,L2,Xpr,F>>
101 {
102 public:
104
105 constexpr PFor(SizeT size, const IndexId<L1>& id1, const IndexId<L2>& id2,
106 const SizeT* map, const Xpr& xpr, F&& f);
107
108 template <class PosT>
109 inline decltype(auto) operator()(const PosT& last) const;
110
111 inline decltype(auto) operator()() const;
112
113 template <SizeT I>
114 inline decltype(auto) rootSteps(const IndexId<I>& id) const;
115
116 private:
117 SizeT mSize = 0;
118 IndexId<L1> mId1;
119 IndexId<L2> mId2;
120 Xpr mXpr;
121 typedef decltype(mXpr.rootSteps(mId1)) XPosT1;
122 typedef decltype(mXpr.rootSteps(mId2)) XPosT2;
123 XPosT1 mExt1;
124 XPosT2 mExt2;
125 FPos mPart;
126 F mF;
127 };
128
129 template <SizeT L, class Xpr, class F>
130 constexpr decltype(auto) mkFor(SizeT size, const IndexId<L>& id, const Xpr& xpr, F&& f);
131
132 template <SizeT L, class Xpr>
133 constexpr decltype(auto) mkFor(SizeT size, const IndexId<L>& id, const Xpr& xpr);
134
135 // multi-threading
136 template <SizeT L, class Xpr, class F = NoF>
137 class TFor : public XprInterface<TFor<L,Xpr,F>>
138 {
139 public:
141
142 constexpr TFor(SizeT size, const IndexId<L>& id, const Xpr& xpr, F&& f);
143
144 template <class PosT>
145 inline decltype(auto) operator()(const PosT& last) const;
146
147 inline decltype(auto) operator()() const;
148
149 template <SizeT I>
150 inline decltype(auto) rootSteps(const IndexId<I>& id) const;
151
152 private:
153 SizeT mSize = 0;
154 IndexId<L> mId;
155 Xpr mXpr;
156 typedef decltype(mXpr.rootSteps(mId)) XPosT;
157 XPosT mExt;
158 F mF;
159 };
160
161 // Extension For (Vectorization)
162 template <SizeT N, SizeT L, class Xpr, class F = NoF>
163 class EFor : public XprInterface<EFor<N,L,Xpr>>
164 {
165 public:
167
168 constexpr EFor(const IndexId<L>& id, const Xpr& xpr, F&& f);
169
170 template <class PosT>
171 constexpr decltype(auto) operator()(const PosT& last) const;
172
173 constexpr decltype(auto) operator()() const;
174
175 template <SizeT I>
176 constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
177
178 private:
179 IndexId<L> mId;
180 Xpr mXpr;
181 typedef decltype(mXpr.rootSteps(mId)) XPosT;
182 XPosT mExt;
183 F mF;
184 };
185
186}
187
188#endif
basic headers
constexpr EFor(const IndexId< L > &id, const Xpr &xpr, F &&f)
Definition for.cc.h:407
constexpr decltype(auto) rootSteps(const IndexId< I > &id) const
DEFAULT_MEMBERS(EFor)
decltype(auto) rootSteps(const IndexId< I > &id) const
Definition for.cc.h:81
DEFAULT_MEMBERS(For)
constexpr For(SizeT size, const IndexId< L > &id, const Xpr &xpr, F &&f)
Definition for.cc.h:27
constexpr PFor(SizeT size, const IndexId< L1 > &id1, const IndexId< L2 > &id2, const SizeT *map, const Xpr &xpr, F &&f)
Definition for.cc.h:227
decltype(auto) rootSteps(const IndexId< I > &id) const
Definition for.cc.h:289
DEFAULT_MEMBERS(PFor)
constexpr SFor(const IndexId< L > &id, const Xpr &xpr, F &&f)
Definition for.cc.h:107
constexpr decltype(auto) rootSteps(const IndexId< I > &id) const
DEFAULT_MEMBERS(SFor)
decltype(auto) rootSteps(const IndexId< I > &id) const
Definition for.cc.h:396
constexpr TFor(SizeT size, const IndexId< L > &id, const Xpr &xpr, F &&f)
Definition for.cc.h:317
DEFAULT_MEMBERS(TFor)
Special function objects declarations.
constexpr decltype(auto) mkSFor(const IndexId< L > &id, const Xpr &xpr, F &&f)
Definition for.cc.h:211
uint64_t SizeT
Definition types.h:38
decltype(auto) xpr(const Sptr< I > &i)
Sptr< Range > rangeCast(const RangePtr r)
constexpr decltype(auto) mkFor(SizeT size, const IndexId< L > &id, const Xpr &xpr, F &&f)
Definition for.cc.h:91
Xpression base declarations.