module Data.Array.Accelerate.Language (
Acc, Exp,
Boundary(..), Stencil,
Stencil3, Stencil5, Stencil7, Stencil9,
Stencil3x3, Stencil5x3, Stencil3x5, Stencil5x5,
Stencil3x3x3, Stencil5x3x3, Stencil3x5x3, Stencil3x3x5, Stencil5x5x3, Stencil5x3x5,
Stencil3x5x5, Stencil5x5x5,
constant,
use, unit, replicate, generate,
reshape,
slice,
map, zipWith,
fold, fold1, foldSeg, fold1Seg,
scanl, scanl', scanl1, scanr, scanr', scanr1,
permute, backpermute,
stencil, stencil2,
foreignAcc, foreignAcc2, foreignAcc3,
foreignExp, foreignExp2, foreignExp3,
(>->),
cond, (?|),
Lift(..), Unlift(..), lift1, lift2, ilift1, ilift2,
fst, snd, curry, uncurry,
index0, index1, unindex1, index2, unindex2,
indexHead, indexTail, toIndex, fromIndex,
(?),
(!), (!!), the, null, shape, size, shapeSize,
(==*), (/=*), (<*), (<=*), (>*), (>=*), max, min,
bit, setBit, clearBit, complementBit, testBit,
shift, shiftL, shiftR,
rotate, rotateL, rotateR,
truncate, round, floor, ceiling,
(&&*), (||*), not,
boolToInt, fromIntegral,
ignore
) where
import Prelude hiding (
(!!), replicate, zip, unzip, map, scanl, scanl1, scanr, scanr1, zipWith,
filter, max, min, not, fst, snd, curry, uncurry, null, truncate, round, floor,
ceiling, fromIntegral)
import Data.Bits (Bits((.&.), (.|.), xor, complement))
import Data.Array.Accelerate.Type
import Data.Array.Accelerate.Tuple
import Data.Array.Accelerate.Smart
import Data.Array.Accelerate.Array.Sugar hiding ((!), ignore, shape, size, toIndex, fromIndex)
import qualified Data.Array.Accelerate.Array.Sugar as Sugar
use :: Arrays arrays => arrays -> Acc arrays
use = Acc . Use
unit :: Elt e => Exp e -> Acc (Scalar e)
unit = Acc . Unit
replicate :: (Slice slix, Elt e)
=> Exp slix
-> Acc (Array (SliceShape slix) e)
-> Acc (Array (FullShape slix) e)
replicate = Acc $$ Replicate
generate :: (Shape ix, Elt a)
=> Exp ix
-> (Exp ix -> Exp a)
-> Acc (Array ix a)
generate = Acc $$ Generate
reshape :: (Shape ix, Shape ix', Elt e)
=> Exp ix
-> Acc (Array ix' e)
-> Acc (Array ix e)
reshape = Acc $$ Reshape
slice :: (Slice slix, Elt e)
=> Acc (Array (FullShape slix) e)
-> Exp slix
-> Acc (Array (SliceShape slix) e)
slice = Acc $$ Slice
map :: (Shape ix, Elt a, Elt b)
=> (Exp a -> Exp b)
-> Acc (Array ix a)
-> Acc (Array ix b)
map = Acc $$ Map
zipWith :: (Shape ix, Elt a, Elt b, Elt c)
=> (Exp a -> Exp b -> Exp c)
-> Acc (Array ix a)
-> Acc (Array ix b)
-> Acc (Array ix c)
zipWith = Acc $$$ ZipWith
fold :: (Shape ix, Elt a)
=> (Exp a -> Exp a -> Exp a)
-> Exp a
-> Acc (Array (ix:.Int) a)
-> Acc (Array ix a)
fold = Acc $$$ Fold
fold1 :: (Shape ix, Elt a)
=> (Exp a -> Exp a -> Exp a)
-> Acc (Array (ix:.Int) a)
-> Acc (Array ix a)
fold1 = Acc $$ Fold1
foldSeg :: (Shape ix, Elt a, Elt i, IsIntegral i)
=> (Exp a -> Exp a -> Exp a)
-> Exp a
-> Acc (Array (ix:.Int) a)
-> Acc (Segments i)
-> Acc (Array (ix:.Int) a)
foldSeg = Acc $$$$ FoldSeg
fold1Seg :: (Shape ix, Elt a, Elt i, IsIntegral i)
=> (Exp a -> Exp a -> Exp a)
-> Acc (Array (ix:.Int) a)
-> Acc (Segments i)
-> Acc (Array (ix:.Int) a)
fold1Seg = Acc $$$ Fold1Seg
scanl :: Elt a
=> (Exp a -> Exp a -> Exp a)
-> Exp a
-> Acc (Vector a)
-> Acc (Vector a)
scanl = Acc $$$ Scanl
scanl' :: Elt a
=> (Exp a -> Exp a -> Exp a)
-> Exp a
-> Acc (Vector a)
-> (Acc (Vector a), Acc (Scalar a))
scanl' = unlift . Acc $$$ Scanl'
scanl1 :: Elt a
=> (Exp a -> Exp a -> Exp a)
-> Acc (Vector a)
-> Acc (Vector a)
scanl1 = Acc $$ Scanl1
scanr :: Elt a
=> (Exp a -> Exp a -> Exp a)
-> Exp a
-> Acc (Vector a)
-> Acc (Vector a)
scanr = Acc $$$ Scanr
scanr' :: Elt a
=> (Exp a -> Exp a -> Exp a)
-> Exp a
-> Acc (Vector a)
-> (Acc (Vector a), Acc (Scalar a))
scanr' = unlift . Acc $$$ Scanr'
scanr1 :: Elt a
=> (Exp a -> Exp a -> Exp a)
-> Acc (Vector a)
-> Acc (Vector a)
scanr1 = Acc $$ Scanr1
permute :: (Shape ix, Shape ix', Elt a)
=> (Exp a -> Exp a -> Exp a)
-> Acc (Array ix' a)
-> (Exp ix -> Exp ix')
-> Acc (Array ix a)
-> Acc (Array ix' a)
permute = Acc $$$$ Permute
backpermute :: (Shape ix, Shape ix', Elt a)
=> Exp ix'
-> (Exp ix' -> Exp ix)
-> Acc (Array ix a)
-> Acc (Array ix' a)
backpermute = Acc $$$ Backpermute
type Stencil3 a = (Exp a, Exp a, Exp a)
type Stencil5 a = (Exp a, Exp a, Exp a, Exp a, Exp a)
type Stencil7 a = (Exp a, Exp a, Exp a, Exp a, Exp a, Exp a, Exp a)
type Stencil9 a = (Exp a, Exp a, Exp a, Exp a, Exp a, Exp a, Exp a, Exp a, Exp a)
type Stencil3x3 a = (Stencil3 a, Stencil3 a, Stencil3 a)
type Stencil5x3 a = (Stencil5 a, Stencil5 a, Stencil5 a)
type Stencil3x5 a = (Stencil3 a, Stencil3 a, Stencil3 a, Stencil3 a, Stencil3 a)
type Stencil5x5 a = (Stencil5 a, Stencil5 a, Stencil5 a, Stencil5 a, Stencil5 a)
type Stencil3x3x3 a = (Stencil3x3 a, Stencil3x3 a, Stencil3x3 a)
type Stencil5x3x3 a = (Stencil5x3 a, Stencil5x3 a, Stencil5x3 a)
type Stencil3x5x3 a = (Stencil3x5 a, Stencil3x5 a, Stencil3x5 a)
type Stencil3x3x5 a = (Stencil3x3 a, Stencil3x3 a, Stencil3x3 a, Stencil3x3 a, Stencil3x3 a)
type Stencil5x5x3 a = (Stencil5x5 a, Stencil5x5 a, Stencil5x5 a)
type Stencil5x3x5 a = (Stencil5x3 a, Stencil5x3 a, Stencil5x3 a, Stencil5x3 a, Stencil5x3 a)
type Stencil3x5x5 a = (Stencil3x5 a, Stencil3x5 a, Stencil3x5 a, Stencil3x5 a, Stencil3x5 a)
type Stencil5x5x5 a = (Stencil5x5 a, Stencil5x5 a, Stencil5x5 a, Stencil5x5 a, Stencil5x5 a)
stencil :: (Shape ix, Elt a, Elt b, Stencil ix a stencil)
=> (stencil -> Exp b)
-> Boundary a
-> Acc (Array ix a)
-> Acc (Array ix b)
stencil = Acc $$$ Stencil
stencil2 :: (Shape ix, Elt a, Elt b, Elt c,
Stencil ix a stencil1,
Stencil ix b stencil2)
=> (stencil1 -> stencil2 -> Exp c)
-> Boundary a
-> Acc (Array ix a)
-> Boundary b
-> Acc (Array ix b)
-> Acc (Array ix c)
stencil2 = Acc $$$$$ Stencil2
foreignAcc :: (Arrays acc, Arrays res, Foreign ff)
=> ff acc res
-> (Acc acc -> Acc res)
-> Acc acc
-> Acc res
foreignAcc = Acc $$$ Aforeign
foreignAcc2 :: (Arrays acc, Arrays res, Foreign ff1, Foreign ff2)
=> ff1 acc res
-> ff2 acc res
-> (Acc acc -> Acc res)
-> Acc acc
-> Acc res
foreignAcc2 ff1 = Acc $$$ Aforeign ff1 $$ Acc $$$ Aforeign
foreignAcc3 :: (Arrays acc, Arrays res, Foreign ff1, Foreign ff2, Foreign ff3)
=> ff1 acc res
-> ff2 acc res
-> ff3 acc res
-> (Acc acc -> Acc res)
-> Acc acc
-> Acc res
foreignAcc3 ff1 ff2 = Acc $$$ Aforeign ff1 $$ Acc $$$ Aforeign ff2 $$ Acc $$$ Aforeign
foreignExp :: (Elt e, Elt res, Foreign ff)
=> ff e res
-> (Exp e -> Exp res)
-> Exp e
-> Exp res
foreignExp = Exp $$$ Foreign
foreignExp2 :: (Elt e, Elt res, Foreign ff1, Foreign ff2)
=> ff1 e res
-> ff2 e res
-> (Exp e -> Exp res)
-> Exp e
-> Exp res
foreignExp2 ff1 = Exp $$$ Foreign ff1 $$ Exp $$$ Foreign
foreignExp3 :: (Elt e, Elt res, Foreign ff1, Foreign ff2, Foreign ff3)
=> ff1 e res
-> ff2 e res
-> ff3 e res
-> (Exp e -> Exp res)
-> Exp e
-> Exp res
foreignExp3 ff1 ff2 = Exp $$$ Foreign ff1 $$ Exp $$$ Foreign ff2 $$ Exp $$$ Foreign
infixl 1 >->
(>->) :: (Arrays a, Arrays b, Arrays c) => (Acc a -> Acc b) -> (Acc b -> Acc c) -> (Acc a -> Acc c)
(>->) = Acc $$$ Pipe
cond :: (Arrays a)
=> Exp Bool
-> Acc a
-> Acc a
-> Acc a
cond = Acc $$$ Acond
infix 0 ?|
(?|) :: (Arrays a) => Exp Bool -> (Acc a, Acc a) -> Acc a
c ?| (t, e) = cond c t e
class Lift c e where
type Plain e
lift :: e -> c (Plain e)
class Lift c e => Unlift c e where
unlift :: c (Plain e) -> e
instance Lift Exp () where
type Plain () = ()
lift _ = Exp $ Tuple NilTup
instance Unlift Exp () where
unlift _ = ()
instance Lift Exp Z where
type Plain Z = Z
lift _ = Exp $ IndexNil
instance Unlift Exp Z where
unlift _ = Z
instance (Slice (Plain ix), Lift Exp ix) => Lift Exp (ix :. Int) where
type Plain (ix :. Int) = Plain ix :. Int
lift (ix:.i) = Exp $ IndexCons (lift ix) (Exp $ Const i)
instance (Slice (Plain ix), Lift Exp ix) => Lift Exp (ix :. All) where
type Plain (ix :. All) = Plain ix :. All
lift (ix:.i) = Exp $ IndexCons (lift ix) (Exp $ Const i)
instance (Elt e, Slice (Plain ix), Lift Exp ix) => Lift Exp (ix :. Exp e) where
type Plain (ix :. Exp e) = Plain ix :. e
lift (ix:.i) = Exp $ IndexCons (lift ix) i
instance (Elt e, Slice (Plain ix), Unlift Exp ix) => Unlift Exp (ix :. Exp e) where
unlift e = unlift (Exp $ IndexTail e) :. Exp (IndexHead e)
instance (Elt e, Slice ix) => Unlift Exp (Exp ix :. Exp e) where
unlift e = (Exp $ IndexTail e) :. Exp (IndexHead e)
instance Shape sh => Lift Exp (Any sh) where
type Plain (Any sh) = Any sh
lift Any = Exp $ IndexAny
instance Lift Exp Int where
type Plain Int = Int
lift = Exp . Const
instance Lift Exp Int8 where
type Plain Int8 = Int8
lift = Exp . Const
instance Lift Exp Int16 where
type Plain Int16 = Int16
lift = Exp . Const
instance Lift Exp Int32 where
type Plain Int32 = Int32
lift = Exp . Const
instance Lift Exp Int64 where
type Plain Int64 = Int64
lift = Exp . Const
instance Lift Exp Word where
type Plain Word = Word
lift = Exp . Const
instance Lift Exp Word8 where
type Plain Word8 = Word8
lift = Exp . Const
instance Lift Exp Word16 where
type Plain Word16 = Word16
lift = Exp . Const
instance Lift Exp Word32 where
type Plain Word32 = Word32
lift = Exp . Const
instance Lift Exp Word64 where
type Plain Word64 = Word64
lift = Exp . Const
instance Lift Exp Float where
type Plain Float = Float
lift = Exp . Const
instance Lift Exp Double where
type Plain Double = Double
lift = Exp . Const
instance Lift Exp Bool where
type Plain Bool = Bool
lift = Exp . Const
instance Lift Exp Char where
type Plain Char = Char
lift = Exp . Const
instance (Lift Exp a, Lift Exp b, Elt (Plain a), Elt (Plain b)) => Lift Exp (a, b) where
type Plain (a, b) = (Plain a, Plain b)
lift (x, y) = tup2 (lift x, lift y)
instance (Elt a, Elt b) => Unlift Exp (Exp a, Exp b) where
unlift = untup2
instance (Lift Exp a, Lift Exp b, Lift Exp c,
Elt (Plain a), Elt (Plain b), Elt (Plain c))
=> Lift Exp (a, b, c) where
type Plain (a, b, c) = (Plain a, Plain b, Plain c)
lift (x, y, z) = tup3 (lift x, lift y, lift z)
instance (Elt a, Elt b, Elt c) => Unlift Exp (Exp a, Exp b, Exp c) where
unlift = untup3
instance (Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d,
Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d))
=> Lift Exp (a, b, c, d) where
type Plain (a, b, c, d) = (Plain a, Plain b, Plain c, Plain d)
lift (x, y, z, u) = tup4 (lift x, lift y, lift z, lift u)
instance (Elt a, Elt b, Elt c, Elt d) => Unlift Exp (Exp a, Exp b, Exp c, Exp d) where
unlift = untup4
instance (Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e,
Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e))
=> Lift Exp (a, b, c, d, e) where
type Plain (a, b, c, d, e) = (Plain a, Plain b, Plain c, Plain d, Plain e)
lift (x, y, z, u, v) = tup5 (lift x, lift y, lift z, lift u, lift v)
instance (Elt a, Elt b, Elt c, Elt d, Elt e)
=> Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e) where
unlift = untup5
instance (Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Lift Exp f,
Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e), Elt (Plain f))
=> Lift Exp (a, b, c, d, e, f) where
type Plain (a, b, c, d, e, f) = (Plain a, Plain b, Plain c, Plain d, Plain e, Plain f)
lift (x, y, z, u, v, w) = tup6 (lift x, lift y, lift z, lift u, lift v, lift w)
instance (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f)
=> Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f) where
unlift = untup6
instance (Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Lift Exp f, Lift Exp g,
Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e), Elt (Plain f),
Elt (Plain g))
=> Lift Exp (a, b, c, d, e, f, g) where
type Plain (a, b, c, d, e, f, g) = (Plain a, Plain b, Plain c, Plain d, Plain e, Plain f, Plain g)
lift (x, y, z, u, v, w, r) = tup7 (lift x, lift y, lift z, lift u, lift v, lift w, lift r)
instance (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g)
=> Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g) where
unlift = untup7
instance (Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Lift Exp f, Lift Exp g, Lift Exp h,
Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e), Elt (Plain f),
Elt (Plain g), Elt (Plain h))
=> Lift Exp (a, b, c, d, e, f, g, h) where
type Plain (a, b, c, d, e, f, g, h)
= (Plain a, Plain b, Plain c, Plain d, Plain e, Plain f, Plain g, Plain h)
lift (x, y, z, u, v, w, r, s)
= tup8 (lift x, lift y, lift z, lift u, lift v, lift w, lift r, lift s)
instance (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h)
=> Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g, Exp h) where
unlift = untup8
instance (Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e,
Lift Exp f, Lift Exp g, Lift Exp h, Lift Exp i,
Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e),
Elt (Plain f), Elt (Plain g), Elt (Plain h), Elt (Plain i))
=> Lift Exp (a, b, c, d, e, f, g, h, i) where
type Plain (a, b, c, d, e, f, g, h, i)
= (Plain a, Plain b, Plain c, Plain d, Plain e, Plain f, Plain g, Plain h, Plain i)
lift (x, y, z, u, v, w, r, s, t)
= tup9 (lift x, lift y, lift z, lift u, lift v, lift w, lift r, lift s, lift t)
instance (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h, Elt i)
=> Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g, Exp h, Exp i) where
unlift = untup9
instance Lift Exp (Exp e) where
type Plain (Exp e) = e
lift = id
instance Lift Acc (Acc a) where
type Plain (Acc a) = a
lift = id
instance (Shape sh, Elt e) => Lift Acc (Array sh e) where
type Plain (Array sh e) = Array sh e
lift = Acc . Use
instance (Lift Acc a, Lift Acc b, Arrays (Plain a), Arrays (Plain b)) => Lift Acc (a, b) where
type Plain (a, b) = (Plain a, Plain b)
lift (x, y) = atup2 (lift x, lift y)
instance (Arrays a, Arrays b) => Unlift Acc (Acc a, Acc b) where
unlift = unatup2
instance (Lift Acc a, Lift Acc b, Lift Acc c,
Arrays (Plain a), Arrays (Plain b), Arrays (Plain c))
=> Lift Acc (a, b, c) where
type Plain (a, b, c) = (Plain a, Plain b, Plain c)
lift (x, y, z) = atup3 (lift x, lift y, lift z)
instance (Arrays a, Arrays b, Arrays c) => Unlift Acc (Acc a, Acc b, Acc c) where
unlift = unatup3
instance (Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d,
Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d))
=> Lift Acc (a, b, c, d) where
type Plain (a, b, c, d) = (Plain a, Plain b, Plain c, Plain d)
lift (x, y, z, u) = atup4 (lift x, lift y, lift z, lift u)
instance (Arrays a, Arrays b, Arrays c, Arrays d) => Unlift Acc (Acc a, Acc b, Acc c, Acc d) where
unlift = unatup4
instance (Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e,
Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e))
=> Lift Acc (a, b, c, d, e) where
type Plain (a, b, c, d, e) = (Plain a, Plain b, Plain c, Plain d, Plain e)
lift (x, y, z, u, v) = atup5 (lift x, lift y, lift z, lift u, lift v)
instance (Arrays a, Arrays b, Arrays c, Arrays d, Arrays e)
=> Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e) where
unlift = unatup5
instance (Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Lift Acc f,
Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e), Arrays (Plain f))
=> Lift Acc (a, b, c, d, e, f) where
type Plain (a, b, c, d, e, f) = (Plain a, Plain b, Plain c, Plain d, Plain e, Plain f)
lift (x, y, z, u, v, w) = atup6 (lift x, lift y, lift z, lift u, lift v, lift w)
instance (Arrays a, Arrays b, Arrays c, Arrays d, Arrays e, Arrays f)
=> Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e, Acc f) where
unlift = unatup6
instance (Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Lift Acc f, Lift Acc g,
Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e), Arrays (Plain f),
Arrays (Plain g))
=> Lift Acc (a, b, c, d, e, f, g) where
type Plain (a, b, c, d, e, f, g) = (Plain a, Plain b, Plain c, Plain d, Plain e, Plain f, Plain g)
lift (x, y, z, u, v, w, r) = atup7 (lift x, lift y, lift z, lift u, lift v, lift w, lift r)
instance (Arrays a, Arrays b, Arrays c, Arrays d, Arrays e, Arrays f, Arrays g)
=> Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e, Acc f, Acc g) where
unlift = unatup7
instance (Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Lift Acc f, Lift Acc g, Lift Acc h,
Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e), Arrays (Plain f),
Arrays (Plain g), Arrays (Plain h))
=> Lift Acc (a, b, c, d, e, f, g, h) where
type Plain (a, b, c, d, e, f, g, h)
= (Plain a, Plain b, Plain c, Plain d, Plain e, Plain f, Plain g, Plain h)
lift (x, y, z, u, v, w, r, s)
= atup8 (lift x, lift y, lift z, lift u, lift v, lift w, lift r, lift s)
instance (Arrays a, Arrays b, Arrays c, Arrays d, Arrays e, Arrays f, Arrays g, Arrays h)
=> Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e, Acc f, Acc g, Acc h) where
unlift = unatup8
instance (Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e,
Lift Acc f, Lift Acc g, Lift Acc h, Lift Acc i,
Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e),
Arrays (Plain f), Arrays (Plain g), Arrays (Plain h), Arrays (Plain i))
=> Lift Acc (a, b, c, d, e, f, g, h, i) where
type Plain (a, b, c, d, e, f, g, h, i)
= (Plain a, Plain b, Plain c, Plain d, Plain e, Plain f, Plain g, Plain h, Plain i)
lift (x, y, z, u, v, w, r, s, t)
= atup9 (lift x, lift y, lift z, lift u, lift v, lift w, lift r, lift s, lift t)
instance (Arrays a, Arrays b, Arrays c, Arrays d, Arrays e, Arrays f, Arrays g, Arrays h, Arrays i)
=> Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e, Acc f, Acc g, Acc h, Acc i) where
unlift = unatup9
lift1 :: (Unlift Exp e1, Lift Exp e2)
=> (e1 -> e2)
-> Exp (Plain e1)
-> Exp (Plain e2)
lift1 f = lift . f . unlift
lift2 :: (Unlift Exp e1, Unlift Exp e2, Lift Exp e3)
=> (e1 -> e2 -> e3)
-> Exp (Plain e1)
-> Exp (Plain e2)
-> Exp (Plain e3)
lift2 f x y = lift $ f (unlift x) (unlift y)
ilift1 :: (Exp Int -> Exp Int) -> Exp DIM1 -> Exp DIM1
ilift1 f = lift1 (\(Z:.i) -> Z :. f i)
ilift2 :: (Exp Int -> Exp Int -> Exp Int) -> Exp DIM1 -> Exp DIM1 -> Exp DIM1
ilift2 f = lift2 (\(Z:.i) (Z:.j) -> Z :. f i j)
fst :: forall f a b. Unlift f (f a, f b) => f (Plain (f a), Plain (f b)) -> f a
fst e = let (x, _:: f b) = unlift e in x
snd :: forall f a b. Unlift f (f a, f b) => f (Plain (f a), Plain (f b)) -> f b
snd e = let (_::f a, y) = unlift e in y
curry :: Lift f (f a, f b) => (f (Plain (f a), Plain (f b)) -> f c) -> f a -> f b -> f c
curry f x y = f (lift (x, y))
uncurry :: Unlift f (f a, f b) => (f a -> f b -> f c) -> f (Plain (f a), Plain (f b)) -> f c
uncurry f t = let (x, y) = unlift t in f x y
index0 :: Exp Z
index0 = lift Z
index1 :: Elt i => Exp i -> Exp (Z :. i)
index1 i = lift (Z :. i)
unindex1 :: Elt i => Exp (Z :. i) -> Exp i
unindex1 ix = let Z :. i = unlift ix in i
index2 :: (Elt i, Slice (Z :. i))
=> Exp i
-> Exp i
-> Exp (Z :. i :. i)
index2 i j = lift (Z :. i :. j)
unindex2 :: forall i. (Elt i, Slice (Z :. i))
=> Exp (Z :. i :. i)
-> Exp (i, i)
unindex2 ix
= let Z :. i :. j = unlift ix :: Z :. Exp i :. Exp i
in lift (i, j)
indexHead :: Slice sh => Exp (sh :. Int) -> Exp Int
indexHead = Exp . IndexHead
indexTail :: Slice sh => Exp (sh :. Int) -> Exp sh
indexTail = Exp . IndexTail
toIndex :: Shape sh => Exp sh -> Exp sh -> Exp Int
toIndex = Exp $$ ToIndex
fromIndex :: Shape sh => Exp sh -> Exp Int -> Exp sh
fromIndex = Exp $$ FromIndex
infix 0 ?
(?) :: Elt t => Exp Bool -> (Exp t, Exp t) -> Exp t
c ? (t, e) = Exp $ Cond c t e
infixl 9 !
(!) :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp ix -> Exp e
(!) arr ix = Exp $ Index arr ix
infixl 9 !!
(!!) :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp Int -> Exp e
(!!) arr i = Exp $ LinearIndex arr i
the :: Elt e => Acc (Scalar e) -> Exp e
the = (!index0)
null :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp Bool
null arr = size arr ==* 0
shape :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp ix
shape = Exp . Shape
size :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp Int
size = shapeSize . shape
shapeSize :: Shape ix => Exp ix -> Exp Int
shapeSize = Exp . ShapeSize
instance (Elt t, IsBounded t) => Bounded (Exp t) where
minBound = mkMinBound
maxBound = mkMaxBound
instance (Elt t, IsScalar t) => Enum (Exp t)
instance (Elt t, IsScalar t) => Prelude.Eq (Exp t) where
(==) = error "Prelude.Eq.== applied to EDSL types"
instance (Elt t, IsScalar t) => Prelude.Ord (Exp t) where
compare = error "Prelude.Ord.compare applied to EDSL types"
instance (Elt t, IsNum t, IsIntegral t) => Bits (Exp t) where
(.&.) = mkBAnd
(.|.) = mkBOr
xor = mkBXor
complement = mkBNot
shift :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
shift x i = i ==* 0 ? (x, i <* 0 ? (x `shiftR` (i), x `shiftL` i))
shiftL :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
shiftL = mkBShiftL
shiftR :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
shiftR = mkBShiftR
rotate :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
rotate x i = i ==* 0 ? (x, i <* 0 ? (x `rotateR` (i), x `rotateL` i))
rotateL :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
rotateL = mkBRotateL
rotateR :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
rotateR = mkBRotateR
bit :: (Elt t, IsIntegral t) => Exp Int -> Exp t
bit x = 1 `shiftL` x
setBit :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
x `setBit` i = x .|. bit i
clearBit :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
x `clearBit` i = x .&. complement (bit i)
complementBit :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
x `complementBit` i = x `xor` bit i
testBit :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp Bool
x `testBit` i = (x .&. bit i) /=* 0
instance (Elt t, IsNum t) => Num (Exp t) where
(+) = mkAdd
() = mkSub
(*) = mkMul
negate = mkNeg
abs = mkAbs
signum = mkSig
fromInteger = constant . fromInteger
instance (Elt t, IsNum t) => Real (Exp t)
instance (Elt t, IsIntegral t) => Integral (Exp t) where
quot = mkQuot
rem = mkRem
div = mkIDiv
mod = mkMod
instance (Elt t, IsFloating t) => Floating (Exp t) where
pi = mkPi
sin = mkSin
cos = mkCos
tan = mkTan
asin = mkAsin
acos = mkAcos
atan = mkAtan
asinh = mkAsinh
acosh = mkAcosh
atanh = mkAtanh
exp = mkExpFloating
sqrt = mkSqrt
log = mkLog
(**) = mkFPow
logBase = mkLogBase
instance (Elt t, IsFloating t) => Fractional (Exp t) where
(/) = mkFDiv
recip = mkRecip
fromRational = constant . fromRational
instance (Elt t, IsFloating t) => RealFrac (Exp t)
instance (Elt t, IsFloating t) => RealFloat (Exp t) where
atan2 = mkAtan2
infix 4 ==*, /=*, <*, <=*, >*, >=*
(==*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
(==*) = mkEq
(/=*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
(/=*) = mkNEq
(<*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
(<*) = mkLt
(>=*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
(>=*) = mkGtEq
(>*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
(>*) = mkGt
(<=*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
(<=*) = mkLtEq
max :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp t
max = mkMax
min :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp t
min = mkMin
truncate :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp b
truncate = mkTruncate
round :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp b
round = mkRound
floor :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp b
floor = mkFloor
ceiling :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp b
ceiling = mkCeiling
infixr 3 &&*
(&&*) :: Exp Bool -> Exp Bool -> Exp Bool
(&&*) = mkLAnd
infixr 2 ||*
(||*) :: Exp Bool -> Exp Bool -> Exp Bool
(||*) = mkLOr
not :: Exp Bool -> Exp Bool
not = mkLNot
boolToInt :: Exp Bool -> Exp Int
boolToInt = mkBoolToInt
fromIntegral :: (Elt a, Elt b, IsIntegral a, IsNum b) => Exp a -> Exp b
fromIntegral = mkFromIntegral
ignore :: Shape ix => Exp ix
ignore = constant Sugar.ignore