32 ProcForeach(
const char *
name,
35 ~ProcForeach()
override {}
37 void configure(ConfIterator iter,
unsigned int n)
override;
39 configureLoop(ConfigCtx::Context *ctx, ConfigCtx::iterator
begin,
40 ConfigCtx::iterator cur, ConfigCtx::iterator
end)
override;
42 void eval(ValueIterator iter,
unsigned int n)
const override;
43 std::vector<double> deriv(
44 ValueIterator iter,
unsigned int n)
const override;
48 unsigned int &nOffset)
const override;
52 ConfContext(
unsigned int origin,
unsigned int count) :
53 origin(origin), count(count) {}
54 ~ConfContext()
override {}
65 ProcForeach::ProcForeach(
const char *
name,
73 void ProcForeach::configure(ConfIterator iter,
unsigned int n)
75 iter << Variable::FLAG_NONE;
77 iter << iter++(Variable::FLAG_MULTIPLE);
81 ProcForeach::configureLoop(ConfigCtx::Context *ctx_, ConfigCtx::iterator
begin,
82 ConfigCtx::iterator cur, ConfigCtx::iterator
end)
84 ConfContext *ctx =
dynamic_cast<ConfContext*
>(ctx_);
86 return new ConfContext(cur - begin + 1,
count);
88 for(ConfigCtx::iterator iter = cur; iter !=
end; iter++) {
89 iter->mask = Variable::FLAG_ALL;
90 iter->origin = ctx->origin;
99 void ProcForeach::eval(ValueIterator iter,
unsigned int n)
const 101 auto const offset = iter.loopCtx().offset();
104 auto& loopSize = iter.loopCtx().size();
106 unsigned int size = iter.size();
116 std::vector<double> ProcForeach::deriv(
117 ValueIterator iter,
unsigned int n)
const 119 auto const offset = iter.loopCtx().offset();
120 std::vector<unsigned int> offsets;
121 unsigned int in = 0,
out = 0;
123 offsets.push_back(in +
offset);
124 in += (iter++).
size();
128 std::vector<double>
result((
out + 1) * in, 0.0);
129 for(
unsigned int i = 0;
i <
out;
i++)
130 result[(
i + 1) * in + offsets[
i]] = 1.0;
137 unsigned int nOutput, LoopCtx& ctx,
unsigned int &nOffset)
const 139 auto&
index = ctx.index();
140 bool endIteration =
false;
145 auto&
offset = ctx.offset();
146 auto& size = ctx.size();
148 if (
offset == 0 && !endIteration) {
149 for(
int cur = *conf + size; nOutput--; cur +=
size)
158 }
else if (
offset > size) {
constexpr char const *const kStop