{"action":"created","comment":{"url":"https://api.github.com/repos/numpy/numpy/pulls/comments/47153999","id":47153999,"diff_hunk":"@@ -1320,6 +1320,201 @@ def gradient(f, *varargs, **kwargs):\n     else:\n         return outvals\n \n+def inplace_sum(items): \n+    \"\"\"\n+    Returns the sum of the elements of a list. \n+    Used in the follwing functions:\n+    divergence,\n+    \"\"\"\n+    it = iter(items)\n+    total = next(it)\n+    for item in it:\n+        total += item\n+    return total\n+\n+\n+def divergence(v,*varargs):\n+    \"\"\"\n+    Return the divergence of an N-dimensional vector field of N \n+    components, each of dimension N.\n+\n+    The divergence is computed using second order accurate central\n+    differences in the interior and either first differences or second\n+    order accurate one-sides (forward or backwards) differences at the\n+    boundaries. The returned gradient hence has the same shape as the\n+    input array.\n+    \n+    Parameters\n+    ----------  \n+    v : list of numpy arrays\n+        Each of these array is the N-dimensional projection of the vector\n+        field on the corresponding axis. \n+    \n+    varargs : scalar or list of scalar, optional\n+        N scalars specifying the sample distances for each dimension,\n+        i.e. `dx`, `dy`, `dz`, ... Default distance: 1.\n+        single scalar specifies sample distance for all dimensions.\n+        if `axis` is given, the number of varargs must equal the number of axes.\n+            \n+    Returns\n+    -------\n+    divergence : numpy array\n+        The output corresponds to the divergence of the input vector field. \n+        This means that the output array has the form \n+        dAx/dx + dAy/dy + dAz/dz + ... for an input vector field \n+        A = (Ax, Ay, Az, ...) up to N dimensions.\n+    \n+    Example\n+    -------\n+    This example shows how the calculated divergence of the 2-D field \n+    (0.5*x**2, -y*x) (whose divergence should be 0 everywhere) returns a 0 array\n+    \n+    >>> import numpy as np\n+    >>> X,Y=np.mgrid[0:2000,0:2000]\n+    >>> a1=0.5*X**2\n+    >>> a2=-Y*X\n+    >>> c=[a1,a2]\n+    >>> d=np.divergence(c)\n+    >>> print d\n+    [[ 0.  0.  0. ...,  0.  0.  0.]\n+     [ 0.  0.  0. ...,  0.  0.  0.]\n+     [ 0.  0.  0. ...,  0.  0.  0.]\n+     ..., \n+     [ 0.  0.  0. ...,  0.  0.  0.]\n+     [ 0.  0.  0. ...,  0.  0.  0.]\n+     [ 0.  0.  0. ...,  0.  0.  0.]\n+    \"\"\"\n+    \n+    N=len(v)\n+    axes = tuple(range(N))\n+    out = inplace_sum([gradient(v[ax],*varargs,axis=ax,edge_order=0)","path":"numpy/lib/function_base.py","position":71,"original_position":71,"commit_id":"87c19b86fac8f2e114b3cae291dc847893704140","original_commit_id":"87c19b86fac8f2e114b3cae291dc847893704140","user":{"login":"mhvk","id":2789820,"avatar_url":"https://avatars.githubusercontent.com/u/2789820?v=3","gravatar_id":"","url":"https://api.github.com/users/mhvk","html_url":"https://github.com/mhvk","followers_url":"https://api.github.com/users/mhvk/followers","following_url":"https://api.github.com/users/mhvk/following{/other_user}","gists_url":"https://api.github.com/users/mhvk/gists{/gist_id}","starred_url":"https://api.github.com/users/mhvk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhvk/subscriptions","organizations_url":"https://api.github.com/users/mhvk/orgs","repos_url":"https://api.github.com/users/mhvk/repos","events_url":"https://api.github.com/users/mhvk/events{/privacy}","received_events_url":"https://api.github.com/users/mhvk/received_events","type":"User","site_admin":false},"body":"No, I just meant to pass on a generator rather than a list to `inplace_sum`, not to the whole function. Here, on line 1390, you are creating a list implicitly, by using the `[` and `]` at the ends; these should be removed.","created_at":"2015-12-09T21:25:04Z","updated_at":"2015-12-09T21:25:04Z","html_url":"https://github.com/numpy/numpy/pull/6727#discussion_r47153999","pull_request_url":"https://api.github.com/repos/numpy/numpy/pulls/6727","_links":{"self":{"href":"https://api.github.com/repos/numpy/numpy/pulls/comments/47153999"},"html":{"href":"https://github.com/numpy/numpy/pull/6727#discussion_r47153999"},"pull_request":{"href":"https://api.github.com/repos/numpy/numpy/pulls/6727"}}},"pull_request":{"url":"https://api.github.com/repos/numpy/numpy/pulls/6727","id":51843411,"html_url":"https://github.com/numpy/numpy/pull/6727","diff_url":"https://github.com/numpy/numpy/pull/6727.diff","patch_url":"https://github.com/numpy/numpy/pull/6727.patch","issue_url":"https://api.github.com/repos/numpy/numpy/issues/6727","number":6727,"state":"open","locked":false,"title":"ENH: added vector operators: divergence, curl and laplacian","user":{"login":"antlarac","id":11930236,"avatar_url":"https://avatars.githubusercontent.com/u/11930236?v=3","gravatar_id":"","url":"https://api.github.com/users/antlarac","html_url":"https://github.com/antlarac","followers_url":"https://api.github.com/users/antlarac/followers","following_url":"https://api.github.com/users/antlarac/following{/other_user}","gists_url":"https://api.github.com/users/antlarac/gists{/gist_id}","starred_url":"https://api.github.com/users/antlarac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antlarac/subscriptions","organizations_url":"https://api.github.com/users/antlarac/orgs","repos_url":"https://api.github.com/users/antlarac/repos","events_url":"https://api.github.com/users/antlarac/events{/privacy}","received_events_url":"https://api.github.com/users/antlarac/received_events","type":"User","site_admin":false},"body":"Hello, yesterday I tried to upload this change but I messed up (sorry, my first time on github). I think I got it right now. In this commit I have included three new functions to /numpy/lib/function_base.py, namely divergence, curl and laplacian. I have been missing these functions when using numpy myself.\r\n\r\nThank you,\r\n\r\nAntonio","created_at":"2015-11-25T20:37:52Z","updated_at":"2015-12-09T21:25:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"38f7a8c10a10187ed91092798a6c42c586aaa97d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/numpy/numpy/pulls/6727/commits","review_comments_url":"https://api.github.com/repos/numpy/numpy/pulls/6727/comments","review_comment_url":"https://api.github.com/repos/numpy/numpy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/6727/comments","statuses_url":"https://api.github.com/repos/numpy/numpy/statuses/87c19b86fac8f2e114b3cae291dc847893704140","head":{"label":"antlarac:NVO","ref":"NVO","sha":"87c19b86fac8f2e114b3cae291dc847893704140","user":{"login":"antlarac","id":11930236,"avatar_url":"https://avatars.githubusercontent.com/u/11930236?v=3","gravatar_id":"","url":"https://api.github.com/users/antlarac","html_url":"https://github.com/antlarac","followers_url":"https://api.github.com/users/antlarac/followers","following_url":"https://api.github.com/users/antlarac/following{/other_user}","gists_url":"https://api.github.com/users/antlarac/gists{/gist_id}","starred_url":"https://api.github.com/users/antlarac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antlarac/subscriptions","organizations_url":"https://api.github.com/users/antlarac/orgs","repos_url":"https://api.github.com/users/antlarac/repos","events_url":"https://api.github.com/users/antlarac/events{/privacy}","received_events_url":"https://api.github.com/users/antlarac/received_events","type":"User","site_admin":false},"repo":{"id":46881244,"name":"numpy","full_name":"antlarac/numpy","owner":{"login":"antlarac","id":11930236,"avatar_url":"https://avatars.githubusercontent.com/u/11930236?v=3","gravatar_id":"","url":"https://api.github.com/users/antlarac","html_url":"https://github.com/antlarac","followers_url":"https://api.github.com/users/antlarac/followers","following_url":"https://api.github.com/users/antlarac/following{/other_user}","gists_url":"https://api.github.com/users/antlarac/gists{/gist_id}","starred_url":"https://api.github.com/users/antlarac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antlarac/subscriptions","organizations_url":"https://api.github.com/users/antlarac/orgs","repos_url":"https://api.github.com/users/antlarac/repos","events_url":"https://api.github.com/users/antlarac/events{/privacy}","received_events_url":"https://api.github.com/users/antlarac/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/antlarac/numpy","description":"Numpy main repository","fork":true,"url":"https://api.github.com/repos/antlarac/numpy","forks_url":"https://api.github.com/repos/antlarac/numpy/forks","keys_url":"https://api.github.com/repos/antlarac/numpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/antlarac/numpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/antlarac/numpy/teams","hooks_url":"https://api.github.com/repos/antlarac/numpy/hooks","issue_events_url":"https://api.github.com/repos/antlarac/numpy/issues/events{/number}","events_url":"https://api.github.com/repos/antlarac/numpy/events","assignees_url":"https://api.github.com/repos/antlarac/numpy/assignees{/user}","branches_url":"https://api.github.com/repos/antlarac/numpy/branches{/branch}","tags_url":"https://api.github.com/repos/antlarac/numpy/tags","blobs_url":"https://api.github.com/repos/antlarac/numpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/antlarac/numpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/antlarac/numpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/antlarac/numpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/antlarac/numpy/statuses/{sha}","languages_url":"https://api.github.com/repos/antlarac/numpy/languages","stargazers_url":"https://api.github.com/repos/antlarac/numpy/stargazers","contributors_url":"https://api.github.com/repos/antlarac/numpy/contributors","subscribers_url":"https://api.github.com/repos/antlarac/numpy/subscribers","subscription_url":"https://api.github.com/repos/antlarac/numpy/subscription","commits_url":"https://api.github.com/repos/antlarac/numpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/antlarac/numpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/antlarac/numpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/antlarac/numpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/antlarac/numpy/contents/{+path}","compare_url":"https://api.github.com/repos/antlarac/numpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/antlarac/numpy/merges","archive_url":"https://api.github.com/repos/antlarac/numpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/antlarac/numpy/downloads","issues_url":"https://api.github.com/repos/antlarac/numpy/issues{/number}","pulls_url":"https://api.github.com/repos/antlarac/numpy/pulls{/number}","milestones_url":"https://api.github.com/repos/antlarac/numpy/milestones{/number}","notifications_url":"https://api.github.com/repos/antlarac/numpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/antlarac/numpy/labels{/name}","releases_url":"https://api.github.com/repos/antlarac/numpy/releases{/id}","created_at":"2015-11-25T19:11:21Z","updated_at":"2015-11-25T19:11:32Z","pushed_at":"2015-12-02T21:47:18Z","git_url":"git://github.com/antlarac/numpy.git","ssh_url":"git@github.com:antlarac/numpy.git","clone_url":"https://github.com/antlarac/numpy.git","svn_url":"https://github.com/antlarac/numpy","homepage":"http://www.numpy.org/","size":42318,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"numpy:master","ref":"master","sha":"e711c9589ea60ac6ca78096906760925a9e216e3","user":{"login":"numpy","id":288276,"avatar_url":"https://avatars.githubusercontent.com/u/288276?v=3","gravatar_id":"","url":"https://api.github.com/users/numpy","html_url":"https://github.com/numpy","followers_url":"https://api.github.com/users/numpy/followers","following_url":"https://api.github.com/users/numpy/following{/other_user}","gists_url":"https://api.github.com/users/numpy/gists{/gist_id}","starred_url":"https://api.github.com/users/numpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numpy/subscriptions","organizations_url":"https://api.github.com/users/numpy/orgs","repos_url":"https://api.github.com/users/numpy/repos","events_url":"https://api.github.com/users/numpy/events{/privacy}","received_events_url":"https://api.github.com/users/numpy/received_events","type":"Organization","site_admin":false},"repo":{"id":908607,"name":"numpy","full_name":"numpy/numpy","owner":{"login":"numpy","id":288276,"avatar_url":"https://avatars.githubusercontent.com/u/288276?v=3","gravatar_id":"","url":"https://api.github.com/users/numpy","html_url":"https://github.com/numpy","followers_url":"https://api.github.com/users/numpy/followers","following_url":"https://api.github.com/users/numpy/following{/other_user}","gists_url":"https://api.github.com/users/numpy/gists{/gist_id}","starred_url":"https://api.github.com/users/numpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numpy/subscriptions","organizations_url":"https://api.github.com/users/numpy/orgs","repos_url":"https://api.github.com/users/numpy/repos","events_url":"https://api.github.com/users/numpy/events{/privacy}","received_events_url":"https://api.github.com/users/numpy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/numpy/numpy","description":"Numpy main repository","fork":false,"url":"https://api.github.com/repos/numpy/numpy","forks_url":"https://api.github.com/repos/numpy/numpy/forks","keys_url":"https://api.github.com/repos/numpy/numpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/numpy/numpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/numpy/numpy/teams","hooks_url":"https://api.github.com/repos/numpy/numpy/hooks","issue_events_url":"https://api.github.com/repos/numpy/numpy/issues/events{/number}","events_url":"https://api.github.com/repos/numpy/numpy/events","assignees_url":"https://api.github.com/repos/numpy/numpy/assignees{/user}","branches_url":"https://api.github.com/repos/numpy/numpy/branches{/branch}","tags_url":"https://api.github.com/repos/numpy/numpy/tags","blobs_url":"https://api.github.com/repos/numpy/numpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/numpy/numpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/numpy/numpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/numpy/numpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/numpy/numpy/statuses/{sha}","languages_url":"https://api.github.com/repos/numpy/numpy/languages","stargazers_url":"https://api.github.com/repos/numpy/numpy/stargazers","contributors_url":"https://api.github.com/repos/numpy/numpy/contributors","subscribers_url":"https://api.github.com/repos/numpy/numpy/subscribers","subscription_url":"https://api.github.com/repos/numpy/numpy/subscription","commits_url":"https://api.github.com/repos/numpy/numpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/numpy/numpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/numpy/numpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/numpy/numpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/numpy/numpy/contents/{+path}","compare_url":"https://api.github.com/repos/numpy/numpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/numpy/numpy/merges","archive_url":"https://api.github.com/repos/numpy/numpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/numpy/numpy/downloads","issues_url":"https://api.github.com/repos/numpy/numpy/issues{/number}","pulls_url":"https://api.github.com/repos/numpy/numpy/pulls{/number}","milestones_url":"https://api.github.com/repos/numpy/numpy/milestones{/number}","notifications_url":"https://api.github.com/repos/numpy/numpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/numpy/numpy/labels{/name}","releases_url":"https://api.github.com/repos/numpy/numpy/releases{/id}","created_at":"2010-09-13T23:02:39Z","updated_at":"2015-12-09T17:51:07Z","pushed_at":"2015-12-09T18:47:10Z","git_url":"git://github.com/numpy/numpy.git","ssh_url":"git@github.com:numpy/numpy.git","clone_url":"https://github.com/numpy/numpy.git","svn_url":"https://github.com/numpy/numpy","homepage":"http://www.numpy.org/","size":63011,"stargazers_count":2396,"watchers_count":2396,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1253,"mirror_url":null,"open_issues_count":1086,"forks":1253,"open_issues":1086,"watchers":2396,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numpy/numpy/pulls/6727"},"html":{"href":"https://github.com/numpy/numpy/pull/6727"},"issue":{"href":"https://api.github.com/repos/numpy/numpy/issues/6727"},"comments":{"href":"https://api.github.com/repos/numpy/numpy/issues/6727/comments"},"review_comments":{"href":"https://api.github.com/repos/numpy/numpy/pulls/6727/comments"},"review_comment":{"href":"https://api.github.com/repos/numpy/numpy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numpy/numpy/pulls/6727/commits"},"statuses":{"href":"https://api.github.com/repos/numpy/numpy/statuses/87c19b86fac8f2e114b3cae291dc847893704140"}}}}