-
Notifications
You must be signed in to change notification settings - Fork 71
map
map
applies an elemental function to every element in a ParallelArray
and returns a new ParallelArray
from the results.
Unlike combine
, map
does not take a depth argument to determine 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
var result = pa.map(2, f);
where 2
would be the depth argument, one can write
var tmp = pa.flatten();
var tmp = tmp.map(f);
var result = tmp.partition(pa.getShape()[0]);
Note that this approach does not work for combine
: since combine
exposes the iteration index to the elemental function, collapsing the iteration space to a single index would be observable from the elemental function.
myParallelArray.map(elementalFunction, arg1, arg2, ...)
-
elementalFunction
: described below. -
arg1
,arg2
, ...: optional arguments, passed unchanged toelementalFunction
.
function(val, arg1, arg2, ...) { <body> }
-
val
: An element from the originalParallelArray
on whichmap
is invoked. -
arg1
,arg2
, ...: The same as the optional arguments passed tomap
.
The result of the elemental function is the array element to be placed in map
's result at the same index position at which val
appeared in the original array.
Inside the elemental function, the value of this
will be the ParallelArray
object on which map
was invoked. For example, in the invocation of map
above, this
would refer to myParallelArray
.
A freshly minted ParallelArray
whose elements are the results of applying the elemental function to each element of the source array, plus any optional arguments.
// an identity function; `pa` is a ParallelArray
pa.map(function(val){ return val; })
// increment each element of a ParallelArray by 1
var source = new ParallelArray([1,2,3,4,5]);
var plusOne = source.map(function inc(v) { return v+1; });