color lib
Manu via Digitalmars-d
digitalmars-d at puremagic.com
Sat Oct 8 22:21:32 PDT 2016
On 9 October 2016 at 14:03, Nicholas Wilson via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> 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);
> }
Well the trouble is the lambda that you might give to 'map' won't work
anymore. Operators don't work on batches, you need to use a completely
different API, and I think that's unfortunate.
More information about the Digitalmars-d
mailing list