Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .venv/lib/python3.11/site-packages/numpy/_pyinstaller/__init__.py +0 -0
- .venv/lib/python3.11/site-packages/numpy/_pyinstaller/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_pyinstaller/__pycache__/hook-numpy.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_pyinstaller/__pycache__/pyinstaller-smoke.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_pyinstaller/__pycache__/test_pyinstaller.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_pyinstaller/hook-numpy.py +37 -0
- .venv/lib/python3.11/site-packages/numpy/_pyinstaller/pyinstaller-smoke.py +32 -0
- .venv/lib/python3.11/site-packages/numpy/_pyinstaller/test_pyinstaller.py +35 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/__init__.py +221 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_add_docstring.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_array_like.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_char_codes.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_dtype_like.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_extended_precision.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_nbit.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_nested_sequence.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_scalars.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_shape.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/setup.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/_add_docstring.py +152 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/_array_like.py +167 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/_callable.pyi +338 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/_char_codes.py +111 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/_dtype_like.py +246 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/_extended_precision.py +27 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/_nbit.py +16 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/_nested_sequence.py +86 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/_scalars.py +30 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/_shape.py +7 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/_ufunc.pyi +445 -0
- .venv/lib/python3.11/site-packages/numpy/_typing/setup.py +10 -0
- .venv/lib/python3.11/site-packages/numpy/fft/__init__.py +212 -0
- .venv/lib/python3.11/site-packages/numpy/fft/__init__.pyi +29 -0
- .venv/lib/python3.11/site-packages/numpy/fft/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/fft/__pycache__/helper.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/fft/_pocketfft.py +1424 -0
- .venv/lib/python3.11/site-packages/numpy/fft/_pocketfft.pyi +108 -0
- .venv/lib/python3.11/site-packages/numpy/fft/_pocketfft_internal.cpython-311-x86_64-linux-gnu.so +0 -0
- .venv/lib/python3.11/site-packages/numpy/fft/helper.py +221 -0
- .venv/lib/python3.11/site-packages/numpy/fft/helper.pyi +47 -0
- .venv/lib/python3.11/site-packages/numpy/fft/tests/test_pocketfft.py +308 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/__pycache__/test_isfile.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/__pycache__/test_runtime.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/__pycache__/test_typing.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/misc/extended_precision.pyi +25 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/reveal/arraysetops.pyi +68 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/reveal/arrayterator.pyi +33 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/reveal/bitwise_ops.pyi +135 -0
.venv/lib/python3.11/site-packages/numpy/_pyinstaller/__init__.py
ADDED
|
File without changes
|
.venv/lib/python3.11/site-packages/numpy/_pyinstaller/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (191 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_pyinstaller/__pycache__/hook-numpy.cpython-311.pyc
ADDED
|
Binary file (1.08 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_pyinstaller/__pycache__/pyinstaller-smoke.cpython-311.pyc
ADDED
|
Binary file (2.64 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_pyinstaller/__pycache__/test_pyinstaller.cpython-311.pyc
ADDED
|
Binary file (2.06 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_pyinstaller/hook-numpy.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""This hook should collect all binary files and any hidden modules that numpy
|
| 2 |
+
needs.
|
| 3 |
+
|
| 4 |
+
Our (some-what inadequate) docs for writing PyInstaller hooks are kept here:
|
| 5 |
+
https://pyinstaller.readthedocs.io/en/stable/hooks.html
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
from PyInstaller.compat import is_conda, is_pure_conda
|
| 9 |
+
from PyInstaller.utils.hooks import collect_dynamic_libs, is_module_satisfies
|
| 10 |
+
|
| 11 |
+
# Collect all DLLs inside numpy's installation folder, dump them into built
|
| 12 |
+
# app's root.
|
| 13 |
+
binaries = collect_dynamic_libs("numpy", ".")
|
| 14 |
+
|
| 15 |
+
# If using Conda without any non-conda virtual environment manager:
|
| 16 |
+
if is_pure_conda:
|
| 17 |
+
# Assume running the NumPy from Conda-forge and collect it's DLLs from the
|
| 18 |
+
# communal Conda bin directory. DLLs from NumPy's dependencies must also be
|
| 19 |
+
# collected to capture MKL, OpenBlas, OpenMP, etc.
|
| 20 |
+
from PyInstaller.utils.hooks import conda_support
|
| 21 |
+
datas = conda_support.collect_dynamic_libs("numpy", dependencies=True)
|
| 22 |
+
|
| 23 |
+
# Submodules PyInstaller cannot detect. `_dtype_ctypes` is only imported
|
| 24 |
+
# from C and `_multiarray_tests` is used in tests (which are not packed).
|
| 25 |
+
hiddenimports = ['numpy.core._dtype_ctypes', 'numpy.core._multiarray_tests']
|
| 26 |
+
|
| 27 |
+
# Remove testing and building code and packages that are referenced throughout
|
| 28 |
+
# NumPy but are not really dependencies.
|
| 29 |
+
excludedimports = [
|
| 30 |
+
"scipy",
|
| 31 |
+
"pytest",
|
| 32 |
+
"f2py",
|
| 33 |
+
"setuptools",
|
| 34 |
+
"numpy.f2py",
|
| 35 |
+
"distutils",
|
| 36 |
+
"numpy.distutils",
|
| 37 |
+
]
|
.venv/lib/python3.11/site-packages/numpy/_pyinstaller/pyinstaller-smoke.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A crude *bit of everything* smoke test to verify PyInstaller compatibility.
|
| 2 |
+
|
| 3 |
+
PyInstaller typically goes wrong by forgetting to package modules, extension
|
| 4 |
+
modules or shared libraries. This script should aim to touch as many of those
|
| 5 |
+
as possible in an attempt to trip a ModuleNotFoundError or a DLL load failure
|
| 6 |
+
due to an uncollected resource. Missing resources are unlikely to lead to
|
| 7 |
+
arithmetic errors so there's generally no need to verify any calculation's
|
| 8 |
+
output - merely that it made it to the end OK. This script should not
|
| 9 |
+
explicitly import any of numpy's submodules as that gives PyInstaller undue
|
| 10 |
+
hints that those submodules exist and should be collected (accessing implicitly
|
| 11 |
+
loaded submodules is OK).
|
| 12 |
+
|
| 13 |
+
"""
|
| 14 |
+
import numpy as np
|
| 15 |
+
|
| 16 |
+
a = np.arange(1., 10.).reshape((3, 3)) % 5
|
| 17 |
+
np.linalg.det(a)
|
| 18 |
+
a @ a
|
| 19 |
+
a @ a.T
|
| 20 |
+
np.linalg.inv(a)
|
| 21 |
+
np.sin(np.exp(a))
|
| 22 |
+
np.linalg.svd(a)
|
| 23 |
+
np.linalg.eigh(a)
|
| 24 |
+
|
| 25 |
+
np.unique(np.random.randint(0, 10, 100))
|
| 26 |
+
np.sort(np.random.uniform(0, 10, 100))
|
| 27 |
+
|
| 28 |
+
np.fft.fft(np.exp(2j * np.pi * np.arange(8) / 8))
|
| 29 |
+
np.ma.masked_array(np.arange(10), np.random.rand(10) < .5).sum()
|
| 30 |
+
np.polynomial.Legendre([7, 8, 9]).roots()
|
| 31 |
+
|
| 32 |
+
print("I made it!")
|
.venv/lib/python3.11/site-packages/numpy/_pyinstaller/test_pyinstaller.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# PyInstaller has been very unproactive about replacing 'imp' with 'importlib'.
|
| 8 |
+
@pytest.mark.filterwarnings('ignore::DeprecationWarning')
|
| 9 |
+
# It also leaks io.BytesIO()s.
|
| 10 |
+
@pytest.mark.filterwarnings('ignore::ResourceWarning')
|
| 11 |
+
@pytest.mark.parametrize("mode", ["--onedir", "--onefile"])
|
| 12 |
+
@pytest.mark.slow
|
| 13 |
+
def test_pyinstaller(mode, tmp_path):
|
| 14 |
+
"""Compile and run pyinstaller-smoke.py using PyInstaller."""
|
| 15 |
+
|
| 16 |
+
pyinstaller_cli = pytest.importorskip("PyInstaller.__main__").run
|
| 17 |
+
|
| 18 |
+
source = Path(__file__).with_name("pyinstaller-smoke.py").resolve()
|
| 19 |
+
args = [
|
| 20 |
+
# Place all generated files in ``tmp_path``.
|
| 21 |
+
'--workpath', str(tmp_path / "build"),
|
| 22 |
+
'--distpath', str(tmp_path / "dist"),
|
| 23 |
+
'--specpath', str(tmp_path),
|
| 24 |
+
mode,
|
| 25 |
+
str(source),
|
| 26 |
+
]
|
| 27 |
+
pyinstaller_cli(args)
|
| 28 |
+
|
| 29 |
+
if mode == "--onefile":
|
| 30 |
+
exe = tmp_path / "dist" / source.stem
|
| 31 |
+
else:
|
| 32 |
+
exe = tmp_path / "dist" / source.stem / source.stem
|
| 33 |
+
|
| 34 |
+
p = subprocess.run([str(exe)], check=True, stdout=subprocess.PIPE)
|
| 35 |
+
assert p.stdout.strip() == b"I made it!"
|
.venv/lib/python3.11/site-packages/numpy/_typing/__init__.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Private counterpart of ``numpy.typing``."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from .. import ufunc
|
| 6 |
+
from .._utils import set_module
|
| 7 |
+
from typing import TYPE_CHECKING, final
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@final # Disallow the creation of arbitrary `NBitBase` subclasses
|
| 11 |
+
@set_module("numpy.typing")
|
| 12 |
+
class NBitBase:
|
| 13 |
+
"""
|
| 14 |
+
A type representing `numpy.number` precision during static type checking.
|
| 15 |
+
|
| 16 |
+
Used exclusively for the purpose static type checking, `NBitBase`
|
| 17 |
+
represents the base of a hierarchical set of subclasses.
|
| 18 |
+
Each subsequent subclass is herein used for representing a lower level
|
| 19 |
+
of precision, *e.g.* ``64Bit > 32Bit > 16Bit``.
|
| 20 |
+
|
| 21 |
+
.. versionadded:: 1.20
|
| 22 |
+
|
| 23 |
+
Examples
|
| 24 |
+
--------
|
| 25 |
+
Below is a typical usage example: `NBitBase` is herein used for annotating
|
| 26 |
+
a function that takes a float and integer of arbitrary precision
|
| 27 |
+
as arguments and returns a new float of whichever precision is largest
|
| 28 |
+
(*e.g.* ``np.float16 + np.int64 -> np.float64``).
|
| 29 |
+
|
| 30 |
+
.. code-block:: python
|
| 31 |
+
|
| 32 |
+
>>> from __future__ import annotations
|
| 33 |
+
>>> from typing import TypeVar, TYPE_CHECKING
|
| 34 |
+
>>> import numpy as np
|
| 35 |
+
>>> import numpy.typing as npt
|
| 36 |
+
|
| 37 |
+
>>> T1 = TypeVar("T1", bound=npt.NBitBase)
|
| 38 |
+
>>> T2 = TypeVar("T2", bound=npt.NBitBase)
|
| 39 |
+
|
| 40 |
+
>>> def add(a: np.floating[T1], b: np.integer[T2]) -> np.floating[T1 | T2]:
|
| 41 |
+
... return a + b
|
| 42 |
+
|
| 43 |
+
>>> a = np.float16()
|
| 44 |
+
>>> b = np.int64()
|
| 45 |
+
>>> out = add(a, b)
|
| 46 |
+
|
| 47 |
+
>>> if TYPE_CHECKING:
|
| 48 |
+
... reveal_locals()
|
| 49 |
+
... # note: Revealed local types are:
|
| 50 |
+
... # note: a: numpy.floating[numpy.typing._16Bit*]
|
| 51 |
+
... # note: b: numpy.signedinteger[numpy.typing._64Bit*]
|
| 52 |
+
... # note: out: numpy.floating[numpy.typing._64Bit*]
|
| 53 |
+
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
def __init_subclass__(cls) -> None:
|
| 57 |
+
allowed_names = {
|
| 58 |
+
"NBitBase", "_256Bit", "_128Bit", "_96Bit", "_80Bit",
|
| 59 |
+
"_64Bit", "_32Bit", "_16Bit", "_8Bit",
|
| 60 |
+
}
|
| 61 |
+
if cls.__name__ not in allowed_names:
|
| 62 |
+
raise TypeError('cannot inherit from final class "NBitBase"')
|
| 63 |
+
super().__init_subclass__()
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# Silence errors about subclassing a `@final`-decorated class
|
| 67 |
+
class _256Bit(NBitBase): # type: ignore[misc]
|
| 68 |
+
pass
|
| 69 |
+
|
| 70 |
+
class _128Bit(_256Bit): # type: ignore[misc]
|
| 71 |
+
pass
|
| 72 |
+
|
| 73 |
+
class _96Bit(_128Bit): # type: ignore[misc]
|
| 74 |
+
pass
|
| 75 |
+
|
| 76 |
+
class _80Bit(_96Bit): # type: ignore[misc]
|
| 77 |
+
pass
|
| 78 |
+
|
| 79 |
+
class _64Bit(_80Bit): # type: ignore[misc]
|
| 80 |
+
pass
|
| 81 |
+
|
| 82 |
+
class _32Bit(_64Bit): # type: ignore[misc]
|
| 83 |
+
pass
|
| 84 |
+
|
| 85 |
+
class _16Bit(_32Bit): # type: ignore[misc]
|
| 86 |
+
pass
|
| 87 |
+
|
| 88 |
+
class _8Bit(_16Bit): # type: ignore[misc]
|
| 89 |
+
pass
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
from ._nested_sequence import (
|
| 93 |
+
_NestedSequence as _NestedSequence,
|
| 94 |
+
)
|
| 95 |
+
from ._nbit import (
|
| 96 |
+
_NBitByte as _NBitByte,
|
| 97 |
+
_NBitShort as _NBitShort,
|
| 98 |
+
_NBitIntC as _NBitIntC,
|
| 99 |
+
_NBitIntP as _NBitIntP,
|
| 100 |
+
_NBitInt as _NBitInt,
|
| 101 |
+
_NBitLongLong as _NBitLongLong,
|
| 102 |
+
_NBitHalf as _NBitHalf,
|
| 103 |
+
_NBitSingle as _NBitSingle,
|
| 104 |
+
_NBitDouble as _NBitDouble,
|
| 105 |
+
_NBitLongDouble as _NBitLongDouble,
|
| 106 |
+
)
|
| 107 |
+
from ._char_codes import (
|
| 108 |
+
_BoolCodes as _BoolCodes,
|
| 109 |
+
_UInt8Codes as _UInt8Codes,
|
| 110 |
+
_UInt16Codes as _UInt16Codes,
|
| 111 |
+
_UInt32Codes as _UInt32Codes,
|
| 112 |
+
_UInt64Codes as _UInt64Codes,
|
| 113 |
+
_Int8Codes as _Int8Codes,
|
| 114 |
+
_Int16Codes as _Int16Codes,
|
| 115 |
+
_Int32Codes as _Int32Codes,
|
| 116 |
+
_Int64Codes as _Int64Codes,
|
| 117 |
+
_Float16Codes as _Float16Codes,
|
| 118 |
+
_Float32Codes as _Float32Codes,
|
| 119 |
+
_Float64Codes as _Float64Codes,
|
| 120 |
+
_Complex64Codes as _Complex64Codes,
|
| 121 |
+
_Complex128Codes as _Complex128Codes,
|
| 122 |
+
_ByteCodes as _ByteCodes,
|
| 123 |
+
_ShortCodes as _ShortCodes,
|
| 124 |
+
_IntCCodes as _IntCCodes,
|
| 125 |
+
_IntPCodes as _IntPCodes,
|
| 126 |
+
_IntCodes as _IntCodes,
|
| 127 |
+
_LongLongCodes as _LongLongCodes,
|
| 128 |
+
_UByteCodes as _UByteCodes,
|
| 129 |
+
_UShortCodes as _UShortCodes,
|
| 130 |
+
_UIntCCodes as _UIntCCodes,
|
| 131 |
+
_UIntPCodes as _UIntPCodes,
|
| 132 |
+
_UIntCodes as _UIntCodes,
|
| 133 |
+
_ULongLongCodes as _ULongLongCodes,
|
| 134 |
+
_HalfCodes as _HalfCodes,
|
| 135 |
+
_SingleCodes as _SingleCodes,
|
| 136 |
+
_DoubleCodes as _DoubleCodes,
|
| 137 |
+
_LongDoubleCodes as _LongDoubleCodes,
|
| 138 |
+
_CSingleCodes as _CSingleCodes,
|
| 139 |
+
_CDoubleCodes as _CDoubleCodes,
|
| 140 |
+
_CLongDoubleCodes as _CLongDoubleCodes,
|
| 141 |
+
_DT64Codes as _DT64Codes,
|
| 142 |
+
_TD64Codes as _TD64Codes,
|
| 143 |
+
_StrCodes as _StrCodes,
|
| 144 |
+
_BytesCodes as _BytesCodes,
|
| 145 |
+
_VoidCodes as _VoidCodes,
|
| 146 |
+
_ObjectCodes as _ObjectCodes,
|
| 147 |
+
)
|
| 148 |
+
from ._scalars import (
|
| 149 |
+
_CharLike_co as _CharLike_co,
|
| 150 |
+
_BoolLike_co as _BoolLike_co,
|
| 151 |
+
_UIntLike_co as _UIntLike_co,
|
| 152 |
+
_IntLike_co as _IntLike_co,
|
| 153 |
+
_FloatLike_co as _FloatLike_co,
|
| 154 |
+
_ComplexLike_co as _ComplexLike_co,
|
| 155 |
+
_TD64Like_co as _TD64Like_co,
|
| 156 |
+
_NumberLike_co as _NumberLike_co,
|
| 157 |
+
_ScalarLike_co as _ScalarLike_co,
|
| 158 |
+
_VoidLike_co as _VoidLike_co,
|
| 159 |
+
)
|
| 160 |
+
from ._shape import (
|
| 161 |
+
_Shape as _Shape,
|
| 162 |
+
_ShapeLike as _ShapeLike,
|
| 163 |
+
)
|
| 164 |
+
from ._dtype_like import (
|
| 165 |
+
DTypeLike as DTypeLike,
|
| 166 |
+
_DTypeLike as _DTypeLike,
|
| 167 |
+
_SupportsDType as _SupportsDType,
|
| 168 |
+
_VoidDTypeLike as _VoidDTypeLike,
|
| 169 |
+
_DTypeLikeBool as _DTypeLikeBool,
|
| 170 |
+
_DTypeLikeUInt as _DTypeLikeUInt,
|
| 171 |
+
_DTypeLikeInt as _DTypeLikeInt,
|
| 172 |
+
_DTypeLikeFloat as _DTypeLikeFloat,
|
| 173 |
+
_DTypeLikeComplex as _DTypeLikeComplex,
|
| 174 |
+
_DTypeLikeTD64 as _DTypeLikeTD64,
|
| 175 |
+
_DTypeLikeDT64 as _DTypeLikeDT64,
|
| 176 |
+
_DTypeLikeObject as _DTypeLikeObject,
|
| 177 |
+
_DTypeLikeVoid as _DTypeLikeVoid,
|
| 178 |
+
_DTypeLikeStr as _DTypeLikeStr,
|
| 179 |
+
_DTypeLikeBytes as _DTypeLikeBytes,
|
| 180 |
+
_DTypeLikeComplex_co as _DTypeLikeComplex_co,
|
| 181 |
+
)
|
| 182 |
+
from ._array_like import (
|
| 183 |
+
NDArray as NDArray,
|
| 184 |
+
ArrayLike as ArrayLike,
|
| 185 |
+
_ArrayLike as _ArrayLike,
|
| 186 |
+
_FiniteNestedSequence as _FiniteNestedSequence,
|
| 187 |
+
_SupportsArray as _SupportsArray,
|
| 188 |
+
_SupportsArrayFunc as _SupportsArrayFunc,
|
| 189 |
+
_ArrayLikeInt as _ArrayLikeInt,
|
| 190 |
+
_ArrayLikeBool_co as _ArrayLikeBool_co,
|
| 191 |
+
_ArrayLikeUInt_co as _ArrayLikeUInt_co,
|
| 192 |
+
_ArrayLikeInt_co as _ArrayLikeInt_co,
|
| 193 |
+
_ArrayLikeFloat_co as _ArrayLikeFloat_co,
|
| 194 |
+
_ArrayLikeComplex_co as _ArrayLikeComplex_co,
|
| 195 |
+
_ArrayLikeNumber_co as _ArrayLikeNumber_co,
|
| 196 |
+
_ArrayLikeTD64_co as _ArrayLikeTD64_co,
|
| 197 |
+
_ArrayLikeDT64_co as _ArrayLikeDT64_co,
|
| 198 |
+
_ArrayLikeObject_co as _ArrayLikeObject_co,
|
| 199 |
+
_ArrayLikeVoid_co as _ArrayLikeVoid_co,
|
| 200 |
+
_ArrayLikeStr_co as _ArrayLikeStr_co,
|
| 201 |
+
_ArrayLikeBytes_co as _ArrayLikeBytes_co,
|
| 202 |
+
_ArrayLikeUnknown as _ArrayLikeUnknown,
|
| 203 |
+
_UnknownType as _UnknownType,
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
if TYPE_CHECKING:
|
| 207 |
+
from ._ufunc import (
|
| 208 |
+
_UFunc_Nin1_Nout1 as _UFunc_Nin1_Nout1,
|
| 209 |
+
_UFunc_Nin2_Nout1 as _UFunc_Nin2_Nout1,
|
| 210 |
+
_UFunc_Nin1_Nout2 as _UFunc_Nin1_Nout2,
|
| 211 |
+
_UFunc_Nin2_Nout2 as _UFunc_Nin2_Nout2,
|
| 212 |
+
_GUFunc_Nin2_Nout1 as _GUFunc_Nin2_Nout1,
|
| 213 |
+
)
|
| 214 |
+
else:
|
| 215 |
+
# Declare the (type-check-only) ufunc subclasses as ufunc aliases during
|
| 216 |
+
# runtime; this helps autocompletion tools such as Jedi (numpy/numpy#19834)
|
| 217 |
+
_UFunc_Nin1_Nout1 = ufunc
|
| 218 |
+
_UFunc_Nin2_Nout1 = ufunc
|
| 219 |
+
_UFunc_Nin1_Nout2 = ufunc
|
| 220 |
+
_UFunc_Nin2_Nout2 = ufunc
|
| 221 |
+
_GUFunc_Nin2_Nout1 = ufunc
|
.venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (8.31 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_add_docstring.cpython-311.pyc
ADDED
|
Binary file (5.04 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_array_like.cpython-311.pyc
ADDED
|
Binary file (5.61 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_char_codes.cpython-311.pyc
ADDED
|
Binary file (5.79 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_dtype_like.cpython-311.pyc
ADDED
|
Binary file (6.52 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_extended_precision.cpython-311.pyc
ADDED
|
Binary file (1.29 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_nbit.cpython-311.pyc
ADDED
|
Binary file (533 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_nested_sequence.cpython-311.pyc
ADDED
|
Binary file (3.75 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_scalars.cpython-311.pyc
ADDED
|
Binary file (1.22 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/_shape.cpython-311.pyc
ADDED
|
Binary file (446 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_typing/__pycache__/setup.cpython-311.pyc
ADDED
|
Binary file (753 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/_typing/_add_docstring.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A module for creating docstrings for sphinx ``data`` domains."""
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
import textwrap
|
| 5 |
+
|
| 6 |
+
from ._array_like import NDArray
|
| 7 |
+
|
| 8 |
+
_docstrings_list = []
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def add_newdoc(name: str, value: str, doc: str) -> None:
|
| 12 |
+
"""Append ``_docstrings_list`` with a docstring for `name`.
|
| 13 |
+
|
| 14 |
+
Parameters
|
| 15 |
+
----------
|
| 16 |
+
name : str
|
| 17 |
+
The name of the object.
|
| 18 |
+
value : str
|
| 19 |
+
A string-representation of the object.
|
| 20 |
+
doc : str
|
| 21 |
+
The docstring of the object.
|
| 22 |
+
|
| 23 |
+
"""
|
| 24 |
+
_docstrings_list.append((name, value, doc))
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _parse_docstrings() -> str:
|
| 28 |
+
"""Convert all docstrings in ``_docstrings_list`` into a single
|
| 29 |
+
sphinx-legible text block.
|
| 30 |
+
|
| 31 |
+
"""
|
| 32 |
+
type_list_ret = []
|
| 33 |
+
for name, value, doc in _docstrings_list:
|
| 34 |
+
s = textwrap.dedent(doc).replace("\n", "\n ")
|
| 35 |
+
|
| 36 |
+
# Replace sections by rubrics
|
| 37 |
+
lines = s.split("\n")
|
| 38 |
+
new_lines = []
|
| 39 |
+
indent = ""
|
| 40 |
+
for line in lines:
|
| 41 |
+
m = re.match(r'^(\s+)[-=]+\s*$', line)
|
| 42 |
+
if m and new_lines:
|
| 43 |
+
prev = textwrap.dedent(new_lines.pop())
|
| 44 |
+
if prev == "Examples":
|
| 45 |
+
indent = ""
|
| 46 |
+
new_lines.append(f'{m.group(1)}.. rubric:: {prev}')
|
| 47 |
+
else:
|
| 48 |
+
indent = 4 * " "
|
| 49 |
+
new_lines.append(f'{m.group(1)}.. admonition:: {prev}')
|
| 50 |
+
new_lines.append("")
|
| 51 |
+
else:
|
| 52 |
+
new_lines.append(f"{indent}{line}")
|
| 53 |
+
|
| 54 |
+
s = "\n".join(new_lines)
|
| 55 |
+
s_block = f""".. data:: {name}\n :value: {value}\n {s}"""
|
| 56 |
+
type_list_ret.append(s_block)
|
| 57 |
+
return "\n".join(type_list_ret)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
add_newdoc('ArrayLike', 'typing.Union[...]',
|
| 61 |
+
"""
|
| 62 |
+
A `~typing.Union` representing objects that can be coerced
|
| 63 |
+
into an `~numpy.ndarray`.
|
| 64 |
+
|
| 65 |
+
Among others this includes the likes of:
|
| 66 |
+
|
| 67 |
+
* Scalars.
|
| 68 |
+
* (Nested) sequences.
|
| 69 |
+
* Objects implementing the `~class.__array__` protocol.
|
| 70 |
+
|
| 71 |
+
.. versionadded:: 1.20
|
| 72 |
+
|
| 73 |
+
See Also
|
| 74 |
+
--------
|
| 75 |
+
:term:`array_like`:
|
| 76 |
+
Any scalar or sequence that can be interpreted as an ndarray.
|
| 77 |
+
|
| 78 |
+
Examples
|
| 79 |
+
--------
|
| 80 |
+
.. code-block:: python
|
| 81 |
+
|
| 82 |
+
>>> import numpy as np
|
| 83 |
+
>>> import numpy.typing as npt
|
| 84 |
+
|
| 85 |
+
>>> def as_array(a: npt.ArrayLike) -> np.ndarray:
|
| 86 |
+
... return np.array(a)
|
| 87 |
+
|
| 88 |
+
""")
|
| 89 |
+
|
| 90 |
+
add_newdoc('DTypeLike', 'typing.Union[...]',
|
| 91 |
+
"""
|
| 92 |
+
A `~typing.Union` representing objects that can be coerced
|
| 93 |
+
into a `~numpy.dtype`.
|
| 94 |
+
|
| 95 |
+
Among others this includes the likes of:
|
| 96 |
+
|
| 97 |
+
* :class:`type` objects.
|
| 98 |
+
* Character codes or the names of :class:`type` objects.
|
| 99 |
+
* Objects with the ``.dtype`` attribute.
|
| 100 |
+
|
| 101 |
+
.. versionadded:: 1.20
|
| 102 |
+
|
| 103 |
+
See Also
|
| 104 |
+
--------
|
| 105 |
+
:ref:`Specifying and constructing data types <arrays.dtypes.constructing>`
|
| 106 |
+
A comprehensive overview of all objects that can be coerced
|
| 107 |
+
into data types.
|
| 108 |
+
|
| 109 |
+
Examples
|
| 110 |
+
--------
|
| 111 |
+
.. code-block:: python
|
| 112 |
+
|
| 113 |
+
>>> import numpy as np
|
| 114 |
+
>>> import numpy.typing as npt
|
| 115 |
+
|
| 116 |
+
>>> def as_dtype(d: npt.DTypeLike) -> np.dtype:
|
| 117 |
+
... return np.dtype(d)
|
| 118 |
+
|
| 119 |
+
""")
|
| 120 |
+
|
| 121 |
+
add_newdoc('NDArray', repr(NDArray),
|
| 122 |
+
"""
|
| 123 |
+
A :term:`generic <generic type>` version of
|
| 124 |
+
`np.ndarray[Any, np.dtype[+ScalarType]] <numpy.ndarray>`.
|
| 125 |
+
|
| 126 |
+
Can be used during runtime for typing arrays with a given dtype
|
| 127 |
+
and unspecified shape.
|
| 128 |
+
|
| 129 |
+
.. versionadded:: 1.21
|
| 130 |
+
|
| 131 |
+
Examples
|
| 132 |
+
--------
|
| 133 |
+
.. code-block:: python
|
| 134 |
+
|
| 135 |
+
>>> import numpy as np
|
| 136 |
+
>>> import numpy.typing as npt
|
| 137 |
+
|
| 138 |
+
>>> print(npt.NDArray)
|
| 139 |
+
numpy.ndarray[typing.Any, numpy.dtype[+ScalarType]]
|
| 140 |
+
|
| 141 |
+
>>> print(npt.NDArray[np.float64])
|
| 142 |
+
numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]
|
| 143 |
+
|
| 144 |
+
>>> NDArrayInt = npt.NDArray[np.int_]
|
| 145 |
+
>>> a: NDArrayInt = np.arange(10)
|
| 146 |
+
|
| 147 |
+
>>> def func(a: npt.ArrayLike) -> npt.NDArray[Any]:
|
| 148 |
+
... return np.array(a)
|
| 149 |
+
|
| 150 |
+
""")
|
| 151 |
+
|
| 152 |
+
_docstrings = _parse_docstrings()
|
.venv/lib/python3.11/site-packages/numpy/_typing/_array_like.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
from collections.abc import Collection, Callable, Sequence
|
| 5 |
+
from typing import Any, Protocol, Union, TypeVar, runtime_checkable
|
| 6 |
+
|
| 7 |
+
from numpy import (
|
| 8 |
+
ndarray,
|
| 9 |
+
dtype,
|
| 10 |
+
generic,
|
| 11 |
+
bool_,
|
| 12 |
+
unsignedinteger,
|
| 13 |
+
integer,
|
| 14 |
+
floating,
|
| 15 |
+
complexfloating,
|
| 16 |
+
number,
|
| 17 |
+
timedelta64,
|
| 18 |
+
datetime64,
|
| 19 |
+
object_,
|
| 20 |
+
void,
|
| 21 |
+
str_,
|
| 22 |
+
bytes_,
|
| 23 |
+
)
|
| 24 |
+
from ._nested_sequence import _NestedSequence
|
| 25 |
+
|
| 26 |
+
_T = TypeVar("_T")
|
| 27 |
+
_ScalarType = TypeVar("_ScalarType", bound=generic)
|
| 28 |
+
_ScalarType_co = TypeVar("_ScalarType_co", bound=generic, covariant=True)
|
| 29 |
+
_DType = TypeVar("_DType", bound=dtype[Any])
|
| 30 |
+
_DType_co = TypeVar("_DType_co", covariant=True, bound=dtype[Any])
|
| 31 |
+
|
| 32 |
+
NDArray = ndarray[Any, dtype[_ScalarType_co]]
|
| 33 |
+
|
| 34 |
+
# The `_SupportsArray` protocol only cares about the default dtype
|
| 35 |
+
# (i.e. `dtype=None` or no `dtype` parameter at all) of the to-be returned
|
| 36 |
+
# array.
|
| 37 |
+
# Concrete implementations of the protocol are responsible for adding
|
| 38 |
+
# any and all remaining overloads
|
| 39 |
+
@runtime_checkable
|
| 40 |
+
class _SupportsArray(Protocol[_DType_co]):
|
| 41 |
+
def __array__(self) -> ndarray[Any, _DType_co]: ...
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@runtime_checkable
|
| 45 |
+
class _SupportsArrayFunc(Protocol):
|
| 46 |
+
"""A protocol class representing `~class.__array_function__`."""
|
| 47 |
+
def __array_function__(
|
| 48 |
+
self,
|
| 49 |
+
func: Callable[..., Any],
|
| 50 |
+
types: Collection[type[Any]],
|
| 51 |
+
args: tuple[Any, ...],
|
| 52 |
+
kwargs: dict[str, Any],
|
| 53 |
+
) -> object: ...
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# TODO: Wait until mypy supports recursive objects in combination with typevars
|
| 57 |
+
_FiniteNestedSequence = Union[
|
| 58 |
+
_T,
|
| 59 |
+
Sequence[_T],
|
| 60 |
+
Sequence[Sequence[_T]],
|
| 61 |
+
Sequence[Sequence[Sequence[_T]]],
|
| 62 |
+
Sequence[Sequence[Sequence[Sequence[_T]]]],
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
+
# A subset of `npt.ArrayLike` that can be parametrized w.r.t. `np.generic`
|
| 66 |
+
_ArrayLike = Union[
|
| 67 |
+
_SupportsArray[dtype[_ScalarType]],
|
| 68 |
+
_NestedSequence[_SupportsArray[dtype[_ScalarType]]],
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
# A union representing array-like objects; consists of two typevars:
|
| 72 |
+
# One representing types that can be parametrized w.r.t. `np.dtype`
|
| 73 |
+
# and another one for the rest
|
| 74 |
+
_DualArrayLike = Union[
|
| 75 |
+
_SupportsArray[_DType],
|
| 76 |
+
_NestedSequence[_SupportsArray[_DType]],
|
| 77 |
+
_T,
|
| 78 |
+
_NestedSequence[_T],
|
| 79 |
+
]
|
| 80 |
+
|
| 81 |
+
if sys.version_info >= (3, 12):
|
| 82 |
+
from collections.abc import Buffer
|
| 83 |
+
|
| 84 |
+
ArrayLike = Buffer | _DualArrayLike[
|
| 85 |
+
dtype[Any],
|
| 86 |
+
Union[bool, int, float, complex, str, bytes],
|
| 87 |
+
]
|
| 88 |
+
else:
|
| 89 |
+
ArrayLike = _DualArrayLike[
|
| 90 |
+
dtype[Any],
|
| 91 |
+
Union[bool, int, float, complex, str, bytes],
|
| 92 |
+
]
|
| 93 |
+
|
| 94 |
+
# `ArrayLike<X>_co`: array-like objects that can be coerced into `X`
|
| 95 |
+
# given the casting rules `same_kind`
|
| 96 |
+
_ArrayLikeBool_co = _DualArrayLike[
|
| 97 |
+
dtype[bool_],
|
| 98 |
+
bool,
|
| 99 |
+
]
|
| 100 |
+
_ArrayLikeUInt_co = _DualArrayLike[
|
| 101 |
+
dtype[Union[bool_, unsignedinteger[Any]]],
|
| 102 |
+
bool,
|
| 103 |
+
]
|
| 104 |
+
_ArrayLikeInt_co = _DualArrayLike[
|
| 105 |
+
dtype[Union[bool_, integer[Any]]],
|
| 106 |
+
Union[bool, int],
|
| 107 |
+
]
|
| 108 |
+
_ArrayLikeFloat_co = _DualArrayLike[
|
| 109 |
+
dtype[Union[bool_, integer[Any], floating[Any]]],
|
| 110 |
+
Union[bool, int, float],
|
| 111 |
+
]
|
| 112 |
+
_ArrayLikeComplex_co = _DualArrayLike[
|
| 113 |
+
dtype[Union[
|
| 114 |
+
bool_,
|
| 115 |
+
integer[Any],
|
| 116 |
+
floating[Any],
|
| 117 |
+
complexfloating[Any, Any],
|
| 118 |
+
]],
|
| 119 |
+
Union[bool, int, float, complex],
|
| 120 |
+
]
|
| 121 |
+
_ArrayLikeNumber_co = _DualArrayLike[
|
| 122 |
+
dtype[Union[bool_, number[Any]]],
|
| 123 |
+
Union[bool, int, float, complex],
|
| 124 |
+
]
|
| 125 |
+
_ArrayLikeTD64_co = _DualArrayLike[
|
| 126 |
+
dtype[Union[bool_, integer[Any], timedelta64]],
|
| 127 |
+
Union[bool, int],
|
| 128 |
+
]
|
| 129 |
+
_ArrayLikeDT64_co = Union[
|
| 130 |
+
_SupportsArray[dtype[datetime64]],
|
| 131 |
+
_NestedSequence[_SupportsArray[dtype[datetime64]]],
|
| 132 |
+
]
|
| 133 |
+
_ArrayLikeObject_co = Union[
|
| 134 |
+
_SupportsArray[dtype[object_]],
|
| 135 |
+
_NestedSequence[_SupportsArray[dtype[object_]]],
|
| 136 |
+
]
|
| 137 |
+
|
| 138 |
+
_ArrayLikeVoid_co = Union[
|
| 139 |
+
_SupportsArray[dtype[void]],
|
| 140 |
+
_NestedSequence[_SupportsArray[dtype[void]]],
|
| 141 |
+
]
|
| 142 |
+
_ArrayLikeStr_co = _DualArrayLike[
|
| 143 |
+
dtype[str_],
|
| 144 |
+
str,
|
| 145 |
+
]
|
| 146 |
+
_ArrayLikeBytes_co = _DualArrayLike[
|
| 147 |
+
dtype[bytes_],
|
| 148 |
+
bytes,
|
| 149 |
+
]
|
| 150 |
+
|
| 151 |
+
_ArrayLikeInt = _DualArrayLike[
|
| 152 |
+
dtype[integer[Any]],
|
| 153 |
+
int,
|
| 154 |
+
]
|
| 155 |
+
|
| 156 |
+
# Extra ArrayLike type so that pyright can deal with NDArray[Any]
|
| 157 |
+
# Used as the first overload, should only match NDArray[Any],
|
| 158 |
+
# not any actual types.
|
| 159 |
+
# https://github.com/numpy/numpy/pull/22193
|
| 160 |
+
class _UnknownType:
|
| 161 |
+
...
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
_ArrayLikeUnknown = _DualArrayLike[
|
| 165 |
+
dtype[_UnknownType],
|
| 166 |
+
_UnknownType,
|
| 167 |
+
]
|
.venv/lib/python3.11/site-packages/numpy/_typing/_callable.pyi
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
A module with various ``typing.Protocol`` subclasses that implement
|
| 3 |
+
the ``__call__`` magic method.
|
| 4 |
+
|
| 5 |
+
See the `Mypy documentation`_ on protocols for more details.
|
| 6 |
+
|
| 7 |
+
.. _`Mypy documentation`: https://mypy.readthedocs.io/en/stable/protocols.html#callback-protocols
|
| 8 |
+
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
from typing import (
|
| 14 |
+
TypeVar,
|
| 15 |
+
overload,
|
| 16 |
+
Any,
|
| 17 |
+
NoReturn,
|
| 18 |
+
Protocol,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
from numpy import (
|
| 22 |
+
ndarray,
|
| 23 |
+
dtype,
|
| 24 |
+
generic,
|
| 25 |
+
bool_,
|
| 26 |
+
timedelta64,
|
| 27 |
+
number,
|
| 28 |
+
integer,
|
| 29 |
+
unsignedinteger,
|
| 30 |
+
signedinteger,
|
| 31 |
+
int8,
|
| 32 |
+
int_,
|
| 33 |
+
floating,
|
| 34 |
+
float64,
|
| 35 |
+
complexfloating,
|
| 36 |
+
complex128,
|
| 37 |
+
)
|
| 38 |
+
from ._nbit import _NBitInt, _NBitDouble
|
| 39 |
+
from ._scalars import (
|
| 40 |
+
_BoolLike_co,
|
| 41 |
+
_IntLike_co,
|
| 42 |
+
_FloatLike_co,
|
| 43 |
+
_NumberLike_co,
|
| 44 |
+
)
|
| 45 |
+
from . import NBitBase
|
| 46 |
+
from ._array_like import NDArray
|
| 47 |
+
from ._nested_sequence import _NestedSequence
|
| 48 |
+
|
| 49 |
+
_T1 = TypeVar("_T1")
|
| 50 |
+
_T2 = TypeVar("_T2")
|
| 51 |
+
_T1_contra = TypeVar("_T1_contra", contravariant=True)
|
| 52 |
+
_T2_contra = TypeVar("_T2_contra", contravariant=True)
|
| 53 |
+
_2Tuple = tuple[_T1, _T1]
|
| 54 |
+
|
| 55 |
+
_NBit1 = TypeVar("_NBit1", bound=NBitBase)
|
| 56 |
+
_NBit2 = TypeVar("_NBit2", bound=NBitBase)
|
| 57 |
+
|
| 58 |
+
_IntType = TypeVar("_IntType", bound=integer)
|
| 59 |
+
_FloatType = TypeVar("_FloatType", bound=floating)
|
| 60 |
+
_NumberType = TypeVar("_NumberType", bound=number)
|
| 61 |
+
_NumberType_co = TypeVar("_NumberType_co", covariant=True, bound=number)
|
| 62 |
+
_GenericType_co = TypeVar("_GenericType_co", covariant=True, bound=generic)
|
| 63 |
+
|
| 64 |
+
class _BoolOp(Protocol[_GenericType_co]):
|
| 65 |
+
@overload
|
| 66 |
+
def __call__(self, other: _BoolLike_co, /) -> _GenericType_co: ...
|
| 67 |
+
@overload # platform dependent
|
| 68 |
+
def __call__(self, other: int, /) -> int_: ...
|
| 69 |
+
@overload
|
| 70 |
+
def __call__(self, other: float, /) -> float64: ...
|
| 71 |
+
@overload
|
| 72 |
+
def __call__(self, other: complex, /) -> complex128: ...
|
| 73 |
+
@overload
|
| 74 |
+
def __call__(self, other: _NumberType, /) -> _NumberType: ...
|
| 75 |
+
|
| 76 |
+
class _BoolBitOp(Protocol[_GenericType_co]):
|
| 77 |
+
@overload
|
| 78 |
+
def __call__(self, other: _BoolLike_co, /) -> _GenericType_co: ...
|
| 79 |
+
@overload # platform dependent
|
| 80 |
+
def __call__(self, other: int, /) -> int_: ...
|
| 81 |
+
@overload
|
| 82 |
+
def __call__(self, other: _IntType, /) -> _IntType: ...
|
| 83 |
+
|
| 84 |
+
class _BoolSub(Protocol):
|
| 85 |
+
# Note that `other: bool_` is absent here
|
| 86 |
+
@overload
|
| 87 |
+
def __call__(self, other: bool, /) -> NoReturn: ...
|
| 88 |
+
@overload # platform dependent
|
| 89 |
+
def __call__(self, other: int, /) -> int_: ...
|
| 90 |
+
@overload
|
| 91 |
+
def __call__(self, other: float, /) -> float64: ...
|
| 92 |
+
@overload
|
| 93 |
+
def __call__(self, other: complex, /) -> complex128: ...
|
| 94 |
+
@overload
|
| 95 |
+
def __call__(self, other: _NumberType, /) -> _NumberType: ...
|
| 96 |
+
|
| 97 |
+
class _BoolTrueDiv(Protocol):
|
| 98 |
+
@overload
|
| 99 |
+
def __call__(self, other: float | _IntLike_co, /) -> float64: ...
|
| 100 |
+
@overload
|
| 101 |
+
def __call__(self, other: complex, /) -> complex128: ...
|
| 102 |
+
@overload
|
| 103 |
+
def __call__(self, other: _NumberType, /) -> _NumberType: ...
|
| 104 |
+
|
| 105 |
+
class _BoolMod(Protocol):
|
| 106 |
+
@overload
|
| 107 |
+
def __call__(self, other: _BoolLike_co, /) -> int8: ...
|
| 108 |
+
@overload # platform dependent
|
| 109 |
+
def __call__(self, other: int, /) -> int_: ...
|
| 110 |
+
@overload
|
| 111 |
+
def __call__(self, other: float, /) -> float64: ...
|
| 112 |
+
@overload
|
| 113 |
+
def __call__(self, other: _IntType, /) -> _IntType: ...
|
| 114 |
+
@overload
|
| 115 |
+
def __call__(self, other: _FloatType, /) -> _FloatType: ...
|
| 116 |
+
|
| 117 |
+
class _BoolDivMod(Protocol):
|
| 118 |
+
@overload
|
| 119 |
+
def __call__(self, other: _BoolLike_co, /) -> _2Tuple[int8]: ...
|
| 120 |
+
@overload # platform dependent
|
| 121 |
+
def __call__(self, other: int, /) -> _2Tuple[int_]: ...
|
| 122 |
+
@overload
|
| 123 |
+
def __call__(self, other: float, /) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
|
| 124 |
+
@overload
|
| 125 |
+
def __call__(self, other: _IntType, /) -> _2Tuple[_IntType]: ...
|
| 126 |
+
@overload
|
| 127 |
+
def __call__(self, other: _FloatType, /) -> _2Tuple[_FloatType]: ...
|
| 128 |
+
|
| 129 |
+
class _TD64Div(Protocol[_NumberType_co]):
|
| 130 |
+
@overload
|
| 131 |
+
def __call__(self, other: timedelta64, /) -> _NumberType_co: ...
|
| 132 |
+
@overload
|
| 133 |
+
def __call__(self, other: _BoolLike_co, /) -> NoReturn: ...
|
| 134 |
+
@overload
|
| 135 |
+
def __call__(self, other: _FloatLike_co, /) -> timedelta64: ...
|
| 136 |
+
|
| 137 |
+
class _IntTrueDiv(Protocol[_NBit1]):
|
| 138 |
+
@overload
|
| 139 |
+
def __call__(self, other: bool, /) -> floating[_NBit1]: ...
|
| 140 |
+
@overload
|
| 141 |
+
def __call__(self, other: int, /) -> floating[_NBit1 | _NBitInt]: ...
|
| 142 |
+
@overload
|
| 143 |
+
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
|
| 144 |
+
@overload
|
| 145 |
+
def __call__(
|
| 146 |
+
self, other: complex, /,
|
| 147 |
+
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
|
| 148 |
+
@overload
|
| 149 |
+
def __call__(self, other: integer[_NBit2], /) -> floating[_NBit1 | _NBit2]: ...
|
| 150 |
+
|
| 151 |
+
class _UnsignedIntOp(Protocol[_NBit1]):
|
| 152 |
+
# NOTE: `uint64 + signedinteger -> float64`
|
| 153 |
+
@overload
|
| 154 |
+
def __call__(self, other: bool, /) -> unsignedinteger[_NBit1]: ...
|
| 155 |
+
@overload
|
| 156 |
+
def __call__(
|
| 157 |
+
self, other: int | signedinteger[Any], /
|
| 158 |
+
) -> Any: ...
|
| 159 |
+
@overload
|
| 160 |
+
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
|
| 161 |
+
@overload
|
| 162 |
+
def __call__(
|
| 163 |
+
self, other: complex, /,
|
| 164 |
+
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
|
| 165 |
+
@overload
|
| 166 |
+
def __call__(
|
| 167 |
+
self, other: unsignedinteger[_NBit2], /
|
| 168 |
+
) -> unsignedinteger[_NBit1 | _NBit2]: ...
|
| 169 |
+
|
| 170 |
+
class _UnsignedIntBitOp(Protocol[_NBit1]):
|
| 171 |
+
@overload
|
| 172 |
+
def __call__(self, other: bool, /) -> unsignedinteger[_NBit1]: ...
|
| 173 |
+
@overload
|
| 174 |
+
def __call__(self, other: int, /) -> signedinteger[Any]: ...
|
| 175 |
+
@overload
|
| 176 |
+
def __call__(self, other: signedinteger[Any], /) -> signedinteger[Any]: ...
|
| 177 |
+
@overload
|
| 178 |
+
def __call__(
|
| 179 |
+
self, other: unsignedinteger[_NBit2], /
|
| 180 |
+
) -> unsignedinteger[_NBit1 | _NBit2]: ...
|
| 181 |
+
|
| 182 |
+
class _UnsignedIntMod(Protocol[_NBit1]):
|
| 183 |
+
@overload
|
| 184 |
+
def __call__(self, other: bool, /) -> unsignedinteger[_NBit1]: ...
|
| 185 |
+
@overload
|
| 186 |
+
def __call__(
|
| 187 |
+
self, other: int | signedinteger[Any], /
|
| 188 |
+
) -> Any: ...
|
| 189 |
+
@overload
|
| 190 |
+
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
|
| 191 |
+
@overload
|
| 192 |
+
def __call__(
|
| 193 |
+
self, other: unsignedinteger[_NBit2], /
|
| 194 |
+
) -> unsignedinteger[_NBit1 | _NBit2]: ...
|
| 195 |
+
|
| 196 |
+
class _UnsignedIntDivMod(Protocol[_NBit1]):
|
| 197 |
+
@overload
|
| 198 |
+
def __call__(self, other: bool, /) -> _2Tuple[signedinteger[_NBit1]]: ...
|
| 199 |
+
@overload
|
| 200 |
+
def __call__(
|
| 201 |
+
self, other: int | signedinteger[Any], /
|
| 202 |
+
) -> _2Tuple[Any]: ...
|
| 203 |
+
@overload
|
| 204 |
+
def __call__(self, other: float, /) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
|
| 205 |
+
@overload
|
| 206 |
+
def __call__(
|
| 207 |
+
self, other: unsignedinteger[_NBit2], /
|
| 208 |
+
) -> _2Tuple[unsignedinteger[_NBit1 | _NBit2]]: ...
|
| 209 |
+
|
| 210 |
+
class _SignedIntOp(Protocol[_NBit1]):
|
| 211 |
+
@overload
|
| 212 |
+
def __call__(self, other: bool, /) -> signedinteger[_NBit1]: ...
|
| 213 |
+
@overload
|
| 214 |
+
def __call__(self, other: int, /) -> signedinteger[_NBit1 | _NBitInt]: ...
|
| 215 |
+
@overload
|
| 216 |
+
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
|
| 217 |
+
@overload
|
| 218 |
+
def __call__(
|
| 219 |
+
self, other: complex, /,
|
| 220 |
+
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
|
| 221 |
+
@overload
|
| 222 |
+
def __call__(
|
| 223 |
+
self, other: signedinteger[_NBit2], /,
|
| 224 |
+
) -> signedinteger[_NBit1 | _NBit2]: ...
|
| 225 |
+
|
| 226 |
+
class _SignedIntBitOp(Protocol[_NBit1]):
|
| 227 |
+
@overload
|
| 228 |
+
def __call__(self, other: bool, /) -> signedinteger[_NBit1]: ...
|
| 229 |
+
@overload
|
| 230 |
+
def __call__(self, other: int, /) -> signedinteger[_NBit1 | _NBitInt]: ...
|
| 231 |
+
@overload
|
| 232 |
+
def __call__(
|
| 233 |
+
self, other: signedinteger[_NBit2], /,
|
| 234 |
+
) -> signedinteger[_NBit1 | _NBit2]: ...
|
| 235 |
+
|
| 236 |
+
class _SignedIntMod(Protocol[_NBit1]):
|
| 237 |
+
@overload
|
| 238 |
+
def __call__(self, other: bool, /) -> signedinteger[_NBit1]: ...
|
| 239 |
+
@overload
|
| 240 |
+
def __call__(self, other: int, /) -> signedinteger[_NBit1 | _NBitInt]: ...
|
| 241 |
+
@overload
|
| 242 |
+
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
|
| 243 |
+
@overload
|
| 244 |
+
def __call__(
|
| 245 |
+
self, other: signedinteger[_NBit2], /,
|
| 246 |
+
) -> signedinteger[_NBit1 | _NBit2]: ...
|
| 247 |
+
|
| 248 |
+
class _SignedIntDivMod(Protocol[_NBit1]):
|
| 249 |
+
@overload
|
| 250 |
+
def __call__(self, other: bool, /) -> _2Tuple[signedinteger[_NBit1]]: ...
|
| 251 |
+
@overload
|
| 252 |
+
def __call__(self, other: int, /) -> _2Tuple[signedinteger[_NBit1 | _NBitInt]]: ...
|
| 253 |
+
@overload
|
| 254 |
+
def __call__(self, other: float, /) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
|
| 255 |
+
@overload
|
| 256 |
+
def __call__(
|
| 257 |
+
self, other: signedinteger[_NBit2], /,
|
| 258 |
+
) -> _2Tuple[signedinteger[_NBit1 | _NBit2]]: ...
|
| 259 |
+
|
| 260 |
+
class _FloatOp(Protocol[_NBit1]):
|
| 261 |
+
@overload
|
| 262 |
+
def __call__(self, other: bool, /) -> floating[_NBit1]: ...
|
| 263 |
+
@overload
|
| 264 |
+
def __call__(self, other: int, /) -> floating[_NBit1 | _NBitInt]: ...
|
| 265 |
+
@overload
|
| 266 |
+
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
|
| 267 |
+
@overload
|
| 268 |
+
def __call__(
|
| 269 |
+
self, other: complex, /,
|
| 270 |
+
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
|
| 271 |
+
@overload
|
| 272 |
+
def __call__(
|
| 273 |
+
self, other: integer[_NBit2] | floating[_NBit2], /
|
| 274 |
+
) -> floating[_NBit1 | _NBit2]: ...
|
| 275 |
+
|
| 276 |
+
class _FloatMod(Protocol[_NBit1]):
|
| 277 |
+
@overload
|
| 278 |
+
def __call__(self, other: bool, /) -> floating[_NBit1]: ...
|
| 279 |
+
@overload
|
| 280 |
+
def __call__(self, other: int, /) -> floating[_NBit1 | _NBitInt]: ...
|
| 281 |
+
@overload
|
| 282 |
+
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
|
| 283 |
+
@overload
|
| 284 |
+
def __call__(
|
| 285 |
+
self, other: integer[_NBit2] | floating[_NBit2], /
|
| 286 |
+
) -> floating[_NBit1 | _NBit2]: ...
|
| 287 |
+
|
| 288 |
+
class _FloatDivMod(Protocol[_NBit1]):
|
| 289 |
+
@overload
|
| 290 |
+
def __call__(self, other: bool, /) -> _2Tuple[floating[_NBit1]]: ...
|
| 291 |
+
@overload
|
| 292 |
+
def __call__(self, other: int, /) -> _2Tuple[floating[_NBit1 | _NBitInt]]: ...
|
| 293 |
+
@overload
|
| 294 |
+
def __call__(self, other: float, /) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
|
| 295 |
+
@overload
|
| 296 |
+
def __call__(
|
| 297 |
+
self, other: integer[_NBit2] | floating[_NBit2], /
|
| 298 |
+
) -> _2Tuple[floating[_NBit1 | _NBit2]]: ...
|
| 299 |
+
|
| 300 |
+
class _ComplexOp(Protocol[_NBit1]):
|
| 301 |
+
@overload
|
| 302 |
+
def __call__(self, other: bool, /) -> complexfloating[_NBit1, _NBit1]: ...
|
| 303 |
+
@overload
|
| 304 |
+
def __call__(self, other: int, /) -> complexfloating[_NBit1 | _NBitInt, _NBit1 | _NBitInt]: ...
|
| 305 |
+
@overload
|
| 306 |
+
def __call__(
|
| 307 |
+
self, other: complex, /,
|
| 308 |
+
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
|
| 309 |
+
@overload
|
| 310 |
+
def __call__(
|
| 311 |
+
self,
|
| 312 |
+
other: (
|
| 313 |
+
integer[_NBit2]
|
| 314 |
+
| floating[_NBit2]
|
| 315 |
+
| complexfloating[_NBit2, _NBit2]
|
| 316 |
+
), /,
|
| 317 |
+
) -> complexfloating[_NBit1 | _NBit2, _NBit1 | _NBit2]: ...
|
| 318 |
+
|
| 319 |
+
class _NumberOp(Protocol):
|
| 320 |
+
def __call__(self, other: _NumberLike_co, /) -> Any: ...
|
| 321 |
+
|
| 322 |
+
class _SupportsLT(Protocol):
|
| 323 |
+
def __lt__(self, other: Any, /) -> object: ...
|
| 324 |
+
|
| 325 |
+
class _SupportsGT(Protocol):
|
| 326 |
+
def __gt__(self, other: Any, /) -> object: ...
|
| 327 |
+
|
| 328 |
+
class _ComparisonOp(Protocol[_T1_contra, _T2_contra]):
|
| 329 |
+
@overload
|
| 330 |
+
def __call__(self, other: _T1_contra, /) -> bool_: ...
|
| 331 |
+
@overload
|
| 332 |
+
def __call__(self, other: _T2_contra, /) -> NDArray[bool_]: ...
|
| 333 |
+
@overload
|
| 334 |
+
def __call__(
|
| 335 |
+
self,
|
| 336 |
+
other: _SupportsLT | _SupportsGT | _NestedSequence[_SupportsLT | _SupportsGT],
|
| 337 |
+
/,
|
| 338 |
+
) -> Any: ...
|
.venv/lib/python3.11/site-packages/numpy/_typing/_char_codes.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Literal
|
| 2 |
+
|
| 3 |
+
_BoolCodes = Literal["?", "=?", "<?", ">?", "bool", "bool_", "bool8"]
|
| 4 |
+
|
| 5 |
+
_UInt8Codes = Literal["uint8", "u1", "=u1", "<u1", ">u1"]
|
| 6 |
+
_UInt16Codes = Literal["uint16", "u2", "=u2", "<u2", ">u2"]
|
| 7 |
+
_UInt32Codes = Literal["uint32", "u4", "=u4", "<u4", ">u4"]
|
| 8 |
+
_UInt64Codes = Literal["uint64", "u8", "=u8", "<u8", ">u8"]
|
| 9 |
+
|
| 10 |
+
_Int8Codes = Literal["int8", "i1", "=i1", "<i1", ">i1"]
|
| 11 |
+
_Int16Codes = Literal["int16", "i2", "=i2", "<i2", ">i2"]
|
| 12 |
+
_Int32Codes = Literal["int32", "i4", "=i4", "<i4", ">i4"]
|
| 13 |
+
_Int64Codes = Literal["int64", "i8", "=i8", "<i8", ">i8"]
|
| 14 |
+
|
| 15 |
+
_Float16Codes = Literal["float16", "f2", "=f2", "<f2", ">f2"]
|
| 16 |
+
_Float32Codes = Literal["float32", "f4", "=f4", "<f4", ">f4"]
|
| 17 |
+
_Float64Codes = Literal["float64", "f8", "=f8", "<f8", ">f8"]
|
| 18 |
+
|
| 19 |
+
_Complex64Codes = Literal["complex64", "c8", "=c8", "<c8", ">c8"]
|
| 20 |
+
_Complex128Codes = Literal["complex128", "c16", "=c16", "<c16", ">c16"]
|
| 21 |
+
|
| 22 |
+
_ByteCodes = Literal["byte", "b", "=b", "<b", ">b"]
|
| 23 |
+
_ShortCodes = Literal["short", "h", "=h", "<h", ">h"]
|
| 24 |
+
_IntCCodes = Literal["intc", "i", "=i", "<i", ">i"]
|
| 25 |
+
_IntPCodes = Literal["intp", "int0", "p", "=p", "<p", ">p"]
|
| 26 |
+
_IntCodes = Literal["long", "int", "int_", "l", "=l", "<l", ">l"]
|
| 27 |
+
_LongLongCodes = Literal["longlong", "q", "=q", "<q", ">q"]
|
| 28 |
+
|
| 29 |
+
_UByteCodes = Literal["ubyte", "B", "=B", "<B", ">B"]
|
| 30 |
+
_UShortCodes = Literal["ushort", "H", "=H", "<H", ">H"]
|
| 31 |
+
_UIntCCodes = Literal["uintc", "I", "=I", "<I", ">I"]
|
| 32 |
+
_UIntPCodes = Literal["uintp", "uint0", "P", "=P", "<P", ">P"]
|
| 33 |
+
_UIntCodes = Literal["ulong", "uint", "L", "=L", "<L", ">L"]
|
| 34 |
+
_ULongLongCodes = Literal["ulonglong", "Q", "=Q", "<Q", ">Q"]
|
| 35 |
+
|
| 36 |
+
_HalfCodes = Literal["half", "e", "=e", "<e", ">e"]
|
| 37 |
+
_SingleCodes = Literal["single", "f", "=f", "<f", ">f"]
|
| 38 |
+
_DoubleCodes = Literal["double", "float", "float_", "d", "=d", "<d", ">d"]
|
| 39 |
+
_LongDoubleCodes = Literal["longdouble", "longfloat", "g", "=g", "<g", ">g"]
|
| 40 |
+
|
| 41 |
+
_CSingleCodes = Literal["csingle", "singlecomplex", "F", "=F", "<F", ">F"]
|
| 42 |
+
_CDoubleCodes = Literal["cdouble", "complex", "complex_", "cfloat", "D", "=D", "<D", ">D"]
|
| 43 |
+
_CLongDoubleCodes = Literal["clongdouble", "clongfloat", "longcomplex", "G", "=G", "<G", ">G"]
|
| 44 |
+
|
| 45 |
+
_StrCodes = Literal["str", "str_", "str0", "unicode", "unicode_", "U", "=U", "<U", ">U"]
|
| 46 |
+
_BytesCodes = Literal["bytes", "bytes_", "bytes0", "S", "=S", "<S", ">S"]
|
| 47 |
+
_VoidCodes = Literal["void", "void0", "V", "=V", "<V", ">V"]
|
| 48 |
+
_ObjectCodes = Literal["object", "object_", "O", "=O", "<O", ">O"]
|
| 49 |
+
|
| 50 |
+
_DT64Codes = Literal[
|
| 51 |
+
"datetime64", "=datetime64", "<datetime64", ">datetime64",
|
| 52 |
+
"datetime64[Y]", "=datetime64[Y]", "<datetime64[Y]", ">datetime64[Y]",
|
| 53 |
+
"datetime64[M]", "=datetime64[M]", "<datetime64[M]", ">datetime64[M]",
|
| 54 |
+
"datetime64[W]", "=datetime64[W]", "<datetime64[W]", ">datetime64[W]",
|
| 55 |
+
"datetime64[D]", "=datetime64[D]", "<datetime64[D]", ">datetime64[D]",
|
| 56 |
+
"datetime64[h]", "=datetime64[h]", "<datetime64[h]", ">datetime64[h]",
|
| 57 |
+
"datetime64[m]", "=datetime64[m]", "<datetime64[m]", ">datetime64[m]",
|
| 58 |
+
"datetime64[s]", "=datetime64[s]", "<datetime64[s]", ">datetime64[s]",
|
| 59 |
+
"datetime64[ms]", "=datetime64[ms]", "<datetime64[ms]", ">datetime64[ms]",
|
| 60 |
+
"datetime64[us]", "=datetime64[us]", "<datetime64[us]", ">datetime64[us]",
|
| 61 |
+
"datetime64[ns]", "=datetime64[ns]", "<datetime64[ns]", ">datetime64[ns]",
|
| 62 |
+
"datetime64[ps]", "=datetime64[ps]", "<datetime64[ps]", ">datetime64[ps]",
|
| 63 |
+
"datetime64[fs]", "=datetime64[fs]", "<datetime64[fs]", ">datetime64[fs]",
|
| 64 |
+
"datetime64[as]", "=datetime64[as]", "<datetime64[as]", ">datetime64[as]",
|
| 65 |
+
"M", "=M", "<M", ">M",
|
| 66 |
+
"M8", "=M8", "<M8", ">M8",
|
| 67 |
+
"M8[Y]", "=M8[Y]", "<M8[Y]", ">M8[Y]",
|
| 68 |
+
"M8[M]", "=M8[M]", "<M8[M]", ">M8[M]",
|
| 69 |
+
"M8[W]", "=M8[W]", "<M8[W]", ">M8[W]",
|
| 70 |
+
"M8[D]", "=M8[D]", "<M8[D]", ">M8[D]",
|
| 71 |
+
"M8[h]", "=M8[h]", "<M8[h]", ">M8[h]",
|
| 72 |
+
"M8[m]", "=M8[m]", "<M8[m]", ">M8[m]",
|
| 73 |
+
"M8[s]", "=M8[s]", "<M8[s]", ">M8[s]",
|
| 74 |
+
"M8[ms]", "=M8[ms]", "<M8[ms]", ">M8[ms]",
|
| 75 |
+
"M8[us]", "=M8[us]", "<M8[us]", ">M8[us]",
|
| 76 |
+
"M8[ns]", "=M8[ns]", "<M8[ns]", ">M8[ns]",
|
| 77 |
+
"M8[ps]", "=M8[ps]", "<M8[ps]", ">M8[ps]",
|
| 78 |
+
"M8[fs]", "=M8[fs]", "<M8[fs]", ">M8[fs]",
|
| 79 |
+
"M8[as]", "=M8[as]", "<M8[as]", ">M8[as]",
|
| 80 |
+
]
|
| 81 |
+
_TD64Codes = Literal[
|
| 82 |
+
"timedelta64", "=timedelta64", "<timedelta64", ">timedelta64",
|
| 83 |
+
"timedelta64[Y]", "=timedelta64[Y]", "<timedelta64[Y]", ">timedelta64[Y]",
|
| 84 |
+
"timedelta64[M]", "=timedelta64[M]", "<timedelta64[M]", ">timedelta64[M]",
|
| 85 |
+
"timedelta64[W]", "=timedelta64[W]", "<timedelta64[W]", ">timedelta64[W]",
|
| 86 |
+
"timedelta64[D]", "=timedelta64[D]", "<timedelta64[D]", ">timedelta64[D]",
|
| 87 |
+
"timedelta64[h]", "=timedelta64[h]", "<timedelta64[h]", ">timedelta64[h]",
|
| 88 |
+
"timedelta64[m]", "=timedelta64[m]", "<timedelta64[m]", ">timedelta64[m]",
|
| 89 |
+
"timedelta64[s]", "=timedelta64[s]", "<timedelta64[s]", ">timedelta64[s]",
|
| 90 |
+
"timedelta64[ms]", "=timedelta64[ms]", "<timedelta64[ms]", ">timedelta64[ms]",
|
| 91 |
+
"timedelta64[us]", "=timedelta64[us]", "<timedelta64[us]", ">timedelta64[us]",
|
| 92 |
+
"timedelta64[ns]", "=timedelta64[ns]", "<timedelta64[ns]", ">timedelta64[ns]",
|
| 93 |
+
"timedelta64[ps]", "=timedelta64[ps]", "<timedelta64[ps]", ">timedelta64[ps]",
|
| 94 |
+
"timedelta64[fs]", "=timedelta64[fs]", "<timedelta64[fs]", ">timedelta64[fs]",
|
| 95 |
+
"timedelta64[as]", "=timedelta64[as]", "<timedelta64[as]", ">timedelta64[as]",
|
| 96 |
+
"m", "=m", "<m", ">m",
|
| 97 |
+
"m8", "=m8", "<m8", ">m8",
|
| 98 |
+
"m8[Y]", "=m8[Y]", "<m8[Y]", ">m8[Y]",
|
| 99 |
+
"m8[M]", "=m8[M]", "<m8[M]", ">m8[M]",
|
| 100 |
+
"m8[W]", "=m8[W]", "<m8[W]", ">m8[W]",
|
| 101 |
+
"m8[D]", "=m8[D]", "<m8[D]", ">m8[D]",
|
| 102 |
+
"m8[h]", "=m8[h]", "<m8[h]", ">m8[h]",
|
| 103 |
+
"m8[m]", "=m8[m]", "<m8[m]", ">m8[m]",
|
| 104 |
+
"m8[s]", "=m8[s]", "<m8[s]", ">m8[s]",
|
| 105 |
+
"m8[ms]", "=m8[ms]", "<m8[ms]", ">m8[ms]",
|
| 106 |
+
"m8[us]", "=m8[us]", "<m8[us]", ">m8[us]",
|
| 107 |
+
"m8[ns]", "=m8[ns]", "<m8[ns]", ">m8[ns]",
|
| 108 |
+
"m8[ps]", "=m8[ps]", "<m8[ps]", ">m8[ps]",
|
| 109 |
+
"m8[fs]", "=m8[fs]", "<m8[fs]", ">m8[fs]",
|
| 110 |
+
"m8[as]", "=m8[as]", "<m8[as]", ">m8[as]",
|
| 111 |
+
]
|
.venv/lib/python3.11/site-packages/numpy/_typing/_dtype_like.py
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Sequence
|
| 2 |
+
from typing import (
|
| 3 |
+
Any,
|
| 4 |
+
Sequence,
|
| 5 |
+
Union,
|
| 6 |
+
TypeVar,
|
| 7 |
+
Protocol,
|
| 8 |
+
TypedDict,
|
| 9 |
+
runtime_checkable,
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
|
| 14 |
+
from ._shape import _ShapeLike
|
| 15 |
+
|
| 16 |
+
from ._char_codes import (
|
| 17 |
+
_BoolCodes,
|
| 18 |
+
_UInt8Codes,
|
| 19 |
+
_UInt16Codes,
|
| 20 |
+
_UInt32Codes,
|
| 21 |
+
_UInt64Codes,
|
| 22 |
+
_Int8Codes,
|
| 23 |
+
_Int16Codes,
|
| 24 |
+
_Int32Codes,
|
| 25 |
+
_Int64Codes,
|
| 26 |
+
_Float16Codes,
|
| 27 |
+
_Float32Codes,
|
| 28 |
+
_Float64Codes,
|
| 29 |
+
_Complex64Codes,
|
| 30 |
+
_Complex128Codes,
|
| 31 |
+
_ByteCodes,
|
| 32 |
+
_ShortCodes,
|
| 33 |
+
_IntCCodes,
|
| 34 |
+
_IntPCodes,
|
| 35 |
+
_IntCodes,
|
| 36 |
+
_LongLongCodes,
|
| 37 |
+
_UByteCodes,
|
| 38 |
+
_UShortCodes,
|
| 39 |
+
_UIntCCodes,
|
| 40 |
+
_UIntPCodes,
|
| 41 |
+
_UIntCodes,
|
| 42 |
+
_ULongLongCodes,
|
| 43 |
+
_HalfCodes,
|
| 44 |
+
_SingleCodes,
|
| 45 |
+
_DoubleCodes,
|
| 46 |
+
_LongDoubleCodes,
|
| 47 |
+
_CSingleCodes,
|
| 48 |
+
_CDoubleCodes,
|
| 49 |
+
_CLongDoubleCodes,
|
| 50 |
+
_DT64Codes,
|
| 51 |
+
_TD64Codes,
|
| 52 |
+
_StrCodes,
|
| 53 |
+
_BytesCodes,
|
| 54 |
+
_VoidCodes,
|
| 55 |
+
_ObjectCodes,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
_SCT = TypeVar("_SCT", bound=np.generic)
|
| 59 |
+
_DType_co = TypeVar("_DType_co", covariant=True, bound=np.dtype[Any])
|
| 60 |
+
|
| 61 |
+
_DTypeLikeNested = Any # TODO: wait for support for recursive types
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
# Mandatory keys
|
| 65 |
+
class _DTypeDictBase(TypedDict):
|
| 66 |
+
names: Sequence[str]
|
| 67 |
+
formats: Sequence[_DTypeLikeNested]
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# Mandatory + optional keys
|
| 71 |
+
class _DTypeDict(_DTypeDictBase, total=False):
|
| 72 |
+
# Only `str` elements are usable as indexing aliases,
|
| 73 |
+
# but `titles` can in principle accept any object
|
| 74 |
+
offsets: Sequence[int]
|
| 75 |
+
titles: Sequence[Any]
|
| 76 |
+
itemsize: int
|
| 77 |
+
aligned: bool
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
# A protocol for anything with the dtype attribute
|
| 81 |
+
@runtime_checkable
|
| 82 |
+
class _SupportsDType(Protocol[_DType_co]):
|
| 83 |
+
@property
|
| 84 |
+
def dtype(self) -> _DType_co: ...
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
# A subset of `npt.DTypeLike` that can be parametrized w.r.t. `np.generic`
|
| 88 |
+
_DTypeLike = Union[
|
| 89 |
+
np.dtype[_SCT],
|
| 90 |
+
type[_SCT],
|
| 91 |
+
_SupportsDType[np.dtype[_SCT]],
|
| 92 |
+
]
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
# Would create a dtype[np.void]
|
| 96 |
+
_VoidDTypeLike = Union[
|
| 97 |
+
# (flexible_dtype, itemsize)
|
| 98 |
+
tuple[_DTypeLikeNested, int],
|
| 99 |
+
# (fixed_dtype, shape)
|
| 100 |
+
tuple[_DTypeLikeNested, _ShapeLike],
|
| 101 |
+
# [(field_name, field_dtype, field_shape), ...]
|
| 102 |
+
#
|
| 103 |
+
# The type here is quite broad because NumPy accepts quite a wide
|
| 104 |
+
# range of inputs inside the list; see the tests for some
|
| 105 |
+
# examples.
|
| 106 |
+
list[Any],
|
| 107 |
+
# {'names': ..., 'formats': ..., 'offsets': ..., 'titles': ...,
|
| 108 |
+
# 'itemsize': ...}
|
| 109 |
+
_DTypeDict,
|
| 110 |
+
# (base_dtype, new_dtype)
|
| 111 |
+
tuple[_DTypeLikeNested, _DTypeLikeNested],
|
| 112 |
+
]
|
| 113 |
+
|
| 114 |
+
# Anything that can be coerced into numpy.dtype.
|
| 115 |
+
# Reference: https://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html
|
| 116 |
+
DTypeLike = Union[
|
| 117 |
+
np.dtype[Any],
|
| 118 |
+
# default data type (float64)
|
| 119 |
+
None,
|
| 120 |
+
# array-scalar types and generic types
|
| 121 |
+
type[Any], # NOTE: We're stuck with `type[Any]` due to object dtypes
|
| 122 |
+
# anything with a dtype attribute
|
| 123 |
+
_SupportsDType[np.dtype[Any]],
|
| 124 |
+
# character codes, type strings or comma-separated fields, e.g., 'float64'
|
| 125 |
+
str,
|
| 126 |
+
_VoidDTypeLike,
|
| 127 |
+
]
|
| 128 |
+
|
| 129 |
+
# NOTE: while it is possible to provide the dtype as a dict of
|
| 130 |
+
# dtype-like objects (e.g. `{'field1': ..., 'field2': ..., ...}`),
|
| 131 |
+
# this syntax is officially discourged and
|
| 132 |
+
# therefore not included in the Union defining `DTypeLike`.
|
| 133 |
+
#
|
| 134 |
+
# See https://github.com/numpy/numpy/issues/16891 for more details.
|
| 135 |
+
|
| 136 |
+
# Aliases for commonly used dtype-like objects.
|
| 137 |
+
# Note that the precision of `np.number` subclasses is ignored herein.
|
| 138 |
+
_DTypeLikeBool = Union[
|
| 139 |
+
type[bool],
|
| 140 |
+
type[np.bool_],
|
| 141 |
+
np.dtype[np.bool_],
|
| 142 |
+
_SupportsDType[np.dtype[np.bool_]],
|
| 143 |
+
_BoolCodes,
|
| 144 |
+
]
|
| 145 |
+
_DTypeLikeUInt = Union[
|
| 146 |
+
type[np.unsignedinteger],
|
| 147 |
+
np.dtype[np.unsignedinteger],
|
| 148 |
+
_SupportsDType[np.dtype[np.unsignedinteger]],
|
| 149 |
+
_UInt8Codes,
|
| 150 |
+
_UInt16Codes,
|
| 151 |
+
_UInt32Codes,
|
| 152 |
+
_UInt64Codes,
|
| 153 |
+
_UByteCodes,
|
| 154 |
+
_UShortCodes,
|
| 155 |
+
_UIntCCodes,
|
| 156 |
+
_UIntPCodes,
|
| 157 |
+
_UIntCodes,
|
| 158 |
+
_ULongLongCodes,
|
| 159 |
+
]
|
| 160 |
+
_DTypeLikeInt = Union[
|
| 161 |
+
type[int],
|
| 162 |
+
type[np.signedinteger],
|
| 163 |
+
np.dtype[np.signedinteger],
|
| 164 |
+
_SupportsDType[np.dtype[np.signedinteger]],
|
| 165 |
+
_Int8Codes,
|
| 166 |
+
_Int16Codes,
|
| 167 |
+
_Int32Codes,
|
| 168 |
+
_Int64Codes,
|
| 169 |
+
_ByteCodes,
|
| 170 |
+
_ShortCodes,
|
| 171 |
+
_IntCCodes,
|
| 172 |
+
_IntPCodes,
|
| 173 |
+
_IntCodes,
|
| 174 |
+
_LongLongCodes,
|
| 175 |
+
]
|
| 176 |
+
_DTypeLikeFloat = Union[
|
| 177 |
+
type[float],
|
| 178 |
+
type[np.floating],
|
| 179 |
+
np.dtype[np.floating],
|
| 180 |
+
_SupportsDType[np.dtype[np.floating]],
|
| 181 |
+
_Float16Codes,
|
| 182 |
+
_Float32Codes,
|
| 183 |
+
_Float64Codes,
|
| 184 |
+
_HalfCodes,
|
| 185 |
+
_SingleCodes,
|
| 186 |
+
_DoubleCodes,
|
| 187 |
+
_LongDoubleCodes,
|
| 188 |
+
]
|
| 189 |
+
_DTypeLikeComplex = Union[
|
| 190 |
+
type[complex],
|
| 191 |
+
type[np.complexfloating],
|
| 192 |
+
np.dtype[np.complexfloating],
|
| 193 |
+
_SupportsDType[np.dtype[np.complexfloating]],
|
| 194 |
+
_Complex64Codes,
|
| 195 |
+
_Complex128Codes,
|
| 196 |
+
_CSingleCodes,
|
| 197 |
+
_CDoubleCodes,
|
| 198 |
+
_CLongDoubleCodes,
|
| 199 |
+
]
|
| 200 |
+
_DTypeLikeDT64 = Union[
|
| 201 |
+
type[np.timedelta64],
|
| 202 |
+
np.dtype[np.timedelta64],
|
| 203 |
+
_SupportsDType[np.dtype[np.timedelta64]],
|
| 204 |
+
_TD64Codes,
|
| 205 |
+
]
|
| 206 |
+
_DTypeLikeTD64 = Union[
|
| 207 |
+
type[np.datetime64],
|
| 208 |
+
np.dtype[np.datetime64],
|
| 209 |
+
_SupportsDType[np.dtype[np.datetime64]],
|
| 210 |
+
_DT64Codes,
|
| 211 |
+
]
|
| 212 |
+
_DTypeLikeStr = Union[
|
| 213 |
+
type[str],
|
| 214 |
+
type[np.str_],
|
| 215 |
+
np.dtype[np.str_],
|
| 216 |
+
_SupportsDType[np.dtype[np.str_]],
|
| 217 |
+
_StrCodes,
|
| 218 |
+
]
|
| 219 |
+
_DTypeLikeBytes = Union[
|
| 220 |
+
type[bytes],
|
| 221 |
+
type[np.bytes_],
|
| 222 |
+
np.dtype[np.bytes_],
|
| 223 |
+
_SupportsDType[np.dtype[np.bytes_]],
|
| 224 |
+
_BytesCodes,
|
| 225 |
+
]
|
| 226 |
+
_DTypeLikeVoid = Union[
|
| 227 |
+
type[np.void],
|
| 228 |
+
np.dtype[np.void],
|
| 229 |
+
_SupportsDType[np.dtype[np.void]],
|
| 230 |
+
_VoidCodes,
|
| 231 |
+
_VoidDTypeLike,
|
| 232 |
+
]
|
| 233 |
+
_DTypeLikeObject = Union[
|
| 234 |
+
type,
|
| 235 |
+
np.dtype[np.object_],
|
| 236 |
+
_SupportsDType[np.dtype[np.object_]],
|
| 237 |
+
_ObjectCodes,
|
| 238 |
+
]
|
| 239 |
+
|
| 240 |
+
_DTypeLikeComplex_co = Union[
|
| 241 |
+
_DTypeLikeBool,
|
| 242 |
+
_DTypeLikeUInt,
|
| 243 |
+
_DTypeLikeInt,
|
| 244 |
+
_DTypeLikeFloat,
|
| 245 |
+
_DTypeLikeComplex,
|
| 246 |
+
]
|
.venv/lib/python3.11/site-packages/numpy/_typing/_extended_precision.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A module with platform-specific extended precision
|
| 2 |
+
`numpy.number` subclasses.
|
| 3 |
+
|
| 4 |
+
The subclasses are defined here (instead of ``__init__.pyi``) such
|
| 5 |
+
that they can be imported conditionally via the numpy's mypy plugin.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
from . import (
|
| 10 |
+
_80Bit,
|
| 11 |
+
_96Bit,
|
| 12 |
+
_128Bit,
|
| 13 |
+
_256Bit,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
uint128 = np.unsignedinteger[_128Bit]
|
| 17 |
+
uint256 = np.unsignedinteger[_256Bit]
|
| 18 |
+
int128 = np.signedinteger[_128Bit]
|
| 19 |
+
int256 = np.signedinteger[_256Bit]
|
| 20 |
+
float80 = np.floating[_80Bit]
|
| 21 |
+
float96 = np.floating[_96Bit]
|
| 22 |
+
float128 = np.floating[_128Bit]
|
| 23 |
+
float256 = np.floating[_256Bit]
|
| 24 |
+
complex160 = np.complexfloating[_80Bit, _80Bit]
|
| 25 |
+
complex192 = np.complexfloating[_96Bit, _96Bit]
|
| 26 |
+
complex256 = np.complexfloating[_128Bit, _128Bit]
|
| 27 |
+
complex512 = np.complexfloating[_256Bit, _256Bit]
|
.venv/lib/python3.11/site-packages/numpy/_typing/_nbit.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A module with the precisions of platform-specific `~numpy.number`s."""
|
| 2 |
+
|
| 3 |
+
from typing import Any
|
| 4 |
+
|
| 5 |
+
# To-be replaced with a `npt.NBitBase` subclass by numpy's mypy plugin
|
| 6 |
+
_NBitByte = Any
|
| 7 |
+
_NBitShort = Any
|
| 8 |
+
_NBitIntC = Any
|
| 9 |
+
_NBitIntP = Any
|
| 10 |
+
_NBitInt = Any
|
| 11 |
+
_NBitLongLong = Any
|
| 12 |
+
|
| 13 |
+
_NBitHalf = Any
|
| 14 |
+
_NBitSingle = Any
|
| 15 |
+
_NBitDouble = Any
|
| 16 |
+
_NBitLongDouble = Any
|
.venv/lib/python3.11/site-packages/numpy/_typing/_nested_sequence.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A module containing the `_NestedSequence` protocol."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from collections.abc import Iterator
|
| 6 |
+
from typing import (
|
| 7 |
+
Any,
|
| 8 |
+
TypeVar,
|
| 9 |
+
Protocol,
|
| 10 |
+
runtime_checkable,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
__all__ = ["_NestedSequence"]
|
| 14 |
+
|
| 15 |
+
_T_co = TypeVar("_T_co", covariant=True)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
@runtime_checkable
|
| 19 |
+
class _NestedSequence(Protocol[_T_co]):
|
| 20 |
+
"""A protocol for representing nested sequences.
|
| 21 |
+
|
| 22 |
+
Warning
|
| 23 |
+
-------
|
| 24 |
+
`_NestedSequence` currently does not work in combination with typevars,
|
| 25 |
+
*e.g.* ``def func(a: _NestedSequnce[T]) -> T: ...``.
|
| 26 |
+
|
| 27 |
+
See Also
|
| 28 |
+
--------
|
| 29 |
+
collections.abc.Sequence
|
| 30 |
+
ABCs for read-only and mutable :term:`sequences`.
|
| 31 |
+
|
| 32 |
+
Examples
|
| 33 |
+
--------
|
| 34 |
+
.. code-block:: python
|
| 35 |
+
|
| 36 |
+
>>> from __future__ import annotations
|
| 37 |
+
|
| 38 |
+
>>> from typing import TYPE_CHECKING
|
| 39 |
+
>>> import numpy as np
|
| 40 |
+
>>> from numpy._typing import _NestedSequence
|
| 41 |
+
|
| 42 |
+
>>> def get_dtype(seq: _NestedSequence[float]) -> np.dtype[np.float64]:
|
| 43 |
+
... return np.asarray(seq).dtype
|
| 44 |
+
|
| 45 |
+
>>> a = get_dtype([1.0])
|
| 46 |
+
>>> b = get_dtype([[1.0]])
|
| 47 |
+
>>> c = get_dtype([[[1.0]]])
|
| 48 |
+
>>> d = get_dtype([[[[1.0]]]])
|
| 49 |
+
|
| 50 |
+
>>> if TYPE_CHECKING:
|
| 51 |
+
... reveal_locals()
|
| 52 |
+
... # note: Revealed local types are:
|
| 53 |
+
... # note: a: numpy.dtype[numpy.floating[numpy._typing._64Bit]]
|
| 54 |
+
... # note: b: numpy.dtype[numpy.floating[numpy._typing._64Bit]]
|
| 55 |
+
... # note: c: numpy.dtype[numpy.floating[numpy._typing._64Bit]]
|
| 56 |
+
... # note: d: numpy.dtype[numpy.floating[numpy._typing._64Bit]]
|
| 57 |
+
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
def __len__(self, /) -> int:
|
| 61 |
+
"""Implement ``len(self)``."""
|
| 62 |
+
raise NotImplementedError
|
| 63 |
+
|
| 64 |
+
def __getitem__(self, index: int, /) -> _T_co | _NestedSequence[_T_co]:
|
| 65 |
+
"""Implement ``self[x]``."""
|
| 66 |
+
raise NotImplementedError
|
| 67 |
+
|
| 68 |
+
def __contains__(self, x: object, /) -> bool:
|
| 69 |
+
"""Implement ``x in self``."""
|
| 70 |
+
raise NotImplementedError
|
| 71 |
+
|
| 72 |
+
def __iter__(self, /) -> Iterator[_T_co | _NestedSequence[_T_co]]:
|
| 73 |
+
"""Implement ``iter(self)``."""
|
| 74 |
+
raise NotImplementedError
|
| 75 |
+
|
| 76 |
+
def __reversed__(self, /) -> Iterator[_T_co | _NestedSequence[_T_co]]:
|
| 77 |
+
"""Implement ``reversed(self)``."""
|
| 78 |
+
raise NotImplementedError
|
| 79 |
+
|
| 80 |
+
def count(self, value: Any, /) -> int:
|
| 81 |
+
"""Return the number of occurrences of `value`."""
|
| 82 |
+
raise NotImplementedError
|
| 83 |
+
|
| 84 |
+
def index(self, value: Any, /) -> int:
|
| 85 |
+
"""Return the first index of `value`."""
|
| 86 |
+
raise NotImplementedError
|
.venv/lib/python3.11/site-packages/numpy/_typing/_scalars.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Union, Any
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# NOTE: `_StrLike_co` and `_BytesLike_co` are pointless, as `np.str_` and
|
| 6 |
+
# `np.bytes_` are already subclasses of their builtin counterpart
|
| 7 |
+
|
| 8 |
+
_CharLike_co = Union[str, bytes]
|
| 9 |
+
|
| 10 |
+
# The 6 `<X>Like_co` type-aliases below represent all scalars that can be
|
| 11 |
+
# coerced into `<X>` (with the casting rule `same_kind`)
|
| 12 |
+
_BoolLike_co = Union[bool, np.bool_]
|
| 13 |
+
_UIntLike_co = Union[_BoolLike_co, np.unsignedinteger[Any]]
|
| 14 |
+
_IntLike_co = Union[_BoolLike_co, int, np.integer[Any]]
|
| 15 |
+
_FloatLike_co = Union[_IntLike_co, float, np.floating[Any]]
|
| 16 |
+
_ComplexLike_co = Union[_FloatLike_co, complex, np.complexfloating[Any, Any]]
|
| 17 |
+
_TD64Like_co = Union[_IntLike_co, np.timedelta64]
|
| 18 |
+
|
| 19 |
+
_NumberLike_co = Union[int, float, complex, np.number[Any], np.bool_]
|
| 20 |
+
_ScalarLike_co = Union[
|
| 21 |
+
int,
|
| 22 |
+
float,
|
| 23 |
+
complex,
|
| 24 |
+
str,
|
| 25 |
+
bytes,
|
| 26 |
+
np.generic,
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
# `_VoidLike_co` is technically not a scalar, but it's close enough
|
| 30 |
+
_VoidLike_co = Union[tuple[Any, ...], np.void]
|
.venv/lib/python3.11/site-packages/numpy/_typing/_shape.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Sequence
|
| 2 |
+
from typing import Union, SupportsIndex
|
| 3 |
+
|
| 4 |
+
_Shape = tuple[int, ...]
|
| 5 |
+
|
| 6 |
+
# Anything that can be coerced to a shape tuple
|
| 7 |
+
_ShapeLike = Union[SupportsIndex, Sequence[SupportsIndex]]
|
.venv/lib/python3.11/site-packages/numpy/_typing/_ufunc.pyi
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A module with private type-check-only `numpy.ufunc` subclasses.
|
| 2 |
+
|
| 3 |
+
The signatures of the ufuncs are too varied to reasonably type
|
| 4 |
+
with a single class. So instead, `ufunc` has been expanded into
|
| 5 |
+
four private subclasses, one for each combination of
|
| 6 |
+
`~ufunc.nin` and `~ufunc.nout`.
|
| 7 |
+
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from typing import (
|
| 11 |
+
Any,
|
| 12 |
+
Generic,
|
| 13 |
+
overload,
|
| 14 |
+
TypeVar,
|
| 15 |
+
Literal,
|
| 16 |
+
SupportsIndex,
|
| 17 |
+
Protocol,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
from numpy import ufunc, _CastingKind, _OrderKACF
|
| 21 |
+
from numpy.typing import NDArray
|
| 22 |
+
|
| 23 |
+
from ._shape import _ShapeLike
|
| 24 |
+
from ._scalars import _ScalarLike_co
|
| 25 |
+
from ._array_like import ArrayLike, _ArrayLikeBool_co, _ArrayLikeInt_co
|
| 26 |
+
from ._dtype_like import DTypeLike
|
| 27 |
+
|
| 28 |
+
_T = TypeVar("_T")
|
| 29 |
+
_2Tuple = tuple[_T, _T]
|
| 30 |
+
_3Tuple = tuple[_T, _T, _T]
|
| 31 |
+
_4Tuple = tuple[_T, _T, _T, _T]
|
| 32 |
+
|
| 33 |
+
_NTypes = TypeVar("_NTypes", bound=int)
|
| 34 |
+
_IDType = TypeVar("_IDType", bound=Any)
|
| 35 |
+
_NameType = TypeVar("_NameType", bound=str)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class _SupportsArrayUFunc(Protocol):
|
| 39 |
+
def __array_ufunc__(
|
| 40 |
+
self,
|
| 41 |
+
ufunc: ufunc,
|
| 42 |
+
method: Literal["__call__", "reduce", "reduceat", "accumulate", "outer", "inner"],
|
| 43 |
+
*inputs: Any,
|
| 44 |
+
**kwargs: Any,
|
| 45 |
+
) -> Any: ...
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# NOTE: In reality `extobj` should be a length of list 3 containing an
|
| 49 |
+
# int, an int, and a callable, but there's no way to properly express
|
| 50 |
+
# non-homogenous lists.
|
| 51 |
+
# Use `Any` over `Union` to avoid issues related to lists invariance.
|
| 52 |
+
|
| 53 |
+
# NOTE: `reduce`, `accumulate`, `reduceat` and `outer` raise a ValueError for
|
| 54 |
+
# ufuncs that don't accept two input arguments and return one output argument.
|
| 55 |
+
# In such cases the respective methods are simply typed as `None`.
|
| 56 |
+
|
| 57 |
+
# NOTE: Similarly, `at` won't be defined for ufuncs that return
|
| 58 |
+
# multiple outputs; in such cases `at` is typed as `None`
|
| 59 |
+
|
| 60 |
+
# NOTE: If 2 output types are returned then `out` must be a
|
| 61 |
+
# 2-tuple of arrays. Otherwise `None` or a plain array are also acceptable
|
| 62 |
+
|
| 63 |
+
class _UFunc_Nin1_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc]
|
| 64 |
+
@property
|
| 65 |
+
def __name__(self) -> _NameType: ...
|
| 66 |
+
@property
|
| 67 |
+
def ntypes(self) -> _NTypes: ...
|
| 68 |
+
@property
|
| 69 |
+
def identity(self) -> _IDType: ...
|
| 70 |
+
@property
|
| 71 |
+
def nin(self) -> Literal[1]: ...
|
| 72 |
+
@property
|
| 73 |
+
def nout(self) -> Literal[1]: ...
|
| 74 |
+
@property
|
| 75 |
+
def nargs(self) -> Literal[2]: ...
|
| 76 |
+
@property
|
| 77 |
+
def signature(self) -> None: ...
|
| 78 |
+
@property
|
| 79 |
+
def reduce(self) -> None: ...
|
| 80 |
+
@property
|
| 81 |
+
def accumulate(self) -> None: ...
|
| 82 |
+
@property
|
| 83 |
+
def reduceat(self) -> None: ...
|
| 84 |
+
@property
|
| 85 |
+
def outer(self) -> None: ...
|
| 86 |
+
|
| 87 |
+
@overload
|
| 88 |
+
def __call__(
|
| 89 |
+
self,
|
| 90 |
+
__x1: _ScalarLike_co,
|
| 91 |
+
out: None = ...,
|
| 92 |
+
*,
|
| 93 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 94 |
+
casting: _CastingKind = ...,
|
| 95 |
+
order: _OrderKACF = ...,
|
| 96 |
+
dtype: DTypeLike = ...,
|
| 97 |
+
subok: bool = ...,
|
| 98 |
+
signature: str | _2Tuple[None | str] = ...,
|
| 99 |
+
extobj: list[Any] = ...,
|
| 100 |
+
) -> Any: ...
|
| 101 |
+
@overload
|
| 102 |
+
def __call__(
|
| 103 |
+
self,
|
| 104 |
+
__x1: ArrayLike,
|
| 105 |
+
out: None | NDArray[Any] | tuple[NDArray[Any]] = ...,
|
| 106 |
+
*,
|
| 107 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 108 |
+
casting: _CastingKind = ...,
|
| 109 |
+
order: _OrderKACF = ...,
|
| 110 |
+
dtype: DTypeLike = ...,
|
| 111 |
+
subok: bool = ...,
|
| 112 |
+
signature: str | _2Tuple[None | str] = ...,
|
| 113 |
+
extobj: list[Any] = ...,
|
| 114 |
+
) -> NDArray[Any]: ...
|
| 115 |
+
@overload
|
| 116 |
+
def __call__(
|
| 117 |
+
self,
|
| 118 |
+
__x1: _SupportsArrayUFunc,
|
| 119 |
+
out: None | NDArray[Any] | tuple[NDArray[Any]] = ...,
|
| 120 |
+
*,
|
| 121 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 122 |
+
casting: _CastingKind = ...,
|
| 123 |
+
order: _OrderKACF = ...,
|
| 124 |
+
dtype: DTypeLike = ...,
|
| 125 |
+
subok: bool = ...,
|
| 126 |
+
signature: str | _2Tuple[None | str] = ...,
|
| 127 |
+
extobj: list[Any] = ...,
|
| 128 |
+
) -> Any: ...
|
| 129 |
+
|
| 130 |
+
def at(
|
| 131 |
+
self,
|
| 132 |
+
a: _SupportsArrayUFunc,
|
| 133 |
+
indices: _ArrayLikeInt_co,
|
| 134 |
+
/,
|
| 135 |
+
) -> None: ...
|
| 136 |
+
|
| 137 |
+
class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc]
|
| 138 |
+
@property
|
| 139 |
+
def __name__(self) -> _NameType: ...
|
| 140 |
+
@property
|
| 141 |
+
def ntypes(self) -> _NTypes: ...
|
| 142 |
+
@property
|
| 143 |
+
def identity(self) -> _IDType: ...
|
| 144 |
+
@property
|
| 145 |
+
def nin(self) -> Literal[2]: ...
|
| 146 |
+
@property
|
| 147 |
+
def nout(self) -> Literal[1]: ...
|
| 148 |
+
@property
|
| 149 |
+
def nargs(self) -> Literal[3]: ...
|
| 150 |
+
@property
|
| 151 |
+
def signature(self) -> None: ...
|
| 152 |
+
|
| 153 |
+
@overload
|
| 154 |
+
def __call__(
|
| 155 |
+
self,
|
| 156 |
+
__x1: _ScalarLike_co,
|
| 157 |
+
__x2: _ScalarLike_co,
|
| 158 |
+
out: None = ...,
|
| 159 |
+
*,
|
| 160 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 161 |
+
casting: _CastingKind = ...,
|
| 162 |
+
order: _OrderKACF = ...,
|
| 163 |
+
dtype: DTypeLike = ...,
|
| 164 |
+
subok: bool = ...,
|
| 165 |
+
signature: str | _3Tuple[None | str] = ...,
|
| 166 |
+
extobj: list[Any] = ...,
|
| 167 |
+
) -> Any: ...
|
| 168 |
+
@overload
|
| 169 |
+
def __call__(
|
| 170 |
+
self,
|
| 171 |
+
__x1: ArrayLike,
|
| 172 |
+
__x2: ArrayLike,
|
| 173 |
+
out: None | NDArray[Any] | tuple[NDArray[Any]] = ...,
|
| 174 |
+
*,
|
| 175 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 176 |
+
casting: _CastingKind = ...,
|
| 177 |
+
order: _OrderKACF = ...,
|
| 178 |
+
dtype: DTypeLike = ...,
|
| 179 |
+
subok: bool = ...,
|
| 180 |
+
signature: str | _3Tuple[None | str] = ...,
|
| 181 |
+
extobj: list[Any] = ...,
|
| 182 |
+
) -> NDArray[Any]: ...
|
| 183 |
+
|
| 184 |
+
def at(
|
| 185 |
+
self,
|
| 186 |
+
a: NDArray[Any],
|
| 187 |
+
indices: _ArrayLikeInt_co,
|
| 188 |
+
b: ArrayLike,
|
| 189 |
+
/,
|
| 190 |
+
) -> None: ...
|
| 191 |
+
|
| 192 |
+
def reduce(
|
| 193 |
+
self,
|
| 194 |
+
array: ArrayLike,
|
| 195 |
+
axis: None | _ShapeLike = ...,
|
| 196 |
+
dtype: DTypeLike = ...,
|
| 197 |
+
out: None | NDArray[Any] = ...,
|
| 198 |
+
keepdims: bool = ...,
|
| 199 |
+
initial: Any = ...,
|
| 200 |
+
where: _ArrayLikeBool_co = ...,
|
| 201 |
+
) -> Any: ...
|
| 202 |
+
|
| 203 |
+
def accumulate(
|
| 204 |
+
self,
|
| 205 |
+
array: ArrayLike,
|
| 206 |
+
axis: SupportsIndex = ...,
|
| 207 |
+
dtype: DTypeLike = ...,
|
| 208 |
+
out: None | NDArray[Any] = ...,
|
| 209 |
+
) -> NDArray[Any]: ...
|
| 210 |
+
|
| 211 |
+
def reduceat(
|
| 212 |
+
self,
|
| 213 |
+
array: ArrayLike,
|
| 214 |
+
indices: _ArrayLikeInt_co,
|
| 215 |
+
axis: SupportsIndex = ...,
|
| 216 |
+
dtype: DTypeLike = ...,
|
| 217 |
+
out: None | NDArray[Any] = ...,
|
| 218 |
+
) -> NDArray[Any]: ...
|
| 219 |
+
|
| 220 |
+
# Expand `**kwargs` into explicit keyword-only arguments
|
| 221 |
+
@overload
|
| 222 |
+
def outer(
|
| 223 |
+
self,
|
| 224 |
+
A: _ScalarLike_co,
|
| 225 |
+
B: _ScalarLike_co,
|
| 226 |
+
/, *,
|
| 227 |
+
out: None = ...,
|
| 228 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 229 |
+
casting: _CastingKind = ...,
|
| 230 |
+
order: _OrderKACF = ...,
|
| 231 |
+
dtype: DTypeLike = ...,
|
| 232 |
+
subok: bool = ...,
|
| 233 |
+
signature: str | _3Tuple[None | str] = ...,
|
| 234 |
+
extobj: list[Any] = ...,
|
| 235 |
+
) -> Any: ...
|
| 236 |
+
@overload
|
| 237 |
+
def outer( # type: ignore[misc]
|
| 238 |
+
self,
|
| 239 |
+
A: ArrayLike,
|
| 240 |
+
B: ArrayLike,
|
| 241 |
+
/, *,
|
| 242 |
+
out: None | NDArray[Any] | tuple[NDArray[Any]] = ...,
|
| 243 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 244 |
+
casting: _CastingKind = ...,
|
| 245 |
+
order: _OrderKACF = ...,
|
| 246 |
+
dtype: DTypeLike = ...,
|
| 247 |
+
subok: bool = ...,
|
| 248 |
+
signature: str | _3Tuple[None | str] = ...,
|
| 249 |
+
extobj: list[Any] = ...,
|
| 250 |
+
) -> NDArray[Any]: ...
|
| 251 |
+
|
| 252 |
+
class _UFunc_Nin1_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc]
|
| 253 |
+
@property
|
| 254 |
+
def __name__(self) -> _NameType: ...
|
| 255 |
+
@property
|
| 256 |
+
def ntypes(self) -> _NTypes: ...
|
| 257 |
+
@property
|
| 258 |
+
def identity(self) -> _IDType: ...
|
| 259 |
+
@property
|
| 260 |
+
def nin(self) -> Literal[1]: ...
|
| 261 |
+
@property
|
| 262 |
+
def nout(self) -> Literal[2]: ...
|
| 263 |
+
@property
|
| 264 |
+
def nargs(self) -> Literal[3]: ...
|
| 265 |
+
@property
|
| 266 |
+
def signature(self) -> None: ...
|
| 267 |
+
@property
|
| 268 |
+
def at(self) -> None: ...
|
| 269 |
+
@property
|
| 270 |
+
def reduce(self) -> None: ...
|
| 271 |
+
@property
|
| 272 |
+
def accumulate(self) -> None: ...
|
| 273 |
+
@property
|
| 274 |
+
def reduceat(self) -> None: ...
|
| 275 |
+
@property
|
| 276 |
+
def outer(self) -> None: ...
|
| 277 |
+
|
| 278 |
+
@overload
|
| 279 |
+
def __call__(
|
| 280 |
+
self,
|
| 281 |
+
__x1: _ScalarLike_co,
|
| 282 |
+
__out1: None = ...,
|
| 283 |
+
__out2: None = ...,
|
| 284 |
+
*,
|
| 285 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 286 |
+
casting: _CastingKind = ...,
|
| 287 |
+
order: _OrderKACF = ...,
|
| 288 |
+
dtype: DTypeLike = ...,
|
| 289 |
+
subok: bool = ...,
|
| 290 |
+
signature: str | _3Tuple[None | str] = ...,
|
| 291 |
+
extobj: list[Any] = ...,
|
| 292 |
+
) -> _2Tuple[Any]: ...
|
| 293 |
+
@overload
|
| 294 |
+
def __call__(
|
| 295 |
+
self,
|
| 296 |
+
__x1: ArrayLike,
|
| 297 |
+
__out1: None | NDArray[Any] = ...,
|
| 298 |
+
__out2: None | NDArray[Any] = ...,
|
| 299 |
+
*,
|
| 300 |
+
out: _2Tuple[NDArray[Any]] = ...,
|
| 301 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 302 |
+
casting: _CastingKind = ...,
|
| 303 |
+
order: _OrderKACF = ...,
|
| 304 |
+
dtype: DTypeLike = ...,
|
| 305 |
+
subok: bool = ...,
|
| 306 |
+
signature: str | _3Tuple[None | str] = ...,
|
| 307 |
+
extobj: list[Any] = ...,
|
| 308 |
+
) -> _2Tuple[NDArray[Any]]: ...
|
| 309 |
+
@overload
|
| 310 |
+
def __call__(
|
| 311 |
+
self,
|
| 312 |
+
__x1: _SupportsArrayUFunc,
|
| 313 |
+
__out1: None | NDArray[Any] = ...,
|
| 314 |
+
__out2: None | NDArray[Any] = ...,
|
| 315 |
+
*,
|
| 316 |
+
out: _2Tuple[NDArray[Any]] = ...,
|
| 317 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 318 |
+
casting: _CastingKind = ...,
|
| 319 |
+
order: _OrderKACF = ...,
|
| 320 |
+
dtype: DTypeLike = ...,
|
| 321 |
+
subok: bool = ...,
|
| 322 |
+
signature: str | _3Tuple[None | str] = ...,
|
| 323 |
+
extobj: list[Any] = ...,
|
| 324 |
+
) -> _2Tuple[Any]: ...
|
| 325 |
+
|
| 326 |
+
class _UFunc_Nin2_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc]
|
| 327 |
+
@property
|
| 328 |
+
def __name__(self) -> _NameType: ...
|
| 329 |
+
@property
|
| 330 |
+
def ntypes(self) -> _NTypes: ...
|
| 331 |
+
@property
|
| 332 |
+
def identity(self) -> _IDType: ...
|
| 333 |
+
@property
|
| 334 |
+
def nin(self) -> Literal[2]: ...
|
| 335 |
+
@property
|
| 336 |
+
def nout(self) -> Literal[2]: ...
|
| 337 |
+
@property
|
| 338 |
+
def nargs(self) -> Literal[4]: ...
|
| 339 |
+
@property
|
| 340 |
+
def signature(self) -> None: ...
|
| 341 |
+
@property
|
| 342 |
+
def at(self) -> None: ...
|
| 343 |
+
@property
|
| 344 |
+
def reduce(self) -> None: ...
|
| 345 |
+
@property
|
| 346 |
+
def accumulate(self) -> None: ...
|
| 347 |
+
@property
|
| 348 |
+
def reduceat(self) -> None: ...
|
| 349 |
+
@property
|
| 350 |
+
def outer(self) -> None: ...
|
| 351 |
+
|
| 352 |
+
@overload
|
| 353 |
+
def __call__(
|
| 354 |
+
self,
|
| 355 |
+
__x1: _ScalarLike_co,
|
| 356 |
+
__x2: _ScalarLike_co,
|
| 357 |
+
__out1: None = ...,
|
| 358 |
+
__out2: None = ...,
|
| 359 |
+
*,
|
| 360 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 361 |
+
casting: _CastingKind = ...,
|
| 362 |
+
order: _OrderKACF = ...,
|
| 363 |
+
dtype: DTypeLike = ...,
|
| 364 |
+
subok: bool = ...,
|
| 365 |
+
signature: str | _4Tuple[None | str] = ...,
|
| 366 |
+
extobj: list[Any] = ...,
|
| 367 |
+
) -> _2Tuple[Any]: ...
|
| 368 |
+
@overload
|
| 369 |
+
def __call__(
|
| 370 |
+
self,
|
| 371 |
+
__x1: ArrayLike,
|
| 372 |
+
__x2: ArrayLike,
|
| 373 |
+
__out1: None | NDArray[Any] = ...,
|
| 374 |
+
__out2: None | NDArray[Any] = ...,
|
| 375 |
+
*,
|
| 376 |
+
out: _2Tuple[NDArray[Any]] = ...,
|
| 377 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 378 |
+
casting: _CastingKind = ...,
|
| 379 |
+
order: _OrderKACF = ...,
|
| 380 |
+
dtype: DTypeLike = ...,
|
| 381 |
+
subok: bool = ...,
|
| 382 |
+
signature: str | _4Tuple[None | str] = ...,
|
| 383 |
+
extobj: list[Any] = ...,
|
| 384 |
+
) -> _2Tuple[NDArray[Any]]: ...
|
| 385 |
+
|
| 386 |
+
class _GUFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc]
|
| 387 |
+
@property
|
| 388 |
+
def __name__(self) -> _NameType: ...
|
| 389 |
+
@property
|
| 390 |
+
def ntypes(self) -> _NTypes: ...
|
| 391 |
+
@property
|
| 392 |
+
def identity(self) -> _IDType: ...
|
| 393 |
+
@property
|
| 394 |
+
def nin(self) -> Literal[2]: ...
|
| 395 |
+
@property
|
| 396 |
+
def nout(self) -> Literal[1]: ...
|
| 397 |
+
@property
|
| 398 |
+
def nargs(self) -> Literal[3]: ...
|
| 399 |
+
|
| 400 |
+
# NOTE: In practice the only gufunc in the main namespace is `matmul`,
|
| 401 |
+
# so we can use its signature here
|
| 402 |
+
@property
|
| 403 |
+
def signature(self) -> Literal["(n?,k),(k,m?)->(n?,m?)"]: ...
|
| 404 |
+
@property
|
| 405 |
+
def reduce(self) -> None: ...
|
| 406 |
+
@property
|
| 407 |
+
def accumulate(self) -> None: ...
|
| 408 |
+
@property
|
| 409 |
+
def reduceat(self) -> None: ...
|
| 410 |
+
@property
|
| 411 |
+
def outer(self) -> None: ...
|
| 412 |
+
@property
|
| 413 |
+
def at(self) -> None: ...
|
| 414 |
+
|
| 415 |
+
# Scalar for 1D array-likes; ndarray otherwise
|
| 416 |
+
@overload
|
| 417 |
+
def __call__(
|
| 418 |
+
self,
|
| 419 |
+
__x1: ArrayLike,
|
| 420 |
+
__x2: ArrayLike,
|
| 421 |
+
out: None = ...,
|
| 422 |
+
*,
|
| 423 |
+
casting: _CastingKind = ...,
|
| 424 |
+
order: _OrderKACF = ...,
|
| 425 |
+
dtype: DTypeLike = ...,
|
| 426 |
+
subok: bool = ...,
|
| 427 |
+
signature: str | _3Tuple[None | str] = ...,
|
| 428 |
+
extobj: list[Any] = ...,
|
| 429 |
+
axes: list[_2Tuple[SupportsIndex]] = ...,
|
| 430 |
+
) -> Any: ...
|
| 431 |
+
@overload
|
| 432 |
+
def __call__(
|
| 433 |
+
self,
|
| 434 |
+
__x1: ArrayLike,
|
| 435 |
+
__x2: ArrayLike,
|
| 436 |
+
out: NDArray[Any] | tuple[NDArray[Any]],
|
| 437 |
+
*,
|
| 438 |
+
casting: _CastingKind = ...,
|
| 439 |
+
order: _OrderKACF = ...,
|
| 440 |
+
dtype: DTypeLike = ...,
|
| 441 |
+
subok: bool = ...,
|
| 442 |
+
signature: str | _3Tuple[None | str] = ...,
|
| 443 |
+
extobj: list[Any] = ...,
|
| 444 |
+
axes: list[_2Tuple[SupportsIndex]] = ...,
|
| 445 |
+
) -> NDArray[Any]: ...
|
.venv/lib/python3.11/site-packages/numpy/_typing/setup.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def configuration(parent_package='', top_path=None):
|
| 2 |
+
from numpy.distutils.misc_util import Configuration
|
| 3 |
+
config = Configuration('_typing', parent_package, top_path)
|
| 4 |
+
config.add_data_files('*.pyi')
|
| 5 |
+
return config
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
if __name__ == '__main__':
|
| 9 |
+
from numpy.distutils.core import setup
|
| 10 |
+
setup(configuration=configuration)
|
.venv/lib/python3.11/site-packages/numpy/fft/__init__.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Discrete Fourier Transform (:mod:`numpy.fft`)
|
| 3 |
+
=============================================
|
| 4 |
+
|
| 5 |
+
.. currentmodule:: numpy.fft
|
| 6 |
+
|
| 7 |
+
The SciPy module `scipy.fft` is a more comprehensive superset
|
| 8 |
+
of ``numpy.fft``, which includes only a basic set of routines.
|
| 9 |
+
|
| 10 |
+
Standard FFTs
|
| 11 |
+
-------------
|
| 12 |
+
|
| 13 |
+
.. autosummary::
|
| 14 |
+
:toctree: generated/
|
| 15 |
+
|
| 16 |
+
fft Discrete Fourier transform.
|
| 17 |
+
ifft Inverse discrete Fourier transform.
|
| 18 |
+
fft2 Discrete Fourier transform in two dimensions.
|
| 19 |
+
ifft2 Inverse discrete Fourier transform in two dimensions.
|
| 20 |
+
fftn Discrete Fourier transform in N-dimensions.
|
| 21 |
+
ifftn Inverse discrete Fourier transform in N dimensions.
|
| 22 |
+
|
| 23 |
+
Real FFTs
|
| 24 |
+
---------
|
| 25 |
+
|
| 26 |
+
.. autosummary::
|
| 27 |
+
:toctree: generated/
|
| 28 |
+
|
| 29 |
+
rfft Real discrete Fourier transform.
|
| 30 |
+
irfft Inverse real discrete Fourier transform.
|
| 31 |
+
rfft2 Real discrete Fourier transform in two dimensions.
|
| 32 |
+
irfft2 Inverse real discrete Fourier transform in two dimensions.
|
| 33 |
+
rfftn Real discrete Fourier transform in N dimensions.
|
| 34 |
+
irfftn Inverse real discrete Fourier transform in N dimensions.
|
| 35 |
+
|
| 36 |
+
Hermitian FFTs
|
| 37 |
+
--------------
|
| 38 |
+
|
| 39 |
+
.. autosummary::
|
| 40 |
+
:toctree: generated/
|
| 41 |
+
|
| 42 |
+
hfft Hermitian discrete Fourier transform.
|
| 43 |
+
ihfft Inverse Hermitian discrete Fourier transform.
|
| 44 |
+
|
| 45 |
+
Helper routines
|
| 46 |
+
---------------
|
| 47 |
+
|
| 48 |
+
.. autosummary::
|
| 49 |
+
:toctree: generated/
|
| 50 |
+
|
| 51 |
+
fftfreq Discrete Fourier Transform sample frequencies.
|
| 52 |
+
rfftfreq DFT sample frequencies (for usage with rfft, irfft).
|
| 53 |
+
fftshift Shift zero-frequency component to center of spectrum.
|
| 54 |
+
ifftshift Inverse of fftshift.
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Background information
|
| 58 |
+
----------------------
|
| 59 |
+
|
| 60 |
+
Fourier analysis is fundamentally a method for expressing a function as a
|
| 61 |
+
sum of periodic components, and for recovering the function from those
|
| 62 |
+
components. When both the function and its Fourier transform are
|
| 63 |
+
replaced with discretized counterparts, it is called the discrete Fourier
|
| 64 |
+
transform (DFT). The DFT has become a mainstay of numerical computing in
|
| 65 |
+
part because of a very fast algorithm for computing it, called the Fast
|
| 66 |
+
Fourier Transform (FFT), which was known to Gauss (1805) and was brought
|
| 67 |
+
to light in its current form by Cooley and Tukey [CT]_. Press et al. [NR]_
|
| 68 |
+
provide an accessible introduction to Fourier analysis and its
|
| 69 |
+
applications.
|
| 70 |
+
|
| 71 |
+
Because the discrete Fourier transform separates its input into
|
| 72 |
+
components that contribute at discrete frequencies, it has a great number
|
| 73 |
+
of applications in digital signal processing, e.g., for filtering, and in
|
| 74 |
+
this context the discretized input to the transform is customarily
|
| 75 |
+
referred to as a *signal*, which exists in the *time domain*. The output
|
| 76 |
+
is called a *spectrum* or *transform* and exists in the *frequency
|
| 77 |
+
domain*.
|
| 78 |
+
|
| 79 |
+
Implementation details
|
| 80 |
+
----------------------
|
| 81 |
+
|
| 82 |
+
There are many ways to define the DFT, varying in the sign of the
|
| 83 |
+
exponent, normalization, etc. In this implementation, the DFT is defined
|
| 84 |
+
as
|
| 85 |
+
|
| 86 |
+
.. math::
|
| 87 |
+
A_k = \\sum_{m=0}^{n-1} a_m \\exp\\left\\{-2\\pi i{mk \\over n}\\right\\}
|
| 88 |
+
\\qquad k = 0,\\ldots,n-1.
|
| 89 |
+
|
| 90 |
+
The DFT is in general defined for complex inputs and outputs, and a
|
| 91 |
+
single-frequency component at linear frequency :math:`f` is
|
| 92 |
+
represented by a complex exponential
|
| 93 |
+
:math:`a_m = \\exp\\{2\\pi i\\,f m\\Delta t\\}`, where :math:`\\Delta t`
|
| 94 |
+
is the sampling interval.
|
| 95 |
+
|
| 96 |
+
The values in the result follow so-called "standard" order: If ``A =
|
| 97 |
+
fft(a, n)``, then ``A[0]`` contains the zero-frequency term (the sum of
|
| 98 |
+
the signal), which is always purely real for real inputs. Then ``A[1:n/2]``
|
| 99 |
+
contains the positive-frequency terms, and ``A[n/2+1:]`` contains the
|
| 100 |
+
negative-frequency terms, in order of decreasingly negative frequency.
|
| 101 |
+
For an even number of input points, ``A[n/2]`` represents both positive and
|
| 102 |
+
negative Nyquist frequency, and is also purely real for real input. For
|
| 103 |
+
an odd number of input points, ``A[(n-1)/2]`` contains the largest positive
|
| 104 |
+
frequency, while ``A[(n+1)/2]`` contains the largest negative frequency.
|
| 105 |
+
The routine ``np.fft.fftfreq(n)`` returns an array giving the frequencies
|
| 106 |
+
of corresponding elements in the output. The routine
|
| 107 |
+
``np.fft.fftshift(A)`` shifts transforms and their frequencies to put the
|
| 108 |
+
zero-frequency components in the middle, and ``np.fft.ifftshift(A)`` undoes
|
| 109 |
+
that shift.
|
| 110 |
+
|
| 111 |
+
When the input `a` is a time-domain signal and ``A = fft(a)``, ``np.abs(A)``
|
| 112 |
+
is its amplitude spectrum and ``np.abs(A)**2`` is its power spectrum.
|
| 113 |
+
The phase spectrum is obtained by ``np.angle(A)``.
|
| 114 |
+
|
| 115 |
+
The inverse DFT is defined as
|
| 116 |
+
|
| 117 |
+
.. math::
|
| 118 |
+
a_m = \\frac{1}{n}\\sum_{k=0}^{n-1}A_k\\exp\\left\\{2\\pi i{mk\\over n}\\right\\}
|
| 119 |
+
\\qquad m = 0,\\ldots,n-1.
|
| 120 |
+
|
| 121 |
+
It differs from the forward transform by the sign of the exponential
|
| 122 |
+
argument and the default normalization by :math:`1/n`.
|
| 123 |
+
|
| 124 |
+
Type Promotion
|
| 125 |
+
--------------
|
| 126 |
+
|
| 127 |
+
`numpy.fft` promotes ``float32`` and ``complex64`` arrays to ``float64`` and
|
| 128 |
+
``complex128`` arrays respectively. For an FFT implementation that does not
|
| 129 |
+
promote input arrays, see `scipy.fftpack`.
|
| 130 |
+
|
| 131 |
+
Normalization
|
| 132 |
+
-------------
|
| 133 |
+
|
| 134 |
+
The argument ``norm`` indicates which direction of the pair of direct/inverse
|
| 135 |
+
transforms is scaled and with what normalization factor.
|
| 136 |
+
The default normalization (``"backward"``) has the direct (forward) transforms
|
| 137 |
+
unscaled and the inverse (backward) transforms scaled by :math:`1/n`. It is
|
| 138 |
+
possible to obtain unitary transforms by setting the keyword argument ``norm``
|
| 139 |
+
to ``"ortho"`` so that both direct and inverse transforms are scaled by
|
| 140 |
+
:math:`1/\\sqrt{n}`. Finally, setting the keyword argument ``norm`` to
|
| 141 |
+
``"forward"`` has the direct transforms scaled by :math:`1/n` and the inverse
|
| 142 |
+
transforms unscaled (i.e. exactly opposite to the default ``"backward"``).
|
| 143 |
+
`None` is an alias of the default option ``"backward"`` for backward
|
| 144 |
+
compatibility.
|
| 145 |
+
|
| 146 |
+
Real and Hermitian transforms
|
| 147 |
+
-----------------------------
|
| 148 |
+
|
| 149 |
+
When the input is purely real, its transform is Hermitian, i.e., the
|
| 150 |
+
component at frequency :math:`f_k` is the complex conjugate of the
|
| 151 |
+
component at frequency :math:`-f_k`, which means that for real
|
| 152 |
+
inputs there is no information in the negative frequency components that
|
| 153 |
+
is not already available from the positive frequency components.
|
| 154 |
+
The family of `rfft` functions is
|
| 155 |
+
designed to operate on real inputs, and exploits this symmetry by
|
| 156 |
+
computing only the positive frequency components, up to and including the
|
| 157 |
+
Nyquist frequency. Thus, ``n`` input points produce ``n/2+1`` complex
|
| 158 |
+
output points. The inverses of this family assumes the same symmetry of
|
| 159 |
+
its input, and for an output of ``n`` points uses ``n/2+1`` input points.
|
| 160 |
+
|
| 161 |
+
Correspondingly, when the spectrum is purely real, the signal is
|
| 162 |
+
Hermitian. The `hfft` family of functions exploits this symmetry by
|
| 163 |
+
using ``n/2+1`` complex points in the input (time) domain for ``n`` real
|
| 164 |
+
points in the frequency domain.
|
| 165 |
+
|
| 166 |
+
In higher dimensions, FFTs are used, e.g., for image analysis and
|
| 167 |
+
filtering. The computational efficiency of the FFT means that it can
|
| 168 |
+
also be a faster way to compute large convolutions, using the property
|
| 169 |
+
that a convolution in the time domain is equivalent to a point-by-point
|
| 170 |
+
multiplication in the frequency domain.
|
| 171 |
+
|
| 172 |
+
Higher dimensions
|
| 173 |
+
-----------------
|
| 174 |
+
|
| 175 |
+
In two dimensions, the DFT is defined as
|
| 176 |
+
|
| 177 |
+
.. math::
|
| 178 |
+
A_{kl} = \\sum_{m=0}^{M-1} \\sum_{n=0}^{N-1}
|
| 179 |
+
a_{mn}\\exp\\left\\{-2\\pi i \\left({mk\\over M}+{nl\\over N}\\right)\\right\\}
|
| 180 |
+
\\qquad k = 0, \\ldots, M-1;\\quad l = 0, \\ldots, N-1,
|
| 181 |
+
|
| 182 |
+
which extends in the obvious way to higher dimensions, and the inverses
|
| 183 |
+
in higher dimensions also extend in the same way.
|
| 184 |
+
|
| 185 |
+
References
|
| 186 |
+
----------
|
| 187 |
+
|
| 188 |
+
.. [CT] Cooley, James W., and John W. Tukey, 1965, "An algorithm for the
|
| 189 |
+
machine calculation of complex Fourier series," *Math. Comput.*
|
| 190 |
+
19: 297-301.
|
| 191 |
+
|
| 192 |
+
.. [NR] Press, W., Teukolsky, S., Vetterline, W.T., and Flannery, B.P.,
|
| 193 |
+
2007, *Numerical Recipes: The Art of Scientific Computing*, ch.
|
| 194 |
+
12-13. Cambridge Univ. Press, Cambridge, UK.
|
| 195 |
+
|
| 196 |
+
Examples
|
| 197 |
+
--------
|
| 198 |
+
|
| 199 |
+
For examples, see the various functions.
|
| 200 |
+
|
| 201 |
+
"""
|
| 202 |
+
|
| 203 |
+
from . import _pocketfft, helper
|
| 204 |
+
from ._pocketfft import *
|
| 205 |
+
from .helper import *
|
| 206 |
+
|
| 207 |
+
__all__ = _pocketfft.__all__.copy()
|
| 208 |
+
__all__ += helper.__all__
|
| 209 |
+
|
| 210 |
+
from numpy._pytesttester import PytestTester
|
| 211 |
+
test = PytestTester(__name__)
|
| 212 |
+
del PytestTester
|
.venv/lib/python3.11/site-packages/numpy/fft/__init__.pyi
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from numpy._pytesttester import PytestTester
|
| 2 |
+
|
| 3 |
+
from numpy.fft._pocketfft import (
|
| 4 |
+
fft as fft,
|
| 5 |
+
ifft as ifft,
|
| 6 |
+
rfft as rfft,
|
| 7 |
+
irfft as irfft,
|
| 8 |
+
hfft as hfft,
|
| 9 |
+
ihfft as ihfft,
|
| 10 |
+
rfftn as rfftn,
|
| 11 |
+
irfftn as irfftn,
|
| 12 |
+
rfft2 as rfft2,
|
| 13 |
+
irfft2 as irfft2,
|
| 14 |
+
fft2 as fft2,
|
| 15 |
+
ifft2 as ifft2,
|
| 16 |
+
fftn as fftn,
|
| 17 |
+
ifftn as ifftn,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
from numpy.fft.helper import (
|
| 21 |
+
fftshift as fftshift,
|
| 22 |
+
ifftshift as ifftshift,
|
| 23 |
+
fftfreq as fftfreq,
|
| 24 |
+
rfftfreq as rfftfreq,
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
__all__: list[str]
|
| 28 |
+
__path__: list[str]
|
| 29 |
+
test: PytestTester
|
.venv/lib/python3.11/site-packages/numpy/fft/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (8.47 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/fft/__pycache__/helper.cpython-311.pyc
ADDED
|
Binary file (8.42 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/fft/_pocketfft.py
ADDED
|
@@ -0,0 +1,1424 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Discrete Fourier Transforms
|
| 3 |
+
|
| 4 |
+
Routines in this module:
|
| 5 |
+
|
| 6 |
+
fft(a, n=None, axis=-1, norm="backward")
|
| 7 |
+
ifft(a, n=None, axis=-1, norm="backward")
|
| 8 |
+
rfft(a, n=None, axis=-1, norm="backward")
|
| 9 |
+
irfft(a, n=None, axis=-1, norm="backward")
|
| 10 |
+
hfft(a, n=None, axis=-1, norm="backward")
|
| 11 |
+
ihfft(a, n=None, axis=-1, norm="backward")
|
| 12 |
+
fftn(a, s=None, axes=None, norm="backward")
|
| 13 |
+
ifftn(a, s=None, axes=None, norm="backward")
|
| 14 |
+
rfftn(a, s=None, axes=None, norm="backward")
|
| 15 |
+
irfftn(a, s=None, axes=None, norm="backward")
|
| 16 |
+
fft2(a, s=None, axes=(-2,-1), norm="backward")
|
| 17 |
+
ifft2(a, s=None, axes=(-2, -1), norm="backward")
|
| 18 |
+
rfft2(a, s=None, axes=(-2,-1), norm="backward")
|
| 19 |
+
irfft2(a, s=None, axes=(-2, -1), norm="backward")
|
| 20 |
+
|
| 21 |
+
i = inverse transform
|
| 22 |
+
r = transform of purely real data
|
| 23 |
+
h = Hermite transform
|
| 24 |
+
n = n-dimensional transform
|
| 25 |
+
2 = 2-dimensional transform
|
| 26 |
+
(Note: 2D routines are just nD routines with different default
|
| 27 |
+
behavior.)
|
| 28 |
+
|
| 29 |
+
"""
|
| 30 |
+
__all__ = ['fft', 'ifft', 'rfft', 'irfft', 'hfft', 'ihfft', 'rfftn',
|
| 31 |
+
'irfftn', 'rfft2', 'irfft2', 'fft2', 'ifft2', 'fftn', 'ifftn']
|
| 32 |
+
|
| 33 |
+
import functools
|
| 34 |
+
|
| 35 |
+
from numpy.core import asarray, zeros, swapaxes, conjugate, take, sqrt
|
| 36 |
+
from . import _pocketfft_internal as pfi
|
| 37 |
+
from numpy.core.multiarray import normalize_axis_index
|
| 38 |
+
from numpy.core import overrides
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
array_function_dispatch = functools.partial(
|
| 42 |
+
overrides.array_function_dispatch, module='numpy.fft')
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# `inv_norm` is a float by which the result of the transform needs to be
|
| 46 |
+
# divided. This replaces the original, more intuitive 'fct` parameter to avoid
|
| 47 |
+
# divisions by zero (or alternatively additional checks) in the case of
|
| 48 |
+
# zero-length axes during its computation.
|
| 49 |
+
def _raw_fft(a, n, axis, is_real, is_forward, inv_norm):
|
| 50 |
+
axis = normalize_axis_index(axis, a.ndim)
|
| 51 |
+
if n is None:
|
| 52 |
+
n = a.shape[axis]
|
| 53 |
+
|
| 54 |
+
fct = 1/inv_norm
|
| 55 |
+
|
| 56 |
+
if a.shape[axis] != n:
|
| 57 |
+
s = list(a.shape)
|
| 58 |
+
index = [slice(None)]*len(s)
|
| 59 |
+
if s[axis] > n:
|
| 60 |
+
index[axis] = slice(0, n)
|
| 61 |
+
a = a[tuple(index)]
|
| 62 |
+
else:
|
| 63 |
+
index[axis] = slice(0, s[axis])
|
| 64 |
+
s[axis] = n
|
| 65 |
+
z = zeros(s, a.dtype.char)
|
| 66 |
+
z[tuple(index)] = a
|
| 67 |
+
a = z
|
| 68 |
+
|
| 69 |
+
if axis == a.ndim-1:
|
| 70 |
+
r = pfi.execute(a, is_real, is_forward, fct)
|
| 71 |
+
else:
|
| 72 |
+
a = swapaxes(a, axis, -1)
|
| 73 |
+
r = pfi.execute(a, is_real, is_forward, fct)
|
| 74 |
+
r = swapaxes(r, axis, -1)
|
| 75 |
+
return r
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def _get_forward_norm(n, norm):
|
| 79 |
+
if n < 1:
|
| 80 |
+
raise ValueError(f"Invalid number of FFT data points ({n}) specified.")
|
| 81 |
+
|
| 82 |
+
if norm is None or norm == "backward":
|
| 83 |
+
return 1
|
| 84 |
+
elif norm == "ortho":
|
| 85 |
+
return sqrt(n)
|
| 86 |
+
elif norm == "forward":
|
| 87 |
+
return n
|
| 88 |
+
raise ValueError(f'Invalid norm value {norm}; should be "backward",'
|
| 89 |
+
'"ortho" or "forward".')
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def _get_backward_norm(n, norm):
|
| 93 |
+
if n < 1:
|
| 94 |
+
raise ValueError(f"Invalid number of FFT data points ({n}) specified.")
|
| 95 |
+
|
| 96 |
+
if norm is None or norm == "backward":
|
| 97 |
+
return n
|
| 98 |
+
elif norm == "ortho":
|
| 99 |
+
return sqrt(n)
|
| 100 |
+
elif norm == "forward":
|
| 101 |
+
return 1
|
| 102 |
+
raise ValueError(f'Invalid norm value {norm}; should be "backward", '
|
| 103 |
+
'"ortho" or "forward".')
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
_SWAP_DIRECTION_MAP = {"backward": "forward", None: "forward",
|
| 107 |
+
"ortho": "ortho", "forward": "backward"}
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def _swap_direction(norm):
|
| 111 |
+
try:
|
| 112 |
+
return _SWAP_DIRECTION_MAP[norm]
|
| 113 |
+
except KeyError:
|
| 114 |
+
raise ValueError(f'Invalid norm value {norm}; should be "backward", '
|
| 115 |
+
'"ortho" or "forward".') from None
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def _fft_dispatcher(a, n=None, axis=None, norm=None):
|
| 119 |
+
return (a,)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@array_function_dispatch(_fft_dispatcher)
|
| 123 |
+
def fft(a, n=None, axis=-1, norm=None):
|
| 124 |
+
"""
|
| 125 |
+
Compute the one-dimensional discrete Fourier Transform.
|
| 126 |
+
|
| 127 |
+
This function computes the one-dimensional *n*-point discrete Fourier
|
| 128 |
+
Transform (DFT) with the efficient Fast Fourier Transform (FFT)
|
| 129 |
+
algorithm [CT].
|
| 130 |
+
|
| 131 |
+
Parameters
|
| 132 |
+
----------
|
| 133 |
+
a : array_like
|
| 134 |
+
Input array, can be complex.
|
| 135 |
+
n : int, optional
|
| 136 |
+
Length of the transformed axis of the output.
|
| 137 |
+
If `n` is smaller than the length of the input, the input is cropped.
|
| 138 |
+
If it is larger, the input is padded with zeros. If `n` is not given,
|
| 139 |
+
the length of the input along the axis specified by `axis` is used.
|
| 140 |
+
axis : int, optional
|
| 141 |
+
Axis over which to compute the FFT. If not given, the last axis is
|
| 142 |
+
used.
|
| 143 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 144 |
+
.. versionadded:: 1.10.0
|
| 145 |
+
|
| 146 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 147 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 148 |
+
is scaled and with what normalization factor.
|
| 149 |
+
|
| 150 |
+
.. versionadded:: 1.20.0
|
| 151 |
+
|
| 152 |
+
The "backward", "forward" values were added.
|
| 153 |
+
|
| 154 |
+
Returns
|
| 155 |
+
-------
|
| 156 |
+
out : complex ndarray
|
| 157 |
+
The truncated or zero-padded input, transformed along the axis
|
| 158 |
+
indicated by `axis`, or the last one if `axis` is not specified.
|
| 159 |
+
|
| 160 |
+
Raises
|
| 161 |
+
------
|
| 162 |
+
IndexError
|
| 163 |
+
If `axis` is not a valid axis of `a`.
|
| 164 |
+
|
| 165 |
+
See Also
|
| 166 |
+
--------
|
| 167 |
+
numpy.fft : for definition of the DFT and conventions used.
|
| 168 |
+
ifft : The inverse of `fft`.
|
| 169 |
+
fft2 : The two-dimensional FFT.
|
| 170 |
+
fftn : The *n*-dimensional FFT.
|
| 171 |
+
rfftn : The *n*-dimensional FFT of real input.
|
| 172 |
+
fftfreq : Frequency bins for given FFT parameters.
|
| 173 |
+
|
| 174 |
+
Notes
|
| 175 |
+
-----
|
| 176 |
+
FFT (Fast Fourier Transform) refers to a way the discrete Fourier
|
| 177 |
+
Transform (DFT) can be calculated efficiently, by using symmetries in the
|
| 178 |
+
calculated terms. The symmetry is highest when `n` is a power of 2, and
|
| 179 |
+
the transform is therefore most efficient for these sizes.
|
| 180 |
+
|
| 181 |
+
The DFT is defined, with the conventions used in this implementation, in
|
| 182 |
+
the documentation for the `numpy.fft` module.
|
| 183 |
+
|
| 184 |
+
References
|
| 185 |
+
----------
|
| 186 |
+
.. [CT] Cooley, James W., and John W. Tukey, 1965, "An algorithm for the
|
| 187 |
+
machine calculation of complex Fourier series," *Math. Comput.*
|
| 188 |
+
19: 297-301.
|
| 189 |
+
|
| 190 |
+
Examples
|
| 191 |
+
--------
|
| 192 |
+
>>> np.fft.fft(np.exp(2j * np.pi * np.arange(8) / 8))
|
| 193 |
+
array([-2.33486982e-16+1.14423775e-17j, 8.00000000e+00-1.25557246e-15j,
|
| 194 |
+
2.33486982e-16+2.33486982e-16j, 0.00000000e+00+1.22464680e-16j,
|
| 195 |
+
-1.14423775e-17+2.33486982e-16j, 0.00000000e+00+5.20784380e-16j,
|
| 196 |
+
1.14423775e-17+1.14423775e-17j, 0.00000000e+00+1.22464680e-16j])
|
| 197 |
+
|
| 198 |
+
In this example, real input has an FFT which is Hermitian, i.e., symmetric
|
| 199 |
+
in the real part and anti-symmetric in the imaginary part, as described in
|
| 200 |
+
the `numpy.fft` documentation:
|
| 201 |
+
|
| 202 |
+
>>> import matplotlib.pyplot as plt
|
| 203 |
+
>>> t = np.arange(256)
|
| 204 |
+
>>> sp = np.fft.fft(np.sin(t))
|
| 205 |
+
>>> freq = np.fft.fftfreq(t.shape[-1])
|
| 206 |
+
>>> plt.plot(freq, sp.real, freq, sp.imag)
|
| 207 |
+
[<matplotlib.lines.Line2D object at 0x...>, <matplotlib.lines.Line2D object at 0x...>]
|
| 208 |
+
>>> plt.show()
|
| 209 |
+
|
| 210 |
+
"""
|
| 211 |
+
a = asarray(a)
|
| 212 |
+
if n is None:
|
| 213 |
+
n = a.shape[axis]
|
| 214 |
+
inv_norm = _get_forward_norm(n, norm)
|
| 215 |
+
output = _raw_fft(a, n, axis, False, True, inv_norm)
|
| 216 |
+
return output
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
@array_function_dispatch(_fft_dispatcher)
|
| 220 |
+
def ifft(a, n=None, axis=-1, norm=None):
|
| 221 |
+
"""
|
| 222 |
+
Compute the one-dimensional inverse discrete Fourier Transform.
|
| 223 |
+
|
| 224 |
+
This function computes the inverse of the one-dimensional *n*-point
|
| 225 |
+
discrete Fourier transform computed by `fft`. In other words,
|
| 226 |
+
``ifft(fft(a)) == a`` to within numerical accuracy.
|
| 227 |
+
For a general description of the algorithm and definitions,
|
| 228 |
+
see `numpy.fft`.
|
| 229 |
+
|
| 230 |
+
The input should be ordered in the same way as is returned by `fft`,
|
| 231 |
+
i.e.,
|
| 232 |
+
|
| 233 |
+
* ``a[0]`` should contain the zero frequency term,
|
| 234 |
+
* ``a[1:n//2]`` should contain the positive-frequency terms,
|
| 235 |
+
* ``a[n//2 + 1:]`` should contain the negative-frequency terms, in
|
| 236 |
+
increasing order starting from the most negative frequency.
|
| 237 |
+
|
| 238 |
+
For an even number of input points, ``A[n//2]`` represents the sum of
|
| 239 |
+
the values at the positive and negative Nyquist frequencies, as the two
|
| 240 |
+
are aliased together. See `numpy.fft` for details.
|
| 241 |
+
|
| 242 |
+
Parameters
|
| 243 |
+
----------
|
| 244 |
+
a : array_like
|
| 245 |
+
Input array, can be complex.
|
| 246 |
+
n : int, optional
|
| 247 |
+
Length of the transformed axis of the output.
|
| 248 |
+
If `n` is smaller than the length of the input, the input is cropped.
|
| 249 |
+
If it is larger, the input is padded with zeros. If `n` is not given,
|
| 250 |
+
the length of the input along the axis specified by `axis` is used.
|
| 251 |
+
See notes about padding issues.
|
| 252 |
+
axis : int, optional
|
| 253 |
+
Axis over which to compute the inverse DFT. If not given, the last
|
| 254 |
+
axis is used.
|
| 255 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 256 |
+
.. versionadded:: 1.10.0
|
| 257 |
+
|
| 258 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 259 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 260 |
+
is scaled and with what normalization factor.
|
| 261 |
+
|
| 262 |
+
.. versionadded:: 1.20.0
|
| 263 |
+
|
| 264 |
+
The "backward", "forward" values were added.
|
| 265 |
+
|
| 266 |
+
Returns
|
| 267 |
+
-------
|
| 268 |
+
out : complex ndarray
|
| 269 |
+
The truncated or zero-padded input, transformed along the axis
|
| 270 |
+
indicated by `axis`, or the last one if `axis` is not specified.
|
| 271 |
+
|
| 272 |
+
Raises
|
| 273 |
+
------
|
| 274 |
+
IndexError
|
| 275 |
+
If `axis` is not a valid axis of `a`.
|
| 276 |
+
|
| 277 |
+
See Also
|
| 278 |
+
--------
|
| 279 |
+
numpy.fft : An introduction, with definitions and general explanations.
|
| 280 |
+
fft : The one-dimensional (forward) FFT, of which `ifft` is the inverse
|
| 281 |
+
ifft2 : The two-dimensional inverse FFT.
|
| 282 |
+
ifftn : The n-dimensional inverse FFT.
|
| 283 |
+
|
| 284 |
+
Notes
|
| 285 |
+
-----
|
| 286 |
+
If the input parameter `n` is larger than the size of the input, the input
|
| 287 |
+
is padded by appending zeros at the end. Even though this is the common
|
| 288 |
+
approach, it might lead to surprising results. If a different padding is
|
| 289 |
+
desired, it must be performed before calling `ifft`.
|
| 290 |
+
|
| 291 |
+
Examples
|
| 292 |
+
--------
|
| 293 |
+
>>> np.fft.ifft([0, 4, 0, 0])
|
| 294 |
+
array([ 1.+0.j, 0.+1.j, -1.+0.j, 0.-1.j]) # may vary
|
| 295 |
+
|
| 296 |
+
Create and plot a band-limited signal with random phases:
|
| 297 |
+
|
| 298 |
+
>>> import matplotlib.pyplot as plt
|
| 299 |
+
>>> t = np.arange(400)
|
| 300 |
+
>>> n = np.zeros((400,), dtype=complex)
|
| 301 |
+
>>> n[40:60] = np.exp(1j*np.random.uniform(0, 2*np.pi, (20,)))
|
| 302 |
+
>>> s = np.fft.ifft(n)
|
| 303 |
+
>>> plt.plot(t, s.real, label='real')
|
| 304 |
+
[<matplotlib.lines.Line2D object at ...>]
|
| 305 |
+
>>> plt.plot(t, s.imag, '--', label='imaginary')
|
| 306 |
+
[<matplotlib.lines.Line2D object at ...>]
|
| 307 |
+
>>> plt.legend()
|
| 308 |
+
<matplotlib.legend.Legend object at ...>
|
| 309 |
+
>>> plt.show()
|
| 310 |
+
|
| 311 |
+
"""
|
| 312 |
+
a = asarray(a)
|
| 313 |
+
if n is None:
|
| 314 |
+
n = a.shape[axis]
|
| 315 |
+
inv_norm = _get_backward_norm(n, norm)
|
| 316 |
+
output = _raw_fft(a, n, axis, False, False, inv_norm)
|
| 317 |
+
return output
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
@array_function_dispatch(_fft_dispatcher)
|
| 321 |
+
def rfft(a, n=None, axis=-1, norm=None):
|
| 322 |
+
"""
|
| 323 |
+
Compute the one-dimensional discrete Fourier Transform for real input.
|
| 324 |
+
|
| 325 |
+
This function computes the one-dimensional *n*-point discrete Fourier
|
| 326 |
+
Transform (DFT) of a real-valued array by means of an efficient algorithm
|
| 327 |
+
called the Fast Fourier Transform (FFT).
|
| 328 |
+
|
| 329 |
+
Parameters
|
| 330 |
+
----------
|
| 331 |
+
a : array_like
|
| 332 |
+
Input array
|
| 333 |
+
n : int, optional
|
| 334 |
+
Number of points along transformation axis in the input to use.
|
| 335 |
+
If `n` is smaller than the length of the input, the input is cropped.
|
| 336 |
+
If it is larger, the input is padded with zeros. If `n` is not given,
|
| 337 |
+
the length of the input along the axis specified by `axis` is used.
|
| 338 |
+
axis : int, optional
|
| 339 |
+
Axis over which to compute the FFT. If not given, the last axis is
|
| 340 |
+
used.
|
| 341 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 342 |
+
.. versionadded:: 1.10.0
|
| 343 |
+
|
| 344 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 345 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 346 |
+
is scaled and with what normalization factor.
|
| 347 |
+
|
| 348 |
+
.. versionadded:: 1.20.0
|
| 349 |
+
|
| 350 |
+
The "backward", "forward" values were added.
|
| 351 |
+
|
| 352 |
+
Returns
|
| 353 |
+
-------
|
| 354 |
+
out : complex ndarray
|
| 355 |
+
The truncated or zero-padded input, transformed along the axis
|
| 356 |
+
indicated by `axis`, or the last one if `axis` is not specified.
|
| 357 |
+
If `n` is even, the length of the transformed axis is ``(n/2)+1``.
|
| 358 |
+
If `n` is odd, the length is ``(n+1)/2``.
|
| 359 |
+
|
| 360 |
+
Raises
|
| 361 |
+
------
|
| 362 |
+
IndexError
|
| 363 |
+
If `axis` is not a valid axis of `a`.
|
| 364 |
+
|
| 365 |
+
See Also
|
| 366 |
+
--------
|
| 367 |
+
numpy.fft : For definition of the DFT and conventions used.
|
| 368 |
+
irfft : The inverse of `rfft`.
|
| 369 |
+
fft : The one-dimensional FFT of general (complex) input.
|
| 370 |
+
fftn : The *n*-dimensional FFT.
|
| 371 |
+
rfftn : The *n*-dimensional FFT of real input.
|
| 372 |
+
|
| 373 |
+
Notes
|
| 374 |
+
-----
|
| 375 |
+
When the DFT is computed for purely real input, the output is
|
| 376 |
+
Hermitian-symmetric, i.e. the negative frequency terms are just the complex
|
| 377 |
+
conjugates of the corresponding positive-frequency terms, and the
|
| 378 |
+
negative-frequency terms are therefore redundant. This function does not
|
| 379 |
+
compute the negative frequency terms, and the length of the transformed
|
| 380 |
+
axis of the output is therefore ``n//2 + 1``.
|
| 381 |
+
|
| 382 |
+
When ``A = rfft(a)`` and fs is the sampling frequency, ``A[0]`` contains
|
| 383 |
+
the zero-frequency term 0*fs, which is real due to Hermitian symmetry.
|
| 384 |
+
|
| 385 |
+
If `n` is even, ``A[-1]`` contains the term representing both positive
|
| 386 |
+
and negative Nyquist frequency (+fs/2 and -fs/2), and must also be purely
|
| 387 |
+
real. If `n` is odd, there is no term at fs/2; ``A[-1]`` contains
|
| 388 |
+
the largest positive frequency (fs/2*(n-1)/n), and is complex in the
|
| 389 |
+
general case.
|
| 390 |
+
|
| 391 |
+
If the input `a` contains an imaginary part, it is silently discarded.
|
| 392 |
+
|
| 393 |
+
Examples
|
| 394 |
+
--------
|
| 395 |
+
>>> np.fft.fft([0, 1, 0, 0])
|
| 396 |
+
array([ 1.+0.j, 0.-1.j, -1.+0.j, 0.+1.j]) # may vary
|
| 397 |
+
>>> np.fft.rfft([0, 1, 0, 0])
|
| 398 |
+
array([ 1.+0.j, 0.-1.j, -1.+0.j]) # may vary
|
| 399 |
+
|
| 400 |
+
Notice how the final element of the `fft` output is the complex conjugate
|
| 401 |
+
of the second element, for real input. For `rfft`, this symmetry is
|
| 402 |
+
exploited to compute only the non-negative frequency terms.
|
| 403 |
+
|
| 404 |
+
"""
|
| 405 |
+
a = asarray(a)
|
| 406 |
+
if n is None:
|
| 407 |
+
n = a.shape[axis]
|
| 408 |
+
inv_norm = _get_forward_norm(n, norm)
|
| 409 |
+
output = _raw_fft(a, n, axis, True, True, inv_norm)
|
| 410 |
+
return output
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
@array_function_dispatch(_fft_dispatcher)
|
| 414 |
+
def irfft(a, n=None, axis=-1, norm=None):
|
| 415 |
+
"""
|
| 416 |
+
Computes the inverse of `rfft`.
|
| 417 |
+
|
| 418 |
+
This function computes the inverse of the one-dimensional *n*-point
|
| 419 |
+
discrete Fourier Transform of real input computed by `rfft`.
|
| 420 |
+
In other words, ``irfft(rfft(a), len(a)) == a`` to within numerical
|
| 421 |
+
accuracy. (See Notes below for why ``len(a)`` is necessary here.)
|
| 422 |
+
|
| 423 |
+
The input is expected to be in the form returned by `rfft`, i.e. the
|
| 424 |
+
real zero-frequency term followed by the complex positive frequency terms
|
| 425 |
+
in order of increasing frequency. Since the discrete Fourier Transform of
|
| 426 |
+
real input is Hermitian-symmetric, the negative frequency terms are taken
|
| 427 |
+
to be the complex conjugates of the corresponding positive frequency terms.
|
| 428 |
+
|
| 429 |
+
Parameters
|
| 430 |
+
----------
|
| 431 |
+
a : array_like
|
| 432 |
+
The input array.
|
| 433 |
+
n : int, optional
|
| 434 |
+
Length of the transformed axis of the output.
|
| 435 |
+
For `n` output points, ``n//2+1`` input points are necessary. If the
|
| 436 |
+
input is longer than this, it is cropped. If it is shorter than this,
|
| 437 |
+
it is padded with zeros. If `n` is not given, it is taken to be
|
| 438 |
+
``2*(m-1)`` where ``m`` is the length of the input along the axis
|
| 439 |
+
specified by `axis`.
|
| 440 |
+
axis : int, optional
|
| 441 |
+
Axis over which to compute the inverse FFT. If not given, the last
|
| 442 |
+
axis is used.
|
| 443 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 444 |
+
.. versionadded:: 1.10.0
|
| 445 |
+
|
| 446 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 447 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 448 |
+
is scaled and with what normalization factor.
|
| 449 |
+
|
| 450 |
+
.. versionadded:: 1.20.0
|
| 451 |
+
|
| 452 |
+
The "backward", "forward" values were added.
|
| 453 |
+
|
| 454 |
+
Returns
|
| 455 |
+
-------
|
| 456 |
+
out : ndarray
|
| 457 |
+
The truncated or zero-padded input, transformed along the axis
|
| 458 |
+
indicated by `axis`, or the last one if `axis` is not specified.
|
| 459 |
+
The length of the transformed axis is `n`, or, if `n` is not given,
|
| 460 |
+
``2*(m-1)`` where ``m`` is the length of the transformed axis of the
|
| 461 |
+
input. To get an odd number of output points, `n` must be specified.
|
| 462 |
+
|
| 463 |
+
Raises
|
| 464 |
+
------
|
| 465 |
+
IndexError
|
| 466 |
+
If `axis` is not a valid axis of `a`.
|
| 467 |
+
|
| 468 |
+
See Also
|
| 469 |
+
--------
|
| 470 |
+
numpy.fft : For definition of the DFT and conventions used.
|
| 471 |
+
rfft : The one-dimensional FFT of real input, of which `irfft` is inverse.
|
| 472 |
+
fft : The one-dimensional FFT.
|
| 473 |
+
irfft2 : The inverse of the two-dimensional FFT of real input.
|
| 474 |
+
irfftn : The inverse of the *n*-dimensional FFT of real input.
|
| 475 |
+
|
| 476 |
+
Notes
|
| 477 |
+
-----
|
| 478 |
+
Returns the real valued `n`-point inverse discrete Fourier transform
|
| 479 |
+
of `a`, where `a` contains the non-negative frequency terms of a
|
| 480 |
+
Hermitian-symmetric sequence. `n` is the length of the result, not the
|
| 481 |
+
input.
|
| 482 |
+
|
| 483 |
+
If you specify an `n` such that `a` must be zero-padded or truncated, the
|
| 484 |
+
extra/removed values will be added/removed at high frequencies. One can
|
| 485 |
+
thus resample a series to `m` points via Fourier interpolation by:
|
| 486 |
+
``a_resamp = irfft(rfft(a), m)``.
|
| 487 |
+
|
| 488 |
+
The correct interpretation of the hermitian input depends on the length of
|
| 489 |
+
the original data, as given by `n`. This is because each input shape could
|
| 490 |
+
correspond to either an odd or even length signal. By default, `irfft`
|
| 491 |
+
assumes an even output length which puts the last entry at the Nyquist
|
| 492 |
+
frequency; aliasing with its symmetric counterpart. By Hermitian symmetry,
|
| 493 |
+
the value is thus treated as purely real. To avoid losing information, the
|
| 494 |
+
correct length of the real input **must** be given.
|
| 495 |
+
|
| 496 |
+
Examples
|
| 497 |
+
--------
|
| 498 |
+
>>> np.fft.ifft([1, -1j, -1, 1j])
|
| 499 |
+
array([0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]) # may vary
|
| 500 |
+
>>> np.fft.irfft([1, -1j, -1])
|
| 501 |
+
array([0., 1., 0., 0.])
|
| 502 |
+
|
| 503 |
+
Notice how the last term in the input to the ordinary `ifft` is the
|
| 504 |
+
complex conjugate of the second term, and the output has zero imaginary
|
| 505 |
+
part everywhere. When calling `irfft`, the negative frequencies are not
|
| 506 |
+
specified, and the output array is purely real.
|
| 507 |
+
|
| 508 |
+
"""
|
| 509 |
+
a = asarray(a)
|
| 510 |
+
if n is None:
|
| 511 |
+
n = (a.shape[axis] - 1) * 2
|
| 512 |
+
inv_norm = _get_backward_norm(n, norm)
|
| 513 |
+
output = _raw_fft(a, n, axis, True, False, inv_norm)
|
| 514 |
+
return output
|
| 515 |
+
|
| 516 |
+
|
| 517 |
+
@array_function_dispatch(_fft_dispatcher)
|
| 518 |
+
def hfft(a, n=None, axis=-1, norm=None):
|
| 519 |
+
"""
|
| 520 |
+
Compute the FFT of a signal that has Hermitian symmetry, i.e., a real
|
| 521 |
+
spectrum.
|
| 522 |
+
|
| 523 |
+
Parameters
|
| 524 |
+
----------
|
| 525 |
+
a : array_like
|
| 526 |
+
The input array.
|
| 527 |
+
n : int, optional
|
| 528 |
+
Length of the transformed axis of the output. For `n` output
|
| 529 |
+
points, ``n//2 + 1`` input points are necessary. If the input is
|
| 530 |
+
longer than this, it is cropped. If it is shorter than this, it is
|
| 531 |
+
padded with zeros. If `n` is not given, it is taken to be ``2*(m-1)``
|
| 532 |
+
where ``m`` is the length of the input along the axis specified by
|
| 533 |
+
`axis`.
|
| 534 |
+
axis : int, optional
|
| 535 |
+
Axis over which to compute the FFT. If not given, the last
|
| 536 |
+
axis is used.
|
| 537 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 538 |
+
.. versionadded:: 1.10.0
|
| 539 |
+
|
| 540 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 541 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 542 |
+
is scaled and with what normalization factor.
|
| 543 |
+
|
| 544 |
+
.. versionadded:: 1.20.0
|
| 545 |
+
|
| 546 |
+
The "backward", "forward" values were added.
|
| 547 |
+
|
| 548 |
+
Returns
|
| 549 |
+
-------
|
| 550 |
+
out : ndarray
|
| 551 |
+
The truncated or zero-padded input, transformed along the axis
|
| 552 |
+
indicated by `axis`, or the last one if `axis` is not specified.
|
| 553 |
+
The length of the transformed axis is `n`, or, if `n` is not given,
|
| 554 |
+
``2*m - 2`` where ``m`` is the length of the transformed axis of
|
| 555 |
+
the input. To get an odd number of output points, `n` must be
|
| 556 |
+
specified, for instance as ``2*m - 1`` in the typical case,
|
| 557 |
+
|
| 558 |
+
Raises
|
| 559 |
+
------
|
| 560 |
+
IndexError
|
| 561 |
+
If `axis` is not a valid axis of `a`.
|
| 562 |
+
|
| 563 |
+
See also
|
| 564 |
+
--------
|
| 565 |
+
rfft : Compute the one-dimensional FFT for real input.
|
| 566 |
+
ihfft : The inverse of `hfft`.
|
| 567 |
+
|
| 568 |
+
Notes
|
| 569 |
+
-----
|
| 570 |
+
`hfft`/`ihfft` are a pair analogous to `rfft`/`irfft`, but for the
|
| 571 |
+
opposite case: here the signal has Hermitian symmetry in the time
|
| 572 |
+
domain and is real in the frequency domain. So here it's `hfft` for
|
| 573 |
+
which you must supply the length of the result if it is to be odd.
|
| 574 |
+
|
| 575 |
+
* even: ``ihfft(hfft(a, 2*len(a) - 2)) == a``, within roundoff error,
|
| 576 |
+
* odd: ``ihfft(hfft(a, 2*len(a) - 1)) == a``, within roundoff error.
|
| 577 |
+
|
| 578 |
+
The correct interpretation of the hermitian input depends on the length of
|
| 579 |
+
the original data, as given by `n`. This is because each input shape could
|
| 580 |
+
correspond to either an odd or even length signal. By default, `hfft`
|
| 581 |
+
assumes an even output length which puts the last entry at the Nyquist
|
| 582 |
+
frequency; aliasing with its symmetric counterpart. By Hermitian symmetry,
|
| 583 |
+
the value is thus treated as purely real. To avoid losing information, the
|
| 584 |
+
shape of the full signal **must** be given.
|
| 585 |
+
|
| 586 |
+
Examples
|
| 587 |
+
--------
|
| 588 |
+
>>> signal = np.array([1, 2, 3, 4, 3, 2])
|
| 589 |
+
>>> np.fft.fft(signal)
|
| 590 |
+
array([15.+0.j, -4.+0.j, 0.+0.j, -1.-0.j, 0.+0.j, -4.+0.j]) # may vary
|
| 591 |
+
>>> np.fft.hfft(signal[:4]) # Input first half of signal
|
| 592 |
+
array([15., -4., 0., -1., 0., -4.])
|
| 593 |
+
>>> np.fft.hfft(signal, 6) # Input entire signal and truncate
|
| 594 |
+
array([15., -4., 0., -1., 0., -4.])
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
>>> signal = np.array([[1, 1.j], [-1.j, 2]])
|
| 598 |
+
>>> np.conj(signal.T) - signal # check Hermitian symmetry
|
| 599 |
+
array([[ 0.-0.j, -0.+0.j], # may vary
|
| 600 |
+
[ 0.+0.j, 0.-0.j]])
|
| 601 |
+
>>> freq_spectrum = np.fft.hfft(signal)
|
| 602 |
+
>>> freq_spectrum
|
| 603 |
+
array([[ 1., 1.],
|
| 604 |
+
[ 2., -2.]])
|
| 605 |
+
|
| 606 |
+
"""
|
| 607 |
+
a = asarray(a)
|
| 608 |
+
if n is None:
|
| 609 |
+
n = (a.shape[axis] - 1) * 2
|
| 610 |
+
new_norm = _swap_direction(norm)
|
| 611 |
+
output = irfft(conjugate(a), n, axis, norm=new_norm)
|
| 612 |
+
return output
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
@array_function_dispatch(_fft_dispatcher)
|
| 616 |
+
def ihfft(a, n=None, axis=-1, norm=None):
|
| 617 |
+
"""
|
| 618 |
+
Compute the inverse FFT of a signal that has Hermitian symmetry.
|
| 619 |
+
|
| 620 |
+
Parameters
|
| 621 |
+
----------
|
| 622 |
+
a : array_like
|
| 623 |
+
Input array.
|
| 624 |
+
n : int, optional
|
| 625 |
+
Length of the inverse FFT, the number of points along
|
| 626 |
+
transformation axis in the input to use. If `n` is smaller than
|
| 627 |
+
the length of the input, the input is cropped. If it is larger,
|
| 628 |
+
the input is padded with zeros. If `n` is not given, the length of
|
| 629 |
+
the input along the axis specified by `axis` is used.
|
| 630 |
+
axis : int, optional
|
| 631 |
+
Axis over which to compute the inverse FFT. If not given, the last
|
| 632 |
+
axis is used.
|
| 633 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 634 |
+
.. versionadded:: 1.10.0
|
| 635 |
+
|
| 636 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 637 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 638 |
+
is scaled and with what normalization factor.
|
| 639 |
+
|
| 640 |
+
.. versionadded:: 1.20.0
|
| 641 |
+
|
| 642 |
+
The "backward", "forward" values were added.
|
| 643 |
+
|
| 644 |
+
Returns
|
| 645 |
+
-------
|
| 646 |
+
out : complex ndarray
|
| 647 |
+
The truncated or zero-padded input, transformed along the axis
|
| 648 |
+
indicated by `axis`, or the last one if `axis` is not specified.
|
| 649 |
+
The length of the transformed axis is ``n//2 + 1``.
|
| 650 |
+
|
| 651 |
+
See also
|
| 652 |
+
--------
|
| 653 |
+
hfft, irfft
|
| 654 |
+
|
| 655 |
+
Notes
|
| 656 |
+
-----
|
| 657 |
+
`hfft`/`ihfft` are a pair analogous to `rfft`/`irfft`, but for the
|
| 658 |
+
opposite case: here the signal has Hermitian symmetry in the time
|
| 659 |
+
domain and is real in the frequency domain. So here it's `hfft` for
|
| 660 |
+
which you must supply the length of the result if it is to be odd:
|
| 661 |
+
|
| 662 |
+
* even: ``ihfft(hfft(a, 2*len(a) - 2)) == a``, within roundoff error,
|
| 663 |
+
* odd: ``ihfft(hfft(a, 2*len(a) - 1)) == a``, within roundoff error.
|
| 664 |
+
|
| 665 |
+
Examples
|
| 666 |
+
--------
|
| 667 |
+
>>> spectrum = np.array([ 15, -4, 0, -1, 0, -4])
|
| 668 |
+
>>> np.fft.ifft(spectrum)
|
| 669 |
+
array([1.+0.j, 2.+0.j, 3.+0.j, 4.+0.j, 3.+0.j, 2.+0.j]) # may vary
|
| 670 |
+
>>> np.fft.ihfft(spectrum)
|
| 671 |
+
array([ 1.-0.j, 2.-0.j, 3.-0.j, 4.-0.j]) # may vary
|
| 672 |
+
|
| 673 |
+
"""
|
| 674 |
+
a = asarray(a)
|
| 675 |
+
if n is None:
|
| 676 |
+
n = a.shape[axis]
|
| 677 |
+
new_norm = _swap_direction(norm)
|
| 678 |
+
output = conjugate(rfft(a, n, axis, norm=new_norm))
|
| 679 |
+
return output
|
| 680 |
+
|
| 681 |
+
|
| 682 |
+
def _cook_nd_args(a, s=None, axes=None, invreal=0):
|
| 683 |
+
if s is None:
|
| 684 |
+
shapeless = 1
|
| 685 |
+
if axes is None:
|
| 686 |
+
s = list(a.shape)
|
| 687 |
+
else:
|
| 688 |
+
s = take(a.shape, axes)
|
| 689 |
+
else:
|
| 690 |
+
shapeless = 0
|
| 691 |
+
s = list(s)
|
| 692 |
+
if axes is None:
|
| 693 |
+
axes = list(range(-len(s), 0))
|
| 694 |
+
if len(s) != len(axes):
|
| 695 |
+
raise ValueError("Shape and axes have different lengths.")
|
| 696 |
+
if invreal and shapeless:
|
| 697 |
+
s[-1] = (a.shape[axes[-1]] - 1) * 2
|
| 698 |
+
return s, axes
|
| 699 |
+
|
| 700 |
+
|
| 701 |
+
def _raw_fftnd(a, s=None, axes=None, function=fft, norm=None):
|
| 702 |
+
a = asarray(a)
|
| 703 |
+
s, axes = _cook_nd_args(a, s, axes)
|
| 704 |
+
itl = list(range(len(axes)))
|
| 705 |
+
itl.reverse()
|
| 706 |
+
for ii in itl:
|
| 707 |
+
a = function(a, n=s[ii], axis=axes[ii], norm=norm)
|
| 708 |
+
return a
|
| 709 |
+
|
| 710 |
+
|
| 711 |
+
def _fftn_dispatcher(a, s=None, axes=None, norm=None):
|
| 712 |
+
return (a,)
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 716 |
+
def fftn(a, s=None, axes=None, norm=None):
|
| 717 |
+
"""
|
| 718 |
+
Compute the N-dimensional discrete Fourier Transform.
|
| 719 |
+
|
| 720 |
+
This function computes the *N*-dimensional discrete Fourier Transform over
|
| 721 |
+
any number of axes in an *M*-dimensional array by means of the Fast Fourier
|
| 722 |
+
Transform (FFT).
|
| 723 |
+
|
| 724 |
+
Parameters
|
| 725 |
+
----------
|
| 726 |
+
a : array_like
|
| 727 |
+
Input array, can be complex.
|
| 728 |
+
s : sequence of ints, optional
|
| 729 |
+
Shape (length of each transformed axis) of the output
|
| 730 |
+
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
| 731 |
+
This corresponds to ``n`` for ``fft(x, n)``.
|
| 732 |
+
Along any axis, if the given shape is smaller than that of the input,
|
| 733 |
+
the input is cropped. If it is larger, the input is padded with zeros.
|
| 734 |
+
if `s` is not given, the shape of the input along the axes specified
|
| 735 |
+
by `axes` is used.
|
| 736 |
+
axes : sequence of ints, optional
|
| 737 |
+
Axes over which to compute the FFT. If not given, the last ``len(s)``
|
| 738 |
+
axes are used, or all axes if `s` is also not specified.
|
| 739 |
+
Repeated indices in `axes` means that the transform over that axis is
|
| 740 |
+
performed multiple times.
|
| 741 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 742 |
+
.. versionadded:: 1.10.0
|
| 743 |
+
|
| 744 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 745 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 746 |
+
is scaled and with what normalization factor.
|
| 747 |
+
|
| 748 |
+
.. versionadded:: 1.20.0
|
| 749 |
+
|
| 750 |
+
The "backward", "forward" values were added.
|
| 751 |
+
|
| 752 |
+
Returns
|
| 753 |
+
-------
|
| 754 |
+
out : complex ndarray
|
| 755 |
+
The truncated or zero-padded input, transformed along the axes
|
| 756 |
+
indicated by `axes`, or by a combination of `s` and `a`,
|
| 757 |
+
as explained in the parameters section above.
|
| 758 |
+
|
| 759 |
+
Raises
|
| 760 |
+
------
|
| 761 |
+
ValueError
|
| 762 |
+
If `s` and `axes` have different length.
|
| 763 |
+
IndexError
|
| 764 |
+
If an element of `axes` is larger than than the number of axes of `a`.
|
| 765 |
+
|
| 766 |
+
See Also
|
| 767 |
+
--------
|
| 768 |
+
numpy.fft : Overall view of discrete Fourier transforms, with definitions
|
| 769 |
+
and conventions used.
|
| 770 |
+
ifftn : The inverse of `fftn`, the inverse *n*-dimensional FFT.
|
| 771 |
+
fft : The one-dimensional FFT, with definitions and conventions used.
|
| 772 |
+
rfftn : The *n*-dimensional FFT of real input.
|
| 773 |
+
fft2 : The two-dimensional FFT.
|
| 774 |
+
fftshift : Shifts zero-frequency terms to centre of array
|
| 775 |
+
|
| 776 |
+
Notes
|
| 777 |
+
-----
|
| 778 |
+
The output, analogously to `fft`, contains the term for zero frequency in
|
| 779 |
+
the low-order corner of all axes, the positive frequency terms in the
|
| 780 |
+
first half of all axes, the term for the Nyquist frequency in the middle
|
| 781 |
+
of all axes and the negative frequency terms in the second half of all
|
| 782 |
+
axes, in order of decreasingly negative frequency.
|
| 783 |
+
|
| 784 |
+
See `numpy.fft` for details, definitions and conventions used.
|
| 785 |
+
|
| 786 |
+
Examples
|
| 787 |
+
--------
|
| 788 |
+
>>> a = np.mgrid[:3, :3, :3][0]
|
| 789 |
+
>>> np.fft.fftn(a, axes=(1, 2))
|
| 790 |
+
array([[[ 0.+0.j, 0.+0.j, 0.+0.j], # may vary
|
| 791 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j],
|
| 792 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j]],
|
| 793 |
+
[[ 9.+0.j, 0.+0.j, 0.+0.j],
|
| 794 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j],
|
| 795 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j]],
|
| 796 |
+
[[18.+0.j, 0.+0.j, 0.+0.j],
|
| 797 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j],
|
| 798 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j]]])
|
| 799 |
+
>>> np.fft.fftn(a, (2, 2), axes=(0, 1))
|
| 800 |
+
array([[[ 2.+0.j, 2.+0.j, 2.+0.j], # may vary
|
| 801 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j]],
|
| 802 |
+
[[-2.+0.j, -2.+0.j, -2.+0.j],
|
| 803 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j]]])
|
| 804 |
+
|
| 805 |
+
>>> import matplotlib.pyplot as plt
|
| 806 |
+
>>> [X, Y] = np.meshgrid(2 * np.pi * np.arange(200) / 12,
|
| 807 |
+
... 2 * np.pi * np.arange(200) / 34)
|
| 808 |
+
>>> S = np.sin(X) + np.cos(Y) + np.random.uniform(0, 1, X.shape)
|
| 809 |
+
>>> FS = np.fft.fftn(S)
|
| 810 |
+
>>> plt.imshow(np.log(np.abs(np.fft.fftshift(FS))**2))
|
| 811 |
+
<matplotlib.image.AxesImage object at 0x...>
|
| 812 |
+
>>> plt.show()
|
| 813 |
+
|
| 814 |
+
"""
|
| 815 |
+
return _raw_fftnd(a, s, axes, fft, norm)
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 819 |
+
def ifftn(a, s=None, axes=None, norm=None):
|
| 820 |
+
"""
|
| 821 |
+
Compute the N-dimensional inverse discrete Fourier Transform.
|
| 822 |
+
|
| 823 |
+
This function computes the inverse of the N-dimensional discrete
|
| 824 |
+
Fourier Transform over any number of axes in an M-dimensional array by
|
| 825 |
+
means of the Fast Fourier Transform (FFT). In other words,
|
| 826 |
+
``ifftn(fftn(a)) == a`` to within numerical accuracy.
|
| 827 |
+
For a description of the definitions and conventions used, see `numpy.fft`.
|
| 828 |
+
|
| 829 |
+
The input, analogously to `ifft`, should be ordered in the same way as is
|
| 830 |
+
returned by `fftn`, i.e. it should have the term for zero frequency
|
| 831 |
+
in all axes in the low-order corner, the positive frequency terms in the
|
| 832 |
+
first half of all axes, the term for the Nyquist frequency in the middle
|
| 833 |
+
of all axes and the negative frequency terms in the second half of all
|
| 834 |
+
axes, in order of decreasingly negative frequency.
|
| 835 |
+
|
| 836 |
+
Parameters
|
| 837 |
+
----------
|
| 838 |
+
a : array_like
|
| 839 |
+
Input array, can be complex.
|
| 840 |
+
s : sequence of ints, optional
|
| 841 |
+
Shape (length of each transformed axis) of the output
|
| 842 |
+
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
| 843 |
+
This corresponds to ``n`` for ``ifft(x, n)``.
|
| 844 |
+
Along any axis, if the given shape is smaller than that of the input,
|
| 845 |
+
the input is cropped. If it is larger, the input is padded with zeros.
|
| 846 |
+
if `s` is not given, the shape of the input along the axes specified
|
| 847 |
+
by `axes` is used. See notes for issue on `ifft` zero padding.
|
| 848 |
+
axes : sequence of ints, optional
|
| 849 |
+
Axes over which to compute the IFFT. If not given, the last ``len(s)``
|
| 850 |
+
axes are used, or all axes if `s` is also not specified.
|
| 851 |
+
Repeated indices in `axes` means that the inverse transform over that
|
| 852 |
+
axis is performed multiple times.
|
| 853 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 854 |
+
.. versionadded:: 1.10.0
|
| 855 |
+
|
| 856 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 857 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 858 |
+
is scaled and with what normalization factor.
|
| 859 |
+
|
| 860 |
+
.. versionadded:: 1.20.0
|
| 861 |
+
|
| 862 |
+
The "backward", "forward" values were added.
|
| 863 |
+
|
| 864 |
+
Returns
|
| 865 |
+
-------
|
| 866 |
+
out : complex ndarray
|
| 867 |
+
The truncated or zero-padded input, transformed along the axes
|
| 868 |
+
indicated by `axes`, or by a combination of `s` or `a`,
|
| 869 |
+
as explained in the parameters section above.
|
| 870 |
+
|
| 871 |
+
Raises
|
| 872 |
+
------
|
| 873 |
+
ValueError
|
| 874 |
+
If `s` and `axes` have different length.
|
| 875 |
+
IndexError
|
| 876 |
+
If an element of `axes` is larger than than the number of axes of `a`.
|
| 877 |
+
|
| 878 |
+
See Also
|
| 879 |
+
--------
|
| 880 |
+
numpy.fft : Overall view of discrete Fourier transforms, with definitions
|
| 881 |
+
and conventions used.
|
| 882 |
+
fftn : The forward *n*-dimensional FFT, of which `ifftn` is the inverse.
|
| 883 |
+
ifft : The one-dimensional inverse FFT.
|
| 884 |
+
ifft2 : The two-dimensional inverse FFT.
|
| 885 |
+
ifftshift : Undoes `fftshift`, shifts zero-frequency terms to beginning
|
| 886 |
+
of array.
|
| 887 |
+
|
| 888 |
+
Notes
|
| 889 |
+
-----
|
| 890 |
+
See `numpy.fft` for definitions and conventions used.
|
| 891 |
+
|
| 892 |
+
Zero-padding, analogously with `ifft`, is performed by appending zeros to
|
| 893 |
+
the input along the specified dimension. Although this is the common
|
| 894 |
+
approach, it might lead to surprising results. If another form of zero
|
| 895 |
+
padding is desired, it must be performed before `ifftn` is called.
|
| 896 |
+
|
| 897 |
+
Examples
|
| 898 |
+
--------
|
| 899 |
+
>>> a = np.eye(4)
|
| 900 |
+
>>> np.fft.ifftn(np.fft.fftn(a, axes=(0,)), axes=(1,))
|
| 901 |
+
array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], # may vary
|
| 902 |
+
[0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
|
| 903 |
+
[0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
|
| 904 |
+
[0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])
|
| 905 |
+
|
| 906 |
+
|
| 907 |
+
Create and plot an image with band-limited frequency content:
|
| 908 |
+
|
| 909 |
+
>>> import matplotlib.pyplot as plt
|
| 910 |
+
>>> n = np.zeros((200,200), dtype=complex)
|
| 911 |
+
>>> n[60:80, 20:40] = np.exp(1j*np.random.uniform(0, 2*np.pi, (20, 20)))
|
| 912 |
+
>>> im = np.fft.ifftn(n).real
|
| 913 |
+
>>> plt.imshow(im)
|
| 914 |
+
<matplotlib.image.AxesImage object at 0x...>
|
| 915 |
+
>>> plt.show()
|
| 916 |
+
|
| 917 |
+
"""
|
| 918 |
+
return _raw_fftnd(a, s, axes, ifft, norm)
|
| 919 |
+
|
| 920 |
+
|
| 921 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 922 |
+
def fft2(a, s=None, axes=(-2, -1), norm=None):
|
| 923 |
+
"""
|
| 924 |
+
Compute the 2-dimensional discrete Fourier Transform.
|
| 925 |
+
|
| 926 |
+
This function computes the *n*-dimensional discrete Fourier Transform
|
| 927 |
+
over any axes in an *M*-dimensional array by means of the
|
| 928 |
+
Fast Fourier Transform (FFT). By default, the transform is computed over
|
| 929 |
+
the last two axes of the input array, i.e., a 2-dimensional FFT.
|
| 930 |
+
|
| 931 |
+
Parameters
|
| 932 |
+
----------
|
| 933 |
+
a : array_like
|
| 934 |
+
Input array, can be complex
|
| 935 |
+
s : sequence of ints, optional
|
| 936 |
+
Shape (length of each transformed axis) of the output
|
| 937 |
+
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
| 938 |
+
This corresponds to ``n`` for ``fft(x, n)``.
|
| 939 |
+
Along each axis, if the given shape is smaller than that of the input,
|
| 940 |
+
the input is cropped. If it is larger, the input is padded with zeros.
|
| 941 |
+
if `s` is not given, the shape of the input along the axes specified
|
| 942 |
+
by `axes` is used.
|
| 943 |
+
axes : sequence of ints, optional
|
| 944 |
+
Axes over which to compute the FFT. If not given, the last two
|
| 945 |
+
axes are used. A repeated index in `axes` means the transform over
|
| 946 |
+
that axis is performed multiple times. A one-element sequence means
|
| 947 |
+
that a one-dimensional FFT is performed.
|
| 948 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 949 |
+
.. versionadded:: 1.10.0
|
| 950 |
+
|
| 951 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 952 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 953 |
+
is scaled and with what normalization factor.
|
| 954 |
+
|
| 955 |
+
.. versionadded:: 1.20.0
|
| 956 |
+
|
| 957 |
+
The "backward", "forward" values were added.
|
| 958 |
+
|
| 959 |
+
Returns
|
| 960 |
+
-------
|
| 961 |
+
out : complex ndarray
|
| 962 |
+
The truncated or zero-padded input, transformed along the axes
|
| 963 |
+
indicated by `axes`, or the last two axes if `axes` is not given.
|
| 964 |
+
|
| 965 |
+
Raises
|
| 966 |
+
------
|
| 967 |
+
ValueError
|
| 968 |
+
If `s` and `axes` have different length, or `axes` not given and
|
| 969 |
+
``len(s) != 2``.
|
| 970 |
+
IndexError
|
| 971 |
+
If an element of `axes` is larger than than the number of axes of `a`.
|
| 972 |
+
|
| 973 |
+
See Also
|
| 974 |
+
--------
|
| 975 |
+
numpy.fft : Overall view of discrete Fourier transforms, with definitions
|
| 976 |
+
and conventions used.
|
| 977 |
+
ifft2 : The inverse two-dimensional FFT.
|
| 978 |
+
fft : The one-dimensional FFT.
|
| 979 |
+
fftn : The *n*-dimensional FFT.
|
| 980 |
+
fftshift : Shifts zero-frequency terms to the center of the array.
|
| 981 |
+
For two-dimensional input, swaps first and third quadrants, and second
|
| 982 |
+
and fourth quadrants.
|
| 983 |
+
|
| 984 |
+
Notes
|
| 985 |
+
-----
|
| 986 |
+
`fft2` is just `fftn` with a different default for `axes`.
|
| 987 |
+
|
| 988 |
+
The output, analogously to `fft`, contains the term for zero frequency in
|
| 989 |
+
the low-order corner of the transformed axes, the positive frequency terms
|
| 990 |
+
in the first half of these axes, the term for the Nyquist frequency in the
|
| 991 |
+
middle of the axes and the negative frequency terms in the second half of
|
| 992 |
+
the axes, in order of decreasingly negative frequency.
|
| 993 |
+
|
| 994 |
+
See `fftn` for details and a plotting example, and `numpy.fft` for
|
| 995 |
+
definitions and conventions used.
|
| 996 |
+
|
| 997 |
+
|
| 998 |
+
Examples
|
| 999 |
+
--------
|
| 1000 |
+
>>> a = np.mgrid[:5, :5][0]
|
| 1001 |
+
>>> np.fft.fft2(a)
|
| 1002 |
+
array([[ 50. +0.j , 0. +0.j , 0. +0.j , # may vary
|
| 1003 |
+
0. +0.j , 0. +0.j ],
|
| 1004 |
+
[-12.5+17.20477401j, 0. +0.j , 0. +0.j ,
|
| 1005 |
+
0. +0.j , 0. +0.j ],
|
| 1006 |
+
[-12.5 +4.0614962j , 0. +0.j , 0. +0.j ,
|
| 1007 |
+
0. +0.j , 0. +0.j ],
|
| 1008 |
+
[-12.5 -4.0614962j , 0. +0.j , 0. +0.j ,
|
| 1009 |
+
0. +0.j , 0. +0.j ],
|
| 1010 |
+
[-12.5-17.20477401j, 0. +0.j , 0. +0.j ,
|
| 1011 |
+
0. +0.j , 0. +0.j ]])
|
| 1012 |
+
|
| 1013 |
+
"""
|
| 1014 |
+
return _raw_fftnd(a, s, axes, fft, norm)
|
| 1015 |
+
|
| 1016 |
+
|
| 1017 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 1018 |
+
def ifft2(a, s=None, axes=(-2, -1), norm=None):
|
| 1019 |
+
"""
|
| 1020 |
+
Compute the 2-dimensional inverse discrete Fourier Transform.
|
| 1021 |
+
|
| 1022 |
+
This function computes the inverse of the 2-dimensional discrete Fourier
|
| 1023 |
+
Transform over any number of axes in an M-dimensional array by means of
|
| 1024 |
+
the Fast Fourier Transform (FFT). In other words, ``ifft2(fft2(a)) == a``
|
| 1025 |
+
to within numerical accuracy. By default, the inverse transform is
|
| 1026 |
+
computed over the last two axes of the input array.
|
| 1027 |
+
|
| 1028 |
+
The input, analogously to `ifft`, should be ordered in the same way as is
|
| 1029 |
+
returned by `fft2`, i.e. it should have the term for zero frequency
|
| 1030 |
+
in the low-order corner of the two axes, the positive frequency terms in
|
| 1031 |
+
the first half of these axes, the term for the Nyquist frequency in the
|
| 1032 |
+
middle of the axes and the negative frequency terms in the second half of
|
| 1033 |
+
both axes, in order of decreasingly negative frequency.
|
| 1034 |
+
|
| 1035 |
+
Parameters
|
| 1036 |
+
----------
|
| 1037 |
+
a : array_like
|
| 1038 |
+
Input array, can be complex.
|
| 1039 |
+
s : sequence of ints, optional
|
| 1040 |
+
Shape (length of each axis) of the output (``s[0]`` refers to axis 0,
|
| 1041 |
+
``s[1]`` to axis 1, etc.). This corresponds to `n` for ``ifft(x, n)``.
|
| 1042 |
+
Along each axis, if the given shape is smaller than that of the input,
|
| 1043 |
+
the input is cropped. If it is larger, the input is padded with zeros.
|
| 1044 |
+
if `s` is not given, the shape of the input along the axes specified
|
| 1045 |
+
by `axes` is used. See notes for issue on `ifft` zero padding.
|
| 1046 |
+
axes : sequence of ints, optional
|
| 1047 |
+
Axes over which to compute the FFT. If not given, the last two
|
| 1048 |
+
axes are used. A repeated index in `axes` means the transform over
|
| 1049 |
+
that axis is performed multiple times. A one-element sequence means
|
| 1050 |
+
that a one-dimensional FFT is performed.
|
| 1051 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 1052 |
+
.. versionadded:: 1.10.0
|
| 1053 |
+
|
| 1054 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 1055 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 1056 |
+
is scaled and with what normalization factor.
|
| 1057 |
+
|
| 1058 |
+
.. versionadded:: 1.20.0
|
| 1059 |
+
|
| 1060 |
+
The "backward", "forward" values were added.
|
| 1061 |
+
|
| 1062 |
+
Returns
|
| 1063 |
+
-------
|
| 1064 |
+
out : complex ndarray
|
| 1065 |
+
The truncated or zero-padded input, transformed along the axes
|
| 1066 |
+
indicated by `axes`, or the last two axes if `axes` is not given.
|
| 1067 |
+
|
| 1068 |
+
Raises
|
| 1069 |
+
------
|
| 1070 |
+
ValueError
|
| 1071 |
+
If `s` and `axes` have different length, or `axes` not given and
|
| 1072 |
+
``len(s) != 2``.
|
| 1073 |
+
IndexError
|
| 1074 |
+
If an element of `axes` is larger than than the number of axes of `a`.
|
| 1075 |
+
|
| 1076 |
+
See Also
|
| 1077 |
+
--------
|
| 1078 |
+
numpy.fft : Overall view of discrete Fourier transforms, with definitions
|
| 1079 |
+
and conventions used.
|
| 1080 |
+
fft2 : The forward 2-dimensional FFT, of which `ifft2` is the inverse.
|
| 1081 |
+
ifftn : The inverse of the *n*-dimensional FFT.
|
| 1082 |
+
fft : The one-dimensional FFT.
|
| 1083 |
+
ifft : The one-dimensional inverse FFT.
|
| 1084 |
+
|
| 1085 |
+
Notes
|
| 1086 |
+
-----
|
| 1087 |
+
`ifft2` is just `ifftn` with a different default for `axes`.
|
| 1088 |
+
|
| 1089 |
+
See `ifftn` for details and a plotting example, and `numpy.fft` for
|
| 1090 |
+
definition and conventions used.
|
| 1091 |
+
|
| 1092 |
+
Zero-padding, analogously with `ifft`, is performed by appending zeros to
|
| 1093 |
+
the input along the specified dimension. Although this is the common
|
| 1094 |
+
approach, it might lead to surprising results. If another form of zero
|
| 1095 |
+
padding is desired, it must be performed before `ifft2` is called.
|
| 1096 |
+
|
| 1097 |
+
Examples
|
| 1098 |
+
--------
|
| 1099 |
+
>>> a = 4 * np.eye(4)
|
| 1100 |
+
>>> np.fft.ifft2(a)
|
| 1101 |
+
array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], # may vary
|
| 1102 |
+
[0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],
|
| 1103 |
+
[0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
|
| 1104 |
+
[0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]])
|
| 1105 |
+
|
| 1106 |
+
"""
|
| 1107 |
+
return _raw_fftnd(a, s, axes, ifft, norm)
|
| 1108 |
+
|
| 1109 |
+
|
| 1110 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 1111 |
+
def rfftn(a, s=None, axes=None, norm=None):
|
| 1112 |
+
"""
|
| 1113 |
+
Compute the N-dimensional discrete Fourier Transform for real input.
|
| 1114 |
+
|
| 1115 |
+
This function computes the N-dimensional discrete Fourier Transform over
|
| 1116 |
+
any number of axes in an M-dimensional real array by means of the Fast
|
| 1117 |
+
Fourier Transform (FFT). By default, all axes are transformed, with the
|
| 1118 |
+
real transform performed over the last axis, while the remaining
|
| 1119 |
+
transforms are complex.
|
| 1120 |
+
|
| 1121 |
+
Parameters
|
| 1122 |
+
----------
|
| 1123 |
+
a : array_like
|
| 1124 |
+
Input array, taken to be real.
|
| 1125 |
+
s : sequence of ints, optional
|
| 1126 |
+
Shape (length along each transformed axis) to use from the input.
|
| 1127 |
+
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
| 1128 |
+
The final element of `s` corresponds to `n` for ``rfft(x, n)``, while
|
| 1129 |
+
for the remaining axes, it corresponds to `n` for ``fft(x, n)``.
|
| 1130 |
+
Along any axis, if the given shape is smaller than that of the input,
|
| 1131 |
+
the input is cropped. If it is larger, the input is padded with zeros.
|
| 1132 |
+
if `s` is not given, the shape of the input along the axes specified
|
| 1133 |
+
by `axes` is used.
|
| 1134 |
+
axes : sequence of ints, optional
|
| 1135 |
+
Axes over which to compute the FFT. If not given, the last ``len(s)``
|
| 1136 |
+
axes are used, or all axes if `s` is also not specified.
|
| 1137 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 1138 |
+
.. versionadded:: 1.10.0
|
| 1139 |
+
|
| 1140 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 1141 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 1142 |
+
is scaled and with what normalization factor.
|
| 1143 |
+
|
| 1144 |
+
.. versionadded:: 1.20.0
|
| 1145 |
+
|
| 1146 |
+
The "backward", "forward" values were added.
|
| 1147 |
+
|
| 1148 |
+
Returns
|
| 1149 |
+
-------
|
| 1150 |
+
out : complex ndarray
|
| 1151 |
+
The truncated or zero-padded input, transformed along the axes
|
| 1152 |
+
indicated by `axes`, or by a combination of `s` and `a`,
|
| 1153 |
+
as explained in the parameters section above.
|
| 1154 |
+
The length of the last axis transformed will be ``s[-1]//2+1``,
|
| 1155 |
+
while the remaining transformed axes will have lengths according to
|
| 1156 |
+
`s`, or unchanged from the input.
|
| 1157 |
+
|
| 1158 |
+
Raises
|
| 1159 |
+
------
|
| 1160 |
+
ValueError
|
| 1161 |
+
If `s` and `axes` have different length.
|
| 1162 |
+
IndexError
|
| 1163 |
+
If an element of `axes` is larger than than the number of axes of `a`.
|
| 1164 |
+
|
| 1165 |
+
See Also
|
| 1166 |
+
--------
|
| 1167 |
+
irfftn : The inverse of `rfftn`, i.e. the inverse of the n-dimensional FFT
|
| 1168 |
+
of real input.
|
| 1169 |
+
fft : The one-dimensional FFT, with definitions and conventions used.
|
| 1170 |
+
rfft : The one-dimensional FFT of real input.
|
| 1171 |
+
fftn : The n-dimensional FFT.
|
| 1172 |
+
rfft2 : The two-dimensional FFT of real input.
|
| 1173 |
+
|
| 1174 |
+
Notes
|
| 1175 |
+
-----
|
| 1176 |
+
The transform for real input is performed over the last transformation
|
| 1177 |
+
axis, as by `rfft`, then the transform over the remaining axes is
|
| 1178 |
+
performed as by `fftn`. The order of the output is as for `rfft` for the
|
| 1179 |
+
final transformation axis, and as for `fftn` for the remaining
|
| 1180 |
+
transformation axes.
|
| 1181 |
+
|
| 1182 |
+
See `fft` for details, definitions and conventions used.
|
| 1183 |
+
|
| 1184 |
+
Examples
|
| 1185 |
+
--------
|
| 1186 |
+
>>> a = np.ones((2, 2, 2))
|
| 1187 |
+
>>> np.fft.rfftn(a)
|
| 1188 |
+
array([[[8.+0.j, 0.+0.j], # may vary
|
| 1189 |
+
[0.+0.j, 0.+0.j]],
|
| 1190 |
+
[[0.+0.j, 0.+0.j],
|
| 1191 |
+
[0.+0.j, 0.+0.j]]])
|
| 1192 |
+
|
| 1193 |
+
>>> np.fft.rfftn(a, axes=(2, 0))
|
| 1194 |
+
array([[[4.+0.j, 0.+0.j], # may vary
|
| 1195 |
+
[4.+0.j, 0.+0.j]],
|
| 1196 |
+
[[0.+0.j, 0.+0.j],
|
| 1197 |
+
[0.+0.j, 0.+0.j]]])
|
| 1198 |
+
|
| 1199 |
+
"""
|
| 1200 |
+
a = asarray(a)
|
| 1201 |
+
s, axes = _cook_nd_args(a, s, axes)
|
| 1202 |
+
a = rfft(a, s[-1], axes[-1], norm)
|
| 1203 |
+
for ii in range(len(axes)-1):
|
| 1204 |
+
a = fft(a, s[ii], axes[ii], norm)
|
| 1205 |
+
return a
|
| 1206 |
+
|
| 1207 |
+
|
| 1208 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 1209 |
+
def rfft2(a, s=None, axes=(-2, -1), norm=None):
|
| 1210 |
+
"""
|
| 1211 |
+
Compute the 2-dimensional FFT of a real array.
|
| 1212 |
+
|
| 1213 |
+
Parameters
|
| 1214 |
+
----------
|
| 1215 |
+
a : array
|
| 1216 |
+
Input array, taken to be real.
|
| 1217 |
+
s : sequence of ints, optional
|
| 1218 |
+
Shape of the FFT.
|
| 1219 |
+
axes : sequence of ints, optional
|
| 1220 |
+
Axes over which to compute the FFT.
|
| 1221 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 1222 |
+
.. versionadded:: 1.10.0
|
| 1223 |
+
|
| 1224 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 1225 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 1226 |
+
is scaled and with what normalization factor.
|
| 1227 |
+
|
| 1228 |
+
.. versionadded:: 1.20.0
|
| 1229 |
+
|
| 1230 |
+
The "backward", "forward" values were added.
|
| 1231 |
+
|
| 1232 |
+
Returns
|
| 1233 |
+
-------
|
| 1234 |
+
out : ndarray
|
| 1235 |
+
The result of the real 2-D FFT.
|
| 1236 |
+
|
| 1237 |
+
See Also
|
| 1238 |
+
--------
|
| 1239 |
+
rfftn : Compute the N-dimensional discrete Fourier Transform for real
|
| 1240 |
+
input.
|
| 1241 |
+
|
| 1242 |
+
Notes
|
| 1243 |
+
-----
|
| 1244 |
+
This is really just `rfftn` with different default behavior.
|
| 1245 |
+
For more details see `rfftn`.
|
| 1246 |
+
|
| 1247 |
+
Examples
|
| 1248 |
+
--------
|
| 1249 |
+
>>> a = np.mgrid[:5, :5][0]
|
| 1250 |
+
>>> np.fft.rfft2(a)
|
| 1251 |
+
array([[ 50. +0.j , 0. +0.j , 0. +0.j ],
|
| 1252 |
+
[-12.5+17.20477401j, 0. +0.j , 0. +0.j ],
|
| 1253 |
+
[-12.5 +4.0614962j , 0. +0.j , 0. +0.j ],
|
| 1254 |
+
[-12.5 -4.0614962j , 0. +0.j , 0. +0.j ],
|
| 1255 |
+
[-12.5-17.20477401j, 0. +0.j , 0. +0.j ]])
|
| 1256 |
+
"""
|
| 1257 |
+
return rfftn(a, s, axes, norm)
|
| 1258 |
+
|
| 1259 |
+
|
| 1260 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 1261 |
+
def irfftn(a, s=None, axes=None, norm=None):
|
| 1262 |
+
"""
|
| 1263 |
+
Computes the inverse of `rfftn`.
|
| 1264 |
+
|
| 1265 |
+
This function computes the inverse of the N-dimensional discrete
|
| 1266 |
+
Fourier Transform for real input over any number of axes in an
|
| 1267 |
+
M-dimensional array by means of the Fast Fourier Transform (FFT). In
|
| 1268 |
+
other words, ``irfftn(rfftn(a), a.shape) == a`` to within numerical
|
| 1269 |
+
accuracy. (The ``a.shape`` is necessary like ``len(a)`` is for `irfft`,
|
| 1270 |
+
and for the same reason.)
|
| 1271 |
+
|
| 1272 |
+
The input should be ordered in the same way as is returned by `rfftn`,
|
| 1273 |
+
i.e. as for `irfft` for the final transformation axis, and as for `ifftn`
|
| 1274 |
+
along all the other axes.
|
| 1275 |
+
|
| 1276 |
+
Parameters
|
| 1277 |
+
----------
|
| 1278 |
+
a : array_like
|
| 1279 |
+
Input array.
|
| 1280 |
+
s : sequence of ints, optional
|
| 1281 |
+
Shape (length of each transformed axis) of the output
|
| 1282 |
+
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.). `s` is also the
|
| 1283 |
+
number of input points used along this axis, except for the last axis,
|
| 1284 |
+
where ``s[-1]//2+1`` points of the input are used.
|
| 1285 |
+
Along any axis, if the shape indicated by `s` is smaller than that of
|
| 1286 |
+
the input, the input is cropped. If it is larger, the input is padded
|
| 1287 |
+
with zeros. If `s` is not given, the shape of the input along the axes
|
| 1288 |
+
specified by axes is used. Except for the last axis which is taken to
|
| 1289 |
+
be ``2*(m-1)`` where ``m`` is the length of the input along that axis.
|
| 1290 |
+
axes : sequence of ints, optional
|
| 1291 |
+
Axes over which to compute the inverse FFT. If not given, the last
|
| 1292 |
+
`len(s)` axes are used, or all axes if `s` is also not specified.
|
| 1293 |
+
Repeated indices in `axes` means that the inverse transform over that
|
| 1294 |
+
axis is performed multiple times.
|
| 1295 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 1296 |
+
.. versionadded:: 1.10.0
|
| 1297 |
+
|
| 1298 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 1299 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 1300 |
+
is scaled and with what normalization factor.
|
| 1301 |
+
|
| 1302 |
+
.. versionadded:: 1.20.0
|
| 1303 |
+
|
| 1304 |
+
The "backward", "forward" values were added.
|
| 1305 |
+
|
| 1306 |
+
Returns
|
| 1307 |
+
-------
|
| 1308 |
+
out : ndarray
|
| 1309 |
+
The truncated or zero-padded input, transformed along the axes
|
| 1310 |
+
indicated by `axes`, or by a combination of `s` or `a`,
|
| 1311 |
+
as explained in the parameters section above.
|
| 1312 |
+
The length of each transformed axis is as given by the corresponding
|
| 1313 |
+
element of `s`, or the length of the input in every axis except for the
|
| 1314 |
+
last one if `s` is not given. In the final transformed axis the length
|
| 1315 |
+
of the output when `s` is not given is ``2*(m-1)`` where ``m`` is the
|
| 1316 |
+
length of the final transformed axis of the input. To get an odd
|
| 1317 |
+
number of output points in the final axis, `s` must be specified.
|
| 1318 |
+
|
| 1319 |
+
Raises
|
| 1320 |
+
------
|
| 1321 |
+
ValueError
|
| 1322 |
+
If `s` and `axes` have different length.
|
| 1323 |
+
IndexError
|
| 1324 |
+
If an element of `axes` is larger than than the number of axes of `a`.
|
| 1325 |
+
|
| 1326 |
+
See Also
|
| 1327 |
+
--------
|
| 1328 |
+
rfftn : The forward n-dimensional FFT of real input,
|
| 1329 |
+
of which `ifftn` is the inverse.
|
| 1330 |
+
fft : The one-dimensional FFT, with definitions and conventions used.
|
| 1331 |
+
irfft : The inverse of the one-dimensional FFT of real input.
|
| 1332 |
+
irfft2 : The inverse of the two-dimensional FFT of real input.
|
| 1333 |
+
|
| 1334 |
+
Notes
|
| 1335 |
+
-----
|
| 1336 |
+
See `fft` for definitions and conventions used.
|
| 1337 |
+
|
| 1338 |
+
See `rfft` for definitions and conventions used for real input.
|
| 1339 |
+
|
| 1340 |
+
The correct interpretation of the hermitian input depends on the shape of
|
| 1341 |
+
the original data, as given by `s`. This is because each input shape could
|
| 1342 |
+
correspond to either an odd or even length signal. By default, `irfftn`
|
| 1343 |
+
assumes an even output length which puts the last entry at the Nyquist
|
| 1344 |
+
frequency; aliasing with its symmetric counterpart. When performing the
|
| 1345 |
+
final complex to real transform, the last value is thus treated as purely
|
| 1346 |
+
real. To avoid losing information, the correct shape of the real input
|
| 1347 |
+
**must** be given.
|
| 1348 |
+
|
| 1349 |
+
Examples
|
| 1350 |
+
--------
|
| 1351 |
+
>>> a = np.zeros((3, 2, 2))
|
| 1352 |
+
>>> a[0, 0, 0] = 3 * 2 * 2
|
| 1353 |
+
>>> np.fft.irfftn(a)
|
| 1354 |
+
array([[[1., 1.],
|
| 1355 |
+
[1., 1.]],
|
| 1356 |
+
[[1., 1.],
|
| 1357 |
+
[1., 1.]],
|
| 1358 |
+
[[1., 1.],
|
| 1359 |
+
[1., 1.]]])
|
| 1360 |
+
|
| 1361 |
+
"""
|
| 1362 |
+
a = asarray(a)
|
| 1363 |
+
s, axes = _cook_nd_args(a, s, axes, invreal=1)
|
| 1364 |
+
for ii in range(len(axes)-1):
|
| 1365 |
+
a = ifft(a, s[ii], axes[ii], norm)
|
| 1366 |
+
a = irfft(a, s[-1], axes[-1], norm)
|
| 1367 |
+
return a
|
| 1368 |
+
|
| 1369 |
+
|
| 1370 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 1371 |
+
def irfft2(a, s=None, axes=(-2, -1), norm=None):
|
| 1372 |
+
"""
|
| 1373 |
+
Computes the inverse of `rfft2`.
|
| 1374 |
+
|
| 1375 |
+
Parameters
|
| 1376 |
+
----------
|
| 1377 |
+
a : array_like
|
| 1378 |
+
The input array
|
| 1379 |
+
s : sequence of ints, optional
|
| 1380 |
+
Shape of the real output to the inverse FFT.
|
| 1381 |
+
axes : sequence of ints, optional
|
| 1382 |
+
The axes over which to compute the inverse fft.
|
| 1383 |
+
Default is the last two axes.
|
| 1384 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 1385 |
+
.. versionadded:: 1.10.0
|
| 1386 |
+
|
| 1387 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 1388 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 1389 |
+
is scaled and with what normalization factor.
|
| 1390 |
+
|
| 1391 |
+
.. versionadded:: 1.20.0
|
| 1392 |
+
|
| 1393 |
+
The "backward", "forward" values were added.
|
| 1394 |
+
|
| 1395 |
+
Returns
|
| 1396 |
+
-------
|
| 1397 |
+
out : ndarray
|
| 1398 |
+
The result of the inverse real 2-D FFT.
|
| 1399 |
+
|
| 1400 |
+
See Also
|
| 1401 |
+
--------
|
| 1402 |
+
rfft2 : The forward two-dimensional FFT of real input,
|
| 1403 |
+
of which `irfft2` is the inverse.
|
| 1404 |
+
rfft : The one-dimensional FFT for real input.
|
| 1405 |
+
irfft : The inverse of the one-dimensional FFT of real input.
|
| 1406 |
+
irfftn : Compute the inverse of the N-dimensional FFT of real input.
|
| 1407 |
+
|
| 1408 |
+
Notes
|
| 1409 |
+
-----
|
| 1410 |
+
This is really `irfftn` with different defaults.
|
| 1411 |
+
For more details see `irfftn`.
|
| 1412 |
+
|
| 1413 |
+
Examples
|
| 1414 |
+
--------
|
| 1415 |
+
>>> a = np.mgrid[:5, :5][0]
|
| 1416 |
+
>>> A = np.fft.rfft2(a)
|
| 1417 |
+
>>> np.fft.irfft2(A, s=a.shape)
|
| 1418 |
+
array([[0., 0., 0., 0., 0.],
|
| 1419 |
+
[1., 1., 1., 1., 1.],
|
| 1420 |
+
[2., 2., 2., 2., 2.],
|
| 1421 |
+
[3., 3., 3., 3., 3.],
|
| 1422 |
+
[4., 4., 4., 4., 4.]])
|
| 1423 |
+
"""
|
| 1424 |
+
return irfftn(a, s, axes, norm)
|
.venv/lib/python3.11/site-packages/numpy/fft/_pocketfft.pyi
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Sequence
|
| 2 |
+
from typing import Literal as L
|
| 3 |
+
|
| 4 |
+
from numpy import complex128, float64
|
| 5 |
+
from numpy._typing import ArrayLike, NDArray, _ArrayLikeNumber_co
|
| 6 |
+
|
| 7 |
+
_NormKind = L[None, "backward", "ortho", "forward"]
|
| 8 |
+
|
| 9 |
+
__all__: list[str]
|
| 10 |
+
|
| 11 |
+
def fft(
|
| 12 |
+
a: ArrayLike,
|
| 13 |
+
n: None | int = ...,
|
| 14 |
+
axis: int = ...,
|
| 15 |
+
norm: _NormKind = ...,
|
| 16 |
+
) -> NDArray[complex128]: ...
|
| 17 |
+
|
| 18 |
+
def ifft(
|
| 19 |
+
a: ArrayLike,
|
| 20 |
+
n: None | int = ...,
|
| 21 |
+
axis: int = ...,
|
| 22 |
+
norm: _NormKind = ...,
|
| 23 |
+
) -> NDArray[complex128]: ...
|
| 24 |
+
|
| 25 |
+
def rfft(
|
| 26 |
+
a: ArrayLike,
|
| 27 |
+
n: None | int = ...,
|
| 28 |
+
axis: int = ...,
|
| 29 |
+
norm: _NormKind = ...,
|
| 30 |
+
) -> NDArray[complex128]: ...
|
| 31 |
+
|
| 32 |
+
def irfft(
|
| 33 |
+
a: ArrayLike,
|
| 34 |
+
n: None | int = ...,
|
| 35 |
+
axis: int = ...,
|
| 36 |
+
norm: _NormKind = ...,
|
| 37 |
+
) -> NDArray[float64]: ...
|
| 38 |
+
|
| 39 |
+
# Input array must be compatible with `np.conjugate`
|
| 40 |
+
def hfft(
|
| 41 |
+
a: _ArrayLikeNumber_co,
|
| 42 |
+
n: None | int = ...,
|
| 43 |
+
axis: int = ...,
|
| 44 |
+
norm: _NormKind = ...,
|
| 45 |
+
) -> NDArray[float64]: ...
|
| 46 |
+
|
| 47 |
+
def ihfft(
|
| 48 |
+
a: ArrayLike,
|
| 49 |
+
n: None | int = ...,
|
| 50 |
+
axis: int = ...,
|
| 51 |
+
norm: _NormKind = ...,
|
| 52 |
+
) -> NDArray[complex128]: ...
|
| 53 |
+
|
| 54 |
+
def fftn(
|
| 55 |
+
a: ArrayLike,
|
| 56 |
+
s: None | Sequence[int] = ...,
|
| 57 |
+
axes: None | Sequence[int] = ...,
|
| 58 |
+
norm: _NormKind = ...,
|
| 59 |
+
) -> NDArray[complex128]: ...
|
| 60 |
+
|
| 61 |
+
def ifftn(
|
| 62 |
+
a: ArrayLike,
|
| 63 |
+
s: None | Sequence[int] = ...,
|
| 64 |
+
axes: None | Sequence[int] = ...,
|
| 65 |
+
norm: _NormKind = ...,
|
| 66 |
+
) -> NDArray[complex128]: ...
|
| 67 |
+
|
| 68 |
+
def rfftn(
|
| 69 |
+
a: ArrayLike,
|
| 70 |
+
s: None | Sequence[int] = ...,
|
| 71 |
+
axes: None | Sequence[int] = ...,
|
| 72 |
+
norm: _NormKind = ...,
|
| 73 |
+
) -> NDArray[complex128]: ...
|
| 74 |
+
|
| 75 |
+
def irfftn(
|
| 76 |
+
a: ArrayLike,
|
| 77 |
+
s: None | Sequence[int] = ...,
|
| 78 |
+
axes: None | Sequence[int] = ...,
|
| 79 |
+
norm: _NormKind = ...,
|
| 80 |
+
) -> NDArray[float64]: ...
|
| 81 |
+
|
| 82 |
+
def fft2(
|
| 83 |
+
a: ArrayLike,
|
| 84 |
+
s: None | Sequence[int] = ...,
|
| 85 |
+
axes: None | Sequence[int] = ...,
|
| 86 |
+
norm: _NormKind = ...,
|
| 87 |
+
) -> NDArray[complex128]: ...
|
| 88 |
+
|
| 89 |
+
def ifft2(
|
| 90 |
+
a: ArrayLike,
|
| 91 |
+
s: None | Sequence[int] = ...,
|
| 92 |
+
axes: None | Sequence[int] = ...,
|
| 93 |
+
norm: _NormKind = ...,
|
| 94 |
+
) -> NDArray[complex128]: ...
|
| 95 |
+
|
| 96 |
+
def rfft2(
|
| 97 |
+
a: ArrayLike,
|
| 98 |
+
s: None | Sequence[int] = ...,
|
| 99 |
+
axes: None | Sequence[int] = ...,
|
| 100 |
+
norm: _NormKind = ...,
|
| 101 |
+
) -> NDArray[complex128]: ...
|
| 102 |
+
|
| 103 |
+
def irfft2(
|
| 104 |
+
a: ArrayLike,
|
| 105 |
+
s: None | Sequence[int] = ...,
|
| 106 |
+
axes: None | Sequence[int] = ...,
|
| 107 |
+
norm: _NormKind = ...,
|
| 108 |
+
) -> NDArray[float64]: ...
|
.venv/lib/python3.11/site-packages/numpy/fft/_pocketfft_internal.cpython-311-x86_64-linux-gnu.so
ADDED
|
Binary file (97 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/fft/helper.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Discrete Fourier Transforms - helper.py
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
from numpy.core import integer, empty, arange, asarray, roll
|
| 6 |
+
from numpy.core.overrides import array_function_dispatch, set_module
|
| 7 |
+
|
| 8 |
+
# Created by Pearu Peterson, September 2002
|
| 9 |
+
|
| 10 |
+
__all__ = ['fftshift', 'ifftshift', 'fftfreq', 'rfftfreq']
|
| 11 |
+
|
| 12 |
+
integer_types = (int, integer)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _fftshift_dispatcher(x, axes=None):
|
| 16 |
+
return (x,)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@array_function_dispatch(_fftshift_dispatcher, module='numpy.fft')
|
| 20 |
+
def fftshift(x, axes=None):
|
| 21 |
+
"""
|
| 22 |
+
Shift the zero-frequency component to the center of the spectrum.
|
| 23 |
+
|
| 24 |
+
This function swaps half-spaces for all axes listed (defaults to all).
|
| 25 |
+
Note that ``y[0]`` is the Nyquist component only if ``len(x)`` is even.
|
| 26 |
+
|
| 27 |
+
Parameters
|
| 28 |
+
----------
|
| 29 |
+
x : array_like
|
| 30 |
+
Input array.
|
| 31 |
+
axes : int or shape tuple, optional
|
| 32 |
+
Axes over which to shift. Default is None, which shifts all axes.
|
| 33 |
+
|
| 34 |
+
Returns
|
| 35 |
+
-------
|
| 36 |
+
y : ndarray
|
| 37 |
+
The shifted array.
|
| 38 |
+
|
| 39 |
+
See Also
|
| 40 |
+
--------
|
| 41 |
+
ifftshift : The inverse of `fftshift`.
|
| 42 |
+
|
| 43 |
+
Examples
|
| 44 |
+
--------
|
| 45 |
+
>>> freqs = np.fft.fftfreq(10, 0.1)
|
| 46 |
+
>>> freqs
|
| 47 |
+
array([ 0., 1., 2., ..., -3., -2., -1.])
|
| 48 |
+
>>> np.fft.fftshift(freqs)
|
| 49 |
+
array([-5., -4., -3., -2., -1., 0., 1., 2., 3., 4.])
|
| 50 |
+
|
| 51 |
+
Shift the zero-frequency component only along the second axis:
|
| 52 |
+
|
| 53 |
+
>>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
|
| 54 |
+
>>> freqs
|
| 55 |
+
array([[ 0., 1., 2.],
|
| 56 |
+
[ 3., 4., -4.],
|
| 57 |
+
[-3., -2., -1.]])
|
| 58 |
+
>>> np.fft.fftshift(freqs, axes=(1,))
|
| 59 |
+
array([[ 2., 0., 1.],
|
| 60 |
+
[-4., 3., 4.],
|
| 61 |
+
[-1., -3., -2.]])
|
| 62 |
+
|
| 63 |
+
"""
|
| 64 |
+
x = asarray(x)
|
| 65 |
+
if axes is None:
|
| 66 |
+
axes = tuple(range(x.ndim))
|
| 67 |
+
shift = [dim // 2 for dim in x.shape]
|
| 68 |
+
elif isinstance(axes, integer_types):
|
| 69 |
+
shift = x.shape[axes] // 2
|
| 70 |
+
else:
|
| 71 |
+
shift = [x.shape[ax] // 2 for ax in axes]
|
| 72 |
+
|
| 73 |
+
return roll(x, shift, axes)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
@array_function_dispatch(_fftshift_dispatcher, module='numpy.fft')
|
| 77 |
+
def ifftshift(x, axes=None):
|
| 78 |
+
"""
|
| 79 |
+
The inverse of `fftshift`. Although identical for even-length `x`, the
|
| 80 |
+
functions differ by one sample for odd-length `x`.
|
| 81 |
+
|
| 82 |
+
Parameters
|
| 83 |
+
----------
|
| 84 |
+
x : array_like
|
| 85 |
+
Input array.
|
| 86 |
+
axes : int or shape tuple, optional
|
| 87 |
+
Axes over which to calculate. Defaults to None, which shifts all axes.
|
| 88 |
+
|
| 89 |
+
Returns
|
| 90 |
+
-------
|
| 91 |
+
y : ndarray
|
| 92 |
+
The shifted array.
|
| 93 |
+
|
| 94 |
+
See Also
|
| 95 |
+
--------
|
| 96 |
+
fftshift : Shift zero-frequency component to the center of the spectrum.
|
| 97 |
+
|
| 98 |
+
Examples
|
| 99 |
+
--------
|
| 100 |
+
>>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
|
| 101 |
+
>>> freqs
|
| 102 |
+
array([[ 0., 1., 2.],
|
| 103 |
+
[ 3., 4., -4.],
|
| 104 |
+
[-3., -2., -1.]])
|
| 105 |
+
>>> np.fft.ifftshift(np.fft.fftshift(freqs))
|
| 106 |
+
array([[ 0., 1., 2.],
|
| 107 |
+
[ 3., 4., -4.],
|
| 108 |
+
[-3., -2., -1.]])
|
| 109 |
+
|
| 110 |
+
"""
|
| 111 |
+
x = asarray(x)
|
| 112 |
+
if axes is None:
|
| 113 |
+
axes = tuple(range(x.ndim))
|
| 114 |
+
shift = [-(dim // 2) for dim in x.shape]
|
| 115 |
+
elif isinstance(axes, integer_types):
|
| 116 |
+
shift = -(x.shape[axes] // 2)
|
| 117 |
+
else:
|
| 118 |
+
shift = [-(x.shape[ax] // 2) for ax in axes]
|
| 119 |
+
|
| 120 |
+
return roll(x, shift, axes)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
@set_module('numpy.fft')
|
| 124 |
+
def fftfreq(n, d=1.0):
|
| 125 |
+
"""
|
| 126 |
+
Return the Discrete Fourier Transform sample frequencies.
|
| 127 |
+
|
| 128 |
+
The returned float array `f` contains the frequency bin centers in cycles
|
| 129 |
+
per unit of the sample spacing (with zero at the start). For instance, if
|
| 130 |
+
the sample spacing is in seconds, then the frequency unit is cycles/second.
|
| 131 |
+
|
| 132 |
+
Given a window length `n` and a sample spacing `d`::
|
| 133 |
+
|
| 134 |
+
f = [0, 1, ..., n/2-1, -n/2, ..., -1] / (d*n) if n is even
|
| 135 |
+
f = [0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (d*n) if n is odd
|
| 136 |
+
|
| 137 |
+
Parameters
|
| 138 |
+
----------
|
| 139 |
+
n : int
|
| 140 |
+
Window length.
|
| 141 |
+
d : scalar, optional
|
| 142 |
+
Sample spacing (inverse of the sampling rate). Defaults to 1.
|
| 143 |
+
|
| 144 |
+
Returns
|
| 145 |
+
-------
|
| 146 |
+
f : ndarray
|
| 147 |
+
Array of length `n` containing the sample frequencies.
|
| 148 |
+
|
| 149 |
+
Examples
|
| 150 |
+
--------
|
| 151 |
+
>>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float)
|
| 152 |
+
>>> fourier = np.fft.fft(signal)
|
| 153 |
+
>>> n = signal.size
|
| 154 |
+
>>> timestep = 0.1
|
| 155 |
+
>>> freq = np.fft.fftfreq(n, d=timestep)
|
| 156 |
+
>>> freq
|
| 157 |
+
array([ 0. , 1.25, 2.5 , ..., -3.75, -2.5 , -1.25])
|
| 158 |
+
|
| 159 |
+
"""
|
| 160 |
+
if not isinstance(n, integer_types):
|
| 161 |
+
raise ValueError("n should be an integer")
|
| 162 |
+
val = 1.0 / (n * d)
|
| 163 |
+
results = empty(n, int)
|
| 164 |
+
N = (n-1)//2 + 1
|
| 165 |
+
p1 = arange(0, N, dtype=int)
|
| 166 |
+
results[:N] = p1
|
| 167 |
+
p2 = arange(-(n//2), 0, dtype=int)
|
| 168 |
+
results[N:] = p2
|
| 169 |
+
return results * val
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
@set_module('numpy.fft')
|
| 173 |
+
def rfftfreq(n, d=1.0):
|
| 174 |
+
"""
|
| 175 |
+
Return the Discrete Fourier Transform sample frequencies
|
| 176 |
+
(for usage with rfft, irfft).
|
| 177 |
+
|
| 178 |
+
The returned float array `f` contains the frequency bin centers in cycles
|
| 179 |
+
per unit of the sample spacing (with zero at the start). For instance, if
|
| 180 |
+
the sample spacing is in seconds, then the frequency unit is cycles/second.
|
| 181 |
+
|
| 182 |
+
Given a window length `n` and a sample spacing `d`::
|
| 183 |
+
|
| 184 |
+
f = [0, 1, ..., n/2-1, n/2] / (d*n) if n is even
|
| 185 |
+
f = [0, 1, ..., (n-1)/2-1, (n-1)/2] / (d*n) if n is odd
|
| 186 |
+
|
| 187 |
+
Unlike `fftfreq` (but like `scipy.fftpack.rfftfreq`)
|
| 188 |
+
the Nyquist frequency component is considered to be positive.
|
| 189 |
+
|
| 190 |
+
Parameters
|
| 191 |
+
----------
|
| 192 |
+
n : int
|
| 193 |
+
Window length.
|
| 194 |
+
d : scalar, optional
|
| 195 |
+
Sample spacing (inverse of the sampling rate). Defaults to 1.
|
| 196 |
+
|
| 197 |
+
Returns
|
| 198 |
+
-------
|
| 199 |
+
f : ndarray
|
| 200 |
+
Array of length ``n//2 + 1`` containing the sample frequencies.
|
| 201 |
+
|
| 202 |
+
Examples
|
| 203 |
+
--------
|
| 204 |
+
>>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5, -3, 4], dtype=float)
|
| 205 |
+
>>> fourier = np.fft.rfft(signal)
|
| 206 |
+
>>> n = signal.size
|
| 207 |
+
>>> sample_rate = 100
|
| 208 |
+
>>> freq = np.fft.fftfreq(n, d=1./sample_rate)
|
| 209 |
+
>>> freq
|
| 210 |
+
array([ 0., 10., 20., ..., -30., -20., -10.])
|
| 211 |
+
>>> freq = np.fft.rfftfreq(n, d=1./sample_rate)
|
| 212 |
+
>>> freq
|
| 213 |
+
array([ 0., 10., 20., 30., 40., 50.])
|
| 214 |
+
|
| 215 |
+
"""
|
| 216 |
+
if not isinstance(n, integer_types):
|
| 217 |
+
raise ValueError("n should be an integer")
|
| 218 |
+
val = 1.0/(n*d)
|
| 219 |
+
N = n//2 + 1
|
| 220 |
+
results = arange(0, N, dtype=int)
|
| 221 |
+
return results * val
|
.venv/lib/python3.11/site-packages/numpy/fft/helper.pyi
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, TypeVar, overload
|
| 2 |
+
|
| 3 |
+
from numpy import generic, integer, floating, complexfloating
|
| 4 |
+
from numpy._typing import (
|
| 5 |
+
NDArray,
|
| 6 |
+
ArrayLike,
|
| 7 |
+
_ShapeLike,
|
| 8 |
+
_ArrayLike,
|
| 9 |
+
_ArrayLikeFloat_co,
|
| 10 |
+
_ArrayLikeComplex_co,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
_SCT = TypeVar("_SCT", bound=generic)
|
| 14 |
+
|
| 15 |
+
__all__: list[str]
|
| 16 |
+
|
| 17 |
+
@overload
|
| 18 |
+
def fftshift(x: _ArrayLike[_SCT], axes: None | _ShapeLike = ...) -> NDArray[_SCT]: ...
|
| 19 |
+
@overload
|
| 20 |
+
def fftshift(x: ArrayLike, axes: None | _ShapeLike = ...) -> NDArray[Any]: ...
|
| 21 |
+
|
| 22 |
+
@overload
|
| 23 |
+
def ifftshift(x: _ArrayLike[_SCT], axes: None | _ShapeLike = ...) -> NDArray[_SCT]: ...
|
| 24 |
+
@overload
|
| 25 |
+
def ifftshift(x: ArrayLike, axes: None | _ShapeLike = ...) -> NDArray[Any]: ...
|
| 26 |
+
|
| 27 |
+
@overload
|
| 28 |
+
def fftfreq(
|
| 29 |
+
n: int | integer[Any],
|
| 30 |
+
d: _ArrayLikeFloat_co = ...,
|
| 31 |
+
) -> NDArray[floating[Any]]: ...
|
| 32 |
+
@overload
|
| 33 |
+
def fftfreq(
|
| 34 |
+
n: int | integer[Any],
|
| 35 |
+
d: _ArrayLikeComplex_co = ...,
|
| 36 |
+
) -> NDArray[complexfloating[Any, Any]]: ...
|
| 37 |
+
|
| 38 |
+
@overload
|
| 39 |
+
def rfftfreq(
|
| 40 |
+
n: int | integer[Any],
|
| 41 |
+
d: _ArrayLikeFloat_co = ...,
|
| 42 |
+
) -> NDArray[floating[Any]]: ...
|
| 43 |
+
@overload
|
| 44 |
+
def rfftfreq(
|
| 45 |
+
n: int | integer[Any],
|
| 46 |
+
d: _ArrayLikeComplex_co = ...,
|
| 47 |
+
) -> NDArray[complexfloating[Any, Any]]: ...
|
.venv/lib/python3.11/site-packages/numpy/fft/tests/test_pocketfft.py
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
from numpy.random import random
|
| 4 |
+
from numpy.testing import (
|
| 5 |
+
assert_array_equal, assert_raises, assert_allclose, IS_WASM
|
| 6 |
+
)
|
| 7 |
+
import threading
|
| 8 |
+
import queue
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def fft1(x):
|
| 12 |
+
L = len(x)
|
| 13 |
+
phase = -2j * np.pi * (np.arange(L) / L)
|
| 14 |
+
phase = np.arange(L).reshape(-1, 1) * phase
|
| 15 |
+
return np.sum(x*np.exp(phase), axis=1)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class TestFFTShift:
|
| 19 |
+
|
| 20 |
+
def test_fft_n(self):
|
| 21 |
+
assert_raises(ValueError, np.fft.fft, [1, 2, 3], 0)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class TestFFT1D:
|
| 25 |
+
|
| 26 |
+
def test_identity(self):
|
| 27 |
+
maxlen = 512
|
| 28 |
+
x = random(maxlen) + 1j*random(maxlen)
|
| 29 |
+
xr = random(maxlen)
|
| 30 |
+
for i in range(1, maxlen):
|
| 31 |
+
assert_allclose(np.fft.ifft(np.fft.fft(x[0:i])), x[0:i],
|
| 32 |
+
atol=1e-12)
|
| 33 |
+
assert_allclose(np.fft.irfft(np.fft.rfft(xr[0:i]), i),
|
| 34 |
+
xr[0:i], atol=1e-12)
|
| 35 |
+
|
| 36 |
+
def test_fft(self):
|
| 37 |
+
x = random(30) + 1j*random(30)
|
| 38 |
+
assert_allclose(fft1(x), np.fft.fft(x), atol=1e-6)
|
| 39 |
+
assert_allclose(fft1(x), np.fft.fft(x, norm="backward"), atol=1e-6)
|
| 40 |
+
assert_allclose(fft1(x) / np.sqrt(30),
|
| 41 |
+
np.fft.fft(x, norm="ortho"), atol=1e-6)
|
| 42 |
+
assert_allclose(fft1(x) / 30.,
|
| 43 |
+
np.fft.fft(x, norm="forward"), atol=1e-6)
|
| 44 |
+
|
| 45 |
+
@pytest.mark.parametrize('norm', (None, 'backward', 'ortho', 'forward'))
|
| 46 |
+
def test_ifft(self, norm):
|
| 47 |
+
x = random(30) + 1j*random(30)
|
| 48 |
+
assert_allclose(
|
| 49 |
+
x, np.fft.ifft(np.fft.fft(x, norm=norm), norm=norm),
|
| 50 |
+
atol=1e-6)
|
| 51 |
+
# Ensure we get the correct error message
|
| 52 |
+
with pytest.raises(ValueError,
|
| 53 |
+
match='Invalid number of FFT data points'):
|
| 54 |
+
np.fft.ifft([], norm=norm)
|
| 55 |
+
|
| 56 |
+
def test_fft2(self):
|
| 57 |
+
x = random((30, 20)) + 1j*random((30, 20))
|
| 58 |
+
assert_allclose(np.fft.fft(np.fft.fft(x, axis=1), axis=0),
|
| 59 |
+
np.fft.fft2(x), atol=1e-6)
|
| 60 |
+
assert_allclose(np.fft.fft2(x),
|
| 61 |
+
np.fft.fft2(x, norm="backward"), atol=1e-6)
|
| 62 |
+
assert_allclose(np.fft.fft2(x) / np.sqrt(30 * 20),
|
| 63 |
+
np.fft.fft2(x, norm="ortho"), atol=1e-6)
|
| 64 |
+
assert_allclose(np.fft.fft2(x) / (30. * 20.),
|
| 65 |
+
np.fft.fft2(x, norm="forward"), atol=1e-6)
|
| 66 |
+
|
| 67 |
+
def test_ifft2(self):
|
| 68 |
+
x = random((30, 20)) + 1j*random((30, 20))
|
| 69 |
+
assert_allclose(np.fft.ifft(np.fft.ifft(x, axis=1), axis=0),
|
| 70 |
+
np.fft.ifft2(x), atol=1e-6)
|
| 71 |
+
assert_allclose(np.fft.ifft2(x),
|
| 72 |
+
np.fft.ifft2(x, norm="backward"), atol=1e-6)
|
| 73 |
+
assert_allclose(np.fft.ifft2(x) * np.sqrt(30 * 20),
|
| 74 |
+
np.fft.ifft2(x, norm="ortho"), atol=1e-6)
|
| 75 |
+
assert_allclose(np.fft.ifft2(x) * (30. * 20.),
|
| 76 |
+
np.fft.ifft2(x, norm="forward"), atol=1e-6)
|
| 77 |
+
|
| 78 |
+
def test_fftn(self):
|
| 79 |
+
x = random((30, 20, 10)) + 1j*random((30, 20, 10))
|
| 80 |
+
assert_allclose(
|
| 81 |
+
np.fft.fft(np.fft.fft(np.fft.fft(x, axis=2), axis=1), axis=0),
|
| 82 |
+
np.fft.fftn(x), atol=1e-6)
|
| 83 |
+
assert_allclose(np.fft.fftn(x),
|
| 84 |
+
np.fft.fftn(x, norm="backward"), atol=1e-6)
|
| 85 |
+
assert_allclose(np.fft.fftn(x) / np.sqrt(30 * 20 * 10),
|
| 86 |
+
np.fft.fftn(x, norm="ortho"), atol=1e-6)
|
| 87 |
+
assert_allclose(np.fft.fftn(x) / (30. * 20. * 10.),
|
| 88 |
+
np.fft.fftn(x, norm="forward"), atol=1e-6)
|
| 89 |
+
|
| 90 |
+
def test_ifftn(self):
|
| 91 |
+
x = random((30, 20, 10)) + 1j*random((30, 20, 10))
|
| 92 |
+
assert_allclose(
|
| 93 |
+
np.fft.ifft(np.fft.ifft(np.fft.ifft(x, axis=2), axis=1), axis=0),
|
| 94 |
+
np.fft.ifftn(x), atol=1e-6)
|
| 95 |
+
assert_allclose(np.fft.ifftn(x),
|
| 96 |
+
np.fft.ifftn(x, norm="backward"), atol=1e-6)
|
| 97 |
+
assert_allclose(np.fft.ifftn(x) * np.sqrt(30 * 20 * 10),
|
| 98 |
+
np.fft.ifftn(x, norm="ortho"), atol=1e-6)
|
| 99 |
+
assert_allclose(np.fft.ifftn(x) * (30. * 20. * 10.),
|
| 100 |
+
np.fft.ifftn(x, norm="forward"), atol=1e-6)
|
| 101 |
+
|
| 102 |
+
def test_rfft(self):
|
| 103 |
+
x = random(30)
|
| 104 |
+
for n in [x.size, 2*x.size]:
|
| 105 |
+
for norm in [None, 'backward', 'ortho', 'forward']:
|
| 106 |
+
assert_allclose(
|
| 107 |
+
np.fft.fft(x, n=n, norm=norm)[:(n//2 + 1)],
|
| 108 |
+
np.fft.rfft(x, n=n, norm=norm), atol=1e-6)
|
| 109 |
+
assert_allclose(
|
| 110 |
+
np.fft.rfft(x, n=n),
|
| 111 |
+
np.fft.rfft(x, n=n, norm="backward"), atol=1e-6)
|
| 112 |
+
assert_allclose(
|
| 113 |
+
np.fft.rfft(x, n=n) / np.sqrt(n),
|
| 114 |
+
np.fft.rfft(x, n=n, norm="ortho"), atol=1e-6)
|
| 115 |
+
assert_allclose(
|
| 116 |
+
np.fft.rfft(x, n=n) / n,
|
| 117 |
+
np.fft.rfft(x, n=n, norm="forward"), atol=1e-6)
|
| 118 |
+
|
| 119 |
+
def test_irfft(self):
|
| 120 |
+
x = random(30)
|
| 121 |
+
assert_allclose(x, np.fft.irfft(np.fft.rfft(x)), atol=1e-6)
|
| 122 |
+
assert_allclose(x, np.fft.irfft(np.fft.rfft(x, norm="backward"),
|
| 123 |
+
norm="backward"), atol=1e-6)
|
| 124 |
+
assert_allclose(x, np.fft.irfft(np.fft.rfft(x, norm="ortho"),
|
| 125 |
+
norm="ortho"), atol=1e-6)
|
| 126 |
+
assert_allclose(x, np.fft.irfft(np.fft.rfft(x, norm="forward"),
|
| 127 |
+
norm="forward"), atol=1e-6)
|
| 128 |
+
|
| 129 |
+
def test_rfft2(self):
|
| 130 |
+
x = random((30, 20))
|
| 131 |
+
assert_allclose(np.fft.fft2(x)[:, :11], np.fft.rfft2(x), atol=1e-6)
|
| 132 |
+
assert_allclose(np.fft.rfft2(x),
|
| 133 |
+
np.fft.rfft2(x, norm="backward"), atol=1e-6)
|
| 134 |
+
assert_allclose(np.fft.rfft2(x) / np.sqrt(30 * 20),
|
| 135 |
+
np.fft.rfft2(x, norm="ortho"), atol=1e-6)
|
| 136 |
+
assert_allclose(np.fft.rfft2(x) / (30. * 20.),
|
| 137 |
+
np.fft.rfft2(x, norm="forward"), atol=1e-6)
|
| 138 |
+
|
| 139 |
+
def test_irfft2(self):
|
| 140 |
+
x = random((30, 20))
|
| 141 |
+
assert_allclose(x, np.fft.irfft2(np.fft.rfft2(x)), atol=1e-6)
|
| 142 |
+
assert_allclose(x, np.fft.irfft2(np.fft.rfft2(x, norm="backward"),
|
| 143 |
+
norm="backward"), atol=1e-6)
|
| 144 |
+
assert_allclose(x, np.fft.irfft2(np.fft.rfft2(x, norm="ortho"),
|
| 145 |
+
norm="ortho"), atol=1e-6)
|
| 146 |
+
assert_allclose(x, np.fft.irfft2(np.fft.rfft2(x, norm="forward"),
|
| 147 |
+
norm="forward"), atol=1e-6)
|
| 148 |
+
|
| 149 |
+
def test_rfftn(self):
|
| 150 |
+
x = random((30, 20, 10))
|
| 151 |
+
assert_allclose(np.fft.fftn(x)[:, :, :6], np.fft.rfftn(x), atol=1e-6)
|
| 152 |
+
assert_allclose(np.fft.rfftn(x),
|
| 153 |
+
np.fft.rfftn(x, norm="backward"), atol=1e-6)
|
| 154 |
+
assert_allclose(np.fft.rfftn(x) / np.sqrt(30 * 20 * 10),
|
| 155 |
+
np.fft.rfftn(x, norm="ortho"), atol=1e-6)
|
| 156 |
+
assert_allclose(np.fft.rfftn(x) / (30. * 20. * 10.),
|
| 157 |
+
np.fft.rfftn(x, norm="forward"), atol=1e-6)
|
| 158 |
+
|
| 159 |
+
def test_irfftn(self):
|
| 160 |
+
x = random((30, 20, 10))
|
| 161 |
+
assert_allclose(x, np.fft.irfftn(np.fft.rfftn(x)), atol=1e-6)
|
| 162 |
+
assert_allclose(x, np.fft.irfftn(np.fft.rfftn(x, norm="backward"),
|
| 163 |
+
norm="backward"), atol=1e-6)
|
| 164 |
+
assert_allclose(x, np.fft.irfftn(np.fft.rfftn(x, norm="ortho"),
|
| 165 |
+
norm="ortho"), atol=1e-6)
|
| 166 |
+
assert_allclose(x, np.fft.irfftn(np.fft.rfftn(x, norm="forward"),
|
| 167 |
+
norm="forward"), atol=1e-6)
|
| 168 |
+
|
| 169 |
+
def test_hfft(self):
|
| 170 |
+
x = random(14) + 1j*random(14)
|
| 171 |
+
x_herm = np.concatenate((random(1), x, random(1)))
|
| 172 |
+
x = np.concatenate((x_herm, x[::-1].conj()))
|
| 173 |
+
assert_allclose(np.fft.fft(x), np.fft.hfft(x_herm), atol=1e-6)
|
| 174 |
+
assert_allclose(np.fft.hfft(x_herm),
|
| 175 |
+
np.fft.hfft(x_herm, norm="backward"), atol=1e-6)
|
| 176 |
+
assert_allclose(np.fft.hfft(x_herm) / np.sqrt(30),
|
| 177 |
+
np.fft.hfft(x_herm, norm="ortho"), atol=1e-6)
|
| 178 |
+
assert_allclose(np.fft.hfft(x_herm) / 30.,
|
| 179 |
+
np.fft.hfft(x_herm, norm="forward"), atol=1e-6)
|
| 180 |
+
|
| 181 |
+
def test_ihfft(self):
|
| 182 |
+
x = random(14) + 1j*random(14)
|
| 183 |
+
x_herm = np.concatenate((random(1), x, random(1)))
|
| 184 |
+
x = np.concatenate((x_herm, x[::-1].conj()))
|
| 185 |
+
assert_allclose(x_herm, np.fft.ihfft(np.fft.hfft(x_herm)), atol=1e-6)
|
| 186 |
+
assert_allclose(x_herm, np.fft.ihfft(np.fft.hfft(x_herm,
|
| 187 |
+
norm="backward"), norm="backward"), atol=1e-6)
|
| 188 |
+
assert_allclose(x_herm, np.fft.ihfft(np.fft.hfft(x_herm,
|
| 189 |
+
norm="ortho"), norm="ortho"), atol=1e-6)
|
| 190 |
+
assert_allclose(x_herm, np.fft.ihfft(np.fft.hfft(x_herm,
|
| 191 |
+
norm="forward"), norm="forward"), atol=1e-6)
|
| 192 |
+
|
| 193 |
+
@pytest.mark.parametrize("op", [np.fft.fftn, np.fft.ifftn,
|
| 194 |
+
np.fft.rfftn, np.fft.irfftn])
|
| 195 |
+
def test_axes(self, op):
|
| 196 |
+
x = random((30, 20, 10))
|
| 197 |
+
axes = [(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)]
|
| 198 |
+
for a in axes:
|
| 199 |
+
op_tr = op(np.transpose(x, a))
|
| 200 |
+
tr_op = np.transpose(op(x, axes=a), a)
|
| 201 |
+
assert_allclose(op_tr, tr_op, atol=1e-6)
|
| 202 |
+
|
| 203 |
+
def test_all_1d_norm_preserving(self):
|
| 204 |
+
# verify that round-trip transforms are norm-preserving
|
| 205 |
+
x = random(30)
|
| 206 |
+
x_norm = np.linalg.norm(x)
|
| 207 |
+
n = x.size * 2
|
| 208 |
+
func_pairs = [(np.fft.fft, np.fft.ifft),
|
| 209 |
+
(np.fft.rfft, np.fft.irfft),
|
| 210 |
+
# hfft: order so the first function takes x.size samples
|
| 211 |
+
# (necessary for comparison to x_norm above)
|
| 212 |
+
(np.fft.ihfft, np.fft.hfft),
|
| 213 |
+
]
|
| 214 |
+
for forw, back in func_pairs:
|
| 215 |
+
for n in [x.size, 2*x.size]:
|
| 216 |
+
for norm in [None, 'backward', 'ortho', 'forward']:
|
| 217 |
+
tmp = forw(x, n=n, norm=norm)
|
| 218 |
+
tmp = back(tmp, n=n, norm=norm)
|
| 219 |
+
assert_allclose(x_norm,
|
| 220 |
+
np.linalg.norm(tmp), atol=1e-6)
|
| 221 |
+
|
| 222 |
+
@pytest.mark.parametrize("dtype", [np.half, np.single, np.double,
|
| 223 |
+
np.longdouble])
|
| 224 |
+
def test_dtypes(self, dtype):
|
| 225 |
+
# make sure that all input precisions are accepted and internally
|
| 226 |
+
# converted to 64bit
|
| 227 |
+
x = random(30).astype(dtype)
|
| 228 |
+
assert_allclose(np.fft.ifft(np.fft.fft(x)), x, atol=1e-6)
|
| 229 |
+
assert_allclose(np.fft.irfft(np.fft.rfft(x)), x, atol=1e-6)
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
@pytest.mark.parametrize(
|
| 233 |
+
"dtype",
|
| 234 |
+
[np.float32, np.float64, np.complex64, np.complex128])
|
| 235 |
+
@pytest.mark.parametrize("order", ["F", 'non-contiguous'])
|
| 236 |
+
@pytest.mark.parametrize(
|
| 237 |
+
"fft",
|
| 238 |
+
[np.fft.fft, np.fft.fft2, np.fft.fftn,
|
| 239 |
+
np.fft.ifft, np.fft.ifft2, np.fft.ifftn])
|
| 240 |
+
def test_fft_with_order(dtype, order, fft):
|
| 241 |
+
# Check that FFT/IFFT produces identical results for C, Fortran and
|
| 242 |
+
# non contiguous arrays
|
| 243 |
+
rng = np.random.RandomState(42)
|
| 244 |
+
X = rng.rand(8, 7, 13).astype(dtype, copy=False)
|
| 245 |
+
# See discussion in pull/14178
|
| 246 |
+
_tol = 8.0 * np.sqrt(np.log2(X.size)) * np.finfo(X.dtype).eps
|
| 247 |
+
if order == 'F':
|
| 248 |
+
Y = np.asfortranarray(X)
|
| 249 |
+
else:
|
| 250 |
+
# Make a non contiguous array
|
| 251 |
+
Y = X[::-1]
|
| 252 |
+
X = np.ascontiguousarray(X[::-1])
|
| 253 |
+
|
| 254 |
+
if fft.__name__.endswith('fft'):
|
| 255 |
+
for axis in range(3):
|
| 256 |
+
X_res = fft(X, axis=axis)
|
| 257 |
+
Y_res = fft(Y, axis=axis)
|
| 258 |
+
assert_allclose(X_res, Y_res, atol=_tol, rtol=_tol)
|
| 259 |
+
elif fft.__name__.endswith(('fft2', 'fftn')):
|
| 260 |
+
axes = [(0, 1), (1, 2), (0, 2)]
|
| 261 |
+
if fft.__name__.endswith('fftn'):
|
| 262 |
+
axes.extend([(0,), (1,), (2,), None])
|
| 263 |
+
for ax in axes:
|
| 264 |
+
X_res = fft(X, axes=ax)
|
| 265 |
+
Y_res = fft(Y, axes=ax)
|
| 266 |
+
assert_allclose(X_res, Y_res, atol=_tol, rtol=_tol)
|
| 267 |
+
else:
|
| 268 |
+
raise ValueError()
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
@pytest.mark.skipif(IS_WASM, reason="Cannot start thread")
|
| 272 |
+
class TestFFTThreadSafe:
|
| 273 |
+
threads = 16
|
| 274 |
+
input_shape = (800, 200)
|
| 275 |
+
|
| 276 |
+
def _test_mtsame(self, func, *args):
|
| 277 |
+
def worker(args, q):
|
| 278 |
+
q.put(func(*args))
|
| 279 |
+
|
| 280 |
+
q = queue.Queue()
|
| 281 |
+
expected = func(*args)
|
| 282 |
+
|
| 283 |
+
# Spin off a bunch of threads to call the same function simultaneously
|
| 284 |
+
t = [threading.Thread(target=worker, args=(args, q))
|
| 285 |
+
for i in range(self.threads)]
|
| 286 |
+
[x.start() for x in t]
|
| 287 |
+
|
| 288 |
+
[x.join() for x in t]
|
| 289 |
+
# Make sure all threads returned the correct value
|
| 290 |
+
for i in range(self.threads):
|
| 291 |
+
assert_array_equal(q.get(timeout=5), expected,
|
| 292 |
+
'Function returned wrong value in multithreaded context')
|
| 293 |
+
|
| 294 |
+
def test_fft(self):
|
| 295 |
+
a = np.ones(self.input_shape) * 1+0j
|
| 296 |
+
self._test_mtsame(np.fft.fft, a)
|
| 297 |
+
|
| 298 |
+
def test_ifft(self):
|
| 299 |
+
a = np.ones(self.input_shape) * 1+0j
|
| 300 |
+
self._test_mtsame(np.fft.ifft, a)
|
| 301 |
+
|
| 302 |
+
def test_rfft(self):
|
| 303 |
+
a = np.ones(self.input_shape)
|
| 304 |
+
self._test_mtsame(np.fft.rfft, a)
|
| 305 |
+
|
| 306 |
+
def test_irfft(self):
|
| 307 |
+
a = np.ones(self.input_shape) * 1+0j
|
| 308 |
+
self._test_mtsame(np.fft.irfft, a)
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (191 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/__pycache__/test_isfile.cpython-311.pyc
ADDED
|
Binary file (1.67 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/__pycache__/test_runtime.cpython-311.pyc
ADDED
|
Binary file (6.35 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/__pycache__/test_typing.cpython-311.pyc
ADDED
|
Binary file (13.8 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/misc/extended_precision.pyi
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
from numpy._typing import _80Bit, _96Bit, _128Bit, _256Bit
|
| 5 |
+
|
| 6 |
+
if sys.version_info >= (3, 11):
|
| 7 |
+
from typing import assert_type
|
| 8 |
+
else:
|
| 9 |
+
from typing_extensions import assert_type
|
| 10 |
+
|
| 11 |
+
assert_type(np.uint128(), np.unsignedinteger[_128Bit])
|
| 12 |
+
assert_type(np.uint256(), np.unsignedinteger[_256Bit])
|
| 13 |
+
|
| 14 |
+
assert_type(np.int128(), np.signedinteger[_128Bit])
|
| 15 |
+
assert_type(np.int256(), np.signedinteger[_256Bit])
|
| 16 |
+
|
| 17 |
+
assert_type(np.float80(), np.floating[_80Bit])
|
| 18 |
+
assert_type(np.float96(), np.floating[_96Bit])
|
| 19 |
+
assert_type(np.float128(), np.floating[_128Bit])
|
| 20 |
+
assert_type(np.float256(), np.floating[_256Bit])
|
| 21 |
+
|
| 22 |
+
assert_type(np.complex160(), np.complexfloating[_80Bit, _80Bit])
|
| 23 |
+
assert_type(np.complex192(), np.complexfloating[_96Bit, _96Bit])
|
| 24 |
+
assert_type(np.complex256(), np.complexfloating[_128Bit, _128Bit])
|
| 25 |
+
assert_type(np.complex512(), np.complexfloating[_256Bit, _256Bit])
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/reveal/arraysetops.pyi
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from typing import Any
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
import numpy.typing as npt
|
| 6 |
+
|
| 7 |
+
if sys.version_info >= (3, 11):
|
| 8 |
+
from typing import assert_type
|
| 9 |
+
else:
|
| 10 |
+
from typing_extensions import assert_type
|
| 11 |
+
|
| 12 |
+
AR_b: npt.NDArray[np.bool_]
|
| 13 |
+
AR_i8: npt.NDArray[np.int64]
|
| 14 |
+
AR_f8: npt.NDArray[np.float64]
|
| 15 |
+
AR_M: npt.NDArray[np.datetime64]
|
| 16 |
+
AR_O: npt.NDArray[np.object_]
|
| 17 |
+
|
| 18 |
+
AR_LIKE_f8: list[float]
|
| 19 |
+
|
| 20 |
+
assert_type(np.ediff1d(AR_b), npt.NDArray[np.int8])
|
| 21 |
+
assert_type(np.ediff1d(AR_i8, to_end=[1, 2, 3]), npt.NDArray[np.int64])
|
| 22 |
+
assert_type(np.ediff1d(AR_M), npt.NDArray[np.timedelta64])
|
| 23 |
+
assert_type(np.ediff1d(AR_O), npt.NDArray[np.object_])
|
| 24 |
+
assert_type(np.ediff1d(AR_LIKE_f8, to_begin=[1, 1.5]), npt.NDArray[Any])
|
| 25 |
+
|
| 26 |
+
assert_type(np.intersect1d(AR_i8, AR_i8), npt.NDArray[np.int64])
|
| 27 |
+
assert_type(np.intersect1d(AR_M, AR_M, assume_unique=True), npt.NDArray[np.datetime64])
|
| 28 |
+
assert_type(np.intersect1d(AR_f8, AR_i8), npt.NDArray[Any])
|
| 29 |
+
assert_type(np.intersect1d(AR_f8, AR_f8, return_indices=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp], npt.NDArray[np.intp]])
|
| 30 |
+
|
| 31 |
+
assert_type(np.setxor1d(AR_i8, AR_i8), npt.NDArray[np.int64])
|
| 32 |
+
assert_type(np.setxor1d(AR_M, AR_M, assume_unique=True), npt.NDArray[np.datetime64])
|
| 33 |
+
assert_type(np.setxor1d(AR_f8, AR_i8), npt.NDArray[Any])
|
| 34 |
+
|
| 35 |
+
assert_type(np.in1d(AR_i8, AR_i8), npt.NDArray[np.bool_])
|
| 36 |
+
assert_type(np.in1d(AR_M, AR_M, assume_unique=True), npt.NDArray[np.bool_])
|
| 37 |
+
assert_type(np.in1d(AR_f8, AR_i8), npt.NDArray[np.bool_])
|
| 38 |
+
assert_type(np.in1d(AR_f8, AR_LIKE_f8, invert=True), npt.NDArray[np.bool_])
|
| 39 |
+
|
| 40 |
+
assert_type(np.isin(AR_i8, AR_i8), npt.NDArray[np.bool_])
|
| 41 |
+
assert_type(np.isin(AR_M, AR_M, assume_unique=True), npt.NDArray[np.bool_])
|
| 42 |
+
assert_type(np.isin(AR_f8, AR_i8), npt.NDArray[np.bool_])
|
| 43 |
+
assert_type(np.isin(AR_f8, AR_LIKE_f8, invert=True), npt.NDArray[np.bool_])
|
| 44 |
+
|
| 45 |
+
assert_type(np.union1d(AR_i8, AR_i8), npt.NDArray[np.int64])
|
| 46 |
+
assert_type(np.union1d(AR_M, AR_M), npt.NDArray[np.datetime64])
|
| 47 |
+
assert_type(np.union1d(AR_f8, AR_i8), npt.NDArray[Any])
|
| 48 |
+
|
| 49 |
+
assert_type(np.setdiff1d(AR_i8, AR_i8), npt.NDArray[np.int64])
|
| 50 |
+
assert_type(np.setdiff1d(AR_M, AR_M, assume_unique=True), npt.NDArray[np.datetime64])
|
| 51 |
+
assert_type(np.setdiff1d(AR_f8, AR_i8), npt.NDArray[Any])
|
| 52 |
+
|
| 53 |
+
assert_type(np.unique(AR_f8), npt.NDArray[np.float64])
|
| 54 |
+
assert_type(np.unique(AR_LIKE_f8, axis=0), npt.NDArray[Any])
|
| 55 |
+
assert_type(np.unique(AR_f8, return_index=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp]])
|
| 56 |
+
assert_type(np.unique(AR_LIKE_f8, return_index=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp]])
|
| 57 |
+
assert_type(np.unique(AR_f8, return_inverse=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp]])
|
| 58 |
+
assert_type(np.unique(AR_LIKE_f8, return_inverse=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp]])
|
| 59 |
+
assert_type(np.unique(AR_f8, return_counts=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp]])
|
| 60 |
+
assert_type(np.unique(AR_LIKE_f8, return_counts=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp]])
|
| 61 |
+
assert_type(np.unique(AR_f8, return_index=True, return_inverse=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp], npt.NDArray[np.intp]])
|
| 62 |
+
assert_type(np.unique(AR_LIKE_f8, return_index=True, return_inverse=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp], npt.NDArray[np.intp]])
|
| 63 |
+
assert_type(np.unique(AR_f8, return_index=True, return_counts=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp], npt.NDArray[np.intp]])
|
| 64 |
+
assert_type(np.unique(AR_LIKE_f8, return_index=True, return_counts=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp], npt.NDArray[np.intp]])
|
| 65 |
+
assert_type(np.unique(AR_f8, return_inverse=True, return_counts=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp], npt.NDArray[np.intp]])
|
| 66 |
+
assert_type(np.unique(AR_LIKE_f8, return_inverse=True, return_counts=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp], npt.NDArray[np.intp]])
|
| 67 |
+
assert_type(np.unique(AR_f8, return_index=True, return_inverse=True, return_counts=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp], npt.NDArray[np.intp], npt.NDArray[np.intp]])
|
| 68 |
+
assert_type(np.unique(AR_LIKE_f8, return_index=True, return_inverse=True, return_counts=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp], npt.NDArray[np.intp], npt.NDArray[np.intp]])
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/reveal/arrayterator.pyi
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from typing import Any
|
| 3 |
+
from collections.abc import Generator
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
import numpy.typing as npt
|
| 7 |
+
|
| 8 |
+
if sys.version_info >= (3, 11):
|
| 9 |
+
from typing import assert_type
|
| 10 |
+
else:
|
| 11 |
+
from typing_extensions import assert_type
|
| 12 |
+
|
| 13 |
+
AR_i8: np.ndarray[Any, np.dtype[np.int64]]
|
| 14 |
+
ar_iter = np.lib.Arrayterator(AR_i8)
|
| 15 |
+
|
| 16 |
+
assert_type(ar_iter.var, npt.NDArray[np.int64])
|
| 17 |
+
assert_type(ar_iter.buf_size, None | int)
|
| 18 |
+
assert_type(ar_iter.start, list[int])
|
| 19 |
+
assert_type(ar_iter.stop, list[int])
|
| 20 |
+
assert_type(ar_iter.step, list[int])
|
| 21 |
+
assert_type(ar_iter.shape, tuple[int, ...])
|
| 22 |
+
assert_type(ar_iter.flat, Generator[np.int64, None, None])
|
| 23 |
+
|
| 24 |
+
assert_type(ar_iter.__array__(), npt.NDArray[np.int64])
|
| 25 |
+
|
| 26 |
+
for i in ar_iter:
|
| 27 |
+
assert_type(i, npt.NDArray[np.int64])
|
| 28 |
+
|
| 29 |
+
assert_type(ar_iter[0], np.lib.Arrayterator[Any, np.dtype[np.int64]])
|
| 30 |
+
assert_type(ar_iter[...], np.lib.Arrayterator[Any, np.dtype[np.int64]])
|
| 31 |
+
assert_type(ar_iter[:], np.lib.Arrayterator[Any, np.dtype[np.int64]])
|
| 32 |
+
assert_type(ar_iter[0, 0, 0], np.lib.Arrayterator[Any, np.dtype[np.int64]])
|
| 33 |
+
assert_type(ar_iter[..., 0, :], np.lib.Arrayterator[Any, np.dtype[np.int64]])
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/reveal/bitwise_ops.pyi
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from typing import Any
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
import numpy.typing as npt
|
| 6 |
+
from numpy._typing import _64Bit, _32Bit
|
| 7 |
+
|
| 8 |
+
if sys.version_info >= (3, 11):
|
| 9 |
+
from typing import assert_type
|
| 10 |
+
else:
|
| 11 |
+
from typing_extensions import assert_type
|
| 12 |
+
|
| 13 |
+
i8 = np.int64(1)
|
| 14 |
+
u8 = np.uint64(1)
|
| 15 |
+
|
| 16 |
+
i4 = np.int32(1)
|
| 17 |
+
u4 = np.uint32(1)
|
| 18 |
+
|
| 19 |
+
b_ = np.bool_(1)
|
| 20 |
+
|
| 21 |
+
b = bool(1)
|
| 22 |
+
i = int(1)
|
| 23 |
+
|
| 24 |
+
AR = np.array([0, 1, 2], dtype=np.int32)
|
| 25 |
+
AR.setflags(write=False)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
assert_type(i8 << i8, np.int64)
|
| 29 |
+
assert_type(i8 >> i8, np.int64)
|
| 30 |
+
assert_type(i8 | i8, np.int64)
|
| 31 |
+
assert_type(i8 ^ i8, np.int64)
|
| 32 |
+
assert_type(i8 & i8, np.int64)
|
| 33 |
+
|
| 34 |
+
assert_type(i8 << AR, npt.NDArray[np.signedinteger[Any]])
|
| 35 |
+
assert_type(i8 >> AR, npt.NDArray[np.signedinteger[Any]])
|
| 36 |
+
assert_type(i8 | AR, npt.NDArray[np.signedinteger[Any]])
|
| 37 |
+
assert_type(i8 ^ AR, npt.NDArray[np.signedinteger[Any]])
|
| 38 |
+
assert_type(i8 & AR, npt.NDArray[np.signedinteger[Any]])
|
| 39 |
+
|
| 40 |
+
assert_type(i4 << i4, np.int32)
|
| 41 |
+
assert_type(i4 >> i4, np.int32)
|
| 42 |
+
assert_type(i4 | i4, np.int32)
|
| 43 |
+
assert_type(i4 ^ i4, np.int32)
|
| 44 |
+
assert_type(i4 & i4, np.int32)
|
| 45 |
+
|
| 46 |
+
assert_type(i8 << i4, np.signedinteger[_32Bit | _64Bit])
|
| 47 |
+
assert_type(i8 >> i4, np.signedinteger[_32Bit | _64Bit])
|
| 48 |
+
assert_type(i8 | i4, np.signedinteger[_32Bit | _64Bit])
|
| 49 |
+
assert_type(i8 ^ i4, np.signedinteger[_32Bit | _64Bit])
|
| 50 |
+
assert_type(i8 & i4, np.signedinteger[_32Bit | _64Bit])
|
| 51 |
+
|
| 52 |
+
assert_type(i8 << b_, np.int64)
|
| 53 |
+
assert_type(i8 >> b_, np.int64)
|
| 54 |
+
assert_type(i8 | b_, np.int64)
|
| 55 |
+
assert_type(i8 ^ b_, np.int64)
|
| 56 |
+
assert_type(i8 & b_, np.int64)
|
| 57 |
+
|
| 58 |
+
assert_type(i8 << b, np.int64)
|
| 59 |
+
assert_type(i8 >> b, np.int64)
|
| 60 |
+
assert_type(i8 | b, np.int64)
|
| 61 |
+
assert_type(i8 ^ b, np.int64)
|
| 62 |
+
assert_type(i8 & b, np.int64)
|
| 63 |
+
|
| 64 |
+
assert_type(u8 << u8, np.uint64)
|
| 65 |
+
assert_type(u8 >> u8, np.uint64)
|
| 66 |
+
assert_type(u8 | u8, np.uint64)
|
| 67 |
+
assert_type(u8 ^ u8, np.uint64)
|
| 68 |
+
assert_type(u8 & u8, np.uint64)
|
| 69 |
+
|
| 70 |
+
assert_type(u8 << AR, npt.NDArray[np.signedinteger[Any]])
|
| 71 |
+
assert_type(u8 >> AR, npt.NDArray[np.signedinteger[Any]])
|
| 72 |
+
assert_type(u8 | AR, npt.NDArray[np.signedinteger[Any]])
|
| 73 |
+
assert_type(u8 ^ AR, npt.NDArray[np.signedinteger[Any]])
|
| 74 |
+
assert_type(u8 & AR, npt.NDArray[np.signedinteger[Any]])
|
| 75 |
+
|
| 76 |
+
assert_type(u4 << u4, np.uint32)
|
| 77 |
+
assert_type(u4 >> u4, np.uint32)
|
| 78 |
+
assert_type(u4 | u4, np.uint32)
|
| 79 |
+
assert_type(u4 ^ u4, np.uint32)
|
| 80 |
+
assert_type(u4 & u4, np.uint32)
|
| 81 |
+
|
| 82 |
+
assert_type(u4 << i4, np.signedinteger[Any])
|
| 83 |
+
assert_type(u4 >> i4, np.signedinteger[Any])
|
| 84 |
+
assert_type(u4 | i4, np.signedinteger[Any])
|
| 85 |
+
assert_type(u4 ^ i4, np.signedinteger[Any])
|
| 86 |
+
assert_type(u4 & i4, np.signedinteger[Any])
|
| 87 |
+
|
| 88 |
+
assert_type(u4 << i, np.signedinteger[Any])
|
| 89 |
+
assert_type(u4 >> i, np.signedinteger[Any])
|
| 90 |
+
assert_type(u4 | i, np.signedinteger[Any])
|
| 91 |
+
assert_type(u4 ^ i, np.signedinteger[Any])
|
| 92 |
+
assert_type(u4 & i, np.signedinteger[Any])
|
| 93 |
+
|
| 94 |
+
assert_type(u8 << b_, np.uint64)
|
| 95 |
+
assert_type(u8 >> b_, np.uint64)
|
| 96 |
+
assert_type(u8 | b_, np.uint64)
|
| 97 |
+
assert_type(u8 ^ b_, np.uint64)
|
| 98 |
+
assert_type(u8 & b_, np.uint64)
|
| 99 |
+
|
| 100 |
+
assert_type(u8 << b, np.uint64)
|
| 101 |
+
assert_type(u8 >> b, np.uint64)
|
| 102 |
+
assert_type(u8 | b, np.uint64)
|
| 103 |
+
assert_type(u8 ^ b, np.uint64)
|
| 104 |
+
assert_type(u8 & b, np.uint64)
|
| 105 |
+
|
| 106 |
+
assert_type(b_ << b_, np.int8)
|
| 107 |
+
assert_type(b_ >> b_, np.int8)
|
| 108 |
+
assert_type(b_ | b_, np.bool_)
|
| 109 |
+
assert_type(b_ ^ b_, np.bool_)
|
| 110 |
+
assert_type(b_ & b_, np.bool_)
|
| 111 |
+
|
| 112 |
+
assert_type(b_ << AR, npt.NDArray[np.signedinteger[Any]])
|
| 113 |
+
assert_type(b_ >> AR, npt.NDArray[np.signedinteger[Any]])
|
| 114 |
+
assert_type(b_ | AR, npt.NDArray[np.signedinteger[Any]])
|
| 115 |
+
assert_type(b_ ^ AR, npt.NDArray[np.signedinteger[Any]])
|
| 116 |
+
assert_type(b_ & AR, npt.NDArray[np.signedinteger[Any]])
|
| 117 |
+
|
| 118 |
+
assert_type(b_ << b, np.int8)
|
| 119 |
+
assert_type(b_ >> b, np.int8)
|
| 120 |
+
assert_type(b_ | b, np.bool_)
|
| 121 |
+
assert_type(b_ ^ b, np.bool_)
|
| 122 |
+
assert_type(b_ & b, np.bool_)
|
| 123 |
+
|
| 124 |
+
assert_type(b_ << i, np.int_)
|
| 125 |
+
assert_type(b_ >> i, np.int_)
|
| 126 |
+
assert_type(b_ | i, np.int_)
|
| 127 |
+
assert_type(b_ ^ i, np.int_)
|
| 128 |
+
assert_type(b_ & i, np.int_)
|
| 129 |
+
|
| 130 |
+
assert_type(~i8, np.int64)
|
| 131 |
+
assert_type(~i4, np.int32)
|
| 132 |
+
assert_type(~u8, np.uint64)
|
| 133 |
+
assert_type(~u4, np.uint32)
|
| 134 |
+
assert_type(~b_, np.bool_)
|
| 135 |
+
assert_type(~AR, npt.NDArray[np.int32])
|