orng 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orng-0.1.0/.github/workflows/lint.yml +35 -0
- orng-0.1.0/.github/workflows/publish.yml +47 -0
- orng-0.1.0/.github/workflows/tests.yml +37 -0
- orng-0.1.0/.gitignore +207 -0
- orng-0.1.0/.pre-commit-config.yaml +27 -0
- orng-0.1.0/LICENSE +21 -0
- orng-0.1.0/PKG-INFO +203 -0
- orng-0.1.0/README.md +160 -0
- orng-0.1.0/pyproject.toml +68 -0
- orng-0.1.0/setup.cfg +4 -0
- orng-0.1.0/src/orng/__init__.py +23 -0
- orng-0.1.0/src/orng/_utils.py +29 -0
- orng-0.1.0/src/orng/backends/__init__.py +101 -0
- orng-0.1.0/src/orng/backends/cupy.py +244 -0
- orng-0.1.0/src/orng/backends/jax.py +256 -0
- orng-0.1.0/src/orng/backends/numpy.py +209 -0
- orng-0.1.0/src/orng/backends/torch.py +380 -0
- orng-0.1.0/src/orng/functional.py +222 -0
- orng-0.1.0/src/orng/orng.py +222 -0
- orng-0.1.0/src/orng.egg-info/PKG-INFO +203 -0
- orng-0.1.0/src/orng.egg-info/SOURCES.txt +25 -0
- orng-0.1.0/src/orng.egg-info/dependency_links.txt +1 -0
- orng-0.1.0/src/orng.egg-info/requires.txt +13 -0
- orng-0.1.0/src/orng.egg-info/top_level.txt +1 -0
- orng-0.1.0/tests/test_backends.py +308 -0
- orng-0.1.0/tests/test_functional_backends.py +304 -0
- orng-0.1.0/tests/test_orng.py +314 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Lint
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main, release* ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main, release* ]
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
ruff:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: astral-sh/ruff-action@v3
|
|
19
|
+
with:
|
|
20
|
+
version: "0.14.x"
|
|
21
|
+
args: 'format --check'
|
|
22
|
+
mypy:
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
- uses: actions/setup-python@v5
|
|
27
|
+
with:
|
|
28
|
+
python-version: "3.11"
|
|
29
|
+
cache: "pip"
|
|
30
|
+
- name: Install dependencies
|
|
31
|
+
run: |
|
|
32
|
+
python -m pip install --upgrade pip
|
|
33
|
+
python -m pip install . "mypy>=1.10"
|
|
34
|
+
- name: Type check
|
|
35
|
+
run: mypy
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: Publish Python distribution to PyPI
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
name: Build distribution
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- name: Set up Python
|
|
14
|
+
uses: actions/setup-python@v5
|
|
15
|
+
with:
|
|
16
|
+
python-version: "3.x"
|
|
17
|
+
- name: Install pypa/build
|
|
18
|
+
run: >-
|
|
19
|
+
python3 -m
|
|
20
|
+
pip install
|
|
21
|
+
build
|
|
22
|
+
--user
|
|
23
|
+
- name: Build a binary wheel and a source tarball
|
|
24
|
+
run: python3 -m build
|
|
25
|
+
- name: Store the distribution packages
|
|
26
|
+
uses: actions/upload-artifact@v4
|
|
27
|
+
with:
|
|
28
|
+
name: python-package-distributions
|
|
29
|
+
path: dist/
|
|
30
|
+
|
|
31
|
+
pypi-publish:
|
|
32
|
+
name: Upload release to PyPI
|
|
33
|
+
needs:
|
|
34
|
+
- build
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
environment: release
|
|
37
|
+
permissions:
|
|
38
|
+
id-token: write
|
|
39
|
+
steps:
|
|
40
|
+
- name: Download all the dists
|
|
41
|
+
uses: actions/download-artifact@v4
|
|
42
|
+
with:
|
|
43
|
+
name: python-package-distributions
|
|
44
|
+
path: dist/
|
|
45
|
+
|
|
46
|
+
- name: Publish package distributions to PyPI
|
|
47
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main, release* ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main, release* ]
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
tests:
|
|
15
|
+
name: Python ${{ matrix.python-version }} (${{ matrix.os }})
|
|
16
|
+
|
|
17
|
+
strategy:
|
|
18
|
+
fail-fast: false
|
|
19
|
+
matrix:
|
|
20
|
+
os: [Ubuntu]
|
|
21
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
22
|
+
runs-on: ${{ matrix.os }}-latest
|
|
23
|
+
|
|
24
|
+
steps:
|
|
25
|
+
- name: Checkout repository and submodules
|
|
26
|
+
uses: actions/checkout@v4
|
|
27
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
28
|
+
uses: actions/setup-python@v4
|
|
29
|
+
with:
|
|
30
|
+
python-version: ${{ matrix.python-version }}
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: |
|
|
33
|
+
python -m pip install --upgrade pip
|
|
34
|
+
pip install -e .[numpy,jax,torch] --group test
|
|
35
|
+
- name: Test with pytest
|
|
36
|
+
run: |
|
|
37
|
+
python -m pytest
|
orng-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: v2.4.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: trailing-whitespace
|
|
6
|
+
- id: end-of-file-fixer
|
|
7
|
+
- id: check-yaml
|
|
8
|
+
- id: check-added-large-files
|
|
9
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
10
|
+
# Ruff version.
|
|
11
|
+
rev: v0.14.2
|
|
12
|
+
hooks:
|
|
13
|
+
# Run the linter.
|
|
14
|
+
- id: ruff
|
|
15
|
+
args: [ --fix ]
|
|
16
|
+
# Run the formatter.
|
|
17
|
+
- id: ruff-format
|
|
18
|
+
- repo: https://github.com/codespell-project/codespell
|
|
19
|
+
rev: v2.2.4
|
|
20
|
+
hooks:
|
|
21
|
+
- id: codespell
|
|
22
|
+
additional_dependencies:
|
|
23
|
+
- tomli
|
|
24
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
25
|
+
rev: v1.10.0
|
|
26
|
+
hooks:
|
|
27
|
+
- id: mypy
|
orng-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Michael J. Williams, Christian Chapman-Bird
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
orng-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: orng
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Omni RNG: A unified, cross-backend random number generator built on the Array API standard.
|
|
5
|
+
Author: Michael J. Williams, Christian Chapman-Bird
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Michael J. Williams, Christian Chapman-Bird
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/sequince-dev/orng
|
|
29
|
+
Project-URL: Repository, https://github.com/sequince-dev/orng
|
|
30
|
+
Requires-Python: >=3.10
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Requires-Dist: array-api-compat
|
|
34
|
+
Provides-Extra: numpy
|
|
35
|
+
Requires-Dist: numpy>=1.22; extra == "numpy"
|
|
36
|
+
Provides-Extra: torch
|
|
37
|
+
Requires-Dist: torch>=2.0; extra == "torch"
|
|
38
|
+
Provides-Extra: cupy
|
|
39
|
+
Requires-Dist: cupy>=12.0; extra == "cupy"
|
|
40
|
+
Provides-Extra: jax
|
|
41
|
+
Requires-Dist: jax>=0.4; extra == "jax"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# Omni RNG (`orng`)
|
|
45
|
+
|
|
46
|
+
`orng` provides a thin wrapper over several Array API–compatible random number
|
|
47
|
+
generators. It mirrors a subset of the `numpy.random.Generator` API:
|
|
48
|
+
|
|
49
|
+
- `random`
|
|
50
|
+
- `uniform`
|
|
51
|
+
- `normal`
|
|
52
|
+
- `choice`
|
|
53
|
+
- `gamma`
|
|
54
|
+
|
|
55
|
+
letting you pick the underlying backend at runtime. The following backends are
|
|
56
|
+
currently supported:
|
|
57
|
+
|
|
58
|
+
- `numpy`
|
|
59
|
+
- `torch`
|
|
60
|
+
- `cupy`
|
|
61
|
+
- `jax`
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
`orng` can be install from PyPI using `pip`:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install orng
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Backends are optional extras that you can install as needed:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install "orng[numpy]" # NumPy RNG support
|
|
75
|
+
pip install "orng[torch]" # PyTorch RNG support
|
|
76
|
+
pip install "orng[cupy]" # CuPy RNG support
|
|
77
|
+
pip install "orng[jax]" # JAX RNG support
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
You can also combine extras, e.g. `pip install "orng[numpy,torch]"`.
|
|
81
|
+
|
|
82
|
+
## Quick Start
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from orng import RandomGenerator
|
|
86
|
+
|
|
87
|
+
rng = RandomGenerator(backend="numpy", seed=42)
|
|
88
|
+
samples = rng.normal(loc=0.0, scale=1.0, size=5)
|
|
89
|
+
uniform = rng.uniform(low=-1.0, high=1.0, size=(2, 2))
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The backend module is imported lazily. If the requested library is missing,
|
|
93
|
+
`RandomGenerator` will raise an informative `ImportError` that points to the matching
|
|
94
|
+
extra.
|
|
95
|
+
|
|
96
|
+
## Functional Backend API
|
|
97
|
+
|
|
98
|
+
For JAX and other functional workflows, `orng` also provides a pure API in
|
|
99
|
+
`orng.functional`:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from orng.functional import create_functional_backend
|
|
103
|
+
|
|
104
|
+
backend = create_functional_backend("numpy")
|
|
105
|
+
state = backend.init_state(seed=42, generator=None)
|
|
106
|
+
|
|
107
|
+
x, state = backend.normal(state, loc=0.0, scale=1.0, size=(4,), dtype=None)
|
|
108
|
+
y, state = backend.uniform(state, low=-1.0, high=1.0, size=(2, 2), dtype=None)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Every sampling call takes an explicit `state` and returns
|
|
112
|
+
`(sample, next_state)`. This avoids mutable RNG objects inside compiled code.
|
|
113
|
+
|
|
114
|
+
By default this API is pure (`pure=True`). On stateful backends (`numpy`,
|
|
115
|
+
`torch`, and `cupy`) this snapshots RNG state each call. For lower overhead on
|
|
116
|
+
those backends, you can opt into a trusted mutable fast path with
|
|
117
|
+
`pure=False`:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
backend = create_functional_backend("numpy", pure=False)
|
|
121
|
+
state = backend.init_state(seed=42, generator=None) # numpy.random.Generator
|
|
122
|
+
x, state = backend.normal(state, loc=0.0, scale=1.0, size=(4,))
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The JAX functional backend is always pure and does not support `pure=False`.
|
|
126
|
+
|
|
127
|
+
Supported functional methods:
|
|
128
|
+
|
|
129
|
+
- `random`
|
|
130
|
+
- `uniform`
|
|
131
|
+
- `normal`
|
|
132
|
+
- `choice`
|
|
133
|
+
- `gamma`
|
|
134
|
+
|
|
135
|
+
### JAX Compilation Example
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
import jax
|
|
139
|
+
import jax.numpy as jnp
|
|
140
|
+
from orng.functional import create_functional_backend
|
|
141
|
+
|
|
142
|
+
backend = create_functional_backend("jax")
|
|
143
|
+
state = backend.init_state(seed=0, generator=None)
|
|
144
|
+
|
|
145
|
+
@jax.jit
|
|
146
|
+
def step(key):
|
|
147
|
+
sample, next_key = backend.normal(
|
|
148
|
+
key, loc=0.0, scale=1.0, size=(8,), dtype=jnp.float32
|
|
149
|
+
)
|
|
150
|
+
return sample, next_key
|
|
151
|
+
|
|
152
|
+
sample, state = step(state)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Functional State Reference
|
|
156
|
+
|
|
157
|
+
The functional API follows the native conventions of each backend rather than
|
|
158
|
+
introducing a wrapper state type.
|
|
159
|
+
|
|
160
|
+
`init_state(seed=..., generator=...)` accepts backend-specific generator
|
|
161
|
+
inputs:
|
|
162
|
+
|
|
163
|
+
| Backend | `generator` argument |
|
|
164
|
+
|---------|----------------------|
|
|
165
|
+
| `numpy` | `numpy.random.Generator` |
|
|
166
|
+
| `torch` | `torch.Generator` |
|
|
167
|
+
| `cupy` | `cupy.random.Generator` |
|
|
168
|
+
| `jax` | JAX PRNG key array, typically from `jax.random.key(...)` |
|
|
169
|
+
|
|
170
|
+
If `generator=None`, ORNG creates a new backend-native state from `seed`. If
|
|
171
|
+
`seed=None`, the backend chooses a fresh random seed using its usual behavior.
|
|
172
|
+
|
|
173
|
+
The `state` value passed into `random`, `uniform`, `normal`, `choice`, and
|
|
174
|
+
`gamma` also matches the backend:
|
|
175
|
+
|
|
176
|
+
| Backend | `pure=True` state | `pure=False` state |
|
|
177
|
+
|---------|-------------------|--------------------|
|
|
178
|
+
| `numpy` | NumPy bit-generator state `dict` | `numpy.random.Generator` |
|
|
179
|
+
| `torch` | `TorchFunctionalState` | `torch.Generator` |
|
|
180
|
+
| `cupy` | CuPy bit-generator state `dict` | `cupy.random.Generator` |
|
|
181
|
+
| `jax` | JAX PRNG key array | not supported |
|
|
182
|
+
|
|
183
|
+
For example, NumPy in pure mode snapshots and returns a bit-generator state
|
|
184
|
+
dictionary each call, while `pure=False` threads a `numpy.random.Generator`
|
|
185
|
+
through the same functional interface. JAX always uses and returns a PRNG key.
|
|
186
|
+
|
|
187
|
+
### Backend State Reference
|
|
188
|
+
|
|
189
|
+
When you pass the optional `generator` argument to `RandomGenerator`, the expected
|
|
190
|
+
object depends on the backend:
|
|
191
|
+
|
|
192
|
+
| Backend | Generator argument |
|
|
193
|
+
|---------|--------------------|
|
|
194
|
+
| `numpy` | `numpy.random.Generator` |
|
|
195
|
+
| `torch` | `torch.Generator` |
|
|
196
|
+
| `cupy` | `cupy.random.Generator` |
|
|
197
|
+
| `jax` | `jax.random.KeyArray` (from `jax.random.key`) |
|
|
198
|
+
|
|
199
|
+
This lets you wrap an existing RNG/key instead of seeding a new one.
|
|
200
|
+
|
|
201
|
+
## Citing
|
|
202
|
+
|
|
203
|
+
If you find `orng` useful in your work, please cite the corresponding [DOI](https://doi.org/10.5281/zenodo.17544786).
|