module Data.Array.Knead.Simple.Slice (
T,
Linear,
apply,
passAny,
pass,
pick,
pickFst,
pickSnd,
extrude,
extrudeFst,
extrudeSnd,
transpose,
(Core.$:.),
id,
first,
second,
compose,
) where
import qualified Data.Array.Knead.Simple.ShapeDependent as ShapeDep
import qualified Data.Array.Knead.Simple.Private as Core
import qualified Data.Array.Knead.Shape.Cubic as Linear
import qualified Data.Array.Knead.Shape as Shape
import qualified Data.Array.Knead.Expression as Expr
import Data.Array.Knead.Shape.Cubic ((#:.), (:.)((:.)), )
import Data.Array.Knead.Expression (Exp, )
import qualified LLVM.Extra.Multi.Value as MultiValue
import LLVM.Extra.Multi.Value (atom, )
import qualified Prelude as P
import Prelude hiding (id, zipWith, zipWith3, zip, zip3, replicate, )
data T sh0 sh1 =
forall ix0 ix1.
(Shape.Index sh0 ~ ix0, Shape.Index sh1 ~ ix1) =>
Cons
(Exp sh0 -> Exp sh1)
(Exp ix1 -> Exp ix0)
apply ::
(Core.C array, Shape.C sh0, Shape.C sh1, MultiValue.C a) =>
T sh0 sh1 ->
array sh0 a ->
array sh1 a
apply (Cons fsh fix) =
ShapeDep.backpermute fsh fix
pickFst :: Exp (Shape.Index n) -> T (n,sh) sh
pickFst i = Cons Expr.snd (Expr.zip i)
pickSnd :: Exp (Shape.Index n) -> T (sh,n) sh
pickSnd i = Cons Expr.fst (flip Expr.zip i)
extrudeFst :: Exp n -> T sh (n,sh)
extrudeFst n = Cons (Expr.zip n) Expr.snd
extrudeSnd :: Exp n -> T sh (sh,n)
extrudeSnd n = Cons (flip Expr.zip n) Expr.fst
transpose :: T (sh0,sh1) (sh1,sh0)
transpose = Cons Expr.swap Expr.swap
id :: T sh sh
id = Cons P.id P.id
first :: T sh0 sh1 -> T (sh0,sh) (sh1,sh)
first (Cons fsh fix) = Cons (Expr.mapFst fsh) (Expr.mapFst fix)
second :: T sh0 sh1 -> T (sh,sh0) (sh,sh1)
second (Cons fsh fix) = Cons (Expr.mapSnd fsh) (Expr.mapSnd fix)
infixr 1 `compose`
compose :: T sh0 sh1 -> T sh1 sh2 -> T sh0 sh2
compose (Cons fshA fixA) (Cons fshB fixB) = Cons (fshB . fshA) (fixA . fixB)
type Linear sh0 sh1 = T (Linear.Shape sh0) (Linear.Shape sh1)
passAny :: Linear sh sh
passAny = Cons P.id P.id
pass ::
Linear sh0 sh1 ->
Linear (sh0:.i) (sh1:.i)
pass (Cons fsh fix) =
Cons
(Expr.modify (Linear.shape (atom:.atom)) $ \(sh:.s) -> fsh sh :. s)
(Expr.modify (Linear.index (atom:.atom)) $ \(ix:.i) -> fix ix :. i)
pick ::
Exp i ->
Linear sh0 sh1 ->
Linear (sh0:.i) sh1
pick i (Cons fsh fix) =
Cons
(fsh . Linear.tail)
(\ix -> fix ix #:. i)
extrude ::
Exp i ->
Linear sh0 sh1 ->
Linear sh0 (sh1:.i)
extrude n (Cons fsh fix) =
Cons
(\sh -> fsh sh #:. n)
(fix . Linear.tail)
instance Core.Process (T sh0 sh1) where