Skip to content

Commit

Permalink
Faster import (lazy numpy) (#285)
Browse files Browse the repository at this point in the history
Co-authored-by: Anirudh Vegesana <anirudh.vegesana@gmail.com>
  • Loading branch information
lebrice and anivegesana committed Aug 10, 2023
1 parent 17b96b1 commit 77e4ff5
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions simple_parsing/helpers/hparams/priors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
overload,
)

numpy_installed = False
try:
import numpy as np
import importlib.util

numpy_installed = True
except ImportError:
pass
class _np_lazy:
def __getattr__(self, attr):
global np
import numpy as np
return getattr(np, attr)

np = _np_lazy()
numpy_installed = importlib.util.find_spec("numpy") is not None


T = TypeVar("T")
Expand Down

0 comments on commit 77e4ff5

Please sign in to comment.