Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_array_object.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_data_type_functions.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_dtypes.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_elementwise_functions.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_manipulation_functions.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_set_functions.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_statistical_functions.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_typing.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_utility_functions.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/linalg.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/setup.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/_array_object.py +1118 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/_constants.py +6 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/_manipulation_functions.py +97 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/_set_functions.py +102 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/_sorting_functions.py +49 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/_statistical_functions.py +115 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/_utility_functions.py +37 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/__init__.py +7 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/test_array_object.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/test_creation_functions.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/test_data_type_functions.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/test_elementwise_functions.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/test_set_functions.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/test_sorting_functions.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/test_creation_functions.py +142 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/test_data_type_functions.py +19 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/test_set_functions.py +19 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/test_sorting_functions.py +23 -0
- wemm/lib/python3.10/site-packages/numpy/array_api/tests/test_validation.py +27 -0
- wemm/lib/python3.10/site-packages/numpy/doc/__pycache__/ufuncs.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/random/__init__.pxd +14 -0
- wemm/lib/python3.10/site-packages/numpy/random/__init__.py +215 -0
- wemm/lib/python3.10/site-packages/numpy/random/__init__.pyi +70 -0
- wemm/lib/python3.10/site-packages/numpy/random/_bounded_integers.pxd +29 -0
- wemm/lib/python3.10/site-packages/numpy/random/_common.pxd +106 -0
- wemm/lib/python3.10/site-packages/numpy/random/_examples/cffi/__pycache__/extending.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/random/_examples/cffi/__pycache__/parse.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/random/_examples/cffi/extending.py +40 -0
- wemm/lib/python3.10/site-packages/numpy/random/_examples/cffi/parse.py +55 -0
- wemm/lib/python3.10/site-packages/numpy/random/_examples/cython/__pycache__/setup.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/random/_examples/cython/extending_distributions.pyx +117 -0
- wemm/lib/python3.10/site-packages/numpy/random/_examples/numba/__pycache__/extending.cpython-310.pyc +0 -0
- wemm/lib/python3.10/site-packages/numpy/random/_examples/numba/extending.py +84 -0
- wemm/lib/python3.10/site-packages/numpy/random/_generator.pyi +638 -0
- wemm/lib/python3.10/site-packages/numpy/random/_mt19937.pyi +22 -0
- wemm/lib/python3.10/site-packages/numpy/random/_pcg64.pyi +42 -0
- wemm/lib/python3.10/site-packages/numpy/random/_philox.pyi +36 -0
- wemm/lib/python3.10/site-packages/numpy/random/_pickle.py +83 -0
wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_array_object.cpython-310.pyc
ADDED
|
Binary file (27.9 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_data_type_functions.cpython-310.pyc
ADDED
|
Binary file (4.26 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_dtypes.cpython-310.pyc
ADDED
|
Binary file (1.94 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_elementwise_functions.cpython-310.pyc
ADDED
|
Binary file (18.6 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_manipulation_functions.cpython-310.pyc
ADDED
|
Binary file (3.44 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_set_functions.cpython-310.pyc
ADDED
|
Binary file (2.22 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_statistical_functions.cpython-310.pyc
ADDED
|
Binary file (2.65 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_typing.cpython-310.pyc
ADDED
|
Binary file (2.04 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/_utility_functions.cpython-310.pyc
ADDED
|
Binary file (1.06 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/linalg.cpython-310.pyc
ADDED
|
Binary file (12.6 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/__pycache__/setup.cpython-310.pyc
ADDED
|
Binary file (548 Bytes). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/_array_object.py
ADDED
|
@@ -0,0 +1,1118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Wrapper class around the ndarray object for the array API standard.
|
| 3 |
+
|
| 4 |
+
The array API standard defines some behaviors differently than ndarray, in
|
| 5 |
+
particular, type promotion rules are different (the standard has no
|
| 6 |
+
value-based casting). The standard also specifies a more limited subset of
|
| 7 |
+
array methods and functionalities than are implemented on ndarray. Since the
|
| 8 |
+
goal of the array_api namespace is to be a minimal implementation of the array
|
| 9 |
+
API standard, we need to define a separate wrapper class for the array_api
|
| 10 |
+
namespace.
|
| 11 |
+
|
| 12 |
+
The standard compliant class is only a wrapper class. It is *not* a subclass
|
| 13 |
+
of ndarray.
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
|
| 18 |
+
import operator
|
| 19 |
+
from enum import IntEnum
|
| 20 |
+
from ._creation_functions import asarray
|
| 21 |
+
from ._dtypes import (
|
| 22 |
+
_all_dtypes,
|
| 23 |
+
_boolean_dtypes,
|
| 24 |
+
_integer_dtypes,
|
| 25 |
+
_integer_or_boolean_dtypes,
|
| 26 |
+
_floating_dtypes,
|
| 27 |
+
_numeric_dtypes,
|
| 28 |
+
_result_type,
|
| 29 |
+
_dtype_categories,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
from typing import TYPE_CHECKING, Optional, Tuple, Union, Any, SupportsIndex
|
| 33 |
+
import types
|
| 34 |
+
|
| 35 |
+
if TYPE_CHECKING:
|
| 36 |
+
from ._typing import Any, PyCapsule, Device, Dtype
|
| 37 |
+
import numpy.typing as npt
|
| 38 |
+
|
| 39 |
+
import numpy as np
|
| 40 |
+
|
| 41 |
+
from numpy import array_api
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class Array:
|
| 45 |
+
"""
|
| 46 |
+
n-d array object for the array API namespace.
|
| 47 |
+
|
| 48 |
+
See the docstring of :py:obj:`np.ndarray <numpy.ndarray>` for more
|
| 49 |
+
information.
|
| 50 |
+
|
| 51 |
+
This is a wrapper around numpy.ndarray that restricts the usage to only
|
| 52 |
+
those things that are required by the array API namespace. Note,
|
| 53 |
+
attributes on this object that start with a single underscore are not part
|
| 54 |
+
of the API specification and should only be used internally. This object
|
| 55 |
+
should not be constructed directly. Rather, use one of the creation
|
| 56 |
+
functions, such as asarray().
|
| 57 |
+
|
| 58 |
+
"""
|
| 59 |
+
_array: np.ndarray
|
| 60 |
+
|
| 61 |
+
# Use a custom constructor instead of __init__, as manually initializing
|
| 62 |
+
# this class is not supported API.
|
| 63 |
+
@classmethod
|
| 64 |
+
def _new(cls, x, /):
|
| 65 |
+
"""
|
| 66 |
+
This is a private method for initializing the array API Array
|
| 67 |
+
object.
|
| 68 |
+
|
| 69 |
+
Functions outside of the array_api submodule should not use this
|
| 70 |
+
method. Use one of the creation functions instead, such as
|
| 71 |
+
``asarray``.
|
| 72 |
+
|
| 73 |
+
"""
|
| 74 |
+
obj = super().__new__(cls)
|
| 75 |
+
# Note: The spec does not have array scalars, only 0-D arrays.
|
| 76 |
+
if isinstance(x, np.generic):
|
| 77 |
+
# Convert the array scalar to a 0-D array
|
| 78 |
+
x = np.asarray(x)
|
| 79 |
+
if x.dtype not in _all_dtypes:
|
| 80 |
+
raise TypeError(
|
| 81 |
+
f"The array_api namespace does not support the dtype '{x.dtype}'"
|
| 82 |
+
)
|
| 83 |
+
obj._array = x
|
| 84 |
+
return obj
|
| 85 |
+
|
| 86 |
+
# Prevent Array() from working
|
| 87 |
+
def __new__(cls, *args, **kwargs):
|
| 88 |
+
raise TypeError(
|
| 89 |
+
"The array_api Array object should not be instantiated directly. Use an array creation function, such as asarray(), instead."
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
# These functions are not required by the spec, but are implemented for
|
| 93 |
+
# the sake of usability.
|
| 94 |
+
|
| 95 |
+
def __str__(self: Array, /) -> str:
|
| 96 |
+
"""
|
| 97 |
+
Performs the operation __str__.
|
| 98 |
+
"""
|
| 99 |
+
return self._array.__str__().replace("array", "Array")
|
| 100 |
+
|
| 101 |
+
def __repr__(self: Array, /) -> str:
|
| 102 |
+
"""
|
| 103 |
+
Performs the operation __repr__.
|
| 104 |
+
"""
|
| 105 |
+
suffix = f", dtype={self.dtype.name})"
|
| 106 |
+
if 0 in self.shape:
|
| 107 |
+
prefix = "empty("
|
| 108 |
+
mid = str(self.shape)
|
| 109 |
+
else:
|
| 110 |
+
prefix = "Array("
|
| 111 |
+
mid = np.array2string(self._array, separator=', ', prefix=prefix, suffix=suffix)
|
| 112 |
+
return prefix + mid + suffix
|
| 113 |
+
|
| 114 |
+
# This function is not required by the spec, but we implement it here for
|
| 115 |
+
# convenience so that np.asarray(np.array_api.Array) will work.
|
| 116 |
+
def __array__(self, dtype: None | np.dtype[Any] = None) -> npt.NDArray[Any]:
|
| 117 |
+
"""
|
| 118 |
+
Warning: this method is NOT part of the array API spec. Implementers
|
| 119 |
+
of other libraries need not include it, and users should not assume it
|
| 120 |
+
will be present in other implementations.
|
| 121 |
+
|
| 122 |
+
"""
|
| 123 |
+
return np.asarray(self._array, dtype=dtype)
|
| 124 |
+
|
| 125 |
+
# These are various helper functions to make the array behavior match the
|
| 126 |
+
# spec in places where it either deviates from or is more strict than
|
| 127 |
+
# NumPy behavior
|
| 128 |
+
|
| 129 |
+
def _check_allowed_dtypes(self, other: bool | int | float | Array, dtype_category: str, op: str) -> Array:
|
| 130 |
+
"""
|
| 131 |
+
Helper function for operators to only allow specific input dtypes
|
| 132 |
+
|
| 133 |
+
Use like
|
| 134 |
+
|
| 135 |
+
other = self._check_allowed_dtypes(other, 'numeric', '__add__')
|
| 136 |
+
if other is NotImplemented:
|
| 137 |
+
return other
|
| 138 |
+
"""
|
| 139 |
+
|
| 140 |
+
if self.dtype not in _dtype_categories[dtype_category]:
|
| 141 |
+
raise TypeError(f"Only {dtype_category} dtypes are allowed in {op}")
|
| 142 |
+
if isinstance(other, (int, float, bool)):
|
| 143 |
+
other = self._promote_scalar(other)
|
| 144 |
+
elif isinstance(other, Array):
|
| 145 |
+
if other.dtype not in _dtype_categories[dtype_category]:
|
| 146 |
+
raise TypeError(f"Only {dtype_category} dtypes are allowed in {op}")
|
| 147 |
+
else:
|
| 148 |
+
return NotImplemented
|
| 149 |
+
|
| 150 |
+
# This will raise TypeError for type combinations that are not allowed
|
| 151 |
+
# to promote in the spec (even if the NumPy array operator would
|
| 152 |
+
# promote them).
|
| 153 |
+
res_dtype = _result_type(self.dtype, other.dtype)
|
| 154 |
+
if op.startswith("__i"):
|
| 155 |
+
# Note: NumPy will allow in-place operators in some cases where
|
| 156 |
+
# the type promoted operator does not match the left-hand side
|
| 157 |
+
# operand. For example,
|
| 158 |
+
|
| 159 |
+
# >>> a = np.array(1, dtype=np.int8)
|
| 160 |
+
# >>> a += np.array(1, dtype=np.int16)
|
| 161 |
+
|
| 162 |
+
# The spec explicitly disallows this.
|
| 163 |
+
if res_dtype != self.dtype:
|
| 164 |
+
raise TypeError(
|
| 165 |
+
f"Cannot perform {op} with dtypes {self.dtype} and {other.dtype}"
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
return other
|
| 169 |
+
|
| 170 |
+
# Helper function to match the type promotion rules in the spec
|
| 171 |
+
def _promote_scalar(self, scalar):
|
| 172 |
+
"""
|
| 173 |
+
Returns a promoted version of a Python scalar appropriate for use with
|
| 174 |
+
operations on self.
|
| 175 |
+
|
| 176 |
+
This may raise an OverflowError in cases where the scalar is an
|
| 177 |
+
integer that is too large to fit in a NumPy integer dtype, or
|
| 178 |
+
TypeError when the scalar type is incompatible with the dtype of self.
|
| 179 |
+
"""
|
| 180 |
+
# Note: Only Python scalar types that match the array dtype are
|
| 181 |
+
# allowed.
|
| 182 |
+
if isinstance(scalar, bool):
|
| 183 |
+
if self.dtype not in _boolean_dtypes:
|
| 184 |
+
raise TypeError(
|
| 185 |
+
"Python bool scalars can only be promoted with bool arrays"
|
| 186 |
+
)
|
| 187 |
+
elif isinstance(scalar, int):
|
| 188 |
+
if self.dtype in _boolean_dtypes:
|
| 189 |
+
raise TypeError(
|
| 190 |
+
"Python int scalars cannot be promoted with bool arrays"
|
| 191 |
+
)
|
| 192 |
+
elif isinstance(scalar, float):
|
| 193 |
+
if self.dtype not in _floating_dtypes:
|
| 194 |
+
raise TypeError(
|
| 195 |
+
"Python float scalars can only be promoted with floating-point arrays."
|
| 196 |
+
)
|
| 197 |
+
else:
|
| 198 |
+
raise TypeError("'scalar' must be a Python scalar")
|
| 199 |
+
|
| 200 |
+
# Note: scalars are unconditionally cast to the same dtype as the
|
| 201 |
+
# array.
|
| 202 |
+
|
| 203 |
+
# Note: the spec only specifies integer-dtype/int promotion
|
| 204 |
+
# behavior for integers within the bounds of the integer dtype.
|
| 205 |
+
# Outside of those bounds we use the default NumPy behavior (either
|
| 206 |
+
# cast or raise OverflowError).
|
| 207 |
+
return Array._new(np.array(scalar, self.dtype))
|
| 208 |
+
|
| 209 |
+
@staticmethod
|
| 210 |
+
def _normalize_two_args(x1, x2) -> Tuple[Array, Array]:
|
| 211 |
+
"""
|
| 212 |
+
Normalize inputs to two arg functions to fix type promotion rules
|
| 213 |
+
|
| 214 |
+
NumPy deviates from the spec type promotion rules in cases where one
|
| 215 |
+
argument is 0-dimensional and the other is not. For example:
|
| 216 |
+
|
| 217 |
+
>>> import numpy as np
|
| 218 |
+
>>> a = np.array([1.0], dtype=np.float32)
|
| 219 |
+
>>> b = np.array(1.0, dtype=np.float64)
|
| 220 |
+
>>> np.add(a, b) # The spec says this should be float64
|
| 221 |
+
array([2.], dtype=float32)
|
| 222 |
+
|
| 223 |
+
To fix this, we add a dimension to the 0-dimension array before passing it
|
| 224 |
+
through. This works because a dimension would be added anyway from
|
| 225 |
+
broadcasting, so the resulting shape is the same, but this prevents NumPy
|
| 226 |
+
from not promoting the dtype.
|
| 227 |
+
"""
|
| 228 |
+
# Another option would be to use signature=(x1.dtype, x2.dtype, None),
|
| 229 |
+
# but that only works for ufuncs, so we would have to call the ufuncs
|
| 230 |
+
# directly in the operator methods. One should also note that this
|
| 231 |
+
# sort of trick wouldn't work for functions like searchsorted, which
|
| 232 |
+
# don't do normal broadcasting, but there aren't any functions like
|
| 233 |
+
# that in the array API namespace.
|
| 234 |
+
if x1.ndim == 0 and x2.ndim != 0:
|
| 235 |
+
# The _array[None] workaround was chosen because it is relatively
|
| 236 |
+
# performant. broadcast_to(x1._array, x2.shape) is much slower. We
|
| 237 |
+
# could also manually type promote x2, but that is more complicated
|
| 238 |
+
# and about the same performance as this.
|
| 239 |
+
x1 = Array._new(x1._array[None])
|
| 240 |
+
elif x2.ndim == 0 and x1.ndim != 0:
|
| 241 |
+
x2 = Array._new(x2._array[None])
|
| 242 |
+
return (x1, x2)
|
| 243 |
+
|
| 244 |
+
# Note: A large fraction of allowed indices are disallowed here (see the
|
| 245 |
+
# docstring below)
|
| 246 |
+
def _validate_index(self, key):
|
| 247 |
+
"""
|
| 248 |
+
Validate an index according to the array API.
|
| 249 |
+
|
| 250 |
+
The array API specification only requires a subset of indices that are
|
| 251 |
+
supported by NumPy. This function will reject any index that is
|
| 252 |
+
allowed by NumPy but not required by the array API specification. We
|
| 253 |
+
always raise ``IndexError`` on such indices (the spec does not require
|
| 254 |
+
any specific behavior on them, but this makes the NumPy array API
|
| 255 |
+
namespace a minimal implementation of the spec). See
|
| 256 |
+
https://data-apis.org/array-api/latest/API_specification/indexing.html
|
| 257 |
+
for the full list of required indexing behavior
|
| 258 |
+
|
| 259 |
+
This function raises IndexError if the index ``key`` is invalid. It
|
| 260 |
+
only raises ``IndexError`` on indices that are not already rejected by
|
| 261 |
+
NumPy, as NumPy will already raise the appropriate error on such
|
| 262 |
+
indices. ``shape`` may be None, in which case, only cases that are
|
| 263 |
+
independent of the array shape are checked.
|
| 264 |
+
|
| 265 |
+
The following cases are allowed by NumPy, but not specified by the array
|
| 266 |
+
API specification:
|
| 267 |
+
|
| 268 |
+
- Indices to not include an implicit ellipsis at the end. That is,
|
| 269 |
+
every axis of an array must be explicitly indexed or an ellipsis
|
| 270 |
+
included. This behaviour is sometimes referred to as flat indexing.
|
| 271 |
+
|
| 272 |
+
- The start and stop of a slice may not be out of bounds. In
|
| 273 |
+
particular, for a slice ``i:j:k`` on an axis of size ``n``, only the
|
| 274 |
+
following are allowed:
|
| 275 |
+
|
| 276 |
+
- ``i`` or ``j`` omitted (``None``).
|
| 277 |
+
- ``-n <= i <= max(0, n - 1)``.
|
| 278 |
+
- For ``k > 0`` or ``k`` omitted (``None``), ``-n <= j <= n``.
|
| 279 |
+
- For ``k < 0``, ``-n - 1 <= j <= max(0, n - 1)``.
|
| 280 |
+
|
| 281 |
+
- Boolean array indices are not allowed as part of a larger tuple
|
| 282 |
+
index.
|
| 283 |
+
|
| 284 |
+
- Integer array indices are not allowed (with the exception of 0-D
|
| 285 |
+
arrays, which are treated the same as scalars).
|
| 286 |
+
|
| 287 |
+
Additionally, it should be noted that indices that would return a
|
| 288 |
+
scalar in NumPy will return a 0-D array. Array scalars are not allowed
|
| 289 |
+
in the specification, only 0-D arrays. This is done in the
|
| 290 |
+
``Array._new`` constructor, not this function.
|
| 291 |
+
|
| 292 |
+
"""
|
| 293 |
+
_key = key if isinstance(key, tuple) else (key,)
|
| 294 |
+
for i in _key:
|
| 295 |
+
if isinstance(i, bool) or not (
|
| 296 |
+
isinstance(i, SupportsIndex) # i.e. ints
|
| 297 |
+
or isinstance(i, slice)
|
| 298 |
+
or i == Ellipsis
|
| 299 |
+
or i is None
|
| 300 |
+
or isinstance(i, Array)
|
| 301 |
+
or isinstance(i, np.ndarray)
|
| 302 |
+
):
|
| 303 |
+
raise IndexError(
|
| 304 |
+
f"Single-axes index {i} has {type(i)=}, but only "
|
| 305 |
+
"integers, slices (:), ellipsis (...), newaxis (None), "
|
| 306 |
+
"zero-dimensional integer arrays and boolean arrays "
|
| 307 |
+
"are specified in the Array API."
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
nonexpanding_key = []
|
| 311 |
+
single_axes = []
|
| 312 |
+
n_ellipsis = 0
|
| 313 |
+
key_has_mask = False
|
| 314 |
+
for i in _key:
|
| 315 |
+
if i is not None:
|
| 316 |
+
nonexpanding_key.append(i)
|
| 317 |
+
if isinstance(i, Array) or isinstance(i, np.ndarray):
|
| 318 |
+
if i.dtype in _boolean_dtypes:
|
| 319 |
+
key_has_mask = True
|
| 320 |
+
single_axes.append(i)
|
| 321 |
+
else:
|
| 322 |
+
# i must not be an array here, to avoid elementwise equals
|
| 323 |
+
if i == Ellipsis:
|
| 324 |
+
n_ellipsis += 1
|
| 325 |
+
else:
|
| 326 |
+
single_axes.append(i)
|
| 327 |
+
|
| 328 |
+
n_single_axes = len(single_axes)
|
| 329 |
+
if n_ellipsis > 1:
|
| 330 |
+
return # handled by ndarray
|
| 331 |
+
elif n_ellipsis == 0:
|
| 332 |
+
# Note boolean masks must be the sole index, which we check for
|
| 333 |
+
# later on.
|
| 334 |
+
if not key_has_mask and n_single_axes < self.ndim:
|
| 335 |
+
raise IndexError(
|
| 336 |
+
f"{self.ndim=}, but the multi-axes index only specifies "
|
| 337 |
+
f"{n_single_axes} dimensions. If this was intentional, "
|
| 338 |
+
"add a trailing ellipsis (...) which expands into as many "
|
| 339 |
+
"slices (:) as necessary - this is what np.ndarray arrays "
|
| 340 |
+
"implicitly do, but such flat indexing behaviour is not "
|
| 341 |
+
"specified in the Array API."
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
if n_ellipsis == 0:
|
| 345 |
+
indexed_shape = self.shape
|
| 346 |
+
else:
|
| 347 |
+
ellipsis_start = None
|
| 348 |
+
for pos, i in enumerate(nonexpanding_key):
|
| 349 |
+
if not (isinstance(i, Array) or isinstance(i, np.ndarray)):
|
| 350 |
+
if i == Ellipsis:
|
| 351 |
+
ellipsis_start = pos
|
| 352 |
+
break
|
| 353 |
+
assert ellipsis_start is not None # sanity check
|
| 354 |
+
ellipsis_end = self.ndim - (n_single_axes - ellipsis_start)
|
| 355 |
+
indexed_shape = (
|
| 356 |
+
self.shape[:ellipsis_start] + self.shape[ellipsis_end:]
|
| 357 |
+
)
|
| 358 |
+
for i, side in zip(single_axes, indexed_shape):
|
| 359 |
+
if isinstance(i, slice):
|
| 360 |
+
if side == 0:
|
| 361 |
+
f_range = "0 (or None)"
|
| 362 |
+
else:
|
| 363 |
+
f_range = f"between -{side} and {side - 1} (or None)"
|
| 364 |
+
if i.start is not None:
|
| 365 |
+
try:
|
| 366 |
+
start = operator.index(i.start)
|
| 367 |
+
except TypeError:
|
| 368 |
+
pass # handled by ndarray
|
| 369 |
+
else:
|
| 370 |
+
if not (-side <= start <= side):
|
| 371 |
+
raise IndexError(
|
| 372 |
+
f"Slice {i} contains {start=}, but should be "
|
| 373 |
+
f"{f_range} for an axis of size {side} "
|
| 374 |
+
"(out-of-bounds starts are not specified in "
|
| 375 |
+
"the Array API)"
|
| 376 |
+
)
|
| 377 |
+
if i.stop is not None:
|
| 378 |
+
try:
|
| 379 |
+
stop = operator.index(i.stop)
|
| 380 |
+
except TypeError:
|
| 381 |
+
pass # handled by ndarray
|
| 382 |
+
else:
|
| 383 |
+
if not (-side <= stop <= side):
|
| 384 |
+
raise IndexError(
|
| 385 |
+
f"Slice {i} contains {stop=}, but should be "
|
| 386 |
+
f"{f_range} for an axis of size {side} "
|
| 387 |
+
"(out-of-bounds stops are not specified in "
|
| 388 |
+
"the Array API)"
|
| 389 |
+
)
|
| 390 |
+
elif isinstance(i, Array):
|
| 391 |
+
if i.dtype in _boolean_dtypes and len(_key) != 1:
|
| 392 |
+
assert isinstance(key, tuple) # sanity check
|
| 393 |
+
raise IndexError(
|
| 394 |
+
f"Single-axes index {i} is a boolean array and "
|
| 395 |
+
f"{len(key)=}, but masking is only specified in the "
|
| 396 |
+
"Array API when the array is the sole index."
|
| 397 |
+
)
|
| 398 |
+
elif i.dtype in _integer_dtypes and i.ndim != 0:
|
| 399 |
+
raise IndexError(
|
| 400 |
+
f"Single-axes index {i} is a non-zero-dimensional "
|
| 401 |
+
"integer array, but advanced integer indexing is not "
|
| 402 |
+
"specified in the Array API."
|
| 403 |
+
)
|
| 404 |
+
elif isinstance(i, tuple):
|
| 405 |
+
raise IndexError(
|
| 406 |
+
f"Single-axes index {i} is a tuple, but nested tuple "
|
| 407 |
+
"indices are not specified in the Array API."
|
| 408 |
+
)
|
| 409 |
+
|
| 410 |
+
# Everything below this line is required by the spec.
|
| 411 |
+
|
| 412 |
+
def __abs__(self: Array, /) -> Array:
|
| 413 |
+
"""
|
| 414 |
+
Performs the operation __abs__.
|
| 415 |
+
"""
|
| 416 |
+
if self.dtype not in _numeric_dtypes:
|
| 417 |
+
raise TypeError("Only numeric dtypes are allowed in __abs__")
|
| 418 |
+
res = self._array.__abs__()
|
| 419 |
+
return self.__class__._new(res)
|
| 420 |
+
|
| 421 |
+
def __add__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 422 |
+
"""
|
| 423 |
+
Performs the operation __add__.
|
| 424 |
+
"""
|
| 425 |
+
other = self._check_allowed_dtypes(other, "numeric", "__add__")
|
| 426 |
+
if other is NotImplemented:
|
| 427 |
+
return other
|
| 428 |
+
self, other = self._normalize_two_args(self, other)
|
| 429 |
+
res = self._array.__add__(other._array)
|
| 430 |
+
return self.__class__._new(res)
|
| 431 |
+
|
| 432 |
+
def __and__(self: Array, other: Union[int, bool, Array], /) -> Array:
|
| 433 |
+
"""
|
| 434 |
+
Performs the operation __and__.
|
| 435 |
+
"""
|
| 436 |
+
other = self._check_allowed_dtypes(other, "integer or boolean", "__and__")
|
| 437 |
+
if other is NotImplemented:
|
| 438 |
+
return other
|
| 439 |
+
self, other = self._normalize_two_args(self, other)
|
| 440 |
+
res = self._array.__and__(other._array)
|
| 441 |
+
return self.__class__._new(res)
|
| 442 |
+
|
| 443 |
+
def __array_namespace__(
|
| 444 |
+
self: Array, /, *, api_version: Optional[str] = None
|
| 445 |
+
) -> types.ModuleType:
|
| 446 |
+
if api_version is not None and not api_version.startswith("2021."):
|
| 447 |
+
raise ValueError(f"Unrecognized array API version: {api_version!r}")
|
| 448 |
+
return array_api
|
| 449 |
+
|
| 450 |
+
def __bool__(self: Array, /) -> bool:
|
| 451 |
+
"""
|
| 452 |
+
Performs the operation __bool__.
|
| 453 |
+
"""
|
| 454 |
+
# Note: This is an error here.
|
| 455 |
+
if self._array.ndim != 0:
|
| 456 |
+
raise TypeError("bool is only allowed on arrays with 0 dimensions")
|
| 457 |
+
if self.dtype not in _boolean_dtypes:
|
| 458 |
+
raise ValueError("bool is only allowed on boolean arrays")
|
| 459 |
+
res = self._array.__bool__()
|
| 460 |
+
return res
|
| 461 |
+
|
| 462 |
+
def __dlpack__(self: Array, /, *, stream: None = None) -> PyCapsule:
|
| 463 |
+
"""
|
| 464 |
+
Performs the operation __dlpack__.
|
| 465 |
+
"""
|
| 466 |
+
return self._array.__dlpack__(stream=stream)
|
| 467 |
+
|
| 468 |
+
def __dlpack_device__(self: Array, /) -> Tuple[IntEnum, int]:
|
| 469 |
+
"""
|
| 470 |
+
Performs the operation __dlpack_device__.
|
| 471 |
+
"""
|
| 472 |
+
# Note: device support is required for this
|
| 473 |
+
return self._array.__dlpack_device__()
|
| 474 |
+
|
| 475 |
+
def __eq__(self: Array, other: Union[int, float, bool, Array], /) -> Array:
|
| 476 |
+
"""
|
| 477 |
+
Performs the operation __eq__.
|
| 478 |
+
"""
|
| 479 |
+
# Even though "all" dtypes are allowed, we still require them to be
|
| 480 |
+
# promotable with each other.
|
| 481 |
+
other = self._check_allowed_dtypes(other, "all", "__eq__")
|
| 482 |
+
if other is NotImplemented:
|
| 483 |
+
return other
|
| 484 |
+
self, other = self._normalize_two_args(self, other)
|
| 485 |
+
res = self._array.__eq__(other._array)
|
| 486 |
+
return self.__class__._new(res)
|
| 487 |
+
|
| 488 |
+
def __float__(self: Array, /) -> float:
|
| 489 |
+
"""
|
| 490 |
+
Performs the operation __float__.
|
| 491 |
+
"""
|
| 492 |
+
# Note: This is an error here.
|
| 493 |
+
if self._array.ndim != 0:
|
| 494 |
+
raise TypeError("float is only allowed on arrays with 0 dimensions")
|
| 495 |
+
if self.dtype not in _floating_dtypes:
|
| 496 |
+
raise ValueError("float is only allowed on floating-point arrays")
|
| 497 |
+
res = self._array.__float__()
|
| 498 |
+
return res
|
| 499 |
+
|
| 500 |
+
def __floordiv__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 501 |
+
"""
|
| 502 |
+
Performs the operation __floordiv__.
|
| 503 |
+
"""
|
| 504 |
+
other = self._check_allowed_dtypes(other, "numeric", "__floordiv__")
|
| 505 |
+
if other is NotImplemented:
|
| 506 |
+
return other
|
| 507 |
+
self, other = self._normalize_two_args(self, other)
|
| 508 |
+
res = self._array.__floordiv__(other._array)
|
| 509 |
+
return self.__class__._new(res)
|
| 510 |
+
|
| 511 |
+
def __ge__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 512 |
+
"""
|
| 513 |
+
Performs the operation __ge__.
|
| 514 |
+
"""
|
| 515 |
+
other = self._check_allowed_dtypes(other, "numeric", "__ge__")
|
| 516 |
+
if other is NotImplemented:
|
| 517 |
+
return other
|
| 518 |
+
self, other = self._normalize_two_args(self, other)
|
| 519 |
+
res = self._array.__ge__(other._array)
|
| 520 |
+
return self.__class__._new(res)
|
| 521 |
+
|
| 522 |
+
def __getitem__(
|
| 523 |
+
self: Array,
|
| 524 |
+
key: Union[
|
| 525 |
+
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], Array
|
| 526 |
+
],
|
| 527 |
+
/,
|
| 528 |
+
) -> Array:
|
| 529 |
+
"""
|
| 530 |
+
Performs the operation __getitem__.
|
| 531 |
+
"""
|
| 532 |
+
# Note: Only indices required by the spec are allowed. See the
|
| 533 |
+
# docstring of _validate_index
|
| 534 |
+
self._validate_index(key)
|
| 535 |
+
if isinstance(key, Array):
|
| 536 |
+
# Indexing self._array with array_api arrays can be erroneous
|
| 537 |
+
key = key._array
|
| 538 |
+
res = self._array.__getitem__(key)
|
| 539 |
+
return self._new(res)
|
| 540 |
+
|
| 541 |
+
def __gt__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 542 |
+
"""
|
| 543 |
+
Performs the operation __gt__.
|
| 544 |
+
"""
|
| 545 |
+
other = self._check_allowed_dtypes(other, "numeric", "__gt__")
|
| 546 |
+
if other is NotImplemented:
|
| 547 |
+
return other
|
| 548 |
+
self, other = self._normalize_two_args(self, other)
|
| 549 |
+
res = self._array.__gt__(other._array)
|
| 550 |
+
return self.__class__._new(res)
|
| 551 |
+
|
| 552 |
+
def __int__(self: Array, /) -> int:
|
| 553 |
+
"""
|
| 554 |
+
Performs the operation __int__.
|
| 555 |
+
"""
|
| 556 |
+
# Note: This is an error here.
|
| 557 |
+
if self._array.ndim != 0:
|
| 558 |
+
raise TypeError("int is only allowed on arrays with 0 dimensions")
|
| 559 |
+
if self.dtype not in _integer_dtypes:
|
| 560 |
+
raise ValueError("int is only allowed on integer arrays")
|
| 561 |
+
res = self._array.__int__()
|
| 562 |
+
return res
|
| 563 |
+
|
| 564 |
+
def __index__(self: Array, /) -> int:
|
| 565 |
+
"""
|
| 566 |
+
Performs the operation __index__.
|
| 567 |
+
"""
|
| 568 |
+
res = self._array.__index__()
|
| 569 |
+
return res
|
| 570 |
+
|
| 571 |
+
def __invert__(self: Array, /) -> Array:
|
| 572 |
+
"""
|
| 573 |
+
Performs the operation __invert__.
|
| 574 |
+
"""
|
| 575 |
+
if self.dtype not in _integer_or_boolean_dtypes:
|
| 576 |
+
raise TypeError("Only integer or boolean dtypes are allowed in __invert__")
|
| 577 |
+
res = self._array.__invert__()
|
| 578 |
+
return self.__class__._new(res)
|
| 579 |
+
|
| 580 |
+
def __le__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 581 |
+
"""
|
| 582 |
+
Performs the operation __le__.
|
| 583 |
+
"""
|
| 584 |
+
other = self._check_allowed_dtypes(other, "numeric", "__le__")
|
| 585 |
+
if other is NotImplemented:
|
| 586 |
+
return other
|
| 587 |
+
self, other = self._normalize_two_args(self, other)
|
| 588 |
+
res = self._array.__le__(other._array)
|
| 589 |
+
return self.__class__._new(res)
|
| 590 |
+
|
| 591 |
+
def __lshift__(self: Array, other: Union[int, Array], /) -> Array:
|
| 592 |
+
"""
|
| 593 |
+
Performs the operation __lshift__.
|
| 594 |
+
"""
|
| 595 |
+
other = self._check_allowed_dtypes(other, "integer", "__lshift__")
|
| 596 |
+
if other is NotImplemented:
|
| 597 |
+
return other
|
| 598 |
+
self, other = self._normalize_two_args(self, other)
|
| 599 |
+
res = self._array.__lshift__(other._array)
|
| 600 |
+
return self.__class__._new(res)
|
| 601 |
+
|
| 602 |
+
def __lt__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 603 |
+
"""
|
| 604 |
+
Performs the operation __lt__.
|
| 605 |
+
"""
|
| 606 |
+
other = self._check_allowed_dtypes(other, "numeric", "__lt__")
|
| 607 |
+
if other is NotImplemented:
|
| 608 |
+
return other
|
| 609 |
+
self, other = self._normalize_two_args(self, other)
|
| 610 |
+
res = self._array.__lt__(other._array)
|
| 611 |
+
return self.__class__._new(res)
|
| 612 |
+
|
| 613 |
+
def __matmul__(self: Array, other: Array, /) -> Array:
|
| 614 |
+
"""
|
| 615 |
+
Performs the operation __matmul__.
|
| 616 |
+
"""
|
| 617 |
+
# matmul is not defined for scalars, but without this, we may get
|
| 618 |
+
# the wrong error message from asarray.
|
| 619 |
+
other = self._check_allowed_dtypes(other, "numeric", "__matmul__")
|
| 620 |
+
if other is NotImplemented:
|
| 621 |
+
return other
|
| 622 |
+
res = self._array.__matmul__(other._array)
|
| 623 |
+
return self.__class__._new(res)
|
| 624 |
+
|
| 625 |
+
def __mod__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 626 |
+
"""
|
| 627 |
+
Performs the operation __mod__.
|
| 628 |
+
"""
|
| 629 |
+
other = self._check_allowed_dtypes(other, "numeric", "__mod__")
|
| 630 |
+
if other is NotImplemented:
|
| 631 |
+
return other
|
| 632 |
+
self, other = self._normalize_two_args(self, other)
|
| 633 |
+
res = self._array.__mod__(other._array)
|
| 634 |
+
return self.__class__._new(res)
|
| 635 |
+
|
| 636 |
+
def __mul__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 637 |
+
"""
|
| 638 |
+
Performs the operation __mul__.
|
| 639 |
+
"""
|
| 640 |
+
other = self._check_allowed_dtypes(other, "numeric", "__mul__")
|
| 641 |
+
if other is NotImplemented:
|
| 642 |
+
return other
|
| 643 |
+
self, other = self._normalize_two_args(self, other)
|
| 644 |
+
res = self._array.__mul__(other._array)
|
| 645 |
+
return self.__class__._new(res)
|
| 646 |
+
|
| 647 |
+
def __ne__(self: Array, other: Union[int, float, bool, Array], /) -> Array:
|
| 648 |
+
"""
|
| 649 |
+
Performs the operation __ne__.
|
| 650 |
+
"""
|
| 651 |
+
other = self._check_allowed_dtypes(other, "all", "__ne__")
|
| 652 |
+
if other is NotImplemented:
|
| 653 |
+
return other
|
| 654 |
+
self, other = self._normalize_two_args(self, other)
|
| 655 |
+
res = self._array.__ne__(other._array)
|
| 656 |
+
return self.__class__._new(res)
|
| 657 |
+
|
| 658 |
+
def __neg__(self: Array, /) -> Array:
|
| 659 |
+
"""
|
| 660 |
+
Performs the operation __neg__.
|
| 661 |
+
"""
|
| 662 |
+
if self.dtype not in _numeric_dtypes:
|
| 663 |
+
raise TypeError("Only numeric dtypes are allowed in __neg__")
|
| 664 |
+
res = self._array.__neg__()
|
| 665 |
+
return self.__class__._new(res)
|
| 666 |
+
|
| 667 |
+
def __or__(self: Array, other: Union[int, bool, Array], /) -> Array:
|
| 668 |
+
"""
|
| 669 |
+
Performs the operation __or__.
|
| 670 |
+
"""
|
| 671 |
+
other = self._check_allowed_dtypes(other, "integer or boolean", "__or__")
|
| 672 |
+
if other is NotImplemented:
|
| 673 |
+
return other
|
| 674 |
+
self, other = self._normalize_two_args(self, other)
|
| 675 |
+
res = self._array.__or__(other._array)
|
| 676 |
+
return self.__class__._new(res)
|
| 677 |
+
|
| 678 |
+
def __pos__(self: Array, /) -> Array:
|
| 679 |
+
"""
|
| 680 |
+
Performs the operation __pos__.
|
| 681 |
+
"""
|
| 682 |
+
if self.dtype not in _numeric_dtypes:
|
| 683 |
+
raise TypeError("Only numeric dtypes are allowed in __pos__")
|
| 684 |
+
res = self._array.__pos__()
|
| 685 |
+
return self.__class__._new(res)
|
| 686 |
+
|
| 687 |
+
def __pow__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 688 |
+
"""
|
| 689 |
+
Performs the operation __pow__.
|
| 690 |
+
"""
|
| 691 |
+
from ._elementwise_functions import pow
|
| 692 |
+
|
| 693 |
+
other = self._check_allowed_dtypes(other, "numeric", "__pow__")
|
| 694 |
+
if other is NotImplemented:
|
| 695 |
+
return other
|
| 696 |
+
# Note: NumPy's __pow__ does not follow type promotion rules for 0-d
|
| 697 |
+
# arrays, so we use pow() here instead.
|
| 698 |
+
return pow(self, other)
|
| 699 |
+
|
| 700 |
+
def __rshift__(self: Array, other: Union[int, Array], /) -> Array:
|
| 701 |
+
"""
|
| 702 |
+
Performs the operation __rshift__.
|
| 703 |
+
"""
|
| 704 |
+
other = self._check_allowed_dtypes(other, "integer", "__rshift__")
|
| 705 |
+
if other is NotImplemented:
|
| 706 |
+
return other
|
| 707 |
+
self, other = self._normalize_two_args(self, other)
|
| 708 |
+
res = self._array.__rshift__(other._array)
|
| 709 |
+
return self.__class__._new(res)
|
| 710 |
+
|
| 711 |
+
def __setitem__(
|
| 712 |
+
self,
|
| 713 |
+
key: Union[
|
| 714 |
+
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], Array
|
| 715 |
+
],
|
| 716 |
+
value: Union[int, float, bool, Array],
|
| 717 |
+
/,
|
| 718 |
+
) -> None:
|
| 719 |
+
"""
|
| 720 |
+
Performs the operation __setitem__.
|
| 721 |
+
"""
|
| 722 |
+
# Note: Only indices required by the spec are allowed. See the
|
| 723 |
+
# docstring of _validate_index
|
| 724 |
+
self._validate_index(key)
|
| 725 |
+
if isinstance(key, Array):
|
| 726 |
+
# Indexing self._array with array_api arrays can be erroneous
|
| 727 |
+
key = key._array
|
| 728 |
+
self._array.__setitem__(key, asarray(value)._array)
|
| 729 |
+
|
| 730 |
+
def __sub__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 731 |
+
"""
|
| 732 |
+
Performs the operation __sub__.
|
| 733 |
+
"""
|
| 734 |
+
other = self._check_allowed_dtypes(other, "numeric", "__sub__")
|
| 735 |
+
if other is NotImplemented:
|
| 736 |
+
return other
|
| 737 |
+
self, other = self._normalize_two_args(self, other)
|
| 738 |
+
res = self._array.__sub__(other._array)
|
| 739 |
+
return self.__class__._new(res)
|
| 740 |
+
|
| 741 |
+
# PEP 484 requires int to be a subtype of float, but __truediv__ should
|
| 742 |
+
# not accept int.
|
| 743 |
+
def __truediv__(self: Array, other: Union[float, Array], /) -> Array:
|
| 744 |
+
"""
|
| 745 |
+
Performs the operation __truediv__.
|
| 746 |
+
"""
|
| 747 |
+
other = self._check_allowed_dtypes(other, "floating-point", "__truediv__")
|
| 748 |
+
if other is NotImplemented:
|
| 749 |
+
return other
|
| 750 |
+
self, other = self._normalize_two_args(self, other)
|
| 751 |
+
res = self._array.__truediv__(other._array)
|
| 752 |
+
return self.__class__._new(res)
|
| 753 |
+
|
| 754 |
+
def __xor__(self: Array, other: Union[int, bool, Array], /) -> Array:
|
| 755 |
+
"""
|
| 756 |
+
Performs the operation __xor__.
|
| 757 |
+
"""
|
| 758 |
+
other = self._check_allowed_dtypes(other, "integer or boolean", "__xor__")
|
| 759 |
+
if other is NotImplemented:
|
| 760 |
+
return other
|
| 761 |
+
self, other = self._normalize_two_args(self, other)
|
| 762 |
+
res = self._array.__xor__(other._array)
|
| 763 |
+
return self.__class__._new(res)
|
| 764 |
+
|
| 765 |
+
def __iadd__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 766 |
+
"""
|
| 767 |
+
Performs the operation __iadd__.
|
| 768 |
+
"""
|
| 769 |
+
other = self._check_allowed_dtypes(other, "numeric", "__iadd__")
|
| 770 |
+
if other is NotImplemented:
|
| 771 |
+
return other
|
| 772 |
+
self._array.__iadd__(other._array)
|
| 773 |
+
return self
|
| 774 |
+
|
| 775 |
+
def __radd__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 776 |
+
"""
|
| 777 |
+
Performs the operation __radd__.
|
| 778 |
+
"""
|
| 779 |
+
other = self._check_allowed_dtypes(other, "numeric", "__radd__")
|
| 780 |
+
if other is NotImplemented:
|
| 781 |
+
return other
|
| 782 |
+
self, other = self._normalize_two_args(self, other)
|
| 783 |
+
res = self._array.__radd__(other._array)
|
| 784 |
+
return self.__class__._new(res)
|
| 785 |
+
|
| 786 |
+
def __iand__(self: Array, other: Union[int, bool, Array], /) -> Array:
|
| 787 |
+
"""
|
| 788 |
+
Performs the operation __iand__.
|
| 789 |
+
"""
|
| 790 |
+
other = self._check_allowed_dtypes(other, "integer or boolean", "__iand__")
|
| 791 |
+
if other is NotImplemented:
|
| 792 |
+
return other
|
| 793 |
+
self._array.__iand__(other._array)
|
| 794 |
+
return self
|
| 795 |
+
|
| 796 |
+
def __rand__(self: Array, other: Union[int, bool, Array], /) -> Array:
|
| 797 |
+
"""
|
| 798 |
+
Performs the operation __rand__.
|
| 799 |
+
"""
|
| 800 |
+
other = self._check_allowed_dtypes(other, "integer or boolean", "__rand__")
|
| 801 |
+
if other is NotImplemented:
|
| 802 |
+
return other
|
| 803 |
+
self, other = self._normalize_two_args(self, other)
|
| 804 |
+
res = self._array.__rand__(other._array)
|
| 805 |
+
return self.__class__._new(res)
|
| 806 |
+
|
| 807 |
+
def __ifloordiv__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 808 |
+
"""
|
| 809 |
+
Performs the operation __ifloordiv__.
|
| 810 |
+
"""
|
| 811 |
+
other = self._check_allowed_dtypes(other, "numeric", "__ifloordiv__")
|
| 812 |
+
if other is NotImplemented:
|
| 813 |
+
return other
|
| 814 |
+
self._array.__ifloordiv__(other._array)
|
| 815 |
+
return self
|
| 816 |
+
|
| 817 |
+
def __rfloordiv__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 818 |
+
"""
|
| 819 |
+
Performs the operation __rfloordiv__.
|
| 820 |
+
"""
|
| 821 |
+
other = self._check_allowed_dtypes(other, "numeric", "__rfloordiv__")
|
| 822 |
+
if other is NotImplemented:
|
| 823 |
+
return other
|
| 824 |
+
self, other = self._normalize_two_args(self, other)
|
| 825 |
+
res = self._array.__rfloordiv__(other._array)
|
| 826 |
+
return self.__class__._new(res)
|
| 827 |
+
|
| 828 |
+
def __ilshift__(self: Array, other: Union[int, Array], /) -> Array:
|
| 829 |
+
"""
|
| 830 |
+
Performs the operation __ilshift__.
|
| 831 |
+
"""
|
| 832 |
+
other = self._check_allowed_dtypes(other, "integer", "__ilshift__")
|
| 833 |
+
if other is NotImplemented:
|
| 834 |
+
return other
|
| 835 |
+
self._array.__ilshift__(other._array)
|
| 836 |
+
return self
|
| 837 |
+
|
| 838 |
+
def __rlshift__(self: Array, other: Union[int, Array], /) -> Array:
|
| 839 |
+
"""
|
| 840 |
+
Performs the operation __rlshift__.
|
| 841 |
+
"""
|
| 842 |
+
other = self._check_allowed_dtypes(other, "integer", "__rlshift__")
|
| 843 |
+
if other is NotImplemented:
|
| 844 |
+
return other
|
| 845 |
+
self, other = self._normalize_two_args(self, other)
|
| 846 |
+
res = self._array.__rlshift__(other._array)
|
| 847 |
+
return self.__class__._new(res)
|
| 848 |
+
|
| 849 |
+
def __imatmul__(self: Array, other: Array, /) -> Array:
|
| 850 |
+
"""
|
| 851 |
+
Performs the operation __imatmul__.
|
| 852 |
+
"""
|
| 853 |
+
# Note: NumPy does not implement __imatmul__.
|
| 854 |
+
|
| 855 |
+
# matmul is not defined for scalars, but without this, we may get
|
| 856 |
+
# the wrong error message from asarray.
|
| 857 |
+
other = self._check_allowed_dtypes(other, "numeric", "__imatmul__")
|
| 858 |
+
if other is NotImplemented:
|
| 859 |
+
return other
|
| 860 |
+
|
| 861 |
+
# __imatmul__ can only be allowed when it would not change the shape
|
| 862 |
+
# of self.
|
| 863 |
+
other_shape = other.shape
|
| 864 |
+
if self.shape == () or other_shape == ():
|
| 865 |
+
raise ValueError("@= requires at least one dimension")
|
| 866 |
+
if len(other_shape) == 1 or other_shape[-1] != other_shape[-2]:
|
| 867 |
+
raise ValueError("@= cannot change the shape of the input array")
|
| 868 |
+
self._array[:] = self._array.__matmul__(other._array)
|
| 869 |
+
return self
|
| 870 |
+
|
| 871 |
+
def __rmatmul__(self: Array, other: Array, /) -> Array:
|
| 872 |
+
"""
|
| 873 |
+
Performs the operation __rmatmul__.
|
| 874 |
+
"""
|
| 875 |
+
# matmul is not defined for scalars, but without this, we may get
|
| 876 |
+
# the wrong error message from asarray.
|
| 877 |
+
other = self._check_allowed_dtypes(other, "numeric", "__rmatmul__")
|
| 878 |
+
if other is NotImplemented:
|
| 879 |
+
return other
|
| 880 |
+
res = self._array.__rmatmul__(other._array)
|
| 881 |
+
return self.__class__._new(res)
|
| 882 |
+
|
| 883 |
+
def __imod__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 884 |
+
"""
|
| 885 |
+
Performs the operation __imod__.
|
| 886 |
+
"""
|
| 887 |
+
other = self._check_allowed_dtypes(other, "numeric", "__imod__")
|
| 888 |
+
if other is NotImplemented:
|
| 889 |
+
return other
|
| 890 |
+
self._array.__imod__(other._array)
|
| 891 |
+
return self
|
| 892 |
+
|
| 893 |
+
def __rmod__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 894 |
+
"""
|
| 895 |
+
Performs the operation __rmod__.
|
| 896 |
+
"""
|
| 897 |
+
other = self._check_allowed_dtypes(other, "numeric", "__rmod__")
|
| 898 |
+
if other is NotImplemented:
|
| 899 |
+
return other
|
| 900 |
+
self, other = self._normalize_two_args(self, other)
|
| 901 |
+
res = self._array.__rmod__(other._array)
|
| 902 |
+
return self.__class__._new(res)
|
| 903 |
+
|
| 904 |
+
def __imul__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 905 |
+
"""
|
| 906 |
+
Performs the operation __imul__.
|
| 907 |
+
"""
|
| 908 |
+
other = self._check_allowed_dtypes(other, "numeric", "__imul__")
|
| 909 |
+
if other is NotImplemented:
|
| 910 |
+
return other
|
| 911 |
+
self._array.__imul__(other._array)
|
| 912 |
+
return self
|
| 913 |
+
|
| 914 |
+
def __rmul__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 915 |
+
"""
|
| 916 |
+
Performs the operation __rmul__.
|
| 917 |
+
"""
|
| 918 |
+
other = self._check_allowed_dtypes(other, "numeric", "__rmul__")
|
| 919 |
+
if other is NotImplemented:
|
| 920 |
+
return other
|
| 921 |
+
self, other = self._normalize_two_args(self, other)
|
| 922 |
+
res = self._array.__rmul__(other._array)
|
| 923 |
+
return self.__class__._new(res)
|
| 924 |
+
|
| 925 |
+
def __ior__(self: Array, other: Union[int, bool, Array], /) -> Array:
|
| 926 |
+
"""
|
| 927 |
+
Performs the operation __ior__.
|
| 928 |
+
"""
|
| 929 |
+
other = self._check_allowed_dtypes(other, "integer or boolean", "__ior__")
|
| 930 |
+
if other is NotImplemented:
|
| 931 |
+
return other
|
| 932 |
+
self._array.__ior__(other._array)
|
| 933 |
+
return self
|
| 934 |
+
|
| 935 |
+
def __ror__(self: Array, other: Union[int, bool, Array], /) -> Array:
|
| 936 |
+
"""
|
| 937 |
+
Performs the operation __ror__.
|
| 938 |
+
"""
|
| 939 |
+
other = self._check_allowed_dtypes(other, "integer or boolean", "__ror__")
|
| 940 |
+
if other is NotImplemented:
|
| 941 |
+
return other
|
| 942 |
+
self, other = self._normalize_two_args(self, other)
|
| 943 |
+
res = self._array.__ror__(other._array)
|
| 944 |
+
return self.__class__._new(res)
|
| 945 |
+
|
| 946 |
+
def __ipow__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 947 |
+
"""
|
| 948 |
+
Performs the operation __ipow__.
|
| 949 |
+
"""
|
| 950 |
+
other = self._check_allowed_dtypes(other, "numeric", "__ipow__")
|
| 951 |
+
if other is NotImplemented:
|
| 952 |
+
return other
|
| 953 |
+
self._array.__ipow__(other._array)
|
| 954 |
+
return self
|
| 955 |
+
|
| 956 |
+
def __rpow__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 957 |
+
"""
|
| 958 |
+
Performs the operation __rpow__.
|
| 959 |
+
"""
|
| 960 |
+
from ._elementwise_functions import pow
|
| 961 |
+
|
| 962 |
+
other = self._check_allowed_dtypes(other, "numeric", "__rpow__")
|
| 963 |
+
if other is NotImplemented:
|
| 964 |
+
return other
|
| 965 |
+
# Note: NumPy's __pow__ does not follow the spec type promotion rules
|
| 966 |
+
# for 0-d arrays, so we use pow() here instead.
|
| 967 |
+
return pow(other, self)
|
| 968 |
+
|
| 969 |
+
def __irshift__(self: Array, other: Union[int, Array], /) -> Array:
|
| 970 |
+
"""
|
| 971 |
+
Performs the operation __irshift__.
|
| 972 |
+
"""
|
| 973 |
+
other = self._check_allowed_dtypes(other, "integer", "__irshift__")
|
| 974 |
+
if other is NotImplemented:
|
| 975 |
+
return other
|
| 976 |
+
self._array.__irshift__(other._array)
|
| 977 |
+
return self
|
| 978 |
+
|
| 979 |
+
def __rrshift__(self: Array, other: Union[int, Array], /) -> Array:
|
| 980 |
+
"""
|
| 981 |
+
Performs the operation __rrshift__.
|
| 982 |
+
"""
|
| 983 |
+
other = self._check_allowed_dtypes(other, "integer", "__rrshift__")
|
| 984 |
+
if other is NotImplemented:
|
| 985 |
+
return other
|
| 986 |
+
self, other = self._normalize_two_args(self, other)
|
| 987 |
+
res = self._array.__rrshift__(other._array)
|
| 988 |
+
return self.__class__._new(res)
|
| 989 |
+
|
| 990 |
+
def __isub__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 991 |
+
"""
|
| 992 |
+
Performs the operation __isub__.
|
| 993 |
+
"""
|
| 994 |
+
other = self._check_allowed_dtypes(other, "numeric", "__isub__")
|
| 995 |
+
if other is NotImplemented:
|
| 996 |
+
return other
|
| 997 |
+
self._array.__isub__(other._array)
|
| 998 |
+
return self
|
| 999 |
+
|
| 1000 |
+
def __rsub__(self: Array, other: Union[int, float, Array], /) -> Array:
|
| 1001 |
+
"""
|
| 1002 |
+
Performs the operation __rsub__.
|
| 1003 |
+
"""
|
| 1004 |
+
other = self._check_allowed_dtypes(other, "numeric", "__rsub__")
|
| 1005 |
+
if other is NotImplemented:
|
| 1006 |
+
return other
|
| 1007 |
+
self, other = self._normalize_two_args(self, other)
|
| 1008 |
+
res = self._array.__rsub__(other._array)
|
| 1009 |
+
return self.__class__._new(res)
|
| 1010 |
+
|
| 1011 |
+
def __itruediv__(self: Array, other: Union[float, Array], /) -> Array:
|
| 1012 |
+
"""
|
| 1013 |
+
Performs the operation __itruediv__.
|
| 1014 |
+
"""
|
| 1015 |
+
other = self._check_allowed_dtypes(other, "floating-point", "__itruediv__")
|
| 1016 |
+
if other is NotImplemented:
|
| 1017 |
+
return other
|
| 1018 |
+
self._array.__itruediv__(other._array)
|
| 1019 |
+
return self
|
| 1020 |
+
|
| 1021 |
+
def __rtruediv__(self: Array, other: Union[float, Array], /) -> Array:
|
| 1022 |
+
"""
|
| 1023 |
+
Performs the operation __rtruediv__.
|
| 1024 |
+
"""
|
| 1025 |
+
other = self._check_allowed_dtypes(other, "floating-point", "__rtruediv__")
|
| 1026 |
+
if other is NotImplemented:
|
| 1027 |
+
return other
|
| 1028 |
+
self, other = self._normalize_two_args(self, other)
|
| 1029 |
+
res = self._array.__rtruediv__(other._array)
|
| 1030 |
+
return self.__class__._new(res)
|
| 1031 |
+
|
| 1032 |
+
def __ixor__(self: Array, other: Union[int, bool, Array], /) -> Array:
|
| 1033 |
+
"""
|
| 1034 |
+
Performs the operation __ixor__.
|
| 1035 |
+
"""
|
| 1036 |
+
other = self._check_allowed_dtypes(other, "integer or boolean", "__ixor__")
|
| 1037 |
+
if other is NotImplemented:
|
| 1038 |
+
return other
|
| 1039 |
+
self._array.__ixor__(other._array)
|
| 1040 |
+
return self
|
| 1041 |
+
|
| 1042 |
+
def __rxor__(self: Array, other: Union[int, bool, Array], /) -> Array:
|
| 1043 |
+
"""
|
| 1044 |
+
Performs the operation __rxor__.
|
| 1045 |
+
"""
|
| 1046 |
+
other = self._check_allowed_dtypes(other, "integer or boolean", "__rxor__")
|
| 1047 |
+
if other is NotImplemented:
|
| 1048 |
+
return other
|
| 1049 |
+
self, other = self._normalize_two_args(self, other)
|
| 1050 |
+
res = self._array.__rxor__(other._array)
|
| 1051 |
+
return self.__class__._new(res)
|
| 1052 |
+
|
| 1053 |
+
def to_device(self: Array, device: Device, /, stream: None = None) -> Array:
|
| 1054 |
+
if stream is not None:
|
| 1055 |
+
raise ValueError("The stream argument to to_device() is not supported")
|
| 1056 |
+
if device == 'cpu':
|
| 1057 |
+
return self
|
| 1058 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 1059 |
+
|
| 1060 |
+
@property
|
| 1061 |
+
def dtype(self) -> Dtype:
|
| 1062 |
+
"""
|
| 1063 |
+
Array API compatible wrapper for :py:meth:`np.ndarray.dtype <numpy.ndarray.dtype>`.
|
| 1064 |
+
|
| 1065 |
+
See its docstring for more information.
|
| 1066 |
+
"""
|
| 1067 |
+
return self._array.dtype
|
| 1068 |
+
|
| 1069 |
+
@property
|
| 1070 |
+
def device(self) -> Device:
|
| 1071 |
+
return "cpu"
|
| 1072 |
+
|
| 1073 |
+
# Note: mT is new in array API spec (see matrix_transpose)
|
| 1074 |
+
@property
|
| 1075 |
+
def mT(self) -> Array:
|
| 1076 |
+
from .linalg import matrix_transpose
|
| 1077 |
+
return matrix_transpose(self)
|
| 1078 |
+
|
| 1079 |
+
@property
|
| 1080 |
+
def ndim(self) -> int:
|
| 1081 |
+
"""
|
| 1082 |
+
Array API compatible wrapper for :py:meth:`np.ndarray.ndim <numpy.ndarray.ndim>`.
|
| 1083 |
+
|
| 1084 |
+
See its docstring for more information.
|
| 1085 |
+
"""
|
| 1086 |
+
return self._array.ndim
|
| 1087 |
+
|
| 1088 |
+
@property
|
| 1089 |
+
def shape(self) -> Tuple[int, ...]:
|
| 1090 |
+
"""
|
| 1091 |
+
Array API compatible wrapper for :py:meth:`np.ndarray.shape <numpy.ndarray.shape>`.
|
| 1092 |
+
|
| 1093 |
+
See its docstring for more information.
|
| 1094 |
+
"""
|
| 1095 |
+
return self._array.shape
|
| 1096 |
+
|
| 1097 |
+
@property
|
| 1098 |
+
def size(self) -> int:
|
| 1099 |
+
"""
|
| 1100 |
+
Array API compatible wrapper for :py:meth:`np.ndarray.size <numpy.ndarray.size>`.
|
| 1101 |
+
|
| 1102 |
+
See its docstring for more information.
|
| 1103 |
+
"""
|
| 1104 |
+
return self._array.size
|
| 1105 |
+
|
| 1106 |
+
@property
|
| 1107 |
+
def T(self) -> Array:
|
| 1108 |
+
"""
|
| 1109 |
+
Array API compatible wrapper for :py:meth:`np.ndarray.T <numpy.ndarray.T>`.
|
| 1110 |
+
|
| 1111 |
+
See its docstring for more information.
|
| 1112 |
+
"""
|
| 1113 |
+
# Note: T only works on 2-dimensional arrays. See the corresponding
|
| 1114 |
+
# note in the specification:
|
| 1115 |
+
# https://data-apis.org/array-api/latest/API_specification/array_object.html#t
|
| 1116 |
+
if self.ndim != 2:
|
| 1117 |
+
raise ValueError("x.T requires x to have 2 dimensions. Use x.mT to transpose stacks of matrices and permute_dims() to permute dimensions.")
|
| 1118 |
+
return self.__class__._new(self._array.T)
|
wemm/lib/python3.10/site-packages/numpy/array_api/_constants.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
e = np.e
|
| 4 |
+
inf = np.inf
|
| 5 |
+
nan = np.nan
|
| 6 |
+
pi = np.pi
|
wemm/lib/python3.10/site-packages/numpy/array_api/_manipulation_functions.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from ._array_object import Array
|
| 4 |
+
from ._data_type_functions import result_type
|
| 5 |
+
|
| 6 |
+
from typing import List, Optional, Tuple, Union
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
|
| 10 |
+
# Note: the function name is different here
|
| 11 |
+
def concat(
|
| 12 |
+
arrays: Union[Tuple[Array, ...], List[Array]], /, *, axis: Optional[int] = 0
|
| 13 |
+
) -> Array:
|
| 14 |
+
"""
|
| 15 |
+
Array API compatible wrapper for :py:func:`np.concatenate <numpy.concatenate>`.
|
| 16 |
+
|
| 17 |
+
See its docstring for more information.
|
| 18 |
+
"""
|
| 19 |
+
# Note: Casting rules here are different from the np.concatenate default
|
| 20 |
+
# (no for scalars with axis=None, no cross-kind casting)
|
| 21 |
+
dtype = result_type(*arrays)
|
| 22 |
+
arrays = tuple(a._array for a in arrays)
|
| 23 |
+
return Array._new(np.concatenate(arrays, axis=axis, dtype=dtype))
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def expand_dims(x: Array, /, *, axis: int) -> Array:
|
| 27 |
+
"""
|
| 28 |
+
Array API compatible wrapper for :py:func:`np.expand_dims <numpy.expand_dims>`.
|
| 29 |
+
|
| 30 |
+
See its docstring for more information.
|
| 31 |
+
"""
|
| 32 |
+
return Array._new(np.expand_dims(x._array, axis))
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def flip(x: Array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Array:
|
| 36 |
+
"""
|
| 37 |
+
Array API compatible wrapper for :py:func:`np.flip <numpy.flip>`.
|
| 38 |
+
|
| 39 |
+
See its docstring for more information.
|
| 40 |
+
"""
|
| 41 |
+
return Array._new(np.flip(x._array, axis=axis))
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# Note: The function name is different here (see also matrix_transpose).
|
| 45 |
+
# Unlike transpose(), the axes argument is required.
|
| 46 |
+
def permute_dims(x: Array, /, axes: Tuple[int, ...]) -> Array:
|
| 47 |
+
"""
|
| 48 |
+
Array API compatible wrapper for :py:func:`np.transpose <numpy.transpose>`.
|
| 49 |
+
|
| 50 |
+
See its docstring for more information.
|
| 51 |
+
"""
|
| 52 |
+
return Array._new(np.transpose(x._array, axes))
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def reshape(x: Array, /, shape: Tuple[int, ...]) -> Array:
|
| 56 |
+
"""
|
| 57 |
+
Array API compatible wrapper for :py:func:`np.reshape <numpy.reshape>`.
|
| 58 |
+
|
| 59 |
+
See its docstring for more information.
|
| 60 |
+
"""
|
| 61 |
+
return Array._new(np.reshape(x._array, shape))
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def roll(
|
| 65 |
+
x: Array,
|
| 66 |
+
/,
|
| 67 |
+
shift: Union[int, Tuple[int, ...]],
|
| 68 |
+
*,
|
| 69 |
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
| 70 |
+
) -> Array:
|
| 71 |
+
"""
|
| 72 |
+
Array API compatible wrapper for :py:func:`np.roll <numpy.roll>`.
|
| 73 |
+
|
| 74 |
+
See its docstring for more information.
|
| 75 |
+
"""
|
| 76 |
+
return Array._new(np.roll(x._array, shift, axis=axis))
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def squeeze(x: Array, /, axis: Union[int, Tuple[int, ...]]) -> Array:
|
| 80 |
+
"""
|
| 81 |
+
Array API compatible wrapper for :py:func:`np.squeeze <numpy.squeeze>`.
|
| 82 |
+
|
| 83 |
+
See its docstring for more information.
|
| 84 |
+
"""
|
| 85 |
+
return Array._new(np.squeeze(x._array, axis=axis))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def stack(arrays: Union[Tuple[Array, ...], List[Array]], /, *, axis: int = 0) -> Array:
|
| 89 |
+
"""
|
| 90 |
+
Array API compatible wrapper for :py:func:`np.stack <numpy.stack>`.
|
| 91 |
+
|
| 92 |
+
See its docstring for more information.
|
| 93 |
+
"""
|
| 94 |
+
# Call result type here just to raise on disallowed type combinations
|
| 95 |
+
result_type(*arrays)
|
| 96 |
+
arrays = tuple(a._array for a in arrays)
|
| 97 |
+
return Array._new(np.stack(arrays, axis=axis))
|
wemm/lib/python3.10/site-packages/numpy/array_api/_set_functions.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from ._array_object import Array
|
| 4 |
+
|
| 5 |
+
from typing import NamedTuple
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
# Note: np.unique() is split into four functions in the array API:
|
| 10 |
+
# unique_all, unique_counts, unique_inverse, and unique_values (this is done
|
| 11 |
+
# to remove polymorphic return types).
|
| 12 |
+
|
| 13 |
+
# Note: The various unique() functions are supposed to return multiple NaNs.
|
| 14 |
+
# This does not match the NumPy behavior, however, this is currently left as a
|
| 15 |
+
# TODO in this implementation as this behavior may be reverted in np.unique().
|
| 16 |
+
# See https://github.com/numpy/numpy/issues/20326.
|
| 17 |
+
|
| 18 |
+
# Note: The functions here return a namedtuple (np.unique() returns a normal
|
| 19 |
+
# tuple).
|
| 20 |
+
|
| 21 |
+
class UniqueAllResult(NamedTuple):
|
| 22 |
+
values: Array
|
| 23 |
+
indices: Array
|
| 24 |
+
inverse_indices: Array
|
| 25 |
+
counts: Array
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class UniqueCountsResult(NamedTuple):
|
| 29 |
+
values: Array
|
| 30 |
+
counts: Array
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class UniqueInverseResult(NamedTuple):
|
| 34 |
+
values: Array
|
| 35 |
+
inverse_indices: Array
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def unique_all(x: Array, /) -> UniqueAllResult:
|
| 39 |
+
"""
|
| 40 |
+
Array API compatible wrapper for :py:func:`np.unique <numpy.unique>`.
|
| 41 |
+
|
| 42 |
+
See its docstring for more information.
|
| 43 |
+
"""
|
| 44 |
+
values, indices, inverse_indices, counts = np.unique(
|
| 45 |
+
x._array,
|
| 46 |
+
return_counts=True,
|
| 47 |
+
return_index=True,
|
| 48 |
+
return_inverse=True,
|
| 49 |
+
)
|
| 50 |
+
# np.unique() flattens inverse indices, but they need to share x's shape
|
| 51 |
+
# See https://github.com/numpy/numpy/issues/20638
|
| 52 |
+
inverse_indices = inverse_indices.reshape(x.shape)
|
| 53 |
+
return UniqueAllResult(
|
| 54 |
+
Array._new(values),
|
| 55 |
+
Array._new(indices),
|
| 56 |
+
Array._new(inverse_indices),
|
| 57 |
+
Array._new(counts),
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def unique_counts(x: Array, /) -> UniqueCountsResult:
|
| 62 |
+
res = np.unique(
|
| 63 |
+
x._array,
|
| 64 |
+
return_counts=True,
|
| 65 |
+
return_index=False,
|
| 66 |
+
return_inverse=False,
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
return UniqueCountsResult(*[Array._new(i) for i in res])
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def unique_inverse(x: Array, /) -> UniqueInverseResult:
|
| 73 |
+
"""
|
| 74 |
+
Array API compatible wrapper for :py:func:`np.unique <numpy.unique>`.
|
| 75 |
+
|
| 76 |
+
See its docstring for more information.
|
| 77 |
+
"""
|
| 78 |
+
values, inverse_indices = np.unique(
|
| 79 |
+
x._array,
|
| 80 |
+
return_counts=False,
|
| 81 |
+
return_index=False,
|
| 82 |
+
return_inverse=True,
|
| 83 |
+
)
|
| 84 |
+
# np.unique() flattens inverse indices, but they need to share x's shape
|
| 85 |
+
# See https://github.com/numpy/numpy/issues/20638
|
| 86 |
+
inverse_indices = inverse_indices.reshape(x.shape)
|
| 87 |
+
return UniqueInverseResult(Array._new(values), Array._new(inverse_indices))
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def unique_values(x: Array, /) -> Array:
|
| 91 |
+
"""
|
| 92 |
+
Array API compatible wrapper for :py:func:`np.unique <numpy.unique>`.
|
| 93 |
+
|
| 94 |
+
See its docstring for more information.
|
| 95 |
+
"""
|
| 96 |
+
res = np.unique(
|
| 97 |
+
x._array,
|
| 98 |
+
return_counts=False,
|
| 99 |
+
return_index=False,
|
| 100 |
+
return_inverse=False,
|
| 101 |
+
)
|
| 102 |
+
return Array._new(res)
|
wemm/lib/python3.10/site-packages/numpy/array_api/_sorting_functions.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from ._array_object import Array
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# Note: the descending keyword argument is new in this function
|
| 9 |
+
def argsort(
|
| 10 |
+
x: Array, /, *, axis: int = -1, descending: bool = False, stable: bool = True
|
| 11 |
+
) -> Array:
|
| 12 |
+
"""
|
| 13 |
+
Array API compatible wrapper for :py:func:`np.argsort <numpy.argsort>`.
|
| 14 |
+
|
| 15 |
+
See its docstring for more information.
|
| 16 |
+
"""
|
| 17 |
+
# Note: this keyword argument is different, and the default is different.
|
| 18 |
+
kind = "stable" if stable else "quicksort"
|
| 19 |
+
if not descending:
|
| 20 |
+
res = np.argsort(x._array, axis=axis, kind=kind)
|
| 21 |
+
else:
|
| 22 |
+
# As NumPy has no native descending sort, we imitate it here. Note that
|
| 23 |
+
# simply flipping the results of np.argsort(x._array, ...) would not
|
| 24 |
+
# respect the relative order like it would in native descending sorts.
|
| 25 |
+
res = np.flip(
|
| 26 |
+
np.argsort(np.flip(x._array, axis=axis), axis=axis, kind=kind),
|
| 27 |
+
axis=axis,
|
| 28 |
+
)
|
| 29 |
+
# Rely on flip()/argsort() to validate axis
|
| 30 |
+
normalised_axis = axis if axis >= 0 else x.ndim + axis
|
| 31 |
+
max_i = x.shape[normalised_axis] - 1
|
| 32 |
+
res = max_i - res
|
| 33 |
+
return Array._new(res)
|
| 34 |
+
|
| 35 |
+
# Note: the descending keyword argument is new in this function
|
| 36 |
+
def sort(
|
| 37 |
+
x: Array, /, *, axis: int = -1, descending: bool = False, stable: bool = True
|
| 38 |
+
) -> Array:
|
| 39 |
+
"""
|
| 40 |
+
Array API compatible wrapper for :py:func:`np.sort <numpy.sort>`.
|
| 41 |
+
|
| 42 |
+
See its docstring for more information.
|
| 43 |
+
"""
|
| 44 |
+
# Note: this keyword argument is different, and the default is different.
|
| 45 |
+
kind = "stable" if stable else "quicksort"
|
| 46 |
+
res = np.sort(x._array, axis=axis, kind=kind)
|
| 47 |
+
if descending:
|
| 48 |
+
res = np.flip(res, axis=axis)
|
| 49 |
+
return Array._new(res)
|
wemm/lib/python3.10/site-packages/numpy/array_api/_statistical_functions.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from ._dtypes import (
|
| 4 |
+
_floating_dtypes,
|
| 5 |
+
_numeric_dtypes,
|
| 6 |
+
)
|
| 7 |
+
from ._array_object import Array
|
| 8 |
+
from ._creation_functions import asarray
|
| 9 |
+
from ._dtypes import float32, float64
|
| 10 |
+
|
| 11 |
+
from typing import TYPE_CHECKING, Optional, Tuple, Union
|
| 12 |
+
|
| 13 |
+
if TYPE_CHECKING:
|
| 14 |
+
from ._typing import Dtype
|
| 15 |
+
|
| 16 |
+
import numpy as np
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def max(
|
| 20 |
+
x: Array,
|
| 21 |
+
/,
|
| 22 |
+
*,
|
| 23 |
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
| 24 |
+
keepdims: bool = False,
|
| 25 |
+
) -> Array:
|
| 26 |
+
if x.dtype not in _numeric_dtypes:
|
| 27 |
+
raise TypeError("Only numeric dtypes are allowed in max")
|
| 28 |
+
return Array._new(np.max(x._array, axis=axis, keepdims=keepdims))
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def mean(
|
| 32 |
+
x: Array,
|
| 33 |
+
/,
|
| 34 |
+
*,
|
| 35 |
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
| 36 |
+
keepdims: bool = False,
|
| 37 |
+
) -> Array:
|
| 38 |
+
if x.dtype not in _floating_dtypes:
|
| 39 |
+
raise TypeError("Only floating-point dtypes are allowed in mean")
|
| 40 |
+
return Array._new(np.mean(x._array, axis=axis, keepdims=keepdims))
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def min(
|
| 44 |
+
x: Array,
|
| 45 |
+
/,
|
| 46 |
+
*,
|
| 47 |
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
| 48 |
+
keepdims: bool = False,
|
| 49 |
+
) -> Array:
|
| 50 |
+
if x.dtype not in _numeric_dtypes:
|
| 51 |
+
raise TypeError("Only numeric dtypes are allowed in min")
|
| 52 |
+
return Array._new(np.min(x._array, axis=axis, keepdims=keepdims))
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def prod(
|
| 56 |
+
x: Array,
|
| 57 |
+
/,
|
| 58 |
+
*,
|
| 59 |
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
| 60 |
+
dtype: Optional[Dtype] = None,
|
| 61 |
+
keepdims: bool = False,
|
| 62 |
+
) -> Array:
|
| 63 |
+
if x.dtype not in _numeric_dtypes:
|
| 64 |
+
raise TypeError("Only numeric dtypes are allowed in prod")
|
| 65 |
+
# Note: sum() and prod() always upcast float32 to float64 for dtype=None
|
| 66 |
+
# We need to do so here before computing the product to avoid overflow
|
| 67 |
+
if dtype is None and x.dtype == float32:
|
| 68 |
+
dtype = float64
|
| 69 |
+
return Array._new(np.prod(x._array, dtype=dtype, axis=axis, keepdims=keepdims))
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def std(
|
| 73 |
+
x: Array,
|
| 74 |
+
/,
|
| 75 |
+
*,
|
| 76 |
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
| 77 |
+
correction: Union[int, float] = 0.0,
|
| 78 |
+
keepdims: bool = False,
|
| 79 |
+
) -> Array:
|
| 80 |
+
# Note: the keyword argument correction is different here
|
| 81 |
+
if x.dtype not in _floating_dtypes:
|
| 82 |
+
raise TypeError("Only floating-point dtypes are allowed in std")
|
| 83 |
+
return Array._new(np.std(x._array, axis=axis, ddof=correction, keepdims=keepdims))
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def sum(
|
| 87 |
+
x: Array,
|
| 88 |
+
/,
|
| 89 |
+
*,
|
| 90 |
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
| 91 |
+
dtype: Optional[Dtype] = None,
|
| 92 |
+
keepdims: bool = False,
|
| 93 |
+
) -> Array:
|
| 94 |
+
if x.dtype not in _numeric_dtypes:
|
| 95 |
+
raise TypeError("Only numeric dtypes are allowed in sum")
|
| 96 |
+
# Note: sum() and prod() always upcast integers to (u)int64 and float32 to
|
| 97 |
+
# float64 for dtype=None. `np.sum` does that too for integers, but not for
|
| 98 |
+
# float32, so we need to special-case it here
|
| 99 |
+
if dtype is None and x.dtype == float32:
|
| 100 |
+
dtype = float64
|
| 101 |
+
return Array._new(np.sum(x._array, axis=axis, dtype=dtype, keepdims=keepdims))
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def var(
|
| 105 |
+
x: Array,
|
| 106 |
+
/,
|
| 107 |
+
*,
|
| 108 |
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
| 109 |
+
correction: Union[int, float] = 0.0,
|
| 110 |
+
keepdims: bool = False,
|
| 111 |
+
) -> Array:
|
| 112 |
+
# Note: the keyword argument correction is different here
|
| 113 |
+
if x.dtype not in _floating_dtypes:
|
| 114 |
+
raise TypeError("Only floating-point dtypes are allowed in var")
|
| 115 |
+
return Array._new(np.var(x._array, axis=axis, ddof=correction, keepdims=keepdims))
|
wemm/lib/python3.10/site-packages/numpy/array_api/_utility_functions.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from ._array_object import Array
|
| 4 |
+
|
| 5 |
+
from typing import Optional, Tuple, Union
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def all(
|
| 11 |
+
x: Array,
|
| 12 |
+
/,
|
| 13 |
+
*,
|
| 14 |
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
| 15 |
+
keepdims: bool = False,
|
| 16 |
+
) -> Array:
|
| 17 |
+
"""
|
| 18 |
+
Array API compatible wrapper for :py:func:`np.all <numpy.all>`.
|
| 19 |
+
|
| 20 |
+
See its docstring for more information.
|
| 21 |
+
"""
|
| 22 |
+
return Array._new(np.asarray(np.all(x._array, axis=axis, keepdims=keepdims)))
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def any(
|
| 26 |
+
x: Array,
|
| 27 |
+
/,
|
| 28 |
+
*,
|
| 29 |
+
axis: Optional[Union[int, Tuple[int, ...]]] = None,
|
| 30 |
+
keepdims: bool = False,
|
| 31 |
+
) -> Array:
|
| 32 |
+
"""
|
| 33 |
+
Array API compatible wrapper for :py:func:`np.any <numpy.any>`.
|
| 34 |
+
|
| 35 |
+
See its docstring for more information.
|
| 36 |
+
"""
|
| 37 |
+
return Array._new(np.asarray(np.any(x._array, axis=axis, keepdims=keepdims)))
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tests for the array API namespace.
|
| 3 |
+
|
| 4 |
+
Note, full compliance with the array API can be tested with the official array API test
|
| 5 |
+
suite https://github.com/data-apis/array-api-tests. This test suite primarily
|
| 6 |
+
focuses on those things that are not tested by the official test suite.
|
| 7 |
+
"""
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (461 Bytes). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/test_array_object.cpython-310.pyc
ADDED
|
Binary file (14.1 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/test_creation_functions.cpython-310.pyc
ADDED
|
Binary file (8.11 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/test_data_type_functions.cpython-310.pyc
ADDED
|
Binary file (625 Bytes). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/test_elementwise_functions.cpython-310.pyc
ADDED
|
Binary file (3.08 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/test_set_functions.cpython-310.pyc
ADDED
|
Binary file (816 Bytes). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/__pycache__/test_sorting_functions.cpython-310.pyc
ADDED
|
Binary file (833 Bytes). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/test_creation_functions.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from numpy.testing import assert_raises
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
from .. import all
|
| 5 |
+
from .._creation_functions import (
|
| 6 |
+
asarray,
|
| 7 |
+
arange,
|
| 8 |
+
empty,
|
| 9 |
+
empty_like,
|
| 10 |
+
eye,
|
| 11 |
+
full,
|
| 12 |
+
full_like,
|
| 13 |
+
linspace,
|
| 14 |
+
meshgrid,
|
| 15 |
+
ones,
|
| 16 |
+
ones_like,
|
| 17 |
+
zeros,
|
| 18 |
+
zeros_like,
|
| 19 |
+
)
|
| 20 |
+
from .._dtypes import float32, float64
|
| 21 |
+
from .._array_object import Array
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def test_asarray_errors():
|
| 25 |
+
# Test various protections against incorrect usage
|
| 26 |
+
assert_raises(TypeError, lambda: Array([1]))
|
| 27 |
+
assert_raises(TypeError, lambda: asarray(["a"]))
|
| 28 |
+
assert_raises(ValueError, lambda: asarray([1.0], dtype=np.float16))
|
| 29 |
+
assert_raises(OverflowError, lambda: asarray(2**100))
|
| 30 |
+
# Preferably this would be OverflowError
|
| 31 |
+
# assert_raises(OverflowError, lambda: asarray([2**100]))
|
| 32 |
+
assert_raises(TypeError, lambda: asarray([2**100]))
|
| 33 |
+
asarray([1], device="cpu") # Doesn't error
|
| 34 |
+
assert_raises(ValueError, lambda: asarray([1], device="gpu"))
|
| 35 |
+
|
| 36 |
+
assert_raises(ValueError, lambda: asarray([1], dtype=int))
|
| 37 |
+
assert_raises(ValueError, lambda: asarray([1], dtype="i"))
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def test_asarray_copy():
|
| 41 |
+
a = asarray([1])
|
| 42 |
+
b = asarray(a, copy=True)
|
| 43 |
+
a[0] = 0
|
| 44 |
+
assert all(b[0] == 1)
|
| 45 |
+
assert all(a[0] == 0)
|
| 46 |
+
a = asarray([1])
|
| 47 |
+
b = asarray(a, copy=np._CopyMode.ALWAYS)
|
| 48 |
+
a[0] = 0
|
| 49 |
+
assert all(b[0] == 1)
|
| 50 |
+
assert all(a[0] == 0)
|
| 51 |
+
a = asarray([1])
|
| 52 |
+
b = asarray(a, copy=np._CopyMode.NEVER)
|
| 53 |
+
a[0] = 0
|
| 54 |
+
assert all(b[0] == 0)
|
| 55 |
+
assert_raises(NotImplementedError, lambda: asarray(a, copy=False))
|
| 56 |
+
assert_raises(NotImplementedError,
|
| 57 |
+
lambda: asarray(a, copy=np._CopyMode.IF_NEEDED))
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def test_arange_errors():
|
| 61 |
+
arange(1, device="cpu") # Doesn't error
|
| 62 |
+
assert_raises(ValueError, lambda: arange(1, device="gpu"))
|
| 63 |
+
assert_raises(ValueError, lambda: arange(1, dtype=int))
|
| 64 |
+
assert_raises(ValueError, lambda: arange(1, dtype="i"))
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def test_empty_errors():
|
| 68 |
+
empty((1,), device="cpu") # Doesn't error
|
| 69 |
+
assert_raises(ValueError, lambda: empty((1,), device="gpu"))
|
| 70 |
+
assert_raises(ValueError, lambda: empty((1,), dtype=int))
|
| 71 |
+
assert_raises(ValueError, lambda: empty((1,), dtype="i"))
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def test_empty_like_errors():
|
| 75 |
+
empty_like(asarray(1), device="cpu") # Doesn't error
|
| 76 |
+
assert_raises(ValueError, lambda: empty_like(asarray(1), device="gpu"))
|
| 77 |
+
assert_raises(ValueError, lambda: empty_like(asarray(1), dtype=int))
|
| 78 |
+
assert_raises(ValueError, lambda: empty_like(asarray(1), dtype="i"))
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def test_eye_errors():
|
| 82 |
+
eye(1, device="cpu") # Doesn't error
|
| 83 |
+
assert_raises(ValueError, lambda: eye(1, device="gpu"))
|
| 84 |
+
assert_raises(ValueError, lambda: eye(1, dtype=int))
|
| 85 |
+
assert_raises(ValueError, lambda: eye(1, dtype="i"))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def test_full_errors():
|
| 89 |
+
full((1,), 0, device="cpu") # Doesn't error
|
| 90 |
+
assert_raises(ValueError, lambda: full((1,), 0, device="gpu"))
|
| 91 |
+
assert_raises(ValueError, lambda: full((1,), 0, dtype=int))
|
| 92 |
+
assert_raises(ValueError, lambda: full((1,), 0, dtype="i"))
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def test_full_like_errors():
|
| 96 |
+
full_like(asarray(1), 0, device="cpu") # Doesn't error
|
| 97 |
+
assert_raises(ValueError, lambda: full_like(asarray(1), 0, device="gpu"))
|
| 98 |
+
assert_raises(ValueError, lambda: full_like(asarray(1), 0, dtype=int))
|
| 99 |
+
assert_raises(ValueError, lambda: full_like(asarray(1), 0, dtype="i"))
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def test_linspace_errors():
|
| 103 |
+
linspace(0, 1, 10, device="cpu") # Doesn't error
|
| 104 |
+
assert_raises(ValueError, lambda: linspace(0, 1, 10, device="gpu"))
|
| 105 |
+
assert_raises(ValueError, lambda: linspace(0, 1, 10, dtype=float))
|
| 106 |
+
assert_raises(ValueError, lambda: linspace(0, 1, 10, dtype="f"))
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def test_ones_errors():
|
| 110 |
+
ones((1,), device="cpu") # Doesn't error
|
| 111 |
+
assert_raises(ValueError, lambda: ones((1,), device="gpu"))
|
| 112 |
+
assert_raises(ValueError, lambda: ones((1,), dtype=int))
|
| 113 |
+
assert_raises(ValueError, lambda: ones((1,), dtype="i"))
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def test_ones_like_errors():
|
| 117 |
+
ones_like(asarray(1), device="cpu") # Doesn't error
|
| 118 |
+
assert_raises(ValueError, lambda: ones_like(asarray(1), device="gpu"))
|
| 119 |
+
assert_raises(ValueError, lambda: ones_like(asarray(1), dtype=int))
|
| 120 |
+
assert_raises(ValueError, lambda: ones_like(asarray(1), dtype="i"))
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def test_zeros_errors():
|
| 124 |
+
zeros((1,), device="cpu") # Doesn't error
|
| 125 |
+
assert_raises(ValueError, lambda: zeros((1,), device="gpu"))
|
| 126 |
+
assert_raises(ValueError, lambda: zeros((1,), dtype=int))
|
| 127 |
+
assert_raises(ValueError, lambda: zeros((1,), dtype="i"))
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def test_zeros_like_errors():
|
| 131 |
+
zeros_like(asarray(1), device="cpu") # Doesn't error
|
| 132 |
+
assert_raises(ValueError, lambda: zeros_like(asarray(1), device="gpu"))
|
| 133 |
+
assert_raises(ValueError, lambda: zeros_like(asarray(1), dtype=int))
|
| 134 |
+
assert_raises(ValueError, lambda: zeros_like(asarray(1), dtype="i"))
|
| 135 |
+
|
| 136 |
+
def test_meshgrid_dtype_errors():
|
| 137 |
+
# Doesn't raise
|
| 138 |
+
meshgrid()
|
| 139 |
+
meshgrid(asarray([1.], dtype=float32))
|
| 140 |
+
meshgrid(asarray([1.], dtype=float32), asarray([1.], dtype=float32))
|
| 141 |
+
|
| 142 |
+
assert_raises(ValueError, lambda: meshgrid(asarray([1.], dtype=float32), asarray([1.], dtype=float64)))
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/test_data_type_functions.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
from numpy import array_api as xp
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@pytest.mark.parametrize(
|
| 7 |
+
"from_, to, expected",
|
| 8 |
+
[
|
| 9 |
+
(xp.int8, xp.int16, True),
|
| 10 |
+
(xp.int16, xp.int8, False),
|
| 11 |
+
(xp.bool, xp.int8, False),
|
| 12 |
+
(xp.asarray(0, dtype=xp.uint8), xp.int8, False),
|
| 13 |
+
],
|
| 14 |
+
)
|
| 15 |
+
def test_can_cast(from_, to, expected):
|
| 16 |
+
"""
|
| 17 |
+
can_cast() returns correct result
|
| 18 |
+
"""
|
| 19 |
+
assert xp.can_cast(from_, to) == expected
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/test_set_functions.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
from hypothesis import given
|
| 3 |
+
from hypothesis.extra.array_api import make_strategies_namespace
|
| 4 |
+
|
| 5 |
+
from numpy import array_api as xp
|
| 6 |
+
|
| 7 |
+
xps = make_strategies_namespace(xp)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@pytest.mark.parametrize("func", [xp.unique_all, xp.unique_inverse])
|
| 11 |
+
@given(xps.arrays(dtype=xps.scalar_dtypes(), shape=xps.array_shapes()))
|
| 12 |
+
def test_inverse_indices_shape(func, x):
|
| 13 |
+
"""
|
| 14 |
+
Inverse indices share shape of input array
|
| 15 |
+
|
| 16 |
+
See https://github.com/numpy/numpy/issues/20638
|
| 17 |
+
"""
|
| 18 |
+
out = func(x)
|
| 19 |
+
assert out.inverse_indices.shape == x.shape
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/test_sorting_functions.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
from numpy import array_api as xp
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@pytest.mark.parametrize(
|
| 7 |
+
"obj, axis, expected",
|
| 8 |
+
[
|
| 9 |
+
([0, 0], -1, [0, 1]),
|
| 10 |
+
([0, 1, 0], -1, [1, 0, 2]),
|
| 11 |
+
([[0, 1], [1, 1]], 0, [[1, 0], [0, 1]]),
|
| 12 |
+
([[0, 1], [1, 1]], 1, [[1, 0], [0, 1]]),
|
| 13 |
+
],
|
| 14 |
+
)
|
| 15 |
+
def test_stable_desc_argsort(obj, axis, expected):
|
| 16 |
+
"""
|
| 17 |
+
Indices respect relative order of a descending stable-sort
|
| 18 |
+
|
| 19 |
+
See https://github.com/numpy/numpy/issues/20778
|
| 20 |
+
"""
|
| 21 |
+
x = xp.asarray(obj)
|
| 22 |
+
out = xp.argsort(x, axis=axis, stable=True, descending=True)
|
| 23 |
+
assert xp.all(out == xp.asarray(expected))
|
wemm/lib/python3.10/site-packages/numpy/array_api/tests/test_validation.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Callable
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from numpy import array_api as xp
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def p(func: Callable, *args, **kwargs):
|
| 9 |
+
f_sig = ", ".join(
|
| 10 |
+
[str(a) for a in args] + [f"{k}={v}" for k, v in kwargs.items()]
|
| 11 |
+
)
|
| 12 |
+
id_ = f"{func.__name__}({f_sig})"
|
| 13 |
+
return pytest.param(func, args, kwargs, id=id_)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@pytest.mark.parametrize(
|
| 17 |
+
"func, args, kwargs",
|
| 18 |
+
[
|
| 19 |
+
p(xp.can_cast, 42, xp.int8),
|
| 20 |
+
p(xp.can_cast, xp.int8, 42),
|
| 21 |
+
p(xp.result_type, 42),
|
| 22 |
+
],
|
| 23 |
+
)
|
| 24 |
+
def test_raises_on_invalid_types(func, args, kwargs):
|
| 25 |
+
"""Function raises TypeError when passed invalidly-typed inputs"""
|
| 26 |
+
with pytest.raises(TypeError):
|
| 27 |
+
func(*args, **kwargs)
|
wemm/lib/python3.10/site-packages/numpy/doc/__pycache__/ufuncs.cpython-310.pyc
ADDED
|
Binary file (5.52 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/random/__init__.pxd
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cimport numpy as np
|
| 2 |
+
from libc.stdint cimport uint32_t, uint64_t
|
| 3 |
+
|
| 4 |
+
cdef extern from "numpy/random/bitgen.h":
|
| 5 |
+
struct bitgen:
|
| 6 |
+
void *state
|
| 7 |
+
uint64_t (*next_uint64)(void *st) nogil
|
| 8 |
+
uint32_t (*next_uint32)(void *st) nogil
|
| 9 |
+
double (*next_double)(void *st) nogil
|
| 10 |
+
uint64_t (*next_raw)(void *st) nogil
|
| 11 |
+
|
| 12 |
+
ctypedef bitgen bitgen_t
|
| 13 |
+
|
| 14 |
+
from numpy.random.bit_generator cimport BitGenerator, SeedSequence
|
wemm/lib/python3.10/site-packages/numpy/random/__init__.py
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
========================
|
| 3 |
+
Random Number Generation
|
| 4 |
+
========================
|
| 5 |
+
|
| 6 |
+
Use ``default_rng()`` to create a `Generator` and call its methods.
|
| 7 |
+
|
| 8 |
+
=============== =========================================================
|
| 9 |
+
Generator
|
| 10 |
+
--------------- ---------------------------------------------------------
|
| 11 |
+
Generator Class implementing all of the random number distributions
|
| 12 |
+
default_rng Default constructor for ``Generator``
|
| 13 |
+
=============== =========================================================
|
| 14 |
+
|
| 15 |
+
============================================= ===
|
| 16 |
+
BitGenerator Streams that work with Generator
|
| 17 |
+
--------------------------------------------- ---
|
| 18 |
+
MT19937
|
| 19 |
+
PCG64
|
| 20 |
+
PCG64DXSM
|
| 21 |
+
Philox
|
| 22 |
+
SFC64
|
| 23 |
+
============================================= ===
|
| 24 |
+
|
| 25 |
+
============================================= ===
|
| 26 |
+
Getting entropy to initialize a BitGenerator
|
| 27 |
+
--------------------------------------------- ---
|
| 28 |
+
SeedSequence
|
| 29 |
+
============================================= ===
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Legacy
|
| 33 |
+
------
|
| 34 |
+
|
| 35 |
+
For backwards compatibility with previous versions of numpy before 1.17, the
|
| 36 |
+
various aliases to the global `RandomState` methods are left alone and do not
|
| 37 |
+
use the new `Generator` API.
|
| 38 |
+
|
| 39 |
+
==================== =========================================================
|
| 40 |
+
Utility functions
|
| 41 |
+
-------------------- ---------------------------------------------------------
|
| 42 |
+
random Uniformly distributed floats over ``[0, 1)``
|
| 43 |
+
bytes Uniformly distributed random bytes.
|
| 44 |
+
permutation Randomly permute a sequence / generate a random sequence.
|
| 45 |
+
shuffle Randomly permute a sequence in place.
|
| 46 |
+
choice Random sample from 1-D array.
|
| 47 |
+
==================== =========================================================
|
| 48 |
+
|
| 49 |
+
==================== =========================================================
|
| 50 |
+
Compatibility
|
| 51 |
+
functions - removed
|
| 52 |
+
in the new API
|
| 53 |
+
-------------------- ---------------------------------------------------------
|
| 54 |
+
rand Uniformly distributed values.
|
| 55 |
+
randn Normally distributed values.
|
| 56 |
+
ranf Uniformly distributed floating point numbers.
|
| 57 |
+
random_integers Uniformly distributed integers in a given range.
|
| 58 |
+
(deprecated, use ``integers(..., closed=True)`` instead)
|
| 59 |
+
random_sample Alias for `random_sample`
|
| 60 |
+
randint Uniformly distributed integers in a given range
|
| 61 |
+
seed Seed the legacy random number generator.
|
| 62 |
+
==================== =========================================================
|
| 63 |
+
|
| 64 |
+
==================== =========================================================
|
| 65 |
+
Univariate
|
| 66 |
+
distributions
|
| 67 |
+
-------------------- ---------------------------------------------------------
|
| 68 |
+
beta Beta distribution over ``[0, 1]``.
|
| 69 |
+
binomial Binomial distribution.
|
| 70 |
+
chisquare :math:`\\chi^2` distribution.
|
| 71 |
+
exponential Exponential distribution.
|
| 72 |
+
f F (Fisher-Snedecor) distribution.
|
| 73 |
+
gamma Gamma distribution.
|
| 74 |
+
geometric Geometric distribution.
|
| 75 |
+
gumbel Gumbel distribution.
|
| 76 |
+
hypergeometric Hypergeometric distribution.
|
| 77 |
+
laplace Laplace distribution.
|
| 78 |
+
logistic Logistic distribution.
|
| 79 |
+
lognormal Log-normal distribution.
|
| 80 |
+
logseries Logarithmic series distribution.
|
| 81 |
+
negative_binomial Negative binomial distribution.
|
| 82 |
+
noncentral_chisquare Non-central chi-square distribution.
|
| 83 |
+
noncentral_f Non-central F distribution.
|
| 84 |
+
normal Normal / Gaussian distribution.
|
| 85 |
+
pareto Pareto distribution.
|
| 86 |
+
poisson Poisson distribution.
|
| 87 |
+
power Power distribution.
|
| 88 |
+
rayleigh Rayleigh distribution.
|
| 89 |
+
triangular Triangular distribution.
|
| 90 |
+
uniform Uniform distribution.
|
| 91 |
+
vonmises Von Mises circular distribution.
|
| 92 |
+
wald Wald (inverse Gaussian) distribution.
|
| 93 |
+
weibull Weibull distribution.
|
| 94 |
+
zipf Zipf's distribution over ranked data.
|
| 95 |
+
==================== =========================================================
|
| 96 |
+
|
| 97 |
+
==================== ==========================================================
|
| 98 |
+
Multivariate
|
| 99 |
+
distributions
|
| 100 |
+
-------------------- ----------------------------------------------------------
|
| 101 |
+
dirichlet Multivariate generalization of Beta distribution.
|
| 102 |
+
multinomial Multivariate generalization of the binomial distribution.
|
| 103 |
+
multivariate_normal Multivariate generalization of the normal distribution.
|
| 104 |
+
==================== ==========================================================
|
| 105 |
+
|
| 106 |
+
==================== =========================================================
|
| 107 |
+
Standard
|
| 108 |
+
distributions
|
| 109 |
+
-------------------- ---------------------------------------------------------
|
| 110 |
+
standard_cauchy Standard Cauchy-Lorentz distribution.
|
| 111 |
+
standard_exponential Standard exponential distribution.
|
| 112 |
+
standard_gamma Standard Gamma distribution.
|
| 113 |
+
standard_normal Standard normal distribution.
|
| 114 |
+
standard_t Standard Student's t-distribution.
|
| 115 |
+
==================== =========================================================
|
| 116 |
+
|
| 117 |
+
==================== =========================================================
|
| 118 |
+
Internal functions
|
| 119 |
+
-------------------- ---------------------------------------------------------
|
| 120 |
+
get_state Get tuple representing internal state of generator.
|
| 121 |
+
set_state Set state of generator.
|
| 122 |
+
==================== =========================================================
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
"""
|
| 126 |
+
__all__ = [
|
| 127 |
+
'beta',
|
| 128 |
+
'binomial',
|
| 129 |
+
'bytes',
|
| 130 |
+
'chisquare',
|
| 131 |
+
'choice',
|
| 132 |
+
'dirichlet',
|
| 133 |
+
'exponential',
|
| 134 |
+
'f',
|
| 135 |
+
'gamma',
|
| 136 |
+
'geometric',
|
| 137 |
+
'get_state',
|
| 138 |
+
'gumbel',
|
| 139 |
+
'hypergeometric',
|
| 140 |
+
'laplace',
|
| 141 |
+
'logistic',
|
| 142 |
+
'lognormal',
|
| 143 |
+
'logseries',
|
| 144 |
+
'multinomial',
|
| 145 |
+
'multivariate_normal',
|
| 146 |
+
'negative_binomial',
|
| 147 |
+
'noncentral_chisquare',
|
| 148 |
+
'noncentral_f',
|
| 149 |
+
'normal',
|
| 150 |
+
'pareto',
|
| 151 |
+
'permutation',
|
| 152 |
+
'poisson',
|
| 153 |
+
'power',
|
| 154 |
+
'rand',
|
| 155 |
+
'randint',
|
| 156 |
+
'randn',
|
| 157 |
+
'random',
|
| 158 |
+
'random_integers',
|
| 159 |
+
'random_sample',
|
| 160 |
+
'ranf',
|
| 161 |
+
'rayleigh',
|
| 162 |
+
'sample',
|
| 163 |
+
'seed',
|
| 164 |
+
'set_state',
|
| 165 |
+
'shuffle',
|
| 166 |
+
'standard_cauchy',
|
| 167 |
+
'standard_exponential',
|
| 168 |
+
'standard_gamma',
|
| 169 |
+
'standard_normal',
|
| 170 |
+
'standard_t',
|
| 171 |
+
'triangular',
|
| 172 |
+
'uniform',
|
| 173 |
+
'vonmises',
|
| 174 |
+
'wald',
|
| 175 |
+
'weibull',
|
| 176 |
+
'zipf',
|
| 177 |
+
]
|
| 178 |
+
|
| 179 |
+
# add these for module-freeze analysis (like PyInstaller)
|
| 180 |
+
from . import _pickle
|
| 181 |
+
from . import _common
|
| 182 |
+
from . import _bounded_integers
|
| 183 |
+
|
| 184 |
+
from ._generator import Generator, default_rng
|
| 185 |
+
from .bit_generator import SeedSequence, BitGenerator
|
| 186 |
+
from ._mt19937 import MT19937
|
| 187 |
+
from ._pcg64 import PCG64, PCG64DXSM
|
| 188 |
+
from ._philox import Philox
|
| 189 |
+
from ._sfc64 import SFC64
|
| 190 |
+
from .mtrand import *
|
| 191 |
+
|
| 192 |
+
__all__ += ['Generator', 'RandomState', 'SeedSequence', 'MT19937',
|
| 193 |
+
'Philox', 'PCG64', 'PCG64DXSM', 'SFC64', 'default_rng',
|
| 194 |
+
'BitGenerator']
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def __RandomState_ctor():
|
| 198 |
+
"""Return a RandomState instance.
|
| 199 |
+
|
| 200 |
+
This function exists solely to assist (un)pickling.
|
| 201 |
+
|
| 202 |
+
Note that the state of the RandomState returned here is irrelevant, as this
|
| 203 |
+
function's entire purpose is to return a newly allocated RandomState whose
|
| 204 |
+
state pickle can set. Consequently the RandomState returned by this function
|
| 205 |
+
is a freshly allocated copy with a seed=0.
|
| 206 |
+
|
| 207 |
+
See https://github.com/numpy/numpy/issues/4763 for a detailed discussion
|
| 208 |
+
|
| 209 |
+
"""
|
| 210 |
+
return RandomState(seed=0)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
from numpy._pytesttester import PytestTester
|
| 214 |
+
test = PytestTester(__name__)
|
| 215 |
+
del PytestTester
|
wemm/lib/python3.10/site-packages/numpy/random/__init__.pyi
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from numpy._pytesttester import PytestTester
|
| 2 |
+
|
| 3 |
+
from numpy.random._generator import Generator as Generator
|
| 4 |
+
from numpy.random._generator import default_rng as default_rng
|
| 5 |
+
from numpy.random._mt19937 import MT19937 as MT19937
|
| 6 |
+
from numpy.random._pcg64 import (
|
| 7 |
+
PCG64 as PCG64,
|
| 8 |
+
PCG64DXSM as PCG64DXSM,
|
| 9 |
+
)
|
| 10 |
+
from numpy.random._philox import Philox as Philox
|
| 11 |
+
from numpy.random._sfc64 import SFC64 as SFC64
|
| 12 |
+
from numpy.random.bit_generator import BitGenerator as BitGenerator
|
| 13 |
+
from numpy.random.bit_generator import SeedSequence as SeedSequence
|
| 14 |
+
from numpy.random.mtrand import (
|
| 15 |
+
RandomState as RandomState,
|
| 16 |
+
beta as beta,
|
| 17 |
+
binomial as binomial,
|
| 18 |
+
bytes as bytes,
|
| 19 |
+
chisquare as chisquare,
|
| 20 |
+
choice as choice,
|
| 21 |
+
dirichlet as dirichlet,
|
| 22 |
+
exponential as exponential,
|
| 23 |
+
f as f,
|
| 24 |
+
gamma as gamma,
|
| 25 |
+
geometric as geometric,
|
| 26 |
+
get_state as get_state,
|
| 27 |
+
gumbel as gumbel,
|
| 28 |
+
hypergeometric as hypergeometric,
|
| 29 |
+
laplace as laplace,
|
| 30 |
+
logistic as logistic,
|
| 31 |
+
lognormal as lognormal,
|
| 32 |
+
logseries as logseries,
|
| 33 |
+
multinomial as multinomial,
|
| 34 |
+
multivariate_normal as multivariate_normal,
|
| 35 |
+
negative_binomial as negative_binomial,
|
| 36 |
+
noncentral_chisquare as noncentral_chisquare,
|
| 37 |
+
noncentral_f as noncentral_f,
|
| 38 |
+
normal as normal,
|
| 39 |
+
pareto as pareto,
|
| 40 |
+
permutation as permutation,
|
| 41 |
+
poisson as poisson,
|
| 42 |
+
power as power,
|
| 43 |
+
rand as rand,
|
| 44 |
+
randint as randint,
|
| 45 |
+
randn as randn,
|
| 46 |
+
random as random,
|
| 47 |
+
random_integers as random_integers,
|
| 48 |
+
random_sample as random_sample,
|
| 49 |
+
ranf as ranf,
|
| 50 |
+
rayleigh as rayleigh,
|
| 51 |
+
sample as sample,
|
| 52 |
+
seed as seed,
|
| 53 |
+
set_state as set_state,
|
| 54 |
+
shuffle as shuffle,
|
| 55 |
+
standard_cauchy as standard_cauchy,
|
| 56 |
+
standard_exponential as standard_exponential,
|
| 57 |
+
standard_gamma as standard_gamma,
|
| 58 |
+
standard_normal as standard_normal,
|
| 59 |
+
standard_t as standard_t,
|
| 60 |
+
triangular as triangular,
|
| 61 |
+
uniform as uniform,
|
| 62 |
+
vonmises as vonmises,
|
| 63 |
+
wald as wald,
|
| 64 |
+
weibull as weibull,
|
| 65 |
+
zipf as zipf,
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
__all__: list[str]
|
| 69 |
+
__path__: list[str]
|
| 70 |
+
test: PytestTester
|
wemm/lib/python3.10/site-packages/numpy/random/_bounded_integers.pxd
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from libc.stdint cimport (uint8_t, uint16_t, uint32_t, uint64_t,
|
| 2 |
+
int8_t, int16_t, int32_t, int64_t, intptr_t)
|
| 3 |
+
import numpy as np
|
| 4 |
+
cimport numpy as np
|
| 5 |
+
ctypedef np.npy_bool bool_t
|
| 6 |
+
|
| 7 |
+
from numpy.random cimport bitgen_t
|
| 8 |
+
|
| 9 |
+
cdef inline uint64_t _gen_mask(uint64_t max_val) nogil:
|
| 10 |
+
"""Mask generator for use in bounded random numbers"""
|
| 11 |
+
# Smallest bit mask >= max
|
| 12 |
+
cdef uint64_t mask = max_val
|
| 13 |
+
mask |= mask >> 1
|
| 14 |
+
mask |= mask >> 2
|
| 15 |
+
mask |= mask >> 4
|
| 16 |
+
mask |= mask >> 8
|
| 17 |
+
mask |= mask >> 16
|
| 18 |
+
mask |= mask >> 32
|
| 19 |
+
return mask
|
| 20 |
+
|
| 21 |
+
cdef object _rand_uint64(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 22 |
+
cdef object _rand_uint32(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 23 |
+
cdef object _rand_uint16(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 24 |
+
cdef object _rand_uint8(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 25 |
+
cdef object _rand_bool(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 26 |
+
cdef object _rand_int64(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 27 |
+
cdef object _rand_int32(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 28 |
+
cdef object _rand_int16(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
| 29 |
+
cdef object _rand_int8(object low, object high, object size, bint use_masked, bint closed, bitgen_t *state, object lock)
|
wemm/lib/python3.10/site-packages/numpy/random/_common.pxd
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#cython: language_level=3
|
| 2 |
+
|
| 3 |
+
from libc.stdint cimport uint32_t, uint64_t, int32_t, int64_t
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
cimport numpy as np
|
| 7 |
+
|
| 8 |
+
from numpy.random cimport bitgen_t
|
| 9 |
+
|
| 10 |
+
cdef double POISSON_LAM_MAX
|
| 11 |
+
cdef double LEGACY_POISSON_LAM_MAX
|
| 12 |
+
cdef uint64_t MAXSIZE
|
| 13 |
+
|
| 14 |
+
cdef enum ConstraintType:
|
| 15 |
+
CONS_NONE
|
| 16 |
+
CONS_NON_NEGATIVE
|
| 17 |
+
CONS_POSITIVE
|
| 18 |
+
CONS_POSITIVE_NOT_NAN
|
| 19 |
+
CONS_BOUNDED_0_1
|
| 20 |
+
CONS_BOUNDED_GT_0_1
|
| 21 |
+
CONS_BOUNDED_LT_0_1
|
| 22 |
+
CONS_GT_1
|
| 23 |
+
CONS_GTE_1
|
| 24 |
+
CONS_POISSON
|
| 25 |
+
LEGACY_CONS_POISSON
|
| 26 |
+
|
| 27 |
+
ctypedef ConstraintType constraint_type
|
| 28 |
+
|
| 29 |
+
cdef object benchmark(bitgen_t *bitgen, object lock, Py_ssize_t cnt, object method)
|
| 30 |
+
cdef object random_raw(bitgen_t *bitgen, object lock, object size, object output)
|
| 31 |
+
cdef object prepare_cffi(bitgen_t *bitgen)
|
| 32 |
+
cdef object prepare_ctypes(bitgen_t *bitgen)
|
| 33 |
+
cdef int check_constraint(double val, object name, constraint_type cons) except -1
|
| 34 |
+
cdef int check_array_constraint(np.ndarray val, object name, constraint_type cons) except -1
|
| 35 |
+
|
| 36 |
+
cdef extern from "include/aligned_malloc.h":
|
| 37 |
+
cdef void *PyArray_realloc_aligned(void *p, size_t n)
|
| 38 |
+
cdef void *PyArray_malloc_aligned(size_t n)
|
| 39 |
+
cdef void *PyArray_calloc_aligned(size_t n, size_t s)
|
| 40 |
+
cdef void PyArray_free_aligned(void *p)
|
| 41 |
+
|
| 42 |
+
ctypedef void (*random_double_fill)(bitgen_t *state, np.npy_intp count, double* out) nogil
|
| 43 |
+
ctypedef double (*random_double_0)(void *state) nogil
|
| 44 |
+
ctypedef double (*random_double_1)(void *state, double a) nogil
|
| 45 |
+
ctypedef double (*random_double_2)(void *state, double a, double b) nogil
|
| 46 |
+
ctypedef double (*random_double_3)(void *state, double a, double b, double c) nogil
|
| 47 |
+
|
| 48 |
+
ctypedef void (*random_float_fill)(bitgen_t *state, np.npy_intp count, float* out) nogil
|
| 49 |
+
ctypedef float (*random_float_0)(bitgen_t *state) nogil
|
| 50 |
+
ctypedef float (*random_float_1)(bitgen_t *state, float a) nogil
|
| 51 |
+
|
| 52 |
+
ctypedef int64_t (*random_uint_0)(void *state) nogil
|
| 53 |
+
ctypedef int64_t (*random_uint_d)(void *state, double a) nogil
|
| 54 |
+
ctypedef int64_t (*random_uint_dd)(void *state, double a, double b) nogil
|
| 55 |
+
ctypedef int64_t (*random_uint_di)(void *state, double a, uint64_t b) nogil
|
| 56 |
+
ctypedef int64_t (*random_uint_i)(void *state, int64_t a) nogil
|
| 57 |
+
ctypedef int64_t (*random_uint_iii)(void *state, int64_t a, int64_t b, int64_t c) nogil
|
| 58 |
+
|
| 59 |
+
ctypedef uint32_t (*random_uint_0_32)(bitgen_t *state) nogil
|
| 60 |
+
ctypedef uint32_t (*random_uint_1_i_32)(bitgen_t *state, uint32_t a) nogil
|
| 61 |
+
|
| 62 |
+
ctypedef int32_t (*random_int_2_i_32)(bitgen_t *state, int32_t a, int32_t b) nogil
|
| 63 |
+
ctypedef int64_t (*random_int_2_i)(bitgen_t *state, int64_t a, int64_t b) nogil
|
| 64 |
+
|
| 65 |
+
cdef double kahan_sum(double *darr, np.npy_intp n)
|
| 66 |
+
|
| 67 |
+
cdef inline double uint64_to_double(uint64_t rnd) nogil:
|
| 68 |
+
return (rnd >> 11) * (1.0 / 9007199254740992.0)
|
| 69 |
+
|
| 70 |
+
cdef object double_fill(void *func, bitgen_t *state, object size, object lock, object out)
|
| 71 |
+
|
| 72 |
+
cdef object float_fill(void *func, bitgen_t *state, object size, object lock, object out)
|
| 73 |
+
|
| 74 |
+
cdef object float_fill_from_double(void *func, bitgen_t *state, object size, object lock, object out)
|
| 75 |
+
|
| 76 |
+
cdef object wrap_int(object val, object bits)
|
| 77 |
+
|
| 78 |
+
cdef np.ndarray int_to_array(object value, object name, object bits, object uint_size)
|
| 79 |
+
|
| 80 |
+
cdef validate_output_shape(iter_shape, np.ndarray output)
|
| 81 |
+
|
| 82 |
+
cdef object cont(void *func, void *state, object size, object lock, int narg,
|
| 83 |
+
object a, object a_name, constraint_type a_constraint,
|
| 84 |
+
object b, object b_name, constraint_type b_constraint,
|
| 85 |
+
object c, object c_name, constraint_type c_constraint,
|
| 86 |
+
object out)
|
| 87 |
+
|
| 88 |
+
cdef object disc(void *func, void *state, object size, object lock,
|
| 89 |
+
int narg_double, int narg_int64,
|
| 90 |
+
object a, object a_name, constraint_type a_constraint,
|
| 91 |
+
object b, object b_name, constraint_type b_constraint,
|
| 92 |
+
object c, object c_name, constraint_type c_constraint)
|
| 93 |
+
|
| 94 |
+
cdef object cont_f(void *func, bitgen_t *state, object size, object lock,
|
| 95 |
+
object a, object a_name, constraint_type a_constraint,
|
| 96 |
+
object out)
|
| 97 |
+
|
| 98 |
+
cdef object cont_broadcast_3(void *func, void *state, object size, object lock,
|
| 99 |
+
np.ndarray a_arr, object a_name, constraint_type a_constraint,
|
| 100 |
+
np.ndarray b_arr, object b_name, constraint_type b_constraint,
|
| 101 |
+
np.ndarray c_arr, object c_name, constraint_type c_constraint)
|
| 102 |
+
|
| 103 |
+
cdef object discrete_broadcast_iii(void *func, void *state, object size, object lock,
|
| 104 |
+
np.ndarray a_arr, object a_name, constraint_type a_constraint,
|
| 105 |
+
np.ndarray b_arr, object b_name, constraint_type b_constraint,
|
| 106 |
+
np.ndarray c_arr, object c_name, constraint_type c_constraint)
|
wemm/lib/python3.10/site-packages/numpy/random/_examples/cffi/__pycache__/extending.cpython-310.pyc
ADDED
|
Binary file (925 Bytes). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/random/_examples/cffi/__pycache__/parse.cpython-310.pyc
ADDED
|
Binary file (1.21 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/random/_examples/cffi/extending.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Use cffi to access any of the underlying C functions from distributions.h
|
| 3 |
+
"""
|
| 4 |
+
import os
|
| 5 |
+
import numpy as np
|
| 6 |
+
import cffi
|
| 7 |
+
from .parse import parse_distributions_h
|
| 8 |
+
ffi = cffi.FFI()
|
| 9 |
+
|
| 10 |
+
inc_dir = os.path.join(np.get_include(), 'numpy')
|
| 11 |
+
|
| 12 |
+
# Basic numpy types
|
| 13 |
+
ffi.cdef('''
|
| 14 |
+
typedef intptr_t npy_intp;
|
| 15 |
+
typedef unsigned char npy_bool;
|
| 16 |
+
|
| 17 |
+
''')
|
| 18 |
+
|
| 19 |
+
parse_distributions_h(ffi, inc_dir)
|
| 20 |
+
|
| 21 |
+
lib = ffi.dlopen(np.random._generator.__file__)
|
| 22 |
+
|
| 23 |
+
# Compare the distributions.h random_standard_normal_fill to
|
| 24 |
+
# Generator.standard_random
|
| 25 |
+
bit_gen = np.random.PCG64()
|
| 26 |
+
rng = np.random.Generator(bit_gen)
|
| 27 |
+
state = bit_gen.state
|
| 28 |
+
|
| 29 |
+
interface = rng.bit_generator.cffi
|
| 30 |
+
n = 100
|
| 31 |
+
vals_cffi = ffi.new('double[%d]' % n)
|
| 32 |
+
lib.random_standard_normal_fill(interface.bit_generator, n, vals_cffi)
|
| 33 |
+
|
| 34 |
+
# reset the state
|
| 35 |
+
bit_gen.state = state
|
| 36 |
+
|
| 37 |
+
vals = rng.standard_normal(n)
|
| 38 |
+
|
| 39 |
+
for i in range(n):
|
| 40 |
+
assert vals[i] == vals_cffi[i]
|
wemm/lib/python3.10/site-packages/numpy/random/_examples/cffi/parse.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def parse_distributions_h(ffi, inc_dir):
|
| 5 |
+
"""
|
| 6 |
+
Parse distributions.h located in inc_dir for CFFI, filling in the ffi.cdef
|
| 7 |
+
|
| 8 |
+
Read the function declarations without the "#define ..." macros that will
|
| 9 |
+
be filled in when loading the library.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
with open(os.path.join(inc_dir, 'random', 'bitgen.h')) as fid:
|
| 13 |
+
s = []
|
| 14 |
+
for line in fid:
|
| 15 |
+
# massage the include file
|
| 16 |
+
if line.strip().startswith('#'):
|
| 17 |
+
continue
|
| 18 |
+
s.append(line)
|
| 19 |
+
ffi.cdef('\n'.join(s))
|
| 20 |
+
|
| 21 |
+
with open(os.path.join(inc_dir, 'random', 'distributions.h')) as fid:
|
| 22 |
+
s = []
|
| 23 |
+
in_skip = 0
|
| 24 |
+
ignoring = False
|
| 25 |
+
for line in fid:
|
| 26 |
+
# check for and remove extern "C" guards
|
| 27 |
+
if ignoring:
|
| 28 |
+
if line.strip().startswith('#endif'):
|
| 29 |
+
ignoring = False
|
| 30 |
+
continue
|
| 31 |
+
if line.strip().startswith('#ifdef __cplusplus'):
|
| 32 |
+
ignoring = True
|
| 33 |
+
|
| 34 |
+
# massage the include file
|
| 35 |
+
if line.strip().startswith('#'):
|
| 36 |
+
continue
|
| 37 |
+
|
| 38 |
+
# skip any inlined function definition
|
| 39 |
+
# which starts with 'static NPY_INLINE xxx(...) {'
|
| 40 |
+
# and ends with a closing '}'
|
| 41 |
+
if line.strip().startswith('static NPY_INLINE'):
|
| 42 |
+
in_skip += line.count('{')
|
| 43 |
+
continue
|
| 44 |
+
elif in_skip > 0:
|
| 45 |
+
in_skip += line.count('{')
|
| 46 |
+
in_skip -= line.count('}')
|
| 47 |
+
continue
|
| 48 |
+
|
| 49 |
+
# replace defines with their value or remove them
|
| 50 |
+
line = line.replace('DECLDIR', '')
|
| 51 |
+
line = line.replace('NPY_INLINE', '')
|
| 52 |
+
line = line.replace('RAND_INT_TYPE', 'int64_t')
|
| 53 |
+
s.append(line)
|
| 54 |
+
ffi.cdef('\n'.join(s))
|
| 55 |
+
|
wemm/lib/python3.10/site-packages/numpy/random/_examples/cython/__pycache__/setup.cpython-310.pyc
ADDED
|
Binary file (1.11 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/random/_examples/cython/extending_distributions.pyx
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
#cython: language_level=3
|
| 3 |
+
"""
|
| 4 |
+
This file shows how the to use a BitGenerator to create a distribution.
|
| 5 |
+
"""
|
| 6 |
+
import numpy as np
|
| 7 |
+
cimport numpy as np
|
| 8 |
+
cimport cython
|
| 9 |
+
from cpython.pycapsule cimport PyCapsule_IsValid, PyCapsule_GetPointer
|
| 10 |
+
from libc.stdint cimport uint16_t, uint64_t
|
| 11 |
+
from numpy.random cimport bitgen_t
|
| 12 |
+
from numpy.random import PCG64
|
| 13 |
+
from numpy.random.c_distributions cimport (
|
| 14 |
+
random_standard_uniform_fill, random_standard_uniform_fill_f)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@cython.boundscheck(False)
|
| 18 |
+
@cython.wraparound(False)
|
| 19 |
+
def uniforms(Py_ssize_t n):
|
| 20 |
+
"""
|
| 21 |
+
Create an array of `n` uniformly distributed doubles.
|
| 22 |
+
A 'real' distribution would want to process the values into
|
| 23 |
+
some non-uniform distribution
|
| 24 |
+
"""
|
| 25 |
+
cdef Py_ssize_t i
|
| 26 |
+
cdef bitgen_t *rng
|
| 27 |
+
cdef const char *capsule_name = "BitGenerator"
|
| 28 |
+
cdef double[::1] random_values
|
| 29 |
+
|
| 30 |
+
x = PCG64()
|
| 31 |
+
capsule = x.capsule
|
| 32 |
+
# Optional check that the capsule if from a BitGenerator
|
| 33 |
+
if not PyCapsule_IsValid(capsule, capsule_name):
|
| 34 |
+
raise ValueError("Invalid pointer to anon_func_state")
|
| 35 |
+
# Cast the pointer
|
| 36 |
+
rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
|
| 37 |
+
random_values = np.empty(n, dtype='float64')
|
| 38 |
+
with x.lock, nogil:
|
| 39 |
+
for i in range(n):
|
| 40 |
+
# Call the function
|
| 41 |
+
random_values[i] = rng.next_double(rng.state)
|
| 42 |
+
randoms = np.asarray(random_values)
|
| 43 |
+
|
| 44 |
+
return randoms
|
| 45 |
+
|
| 46 |
+
# cython example 2
|
| 47 |
+
@cython.boundscheck(False)
|
| 48 |
+
@cython.wraparound(False)
|
| 49 |
+
def uint10_uniforms(Py_ssize_t n):
|
| 50 |
+
"""Uniform 10 bit integers stored as 16-bit unsigned integers"""
|
| 51 |
+
cdef Py_ssize_t i
|
| 52 |
+
cdef bitgen_t *rng
|
| 53 |
+
cdef const char *capsule_name = "BitGenerator"
|
| 54 |
+
cdef uint16_t[::1] random_values
|
| 55 |
+
cdef int bits_remaining
|
| 56 |
+
cdef int width = 10
|
| 57 |
+
cdef uint64_t buff, mask = 0x3FF
|
| 58 |
+
|
| 59 |
+
x = PCG64()
|
| 60 |
+
capsule = x.capsule
|
| 61 |
+
if not PyCapsule_IsValid(capsule, capsule_name):
|
| 62 |
+
raise ValueError("Invalid pointer to anon_func_state")
|
| 63 |
+
rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
|
| 64 |
+
random_values = np.empty(n, dtype='uint16')
|
| 65 |
+
# Best practice is to release GIL and acquire the lock
|
| 66 |
+
bits_remaining = 0
|
| 67 |
+
with x.lock, nogil:
|
| 68 |
+
for i in range(n):
|
| 69 |
+
if bits_remaining < width:
|
| 70 |
+
buff = rng.next_uint64(rng.state)
|
| 71 |
+
random_values[i] = buff & mask
|
| 72 |
+
buff >>= width
|
| 73 |
+
|
| 74 |
+
randoms = np.asarray(random_values)
|
| 75 |
+
return randoms
|
| 76 |
+
|
| 77 |
+
# cython example 3
|
| 78 |
+
def uniforms_ex(bit_generator, Py_ssize_t n, dtype=np.float64):
|
| 79 |
+
"""
|
| 80 |
+
Create an array of `n` uniformly distributed doubles via a "fill" function.
|
| 81 |
+
|
| 82 |
+
A 'real' distribution would want to process the values into
|
| 83 |
+
some non-uniform distribution
|
| 84 |
+
|
| 85 |
+
Parameters
|
| 86 |
+
----------
|
| 87 |
+
bit_generator: BitGenerator instance
|
| 88 |
+
n: int
|
| 89 |
+
Output vector length
|
| 90 |
+
dtype: {str, dtype}, optional
|
| 91 |
+
Desired dtype, either 'd' (or 'float64') or 'f' (or 'float32'). The
|
| 92 |
+
default dtype value is 'd'
|
| 93 |
+
"""
|
| 94 |
+
cdef Py_ssize_t i
|
| 95 |
+
cdef bitgen_t *rng
|
| 96 |
+
cdef const char *capsule_name = "BitGenerator"
|
| 97 |
+
cdef np.ndarray randoms
|
| 98 |
+
|
| 99 |
+
capsule = bit_generator.capsule
|
| 100 |
+
# Optional check that the capsule if from a BitGenerator
|
| 101 |
+
if not PyCapsule_IsValid(capsule, capsule_name):
|
| 102 |
+
raise ValueError("Invalid pointer to anon_func_state")
|
| 103 |
+
# Cast the pointer
|
| 104 |
+
rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
|
| 105 |
+
|
| 106 |
+
_dtype = np.dtype(dtype)
|
| 107 |
+
randoms = np.empty(n, dtype=_dtype)
|
| 108 |
+
if _dtype == np.float32:
|
| 109 |
+
with bit_generator.lock:
|
| 110 |
+
random_standard_uniform_fill_f(rng, n, <float*>np.PyArray_DATA(randoms))
|
| 111 |
+
elif _dtype == np.float64:
|
| 112 |
+
with bit_generator.lock:
|
| 113 |
+
random_standard_uniform_fill(rng, n, <double*>np.PyArray_DATA(randoms))
|
| 114 |
+
else:
|
| 115 |
+
raise TypeError('Unsupported dtype %r for random' % _dtype)
|
| 116 |
+
return randoms
|
| 117 |
+
|
wemm/lib/python3.10/site-packages/numpy/random/_examples/numba/__pycache__/extending.cpython-310.pyc
ADDED
|
Binary file (2.16 kB). View file
|
|
|
wemm/lib/python3.10/site-packages/numpy/random/_examples/numba/extending.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import numba as nb
|
| 3 |
+
|
| 4 |
+
from numpy.random import PCG64
|
| 5 |
+
from timeit import timeit
|
| 6 |
+
|
| 7 |
+
bit_gen = PCG64()
|
| 8 |
+
next_d = bit_gen.cffi.next_double
|
| 9 |
+
state_addr = bit_gen.cffi.state_address
|
| 10 |
+
|
| 11 |
+
def normals(n, state):
|
| 12 |
+
out = np.empty(n)
|
| 13 |
+
for i in range((n + 1) // 2):
|
| 14 |
+
x1 = 2.0 * next_d(state) - 1.0
|
| 15 |
+
x2 = 2.0 * next_d(state) - 1.0
|
| 16 |
+
r2 = x1 * x1 + x2 * x2
|
| 17 |
+
while r2 >= 1.0 or r2 == 0.0:
|
| 18 |
+
x1 = 2.0 * next_d(state) - 1.0
|
| 19 |
+
x2 = 2.0 * next_d(state) - 1.0
|
| 20 |
+
r2 = x1 * x1 + x2 * x2
|
| 21 |
+
f = np.sqrt(-2.0 * np.log(r2) / r2)
|
| 22 |
+
out[2 * i] = f * x1
|
| 23 |
+
if 2 * i + 1 < n:
|
| 24 |
+
out[2 * i + 1] = f * x2
|
| 25 |
+
return out
|
| 26 |
+
|
| 27 |
+
# Compile using Numba
|
| 28 |
+
normalsj = nb.jit(normals, nopython=True)
|
| 29 |
+
# Must use state address not state with numba
|
| 30 |
+
n = 10000
|
| 31 |
+
|
| 32 |
+
def numbacall():
|
| 33 |
+
return normalsj(n, state_addr)
|
| 34 |
+
|
| 35 |
+
rg = np.random.Generator(PCG64())
|
| 36 |
+
|
| 37 |
+
def numpycall():
|
| 38 |
+
return rg.normal(size=n)
|
| 39 |
+
|
| 40 |
+
# Check that the functions work
|
| 41 |
+
r1 = numbacall()
|
| 42 |
+
r2 = numpycall()
|
| 43 |
+
assert r1.shape == (n,)
|
| 44 |
+
assert r1.shape == r2.shape
|
| 45 |
+
|
| 46 |
+
t1 = timeit(numbacall, number=1000)
|
| 47 |
+
print(f'{t1:.2f} secs for {n} PCG64 (Numba/PCG64) gaussian randoms')
|
| 48 |
+
t2 = timeit(numpycall, number=1000)
|
| 49 |
+
print(f'{t2:.2f} secs for {n} PCG64 (NumPy/PCG64) gaussian randoms')
|
| 50 |
+
|
| 51 |
+
# example 2
|
| 52 |
+
|
| 53 |
+
next_u32 = bit_gen.ctypes.next_uint32
|
| 54 |
+
ctypes_state = bit_gen.ctypes.state
|
| 55 |
+
|
| 56 |
+
@nb.jit(nopython=True)
|
| 57 |
+
def bounded_uint(lb, ub, state):
|
| 58 |
+
mask = delta = ub - lb
|
| 59 |
+
mask |= mask >> 1
|
| 60 |
+
mask |= mask >> 2
|
| 61 |
+
mask |= mask >> 4
|
| 62 |
+
mask |= mask >> 8
|
| 63 |
+
mask |= mask >> 16
|
| 64 |
+
|
| 65 |
+
val = next_u32(state) & mask
|
| 66 |
+
while val > delta:
|
| 67 |
+
val = next_u32(state) & mask
|
| 68 |
+
|
| 69 |
+
return lb + val
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
print(bounded_uint(323, 2394691, ctypes_state.value))
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
@nb.jit(nopython=True)
|
| 76 |
+
def bounded_uints(lb, ub, n, state):
|
| 77 |
+
out = np.empty(n, dtype=np.uint32)
|
| 78 |
+
for i in range(n):
|
| 79 |
+
out[i] = bounded_uint(lb, ub, state)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
bounded_uints(323, 2394691, 10000000, ctypes_state.value)
|
| 83 |
+
|
| 84 |
+
|
wemm/lib/python3.10/site-packages/numpy/random/_generator.pyi
ADDED
|
@@ -0,0 +1,638 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Callable
|
| 2 |
+
from typing import Any, Union, overload, TypeVar, Literal
|
| 3 |
+
|
| 4 |
+
from numpy import (
|
| 5 |
+
bool_,
|
| 6 |
+
dtype,
|
| 7 |
+
float32,
|
| 8 |
+
float64,
|
| 9 |
+
int8,
|
| 10 |
+
int16,
|
| 11 |
+
int32,
|
| 12 |
+
int64,
|
| 13 |
+
int_,
|
| 14 |
+
ndarray,
|
| 15 |
+
uint,
|
| 16 |
+
uint8,
|
| 17 |
+
uint16,
|
| 18 |
+
uint32,
|
| 19 |
+
uint64,
|
| 20 |
+
)
|
| 21 |
+
from numpy.random import BitGenerator, SeedSequence
|
| 22 |
+
from numpy._typing import (
|
| 23 |
+
ArrayLike,
|
| 24 |
+
_ArrayLikeFloat_co,
|
| 25 |
+
_ArrayLikeInt_co,
|
| 26 |
+
_DoubleCodes,
|
| 27 |
+
_DTypeLikeBool,
|
| 28 |
+
_DTypeLikeInt,
|
| 29 |
+
_DTypeLikeUInt,
|
| 30 |
+
_Float32Codes,
|
| 31 |
+
_Float64Codes,
|
| 32 |
+
_Int8Codes,
|
| 33 |
+
_Int16Codes,
|
| 34 |
+
_Int32Codes,
|
| 35 |
+
_Int64Codes,
|
| 36 |
+
_IntCodes,
|
| 37 |
+
_ShapeLike,
|
| 38 |
+
_SingleCodes,
|
| 39 |
+
_SupportsDType,
|
| 40 |
+
_UInt8Codes,
|
| 41 |
+
_UInt16Codes,
|
| 42 |
+
_UInt32Codes,
|
| 43 |
+
_UInt64Codes,
|
| 44 |
+
_UIntCodes,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
_ArrayType = TypeVar("_ArrayType", bound=ndarray[Any, Any])
|
| 48 |
+
|
| 49 |
+
_DTypeLikeFloat32 = Union[
|
| 50 |
+
dtype[float32],
|
| 51 |
+
_SupportsDType[dtype[float32]],
|
| 52 |
+
type[float32],
|
| 53 |
+
_Float32Codes,
|
| 54 |
+
_SingleCodes,
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
_DTypeLikeFloat64 = Union[
|
| 58 |
+
dtype[float64],
|
| 59 |
+
_SupportsDType[dtype[float64]],
|
| 60 |
+
type[float],
|
| 61 |
+
type[float64],
|
| 62 |
+
_Float64Codes,
|
| 63 |
+
_DoubleCodes,
|
| 64 |
+
]
|
| 65 |
+
|
| 66 |
+
class Generator:
|
| 67 |
+
def __init__(self, bit_generator: BitGenerator) -> None: ...
|
| 68 |
+
def __repr__(self) -> str: ...
|
| 69 |
+
def __str__(self) -> str: ...
|
| 70 |
+
def __getstate__(self) -> dict[str, Any]: ...
|
| 71 |
+
def __setstate__(self, state: dict[str, Any]) -> None: ...
|
| 72 |
+
def __reduce__(self) -> tuple[Callable[[str], Generator], tuple[str], dict[str, Any]]: ...
|
| 73 |
+
@property
|
| 74 |
+
def bit_generator(self) -> BitGenerator: ...
|
| 75 |
+
def bytes(self, length: int) -> bytes: ...
|
| 76 |
+
@overload
|
| 77 |
+
def standard_normal( # type: ignore[misc]
|
| 78 |
+
self,
|
| 79 |
+
size: None = ...,
|
| 80 |
+
dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
|
| 81 |
+
out: None = ...,
|
| 82 |
+
) -> float: ...
|
| 83 |
+
@overload
|
| 84 |
+
def standard_normal( # type: ignore[misc]
|
| 85 |
+
self,
|
| 86 |
+
size: _ShapeLike = ...,
|
| 87 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 88 |
+
@overload
|
| 89 |
+
def standard_normal( # type: ignore[misc]
|
| 90 |
+
self,
|
| 91 |
+
*,
|
| 92 |
+
out: ndarray[Any, dtype[float64]] = ...,
|
| 93 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 94 |
+
@overload
|
| 95 |
+
def standard_normal( # type: ignore[misc]
|
| 96 |
+
self,
|
| 97 |
+
size: _ShapeLike = ...,
|
| 98 |
+
dtype: _DTypeLikeFloat32 = ...,
|
| 99 |
+
out: None | ndarray[Any, dtype[float32]] = ...,
|
| 100 |
+
) -> ndarray[Any, dtype[float32]]: ...
|
| 101 |
+
@overload
|
| 102 |
+
def standard_normal( # type: ignore[misc]
|
| 103 |
+
self,
|
| 104 |
+
size: _ShapeLike = ...,
|
| 105 |
+
dtype: _DTypeLikeFloat64 = ...,
|
| 106 |
+
out: None | ndarray[Any, dtype[float64]] = ...,
|
| 107 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 108 |
+
@overload
|
| 109 |
+
def permutation(self, x: int, axis: int = ...) -> ndarray[Any, dtype[int64]]: ...
|
| 110 |
+
@overload
|
| 111 |
+
def permutation(self, x: ArrayLike, axis: int = ...) -> ndarray[Any, Any]: ...
|
| 112 |
+
@overload
|
| 113 |
+
def standard_exponential( # type: ignore[misc]
|
| 114 |
+
self,
|
| 115 |
+
size: None = ...,
|
| 116 |
+
dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
|
| 117 |
+
method: Literal["zig", "inv"] = ...,
|
| 118 |
+
out: None = ...,
|
| 119 |
+
) -> float: ...
|
| 120 |
+
@overload
|
| 121 |
+
def standard_exponential(
|
| 122 |
+
self,
|
| 123 |
+
size: _ShapeLike = ...,
|
| 124 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 125 |
+
@overload
|
| 126 |
+
def standard_exponential(
|
| 127 |
+
self,
|
| 128 |
+
*,
|
| 129 |
+
out: ndarray[Any, dtype[float64]] = ...,
|
| 130 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 131 |
+
@overload
|
| 132 |
+
def standard_exponential(
|
| 133 |
+
self,
|
| 134 |
+
size: _ShapeLike = ...,
|
| 135 |
+
*,
|
| 136 |
+
method: Literal["zig", "inv"] = ...,
|
| 137 |
+
out: None | ndarray[Any, dtype[float64]] = ...,
|
| 138 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 139 |
+
@overload
|
| 140 |
+
def standard_exponential(
|
| 141 |
+
self,
|
| 142 |
+
size: _ShapeLike = ...,
|
| 143 |
+
dtype: _DTypeLikeFloat32 = ...,
|
| 144 |
+
method: Literal["zig", "inv"] = ...,
|
| 145 |
+
out: None | ndarray[Any, dtype[float32]] = ...,
|
| 146 |
+
) -> ndarray[Any, dtype[float32]]: ...
|
| 147 |
+
@overload
|
| 148 |
+
def standard_exponential(
|
| 149 |
+
self,
|
| 150 |
+
size: _ShapeLike = ...,
|
| 151 |
+
dtype: _DTypeLikeFloat64 = ...,
|
| 152 |
+
method: Literal["zig", "inv"] = ...,
|
| 153 |
+
out: None | ndarray[Any, dtype[float64]] = ...,
|
| 154 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 155 |
+
@overload
|
| 156 |
+
def random( # type: ignore[misc]
|
| 157 |
+
self,
|
| 158 |
+
size: None = ...,
|
| 159 |
+
dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
|
| 160 |
+
out: None = ...,
|
| 161 |
+
) -> float: ...
|
| 162 |
+
@overload
|
| 163 |
+
def random(
|
| 164 |
+
self,
|
| 165 |
+
*,
|
| 166 |
+
out: ndarray[Any, dtype[float64]] = ...,
|
| 167 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 168 |
+
@overload
|
| 169 |
+
def random(
|
| 170 |
+
self,
|
| 171 |
+
size: _ShapeLike = ...,
|
| 172 |
+
*,
|
| 173 |
+
out: None | ndarray[Any, dtype[float64]] = ...,
|
| 174 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 175 |
+
@overload
|
| 176 |
+
def random(
|
| 177 |
+
self,
|
| 178 |
+
size: _ShapeLike = ...,
|
| 179 |
+
dtype: _DTypeLikeFloat32 = ...,
|
| 180 |
+
out: None | ndarray[Any, dtype[float32]] = ...,
|
| 181 |
+
) -> ndarray[Any, dtype[float32]]: ...
|
| 182 |
+
@overload
|
| 183 |
+
def random(
|
| 184 |
+
self,
|
| 185 |
+
size: _ShapeLike = ...,
|
| 186 |
+
dtype: _DTypeLikeFloat64 = ...,
|
| 187 |
+
out: None | ndarray[Any, dtype[float64]] = ...,
|
| 188 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 189 |
+
@overload
|
| 190 |
+
def beta(self, a: float, b: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 191 |
+
@overload
|
| 192 |
+
def beta(
|
| 193 |
+
self, a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 194 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 195 |
+
@overload
|
| 196 |
+
def exponential(self, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 197 |
+
@overload
|
| 198 |
+
def exponential(
|
| 199 |
+
self, scale: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
|
| 200 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 201 |
+
@overload
|
| 202 |
+
def integers( # type: ignore[misc]
|
| 203 |
+
self,
|
| 204 |
+
low: int,
|
| 205 |
+
high: None | int = ...,
|
| 206 |
+
) -> int: ...
|
| 207 |
+
@overload
|
| 208 |
+
def integers( # type: ignore[misc]
|
| 209 |
+
self,
|
| 210 |
+
low: int,
|
| 211 |
+
high: None | int = ...,
|
| 212 |
+
size: None = ...,
|
| 213 |
+
dtype: _DTypeLikeBool = ...,
|
| 214 |
+
endpoint: bool = ...,
|
| 215 |
+
) -> bool: ...
|
| 216 |
+
@overload
|
| 217 |
+
def integers( # type: ignore[misc]
|
| 218 |
+
self,
|
| 219 |
+
low: int,
|
| 220 |
+
high: None | int = ...,
|
| 221 |
+
size: None = ...,
|
| 222 |
+
dtype: _DTypeLikeInt | _DTypeLikeUInt = ...,
|
| 223 |
+
endpoint: bool = ...,
|
| 224 |
+
) -> int: ...
|
| 225 |
+
@overload
|
| 226 |
+
def integers( # type: ignore[misc]
|
| 227 |
+
self,
|
| 228 |
+
low: _ArrayLikeInt_co,
|
| 229 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 230 |
+
size: None | _ShapeLike = ...,
|
| 231 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 232 |
+
@overload
|
| 233 |
+
def integers( # type: ignore[misc]
|
| 234 |
+
self,
|
| 235 |
+
low: _ArrayLikeInt_co,
|
| 236 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 237 |
+
size: None | _ShapeLike = ...,
|
| 238 |
+
dtype: _DTypeLikeBool = ...,
|
| 239 |
+
endpoint: bool = ...,
|
| 240 |
+
) -> ndarray[Any, dtype[bool_]]: ...
|
| 241 |
+
@overload
|
| 242 |
+
def integers( # type: ignore[misc]
|
| 243 |
+
self,
|
| 244 |
+
low: _ArrayLikeInt_co,
|
| 245 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 246 |
+
size: None | _ShapeLike = ...,
|
| 247 |
+
dtype: dtype[int8] | type[int8] | _Int8Codes | _SupportsDType[dtype[int8]] = ...,
|
| 248 |
+
endpoint: bool = ...,
|
| 249 |
+
) -> ndarray[Any, dtype[int8]]: ...
|
| 250 |
+
@overload
|
| 251 |
+
def integers( # type: ignore[misc]
|
| 252 |
+
self,
|
| 253 |
+
low: _ArrayLikeInt_co,
|
| 254 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 255 |
+
size: None | _ShapeLike = ...,
|
| 256 |
+
dtype: dtype[int16] | type[int16] | _Int16Codes | _SupportsDType[dtype[int16]] = ...,
|
| 257 |
+
endpoint: bool = ...,
|
| 258 |
+
) -> ndarray[Any, dtype[int16]]: ...
|
| 259 |
+
@overload
|
| 260 |
+
def integers( # type: ignore[misc]
|
| 261 |
+
self,
|
| 262 |
+
low: _ArrayLikeInt_co,
|
| 263 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 264 |
+
size: None | _ShapeLike = ...,
|
| 265 |
+
dtype: dtype[int32] | type[int32] | _Int32Codes | _SupportsDType[dtype[int32]] = ...,
|
| 266 |
+
endpoint: bool = ...,
|
| 267 |
+
) -> ndarray[Any, dtype[int32]]: ...
|
| 268 |
+
@overload
|
| 269 |
+
def integers( # type: ignore[misc]
|
| 270 |
+
self,
|
| 271 |
+
low: _ArrayLikeInt_co,
|
| 272 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 273 |
+
size: None | _ShapeLike = ...,
|
| 274 |
+
dtype: None | dtype[int64] | type[int64] | _Int64Codes | _SupportsDType[dtype[int64]] = ...,
|
| 275 |
+
endpoint: bool = ...,
|
| 276 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 277 |
+
@overload
|
| 278 |
+
def integers( # type: ignore[misc]
|
| 279 |
+
self,
|
| 280 |
+
low: _ArrayLikeInt_co,
|
| 281 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 282 |
+
size: None | _ShapeLike = ...,
|
| 283 |
+
dtype: dtype[uint8] | type[uint8] | _UInt8Codes | _SupportsDType[dtype[uint8]] = ...,
|
| 284 |
+
endpoint: bool = ...,
|
| 285 |
+
) -> ndarray[Any, dtype[uint8]]: ...
|
| 286 |
+
@overload
|
| 287 |
+
def integers( # type: ignore[misc]
|
| 288 |
+
self,
|
| 289 |
+
low: _ArrayLikeInt_co,
|
| 290 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 291 |
+
size: None | _ShapeLike = ...,
|
| 292 |
+
dtype: dtype[uint16] | type[uint16] | _UInt16Codes | _SupportsDType[dtype[uint16]] = ...,
|
| 293 |
+
endpoint: bool = ...,
|
| 294 |
+
) -> ndarray[Any, dtype[uint16]]: ...
|
| 295 |
+
@overload
|
| 296 |
+
def integers( # type: ignore[misc]
|
| 297 |
+
self,
|
| 298 |
+
low: _ArrayLikeInt_co,
|
| 299 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 300 |
+
size: None | _ShapeLike = ...,
|
| 301 |
+
dtype: dtype[uint32] | type[uint32] | _UInt32Codes | _SupportsDType[dtype[uint32]] = ...,
|
| 302 |
+
endpoint: bool = ...,
|
| 303 |
+
) -> ndarray[Any, dtype[uint32]]: ...
|
| 304 |
+
@overload
|
| 305 |
+
def integers( # type: ignore[misc]
|
| 306 |
+
self,
|
| 307 |
+
low: _ArrayLikeInt_co,
|
| 308 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 309 |
+
size: None | _ShapeLike = ...,
|
| 310 |
+
dtype: dtype[uint64] | type[uint64] | _UInt64Codes | _SupportsDType[dtype[uint64]] = ...,
|
| 311 |
+
endpoint: bool = ...,
|
| 312 |
+
) -> ndarray[Any, dtype[uint64]]: ...
|
| 313 |
+
@overload
|
| 314 |
+
def integers( # type: ignore[misc]
|
| 315 |
+
self,
|
| 316 |
+
low: _ArrayLikeInt_co,
|
| 317 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 318 |
+
size: None | _ShapeLike = ...,
|
| 319 |
+
dtype: dtype[int_] | type[int] | type[int_] | _IntCodes | _SupportsDType[dtype[int_]] = ...,
|
| 320 |
+
endpoint: bool = ...,
|
| 321 |
+
) -> ndarray[Any, dtype[int_]]: ...
|
| 322 |
+
@overload
|
| 323 |
+
def integers( # type: ignore[misc]
|
| 324 |
+
self,
|
| 325 |
+
low: _ArrayLikeInt_co,
|
| 326 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 327 |
+
size: None | _ShapeLike = ...,
|
| 328 |
+
dtype: dtype[uint] | type[uint] | _UIntCodes | _SupportsDType[dtype[uint]] = ...,
|
| 329 |
+
endpoint: bool = ...,
|
| 330 |
+
) -> ndarray[Any, dtype[uint]]: ...
|
| 331 |
+
# TODO: Use a TypeVar _T here to get away from Any output? Should be int->ndarray[Any,dtype[int64]], ArrayLike[_T] -> _T | ndarray[Any,Any]
|
| 332 |
+
@overload
|
| 333 |
+
def choice(
|
| 334 |
+
self,
|
| 335 |
+
a: int,
|
| 336 |
+
size: None = ...,
|
| 337 |
+
replace: bool = ...,
|
| 338 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 339 |
+
axis: int = ...,
|
| 340 |
+
shuffle: bool = ...,
|
| 341 |
+
) -> int: ...
|
| 342 |
+
@overload
|
| 343 |
+
def choice(
|
| 344 |
+
self,
|
| 345 |
+
a: int,
|
| 346 |
+
size: _ShapeLike = ...,
|
| 347 |
+
replace: bool = ...,
|
| 348 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 349 |
+
axis: int = ...,
|
| 350 |
+
shuffle: bool = ...,
|
| 351 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 352 |
+
@overload
|
| 353 |
+
def choice(
|
| 354 |
+
self,
|
| 355 |
+
a: ArrayLike,
|
| 356 |
+
size: None = ...,
|
| 357 |
+
replace: bool = ...,
|
| 358 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 359 |
+
axis: int = ...,
|
| 360 |
+
shuffle: bool = ...,
|
| 361 |
+
) -> Any: ...
|
| 362 |
+
@overload
|
| 363 |
+
def choice(
|
| 364 |
+
self,
|
| 365 |
+
a: ArrayLike,
|
| 366 |
+
size: _ShapeLike = ...,
|
| 367 |
+
replace: bool = ...,
|
| 368 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 369 |
+
axis: int = ...,
|
| 370 |
+
shuffle: bool = ...,
|
| 371 |
+
) -> ndarray[Any, Any]: ...
|
| 372 |
+
@overload
|
| 373 |
+
def uniform(self, low: float = ..., high: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 374 |
+
@overload
|
| 375 |
+
def uniform(
|
| 376 |
+
self,
|
| 377 |
+
low: _ArrayLikeFloat_co = ...,
|
| 378 |
+
high: _ArrayLikeFloat_co = ...,
|
| 379 |
+
size: None | _ShapeLike = ...,
|
| 380 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 381 |
+
@overload
|
| 382 |
+
def normal(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 383 |
+
@overload
|
| 384 |
+
def normal(
|
| 385 |
+
self,
|
| 386 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 387 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 388 |
+
size: None | _ShapeLike = ...,
|
| 389 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 390 |
+
@overload
|
| 391 |
+
def standard_gamma( # type: ignore[misc]
|
| 392 |
+
self,
|
| 393 |
+
shape: float,
|
| 394 |
+
size: None = ...,
|
| 395 |
+
dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
|
| 396 |
+
out: None = ...,
|
| 397 |
+
) -> float: ...
|
| 398 |
+
@overload
|
| 399 |
+
def standard_gamma(
|
| 400 |
+
self,
|
| 401 |
+
shape: _ArrayLikeFloat_co,
|
| 402 |
+
size: None | _ShapeLike = ...,
|
| 403 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 404 |
+
@overload
|
| 405 |
+
def standard_gamma(
|
| 406 |
+
self,
|
| 407 |
+
shape: _ArrayLikeFloat_co,
|
| 408 |
+
*,
|
| 409 |
+
out: ndarray[Any, dtype[float64]] = ...,
|
| 410 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 411 |
+
@overload
|
| 412 |
+
def standard_gamma(
|
| 413 |
+
self,
|
| 414 |
+
shape: _ArrayLikeFloat_co,
|
| 415 |
+
size: None | _ShapeLike = ...,
|
| 416 |
+
dtype: _DTypeLikeFloat32 = ...,
|
| 417 |
+
out: None | ndarray[Any, dtype[float32]] = ...,
|
| 418 |
+
) -> ndarray[Any, dtype[float32]]: ...
|
| 419 |
+
@overload
|
| 420 |
+
def standard_gamma(
|
| 421 |
+
self,
|
| 422 |
+
shape: _ArrayLikeFloat_co,
|
| 423 |
+
size: None | _ShapeLike = ...,
|
| 424 |
+
dtype: _DTypeLikeFloat64 = ...,
|
| 425 |
+
out: None | ndarray[Any, dtype[float64]] = ...,
|
| 426 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 427 |
+
@overload
|
| 428 |
+
def gamma(self, shape: float, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 429 |
+
@overload
|
| 430 |
+
def gamma(
|
| 431 |
+
self,
|
| 432 |
+
shape: _ArrayLikeFloat_co,
|
| 433 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 434 |
+
size: None | _ShapeLike = ...,
|
| 435 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 436 |
+
@overload
|
| 437 |
+
def f(self, dfnum: float, dfden: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 438 |
+
@overload
|
| 439 |
+
def f(
|
| 440 |
+
self, dfnum: _ArrayLikeFloat_co, dfden: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 441 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 442 |
+
@overload
|
| 443 |
+
def noncentral_f(self, dfnum: float, dfden: float, nonc: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 444 |
+
@overload
|
| 445 |
+
def noncentral_f(
|
| 446 |
+
self,
|
| 447 |
+
dfnum: _ArrayLikeFloat_co,
|
| 448 |
+
dfden: _ArrayLikeFloat_co,
|
| 449 |
+
nonc: _ArrayLikeFloat_co,
|
| 450 |
+
size: None | _ShapeLike = ...,
|
| 451 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 452 |
+
@overload
|
| 453 |
+
def chisquare(self, df: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 454 |
+
@overload
|
| 455 |
+
def chisquare(
|
| 456 |
+
self, df: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 457 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 458 |
+
@overload
|
| 459 |
+
def noncentral_chisquare(self, df: float, nonc: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 460 |
+
@overload
|
| 461 |
+
def noncentral_chisquare(
|
| 462 |
+
self, df: _ArrayLikeFloat_co, nonc: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 463 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 464 |
+
@overload
|
| 465 |
+
def standard_t(self, df: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 466 |
+
@overload
|
| 467 |
+
def standard_t(
|
| 468 |
+
self, df: _ArrayLikeFloat_co, size: None = ...
|
| 469 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 470 |
+
@overload
|
| 471 |
+
def standard_t(
|
| 472 |
+
self, df: _ArrayLikeFloat_co, size: _ShapeLike = ...
|
| 473 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 474 |
+
@overload
|
| 475 |
+
def vonmises(self, mu: float, kappa: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 476 |
+
@overload
|
| 477 |
+
def vonmises(
|
| 478 |
+
self, mu: _ArrayLikeFloat_co, kappa: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 479 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 480 |
+
@overload
|
| 481 |
+
def pareto(self, a: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 482 |
+
@overload
|
| 483 |
+
def pareto(
|
| 484 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 485 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 486 |
+
@overload
|
| 487 |
+
def weibull(self, a: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 488 |
+
@overload
|
| 489 |
+
def weibull(
|
| 490 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 491 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 492 |
+
@overload
|
| 493 |
+
def power(self, a: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 494 |
+
@overload
|
| 495 |
+
def power(
|
| 496 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 497 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 498 |
+
@overload
|
| 499 |
+
def standard_cauchy(self, size: None = ...) -> float: ... # type: ignore[misc]
|
| 500 |
+
@overload
|
| 501 |
+
def standard_cauchy(self, size: _ShapeLike = ...) -> ndarray[Any, dtype[float64]]: ...
|
| 502 |
+
@overload
|
| 503 |
+
def laplace(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 504 |
+
@overload
|
| 505 |
+
def laplace(
|
| 506 |
+
self,
|
| 507 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 508 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 509 |
+
size: None | _ShapeLike = ...,
|
| 510 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 511 |
+
@overload
|
| 512 |
+
def gumbel(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 513 |
+
@overload
|
| 514 |
+
def gumbel(
|
| 515 |
+
self,
|
| 516 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 517 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 518 |
+
size: None | _ShapeLike = ...,
|
| 519 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 520 |
+
@overload
|
| 521 |
+
def logistic(self, loc: float = ..., scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 522 |
+
@overload
|
| 523 |
+
def logistic(
|
| 524 |
+
self,
|
| 525 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 526 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 527 |
+
size: None | _ShapeLike = ...,
|
| 528 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 529 |
+
@overload
|
| 530 |
+
def lognormal(self, mean: float = ..., sigma: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 531 |
+
@overload
|
| 532 |
+
def lognormal(
|
| 533 |
+
self,
|
| 534 |
+
mean: _ArrayLikeFloat_co = ...,
|
| 535 |
+
sigma: _ArrayLikeFloat_co = ...,
|
| 536 |
+
size: None | _ShapeLike = ...,
|
| 537 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 538 |
+
@overload
|
| 539 |
+
def rayleigh(self, scale: float = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 540 |
+
@overload
|
| 541 |
+
def rayleigh(
|
| 542 |
+
self, scale: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
|
| 543 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 544 |
+
@overload
|
| 545 |
+
def wald(self, mean: float, scale: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 546 |
+
@overload
|
| 547 |
+
def wald(
|
| 548 |
+
self, mean: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 549 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 550 |
+
@overload
|
| 551 |
+
def triangular(self, left: float, mode: float, right: float, size: None = ...) -> float: ... # type: ignore[misc]
|
| 552 |
+
@overload
|
| 553 |
+
def triangular(
|
| 554 |
+
self,
|
| 555 |
+
left: _ArrayLikeFloat_co,
|
| 556 |
+
mode: _ArrayLikeFloat_co,
|
| 557 |
+
right: _ArrayLikeFloat_co,
|
| 558 |
+
size: None | _ShapeLike = ...,
|
| 559 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 560 |
+
@overload
|
| 561 |
+
def binomial(self, n: int, p: float, size: None = ...) -> int: ... # type: ignore[misc]
|
| 562 |
+
@overload
|
| 563 |
+
def binomial(
|
| 564 |
+
self, n: _ArrayLikeInt_co, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 565 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 566 |
+
@overload
|
| 567 |
+
def negative_binomial(self, n: float, p: float, size: None = ...) -> int: ... # type: ignore[misc]
|
| 568 |
+
@overload
|
| 569 |
+
def negative_binomial(
|
| 570 |
+
self, n: _ArrayLikeFloat_co, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 571 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 572 |
+
@overload
|
| 573 |
+
def poisson(self, lam: float = ..., size: None = ...) -> int: ... # type: ignore[misc]
|
| 574 |
+
@overload
|
| 575 |
+
def poisson(
|
| 576 |
+
self, lam: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
|
| 577 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 578 |
+
@overload
|
| 579 |
+
def zipf(self, a: float, size: None = ...) -> int: ... # type: ignore[misc]
|
| 580 |
+
@overload
|
| 581 |
+
def zipf(
|
| 582 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 583 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 584 |
+
@overload
|
| 585 |
+
def geometric(self, p: float, size: None = ...) -> int: ... # type: ignore[misc]
|
| 586 |
+
@overload
|
| 587 |
+
def geometric(
|
| 588 |
+
self, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 589 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 590 |
+
@overload
|
| 591 |
+
def hypergeometric(self, ngood: int, nbad: int, nsample: int, size: None = ...) -> int: ... # type: ignore[misc]
|
| 592 |
+
@overload
|
| 593 |
+
def hypergeometric(
|
| 594 |
+
self,
|
| 595 |
+
ngood: _ArrayLikeInt_co,
|
| 596 |
+
nbad: _ArrayLikeInt_co,
|
| 597 |
+
nsample: _ArrayLikeInt_co,
|
| 598 |
+
size: None | _ShapeLike = ...,
|
| 599 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 600 |
+
@overload
|
| 601 |
+
def logseries(self, p: float, size: None = ...) -> int: ... # type: ignore[misc]
|
| 602 |
+
@overload
|
| 603 |
+
def logseries(
|
| 604 |
+
self, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 605 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 606 |
+
def multivariate_normal(
|
| 607 |
+
self,
|
| 608 |
+
mean: _ArrayLikeFloat_co,
|
| 609 |
+
cov: _ArrayLikeFloat_co,
|
| 610 |
+
size: None | _ShapeLike = ...,
|
| 611 |
+
check_valid: Literal["warn", "raise", "ignore"] = ...,
|
| 612 |
+
tol: float = ...,
|
| 613 |
+
*,
|
| 614 |
+
method: Literal["svd", "eigh", "cholesky"] = ...,
|
| 615 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 616 |
+
def multinomial(
|
| 617 |
+
self, n: _ArrayLikeInt_co,
|
| 618 |
+
pvals: _ArrayLikeFloat_co,
|
| 619 |
+
size: None | _ShapeLike = ...
|
| 620 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 621 |
+
def multivariate_hypergeometric(
|
| 622 |
+
self,
|
| 623 |
+
colors: _ArrayLikeInt_co,
|
| 624 |
+
nsample: int,
|
| 625 |
+
size: None | _ShapeLike = ...,
|
| 626 |
+
method: Literal["marginals", "count"] = ...,
|
| 627 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 628 |
+
def dirichlet(
|
| 629 |
+
self, alpha: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 630 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 631 |
+
def permuted(
|
| 632 |
+
self, x: ArrayLike, *, axis: None | int = ..., out: None | ndarray[Any, Any] = ...
|
| 633 |
+
) -> ndarray[Any, Any]: ...
|
| 634 |
+
def shuffle(self, x: ArrayLike, axis: int = ...) -> None: ...
|
| 635 |
+
|
| 636 |
+
def default_rng(
|
| 637 |
+
seed: None | _ArrayLikeInt_co | SeedSequence | BitGenerator | Generator = ...
|
| 638 |
+
) -> Generator: ...
|
wemm/lib/python3.10/site-packages/numpy/random/_mt19937.pyi
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, TypedDict
|
| 2 |
+
|
| 3 |
+
from numpy import dtype, ndarray, uint32
|
| 4 |
+
from numpy.random.bit_generator import BitGenerator, SeedSequence
|
| 5 |
+
from numpy._typing import _ArrayLikeInt_co
|
| 6 |
+
|
| 7 |
+
class _MT19937Internal(TypedDict):
|
| 8 |
+
key: ndarray[Any, dtype[uint32]]
|
| 9 |
+
pos: int
|
| 10 |
+
|
| 11 |
+
class _MT19937State(TypedDict):
|
| 12 |
+
bit_generator: str
|
| 13 |
+
state: _MT19937Internal
|
| 14 |
+
|
| 15 |
+
class MT19937(BitGenerator):
|
| 16 |
+
def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
|
| 17 |
+
def _legacy_seeding(self, seed: _ArrayLikeInt_co) -> None: ...
|
| 18 |
+
def jumped(self, jumps: int = ...) -> MT19937: ...
|
| 19 |
+
@property
|
| 20 |
+
def state(self) -> _MT19937State: ...
|
| 21 |
+
@state.setter
|
| 22 |
+
def state(self, value: _MT19937State) -> None: ...
|
wemm/lib/python3.10/site-packages/numpy/random/_pcg64.pyi
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import TypedDict
|
| 2 |
+
|
| 3 |
+
from numpy.random.bit_generator import BitGenerator, SeedSequence
|
| 4 |
+
from numpy._typing import _ArrayLikeInt_co
|
| 5 |
+
|
| 6 |
+
class _PCG64Internal(TypedDict):
|
| 7 |
+
state: int
|
| 8 |
+
inc: int
|
| 9 |
+
|
| 10 |
+
class _PCG64State(TypedDict):
|
| 11 |
+
bit_generator: str
|
| 12 |
+
state: _PCG64Internal
|
| 13 |
+
has_uint32: int
|
| 14 |
+
uinteger: int
|
| 15 |
+
|
| 16 |
+
class PCG64(BitGenerator):
|
| 17 |
+
def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
|
| 18 |
+
def jumped(self, jumps: int = ...) -> PCG64: ...
|
| 19 |
+
@property
|
| 20 |
+
def state(
|
| 21 |
+
self,
|
| 22 |
+
) -> _PCG64State: ...
|
| 23 |
+
@state.setter
|
| 24 |
+
def state(
|
| 25 |
+
self,
|
| 26 |
+
value: _PCG64State,
|
| 27 |
+
) -> None: ...
|
| 28 |
+
def advance(self, delta: int) -> PCG64: ...
|
| 29 |
+
|
| 30 |
+
class PCG64DXSM(BitGenerator):
|
| 31 |
+
def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
|
| 32 |
+
def jumped(self, jumps: int = ...) -> PCG64DXSM: ...
|
| 33 |
+
@property
|
| 34 |
+
def state(
|
| 35 |
+
self,
|
| 36 |
+
) -> _PCG64State: ...
|
| 37 |
+
@state.setter
|
| 38 |
+
def state(
|
| 39 |
+
self,
|
| 40 |
+
value: _PCG64State,
|
| 41 |
+
) -> None: ...
|
| 42 |
+
def advance(self, delta: int) -> PCG64DXSM: ...
|
wemm/lib/python3.10/site-packages/numpy/random/_philox.pyi
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, TypedDict
|
| 2 |
+
|
| 3 |
+
from numpy import dtype, ndarray, uint64
|
| 4 |
+
from numpy.random.bit_generator import BitGenerator, SeedSequence
|
| 5 |
+
from numpy._typing import _ArrayLikeInt_co
|
| 6 |
+
|
| 7 |
+
class _PhiloxInternal(TypedDict):
|
| 8 |
+
counter: ndarray[Any, dtype[uint64]]
|
| 9 |
+
key: ndarray[Any, dtype[uint64]]
|
| 10 |
+
|
| 11 |
+
class _PhiloxState(TypedDict):
|
| 12 |
+
bit_generator: str
|
| 13 |
+
state: _PhiloxInternal
|
| 14 |
+
buffer: ndarray[Any, dtype[uint64]]
|
| 15 |
+
buffer_pos: int
|
| 16 |
+
has_uint32: int
|
| 17 |
+
uinteger: int
|
| 18 |
+
|
| 19 |
+
class Philox(BitGenerator):
|
| 20 |
+
def __init__(
|
| 21 |
+
self,
|
| 22 |
+
seed: None | _ArrayLikeInt_co | SeedSequence = ...,
|
| 23 |
+
counter: None | _ArrayLikeInt_co = ...,
|
| 24 |
+
key: None | _ArrayLikeInt_co = ...,
|
| 25 |
+
) -> None: ...
|
| 26 |
+
@property
|
| 27 |
+
def state(
|
| 28 |
+
self,
|
| 29 |
+
) -> _PhiloxState: ...
|
| 30 |
+
@state.setter
|
| 31 |
+
def state(
|
| 32 |
+
self,
|
| 33 |
+
value: _PhiloxState,
|
| 34 |
+
) -> None: ...
|
| 35 |
+
def jumped(self, jumps: int = ...) -> Philox: ...
|
| 36 |
+
def advance(self, delta: int) -> Philox: ...
|
wemm/lib/python3.10/site-packages/numpy/random/_pickle.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .mtrand import RandomState
|
| 2 |
+
from ._philox import Philox
|
| 3 |
+
from ._pcg64 import PCG64, PCG64DXSM
|
| 4 |
+
from ._sfc64 import SFC64
|
| 5 |
+
|
| 6 |
+
from ._generator import Generator
|
| 7 |
+
from ._mt19937 import MT19937
|
| 8 |
+
|
| 9 |
+
BitGenerators = {'MT19937': MT19937,
|
| 10 |
+
'PCG64': PCG64,
|
| 11 |
+
'PCG64DXSM': PCG64DXSM,
|
| 12 |
+
'Philox': Philox,
|
| 13 |
+
'SFC64': SFC64,
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def __generator_ctor(bit_generator_name='MT19937'):
|
| 18 |
+
"""
|
| 19 |
+
Pickling helper function that returns a Generator object
|
| 20 |
+
|
| 21 |
+
Parameters
|
| 22 |
+
----------
|
| 23 |
+
bit_generator_name : str
|
| 24 |
+
String containing the core BitGenerator
|
| 25 |
+
|
| 26 |
+
Returns
|
| 27 |
+
-------
|
| 28 |
+
rg : Generator
|
| 29 |
+
Generator using the named core BitGenerator
|
| 30 |
+
"""
|
| 31 |
+
if bit_generator_name in BitGenerators:
|
| 32 |
+
bit_generator = BitGenerators[bit_generator_name]
|
| 33 |
+
else:
|
| 34 |
+
raise ValueError(str(bit_generator_name) + ' is not a known '
|
| 35 |
+
'BitGenerator module.')
|
| 36 |
+
|
| 37 |
+
return Generator(bit_generator())
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def __bit_generator_ctor(bit_generator_name='MT19937'):
|
| 41 |
+
"""
|
| 42 |
+
Pickling helper function that returns a bit generator object
|
| 43 |
+
|
| 44 |
+
Parameters
|
| 45 |
+
----------
|
| 46 |
+
bit_generator_name : str
|
| 47 |
+
String containing the name of the BitGenerator
|
| 48 |
+
|
| 49 |
+
Returns
|
| 50 |
+
-------
|
| 51 |
+
bit_generator : BitGenerator
|
| 52 |
+
BitGenerator instance
|
| 53 |
+
"""
|
| 54 |
+
if bit_generator_name in BitGenerators:
|
| 55 |
+
bit_generator = BitGenerators[bit_generator_name]
|
| 56 |
+
else:
|
| 57 |
+
raise ValueError(str(bit_generator_name) + ' is not a known '
|
| 58 |
+
'BitGenerator module.')
|
| 59 |
+
|
| 60 |
+
return bit_generator()
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def __randomstate_ctor(bit_generator_name='MT19937'):
|
| 64 |
+
"""
|
| 65 |
+
Pickling helper function that returns a legacy RandomState-like object
|
| 66 |
+
|
| 67 |
+
Parameters
|
| 68 |
+
----------
|
| 69 |
+
bit_generator_name : str
|
| 70 |
+
String containing the core BitGenerator
|
| 71 |
+
|
| 72 |
+
Returns
|
| 73 |
+
-------
|
| 74 |
+
rs : RandomState
|
| 75 |
+
Legacy RandomState using the named core BitGenerator
|
| 76 |
+
"""
|
| 77 |
+
if bit_generator_name in BitGenerators:
|
| 78 |
+
bit_generator = BitGenerators[bit_generator_name]
|
| 79 |
+
else:
|
| 80 |
+
raise ValueError(str(bit_generator_name) + ' is not a known '
|
| 81 |
+
'BitGenerator module.')
|
| 82 |
+
|
| 83 |
+
return RandomState(bit_generator())
|