This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ForwardDiff | |
goo((x, y, z),) = [x^2*z, x*y*z, abs(z)-y] | |
foo((x, y, z),) = [x^2*z, x*y*z, abs(z)-y] | |
function foo(u::Vector{ForwardDiff.Dual{T,V,P}}) where {T,V,P} | |
# unpack: AoS -> SoA | |
vs = ForwardDiff.value.(u) | |
# you can play with the dimension here, sometimes it makes sense to transpose | |
ps = mapreduce(ForwardDiff.partials, hcat, u) | |
# get f(vs) | |
val = foo(vs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jax | |
from jax import core | |
from graphviz import Digraph | |
import itertools | |
styles = { | |
'const': dict(style='filled', color='goldenrod1'), | |
'invar': dict(color='mediumspringgreen', style='filled'), | |
'outvar': dict(style='filled,dashed', fillcolor='indianred1', color='black'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeSynonymInstances #-} | |
data Dual d = D Float d deriving Show | |
type Float' = Float | |
diff :: (Dual Float' -> Dual Float') -> Float -> Float' | |
diff f x = y' | |
where D y y' = f (D x 1) | |
class VectorSpace v where | |
zero :: v |