{-# LANGUAGE PostfixOperators #-}
{-# OPTIONS_HADDOCK hide #-}
module ForSyDe.Atom.MoC.DE.Interface where
import ForSyDe.Atom.MoC.DE.Lib (sync2, sync3, sync4)
import ForSyDe.Atom.MoC.Stream (Stream(..))
import qualified ForSyDe.Atom.Skel.Vector as V (
Vector, vector, zipx, unzipx, fanout, length, reverse)
import ForSyDe.Atom.Utility.Tuple
import qualified ForSyDe.Atom.MoC.DE.Core as DE
import qualified ForSyDe.Atom.MoC.SY.Core as SY
import qualified ForSyDe.Atom.MoC.CT.Core as CT
import Prelude hiding ((<>))
toSY2 :: (Num t, Ord t, Eq t)
=> DE.SignalBase t a
-> DE.SignalBase t b
-> (SY.Signal t, SY.Signal a, SY.Signal b)
toSY1 :: (Num t, Ord t, Eq t)
=> DE.SignalBase t a
-> (SY.Signal t, SY.Signal a)
toSY3 :: (Num t, Ord t, Eq t)
=> DE.SignalBase t a -> DE.SignalBase t b -> DE.SignalBase t c
-> (SY.Signal t, SY.Signal a, SY.Signal b, SY.Signal c)
toSY4 :: (Num t, Ord t, Eq t)
=> DE.SignalBase t a -> DE.SignalBase t b -> DE.SignalBase t c
-> DE.SignalBase t d
-> (SY.Signal t, SY.Signal a, SY.Signal b, SY.Signal c, SY.Signal d)
eventToSY :: DE t a -> (SY t, SY a)
eventToSY (DE.DE t :: t
t a :: a
a) = (t -> SY t
forall a. a -> SY a
SY.SY t
t, a -> SY a
forall a. a -> SY a
SY.SY a
a)
toSY1 :: SignalBase t a -> (Signal t, Signal a)
toSY1 s1 :: SignalBase t a
s1 = (DE t a -> (SY t, SY a)
forall t a. DE t a -> (SY t, SY a)
eventToSY (DE t a -> (SY t, SY a)) -> SignalBase t a -> Stream (SY t, SY a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SignalBase t a
s1 Stream (SY t, SY a) -> (Signal t, Signal a)
forall (f :: * -> *) a1 b. Functor f => f (a1, b) -> (f a1, f b)
|<)
toSY2 :: SignalBase t a -> SignalBase t b -> (Signal t, Signal a, Signal b)
toSY2 s1 :: SignalBase t a
s1 s2 :: SignalBase t b
s2
= let (sy1 :: (Signal t, Signal a)
sy1,sy2 :: (Signal t, Signal b)
sy2) = (SignalBase t a -> (Signal t, Signal a)
forall t a.
(Num t, Ord t, Eq t) =>
SignalBase t a -> (Signal t, Signal a)
toSY1,SignalBase t b -> (Signal t, Signal b)
forall t a.
(Num t, Ord t, Eq t) =>
SignalBase t a -> (Signal t, Signal a)
toSY1) (SignalBase t a -> (Signal t, Signal a),
SignalBase t b -> (Signal t, Signal b))
-> (SignalBase t a, SignalBase t b)
-> ((Signal t, Signal a), (Signal t, Signal b))
forall a1 b1 a2 b2. (a1 -> b1, a2 -> b2) -> (a1, a2) -> (b1, b2)
$$ SignalBase t a
-> SignalBase t b -> (SignalBase t a, SignalBase t b)
forall t a1 a2.
(Num t, Ord t, Eq t) =>
SignalBase t a1
-> SignalBase t a2 -> (SignalBase t a1, SignalBase t a2)
sync2 SignalBase t a
s1 SignalBase t b
s2
in ((Signal t, Signal a) -> Signal t
forall a b. (a, b) -> a
fst,(Signal t, Signal a) -> Signal a
forall a b. (a, b) -> b
snd,(Signal t, Signal b) -> Signal b
forall a b. (a, b) -> b
snd) ((Signal t, Signal a) -> Signal t,
(Signal t, Signal a) -> Signal a, (Signal t, Signal b) -> Signal b)
-> ((Signal t, Signal a), (Signal t, Signal a),
(Signal t, Signal b))
-> (Signal t, Signal a, Signal b)
forall t1 a t2 b t3 c.
(t1 -> a, t2 -> b, t3 -> c) -> (t1, t2, t3) -> (a, b, c)
$$$ ((Signal t, Signal a)
sy1,(Signal t, Signal a)
sy1,(Signal t, Signal b)
sy2)
toSY3 :: SignalBase t a
-> SignalBase t b
-> SignalBase t c
-> (Signal t, Signal a, Signal b, Signal c)
toSY3 s1 :: SignalBase t a
s1 s2 :: SignalBase t b
s2 s3 :: SignalBase t c
s3
= let (sy1 :: (Signal t, Signal a)
sy1,sy2 :: (Signal t, Signal b)
sy2,sy3 :: (Signal t, Signal c)
sy3) = (SignalBase t a -> (Signal t, Signal a)
forall t a.
(Num t, Ord t, Eq t) =>
SignalBase t a -> (Signal t, Signal a)
toSY1,SignalBase t b -> (Signal t, Signal b)
forall t a.
(Num t, Ord t, Eq t) =>
SignalBase t a -> (Signal t, Signal a)
toSY1,SignalBase t c -> (Signal t, Signal c)
forall t a.
(Num t, Ord t, Eq t) =>
SignalBase t a -> (Signal t, Signal a)
toSY1) (SignalBase t a -> (Signal t, Signal a),
SignalBase t b -> (Signal t, Signal b),
SignalBase t c -> (Signal t, Signal c))
-> (SignalBase t a, SignalBase t b, SignalBase t c)
-> ((Signal t, Signal a), (Signal t, Signal b),
(Signal t, Signal c))
forall t1 a t2 b t3 c.
(t1 -> a, t2 -> b, t3 -> c) -> (t1, t2, t3) -> (a, b, c)
$$$ SignalBase t a
-> SignalBase t b
-> SignalBase t c
-> (SignalBase t a, SignalBase t b, SignalBase t c)
forall t a1 a2 a3.
(Num t, Ord t, Eq t) =>
SignalBase t a1
-> SignalBase t a2
-> SignalBase t a3
-> (SignalBase t a1, SignalBase t a2, SignalBase t a3)
sync3 SignalBase t a
s1 SignalBase t b
s2 SignalBase t c
s3
in ((Signal t, Signal a) -> Signal t
forall a b. (a, b) -> a
fst,(Signal t, Signal a) -> Signal a
forall a b. (a, b) -> b
snd,(Signal t, Signal b) -> Signal b
forall a b. (a, b) -> b
snd,(Signal t, Signal c) -> Signal c
forall a b. (a, b) -> b
snd) ((Signal t, Signal a) -> Signal t,
(Signal t, Signal a) -> Signal a, (Signal t, Signal b) -> Signal b,
(Signal t, Signal c) -> Signal c)
-> ((Signal t, Signal a), (Signal t, Signal a),
(Signal t, Signal b), (Signal t, Signal c))
-> (Signal t, Signal a, Signal b, Signal c)
forall t1 a t2 b t3 c t4 d.
(t1 -> a, t2 -> b, t3 -> c, t4 -> d)
-> (t1, t2, t3, t4) -> (a, b, c, d)
$$$$ ((Signal t, Signal a)
sy1,(Signal t, Signal a)
sy1,(Signal t, Signal b)
sy2,(Signal t, Signal c)
sy3)
toSY4 :: SignalBase t a
-> SignalBase t b
-> SignalBase t c
-> SignalBase t d
-> (Signal t, Signal a, Signal b, Signal c, Signal d)
toSY4 s1 :: SignalBase t a
s1 s2 :: SignalBase t b
s2 s3 :: SignalBase t c
s3 s4 :: SignalBase t d
s4
= let (sy1 :: (Signal t, Signal a)
sy1,sy2 :: (Signal t, Signal b)
sy2,sy3 :: (Signal t, Signal c)
sy3,sy4 :: (Signal t, Signal d)
sy4) = (SignalBase t a -> (Signal t, Signal a)
forall t a.
(Num t, Ord t, Eq t) =>
SignalBase t a -> (Signal t, Signal a)
toSY1,SignalBase t b -> (Signal t, Signal b)
forall t a.
(Num t, Ord t, Eq t) =>
SignalBase t a -> (Signal t, Signal a)
toSY1,SignalBase t c -> (Signal t, Signal c)
forall t a.
(Num t, Ord t, Eq t) =>
SignalBase t a -> (Signal t, Signal a)
toSY1,SignalBase t d -> (Signal t, Signal d)
forall t a.
(Num t, Ord t, Eq t) =>
SignalBase t a -> (Signal t, Signal a)
toSY1) (SignalBase t a -> (Signal t, Signal a),
SignalBase t b -> (Signal t, Signal b),
SignalBase t c -> (Signal t, Signal c),
SignalBase t d -> (Signal t, Signal d))
-> (SignalBase t a, SignalBase t b, SignalBase t c, SignalBase t d)
-> ((Signal t, Signal a), (Signal t, Signal b),
(Signal t, Signal c), (Signal t, Signal d))
forall t1 a t2 b t3 c t4 d.
(t1 -> a, t2 -> b, t3 -> c, t4 -> d)
-> (t1, t2, t3, t4) -> (a, b, c, d)
$$$$ SignalBase t a
-> SignalBase t b
-> SignalBase t c
-> SignalBase t d
-> (SignalBase t a, SignalBase t b, SignalBase t c, SignalBase t d)
forall t a1 a2 a3 a4.
(Num t, Ord t, Eq t) =>
SignalBase t a1
-> SignalBase t a2
-> SignalBase t a3
-> SignalBase t a4
-> (SignalBase t a1, SignalBase t a2, SignalBase t a3,
SignalBase t a4)
sync4 SignalBase t a
s1 SignalBase t b
s2 SignalBase t c
s3 SignalBase t d
s4
in ((Signal t, Signal a) -> Signal t
forall a b. (a, b) -> a
fst,(Signal t, Signal a) -> Signal a
forall a b. (a, b) -> b
snd,(Signal t, Signal b) -> Signal b
forall a b. (a, b) -> b
snd,(Signal t, Signal c) -> Signal c
forall a b. (a, b) -> b
snd,(Signal t, Signal d) -> Signal d
forall a b. (a, b) -> b
snd) ((Signal t, Signal a) -> Signal t,
(Signal t, Signal a) -> Signal a, (Signal t, Signal b) -> Signal b,
(Signal t, Signal c) -> Signal c, (Signal t, Signal d) -> Signal d)
-> ((Signal t, Signal a), (Signal t, Signal a),
(Signal t, Signal b), (Signal t, Signal c), (Signal t, Signal d))
-> (Signal t, Signal a, Signal b, Signal c, Signal d)
forall t1 a t2 b t3 c t4 d t5 e.
(t1 -> a, t2 -> b, t3 -> c, t4 -> d, t5 -> e)
-> (t1, t2, t3, t4, t5) -> (a, b, c, d, e)
$$$$$ ((Signal t, Signal a)
sy1,(Signal t, Signal a)
sy1,(Signal t, Signal b)
sy2,(Signal t, Signal c)
sy3,(Signal t, Signal d)
sy4)
toCT2 :: (Num ts, Real ts, Ord ts, Eq ts, Num tm, Fractional tm, Ord tm)
=> DE.SignalBase ts (tm -> a)
-> DE.SignalBase ts (tm -> b)
-> (CT.SignalBase ts tm a, CT.SignalBase ts tm b)
eventToCT :: DE t (time -> a) -> CT t time a
eventToCT (DE.DE t :: t
t a :: time -> a
a) = t -> time -> (time -> a) -> CT t time a
forall time timestamp a.
(Num time, Num timestamp, Ord timestamp, Eq timestamp) =>
timestamp -> time -> (time -> a) -> CT timestamp time a
CT.CT t
t 0 time -> a
a
toCT1 :: f (DE t (time -> a)) -> f (CT t time a)
toCT1 s1 :: f (DE t (time -> a))
s1 = DE t (time -> a) -> CT t time a
forall time t a. Num time => DE t (time -> a) -> CT t time a
eventToCT (DE t (time -> a) -> CT t time a)
-> f (DE t (time -> a)) -> f (CT t time a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (DE t (time -> a))
s1
toCT2 :: SignalBase ts (tm -> a)
-> SignalBase ts (tm -> b)
-> (SignalBase ts tm a, SignalBase ts tm b)
toCT2 s1 :: SignalBase ts (tm -> a)
s1 s2 :: SignalBase ts (tm -> b)
s2 = (SignalBase ts (tm -> a) -> SignalBase ts tm a
forall (f :: * -> *) time t a.
(Functor f, Num time) =>
f (DE t (time -> a)) -> f (CT t time a)
toCT1, SignalBase ts (tm -> b) -> SignalBase ts tm b
forall (f :: * -> *) time t a.
(Functor f, Num time) =>
f (DE t (time -> a)) -> f (CT t time a)
toCT1) (SignalBase ts (tm -> a) -> SignalBase ts tm a,
SignalBase ts (tm -> b) -> SignalBase ts tm b)
-> (SignalBase ts (tm -> a), SignalBase ts (tm -> b))
-> (SignalBase ts tm a, SignalBase ts tm b)
forall a1 b1 a2 b2. (a1 -> b1, a2 -> b2) -> (a1, a2) -> (b1, b2)
$$ (SignalBase ts (tm -> a)
s1,SignalBase ts (tm -> b)
s2)
toCT3 :: f (DE t (time -> a))
-> f (DE t (time -> a))
-> f (DE t (time -> a))
-> (f (CT t time a), f (CT t time a), f (CT t time a))
toCT3 s1 :: f (DE t (time -> a))
s1 s2 :: f (DE t (time -> a))
s2 s3 :: f (DE t (time -> a))
s3 = (f (DE t (time -> a)) -> f (CT t time a)
forall (f :: * -> *) time t a.
(Functor f, Num time) =>
f (DE t (time -> a)) -> f (CT t time a)
toCT1, f (DE t (time -> a)) -> f (CT t time a)
forall (f :: * -> *) time t a.
(Functor f, Num time) =>
f (DE t (time -> a)) -> f (CT t time a)
toCT1, f (DE t (time -> a)) -> f (CT t time a)
forall (f :: * -> *) time t a.
(Functor f, Num time) =>
f (DE t (time -> a)) -> f (CT t time a)
toCT1) (f (DE t (time -> a)) -> f (CT t time a),
f (DE t (time -> a)) -> f (CT t time a),
f (DE t (time -> a)) -> f (CT t time a))
-> (f (DE t (time -> a)), f (DE t (time -> a)),
f (DE t (time -> a)))
-> (f (CT t time a), f (CT t time a), f (CT t time a))
forall t1 a t2 b t3 c.
(t1 -> a, t2 -> b, t3 -> c) -> (t1, t2, t3) -> (a, b, c)
$$$ (f (DE t (time -> a))
s1,f (DE t (time -> a))
s2,f (DE t (time -> a))
s3)
toCT4 :: f (DE t (time -> a))
-> f (DE t (time -> a))
-> f (DE t (time -> a))
-> f (DE t (time -> a))
-> (f (CT t time a), f (CT t time a), f (CT t time a),
f (CT t time a))
toCT4 s1 :: f (DE t (time -> a))
s1 s2 :: f (DE t (time -> a))
s2 s3 :: f (DE t (time -> a))
s3 s4 :: f (DE t (time -> a))
s4 = (f (DE t (time -> a)) -> f (CT t time a)
forall (f :: * -> *) time t a.
(Functor f, Num time) =>
f (DE t (time -> a)) -> f (CT t time a)
toCT1, f (DE t (time -> a)) -> f (CT t time a)
forall (f :: * -> *) time t a.
(Functor f, Num time) =>
f (DE t (time -> a)) -> f (CT t time a)
toCT1, f (DE t (time -> a)) -> f (CT t time a)
forall (f :: * -> *) time t a.
(Functor f, Num time) =>
f (DE t (time -> a)) -> f (CT t time a)
toCT1, f (DE t (time -> a)) -> f (CT t time a)
forall (f :: * -> *) time t a.
(Functor f, Num time) =>
f (DE t (time -> a)) -> f (CT t time a)
toCT1) (f (DE t (time -> a)) -> f (CT t time a),
f (DE t (time -> a)) -> f (CT t time a),
f (DE t (time -> a)) -> f (CT t time a),
f (DE t (time -> a)) -> f (CT t time a))
-> (f (DE t (time -> a)), f (DE t (time -> a)),
f (DE t (time -> a)), f (DE t (time -> a)))
-> (f (CT t time a), f (CT t time a), f (CT t time a),
f (CT t time a))
forall t1 a t2 b t3 c t4 d.
(t1 -> a, t2 -> b, t3 -> c, t4 -> d)
-> (t1, t2, t3, t4) -> (a, b, c, d)
$$$$ (f (DE t (time -> a))
s1,f (DE t (time -> a))
s2,f (DE t (time -> a))
s3,f (DE t (time -> a))
s4)
zipx ::(Num t, Ord t, Eq t)
=> V.Vector (DE.SignalBase t a) -> DE.SignalBase t (V.Vector a)
zipx :: Vector (SignalBase t a) -> SignalBase t (Vector a)
zipx = Vector
((Vector a -> Vector a -> Vector a)
-> Fun
(DE t) (Vector a) (Fun (DE t) (Vector a) (Ret (DE t) (Vector a))))
-> Vector (SignalBase t a) -> SignalBase t (Vector a)
forall (e :: * -> *) a.
MoC e =>
Vector
((Vector a -> Vector a -> Vector a)
-> Fun e (Vector a) (Fun e (Vector a) (Ret e (Vector a))))
-> Vector (Stream (e a)) -> Stream (e (Vector a))
V.zipx (((Vector a -> Vector a -> Vector a)
-> Vector a -> Vector a -> Vector a)
-> Vector
((Vector a -> Vector a -> Vector a)
-> Vector a -> Vector a -> Vector a)
forall t. t -> Vector t
V.fanout (\cat :: Vector a -> Vector a -> Vector a
cat a :: Vector a
a b :: Vector a
b -> Vector a
a Vector a -> Vector a -> Vector a
`cat` Vector a
b))
unzipx :: (Num t, Ord t, Eq t)
=> Integer -> DE.SignalBase t (V.Vector a) -> V.Vector (DE.SignalBase t a)
unzipx :: Integer -> SignalBase t (Vector a) -> Vector (SignalBase t a)
unzipx n :: Integer
n = Vector (SignalBase t a) -> Vector (SignalBase t a)
forall a. Vector a -> Vector a
V.reverse (Vector (SignalBase t a) -> Vector (SignalBase t a))
-> (SignalBase t (Vector a) -> Vector (SignalBase t a))
-> SignalBase t (Vector a)
-> Vector (SignalBase t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Vector a -> Vector (Ret (DE t) a))
-> Integer -> SignalBase t (Vector a) -> Vector (SignalBase t a)
forall (e :: * -> *) a.
MoC e =>
(Vector a -> Vector (Ret e a))
-> Integer -> Stream (e (Vector a)) -> Vector (Stream (e a))
V.unzipx Vector a -> Vector (Ret (DE t) a)
forall a. a -> a
id Integer
n
unzipx' :: (Num t, Ord t, Eq t)
=> DE.SignalBase t (V.Vector a) -> V.Vector (DE.SignalBase t a)
unzipx' :: SignalBase t (Vector a) -> Vector (SignalBase t a)
unzipx' s :: SignalBase t (Vector a)
s@(a :: DE t (Vector a)
a:-_) = Integer -> SignalBase t (Vector a) -> Vector (SignalBase t a)
forall t a.
(Num t, Ord t, Eq t) =>
Integer -> SignalBase t (Vector a) -> Vector (SignalBase t a)
unzipx (Vector a -> Integer
forall p a. Num p => Vector a -> p
V.length (Vector a -> Integer) -> Vector a -> Integer
forall a b. (a -> b) -> a -> b
$ DE t (Vector a) -> Vector a
forall t a. DE t a -> a
DE.val DE t (Vector a)
a) SignalBase t (Vector a)
s