Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
RLH edited this page Dec 27, 2011 · 13 revisions

Synopsis

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

Current Status

Currently this API is invoked using mapSeq to get the JavaScript library version and map to get the optimized version. This is a temporary situation as we undergo some reworking of the API.

Arguments

elementalFunction described below

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

Elemental Function

function (a, arg1, arg2, ...)

this The entire ParallelArray

val An element from the ParallelArray

Optional arguments - 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

pa.map(function(val){return val;})

Clone this wiki locally