Closed timotheecour closed 6 years ago
Yes, foreach (idx, elem; ndslice)
is not yet supported. See this forum post and the next two for more information on how to do this.
Alternatives:
// two integer additions
// per iteration
size_t i;
foreach(ai; temp) { i++; }
Slower alternative:
// two integer additions
// one multiplication
// per iteration
foreach(i; 0..temp.length) {auto ai = temp[i]; }
enumerate
can be used too, but I expect it is the slowest way.
If temp
has original structure (strides and lengths) then assumeSameStructure
can be used, the following way is fast too:
// two integer additions
foreach(tup; assumeSameStructure!("i", "ai")(iotaSlice(temp.shape), temp))
{
auto i = tup.i;
auto ai = tup.ai;
}
We can implement them now, but I expect one to create a DIP (D Improvement Proposal) to do it a proper way without workarounds that may be deprecated in the future.
I a interesting if your algorithm can be implemented in terms of mir.ndslice.algorithm
?
(BTW, starting from 2.072 Mir ndslice is compatible with Phobos ndslice).
this should be supported IMO ?
or should we just use:
import std.range:enumerate; foreach(i,ai;temp.enumerate){}