Numeric Haskell: A Repa Tutorial
Numeric Haskell: A Repa Tutorial
Repa is a Haskell library for high performance, regular, multi-dimensional parallel arrays. All numeric data is stored unboxed. Functions written with the Repa combinators are automatically parallel provided you supply +RTS -Nwhatever on the command line when running the program.
See also the vector tutorial.
Quick Tour
Importing the library
Download the `repa` package:
$ cabal install repa
and import it qualified:
import qualified Data.Array.Repa as R
The library needs to be imported qualified as it shares the same function names as list operations in the Prelude.
Generating arrays
Modifying arrays
Indexing arrays
To access elements in repa arrays, you provide an array and a shape, to access the element:
(!) :: (Shape sh, Elt a) => Array sh a -> sh -> a
Syntax
Repa arrays are instances of `Num`. This means that operations on numerical elements are lifted automagically onto arrays of such elements:
For example, `(+)` on two double values corresponds to zip-wise `(+)` on two arrays of doubles.