Thread overview
[Issue 6345] A different kind of vector operation
Dec 17, 2022
Iain Buclaw
Jul 05, 2023
Nick Treleaven
Jul 17, 2023
Nick Treleaven
June 09, 2015
https://issues.dlang.org/show_bug.cgi?id=6345

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |D2

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=6345

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P4

--
July 05, 2023
https://issues.dlang.org/show_bug.cgi?id=6345

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick@geany.org

--- Comment #5 from Nick Treleaven <nick@geany.org> ---
List comprehensions would cover these and avoid any ambiguity. They are also more expressive and composable than vector ops:

>    auto foos = new Foo[100];
>    foos[].y += 10; // ********

[e.y += 10 for e in foos];

Note this doesn't need to allocate an array as the result is not used.

>     cdouble[100] foos;
>     foos[].re = 5.0;

[e.re = 5.0 for e in foos];

>   auto foos = new Foo[100];
>   auto ints = new int[100]
>   ints = foos[].y;

ints = [e.y for e in foos];

> float[] buffers = malloc...;
> float*[] CBuffers = buffers[].ptr;

float*[] cBuffers = [e.ptr for e in buffers];

Also, type inference could be used `auto cBuffers = ` because the RHS is no
longer ambiguous with `float*`.
(This would also solve Issue #2548).

> auto M = new double[][](10, 20);
> M[][1] = 1.0;

[e[1] = 1.0 for e in m];

And indexes mean they can cover vector ops too:

> a[] = b[] / c[];

a = [b[i] / e for i, e in c];

A benefit is that `b.length` can be larger than `c.length`. Also we can use the index variable e.g. to index b in reverse order.

The key benefit however is that we can use expressions not supported by vector ops such as function calls, comparisons and the conditional operator - see issue #5636.

--
July 17, 2023
https://issues.dlang.org/show_bug.cgi?id=6345

--- Comment #6 from Nick Treleaven <nick@geany.org> ---
A less drastic change would be this syntax, which also solves the ambiguities:

float*[] CBuffers = buffers[#].ptr;

m[#][1] = 1.0;

c[#] = a[#] < b[#]; // issue #5636

Note: issue #5636 was fixed by simply documenting that comparisons, equality, etc make the operation not a vector op, just an array comparison.

--