-
Notifications
You must be signed in to change notification settings - Fork 479
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
replace np with torch linsapce in riemann approximation #714
Conversation
@aobo-y has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
import torch | ||
|
||
try: | ||
import numpy as np |
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.
To make this more clean can we move the import into gauss_legendre_builders
. Then we won't need try-except.
r"""Numpy's `np.polynomial.legendre` function helps to compute step sizes |
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.
But as you can see below, I also rely on this to raise an explicit error for using gausslegendre
when numpy
is not available and suggesting riemann
. Without it, users will only receive an contextless message like Cannot find module numpy
.
I know we are doing this for a special use case and it is unlikely to have any users encounter this. So I am also open to your suggestion.
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.
My worry is, since this code is going to be executed, it could make problems during packaging (It might try to load numpy. We have to test, I can't say exactly). If we put it in the function, the import is not going to be executed at all when we choose riemann sum. If numpy is not available an error will raise only if the user chooses gauss legendre. If you want, you can keep try-except in the gauss_legendre_builders
function.
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.
Sure, I will move it.
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.
Thank you :)
@aobo-y has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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.
LGTM! Thank you very much for the fix, @aobo-y!
Reduce the dependency on numpy in approximation methods
torch.linspace
in riemann methods