July 05, 2008 Re: Iterating over multiple collections in parallel | ||||
---|---|---|---|---|
| ||||
Posted in reply to Koroskin Denis | Koroskin Denis wrote:
> int[] c = new int[a.length];
> foreach (i : a; j : b; ref k : c) {
> k = a + b;
> }
What's wrong with
auto c= a .* b;
except, that it is neither suggested nor supported?
Or
auto c= a (*) b;
which was suggested some long time ago, but has not got through?
Is it horrible then to define:
void opDotMul(T)(out T c, T x, T y){
assert( x.length == y.length);
c.length= x.length;
foreach( i,v; x){
c[i]= x[i] * y[i];
}
}
-manfred
|
July 05, 2008 Re: Iterating over multiple collections in parallel | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred_Nowak | Manfred_Nowak wrote:
> Koroskin Denis wrote:
>
>> int[] c = new int[a.length];
>> foreach (i : a; j : b; ref k : c) {
>> k = a + b;
>> }
>
> What's wrong with
>
> auto c= a .* b;
>
> except, that it is neither suggested nor supported?
>
>
> Or
>
> auto c= a (*) b;
>
> which was suggested some long time ago, but has not got through?
>
>
> Is it horrible then to define:
>
> void opDotMul(T)(out T c, T x, T y){
> assert( x.length == y.length);
> c.length= x.length;
> foreach( i,v; x){
> c[i]= x[i] * y[i];
> }
> }
>
> -manfred
what about:
int[100] a, b, c;
for (int i = 0; i < 100; ++i) {
a[i] = myCrazyFunkyFunction(b[i], c[i]);
}
D does not and should not have an opMyCrazyFunkyFunction.
|
July 05, 2008 Re: Iterating over multiple collections in parallel | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred_Nowak | On Sun, 06 Jul 2008 01:45:08 +0400, Manfred_Nowak <svv1999@hotmail.com> wrote:
> Koroskin Denis wrote:
>
>> int[] c = new int[a.length];
>> foreach (i : a; j : b; ref k : c) {
>> k = a + b;
>> }
>
> What's wrong with
>
> auto c= a .* b;
>
> except, that it is neither suggested nor supported?
>
>
> Or
>
> auto c= a (*) b;
>
> which was suggested some long time ago, but has not got through?
>
>
> Is it horrible then to define:
>
> void opDotMul(T)(out T c, T x, T y){
> assert( x.length == y.length);
> c.length= x.length;
> foreach( i,v; x){
> c[i]= x[i] * y[i];
> }
> }
>
> -manfred
Nothing wrong. It was just brought as an example.
Replace int[] with a List!(int) that exposes opApply() but not iterators and try again :)
The only way (apart from using stackthreads) you can do it now is something like this:
List!(int) a, b, c;
int[] acopy, bcopy;
foreach (i; a) {
acopy ~= i;
}
foreach (j; b) {
bcopy ~= j;
}
int i = 0;
foreach (ref k; c) {
k = acopy[i] + bcopy[i];
}
compare with the following:
List!(int) a, b, c;
foreach (i; a) (j; b)(ref k; c) {
c = a + b;
}
which one would you prefer?
|
July 06, 2008 Re: Iterating over multiple collections in parallel | ||||
---|---|---|---|---|
| ||||
Posted in reply to Koroskin Denis | Koroskin Denis wrote: > List!(int) a, b, c; [...] > which one would you prefer? Still c= a .+ b; To do componentwise operations imposes some requirements for the involved types. These are at least: - an order on the elements, and - definition(s) for the operation(s) on the elements If an opApply cannot be interpreted as representing an ordering, than your List!-example will fail badly. -manfred |
July 06, 2008 Re: Iterating over multiple collections in parallel | ||||
---|---|---|---|---|
| ||||
Posted in reply to Yigal Chripun | Yigal Chripun wrote: > D does not and should not have an opMyCrazyFunkyFunction. - Maybe some knowledge of some types of disagreeing and their relation can turn out to be useful: http://blog.createdebate.com/2008/04/07/writing-strong-arguments/ - Maybe a DigitalMars_funky_extension.opMyCrazyFunkyFunction is allowed to exist? At least it's in the language specification: http://www.digitalmars.com/d/1.0/pragma.html -manfred |
July 06, 2008 Re: Iterating over multiple collections in parallel | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred_Nowak | Manfred_Nowak wrote:
> Yigal Chripun wrote:
>
>> D does not and should not have an opMyCrazyFunkyFunction.
>
> - Maybe some knowledge of some types of disagreeing and their relation can turn out to be useful: http://blog.createdebate.com/2008/04/07/writing-strong-arguments/
>
> - Maybe a DigitalMars_funky_extension.opMyCrazyFunkyFunction is allowed to exist? At least it's in the language specification: http://www.digitalmars.com/d/1.0/pragma.html
>
> -manfred
What's so strong about the word "should" ?!
If I wanted to make a "strong argument" as you say, I would've used the
word "must".
Also, I didn't talk about pragmas and compiler specific extensions but rather meant the core language.
maybe you want to suggest a way to define infix functions?
Last thing: I find it ridiculous you try to teach me the proper way to post because you didn't like my phrasing while other people use insults and other bad language on the NG and you're fine with that. That's just smells of hypocrisy. If you really want to educate someone here, start with those that curse, swear and troll.
disappointed,
Yigal
|
Copyright © 1999-2021 by the D Language Foundation