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

 

Prefix and Suffix Functions

Both classes of functions are related, Prefix functions go from left to right along an array. The difference between PRODUCT_PREFIX and PRODUCT is that the latter returns a single value whereas the former returns an array result. This array contains the value obtained by multiplying the current element by all the elements to the left of it. In the case of a 2D (or more) example, the array is traversed in array element order.

Suffix functions are exactly the same except that the array is traversed from right to left (or for multi-dimensional arrays in reverse array element order).

 

There are prefix and suffix functions corresponding to all the Fortran 90 and new HPF reduction functions. They all work in the same way and have more or less the same set of arguments. These include:

plus HPF defined intrinsics: IALL, IANY, IPARITY and PARITY.

 

All these functions take (more or less) the same arguments, for example:

 MINVAL_PREFIX(ARRAY[,DIM][,MASK][,SEGMENT][,EXCLUSIVE])

MASK and SEGMENT are LOGICAL, MASK conforms to ARRAY, SEGMENT has same shape as ARRAY.

Example of the MASK argument,

PRODUCT_PREFIX((/1,2,3,4/), MASK=(/T,F,T,F/)) = (/1,1,3,3/)

Only the elements corresponding to .TRUE. positions of the mask contribute to the results, the positions of the source array which correspond to the .FALSE. mask elements are ignored.

 

The SEGMENT argument is a LOGICAL array and allows the function to be applied to sections of the source array, for example,

  S       =  (/T,T,T, F,F, T,T, F, T,T/)
  !            -----  ---  ---  -  ---
  SUM_PREFIX((/1,2,3, 4,5, 6,1, 2, 3,4/),SEGMENT=S) =
             (/1,3,6, 4,9, 6,7, 2, 3,7/)

The EXCLUSIVE argument is a LOGICAL valued scalar. If it is .FALSE. (the default) then each element takes part in operation for its position, otherwise it does not and the first scanned element has identity value. For example,

  PRODUCT_PREFIX((/1,2,3,4/), EXCLUSIVE=.TRUE.) =
                 (/1,1,2,6/)
  SUM_PREFIX((/1,2,3,4/), EXCLUSIVE=.TRUE.) =
             (/0,1,3,6/)

When both a MASK and a SEGMENT argument are supplied the result is partitioned and the function only applied to the .TRUE. elements of each partition.

Now try this question gif

Return to corresponding overview page gif


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

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.