-
Notifications
You must be signed in to change notification settings - Fork 8
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
fix inverse(^) domain #34
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #34 +/- ##
==========================================
- Coverage 99.25% 97.82% -1.43%
==========================================
Files 6 6
Lines 134 138 +4
==========================================
+ Hits 133 135 +2
- Misses 1 3 +2 ☔ View full report in Codecov by Sentry. |
Why can't it be defined? x^2 is invertible when restricted to positive values. |
These usecase-specific inverses are what |
Yes, you do have a point @aplavin . In any case, I don't think people will often need the inverse for |
That's a bugfix, so a regular release should be fine - without changing the major version. |
I have no strong opinion here - @devmotion ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the feeling this should be addressed more generally at some point, I don't like that there's no easy way to say "give me the inverse of some function whose domain is the positive real line". Using setinverse
is cumbersome and redundant in these cases, and if you want to deal with generic functions this workaround is not even possible.
For the time being, both adopting a convention (always positive real line in these cases?) and throwing an error seem fine to me. I am not sure if there are examples but I think it's not unlikely that someone relied on or assumed we had such a convention - so I would rather be more cautious here and tag a breaking release.
Also relates to #10.
Yeah, a nice way to support those would be nice! Personally, I have multiple usecases for inverses, and some of them in principle require different kinds of inverse.
Given a single function |
So should be do a breaking release with this now, or keep it until we have to do a breaking release anyway? |
Depends on how urgent we want this to be released and if any other breaking changes are expected I assume 🤷 Maybe it would be good to address #10 in the same release. |
Well, unfortunate that this change is considered breaking instead of a bugfix: changing from objectively incorrect to correct behavior. Supporting left/right inverses is orthogonal, because this PR is only concerned with the correctness of |
I wouldn't say the current behavior is "obviously incorrect" - it's a question of how narrow one defined invertibility (full domain or part of the domain). I agree this change should be made, the question is whether it's of any urgency, since it just removes some (probably little-used) "incorect" functionality, or whether it should wait until we have to make other breaking changes anyway. At some point, we may also want to do a v1.0 release, that would also be a good opportunity. |
If that's the case, better sooner than later I think. The longer we wait the more likely it is someone will depend on this (incorrect) functionality. |
You make a good point @ParadaCarleton , if there are no objections (@devmotion ?), I'll merge and release this. @aplavin , should we do #38 as well then? |
Yes I think this should be merged, as a bugfix. |
I also looked at other functions and fixed their inverse domains. It's quite hard to be sure that no edgecase is missed there! (most definitely some still remain) |
If I understood @devmotion correctly, he would prefer a breaking release. @devmotion ? |
Sorry, I didn't imply any specific numbering of the next release. No matter the version number, this PR is still fundamentally a fix making behavior correct, following the function semantics and docs. Would appreciate another look at the conditions in the code, especially important if such a fix involves a "breaking" version bump. |
Thank let's maybe just make a v0.2 and be done with it. :-) Good from your side @devmotion ? |
Not that I have a lot of hope, but... Is there a chance this bugfix could be accepted anytime soon? Another recent example: julia> f = Base.Fix1(log, 1)
# would throw a DomainError with this PR:
julia> inverse(f)(f(10))
1.0 |
My apologies, I kinda lost track of this one. Let's get it in |
Looking at this again, I think it's indeed a bugfix, and so non-breaking. @devmotion any objections? |
@@ -80,7 +80,9 @@ InverseFunctions.inverse(f::Bar) = Bar(inv(f.A)) | |||
@test_throws DomainError inverse(Base.Fix2(^, 0.5))(-5) | |||
@test_throws DomainError inverse(Base.Fix2(^, 0.51))(complex(-5)) | |||
InverseFunctions.test_inverse(Base.Fix2(^, 0.5), complex(-5)) | |||
@test_throws DomainError inverse(Base.Fix2(^, 2))(-5) | |||
@test_throws DomainError inverse(Base.Fix2(^, 2)) | |||
@test_throws DomainError inverse(Base.Fix2(^, -4)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the errors for Base.Fix1(^ and log tested somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aplavin I think there's not test for that yet, correct?
Co-authored-by: David Widmann <[email protected]>
Co-authored-by: David Widmann <[email protected]>
Co-authored-by: David Widmann <[email protected]>
Co-authored-by: David Widmann <[email protected]>
@aplavin could you look into adding the tests that @devmotion mentioned, before this gets merged? |
@aplavin is that covered already? |
sorry, almost forgot about it! |
Thanks @aplavin ! |
@devmotion , good from your side now? |
There are merge conflicts? |
Oh, so there are, silly me. @aplavin , pretty please? |
Indeed, there were quite some code changes during this year :) Not sure what exactly went wrong here and caused this delay, even the original feature was accepted faster than the bugfix... |
Thanks for rebasing @aplavin (and sorry we've dragged our feet on this one in between). @devmotion ? |
@aplavin could you add a minor version bump? Then I'll merge and release. |
You mean patch version, right? Bumped! |
Sorry, @aplavin , forgot to trigger registrator. Just did: |
@devmotion do you know why TagBot keeps failing now? |
Probably JuliaRegistries/TagBot#350 which seems to be fixed in the latest release. |
Do we have to take any action, re-run it or so? |
Oh, right - sorry, just saw it. Thanks! |
Technically breaking, but the old behavior was wrong - so this is a bug fix.
Inverse to y=x^2 at y=4 isn't 2 - it's not defined.
Maybe there are better and less error-prone approaches to handling these domains?..