orng 0.1.0a1__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.
@@ -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 . --group test
35
+ - name: Test with pytest
36
+ run: |
37
+ python -m pytest
@@ -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.0a1/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.0a1/PKG-INFO ADDED
@@ -0,0 +1,121 @@
1
+ Metadata-Version: 2.4
2
+ Name: orng
3
+ Version: 0.1.0a1
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
+ Provides-Extra: numpy
34
+ Requires-Dist: numpy>=1.22; extra == "numpy"
35
+ Provides-Extra: torch
36
+ Requires-Dist: torch>=2.0; extra == "torch"
37
+ Provides-Extra: cupy
38
+ Requires-Dist: cupy>=12.0; extra == "cupy"
39
+ Provides-Extra: jax
40
+ Requires-Dist: jax>=0.4; extra == "jax"
41
+ Dynamic: license-file
42
+
43
+ # Omni RNG (`orng`)
44
+
45
+ `orng` provides a thin facade over several Array API–compatible random number
46
+ generators. It mirrors the subset of the `numpy.random.Generator` API:
47
+
48
+ - `random`
49
+ - `uniform`
50
+ - `normal`
51
+ - `choice`
52
+
53
+ letting you pick the underlying backend at runtime. The following backends are
54
+ currently supported:
55
+
56
+ - `numpy`
57
+ - `torch`
58
+ - `cupy`
59
+ - `jax`
60
+
61
+ ## Installation
62
+
63
+ The core package only depends on the standard Python library:
64
+
65
+ ```bash
66
+ pip install orng
67
+ ```
68
+
69
+ Backends are optional extras that you can install on demand:
70
+
71
+ ```bash
72
+ pip install "orng[numpy]" # NumPy RNG support
73
+ pip install "orng[torch]" # PyTorch RNG support
74
+ pip install "orng[cupy]" # CuPy RNG support
75
+ pip install "orng[jax]" # JAX RNG support
76
+ ```
77
+
78
+ You can also combine extras, e.g. `pip install "orng[numpy,torch]"`.
79
+
80
+ ## Quick Start
81
+
82
+ ```python
83
+ from orng import ArrayRNG
84
+
85
+ rng = ArrayRNG(backend="numpy", seed=42)
86
+ samples = rng.normal(loc=0.0, scale=1.0, size=5)
87
+ uniform = rng.uniform(low=-1.0, high=1.0, size=(2, 2))
88
+ ```
89
+
90
+ The backend module is imported lazily. If the requested library is missing,
91
+ `ArrayRNG` will raise an informative `ImportError` that points to the matching
92
+ extra.
93
+
94
+ ### Backend State Reference
95
+
96
+ When you pass the optional `generator` argument to `ArrayRNG`, the expected
97
+ object depends on the backend:
98
+
99
+ | Backend | Generator argument |
100
+ |---------|--------------------|
101
+ | `numpy` | `numpy.random.Generator` |
102
+ | `torch` | `torch.Generator` |
103
+ | `cupy` | `cupy.random.Generator` |
104
+ | `jax` | `jax.random.KeyArray` (from `jax.random.key`) |
105
+
106
+ This lets you wrap an existing RNG/key instead of seeding a new one.
107
+
108
+ ## Project Layout
109
+
110
+ ```
111
+ orng/
112
+ ├── src/orng/
113
+ │ ├── __init__.py # package exports
114
+ │ ├── _utils.py # shared helpers (internal)
115
+ │ ├── orng.py # ArrayRNG facade
116
+ │ └── backends/ # backend-specific implementations
117
+ └── README.md
118
+ ```
119
+
120
+ Each backend class lives in its own module under `orng/backends/`, keeping the
121
+ core facade compact and making optional dependencies easy to manage.
orng-0.1.0a1/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Omni RNG (`orng`)
2
+
3
+ `orng` provides a thin facade over several Array API–compatible random number
4
+ generators. It mirrors the subset of the `numpy.random.Generator` API:
5
+
6
+ - `random`
7
+ - `uniform`
8
+ - `normal`
9
+ - `choice`
10
+
11
+ letting you pick the underlying backend at runtime. The following backends are
12
+ currently supported:
13
+
14
+ - `numpy`
15
+ - `torch`
16
+ - `cupy`
17
+ - `jax`
18
+
19
+ ## Installation
20
+
21
+ The core package only depends on the standard Python library:
22
+
23
+ ```bash
24
+ pip install orng
25
+ ```
26
+
27
+ Backends are optional extras that you can install on demand:
28
+
29
+ ```bash
30
+ pip install "orng[numpy]" # NumPy RNG support
31
+ pip install "orng[torch]" # PyTorch RNG support
32
+ pip install "orng[cupy]" # CuPy RNG support
33
+ pip install "orng[jax]" # JAX RNG support
34
+ ```
35
+
36
+ You can also combine extras, e.g. `pip install "orng[numpy,torch]"`.
37
+
38
+ ## Quick Start
39
+
40
+ ```python
41
+ from orng import ArrayRNG
42
+
43
+ rng = ArrayRNG(backend="numpy", seed=42)
44
+ samples = rng.normal(loc=0.0, scale=1.0, size=5)
45
+ uniform = rng.uniform(low=-1.0, high=1.0, size=(2, 2))
46
+ ```
47
+
48
+ The backend module is imported lazily. If the requested library is missing,
49
+ `ArrayRNG` will raise an informative `ImportError` that points to the matching
50
+ extra.
51
+
52
+ ### Backend State Reference
53
+
54
+ When you pass the optional `generator` argument to `ArrayRNG`, the expected
55
+ object depends on the backend:
56
+
57
+ | Backend | Generator argument |
58
+ |---------|--------------------|
59
+ | `numpy` | `numpy.random.Generator` |
60
+ | `torch` | `torch.Generator` |
61
+ | `cupy` | `cupy.random.Generator` |
62
+ | `jax` | `jax.random.KeyArray` (from `jax.random.key`) |
63
+
64
+ This lets you wrap an existing RNG/key instead of seeding a new one.
65
+
66
+ ## Project Layout
67
+
68
+ ```
69
+ orng/
70
+ ├── src/orng/
71
+ │ ├── __init__.py # package exports
72
+ │ ├── _utils.py # shared helpers (internal)
73
+ │ ├── orng.py # ArrayRNG facade
74
+ │ └── backends/ # backend-specific implementations
75
+ └── README.md
76
+ ```
77
+
78
+ Each backend class lives in its own module under `orng/backends/`, keeping the
79
+ core facade compact and making optional dependencies easy to manage.
@@ -0,0 +1,66 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel", "setuptools-scm[toml]>=6.2"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "orng"
7
+ description = "Omni RNG: A unified, cross-backend random number generator built on the Array API standard."
8
+ readme = "README.md"
9
+ requires-python = ">=3.10"
10
+ license = { file = "LICENSE" }
11
+ authors = [
12
+ { name = "Michael J. Williams" },
13
+ { name = "Christian Chapman-Bird" }
14
+ ]
15
+ dependencies = []
16
+ dynamic = [
17
+ "version"
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/sequince-dev/orng"
22
+ Repository = "https://github.com/sequince-dev/orng"
23
+
24
+ [tool.setuptools]
25
+ package-dir = {"" = "src"}
26
+
27
+ [tool.setuptools.packages.find]
28
+ where = ["src"]
29
+ include = ["orng*"]
30
+
31
+ [tool.setuptools_scm]
32
+
33
+ [project.optional-dependencies]
34
+ numpy = ["numpy>=1.22"]
35
+ torch = ["torch>=2.0"]
36
+ cupy = ["cupy>=12.0"]
37
+ jax = ["jax>=0.4"]
38
+
39
+ [dependency-groups]
40
+ test = [
41
+ "pytest>=7.0",
42
+ "pytest-cov>=4.0",
43
+ ]
44
+ dev = [
45
+ "pre-commit",
46
+ "mypy>=1.10",
47
+ {include-group = "test"},
48
+ ]
49
+
50
+ [tool.ruff]
51
+ line-length = 79
52
+ indent-width = 4
53
+ target-version = "py310"
54
+
55
+ [tool.ruff.lint]
56
+ # Allow fix for all enabled rules (when `--fix`) is provided.
57
+ fixable = ["ALL"]
58
+ extend-select = ["I"]
59
+
60
+ [tool.mypy]
61
+ python_version = "3.10"
62
+ packages = ["orng"]
63
+ mypy_path = ["src"]
64
+ ignore_missing_imports = true
65
+ warn_unused_configs = true
66
+ show_error_codes = true
orng-0.1.0a1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,10 @@
1
+ import importlib.metadata
2
+
3
+ try:
4
+ __version__ = importlib.metadata.version("orng")
5
+ except importlib.metadata.PackageNotFoundError:
6
+ __version__ = "unknown"
7
+
8
+ from .orng import ArrayRNG
9
+
10
+ __all__ = ["ArrayRNG", "__version__"]
@@ -0,0 +1,29 @@
1
+ from __future__ import annotations
2
+
3
+ import math
4
+ from typing import Sequence, Tuple
5
+
6
+ SizeLike = int | Sequence[int] | None
7
+
8
+
9
+ def normalize_shape(size: SizeLike) -> Tuple[int, ...]:
10
+ """Convert a size argument to a canonical ``tuple`` form."""
11
+ if size is None:
12
+ return ()
13
+ if isinstance(size, int):
14
+ if size < 0:
15
+ raise ValueError("size must be non-negative.")
16
+ return (size,)
17
+ shape = tuple(int(dim) for dim in size)
18
+ if any(dim < 0 for dim in shape):
19
+ raise ValueError("size entries must be non-negative.")
20
+ return shape
21
+
22
+
23
+ def total_size(shape: Tuple[int, ...]) -> int:
24
+ if not shape:
25
+ return 1
26
+ return math.prod(shape)
27
+
28
+
29
+ __all__ = ["SizeLike", "normalize_shape", "total_size"]