-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Replace Transform.__add__
with Transform.__matmul__
?
#17230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Oh, forgot the main reason why I started being bothered by this. A lot of places in the code use "+=" to combine transforms, such as in t += Affine2D().scale(1.0 + extra_width, 1.0 + extra_height) In this case (and often, in general), whether this gets added on the right or left matters. So having it be feel ambiguous with "+=" makes life harder for someone trying to read/understand this code. At least, I know I personally have to drop a break point (or lookup how |
This was just discussed in #17206 (comment) / #17217 / #17218. I personally think |
Oh sorry, github didn't recommed those to me, I'll close this. |
Seems like the main con is actually losing the ability to cleverly make A @ A.inverted() == IdentityTransform() return So in order to get feature parity, we'd need Seems like an additional complaint is also that To me, it seems like having code that makes I'll reopen this if people are favorable to something like this (i.e. |
Having a real InvertedTransform() was proposed at least once (by @ImportanceOfBeingErnest iirc? you'll have to look it up) to get a non-frozen inverse() (i.e. one that keeps track of changes in the original thing); I think it would be usefule, and I guess it would be a prerequisite for a switch to matmul to happen (even though right now I still don't like it). |
Looks like it was proposed in #10741. |
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 associative, and definitely not commutative.
Also, 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 expectingNow that Python has the "@" operator, this feels like a more natural choice for "combining"
Transforms
. People don't generally expectA@B == B@A
, while they do expectA + B == B + A
, which is definitely not true for Transforms.The implementation would just be something like (modulo deprecation code)
And we would get
Release strategy
Fixing 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.
However, 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?
In summary:
Pros
Cons
Transform
APITransform
-related internals.The text was updated successfully, but these errors were encountered: