-
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
Convenient way to specify/override the inverse of a function #18
Comments
This sounds great! One thing that I think comes up a lot is pairs of functions where the functions themselves are not inverses, but restrictions of both are inverses. In these cases it doesn't make sense to have a global inverse, but it would be great to still be able to use this interface. |
The benefit of such a function |
The main benefits would be that one can attach missing inverses to functions quickly on the fly - and, maybe even more importantly (like @cscherrer noted) easily attach inverses to functions that are only valid inverses for specific uses cases, e.g. because it's ensured that the function resp. inverse will only be used on a limited value range. We were discussing this in the context of JuliaMath/MeasureBase.jl#89 today - I think a |
I skimmed through the issue but it's still not clear to me why you would want to use If you use e.g. specific transformations and only operate on domains where inverses actually exist, I think custom functions, maybe even on the module level, with their inverses don't seem too bad. In any case, I think |
The use case above may actually occur in "user-level" code (e.g. in scripts/notebooks) as often (if not more often) than in "library-level" code. An inline solution would be very user-friendly, I think.
|
@devmotion unless you have strong objections to this, I'd like to prep a PR to add |
I'm fine with it. I am still not sure if it's a good design and what exactly the advantages and disadvantages are here but I don't have a strong opinion on this matter as it should not negatively impact in any way. Based on my experience with wrapper types, e.g., I was also wondering whether that could lead to downstream issues - if there are dispatches on |
Thanks, I'll put a PR together then. I'll see if I can come up with a better name for the function.
I would hope that wouldn't be a problem in typical applications, but that's hard to predict, of course. But since this is for cases where one can't specialize |
It would be convenient to have a function
setinverse
(or other name) that behaves like this:It would make it easy to specify the inverse of an anonymous function:
In some scenarios users may also want to override the default inverse of a function,
setinverse
would provide an easy and very readable way to do that.@devmotion , would you support adding this?
The text was updated successfully, but these errors were encountered: