Thread overview | |||||
---|---|---|---|---|---|
|
January 06, 2013 Array-wise expressions | ||||
---|---|---|---|---|
| ||||
Is there any plan to extend array-wise expressions to include calls to arbitrary "scalar" functions, i.e. auto a = [1.2, 2.3, 3.4]; auto b = [7.1, 8.2, 9.3]; auto c = new double[3]; c[] = sin( 4 * a[] + b[] ); or c[] = foo(a[], b[], 42); |
January 06, 2013 Re: Array-wise expressions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lobachevsky | On Sunday, 6 January 2013 at 15:39:03 UTC, Lobachevsky wrote:
> Is there any plan to extend array-wise expressions to include calls to arbitrary "scalar" functions
Currently, there are no plans for adding a feature like this – at least I'm not aware of any.
However, you can just use std.algorithm.map and write map!sin(…), possibly followed by .array() (import std.array) for eager evaluation.
David
|
January 06, 2013 Re: Array-wise expressions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lobachevsky | On Sunday, 6 January 2013 at 15:39:03 UTC, Lobachevsky wrote: > Is there any plan to extend array-wise expressions to include calls to arbitrary "scalar" functions, i.e. > > auto a = [1.2, 2.3, 3.4]; > auto b = [7.1, 8.2, 9.3]; > auto c = new double[3]; > c[] = sin( 4 * a[] + b[] ); > > or > > c[] = foo(a[], b[], 42); Performing this action would require several calls to foo. By convention, array operations aren't loops; it only calculates the R-value once, then sets all elements to the same value. I wrote this as a quick example: http://dpaste.dzfl.pl/4ba03ef6 It does get a random value, but it only calls rand() once so all of the elements in the array are set to the same random value. |
Copyright © 1999-2021 by the D Language Foundation