{-# LANGUAGE FlexibleContexts #-}
module Prelude.Backprop (
sum
, product
, length
, minimum
, maximum
, traverse
, toList
, mapAccumL
, mapAccumR
, foldr, foldl'
, fmap, fmapConst
, (<$>), (<$), ($>)
, pure
, liftA2
, liftA3
, fromIntegral
, realToFrac
, round
, fromIntegral'
, E.coerce
) where
import Numeric.Backprop
import Prelude (Num(..), Fractional(..), Ord(..), Functor, Foldable, Traversable, Applicative)
import qualified Numeric.Backprop.Explicit as E
import qualified Prelude as P
import qualified Prelude.Backprop.Explicit as E
sum :: (Foldable t, Functor t, Backprop (t a), Num a, Reifies s W)
=> BVar s (t a)
-> BVar s a
sum :: forall (t :: * -> *) a s.
(Foldable t, Functor t, Backprop (t a), Num a, Reifies s W) =>
BVar s (t a) -> BVar s a
sum = forall (t :: * -> *) a s.
(Foldable t, Functor t, Num a, Reifies s W) =>
AddFunc (t a) -> BVar s (t a) -> BVar s a
E.sum forall a. Backprop a => AddFunc a
E.addFunc
{-# INLINE sum #-}
pure
:: (Foldable t, Applicative t, Backprop a, Reifies s W)
=> BVar s a
-> BVar s (t a)
pure :: forall (t :: * -> *) a s.
(Foldable t, Applicative t, Backprop a, Reifies s W) =>
BVar s a -> BVar s (t a)
pure = forall (t :: * -> *) s a.
(Foldable t, Applicative t, Reifies s W) =>
AddFunc a -> ZeroFunc a -> BVar s a -> BVar s (t a)
E.pure forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE pure #-}
product
:: (Foldable t, Functor t, Backprop (t a), Fractional a, Reifies s W)
=> BVar s (t a)
-> BVar s a
product :: forall (t :: * -> *) a s.
(Foldable t, Functor t, Backprop (t a), Fractional a,
Reifies s W) =>
BVar s (t a) -> BVar s a
product = forall (t :: * -> *) a s.
(Foldable t, Functor t, Fractional a, Reifies s W) =>
AddFunc (t a) -> BVar s (t a) -> BVar s a
E.product forall a. Backprop a => AddFunc a
E.addFunc
{-# INLINE product #-}
length
:: (Foldable t, Backprop (t a), Num b, Reifies s W)
=> BVar s (t a)
-> BVar s b
length :: forall (t :: * -> *) a b s.
(Foldable t, Backprop (t a), Num b, Reifies s W) =>
BVar s (t a) -> BVar s b
length = forall (t :: * -> *) b s a.
(Foldable t, Num b, Reifies s W) =>
AddFunc (t a) -> ZeroFunc (t a) -> BVar s (t a) -> BVar s b
E.length forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE length #-}
minimum
:: (Foldable t, Functor t, Backprop a, Ord a, Backprop (t a), Reifies s W)
=> BVar s (t a)
-> BVar s a
minimum :: forall (t :: * -> *) a s.
(Foldable t, Functor t, Backprop a, Ord a, Backprop (t a),
Reifies s W) =>
BVar s (t a) -> BVar s a
minimum = forall (t :: * -> *) a s.
(Foldable t, Functor t, Ord a, Reifies s W) =>
AddFunc (t a) -> ZeroFunc a -> BVar s (t a) -> BVar s a
E.minimum forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE minimum #-}
maximum
:: (Foldable t, Functor t, Backprop a, Ord a, Backprop (t a), Reifies s W)
=> BVar s (t a)
-> BVar s a
maximum :: forall (t :: * -> *) a s.
(Foldable t, Functor t, Backprop a, Ord a, Backprop (t a),
Reifies s W) =>
BVar s (t a) -> BVar s a
maximum = forall (t :: * -> *) a s.
(Foldable t, Functor t, Ord a, Reifies s W) =>
AddFunc (t a) -> ZeroFunc a -> BVar s (t a) -> BVar s a
E.maximum forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE maximum #-}
foldr
:: (Traversable t, Backprop a, Reifies s W)
=> (BVar s a -> BVar s b -> BVar s b)
-> BVar s b
-> BVar s (t a)
-> BVar s b
foldr :: forall (t :: * -> *) a s b.
(Traversable t, Backprop a, Reifies s W) =>
(BVar s a -> BVar s b -> BVar s b)
-> BVar s b -> BVar s (t a) -> BVar s b
foldr = forall (t :: * -> *) s a b.
(Traversable t, Reifies s W) =>
AddFunc a
-> ZeroFunc a
-> (BVar s a -> BVar s b -> BVar s b)
-> BVar s b
-> BVar s (t a)
-> BVar s b
E.foldr forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE foldr #-}
foldl'
:: (Traversable t, Backprop a, Reifies s W)
=> (BVar s b -> BVar s a -> BVar s b)
-> BVar s b
-> BVar s (t a)
-> BVar s b
foldl' :: forall (t :: * -> *) a s b.
(Traversable t, Backprop a, Reifies s W) =>
(BVar s b -> BVar s a -> BVar s b)
-> BVar s b -> BVar s (t a) -> BVar s b
foldl' = forall (t :: * -> *) s a b.
(Traversable t, Reifies s W) =>
AddFunc a
-> ZeroFunc a
-> (BVar s b -> BVar s a -> BVar s b)
-> BVar s b
-> BVar s (t a)
-> BVar s b
E.foldl' forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE foldl' #-}
fmap
:: (Traversable f, Backprop a, Backprop b, Reifies s W)
=> (BVar s a -> BVar s b)
-> BVar s (f a)
-> BVar s (f b)
fmap :: forall (f :: * -> *) a b s.
(Traversable f, Backprop a, Backprop b, Reifies s W) =>
(BVar s a -> BVar s b) -> BVar s (f a) -> BVar s (f b)
fmap = forall (f :: * -> *) s a b.
(Traversable f, Reifies s W) =>
AddFunc a
-> AddFunc b
-> ZeroFunc a
-> ZeroFunc b
-> (BVar s a -> BVar s b)
-> BVar s (f a)
-> BVar s (f b)
E.fmap forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE fmap #-}
fmapConst
:: (Functor f, Foldable f, Backprop b, Backprop (f a), Reifies s W)
=> BVar s b
-> BVar s (f a)
-> BVar s (f b)
fmapConst :: forall (f :: * -> *) b a s.
(Functor f, Foldable f, Backprop b, Backprop (f a), Reifies s W) =>
BVar s b -> BVar s (f a) -> BVar s (f b)
fmapConst = forall (f :: * -> *) s a b.
(Functor f, Foldable f, Reifies s W) =>
AddFunc (f a)
-> AddFunc b
-> ZeroFunc (f a)
-> ZeroFunc b
-> BVar s b
-> BVar s (f a)
-> BVar s (f b)
E.fmapConst forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE fmapConst #-}
(<$>)
:: (Traversable f, Backprop a, Backprop b, Reifies s W)
=> (BVar s a -> BVar s b)
-> BVar s (f a)
-> BVar s (f b)
<$> :: forall (f :: * -> *) a b s.
(Traversable f, Backprop a, Backprop b, Reifies s W) =>
(BVar s a -> BVar s b) -> BVar s (f a) -> BVar s (f b)
(<$>) = forall (f :: * -> *) a b s.
(Traversable f, Backprop a, Backprop b, Reifies s W) =>
(BVar s a -> BVar s b) -> BVar s (f a) -> BVar s (f b)
fmap
infixl 4 <$>
{-# INLINE (<$>) #-}
(<$)
:: (Traversable f, Backprop b, Backprop (f a), Reifies s W)
=> BVar s b
-> BVar s (f a)
-> BVar s (f b)
<$ :: forall (f :: * -> *) b a s.
(Traversable f, Backprop b, Backprop (f a), Reifies s W) =>
BVar s b -> BVar s (f a) -> BVar s (f b)
(<$) = forall (f :: * -> *) b a s.
(Functor f, Foldable f, Backprop b, Backprop (f a), Reifies s W) =>
BVar s b -> BVar s (f a) -> BVar s (f b)
fmapConst
infixl 4 <$
{-# INLINE (<$) #-}
($>)
:: (Traversable f, Backprop b, Backprop (f a), Reifies s W)
=> BVar s (f a)
-> BVar s b
-> BVar s (f b)
BVar s (f a)
xs $> :: forall (f :: * -> *) b a s.
(Traversable f, Backprop b, Backprop (f a), Reifies s W) =>
BVar s (f a) -> BVar s b -> BVar s (f b)
$> BVar s b
x = BVar s b
x forall (f :: * -> *) b a s.
(Traversable f, Backprop b, Backprop (f a), Reifies s W) =>
BVar s b -> BVar s (f a) -> BVar s (f b)
<$ BVar s (f a)
xs
infixl 4 $>
{-# INLINE ($>) #-}
traverse
:: (Traversable t, Applicative f, Foldable f, Backprop a, Backprop b, Backprop (t b), Reifies s W)
=> (BVar s a -> f (BVar s b))
-> BVar s (t a)
-> BVar s (f (t b))
traverse :: forall (t :: * -> *) (f :: * -> *) a b s.
(Traversable t, Applicative f, Foldable f, Backprop a, Backprop b,
Backprop (t b), Reifies s W) =>
(BVar s a -> f (BVar s b)) -> BVar s (t a) -> BVar s (f (t b))
traverse = forall (t :: * -> *) (f :: * -> *) s a b.
(Traversable t, Applicative f, Foldable f, Reifies s W) =>
AddFunc a
-> AddFunc b
-> AddFunc (t b)
-> ZeroFunc a
-> ZeroFunc b
-> (BVar s a -> f (BVar s b))
-> BVar s (t a)
-> BVar s (f (t b))
E.traverse forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => AddFunc a
E.addFunc
forall a. Backprop a => ZeroFunc a
E.zeroFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE traverse #-}
liftA2
:: ( Traversable f, Applicative f
, Backprop a, Backprop b, Backprop c
, Reifies s W
)
=> (BVar s a -> BVar s b -> BVar s c)
-> BVar s (f a)
-> BVar s (f b)
-> BVar s (f c)
liftA2 :: forall (f :: * -> *) a b c s.
(Traversable f, Applicative f, Backprop a, Backprop b, Backprop c,
Reifies s W) =>
(BVar s a -> BVar s b -> BVar s c)
-> BVar s (f a) -> BVar s (f b) -> BVar s (f c)
liftA2 = forall (f :: * -> *) s a b c.
(Traversable f, Applicative f, Reifies s W) =>
AddFunc a
-> AddFunc b
-> AddFunc c
-> ZeroFunc a
-> ZeroFunc b
-> ZeroFunc c
-> (BVar s a -> BVar s b -> BVar s c)
-> BVar s (f a)
-> BVar s (f b)
-> BVar s (f c)
E.liftA2 forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => AddFunc a
E.addFunc
forall a. Backprop a => ZeroFunc a
E.zeroFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE liftA2 #-}
liftA3
:: ( Traversable f
, Applicative f
, Backprop a, Backprop b, Backprop c, Backprop d
, Reifies s W
)
=> (BVar s a -> BVar s b -> BVar s c -> BVar s d)
-> BVar s (f a)
-> BVar s (f b)
-> BVar s (f c)
-> BVar s (f d)
liftA3 :: forall (f :: * -> *) a b c d s.
(Traversable f, Applicative f, Backprop a, Backprop b, Backprop c,
Backprop d, Reifies s W) =>
(BVar s a -> BVar s b -> BVar s c -> BVar s d)
-> BVar s (f a) -> BVar s (f b) -> BVar s (f c) -> BVar s (f d)
liftA3 = forall (f :: * -> *) s a b c d.
(Traversable f, Applicative f, Reifies s W) =>
AddFunc a
-> AddFunc b
-> AddFunc c
-> AddFunc d
-> ZeroFunc a
-> ZeroFunc b
-> ZeroFunc c
-> ZeroFunc d
-> (BVar s a -> BVar s b -> BVar s c -> BVar s d)
-> BVar s (f a)
-> BVar s (f b)
-> BVar s (f c)
-> BVar s (f d)
E.liftA3 forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => AddFunc a
E.addFunc
forall a. Backprop a => ZeroFunc a
E.zeroFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE liftA3 #-}
fromIntegral
:: (Backprop a, P.Integral a, P.Integral b, Reifies s W)
=> BVar s a
-> BVar s b
fromIntegral :: forall a b s.
(Backprop a, Integral a, Integral b, Reifies s W) =>
BVar s a -> BVar s b
fromIntegral = forall a b s.
(Integral a, Integral b, Reifies s W) =>
AddFunc a -> BVar s a -> BVar s b
E.fromIntegral forall a. Backprop a => AddFunc a
E.addFunc
{-# INLINE fromIntegral #-}
realToFrac
:: (Backprop a, Fractional a, P.Real a, Fractional b, P.Real b, Reifies s W)
=> BVar s a
-> BVar s b
realToFrac :: forall a b s.
(Backprop a, Fractional a, Real a, Fractional b, Real b,
Reifies s W) =>
BVar s a -> BVar s b
realToFrac = forall a b s.
(Fractional a, Real a, Fractional b, Real b, Reifies s W) =>
AddFunc a -> BVar s a -> BVar s b
E.realToFrac forall a. Backprop a => AddFunc a
E.addFunc
{-# INLINE realToFrac #-}
round
:: (P.RealFrac a, P.Integral b, Reifies s W)
=> BVar s a
-> BVar s b
round :: forall a b s.
(RealFrac a, Integral b, Reifies s W) =>
BVar s a -> BVar s b
round = forall a b s.
(RealFrac a, Integral b, Reifies s W) =>
AddFunc a -> BVar s a -> BVar s b
E.round forall a. Num a => AddFunc a
E.afNum
{-# INLINE round #-}
fromIntegral'
:: (P.Integral a, P.RealFrac b, Reifies s W)
=> BVar s a
-> BVar s b
fromIntegral' :: forall a b s.
(Integral a, RealFrac b, Reifies s W) =>
BVar s a -> BVar s b
fromIntegral' = forall a b s.
(Integral a, RealFrac b, Reifies s W) =>
AddFunc a -> BVar s a -> BVar s b
E.fromIntegral' forall a. Num a => AddFunc a
E.afNum
{-# INLINE fromIntegral' #-}
toList
:: (Traversable t, Backprop a, Reifies s W)
=> BVar s (t a)
-> [BVar s a]
toList :: forall (t :: * -> *) a s.
(Traversable t, Backprop a, Reifies s W) =>
BVar s (t a) -> [BVar s a]
toList = forall (t :: * -> *) s a.
(Traversable t, Reifies s W) =>
AddFunc a -> ZeroFunc a -> BVar s (t a) -> [BVar s a]
E.toList forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE toList #-}
mapAccumL
:: (Traversable t, Backprop b, Backprop c, Reifies s W)
=> (BVar s a -> BVar s b -> (BVar s a, BVar s c))
-> BVar s a
-> BVar s (t b)
-> (BVar s a, BVar s (t c))
mapAccumL :: forall (t :: * -> *) b c s a.
(Traversable t, Backprop b, Backprop c, Reifies s W) =>
(BVar s a -> BVar s b -> (BVar s a, BVar s c))
-> BVar s a -> BVar s (t b) -> (BVar s a, BVar s (t c))
mapAccumL = forall (t :: * -> *) s b c a.
(Traversable t, Reifies s W) =>
AddFunc b
-> AddFunc c
-> ZeroFunc b
-> ZeroFunc c
-> (BVar s a -> BVar s b -> (BVar s a, BVar s c))
-> BVar s a
-> BVar s (t b)
-> (BVar s a, BVar s (t c))
E.mapAccumL forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE mapAccumL #-}
mapAccumR
:: (Traversable t, Backprop b, Backprop c, Reifies s W)
=> (BVar s a -> BVar s b -> (BVar s a, BVar s c))
-> BVar s a
-> BVar s (t b)
-> (BVar s a, BVar s (t c))
mapAccumR :: forall (t :: * -> *) b c s a.
(Traversable t, Backprop b, Backprop c, Reifies s W) =>
(BVar s a -> BVar s b -> (BVar s a, BVar s c))
-> BVar s a -> BVar s (t b) -> (BVar s a, BVar s (t c))
mapAccumR = forall (t :: * -> *) s b c a.
(Traversable t, Reifies s W) =>
AddFunc b
-> AddFunc c
-> ZeroFunc b
-> ZeroFunc c
-> (BVar s a -> BVar s b -> (BVar s a, BVar s c))
-> BVar s a
-> BVar s (t b)
-> (BVar s a, BVar s (t c))
E.mapAccumR forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => AddFunc a
E.addFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc forall a. Backprop a => ZeroFunc a
E.zeroFunc
{-# INLINE mapAccumR #-}