{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Numeric.Backprop.Class (
Backprop(..)
, zeroNum, addNum, oneNum
, zeroVec, addVec, oneVec, zeroVecNum, oneVecNum
, zeroFunctor, addIsList, addAsList, oneFunctor
, genericZero, genericAdd, genericOne
, ABP(..), NumBP(..), NumVec(..)
, GZero, GAdd, GOne
) where
import Control.Applicative
import Control.DeepSeq
import Control.Monad
import Data.Coerce
import Data.Complex
import Data.Data
import Data.Foldable hiding (toList)
import Data.Functor.Compose
import Data.Functor.Identity
import Data.List.NonEmpty (NonEmpty(..))
import Data.Monoid
import Data.Ratio
import Data.Vinyl
import Data.Vinyl.ARec
import Data.Vinyl.TypeLevel
import Data.Void
import Data.Word
import GHC.Exts
import GHC.Generics
import Numeric.Natural
import qualified Control.Arrow as Arr
import qualified Data.Functor.Product as DFP
import qualified Data.IntMap as IM
import qualified Data.Map as M
import qualified Data.Semigroup as SG
import qualified Data.Sequence as Seq
import qualified Data.Vector as V
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Primitive as VP
import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vinyl.Functor as V
import qualified Data.Vinyl.XRec as V
class Backprop a where
zero :: a -> a
add :: a -> a -> a
one :: a -> a
default zero :: (Generic a, GZero (Rep a)) => a -> a
zero = forall a. (Generic a, GZero (Rep a)) => a -> a
genericZero
{-# INLINE zero #-}
default add :: (Generic a, GAdd (Rep a)) => a -> a -> a
add = forall a. (Generic a, GAdd (Rep a)) => a -> a -> a
genericAdd
{-# INLINE add #-}
default one :: (Generic a, GOne (Rep a)) => a -> a
one = forall a. (Generic a, GOne (Rep a)) => a -> a
genericOne
{-# INLINE one #-}
genericZero :: (Generic a, GZero (Rep a)) => a -> a
genericZero :: forall a. (Generic a, GZero (Rep a)) => a -> a
genericZero = forall a x. Generic a => Rep a x -> a
to forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) t. GZero f => f t -> f t
gzero forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
{-# INLINE genericZero #-}
genericAdd :: (Generic a, GAdd (Rep a)) => a -> a -> a
genericAdd :: forall a. (Generic a, GAdd (Rep a)) => a -> a -> a
genericAdd a
x a
y = forall a x. Generic a => Rep a x -> a
to forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) t. GAdd f => f t -> f t -> f t
gadd (forall a x. Generic a => a -> Rep a x
from a
x) (forall a x. Generic a => a -> Rep a x
from a
y)
{-# INLINE genericAdd #-}
genericOne :: (Generic a, GOne (Rep a)) => a -> a
genericOne :: forall a. (Generic a, GOne (Rep a)) => a -> a
genericOne = forall a x. Generic a => Rep a x -> a
to forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) t. GOne f => f t -> f t
gone forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
{-# INLINE genericOne #-}
zeroNum :: Num a => a -> a
zeroNum :: forall a. Num a => a -> a
zeroNum a
_ = a
0
{-# INLINE zeroNum #-}
addNum :: Num a => a -> a -> a
addNum :: forall a. Num a => a -> a -> a
addNum = forall a. Num a => a -> a -> a
(+)
{-# INLINE addNum #-}
oneNum :: Num a => a -> a
oneNum :: forall a. Num a => a -> a
oneNum a
_ = a
1
{-# INLINE oneNum #-}
zeroVec :: (VG.Vector v a, Backprop a) => v a -> v a
zeroVec :: forall (v :: * -> *) a. (Vector v a, Backprop a) => v a -> v a
zeroVec = forall (v :: * -> *) a b.
(Vector v a, Vector v b) =>
(a -> b) -> v a -> v b
VG.map forall a. Backprop a => a -> a
zero
{-# INLINE zeroVec #-}
addVec :: (VG.Vector v a, Backprop a) => v a -> v a -> v a
addVec :: forall (v :: * -> *) a.
(Vector v a, Backprop a) =>
v a -> v a -> v a
addVec v a
x v a
y = case forall a. Ord a => a -> a -> Ordering
compare Int
lX Int
lY of
Ordering
LT -> let (v a
y1,v a
y2) = forall (v :: * -> *) a. Vector v a => Int -> v a -> (v a, v a)
VG.splitAt (Int
lY forall a. Num a => a -> a -> a
- Int
lX) v a
y
in forall (v :: * -> *) a b c.
(Vector v a, Vector v b, Vector v c) =>
(a -> b -> c) -> v a -> v b -> v c
VG.zipWith forall a. Backprop a => a -> a -> a
add v a
x v a
y1 forall (v :: * -> *) a. Vector v a => v a -> v a -> v a
VG.++ v a
y2
Ordering
EQ -> forall (v :: * -> *) a b c.
(Vector v a, Vector v b, Vector v c) =>
(a -> b -> c) -> v a -> v b -> v c
VG.zipWith forall a. Backprop a => a -> a -> a
add v a
x v a
y
Ordering
GT -> let (v a
x1,v a
x2) = forall (v :: * -> *) a. Vector v a => Int -> v a -> (v a, v a)
VG.splitAt (Int
lX forall a. Num a => a -> a -> a
- Int
lY) v a
x
in forall (v :: * -> *) a b c.
(Vector v a, Vector v b, Vector v c) =>
(a -> b -> c) -> v a -> v b -> v c
VG.zipWith forall a. Backprop a => a -> a -> a
add v a
x1 v a
y forall (v :: * -> *) a. Vector v a => v a -> v a -> v a
VG.++ v a
x2
where
lX :: Int
lX = forall (v :: * -> *) a. Vector v a => v a -> Int
VG.length v a
x
lY :: Int
lY = forall (v :: * -> *) a. Vector v a => v a -> Int
VG.length v a
y
oneVec :: (VG.Vector v a, Backprop a) => v a -> v a
oneVec :: forall (v :: * -> *) a. (Vector v a, Backprop a) => v a -> v a
oneVec = forall (v :: * -> *) a b.
(Vector v a, Vector v b) =>
(a -> b) -> v a -> v b
VG.map forall a. Backprop a => a -> a
one
{-# INLINE oneVec #-}
zeroVecNum :: (VG.Vector v a, Num a) => v a -> v a
zeroVecNum :: forall (v :: * -> *) a. (Vector v a, Num a) => v a -> v a
zeroVecNum = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (v :: * -> *) a. Vector v a => Int -> a -> v a
VG.replicate a
0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) a. Vector v a => v a -> Int
VG.length
{-# INLINE zeroVecNum #-}
oneVecNum :: (VG.Vector v a, Num a) => v a -> v a
oneVecNum :: forall (v :: * -> *) a. (Vector v a, Num a) => v a -> v a
oneVecNum = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (v :: * -> *) a. Vector v a => Int -> a -> v a
VG.replicate a
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) a. Vector v a => v a -> Int
VG.length
{-# INLINE oneVecNum #-}
zeroFunctor :: (Functor f, Backprop a) => f a -> f a
zeroFunctor :: forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
zeroFunctor = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Backprop a => a -> a
zero
{-# INLINE zeroFunctor #-}
addIsList :: (IsList a, Backprop (Item a)) => a -> a -> a
addIsList :: forall a. (IsList a, Backprop (Item a)) => a -> a -> a
addIsList = forall b a. Backprop b => (a -> [b]) -> ([b] -> a) -> a -> a -> a
addAsList forall l. IsList l => l -> [Item l]
toList forall l. IsList l => [Item l] -> l
fromList
{-# INLINE addIsList #-}
addAsList
:: Backprop b
=> (a -> [b])
-> ([b] -> a)
-> a
-> a
-> a
addAsList :: forall b a. Backprop b => (a -> [b]) -> ([b] -> a) -> a -> a -> a
addAsList a -> [b]
f [b] -> a
g a
x a
y = [b] -> a
g forall a b. (a -> b) -> a -> b
$ [b] -> [b] -> [b]
go (a -> [b]
f a
x) (a -> [b]
f a
y)
where
go :: [b] -> [b] -> [b]
go = \case
[] -> forall a. a -> a
id
o :: [b]
o@(b
x':[b]
xs) -> \case
[] -> [b]
o
b
y':[b]
ys -> forall a. Backprop a => a -> a -> a
add b
x' b
y' forall a. a -> [a] -> [a]
: [b] -> [b] -> [b]
go [b]
xs [b]
ys
oneFunctor :: (Functor f, Backprop a) => f a -> f a
oneFunctor :: forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
oneFunctor = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Backprop a => a -> a
one
{-# INLINE oneFunctor #-}
newtype NumBP a = NumBP { forall a. NumBP a -> a
runNumBP :: a }
deriving (Int -> NumBP a -> ShowS
forall a. Show a => Int -> NumBP a -> ShowS
forall a. Show a => [NumBP a] -> ShowS
forall a. Show a => NumBP a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NumBP a] -> ShowS
$cshowList :: forall a. Show a => [NumBP a] -> ShowS
show :: NumBP a -> String
$cshow :: forall a. Show a => NumBP a -> String
showsPrec :: Int -> NumBP a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> NumBP a -> ShowS
Show, ReadPrec [NumBP a]
ReadPrec (NumBP a)
ReadS [NumBP a]
forall a. Read a => ReadPrec [NumBP a]
forall a. Read a => ReadPrec (NumBP a)
forall a. Read a => Int -> ReadS (NumBP a)
forall a. Read a => ReadS [NumBP a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NumBP a]
$creadListPrec :: forall a. Read a => ReadPrec [NumBP a]
readPrec :: ReadPrec (NumBP a)
$creadPrec :: forall a. Read a => ReadPrec (NumBP a)
readList :: ReadS [NumBP a]
$creadList :: forall a. Read a => ReadS [NumBP a]
readsPrec :: Int -> ReadS (NumBP a)
$creadsPrec :: forall a. Read a => Int -> ReadS (NumBP a)
Read, NumBP a -> NumBP a -> Bool
forall a. Eq a => NumBP a -> NumBP a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NumBP a -> NumBP a -> Bool
$c/= :: forall a. Eq a => NumBP a -> NumBP a -> Bool
== :: NumBP a -> NumBP a -> Bool
$c== :: forall a. Eq a => NumBP a -> NumBP a -> Bool
Eq, NumBP a -> NumBP a -> Bool
NumBP a -> NumBP a -> Ordering
NumBP a -> NumBP a -> NumBP a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (NumBP a)
forall a. Ord a => NumBP a -> NumBP a -> Bool
forall a. Ord a => NumBP a -> NumBP a -> Ordering
forall a. Ord a => NumBP a -> NumBP a -> NumBP a
min :: NumBP a -> NumBP a -> NumBP a
$cmin :: forall a. Ord a => NumBP a -> NumBP a -> NumBP a
max :: NumBP a -> NumBP a -> NumBP a
$cmax :: forall a. Ord a => NumBP a -> NumBP a -> NumBP a
>= :: NumBP a -> NumBP a -> Bool
$c>= :: forall a. Ord a => NumBP a -> NumBP a -> Bool
> :: NumBP a -> NumBP a -> Bool
$c> :: forall a. Ord a => NumBP a -> NumBP a -> Bool
<= :: NumBP a -> NumBP a -> Bool
$c<= :: forall a. Ord a => NumBP a -> NumBP a -> Bool
< :: NumBP a -> NumBP a -> Bool
$c< :: forall a. Ord a => NumBP a -> NumBP a -> Bool
compare :: NumBP a -> NumBP a -> Ordering
$ccompare :: forall a. Ord a => NumBP a -> NumBP a -> Ordering
Ord, Typeable, NumBP a -> DataType
NumBP a -> Constr
forall {a}. Data a => Typeable (NumBP a)
forall a. Data a => NumBP a -> DataType
forall a. Data a => NumBP a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> NumBP a -> NumBP a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> NumBP a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> NumBP a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NumBP a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NumBP a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> NumBP a -> m (NumBP a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> NumBP a -> m (NumBP a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NumBP a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NumBP a -> c (NumBP a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (NumBP a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (NumBP a))
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NumBP a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NumBP a -> c (NumBP a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (NumBP a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NumBP a -> m (NumBP a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> NumBP a -> m (NumBP a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NumBP a -> m (NumBP a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> NumBP a -> m (NumBP a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NumBP a -> m (NumBP a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> NumBP a -> m (NumBP a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NumBP a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> NumBP a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> NumBP a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> NumBP a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NumBP a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NumBP a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NumBP a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NumBP a -> r
gmapT :: (forall b. Data b => b -> b) -> NumBP a -> NumBP a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> NumBP a -> NumBP a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (NumBP a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (NumBP a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (NumBP a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (NumBP a))
dataTypeOf :: NumBP a -> DataType
$cdataTypeOf :: forall a. Data a => NumBP a -> DataType
toConstr :: NumBP a -> Constr
$ctoConstr :: forall a. Data a => NumBP a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NumBP a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NumBP a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NumBP a -> c (NumBP a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NumBP a -> c (NumBP a)
Data, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (NumBP a) x -> NumBP a
forall a x. NumBP a -> Rep (NumBP a) x
$cto :: forall a x. Rep (NumBP a) x -> NumBP a
$cfrom :: forall a x. NumBP a -> Rep (NumBP a) x
Generic, forall a b. a -> NumBP b -> NumBP a
forall a b. (a -> b) -> NumBP a -> NumBP b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> NumBP b -> NumBP a
$c<$ :: forall a b. a -> NumBP b -> NumBP a
fmap :: forall a b. (a -> b) -> NumBP a -> NumBP b
$cfmap :: forall a b. (a -> b) -> NumBP a -> NumBP b
Functor, forall a. Eq a => a -> NumBP a -> Bool
forall a. Num a => NumBP a -> a
forall a. Ord a => NumBP a -> a
forall m. Monoid m => NumBP m -> m
forall a. NumBP a -> Bool
forall a. NumBP a -> Int
forall a. NumBP a -> [a]
forall a. (a -> a -> a) -> NumBP a -> a
forall m a. Monoid m => (a -> m) -> NumBP a -> m
forall b a. (b -> a -> b) -> b -> NumBP a -> b
forall a b. (a -> b -> b) -> b -> NumBP a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => NumBP a -> a
$cproduct :: forall a. Num a => NumBP a -> a
sum :: forall a. Num a => NumBP a -> a
$csum :: forall a. Num a => NumBP a -> a
minimum :: forall a. Ord a => NumBP a -> a
$cminimum :: forall a. Ord a => NumBP a -> a
maximum :: forall a. Ord a => NumBP a -> a
$cmaximum :: forall a. Ord a => NumBP a -> a
elem :: forall a. Eq a => a -> NumBP a -> Bool
$celem :: forall a. Eq a => a -> NumBP a -> Bool
length :: forall a. NumBP a -> Int
$clength :: forall a. NumBP a -> Int
null :: forall a. NumBP a -> Bool
$cnull :: forall a. NumBP a -> Bool
toList :: forall a. NumBP a -> [a]
$ctoList :: forall a. NumBP a -> [a]
foldl1 :: forall a. (a -> a -> a) -> NumBP a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> NumBP a -> a
foldr1 :: forall a. (a -> a -> a) -> NumBP a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> NumBP a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> NumBP a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> NumBP a -> b
foldl :: forall b a. (b -> a -> b) -> b -> NumBP a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> NumBP a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> NumBP a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> NumBP a -> b
foldr :: forall a b. (a -> b -> b) -> b -> NumBP a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> NumBP a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> NumBP a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> NumBP a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> NumBP a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> NumBP a -> m
fold :: forall m. Monoid m => NumBP m -> m
$cfold :: forall m. Monoid m => NumBP m -> m
Foldable, Functor NumBP
Foldable NumBP
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => NumBP (m a) -> m (NumBP a)
forall (f :: * -> *) a. Applicative f => NumBP (f a) -> f (NumBP a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NumBP a -> m (NumBP b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NumBP a -> f (NumBP b)
sequence :: forall (m :: * -> *) a. Monad m => NumBP (m a) -> m (NumBP a)
$csequence :: forall (m :: * -> *) a. Monad m => NumBP (m a) -> m (NumBP a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NumBP a -> m (NumBP b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NumBP a -> m (NumBP b)
sequenceA :: forall (f :: * -> *) a. Applicative f => NumBP (f a) -> f (NumBP a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => NumBP (f a) -> f (NumBP a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NumBP a -> f (NumBP b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NumBP a -> f (NumBP b)
Traversable, Integer -> NumBP a
NumBP a -> NumBP a
NumBP a -> NumBP a -> NumBP a
forall a. Num a => Integer -> NumBP a
forall a. Num a => NumBP a -> NumBP a
forall a. Num a => NumBP a -> NumBP a -> NumBP a
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> NumBP a
$cfromInteger :: forall a. Num a => Integer -> NumBP a
signum :: NumBP a -> NumBP a
$csignum :: forall a. Num a => NumBP a -> NumBP a
abs :: NumBP a -> NumBP a
$cabs :: forall a. Num a => NumBP a -> NumBP a
negate :: NumBP a -> NumBP a
$cnegate :: forall a. Num a => NumBP a -> NumBP a
* :: NumBP a -> NumBP a -> NumBP a
$c* :: forall a. Num a => NumBP a -> NumBP a -> NumBP a
- :: NumBP a -> NumBP a -> NumBP a
$c- :: forall a. Num a => NumBP a -> NumBP a -> NumBP a
+ :: NumBP a -> NumBP a -> NumBP a
$c+ :: forall a. Num a => NumBP a -> NumBP a -> NumBP a
Num, Rational -> NumBP a
NumBP a -> NumBP a
NumBP a -> NumBP a -> NumBP a
forall {a}. Fractional a => Num (NumBP a)
forall a. Fractional a => Rational -> NumBP a
forall a. Fractional a => NumBP a -> NumBP a
forall a. Fractional a => NumBP a -> NumBP a -> NumBP a
forall a.
Num a
-> (a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
fromRational :: Rational -> NumBP a
$cfromRational :: forall a. Fractional a => Rational -> NumBP a
recip :: NumBP a -> NumBP a
$crecip :: forall a. Fractional a => NumBP a -> NumBP a
/ :: NumBP a -> NumBP a -> NumBP a
$c/ :: forall a. Fractional a => NumBP a -> NumBP a -> NumBP a
Fractional, NumBP a
NumBP a -> NumBP a
NumBP a -> NumBP a -> NumBP a
forall {a}. Floating a => Fractional (NumBP a)
forall a. Floating a => NumBP a
forall a. Floating a => NumBP a -> NumBP a
forall a. Floating a => NumBP a -> NumBP a -> NumBP a
forall a.
Fractional a
-> a
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> Floating a
log1mexp :: NumBP a -> NumBP a
$clog1mexp :: forall a. Floating a => NumBP a -> NumBP a
log1pexp :: NumBP a -> NumBP a
$clog1pexp :: forall a. Floating a => NumBP a -> NumBP a
expm1 :: NumBP a -> NumBP a
$cexpm1 :: forall a. Floating a => NumBP a -> NumBP a
log1p :: NumBP a -> NumBP a
$clog1p :: forall a. Floating a => NumBP a -> NumBP a
atanh :: NumBP a -> NumBP a
$catanh :: forall a. Floating a => NumBP a -> NumBP a
acosh :: NumBP a -> NumBP a
$cacosh :: forall a. Floating a => NumBP a -> NumBP a
asinh :: NumBP a -> NumBP a
$casinh :: forall a. Floating a => NumBP a -> NumBP a
tanh :: NumBP a -> NumBP a
$ctanh :: forall a. Floating a => NumBP a -> NumBP a
cosh :: NumBP a -> NumBP a
$ccosh :: forall a. Floating a => NumBP a -> NumBP a
sinh :: NumBP a -> NumBP a
$csinh :: forall a. Floating a => NumBP a -> NumBP a
atan :: NumBP a -> NumBP a
$catan :: forall a. Floating a => NumBP a -> NumBP a
acos :: NumBP a -> NumBP a
$cacos :: forall a. Floating a => NumBP a -> NumBP a
asin :: NumBP a -> NumBP a
$casin :: forall a. Floating a => NumBP a -> NumBP a
tan :: NumBP a -> NumBP a
$ctan :: forall a. Floating a => NumBP a -> NumBP a
cos :: NumBP a -> NumBP a
$ccos :: forall a. Floating a => NumBP a -> NumBP a
sin :: NumBP a -> NumBP a
$csin :: forall a. Floating a => NumBP a -> NumBP a
logBase :: NumBP a -> NumBP a -> NumBP a
$clogBase :: forall a. Floating a => NumBP a -> NumBP a -> NumBP a
** :: NumBP a -> NumBP a -> NumBP a
$c** :: forall a. Floating a => NumBP a -> NumBP a -> NumBP a
sqrt :: NumBP a -> NumBP a
$csqrt :: forall a. Floating a => NumBP a -> NumBP a
log :: NumBP a -> NumBP a
$clog :: forall a. Floating a => NumBP a -> NumBP a
exp :: NumBP a -> NumBP a
$cexp :: forall a. Floating a => NumBP a -> NumBP a
pi :: NumBP a
$cpi :: forall a. Floating a => NumBP a
Floating)
instance NFData a => NFData (NumBP a)
instance Applicative NumBP where
pure :: forall a. a -> NumBP a
pure = forall a. a -> NumBP a
NumBP
{-# INLINE pure #-}
NumBP (a -> b)
f <*> :: forall a b. NumBP (a -> b) -> NumBP a -> NumBP b
<*> NumBP a
x = forall a. a -> NumBP a
NumBP forall a b. (a -> b) -> a -> b
$ (forall a. NumBP a -> a
runNumBP NumBP (a -> b)
f) (forall a. NumBP a -> a
runNumBP NumBP a
x)
{-# INLINE (<*>) #-}
instance Monad NumBP where
return :: forall a. a -> NumBP a
return = forall a. a -> NumBP a
NumBP
{-# INLINE return #-}
NumBP a
x >>= :: forall a b. NumBP a -> (a -> NumBP b) -> NumBP b
>>= a -> NumBP b
f = a -> NumBP b
f (forall a. NumBP a -> a
runNumBP NumBP a
x)
{-# INLINE (>>=) #-}
instance Num a => Backprop (NumBP a) where
zero :: NumBP a -> NumBP a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a
zeroNum :: a -> a)
{-# INLINE zero #-}
add :: NumBP a -> NumBP a -> NumBP a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a -> a
addNum :: a -> a -> a)
{-# INLINE add #-}
one :: NumBP a -> NumBP a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a
oneNum :: a -> a)
{-# INLINE one #-}
newtype NumVec v a = NumVec { forall (v :: * -> *) a. NumVec v a -> v a
runNumVec :: v a }
deriving (Int -> NumVec v a -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (v :: * -> *) a. Show (v a) => Int -> NumVec v a -> ShowS
forall (v :: * -> *) a. Show (v a) => [NumVec v a] -> ShowS
forall (v :: * -> *) a. Show (v a) => NumVec v a -> String
showList :: [NumVec v a] -> ShowS
$cshowList :: forall (v :: * -> *) a. Show (v a) => [NumVec v a] -> ShowS
show :: NumVec v a -> String
$cshow :: forall (v :: * -> *) a. Show (v a) => NumVec v a -> String
showsPrec :: Int -> NumVec v a -> ShowS
$cshowsPrec :: forall (v :: * -> *) a. Show (v a) => Int -> NumVec v a -> ShowS
Show, ReadPrec [NumVec v a]
ReadPrec (NumVec v a)
ReadS [NumVec v a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall (v :: * -> *) a. Read (v a) => ReadPrec [NumVec v a]
forall (v :: * -> *) a. Read (v a) => ReadPrec (NumVec v a)
forall (v :: * -> *) a. Read (v a) => Int -> ReadS (NumVec v a)
forall (v :: * -> *) a. Read (v a) => ReadS [NumVec v a]
readListPrec :: ReadPrec [NumVec v a]
$creadListPrec :: forall (v :: * -> *) a. Read (v a) => ReadPrec [NumVec v a]
readPrec :: ReadPrec (NumVec v a)
$creadPrec :: forall (v :: * -> *) a. Read (v a) => ReadPrec (NumVec v a)
readList :: ReadS [NumVec v a]
$creadList :: forall (v :: * -> *) a. Read (v a) => ReadS [NumVec v a]
readsPrec :: Int -> ReadS (NumVec v a)
$creadsPrec :: forall (v :: * -> *) a. Read (v a) => Int -> ReadS (NumVec v a)
Read, NumVec v a -> NumVec v a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (v :: * -> *) a.
Eq (v a) =>
NumVec v a -> NumVec v a -> Bool
/= :: NumVec v a -> NumVec v a -> Bool
$c/= :: forall (v :: * -> *) a.
Eq (v a) =>
NumVec v a -> NumVec v a -> Bool
== :: NumVec v a -> NumVec v a -> Bool
$c== :: forall (v :: * -> *) a.
Eq (v a) =>
NumVec v a -> NumVec v a -> Bool
Eq, NumVec v a -> NumVec v a -> Bool
NumVec v a -> NumVec v a -> Ordering
NumVec v a -> NumVec v a -> NumVec v a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {v :: * -> *} {a}. Ord (v a) => Eq (NumVec v a)
forall (v :: * -> *) a.
Ord (v a) =>
NumVec v a -> NumVec v a -> Bool
forall (v :: * -> *) a.
Ord (v a) =>
NumVec v a -> NumVec v a -> Ordering
forall (v :: * -> *) a.
Ord (v a) =>
NumVec v a -> NumVec v a -> NumVec v a
min :: NumVec v a -> NumVec v a -> NumVec v a
$cmin :: forall (v :: * -> *) a.
Ord (v a) =>
NumVec v a -> NumVec v a -> NumVec v a
max :: NumVec v a -> NumVec v a -> NumVec v a
$cmax :: forall (v :: * -> *) a.
Ord (v a) =>
NumVec v a -> NumVec v a -> NumVec v a
>= :: NumVec v a -> NumVec v a -> Bool
$c>= :: forall (v :: * -> *) a.
Ord (v a) =>
NumVec v a -> NumVec v a -> Bool
> :: NumVec v a -> NumVec v a -> Bool
$c> :: forall (v :: * -> *) a.
Ord (v a) =>
NumVec v a -> NumVec v a -> Bool
<= :: NumVec v a -> NumVec v a -> Bool
$c<= :: forall (v :: * -> *) a.
Ord (v a) =>
NumVec v a -> NumVec v a -> Bool
< :: NumVec v a -> NumVec v a -> Bool
$c< :: forall (v :: * -> *) a.
Ord (v a) =>
NumVec v a -> NumVec v a -> Bool
compare :: NumVec v a -> NumVec v a -> Ordering
$ccompare :: forall (v :: * -> *) a.
Ord (v a) =>
NumVec v a -> NumVec v a -> Ordering
Ord, Typeable, NumVec v a -> DataType
NumVec v a -> Constr
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NumVec v a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NumVec v a -> c (NumVec v a)
forall {v :: * -> *} {a}.
(Typeable v, Typeable a, Data (v a)) =>
Typeable (NumVec v a)
forall (v :: * -> *) a.
(Typeable v, Typeable a, Data (v a)) =>
NumVec v a -> DataType
forall (v :: * -> *) a.
(Typeable v, Typeable a, Data (v a)) =>
NumVec v a -> Constr
forall (v :: * -> *) a.
(Typeable v, Typeable a, Data (v a)) =>
(forall b. Data b => b -> b) -> NumVec v a -> NumVec v a
forall (v :: * -> *) a u.
(Typeable v, Typeable a, Data (v a)) =>
Int -> (forall d. Data d => d -> u) -> NumVec v a -> u
forall (v :: * -> *) a u.
(Typeable v, Typeable a, Data (v a)) =>
(forall d. Data d => d -> u) -> NumVec v a -> [u]
forall (v :: * -> *) a r r'.
(Typeable v, Typeable a, Data (v a)) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NumVec v a -> r
forall (v :: * -> *) a r r'.
(Typeable v, Typeable a, Data (v a)) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NumVec v a -> r
forall (v :: * -> *) a (m :: * -> *).
(Typeable v, Typeable a, Data (v a), Monad m) =>
(forall d. Data d => d -> m d) -> NumVec v a -> m (NumVec v a)
forall (v :: * -> *) a (m :: * -> *).
(Typeable v, Typeable a, Data (v a), MonadPlus m) =>
(forall d. Data d => d -> m d) -> NumVec v a -> m (NumVec v a)
forall (v :: * -> *) a (c :: * -> *).
(Typeable v, Typeable a, Data (v a)) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NumVec v a)
forall (v :: * -> *) a (c :: * -> *).
(Typeable v, Typeable a, Data (v a)) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NumVec v a -> c (NumVec v a)
forall (v :: * -> *) a (t :: * -> *) (c :: * -> *).
(Typeable v, Typeable a, Data (v a), Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (NumVec v a))
forall (v :: * -> *) a (t :: * -> * -> *) (c :: * -> *).
(Typeable v, Typeable a, Data (v a), Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (NumVec v a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NumVec v a -> m (NumVec v a)
$cgmapMo :: forall (v :: * -> *) a (m :: * -> *).
(Typeable v, Typeable a, Data (v a), MonadPlus m) =>
(forall d. Data d => d -> m d) -> NumVec v a -> m (NumVec v a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NumVec v a -> m (NumVec v a)
$cgmapMp :: forall (v :: * -> *) a (m :: * -> *).
(Typeable v, Typeable a, Data (v a), MonadPlus m) =>
(forall d. Data d => d -> m d) -> NumVec v a -> m (NumVec v a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NumVec v a -> m (NumVec v a)
$cgmapM :: forall (v :: * -> *) a (m :: * -> *).
(Typeable v, Typeable a, Data (v a), Monad m) =>
(forall d. Data d => d -> m d) -> NumVec v a -> m (NumVec v a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NumVec v a -> u
$cgmapQi :: forall (v :: * -> *) a u.
(Typeable v, Typeable a, Data (v a)) =>
Int -> (forall d. Data d => d -> u) -> NumVec v a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> NumVec v a -> [u]
$cgmapQ :: forall (v :: * -> *) a u.
(Typeable v, Typeable a, Data (v a)) =>
(forall d. Data d => d -> u) -> NumVec v a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NumVec v a -> r
$cgmapQr :: forall (v :: * -> *) a r r'.
(Typeable v, Typeable a, Data (v a)) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NumVec v a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NumVec v a -> r
$cgmapQl :: forall (v :: * -> *) a r r'.
(Typeable v, Typeable a, Data (v a)) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NumVec v a -> r
gmapT :: (forall b. Data b => b -> b) -> NumVec v a -> NumVec v a
$cgmapT :: forall (v :: * -> *) a.
(Typeable v, Typeable a, Data (v a)) =>
(forall b. Data b => b -> b) -> NumVec v a -> NumVec v a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (NumVec v a))
$cdataCast2 :: forall (v :: * -> *) a (t :: * -> * -> *) (c :: * -> *).
(Typeable v, Typeable a, Data (v a), Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (NumVec v a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (NumVec v a))
$cdataCast1 :: forall (v :: * -> *) a (t :: * -> *) (c :: * -> *).
(Typeable v, Typeable a, Data (v a), Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (NumVec v a))
dataTypeOf :: NumVec v a -> DataType
$cdataTypeOf :: forall (v :: * -> *) a.
(Typeable v, Typeable a, Data (v a)) =>
NumVec v a -> DataType
toConstr :: NumVec v a -> Constr
$ctoConstr :: forall (v :: * -> *) a.
(Typeable v, Typeable a, Data (v a)) =>
NumVec v a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NumVec v a)
$cgunfold :: forall (v :: * -> *) a (c :: * -> *).
(Typeable v, Typeable a, Data (v a)) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NumVec v a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NumVec v a -> c (NumVec v a)
$cgfoldl :: forall (v :: * -> *) a (c :: * -> *).
(Typeable v, Typeable a, Data (v a)) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NumVec v a -> c (NumVec v a)
Data, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (v :: * -> *) a x. Rep (NumVec v a) x -> NumVec v a
forall (v :: * -> *) a x. NumVec v a -> Rep (NumVec v a) x
$cto :: forall (v :: * -> *) a x. Rep (NumVec v a) x -> NumVec v a
$cfrom :: forall (v :: * -> *) a x. NumVec v a -> Rep (NumVec v a) x
Generic, forall a b. a -> NumVec v b -> NumVec v a
forall a b. (a -> b) -> NumVec v a -> NumVec v b
forall (v :: * -> *) a b.
Functor v =>
a -> NumVec v b -> NumVec v a
forall (v :: * -> *) a b.
Functor v =>
(a -> b) -> NumVec v a -> NumVec v b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> NumVec v b -> NumVec v a
$c<$ :: forall (v :: * -> *) a b.
Functor v =>
a -> NumVec v b -> NumVec v a
fmap :: forall a b. (a -> b) -> NumVec v a -> NumVec v b
$cfmap :: forall (v :: * -> *) a b.
Functor v =>
(a -> b) -> NumVec v a -> NumVec v b
Functor, forall a. a -> NumVec v a
forall a b. NumVec v a -> NumVec v b -> NumVec v a
forall a b. NumVec v a -> NumVec v b -> NumVec v b
forall a b. NumVec v (a -> b) -> NumVec v a -> NumVec v b
forall a b c.
(a -> b -> c) -> NumVec v a -> NumVec v b -> NumVec v c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall {v :: * -> *}. Applicative v => Functor (NumVec v)
forall (v :: * -> *) a. Applicative v => a -> NumVec v a
forall (v :: * -> *) a b.
Applicative v =>
NumVec v a -> NumVec v b -> NumVec v a
forall (v :: * -> *) a b.
Applicative v =>
NumVec v a -> NumVec v b -> NumVec v b
forall (v :: * -> *) a b.
Applicative v =>
NumVec v (a -> b) -> NumVec v a -> NumVec v b
forall (v :: * -> *) a b c.
Applicative v =>
(a -> b -> c) -> NumVec v a -> NumVec v b -> NumVec v c
<* :: forall a b. NumVec v a -> NumVec v b -> NumVec v a
$c<* :: forall (v :: * -> *) a b.
Applicative v =>
NumVec v a -> NumVec v b -> NumVec v a
*> :: forall a b. NumVec v a -> NumVec v b -> NumVec v b
$c*> :: forall (v :: * -> *) a b.
Applicative v =>
NumVec v a -> NumVec v b -> NumVec v b
liftA2 :: forall a b c.
(a -> b -> c) -> NumVec v a -> NumVec v b -> NumVec v c
$cliftA2 :: forall (v :: * -> *) a b c.
Applicative v =>
(a -> b -> c) -> NumVec v a -> NumVec v b -> NumVec v c
<*> :: forall a b. NumVec v (a -> b) -> NumVec v a -> NumVec v b
$c<*> :: forall (v :: * -> *) a b.
Applicative v =>
NumVec v (a -> b) -> NumVec v a -> NumVec v b
pure :: forall a. a -> NumVec v a
$cpure :: forall (v :: * -> *) a. Applicative v => a -> NumVec v a
Applicative, forall a. a -> NumVec v a
forall a b. NumVec v a -> NumVec v b -> NumVec v b
forall a b. NumVec v a -> (a -> NumVec v b) -> NumVec v b
forall {v :: * -> *}. Monad v => Applicative (NumVec v)
forall (v :: * -> *) a. Monad v => a -> NumVec v a
forall (v :: * -> *) a b.
Monad v =>
NumVec v a -> NumVec v b -> NumVec v b
forall (v :: * -> *) a b.
Monad v =>
NumVec v a -> (a -> NumVec v b) -> NumVec v b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> NumVec v a
$creturn :: forall (v :: * -> *) a. Monad v => a -> NumVec v a
>> :: forall a b. NumVec v a -> NumVec v b -> NumVec v b
$c>> :: forall (v :: * -> *) a b.
Monad v =>
NumVec v a -> NumVec v b -> NumVec v b
>>= :: forall a b. NumVec v a -> (a -> NumVec v b) -> NumVec v b
$c>>= :: forall (v :: * -> *) a b.
Monad v =>
NumVec v a -> (a -> NumVec v b) -> NumVec v b
Monad, forall a. NumVec v a
forall a. NumVec v a -> NumVec v [a]
forall a. NumVec v a -> NumVec v a -> NumVec v a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall {v :: * -> *}. Alternative v => Applicative (NumVec v)
forall (v :: * -> *) a. Alternative v => NumVec v a
forall (v :: * -> *) a. Alternative v => NumVec v a -> NumVec v [a]
forall (v :: * -> *) a.
Alternative v =>
NumVec v a -> NumVec v a -> NumVec v a
many :: forall a. NumVec v a -> NumVec v [a]
$cmany :: forall (v :: * -> *) a. Alternative v => NumVec v a -> NumVec v [a]
some :: forall a. NumVec v a -> NumVec v [a]
$csome :: forall (v :: * -> *) a. Alternative v => NumVec v a -> NumVec v [a]
<|> :: forall a. NumVec v a -> NumVec v a -> NumVec v a
$c<|> :: forall (v :: * -> *) a.
Alternative v =>
NumVec v a -> NumVec v a -> NumVec v a
empty :: forall a. NumVec v a
$cempty :: forall (v :: * -> *) a. Alternative v => NumVec v a
Alternative, forall a. NumVec v a
forall a. NumVec v a -> NumVec v a -> NumVec v a
forall {v :: * -> *}. MonadPlus v => Monad (NumVec v)
forall {v :: * -> *}. MonadPlus v => Alternative (NumVec v)
forall (v :: * -> *) a. MonadPlus v => NumVec v a
forall (v :: * -> *) a.
MonadPlus v =>
NumVec v a -> NumVec v a -> NumVec v a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
mplus :: forall a. NumVec v a -> NumVec v a -> NumVec v a
$cmplus :: forall (v :: * -> *) a.
MonadPlus v =>
NumVec v a -> NumVec v a -> NumVec v a
mzero :: forall a. NumVec v a
$cmzero :: forall (v :: * -> *) a. MonadPlus v => NumVec v a
MonadPlus, forall a. Eq a => a -> NumVec v a -> Bool
forall a. Num a => NumVec v a -> a
forall a. Ord a => NumVec v a -> a
forall m. Monoid m => NumVec v m -> m
forall a. NumVec v a -> Bool
forall a. NumVec v a -> Int
forall a. NumVec v a -> [a]
forall a. (a -> a -> a) -> NumVec v a -> a
forall m a. Monoid m => (a -> m) -> NumVec v a -> m
forall b a. (b -> a -> b) -> b -> NumVec v a -> b
forall a b. (a -> b -> b) -> b -> NumVec v a -> b
forall (v :: * -> *) a.
(Foldable v, Eq a) =>
a -> NumVec v a -> Bool
forall (v :: * -> *) a. (Foldable v, Num a) => NumVec v a -> a
forall (v :: * -> *) a. (Foldable v, Ord a) => NumVec v a -> a
forall (v :: * -> *) m. (Foldable v, Monoid m) => NumVec v m -> m
forall (v :: * -> *) a. Foldable v => NumVec v a -> Bool
forall (v :: * -> *) a. Foldable v => NumVec v a -> Int
forall (v :: * -> *) a. Foldable v => NumVec v a -> [a]
forall (v :: * -> *) a.
Foldable v =>
(a -> a -> a) -> NumVec v a -> a
forall (v :: * -> *) m a.
(Foldable v, Monoid m) =>
(a -> m) -> NumVec v a -> m
forall (v :: * -> *) b a.
Foldable v =>
(b -> a -> b) -> b -> NumVec v a -> b
forall (v :: * -> *) a b.
Foldable v =>
(a -> b -> b) -> b -> NumVec v a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => NumVec v a -> a
$cproduct :: forall (v :: * -> *) a. (Foldable v, Num a) => NumVec v a -> a
sum :: forall a. Num a => NumVec v a -> a
$csum :: forall (v :: * -> *) a. (Foldable v, Num a) => NumVec v a -> a
minimum :: forall a. Ord a => NumVec v a -> a
$cminimum :: forall (v :: * -> *) a. (Foldable v, Ord a) => NumVec v a -> a
maximum :: forall a. Ord a => NumVec v a -> a
$cmaximum :: forall (v :: * -> *) a. (Foldable v, Ord a) => NumVec v a -> a
elem :: forall a. Eq a => a -> NumVec v a -> Bool
$celem :: forall (v :: * -> *) a.
(Foldable v, Eq a) =>
a -> NumVec v a -> Bool
length :: forall a. NumVec v a -> Int
$clength :: forall (v :: * -> *) a. Foldable v => NumVec v a -> Int
null :: forall a. NumVec v a -> Bool
$cnull :: forall (v :: * -> *) a. Foldable v => NumVec v a -> Bool
toList :: forall a. NumVec v a -> [a]
$ctoList :: forall (v :: * -> *) a. Foldable v => NumVec v a -> [a]
foldl1 :: forall a. (a -> a -> a) -> NumVec v a -> a
$cfoldl1 :: forall (v :: * -> *) a.
Foldable v =>
(a -> a -> a) -> NumVec v a -> a
foldr1 :: forall a. (a -> a -> a) -> NumVec v a -> a
$cfoldr1 :: forall (v :: * -> *) a.
Foldable v =>
(a -> a -> a) -> NumVec v a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> NumVec v a -> b
$cfoldl' :: forall (v :: * -> *) b a.
Foldable v =>
(b -> a -> b) -> b -> NumVec v a -> b
foldl :: forall b a. (b -> a -> b) -> b -> NumVec v a -> b
$cfoldl :: forall (v :: * -> *) b a.
Foldable v =>
(b -> a -> b) -> b -> NumVec v a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> NumVec v a -> b
$cfoldr' :: forall (v :: * -> *) a b.
Foldable v =>
(a -> b -> b) -> b -> NumVec v a -> b
foldr :: forall a b. (a -> b -> b) -> b -> NumVec v a -> b
$cfoldr :: forall (v :: * -> *) a b.
Foldable v =>
(a -> b -> b) -> b -> NumVec v a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> NumVec v a -> m
$cfoldMap' :: forall (v :: * -> *) m a.
(Foldable v, Monoid m) =>
(a -> m) -> NumVec v a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> NumVec v a -> m
$cfoldMap :: forall (v :: * -> *) m a.
(Foldable v, Monoid m) =>
(a -> m) -> NumVec v a -> m
fold :: forall m. Monoid m => NumVec v m -> m
$cfold :: forall (v :: * -> *) m. (Foldable v, Monoid m) => NumVec v m -> m
Foldable, forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall {v :: * -> *}. Traversable v => Functor (NumVec v)
forall {v :: * -> *}. Traversable v => Foldable (NumVec v)
forall (v :: * -> *) (m :: * -> *) a.
(Traversable v, Monad m) =>
NumVec v (m a) -> m (NumVec v a)
forall (v :: * -> *) (f :: * -> *) a.
(Traversable v, Applicative f) =>
NumVec v (f a) -> f (NumVec v a)
forall (v :: * -> *) (m :: * -> *) a b.
(Traversable v, Monad m) =>
(a -> m b) -> NumVec v a -> m (NumVec v b)
forall (v :: * -> *) (f :: * -> *) a b.
(Traversable v, Applicative f) =>
(a -> f b) -> NumVec v a -> f (NumVec v b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NumVec v a -> f (NumVec v b)
sequence :: forall (m :: * -> *) a. Monad m => NumVec v (m a) -> m (NumVec v a)
$csequence :: forall (v :: * -> *) (m :: * -> *) a.
(Traversable v, Monad m) =>
NumVec v (m a) -> m (NumVec v a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NumVec v a -> m (NumVec v b)
$cmapM :: forall (v :: * -> *) (m :: * -> *) a b.
(Traversable v, Monad m) =>
(a -> m b) -> NumVec v a -> m (NumVec v b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
NumVec v (f a) -> f (NumVec v a)
$csequenceA :: forall (v :: * -> *) (f :: * -> *) a.
(Traversable v, Applicative f) =>
NumVec v (f a) -> f (NumVec v a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NumVec v a -> f (NumVec v b)
$ctraverse :: forall (v :: * -> *) (f :: * -> *) a b.
(Traversable v, Applicative f) =>
(a -> f b) -> NumVec v a -> f (NumVec v b)
Traversable)
instance NFData (v a) => NFData (NumVec v a)
instance (VG.Vector v a, Num a) => Backprop (NumVec v a) where
zero :: NumVec v a -> NumVec v a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a. (Vector v a, Num a) => v a -> v a
zeroVecNum @v @a
add :: NumVec v a -> NumVec v a -> NumVec v a
add (NumVec v a
x) (NumVec v a
y) = forall (v :: * -> *) a. v a -> NumVec v a
NumVec forall a b. (a -> b) -> a -> b
$ case forall a. Ord a => a -> a -> Ordering
compare Int
lX Int
lY of
Ordering
LT -> let (v a
y1,v a
y2) = forall (v :: * -> *) a. Vector v a => Int -> v a -> (v a, v a)
VG.splitAt (Int
lY forall a. Num a => a -> a -> a
- Int
lX) v a
y
in forall (v :: * -> *) a b c.
(Vector v a, Vector v b, Vector v c) =>
(a -> b -> c) -> v a -> v b -> v c
VG.zipWith forall a. Num a => a -> a -> a
(+) v a
x v a
y1 forall (v :: * -> *) a. Vector v a => v a -> v a -> v a
VG.++ v a
y2
Ordering
EQ -> forall (v :: * -> *) a b c.
(Vector v a, Vector v b, Vector v c) =>
(a -> b -> c) -> v a -> v b -> v c
VG.zipWith forall a. Num a => a -> a -> a
(+) v a
x v a
y
Ordering
GT -> let (v a
x1,v a
x2) = forall (v :: * -> *) a. Vector v a => Int -> v a -> (v a, v a)
VG.splitAt (Int
lX forall a. Num a => a -> a -> a
- Int
lY) v a
x
in forall (v :: * -> *) a b c.
(Vector v a, Vector v b, Vector v c) =>
(a -> b -> c) -> v a -> v b -> v c
VG.zipWith forall a. Num a => a -> a -> a
(+) v a
x1 v a
y forall (v :: * -> *) a. Vector v a => v a -> v a -> v a
VG.++ v a
x2
where
lX :: Int
lX = forall (v :: * -> *) a. Vector v a => v a -> Int
VG.length v a
x
lY :: Int
lY = forall (v :: * -> *) a. Vector v a => v a -> Int
VG.length v a
y
one :: NumVec v a -> NumVec v a
one = coerce :: forall a b. Coercible a b => a -> b
coerce forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a. (Vector v a, Num a) => v a -> v a
oneVecNum @v @a
newtype ABP f a = ABP { forall (f :: * -> *) a. ABP f a -> f a
runABP :: f a }
deriving (Int -> ABP f a -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (f :: * -> *) a. Show (f a) => Int -> ABP f a -> ShowS
forall (f :: * -> *) a. Show (f a) => [ABP f a] -> ShowS
forall (f :: * -> *) a. Show (f a) => ABP f a -> String
showList :: [ABP f a] -> ShowS
$cshowList :: forall (f :: * -> *) a. Show (f a) => [ABP f a] -> ShowS
show :: ABP f a -> String
$cshow :: forall (f :: * -> *) a. Show (f a) => ABP f a -> String
showsPrec :: Int -> ABP f a -> ShowS
$cshowsPrec :: forall (f :: * -> *) a. Show (f a) => Int -> ABP f a -> ShowS
Show, ReadPrec [ABP f a]
ReadPrec (ABP f a)
ReadS [ABP f a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall (f :: * -> *) a. Read (f a) => ReadPrec [ABP f a]
forall (f :: * -> *) a. Read (f a) => ReadPrec (ABP f a)
forall (f :: * -> *) a. Read (f a) => Int -> ReadS (ABP f a)
forall (f :: * -> *) a. Read (f a) => ReadS [ABP f a]
readListPrec :: ReadPrec [ABP f a]
$creadListPrec :: forall (f :: * -> *) a. Read (f a) => ReadPrec [ABP f a]
readPrec :: ReadPrec (ABP f a)
$creadPrec :: forall (f :: * -> *) a. Read (f a) => ReadPrec (ABP f a)
readList :: ReadS [ABP f a]
$creadList :: forall (f :: * -> *) a. Read (f a) => ReadS [ABP f a]
readsPrec :: Int -> ReadS (ABP f a)
$creadsPrec :: forall (f :: * -> *) a. Read (f a) => Int -> ReadS (ABP f a)
Read, ABP f a -> ABP f a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (f :: * -> *) a. Eq (f a) => ABP f a -> ABP f a -> Bool
/= :: ABP f a -> ABP f a -> Bool
$c/= :: forall (f :: * -> *) a. Eq (f a) => ABP f a -> ABP f a -> Bool
== :: ABP f a -> ABP f a -> Bool
$c== :: forall (f :: * -> *) a. Eq (f a) => ABP f a -> ABP f a -> Bool
Eq, ABP f a -> ABP f a -> Bool
ABP f a -> ABP f a -> Ordering
ABP f a -> ABP f a -> ABP f a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {f :: * -> *} {a}. Ord (f a) => Eq (ABP f a)
forall (f :: * -> *) a. Ord (f a) => ABP f a -> ABP f a -> Bool
forall (f :: * -> *) a. Ord (f a) => ABP f a -> ABP f a -> Ordering
forall (f :: * -> *) a. Ord (f a) => ABP f a -> ABP f a -> ABP f a
min :: ABP f a -> ABP f a -> ABP f a
$cmin :: forall (f :: * -> *) a. Ord (f a) => ABP f a -> ABP f a -> ABP f a
max :: ABP f a -> ABP f a -> ABP f a
$cmax :: forall (f :: * -> *) a. Ord (f a) => ABP f a -> ABP f a -> ABP f a
>= :: ABP f a -> ABP f a -> Bool
$c>= :: forall (f :: * -> *) a. Ord (f a) => ABP f a -> ABP f a -> Bool
> :: ABP f a -> ABP f a -> Bool
$c> :: forall (f :: * -> *) a. Ord (f a) => ABP f a -> ABP f a -> Bool
<= :: ABP f a -> ABP f a -> Bool
$c<= :: forall (f :: * -> *) a. Ord (f a) => ABP f a -> ABP f a -> Bool
< :: ABP f a -> ABP f a -> Bool
$c< :: forall (f :: * -> *) a. Ord (f a) => ABP f a -> ABP f a -> Bool
compare :: ABP f a -> ABP f a -> Ordering
$ccompare :: forall (f :: * -> *) a. Ord (f a) => ABP f a -> ABP f a -> Ordering
Ord, Typeable, ABP f a -> DataType
ABP f a -> Constr
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ABP f a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ABP f a -> c (ABP f a)
forall {f :: * -> *} {a}.
(Typeable f, Typeable a, Data (f a)) =>
Typeable (ABP f a)
forall (f :: * -> *) a.
(Typeable f, Typeable a, Data (f a)) =>
ABP f a -> DataType
forall (f :: * -> *) a.
(Typeable f, Typeable a, Data (f a)) =>
ABP f a -> Constr
forall (f :: * -> *) a.
(Typeable f, Typeable a, Data (f a)) =>
(forall b. Data b => b -> b) -> ABP f a -> ABP f a
forall (f :: * -> *) a u.
(Typeable f, Typeable a, Data (f a)) =>
Int -> (forall d. Data d => d -> u) -> ABP f a -> u
forall (f :: * -> *) a u.
(Typeable f, Typeable a, Data (f a)) =>
(forall d. Data d => d -> u) -> ABP f a -> [u]
forall (f :: * -> *) a r r'.
(Typeable f, Typeable a, Data (f a)) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ABP f a -> r
forall (f :: * -> *) a r r'.
(Typeable f, Typeable a, Data (f a)) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ABP f a -> r
forall (f :: * -> *) a (m :: * -> *).
(Typeable f, Typeable a, Data (f a), Monad m) =>
(forall d. Data d => d -> m d) -> ABP f a -> m (ABP f a)
forall (f :: * -> *) a (m :: * -> *).
(Typeable f, Typeable a, Data (f a), MonadPlus m) =>
(forall d. Data d => d -> m d) -> ABP f a -> m (ABP f a)
forall (f :: * -> *) a (c :: * -> *).
(Typeable f, Typeable a, Data (f a)) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ABP f a)
forall (f :: * -> *) a (c :: * -> *).
(Typeable f, Typeable a, Data (f a)) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ABP f a -> c (ABP f a)
forall (f :: * -> *) a (t :: * -> *) (c :: * -> *).
(Typeable f, Typeable a, Data (f a), Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ABP f a))
forall (f :: * -> *) a (t :: * -> * -> *) (c :: * -> *).
(Typeable f, Typeable a, Data (f a), Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (ABP f a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ABP f a -> m (ABP f a)
$cgmapMo :: forall (f :: * -> *) a (m :: * -> *).
(Typeable f, Typeable a, Data (f a), MonadPlus m) =>
(forall d. Data d => d -> m d) -> ABP f a -> m (ABP f a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ABP f a -> m (ABP f a)
$cgmapMp :: forall (f :: * -> *) a (m :: * -> *).
(Typeable f, Typeable a, Data (f a), MonadPlus m) =>
(forall d. Data d => d -> m d) -> ABP f a -> m (ABP f a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ABP f a -> m (ABP f a)
$cgmapM :: forall (f :: * -> *) a (m :: * -> *).
(Typeable f, Typeable a, Data (f a), Monad m) =>
(forall d. Data d => d -> m d) -> ABP f a -> m (ABP f a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ABP f a -> u
$cgmapQi :: forall (f :: * -> *) a u.
(Typeable f, Typeable a, Data (f a)) =>
Int -> (forall d. Data d => d -> u) -> ABP f a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> ABP f a -> [u]
$cgmapQ :: forall (f :: * -> *) a u.
(Typeable f, Typeable a, Data (f a)) =>
(forall d. Data d => d -> u) -> ABP f a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ABP f a -> r
$cgmapQr :: forall (f :: * -> *) a r r'.
(Typeable f, Typeable a, Data (f a)) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ABP f a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ABP f a -> r
$cgmapQl :: forall (f :: * -> *) a r r'.
(Typeable f, Typeable a, Data (f a)) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ABP f a -> r
gmapT :: (forall b. Data b => b -> b) -> ABP f a -> ABP f a
$cgmapT :: forall (f :: * -> *) a.
(Typeable f, Typeable a, Data (f a)) =>
(forall b. Data b => b -> b) -> ABP f a -> ABP f a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (ABP f a))
$cdataCast2 :: forall (f :: * -> *) a (t :: * -> * -> *) (c :: * -> *).
(Typeable f, Typeable a, Data (f a), Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (ABP f a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (ABP f a))
$cdataCast1 :: forall (f :: * -> *) a (t :: * -> *) (c :: * -> *).
(Typeable f, Typeable a, Data (f a), Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ABP f a))
dataTypeOf :: ABP f a -> DataType
$cdataTypeOf :: forall (f :: * -> *) a.
(Typeable f, Typeable a, Data (f a)) =>
ABP f a -> DataType
toConstr :: ABP f a -> Constr
$ctoConstr :: forall (f :: * -> *) a.
(Typeable f, Typeable a, Data (f a)) =>
ABP f a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ABP f a)
$cgunfold :: forall (f :: * -> *) a (c :: * -> *).
(Typeable f, Typeable a, Data (f a)) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ABP f a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ABP f a -> c (ABP f a)
$cgfoldl :: forall (f :: * -> *) a (c :: * -> *).
(Typeable f, Typeable a, Data (f a)) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ABP f a -> c (ABP f a)
Data, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (f :: * -> *) a x. Rep (ABP f a) x -> ABP f a
forall (f :: * -> *) a x. ABP f a -> Rep (ABP f a) x
$cto :: forall (f :: * -> *) a x. Rep (ABP f a) x -> ABP f a
$cfrom :: forall (f :: * -> *) a x. ABP f a -> Rep (ABP f a) x
Generic, forall a b. a -> ABP f b -> ABP f a
forall a b. (a -> b) -> ABP f a -> ABP f b
forall (f :: * -> *) a b. Functor f => a -> ABP f b -> ABP f a
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> ABP f a -> ABP f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> ABP f b -> ABP f a
$c<$ :: forall (f :: * -> *) a b. Functor f => a -> ABP f b -> ABP f a
fmap :: forall a b. (a -> b) -> ABP f a -> ABP f b
$cfmap :: forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> ABP f a -> ABP f b
Functor, forall a. a -> ABP f a
forall a b. ABP f a -> ABP f b -> ABP f a
forall a b. ABP f a -> ABP f b -> ABP f b
forall a b. ABP f (a -> b) -> ABP f a -> ABP f b
forall a b c. (a -> b -> c) -> ABP f a -> ABP f b -> ABP f c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall {f :: * -> *}. Applicative f => Functor (ABP f)
forall (f :: * -> *) a. Applicative f => a -> ABP f a
forall (f :: * -> *) a b.
Applicative f =>
ABP f a -> ABP f b -> ABP f a
forall (f :: * -> *) a b.
Applicative f =>
ABP f a -> ABP f b -> ABP f b
forall (f :: * -> *) a b.
Applicative f =>
ABP f (a -> b) -> ABP f a -> ABP f b
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> ABP f a -> ABP f b -> ABP f c
<* :: forall a b. ABP f a -> ABP f b -> ABP f a
$c<* :: forall (f :: * -> *) a b.
Applicative f =>
ABP f a -> ABP f b -> ABP f a
*> :: forall a b. ABP f a -> ABP f b -> ABP f b
$c*> :: forall (f :: * -> *) a b.
Applicative f =>
ABP f a -> ABP f b -> ABP f b
liftA2 :: forall a b c. (a -> b -> c) -> ABP f a -> ABP f b -> ABP f c
$cliftA2 :: forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> ABP f a -> ABP f b -> ABP f c
<*> :: forall a b. ABP f (a -> b) -> ABP f a -> ABP f b
$c<*> :: forall (f :: * -> *) a b.
Applicative f =>
ABP f (a -> b) -> ABP f a -> ABP f b
pure :: forall a. a -> ABP f a
$cpure :: forall (f :: * -> *) a. Applicative f => a -> ABP f a
Applicative, forall a. a -> ABP f a
forall a b. ABP f a -> ABP f b -> ABP f b
forall a b. ABP f a -> (a -> ABP f b) -> ABP f b
forall {f :: * -> *}. Monad f => Applicative (ABP f)
forall (f :: * -> *) a. Monad f => a -> ABP f a
forall (f :: * -> *) a b. Monad f => ABP f a -> ABP f b -> ABP f b
forall (f :: * -> *) a b.
Monad f =>
ABP f a -> (a -> ABP f b) -> ABP f b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> ABP f a
$creturn :: forall (f :: * -> *) a. Monad f => a -> ABP f a
>> :: forall a b. ABP f a -> ABP f b -> ABP f b
$c>> :: forall (f :: * -> *) a b. Monad f => ABP f a -> ABP f b -> ABP f b
>>= :: forall a b. ABP f a -> (a -> ABP f b) -> ABP f b
$c>>= :: forall (f :: * -> *) a b.
Monad f =>
ABP f a -> (a -> ABP f b) -> ABP f b
Monad, forall a. ABP f a
forall a. ABP f a -> ABP f [a]
forall a. ABP f a -> ABP f a -> ABP f a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall {f :: * -> *}. Alternative f => Applicative (ABP f)
forall (f :: * -> *) a. Alternative f => ABP f a
forall (f :: * -> *) a. Alternative f => ABP f a -> ABP f [a]
forall (f :: * -> *) a.
Alternative f =>
ABP f a -> ABP f a -> ABP f a
many :: forall a. ABP f a -> ABP f [a]
$cmany :: forall (f :: * -> *) a. Alternative f => ABP f a -> ABP f [a]
some :: forall a. ABP f a -> ABP f [a]
$csome :: forall (f :: * -> *) a. Alternative f => ABP f a -> ABP f [a]
<|> :: forall a. ABP f a -> ABP f a -> ABP f a
$c<|> :: forall (f :: * -> *) a.
Alternative f =>
ABP f a -> ABP f a -> ABP f a
empty :: forall a. ABP f a
$cempty :: forall (f :: * -> *) a. Alternative f => ABP f a
Alternative, forall a. ABP f a
forall a. ABP f a -> ABP f a -> ABP f a
forall {f :: * -> *}. MonadPlus f => Monad (ABP f)
forall {f :: * -> *}. MonadPlus f => Alternative (ABP f)
forall (f :: * -> *) a. MonadPlus f => ABP f a
forall (f :: * -> *) a.
MonadPlus f =>
ABP f a -> ABP f a -> ABP f a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
mplus :: forall a. ABP f a -> ABP f a -> ABP f a
$cmplus :: forall (f :: * -> *) a.
MonadPlus f =>
ABP f a -> ABP f a -> ABP f a
mzero :: forall a. ABP f a
$cmzero :: forall (f :: * -> *) a. MonadPlus f => ABP f a
MonadPlus, forall a. Eq a => a -> ABP f a -> Bool
forall a. Num a => ABP f a -> a
forall a. Ord a => ABP f a -> a
forall m. Monoid m => ABP f m -> m
forall a. ABP f a -> Bool
forall a. ABP f a -> Int
forall a. ABP f a -> [a]
forall a. (a -> a -> a) -> ABP f a -> a
forall m a. Monoid m => (a -> m) -> ABP f a -> m
forall b a. (b -> a -> b) -> b -> ABP f a -> b
forall a b. (a -> b -> b) -> b -> ABP f a -> b
forall (f :: * -> *) a. (Foldable f, Eq a) => a -> ABP f a -> Bool
forall (f :: * -> *) a. (Foldable f, Num a) => ABP f a -> a
forall (f :: * -> *) a. (Foldable f, Ord a) => ABP f a -> a
forall (f :: * -> *) m. (Foldable f, Monoid m) => ABP f m -> m
forall (f :: * -> *) a. Foldable f => ABP f a -> Bool
forall (f :: * -> *) a. Foldable f => ABP f a -> Int
forall (f :: * -> *) a. Foldable f => ABP f a -> [a]
forall (f :: * -> *) a. Foldable f => (a -> a -> a) -> ABP f a -> a
forall (f :: * -> *) m a.
(Foldable f, Monoid m) =>
(a -> m) -> ABP f a -> m
forall (f :: * -> *) b a.
Foldable f =>
(b -> a -> b) -> b -> ABP f a -> b
forall (f :: * -> *) a b.
Foldable f =>
(a -> b -> b) -> b -> ABP f a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => ABP f a -> a
$cproduct :: forall (f :: * -> *) a. (Foldable f, Num a) => ABP f a -> a
sum :: forall a. Num a => ABP f a -> a
$csum :: forall (f :: * -> *) a. (Foldable f, Num a) => ABP f a -> a
minimum :: forall a. Ord a => ABP f a -> a
$cminimum :: forall (f :: * -> *) a. (Foldable f, Ord a) => ABP f a -> a
maximum :: forall a. Ord a => ABP f a -> a
$cmaximum :: forall (f :: * -> *) a. (Foldable f, Ord a) => ABP f a -> a
elem :: forall a. Eq a => a -> ABP f a -> Bool
$celem :: forall (f :: * -> *) a. (Foldable f, Eq a) => a -> ABP f a -> Bool
length :: forall a. ABP f a -> Int
$clength :: forall (f :: * -> *) a. Foldable f => ABP f a -> Int
null :: forall a. ABP f a -> Bool
$cnull :: forall (f :: * -> *) a. Foldable f => ABP f a -> Bool
toList :: forall a. ABP f a -> [a]
$ctoList :: forall (f :: * -> *) a. Foldable f => ABP f a -> [a]
foldl1 :: forall a. (a -> a -> a) -> ABP f a -> a
$cfoldl1 :: forall (f :: * -> *) a. Foldable f => (a -> a -> a) -> ABP f a -> a
foldr1 :: forall a. (a -> a -> a) -> ABP f a -> a
$cfoldr1 :: forall (f :: * -> *) a. Foldable f => (a -> a -> a) -> ABP f a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> ABP f a -> b
$cfoldl' :: forall (f :: * -> *) b a.
Foldable f =>
(b -> a -> b) -> b -> ABP f a -> b
foldl :: forall b a. (b -> a -> b) -> b -> ABP f a -> b
$cfoldl :: forall (f :: * -> *) b a.
Foldable f =>
(b -> a -> b) -> b -> ABP f a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> ABP f a -> b
$cfoldr' :: forall (f :: * -> *) a b.
Foldable f =>
(a -> b -> b) -> b -> ABP f a -> b
foldr :: forall a b. (a -> b -> b) -> b -> ABP f a -> b
$cfoldr :: forall (f :: * -> *) a b.
Foldable f =>
(a -> b -> b) -> b -> ABP f a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> ABP f a -> m
$cfoldMap' :: forall (f :: * -> *) m a.
(Foldable f, Monoid m) =>
(a -> m) -> ABP f a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> ABP f a -> m
$cfoldMap :: forall (f :: * -> *) m a.
(Foldable f, Monoid m) =>
(a -> m) -> ABP f a -> m
fold :: forall m. Monoid m => ABP f m -> m
$cfold :: forall (f :: * -> *) m. (Foldable f, Monoid m) => ABP f m -> m
Foldable, forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall {f :: * -> *}. Traversable f => Functor (ABP f)
forall {f :: * -> *}. Traversable f => Foldable (ABP f)
forall (f :: * -> *) (m :: * -> *) a.
(Traversable f, Monad m) =>
ABP f (m a) -> m (ABP f a)
forall (f :: * -> *) (f :: * -> *) a.
(Traversable f, Applicative f) =>
ABP f (f a) -> f (ABP f a)
forall (f :: * -> *) (m :: * -> *) a b.
(Traversable f, Monad m) =>
(a -> m b) -> ABP f a -> m (ABP f b)
forall (f :: * -> *) (f :: * -> *) a b.
(Traversable f, Applicative f) =>
(a -> f b) -> ABP f a -> f (ABP f b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ABP f a -> f (ABP f b)
sequence :: forall (m :: * -> *) a. Monad m => ABP f (m a) -> m (ABP f a)
$csequence :: forall (f :: * -> *) (m :: * -> *) a.
(Traversable f, Monad m) =>
ABP f (m a) -> m (ABP f a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ABP f a -> m (ABP f b)
$cmapM :: forall (f :: * -> *) (m :: * -> *) a b.
(Traversable f, Monad m) =>
(a -> m b) -> ABP f a -> m (ABP f b)
sequenceA :: forall (f :: * -> *) a. Applicative f => ABP f (f a) -> f (ABP f a)
$csequenceA :: forall (f :: * -> *) (f :: * -> *) a.
(Traversable f, Applicative f) =>
ABP f (f a) -> f (ABP f a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ABP f a -> f (ABP f b)
$ctraverse :: forall (f :: * -> *) (f :: * -> *) a b.
(Traversable f, Applicative f) =>
(a -> f b) -> ABP f a -> f (ABP f b)
Traversable)
instance NFData (f a) => NFData (ABP f a)
instance (Applicative f, Backprop a) => Backprop (ABP f a) where
zero :: ABP f a -> ABP f a
zero = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Backprop a => a -> a
zero
{-# INLINE zero #-}
add :: ABP f a -> ABP f a -> ABP f a
add = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Backprop a => a -> a -> a
add
{-# INLINE add #-}
one :: ABP f a -> ABP f a
one = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Backprop a => a -> a
one
{-# INLINE one #-}
instance (Applicative f, Num a) => Num (ABP f a) where
+ :: ABP f a -> ABP f a -> ABP f a
(+) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Num a => a -> a -> a
(+)
{-# INLINE (+) #-}
(-) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (-)
{-# INLINE (-) #-}
* :: ABP f a -> ABP f a -> ABP f a
(*) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Num a => a -> a -> a
(*)
{-# INLINE (*) #-}
negate :: ABP f a -> ABP f a
negate = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Num a => a -> a
negate
{-# INLINE negate #-}
abs :: ABP f a -> ABP f a
abs = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Num a => a -> a
abs
{-# INLINE abs #-}
signum :: ABP f a -> ABP f a
signum = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Num a => a -> a
signum
{-# INLINE signum #-}
fromInteger :: Integer -> ABP f a
fromInteger = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => Integer -> a
fromInteger
{-# INLINE fromInteger #-}
instance (Applicative f, Fractional a) => Fractional (ABP f a) where
/ :: ABP f a -> ABP f a -> ABP f a
(/) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Fractional a => a -> a -> a
(/)
{-# INLINE (/) #-}
recip :: ABP f a -> ABP f a
recip = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Fractional a => a -> a
recip
{-# INLINE recip #-}
fromRational :: Rational -> ABP f a
fromRational = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Fractional a => Rational -> a
fromRational
{-# INLINE fromRational #-}
instance (Applicative f, Floating a) => Floating (ABP f a) where
pi :: ABP f a
pi = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Floating a => a
pi
{-# INLINE pi #-}
exp :: ABP f a -> ABP f a
exp = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
exp
{-# INLINE exp #-}
log :: ABP f a -> ABP f a
log = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
log
{-# INLINE log #-}
sqrt :: ABP f a -> ABP f a
sqrt = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
sqrt
{-# INLINE sqrt #-}
** :: ABP f a -> ABP f a -> ABP f a
(**) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Floating a => a -> a -> a
(**)
{-# INLINE (**) #-}
logBase :: ABP f a -> ABP f a -> ABP f a
logBase = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Floating a => a -> a -> a
logBase
{-# INLINE logBase #-}
sin :: ABP f a -> ABP f a
sin = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
sin
{-# INLINE sin #-}
cos :: ABP f a -> ABP f a
cos = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
cos
{-# INLINE cos #-}
tan :: ABP f a -> ABP f a
tan = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
tan
{-# INLINE tan #-}
asin :: ABP f a -> ABP f a
asin = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
asin
{-# INLINE asin #-}
acos :: ABP f a -> ABP f a
acos = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
acos
{-# INLINE acos #-}
atan :: ABP f a -> ABP f a
atan = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
atan
{-# INLINE atan #-}
sinh :: ABP f a -> ABP f a
sinh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
sinh
{-# INLINE sinh #-}
cosh :: ABP f a -> ABP f a
cosh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
cosh
{-# INLINE cosh #-}
tanh :: ABP f a -> ABP f a
tanh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
tanh
{-# INLINE tanh #-}
asinh :: ABP f a -> ABP f a
asinh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
asinh
{-# INLINE asinh #-}
acosh :: ABP f a -> ABP f a
acosh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
acosh
{-# INLINE acosh #-}
atanh :: ABP f a -> ABP f a
atanh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
atanh
{-# INLINE atanh #-}
class GZero f where
gzero :: f t -> f t
instance Backprop a => GZero (K1 i a) where
gzero :: forall t. K1 i a t -> K1 i a t
gzero (K1 a
x) = forall k i c (p :: k). c -> K1 i c p
K1 (forall a. Backprop a => a -> a
zero a
x)
{-# INLINE gzero #-}
instance (GZero f, GZero g) => GZero (f :*: g) where
gzero :: forall t. (:*:) f g t -> (:*:) f g t
gzero (f t
x :*: g t
y) = forall (f :: * -> *) t. GZero f => f t -> f t
gzero f t
x forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: forall (f :: * -> *) t. GZero f => f t -> f t
gzero g t
y
{-# INLINE gzero #-}
instance (GZero f, GZero g) => GZero (f :+: g) where
gzero :: forall t. (:+:) f g t -> (:+:) f g t
gzero (L1 f t
x) = forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 (forall (f :: * -> *) t. GZero f => f t -> f t
gzero f t
x)
gzero (R1 g t
x) = forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (forall (f :: * -> *) t. GZero f => f t -> f t
gzero g t
x)
{-# INLINE gzero #-}
instance GZero V1 where
gzero :: forall t. V1 t -> V1 t
gzero = \case {}
{-# INLINE gzero #-}
instance GZero U1 where
gzero :: forall t. U1 t -> U1 t
gzero U1 t
_ = forall k (p :: k). U1 p
U1
{-# INLINE gzero #-}
instance GZero f => GZero (M1 i c f) where
gzero :: forall t. M1 i c f t -> M1 i c f t
gzero (M1 f t
x) = forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (forall (f :: * -> *) t. GZero f => f t -> f t
gzero f t
x)
{-# INLINE gzero #-}
instance GZero f => GZero (f :.: g) where
gzero :: forall t. (:.:) f g t -> (:.:) f g t
gzero (Comp1 f (g t)
x) = forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
f (g p) -> (:.:) f g p
Comp1 (forall (f :: * -> *) t. GZero f => f t -> f t
gzero f (g t)
x)
{-# INLINE gzero #-}
class GAdd f where
gadd :: f t -> f t -> f t
instance Backprop a => GAdd (K1 i a) where
gadd :: forall t. K1 i a t -> K1 i a t -> K1 i a t
gadd (K1 a
x) (K1 a
y) = forall k i c (p :: k). c -> K1 i c p
K1 (forall a. Backprop a => a -> a -> a
add a
x a
y)
{-# INLINE gadd #-}
instance (GAdd f, GAdd g) => GAdd (f :*: g) where
gadd :: forall t. (:*:) f g t -> (:*:) f g t -> (:*:) f g t
gadd (f t
x1 :*: g t
y1) (f t
x2 :*: g t
y2) = f t
x3 forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: g t
y3
where
!x3 :: f t
x3 = forall (f :: * -> *) t. GAdd f => f t -> f t -> f t
gadd f t
x1 f t
x2
!y3 :: g t
y3 = forall (f :: * -> *) t. GAdd f => f t -> f t -> f t
gadd g t
y1 g t
y2
{-# INLINE gadd #-}
instance GAdd V1 where
gadd :: forall t. V1 t -> V1 t -> V1 t
gadd = \case {}
{-# INLINE gadd #-}
instance GAdd U1 where
gadd :: forall t. U1 t -> U1 t -> U1 t
gadd U1 t
_ U1 t
_ = forall k (p :: k). U1 p
U1
{-# INLINE gadd #-}
instance GAdd f => GAdd (M1 i c f) where
gadd :: forall t. M1 i c f t -> M1 i c f t -> M1 i c f t
gadd (M1 f t
x) (M1 f t
y) = forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (forall (f :: * -> *) t. GAdd f => f t -> f t -> f t
gadd f t
x f t
y)
{-# INLINE gadd #-}
instance GAdd f => GAdd (f :.: g) where
gadd :: forall t. (:.:) f g t -> (:.:) f g t -> (:.:) f g t
gadd (Comp1 f (g t)
x) (Comp1 f (g t)
y) = forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
f (g p) -> (:.:) f g p
Comp1 (forall (f :: * -> *) t. GAdd f => f t -> f t -> f t
gadd f (g t)
x f (g t)
y)
{-# INLINE gadd #-}
class GOne f where
gone :: f t -> f t
instance Backprop a => GOne (K1 i a) where
gone :: forall t. K1 i a t -> K1 i a t
gone (K1 a
x) = forall k i c (p :: k). c -> K1 i c p
K1 (forall a. Backprop a => a -> a
one a
x)
{-# INLINE gone #-}
instance (GOne f, GOne g) => GOne (f :*: g) where
gone :: forall t. (:*:) f g t -> (:*:) f g t
gone (f t
x :*: g t
y) = forall (f :: * -> *) t. GOne f => f t -> f t
gone f t
x forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: forall (f :: * -> *) t. GOne f => f t -> f t
gone g t
y
{-# INLINE gone #-}
instance (GOne f, GOne g) => GOne (f :+: g) where
gone :: forall t. (:+:) f g t -> (:+:) f g t
gone (L1 f t
x) = forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 (forall (f :: * -> *) t. GOne f => f t -> f t
gone f t
x)
gone (R1 g t
x) = forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (forall (f :: * -> *) t. GOne f => f t -> f t
gone g t
x)
{-# INLINE gone #-}
instance GOne V1 where
gone :: forall t. V1 t -> V1 t
gone = \case {}
{-# INLINE gone #-}
instance GOne U1 where
gone :: forall t. U1 t -> U1 t
gone U1 t
_ = forall k (p :: k). U1 p
U1
{-# INLINE gone #-}
instance GOne f => GOne (M1 i c f) where
gone :: forall t. M1 i c f t -> M1 i c f t
gone (M1 f t
x) = forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (forall (f :: * -> *) t. GOne f => f t -> f t
gone f t
x)
{-# INLINE gone #-}
instance GOne f => GOne (f :.: g) where
gone :: forall t. (:.:) f g t -> (:.:) f g t
gone (Comp1 f (g t)
x) = forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
f (g p) -> (:.:) f g p
Comp1 (forall (f :: * -> *) t. GOne f => f t -> f t
gone f (g t)
x)
{-# INLINE gone #-}
instance Backprop Int where
zero :: Int -> Int
zero = forall a. Num a => a -> a
zeroNum
{-# INLINE zero #-}
add :: Int -> Int -> Int
add = forall a. Num a => a -> a -> a
addNum
{-# INLINE add #-}
one :: Int -> Int
one = forall a. Num a => a -> a
oneNum
{-# INLINE one #-}
instance Backprop Integer where
zero :: Integer -> Integer
zero = forall a. Num a => a -> a
zeroNum
{-# INLINE zero #-}
add :: Integer -> Integer -> Integer
add = forall a. Num a => a -> a -> a
addNum
{-# INLINE add #-}
one :: Integer -> Integer
one = forall a. Num a => a -> a
oneNum
{-# INLINE one #-}
instance Backprop Natural where
zero :: Natural -> Natural
zero = forall a. Num a => a -> a
zeroNum
{-# INLINE zero #-}
add :: Natural -> Natural -> Natural
add = forall a. Num a => a -> a -> a
addNum
{-# INLINE add #-}
one :: Natural -> Natural
one = forall a. Num a => a -> a
oneNum
{-# INLINE one #-}
instance Backprop Word8 where
zero :: Word8 -> Word8
zero = forall a. Num a => a -> a
zeroNum
{-# INLINE zero #-}
add :: Word8 -> Word8 -> Word8
add = forall a. Num a => a -> a -> a
addNum
{-# INLINE add #-}
one :: Word8 -> Word8
one = forall a. Num a => a -> a
oneNum
{-# INLINE one #-}
instance Backprop Word where
zero :: Word -> Word
zero = forall a. Num a => a -> a
zeroNum
{-# INLINE zero #-}
add :: Word -> Word -> Word
add = forall a. Num a => a -> a -> a
addNum
{-# INLINE add #-}
one :: Word -> Word
one = forall a. Num a => a -> a
oneNum
{-# INLINE one #-}
instance Backprop Word16 where
zero :: Word16 -> Word16
zero = forall a. Num a => a -> a
zeroNum
{-# INLINE zero #-}
add :: Word16 -> Word16 -> Word16
add = forall a. Num a => a -> a -> a
addNum
{-# INLINE add #-}
one :: Word16 -> Word16
one = forall a. Num a => a -> a
oneNum
{-# INLINE one #-}
instance Backprop Word32 where
zero :: Word32 -> Word32
zero = forall a. Num a => a -> a
zeroNum
{-# INLINE zero #-}
add :: Word32 -> Word32 -> Word32
add = forall a. Num a => a -> a -> a
addNum
{-# INLINE add #-}
one :: Word32 -> Word32
one = forall a. Num a => a -> a
oneNum
{-# INLINE one #-}
instance Backprop Word64 where
zero :: Word64 -> Word64
zero = forall a. Num a => a -> a
zeroNum
{-# INLINE zero #-}
add :: Word64 -> Word64 -> Word64
add = forall a. Num a => a -> a -> a
addNum
{-# INLINE add #-}
one :: Word64 -> Word64
one = forall a. Num a => a -> a
oneNum
{-# INLINE one #-}
instance Integral a => Backprop (Ratio a) where
zero :: Ratio a -> Ratio a
zero = forall a. Num a => a -> a
zeroNum
{-# INLINE zero #-}
add :: Ratio a -> Ratio a -> Ratio a
add = forall a. Num a => a -> a -> a
addNum
{-# INLINE add #-}
one :: Ratio a -> Ratio a
one = forall a. Num a => a -> a
oneNum
{-# INLINE one #-}
instance RealFloat a => Backprop (Complex a) where
zero :: Complex a -> Complex a
zero = forall a. Num a => a -> a
zeroNum
{-# INLINE zero #-}
add :: Complex a -> Complex a -> Complex a
add = forall a. Num a => a -> a -> a
addNum
{-# INLINE add #-}
one :: Complex a -> Complex a
one = forall a. Num a => a -> a
oneNum
{-# INLINE one #-}
instance Backprop Float where
zero :: Float -> Float
zero = forall a. Num a => a -> a
zeroNum
{-# INLINE zero #-}
add :: Float -> Float -> Float
add = forall a. Num a => a -> a -> a
addNum
{-# INLINE add #-}
one :: Float -> Float
one = forall a. Num a => a -> a
oneNum
{-# INLINE one #-}
instance Backprop Double where
zero :: Double -> Double
zero = forall a. Num a => a -> a
zeroNum
{-# INLINE zero #-}
add :: Double -> Double -> Double
add = forall a. Num a => a -> a -> a
addNum
{-# INLINE add #-}
one :: Double -> Double
one = forall a. Num a => a -> a
oneNum
{-# INLINE one #-}
instance Backprop a => Backprop (V.Vector a) where
zero :: Vector a -> Vector a
zero = forall (v :: * -> *) a. (Vector v a, Backprop a) => v a -> v a
zeroVec
{-# INLINE zero #-}
add :: Vector a -> Vector a -> Vector a
add = forall (v :: * -> *) a.
(Vector v a, Backprop a) =>
v a -> v a -> v a
addVec
{-# INLINE add #-}
one :: Vector a -> Vector a
one = forall (v :: * -> *) a. (Vector v a, Backprop a) => v a -> v a
oneVec
{-# INLINE one #-}
instance (VU.Unbox a, Backprop a) => Backprop (VU.Vector a) where
zero :: Vector a -> Vector a
zero = forall (v :: * -> *) a. (Vector v a, Backprop a) => v a -> v a
zeroVec
{-# INLINE zero #-}
add :: Vector a -> Vector a -> Vector a
add = forall (v :: * -> *) a.
(Vector v a, Backprop a) =>
v a -> v a -> v a
addVec
{-# INLINE add #-}
one :: Vector a -> Vector a
one = forall (v :: * -> *) a. (Vector v a, Backprop a) => v a -> v a
oneVec
{-# INLINE one #-}
instance (VS.Storable a, Backprop a) => Backprop (VS.Vector a) where
zero :: Vector a -> Vector a
zero = forall (v :: * -> *) a. (Vector v a, Backprop a) => v a -> v a
zeroVec
{-# INLINE zero #-}
add :: Vector a -> Vector a -> Vector a
add = forall (v :: * -> *) a.
(Vector v a, Backprop a) =>
v a -> v a -> v a
addVec
{-# INLINE add #-}
one :: Vector a -> Vector a
one = forall (v :: * -> *) a. (Vector v a, Backprop a) => v a -> v a
oneVec
{-# INLINE one #-}
instance (VP.Prim a, Backprop a) => Backprop (VP.Vector a) where
zero :: Vector a -> Vector a
zero = forall (v :: * -> *) a. (Vector v a, Backprop a) => v a -> v a
zeroVec
{-# INLINE zero #-}
add :: Vector a -> Vector a -> Vector a
add = forall (v :: * -> *) a.
(Vector v a, Backprop a) =>
v a -> v a -> v a
addVec
{-# INLINE add #-}
one :: Vector a -> Vector a
one = forall (v :: * -> *) a. (Vector v a, Backprop a) => v a -> v a
oneVec
{-# INLINE one #-}
instance Backprop a => Backprop [a] where
zero :: [a] -> [a]
zero = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
zeroFunctor
{-# INLINE zero #-}
add :: [a] -> [a] -> [a]
add = forall a. (IsList a, Backprop (Item a)) => a -> a -> a
addIsList
{-# INLINE add #-}
one :: [a] -> [a]
one = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
oneFunctor
{-# INLINE one #-}
instance Backprop a => Backprop (NonEmpty a) where
zero :: NonEmpty a -> NonEmpty a
zero = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
zeroFunctor
{-# INLINE zero #-}
add :: NonEmpty a -> NonEmpty a -> NonEmpty a
add = forall a. (IsList a, Backprop (Item a)) => a -> a -> a
addIsList
{-# INLINE add #-}
one :: NonEmpty a -> NonEmpty a
one = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
oneFunctor
{-# INLINE one #-}
instance Backprop a => Backprop (Seq.Seq a) where
zero :: Seq a -> Seq a
zero = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
zeroFunctor
{-# INLINE zero #-}
add :: Seq a -> Seq a -> Seq a
add = forall a. (IsList a, Backprop (Item a)) => a -> a -> a
addIsList
{-# INLINE add #-}
one :: Seq a -> Seq a
one = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
oneFunctor
{-# INLINE one #-}
instance Backprop a => Backprop (Maybe a) where
zero :: Maybe a -> Maybe a
zero = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
zeroFunctor
{-# INLINE zero #-}
add :: Maybe a -> Maybe a -> Maybe a
add Maybe a
x Maybe a
y = forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum [ forall a. Backprop a => a -> a -> a
add forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
x forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe a
y
, Maybe a
x
, Maybe a
y
]
{-# INLINE add #-}
one :: Maybe a -> Maybe a
one = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
oneFunctor
{-# INLINE one #-}
instance Backprop () where
zero :: () -> ()
zero ()
_ = ()
add :: () -> () -> ()
add () () = ()
one :: () -> ()
one ()
_ = ()
instance (Backprop a, Backprop b) => Backprop (a, b) where
zero :: (a, b) -> (a, b)
zero (a
x, b
y) = (forall a. Backprop a => a -> a
zero a
x, forall a. Backprop a => a -> a
zero b
y)
{-# INLINE zero #-}
add :: (a, b) -> (a, b) -> (a, b)
add (a
x1, b
y1) (a
x2, b
y2) = (a
x3, b
y3)
where
!x3 :: a
x3 = forall a. Backprop a => a -> a -> a
add a
x1 a
x2
!y3 :: b
y3 = forall a. Backprop a => a -> a -> a
add b
y1 b
y2
{-# INLINE add #-}
one :: (a, b) -> (a, b)
one (a
x, b
y) = (forall a. Backprop a => a -> a
one a
x, forall a. Backprop a => a -> a
one b
y)
{-# INLINE one #-}
instance (Backprop a, Backprop b, Backprop c) => Backprop (a, b, c) where
zero :: (a, b, c) -> (a, b, c)
zero (a
x, b
y, c
z) = (forall a. Backprop a => a -> a
zero a
x, forall a. Backprop a => a -> a
zero b
y, forall a. Backprop a => a -> a
zero c
z)
{-# INLINE zero #-}
add :: (a, b, c) -> (a, b, c) -> (a, b, c)
add (a
x1, b
y1, c
z1) (a
x2, b
y2, c
z2) = (a
x3, b
y3, c
z3)
where
!x3 :: a
x3 = forall a. Backprop a => a -> a -> a
add a
x1 a
x2
!y3 :: b
y3 = forall a. Backprop a => a -> a -> a
add b
y1 b
y2
!z3 :: c
z3 = forall a. Backprop a => a -> a -> a
add c
z1 c
z2
{-# INLINE add #-}
one :: (a, b, c) -> (a, b, c)
one (a
x, b
y, c
z) = (forall a. Backprop a => a -> a
one a
x, forall a. Backprop a => a -> a
one b
y, forall a. Backprop a => a -> a
one c
z)
{-# INLINE one #-}
instance (Backprop a, Backprop b, Backprop c, Backprop d) => Backprop (a, b, c, d) where
zero :: (a, b, c, d) -> (a, b, c, d)
zero (a
x, b
y, c
z, d
w) = (forall a. Backprop a => a -> a
zero a
x, forall a. Backprop a => a -> a
zero b
y, forall a. Backprop a => a -> a
zero c
z, forall a. Backprop a => a -> a
zero d
w)
{-# INLINE zero #-}
add :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d)
add (a
x1, b
y1, c
z1, d
w1) (a
x2, b
y2, c
z2, d
w2) = (a
x3, b
y3, c
z3, d
w3)
where
!x3 :: a
x3 = forall a. Backprop a => a -> a -> a
add a
x1 a
x2
!y3 :: b
y3 = forall a. Backprop a => a -> a -> a
add b
y1 b
y2
!z3 :: c
z3 = forall a. Backprop a => a -> a -> a
add c
z1 c
z2
!w3 :: d
w3 = forall a. Backprop a => a -> a -> a
add d
w1 d
w2
{-# INLINE add #-}
one :: (a, b, c, d) -> (a, b, c, d)
one (a
x, b
y, c
z, d
w) = (forall a. Backprop a => a -> a
one a
x, forall a. Backprop a => a -> a
one b
y, forall a. Backprop a => a -> a
one c
z, forall a. Backprop a => a -> a
one d
w)
{-# INLINE one #-}
instance (Backprop a, Backprop b, Backprop c, Backprop d, Backprop e) => Backprop (a, b, c, d, e) where
zero :: (a, b, c, d, e) -> (a, b, c, d, e)
zero (a
x, b
y, c
z, d
w, e
v) = (forall a. Backprop a => a -> a
zero a
x, forall a. Backprop a => a -> a
zero b
y, forall a. Backprop a => a -> a
zero c
z, forall a. Backprop a => a -> a
zero d
w, forall a. Backprop a => a -> a
zero e
v)
{-# INLINE zero #-}
add :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e)
add (a
x1, b
y1, c
z1, d
w1, e
v1) (a
x2, b
y2, c
z2, d
w2, e
v2) = (a
x3, b
y3, c
z3, d
w3, e
v3)
where
!x3 :: a
x3 = forall a. Backprop a => a -> a -> a
add a
x1 a
x2
!y3 :: b
y3 = forall a. Backprop a => a -> a -> a
add b
y1 b
y2
!z3 :: c
z3 = forall a. Backprop a => a -> a -> a
add c
z1 c
z2
!w3 :: d
w3 = forall a. Backprop a => a -> a -> a
add d
w1 d
w2
!v3 :: e
v3 = forall a. Backprop a => a -> a -> a
add e
v1 e
v2
{-# INLINE add #-}
one :: (a, b, c, d, e) -> (a, b, c, d, e)
one (a
x, b
y, c
z, d
w, e
v) = (forall a. Backprop a => a -> a
one a
x, forall a. Backprop a => a -> a
one b
y, forall a. Backprop a => a -> a
one c
z, forall a. Backprop a => a -> a
one d
w, forall a. Backprop a => a -> a
one e
v)
{-# INLINE one #-}
instance Backprop a => Backprop (Identity a) where
zero :: Identity a -> Identity a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @a)
add :: Identity a -> Identity a -> Identity a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @a)
one :: Identity a -> Identity a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @a)
instance Backprop (Proxy a) where
zero :: Proxy a -> Proxy a
zero Proxy a
_ = forall {k} (t :: k). Proxy t
Proxy
{-# INLINE zero #-}
add :: Proxy a -> Proxy a -> Proxy a
add Proxy a
_ Proxy a
_ = forall {k} (t :: k). Proxy t
Proxy
{-# INLINE add #-}
one :: Proxy a -> Proxy a
one Proxy a
_ = forall {k} (t :: k). Proxy t
Proxy
{-# INLINE one #-}
instance Backprop w => Backprop (Const w a) where
zero :: Const w a -> Const w a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @w)
add :: Const w a -> Const w a -> Const w a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @w)
one :: Const w a -> Const w a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @w)
instance Backprop Void where
zero :: Void -> Void
zero = \case {}
{-# INLINE zero #-}
add :: Void -> Void -> Void
add = \case {}
{-# INLINE add #-}
one :: Void -> Void
one = \case {}
{-# INLINE one #-}
instance (Backprop a, Ord k) => Backprop (M.Map k a) where
zero :: Map k a -> Map k a
zero = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
zeroFunctor
{-# INLINE zero #-}
add :: Map k a -> Map k a -> Map k a
add = forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
M.unionWith forall a. Backprop a => a -> a -> a
add
{-# INLINE add #-}
one :: Map k a -> Map k a
one = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
oneFunctor
{-# INLINE one #-}
instance (Backprop a) => Backprop (IM.IntMap a) where
zero :: IntMap a -> IntMap a
zero = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
zeroFunctor
{-# INLINE zero #-}
add :: IntMap a -> IntMap a -> IntMap a
add = forall a. (a -> a -> a) -> IntMap a -> IntMap a -> IntMap a
IM.unionWith forall a. Backprop a => a -> a -> a
add
{-# INLINE add #-}
one :: IntMap a -> IntMap a
one = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
oneFunctor
{-# INLINE one #-}
instance Backprop a => Backprop (K1 i a p) where
zero :: K1 i a p -> K1 i a p
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @a)
add :: K1 i a p -> K1 i a p -> K1 i a p
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @a)
one :: K1 i a p -> K1 i a p
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @a)
instance Backprop (f p) => Backprop (M1 i c f p) where
zero :: M1 i c f p -> M1 i c f p
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @(f p))
add :: M1 i c f p -> M1 i c f p -> M1 i c f p
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @(f p))
one :: M1 i c f p -> M1 i c f p
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @(f p))
instance (Backprop (f p), Backprop (g p)) => Backprop ((f :*: g) p)
instance (Backprop (f (g a))) => Backprop ((f :.: g) a) where
zero :: (:.:) f g a -> (:.:) f g a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @(f (g a)))
add :: (:.:) f g a -> (:.:) f g a -> (:.:) f g a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @(f (g a)))
one :: (:.:) f g a -> (:.:) f g a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @(f (g a)))
instance Backprop (V1 p)
instance Backprop (U1 p)
instance Backprop a => Backprop (Sum a) where
zero :: Sum a -> Sum a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @a)
add :: Sum a -> Sum a -> Sum a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @a)
one :: Sum a -> Sum a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @a)
instance Backprop a => Backprop (Product a) where
zero :: Product a -> Product a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @a)
add :: Product a -> Product a -> Product a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @a)
one :: Product a -> Product a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @a)
#if !MIN_VERSION_base(4,16,0)
instance Backprop a => Backprop (SG.Option a) where
zero = coerce (zero @(Maybe a))
add = coerce (add @(Maybe a))
one = coerce (one @(Maybe a))
#endif
instance Backprop a => Backprop (SG.First a) where
zero :: First a -> First a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @a)
add :: First a -> First a -> First a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @a)
one :: First a -> First a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @a)
instance Backprop a => Backprop (SG.Last a) where
zero :: Last a -> Last a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @a)
add :: Last a -> Last a -> Last a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @a)
one :: Last a -> Last a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @a)
instance Backprop a => Backprop (First a) where
zero :: First a -> First a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @(Maybe a))
add :: First a -> First a -> First a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @(Maybe a))
one :: First a -> First a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @(Maybe a))
instance Backprop a => Backprop (Data.Monoid.Last a) where
zero :: Last a -> Last a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @(Maybe a))
add :: Last a -> Last a -> Last a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @(Maybe a))
one :: Last a -> Last a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @(Maybe a))
instance Backprop a => Backprop (Dual a) where
zero :: Dual a -> Dual a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @a)
add :: Dual a -> Dual a -> Dual a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @a)
one :: Dual a -> Dual a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @a)
instance (Backprop a, Backprop b) => Backprop (SG.Arg a b)
instance (Backprop (f a), Backprop (g a)) => Backprop (DFP.Product f g a)
instance Backprop (f (g a)) => Backprop (Compose f g a) where
zero :: Compose f g a -> Compose f g a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @(f (g a)))
add :: Compose f g a -> Compose f g a -> Compose f g a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @(f (g a)))
one :: Compose f g a -> Compose f g a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @(f (g a)))
instance Backprop a => Backprop (r -> a) where
zero :: (r -> a) -> r -> a
zero = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
zeroFunctor
{-# INLINE zero #-}
add :: (r -> a) -> (r -> a) -> r -> a
add = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Backprop a => a -> a -> a
add
{-# INLINE add #-}
one :: (r -> a) -> r -> a
one = forall (f :: * -> *) a. (Functor f, Backprop a) => f a -> f a
oneFunctor
{-# INLINE one #-}
instance (Backprop a, Applicative m) => Backprop (Arr.Kleisli m r a) where
zero :: Kleisli m r a -> Kleisli m r a
zero (Arr.Kleisli r -> m a
f) = forall (m :: * -> *) a b. (a -> m b) -> Kleisli m a b
Arr.Kleisli ((forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) forall a. Backprop a => a -> a
zero r -> m a
f)
{-# INLINE zero #-}
add :: Kleisli m r a -> Kleisli m r a -> Kleisli m r a
add (Arr.Kleisli r -> m a
f) (Arr.Kleisli r -> m a
g) = forall (m :: * -> *) a b. (a -> m b) -> Kleisli m a b
Arr.Kleisli forall a b. (a -> b) -> a -> b
$ \r
x ->
forall a. Backprop a => a -> a -> a
add forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> r -> m a
f r
x forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> r -> m a
g r
x
{-# INLINE add #-}
one :: Kleisli m r a -> Kleisli m r a
one (Arr.Kleisli r -> m a
f) = forall (m :: * -> *) a b. (a -> m b) -> Kleisli m a b
Arr.Kleisli ((forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) forall a. Backprop a => a -> a
one r -> m a
f)
{-# INLINE one #-}
instance (ReifyConstraint Backprop f rs, RMap rs, RApply rs) => Backprop (Rec f rs) where
zero :: Rec f rs -> Rec f rs
zero = forall {u} (rs :: [u]) (f :: u -> *) (g :: u -> *).
RMap rs =>
(forall (x :: u). f x -> g x) -> Rec f rs -> Rec g rs
rmap (\case V.Compose (Dict f x
x) -> forall a. Backprop a => a -> a
zero f x
x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {u} (c :: * -> Constraint) (f :: u -> *) (rs :: [u]).
ReifyConstraint c f rs =>
Rec f rs -> Rec (Dict c :. f) rs
reifyConstraint @Backprop
{-# INLINE zero #-}
add :: Rec f rs -> Rec f rs -> Rec f rs
add Rec f rs
xs = forall {u} (xs :: [u]) (f :: u -> *) (g :: u -> *) (h :: u -> *).
(RMap xs, RApply xs) =>
(forall (x :: u). f x -> g x -> h x)
-> Rec f xs -> Rec g xs -> Rec h xs
rzipWith (\f x
x -> \case V.Compose (Dict f x
y) -> forall a. Backprop a => a -> a -> a
add f x
x f x
y) Rec f rs
xs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {u} (c :: * -> Constraint) (f :: u -> *) (rs :: [u]).
ReifyConstraint c f rs =>
Rec f rs -> Rec (Dict c :. f) rs
reifyConstraint @Backprop
{-# INLINE add #-}
one :: Rec f rs -> Rec f rs
one = forall {u} (rs :: [u]) (f :: u -> *) (g :: u -> *).
RMap rs =>
(forall (x :: u). f x -> g x) -> Rec f rs -> Rec g rs
rmap (\case V.Compose (Dict f x
x) -> forall a. Backprop a => a -> a
one f x
x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {u} (c :: * -> Constraint) (f :: u -> *) (rs :: [u]).
ReifyConstraint c f rs =>
Rec f rs -> Rec (Dict c :. f) rs
reifyConstraint @Backprop
{-# INLINE one #-}
#if MIN_VERSION_vinyl(0,14,2)
instance (ReifyConstraint Backprop f rs, RMap rs, RApply rs, RecApplicative rs, NatToInt (RLength rs), RPureConstrained (IndexableField rs) rs, ToARec rs)
#else
instance (ReifyConstraint Backprop f rs, RMap rs, RApply rs, RecApplicative rs, NatToInt (RLength rs), RPureConstrained (IndexableField rs) rs)
#endif
=> Backprop (ARec f rs) where
zero :: ARec f rs -> ARec f rs
zero = forall {k} (f :: k -> *) (ts :: [k]).
(NatToInt (RLength ts), ToARec ts) =>
Rec f ts -> ARec f ts
toARec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Backprop a => a -> a
zero forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {u} (f :: u -> *) (ts :: [u]).
(RecApplicative ts, RPureConstrained (IndexableField ts) ts) =>
ARec f ts -> Rec f ts
fromARec
{-# INLINE zero #-}
add :: ARec f rs -> ARec f rs -> ARec f rs
add ARec f rs
xs ARec f rs
ys = forall {k} (f :: k -> *) (ts :: [k]).
(NatToInt (RLength ts), ToARec ts) =>
Rec f ts -> ARec f ts
toARec forall a b. (a -> b) -> a -> b
$ forall a. Backprop a => a -> a -> a
add (forall {u} (f :: u -> *) (ts :: [u]).
(RecApplicative ts, RPureConstrained (IndexableField ts) ts) =>
ARec f ts -> Rec f ts
fromARec ARec f rs
xs) (forall {u} (f :: u -> *) (ts :: [u]).
(RecApplicative ts, RPureConstrained (IndexableField ts) ts) =>
ARec f ts -> Rec f ts
fromARec ARec f rs
ys)
{-# INLINE add #-}
one :: ARec f rs -> ARec f rs
one = forall {k} (f :: k -> *) (ts :: [k]).
(NatToInt (RLength ts), ToARec ts) =>
Rec f ts -> ARec f ts
toARec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Backprop a => a -> a
zero forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {u} (f :: u -> *) (ts :: [u]).
(RecApplicative ts, RPureConstrained (IndexableField ts) ts) =>
ARec f ts -> Rec f ts
fromARec
{-# INLINE one #-}
instance (ReifyConstraint Backprop f rs, RMap rs, RApply rs, VS.Storable (Rec f rs))
=> Backprop (SRec f rs) where
zero :: SRec f rs -> SRec f rs
zero = forall {k} (f :: k -> *) (ts :: [k]).
Storable (Rec f ts) =>
Rec f ts -> SRec f ts
toSRec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Backprop a => a -> a
zero forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {u} (f :: u -> *) (ts :: [u]).
Storable (Rec f ts) =>
SRec f ts -> Rec f ts
fromSRec
{-# INLINE zero #-}
add :: SRec f rs -> SRec f rs -> SRec f rs
add SRec f rs
xs SRec f rs
ys = forall {k} (f :: k -> *) (ts :: [k]).
Storable (Rec f ts) =>
Rec f ts -> SRec f ts
toSRec forall a b. (a -> b) -> a -> b
$ forall a. Backprop a => a -> a -> a
add (forall {u} (f :: u -> *) (ts :: [u]).
Storable (Rec f ts) =>
SRec f ts -> Rec f ts
fromSRec SRec f rs
xs) (forall {u} (f :: u -> *) (ts :: [u]).
Storable (Rec f ts) =>
SRec f ts -> Rec f ts
fromSRec SRec f rs
ys)
{-# INLINE add #-}
one :: SRec f rs -> SRec f rs
one = forall {k} (f :: k -> *) (ts :: [k]).
Storable (Rec f ts) =>
Rec f ts -> SRec f ts
toSRec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Backprop a => a -> a
zero forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {u} (f :: u -> *) (ts :: [u]).
Storable (Rec f ts) =>
SRec f ts -> Rec f ts
fromSRec
{-# INLINE one #-}
instance (ReifyConstraint Backprop f rs, RMap rs, RApply rs, IsoXRec f rs)
=> Backprop (XRec f rs) where
zero :: XRec f rs -> XRec f rs
zero = forall {u} (f :: u -> *) (ts :: [u]).
IsoXRec f ts =>
Rec f ts -> XRec f ts
toXRec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Backprop a => a -> a
zero forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {u} (f :: u -> *) (ts :: [u]).
IsoXRec f ts =>
XRec f ts -> Rec f ts
fromXRec
{-# INLINE zero #-}
add :: XRec f rs -> XRec f rs -> XRec f rs
add XRec f rs
xs XRec f rs
ys = forall {u} (f :: u -> *) (ts :: [u]).
IsoXRec f ts =>
Rec f ts -> XRec f ts
toXRec forall a b. (a -> b) -> a -> b
$ forall a. Backprop a => a -> a -> a
add (forall {u} (f :: u -> *) (ts :: [u]).
IsoXRec f ts =>
XRec f ts -> Rec f ts
fromXRec XRec f rs
xs) (forall {u} (f :: u -> *) (ts :: [u]).
IsoXRec f ts =>
XRec f ts -> Rec f ts
fromXRec XRec f rs
ys)
{-# INLINE add #-}
one :: XRec f rs -> XRec f rs
one = forall {u} (f :: u -> *) (ts :: [u]).
IsoXRec f ts =>
Rec f ts -> XRec f ts
toXRec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Backprop a => a -> a
zero forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {u} (f :: u -> *) (ts :: [u]).
IsoXRec f ts =>
XRec f ts -> Rec f ts
fromXRec
{-# INLINE one #-}
instance Backprop a => Backprop (V.Identity a) where
zero :: Identity a -> Identity a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @a)
add :: Identity a -> Identity a -> Identity a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @a)
one :: Identity a -> Identity a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @a)
instance Backprop a => Backprop (V.Thunk a) where
zero :: Thunk a -> Thunk a
zero (V.Thunk a
x) = forall a. a -> Thunk a
V.Thunk (forall a. Backprop a => a -> a
zero a
x)
add :: Thunk a -> Thunk a -> Thunk a
add (V.Thunk a
x) (V.Thunk a
y) = forall a. a -> Thunk a
V.Thunk (forall a. Backprop a => a -> a -> a
add a
x a
y)
one :: Thunk a -> Thunk a
one (V.Thunk a
x) = forall a. a -> Thunk a
V.Thunk (forall a. Backprop a => a -> a
one a
x)
instance Backprop (op (f a) (g a)) => Backprop (V.Lift op f g a) where
zero :: Lift op f g a -> Lift op f g a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @(op (f a) (g a)))
add :: Lift op f g a -> Lift op f g a -> Lift op f g a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @(op (f a) (g a)))
one :: Lift op f g a -> Lift op f g a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @(op (f a) (g a)))
instance Backprop t => Backprop (V.ElField '(s, t)) where
zero :: ElField '(s, t) -> ElField '(s, t)
zero (V.Field Snd '(s, t)
x) = forall (t :: (Symbol, *)). Snd t -> ElField t
V.Field (forall a. Backprop a => a -> a
zero Snd '(s, t)
x)
add :: ElField '(s, t) -> ElField '(s, t) -> ElField '(s, t)
add (V.Field Snd '(s, t)
x) (V.Field Snd '(s, t)
y) = forall (t :: (Symbol, *)). Snd t -> ElField t
V.Field (forall a. Backprop a => a -> a -> a
add Snd '(s, t)
x Snd '(s, t)
y)
one :: ElField '(s, t) -> ElField '(s, t)
one (V.Field Snd '(s, t)
x) = forall (t :: (Symbol, *)). Snd t -> ElField t
V.Field (forall a. Backprop a => a -> a
one Snd '(s, t)
x)
instance Backprop (f (g a)) => Backprop (V.Compose f g a) where
zero :: Compose f g a -> Compose f g a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @(f (g a)))
add :: Compose f g a -> Compose f g a -> Compose f g a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @(f (g a)))
one :: Compose f g a -> Compose f g a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @(f (g a)))
instance Backprop w => Backprop (V.Const w a) where
zero :: Const w a -> Const w a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @w)
add :: Const w a -> Const w a -> Const w a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @w)
one :: Const w a -> Const w a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @w)
instance Backprop (V.HKD t a) => Backprop (V.XData t a) where
zero :: XData t a -> XData t a
zero = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
zero @(V.HKD t a))
add :: XData t a -> XData t a -> XData t a
add = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a -> a
add @(V.HKD t a))
one :: XData t a -> XData t a
one = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Backprop a => a -> a
one @(V.HKD t a))
instance Backprop (SField field) where
zero :: SField field -> SField field
zero SField field
_ = forall k (field :: k). SField field
SField
add :: SField field -> SField field -> SField field
add SField field
_ SField field
_ = forall k (field :: k). SField field
SField
one :: SField field -> SField field
one SField field
_ = forall k (field :: k). SField field
SField
instance Backprop (Label field) where
zero :: Label field -> Label field
zero Label field
_ = forall (a :: Symbol). Label a
Label
add :: Label field -> Label field -> Label field
add Label field
_ Label field
_ = forall (a :: Symbol). Label a
Label
one :: Label field -> Label field
one Label field
_ = forall (a :: Symbol). Label a
Label