Difference between revisions of "Numeric Haskell: A Repa Tutorial"

From HaskellWiki
Jump to: navigation, search
(New page: = Numeric Haskell: A Repa Tutorial = [http://hackage.haskell.org/package/repa Repa] is a Haskell library for high performance, regular, multi-dimensional parallel arrays. All numeric dat...)
 
(Quick Tour)
Line 8: Line 8:
   
 
== Importing the library ==
 
== 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 ==
 
== Generating arrays ==
  +
  +
   
 
== Modifying arrays ==
 
== Modifying arrays ==
   
 
== Indexing 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.

Revision as of 19:58, 9 May 2011

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.