Skip to content
This repository


myArray.combine(elementalFunction, arg1, arg2, ...)
myArray.combine(depth, elementalFunction, arg1, arg2, ...)

Current Status

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


depth (optional) the number of dimensions traversed to access an element in this; the default is 1

elementalFunction described below

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

Elemental Function

function (index, arg1, arg2, ...)

this The ParallelArray

index Location in combine’s result where the result of the elemental function is placed. Suitable as the first argument to “get” to retrieve source values.

arg1, arg2, ... Same as the optional arguments passed to combine

The result is used as an element to be placed in combine’s result at the location indicated by index


A freshly minted ParallelArray whose elements are the results of applying the elemental function.


Combine is similar to map, except an index is provided. This allows elemental functions to access elements from the source array relative to the one at the current index position.


 // an identity function
 pa.combine(function(i){return this.get(i);})

 // element-wise addition of two vectors
 pa1.combine(function(iv, pa2){return this.get(iv) + pa2.get(iv);}, pa2)

 // addition of two arrays of same shape
 pa1.combine(pa1.getShape().length, function(iv, pa2){return this.get(iv) + pa2.get(iv);}, pa2)

 // increment each element by 1
 var source = new ParallelArray([1,2,3,4,5]);
 var plusOne = source.combine(function inc(i) { return this.get(i)+1; });

 // reverse the elements
 var source = new ParallelArray([1,2,3,4,5]);
 var reverse = source.combine(function rev(i) { return this.get(this.length-i[0]-1); });

 // transpose a matrix using a depth of 2.
 var source = new ParallelArray([4,4], function (iv) { return iv[0]*iv[1]; });
 var transpose = source.combine(2, function rev(iv) { 
                                       return this.get([this.getShape()[0]-iv[0]-1, 
                                                        this.getShape()[1]-iv[1]-1]); });
Something went wrong with that request. Please try again.