Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
Jaswanth Sreeram edited this page Jan 15, 2015 · 13 revisions

Synopsis

myParallelArray.map(elementalFunction, arg1, arg2, ...)

Arguments

elementalFunction described below

arg1, arg2, ... optional arguments passed unchanged to elemental function

Elemental Function

function (val, arg1, arg2, ...) { <body of the function> }

this Inside the body of the elemental function, the value of this is the ParallelArray object on which the map was invoked - for example, in the invocation of map above, the this would refer to myParallelArray

val An element from the ParallelArray

arg1, arg2, ... - Same as the optional arguments passed to map.

The result of the function will be used as an element to be placed in the result at the same offset we found val in the source array.

Returns

A freshly minted ParallelArray

Elements are the results of applying the elemental function to the elements in the original ParallelArray plus any optional arguments.

Discussion

Unlike combine, map does not provide a depth argument to steer the number of dimensions the map operation iterates over. Instead, flatten can be used to collapse the outer dimensions of an array into a single dimension. A consecutive application of map then iterates over all previously collapsed dimensions. Finally, partition can be used to restore the original shape of the array. For example, instead of

result = pa.map(2, f);

where 2 would be the depth argument, can instead be expressed by

tmp = pa.flatten();
tmp = tmp.map(f);
result = tmp.partition(pa.getShape()[0]);

Note that this does not work for combine. As combine exposes the iteration index to the elemental function, collapsing the iteration space to a single index would be observable from the elemental function.

Example: an identity function

 // an identity function
 pa.map(function(val){return val;})
 // Adding one to each element.
 var source = new ParallelArray([1,2,3,4,5]);
 var plusOne = source.map(function inc(v) { return v+1; }); //<2,3,4,5,6>
Clone this wiki locally