More Accelerate concepts
So far, we have considered accelerated arrays and expressions. These are the primitives that Accelerate builds upon. On top, we have a bunch of functional machinery to help us express ourselves in accelerated computations: zips and unzips, reductions, permutations, stencils, and so forth. The complete API is documented in the accelerate package. In this section, we consider using some of the most useful parts of this machinery.
Working with tuples
GPUs don't allow array nesting or tuples as elements of an array. Nested arrays can be somewhat mimicked with higher-dimensional arrays. And it might not come as a surprise that Accelerate supports tuples as elements of an array. Internally, arrays with tupled elements are represented as tuples of arrays, but this is strictly an implementation detail. For the programmer, it really looks like we are working with tupled elements, which is sometimes very convenient.
With zip
and unzip
, we can (de)construct tupled elements...