feldspar-language-0.6.0.2: A functional embedded language for DSP and parallelism

Safe HaskellNone

Feldspar.Repa

Contents

Synopsis

Documentation

data Z

  • Shapes

Constructors

Z 

Instances

data tail :. head

Constructors

tail :. head 

Instances

Slice sl => Slice (:. sl All) 
Slice sl => Slice (:. sl (Data Length)) 
Shape sh => Shape (:. sh (Data Length)) 

type DIM0 = Z

class Shape sh where

Methods

dim :: sh -> Int

Get the number of dimensions in a shape

zeroDim :: sh

The shape of an array of size zero, with a particular dimension

unitDim :: sh

The shape of an array with size one, with a particular dimension

size :: sh -> Data Length

Get the total number of elements in an array with this shape.

toIndex :: sh -> sh -> Data Index

Index into flat, linear, row-major representation

fromIndex :: sh -> Data Index -> sh

Inverse of toIndex.

intersectDim :: sh -> sh -> sh

The intersection of two dimensions.

inRange :: sh -> sh -> sh -> Data Bool

Check whether an index is within a given shape. inRange l u i checks that i fits between l and u.

toList :: sh -> [Data Length]

Turn a shape into a list. Used in the Syntactic instance.

toShape :: Int -> Data [Length] -> sh

Reconstruct a shape. Used in the Syntactic instance.

Instances

Shape Z 
Shape sh => Shape (:. sh (Data Length)) 

data All

  • Slices

Constructors

All 

Instances

Slice sl => Slice (:. sl All) 

data Any sh

Constructors

Any 

Instances

Slice (Any sh) 

type family FullShape ss

type family SliceShape ss

class Slice ss where

Methods

sliceOfFull :: ss -> FullShape ss -> SliceShape ss

fullOfSlice :: ss -> SliceShape ss -> FullShape ss

Instances

Slice Z 
Slice (Any sh) 
Slice sl => Slice (:. sl All) 
Slice sl => Slice (:. sl (Data Length)) 

data Vector sh a

  • Vectors

Constructors

Vector sh (sh -> a) 

Instances

Annotatable a => Annotatable (Vector s a) 
(Shape sh, Syntax a) => Syntactic (Vector sh a) 
(Syntax a, Shape sh) => Sized (Vector sh a) 
Syntax a => Indexed (Vector sh a) 
(Shape sh, Syntax a) => Syntax (Vector sh a) 
CollMap (Vector sh a) (Vector sh a) 

type DVector sh a = Vector sh (Data a)

fromVector :: (Shape sh, Type a) => DVector sh a -> Data [a]

  • Fuctions

Store a vector in an array.

toVector :: (Shape sh, Type a) => sh -> Data [a] -> DVector sh a

Restore a vector from an array

freezeVector :: (Shape sh, Type a) => DVector sh a -> (Data [Length], Data [a])

fromList :: Type a => [Data a] -> Data [a]

thawVector :: (Shape sh, Type a) => (Data [Length], Data [a]) -> DVector sh a

memorize :: (Shape sh, Type a) => DVector sh a -> DVector sh a

Store a vector in memory. Use this function instead of force if possible as it is both much more safe and faster.

extent :: Vector sh a -> sh

The shape and size of the vector

newExtent :: sh -> Vector sh a -> Vector sh a

Change the extent of the vector to the supplied value. If the supplied extent will contain more elements than the old extent, the new elements will have undefined value.

traverse :: (Shape sh, Shape sh') => Vector sh a -> (sh -> sh') -> ((sh -> a) -> sh' -> a') -> Vector sh' a'

Change shape and transform elements of a vector. This function is the most general way of manipulating a vector.

replicate :: (Slice sl, Shape (FullShape sl), Shape (SliceShape sl)) => sl -> Vector (SliceShape sl) a -> Vector (FullShape sl) a

Duplicates part of a vector along a new dimension.

slice :: (Slice sl, Shape (FullShape sl), Shape (SliceShape sl)) => Vector (FullShape sl) a -> sl -> Vector (SliceShape sl) a

Extracts a slice from a vector.

reshape :: (Shape sh, Shape sh') => sh -> Vector sh' a -> Vector sh a

Change the shape of a vector. This function is potentially unsafe, the new shape need to have fewer or equal number of elements compared to the old shape.

unit :: a -> Vector Z a

A scalar (zero dimensional) vector

(!:) :: Shape sh => Vector sh a -> sh -> a

Index into a vector

diagonal :: Vector DIM2 a -> Vector DIM1 a

Extract the diagonal of a two dimensional vector

backpermute :: (Shape sh, Shape sh') => sh' -> (sh' -> sh) -> Vector sh a -> Vector sh' a

Change the shape of a vector.

map :: (a -> b) -> Vector sh a -> Vector sh b

Map a function on all the elements of a vector

zip :: Shape sh => Vector sh a -> Vector sh b -> Vector sh (a, b)

Combines the elements of two vectors. The size of the resulting vector will be the intersection of the two argument vectors.

zipWith :: Shape sh => (a -> b -> c) -> Vector sh a -> Vector sh b -> Vector sh c

Combines the elements of two vectors pointwise using a function. The size of the resulting vector will be the intersection of the two argument vectors.

fold :: (Shape sh, Syntax a) => (a -> a -> a) -> a -> Vector (sh :. Data Length) a -> Vector sh a

Reduce a vector along its last dimension

fold' :: (Shape sh, Syntax a) => (a -> a -> a) -> Vector sh a -> Vector (sh :. Data Length) a -> Vector sh a

A generalization of fold which allows for different initial values when starting to fold.

sum :: (Shape sh, Type a, Numeric a) => DVector (sh :. Data Length) a -> DVector sh a

Summing a vector along its last dimension

(...) :: Data Index -> Data Index -> DVector DIM1 Index

Enumerating a vector

mmMult :: (Type e, Numeric e) => DVector DIM2 e -> DVector DIM2 e -> DVector DIM2 e

Matrix multiplication

indexed :: Data Length -> (Data Index -> a) -> Vector DIM1 a

Operations on one dimensional vectors

newLen :: Syntax a => Data Length -> Vector DIM1 a -> Vector DIM1 a

Change the length of the vector to the supplied value. If the supplied length is greater than the old length, the new elements will have undefined value. The resulting vector has only one segment.

(++) :: Syntax a => Vector DIM1 a -> Vector DIM1 a -> Vector DIM1 a

head :: Syntax a => Vector DIM1 a -> a

last :: Syntax a => Vector DIM1 a -> a

permute :: (Data Length -> Data Index -> Data Index) -> Vector DIM1 a -> Vector DIM1 a

Permute a vector

enumFromTo :: Data Index -> Data Index -> Vector DIM1 (Data Index)

enumFromTo m n: Enumerate the indexes from m to n

In order to enumerate a different type, use i2n, e.g:

 map i2n (10...20) :: Vector1 Word8

enumFrom :: Data Index -> Vector DIM1 (Data Index)

enumFrom m: Enumerate the indexes from m to maxBound

unzip :: Vector DIM1 (a, b) -> (Vector DIM1 a, Vector DIM1 b)

foldl :: Syntax a => (a -> b -> a) -> a -> Vector DIM1 b -> a

Corresponds to the standard foldl.

fold1 :: Syntax a => (a -> a -> a) -> Vector DIM1 a -> a

Corresponds to the standard foldl1.

sum1 :: (Syntax a, Num a) => Vector DIM1 a -> a

maximum :: Ord a => Vector DIM1 (Data a) -> Data a

minimum :: Ord a => Vector DIM1 (Data a) -> Data a

scalarProd :: (Syntax a, Num a) => Vector DIM1 a -> Vector DIM1 a -> a

Scalar product of two vectors

tVec :: Patch a a -> Patch (Vector DIM1 a) (Vector DIM1 a)

tVec1 :: Patch a a -> Patch (Vector DIM1 (Data a)) (Vector DIM1 (Data a))

tVec2 :: Patch a a -> Patch (Vector DIM2 (Data a)) (Vector DIM2 (Data a))