Skip to content
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 with_inverse(f, x)? #6

Closed
oschulz opened this issue Oct 13, 2021 · 6 comments
Closed

Add with_inverse(f, x)? #6

oschulz opened this issue Oct 13, 2021 · 6 comments

Comments

@oschulz
Copy link
Collaborator

oschulz commented Oct 13, 2021

Maybe we should add an interface y, inverse_f = with_inverse(f, x), to support use cases that can't generate an inverse function without x (like a generic flatten-to-real-vector function, see JuliaGaussianProcesses/ParameterHandling.jl#43).

The default implementation would simply be

with_inverse(f, x) = f(x), inverse(f)

so it wouldn't make InverseFunctions noticeably heavier.

@devmotion
Copy link
Member

I think it would be good to see some concrete implementations for ParameterHandling and one or two other packages first. This would make it easier to evaluate its usefulness and potential problems.

@oschulz
Copy link
Collaborator Author

oschulz commented Oct 15, 2021

I think it would be good to see some concrete implementations for ParameterHandling and one or two other packages first.

You mean implement a with_inverse-equivalent internally there, first?

@devmotion
Copy link
Member

Yes, or implement with_inverse in a branch in these packages. Just to figure any problems and requirements of these concrete implementations and differences between different packages.

@oschulz
Copy link
Collaborator Author

oschulz commented Oct 15, 2021

Oh, sure, makes sense.

@aplavin
Copy link
Contributor

aplavin commented Sep 26, 2022

Looks like this functionality is already present in Accessors.
With the same notation as the OP:

with_inverse(f, x) = f(x), y -> set(x, f, y)

f = @optic exp(_.field[2])  # just an example f
y, inverse_f = with_inverse(f, x)

Of course, defining this with_inverse function isn't actually needed, one would just use set(...) as needed.
set is also not as ambiguous as with_inverse: different meanings could potentially be assigned to the latter, see eg #25 (comment).

@oschulz oschulz mentioned this issue Sep 26, 2022
@oschulz
Copy link
Collaborator Author

oschulz commented Sep 26, 2022

Thanks @aplavin - I guess we should close this for now, then, until use cases come up that really can't separate forward and inverse calculation without significant overhead.

@oschulz oschulz closed this as completed Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants