module Data.Array.Accelerate.Language (
Acc, Exp,
constant,
use, unit,
reshape,
slice, replicate, zip, unzip, map, zipWith, scanl, scanr, fold, foldSeg,
permute, backpermute,
Tuple(..), fst, snd, curry, uncurry,
(?),
(!), shape,
(==*), (/=*), (<*), (<=*), (>*), (>=*), max, min,
bit, setBit, clearBit, complementBit, testBit,
shift, shiftL, shiftR,
rotate, rotateL, rotateR,
(&&*), (||*), not,
boolToInt, intToFloat, roundFloatToInt, truncateFloatToInt,
ignore
) where
import Prelude hiding (replicate, zip, unzip, map, scanl, scanr, zipWith,
filter, max, min, not, const, fst, snd, curry, uncurry)
import Data.Bits (Bits((.&.), (.|.), xor, complement))
import Data.Array.Accelerate.Type
import Data.Array.Accelerate.Array.Sugar hiding ((!), ignore, shape)
import qualified Data.Array.Accelerate.Array.Sugar as Sugar
import Data.Array.Accelerate.Smart
use :: (Ix dim, Elem e) => Array dim e -> Acc (Array dim e)
use = Use
unit :: Elem e => Exp e -> Acc (Scalar e)
unit = Unit
reshape :: (Ix dim, Ix dim', Elem e)
=> Exp dim
-> Acc (Array dim' e)
-> Acc (Array dim e)
reshape = Reshape
replicate :: forall slix e. (SliceIx slix, Elem e)
=> Exp slix
-> Acc (Array (Slice slix) e)
-> Acc (Array (SliceDim slix) e)
replicate = Replicate
slice :: forall slix e. (SliceIx slix, Elem e)
=> Acc (Array (SliceDim slix) e)
-> Exp slix
-> Acc (Array (Slice slix) e)
slice = Index
zip :: (Ix dim, Elem a, Elem b)
=> Acc (Array dim a)
-> Acc (Array dim b)
-> Acc (Array dim (a, b))
zip = zipWith (\x y -> tuple (x, y))
unzip :: (Ix dim, Elem a, Elem b)
=> Acc (Array dim (a, b))
-> (Acc (Array dim a), Acc (Array dim b))
unzip arr = (map fst arr, map snd arr)
map :: (Ix dim, Elem a, Elem b)
=> (Exp a -> Exp b)
-> Acc (Array dim a)
-> Acc (Array dim b)
map = Map
zipWith :: (Ix dim, Elem a, Elem b, Elem c)
=> (Exp a -> Exp b -> Exp c)
-> Acc (Array dim a)
-> Acc (Array dim b)
-> Acc (Array dim c)
zipWith = ZipWith
scanl :: Elem a
=> (Exp a -> Exp a -> Exp a)
-> Exp a
-> Acc (Vector a)
-> (Acc (Vector a), Acc (Scalar a))
scanl f e arr = unpair (Scanl f e arr)
scanr :: Elem a
=> (Exp a -> Exp a -> Exp a)
-> Exp a
-> Acc (Vector a)
-> (Acc (Vector a), Acc (Scalar a))
scanr f e arr = unpair (Scanr f e arr)
fold :: (Ix dim, Elem a)
=> (Exp a -> Exp a -> Exp a)
-> Exp a
-> Acc (Array dim a)
-> Acc (Scalar a)
fold = Fold
foldSeg :: Elem a
=> (Exp a -> Exp a -> Exp a)
-> Exp a
-> Acc (Vector a)
-> Acc Segments
-> Acc (Vector a)
foldSeg = FoldSeg
permute :: (Ix dim, Ix dim', Elem a)
=> (Exp a -> Exp a -> Exp a)
-> Acc (Array dim' a)
-> (Exp dim -> Exp dim')
-> Acc (Array dim a)
-> Acc (Array dim' a)
permute = Permute
backpermute :: (Ix dim, Ix dim', Elem a)
=> Exp dim'
-> (Exp dim' -> Exp dim)
-> Acc (Array dim a)
-> Acc (Array dim' a)
backpermute = Backpermute
class Tuple tup where
type TupleT tup
tuple :: tup -> TupleT tup
untuple :: TupleT tup -> tup
instance (Elem a, Elem b) => Tuple (Exp a, Exp b) where
type TupleT (Exp a, Exp b) = Exp (a, b)
tuple = tup2
untuple = untup2
instance (Elem a, Elem b, Elem c) => Tuple (Exp a, Exp b, Exp c) where
type TupleT (Exp a, Exp b, Exp c) = Exp (a, b, c)
tuple = tup3
untuple = untup3
instance (Elem a, Elem b, Elem c, Elem d)
=> Tuple (Exp a, Exp b, Exp c, Exp d) where
type TupleT (Exp a, Exp b, Exp c, Exp d) = Exp (a, b, c, d)
tuple = tup4
untuple = untup4
instance (Elem a, Elem b, Elem c, Elem d, Elem e)
=> Tuple (Exp a, Exp b, Exp c, Exp d, Exp e) where
type TupleT (Exp a, Exp b, Exp c, Exp d, Exp e) = Exp (a, b, c, d, e)
tuple = tup5
untuple = untup5
fst :: forall a b. (Elem a, Elem b) => Exp (a, b) -> Exp a
fst e = let (x, _:: Exp b) = untuple e in x
snd :: forall a b. (Elem a, Elem b) => Exp (a, b) -> Exp b
snd e = let (_ :: Exp a, y) = untuple e in y
curry :: (Elem a, Elem b) => (Exp (a,b) -> Exp c) -> Exp a -> Exp b -> Exp c
curry f x y = f (tuple (x,y))
uncurry :: (Elem a, Elem b) => (Exp a -> Exp b -> Exp c) -> Exp (a,b) -> Exp c
uncurry f t = let (x,y) = untuple t in f x y
infix 0 ?
(?) :: Elem t => Exp Bool -> (Exp t, Exp t) -> Exp t
c ? (t, e) = Cond c t e
infixl 9 !
(!) :: (Ix dim, Elem e) => Acc (Array dim e) -> Exp dim -> Exp e
(!) = IndexScalar
shape :: (Ix dim, Elem dim) => Acc (Array dim e) -> Exp dim
shape = Shape
instance (Elem t, IsBounded t) => Bounded (Exp t) where
minBound = mkMinBound
maxBound = mkMaxBound
instance (Elem t, IsScalar t) => Enum (Exp t)
instance (Elem t, IsScalar t) => Prelude.Eq (Exp t) where
(==) = error "Prelude.Eq.== applied to EDSL types"
instance (Elem t, IsScalar t) => Prelude.Ord (Exp t) where
compare = error "Prelude.Ord.compare applied to EDSL types"
instance (Elem t, IsNum t, IsIntegral t) => Bits (Exp t) where
(.&.) = mkBAnd
(.|.) = mkBOr
xor = mkBXor
complement = mkBNot
shift, shiftL, shiftR :: (Elem t, IsIntegral t) => Exp t -> Exp Int -> Exp t
shift x i = i ==* 0 ? (x, i <* 0 ? (x `shiftR` (i), x `shiftL` i))
shiftL = mkBShiftL
shiftR = mkBShiftR
rotate, rotateL, rotateR :: (Elem t, IsIntegral t) => Exp t -> Exp Int -> Exp t
rotate x i = i ==* 0 ? (x, i <* 0 ? (x `rotateR` (i), x `rotateL` i))
rotateL = mkBRotateL
rotateR = mkBRotateR
bit :: (Elem t, IsIntegral t) => Exp Int -> Exp t
bit x = 1 `shiftL` x
setBit, clearBit, complementBit :: (Elem t, IsIntegral t) => Exp t -> Exp Int -> Exp t
x `setBit` i = x .|. bit i
x `clearBit` i = x .&. complement (bit i)
x `complementBit` i = x `xor` bit i
testBit :: (Elem t, IsIntegral t) => Exp t -> Exp Int -> Exp Bool
x `testBit` i = (x .&. bit i) /=* 0
instance (Elem t, IsNum t) => Num (Exp t) where
(+) = mkAdd
() = mkSub
(*) = mkMul
negate = mkNeg
abs = mkAbs
signum = mkSig
fromInteger = constant . fromInteger
instance (Elem t, IsNum t) => Real (Exp t)
instance (Elem t, IsIntegral t) => Integral (Exp t) where
quot = mkQuot
rem = mkRem
div = mkIDiv
mod = mkMod
instance (Elem 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 (Elem t, IsFloating t) => Fractional (Exp t) where
(/) = mkFDiv
recip = mkRecip
fromRational = constant . fromRational
instance (Elem t, IsFloating t) => RealFrac (Exp t)
instance (Elem t, IsFloating t) => RealFloat (Exp t)
infix 4 ==*, /=*, <*, <=*, >*, >=*
(==*) :: (Elem t, IsScalar t) => Exp t -> Exp t -> Exp Bool
(==*) = mkEq
(/=*) :: (Elem t, IsScalar t) => Exp t -> Exp t -> Exp Bool
(/=*) = mkNEq
(<*) :: (Elem t, IsScalar t) => Exp t -> Exp t -> Exp Bool
(<*) = mkLt
(>=*) :: (Elem t, IsScalar t) => Exp t -> Exp t -> Exp Bool
(>=*) = mkGtEq
(>*) :: (Elem t, IsScalar t) => Exp t -> Exp t -> Exp Bool
(>*) = mkGt
(<=*) :: (Elem t, IsScalar t) => Exp t -> Exp t -> Exp Bool
(<=*) = mkLtEq
max :: (Elem t, IsScalar t) => Exp t -> Exp t -> Exp t
max = mkMax
min :: (Elem t, IsScalar t) => Exp t -> Exp t -> Exp t
min = mkMin
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
intToFloat :: Exp Int -> Exp Float
intToFloat = mkIntFloat
roundFloatToInt :: Exp Float -> Exp Int
roundFloatToInt = mkRoundFloatInt
truncateFloatToInt :: Exp Float -> Exp Int
truncateFloatToInt = mkTruncFloatInt
ignore :: Ix dim => Exp dim
ignore = constant Sugar.ignore