Title: Replace `Transform.__add__` with `Transform.__matmul__`? · Issue #17230 · matplotlib/matplotlib · GitHub
Open Graph Title: Replace `Transform.__add__` with `Transform.__matmul__`? · Issue #17230 · matplotlib/matplotlib
X Title: Replace `Transform.__add__` with `Transform.__matmul__`? · Issue #17230 · matplotlib/matplotlib
Description: Bug report Bug summary While working on fixing the transform pipeline for image rendering, it struck me that the operator "+" probably sends the wrong impression to users in terms of expected properties. The Euclidean group is barely ass...
Open Graph Description: Bug report Bug summary While working on fixing the transform pipeline for image rendering, it struck me that the operator "+" probably sends the wrong impression to users in terms of expected prope...
X Description: Bug report Bug summary While working on fixing the transform pipeline for image rendering, it struck me that the operator "+" probably sends the wrong impression to users in terms of expe...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/17230
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Replace `Transform.__add__` with `Transform.__matmul__`?","articleBody":"\u003c!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--\u003e\r\n\u003c!--You can feel free to delete the sections that do not apply.--\u003e\r\n\r\n### Bug report\r\n\r\n**Bug summary**\r\n\r\nWhile working on fixing the transform pipeline for image rendering, it struck me that the operator \"+\" probably sends the wrong impression to users in terms of expected properties. The Euclidean group is barely associative, and definitely not commutative. \r\n\r\nAlso, since a `Transform` is something that's *applied* (like an operator), my expectation as I'm using composite transforms is that they will be applied rightmost-first. In other words, I keep expecting\r\n\r\n```python\r\n\u003e\u003e\u003e (A + B).transform(X) == A.transform(B.transform(X)) # but it's currently False\r\n\u003e\u003e\u003e (A + B).transform(X) == B.transform(A.transform(X)) # how it currently works.\r\n```\r\n\r\nNow that Python has the \"@\" operator, this feels like a more natural choice for \"combining\" `Transforms`. People don't generally expect `A@B == B@A`, while they do expect `A + B == B + A`, which is definitely not true for Transforms. \r\n\r\nThe implementation would just be something like (modulo deprecation code)\r\n\r\n```python\r\ndef __matmul__(self, other):\r\n return other + self\r\n```\r\n\r\nAnd we would get \r\n```python\r\n\u003e\u003e\u003e (A @ B).transform(X) == A.transform(B.transform(X)) # returns True\r\n```\r\n\r\n**Release strategy** \r\n\r\nFixing all our internal uses is (probably) only one PR's worth of work, since (relative to how much code would churn) it would be easy to verify/review. \r\n\r\nHowever, to me this feels like an integral enough part of the Transform API that it might make sense to leave in \"+\" until 4.x, and maybe just make sure we only advertise \"@\" in e.g. the tutorials?\r\n\r\nIn summary:\r\n\r\n**Pros**\r\n1. \"@\" implies lack of commutivity, whereas \"+\" implied commutivity\r\n2. \"@\" implies order of application (rightmost-first), whereas \"+\" is ambigious\r\n\r\n**Cons**\r\n1. Pretty core part of `Transform` API\r\n2. Lots of code-churn in `Transform`-related internals.\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/brunobeltran","@type":"Person","name":"brunobeltran"},"datePublished":"2020-04-23T21:19:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/17230/matplotlib/issues/17230"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ee53210c-d4bc-b5b9-4479-8d9b292fe4b5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C57C:22AA41:153925B:1EF5ED3:6A54CCD5 |
| html-safe-nonce | a7e8f45b8c8339cc2c7e9c559aba9c0ba701f18a83afcafa173032b63c618d85 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTdDOjIyQUE0MToxNTM5MjVCOjFFRjVFRDM6NkE1NENDRDUiLCJ2aXNpdG9yX2lkIjoiNTE0ODA4ODA1OTIyMTU2MDUzMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 46250f7b8a6648f13551745980aa679ab6da3c43213dc7524a96759ca4eadf60 |
| hovercard-subject-tag | issue:605881257 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/17230/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d1ea481bfe35c7f91eca636be9b934cc7e8db90060011daa5077e24ac704499a/matplotlib/matplotlib/issues/17230 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d1ea481bfe35c7f91eca636be9b934cc7e8db90060011daa5077e24ac704499a/matplotlib/matplotlib/issues/17230 |
| og:image:alt | Bug report Bug summary While working on fixing the transform pipeline for image rendering, it struck me that the operator "+" probably sends the wrong impression to users in terms of expected prope... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brunobeltran |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6e5f2e6ff3f430aa60a674066f957bca9f2106017e1b68126417422b58ce6e1e |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | be4d48619391052c9d312c7b587bb2ac38a97f57 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width