color lib
Nicholas Wilson via Digitalmars-d
digitalmars-d at puremagic.com
Mon Oct 10 17:10:04 PDT 2016
On Sunday, 9 October 2016 at 13:28:05 UTC, Manu wrote:
> On 9 October 2016 at 15:34, Ilya Yaroshenko via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
>> On Sunday, 9 October 2016 at 05:21:32 UTC, Manu wrote:
>>>
>>> On 9 October 2016 at 14:03, Nicholas Wilson via Digitalmars-d
>>> <digitalmars-d at puremagic.com> wrote:
>>>>
>>>> [...]
>>>
>>>
>>> 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.
>>
>>
>> Could you please give an example what type of operation should
>> be vectorized?
>
> Even operations that don't require shuffling, eg:
> RGBA8[] a, b;
> zip(a, b).map!(e => e[0] + e[1]).copy(output);
>
> Which I've suggested before (and Walter liked the idea), could
> be
> sugared up by making use of the languages largely under-used
> array
> operation syntax:
> output[] = a[] + b[]; // ie, types have overloaded addition
> operators, so this array expression would be lowered to the
> pipeline
> expression above. This would be super-useful for HEAPS of
> things!
>
> Even these still need to be done in batches since colour adds
> are saturating operations, and there are SIMD instructions for
> saturating arithmetic, so we basically always have to do colour
> work in SIMD, which means batching, and that basically ruins
> any chance for natural, readable, expressions in your code. I
> want to find a way that we can express these operations
> naturally, without having to always manually handle the
> batching.
>
> If we can get there, then I will say D is a good language for
> stream-data processing.
What about forwarding the array ops to a foreach of the static
array?
Like as above but instead of:
ElementType!(R)[N] batch;
have:
static struct Batch
{
ElementType!(R)[N] elements;
auto get() { return elements[];}
Batch opBinary(string op)(Batch rhs)
if(hasOperator!(ElementType!(R),op))
{
Batch b;
foreach(i; iota(N)) mixin("b.elements[i] = elememts[i]"
~op~"rhs.elements[i]");
return b;
}
//repeat for opUnary,opOpAssign...
}
Batch batch;
I'll make another forum thread for this.
More information about the Digitalmars-d
mailing list