next up previous contents
Next: Array Sorting Functions Up: Library Procedures Previous: Array Combining Scatter Functions

Array Prefix and Suffix Functions

  In a scan of a vector, each element of the result is a function of the elements of the vector that precede it (for a prefix scan) or that follow it (for a suffix scan). These functions provide scan operations on arrays and subarrays. The functions have the general form

XXX_PREFIX(ARRAY, DIM, MASK, SEGMENT, EXCLUSIVE)
XXX_SUFFIX(ARRAY, DIM, MASK, SEGMENT, EXCLUSIVE)

except in the special cases noted below. The allowed values of XXX are ALL, ANY, COPY, COUNT, IALL, IANY, IPARITY, MAXVAL, MINVAL, PARITY, PRODUCT, and SUM.

When comments below apply to both prefix and suffix forms of the routines, we will refer to them as YYYFIX functions.

The arguments DIM, MASK, SEGMENT, and EXCLUSIVE are optional. The COPY_YYYFIX functions do not have MASK or EXCLUSIVE arguments. The ALL_YYYFIX, ANY_YYYFIX, COUNT_YYYFIX, and PARITY_YYYFIX functions do not have MASK arguments. Their ARRAY argument must be of type logical; it is denoted MASK in their specifications in Section 7.7.

The arguments MASK and SEGMENT must be of type logical. SEGMENT must have the same shape as ARRAY. MASK must be conformable with ARRAY. EXCLUSIVE is a logical scalar. DIM is a scalar integer between one and the rank of ARRAY.


Examples. The examples below illustrate all possible combinations of optional arguments for SUM_PREFIX. The default value for SUM_YYYFIX is zero.

Case (i): SUM_PREFIX((/1,3,5,7/)) is [1 4 9 16].

Case (ii):

                  /       \
                  | 1 2 3 |
If B is the array | 4 5 6 |,
                  | 7 8 9 |
                  \       /

                                /          \
                                |  1 14 30 |
then SUM_PREFIX(B) is the array |  5 19 36 |.
                                | 12 27 45 |
                                \          /

Case (iii): If A is the array [3 5 -2 -1 7 4 8], then SUM_PREFIX(A, MASK = A .LT. 6) is [3 8 6 5 5 9 9]

Case (iv):

                  /       \ 
                  | 1 2 3 |
If B is the array | 4 5 6 |,
                  | 7 8 9 |
                  \       /

                                       /          \
                                       |  1  2  3 |
then SUM_PREFIX(B, DIM=1) is the array |  5  7  9 |.
                                       | 12 15 18 |
                                       \          /



                                      /         \
                                      | 1  3  6 |
and SUM_PREFIX(B, DIM=2) is the array | 4  9 15 |.
                                      | 7 15 24 |
                                      \         /

Case (v): SUM_PREFIX((/1,3,5,7/), EXCLUSIVE=.TRUE.) is [0 1 4 9].

Case (vi):

                   /                \
                   |  1  2  3  4  5 |
If  B is the array |  6  7  8  9 10 |,  M is the array
                   | 11 12 13 14 15 |
                   \                /

   /           \                       /           \
   | T T T T T |                       | T T F F F |
   | F F T T T |,   and S is the array | F T T F F |,   then:
   | T F T F F |                       | T T T T T |
   \           /                       \           /

SUM_PREFIX(B, DIM=2, MASK=M, SEGMENT=S, EXCLUSIVE=.TRUE.) is
                                                     /               \
                                                     | 0  1  0  3  7 |
                                                     | 0  0  0  0  9 |.
                                                     | 0 11 11 24 24 |
                                                     \               /

SUM_PREFIX(B, DIM=2, MASK=M, SEGMENT=S, EXCLUSIVE=.FALSE.) is
                                                     /                \
                                                     | 1  3  3  7  12 |
                                                     | 0  0  8  9  19 |.
                                                     | 11 11 24 24 24 |
                                                     \                /

                                                  /               \
                                                  | 0  1  3  6 10 |
SUM_PREFIX(B, DIM=2, MASK=M, EXCLUSIVE=.TRUE.) is | 0  0  0  8 17 |.
                                                  | 0 11 11 24 24 |
                                                  \               /

                                                   /                \
                                                   |  1  3  6 10 15 |
SUM_PREFIX(B, DIM=2, MASK=M, EXCLUSIVE=.FALSE.) is |  0  0  8 17 27 |.
                                                   | 11 11 24 24 24 |
                                                   \                /

                                                     /               \
                                                     | 0  1  0  3  7 |
SUM_PREFIX(B, DIM=2, SEGMENT=S, EXCLUSIVE=.TRUE.) is | 0  0  7  0  9 |.
                                                     | 0 11 23 36 50 |
                                                     \               /


                                                      /                \
                                                      |  1  3  3  7 12 |
SUM_PREFIX(B, DIM=2, SEGMENT=S, EXCLUSIVE=.FALSE.) is |  6  7 15  9 19 |.
                                                      | 11 23 36 50 65 |
                                                      \                /


                                          /               \
                                          | 0  1  3  6 10 |
SUM_PREFIX(B, DIM=2, EXCLUSIVE=.TRUE.) is | 0  6 13 21 30 |.
                                          | 0 11 23 36 50 |
                                          \               /

                                           /                \
                                           |  1  3  6 10 15 |
SUM_PREFIX(B, DIM=2, EXCLUSIVE=.FALSE.) is |  6 13 21 30 40 |.
                                           | 11 23 36 50 65 |
                                           \                /

                                                      /            \
                                                      | 0 11 0 0 0 |
SUM_PREFIX(B, MASK=M, SEGMENT=S, EXCLUSIVE=.TRUE.) is | 0 13 0 4 5 |.
                                                      | 0 13 8 0 0 |
                                                      \            /

SUM_PREFIX(B, MASK=M, SEGMENT=S, EXCLUSIVE=.FALSE.) is
                                                     /                \
                                                     |  1 13  3  4  5 |
                                                     |  0 13  8 13 15 |.
                                                     | 11 13 21  0  0 |
                                                     \                /

                                           /               \
                                           | 0 12 14 38 51 |
SUM_PREFIX(B, MASK=M, EXCLUSIVE=.TRUE.) is | 1 14 17 42 66 |.
                                           | 1 14 25 51 66 |
                                           \               /

                                            /                \
                                            |  1 14 17 42 56 |
SUM_PREFIX(B, MASK=M, EXCLUSIVE=.FALSE.) is |  1 14 25 51 66 |.
                                            | 12 14 38 51 66 |
                                            \                /

                                              /            \
                                              | 0 11 0 0 0 |
SUM_PREFIX(B, SEGMENT=S, EXCLUSIVE=.TRUE.) is | 0 13 0 4 5 |.
                                              | 0 20 8 0 0 |
                                              \            /

                                               /                \
                                               |  1 13  3  4  5 |
SUM_PREFIX(B, SEGMENT=S, EXCLUSIVE=.FALSE.) is |  6 20  8 13 15 |.
                                               | 11 32 21 14 15 |
                                               \                /

                                   /                \
                                   | 0 18 39 63  90 |
SUM_PREFIX(B, EXCLUSIVE=.TRUE.) is | 1 20 42 67  95 |
                                   | 7 27 50 76 105 |
                                   \                /

                                    /                 \
                                    |  0 18 39 63  90 |
SUM_PREFIX(B, EXCLUSIVE=.FALSE.) is |  1 20 42 67  95 |
                                    | 18 39 63 90 120 |
                                    \                 /


next up previous contents
Next: Array Sorting Functions Up: Library Procedures Previous: Array Combining Scatter Functions