Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
sherhut edited this page Oct 29, 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 (arg1, arg2, ...)

this 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 this 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

Other than 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 dimenions. Finally, partition can be used to restore the original shape of the array. For example,

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(){return this;})

Clone this wiki locally