@@ -160,13 +160,21 @@ <h3>Multi-Dimensional and Uniform</h3>
160
160
The shape of a < code > ParallelArray</ code > is specified as
161
161
an array of numbers in which the value of the < em > i</ em > th
162
162
element is the number of elements in the < em > i</ em > th
163
- dimension of the < code > ParallelArray</ code > . So, for
164
- instance, a 4x5 matrix of numbers can be represented as
165
- a < code > ParallelArray</ code > object whose shape
163
+ dimension of the < code > ParallelArray</ code > . The number
164
+ of dimensions of a < code > ParallelArray</ code > is the
165
+ number of elements in its shape array.
166
+ </ p >
167
+
168
+ < p >
169
+ For instance, a 4x5 matrix of numbers can be represented
170
+ as a < code > ParallelArray</ code > object whose shape
166
171
is < code > [4, 5]</ code > . Similarly, a 2D image in which
167
172
each pixel has an RGBA value can be represented as
168
173
a < code > ParallelArray</ code > object with shape < code > [h,
169
- w, 4]</ code > . An empty < code > ParallelArray</ code > has
174
+ w, 4]</ code > . (The < code > 4</ code > comes from the fact
175
+ that an RGBA value is 4 bytes, one for each of the red,
176
+ green, and blue channels and one for the alpha channel.)
177
+ An empty < code > ParallelArray</ code > has
170
178
shape < code > [0]</ code > , and a
171
179
one-dimensional < code > ParallelArray</ code > with three
172
180
elements has shape < code > [3]</ code > .
@@ -208,8 +216,8 @@ <h2><a name="constructors"></a>Constructors</h2>
208
216
We can pass a regular JavaScript array to
209
217
the < code > ParallelArray</ code > constructor, as well.
210
218
Here, we are creating a < code > ParallelArray</ code > out of
211
- a nested JS array. The inner arrays are
212
- also < code > ParallelArray</ code > s.
219
+ a nested JS array. The inner arrays will also become
220
+ < code > ParallelArray</ code > s.
213
221
</ p >
214
222
215
223
< pre class ="brush: js; ">
@@ -338,7 +346,7 @@ <h3>Map</h3>
338
346
< p >
339
347
The first method we will discuss is < code > map</ code > ,
340
348
probably the most prominent and well-known data-parallel
341
- skeleton . The < code > map</ code > method expects a function
349
+ construct . The < code > map</ code > method expects a function
342
350
as its first argument that, given a single value, produces
343
351
a new value as its result. We call such
344
352
functions < em > elemental functions</ em > , since they are
@@ -540,7 +548,7 @@ <h3>Scan</h3>
540
548
each position contains the sum of all elements of the
541
549
source vector up to that position. To implement this
542
550
parallel pattern, < code > ParallelArray</ code > s support a
543
- < em > scan</ em > method.
551
+ < code > scan</ code > method.
544
552
</ p >
545
553
546
554
< pre class ="brush: js; ">
@@ -551,8 +559,13 @@ <h3>Scan</h3>
551
559
< p >
552
560
Here, we again use the < code > plus</ code > elemental
553
561
function from the previous reduction example. However,
554
- when used with < em > scan</ em > , it now produces the
555
- prefix-sum array of the < code > source</ code > array.
562
+ when used with < code > scan</ code > , it now produces the
563
+ prefix-sum array of the < code > source</ code > array, which
564
+ is the < code > ParallelArray</ code > < code > [1, 3, 6, 10,
565
+ 15]</ code > . If we were only interested in the last
566
+ element, < code > 15</ code > , we could have just
567
+ called < code > reduce</ code > ; by using < code > scan</ code > , we
568
+ also get all the intermediate results.
556
569
</ p >
557
570
558
571
< p >
@@ -575,7 +588,7 @@ <h3>Scatter</h3>
575
588
specify or costly to compute. Instead, it is preferable to
576
589
specify for a certain < em > source</ em > index where it
577
590
should be stored in the result array. This pattern is
578
- supported by the < em > scatter</ em > method in River
591
+ supported by the < code > scatter</ code > method in River
579
592
Trail. Here is an example:
580
593
</ p >
581
594
@@ -586,8 +599,8 @@ <h3>Scatter</h3>
586
599
587
600
< p >
588
601
We first compute our source array < code > source</ code > . In
589
- a second step, we apply the < em > scatter</ em > method with a
590
- single argument: the < em > scatter
602
+ a second step, we apply the < code > scatter</ code > method
603
+ with a single argument: the < em > scatter
591
604
vector</ em > < code > [4,0,3,1,2]</ code > . Thereby, we specify
592
605
that the first element of < code > source</ code > is to become
593
606
the fifth element of the result (indexing starts with 0),
0 commit comments