3.11 Miscellaneous Functions

Finally we come to the functions that don’t exactly fit anywhere else. These are shown in Table 3.24.





Operation  r <-- a,b,c,... Description






cast<M>  M <-- N Tuple resize
 For M > N, pads extra components with 0
For M < N, discards extra components



fillcast<M>  M <-- N Right-filled tuple resize
 For M > N, pads extra components with aN
For M < N, discards extra components



/ E  groupsort<S> <-- N[S] Sorts S tuples’ components based on the components of a[0]



/ E  join  M + N <-- M,NForms tuple filled with a’s, then b’s, components



/ E  discard  <-- N Discards fragment if any ai > 0



/ E  sort  N <-- N Sort components of a into r



 


Table 3.24: Miscellaneous functions.

cast<M> and fillcast<M> are both useful in situations where one needs to turn an N-tuple into an M-tuple. The former pads remaining values with zero, the latter replicates the last element. So, to get a 9-vector filled with ones, one might write fillcast<9>(ShVector1f(1.0)).

The discard function only makes sense in fragment or stream programs. It conditionally discards the current fragment or stream element, not writing any output. On fully SIMD processors (which most GPUs are) this will generally not save any processing time, as all instructions will still be evaluated, but it can be useful to generate certain effects or, for instance, to ignore edge cases in stream computations. Note that discard takes an N-tuple. It will discard the current fragment or element if any of the tuple’s components are true (i.e. greater than zero).


Note: This manual is available as a bound book from AK Peters, including better formatting, in-depth examples, and about 200 pages not available on-line.