Why ranges don't return vectors?
monarch_dodra
monarchdodra at gmail.com
Fri Mar 1 08:39:20 PST 2013
On Friday, 1 March 2013 at 15:38:28 UTC, Piotr Szturmaj wrote:
> Range abstraction is limiting some useful optimizations, mainly
> vectorization. Even if range internally uses a buffer and does
> some SIMD operations on it, it exposes only one element from
> this buffer, which can't be used for next SIMD operation. In
> other words it limits pipelining.
Well, why don't you write a range whose "elements" are vectors?
Or that operate on vectors.
The range abstraction only defines how you iterate and view a
collection. YOU are the one that defines what the elements in
that collection are.
For example, "chunk" will do exactly that: Given a range, it
transforms it into a range of sub-slices:
//----
int[] arr = iota(0, 16).array(); //[0, 1, 2, ..., 16]
auto chunks = std.range.chunks(arr, 4);
foreach (int[] chunk ; chunks)
{
chunk[] *= 2;
writeln(chunk);
}
//----
What else are you asking for? Nothing is stopping you from
pipping the chunk elements with another range, btw.
More information about the Digitalmars-d
mailing list