-
Notifications
You must be signed in to change notification settings - Fork 31
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
Sampling an int with a large bound value raises a MemoryError #270
Comments
Thanks! This |
If I am not mistaken, the incriminated lines are: f3dasm/src/f3dasm/_src/experimentdata/samplers.py Lines 180 to 184 in 6b0da8b
Indeed, the The issue with displaying an upper limit in the documentation is that it's a user-specific limit, depending on the hardware. A workaround should avoid this evaluation. For an import numpy as np
def current_implementation(n_samples, lower_bound, upper_bound, step):
rng = np.random.default_rng(seed=42)
return rng.choice(
range(lower_bound, upper_bound + 1, step),
size=n_samples,
)
def proposed_workaround(n_samples, lower_bound, upper_bound, step):
rng = np.random.default_rng(seed=42)
return (
lower_bound
+ rng.integers(
low=0, high=(upper_bound - lower_bound) / step + 1, size=n_samples
)
* step
) current_implementation(n_samples=10, lower_bound=32, upper_bound=42, step=2)
proposed_workaround(n_samples=10, lower_bound=32, upper_bound=42, step=2)
current_implementation(n_samples=10, lower_bound=0, upper_bound=int(1e12), step=1)
proposed_workaround(n_samples=10, lower_bound=0, upper_bound=int(1e12), step=1)
|
The following code with a higher bound of 1e12 raises a
MemoryError
(the exact admissible value will depend on the machine).The error could be explained if the full int sequence is evaluated at some point (I did not inspect the code).
The text was updated successfully, but these errors were encountered: