{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ParallelListComp #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}
module Data.Array.Accelerate.Pattern (
pattern Pattern,
pattern T2, pattern T3, pattern T4, pattern T5, pattern T6,
pattern T7, pattern T8, pattern T9, pattern T10, pattern T11,
pattern T12, pattern T13, pattern T14, pattern T15, pattern T16,
pattern Z_, pattern Ix, pattern (::.),
pattern I0, pattern I1, pattern I2, pattern I3, pattern I4,
pattern I5, pattern I6, pattern I7, pattern I8, pattern I9,
pattern V2, pattern V3, pattern V4, pattern V8, pattern V16,
) where
import Data.Array.Accelerate.AST.Idx
import Data.Array.Accelerate.Representation.Tag
import Data.Array.Accelerate.Representation.Vec
import Data.Array.Accelerate.Smart
import Data.Array.Accelerate.Sugar.Array
import Data.Array.Accelerate.Sugar.Elt
import Data.Array.Accelerate.Sugar.Shape
import Data.Array.Accelerate.Sugar.Vec
import Data.Array.Accelerate.Type
import Data.Primitive.Vec
import Language.Haskell.TH hiding ( Exp, Match, tupP, tupE )
import Language.Haskell.TH.Extra
pattern Pattern :: forall b a context. IsPattern context a b => b -> context a
pattern $bPattern :: b -> context a
$mPattern :: forall r b a (context :: * -> *).
IsPattern context a b =>
context a -> (b -> r) -> (Void# -> r) -> r
Pattern vars <- (destruct @context -> vars)
where Pattern = forall a b. IsPattern context a b => b -> context a
forall (con :: * -> *) a b. IsPattern con a b => b -> con a
construct @context
class IsPattern con a b where
construct :: b -> con a
destruct :: con a -> b
pattern Vector :: forall b a context. IsVector context a b => b -> context a
pattern $bVector :: b -> context a
$mVector :: forall r b a (context :: * -> *).
IsVector context a b =>
context a -> (b -> r) -> (Void# -> r) -> r
Vector vars <- (vunpack @context -> vars)
where Vector = forall a b. IsVector context a b => b -> context a
forall (context :: * -> *) a b.
IsVector context a b =>
b -> context a
vpack @context
class IsVector context a b where
vpack :: b -> context a
vunpack :: context a -> b
pattern Z_ :: Exp DIM0
pattern $bZ_ :: Exp DIM0
$mZ_ :: forall r. Exp DIM0 -> (Void# -> r) -> (Void# -> r) -> r
Z_ = Pattern Z
{-# COMPLETE Z_ #-}
infixl 3 ::.
pattern (::.) :: (Elt a, Elt b) => Exp a -> Exp b -> Exp (a :. b)
pattern a $b::. :: Exp a -> Exp b -> Exp (a :. b)
$m::. :: forall r a b.
(Elt a, Elt b) =>
Exp (a :. b) -> (Exp a -> Exp b -> r) -> (Void# -> r) -> r
::. b = Pattern (a :. b)
{-# COMPLETE (::.) #-}
infixl 3 `Ix`
pattern Ix :: (Elt a, Elt b) => Exp a -> Exp b -> Exp (a :. b)
pattern a $bIx :: Exp a -> Exp b -> Exp (a :. b)
$mIx :: forall r a b.
(Elt a, Elt b) =>
Exp (a :. b) -> (Exp a -> Exp b -> r) -> (Void# -> r) -> r
`Ix` b = a ::. b
{-# COMPLETE Ix #-}
instance IsPattern Exp Z Z where
construct :: DIM0 -> Exp DIM0
construct DIM0
_ = DIM0 -> Exp DIM0
forall e. (HasCallStack, Elt e) => e -> Exp e
constant DIM0
Z
destruct :: Exp DIM0 -> DIM0
destruct Exp DIM0
_ = DIM0
Z
instance (Elt a, Elt b) => IsPattern Exp (a :. b) (Exp a :. Exp b) where
construct :: (Exp a :. Exp b) -> Exp (a :. b)
construct (Exp SmartExp (EltR a)
a :. Exp SmartExp (EltR b)
b) = SmartExp (EltR (a :. b)) -> Exp (a :. b)
forall t. SmartExp (EltR t) -> Exp t
Exp (SmartExp (EltR (a :. b)) -> Exp (a :. b))
-> SmartExp (EltR (a :. b)) -> Exp (a :. b)
forall a b. (a -> b) -> a -> b
$ PreSmartExp SmartAcc SmartExp (EltR a, EltR b)
-> SmartExp (EltR a, EltR b)
forall t. PreSmartExp SmartAcc SmartExp t -> SmartExp t
SmartExp (PreSmartExp SmartAcc SmartExp (EltR a, EltR b)
-> SmartExp (EltR a, EltR b))
-> PreSmartExp SmartAcc SmartExp (EltR a, EltR b)
-> SmartExp (EltR a, EltR b)
forall a b. (a -> b) -> a -> b
$ SmartExp (EltR a)
-> SmartExp (EltR b)
-> PreSmartExp SmartAcc SmartExp (EltR a, EltR b)
forall (exp :: * -> *) t1 t2 (acc :: * -> *).
exp t1 -> exp t2 -> PreSmartExp acc exp (t1, t2)
Pair SmartExp (EltR a)
a SmartExp (EltR b)
b
destruct :: Exp (a :. b) -> Exp a :. Exp b
destruct (Exp SmartExp (EltR (a :. b))
t) = SmartExp (EltR a) -> Exp a
forall t. SmartExp (EltR t) -> Exp t
Exp (PreSmartExp SmartAcc SmartExp (EltR a) -> SmartExp (EltR a)
forall t. PreSmartExp SmartAcc SmartExp t -> SmartExp t
SmartExp (PreSmartExp SmartAcc SmartExp (EltR a) -> SmartExp (EltR a))
-> PreSmartExp SmartAcc SmartExp (EltR a) -> SmartExp (EltR a)
forall a b. (a -> b) -> a -> b
$ PairIdx (EltR a, EltR b) (EltR a)
-> SmartExp (EltR a, EltR b)
-> PreSmartExp SmartAcc SmartExp (EltR a)
forall t1 t2 t (exp :: * -> *) (acc :: * -> *).
PairIdx (t1, t2) t -> exp (t1, t2) -> PreSmartExp acc exp t
Prj PairIdx (EltR a, EltR b) (EltR a)
forall a b. PairIdx (a, b) a
PairIdxLeft SmartExp (EltR a, EltR b)
SmartExp (EltR (a :. b))
t) Exp a -> Exp b -> Exp a :. Exp b
forall tail head. tail -> head -> tail :. head
:. SmartExp (EltR b) -> Exp b
forall t. SmartExp (EltR t) -> Exp t
Exp (PreSmartExp SmartAcc SmartExp (EltR b) -> SmartExp (EltR b)
forall t. PreSmartExp SmartAcc SmartExp t -> SmartExp t
SmartExp (PreSmartExp SmartAcc SmartExp (EltR b) -> SmartExp (EltR b))
-> PreSmartExp SmartAcc SmartExp (EltR b) -> SmartExp (EltR b)
forall a b. (a -> b) -> a -> b
$ PairIdx (EltR a, EltR b) (EltR b)
-> SmartExp (EltR a, EltR b)
-> PreSmartExp SmartAcc SmartExp (EltR b)
forall t1 t2 t (exp :: * -> *) (acc :: * -> *).
PairIdx (t1, t2) t -> exp (t1, t2) -> PreSmartExp acc exp t
Prj PairIdx (EltR a, EltR b) (EltR b)
forall a b. PairIdx (a, b) b
PairIdxRight SmartExp (EltR a, EltR b)
SmartExp (EltR (a :. b))
t)