{"action":"created","comment":{"url":"https://api.github.com/repos/opesci/devito/pulls/comments/216907940","pull_request_review_id":154497280,"id":216907940,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNjkwNzk0MA==","diff_hunk":"@@ -0,0 +1,182 @@\n+import sympy\n+from sympy.core.basic import _aresame\n+import numpy as np\n+\n+from devito.symbolics.extended_sympy import ExprDiv\n+\n+__all__ = ['Differentiable']\n+\n+\n+class Differentiable(sympy.Expr):\n+    \"\"\"\n+    This class represents Devito differentiable objects such as\n+    sum of functions, product of function or FD approximation and\n+    provides FD shortcuts for such expressions\n+    \"\"\"\n+    _op_priority = 100.0\n+\n+    def __new__(cls, *args, **kwargs):\n+        if cls == Differentiable:\n+            assert len(args) == 1\n+            expr = args[0]\n+            new_obj = sympy.Expr.__new__(cls, expr)\n+            # Initialization\n+            new_obj.__init__(expr, **kwargs)\n+            return new_obj\n+        return sympy.Expr.__new__(cls, *args)\n+\n+    def __init__(self, expr, **kwargs):\n+        # Recover the list of possible FD shortcuts\n+        self._dtype = kwargs.get('dtype')\n+        self._space_order = kwargs.get('space_order')\n+        self._time_order = kwargs.get('time_order', 0)\n+        self._indices = kwargs.get('indices', ())\n+        self._staggered = kwargs.get('staggered')\n+        self._grid = kwargs.get('grid')\n+        # Generate FD shortcuts for expression or copy from input\n+        self._fd = kwargs.get('fd', {})\n+        # Save kwargs\n+        self._expr = expr\n+\n+    @property\n+    def space_order(self):\n+        return self._space_order\n+\n+    @property\n+    def time_order(self):\n+        return self._time_order\n+\n+    @property\n+    def staggered(self):\n+        return self._staggered\n+\n+    @property\n+    def indices(self):\n+        return self._indices\n+\n+    @property\n+    def fd(self):\n+        return self._fd\n+\n+    @property\n+    def grid(self):\n+        return self._grid\n+\n+    @property\n+    def dtype(self):\n+        return self._dtype\n+\n+    def __getattr__(self, name):\n+        if name == 'fd' or name == '_fd':\n+            raise AttributeError()\n+        if name in self.fd.keys():\n+            return self.fd[name][0](self)\n+        return self.__getattribute__(name)\n+\n+    def xreplace(self, rule):\n+        out = getattr(self, '_expr', self)\n+        if out in rule:\n+            return rule[out]\n+        elif rule:\n+            args = []\n+            for a in out.args:\n+                try:\n+                    args.append(a.xreplace(rule))\n+                except AttributeError:\n+                    args.append(a)\n+            args = tuple(args)\n+            if not _aresame(args, out.args):\n+                return out.func(*args)\n+        return out\n+\n+    def _merge_fd_properties(self, other):\n+        merged = {}\n+        merged[\"space_order\"] = np.min([getattr(self, 'space_order', 100) or 100,\n+                                        getattr(other, 'space_order', 100)])\n+        merged[\"time_order\"] = np.min([getattr(self, 'time_order', 100) or 100,\n+                                       getattr(other, 'time_order', 100)])\n+        merged[\"indices\"] = tuple(set(self.indices + getattr(other, 'indices', ())))\n+        merged[\"fd\"] = dict(getattr(self, 'fd', {}), **getattr(other, 'fd', {}))\n+        merged[\"staggered\"] = self.staggered\n+        merged[\"dtype\"] = self.dtype\n+        return merged\n+\n+    def __add__(self, other):\n+        return Differentiable(sympy.Add(*[getattr(self, '_expr', self),\n+                                          getattr(other, '_expr', other)]),\n+                              **self._merge_fd_properties(other))\n+\n+    __iadd__ = __add__","path":"devito/finite_differences/differentiable.py","position":104,"original_position":109,"commit_id":"0c504d1fc3f14e04a96971c6ad26b457079bb34d","original_commit_id":"92d81be23aea45894a44f2749603cd9b04159e8a","user":{"login":"FabioLuporini","id":478143,"node_id":"MDQ6VXNlcjQ3ODE0Mw==","avatar_url":"https://avatars3.githubusercontent.com/u/478143?v=4","gravatar_id":"","url":"https://api.github.com/users/FabioLuporini","html_url":"https://github.com/FabioLuporini","followers_url":"https://api.github.com/users/FabioLuporini/followers","following_url":"https://api.github.com/users/FabioLuporini/following{/other_user}","gists_url":"https://api.github.com/users/FabioLuporini/gists{/gist_id}","starred_url":"https://api.github.com/users/FabioLuporini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FabioLuporini/subscriptions","organizations_url":"https://api.github.com/users/FabioLuporini/orgs","repos_url":"https://api.github.com/users/FabioLuporini/repos","events_url":"https://api.github.com/users/FabioLuporini/events{/privacy}","received_events_url":"https://api.github.com/users/FabioLuporini/received_events","type":"User","site_admin":false},"body":"it appears that += actually has an effect:\r\n```\r\nIn [1]: from sympy import *\r\n...\r\nIn [5]: a=Symbol('a')\r\nIn [6]: b=Symbol('b')\r\nIn [7]: a + b\r\nOut[7]: a + b\r\nIn [8]: a += b\r\nIn [9]: a\r\nOut[9]: a + b\r\n```\r\nnote that the content of ``a`` has actually changed\r\n\r\nas for __radd__, __rmul__, __rdiv__ ... we should swap the operands. See for example here: https://github.com/sympy/sympy/blob/master/sympy/core/expr.py#L124\r\nnot sure, however, what are the practical implications of this in SymPy","created_at":"2018-09-12T06:18:31Z","updated_at":"2018-09-12T06:40:10Z","html_url":"https://github.com/opesci/devito/pull/642#discussion_r216907940","pull_request_url":"https://api.github.com/repos/opesci/devito/pulls/642","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/opesci/devito/pulls/comments/216907940"},"html":{"href":"https://github.com/opesci/devito/pull/642#discussion_r216907940"},"pull_request":{"href":"https://api.github.com/repos/opesci/devito/pulls/642"}},"in_reply_to_id":216558626},"pull_request":{"url":"https://api.github.com/repos/opesci/devito/pulls/642","id":214000213,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE0MDAwMjEz","html_url":"https://github.com/opesci/devito/pull/642","diff_url":"https://github.com/opesci/devito/pull/642.diff","patch_url":"https://github.com/opesci/devito/pull/642.patch","issue_url":"https://api.github.com/repos/opesci/devito/issues/642","number":642,"state":"open","locked":false,"title":"Interface2","user":{"login":"mloubout","id":5702350,"node_id":"MDQ6VXNlcjU3MDIzNTA=","avatar_url":"https://avatars3.githubusercontent.com/u/5702350?v=4","gravatar_id":"","url":"https://api.github.com/users/mloubout","html_url":"https://github.com/mloubout","followers_url":"https://api.github.com/users/mloubout/followers","following_url":"https://api.github.com/users/mloubout/following{/other_user}","gists_url":"https://api.github.com/users/mloubout/gists{/gist_id}","starred_url":"https://api.github.com/users/mloubout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mloubout/subscriptions","organizations_url":"https://api.github.com/users/mloubout/orgs","repos_url":"https://api.github.com/users/mloubout/repos","events_url":"https://api.github.com/users/mloubout/events{/privacy}","received_events_url":"https://api.github.com/users/mloubout/received_events","type":"User","site_admin":false},"body":"Reopening interface enhancement, WIP but mostly there\r\n\r\n- '(u + v.dx).dy' and things like that possible\r\n- staggered no is defined as `staggered = x` for example, not more `(0,1,0)` and `None` corresponds to cartesian grids. Need to add check to make sure all fields are either staggered or non-staggered\r\n- FD shortcuts are no only created if called to avoid hundreds if not thousands of calls to `setattr` during FD manipulation\r\n\r\n- Some misc","created_at":"2018-09-07T18:03:13Z","updated_at":"2018-09-12T06:40:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7823834eabe7633bbf2e1e424086a9c32c19ee73","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/opesci/devito/pulls/642/commits","review_comments_url":"https://api.github.com/repos/opesci/devito/pulls/642/comments","review_comment_url":"https://api.github.com/repos/opesci/devito/pulls/comments{/number}","comments_url":"https://api.github.com/repos/opesci/devito/issues/642/comments","statuses_url":"https://api.github.com/repos/opesci/devito/statuses/0c504d1fc3f14e04a96971c6ad26b457079bb34d","head":{"label":"opesci:interface2","ref":"interface2","sha":"0c504d1fc3f14e04a96971c6ad26b457079bb34d","user":{"login":"opesci","id":10018551,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwMDE4NTUx","avatar_url":"https://avatars1.githubusercontent.com/u/10018551?v=4","gravatar_id":"","url":"https://api.github.com/users/opesci","html_url":"https://github.com/opesci","followers_url":"https://api.github.com/users/opesci/followers","following_url":"https://api.github.com/users/opesci/following{/other_user}","gists_url":"https://api.github.com/users/opesci/gists{/gist_id}","starred_url":"https://api.github.com/users/opesci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opesci/subscriptions","organizations_url":"https://api.github.com/users/opesci/orgs","repos_url":"https://api.github.com/users/opesci/repos","events_url":"https://api.github.com/users/opesci/events{/privacy}","received_events_url":"https://api.github.com/users/opesci/received_events","type":"Organization","site_admin":false},"repo":{"id":54585666,"node_id":"MDEwOlJlcG9zaXRvcnk1NDU4NTY2Ng==","name":"devito","full_name":"opesci/devito","owner":{"login":"opesci","id":10018551,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwMDE4NTUx","avatar_url":"https://avatars1.githubusercontent.com/u/10018551?v=4","gravatar_id":"","url":"https://api.github.com/users/opesci","html_url":"https://github.com/opesci","followers_url":"https://api.github.com/users/opesci/followers","following_url":"https://api.github.com/users/opesci/following{/other_user}","gists_url":"https://api.github.com/users/opesci/gists{/gist_id}","starred_url":"https://api.github.com/users/opesci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opesci/subscriptions","organizations_url":"https://api.github.com/users/opesci/orgs","repos_url":"https://api.github.com/users/opesci/repos","events_url":"https://api.github.com/users/opesci/events{/privacy}","received_events_url":"https://api.github.com/users/opesci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/opesci/devito","description":"Code generation framework for automated finite difference computation","fork":false,"url":"https://api.github.com/repos/opesci/devito","forks_url":"https://api.github.com/repos/opesci/devito/forks","keys_url":"https://api.github.com/repos/opesci/devito/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opesci/devito/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opesci/devito/teams","hooks_url":"https://api.github.com/repos/opesci/devito/hooks","issue_events_url":"https://api.github.com/repos/opesci/devito/issues/events{/number}","events_url":"https://api.github.com/repos/opesci/devito/events","assignees_url":"https://api.github.com/repos/opesci/devito/assignees{/user}","branches_url":"https://api.github.com/repos/opesci/devito/branches{/branch}","tags_url":"https://api.github.com/repos/opesci/devito/tags","blobs_url":"https://api.github.com/repos/opesci/devito/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opesci/devito/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opesci/devito/git/refs{/sha}","trees_url":"https://api.github.com/repos/opesci/devito/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opesci/devito/statuses/{sha}","languages_url":"https://api.github.com/repos/opesci/devito/languages","stargazers_url":"https://api.github.com/repos/opesci/devito/stargazers","contributors_url":"https://api.github.com/repos/opesci/devito/contributors","subscribers_url":"https://api.github.com/repos/opesci/devito/subscribers","subscription_url":"https://api.github.com/repos/opesci/devito/subscription","commits_url":"https://api.github.com/repos/opesci/devito/commits{/sha}","git_commits_url":"https://api.github.com/repos/opesci/devito/git/commits{/sha}","comments_url":"https://api.github.com/repos/opesci/devito/comments{/number}","issue_comment_url":"https://api.github.com/repos/opesci/devito/issues/comments{/number}","contents_url":"https://api.github.com/repos/opesci/devito/contents/{+path}","compare_url":"https://api.github.com/repos/opesci/devito/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opesci/devito/merges","archive_url":"https://api.github.com/repos/opesci/devito/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opesci/devito/downloads","issues_url":"https://api.github.com/repos/opesci/devito/issues{/number}","pulls_url":"https://api.github.com/repos/opesci/devito/pulls{/number}","milestones_url":"https://api.github.com/repos/opesci/devito/milestones{/number}","notifications_url":"https://api.github.com/repos/opesci/devito/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opesci/devito/labels{/name}","releases_url":"https://api.github.com/repos/opesci/devito/releases{/id}","deployments_url":"https://api.github.com/repos/opesci/devito/deployments","created_at":"2016-03-23T18:59:49Z","updated_at":"2018-09-07T12:32:23Z","pushed_at":"2018-09-11T20:40:52Z","git_url":"git://github.com/opesci/devito.git","ssh_url":"git@github.com:opesci/devito.git","clone_url":"https://github.com/opesci/devito.git","svn_url":"https://github.com/opesci/devito","homepage":"http://www.devitoproject.org","size":62644,"stargazers_count":71,"watchers_count":71,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":25,"mirror_url":null,"archived":false,"open_issues_count":35,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":25,"open_issues":35,"watchers":71,"default_branch":"master"}},"base":{"label":"opesci:master","ref":"master","sha":"1b2e46012eaa22ce5272f40915f235edcad97f19","user":{"login":"opesci","id":10018551,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwMDE4NTUx","avatar_url":"https://avatars1.githubusercontent.com/u/10018551?v=4","gravatar_id":"","url":"https://api.github.com/users/opesci","html_url":"https://github.com/opesci","followers_url":"https://api.github.com/users/opesci/followers","following_url":"https://api.github.com/users/opesci/following{/other_user}","gists_url":"https://api.github.com/users/opesci/gists{/gist_id}","starred_url":"https://api.github.com/users/opesci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opesci/subscriptions","organizations_url":"https://api.github.com/users/opesci/orgs","repos_url":"https://api.github.com/users/opesci/repos","events_url":"https://api.github.com/users/opesci/events{/privacy}","received_events_url":"https://api.github.com/users/opesci/received_events","type":"Organization","site_admin":false},"repo":{"id":54585666,"node_id":"MDEwOlJlcG9zaXRvcnk1NDU4NTY2Ng==","name":"devito","full_name":"opesci/devito","owner":{"login":"opesci","id":10018551,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwMDE4NTUx","avatar_url":"https://avatars1.githubusercontent.com/u/10018551?v=4","gravatar_id":"","url":"https://api.github.com/users/opesci","html_url":"https://github.com/opesci","followers_url":"https://api.github.com/users/opesci/followers","following_url":"https://api.github.com/users/opesci/following{/other_user}","gists_url":"https://api.github.com/users/opesci/gists{/gist_id}","starred_url":"https://api.github.com/users/opesci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opesci/subscriptions","organizations_url":"https://api.github.com/users/opesci/orgs","repos_url":"https://api.github.com/users/opesci/repos","events_url":"https://api.github.com/users/opesci/events{/privacy}","received_events_url":"https://api.github.com/users/opesci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/opesci/devito","description":"Code generation framework for automated finite difference computation","fork":false,"url":"https://api.github.com/repos/opesci/devito","forks_url":"https://api.github.com/repos/opesci/devito/forks","keys_url":"https://api.github.com/repos/opesci/devito/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opesci/devito/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opesci/devito/teams","hooks_url":"https://api.github.com/repos/opesci/devito/hooks","issue_events_url":"https://api.github.com/repos/opesci/devito/issues/events{/number}","events_url":"https://api.github.com/repos/opesci/devito/events","assignees_url":"https://api.github.com/repos/opesci/devito/assignees{/user}","branches_url":"https://api.github.com/repos/opesci/devito/branches{/branch}","tags_url":"https://api.github.com/repos/opesci/devito/tags","blobs_url":"https://api.github.com/repos/opesci/devito/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opesci/devito/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opesci/devito/git/refs{/sha}","trees_url":"https://api.github.com/repos/opesci/devito/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opesci/devito/statuses/{sha}","languages_url":"https://api.github.com/repos/opesci/devito/languages","stargazers_url":"https://api.github.com/repos/opesci/devito/stargazers","contributors_url":"https://api.github.com/repos/opesci/devito/contributors","subscribers_url":"https://api.github.com/repos/opesci/devito/subscribers","subscription_url":"https://api.github.com/repos/opesci/devito/subscription","commits_url":"https://api.github.com/repos/opesci/devito/commits{/sha}","git_commits_url":"https://api.github.com/repos/opesci/devito/git/commits{/sha}","comments_url":"https://api.github.com/repos/opesci/devito/comments{/number}","issue_comment_url":"https://api.github.com/repos/opesci/devito/issues/comments{/number}","contents_url":"https://api.github.com/repos/opesci/devito/contents/{+path}","compare_url":"https://api.github.com/repos/opesci/devito/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opesci/devito/merges","archive_url":"https://api.github.com/repos/opesci/devito/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opesci/devito/downloads","issues_url":"https://api.github.com/repos/opesci/devito/issues{/number}","pulls_url":"https://api.github.com/repos/opesci/devito/pulls{/number}","milestones_url":"https://api.github.com/repos/opesci/devito/milestones{/number}","notifications_url":"https://api.github.com/repos/opesci/devito/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opesci/devito/labels{/name}","releases_url":"https://api.github.com/repos/opesci/devito/releases{/id}","deployments_url":"https://api.github.com/repos/opesci/devito/deployments","created_at":"2016-03-23T18:59:49Z","updated_at":"2018-09-07T12:32:23Z","pushed_at":"2018-09-11T20:40:52Z","git_url":"git://github.com/opesci/devito.git","ssh_url":"git@github.com:opesci/devito.git","clone_url":"https://github.com/opesci/devito.git","svn_url":"https://github.com/opesci/devito","homepage":"http://www.devitoproject.org","size":62644,"stargazers_count":71,"watchers_count":71,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":25,"mirror_url":null,"archived":false,"open_issues_count":35,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":25,"open_issues":35,"watchers":71,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/opesci/devito/pulls/642"},"html":{"href":"https://github.com/opesci/devito/pull/642"},"issue":{"href":"https://api.github.com/repos/opesci/devito/issues/642"},"comments":{"href":"https://api.github.com/repos/opesci/devito/issues/642/comments"},"review_comments":{"href":"https://api.github.com/repos/opesci/devito/pulls/642/comments"},"review_comment":{"href":"https://api.github.com/repos/opesci/devito/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/opesci/devito/pulls/642/commits"},"statuses":{"href":"https://api.github.com/repos/opesci/devito/statuses/0c504d1fc3f14e04a96971c6ad26b457079bb34d"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"FabioLuporini"}}