-
Notifications
You must be signed in to change notification settings - Fork 744
perf: parallel downsample #4004
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
Draft
flying-sheep
wants to merge
43
commits into
main
Choose a base branch
from
parallel-downsample
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.
Draft
Changes from 33 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
de9c481
feat: support np.random.Generator
flying-sheep 8ab6661
add decorator
flying-sheep 1ef8780
scrublet
flying-sheep 5308a1a
almost done
flying-sheep 93a8c0b
Merge branch 'main' into pa/rng
flying-sheep 32b3ddc
fix scrublet_simulate_doublets
flying-sheep c3da2bb
fix _RNGIgraph compat
flying-sheep 2c82b67
Merge branch 'main' into pa/rng
flying-sheep bd85d95
whoops
flying-sheep 8247cdb
relnote
flying-sheep 47f3ceb
don’t store rng in random_state arg
flying-sheep 1e43b2a
make consistent
flying-sheep 64a0f26
use sub-generators
flying-sheep baf2c85
docs
flying-sheep 7e2fab5
paga
flying-sheep 8ad699a
test
flying-sheep a4b2d12
Selman’s findings
flying-sheep 0c30aa4
ingest
flying-sheep e8a411e
rename
flying-sheep 4077502
spawn docs
flying-sheep 5797129
fix paga
flying-sheep 9bc61f0
docs reuse
flying-sheep 43ad1ee
fix docs
flying-sheep c98ce73
no spawning without loops/parallel
flying-sheep 93a9d90
test
flying-sheep 11155c3
undo spawn param
flying-sheep 4570320
fix pca
flying-sheep d4814ee
more bench
flying-sheep 4d82e6b
fix tests
flying-sheep 65fb583
whoops
flying-sheep d8d0e80
no rng warning
flying-sheep afb93e7
parallel downsample
flying-sheep 41cd6a6
impl choice
flying-sheep a491b3a
Update src/scanpy/neighbors/__init__.py
flying-sheep f736f2d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e402b8f
test downsample_total as well
flying-sheep 1596277
don’t store random_state metadata if it’s ignored
flying-sheep 77ff5f5
parallelize
flying-sheep 908677d
explicit
flying-sheep e1fff03
fix types
flying-sheep e59ba57
docstring
flying-sheep fbdc47e
comment on RNG spawning
flying-sheep d748f0b
Merge branch 'pa/rng' into parallel-downsample
flying-sheep 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
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add support for {class}`numpy.random.Generator` to all functions previously accepting a `random_state` parameter {smaller}`P Angerer` |
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| """Shared docstrings for general parameters.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| __all__ = ["doc_rng"] | ||
|
|
||
| doc_rng = """\ | ||
| rng | ||
| Random number generation to control stochasticity. | ||
|
|
||
| If a type:`SeedLike` value, it’s used to seed a new random number generator; | ||
| If a :class:`numpy.random.Generator`, `rng`’s state will be directly advanced; | ||
| If :data:`None`, a non-reproducible random number generator is used. | ||
| See :func:`numpy.random.default_rng` for more details. | ||
|
|
||
| The default value matches legacy scanpy behavior and will change to `None` in scanpy 2.0.\ | ||
| """ |
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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from functools import cache | ||
|
|
||
| import numba as nb | ||
| import numpy as np | ||
| from numba.extending import overload_method | ||
| from numba.np.numpy_support import is_nonelike | ||
|
|
||
| __all__ = ["add_np_generator_choice"] | ||
|
|
||
|
|
||
| @cache # make sure this is only called once | ||
| def add_np_generator_choice(): | ||
| """Add `np.random.Generator.choice` to numba if necessary.""" | ||
|
|
||
| @nb.njit # noqa: TID251 | ||
| def test(rng: np.random.Generator) -> int: | ||
| return rng.choice(1) | ||
|
|
||
| try: | ||
| test(np.random.default_rng()) | ||
| except nb.TypingError: | ||
| _register_np_generator_choice() | ||
|
|
||
|
|
||
| def _register_np_generator_choice(): | ||
|
|
||
| @overload_method(nb.types.NumPyRandomGeneratorType, "choice") | ||
| def NumPyRandomGeneratorType_choice(inst, a, size=None, replace=True): # noqa: FBT002, N802 | ||
| if is_nonelike(size): | ||
|
|
||
| def impl(inst, a, size=None, replace=True): # noqa: FBT002 | ||
| return inst.integers(0, a) | ||
|
|
||
| else: | ||
|
|
||
| def impl(inst, a, size=None, replace=True): # noqa: FBT002 | ||
| if replace: | ||
| return inst.integers(0, a, size=size) | ||
| else: | ||
| pool = np.arange(a) | ||
| for i in range(size): | ||
| j = inst.integers(i, a) | ||
| pool[i], pool[j] = pool[j], pool[i] | ||
| return pool[:size].copy() | ||
|
|
||
| return impl |
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.