Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing derivatives for asarray #553

Closed
Gattocrucco opened this issue Apr 23, 2020 · 1 comment
Closed

Missing derivatives for asarray #553

Gattocrucco opened this issue Apr 23, 2020 · 1 comment

Comments

@Gattocrucco
Copy link

import autograd
def f(x):
    return autograd.numpy.asarray(x)
g = autograd.elementwise_grad(f)
g(autograd.numpy.arange(3))

Error:

NotImplementedError: VJP of asarray wrt argnums (0,) not defined

Fix:

autograd.extend.defvjp(
    autograd.numpy.asarray,
    lambda ans, *args, **kw: lambda g: g
)

Python version:

Python 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18) 
[Clang 6.0 (clang-600.0.57)] on darwin

Autograd version: 1.3 (installed with pip)

@Gattocrucco
Copy link
Author

In hindsight I understand why the derivatives of asarray are not defined by default, it is because array does additional stuff like searching for boxes in the arguments and it wouldn't be obvious if asarray does the same or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant