
Tangent: Source-To-Source Autodiff for Python - alexbw
https://research.googleblog.com/2017/11/tangent-source-to-source-debuggable.html
======
simonbyrne
No nested differentiation:

    
    
      >>> import tangent
      >>> import numpy as np
      >>> tangent.grad(tangent.grad(np.sin))
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/usr/local/lib/python3.6/site-packages/tangent/grad_util.py", line 178, in grad
          node, namespace = grad_tree(func, wrt, motion, mode, preserve_result, verbose)
        File "/usr/local/lib/python3.6/site-packages/tangent/grad_util.py", line 97, in grad_tree
          namespace.update(six.get_function_globals(func))
      AttributeError: 'numpy.ufunc' object has no attribute '__globals__'

~~~
dbieber
^I get that error with just `tangent.grad(np.sin)`.

So, it's not a nested differentiation problem, so much as a problem with
"ufuncs". If you wrap np.sin in your own function then it takes the gradient
just fine.

def sin(x): return np.sin(x)

negative_sin = tangent.grad(tangent.grad(sin))

~~~
simonbyrne
Ah, good point, thanks!

