{-# 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 All_, pattern Any_,
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.Extra hiding ( Exp, Match )
pattern Pattern :: forall b a context. IsPattern context a b => b -> context a
pattern $mPattern :: forall {r} {b} {a} {context :: * -> *}.
IsPattern context a b =>
context a -> (b -> r) -> ((# #) -> r) -> r
$bPattern :: forall b a (context :: * -> *).
IsPattern context a b =>
b -> context a
Pattern vars <- (matcher @context -> vars)
where Pattern = forall (context :: * -> *) a b.
IsPattern context a b =>
b -> context a
builder @context
class IsPattern context a b where
builder :: b -> context a
matcher :: context a -> b
pattern Vector :: forall b a context. IsVector context a b => b -> context a
pattern $mVector :: forall {r} {b} {a} {context :: * -> *}.
IsVector context a b =>
context a -> (b -> r) -> ((# #) -> r) -> r
$bVector :: forall b a (context :: * -> *).
IsVector context a b =>
b -> context a
Vector vars <- (vunpack @context -> vars)
where Vector = 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 $mZ_ :: forall {r}. Exp Z -> ((# #) -> r) -> ((# #) -> r) -> r
$bZ_ :: Exp Z
Z_ = Pattern Z
{-# COMPLETE Z_ #-}
infixl 3 ::.
pattern (::.) :: (Elt a, Elt b) => Exp a -> Exp b -> Exp (a :. b)
pattern a $m::. :: forall {r} {a} {b}.
(Elt a, Elt b) =>
Exp (a :. b) -> (Exp a -> Exp b -> r) -> ((# #) -> r) -> r
$b::. :: forall a b. (Elt a, Elt b) => Exp a -> Exp b -> Exp (a :. b)
::. b = Pattern (a :. b)
{-# COMPLETE (::.) #-}
infixl 3 `Ix`
pattern Ix :: (Elt a, Elt b) => Exp a -> Exp b -> Exp (a :. b)
pattern a $mIx :: forall {r} {a} {b}.
(Elt a, Elt b) =>
Exp (a :. b) -> (Exp a -> Exp b -> r) -> ((# #) -> r) -> r
$bIx :: forall a b. (Elt a, Elt b) => Exp a -> Exp b -> Exp (a :. b)
`Ix` b = a ::. b
{-# COMPLETE Ix #-}
pattern All_ :: Exp All
pattern $mAll_ :: forall {r}. Exp All -> ((# #) -> r) -> ((# #) -> r) -> r
$bAll_ :: Exp All
All_ <- (const True -> True)
where All_ = All -> Exp All
forall e. (HasCallStack, Elt e) => e -> Exp e
constant All
All
{-# COMPLETE All_ #-}
pattern Any_ :: (Shape sh, Elt (Any sh)) => Exp (Any sh)
pattern $mAny_ :: forall {r} {sh}.
(Shape sh, Elt (Any sh)) =>
Exp (Any sh) -> ((# #) -> r) -> ((# #) -> r) -> r
$bAny_ :: forall sh. (Shape sh, Elt (Any sh)) => Exp (Any sh)
Any_ <- (const True -> True)
where Any_ = Any sh -> Exp (Any sh)
forall e. (HasCallStack, Elt e) => e -> Exp e
constant Any sh
forall sh. Any sh
Any
{-# COMPLETE Any_ #-}
instance IsPattern Exp Z Z where
builder :: Z -> Exp Z
builder Z
_ = Z -> Exp Z
forall e. (HasCallStack, Elt e) => e -> Exp e
constant Z
Z
matcher :: Exp Z -> Z
matcher Exp Z
_ = Z
Z
instance (Elt a, Elt b) => IsPattern Exp (a :. b) (Exp a :. Exp b) where
builder :: (Exp a :. Exp b) -> Exp (a :. b)
builder (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 :. b))
-> SmartExp (EltR (a :. b))
forall t. PreSmartExp SmartAcc SmartExp t -> SmartExp t
SmartExp (PreSmartExp SmartAcc SmartExp (EltR (a :. b))
-> SmartExp (EltR (a :. b)))
-> PreSmartExp SmartAcc SmartExp (EltR (a :. b))
-> SmartExp (EltR (a :. 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
matcher :: Exp (a :. b) -> Exp a :. Exp b
matcher (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 a1 a. PairIdx (a1, a) a
PairIdxRight SmartExp (EltR a, EltR b)
SmartExp (EltR (a :. b))
t)