{"action":"created","issue":{"url":"https://api.github.com/repos/sympy/sympy/issues/14686","repository_url":"https://api.github.com/repos/sympy/sympy","labels_url":"https://api.github.com/repos/sympy/sympy/issues/14686/labels{/name}","comments_url":"https://api.github.com/repos/sympy/sympy/issues/14686/comments","events_url":"https://api.github.com/repos/sympy/sympy/issues/14686/events","html_url":"https://github.com/sympy/sympy/issues/14686","id":319390533,"number":14686,"title":"Support autograd's numpy in lambdify?","user":{"login":"RJTK","id":6856593,"avatar_url":"https://avatars3.githubusercontent.com/u/6856593?v=4","gravatar_id":"","url":"https://api.github.com/users/RJTK","html_url":"https://github.com/RJTK","followers_url":"https://api.github.com/users/RJTK/followers","following_url":"https://api.github.com/users/RJTK/following{/other_user}","gists_url":"https://api.github.com/users/RJTK/gists{/gist_id}","starred_url":"https://api.github.com/users/RJTK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RJTK/subscriptions","organizations_url":"https://api.github.com/users/RJTK/orgs","repos_url":"https://api.github.com/users/RJTK/repos","events_url":"https://api.github.com/users/RJTK/events{/privacy}","received_events_url":"https://api.github.com/users/RJTK/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-02T02:31:30Z","updated_at":"2018-05-02T02:54:07Z","closed_at":null,"author_association":"NONE","body":"I am generating some numpy code with ``sympy.lambdify``, which I want to be able to be able to use with [autograd](https://github.com/HIPS/autograd).\r\n\r\nautograd, however, requires it's own wrapped version of numpy to work:\r\n\r\n```\r\nfrom sympy import Symbol, Matrix, lambdify\r\nfrom autograd import jacobian\r\n\r\nx = Symbol('x')\r\nf = Matrix([x, x**2])  # Vector function whose jacobian matrix we want to compute\r\nf_lmbda = lambdify(x, f, modules=\"numpy\")\r\nf_jac = jacobian(f_lmbda)\r\n```\r\nCalling e.g. ``f_jac(1.)`` produces\r\n\r\n```\r\n.../lib/python3.6/site-packages/autograd/tracer.py:14: UserWarning: Output seems independent of input.\r\n  warnings.warn(\"Output seems independent of input.\")\r\nOut[141]: \r\narray([[ 0.],\r\n       [ 0.]])\r\n```\r\n\r\nWhich is due to ``lambdify`` using ``numpy`` rather than ``autograd.numpy``.\r\n\r\nI have produced a minimal hack to allow specifying ``modules=autograd.numpy`` in the lambdify function by modifying ``sympy.lambdify.py`` with\r\n\r\n```MODULES = {...,\r\n    \"autograd.numpy\": (AUTOGRAD_NUMPY,\r\n                       AUTOGRAD_NUMPY_DEFAULT,\r\n                       AUTOGRAD_NUMPY_TRANSLATIONS,\r\n                       (\"import_module('autograd.numpy', \"\r\n                        \"__import__kwargs={'fromlist': ('numpy',)})\",)),\r\n...}\r\n```\r\n\r\nwhich forces lambdify to pull in the autograd.numpy namespace.  The same code above then works correctly and produces:\r\n\r\n```\r\nf_lmbda = lambdify(x, f, modules=\"autograd.numpy\")\r\nf_jac = jacobian(f_lmbda)\r\n\r\nIn [149]: f_jac(1.)\r\nOut[149]: \r\narray([[ 1.],\r\n       [ 2.]])\r\n```\r\nas expected.\r\n\r\nIs this a reasonable solution?  Should I create a PR for this?"},"comment":{"url":"https://api.github.com/repos/sympy/sympy/issues/comments/385850535","html_url":"https://github.com/sympy/sympy/issues/14686#issuecomment-385850535","issue_url":"https://api.github.com/repos/sympy/sympy/issues/14686","id":385850535,"user":{"login":"asmeurer","id":71486,"avatar_url":"https://avatars3.githubusercontent.com/u/71486?v=4","gravatar_id":"","url":"https://api.github.com/users/asmeurer","html_url":"https://github.com/asmeurer","followers_url":"https://api.github.com/users/asmeurer/followers","following_url":"https://api.github.com/users/asmeurer/following{/other_user}","gists_url":"https://api.github.com/users/asmeurer/gists{/gist_id}","starred_url":"https://api.github.com/users/asmeurer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asmeurer/subscriptions","organizations_url":"https://api.github.com/users/asmeurer/orgs","repos_url":"https://api.github.com/users/asmeurer/repos","events_url":"https://api.github.com/users/asmeurer/events{/privacy}","received_events_url":"https://api.github.com/users/asmeurer/received_events","type":"User","site_admin":false},"created_at":"2018-05-02T02:54:07Z","updated_at":"2018-05-02T02:54:07Z","author_association":"OWNER","body":"I think that should work. You can add a PR for it. \r\n\r\nI'm curious, what are the advantages of using autograd rather than just taking symbolic derivatives with SymPy? "}}
{"actor":{"display_login":"asmeurer"}}