parallel map and dot product

# Norm Rubin (12 years ago)

I've started to read through the parallel JavaScript proposal and have a novice question How would you write a dot product Given:

P1 = parallelArray(1,2,3) P2 = ParallelArray(4,5,6)

We want to compute 14 + 25 + 3*6

As far as I can tell, you need a reduce to do the sums, so you first need to construct P12 = ParallelArray(14, 25, 3*6)

Is there a way to generate this using map?


This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.

# Till Schneidereit (12 years ago)

the people behind ParallelArray mostly aren't on es-discuss, so you'll probably have more luck here: lists.mozilla.org/listinfo/dev-tech-js-engine-rivertrail

hth, till

# Norm Rubin (12 years ago)

Thanks I'll move it over

# Hudson, Rick (12 years ago)

In this case it is the same as with a normal array.

function dotProduct(v1, v2) {
return v1.map(function (e, i) {return e*v2[i];}).reduce(function (a, b) {return a+b;});
}
# Brendan Eich (12 years ago)

Hudson, Rick wrote:

In this case it is the same as with a normal array.

function dotProduct(v1, v2) {
return v1.map(function (e, i) {return e*v2[i];}).reduce(function (a, b) {return a+b;});
}

So much nicer with ES6 arrow functions (now in SpiderMonkey):

function dotProduct(v1, v2) {
    return v1.map((e, i) => e * v2[i]).reduce((a, b) => a + b);
}
# Norm Rubin (12 years ago)

From a language point of view, I see the relation to array is pretty important but what about the approach in something like

underscore.js

underscore.js: .sum(.map() ......)
compared to: Parallel.sum(parallel.map(......)

Where_ is some kind of object proving map and friends Then you could pass around special versions of map etc, like a version specially good for small parallel arrays, one for latency devices (cpus) , one for throughput devices (gpu) or a version with extra debugging

Is that far from the spirit of JavaScript?