Skip to content

Fixed #1112 Migrate to New NumPy Random Number Generator (RNG) API#1147

Open
seanlaw wants to merge 3 commits into
stumpy-dev:mainfrom
seanlaw:migrate_numpy_rng
Open

Fixed #1112 Migrate to New NumPy Random Number Generator (RNG) API#1147
seanlaw wants to merge 3 commits into
stumpy-dev:mainfrom
seanlaw:migrate_numpy_rng

Conversation

@seanlaw

@seanlaw seanlaw commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

See issue #1112

This is a second attempt that follows failed PR #1131

Pull Request Checklist

Below is a simple checklist but please do not hesitate to ask for assistance!

  • Fork, clone, and checkout the newest version of the code
  • Create a new branch
  • Make necessary code changes
  • Install black (i.e., python -m pip install black or conda install -c conda-forge black)
  • Install flake8 (i.e., python -m pip install flake8 or conda install -c conda-forge flake8)
  • Install pytest-cov (i.e., python -m pip install pytest-cov or conda install -c conda-forge pytest-cov)
  • Run black --exclude=".*\.ipynb" --extend-exclude=".venv" --diff ./ in the root stumpy directory
  • Run flake8 --extend-exclude=.venv ./ in the root stumpy directory
  • Run ./setup.sh dev && ./test.sh in the root stumpy directory
  • Reference a Github issue (and create one if one doesn't already exist)

To Do List

  1. Search for np.random
  2. Replace np.random.rand(x) with rng.RNG.random(x)
  3. Replace np.random.rand(x*y).reshape(x,y) with rng.RNG.random(size=(x, y))
  4. Replace np.random.uniform(x, y, [z]) with rng.RNG.uniform(x, y, size=z)
  5. Replace np.random.permutation([x, y, z]) with rng.RNG.permutation([x, y, z])
  6. Replace np.random.randint(x, y, z) with rng.RNG.integers(x, y, z)
  7. Replace np.random.choice([x, y], l, replace=True) with rng.RNG.choice([x, y], l, replace=True)
  8. Replace np.random.normal(size=x) with rng.RNG.normal(size=x)
  9. Replace all np.random from docstrings, README, tutorials, etc

@gitnotebooks

gitnotebooks Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review these changes at https://app.gitnotebooks.com/stumpy-dev/stumpy/pull/1147

@seanlaw

seanlaw commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@NimaSarajpoor I've created a newstumpy/rng.py module that will manage our random number usage and tested the numpy.random migration on test_core.py as an initial trial run. Would you mind taking a look and providing any feedback before I do the same thing on the other tests?

I will be adding a tests/test_rng.py next

@NimaSarajpoor

Copy link
Copy Markdown
Collaborator

@seanlaw Please allow me some time to take a look. Will provide an update in a couple of days.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants