{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Synthesizer.LLVM.Causal.Exponential2 (
Parameter,
parameter,
parameterPlain,
multiValueParameter,
unMultiValueParameter,
causal,
ParameterPacked,
parameterPacked,
parameterPackedExp,
parameterPackedPlain,
multiValueParameterPacked,
unMultiValueParameterPacked,
causalPacked,
) where
import qualified Synthesizer.LLVM.Causal.Private as CausalPriv
import qualified Synthesizer.LLVM.Causal.Process as Causal
import qualified Synthesizer.LLVM.Causal.Functional as F
import qualified Synthesizer.LLVM.Frame.SerialVector.Plain as SerialPlain
import qualified Synthesizer.LLVM.Frame.SerialVector.Code as SerialCode
import qualified Synthesizer.LLVM.Frame.SerialVector as Serial
import qualified Synthesizer.LLVM.Frame.SerialVector.Class as SerialOld
import qualified Synthesizer.LLVM.Value as Value
import qualified LLVM.DSL.Expression as Expr
import LLVM.DSL.Expression (Exp)
import qualified LLVM.Extra.Multi.Value.Marshal as MarshalMV
import qualified LLVM.Extra.Multi.Value as MultiValue
import qualified LLVM.Extra.Multi.Vector as MultiVector
import qualified LLVM.Extra.ScalarOrVector as SoV
import qualified LLVM.Extra.Vector as Vector
import qualified LLVM.Extra.Storable as Storable
import qualified LLVM.Extra.Marshal as Marshal
import qualified LLVM.Extra.Memory as Memory
import qualified LLVM.Extra.Tuple as Tuple
import qualified LLVM.Extra.Arithmetic as A
import qualified LLVM.Core as LLVM
import LLVM.Core (CodeGenFunction, Value, IsFloating)
import qualified Type.Data.Num.Decimal as TypeNum
import qualified Foreign.Storable.Traversable as Store
import qualified Foreign.Storable
import Foreign.Storable (Storable)
import qualified Control.Applicative as App
import Control.Applicative (liftA2, pure, (<*>))
import Control.Arrow (arr, (&&&))
import qualified Data.Foldable as Fold
import qualified Data.Traversable as Trav
import Data.Traversable (traverse)
import qualified Algebra.Transcendental as Trans
import NumericPrelude.Numeric
import NumericPrelude.Base
newtype Parameter a = Parameter a
deriving (Int -> Parameter a -> ShowS
[Parameter a] -> ShowS
Parameter a -> String
(Int -> Parameter a -> ShowS)
-> (Parameter a -> String)
-> ([Parameter a] -> ShowS)
-> Show (Parameter a)
forall a. Show a => Int -> Parameter a -> ShowS
forall a. Show a => [Parameter a] -> ShowS
forall a. Show a => Parameter a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Parameter a -> ShowS
showsPrec :: Int -> Parameter a -> ShowS
$cshow :: forall a. Show a => Parameter a -> String
show :: Parameter a -> String
$cshowList :: forall a. Show a => [Parameter a] -> ShowS
showList :: [Parameter a] -> ShowS
Show, Ptr (Parameter a) -> IO (Parameter a)
Ptr (Parameter a) -> Int -> IO (Parameter a)
Ptr (Parameter a) -> Int -> Parameter a -> IO ()
Ptr (Parameter a) -> Parameter a -> IO ()
Parameter a -> Int
(Parameter a -> Int)
-> (Parameter a -> Int)
-> (Ptr (Parameter a) -> Int -> IO (Parameter a))
-> (Ptr (Parameter a) -> Int -> Parameter a -> IO ())
-> (forall b. Ptr b -> Int -> IO (Parameter a))
-> (forall b. Ptr b -> Int -> Parameter a -> IO ())
-> (Ptr (Parameter a) -> IO (Parameter a))
-> (Ptr (Parameter a) -> Parameter a -> IO ())
-> Storable (Parameter a)
forall b. Ptr b -> Int -> IO (Parameter a)
forall b. Ptr b -> Int -> Parameter a -> IO ()
forall a. Storable a => Ptr (Parameter a) -> IO (Parameter a)
forall a.
Storable a =>
Ptr (Parameter a) -> Int -> IO (Parameter a)
forall a.
Storable a =>
Ptr (Parameter a) -> Int -> Parameter a -> IO ()
forall a. Storable a => Ptr (Parameter a) -> Parameter a -> IO ()
forall a. Storable a => Parameter a -> Int
forall a b. Storable a => Ptr b -> Int -> IO (Parameter a)
forall a b. Storable a => Ptr b -> Int -> Parameter a -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
$csizeOf :: forall a. Storable a => Parameter a -> Int
sizeOf :: Parameter a -> Int
$calignment :: forall a. Storable a => Parameter a -> Int
alignment :: Parameter a -> Int
$cpeekElemOff :: forall a.
Storable a =>
Ptr (Parameter a) -> Int -> IO (Parameter a)
peekElemOff :: Ptr (Parameter a) -> Int -> IO (Parameter a)
$cpokeElemOff :: forall a.
Storable a =>
Ptr (Parameter a) -> Int -> Parameter a -> IO ()
pokeElemOff :: Ptr (Parameter a) -> Int -> Parameter a -> IO ()
$cpeekByteOff :: forall a b. Storable a => Ptr b -> Int -> IO (Parameter a)
peekByteOff :: forall b. Ptr b -> Int -> IO (Parameter a)
$cpokeByteOff :: forall a b. Storable a => Ptr b -> Int -> Parameter a -> IO ()
pokeByteOff :: forall b. Ptr b -> Int -> Parameter a -> IO ()
$cpeek :: forall a. Storable a => Ptr (Parameter a) -> IO (Parameter a)
peek :: Ptr (Parameter a) -> IO (Parameter a)
$cpoke :: forall a. Storable a => Ptr (Parameter a) -> Parameter a -> IO ()
poke :: Ptr (Parameter a) -> Parameter a -> IO ()
Storable)
instance Functor Parameter where
{-# INLINE fmap #-}
fmap :: forall a b. (a -> b) -> Parameter a -> Parameter b
fmap a -> b
f (Parameter a
k) = b -> Parameter b
forall a. a -> Parameter a
Parameter (a -> b
f a
k)
instance App.Applicative Parameter where
{-# INLINE pure #-}
pure :: forall a. a -> Parameter a
pure a
x = a -> Parameter a
forall a. a -> Parameter a
Parameter a
x
{-# INLINE (<*>) #-}
Parameter a -> b
f <*> :: forall a b. Parameter (a -> b) -> Parameter a -> Parameter b
<*> Parameter a
k = b -> Parameter b
forall a. a -> Parameter a
Parameter (a -> b
f a
k)
instance Fold.Foldable Parameter where
{-# INLINE foldMap #-}
foldMap :: forall m a. Monoid m => (a -> m) -> Parameter a -> m
foldMap = (a -> m) -> Parameter a -> m
forall (t :: * -> *) m a.
(Traversable t, Monoid m) =>
(a -> m) -> t a -> m
Trav.foldMapDefault
instance Trav.Traversable Parameter where
{-# INLINE sequenceA #-}
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Parameter (f a) -> f (Parameter a)
sequenceA (Parameter f a
k) = (a -> Parameter a) -> f a -> f (Parameter a)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Parameter a
forall a. a -> Parameter a
Parameter f a
k
instance (Tuple.Phi a) => Tuple.Phi (Parameter a) where
phi :: forall r.
BasicBlock -> Parameter a -> CodeGenFunction r (Parameter a)
phi = BasicBlock -> Parameter a -> CodeGenFunction r (Parameter a)
forall a (f :: * -> *) r.
(Phi a, Traversable f) =>
BasicBlock -> f a -> CodeGenFunction r (f a)
Tuple.phiTraversable
addPhi :: forall r.
BasicBlock -> Parameter a -> Parameter a -> CodeGenFunction r ()
addPhi = BasicBlock -> Parameter a -> Parameter a -> CodeGenFunction r ()
forall a (f :: * -> *) r.
(Phi a, Foldable f, Applicative f) =>
BasicBlock -> f a -> f a -> CodeGenFunction r ()
Tuple.addPhiFoldable
instance Tuple.Undefined a => Tuple.Undefined (Parameter a) where
undef :: Parameter a
undef = Parameter a
forall a (f :: * -> *). (Undefined a, Applicative f) => f a
Tuple.undefPointed
instance Tuple.Zero a => Tuple.Zero (Parameter a) where
zero :: Parameter a
zero = Parameter a
forall a (f :: * -> *). (Zero a, Applicative f) => f a
Tuple.zeroPointed
instance (Memory.C a) => Memory.C (Parameter a) where
type Struct (Parameter a) = Memory.Struct a
load :: forall r.
Value (Ptr (Struct (Parameter a)))
-> CodeGenFunction r (Parameter a)
load = (a -> Parameter a)
-> Value (Ptr (Struct a)) -> CodeGenFunction r (Parameter a)
forall a llvmValue r.
C a =>
(a -> llvmValue)
-> Value (Ptr (Struct a)) -> CodeGenFunction r llvmValue
Memory.loadNewtype a -> Parameter a
forall a. a -> Parameter a
Parameter
store :: forall r.
Parameter a
-> Value (Ptr (Struct (Parameter a))) -> CodeGenFunction r ()
store = (Parameter a -> a)
-> Parameter a -> Value (Ptr (Struct a)) -> CodeGenFunction r ()
forall a llvmValue r.
C a =>
(llvmValue -> a)
-> llvmValue -> Value (Ptr (Struct a)) -> CodeGenFunction r ()
Memory.storeNewtype (\(Parameter a
k) -> a
k)
decompose :: forall r.
Value (Struct (Parameter a)) -> CodeGenFunction r (Parameter a)
decompose = (a -> Parameter a)
-> Value (Struct a) -> CodeGenFunction r (Parameter a)
forall a llvmValue r.
C a =>
(a -> llvmValue) -> Value (Struct a) -> CodeGenFunction r llvmValue
Memory.decomposeNewtype a -> Parameter a
forall a. a -> Parameter a
Parameter
compose :: forall r.
Parameter a -> CodeGenFunction r (Value (Struct (Parameter a)))
compose = (Parameter a -> a)
-> Parameter a -> CodeGenFunction r (Value (Struct a))
forall a llvmValue r.
C a =>
(llvmValue -> a)
-> llvmValue -> CodeGenFunction r (Value (Struct a))
Memory.composeNewtype (\(Parameter a
k) -> a
k)
instance (Marshal.C a) => Marshal.C (Parameter a) where
pack :: Parameter a -> Struct (Parameter a)
pack (Parameter a
k) = a -> Struct a
forall a. C a => a -> Struct a
Marshal.pack a
k
unpack :: Struct (Parameter a) -> Parameter a
unpack = a -> Parameter a
forall a. a -> Parameter a
Parameter (a -> Parameter a) -> (Struct a -> a) -> Struct a -> Parameter a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Struct a -> a
forall a. C a => Struct a -> a
Marshal.unpack
instance (MarshalMV.C a) => MarshalMV.C (Parameter a) where
pack :: Parameter a -> Struct (Parameter a)
pack (Parameter a
k) = a -> Struct a
forall a. C a => a -> Struct a
MarshalMV.pack a
k
unpack :: Struct (Parameter a) -> Parameter a
unpack = a -> Parameter a
forall a. a -> Parameter a
Parameter (a -> Parameter a) -> (Struct a -> a) -> Struct a -> Parameter a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Struct a -> a
forall a. C a => Struct a -> a
MarshalMV.unpack
instance (Storable.C a) => Storable.C (Parameter a) where
load :: forall r.
Value (Ptr (Parameter a))
-> CodeGenFunction r (ValueOf (Parameter a))
load = (a -> Parameter a)
-> (ValueOf a -> Parameter (ValueOf a))
-> Value (Ptr (Parameter a))
-> CodeGenFunction r (Parameter (ValueOf a))
forall a al wrapped wrappedl r.
(C a, ValueOf a ~ al) =>
(a -> wrapped)
-> (al -> wrappedl)
-> Value (Ptr wrapped)
-> CodeGenFunction r wrappedl
Storable.loadNewtype a -> Parameter a
forall a. a -> Parameter a
Parameter ValueOf a -> Parameter (ValueOf a)
forall a. a -> Parameter a
Parameter
store :: forall r.
ValueOf (Parameter a)
-> Value (Ptr (Parameter a)) -> CodeGenFunction r ()
store = (a -> Parameter a)
-> (Parameter (ValueOf a) -> ValueOf a)
-> Parameter (ValueOf a)
-> Value (Ptr (Parameter a))
-> CodeGenFunction r ()
forall a al wrapped wrappedl r.
(C a, ValueOf a ~ al) =>
(a -> wrapped)
-> (wrappedl -> al)
-> wrappedl
-> Value (Ptr wrapped)
-> CodeGenFunction r ()
Storable.storeNewtype a -> Parameter a
forall a. a -> Parameter a
Parameter (\(Parameter ValueOf a
k) -> ValueOf a
k)
instance (Tuple.Value a) => Tuple.Value (Parameter a) where
type ValueOf (Parameter a) = Parameter (Tuple.ValueOf a)
valueOf :: Parameter a -> ValueOf (Parameter a)
valueOf = Parameter a -> ValueOf (Parameter a)
Parameter a -> Parameter (ValueOf a)
forall h (f :: * -> *).
(Value h, Functor f) =>
f h -> f (ValueOf h)
Tuple.valueOfFunctor
instance (MultiValue.C a) => MultiValue.C (Parameter a) where
type Repr (Parameter a) = Parameter (MultiValue.Repr a)
cons :: Parameter a -> T (Parameter a)
cons = Parameter (T a) -> T (Parameter a)
forall a. Parameter (T a) -> T (Parameter a)
multiValueParameter (Parameter (T a) -> T (Parameter a))
-> (Parameter a -> Parameter (T a))
-> Parameter a
-> T (Parameter a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> T a) -> Parameter a -> Parameter (T a)
forall a b. (a -> b) -> Parameter a -> Parameter b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> T a
forall a. C a => a -> T a
MultiValue.cons
undef :: T (Parameter a)
undef = Parameter (T a) -> T (Parameter a)
forall a. Parameter (T a) -> T (Parameter a)
multiValueParameter (Parameter (T a) -> T (Parameter a))
-> Parameter (T a) -> T (Parameter a)
forall a b. (a -> b) -> a -> b
$ T a -> Parameter (T a)
forall a. a -> Parameter a
forall (f :: * -> *) a. Applicative f => a -> f a
pure T a
forall a. C a => T a
MultiValue.undef
zero :: T (Parameter a)
zero = Parameter (T a) -> T (Parameter a)
forall a. Parameter (T a) -> T (Parameter a)
multiValueParameter (Parameter (T a) -> T (Parameter a))
-> Parameter (T a) -> T (Parameter a)
forall a b. (a -> b) -> a -> b
$ T a -> Parameter (T a)
forall a. a -> Parameter a
forall (f :: * -> *) a. Applicative f => a -> f a
pure T a
forall a. C a => T a
MultiValue.zero
phi :: forall r.
BasicBlock
-> T (Parameter a) -> CodeGenFunction r (T (Parameter a))
phi BasicBlock
bb =
(Parameter (T a) -> T (Parameter a))
-> CodeGenFunction r (Parameter (T a))
-> CodeGenFunction r (T (Parameter a))
forall a b. (a -> b) -> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Parameter (T a) -> T (Parameter a)
forall a. Parameter (T a) -> T (Parameter a)
multiValueParameter (CodeGenFunction r (Parameter (T a))
-> CodeGenFunction r (T (Parameter a)))
-> (T (Parameter a) -> CodeGenFunction r (Parameter (T a)))
-> T (Parameter a)
-> CodeGenFunction r (T (Parameter a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(T a -> CodeGenFunction r (T a))
-> Parameter (T a) -> CodeGenFunction r (Parameter (T a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Parameter a -> f (Parameter b)
traverse (BasicBlock -> T a -> CodeGenFunction r (T a)
forall a r. C a => BasicBlock -> T a -> CodeGenFunction r (T a)
forall r. BasicBlock -> T a -> CodeGenFunction r (T a)
MultiValue.phi BasicBlock
bb) (Parameter (T a) -> CodeGenFunction r (Parameter (T a)))
-> (T (Parameter a) -> Parameter (T a))
-> T (Parameter a)
-> CodeGenFunction r (Parameter (T a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T (Parameter a) -> Parameter (T a)
forall a. T (Parameter a) -> Parameter (T a)
unMultiValueParameter
addPhi :: forall r.
BasicBlock
-> T (Parameter a) -> T (Parameter a) -> CodeGenFunction r ()
addPhi BasicBlock
bb T (Parameter a)
a T (Parameter a)
b =
Parameter (CodeGenFunction r ()) -> CodeGenFunction r ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
Fold.sequence_ (Parameter (CodeGenFunction r ()) -> CodeGenFunction r ())
-> Parameter (CodeGenFunction r ()) -> CodeGenFunction r ()
forall a b. (a -> b) -> a -> b
$
(T a -> T a -> CodeGenFunction r ())
-> Parameter (T a)
-> Parameter (T a)
-> Parameter (CodeGenFunction r ())
forall a b c.
(a -> b -> c) -> Parameter a -> Parameter b -> Parameter c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (BasicBlock -> T a -> T a -> CodeGenFunction r ()
forall a r. C a => BasicBlock -> T a -> T a -> CodeGenFunction r ()
forall r. BasicBlock -> T a -> T a -> CodeGenFunction r ()
MultiValue.addPhi BasicBlock
bb)
(T (Parameter a) -> Parameter (T a)
forall a. T (Parameter a) -> Parameter (T a)
unMultiValueParameter T (Parameter a)
a) (T (Parameter a) -> Parameter (T a)
forall a. T (Parameter a) -> Parameter (T a)
unMultiValueParameter T (Parameter a)
b)
multiValueParameter ::
Parameter (MultiValue.T a) -> MultiValue.T (Parameter a)
multiValueParameter :: forall a. Parameter (T a) -> T (Parameter a)
multiValueParameter = Repr (Parameter a) -> T (Parameter a)
Parameter (Repr a) -> T (Parameter a)
forall a. Repr a -> T a
MultiValue.Cons (Parameter (Repr a) -> T (Parameter a))
-> (Parameter (T a) -> Parameter (Repr a))
-> Parameter (T a)
-> T (Parameter a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (T a -> Repr a) -> Parameter (T a) -> Parameter (Repr a)
forall a b. (a -> b) -> Parameter a -> Parameter b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(MultiValue.Cons Repr a
a) -> Repr a
a)
unMultiValueParameter ::
MultiValue.T (Parameter a) -> Parameter (MultiValue.T a)
unMultiValueParameter :: forall a. T (Parameter a) -> Parameter (T a)
unMultiValueParameter (MultiValue.Cons Repr (Parameter a)
x) = (Repr a -> T a) -> Parameter (Repr a) -> Parameter (T a)
forall a b. (a -> b) -> Parameter a -> Parameter b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Repr a -> T a
forall a. Repr a -> T a
MultiValue.Cons Repr (Parameter a)
Parameter (Repr a)
x
instance (Value.Flatten a) => Value.Flatten (Parameter a) where
type Registers (Parameter a) = Parameter (Value.Registers a)
flattenCode :: forall r. Parameter a -> Compute r (Registers (Parameter a))
flattenCode = Parameter a
-> StateT Vault (CodeGenFunction r) (Registers (Parameter a))
Parameter a -> Compute r (Parameter (Registers a))
forall value (f :: * -> *) r.
(Flatten value, Traversable f) =>
f value -> Compute r (f (Registers value))
Value.flattenCodeTraversable
unfoldCode :: T (Registers (Parameter a)) -> Parameter a
unfoldCode = T (Registers (Parameter a)) -> Parameter a
T (Parameter (Registers a)) -> Parameter a
forall value (f :: * -> *).
(Flatten value, Traversable f, Applicative f) =>
T (f (Registers value)) -> f value
Value.unfoldCodeTraversable
instance (Vector.Simple v) => Vector.Simple (Parameter v) where
type Element (Parameter v) = Parameter (Vector.Element v)
type Size (Parameter v) = Vector.Size v
shuffleMatch :: forall r.
ConstValue (Vector (Size (Parameter v)) Word32)
-> Parameter v -> CodeGenFunction r (Parameter v)
shuffleMatch = ConstValue (Vector (Size v) Word32)
-> Parameter v -> CodeGenFunction r (Parameter v)
ConstValue (Vector (Size (Parameter v)) Word32)
-> Parameter v -> CodeGenFunction r (Parameter v)
forall v (f :: * -> *) r.
(Simple v, Traversable f) =>
ConstValue (Vector (Size v) Word32)
-> f v -> CodeGenFunction r (f v)
Vector.shuffleMatchTraversable
extract :: forall r.
Value Word32
-> Parameter v -> CodeGenFunction r (Element (Parameter v))
extract = Value Word32
-> Parameter v -> CodeGenFunction r (Element (Parameter v))
Value Word32
-> Parameter v -> CodeGenFunction r (Parameter (Element v))
forall v (f :: * -> *) r.
(Simple v, Traversable f) =>
Value Word32 -> f v -> CodeGenFunction r (f (Element v))
Vector.extractTraversable
instance (Vector.C v) => Vector.C (Parameter v) where
insert :: forall r.
Value Word32
-> Element (Parameter v)
-> Parameter v
-> CodeGenFunction r (Parameter v)
insert = Value Word32
-> Element (Parameter v)
-> Parameter v
-> CodeGenFunction r (Parameter v)
Value Word32
-> Parameter (Element v)
-> Parameter v
-> CodeGenFunction r (Parameter v)
forall v (f :: * -> *) r.
(C v, Traversable f, Applicative f) =>
Value Word32 -> f (Element v) -> f v -> CodeGenFunction r (f v)
Vector.insertTraversable
instance
(Expr.Aggregate exp mv) =>
Expr.Aggregate (Parameter exp) (Parameter mv) where
type MultiValuesOf (Parameter exp) = Parameter (Expr.MultiValuesOf exp)
type ExpressionsOf (Parameter mv) = Parameter (Expr.ExpressionsOf mv)
bundle :: forall r. Parameter exp -> CodeGenFunction r (Parameter mv)
bundle (Parameter exp
p) = (mv -> Parameter mv)
-> CodeGenFunction r mv -> CodeGenFunction r (Parameter mv)
forall a b. (a -> b) -> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap mv -> Parameter mv
forall a. a -> Parameter a
Parameter (CodeGenFunction r mv -> CodeGenFunction r (Parameter mv))
-> CodeGenFunction r mv -> CodeGenFunction r (Parameter mv)
forall a b. (a -> b) -> a -> b
$ exp -> CodeGenFunction r mv
forall r. exp -> CodeGenFunction r mv
forall exp mv r. Aggregate exp mv => exp -> CodeGenFunction r mv
Expr.bundle exp
p
dissect :: Parameter mv -> Parameter exp
dissect (Parameter mv
p) = exp -> Parameter exp
forall a. a -> Parameter a
Parameter (exp -> Parameter exp) -> exp -> Parameter exp
forall a b. (a -> b) -> a -> b
$ mv -> exp
forall exp mv. Aggregate exp mv => mv -> exp
Expr.dissect mv
p
parameter ::
(Trans.C a, SoV.TranscendentalConstant a, IsFloating a) =>
Value a ->
CodeGenFunction r (Parameter (Value a))
parameter :: forall a r.
(C a, TranscendentalConstant a, IsFloating a) =>
Value a -> CodeGenFunction r (Parameter (Value a))
parameter = (T (Value a) -> Parameter (T (Value a)))
-> forall r.
Value a -> CodeGenFunction r (Registers (Parameter (T (Value a))))
forall value a.
Flatten value =>
(T a -> value)
-> forall r. a -> CodeGenFunction r (Registers value)
Value.unlift1 T (Value a) -> Parameter (T (Value a))
forall a. C a => a -> Parameter a
parameterPlain
parameterPlain ::
(Trans.C a) =>
a -> Parameter a
parameterPlain :: forall a. C a => a -> Parameter a
parameterPlain a
halfLife =
a -> Parameter a
forall a. a -> Parameter a
Parameter (a -> Parameter a) -> a -> Parameter a
forall a b. (a -> b) -> a -> b
$ a
0.5 a -> a -> a
forall a. C a => a -> a -> a
^? a -> a
forall a. C a => a -> a
recip a
halfLife
causal ::
(MarshalMV.C a, MultiValue.T a ~ am, MultiValue.PseudoRing a) =>
Exp a -> Causal.T (Parameter am) am
causal :: forall a am.
(C a, T a ~ am, PseudoRing a) =>
Exp a -> T (Parameter am) am
causal Exp a
initial =
Exp a -> T (Parameter am, am) (am, am) -> T (Parameter am) am
forall ce c a b.
(Aggregate ce c, C c) =>
ce -> T (a, c) (b, c) -> T a b
Causal.loop Exp a
initial
(((Parameter am, am) -> am) -> T (Parameter am, am) am
forall b c. (b -> c) -> T b c
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (Parameter am, am) -> am
forall a b. (a, b) -> b
snd T (Parameter am, am) am
-> T (Parameter am, am) am -> T (Parameter am, am) (am, am)
forall b c c'. T b c -> T b c' -> T b (c, c')
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& (forall r. Parameter am -> am -> CodeGenFunction r am)
-> T (Parameter am, am) am
forall a b c.
(forall r. a -> b -> CodeGenFunction r c) -> T (a, b) c
CausalPriv.zipWith (\(Parameter am
a) -> am -> am -> CodeGenFunction r am
forall r. am -> am -> CodeGenFunction r am
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul am
a))
data ParameterPacked a =
ParameterPacked {forall a. ParameterPacked a -> a
ppFeedback, forall a. ParameterPacked a -> a
ppCurrent :: a}
instance Functor ParameterPacked where
{-# INLINE fmap #-}
fmap :: forall a b. (a -> b) -> ParameterPacked a -> ParameterPacked b
fmap a -> b
f ParameterPacked a
p = b -> b -> ParameterPacked b
forall a. a -> a -> ParameterPacked a
ParameterPacked
(a -> b
f (a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ ParameterPacked a -> a
forall a. ParameterPacked a -> a
ppFeedback ParameterPacked a
p) (a -> b
f (a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ ParameterPacked a -> a
forall a. ParameterPacked a -> a
ppCurrent ParameterPacked a
p)
instance App.Applicative ParameterPacked where
{-# INLINE pure #-}
pure :: forall a. a -> ParameterPacked a
pure a
x = a -> a -> ParameterPacked a
forall a. a -> a -> ParameterPacked a
ParameterPacked a
x a
x
{-# INLINE (<*>) #-}
ParameterPacked (a -> b)
f <*> :: forall a b.
ParameterPacked (a -> b) -> ParameterPacked a -> ParameterPacked b
<*> ParameterPacked a
p = b -> b -> ParameterPacked b
forall a. a -> a -> ParameterPacked a
ParameterPacked
(ParameterPacked (a -> b) -> a -> b
forall a. ParameterPacked a -> a
ppFeedback ParameterPacked (a -> b)
f (a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ ParameterPacked a -> a
forall a. ParameterPacked a -> a
ppFeedback ParameterPacked a
p)
(ParameterPacked (a -> b) -> a -> b
forall a. ParameterPacked a -> a
ppCurrent ParameterPacked (a -> b)
f (a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ ParameterPacked a -> a
forall a. ParameterPacked a -> a
ppCurrent ParameterPacked a
p)
instance Fold.Foldable ParameterPacked where
{-# INLINE foldMap #-}
foldMap :: forall m a. Monoid m => (a -> m) -> ParameterPacked a -> m
foldMap = (a -> m) -> ParameterPacked a -> m
forall (t :: * -> *) m a.
(Traversable t, Monoid m) =>
(a -> m) -> t a -> m
Trav.foldMapDefault
instance Trav.Traversable ParameterPacked where
{-# INLINE sequenceA #-}
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
ParameterPacked (f a) -> f (ParameterPacked a)
sequenceA ParameterPacked (f a)
p =
(a -> a -> ParameterPacked a)
-> f a -> f a -> f (ParameterPacked a)
forall a b c. (a -> b -> c) -> f a -> f b -> f c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> ParameterPacked a
forall a. a -> a -> ParameterPacked a
ParameterPacked
(ParameterPacked (f a) -> f a
forall a. ParameterPacked a -> a
ppFeedback ParameterPacked (f a)
p) (ParameterPacked (f a) -> f a
forall a. ParameterPacked a -> a
ppCurrent ParameterPacked (f a)
p)
instance (Tuple.Phi a) => Tuple.Phi (ParameterPacked a) where
phi :: forall r.
BasicBlock
-> ParameterPacked a -> CodeGenFunction r (ParameterPacked a)
phi = BasicBlock
-> ParameterPacked a -> CodeGenFunction r (ParameterPacked a)
forall a (f :: * -> *) r.
(Phi a, Traversable f) =>
BasicBlock -> f a -> CodeGenFunction r (f a)
Tuple.phiTraversable
addPhi :: forall r.
BasicBlock
-> ParameterPacked a -> ParameterPacked a -> CodeGenFunction r ()
addPhi = BasicBlock
-> ParameterPacked a -> ParameterPacked a -> CodeGenFunction r ()
forall a (f :: * -> *) r.
(Phi a, Foldable f, Applicative f) =>
BasicBlock -> f a -> f a -> CodeGenFunction r ()
Tuple.addPhiFoldable
instance Tuple.Undefined a => Tuple.Undefined (ParameterPacked a) where
undef :: ParameterPacked a
undef = ParameterPacked a
forall a (f :: * -> *). (Undefined a, Applicative f) => f a
Tuple.undefPointed
instance Tuple.Zero a => Tuple.Zero (ParameterPacked a) where
zero :: ParameterPacked a
zero = ParameterPacked a
forall a (f :: * -> *). (Zero a, Applicative f) => f a
Tuple.zeroPointed
instance Storable a => Storable (ParameterPacked a) where
sizeOf :: ParameterPacked a -> Int
sizeOf = ParameterPacked a -> Int
forall (f :: * -> *) a. (Foldable f, Storable a) => f a -> Int
Store.sizeOf
alignment :: ParameterPacked a -> Int
alignment = ParameterPacked a -> Int
forall (f :: * -> *) a. (Foldable f, Storable a) => f a -> Int
Store.alignment
peek :: Ptr (ParameterPacked a) -> IO (ParameterPacked a)
peek = Ptr (ParameterPacked a) -> IO (ParameterPacked a)
forall (f :: * -> *) a.
(Applicative f, Traversable f, Storable a) =>
Ptr (f a) -> IO (f a)
Store.peekApplicative
poke :: Ptr (ParameterPacked a) -> ParameterPacked a -> IO ()
poke = Ptr (ParameterPacked a) -> ParameterPacked a -> IO ()
forall (f :: * -> *) a.
(Foldable f, Storable a) =>
Ptr (f a) -> f a -> IO ()
Store.poke
type ParameterPackedStruct a = LLVM.Struct (a, (a, ()))
memory ::
(Memory.C a) =>
Memory.Record r (ParameterPackedStruct (Memory.Struct a)) (ParameterPacked a)
memory :: forall a r.
C a =>
Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
memory =
(a -> a -> ParameterPacked a)
-> Element
r (ParameterPackedStruct (Struct a)) (ParameterPacked a) a
-> Element
r (ParameterPackedStruct (Struct a)) (ParameterPacked a) a
-> Element
r
(ParameterPackedStruct (Struct a))
(ParameterPacked a)
(ParameterPacked a)
forall a b c.
(a -> b -> c)
-> Element
r (ParameterPackedStruct (Struct a)) (ParameterPacked a) a
-> Element
r (ParameterPackedStruct (Struct a)) (ParameterPacked a) b
-> Element
r (ParameterPackedStruct (Struct a)) (ParameterPacked a) c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> ParameterPacked a
forall a. a -> a -> ParameterPacked a
ParameterPacked
((ParameterPacked a -> a)
-> Proxy D0
-> Element
r (ParameterPackedStruct (Struct a)) (ParameterPacked a) a
forall x o n v r.
(C x, GetValue o n, ValueType o n ~ Struct x,
GetElementPtr o (n, ()), ElementPtrType o (n, ()) ~ Struct x) =>
(v -> x) -> n -> Element r o v x
Memory.element ParameterPacked a -> a
forall a. ParameterPacked a -> a
ppFeedback Proxy D0
TypeNum.d0)
((ParameterPacked a -> a)
-> Proxy D1
-> Element
r (ParameterPackedStruct (Struct a)) (ParameterPacked a) a
forall x o n v r.
(C x, GetValue o n, ValueType o n ~ Struct x,
GetElementPtr o (n, ()), ElementPtrType o (n, ()) ~ Struct x) =>
(v -> x) -> n -> Element r o v x
Memory.element ParameterPacked a -> a
forall a. ParameterPacked a -> a
ppCurrent Proxy D1
TypeNum.d1)
instance (Memory.C a) => Memory.C (ParameterPacked a) where
type Struct (ParameterPacked a) = ParameterPackedStruct (Memory.Struct a)
load :: forall r.
Value (Ptr (Struct (ParameterPacked a)))
-> CodeGenFunction r (ParameterPacked a)
load = Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
-> Value (Ptr (ParameterPackedStruct (Struct a)))
-> CodeGenFunction r (ParameterPacked a)
forall r o llvmValue.
Record r o llvmValue
-> Value (Ptr o) -> CodeGenFunction r llvmValue
Memory.loadRecord Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
forall a r.
C a =>
Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
memory
store :: forall r.
ParameterPacked a
-> Value (Ptr (Struct (ParameterPacked a))) -> CodeGenFunction r ()
store = Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
-> ParameterPacked a
-> Value (Ptr (ParameterPackedStruct (Struct a)))
-> CodeGenFunction r ()
forall r o llvmValue.
Record r o llvmValue
-> llvmValue -> Value (Ptr o) -> CodeGenFunction r ()
Memory.storeRecord Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
forall a r.
C a =>
Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
memory
decompose :: forall r.
Value (Struct (ParameterPacked a))
-> CodeGenFunction r (ParameterPacked a)
decompose = Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
-> Value (ParameterPackedStruct (Struct a))
-> CodeGenFunction r (ParameterPacked a)
forall r o llvmValue.
Record r o llvmValue -> Value o -> CodeGenFunction r llvmValue
Memory.decomposeRecord Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
forall a r.
C a =>
Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
memory
compose :: forall r.
ParameterPacked a
-> CodeGenFunction r (Value (Struct (ParameterPacked a)))
compose = Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
-> ParameterPacked a
-> CodeGenFunction r (Value (ParameterPackedStruct (Struct a)))
forall o r llvmValue.
IsType o =>
Record r o llvmValue -> llvmValue -> CodeGenFunction r (Value o)
Memory.composeRecord Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
forall a r.
C a =>
Record r (ParameterPackedStruct (Struct a)) (ParameterPacked a)
memory
instance (Marshal.C a) => Marshal.C (ParameterPacked a) where
pack :: ParameterPacked a -> Struct (ParameterPacked a)
pack (ParameterPacked a
bend a
depth) = (a, a) -> Struct (a, a)
forall a. C a => a -> Struct a
Marshal.pack (a
bend, a
depth)
unpack :: Struct (ParameterPacked a) -> ParameterPacked a
unpack = (a -> a -> ParameterPacked a) -> (a, a) -> ParameterPacked a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> a -> ParameterPacked a
forall a. a -> a -> ParameterPacked a
ParameterPacked ((a, a) -> ParameterPacked a)
-> (ParameterPackedStruct (Struct a) -> (a, a))
-> ParameterPackedStruct (Struct a)
-> ParameterPacked a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Struct (a, a) -> (a, a)
ParameterPackedStruct (Struct a) -> (a, a)
forall a. C a => Struct a -> a
Marshal.unpack
instance (MarshalMV.C a) => MarshalMV.C (ParameterPacked a) where
pack :: ParameterPacked a -> Struct (ParameterPacked a)
pack (ParameterPacked a
bend a
depth) = (a, a) -> Struct (a, a)
forall a. C a => a -> Struct a
MarshalMV.pack (a
bend, a
depth)
unpack :: Struct (ParameterPacked a) -> ParameterPacked a
unpack = (a -> a -> ParameterPacked a) -> (a, a) -> ParameterPacked a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> a -> ParameterPacked a
forall a. a -> a -> ParameterPacked a
ParameterPacked ((a, a) -> ParameterPacked a)
-> (ParameterPackedStruct (Struct (Repr a)) -> (a, a))
-> ParameterPackedStruct (Struct (Repr a))
-> ParameterPacked a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Struct (a, a) -> (a, a)
ParameterPackedStruct (Struct (Repr a)) -> (a, a)
forall a. C a => Struct a -> a
MarshalMV.unpack
instance (Storable.C a) => Storable.C (ParameterPacked a) where
load :: forall r.
Value (Ptr (ParameterPacked a))
-> CodeGenFunction r (ValueOf (ParameterPacked a))
load = Value (Ptr (ParameterPacked a))
-> CodeGenFunction r (ValueOf (ParameterPacked a))
Value (Ptr (ParameterPacked a))
-> CodeGenFunction r (ParameterPacked (ValueOf a))
forall (f :: * -> *) a al r.
(Applicative f, Traversable f, C a, ValueOf a ~ al) =>
Value (Ptr (f a)) -> CodeGenFunction r (f al)
Storable.loadApplicative
store :: forall r.
ValueOf (ParameterPacked a)
-> Value (Ptr (ParameterPacked a)) -> CodeGenFunction r ()
store = ValueOf (ParameterPacked a)
-> Value (Ptr (ParameterPacked a)) -> CodeGenFunction r ()
ParameterPacked (ValueOf a)
-> Value (Ptr (ParameterPacked a)) -> CodeGenFunction r ()
forall (f :: * -> *) a al r.
(Foldable f, C a, ValueOf a ~ al) =>
f al -> Value (Ptr (f a)) -> CodeGenFunction r ()
Storable.storeFoldable
instance (Tuple.Value a) => Tuple.Value (ParameterPacked a) where
type ValueOf (ParameterPacked a) = ParameterPacked (Tuple.ValueOf a)
valueOf :: ParameterPacked a -> ValueOf (ParameterPacked a)
valueOf = ParameterPacked a -> ValueOf (ParameterPacked a)
ParameterPacked a -> ParameterPacked (ValueOf a)
forall h (f :: * -> *).
(Value h, Functor f) =>
f h -> f (ValueOf h)
Tuple.valueOfFunctor
instance (MultiValue.C a) => MultiValue.C (ParameterPacked a) where
type Repr (ParameterPacked a) = ParameterPacked (MultiValue.Repr a)
cons :: ParameterPacked a -> T (ParameterPacked a)
cons = ParameterPacked (T a) -> T (ParameterPacked a)
forall a. ParameterPacked (T a) -> T (ParameterPacked a)
multiValueParameterPacked (ParameterPacked (T a) -> T (ParameterPacked a))
-> (ParameterPacked a -> ParameterPacked (T a))
-> ParameterPacked a
-> T (ParameterPacked a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> T a) -> ParameterPacked a -> ParameterPacked (T a)
forall a b. (a -> b) -> ParameterPacked a -> ParameterPacked b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> T a
forall a. C a => a -> T a
MultiValue.cons
undef :: T (ParameterPacked a)
undef = ParameterPacked (T a) -> T (ParameterPacked a)
forall a. ParameterPacked (T a) -> T (ParameterPacked a)
multiValueParameterPacked (ParameterPacked (T a) -> T (ParameterPacked a))
-> ParameterPacked (T a) -> T (ParameterPacked a)
forall a b. (a -> b) -> a -> b
$ T a -> ParameterPacked (T a)
forall a. a -> ParameterPacked a
forall (f :: * -> *) a. Applicative f => a -> f a
pure T a
forall a. C a => T a
MultiValue.undef
zero :: T (ParameterPacked a)
zero = ParameterPacked (T a) -> T (ParameterPacked a)
forall a. ParameterPacked (T a) -> T (ParameterPacked a)
multiValueParameterPacked (ParameterPacked (T a) -> T (ParameterPacked a))
-> ParameterPacked (T a) -> T (ParameterPacked a)
forall a b. (a -> b) -> a -> b
$ T a -> ParameterPacked (T a)
forall a. a -> ParameterPacked a
forall (f :: * -> *) a. Applicative f => a -> f a
pure T a
forall a. C a => T a
MultiValue.zero
phi :: forall r.
BasicBlock
-> T (ParameterPacked a)
-> CodeGenFunction r (T (ParameterPacked a))
phi BasicBlock
bb =
(ParameterPacked (T a) -> T (ParameterPacked a))
-> CodeGenFunction r (ParameterPacked (T a))
-> CodeGenFunction r (T (ParameterPacked a))
forall a b. (a -> b) -> CodeGenFunction r a -> CodeGenFunction r b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ParameterPacked (T a) -> T (ParameterPacked a)
forall a. ParameterPacked (T a) -> T (ParameterPacked a)
multiValueParameterPacked (CodeGenFunction r (ParameterPacked (T a))
-> CodeGenFunction r (T (ParameterPacked a)))
-> (T (ParameterPacked a)
-> CodeGenFunction r (ParameterPacked (T a)))
-> T (ParameterPacked a)
-> CodeGenFunction r (T (ParameterPacked a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(T a -> CodeGenFunction r (T a))
-> ParameterPacked (T a)
-> CodeGenFunction r (ParameterPacked (T a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ParameterPacked a -> f (ParameterPacked b)
traverse (BasicBlock -> T a -> CodeGenFunction r (T a)
forall a r. C a => BasicBlock -> T a -> CodeGenFunction r (T a)
forall r. BasicBlock -> T a -> CodeGenFunction r (T a)
MultiValue.phi BasicBlock
bb) (ParameterPacked (T a)
-> CodeGenFunction r (ParameterPacked (T a)))
-> (T (ParameterPacked a) -> ParameterPacked (T a))
-> T (ParameterPacked a)
-> CodeGenFunction r (ParameterPacked (T a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T (ParameterPacked a) -> ParameterPacked (T a)
forall a. T (ParameterPacked a) -> ParameterPacked (T a)
unMultiValueParameterPacked
addPhi :: forall r.
BasicBlock
-> T (ParameterPacked a)
-> T (ParameterPacked a)
-> CodeGenFunction r ()
addPhi BasicBlock
bb T (ParameterPacked a)
a T (ParameterPacked a)
b =
ParameterPacked (CodeGenFunction r ()) -> CodeGenFunction r ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
Fold.sequence_ (ParameterPacked (CodeGenFunction r ()) -> CodeGenFunction r ())
-> ParameterPacked (CodeGenFunction r ()) -> CodeGenFunction r ()
forall a b. (a -> b) -> a -> b
$
(T a -> T a -> CodeGenFunction r ())
-> ParameterPacked (T a)
-> ParameterPacked (T a)
-> ParameterPacked (CodeGenFunction r ())
forall a b c.
(a -> b -> c)
-> ParameterPacked a -> ParameterPacked b -> ParameterPacked c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (BasicBlock -> T a -> T a -> CodeGenFunction r ()
forall a r. C a => BasicBlock -> T a -> T a -> CodeGenFunction r ()
forall r. BasicBlock -> T a -> T a -> CodeGenFunction r ()
MultiValue.addPhi BasicBlock
bb)
(T (ParameterPacked a) -> ParameterPacked (T a)
forall a. T (ParameterPacked a) -> ParameterPacked (T a)
unMultiValueParameterPacked T (ParameterPacked a)
a) (T (ParameterPacked a) -> ParameterPacked (T a)
forall a. T (ParameterPacked a) -> ParameterPacked (T a)
unMultiValueParameterPacked T (ParameterPacked a)
b)
multiValueParameterPacked ::
ParameterPacked (MultiValue.T a) -> MultiValue.T (ParameterPacked a)
multiValueParameterPacked :: forall a. ParameterPacked (T a) -> T (ParameterPacked a)
multiValueParameterPacked = Repr (ParameterPacked a) -> T (ParameterPacked a)
ParameterPacked (Repr a) -> T (ParameterPacked a)
forall a. Repr a -> T a
MultiValue.Cons (ParameterPacked (Repr a) -> T (ParameterPacked a))
-> (ParameterPacked (T a) -> ParameterPacked (Repr a))
-> ParameterPacked (T a)
-> T (ParameterPacked a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (T a -> Repr a)
-> ParameterPacked (T a) -> ParameterPacked (Repr a)
forall a b. (a -> b) -> ParameterPacked a -> ParameterPacked b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(MultiValue.Cons Repr a
a) -> Repr a
a)
unMultiValueParameterPacked ::
MultiValue.T (ParameterPacked a) -> ParameterPacked (MultiValue.T a)
unMultiValueParameterPacked :: forall a. T (ParameterPacked a) -> ParameterPacked (T a)
unMultiValueParameterPacked (MultiValue.Cons Repr (ParameterPacked a)
x) = (Repr a -> T a)
-> ParameterPacked (Repr a) -> ParameterPacked (T a)
forall a b. (a -> b) -> ParameterPacked a -> ParameterPacked b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Repr a -> T a
forall a. Repr a -> T a
MultiValue.Cons Repr (ParameterPacked a)
ParameterPacked (Repr a)
x
instance (Value.Flatten a) => Value.Flatten (ParameterPacked a) where
type Registers (ParameterPacked a) = ParameterPacked (Value.Registers a)
flattenCode :: forall r.
ParameterPacked a -> Compute r (Registers (ParameterPacked a))
flattenCode = ParameterPacked a
-> StateT Vault (CodeGenFunction r) (Registers (ParameterPacked a))
ParameterPacked a -> Compute r (ParameterPacked (Registers a))
forall value (f :: * -> *) r.
(Flatten value, Traversable f) =>
f value -> Compute r (f (Registers value))
Value.flattenCodeTraversable
unfoldCode :: T (Registers (ParameterPacked a)) -> ParameterPacked a
unfoldCode = T (Registers (ParameterPacked a)) -> ParameterPacked a
T (ParameterPacked (Registers a)) -> ParameterPacked a
forall value (f :: * -> *).
(Flatten value, Traversable f, Applicative f) =>
T (f (Registers value)) -> f value
Value.unfoldCodeTraversable
instance
(Expr.Aggregate exp mv) =>
Expr.Aggregate (ParameterPacked exp) (ParameterPacked mv) where
type MultiValuesOf (ParameterPacked exp) =
ParameterPacked (Expr.MultiValuesOf exp)
type ExpressionsOf (ParameterPacked mv) =
ParameterPacked (Expr.ExpressionsOf mv)
bundle :: forall r.
ParameterPacked exp -> CodeGenFunction r (ParameterPacked mv)
bundle ParameterPacked exp
p =
(mv -> mv -> ParameterPacked mv)
-> CodeGenFunction r mv
-> CodeGenFunction r mv
-> CodeGenFunction r (ParameterPacked mv)
forall a b c.
(a -> b -> c)
-> CodeGenFunction r a
-> CodeGenFunction r b
-> CodeGenFunction r c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 mv -> mv -> ParameterPacked mv
forall a. a -> a -> ParameterPacked a
ParameterPacked
(exp -> CodeGenFunction r mv
forall r. exp -> CodeGenFunction r mv
forall exp mv r. Aggregate exp mv => exp -> CodeGenFunction r mv
Expr.bundle (exp -> CodeGenFunction r mv) -> exp -> CodeGenFunction r mv
forall a b. (a -> b) -> a -> b
$ ParameterPacked exp -> exp
forall a. ParameterPacked a -> a
ppFeedback ParameterPacked exp
p) (exp -> CodeGenFunction r mv
forall r. exp -> CodeGenFunction r mv
forall exp mv r. Aggregate exp mv => exp -> CodeGenFunction r mv
Expr.bundle (exp -> CodeGenFunction r mv) -> exp -> CodeGenFunction r mv
forall a b. (a -> b) -> a -> b
$ ParameterPacked exp -> exp
forall a. ParameterPacked a -> a
ppCurrent ParameterPacked exp
p)
dissect :: ParameterPacked mv -> ParameterPacked exp
dissect ParameterPacked mv
p =
exp -> exp -> ParameterPacked exp
forall a. a -> a -> ParameterPacked a
ParameterPacked
(mv -> exp
forall exp mv. Aggregate exp mv => mv -> exp
Expr.dissect (mv -> exp) -> mv -> exp
forall a b. (a -> b) -> a -> b
$ ParameterPacked mv -> mv
forall a. ParameterPacked a -> a
ppFeedback ParameterPacked mv
p) (mv -> exp
forall exp mv. Aggregate exp mv => mv -> exp
Expr.dissect (mv -> exp) -> mv -> exp
forall a b. (a -> b) -> a -> b
$ ParameterPacked mv -> mv
forall a. ParameterPacked a -> a
ppCurrent ParameterPacked mv
p)
type instance F.Arguments f (ParameterPacked a) = f (ParameterPacked a)
instance F.MakeArguments (ParameterPacked a) where
makeArgs :: forall (f :: * -> *).
Functor f =>
f (ParameterPacked a) -> Arguments f (ParameterPacked a)
makeArgs = f (ParameterPacked a) -> f (ParameterPacked a)
f (ParameterPacked a) -> Arguments f (ParameterPacked a)
forall a. a -> a
id
withSize ::
(TypeNum.Natural n) =>
(SerialOld.Write v, SerialOld.Size v ~ n, TypeNum.Positive n) =>
(TypeNum.Singleton n -> m (param v)) ->
m (param v)
withSize :: forall n v (m :: * -> *) (param :: * -> *).
(Natural n, Write v, Size v ~ n, Positive n) =>
(Singleton n -> m (param v)) -> m (param v)
withSize Singleton n -> m (param v)
f = Singleton n -> m (param v)
f Singleton n
forall x. Integer x => Singleton x
TypeNum.singleton
parameterPacked ::
(SerialOld.Write v, SerialOld.Element v ~ a,
A.PseudoRing v, A.RationalConstant v,
A.Transcendental a, A.RationalConstant a) =>
a -> CodeGenFunction r (ParameterPacked v)
parameterPacked :: forall v a r.
(Write v, Element v ~ a, PseudoRing v, RationalConstant v,
Transcendental a, RationalConstant a) =>
a -> CodeGenFunction r (ParameterPacked v)
parameterPacked a
halfLife = (Singleton (Size v) -> CodeGenFunction r (ParameterPacked v))
-> CodeGenFunction r (ParameterPacked v)
forall n v (m :: * -> *) (param :: * -> *).
(Natural n, Write v, Size v ~ n, Positive n) =>
(Singleton n -> m (param v)) -> m (param v)
withSize ((Singleton (Size v) -> CodeGenFunction r (ParameterPacked v))
-> CodeGenFunction r (ParameterPacked v))
-> (Singleton (Size v) -> CodeGenFunction r (ParameterPacked v))
-> CodeGenFunction r (ParameterPacked v)
forall a b. (a -> b) -> a -> b
$ \Singleton (Size v)
n -> do
v
feedback <-
a -> CodeGenFunction r v
Element v -> CodeGenFunction r v
forall v r. Write v => Element v -> CodeGenFunction r v
SerialOld.upsample (a -> CodeGenFunction r v)
-> CodeGenFunction r a -> CodeGenFunction r v
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. Transcendental a => a -> a -> CodeGenFunction r a
A.pow (Rational -> a
forall a. RationalConstant a => Rational -> a
A.fromRational' Rational
0.5) (a -> CodeGenFunction r a)
-> CodeGenFunction r a -> CodeGenFunction r a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. Field a => a -> a -> CodeGenFunction r a
A.fdiv (Integer -> a
forall a. IntegerConstant a => Integer -> a
A.fromInteger' (Integer -> a) -> Integer -> a
forall a b. (a -> b) -> a -> b
$ Singleton (Size v) -> Integer
forall n a. (Integer n, Num a) => Singleton n -> a
TypeNum.integralFromSingleton Singleton (Size v)
n) a
halfLife
a
k <-
a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. Transcendental a => a -> a -> CodeGenFunction r a
A.pow (Rational -> a
forall a. RationalConstant a => Rational -> a
A.fromRational' Rational
0.5) (a -> CodeGenFunction r a)
-> CodeGenFunction r a -> CodeGenFunction r a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. Field a => a -> a -> CodeGenFunction r a
A.fdiv (Integer -> a
forall a. IntegerConstant a => Integer -> a
A.fromInteger' Integer
1) a
halfLife
v
current <-
(Element v -> CodeGenFunction r (Element v))
-> Element v -> CodeGenFunction r v
forall v r.
Write v =>
(Element v -> CodeGenFunction r (Element v))
-> Element v -> CodeGenFunction r v
SerialOld.iterate (a -> a -> CodeGenFunction r a
forall r. a -> a -> CodeGenFunction r a
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
A.mul a
k) (Integer -> a
forall a. IntegerConstant a => Integer -> a
A.fromInteger' Integer
1)
ParameterPacked v -> CodeGenFunction r (ParameterPacked v)
forall a. a -> CodeGenFunction r a
forall (m :: * -> *) a. Monad m => a -> m a
return (ParameterPacked v -> CodeGenFunction r (ParameterPacked v))
-> ParameterPacked v -> CodeGenFunction r (ParameterPacked v)
forall a b. (a -> b) -> a -> b
$ v -> v -> ParameterPacked v
forall a. a -> a -> ParameterPacked a
ParameterPacked v
feedback v
current
withSizePlain ::
(TypeNum.Positive n) =>
(TypeNum.Singleton n -> param (Serial.T n a)) ->
param (Serial.T n a)
withSizePlain :: forall n (param :: * -> *) a.
Positive n =>
(Singleton n -> param (T n a)) -> param (T n a)
withSizePlain Singleton n -> param (T n a)
f = Singleton n -> param (T n a)
f Singleton n
forall x. Integer x => Singleton x
TypeNum.singleton
parameterPackedPlain ::
(TypeNum.Positive n, Trans.C a) =>
a -> ParameterPacked (Serial.T n a)
parameterPackedPlain :: forall n a. (Positive n, C a) => a -> ParameterPacked (T n a)
parameterPackedPlain a
halfLife =
(Singleton n -> ParameterPacked (T n a)) -> ParameterPacked (T n a)
forall n (param :: * -> *) a.
Positive n =>
(Singleton n -> param (T n a)) -> param (T n a)
withSizePlain ((Singleton n -> ParameterPacked (T n a))
-> ParameterPacked (T n a))
-> (Singleton n -> ParameterPacked (T n a))
-> ParameterPacked (T n a)
forall a b. (a -> b) -> a -> b
$ \Singleton n
n ->
T n a -> T n a -> ParameterPacked (T n a)
forall a. a -> a -> ParameterPacked a
ParameterPacked
(a -> T n a
forall n a. Positive n => a -> T n a
SerialPlain.replicate
(a
0.5 a -> a -> a
forall a. C a => a -> a -> a
^? (Integer -> a
forall a. C a => Integer -> a
fromInteger (Singleton n -> Integer
forall n. Integer n => Singleton n -> Integer
TypeNum.integerFromSingleton Singleton n
n) a -> a -> a
forall a. C a => a -> a -> a
/ a
halfLife)))
((a -> a) -> a -> T n a
forall n a. Positive n => (a -> a) -> a -> T n a
SerialPlain.iterate (a
0.5 a -> a -> a
forall a. C a => a -> a -> a
^? a -> a
forall a. C a => a -> a
recip a
halfLife a -> a -> a
forall a. C a => a -> a -> a
*) a
forall a. C a => a
one)
withSizeExp ::
(TypeNum.Positive n) =>
(TypeNum.Singleton n -> param (exp (Serial.T n a))) ->
param (exp (Serial.T n a))
withSizeExp :: forall n (param :: * -> *) (exp :: * -> *) a.
Positive n =>
(Singleton n -> param (exp (T n a))) -> param (exp (T n a))
withSizeExp Singleton n -> param (exp (T n a))
f = Singleton n -> param (exp (T n a))
f Singleton n
forall x. Integer x => Singleton x
TypeNum.singleton
parameterPackedExp ::
(TypeNum.Positive n) =>
(MultiValue.Transcendental a, MultiValue.RationalConstant a) =>
(MultiVector.C a) =>
Exp a -> ParameterPacked (Exp (Serial.T n a))
parameterPackedExp :: forall n a.
(Positive n, Transcendental a, RationalConstant a, C a) =>
Exp a -> ParameterPacked (Exp (T n a))
parameterPackedExp Exp a
halfLife =
(Singleton n -> ParameterPacked (Exp (T n a)))
-> ParameterPacked (Exp (T n a))
forall n (param :: * -> *) (exp :: * -> *) a.
Positive n =>
(Singleton n -> param (exp (T n a))) -> param (exp (T n a))
withSizeExp ((Singleton n -> ParameterPacked (Exp (T n a)))
-> ParameterPacked (Exp (T n a)))
-> (Singleton n -> ParameterPacked (Exp (T n a)))
-> ParameterPacked (Exp (T n a))
forall a b. (a -> b) -> a -> b
$ \Singleton n
n ->
Exp (T n a) -> Exp (T n a) -> ParameterPacked (Exp (T n a))
forall a. a -> a -> ParameterPacked a
ParameterPacked
(Exp a -> Exp (T n a)
forall n a. (Positive n, C a) => Exp a -> Exp (T n a)
Serial.upsample
(Exp a
0.5 Exp a -> Exp a -> Exp a
forall a. C a => a -> a -> a
^? (Integer -> Exp a
forall a. C a => Integer -> a
fromInteger (Singleton n -> Integer
forall n. Integer n => Singleton n -> Integer
TypeNum.integerFromSingleton Singleton n
n) Exp a -> Exp a -> Exp a
forall a. C a => a -> a -> a
/ Exp a
halfLife)))
((Exp a -> Exp a) -> Exp a -> Exp (T n a)
forall n a.
(Positive n, C a) =>
(Exp a -> Exp a) -> Exp a -> Exp (T n a)
Serial.iterate (Exp a
0.5 Exp a -> Exp a -> Exp a
forall a. C a => a -> a -> a
^? Exp a -> Exp a
forall a. C a => a -> a
recip Exp a
halfLife Exp a -> Exp a -> Exp a
forall a. C a => a -> a -> a
*) Exp a
forall a. C a => a
one)
causalPacked ::
(MultiVector.PseudoRing a, MultiValue.IntegerConstant a,
TypeNum.Positive n, MarshalMV.Vector n a, MarshalMV.C a) =>
Exp a ->
Causal.T (ParameterPacked (SerialCode.Value n a)) (SerialCode.Value n a)
causalPacked :: forall a n.
(PseudoRing a, IntegerConstant a, Positive n, Vector n a, C a) =>
Exp a -> T (ParameterPacked (Value n a)) (Value n a)
causalPacked Exp a
initial =
Exp (T n a)
-> T (ParameterPacked (Value n a), Value n a)
(Value n a, Value n a)
-> T (ParameterPacked (Value n a)) (Value n a)
forall ce c a b.
(Aggregate ce c, C c) =>
ce -> T (a, c) (b, c) -> T a b
Causal.loop
(Exp a -> Exp (T n a)
forall n a. (Positive n, C a) => Exp a -> Exp (T n a)
Serial.upsample Exp a
initial)
((forall r.
(ParameterPacked (Value n a), Value n a)
-> CodeGenFunction r (Value n a, Value n a))
-> T (ParameterPacked (Value n a), Value n a)
(Value n a, Value n a)
forall a b. (forall r. a -> CodeGenFunction r b) -> T a b
CausalPriv.map ((forall r.
(ParameterPacked (Value n a), Value n a)
-> CodeGenFunction r (Value n a, Value n a))
-> T (ParameterPacked (Value n a), Value n a)
(Value n a, Value n a))
-> (forall r.
(ParameterPacked (Value n a), Value n a)
-> CodeGenFunction r (Value n a, Value n a))
-> T (ParameterPacked (Value n a), Value n a)
(Value n a, Value n a)
forall a b. (a -> b) -> a -> b
$
\(ParameterPacked (Value n a)
p, Value n a
s0) -> (Value n a -> Value n a -> (Value n a, Value n a))
-> CodeGenFunction r (Value n a)
-> CodeGenFunction r (Value n a)
-> CodeGenFunction r (Value n a, Value n a)
forall a b c.
(a -> b -> c)
-> CodeGenFunction r a
-> CodeGenFunction r b
-> CodeGenFunction r c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,)
(Value n a -> Value n a -> CodeGenFunction r (Value n a)
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
forall r. Value n a -> Value n a -> CodeGenFunction r (Value n a)
A.mul (ParameterPacked (Value n a) -> Value n a
forall a. ParameterPacked a -> a
ppCurrent ParameterPacked (Value n a)
p) Value n a
s0)
(Value n a -> Value n a -> CodeGenFunction r (Value n a)
forall a r. PseudoRing a => a -> a -> CodeGenFunction r a
forall r. Value n a -> Value n a -> CodeGenFunction r (Value n a)
A.mul (ParameterPacked (Value n a) -> Value n a
forall a. ParameterPacked a -> a
ppFeedback ParameterPacked (Value n a)
p) Value n a
s0))