Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +4 -0
- mgm/lib/python3.10/site-packages/gradio_client-0.2.9.dist-info/INSTALLER +1 -0
- mgm/lib/python3.10/site-packages/gradio_client-0.2.9.dist-info/METADATA +178 -0
- mgm/lib/python3.10/site-packages/gradio_client-0.2.9.dist-info/REQUESTED +0 -0
- mgm/lib/python3.10/site-packages/numpy/array_api/__init__.py +387 -0
- mgm/lib/python3.10/site-packages/numpy/array_api/_creation_functions.py +351 -0
- mgm/lib/python3.10/site-packages/numpy/array_api/_data_type_functions.py +197 -0
- mgm/lib/python3.10/site-packages/numpy/array_api/_dtypes.py +180 -0
- mgm/lib/python3.10/site-packages/numpy/array_api/_indexing_functions.py +20 -0
- mgm/lib/python3.10/site-packages/numpy/array_api/_sorting_functions.py +54 -0
- mgm/lib/python3.10/site-packages/numpy/array_api/_typing.py +76 -0
- mgm/lib/python3.10/site-packages/numpy/compat/__pycache__/__init__.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/compat/__pycache__/py3k.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/compat/tests/test_compat.py +22 -0
- mgm/lib/python3.10/site-packages/numpy/doc/__pycache__/ufuncs.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/LICENSE.md +71 -0
- mgm/lib/python3.10/site-packages/numpy/random/__init__.pxd +14 -0
- mgm/lib/python3.10/site-packages/numpy/random/__init__.py +215 -0
- mgm/lib/python3.10/site-packages/numpy/random/__pycache__/__init__.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/__pycache__/_pickle.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/_bounded_integers.cpython-310-x86_64-linux-gnu.so +3 -0
- mgm/lib/python3.10/site-packages/numpy/random/_bounded_integers.pxd +29 -0
- mgm/lib/python3.10/site-packages/numpy/random/_common.pxd +106 -0
- mgm/lib/python3.10/site-packages/numpy/random/_examples/cffi/__pycache__/extending.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/_examples/cffi/__pycache__/parse.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/_examples/cffi/extending.py +40 -0
- mgm/lib/python3.10/site-packages/numpy/random/_examples/cffi/parse.py +54 -0
- mgm/lib/python3.10/site-packages/numpy/random/_examples/cython/extending.pyx +78 -0
- mgm/lib/python3.10/site-packages/numpy/random/_examples/cython/extending_distributions.pyx +117 -0
- mgm/lib/python3.10/site-packages/numpy/random/_examples/cython/meson.build +45 -0
- mgm/lib/python3.10/site-packages/numpy/random/_examples/numba/__pycache__/extending.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/_examples/numba/__pycache__/extending_distributions.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/_examples/numba/extending.py +84 -0
- mgm/lib/python3.10/site-packages/numpy/random/_examples/numba/extending_distributions.py +67 -0
- mgm/lib/python3.10/site-packages/numpy/random/_mt19937.cpython-310-x86_64-linux-gnu.so +3 -0
- mgm/lib/python3.10/site-packages/numpy/random/_pcg64.cpython-310-x86_64-linux-gnu.so +3 -0
- mgm/lib/python3.10/site-packages/numpy/random/_pcg64.pyi +42 -0
- mgm/lib/python3.10/site-packages/numpy/random/_sfc64.cpython-310-x86_64-linux-gnu.so +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/bit_generator.cpython-310-x86_64-linux-gnu.so +3 -0
- mgm/lib/python3.10/site-packages/numpy/random/bit_generator.pxd +35 -0
- mgm/lib/python3.10/site-packages/numpy/random/bit_generator.pyi +112 -0
- mgm/lib/python3.10/site-packages/numpy/random/c_distributions.pxd +120 -0
- mgm/lib/python3.10/site-packages/numpy/random/lib/libnpyrandom.a +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/tests/__init__.py +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_direct.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_extending.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_generator_mt19937.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_generator_mt19937_regressions.cpython-310.pyc +0 -0
- mgm/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_random.cpython-310.pyc +0 -0
.gitattributes
CHANGED
|
@@ -1124,3 +1124,7 @@ mgm/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda117_nocublaslt
|
|
| 1124 |
mgm/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda122.so filter=lfs diff=lfs merge=lfs -text
|
| 1125 |
mgm/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda122_nocublaslt.so filter=lfs diff=lfs merge=lfs -text
|
| 1126 |
mgm/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda110.so filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1124 |
mgm/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda122.so filter=lfs diff=lfs merge=lfs -text
|
| 1125 |
mgm/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda122_nocublaslt.so filter=lfs diff=lfs merge=lfs -text
|
| 1126 |
mgm/lib/python3.10/site-packages/bitsandbytes/libbitsandbytes_cuda110.so filter=lfs diff=lfs merge=lfs -text
|
| 1127 |
+
mgm/lib/python3.10/site-packages/numpy/random/_bounded_integers.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 1128 |
+
mgm/lib/python3.10/site-packages/numpy/random/_pcg64.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 1129 |
+
mgm/lib/python3.10/site-packages/numpy/random/_mt19937.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 1130 |
+
mgm/lib/python3.10/site-packages/numpy/random/bit_generator.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
mgm/lib/python3.10/site-packages/gradio_client-0.2.9.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
mgm/lib/python3.10/site-packages/gradio_client-0.2.9.dist-info/METADATA
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: gradio_client
|
| 3 |
+
Version: 0.2.9
|
| 4 |
+
Summary: Python library for easily interacting with trained machine learning models
|
| 5 |
+
Project-URL: Homepage, https://github.com/gradio-app/gradio
|
| 6 |
+
Author-email: Abubakar Abid <team@gradio.app>, Ali Abid <team@gradio.app>, Ali Abdalla <team@gradio.app>, Dawood Khan <team@gradio.app>, Ahsen Khaliq <team@gradio.app>, Pete Allen <team@gradio.app>, Freddy Boulton <team@gradio.app>
|
| 7 |
+
License-Expression: Apache-2.0
|
| 8 |
+
Keywords: API,client,machine learning
|
| 9 |
+
Classifier: Development Status :: 4 - Beta
|
| 10 |
+
Classifier: License :: OSI Approved :: Apache Software License
|
| 11 |
+
Classifier: Operating System :: OS Independent
|
| 12 |
+
Classifier: Programming Language :: Python :: 3
|
| 13 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 14 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 15 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 16 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 18 |
+
Classifier: Topic :: Scientific/Engineering
|
| 19 |
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
| 20 |
+
Classifier: Topic :: Software Development :: User Interfaces
|
| 21 |
+
Requires-Python: >=3.8
|
| 22 |
+
Requires-Dist: fsspec
|
| 23 |
+
Requires-Dist: httpx
|
| 24 |
+
Requires-Dist: huggingface-hub>=0.13.0
|
| 25 |
+
Requires-Dist: packaging
|
| 26 |
+
Requires-Dist: requests
|
| 27 |
+
Requires-Dist: typing-extensions
|
| 28 |
+
Requires-Dist: websockets
|
| 29 |
+
Description-Content-Type: text/markdown
|
| 30 |
+
|
| 31 |
+
# `gradio_client`: Use a Gradio app as an API -- in 3 lines of Python
|
| 32 |
+
|
| 33 |
+
This directory contains the source code for `gradio_client`, a lightweight Python library that makes it very easy to use any Gradio app as an API.
|
| 34 |
+
|
| 35 |
+
As an example, consider this [Hugging Face Space that transcribes audio files](https://huggingface.co/spaces/abidlabs/whisper) that are recorded from the microphone.
|
| 36 |
+
|
| 37 |
+

|
| 38 |
+
|
| 39 |
+
Using the `gradio_client` library, we can easily use the Gradio as an API to transcribe audio files programmatically.
|
| 40 |
+
|
| 41 |
+
Here's the entire code to do it:
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
from gradio_client import Client
|
| 45 |
+
|
| 46 |
+
client = Client("abidlabs/whisper")
|
| 47 |
+
client.predict("audio_sample.wav")
|
| 48 |
+
|
| 49 |
+
>> "This is a test of the whisper speech recognition model."
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
The Gradio client works with any Gradio Space, whether it be an image generator, a stateful chatbot, or a tax calculator.
|
| 53 |
+
|
| 54 |
+
## Installation
|
| 55 |
+
|
| 56 |
+
If you already have a recent version of `gradio`, then the `gradio_client` is included as a dependency.
|
| 57 |
+
|
| 58 |
+
Otherwise, the lightweight `gradio_client` package can be installed from pip (or pip3) and works with Python versions 3.8 or higher:
|
| 59 |
+
|
| 60 |
+
```bash
|
| 61 |
+
$ pip install gradio_client
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
## Basic Usage
|
| 65 |
+
|
| 66 |
+
### Connecting to a Space or a Gradio app
|
| 67 |
+
|
| 68 |
+
Start by connecting instantiating a `Client` object and connecting it to a Gradio app that is running on Spaces (or anywhere else)!
|
| 69 |
+
|
| 70 |
+
**Connecting to a Space**
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
from gradio_client import Client
|
| 74 |
+
|
| 75 |
+
client = Client("abidlabs/en2fr") # a Space that translates from English to French
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
You can also connect to private Spaces by passing in your HF token with the `hf_token` parameter. You can get your HF token here: https://huggingface.co/settings/tokens
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
from gradio_client import Client
|
| 82 |
+
|
| 83 |
+
client = Client("abidlabs/my-private-space", hf_token="...")
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
**Duplicating a Space for private use**
|
| 87 |
+
|
| 88 |
+
While you can use any public Space as an API, you may get rate limited by Hugging Face if you make too many requests. For unlimited usage of a Space, simply duplicate the Space to create a private Space,
|
| 89 |
+
and then use it to make as many requests as you'd like!
|
| 90 |
+
|
| 91 |
+
The `gradio_client` includes a class method: `Client.duplicate()` to make this process simple:
|
| 92 |
+
|
| 93 |
+
```python
|
| 94 |
+
from gradio_client import Client
|
| 95 |
+
|
| 96 |
+
client = Client.duplicate("abidlabs/whisper")
|
| 97 |
+
client.predict("audio_sample.wav")
|
| 98 |
+
|
| 99 |
+
>> "This is a test of the whisper speech recognition model."
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
If you have previously duplicated a Space, re-running `duplicate()` will *not* create a new Space. Instead, the Client will attach to the previously-created Space. So it is safe to re-run the `Client.duplicate()` method multiple times.
|
| 103 |
+
|
| 104 |
+
**Note:** if the original Space uses GPUs, your private Space will as well, and your Hugging Face account will get billed based on the price of the GPU. To minimize charges, your Space will automatically go to sleep after 1 hour of inactivity. You can also set the hardware using the `hardware` parameter of `duplicate()`.
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
**Connecting a general Gradio app**
|
| 108 |
+
|
| 109 |
+
If your app is running somewhere else, just provide the full URL instead, including the "http://" or "https://". Here's an example of making predictions to a Gradio app that is running on a share URL:
|
| 110 |
+
|
| 111 |
+
```python
|
| 112 |
+
from gradio_client import Client
|
| 113 |
+
|
| 114 |
+
client = Client("https://bec81a83-5b5c-471e.gradio.live")
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
### Inspecting the API endpoints
|
| 119 |
+
|
| 120 |
+
Once you have connected to a Gradio app, you can view the APIs that are available to you by calling the `.view_api()` method. For the Whisper Space, we see the following:
|
| 121 |
+
|
| 122 |
+
```
|
| 123 |
+
Client.predict() Usage Info
|
| 124 |
+
---------------------------
|
| 125 |
+
Named API endpoints: 1
|
| 126 |
+
|
| 127 |
+
- predict(input_audio, api_name="/predict") -> value_0
|
| 128 |
+
Parameters:
|
| 129 |
+
- [Audio] input_audio: str (filepath or URL)
|
| 130 |
+
Returns:
|
| 131 |
+
- [Textbox] value_0: str (value)
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
This shows us that we have 1 API endpoint in this space, and shows us how to use the API endpoint to make a prediction: we should call the `.predict()` method, providing a parameter `input_audio` of type `str`, which is a `filepath or URL`.
|
| 135 |
+
|
| 136 |
+
We should also provide the `api_name='/predict'` argument. Although this isn't necessary if a Gradio app has a single named endpoint, it does allow us to call different endpoints in a single app if they are available. If an app has unnamed API endpoints, these can also be displayed by running `.view_api(all_endpoints=True)`.
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
### Making a prediction
|
| 140 |
+
|
| 141 |
+
The simplest way to make a prediction is simply to call the `.predict()` function with the appropriate arguments:
|
| 142 |
+
|
| 143 |
+
```python
|
| 144 |
+
from gradio_client import Client
|
| 145 |
+
|
| 146 |
+
client = Client("abidlabs/en2fr")
|
| 147 |
+
client.predict("Hello")
|
| 148 |
+
|
| 149 |
+
>> Bonjour
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
If there are multiple parameters, then you should pass them as separate arguments to `.predict()`, like this:
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
```python
|
| 156 |
+
from gradio_client import Client
|
| 157 |
+
|
| 158 |
+
client = Client("gradio/calculator")
|
| 159 |
+
client.predict(4, "add", 5)
|
| 160 |
+
|
| 161 |
+
>> 9.0
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
For certain inputs, such as images, you should pass in the filepath or URL to the file. Likewise, for the corresponding output types, you will get a filepath or URL returned.
|
| 165 |
+
|
| 166 |
+
```python
|
| 167 |
+
from gradio_client import Client
|
| 168 |
+
|
| 169 |
+
client = Client("abidlabs/whisper")
|
| 170 |
+
client.predict("https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3")
|
| 171 |
+
|
| 172 |
+
>> "My thought I have nobody by a beauty and will as you poured. Mr. Rochester is serve in that so don't find simpus, and devoted abode, to at might in a r—"
|
| 173 |
+
```
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
## Advanced Usage
|
| 177 |
+
|
| 178 |
+
For more ways to use the Gradio Python Client, check out our dedicated Guide on the Python client, available here: https://www.gradio.app/getting-started-with-the-python-client/
|
mgm/lib/python3.10/site-packages/gradio_client-0.2.9.dist-info/REQUESTED
ADDED
|
File without changes
|
mgm/lib/python3.10/site-packages/numpy/array_api/__init__.py
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
A NumPy sub-namespace that conforms to the Python array API standard.
|
| 3 |
+
|
| 4 |
+
This submodule accompanies NEP 47, which proposes its inclusion in NumPy. It
|
| 5 |
+
is still considered experimental, and will issue a warning when imported.
|
| 6 |
+
|
| 7 |
+
This is a proof-of-concept namespace that wraps the corresponding NumPy
|
| 8 |
+
functions to give a conforming implementation of the Python array API standard
|
| 9 |
+
(https://data-apis.github.io/array-api/latest/). The standard is currently in
|
| 10 |
+
an RFC phase and comments on it are both welcome and encouraged. Comments
|
| 11 |
+
should be made either at https://github.com/data-apis/array-api or at
|
| 12 |
+
https://github.com/data-apis/consortium-feedback/discussions.
|
| 13 |
+
|
| 14 |
+
NumPy already follows the proposed spec for the most part, so this module
|
| 15 |
+
serves mostly as a thin wrapper around it. However, NumPy also implements a
|
| 16 |
+
lot of behavior that is not included in the spec, so this serves as a
|
| 17 |
+
restricted subset of the API. Only those functions that are part of the spec
|
| 18 |
+
are included in this namespace, and all functions are given with the exact
|
| 19 |
+
signature given in the spec, including the use of position-only arguments, and
|
| 20 |
+
omitting any extra keyword arguments implemented by NumPy but not part of the
|
| 21 |
+
spec. The behavior of some functions is also modified from the NumPy behavior
|
| 22 |
+
to conform to the standard. Note that the underlying array object itself is
|
| 23 |
+
wrapped in a wrapper Array() class, but is otherwise unchanged. This submodule
|
| 24 |
+
is implemented in pure Python with no C extensions.
|
| 25 |
+
|
| 26 |
+
The array API spec is designed as a "minimal API subset" and explicitly allows
|
| 27 |
+
libraries to include behaviors not specified by it. But users of this module
|
| 28 |
+
that intend to write portable code should be aware that only those behaviors
|
| 29 |
+
that are listed in the spec are guaranteed to be implemented across libraries.
|
| 30 |
+
Consequently, the NumPy implementation was chosen to be both conforming and
|
| 31 |
+
minimal, so that users can use this implementation of the array API namespace
|
| 32 |
+
and be sure that behaviors that it defines will be available in conforming
|
| 33 |
+
namespaces from other libraries.
|
| 34 |
+
|
| 35 |
+
A few notes about the current state of this submodule:
|
| 36 |
+
|
| 37 |
+
- There is a test suite that tests modules against the array API standard at
|
| 38 |
+
https://github.com/data-apis/array-api-tests. The test suite is still a work
|
| 39 |
+
in progress, but the existing tests pass on this module, with a few
|
| 40 |
+
exceptions:
|
| 41 |
+
|
| 42 |
+
- DLPack support (see https://github.com/data-apis/array-api/pull/106) is
|
| 43 |
+
not included here, as it requires a full implementation in NumPy proper
|
| 44 |
+
first.
|
| 45 |
+
|
| 46 |
+
The test suite is not yet complete, and even the tests that exist are not
|
| 47 |
+
guaranteed to give a comprehensive coverage of the spec. Therefore, when
|
| 48 |
+
reviewing and using this submodule, you should refer to the standard
|
| 49 |
+
documents themselves. There are some tests in numpy.array_api.tests, but
|
| 50 |
+
they primarily focus on things that are not tested by the official array API
|
| 51 |
+
test suite.
|
| 52 |
+
|
| 53 |
+
- There is a custom array object, numpy.array_api.Array, which is returned by
|
| 54 |
+
all functions in this module. All functions in the array API namespace
|
| 55 |
+
implicitly assume that they will only receive this object as input. The only
|
| 56 |
+
way to create instances of this object is to use one of the array creation
|
| 57 |
+
functions. It does not have a public constructor on the object itself. The
|
| 58 |
+
object is a small wrapper class around numpy.ndarray. The main purpose of it
|
| 59 |
+
is to restrict the namespace of the array object to only those dtypes and
|
| 60 |
+
only those methods that are required by the spec, as well as to limit/change
|
| 61 |
+
certain behavior that differs in the spec. In particular:
|
| 62 |
+
|
| 63 |
+
- The array API namespace does not have scalar objects, only 0-D arrays.
|
| 64 |
+
Operations on Array that would create a scalar in NumPy create a 0-D
|
| 65 |
+
array.
|
| 66 |
+
|
| 67 |
+
- Indexing: Only a subset of indices supported by NumPy are required by the
|
| 68 |
+
spec. The Array object restricts indexing to only allow those types of
|
| 69 |
+
indices that are required by the spec. See the docstring of the
|
| 70 |
+
numpy.array_api.Array._validate_indices helper function for more
|
| 71 |
+
information.
|
| 72 |
+
|
| 73 |
+
- Type promotion: Some type promotion rules are different in the spec. In
|
| 74 |
+
particular, the spec does not have any value-based casting. The spec also
|
| 75 |
+
does not require cross-kind casting, like integer -> floating-point. Only
|
| 76 |
+
those promotions that are explicitly required by the array API
|
| 77 |
+
specification are allowed in this module. See NEP 47 for more info.
|
| 78 |
+
|
| 79 |
+
- Functions do not automatically call asarray() on their input, and will not
|
| 80 |
+
work if the input type is not Array. The exception is array creation
|
| 81 |
+
functions, and Python operators on the Array object, which accept Python
|
| 82 |
+
scalars of the same type as the array dtype.
|
| 83 |
+
|
| 84 |
+
- All functions include type annotations, corresponding to those given in the
|
| 85 |
+
spec (see _typing.py for definitions of some custom types). These do not
|
| 86 |
+
currently fully pass mypy due to some limitations in mypy.
|
| 87 |
+
|
| 88 |
+
- Dtype objects are just the NumPy dtype objects, e.g., float64 =
|
| 89 |
+
np.dtype('float64'). The spec does not require any behavior on these dtype
|
| 90 |
+
objects other than that they be accessible by name and be comparable by
|
| 91 |
+
equality, but it was considered too much extra complexity to create custom
|
| 92 |
+
objects to represent dtypes.
|
| 93 |
+
|
| 94 |
+
- All places where the implementations in this submodule are known to deviate
|
| 95 |
+
from their corresponding functions in NumPy are marked with "# Note:"
|
| 96 |
+
comments.
|
| 97 |
+
|
| 98 |
+
Still TODO in this module are:
|
| 99 |
+
|
| 100 |
+
- DLPack support for numpy.ndarray is still in progress. See
|
| 101 |
+
https://github.com/numpy/numpy/pull/19083.
|
| 102 |
+
|
| 103 |
+
- The copy=False keyword argument to asarray() is not yet implemented. This
|
| 104 |
+
requires support in numpy.asarray() first.
|
| 105 |
+
|
| 106 |
+
- Some functions are not yet fully tested in the array API test suite, and may
|
| 107 |
+
require updates that are not yet known until the tests are written.
|
| 108 |
+
|
| 109 |
+
- The spec is still in an RFC phase and may still have minor updates, which
|
| 110 |
+
will need to be reflected here.
|
| 111 |
+
|
| 112 |
+
- Complex number support in array API spec is planned but not yet finalized,
|
| 113 |
+
as are the fft extension and certain linear algebra functions such as eig
|
| 114 |
+
that require complex dtypes.
|
| 115 |
+
|
| 116 |
+
"""
|
| 117 |
+
|
| 118 |
+
import warnings
|
| 119 |
+
|
| 120 |
+
warnings.warn(
|
| 121 |
+
"The numpy.array_api submodule is still experimental. See NEP 47.", stacklevel=2
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
__array_api_version__ = "2022.12"
|
| 125 |
+
|
| 126 |
+
__all__ = ["__array_api_version__"]
|
| 127 |
+
|
| 128 |
+
from ._constants import e, inf, nan, pi, newaxis
|
| 129 |
+
|
| 130 |
+
__all__ += ["e", "inf", "nan", "pi", "newaxis"]
|
| 131 |
+
|
| 132 |
+
from ._creation_functions import (
|
| 133 |
+
asarray,
|
| 134 |
+
arange,
|
| 135 |
+
empty,
|
| 136 |
+
empty_like,
|
| 137 |
+
eye,
|
| 138 |
+
from_dlpack,
|
| 139 |
+
full,
|
| 140 |
+
full_like,
|
| 141 |
+
linspace,
|
| 142 |
+
meshgrid,
|
| 143 |
+
ones,
|
| 144 |
+
ones_like,
|
| 145 |
+
tril,
|
| 146 |
+
triu,
|
| 147 |
+
zeros,
|
| 148 |
+
zeros_like,
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
__all__ += [
|
| 152 |
+
"asarray",
|
| 153 |
+
"arange",
|
| 154 |
+
"empty",
|
| 155 |
+
"empty_like",
|
| 156 |
+
"eye",
|
| 157 |
+
"from_dlpack",
|
| 158 |
+
"full",
|
| 159 |
+
"full_like",
|
| 160 |
+
"linspace",
|
| 161 |
+
"meshgrid",
|
| 162 |
+
"ones",
|
| 163 |
+
"ones_like",
|
| 164 |
+
"tril",
|
| 165 |
+
"triu",
|
| 166 |
+
"zeros",
|
| 167 |
+
"zeros_like",
|
| 168 |
+
]
|
| 169 |
+
|
| 170 |
+
from ._data_type_functions import (
|
| 171 |
+
astype,
|
| 172 |
+
broadcast_arrays,
|
| 173 |
+
broadcast_to,
|
| 174 |
+
can_cast,
|
| 175 |
+
finfo,
|
| 176 |
+
isdtype,
|
| 177 |
+
iinfo,
|
| 178 |
+
result_type,
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
__all__ += [
|
| 182 |
+
"astype",
|
| 183 |
+
"broadcast_arrays",
|
| 184 |
+
"broadcast_to",
|
| 185 |
+
"can_cast",
|
| 186 |
+
"finfo",
|
| 187 |
+
"iinfo",
|
| 188 |
+
"result_type",
|
| 189 |
+
]
|
| 190 |
+
|
| 191 |
+
from ._dtypes import (
|
| 192 |
+
int8,
|
| 193 |
+
int16,
|
| 194 |
+
int32,
|
| 195 |
+
int64,
|
| 196 |
+
uint8,
|
| 197 |
+
uint16,
|
| 198 |
+
uint32,
|
| 199 |
+
uint64,
|
| 200 |
+
float32,
|
| 201 |
+
float64,
|
| 202 |
+
complex64,
|
| 203 |
+
complex128,
|
| 204 |
+
bool,
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
+
__all__ += [
|
| 208 |
+
"int8",
|
| 209 |
+
"int16",
|
| 210 |
+
"int32",
|
| 211 |
+
"int64",
|
| 212 |
+
"uint8",
|
| 213 |
+
"uint16",
|
| 214 |
+
"uint32",
|
| 215 |
+
"uint64",
|
| 216 |
+
"float32",
|
| 217 |
+
"float64",
|
| 218 |
+
"bool",
|
| 219 |
+
]
|
| 220 |
+
|
| 221 |
+
from ._elementwise_functions import (
|
| 222 |
+
abs,
|
| 223 |
+
acos,
|
| 224 |
+
acosh,
|
| 225 |
+
add,
|
| 226 |
+
asin,
|
| 227 |
+
asinh,
|
| 228 |
+
atan,
|
| 229 |
+
atan2,
|
| 230 |
+
atanh,
|
| 231 |
+
bitwise_and,
|
| 232 |
+
bitwise_left_shift,
|
| 233 |
+
bitwise_invert,
|
| 234 |
+
bitwise_or,
|
| 235 |
+
bitwise_right_shift,
|
| 236 |
+
bitwise_xor,
|
| 237 |
+
ceil,
|
| 238 |
+
conj,
|
| 239 |
+
cos,
|
| 240 |
+
cosh,
|
| 241 |
+
divide,
|
| 242 |
+
equal,
|
| 243 |
+
exp,
|
| 244 |
+
expm1,
|
| 245 |
+
floor,
|
| 246 |
+
floor_divide,
|
| 247 |
+
greater,
|
| 248 |
+
greater_equal,
|
| 249 |
+
imag,
|
| 250 |
+
isfinite,
|
| 251 |
+
isinf,
|
| 252 |
+
isnan,
|
| 253 |
+
less,
|
| 254 |
+
less_equal,
|
| 255 |
+
log,
|
| 256 |
+
log1p,
|
| 257 |
+
log2,
|
| 258 |
+
log10,
|
| 259 |
+
logaddexp,
|
| 260 |
+
logical_and,
|
| 261 |
+
logical_not,
|
| 262 |
+
logical_or,
|
| 263 |
+
logical_xor,
|
| 264 |
+
multiply,
|
| 265 |
+
negative,
|
| 266 |
+
not_equal,
|
| 267 |
+
positive,
|
| 268 |
+
pow,
|
| 269 |
+
real,
|
| 270 |
+
remainder,
|
| 271 |
+
round,
|
| 272 |
+
sign,
|
| 273 |
+
sin,
|
| 274 |
+
sinh,
|
| 275 |
+
square,
|
| 276 |
+
sqrt,
|
| 277 |
+
subtract,
|
| 278 |
+
tan,
|
| 279 |
+
tanh,
|
| 280 |
+
trunc,
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
__all__ += [
|
| 284 |
+
"abs",
|
| 285 |
+
"acos",
|
| 286 |
+
"acosh",
|
| 287 |
+
"add",
|
| 288 |
+
"asin",
|
| 289 |
+
"asinh",
|
| 290 |
+
"atan",
|
| 291 |
+
"atan2",
|
| 292 |
+
"atanh",
|
| 293 |
+
"bitwise_and",
|
| 294 |
+
"bitwise_left_shift",
|
| 295 |
+
"bitwise_invert",
|
| 296 |
+
"bitwise_or",
|
| 297 |
+
"bitwise_right_shift",
|
| 298 |
+
"bitwise_xor",
|
| 299 |
+
"ceil",
|
| 300 |
+
"cos",
|
| 301 |
+
"cosh",
|
| 302 |
+
"divide",
|
| 303 |
+
"equal",
|
| 304 |
+
"exp",
|
| 305 |
+
"expm1",
|
| 306 |
+
"floor",
|
| 307 |
+
"floor_divide",
|
| 308 |
+
"greater",
|
| 309 |
+
"greater_equal",
|
| 310 |
+
"isfinite",
|
| 311 |
+
"isinf",
|
| 312 |
+
"isnan",
|
| 313 |
+
"less",
|
| 314 |
+
"less_equal",
|
| 315 |
+
"log",
|
| 316 |
+
"log1p",
|
| 317 |
+
"log2",
|
| 318 |
+
"log10",
|
| 319 |
+
"logaddexp",
|
| 320 |
+
"logical_and",
|
| 321 |
+
"logical_not",
|
| 322 |
+
"logical_or",
|
| 323 |
+
"logical_xor",
|
| 324 |
+
"multiply",
|
| 325 |
+
"negative",
|
| 326 |
+
"not_equal",
|
| 327 |
+
"positive",
|
| 328 |
+
"pow",
|
| 329 |
+
"remainder",
|
| 330 |
+
"round",
|
| 331 |
+
"sign",
|
| 332 |
+
"sin",
|
| 333 |
+
"sinh",
|
| 334 |
+
"square",
|
| 335 |
+
"sqrt",
|
| 336 |
+
"subtract",
|
| 337 |
+
"tan",
|
| 338 |
+
"tanh",
|
| 339 |
+
"trunc",
|
| 340 |
+
]
|
| 341 |
+
|
| 342 |
+
from ._indexing_functions import take
|
| 343 |
+
|
| 344 |
+
__all__ += ["take"]
|
| 345 |
+
|
| 346 |
+
# linalg is an extension in the array API spec, which is a sub-namespace. Only
|
| 347 |
+
# a subset of functions in it are imported into the top-level namespace.
|
| 348 |
+
from . import linalg
|
| 349 |
+
|
| 350 |
+
__all__ += ["linalg"]
|
| 351 |
+
|
| 352 |
+
from .linalg import matmul, tensordot, matrix_transpose, vecdot
|
| 353 |
+
|
| 354 |
+
__all__ += ["matmul", "tensordot", "matrix_transpose", "vecdot"]
|
| 355 |
+
|
| 356 |
+
from ._manipulation_functions import (
|
| 357 |
+
concat,
|
| 358 |
+
expand_dims,
|
| 359 |
+
flip,
|
| 360 |
+
permute_dims,
|
| 361 |
+
reshape,
|
| 362 |
+
roll,
|
| 363 |
+
squeeze,
|
| 364 |
+
stack,
|
| 365 |
+
)
|
| 366 |
+
|
| 367 |
+
__all__ += ["concat", "expand_dims", "flip", "permute_dims", "reshape", "roll", "squeeze", "stack"]
|
| 368 |
+
|
| 369 |
+
from ._searching_functions import argmax, argmin, nonzero, where
|
| 370 |
+
|
| 371 |
+
__all__ += ["argmax", "argmin", "nonzero", "where"]
|
| 372 |
+
|
| 373 |
+
from ._set_functions import unique_all, unique_counts, unique_inverse, unique_values
|
| 374 |
+
|
| 375 |
+
__all__ += ["unique_all", "unique_counts", "unique_inverse", "unique_values"]
|
| 376 |
+
|
| 377 |
+
from ._sorting_functions import argsort, sort
|
| 378 |
+
|
| 379 |
+
__all__ += ["argsort", "sort"]
|
| 380 |
+
|
| 381 |
+
from ._statistical_functions import max, mean, min, prod, std, sum, var
|
| 382 |
+
|
| 383 |
+
__all__ += ["max", "mean", "min", "prod", "std", "sum", "var"]
|
| 384 |
+
|
| 385 |
+
from ._utility_functions import all, any
|
| 386 |
+
|
| 387 |
+
__all__ += ["all", "any"]
|
mgm/lib/python3.10/site-packages/numpy/array_api/_creation_functions.py
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
from typing import TYPE_CHECKING, List, Optional, Tuple, Union
|
| 5 |
+
|
| 6 |
+
if TYPE_CHECKING:
|
| 7 |
+
from ._typing import (
|
| 8 |
+
Array,
|
| 9 |
+
Device,
|
| 10 |
+
Dtype,
|
| 11 |
+
NestedSequence,
|
| 12 |
+
SupportsBufferProtocol,
|
| 13 |
+
)
|
| 14 |
+
from collections.abc import Sequence
|
| 15 |
+
from ._dtypes import _all_dtypes
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _check_valid_dtype(dtype):
|
| 21 |
+
# Note: Only spelling dtypes as the dtype objects is supported.
|
| 22 |
+
|
| 23 |
+
# We use this instead of "dtype in _all_dtypes" because the dtype objects
|
| 24 |
+
# define equality with the sorts of things we want to disallow.
|
| 25 |
+
for d in (None,) + _all_dtypes:
|
| 26 |
+
if dtype is d:
|
| 27 |
+
return
|
| 28 |
+
raise ValueError("dtype must be one of the supported dtypes")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def asarray(
|
| 32 |
+
obj: Union[
|
| 33 |
+
Array,
|
| 34 |
+
bool,
|
| 35 |
+
int,
|
| 36 |
+
float,
|
| 37 |
+
NestedSequence[bool | int | float],
|
| 38 |
+
SupportsBufferProtocol,
|
| 39 |
+
],
|
| 40 |
+
/,
|
| 41 |
+
*,
|
| 42 |
+
dtype: Optional[Dtype] = None,
|
| 43 |
+
device: Optional[Device] = None,
|
| 44 |
+
copy: Optional[Union[bool, np._CopyMode]] = None,
|
| 45 |
+
) -> Array:
|
| 46 |
+
"""
|
| 47 |
+
Array API compatible wrapper for :py:func:`np.asarray <numpy.asarray>`.
|
| 48 |
+
|
| 49 |
+
See its docstring for more information.
|
| 50 |
+
"""
|
| 51 |
+
# _array_object imports in this file are inside the functions to avoid
|
| 52 |
+
# circular imports
|
| 53 |
+
from ._array_object import Array
|
| 54 |
+
|
| 55 |
+
_check_valid_dtype(dtype)
|
| 56 |
+
if device not in ["cpu", None]:
|
| 57 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 58 |
+
if copy in (False, np._CopyMode.IF_NEEDED):
|
| 59 |
+
# Note: copy=False is not yet implemented in np.asarray
|
| 60 |
+
raise NotImplementedError("copy=False is not yet implemented")
|
| 61 |
+
if isinstance(obj, Array):
|
| 62 |
+
if dtype is not None and obj.dtype != dtype:
|
| 63 |
+
copy = True
|
| 64 |
+
if copy in (True, np._CopyMode.ALWAYS):
|
| 65 |
+
return Array._new(np.array(obj._array, copy=True, dtype=dtype))
|
| 66 |
+
return obj
|
| 67 |
+
if dtype is None and isinstance(obj, int) and (obj > 2 ** 64 or obj < -(2 ** 63)):
|
| 68 |
+
# Give a better error message in this case. NumPy would convert this
|
| 69 |
+
# to an object array. TODO: This won't handle large integers in lists.
|
| 70 |
+
raise OverflowError("Integer out of bounds for array dtypes")
|
| 71 |
+
res = np.asarray(obj, dtype=dtype)
|
| 72 |
+
return Array._new(res)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def arange(
|
| 76 |
+
start: Union[int, float],
|
| 77 |
+
/,
|
| 78 |
+
stop: Optional[Union[int, float]] = None,
|
| 79 |
+
step: Union[int, float] = 1,
|
| 80 |
+
*,
|
| 81 |
+
dtype: Optional[Dtype] = None,
|
| 82 |
+
device: Optional[Device] = None,
|
| 83 |
+
) -> Array:
|
| 84 |
+
"""
|
| 85 |
+
Array API compatible wrapper for :py:func:`np.arange <numpy.arange>`.
|
| 86 |
+
|
| 87 |
+
See its docstring for more information.
|
| 88 |
+
"""
|
| 89 |
+
from ._array_object import Array
|
| 90 |
+
|
| 91 |
+
_check_valid_dtype(dtype)
|
| 92 |
+
if device not in ["cpu", None]:
|
| 93 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 94 |
+
return Array._new(np.arange(start, stop=stop, step=step, dtype=dtype))
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def empty(
|
| 98 |
+
shape: Union[int, Tuple[int, ...]],
|
| 99 |
+
*,
|
| 100 |
+
dtype: Optional[Dtype] = None,
|
| 101 |
+
device: Optional[Device] = None,
|
| 102 |
+
) -> Array:
|
| 103 |
+
"""
|
| 104 |
+
Array API compatible wrapper for :py:func:`np.empty <numpy.empty>`.
|
| 105 |
+
|
| 106 |
+
See its docstring for more information.
|
| 107 |
+
"""
|
| 108 |
+
from ._array_object import Array
|
| 109 |
+
|
| 110 |
+
_check_valid_dtype(dtype)
|
| 111 |
+
if device not in ["cpu", None]:
|
| 112 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 113 |
+
return Array._new(np.empty(shape, dtype=dtype))
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def empty_like(
|
| 117 |
+
x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None
|
| 118 |
+
) -> Array:
|
| 119 |
+
"""
|
| 120 |
+
Array API compatible wrapper for :py:func:`np.empty_like <numpy.empty_like>`.
|
| 121 |
+
|
| 122 |
+
See its docstring for more information.
|
| 123 |
+
"""
|
| 124 |
+
from ._array_object import Array
|
| 125 |
+
|
| 126 |
+
_check_valid_dtype(dtype)
|
| 127 |
+
if device not in ["cpu", None]:
|
| 128 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 129 |
+
return Array._new(np.empty_like(x._array, dtype=dtype))
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def eye(
|
| 133 |
+
n_rows: int,
|
| 134 |
+
n_cols: Optional[int] = None,
|
| 135 |
+
/,
|
| 136 |
+
*,
|
| 137 |
+
k: int = 0,
|
| 138 |
+
dtype: Optional[Dtype] = None,
|
| 139 |
+
device: Optional[Device] = None,
|
| 140 |
+
) -> Array:
|
| 141 |
+
"""
|
| 142 |
+
Array API compatible wrapper for :py:func:`np.eye <numpy.eye>`.
|
| 143 |
+
|
| 144 |
+
See its docstring for more information.
|
| 145 |
+
"""
|
| 146 |
+
from ._array_object import Array
|
| 147 |
+
|
| 148 |
+
_check_valid_dtype(dtype)
|
| 149 |
+
if device not in ["cpu", None]:
|
| 150 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 151 |
+
return Array._new(np.eye(n_rows, M=n_cols, k=k, dtype=dtype))
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def from_dlpack(x: object, /) -> Array:
|
| 155 |
+
from ._array_object import Array
|
| 156 |
+
|
| 157 |
+
return Array._new(np.from_dlpack(x))
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def full(
|
| 161 |
+
shape: Union[int, Tuple[int, ...]],
|
| 162 |
+
fill_value: Union[int, float],
|
| 163 |
+
*,
|
| 164 |
+
dtype: Optional[Dtype] = None,
|
| 165 |
+
device: Optional[Device] = None,
|
| 166 |
+
) -> Array:
|
| 167 |
+
"""
|
| 168 |
+
Array API compatible wrapper for :py:func:`np.full <numpy.full>`.
|
| 169 |
+
|
| 170 |
+
See its docstring for more information.
|
| 171 |
+
"""
|
| 172 |
+
from ._array_object import Array
|
| 173 |
+
|
| 174 |
+
_check_valid_dtype(dtype)
|
| 175 |
+
if device not in ["cpu", None]:
|
| 176 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 177 |
+
if isinstance(fill_value, Array) and fill_value.ndim == 0:
|
| 178 |
+
fill_value = fill_value._array
|
| 179 |
+
res = np.full(shape, fill_value, dtype=dtype)
|
| 180 |
+
if res.dtype not in _all_dtypes:
|
| 181 |
+
# This will happen if the fill value is not something that NumPy
|
| 182 |
+
# coerces to one of the acceptable dtypes.
|
| 183 |
+
raise TypeError("Invalid input to full")
|
| 184 |
+
return Array._new(res)
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def full_like(
|
| 188 |
+
x: Array,
|
| 189 |
+
/,
|
| 190 |
+
fill_value: Union[int, float],
|
| 191 |
+
*,
|
| 192 |
+
dtype: Optional[Dtype] = None,
|
| 193 |
+
device: Optional[Device] = None,
|
| 194 |
+
) -> Array:
|
| 195 |
+
"""
|
| 196 |
+
Array API compatible wrapper for :py:func:`np.full_like <numpy.full_like>`.
|
| 197 |
+
|
| 198 |
+
See its docstring for more information.
|
| 199 |
+
"""
|
| 200 |
+
from ._array_object import Array
|
| 201 |
+
|
| 202 |
+
_check_valid_dtype(dtype)
|
| 203 |
+
if device not in ["cpu", None]:
|
| 204 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 205 |
+
res = np.full_like(x._array, fill_value, dtype=dtype)
|
| 206 |
+
if res.dtype not in _all_dtypes:
|
| 207 |
+
# This will happen if the fill value is not something that NumPy
|
| 208 |
+
# coerces to one of the acceptable dtypes.
|
| 209 |
+
raise TypeError("Invalid input to full_like")
|
| 210 |
+
return Array._new(res)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def linspace(
|
| 214 |
+
start: Union[int, float],
|
| 215 |
+
stop: Union[int, float],
|
| 216 |
+
/,
|
| 217 |
+
num: int,
|
| 218 |
+
*,
|
| 219 |
+
dtype: Optional[Dtype] = None,
|
| 220 |
+
device: Optional[Device] = None,
|
| 221 |
+
endpoint: bool = True,
|
| 222 |
+
) -> Array:
|
| 223 |
+
"""
|
| 224 |
+
Array API compatible wrapper for :py:func:`np.linspace <numpy.linspace>`.
|
| 225 |
+
|
| 226 |
+
See its docstring for more information.
|
| 227 |
+
"""
|
| 228 |
+
from ._array_object import Array
|
| 229 |
+
|
| 230 |
+
_check_valid_dtype(dtype)
|
| 231 |
+
if device not in ["cpu", None]:
|
| 232 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 233 |
+
return Array._new(np.linspace(start, stop, num, dtype=dtype, endpoint=endpoint))
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def meshgrid(*arrays: Array, indexing: str = "xy") -> List[Array]:
|
| 237 |
+
"""
|
| 238 |
+
Array API compatible wrapper for :py:func:`np.meshgrid <numpy.meshgrid>`.
|
| 239 |
+
|
| 240 |
+
See its docstring for more information.
|
| 241 |
+
"""
|
| 242 |
+
from ._array_object import Array
|
| 243 |
+
|
| 244 |
+
# Note: unlike np.meshgrid, only inputs with all the same dtype are
|
| 245 |
+
# allowed
|
| 246 |
+
|
| 247 |
+
if len({a.dtype for a in arrays}) > 1:
|
| 248 |
+
raise ValueError("meshgrid inputs must all have the same dtype")
|
| 249 |
+
|
| 250 |
+
return [
|
| 251 |
+
Array._new(array)
|
| 252 |
+
for array in np.meshgrid(*[a._array for a in arrays], indexing=indexing)
|
| 253 |
+
]
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def ones(
|
| 257 |
+
shape: Union[int, Tuple[int, ...]],
|
| 258 |
+
*,
|
| 259 |
+
dtype: Optional[Dtype] = None,
|
| 260 |
+
device: Optional[Device] = None,
|
| 261 |
+
) -> Array:
|
| 262 |
+
"""
|
| 263 |
+
Array API compatible wrapper for :py:func:`np.ones <numpy.ones>`.
|
| 264 |
+
|
| 265 |
+
See its docstring for more information.
|
| 266 |
+
"""
|
| 267 |
+
from ._array_object import Array
|
| 268 |
+
|
| 269 |
+
_check_valid_dtype(dtype)
|
| 270 |
+
if device not in ["cpu", None]:
|
| 271 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 272 |
+
return Array._new(np.ones(shape, dtype=dtype))
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
def ones_like(
|
| 276 |
+
x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None
|
| 277 |
+
) -> Array:
|
| 278 |
+
"""
|
| 279 |
+
Array API compatible wrapper for :py:func:`np.ones_like <numpy.ones_like>`.
|
| 280 |
+
|
| 281 |
+
See its docstring for more information.
|
| 282 |
+
"""
|
| 283 |
+
from ._array_object import Array
|
| 284 |
+
|
| 285 |
+
_check_valid_dtype(dtype)
|
| 286 |
+
if device not in ["cpu", None]:
|
| 287 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 288 |
+
return Array._new(np.ones_like(x._array, dtype=dtype))
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def tril(x: Array, /, *, k: int = 0) -> Array:
|
| 292 |
+
"""
|
| 293 |
+
Array API compatible wrapper for :py:func:`np.tril <numpy.tril>`.
|
| 294 |
+
|
| 295 |
+
See its docstring for more information.
|
| 296 |
+
"""
|
| 297 |
+
from ._array_object import Array
|
| 298 |
+
|
| 299 |
+
if x.ndim < 2:
|
| 300 |
+
# Note: Unlike np.tril, x must be at least 2-D
|
| 301 |
+
raise ValueError("x must be at least 2-dimensional for tril")
|
| 302 |
+
return Array._new(np.tril(x._array, k=k))
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def triu(x: Array, /, *, k: int = 0) -> Array:
|
| 306 |
+
"""
|
| 307 |
+
Array API compatible wrapper for :py:func:`np.triu <numpy.triu>`.
|
| 308 |
+
|
| 309 |
+
See its docstring for more information.
|
| 310 |
+
"""
|
| 311 |
+
from ._array_object import Array
|
| 312 |
+
|
| 313 |
+
if x.ndim < 2:
|
| 314 |
+
# Note: Unlike np.triu, x must be at least 2-D
|
| 315 |
+
raise ValueError("x must be at least 2-dimensional for triu")
|
| 316 |
+
return Array._new(np.triu(x._array, k=k))
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def zeros(
|
| 320 |
+
shape: Union[int, Tuple[int, ...]],
|
| 321 |
+
*,
|
| 322 |
+
dtype: Optional[Dtype] = None,
|
| 323 |
+
device: Optional[Device] = None,
|
| 324 |
+
) -> Array:
|
| 325 |
+
"""
|
| 326 |
+
Array API compatible wrapper for :py:func:`np.zeros <numpy.zeros>`.
|
| 327 |
+
|
| 328 |
+
See its docstring for more information.
|
| 329 |
+
"""
|
| 330 |
+
from ._array_object import Array
|
| 331 |
+
|
| 332 |
+
_check_valid_dtype(dtype)
|
| 333 |
+
if device not in ["cpu", None]:
|
| 334 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 335 |
+
return Array._new(np.zeros(shape, dtype=dtype))
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def zeros_like(
|
| 339 |
+
x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None
|
| 340 |
+
) -> Array:
|
| 341 |
+
"""
|
| 342 |
+
Array API compatible wrapper for :py:func:`np.zeros_like <numpy.zeros_like>`.
|
| 343 |
+
|
| 344 |
+
See its docstring for more information.
|
| 345 |
+
"""
|
| 346 |
+
from ._array_object import Array
|
| 347 |
+
|
| 348 |
+
_check_valid_dtype(dtype)
|
| 349 |
+
if device not in ["cpu", None]:
|
| 350 |
+
raise ValueError(f"Unsupported device {device!r}")
|
| 351 |
+
return Array._new(np.zeros_like(x._array, dtype=dtype))
|
mgm/lib/python3.10/site-packages/numpy/array_api/_data_type_functions.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from ._array_object import Array
|
| 4 |
+
from ._dtypes import (
|
| 5 |
+
_all_dtypes,
|
| 6 |
+
_boolean_dtypes,
|
| 7 |
+
_signed_integer_dtypes,
|
| 8 |
+
_unsigned_integer_dtypes,
|
| 9 |
+
_integer_dtypes,
|
| 10 |
+
_real_floating_dtypes,
|
| 11 |
+
_complex_floating_dtypes,
|
| 12 |
+
_numeric_dtypes,
|
| 13 |
+
_result_type,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
from dataclasses import dataclass
|
| 17 |
+
from typing import TYPE_CHECKING, List, Tuple, Union
|
| 18 |
+
|
| 19 |
+
if TYPE_CHECKING:
|
| 20 |
+
from ._typing import Dtype
|
| 21 |
+
from collections.abc import Sequence
|
| 22 |
+
|
| 23 |
+
import numpy as np
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Note: astype is a function, not an array method as in NumPy.
|
| 27 |
+
def astype(x: Array, dtype: Dtype, /, *, copy: bool = True) -> Array:
|
| 28 |
+
if not copy and dtype == x.dtype:
|
| 29 |
+
return x
|
| 30 |
+
return Array._new(x._array.astype(dtype=dtype, copy=copy))
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def broadcast_arrays(*arrays: Array) -> List[Array]:
|
| 34 |
+
"""
|
| 35 |
+
Array API compatible wrapper for :py:func:`np.broadcast_arrays <numpy.broadcast_arrays>`.
|
| 36 |
+
|
| 37 |
+
See its docstring for more information.
|
| 38 |
+
"""
|
| 39 |
+
from ._array_object import Array
|
| 40 |
+
|
| 41 |
+
return [
|
| 42 |
+
Array._new(array) for array in np.broadcast_arrays(*[a._array for a in arrays])
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def broadcast_to(x: Array, /, shape: Tuple[int, ...]) -> Array:
|
| 47 |
+
"""
|
| 48 |
+
Array API compatible wrapper for :py:func:`np.broadcast_to <numpy.broadcast_to>`.
|
| 49 |
+
|
| 50 |
+
See its docstring for more information.
|
| 51 |
+
"""
|
| 52 |
+
from ._array_object import Array
|
| 53 |
+
|
| 54 |
+
return Array._new(np.broadcast_to(x._array, shape))
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def can_cast(from_: Union[Dtype, Array], to: Dtype, /) -> bool:
|
| 58 |
+
"""
|
| 59 |
+
Array API compatible wrapper for :py:func:`np.can_cast <numpy.can_cast>`.
|
| 60 |
+
|
| 61 |
+
See its docstring for more information.
|
| 62 |
+
"""
|
| 63 |
+
if isinstance(from_, Array):
|
| 64 |
+
from_ = from_.dtype
|
| 65 |
+
elif from_ not in _all_dtypes:
|
| 66 |
+
raise TypeError(f"{from_=}, but should be an array_api array or dtype")
|
| 67 |
+
if to not in _all_dtypes:
|
| 68 |
+
raise TypeError(f"{to=}, but should be a dtype")
|
| 69 |
+
# Note: We avoid np.can_cast() as it has discrepancies with the array API,
|
| 70 |
+
# since NumPy allows cross-kind casting (e.g., NumPy allows bool -> int8).
|
| 71 |
+
# See https://github.com/numpy/numpy/issues/20870
|
| 72 |
+
try:
|
| 73 |
+
# We promote `from_` and `to` together. We then check if the promoted
|
| 74 |
+
# dtype is `to`, which indicates if `from_` can (up)cast to `to`.
|
| 75 |
+
dtype = _result_type(from_, to)
|
| 76 |
+
return to == dtype
|
| 77 |
+
except TypeError:
|
| 78 |
+
# _result_type() raises if the dtypes don't promote together
|
| 79 |
+
return False
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
# These are internal objects for the return types of finfo and iinfo, since
|
| 83 |
+
# the NumPy versions contain extra data that isn't part of the spec.
|
| 84 |
+
@dataclass
|
| 85 |
+
class finfo_object:
|
| 86 |
+
bits: int
|
| 87 |
+
# Note: The types of the float data here are float, whereas in NumPy they
|
| 88 |
+
# are scalars of the corresponding float dtype.
|
| 89 |
+
eps: float
|
| 90 |
+
max: float
|
| 91 |
+
min: float
|
| 92 |
+
smallest_normal: float
|
| 93 |
+
dtype: Dtype
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
@dataclass
|
| 97 |
+
class iinfo_object:
|
| 98 |
+
bits: int
|
| 99 |
+
max: int
|
| 100 |
+
min: int
|
| 101 |
+
dtype: Dtype
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def finfo(type: Union[Dtype, Array], /) -> finfo_object:
|
| 105 |
+
"""
|
| 106 |
+
Array API compatible wrapper for :py:func:`np.finfo <numpy.finfo>`.
|
| 107 |
+
|
| 108 |
+
See its docstring for more information.
|
| 109 |
+
"""
|
| 110 |
+
fi = np.finfo(type)
|
| 111 |
+
# Note: The types of the float data here are float, whereas in NumPy they
|
| 112 |
+
# are scalars of the corresponding float dtype.
|
| 113 |
+
return finfo_object(
|
| 114 |
+
fi.bits,
|
| 115 |
+
float(fi.eps),
|
| 116 |
+
float(fi.max),
|
| 117 |
+
float(fi.min),
|
| 118 |
+
float(fi.smallest_normal),
|
| 119 |
+
fi.dtype,
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def iinfo(type: Union[Dtype, Array], /) -> iinfo_object:
|
| 124 |
+
"""
|
| 125 |
+
Array API compatible wrapper for :py:func:`np.iinfo <numpy.iinfo>`.
|
| 126 |
+
|
| 127 |
+
See its docstring for more information.
|
| 128 |
+
"""
|
| 129 |
+
ii = np.iinfo(type)
|
| 130 |
+
return iinfo_object(ii.bits, ii.max, ii.min, ii.dtype)
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
# Note: isdtype is a new function from the 2022.12 array API specification.
|
| 134 |
+
def isdtype(
|
| 135 |
+
dtype: Dtype, kind: Union[Dtype, str, Tuple[Union[Dtype, str], ...]]
|
| 136 |
+
) -> bool:
|
| 137 |
+
"""
|
| 138 |
+
Returns a boolean indicating whether a provided dtype is of a specified data type ``kind``.
|
| 139 |
+
|
| 140 |
+
See
|
| 141 |
+
https://data-apis.org/array-api/latest/API_specification/generated/array_api.isdtype.html
|
| 142 |
+
for more details
|
| 143 |
+
"""
|
| 144 |
+
if isinstance(kind, tuple):
|
| 145 |
+
# Disallow nested tuples
|
| 146 |
+
if any(isinstance(k, tuple) for k in kind):
|
| 147 |
+
raise TypeError("'kind' must be a dtype, str, or tuple of dtypes and strs")
|
| 148 |
+
return any(isdtype(dtype, k) for k in kind)
|
| 149 |
+
elif isinstance(kind, str):
|
| 150 |
+
if kind == 'bool':
|
| 151 |
+
return dtype in _boolean_dtypes
|
| 152 |
+
elif kind == 'signed integer':
|
| 153 |
+
return dtype in _signed_integer_dtypes
|
| 154 |
+
elif kind == 'unsigned integer':
|
| 155 |
+
return dtype in _unsigned_integer_dtypes
|
| 156 |
+
elif kind == 'integral':
|
| 157 |
+
return dtype in _integer_dtypes
|
| 158 |
+
elif kind == 'real floating':
|
| 159 |
+
return dtype in _real_floating_dtypes
|
| 160 |
+
elif kind == 'complex floating':
|
| 161 |
+
return dtype in _complex_floating_dtypes
|
| 162 |
+
elif kind == 'numeric':
|
| 163 |
+
return dtype in _numeric_dtypes
|
| 164 |
+
else:
|
| 165 |
+
raise ValueError(f"Unrecognized data type kind: {kind!r}")
|
| 166 |
+
elif kind in _all_dtypes:
|
| 167 |
+
return dtype == kind
|
| 168 |
+
else:
|
| 169 |
+
raise TypeError(f"'kind' must be a dtype, str, or tuple of dtypes and strs, not {type(kind).__name__}")
|
| 170 |
+
|
| 171 |
+
def result_type(*arrays_and_dtypes: Union[Array, Dtype]) -> Dtype:
|
| 172 |
+
"""
|
| 173 |
+
Array API compatible wrapper for :py:func:`np.result_type <numpy.result_type>`.
|
| 174 |
+
|
| 175 |
+
See its docstring for more information.
|
| 176 |
+
"""
|
| 177 |
+
# Note: we use a custom implementation that gives only the type promotions
|
| 178 |
+
# required by the spec rather than using np.result_type. NumPy implements
|
| 179 |
+
# too many extra type promotions like int64 + uint64 -> float64, and does
|
| 180 |
+
# value-based casting on scalar arrays.
|
| 181 |
+
A = []
|
| 182 |
+
for a in arrays_and_dtypes:
|
| 183 |
+
if isinstance(a, Array):
|
| 184 |
+
a = a.dtype
|
| 185 |
+
elif isinstance(a, np.ndarray) or a not in _all_dtypes:
|
| 186 |
+
raise TypeError("result_type() inputs must be array_api arrays or dtypes")
|
| 187 |
+
A.append(a)
|
| 188 |
+
|
| 189 |
+
if len(A) == 0:
|
| 190 |
+
raise ValueError("at least one array or dtype is required")
|
| 191 |
+
elif len(A) == 1:
|
| 192 |
+
return A[0]
|
| 193 |
+
else:
|
| 194 |
+
t = A[0]
|
| 195 |
+
for t2 in A[1:]:
|
| 196 |
+
t = _result_type(t, t2)
|
| 197 |
+
return t
|
mgm/lib/python3.10/site-packages/numpy/array_api/_dtypes.py
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
# Note: we use dtype objects instead of dtype classes. The spec does not
|
| 4 |
+
# require any behavior on dtypes other than equality.
|
| 5 |
+
int8 = np.dtype("int8")
|
| 6 |
+
int16 = np.dtype("int16")
|
| 7 |
+
int32 = np.dtype("int32")
|
| 8 |
+
int64 = np.dtype("int64")
|
| 9 |
+
uint8 = np.dtype("uint8")
|
| 10 |
+
uint16 = np.dtype("uint16")
|
| 11 |
+
uint32 = np.dtype("uint32")
|
| 12 |
+
uint64 = np.dtype("uint64")
|
| 13 |
+
float32 = np.dtype("float32")
|
| 14 |
+
float64 = np.dtype("float64")
|
| 15 |
+
complex64 = np.dtype("complex64")
|
| 16 |
+
complex128 = np.dtype("complex128")
|
| 17 |
+
# Note: This name is changed
|
| 18 |
+
bool = np.dtype("bool")
|
| 19 |
+
|
| 20 |
+
_all_dtypes = (
|
| 21 |
+
int8,
|
| 22 |
+
int16,
|
| 23 |
+
int32,
|
| 24 |
+
int64,
|
| 25 |
+
uint8,
|
| 26 |
+
uint16,
|
| 27 |
+
uint32,
|
| 28 |
+
uint64,
|
| 29 |
+
float32,
|
| 30 |
+
float64,
|
| 31 |
+
complex64,
|
| 32 |
+
complex128,
|
| 33 |
+
bool,
|
| 34 |
+
)
|
| 35 |
+
_boolean_dtypes = (bool,)
|
| 36 |
+
_real_floating_dtypes = (float32, float64)
|
| 37 |
+
_floating_dtypes = (float32, float64, complex64, complex128)
|
| 38 |
+
_complex_floating_dtypes = (complex64, complex128)
|
| 39 |
+
_integer_dtypes = (int8, int16, int32, int64, uint8, uint16, uint32, uint64)
|
| 40 |
+
_signed_integer_dtypes = (int8, int16, int32, int64)
|
| 41 |
+
_unsigned_integer_dtypes = (uint8, uint16, uint32, uint64)
|
| 42 |
+
_integer_or_boolean_dtypes = (
|
| 43 |
+
bool,
|
| 44 |
+
int8,
|
| 45 |
+
int16,
|
| 46 |
+
int32,
|
| 47 |
+
int64,
|
| 48 |
+
uint8,
|
| 49 |
+
uint16,
|
| 50 |
+
uint32,
|
| 51 |
+
uint64,
|
| 52 |
+
)
|
| 53 |
+
_real_numeric_dtypes = (
|
| 54 |
+
float32,
|
| 55 |
+
float64,
|
| 56 |
+
int8,
|
| 57 |
+
int16,
|
| 58 |
+
int32,
|
| 59 |
+
int64,
|
| 60 |
+
uint8,
|
| 61 |
+
uint16,
|
| 62 |
+
uint32,
|
| 63 |
+
uint64,
|
| 64 |
+
)
|
| 65 |
+
_numeric_dtypes = (
|
| 66 |
+
float32,
|
| 67 |
+
float64,
|
| 68 |
+
complex64,
|
| 69 |
+
complex128,
|
| 70 |
+
int8,
|
| 71 |
+
int16,
|
| 72 |
+
int32,
|
| 73 |
+
int64,
|
| 74 |
+
uint8,
|
| 75 |
+
uint16,
|
| 76 |
+
uint32,
|
| 77 |
+
uint64,
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
_dtype_categories = {
|
| 81 |
+
"all": _all_dtypes,
|
| 82 |
+
"real numeric": _real_numeric_dtypes,
|
| 83 |
+
"numeric": _numeric_dtypes,
|
| 84 |
+
"integer": _integer_dtypes,
|
| 85 |
+
"integer or boolean": _integer_or_boolean_dtypes,
|
| 86 |
+
"boolean": _boolean_dtypes,
|
| 87 |
+
"real floating-point": _floating_dtypes,
|
| 88 |
+
"complex floating-point": _complex_floating_dtypes,
|
| 89 |
+
"floating-point": _floating_dtypes,
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
# Note: the spec defines a restricted type promotion table compared to NumPy.
|
| 94 |
+
# In particular, cross-kind promotions like integer + float or boolean +
|
| 95 |
+
# integer are not allowed, even for functions that accept both kinds.
|
| 96 |
+
# Additionally, NumPy promotes signed integer + uint64 to float64, but this
|
| 97 |
+
# promotion is not allowed here. To be clear, Python scalar int objects are
|
| 98 |
+
# allowed to promote to floating-point dtypes, but only in array operators
|
| 99 |
+
# (see Array._promote_scalar) method in _array_object.py.
|
| 100 |
+
_promotion_table = {
|
| 101 |
+
(int8, int8): int8,
|
| 102 |
+
(int8, int16): int16,
|
| 103 |
+
(int8, int32): int32,
|
| 104 |
+
(int8, int64): int64,
|
| 105 |
+
(int16, int8): int16,
|
| 106 |
+
(int16, int16): int16,
|
| 107 |
+
(int16, int32): int32,
|
| 108 |
+
(int16, int64): int64,
|
| 109 |
+
(int32, int8): int32,
|
| 110 |
+
(int32, int16): int32,
|
| 111 |
+
(int32, int32): int32,
|
| 112 |
+
(int32, int64): int64,
|
| 113 |
+
(int64, int8): int64,
|
| 114 |
+
(int64, int16): int64,
|
| 115 |
+
(int64, int32): int64,
|
| 116 |
+
(int64, int64): int64,
|
| 117 |
+
(uint8, uint8): uint8,
|
| 118 |
+
(uint8, uint16): uint16,
|
| 119 |
+
(uint8, uint32): uint32,
|
| 120 |
+
(uint8, uint64): uint64,
|
| 121 |
+
(uint16, uint8): uint16,
|
| 122 |
+
(uint16, uint16): uint16,
|
| 123 |
+
(uint16, uint32): uint32,
|
| 124 |
+
(uint16, uint64): uint64,
|
| 125 |
+
(uint32, uint8): uint32,
|
| 126 |
+
(uint32, uint16): uint32,
|
| 127 |
+
(uint32, uint32): uint32,
|
| 128 |
+
(uint32, uint64): uint64,
|
| 129 |
+
(uint64, uint8): uint64,
|
| 130 |
+
(uint64, uint16): uint64,
|
| 131 |
+
(uint64, uint32): uint64,
|
| 132 |
+
(uint64, uint64): uint64,
|
| 133 |
+
(int8, uint8): int16,
|
| 134 |
+
(int8, uint16): int32,
|
| 135 |
+
(int8, uint32): int64,
|
| 136 |
+
(int16, uint8): int16,
|
| 137 |
+
(int16, uint16): int32,
|
| 138 |
+
(int16, uint32): int64,
|
| 139 |
+
(int32, uint8): int32,
|
| 140 |
+
(int32, uint16): int32,
|
| 141 |
+
(int32, uint32): int64,
|
| 142 |
+
(int64, uint8): int64,
|
| 143 |
+
(int64, uint16): int64,
|
| 144 |
+
(int64, uint32): int64,
|
| 145 |
+
(uint8, int8): int16,
|
| 146 |
+
(uint16, int8): int32,
|
| 147 |
+
(uint32, int8): int64,
|
| 148 |
+
(uint8, int16): int16,
|
| 149 |
+
(uint16, int16): int32,
|
| 150 |
+
(uint32, int16): int64,
|
| 151 |
+
(uint8, int32): int32,
|
| 152 |
+
(uint16, int32): int32,
|
| 153 |
+
(uint32, int32): int64,
|
| 154 |
+
(uint8, int64): int64,
|
| 155 |
+
(uint16, int64): int64,
|
| 156 |
+
(uint32, int64): int64,
|
| 157 |
+
(float32, float32): float32,
|
| 158 |
+
(float32, float64): float64,
|
| 159 |
+
(float64, float32): float64,
|
| 160 |
+
(float64, float64): float64,
|
| 161 |
+
(complex64, complex64): complex64,
|
| 162 |
+
(complex64, complex128): complex128,
|
| 163 |
+
(complex128, complex64): complex128,
|
| 164 |
+
(complex128, complex128): complex128,
|
| 165 |
+
(float32, complex64): complex64,
|
| 166 |
+
(float32, complex128): complex128,
|
| 167 |
+
(float64, complex64): complex128,
|
| 168 |
+
(float64, complex128): complex128,
|
| 169 |
+
(complex64, float32): complex64,
|
| 170 |
+
(complex64, float64): complex128,
|
| 171 |
+
(complex128, float32): complex128,
|
| 172 |
+
(complex128, float64): complex128,
|
| 173 |
+
(bool, bool): bool,
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def _result_type(type1, type2):
|
| 178 |
+
if (type1, type2) in _promotion_table:
|
| 179 |
+
return _promotion_table[type1, type2]
|
| 180 |
+
raise TypeError(f"{type1} and {type2} cannot be type promoted together")
|
mgm/lib/python3.10/site-packages/numpy/array_api/_indexing_functions.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from ._array_object import Array
|
| 4 |
+
from ._dtypes import _integer_dtypes
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
def take(x: Array, indices: Array, /, *, axis: Optional[int] = None) -> Array:
|
| 9 |
+
"""
|
| 10 |
+
Array API compatible wrapper for :py:func:`np.take <numpy.take>`.
|
| 11 |
+
|
| 12 |
+
See its docstring for more information.
|
| 13 |
+
"""
|
| 14 |
+
if axis is None and x.ndim != 1:
|
| 15 |
+
raise ValueError("axis must be specified when ndim > 1")
|
| 16 |
+
if indices.dtype not in _integer_dtypes:
|
| 17 |
+
raise TypeError("Only integer dtypes are allowed in indexing")
|
| 18 |
+
if indices.ndim != 1:
|
| 19 |
+
raise ValueError("Only 1-dim indices array is supported")
|
| 20 |
+
return Array._new(np.take(x._array, indices._array, axis=axis))
|
mgm/lib/python3.10/site-packages/numpy/array_api/_sorting_functions.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from ._array_object import Array
|
| 4 |
+
from ._dtypes import _real_numeric_dtypes
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# Note: the descending keyword argument is new in this function
|
| 10 |
+
def argsort(
|
| 11 |
+
x: Array, /, *, axis: int = -1, descending: bool = False, stable: bool = True
|
| 12 |
+
) -> Array:
|
| 13 |
+
"""
|
| 14 |
+
Array API compatible wrapper for :py:func:`np.argsort <numpy.argsort>`.
|
| 15 |
+
|
| 16 |
+
See its docstring for more information.
|
| 17 |
+
"""
|
| 18 |
+
if x.dtype not in _real_numeric_dtypes:
|
| 19 |
+
raise TypeError("Only real numeric dtypes are allowed in argsort")
|
| 20 |
+
# Note: this keyword argument is different, and the default is different.
|
| 21 |
+
kind = "stable" if stable else "quicksort"
|
| 22 |
+
if not descending:
|
| 23 |
+
res = np.argsort(x._array, axis=axis, kind=kind)
|
| 24 |
+
else:
|
| 25 |
+
# As NumPy has no native descending sort, we imitate it here. Note that
|
| 26 |
+
# simply flipping the results of np.argsort(x._array, ...) would not
|
| 27 |
+
# respect the relative order like it would in native descending sorts.
|
| 28 |
+
res = np.flip(
|
| 29 |
+
np.argsort(np.flip(x._array, axis=axis), axis=axis, kind=kind),
|
| 30 |
+
axis=axis,
|
| 31 |
+
)
|
| 32 |
+
# Rely on flip()/argsort() to validate axis
|
| 33 |
+
normalised_axis = axis if axis >= 0 else x.ndim + axis
|
| 34 |
+
max_i = x.shape[normalised_axis] - 1
|
| 35 |
+
res = max_i - res
|
| 36 |
+
return Array._new(res)
|
| 37 |
+
|
| 38 |
+
# Note: the descending keyword argument is new in this function
|
| 39 |
+
def sort(
|
| 40 |
+
x: Array, /, *, axis: int = -1, descending: bool = False, stable: bool = True
|
| 41 |
+
) -> Array:
|
| 42 |
+
"""
|
| 43 |
+
Array API compatible wrapper for :py:func:`np.sort <numpy.sort>`.
|
| 44 |
+
|
| 45 |
+
See its docstring for more information.
|
| 46 |
+
"""
|
| 47 |
+
if x.dtype not in _real_numeric_dtypes:
|
| 48 |
+
raise TypeError("Only real numeric dtypes are allowed in sort")
|
| 49 |
+
# Note: this keyword argument is different, and the default is different.
|
| 50 |
+
kind = "stable" if stable else "quicksort"
|
| 51 |
+
res = np.sort(x._array, axis=axis, kind=kind)
|
| 52 |
+
if descending:
|
| 53 |
+
res = np.flip(res, axis=axis)
|
| 54 |
+
return Array._new(res)
|
mgm/lib/python3.10/site-packages/numpy/array_api/_typing.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This file defines the types for type annotations.
|
| 3 |
+
|
| 4 |
+
These names aren't part of the module namespace, but they are used in the
|
| 5 |
+
annotations in the function signatures. The functions in the module are only
|
| 6 |
+
valid for inputs that match the given type annotations.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
__all__ = [
|
| 12 |
+
"Array",
|
| 13 |
+
"Device",
|
| 14 |
+
"Dtype",
|
| 15 |
+
"SupportsDLPack",
|
| 16 |
+
"SupportsBufferProtocol",
|
| 17 |
+
"PyCapsule",
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
import sys
|
| 21 |
+
|
| 22 |
+
from typing import (
|
| 23 |
+
Any,
|
| 24 |
+
Literal,
|
| 25 |
+
Sequence,
|
| 26 |
+
Type,
|
| 27 |
+
Union,
|
| 28 |
+
TypeVar,
|
| 29 |
+
Protocol,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
from ._array_object import Array
|
| 33 |
+
from numpy import (
|
| 34 |
+
dtype,
|
| 35 |
+
int8,
|
| 36 |
+
int16,
|
| 37 |
+
int32,
|
| 38 |
+
int64,
|
| 39 |
+
uint8,
|
| 40 |
+
uint16,
|
| 41 |
+
uint32,
|
| 42 |
+
uint64,
|
| 43 |
+
float32,
|
| 44 |
+
float64,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
_T_co = TypeVar("_T_co", covariant=True)
|
| 48 |
+
|
| 49 |
+
class NestedSequence(Protocol[_T_co]):
|
| 50 |
+
def __getitem__(self, key: int, /) -> _T_co | NestedSequence[_T_co]: ...
|
| 51 |
+
def __len__(self, /) -> int: ...
|
| 52 |
+
|
| 53 |
+
Device = Literal["cpu"]
|
| 54 |
+
|
| 55 |
+
Dtype = dtype[Union[
|
| 56 |
+
int8,
|
| 57 |
+
int16,
|
| 58 |
+
int32,
|
| 59 |
+
int64,
|
| 60 |
+
uint8,
|
| 61 |
+
uint16,
|
| 62 |
+
uint32,
|
| 63 |
+
uint64,
|
| 64 |
+
float32,
|
| 65 |
+
float64,
|
| 66 |
+
]]
|
| 67 |
+
|
| 68 |
+
if sys.version_info >= (3, 12):
|
| 69 |
+
from collections.abc import Buffer as SupportsBufferProtocol
|
| 70 |
+
else:
|
| 71 |
+
SupportsBufferProtocol = Any
|
| 72 |
+
|
| 73 |
+
PyCapsule = Any
|
| 74 |
+
|
| 75 |
+
class SupportsDLPack(Protocol):
|
| 76 |
+
def __dlpack__(self, /, *, stream: None = ...) -> PyCapsule: ...
|
mgm/lib/python3.10/site-packages/numpy/compat/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (630 Bytes). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/compat/__pycache__/py3k.cpython-310.pyc
ADDED
|
Binary file (4.72 kB). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/compat/tests/test_compat.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from os.path import join
|
| 2 |
+
from io import BufferedReader, BytesIO
|
| 3 |
+
|
| 4 |
+
from numpy.compat import isfileobj
|
| 5 |
+
from numpy.testing import assert_
|
| 6 |
+
from numpy.testing import tempdir
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def test_isfileobj():
|
| 10 |
+
with tempdir(prefix="numpy_test_compat_") as folder:
|
| 11 |
+
filename = join(folder, 'a.bin')
|
| 12 |
+
|
| 13 |
+
with open(filename, 'wb') as f:
|
| 14 |
+
assert_(isfileobj(f))
|
| 15 |
+
|
| 16 |
+
with open(filename, 'ab') as f:
|
| 17 |
+
assert_(isfileobj(f))
|
| 18 |
+
|
| 19 |
+
with open(filename, 'rb') as f:
|
| 20 |
+
assert_(isfileobj(f))
|
| 21 |
+
|
| 22 |
+
assert_(isfileobj(BufferedReader(BytesIO())) is False)
|
mgm/lib/python3.10/site-packages/numpy/doc/__pycache__/ufuncs.cpython-310.pyc
ADDED
|
Binary file (5.52 kB). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/random/LICENSE.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
**This software is dual-licensed under the The University of Illinois/NCSA
|
| 2 |
+
Open Source License (NCSA) and The 3-Clause BSD License**
|
| 3 |
+
|
| 4 |
+
# NCSA Open Source License
|
| 5 |
+
**Copyright (c) 2019 Kevin Sheppard. All rights reserved.**
|
| 6 |
+
|
| 7 |
+
Developed by: Kevin Sheppard (<kevin.sheppard@economics.ox.ac.uk>,
|
| 8 |
+
<kevin.k.sheppard@gmail.com>)
|
| 9 |
+
[http://www.kevinsheppard.com](http://www.kevinsheppard.com)
|
| 10 |
+
|
| 11 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 12 |
+
this software and associated documentation files (the "Software"), to deal with
|
| 13 |
+
the Software without restriction, including without limitation the rights to
|
| 14 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
| 15 |
+
of the Software, and to permit persons to whom the Software is furnished to do
|
| 16 |
+
so, subject to the following conditions:
|
| 17 |
+
|
| 18 |
+
Redistributions of source code must retain the above copyright notice, this
|
| 19 |
+
list of conditions and the following disclaimers.
|
| 20 |
+
|
| 21 |
+
Redistributions in binary form must reproduce the above copyright notice, this
|
| 22 |
+
list of conditions and the following disclaimers in the documentation and/or
|
| 23 |
+
other materials provided with the distribution.
|
| 24 |
+
|
| 25 |
+
Neither the names of Kevin Sheppard, nor the names of any contributors may be
|
| 26 |
+
used to endorse or promote products derived from this Software without specific
|
| 27 |
+
prior written permission.
|
| 28 |
+
|
| 29 |
+
**THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 30 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 31 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 32 |
+
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 33 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 34 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
|
| 35 |
+
THE SOFTWARE.**
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# 3-Clause BSD License
|
| 39 |
+
**Copyright (c) 2019 Kevin Sheppard. All rights reserved.**
|
| 40 |
+
|
| 41 |
+
Redistribution and use in source and binary forms, with or without
|
| 42 |
+
modification, are permitted provided that the following conditions are met:
|
| 43 |
+
|
| 44 |
+
1. Redistributions of source code must retain the above copyright notice,
|
| 45 |
+
this list of conditions and the following disclaimer.
|
| 46 |
+
|
| 47 |
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
| 48 |
+
this list of conditions and the following disclaimer in the documentation
|
| 49 |
+
and/or other materials provided with the distribution.
|
| 50 |
+
|
| 51 |
+
3. Neither the name of the copyright holder nor the names of its contributors
|
| 52 |
+
may be used to endorse or promote products derived from this software
|
| 53 |
+
without specific prior written permission.
|
| 54 |
+
|
| 55 |
+
**THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 56 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 57 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 58 |
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
| 59 |
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
| 60 |
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
| 61 |
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 62 |
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 63 |
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 64 |
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
| 65 |
+
THE POSSIBILITY OF SUCH DAMAGE.**
|
| 66 |
+
|
| 67 |
+
# Components
|
| 68 |
+
|
| 69 |
+
Many parts of this module have been derived from original sources,
|
| 70 |
+
often the algorithm's designer. Component licenses are located with
|
| 71 |
+
the component code.
|
mgm/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
|
mgm/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
|
mgm/lib/python3.10/site-packages/numpy/random/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (7.41 kB). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/random/__pycache__/_pickle.cpython-310.pyc
ADDED
|
Binary file (2.21 kB). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/random/_bounded_integers.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cc009884164d0c98b9ad76d899d8318cb2436e4caaa0034b48b6607b70efa5ad
|
| 3 |
+
size 379216
|
mgm/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)
|
mgm/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) noexcept nogil
|
| 43 |
+
ctypedef double (*random_double_0)(void *state) noexcept nogil
|
| 44 |
+
ctypedef double (*random_double_1)(void *state, double a) noexcept nogil
|
| 45 |
+
ctypedef double (*random_double_2)(void *state, double a, double b) noexcept nogil
|
| 46 |
+
ctypedef double (*random_double_3)(void *state, double a, double b, double c) noexcept nogil
|
| 47 |
+
|
| 48 |
+
ctypedef void (*random_float_fill)(bitgen_t *state, np.npy_intp count, float* out) noexcept nogil
|
| 49 |
+
ctypedef float (*random_float_0)(bitgen_t *state) noexcept nogil
|
| 50 |
+
ctypedef float (*random_float_1)(bitgen_t *state, float a) noexcept nogil
|
| 51 |
+
|
| 52 |
+
ctypedef int64_t (*random_uint_0)(void *state) noexcept nogil
|
| 53 |
+
ctypedef int64_t (*random_uint_d)(void *state, double a) noexcept nogil
|
| 54 |
+
ctypedef int64_t (*random_uint_dd)(void *state, double a, double b) noexcept nogil
|
| 55 |
+
ctypedef int64_t (*random_uint_di)(void *state, double a, uint64_t b) noexcept nogil
|
| 56 |
+
ctypedef int64_t (*random_uint_i)(void *state, int64_t a) noexcept nogil
|
| 57 |
+
ctypedef int64_t (*random_uint_iii)(void *state, int64_t a, int64_t b, int64_t c) noexcept nogil
|
| 58 |
+
|
| 59 |
+
ctypedef uint32_t (*random_uint_0_32)(bitgen_t *state) noexcept nogil
|
| 60 |
+
ctypedef uint32_t (*random_uint_1_i_32)(bitgen_t *state, uint32_t a) noexcept nogil
|
| 61 |
+
|
| 62 |
+
ctypedef int32_t (*random_int_2_i_32)(bitgen_t *state, int32_t a, int32_t b) noexcept nogil
|
| 63 |
+
ctypedef int64_t (*random_int_2_i)(bitgen_t *state, int64_t a, int64_t b) noexcept nogil
|
| 64 |
+
|
| 65 |
+
cdef double kahan_sum(double *darr, np.npy_intp n) noexcept
|
| 66 |
+
|
| 67 |
+
cdef inline double uint64_to_double(uint64_t rnd) noexcept 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)
|
mgm/lib/python3.10/site-packages/numpy/random/_examples/cffi/__pycache__/extending.cpython-310.pyc
ADDED
|
Binary file (924 Bytes). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/random/_examples/cffi/__pycache__/parse.cpython-310.pyc
ADDED
|
Binary file (1.18 kB). View file
|
|
|
mgm/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]
|
mgm/lib/python3.10/site-packages/numpy/random/_examples/cffi/parse.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 inline xxx(...) {'
|
| 40 |
+
# and ends with a closing '}'
|
| 41 |
+
if line.strip().startswith('static 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('RAND_INT_TYPE', 'int64_t')
|
| 52 |
+
s.append(line)
|
| 53 |
+
ffi.cdef('\n'.join(s))
|
| 54 |
+
|
mgm/lib/python3.10/site-packages/numpy/random/_examples/cython/extending.pyx
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
#cython: language_level=3
|
| 3 |
+
|
| 4 |
+
from libc.stdint cimport uint32_t
|
| 5 |
+
from cpython.pycapsule cimport PyCapsule_IsValid, PyCapsule_GetPointer
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
cimport numpy as np
|
| 9 |
+
cimport cython
|
| 10 |
+
|
| 11 |
+
from numpy.random cimport bitgen_t
|
| 12 |
+
from numpy.random import PCG64
|
| 13 |
+
|
| 14 |
+
np.import_array()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@cython.boundscheck(False)
|
| 18 |
+
@cython.wraparound(False)
|
| 19 |
+
def uniform_mean(Py_ssize_t n):
|
| 20 |
+
cdef Py_ssize_t i
|
| 21 |
+
cdef bitgen_t *rng
|
| 22 |
+
cdef const char *capsule_name = "BitGenerator"
|
| 23 |
+
cdef double[::1] random_values
|
| 24 |
+
cdef np.ndarray randoms
|
| 25 |
+
|
| 26 |
+
x = PCG64()
|
| 27 |
+
capsule = x.capsule
|
| 28 |
+
if not PyCapsule_IsValid(capsule, capsule_name):
|
| 29 |
+
raise ValueError("Invalid pointer to anon_func_state")
|
| 30 |
+
rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
|
| 31 |
+
random_values = np.empty(n)
|
| 32 |
+
# Best practice is to acquire the lock whenever generating random values.
|
| 33 |
+
# This prevents other threads from modifying the state. Acquiring the lock
|
| 34 |
+
# is only necessary if the GIL is also released, as in this example.
|
| 35 |
+
with x.lock, nogil:
|
| 36 |
+
for i in range(n):
|
| 37 |
+
random_values[i] = rng.next_double(rng.state)
|
| 38 |
+
randoms = np.asarray(random_values)
|
| 39 |
+
return randoms.mean()
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# This function is declared nogil so it can be used without the GIL below
|
| 43 |
+
cdef uint32_t bounded_uint(uint32_t lb, uint32_t ub, bitgen_t *rng) nogil:
|
| 44 |
+
cdef uint32_t mask, delta, val
|
| 45 |
+
mask = delta = ub - lb
|
| 46 |
+
mask |= mask >> 1
|
| 47 |
+
mask |= mask >> 2
|
| 48 |
+
mask |= mask >> 4
|
| 49 |
+
mask |= mask >> 8
|
| 50 |
+
mask |= mask >> 16
|
| 51 |
+
|
| 52 |
+
val = rng.next_uint32(rng.state) & mask
|
| 53 |
+
while val > delta:
|
| 54 |
+
val = rng.next_uint32(rng.state) & mask
|
| 55 |
+
|
| 56 |
+
return lb + val
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
@cython.boundscheck(False)
|
| 60 |
+
@cython.wraparound(False)
|
| 61 |
+
def bounded_uints(uint32_t lb, uint32_t ub, Py_ssize_t n):
|
| 62 |
+
cdef Py_ssize_t i
|
| 63 |
+
cdef bitgen_t *rng
|
| 64 |
+
cdef uint32_t[::1] out
|
| 65 |
+
cdef const char *capsule_name = "BitGenerator"
|
| 66 |
+
|
| 67 |
+
x = PCG64()
|
| 68 |
+
out = np.empty(n, dtype=np.uint32)
|
| 69 |
+
capsule = x.capsule
|
| 70 |
+
|
| 71 |
+
if not PyCapsule_IsValid(capsule, capsule_name):
|
| 72 |
+
raise ValueError("Invalid pointer to anon_func_state")
|
| 73 |
+
rng = <bitgen_t *>PyCapsule_GetPointer(capsule, capsule_name)
|
| 74 |
+
|
| 75 |
+
with x.lock, nogil:
|
| 76 |
+
for i in range(n):
|
| 77 |
+
out[i] = bounded_uint(lb, ub, rng)
|
| 78 |
+
return np.asarray(out)
|
mgm/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 |
+
|
mgm/lib/python3.10/site-packages/numpy/random/_examples/cython/meson.build
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
project('random-build-examples', 'c', 'cpp', 'cython')
|
| 2 |
+
|
| 3 |
+
py_mod = import('python')
|
| 4 |
+
py3 = py_mod.find_installation(pure: false)
|
| 5 |
+
|
| 6 |
+
cc = meson.get_compiler('c')
|
| 7 |
+
cy = meson.get_compiler('cython')
|
| 8 |
+
|
| 9 |
+
if not cy.version().version_compare('>=0.29.35')
|
| 10 |
+
error('tests requires Cython >= 0.29.35')
|
| 11 |
+
endif
|
| 12 |
+
|
| 13 |
+
_numpy_abs = run_command(py3, ['-c',
|
| 14 |
+
'import os; os.chdir(".."); import numpy; print(os.path.abspath(numpy.get_include() + "../../.."))'],
|
| 15 |
+
check: true).stdout().strip()
|
| 16 |
+
|
| 17 |
+
npymath_path = _numpy_abs / 'core' / 'lib'
|
| 18 |
+
npy_include_path = _numpy_abs / 'core' / 'include'
|
| 19 |
+
npyrandom_path = _numpy_abs / 'random' / 'lib'
|
| 20 |
+
npymath_lib = cc.find_library('npymath', dirs: npymath_path)
|
| 21 |
+
npyrandom_lib = cc.find_library('npyrandom', dirs: npyrandom_path)
|
| 22 |
+
|
| 23 |
+
py3.extension_module(
|
| 24 |
+
'extending_distributions',
|
| 25 |
+
'extending_distributions.pyx',
|
| 26 |
+
install: false,
|
| 27 |
+
include_directories: [npy_include_path],
|
| 28 |
+
dependencies: [npyrandom_lib, npymath_lib],
|
| 29 |
+
)
|
| 30 |
+
py3.extension_module(
|
| 31 |
+
'extending',
|
| 32 |
+
'extending.pyx',
|
| 33 |
+
install: false,
|
| 34 |
+
include_directories: [npy_include_path],
|
| 35 |
+
dependencies: [npyrandom_lib, npymath_lib],
|
| 36 |
+
)
|
| 37 |
+
py3.extension_module(
|
| 38 |
+
'extending_cpp',
|
| 39 |
+
'extending_distributions.pyx',
|
| 40 |
+
install: false,
|
| 41 |
+
override_options : ['cython_language=cpp'],
|
| 42 |
+
cython_args: ['--module-name', 'extending_cpp'],
|
| 43 |
+
include_directories: [npy_include_path],
|
| 44 |
+
dependencies: [npyrandom_lib, npymath_lib],
|
| 45 |
+
)
|
mgm/lib/python3.10/site-packages/numpy/random/_examples/numba/__pycache__/extending.cpython-310.pyc
ADDED
|
Binary file (2.16 kB). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/random/_examples/numba/__pycache__/extending_distributions.cpython-310.pyc
ADDED
|
Binary file (2.09 kB). View file
|
|
|
mgm/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 |
+
|
mgm/lib/python3.10/site-packages/numpy/random/_examples/numba/extending_distributions.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
r"""
|
| 2 |
+
Building the required library in this example requires a source distribution
|
| 3 |
+
of NumPy or clone of the NumPy git repository since distributions.c is not
|
| 4 |
+
included in binary distributions.
|
| 5 |
+
|
| 6 |
+
On *nix, execute in numpy/random/src/distributions
|
| 7 |
+
|
| 8 |
+
export ${PYTHON_VERSION}=3.8 # Python version
|
| 9 |
+
export PYTHON_INCLUDE=#path to Python's include folder, usually \
|
| 10 |
+
${PYTHON_HOME}/include/python${PYTHON_VERSION}m
|
| 11 |
+
export NUMPY_INCLUDE=#path to numpy's include folder, usually \
|
| 12 |
+
${PYTHON_HOME}/lib/python${PYTHON_VERSION}/site-packages/numpy/core/include
|
| 13 |
+
gcc -shared -o libdistributions.so -fPIC distributions.c \
|
| 14 |
+
-I${NUMPY_INCLUDE} -I${PYTHON_INCLUDE}
|
| 15 |
+
mv libdistributions.so ../../_examples/numba/
|
| 16 |
+
|
| 17 |
+
On Windows
|
| 18 |
+
|
| 19 |
+
rem PYTHON_HOME and PYTHON_VERSION are setup dependent, this is an example
|
| 20 |
+
set PYTHON_HOME=c:\Anaconda
|
| 21 |
+
set PYTHON_VERSION=38
|
| 22 |
+
cl.exe /LD .\distributions.c -DDLL_EXPORT \
|
| 23 |
+
-I%PYTHON_HOME%\lib\site-packages\numpy\core\include \
|
| 24 |
+
-I%PYTHON_HOME%\include %PYTHON_HOME%\libs\python%PYTHON_VERSION%.lib
|
| 25 |
+
move distributions.dll ../../_examples/numba/
|
| 26 |
+
"""
|
| 27 |
+
import os
|
| 28 |
+
|
| 29 |
+
import numba as nb
|
| 30 |
+
import numpy as np
|
| 31 |
+
from cffi import FFI
|
| 32 |
+
|
| 33 |
+
from numpy.random import PCG64
|
| 34 |
+
|
| 35 |
+
ffi = FFI()
|
| 36 |
+
if os.path.exists('./distributions.dll'):
|
| 37 |
+
lib = ffi.dlopen('./distributions.dll')
|
| 38 |
+
elif os.path.exists('./libdistributions.so'):
|
| 39 |
+
lib = ffi.dlopen('./libdistributions.so')
|
| 40 |
+
else:
|
| 41 |
+
raise RuntimeError('Required DLL/so file was not found.')
|
| 42 |
+
|
| 43 |
+
ffi.cdef("""
|
| 44 |
+
double random_standard_normal(void *bitgen_state);
|
| 45 |
+
""")
|
| 46 |
+
x = PCG64()
|
| 47 |
+
xffi = x.cffi
|
| 48 |
+
bit_generator = xffi.bit_generator
|
| 49 |
+
|
| 50 |
+
random_standard_normal = lib.random_standard_normal
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def normals(n, bit_generator):
|
| 54 |
+
out = np.empty(n)
|
| 55 |
+
for i in range(n):
|
| 56 |
+
out[i] = random_standard_normal(bit_generator)
|
| 57 |
+
return out
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
normalsj = nb.jit(normals, nopython=True)
|
| 61 |
+
|
| 62 |
+
# Numba requires a memory address for void *
|
| 63 |
+
# Can also get address from x.ctypes.bit_generator.value
|
| 64 |
+
bit_generator_address = int(ffi.cast('uintptr_t', bit_generator))
|
| 65 |
+
|
| 66 |
+
norm = normalsj(1000, bit_generator_address)
|
| 67 |
+
print(norm[:12])
|
mgm/lib/python3.10/site-packages/numpy/random/_mt19937.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d30bd4b7d986fc29800bd588c70d3223143932ddc802bdc46d72197fbc096c11
|
| 3 |
+
size 120224
|
mgm/lib/python3.10/site-packages/numpy/random/_pcg64.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:646d4a06bdf86066d285398a89f1f610601d755f9a774b25c7316db9ec404eab
|
| 3 |
+
size 126400
|
mgm/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: ...
|
mgm/lib/python3.10/site-packages/numpy/random/_sfc64.cpython-310-x86_64-linux-gnu.so
ADDED
|
Binary file (76.7 kB). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/random/bit_generator.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d4ee3d720f9eee0541548507dc7fe2f323ea481cdc33e37906fe78bc2e981a0d
|
| 3 |
+
size 246536
|
mgm/lib/python3.10/site-packages/numpy/random/bit_generator.pxd
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
cdef class BitGenerator():
|
| 15 |
+
cdef readonly object _seed_seq
|
| 16 |
+
cdef readonly object lock
|
| 17 |
+
cdef bitgen_t _bitgen
|
| 18 |
+
cdef readonly object _ctypes
|
| 19 |
+
cdef readonly object _cffi
|
| 20 |
+
cdef readonly object capsule
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
cdef class SeedSequence():
|
| 24 |
+
cdef readonly object entropy
|
| 25 |
+
cdef readonly tuple spawn_key
|
| 26 |
+
cdef readonly Py_ssize_t pool_size
|
| 27 |
+
cdef readonly object pool
|
| 28 |
+
cdef readonly uint32_t n_children_spawned
|
| 29 |
+
|
| 30 |
+
cdef mix_entropy(self, np.ndarray[np.npy_uint32, ndim=1] mixer,
|
| 31 |
+
np.ndarray[np.npy_uint32, ndim=1] entropy_array)
|
| 32 |
+
cdef get_assembled_entropy(self)
|
| 33 |
+
|
| 34 |
+
cdef class SeedlessSequence():
|
| 35 |
+
pass
|
mgm/lib/python3.10/site-packages/numpy/random/bit_generator.pyi
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import abc
|
| 2 |
+
from threading import Lock
|
| 3 |
+
from collections.abc import Callable, Mapping, Sequence
|
| 4 |
+
from typing import (
|
| 5 |
+
Any,
|
| 6 |
+
NamedTuple,
|
| 7 |
+
TypedDict,
|
| 8 |
+
TypeVar,
|
| 9 |
+
Union,
|
| 10 |
+
overload,
|
| 11 |
+
Literal,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
from numpy import dtype, ndarray, uint32, uint64
|
| 15 |
+
from numpy._typing import _ArrayLikeInt_co, _ShapeLike, _SupportsDType, _UInt32Codes, _UInt64Codes
|
| 16 |
+
|
| 17 |
+
_T = TypeVar("_T")
|
| 18 |
+
|
| 19 |
+
_DTypeLikeUint32 = Union[
|
| 20 |
+
dtype[uint32],
|
| 21 |
+
_SupportsDType[dtype[uint32]],
|
| 22 |
+
type[uint32],
|
| 23 |
+
_UInt32Codes,
|
| 24 |
+
]
|
| 25 |
+
_DTypeLikeUint64 = Union[
|
| 26 |
+
dtype[uint64],
|
| 27 |
+
_SupportsDType[dtype[uint64]],
|
| 28 |
+
type[uint64],
|
| 29 |
+
_UInt64Codes,
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
class _SeedSeqState(TypedDict):
|
| 33 |
+
entropy: None | int | Sequence[int]
|
| 34 |
+
spawn_key: tuple[int, ...]
|
| 35 |
+
pool_size: int
|
| 36 |
+
n_children_spawned: int
|
| 37 |
+
|
| 38 |
+
class _Interface(NamedTuple):
|
| 39 |
+
state_address: Any
|
| 40 |
+
state: Any
|
| 41 |
+
next_uint64: Any
|
| 42 |
+
next_uint32: Any
|
| 43 |
+
next_double: Any
|
| 44 |
+
bit_generator: Any
|
| 45 |
+
|
| 46 |
+
class ISeedSequence(abc.ABC):
|
| 47 |
+
@abc.abstractmethod
|
| 48 |
+
def generate_state(
|
| 49 |
+
self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ...
|
| 50 |
+
) -> ndarray[Any, dtype[uint32 | uint64]]: ...
|
| 51 |
+
|
| 52 |
+
class ISpawnableSeedSequence(ISeedSequence):
|
| 53 |
+
@abc.abstractmethod
|
| 54 |
+
def spawn(self: _T, n_children: int) -> list[_T]: ...
|
| 55 |
+
|
| 56 |
+
class SeedlessSeedSequence(ISpawnableSeedSequence):
|
| 57 |
+
def generate_state(
|
| 58 |
+
self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ...
|
| 59 |
+
) -> ndarray[Any, dtype[uint32 | uint64]]: ...
|
| 60 |
+
def spawn(self: _T, n_children: int) -> list[_T]: ...
|
| 61 |
+
|
| 62 |
+
class SeedSequence(ISpawnableSeedSequence):
|
| 63 |
+
entropy: None | int | Sequence[int]
|
| 64 |
+
spawn_key: tuple[int, ...]
|
| 65 |
+
pool_size: int
|
| 66 |
+
n_children_spawned: int
|
| 67 |
+
pool: ndarray[Any, dtype[uint32]]
|
| 68 |
+
def __init__(
|
| 69 |
+
self,
|
| 70 |
+
entropy: None | int | Sequence[int] | _ArrayLikeInt_co = ...,
|
| 71 |
+
*,
|
| 72 |
+
spawn_key: Sequence[int] = ...,
|
| 73 |
+
pool_size: int = ...,
|
| 74 |
+
n_children_spawned: int = ...,
|
| 75 |
+
) -> None: ...
|
| 76 |
+
def __repr__(self) -> str: ...
|
| 77 |
+
@property
|
| 78 |
+
def state(
|
| 79 |
+
self,
|
| 80 |
+
) -> _SeedSeqState: ...
|
| 81 |
+
def generate_state(
|
| 82 |
+
self, n_words: int, dtype: _DTypeLikeUint32 | _DTypeLikeUint64 = ...
|
| 83 |
+
) -> ndarray[Any, dtype[uint32 | uint64]]: ...
|
| 84 |
+
def spawn(self, n_children: int) -> list[SeedSequence]: ...
|
| 85 |
+
|
| 86 |
+
class BitGenerator(abc.ABC):
|
| 87 |
+
lock: Lock
|
| 88 |
+
def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
|
| 89 |
+
def __getstate__(self) -> dict[str, Any]: ...
|
| 90 |
+
def __setstate__(self, state: dict[str, Any]) -> None: ...
|
| 91 |
+
def __reduce__(
|
| 92 |
+
self,
|
| 93 |
+
) -> tuple[Callable[[str], BitGenerator], tuple[str], tuple[dict[str, Any]]]: ...
|
| 94 |
+
@abc.abstractmethod
|
| 95 |
+
@property
|
| 96 |
+
def state(self) -> Mapping[str, Any]: ...
|
| 97 |
+
@state.setter
|
| 98 |
+
def state(self, value: Mapping[str, Any]) -> None: ...
|
| 99 |
+
@property
|
| 100 |
+
def seed_seq(self) -> ISeedSequence: ...
|
| 101 |
+
def spawn(self, n_children: int) -> list[BitGenerator]: ...
|
| 102 |
+
@overload
|
| 103 |
+
def random_raw(self, size: None = ..., output: Literal[True] = ...) -> int: ... # type: ignore[misc]
|
| 104 |
+
@overload
|
| 105 |
+
def random_raw(self, size: _ShapeLike = ..., output: Literal[True] = ...) -> ndarray[Any, dtype[uint64]]: ... # type: ignore[misc]
|
| 106 |
+
@overload
|
| 107 |
+
def random_raw(self, size: None | _ShapeLike = ..., output: Literal[False] = ...) -> None: ... # type: ignore[misc]
|
| 108 |
+
def _benchmark(self, cnt: int, method: str = ...) -> None: ...
|
| 109 |
+
@property
|
| 110 |
+
def ctypes(self) -> _Interface: ...
|
| 111 |
+
@property
|
| 112 |
+
def cffi(self) -> _Interface: ...
|
mgm/lib/python3.10/site-packages/numpy/random/c_distributions.pxd
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!python
|
| 2 |
+
#cython: wraparound=False, nonecheck=False, boundscheck=False, cdivision=True, language_level=3
|
| 3 |
+
from numpy cimport npy_intp
|
| 4 |
+
|
| 5 |
+
from libc.stdint cimport (uint64_t, int32_t, int64_t)
|
| 6 |
+
from numpy.random cimport bitgen_t
|
| 7 |
+
|
| 8 |
+
cdef extern from "numpy/random/distributions.h":
|
| 9 |
+
|
| 10 |
+
struct s_binomial_t:
|
| 11 |
+
int has_binomial
|
| 12 |
+
double psave
|
| 13 |
+
int64_t nsave
|
| 14 |
+
double r
|
| 15 |
+
double q
|
| 16 |
+
double fm
|
| 17 |
+
int64_t m
|
| 18 |
+
double p1
|
| 19 |
+
double xm
|
| 20 |
+
double xl
|
| 21 |
+
double xr
|
| 22 |
+
double c
|
| 23 |
+
double laml
|
| 24 |
+
double lamr
|
| 25 |
+
double p2
|
| 26 |
+
double p3
|
| 27 |
+
double p4
|
| 28 |
+
|
| 29 |
+
ctypedef s_binomial_t binomial_t
|
| 30 |
+
|
| 31 |
+
float random_standard_uniform_f(bitgen_t *bitgen_state) nogil
|
| 32 |
+
double random_standard_uniform(bitgen_t *bitgen_state) nogil
|
| 33 |
+
void random_standard_uniform_fill(bitgen_t* bitgen_state, npy_intp cnt, double *out) nogil
|
| 34 |
+
void random_standard_uniform_fill_f(bitgen_t *bitgen_state, npy_intp cnt, float *out) nogil
|
| 35 |
+
|
| 36 |
+
double random_standard_exponential(bitgen_t *bitgen_state) nogil
|
| 37 |
+
float random_standard_exponential_f(bitgen_t *bitgen_state) nogil
|
| 38 |
+
void random_standard_exponential_fill(bitgen_t *bitgen_state, npy_intp cnt, double *out) nogil
|
| 39 |
+
void random_standard_exponential_fill_f(bitgen_t *bitgen_state, npy_intp cnt, float *out) nogil
|
| 40 |
+
void random_standard_exponential_inv_fill(bitgen_t *bitgen_state, npy_intp cnt, double *out) nogil
|
| 41 |
+
void random_standard_exponential_inv_fill_f(bitgen_t *bitgen_state, npy_intp cnt, float *out) nogil
|
| 42 |
+
|
| 43 |
+
double random_standard_normal(bitgen_t* bitgen_state) nogil
|
| 44 |
+
float random_standard_normal_f(bitgen_t *bitgen_state) nogil
|
| 45 |
+
void random_standard_normal_fill(bitgen_t *bitgen_state, npy_intp count, double *out) nogil
|
| 46 |
+
void random_standard_normal_fill_f(bitgen_t *bitgen_state, npy_intp count, float *out) nogil
|
| 47 |
+
double random_standard_gamma(bitgen_t *bitgen_state, double shape) nogil
|
| 48 |
+
float random_standard_gamma_f(bitgen_t *bitgen_state, float shape) nogil
|
| 49 |
+
|
| 50 |
+
float random_standard_uniform_f(bitgen_t *bitgen_state) nogil
|
| 51 |
+
void random_standard_uniform_fill_f(bitgen_t* bitgen_state, npy_intp cnt, float *out) nogil
|
| 52 |
+
float random_standard_normal_f(bitgen_t* bitgen_state) nogil
|
| 53 |
+
float random_standard_gamma_f(bitgen_t *bitgen_state, float shape) nogil
|
| 54 |
+
|
| 55 |
+
int64_t random_positive_int64(bitgen_t *bitgen_state) nogil
|
| 56 |
+
int32_t random_positive_int32(bitgen_t *bitgen_state) nogil
|
| 57 |
+
int64_t random_positive_int(bitgen_t *bitgen_state) nogil
|
| 58 |
+
uint64_t random_uint(bitgen_t *bitgen_state) nogil
|
| 59 |
+
|
| 60 |
+
double random_normal(bitgen_t *bitgen_state, double loc, double scale) nogil
|
| 61 |
+
|
| 62 |
+
double random_gamma(bitgen_t *bitgen_state, double shape, double scale) nogil
|
| 63 |
+
float random_gamma_f(bitgen_t *bitgen_state, float shape, float scale) nogil
|
| 64 |
+
|
| 65 |
+
double random_exponential(bitgen_t *bitgen_state, double scale) nogil
|
| 66 |
+
double random_uniform(bitgen_t *bitgen_state, double lower, double range) nogil
|
| 67 |
+
double random_beta(bitgen_t *bitgen_state, double a, double b) nogil
|
| 68 |
+
double random_chisquare(bitgen_t *bitgen_state, double df) nogil
|
| 69 |
+
double random_f(bitgen_t *bitgen_state, double dfnum, double dfden) nogil
|
| 70 |
+
double random_standard_cauchy(bitgen_t *bitgen_state) nogil
|
| 71 |
+
double random_pareto(bitgen_t *bitgen_state, double a) nogil
|
| 72 |
+
double random_weibull(bitgen_t *bitgen_state, double a) nogil
|
| 73 |
+
double random_power(bitgen_t *bitgen_state, double a) nogil
|
| 74 |
+
double random_laplace(bitgen_t *bitgen_state, double loc, double scale) nogil
|
| 75 |
+
double random_gumbel(bitgen_t *bitgen_state, double loc, double scale) nogil
|
| 76 |
+
double random_logistic(bitgen_t *bitgen_state, double loc, double scale) nogil
|
| 77 |
+
double random_lognormal(bitgen_t *bitgen_state, double mean, double sigma) nogil
|
| 78 |
+
double random_rayleigh(bitgen_t *bitgen_state, double mode) nogil
|
| 79 |
+
double random_standard_t(bitgen_t *bitgen_state, double df) nogil
|
| 80 |
+
double random_noncentral_chisquare(bitgen_t *bitgen_state, double df,
|
| 81 |
+
double nonc) nogil
|
| 82 |
+
double random_noncentral_f(bitgen_t *bitgen_state, double dfnum,
|
| 83 |
+
double dfden, double nonc) nogil
|
| 84 |
+
double random_wald(bitgen_t *bitgen_state, double mean, double scale) nogil
|
| 85 |
+
double random_vonmises(bitgen_t *bitgen_state, double mu, double kappa) nogil
|
| 86 |
+
double random_triangular(bitgen_t *bitgen_state, double left, double mode,
|
| 87 |
+
double right) nogil
|
| 88 |
+
|
| 89 |
+
int64_t random_poisson(bitgen_t *bitgen_state, double lam) nogil
|
| 90 |
+
int64_t random_negative_binomial(bitgen_t *bitgen_state, double n, double p) nogil
|
| 91 |
+
int64_t random_binomial(bitgen_t *bitgen_state, double p, int64_t n, binomial_t *binomial) nogil
|
| 92 |
+
int64_t random_logseries(bitgen_t *bitgen_state, double p) nogil
|
| 93 |
+
int64_t random_geometric_search(bitgen_t *bitgen_state, double p) nogil
|
| 94 |
+
int64_t random_geometric_inversion(bitgen_t *bitgen_state, double p) nogil
|
| 95 |
+
int64_t random_geometric(bitgen_t *bitgen_state, double p) nogil
|
| 96 |
+
int64_t random_zipf(bitgen_t *bitgen_state, double a) nogil
|
| 97 |
+
int64_t random_hypergeometric(bitgen_t *bitgen_state, int64_t good, int64_t bad,
|
| 98 |
+
int64_t sample) nogil
|
| 99 |
+
|
| 100 |
+
uint64_t random_interval(bitgen_t *bitgen_state, uint64_t max) nogil
|
| 101 |
+
|
| 102 |
+
# Generate random uint64 numbers in closed interval [off, off + rng].
|
| 103 |
+
uint64_t random_bounded_uint64(bitgen_t *bitgen_state,
|
| 104 |
+
uint64_t off, uint64_t rng,
|
| 105 |
+
uint64_t mask, bint use_masked) nogil
|
| 106 |
+
|
| 107 |
+
void random_multinomial(bitgen_t *bitgen_state, int64_t n, int64_t *mnix,
|
| 108 |
+
double *pix, npy_intp d, binomial_t *binomial) nogil
|
| 109 |
+
|
| 110 |
+
int random_multivariate_hypergeometric_count(bitgen_t *bitgen_state,
|
| 111 |
+
int64_t total,
|
| 112 |
+
size_t num_colors, int64_t *colors,
|
| 113 |
+
int64_t nsample,
|
| 114 |
+
size_t num_variates, int64_t *variates) nogil
|
| 115 |
+
void random_multivariate_hypergeometric_marginals(bitgen_t *bitgen_state,
|
| 116 |
+
int64_t total,
|
| 117 |
+
size_t num_colors, int64_t *colors,
|
| 118 |
+
int64_t nsample,
|
| 119 |
+
size_t num_variates, int64_t *variates) nogil
|
| 120 |
+
|
mgm/lib/python3.10/site-packages/numpy/random/lib/libnpyrandom.a
ADDED
|
Binary file (71.9 kB). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/random/tests/__init__.py
ADDED
|
File without changes
|
mgm/lib/python3.10/site-packages/numpy/random/tests/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (167 Bytes). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_direct.cpython-310.pyc
ADDED
|
Binary file (17.5 kB). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_extending.cpython-310.pyc
ADDED
|
Binary file (3.13 kB). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_generator_mt19937.cpython-310.pyc
ADDED
|
Binary file (88.9 kB). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_generator_mt19937_regressions.cpython-310.pyc
ADDED
|
Binary file (7.6 kB). View file
|
|
|
mgm/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_random.cpython-310.pyc
ADDED
|
Binary file (52.9 kB). View file
|
|
|