-
Notifications
You must be signed in to change notification settings - Fork 15
Add type annotations around sumpy.fmm #300
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
Open
alexfikl
wants to merge
6
commits into
inducer:main
Choose a base branch
from
alexfikl:type-fmm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c15e7b2
feat(typing): add type annotations to fmm.py
alexfikl 526bde7
feat(typing): add type annotations to __init__.py
alexfikl 55701b3
feat(typing): improve type annotations for tools.py
alexfikl 78da23b
fix: add boxtree to first-party imports
alexfikl 9f1c6e4
docs: fix from type annotations in fmm
alexfikl 7179cc7
chore: update baseline
alexfikl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| import types | ||
| from collections.abc import Hashable | ||
|
|
||
| import loopy as lp | ||
|
|
@@ -72,15 +73,13 @@ | |
|
|
||
| # {{{ optimization control | ||
|
|
||
| OPT_ENABLED = True | ||
|
|
||
| OPT_ENABLED = "SUMPY_NO_OPT" not in os.environ | ||
|
|
||
|
|
||
| def set_optimization_enabled(flag): | ||
| def set_optimization_enabled(flag: bool) -> None: | ||
| """Set whether the :mod:`loopy` kernels should be optimized.""" | ||
| global OPT_ENABLED | ||
| OPT_ENABLED = flag | ||
| OPT_ENABLED = flag # pyright: ignore[reportConstantRedefinition] | ||
|
|
||
| # }}} | ||
|
|
||
|
|
@@ -91,36 +90,55 @@ def set_optimization_enabled(flag): | |
| "SUMPY_NO_CACHE" not in os.environ | ||
| and "CG_NO_CACHE" not in os.environ) | ||
|
|
||
| NO_CACHE_KERNELS = tuple(os.environ.get("SUMPY_NO_CACHE_KERNELS", | ||
| "").split(",")) | ||
| NO_CACHE_KERNELS = tuple(os.environ.get("SUMPY_NO_CACHE_KERNELS", "").split(",")) | ||
|
|
||
|
|
||
| def set_caching_enabled(flag, no_cache_kernels=()): | ||
| def set_caching_enabled(flag: bool, no_cache_kernels: tuple[str, ...] = ()) -> None: | ||
| """Set whether :mod:`loopy` is allowed to use disk caching for its various | ||
| code generation stages. | ||
| """ | ||
| global CACHING_ENABLED, NO_CACHE_KERNELS | ||
| NO_CACHE_KERNELS = no_cache_kernels | ||
| CACHING_ENABLED = flag | ||
| NO_CACHE_KERNELS = no_cache_kernels # pyright: ignore[reportConstantRedefinition] | ||
| CACHING_ENABLED = flag # pyright: ignore[reportConstantRedefinition] | ||
|
|
||
|
|
||
| class CacheMode: | ||
| """A context manager for setting whether :mod:`sumpy` is allowed to use | ||
| disk caches. | ||
| """ | ||
|
|
||
| def __init__(self, new_flag, new_no_cache_kernels=()): | ||
| new_flag: bool | ||
| previous_flag: bool | None | ||
|
|
||
| new_no_cache_kernels: tuple[str, ...] | ||
| previous_no_cache_kernels: tuple[str, ...] | None | ||
|
|
||
| def __init__(self, | ||
| new_flag: bool, | ||
| new_no_cache_kernels: tuple[str, ...] = ()) -> None: | ||
| self.new_flag = new_flag | ||
| self.previous_flag = None | ||
| self.new_no_cache_kernels = new_no_cache_kernels | ||
| self.previous_no_cache_kernels = None | ||
|
|
||
| def __enter__(self) -> None: | ||
| if self.previous_flag is not None or self.previous_no_cache_kernels is not None: | ||
| raise RuntimeError("cannot reuse the 'CacheMode' context manager") | ||
|
Comment on lines
+125
to
+126
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| def __enter__(self): | ||
| self.previous_flag = CACHING_ENABLED | ||
| self.previous_kernels = NO_CACHE_KERNELS | ||
| self.previous_no_cache_kernels = NO_CACHE_KERNELS | ||
| set_caching_enabled(self.new_flag, self.new_no_cache_kernels) | ||
|
|
||
| def __exit__(self, exc_type, exc_val, exc_tb): | ||
| set_caching_enabled(self.previous_flag, self.previous_kernels) | ||
| del self.previous_flag | ||
| del self.previous_kernels | ||
| def __exit__(self, | ||
| exc_type: type[BaseException] | None, | ||
| exc_val: BaseException | None, | ||
| exc_tb: types.TracebackType | None) -> None: | ||
| if self.previous_flag is None or self.previous_no_cache_kernels is None: | ||
| raise RuntimeError("cannot reuse the 'CacheMode' context manager") | ||
|
|
||
| set_caching_enabled(self.previous_flag, self.previous_no_cache_kernels) | ||
|
|
||
| self.previous_flag = None | ||
| self.previous_no_cache_kernels = None | ||
|
|
||
| # }}} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.