Skip to content

Instantly share code, notes, and snippets.

@jsreeram
Created August 8, 2012 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsreeram/3299719 to your computer and use it in GitHub Desktop.
Save jsreeram/3299719 to your computer and use it in GitHub Desktop.
Parallel Array Constructors
// Create an empty Parallel Array
var pa0 = new ParallelArray();
// pa0 = <>
// Create a ParallelArray out of a nested JS array.
// Note that the inner arrays are also ParallelArrays
var pa1 = new ParallelArray([ [0,1], [2,3], [4,5] ]);
// pa1 = <<0,1>, <2,3>, <4.5>>
// Create a ParallelArray from another ParallelArray
var pa2 = new ParallelArray(pa1);
// pa2 = <<0,1>, <2,3>, <4.5>>
// Create a ParallelArray from several other ParallelArrays
var pa3 = new ParallelArray(<0,1>, <2,3>);
// pa3 = <<0,1>,<2,3>>
// Create a one-dimensional ParallelArray of length 3 using
// the "comprehension" constructor
var pa6 = new ParallelArray(3,
function(i){return [i, i+1];});
// pa6 = <<0,1>, <1,2>, <2,3>>
// Create a two-dimensional ParallelArray with shape [3, 2] using
// the comprehension constructor
var pa7 = new ParallelArray([3, 2],
function(iv){return iv[0] * iv[1];});
// pa7 = <<0,0>, <0,1>, <0,2>>
// Create a ParallelArray from canvas.
// This creates a PA with shape [w, h, 4], corresponding to the
// width and height of the canvas and the RGBA values for each pixel.
var pa8 = new ParallelArray(canvas);
// pa8 = CanvasPixelArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment