On Saturday, 8 October 2016 at 13:06:42 UTC, Manu wrote:
Oh no, you too? >_<
Incidentally, have you had a geez over the core API? An efficient API
will emerge when we work out how to work batched operations into
ranges...

How far would `r.inBatchesOf!(N)` go in terms of compiler optimisations (e.g. vectorisation) if N is a power of 2?

auto inBatchesOf(size_t N,R)(R r) if(N!=0 &&isInputRange!R && hasLength!R)
{
    struct InBatchesOfN
    {
        R r;
        ElementType!(R)[N] batch;
        this(R _r)
        {
assert(_r.length % N ==0);// could have overloads where undefined elements == ElementType!(R).init
             r = _r;
             foreach( i; 0..N)
             {
                  batch[i] = r.front;
                  r.popFront;
             }
        }

        bool empty() { return r.empty; }
        auto front { return batch; }
        void popFront()
        {
             foreach( i; 0..N)
             {
                  batch[i] = r.front;
                  r.popFront;
             }
        }
    }

    return InBatchesOfN(r);
}

Reply via email to