{"action":"created","comment":{"url":"https://api.github.com/repos/firedrakeproject/ufl/pulls/comments/145084605","pull_request_review_id":69817264,"id":145084605,"diff_hunk":"@@ -0,0 +1,150 @@\n+# -*- coding: utf-8 -*-\n+\"\"\"Algorithm to check for 'comparison' nodes\n+in a form when the user is in 'complex mode'\"\"\"\n+\n+from ufl.corealg.multifunction import MultiFunction\n+from ufl.algorithms.map_integrands import map_integrand_dags\n+from ufl.algebra import Real\n+from ufl.constantvalue import IntValue, FloatValue, Zero\n+from ufl.argument import Argument\n+\n+class CheckComparisons(MultiFunction):\n+    \"\"\"Raises an error if comparisons are done with complex quantities.\n+\n+    If quantities are real, adds the Real operator to the compared quantities. \n+\n+\tTerminals that are real are IntValue, FloatValue, Zero, and Argument\n+    (even in complex FEM, the basis functions are real)\n+    Operations that produce reals are Abs, Real, Imag.\n+    Terminals default to complex, and Sqrt, Pow (defensively) imply complex.\n+\tOtherwise, operators preserve the type of their operands.\n+    \"\"\"\n+    def __init__(self):\n+        MultiFunction.__init__(self)\n+        self.nodetype = {}\n+\n+    def expr(self, o, *ops):\n+        \"\"\"Defaults expressions to complex unless they only\n+        act on real quantities. Overridden for specific operators.\n+\n+        Rebuilds objects if necessary.\n+        \"\"\"\n+\n+        types = {self.nodetype[op] for op in ops}\n+\n+\n+        if types:\n+            t = \"complex\" if \"complex\" in types else \"real\"\n+        else:\n+            t = \"complex\"\n+\n+        o = self.reuse_if_untouched(o, *ops)\n+        self.nodetype[o] = t\n+        return o\n+\n+    def gt(self, o, *ops):\n+        types = {self.nodetype[op] for op in ops}\n+\n+        if \"complex\" in types:\n+            raise ComplexComparisonError(\"You can't compare complex numbers with gt.\")\n+        else:\n+        \to = o._ufl_expr_reconstruct_(*map(Real, ops))\n+        \tself.nodetype[o] = \"bool\"\n+        \treturn o\n+\n+    def lt(self, o, *ops):\n+        types = {self.nodetype[op] for op in ops}\n+\n+        if \"complex\" in types:\n+            raise ComplexComparisonError(\"You can't compare complex numbers with lt.\")\n+        else:\n+        \to = o._ufl_expr_reconstruct_(*map(Real, ops))\n+        \tself.nodetype[o] = \"bool\"\n+        \treturn o\n+\n+    def ge(self, o, *ops):\n+        types = {self.nodetype[op] for op in ops}\n+\n+        if \"complex\" in types:\n+            raise ComplexComparisonError(\"You can't compare complex numbers with ge.\")\n+        else:\n+        \to = o._ufl_expr_reconstruct_(*map(Real, ops))\n+        \tself.nodetype[o] = \"bool\"\n+        \treturn o\n+\n+    def le(self, o, *ops):\n+        types = {self.nodetype[op] for op in ops}\n+\n+        if \"complex\" in types:\n+            raise ComplexComparisonError(\"You can't compare complex numbers with le.\")\n+        else:\n+        \to = o._ufl_expr_reconstruct_(*map(Real, ops))\n+        \tself.nodetype[o] = \"bool\"\n+        \treturn o\n+\n+    def max_value(self, o, *ops):\n+        types = {self.nodetype[op] for op in ops}\n+\n+        if \"complex\" in types:\n+            raise ComplexComparisonError(\"You can't compare complex numbers with max.\")\n+        else:\n+        \to = o._ufl_expr_reconstruct_(*map(Real, ops))\n+        \tself.nodetype[o] = \"bool\"\n+        \treturn o\n+\n+    def min_value(self, o, *ops):\n+        types = {self.nodetype[op] for op in ops}\n+\n+        if \"complex\" in types:\n+            raise ComplexComparisonError(\"You can't compare complex numbers with min.\")\n+        else:\n+        \to = o._ufl_expr_reconstruct_(*map(Real, ops))\n+        \tself.nodetype[o] = \"bool\"\n+        \treturn o\n+\n+    def real(self, o, *ops):\n+    \to = self.reuse_if_untouched(o, *ops)\n+    \tself.nodetype[o] = 'real'\n+    \treturn o\n+\n+    def imag(self, o, *ops):\n+    \to = self.reuse_if_untouched(o, *ops)\n+    \tself.nodetype[o] = 'real'\t    \t\n+    \treturn o\n+\n+    def sqrt(self, o, *ops):\n+    \to = self.reuse_if_untouched(o, *ops)\n+    \tself.nodetype[o] = 'complex'\n+    \treturn o\n+\n+    def power(self, o, *ops):\n+    \to = self.reuse_if_untouched(o, *ops)\n+        if float(ops[1]) < 1.0 and float(ops[1]) > 0.0:\n+    \t   self.nodetype[o] = 'complex'\n+        elif self.nodetype[ops[0]] == 'complex':\n+            self.nodetype[o] = 'complex'\n+        else:\n+            self.nodetype[o] = 'real'\n+    \treturn o\n+\n+    def abs(self, o, *ops):\n+    \to = self.reuse_if_untouched(o, *ops)\n+    \tself.nodetype[o] = 'real'\n+    \treturn o\n+\n+    def terminal(self, term, *ops):\n+    \t# default terminals to complex, except the ones we *know* are real\n+    \tif type(term) in {IntValue, FloatValue, Zero, Argument}:\n+    \t\tself.nodetype[term] = 'real'\n+        else:\n+        \tself.nodetype[term] = 'complex'\n+        return term\n+\n+\n+def do_comparison_check(expr):\n+    \"\"\"Raises an error if invalid comparison nodes exist\"\"\"\n+    return map_integrand_dags(CheckComparisons(), expr)","path":"ufl/algorithms/comparison_checker.py","position":146,"original_position":146,"commit_id":"84cc36fa107e2c1846cdeb725b637113ff9cbb03","original_commit_id":"e44cc23734f0fe1652a4e115a1081307dffa8d51","user":{"login":"miklos1","id":4210841,"avatar_url":"https://avatars2.githubusercontent.com/u/4210841?v=4","gravatar_id":"","url":"https://api.github.com/users/miklos1","html_url":"https://github.com/miklos1","followers_url":"https://api.github.com/users/miklos1/followers","following_url":"https://api.github.com/users/miklos1/following{/other_user}","gists_url":"https://api.github.com/users/miklos1/gists{/gist_id}","starred_url":"https://api.github.com/users/miklos1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miklos1/subscriptions","organizations_url":"https://api.github.com/users/miklos1/orgs","repos_url":"https://api.github.com/users/miklos1/repos","events_url":"https://api.github.com/users/miklos1/events{/privacy}","received_events_url":"https://api.github.com/users/miklos1/received_events","type":"User","site_admin":false},"body":":+1: to fixing the misleading name","created_at":"2017-10-17T10:08:33Z","updated_at":"2017-10-17T10:38:40Z","html_url":"https://github.com/firedrakeproject/ufl/pull/7#discussion_r145084605","pull_request_url":"https://api.github.com/repos/firedrakeproject/ufl/pulls/7","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/firedrakeproject/ufl/pulls/comments/145084605"},"html":{"href":"https://github.com/firedrakeproject/ufl/pull/7#discussion_r145084605"},"pull_request":{"href":"https://api.github.com/repos/firedrakeproject/ufl/pulls/7"}},"in_reply_to_id":144512372},"pull_request":{"url":"https://api.github.com/repos/firedrakeproject/ufl/pulls/7","id":146411401,"html_url":"https://github.com/firedrakeproject/ufl/pull/7","diff_url":"https://github.com/firedrakeproject/ufl/pull/7.diff","patch_url":"https://github.com/firedrakeproject/ufl/pull/7.patch","issue_url":"https://api.github.com/repos/firedrakeproject/ufl/issues/7","number":7,"state":"open","locked":false,"title":"Complex","user":{"login":"dham","id":848103,"avatar_url":"https://avatars2.githubusercontent.com/u/848103?v=4","gravatar_id":"","url":"https://api.github.com/users/dham","html_url":"https://github.com/dham","followers_url":"https://api.github.com/users/dham/followers","following_url":"https://api.github.com/users/dham/following{/other_user}","gists_url":"https://api.github.com/users/dham/gists{/gist_id}","starred_url":"https://api.github.com/users/dham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dham/subscriptions","organizations_url":"https://api.github.com/users/dham/orgs","repos_url":"https://api.github.com/users/dham/repos","events_url":"https://api.github.com/users/dham/events{/privacy}","received_events_url":"https://api.github.com/users/dham/received_events","type":"User","site_admin":false},"body":"This PR enables us to get our act together before PRing against upstream. We probably never actually want to directly merge this.","created_at":"2017-10-13T09:31:43Z","updated_at":"2017-10-17T10:38:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0a51bfe95601bffdafed7115e88c62513058681c","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/firedrakeproject/ufl/pulls/7/commits","review_comments_url":"https://api.github.com/repos/firedrakeproject/ufl/pulls/7/comments","review_comment_url":"https://api.github.com/repos/firedrakeproject/ufl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/firedrakeproject/ufl/issues/7/comments","statuses_url":"https://api.github.com/repos/firedrakeproject/ufl/statuses/84cc36fa107e2c1846cdeb725b637113ff9cbb03","head":{"label":"firedrakeproject:complex","ref":"complex","sha":"84cc36fa107e2c1846cdeb725b637113ff9cbb03","user":{"login":"firedrakeproject","id":5558005,"avatar_url":"https://avatars3.githubusercontent.com/u/5558005?v=4","gravatar_id":"","url":"https://api.github.com/users/firedrakeproject","html_url":"https://github.com/firedrakeproject","followers_url":"https://api.github.com/users/firedrakeproject/followers","following_url":"https://api.github.com/users/firedrakeproject/following{/other_user}","gists_url":"https://api.github.com/users/firedrakeproject/gists{/gist_id}","starred_url":"https://api.github.com/users/firedrakeproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/firedrakeproject/subscriptions","organizations_url":"https://api.github.com/users/firedrakeproject/orgs","repos_url":"https://api.github.com/users/firedrakeproject/repos","events_url":"https://api.github.com/users/firedrakeproject/events{/privacy}","received_events_url":"https://api.github.com/users/firedrakeproject/received_events","type":"Organization","site_admin":false},"repo":{"id":52270508,"name":"ufl","full_name":"firedrakeproject/ufl","owner":{"login":"firedrakeproject","id":5558005,"avatar_url":"https://avatars3.githubusercontent.com/u/5558005?v=4","gravatar_id":"","url":"https://api.github.com/users/firedrakeproject","html_url":"https://github.com/firedrakeproject","followers_url":"https://api.github.com/users/firedrakeproject/followers","following_url":"https://api.github.com/users/firedrakeproject/following{/other_user}","gists_url":"https://api.github.com/users/firedrakeproject/gists{/gist_id}","starred_url":"https://api.github.com/users/firedrakeproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/firedrakeproject/subscriptions","organizations_url":"https://api.github.com/users/firedrakeproject/orgs","repos_url":"https://api.github.com/users/firedrakeproject/repos","events_url":"https://api.github.com/users/firedrakeproject/events{/privacy}","received_events_url":"https://api.github.com/users/firedrakeproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/firedrakeproject/ufl","description":"This is the Firedrake repository of UFL. For the upstream version see: ","fork":true,"url":"https://api.github.com/repos/firedrakeproject/ufl","forks_url":"https://api.github.com/repos/firedrakeproject/ufl/forks","keys_url":"https://api.github.com/repos/firedrakeproject/ufl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/firedrakeproject/ufl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/firedrakeproject/ufl/teams","hooks_url":"https://api.github.com/repos/firedrakeproject/ufl/hooks","issue_events_url":"https://api.github.com/repos/firedrakeproject/ufl/issues/events{/number}","events_url":"https://api.github.com/repos/firedrakeproject/ufl/events","assignees_url":"https://api.github.com/repos/firedrakeproject/ufl/assignees{/user}","branches_url":"https://api.github.com/repos/firedrakeproject/ufl/branches{/branch}","tags_url":"https://api.github.com/repos/firedrakeproject/ufl/tags","blobs_url":"https://api.github.com/repos/firedrakeproject/ufl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/firedrakeproject/ufl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/firedrakeproject/ufl/git/refs{/sha}","trees_url":"https://api.github.com/repos/firedrakeproject/ufl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/firedrakeproject/ufl/statuses/{sha}","languages_url":"https://api.github.com/repos/firedrakeproject/ufl/languages","stargazers_url":"https://api.github.com/repos/firedrakeproject/ufl/stargazers","contributors_url":"https://api.github.com/repos/firedrakeproject/ufl/contributors","subscribers_url":"https://api.github.com/repos/firedrakeproject/ufl/subscribers","subscription_url":"https://api.github.com/repos/firedrakeproject/ufl/subscription","commits_url":"https://api.github.com/repos/firedrakeproject/ufl/commits{/sha}","git_commits_url":"https://api.github.com/repos/firedrakeproject/ufl/git/commits{/sha}","comments_url":"https://api.github.com/repos/firedrakeproject/ufl/comments{/number}","issue_comment_url":"https://api.github.com/repos/firedrakeproject/ufl/issues/comments{/number}","contents_url":"https://api.github.com/repos/firedrakeproject/ufl/contents/{+path}","compare_url":"https://api.github.com/repos/firedrakeproject/ufl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/firedrakeproject/ufl/merges","archive_url":"https://api.github.com/repos/firedrakeproject/ufl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/firedrakeproject/ufl/downloads","issues_url":"https://api.github.com/repos/firedrakeproject/ufl/issues{/number}","pulls_url":"https://api.github.com/repos/firedrakeproject/ufl/pulls{/number}","milestones_url":"https://api.github.com/repos/firedrakeproject/ufl/milestones{/number}","notifications_url":"https://api.github.com/repos/firedrakeproject/ufl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/firedrakeproject/ufl/labels{/name}","releases_url":"https://api.github.com/repos/firedrakeproject/ufl/releases{/id}","deployments_url":"https://api.github.com/repos/firedrakeproject/ufl/deployments","created_at":"2016-02-22T12:00:57Z","updated_at":"2016-11-04T18:03:05Z","pushed_at":"2017-10-13T14:35:15Z","git_url":"git://github.com/firedrakeproject/ufl.git","ssh_url":"git@github.com:firedrakeproject/ufl.git","clone_url":"https://github.com/firedrakeproject/ufl.git","svn_url":"https://github.com/firedrakeproject/ufl","homepage":"https://bitbucket.org/fenics-project/ufl/","size":4163,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"firedrakeproject:master","ref":"master","sha":"8ff2909ed888a5e4d8a4344850a3498f6d7d5be3","user":{"login":"firedrakeproject","id":5558005,"avatar_url":"https://avatars3.githubusercontent.com/u/5558005?v=4","gravatar_id":"","url":"https://api.github.com/users/firedrakeproject","html_url":"https://github.com/firedrakeproject","followers_url":"https://api.github.com/users/firedrakeproject/followers","following_url":"https://api.github.com/users/firedrakeproject/following{/other_user}","gists_url":"https://api.github.com/users/firedrakeproject/gists{/gist_id}","starred_url":"https://api.github.com/users/firedrakeproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/firedrakeproject/subscriptions","organizations_url":"https://api.github.com/users/firedrakeproject/orgs","repos_url":"https://api.github.com/users/firedrakeproject/repos","events_url":"https://api.github.com/users/firedrakeproject/events{/privacy}","received_events_url":"https://api.github.com/users/firedrakeproject/received_events","type":"Organization","site_admin":false},"repo":{"id":52270508,"name":"ufl","full_name":"firedrakeproject/ufl","owner":{"login":"firedrakeproject","id":5558005,"avatar_url":"https://avatars3.githubusercontent.com/u/5558005?v=4","gravatar_id":"","url":"https://api.github.com/users/firedrakeproject","html_url":"https://github.com/firedrakeproject","followers_url":"https://api.github.com/users/firedrakeproject/followers","following_url":"https://api.github.com/users/firedrakeproject/following{/other_user}","gists_url":"https://api.github.com/users/firedrakeproject/gists{/gist_id}","starred_url":"https://api.github.com/users/firedrakeproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/firedrakeproject/subscriptions","organizations_url":"https://api.github.com/users/firedrakeproject/orgs","repos_url":"https://api.github.com/users/firedrakeproject/repos","events_url":"https://api.github.com/users/firedrakeproject/events{/privacy}","received_events_url":"https://api.github.com/users/firedrakeproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/firedrakeproject/ufl","description":"This is the Firedrake repository of UFL. For the upstream version see: ","fork":true,"url":"https://api.github.com/repos/firedrakeproject/ufl","forks_url":"https://api.github.com/repos/firedrakeproject/ufl/forks","keys_url":"https://api.github.com/repos/firedrakeproject/ufl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/firedrakeproject/ufl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/firedrakeproject/ufl/teams","hooks_url":"https://api.github.com/repos/firedrakeproject/ufl/hooks","issue_events_url":"https://api.github.com/repos/firedrakeproject/ufl/issues/events{/number}","events_url":"https://api.github.com/repos/firedrakeproject/ufl/events","assignees_url":"https://api.github.com/repos/firedrakeproject/ufl/assignees{/user}","branches_url":"https://api.github.com/repos/firedrakeproject/ufl/branches{/branch}","tags_url":"https://api.github.com/repos/firedrakeproject/ufl/tags","blobs_url":"https://api.github.com/repos/firedrakeproject/ufl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/firedrakeproject/ufl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/firedrakeproject/ufl/git/refs{/sha}","trees_url":"https://api.github.com/repos/firedrakeproject/ufl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/firedrakeproject/ufl/statuses/{sha}","languages_url":"https://api.github.com/repos/firedrakeproject/ufl/languages","stargazers_url":"https://api.github.com/repos/firedrakeproject/ufl/stargazers","contributors_url":"https://api.github.com/repos/firedrakeproject/ufl/contributors","subscribers_url":"https://api.github.com/repos/firedrakeproject/ufl/subscribers","subscription_url":"https://api.github.com/repos/firedrakeproject/ufl/subscription","commits_url":"https://api.github.com/repos/firedrakeproject/ufl/commits{/sha}","git_commits_url":"https://api.github.com/repos/firedrakeproject/ufl/git/commits{/sha}","comments_url":"https://api.github.com/repos/firedrakeproject/ufl/comments{/number}","issue_comment_url":"https://api.github.com/repos/firedrakeproject/ufl/issues/comments{/number}","contents_url":"https://api.github.com/repos/firedrakeproject/ufl/contents/{+path}","compare_url":"https://api.github.com/repos/firedrakeproject/ufl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/firedrakeproject/ufl/merges","archive_url":"https://api.github.com/repos/firedrakeproject/ufl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/firedrakeproject/ufl/downloads","issues_url":"https://api.github.com/repos/firedrakeproject/ufl/issues{/number}","pulls_url":"https://api.github.com/repos/firedrakeproject/ufl/pulls{/number}","milestones_url":"https://api.github.com/repos/firedrakeproject/ufl/milestones{/number}","notifications_url":"https://api.github.com/repos/firedrakeproject/ufl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/firedrakeproject/ufl/labels{/name}","releases_url":"https://api.github.com/repos/firedrakeproject/ufl/releases{/id}","deployments_url":"https://api.github.com/repos/firedrakeproject/ufl/deployments","created_at":"2016-02-22T12:00:57Z","updated_at":"2016-11-04T18:03:05Z","pushed_at":"2017-10-13T14:35:15Z","git_url":"git://github.com/firedrakeproject/ufl.git","ssh_url":"git@github.com:firedrakeproject/ufl.git","clone_url":"https://github.com/firedrakeproject/ufl.git","svn_url":"https://github.com/firedrakeproject/ufl","homepage":"https://bitbucket.org/fenics-project/ufl/","size":4163,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/firedrakeproject/ufl/pulls/7"},"html":{"href":"https://github.com/firedrakeproject/ufl/pull/7"},"issue":{"href":"https://api.github.com/repos/firedrakeproject/ufl/issues/7"},"comments":{"href":"https://api.github.com/repos/firedrakeproject/ufl/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/firedrakeproject/ufl/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/firedrakeproject/ufl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/firedrakeproject/ufl/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/firedrakeproject/ufl/statuses/84cc36fa107e2c1846cdeb725b637113ff9cbb03"}},"author_association":"OWNER"}}
{"actor":{"display_login":"miklos1"}}