-
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
Add setinverse #25
Add setinverse #25
Conversation
@devmotion, I couldn't come up with a better function name than |
Codecov ReportBase: 100.00% // Head: 100.00% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## master #25 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 4 +1
Lines 74 80 +6
=========================================
+ Hits 74 80 +6
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
Looking good! I had two very minor nit-picks :)
Co-authored-by: Chad Scherrer <[email protected]>
Co-authored-by: Chad Scherrer <[email protected]>
Thanks for the corrections, @cscherrer ! |
Ok, docgen is fixed too now. |
|
||
```@docs | ||
InverseFunctions.square | ||
InverseFunctions.FunctionWithInverse |
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.
Since it's not exported and not intended to be constructed directly, I wonder if it should be omitted from the docs?
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 thought people might want to have the option to dispatch on it, in low-level uses cases and so on, that's why I made it party of the official API.
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 assumed that this was the motivation. I wonder, however, how often one would actually want to dispatch on FunctionWithInverse
. I assume for many cases it would be simpler to just use unwrap_f
(or something equivalent of the same name) and inverse
- similar to the setinverse
case in this PR.
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 wonder, however, how often one would actually want to dispatch on FunctionWithInverse.
We may actually have occasion to do that in the pushforward measure in MeasureBase (in the context of JuliaMath/MeasureBase.jl#89, since PushforwardMeasure
stores both forward and inverse function for performance reasons). Not sure yet - but it's an interesting option (we may want to extract forward and inverse from FunctionWithInverse). So there's at least one possible use case, so there may be more. And it doesn't cost us anything, I wouldn't expect FunctionWithInverse
to change in breaking ways in the future.
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.
since PushforwardMeasure stores both forward and inverse function for performance reasons
To obtain these you don't have to specialize on FunctionWithInverse
though. You could just store _unwrap_f(f)
and inverse(f)
if an arbitrary f
is provided.
Co-authored-by: David Widmann <[email protected]>
|
||
```@docs | ||
InverseFunctions.square | ||
InverseFunctions.FunctionWithInverse |
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 assumed that this was the motivation. I wonder, however, how often one would actually want to dispatch on FunctionWithInverse
. I assume for many cases it would be simpler to just use unwrap_f
(or something equivalent of the same name) and inverse
- similar to the setinverse
case in this PR.
Co-authored-by: David Widmann <[email protected]>
Maybe, Just a suggestion. |
It would, in principle, and was my first idea for naming this functionality. However, we use How about |
Interesting, if I understand correctly that package uses basically the opposite "direction" of
Well, For example, |
FWIW, Zygote has something similar: help?> Zygote.withgradient
withgradient(f, args...)
withgradient(f, ::Params)
Returns both the value of the function and the gradient, as a named tuple.
julia> y, ∇ = withgradient(/, 1, 2)
(val = 0.5, grad = (0.5, -0.25))
julia> ∇ == gradient(/, 1, 2)
true |
Yes, that matches what |
Oh, that's very neat! Maybe |
Yes, maybe Seems like |
Are you happy with how this looks now, @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.
Looks good to me, I don't think the discussion in https://github.com/JuliaMath/InverseFunctions.jl/pull/25/files#r979044891 is blocking this PR.
Thanks, I'll merge then? |
Closes #18
CC @cscherrer