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 implementations of logaddexp and logaddexp2 #249

Closed
erikbrinkman opened this issue Oct 16, 2022 · 2 comments
Closed

Add implementations of logaddexp and logaddexp2 #249

erikbrinkman opened this issue Oct 16, 2022 · 2 comments

Comments

@erikbrinkman
Copy link

logaddexp(x, y) computes (x.exp() + y.exp()).log() more stably than doing those operations naively, and is particularly useful when doing floating point computations in log-space for better precision / stability.

Num-traits seems like the right place for this implementation, which is why I'm opening an issue., but it also seems like most things are just forwarded, so maybe it was decided here to only provide functionality that could be be forwarded, even if things like abs_sub aren't in std.

I'm happy to submit a PR, but wanted to verify that this was desired / in scope before putting more work into it.

@cuviper
Copy link
Member

cuviper commented Oct 18, 2022

Did you consider proposing these for the standard library? Generally, I do prefer to leave the actual implementation there and just provide the generic interface here. We do have some implementations for version compatibility or no_std fallbacks, but those are low effort. (FWIW, abs_sub is indeed in std, just deprecated.)

If nothing else, supposing std does add functions like these some day, I would want us to match the API here -- but that's hard to predict if we go first. :)

@erikbrinkman
Copy link
Author

I have not proposed adding it to the standard library, primarily because I see these as somewhat scientific. There's a reason they occur in libraries like pytorch and numpy, but not in most standard math libraries. I think the second reason they're not frequently in standard libraries is that the implementation is composed of the primitives that are there, notably ln_1p. The api is useful, but it doesn't require anything lower level.

Those explanations, combined with your response on just providing generic compatibility makes me feel like this would be better served in a library supporting scientific math.

Thanks for the fast response!

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

2 participants