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

replace np with torch linsapce in riemann approximation #714

Closed
wants to merge 2 commits into from

Conversation

aobo-y
Copy link
Contributor

@aobo-y aobo-y commented Jul 9, 2021

Reduce the dependency on numpy in approximation methods

  • use torch.linspace in riemann methods

@facebook-github-bot
Copy link
Contributor

@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
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@NarineK NarineK Jul 9, 2021

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :)

@facebook-github-bot
Copy link
Contributor

@aobo-y has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@NarineK NarineK left a 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!

@facebook-github-bot
Copy link
Contributor

@aobo-y merged this pull request in 69a6a94.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants