Writing Accelerate programs
Accelerate arrays are indexed by similar data types with Repa arrays, in other words, snoc-style lists:
data Z data tail :. head = tail :. head
Like Repa, type
synonyms are provided for Accelerate indices:
type DIM0 = Z type DIM1 = DIM0 :. Int type DIM2 = DIM1 :. Int ...
The Accelerate array type is Array sh e
. We can build accelerated arrays from lists with fromList
:
> import Data.Array.Accelerate as A > fromList (Z :. 5) [1..5] Array (Z :. 5) [1,2,3,4,5]
Now let's try to do something with an Array
: reverse it. Accelerate provides the function reverse
, but it has this slightly daunting type signature:
reverse :: Elt e => Acc (Vector e) -> Acc (Vector e)
And if we try to apply reverse
to an array directly, we are greeted with a type-mismatch error:
> A.reverse (fromList (Z :. 5) [1..] :: Array DIM1 Int) <interactive>:24:12: Couldn't match expected type 'Acc (Vector e)' with actual type 'Array DIM1 Int...