Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +8 -0
- .venv/lib/python3.11/site-packages/numpy/core/__init__.py +180 -0
- .venv/lib/python3.11/site-packages/numpy/core/__init__.pyi +2 -0
- .venv/lib/python3.11/site-packages/numpy/core/__pycache__/arrayprint.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/core/_add_newdocs.py +0 -0
- .venv/lib/python3.11/site-packages/numpy/core/_add_newdocs_scalars.py +372 -0
- .venv/lib/python3.11/site-packages/numpy/core/_asarray.py +134 -0
- .venv/lib/python3.11/site-packages/numpy/core/_asarray.pyi +42 -0
- .venv/lib/python3.11/site-packages/numpy/core/_dtype.py +369 -0
- .venv/lib/python3.11/site-packages/numpy/core/_dtype_ctypes.py +117 -0
- .venv/lib/python3.11/site-packages/numpy/core/_exceptions.py +172 -0
- .venv/lib/python3.11/site-packages/numpy/core/_internal.pyi +30 -0
- .venv/lib/python3.11/site-packages/numpy/core/_machar.py +356 -0
- .venv/lib/python3.11/site-packages/numpy/core/_methods.py +234 -0
- .venv/lib/python3.11/site-packages/numpy/core/_operand_flag_tests.cpython-311-x86_64-linux-gnu.so +0 -0
- .venv/lib/python3.11/site-packages/numpy/core/_rational_tests.cpython-311-x86_64-linux-gnu.so +0 -0
- .venv/lib/python3.11/site-packages/numpy/core/_string_helpers.py +100 -0
- .venv/lib/python3.11/site-packages/numpy/core/_struct_ufunc_tests.cpython-311-x86_64-linux-gnu.so +0 -0
- .venv/lib/python3.11/site-packages/numpy/core/_type_aliases.py +245 -0
- .venv/lib/python3.11/site-packages/numpy/core/_ufunc_config.py +466 -0
- .venv/lib/python3.11/site-packages/numpy/core/_ufunc_config.pyi +37 -0
- .venv/lib/python3.11/site-packages/numpy/core/arrayprint.py +1725 -0
- .venv/lib/python3.11/site-packages/numpy/core/arrayprint.pyi +142 -0
- .venv/lib/python3.11/site-packages/numpy/core/defchararray.py +2914 -0
- .venv/lib/python3.11/site-packages/numpy/core/defchararray.pyi +421 -0
- .venv/lib/python3.11/site-packages/numpy/core/einsumfunc.py +1443 -0
- .venv/lib/python3.11/site-packages/numpy/core/einsumfunc.pyi +187 -0
- .venv/lib/python3.11/site-packages/numpy/core/fromnumeric.pyi +1060 -0
- .venv/lib/python3.11/site-packages/numpy/core/function_base.py +551 -0
- .venv/lib/python3.11/site-packages/numpy/core/function_base.pyi +187 -0
- .venv/lib/python3.11/site-packages/numpy/core/getlimits.py +735 -0
- .venv/lib/python3.11/site-packages/numpy/core/getlimits.pyi +6 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/__multiarray_api.c +314 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/__multiarray_api.h +1566 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/__ufunc_api.c +50 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/__ufunc_api.h +314 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/_dtype_api.h +408 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/_neighborhood_iterator_imp.h +90 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/_numpyconfig.h +32 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/arrayobject.h +12 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/arrayscalars.h +186 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/experimental_dtype_api.h +365 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/halffloat.h +70 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/ndarrayobject.h +251 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/ndarraytypes.h +1945 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/noprefix.h +211 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h +124 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/npy_3kcompat.h +595 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/npy_common.h +1086 -0
- .venv/lib/python3.11/site-packages/numpy/core/include/numpy/npy_cpu.h +129 -0
.gitattributes
CHANGED
|
@@ -361,3 +361,11 @@ tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cudnn/lib/
|
|
| 361 |
.venv/lib/python3.11/site-packages/numpy/random/_mt19937.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 362 |
.venv/lib/python3.11/site-packages/numpy/random/_generator.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 363 |
.venv/lib/python3.11/site-packages/numpy/random/bit_generator.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
.venv/lib/python3.11/site-packages/numpy/random/_mt19937.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 362 |
.venv/lib/python3.11/site-packages/numpy/random/_generator.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 363 |
.venv/lib/python3.11/site-packages/numpy/random/bit_generator.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 364 |
+
.venv/lib/python3.11/site-packages/numpy/random/_philox.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 365 |
+
.venv/lib/python3.11/site-packages/numpy/random/_bounded_integers.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 366 |
+
.venv/lib/python3.11/site-packages/numpy/random/_pcg64.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 367 |
+
.venv/lib/python3.11/site-packages/numpy/random/_common.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 368 |
+
.venv/lib/python3.11/site-packages/numpy/random/tests/__pycache__/test_generator_mt19937.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
| 369 |
+
.venv/lib/python3.11/site-packages/numpy/random/tests/__pycache__/test_random.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
| 370 |
+
.venv/lib/python3.11/site-packages/numpy/random/mtrand.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 371 |
+
.venv/lib/python3.11/site-packages/numpy/random/tests/__pycache__/test_randomstate.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
.venv/lib/python3.11/site-packages/numpy/core/__init__.py
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Contains the core of NumPy: ndarray, ufuncs, dtypes, etc.
|
| 3 |
+
|
| 4 |
+
Please note that this module is private. All functions and objects
|
| 5 |
+
are available in the main ``numpy`` namespace - use that instead.
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import warnings
|
| 11 |
+
|
| 12 |
+
from numpy.version import version as __version__
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# disables OpenBLAS affinity setting of the main thread that limits
|
| 16 |
+
# python threads or processes to one core
|
| 17 |
+
env_added = []
|
| 18 |
+
for envkey in ['OPENBLAS_MAIN_FREE', 'GOTOBLAS_MAIN_FREE']:
|
| 19 |
+
if envkey not in os.environ:
|
| 20 |
+
os.environ[envkey] = '1'
|
| 21 |
+
env_added.append(envkey)
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
from . import multiarray
|
| 25 |
+
except ImportError as exc:
|
| 26 |
+
import sys
|
| 27 |
+
msg = """
|
| 28 |
+
|
| 29 |
+
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
|
| 30 |
+
|
| 31 |
+
Importing the numpy C-extensions failed. This error can happen for
|
| 32 |
+
many reasons, often due to issues with your setup or how NumPy was
|
| 33 |
+
installed.
|
| 34 |
+
|
| 35 |
+
We have compiled some common reasons and troubleshooting tips at:
|
| 36 |
+
|
| 37 |
+
https://numpy.org/devdocs/user/troubleshooting-importerror.html
|
| 38 |
+
|
| 39 |
+
Please note and check the following:
|
| 40 |
+
|
| 41 |
+
* The Python version is: Python%d.%d from "%s"
|
| 42 |
+
* The NumPy version is: "%s"
|
| 43 |
+
|
| 44 |
+
and make sure that they are the versions you expect.
|
| 45 |
+
Please carefully study the documentation linked above for further help.
|
| 46 |
+
|
| 47 |
+
Original error was: %s
|
| 48 |
+
""" % (sys.version_info[0], sys.version_info[1], sys.executable,
|
| 49 |
+
__version__, exc)
|
| 50 |
+
raise ImportError(msg)
|
| 51 |
+
finally:
|
| 52 |
+
for envkey in env_added:
|
| 53 |
+
del os.environ[envkey]
|
| 54 |
+
del envkey
|
| 55 |
+
del env_added
|
| 56 |
+
del os
|
| 57 |
+
|
| 58 |
+
from . import umath
|
| 59 |
+
|
| 60 |
+
# Check that multiarray,umath are pure python modules wrapping
|
| 61 |
+
# _multiarray_umath and not either of the old c-extension modules
|
| 62 |
+
if not (hasattr(multiarray, '_multiarray_umath') and
|
| 63 |
+
hasattr(umath, '_multiarray_umath')):
|
| 64 |
+
import sys
|
| 65 |
+
path = sys.modules['numpy'].__path__
|
| 66 |
+
msg = ("Something is wrong with the numpy installation. "
|
| 67 |
+
"While importing we detected an older version of "
|
| 68 |
+
"numpy in {}. One method of fixing this is to repeatedly uninstall "
|
| 69 |
+
"numpy until none is found, then reinstall this version.")
|
| 70 |
+
raise ImportError(msg.format(path))
|
| 71 |
+
|
| 72 |
+
from . import numerictypes as nt
|
| 73 |
+
multiarray.set_typeDict(nt.sctypeDict)
|
| 74 |
+
from . import numeric
|
| 75 |
+
from .numeric import *
|
| 76 |
+
from . import fromnumeric
|
| 77 |
+
from .fromnumeric import *
|
| 78 |
+
from . import defchararray as char
|
| 79 |
+
from . import records
|
| 80 |
+
from . import records as rec
|
| 81 |
+
from .records import record, recarray, format_parser
|
| 82 |
+
# Note: module name memmap is overwritten by a class with same name
|
| 83 |
+
from .memmap import *
|
| 84 |
+
from .defchararray import chararray
|
| 85 |
+
from . import function_base
|
| 86 |
+
from .function_base import *
|
| 87 |
+
from . import _machar
|
| 88 |
+
from . import getlimits
|
| 89 |
+
from .getlimits import *
|
| 90 |
+
from . import shape_base
|
| 91 |
+
from .shape_base import *
|
| 92 |
+
from . import einsumfunc
|
| 93 |
+
from .einsumfunc import *
|
| 94 |
+
del nt
|
| 95 |
+
|
| 96 |
+
from .numeric import absolute as abs
|
| 97 |
+
|
| 98 |
+
# do this after everything else, to minimize the chance of this misleadingly
|
| 99 |
+
# appearing in an import-time traceback
|
| 100 |
+
from . import _add_newdocs
|
| 101 |
+
from . import _add_newdocs_scalars
|
| 102 |
+
# add these for module-freeze analysis (like PyInstaller)
|
| 103 |
+
from . import _dtype_ctypes
|
| 104 |
+
from . import _internal
|
| 105 |
+
from . import _dtype
|
| 106 |
+
from . import _methods
|
| 107 |
+
|
| 108 |
+
__all__ = ['char', 'rec', 'memmap']
|
| 109 |
+
__all__ += numeric.__all__
|
| 110 |
+
__all__ += ['record', 'recarray', 'format_parser']
|
| 111 |
+
__all__ += ['chararray']
|
| 112 |
+
__all__ += function_base.__all__
|
| 113 |
+
__all__ += getlimits.__all__
|
| 114 |
+
__all__ += shape_base.__all__
|
| 115 |
+
__all__ += einsumfunc.__all__
|
| 116 |
+
|
| 117 |
+
# We used to use `np.core._ufunc_reconstruct` to unpickle. This is unnecessary,
|
| 118 |
+
# but old pickles saved before 1.20 will be using it, and there is no reason
|
| 119 |
+
# to break loading them.
|
| 120 |
+
def _ufunc_reconstruct(module, name):
|
| 121 |
+
# The `fromlist` kwarg is required to ensure that `mod` points to the
|
| 122 |
+
# inner-most module rather than the parent package when module name is
|
| 123 |
+
# nested. This makes it possible to pickle non-toplevel ufuncs such as
|
| 124 |
+
# scipy.special.expit for instance.
|
| 125 |
+
mod = __import__(module, fromlist=[name])
|
| 126 |
+
return getattr(mod, name)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def _ufunc_reduce(func):
|
| 130 |
+
# Report the `__name__`. pickle will try to find the module. Note that
|
| 131 |
+
# pickle supports for this `__name__` to be a `__qualname__`. It may
|
| 132 |
+
# make sense to add a `__qualname__` to ufuncs, to allow this more
|
| 133 |
+
# explicitly (Numba has ufuncs as attributes).
|
| 134 |
+
# See also: https://github.com/dask/distributed/issues/3450
|
| 135 |
+
return func.__name__
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def _DType_reconstruct(scalar_type):
|
| 139 |
+
# This is a work-around to pickle type(np.dtype(np.float64)), etc.
|
| 140 |
+
# and it should eventually be replaced with a better solution, e.g. when
|
| 141 |
+
# DTypes become HeapTypes.
|
| 142 |
+
return type(dtype(scalar_type))
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def _DType_reduce(DType):
|
| 146 |
+
# As types/classes, most DTypes can simply be pickled by their name:
|
| 147 |
+
if not DType._legacy or DType.__module__ == "numpy.dtypes":
|
| 148 |
+
return DType.__name__
|
| 149 |
+
|
| 150 |
+
# However, user defined legacy dtypes (like rational) do not end up in
|
| 151 |
+
# `numpy.dtypes` as module and do not have a public class at all.
|
| 152 |
+
# For these, we pickle them by reconstructing them from the scalar type:
|
| 153 |
+
scalar_type = DType.type
|
| 154 |
+
return _DType_reconstruct, (scalar_type,)
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def __getattr__(name):
|
| 158 |
+
# Deprecated 2022-11-22, NumPy 1.25.
|
| 159 |
+
if name == "MachAr":
|
| 160 |
+
warnings.warn(
|
| 161 |
+
"The `np.core.MachAr` is considered private API (NumPy 1.24)",
|
| 162 |
+
DeprecationWarning, stacklevel=2,
|
| 163 |
+
)
|
| 164 |
+
return _machar.MachAr
|
| 165 |
+
raise AttributeError(f"Module {__name__!r} has no attribute {name!r}")
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
import copyreg
|
| 169 |
+
|
| 170 |
+
copyreg.pickle(ufunc, _ufunc_reduce)
|
| 171 |
+
copyreg.pickle(type(dtype), _DType_reduce, _DType_reconstruct)
|
| 172 |
+
|
| 173 |
+
# Unclutter namespace (must keep _*_reconstruct for unpickling)
|
| 174 |
+
del copyreg
|
| 175 |
+
del _ufunc_reduce
|
| 176 |
+
del _DType_reduce
|
| 177 |
+
|
| 178 |
+
from numpy._pytesttester import PytestTester
|
| 179 |
+
test = PytestTester(__name__)
|
| 180 |
+
del PytestTester
|
.venv/lib/python3.11/site-packages/numpy/core/__init__.pyi
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# NOTE: The `np.core` namespace is deliberately kept empty due to it
|
| 2 |
+
# being private (despite the lack of leading underscore)
|
.venv/lib/python3.11/site-packages/numpy/core/__pycache__/arrayprint.cpython-311.pyc
ADDED
|
Binary file (76.7 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/core/_add_newdocs.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
.venv/lib/python3.11/site-packages/numpy/core/_add_newdocs_scalars.py
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This file is separate from ``_add_newdocs.py`` so that it can be mocked out by
|
| 3 |
+
our sphinx ``conf.py`` during doc builds, where we want to avoid showing
|
| 4 |
+
platform-dependent information.
|
| 5 |
+
"""
|
| 6 |
+
import sys
|
| 7 |
+
import os
|
| 8 |
+
from numpy.core import dtype
|
| 9 |
+
from numpy.core import numerictypes as _numerictypes
|
| 10 |
+
from numpy.core.function_base import add_newdoc
|
| 11 |
+
|
| 12 |
+
##############################################################################
|
| 13 |
+
#
|
| 14 |
+
# Documentation for concrete scalar classes
|
| 15 |
+
#
|
| 16 |
+
##############################################################################
|
| 17 |
+
|
| 18 |
+
def numeric_type_aliases(aliases):
|
| 19 |
+
def type_aliases_gen():
|
| 20 |
+
for alias, doc in aliases:
|
| 21 |
+
try:
|
| 22 |
+
alias_type = getattr(_numerictypes, alias)
|
| 23 |
+
except AttributeError:
|
| 24 |
+
# The set of aliases that actually exist varies between platforms
|
| 25 |
+
pass
|
| 26 |
+
else:
|
| 27 |
+
yield (alias_type, alias, doc)
|
| 28 |
+
return list(type_aliases_gen())
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
possible_aliases = numeric_type_aliases([
|
| 32 |
+
('int8', '8-bit signed integer (``-128`` to ``127``)'),
|
| 33 |
+
('int16', '16-bit signed integer (``-32_768`` to ``32_767``)'),
|
| 34 |
+
('int32', '32-bit signed integer (``-2_147_483_648`` to ``2_147_483_647``)'),
|
| 35 |
+
('int64', '64-bit signed integer (``-9_223_372_036_854_775_808`` to ``9_223_372_036_854_775_807``)'),
|
| 36 |
+
('intp', 'Signed integer large enough to fit pointer, compatible with C ``intptr_t``'),
|
| 37 |
+
('uint8', '8-bit unsigned integer (``0`` to ``255``)'),
|
| 38 |
+
('uint16', '16-bit unsigned integer (``0`` to ``65_535``)'),
|
| 39 |
+
('uint32', '32-bit unsigned integer (``0`` to ``4_294_967_295``)'),
|
| 40 |
+
('uint64', '64-bit unsigned integer (``0`` to ``18_446_744_073_709_551_615``)'),
|
| 41 |
+
('uintp', 'Unsigned integer large enough to fit pointer, compatible with C ``uintptr_t``'),
|
| 42 |
+
('float16', '16-bit-precision floating-point number type: sign bit, 5 bits exponent, 10 bits mantissa'),
|
| 43 |
+
('float32', '32-bit-precision floating-point number type: sign bit, 8 bits exponent, 23 bits mantissa'),
|
| 44 |
+
('float64', '64-bit precision floating-point number type: sign bit, 11 bits exponent, 52 bits mantissa'),
|
| 45 |
+
('float96', '96-bit extended-precision floating-point number type'),
|
| 46 |
+
('float128', '128-bit extended-precision floating-point number type'),
|
| 47 |
+
('complex64', 'Complex number type composed of 2 32-bit-precision floating-point numbers'),
|
| 48 |
+
('complex128', 'Complex number type composed of 2 64-bit-precision floating-point numbers'),
|
| 49 |
+
('complex192', 'Complex number type composed of 2 96-bit extended-precision floating-point numbers'),
|
| 50 |
+
('complex256', 'Complex number type composed of 2 128-bit extended-precision floating-point numbers'),
|
| 51 |
+
])
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _get_platform_and_machine():
|
| 55 |
+
try:
|
| 56 |
+
system, _, _, _, machine = os.uname()
|
| 57 |
+
except AttributeError:
|
| 58 |
+
system = sys.platform
|
| 59 |
+
if system == 'win32':
|
| 60 |
+
machine = os.environ.get('PROCESSOR_ARCHITEW6432', '') \
|
| 61 |
+
or os.environ.get('PROCESSOR_ARCHITECTURE', '')
|
| 62 |
+
else:
|
| 63 |
+
machine = 'unknown'
|
| 64 |
+
return system, machine
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
_system, _machine = _get_platform_and_machine()
|
| 68 |
+
_doc_alias_string = f":Alias on this platform ({_system} {_machine}):"
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def add_newdoc_for_scalar_type(obj, fixed_aliases, doc):
|
| 72 |
+
# note: `:field: value` is rST syntax which renders as field lists.
|
| 73 |
+
o = getattr(_numerictypes, obj)
|
| 74 |
+
|
| 75 |
+
character_code = dtype(o).char
|
| 76 |
+
canonical_name_doc = "" if obj == o.__name__ else \
|
| 77 |
+
f":Canonical name: `numpy.{obj}`\n "
|
| 78 |
+
if fixed_aliases:
|
| 79 |
+
alias_doc = ''.join(f":Alias: `numpy.{alias}`\n "
|
| 80 |
+
for alias in fixed_aliases)
|
| 81 |
+
else:
|
| 82 |
+
alias_doc = ''
|
| 83 |
+
alias_doc += ''.join(f"{_doc_alias_string} `numpy.{alias}`: {doc}.\n "
|
| 84 |
+
for (alias_type, alias, doc) in possible_aliases if alias_type is o)
|
| 85 |
+
|
| 86 |
+
docstring = f"""
|
| 87 |
+
{doc.strip()}
|
| 88 |
+
|
| 89 |
+
:Character code: ``'{character_code}'``
|
| 90 |
+
{canonical_name_doc}{alias_doc}
|
| 91 |
+
"""
|
| 92 |
+
|
| 93 |
+
add_newdoc('numpy.core.numerictypes', obj, docstring)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
add_newdoc_for_scalar_type('bool_', [],
|
| 97 |
+
"""
|
| 98 |
+
Boolean type (True or False), stored as a byte.
|
| 99 |
+
|
| 100 |
+
.. warning::
|
| 101 |
+
|
| 102 |
+
The :class:`bool_` type is not a subclass of the :class:`int_` type
|
| 103 |
+
(the :class:`bool_` is not even a number type). This is different
|
| 104 |
+
than Python's default implementation of :class:`bool` as a
|
| 105 |
+
sub-class of :class:`int`.
|
| 106 |
+
""")
|
| 107 |
+
|
| 108 |
+
add_newdoc_for_scalar_type('byte', [],
|
| 109 |
+
"""
|
| 110 |
+
Signed integer type, compatible with C ``char``.
|
| 111 |
+
""")
|
| 112 |
+
|
| 113 |
+
add_newdoc_for_scalar_type('short', [],
|
| 114 |
+
"""
|
| 115 |
+
Signed integer type, compatible with C ``short``.
|
| 116 |
+
""")
|
| 117 |
+
|
| 118 |
+
add_newdoc_for_scalar_type('intc', [],
|
| 119 |
+
"""
|
| 120 |
+
Signed integer type, compatible with C ``int``.
|
| 121 |
+
""")
|
| 122 |
+
|
| 123 |
+
add_newdoc_for_scalar_type('int_', [],
|
| 124 |
+
"""
|
| 125 |
+
Signed integer type, compatible with Python `int` and C ``long``.
|
| 126 |
+
""")
|
| 127 |
+
|
| 128 |
+
add_newdoc_for_scalar_type('longlong', [],
|
| 129 |
+
"""
|
| 130 |
+
Signed integer type, compatible with C ``long long``.
|
| 131 |
+
""")
|
| 132 |
+
|
| 133 |
+
add_newdoc_for_scalar_type('ubyte', [],
|
| 134 |
+
"""
|
| 135 |
+
Unsigned integer type, compatible with C ``unsigned char``.
|
| 136 |
+
""")
|
| 137 |
+
|
| 138 |
+
add_newdoc_for_scalar_type('ushort', [],
|
| 139 |
+
"""
|
| 140 |
+
Unsigned integer type, compatible with C ``unsigned short``.
|
| 141 |
+
""")
|
| 142 |
+
|
| 143 |
+
add_newdoc_for_scalar_type('uintc', [],
|
| 144 |
+
"""
|
| 145 |
+
Unsigned integer type, compatible with C ``unsigned int``.
|
| 146 |
+
""")
|
| 147 |
+
|
| 148 |
+
add_newdoc_for_scalar_type('uint', [],
|
| 149 |
+
"""
|
| 150 |
+
Unsigned integer type, compatible with C ``unsigned long``.
|
| 151 |
+
""")
|
| 152 |
+
|
| 153 |
+
add_newdoc_for_scalar_type('ulonglong', [],
|
| 154 |
+
"""
|
| 155 |
+
Signed integer type, compatible with C ``unsigned long long``.
|
| 156 |
+
""")
|
| 157 |
+
|
| 158 |
+
add_newdoc_for_scalar_type('half', [],
|
| 159 |
+
"""
|
| 160 |
+
Half-precision floating-point number type.
|
| 161 |
+
""")
|
| 162 |
+
|
| 163 |
+
add_newdoc_for_scalar_type('single', [],
|
| 164 |
+
"""
|
| 165 |
+
Single-precision floating-point number type, compatible with C ``float``.
|
| 166 |
+
""")
|
| 167 |
+
|
| 168 |
+
add_newdoc_for_scalar_type('double', ['float_'],
|
| 169 |
+
"""
|
| 170 |
+
Double-precision floating-point number type, compatible with Python `float`
|
| 171 |
+
and C ``double``.
|
| 172 |
+
""")
|
| 173 |
+
|
| 174 |
+
add_newdoc_for_scalar_type('longdouble', ['longfloat'],
|
| 175 |
+
"""
|
| 176 |
+
Extended-precision floating-point number type, compatible with C
|
| 177 |
+
``long double`` but not necessarily with IEEE 754 quadruple-precision.
|
| 178 |
+
""")
|
| 179 |
+
|
| 180 |
+
add_newdoc_for_scalar_type('csingle', ['singlecomplex'],
|
| 181 |
+
"""
|
| 182 |
+
Complex number type composed of two single-precision floating-point
|
| 183 |
+
numbers.
|
| 184 |
+
""")
|
| 185 |
+
|
| 186 |
+
add_newdoc_for_scalar_type('cdouble', ['cfloat', 'complex_'],
|
| 187 |
+
"""
|
| 188 |
+
Complex number type composed of two double-precision floating-point
|
| 189 |
+
numbers, compatible with Python `complex`.
|
| 190 |
+
""")
|
| 191 |
+
|
| 192 |
+
add_newdoc_for_scalar_type('clongdouble', ['clongfloat', 'longcomplex'],
|
| 193 |
+
"""
|
| 194 |
+
Complex number type composed of two extended-precision floating-point
|
| 195 |
+
numbers.
|
| 196 |
+
""")
|
| 197 |
+
|
| 198 |
+
add_newdoc_for_scalar_type('object_', [],
|
| 199 |
+
"""
|
| 200 |
+
Any Python object.
|
| 201 |
+
""")
|
| 202 |
+
|
| 203 |
+
add_newdoc_for_scalar_type('str_', ['unicode_'],
|
| 204 |
+
r"""
|
| 205 |
+
A unicode string.
|
| 206 |
+
|
| 207 |
+
This type strips trailing null codepoints.
|
| 208 |
+
|
| 209 |
+
>>> s = np.str_("abc\x00")
|
| 210 |
+
>>> s
|
| 211 |
+
'abc'
|
| 212 |
+
|
| 213 |
+
Unlike the builtin `str`, this supports the :ref:`python:bufferobjects`, exposing its
|
| 214 |
+
contents as UCS4:
|
| 215 |
+
|
| 216 |
+
>>> m = memoryview(np.str_("abc"))
|
| 217 |
+
>>> m.format
|
| 218 |
+
'3w'
|
| 219 |
+
>>> m.tobytes()
|
| 220 |
+
b'a\x00\x00\x00b\x00\x00\x00c\x00\x00\x00'
|
| 221 |
+
""")
|
| 222 |
+
|
| 223 |
+
add_newdoc_for_scalar_type('bytes_', ['string_'],
|
| 224 |
+
r"""
|
| 225 |
+
A byte string.
|
| 226 |
+
|
| 227 |
+
When used in arrays, this type strips trailing null bytes.
|
| 228 |
+
""")
|
| 229 |
+
|
| 230 |
+
add_newdoc_for_scalar_type('void', [],
|
| 231 |
+
r"""
|
| 232 |
+
np.void(length_or_data, /, dtype=None)
|
| 233 |
+
|
| 234 |
+
Create a new structured or unstructured void scalar.
|
| 235 |
+
|
| 236 |
+
Parameters
|
| 237 |
+
----------
|
| 238 |
+
length_or_data : int, array-like, bytes-like, object
|
| 239 |
+
One of multiple meanings (see notes). The length or
|
| 240 |
+
bytes data of an unstructured void. Or alternatively,
|
| 241 |
+
the data to be stored in the new scalar when `dtype`
|
| 242 |
+
is provided.
|
| 243 |
+
This can be an array-like, in which case an array may
|
| 244 |
+
be returned.
|
| 245 |
+
dtype : dtype, optional
|
| 246 |
+
If provided the dtype of the new scalar. This dtype must
|
| 247 |
+
be "void" dtype (i.e. a structured or unstructured void,
|
| 248 |
+
see also :ref:`defining-structured-types`).
|
| 249 |
+
|
| 250 |
+
..versionadded:: 1.24
|
| 251 |
+
|
| 252 |
+
Notes
|
| 253 |
+
-----
|
| 254 |
+
For historical reasons and because void scalars can represent both
|
| 255 |
+
arbitrary byte data and structured dtypes, the void constructor
|
| 256 |
+
has three calling conventions:
|
| 257 |
+
|
| 258 |
+
1. ``np.void(5)`` creates a ``dtype="V5"`` scalar filled with five
|
| 259 |
+
``\0`` bytes. The 5 can be a Python or NumPy integer.
|
| 260 |
+
2. ``np.void(b"bytes-like")`` creates a void scalar from the byte string.
|
| 261 |
+
The dtype itemsize will match the byte string length, here ``"V10"``.
|
| 262 |
+
3. When a ``dtype=`` is passed the call is roughly the same as an
|
| 263 |
+
array creation. However, a void scalar rather than array is returned.
|
| 264 |
+
|
| 265 |
+
Please see the examples which show all three different conventions.
|
| 266 |
+
|
| 267 |
+
Examples
|
| 268 |
+
--------
|
| 269 |
+
>>> np.void(5)
|
| 270 |
+
void(b'\x00\x00\x00\x00\x00')
|
| 271 |
+
>>> np.void(b'abcd')
|
| 272 |
+
void(b'\x61\x62\x63\x64')
|
| 273 |
+
>>> np.void((5, 3.2, "eggs"), dtype="i,d,S5")
|
| 274 |
+
(5, 3.2, b'eggs') # looks like a tuple, but is `np.void`
|
| 275 |
+
>>> np.void(3, dtype=[('x', np.int8), ('y', np.int8)])
|
| 276 |
+
(3, 3) # looks like a tuple, but is `np.void`
|
| 277 |
+
|
| 278 |
+
""")
|
| 279 |
+
|
| 280 |
+
add_newdoc_for_scalar_type('datetime64', [],
|
| 281 |
+
"""
|
| 282 |
+
If created from a 64-bit integer, it represents an offset from
|
| 283 |
+
``1970-01-01T00:00:00``.
|
| 284 |
+
If created from string, the string can be in ISO 8601 date
|
| 285 |
+
or datetime format.
|
| 286 |
+
|
| 287 |
+
>>> np.datetime64(10, 'Y')
|
| 288 |
+
numpy.datetime64('1980')
|
| 289 |
+
>>> np.datetime64('1980', 'Y')
|
| 290 |
+
numpy.datetime64('1980')
|
| 291 |
+
>>> np.datetime64(10, 'D')
|
| 292 |
+
numpy.datetime64('1970-01-11')
|
| 293 |
+
|
| 294 |
+
See :ref:`arrays.datetime` for more information.
|
| 295 |
+
""")
|
| 296 |
+
|
| 297 |
+
add_newdoc_for_scalar_type('timedelta64', [],
|
| 298 |
+
"""
|
| 299 |
+
A timedelta stored as a 64-bit integer.
|
| 300 |
+
|
| 301 |
+
See :ref:`arrays.datetime` for more information.
|
| 302 |
+
""")
|
| 303 |
+
|
| 304 |
+
add_newdoc('numpy.core.numerictypes', "integer", ('is_integer',
|
| 305 |
+
"""
|
| 306 |
+
integer.is_integer() -> bool
|
| 307 |
+
|
| 308 |
+
Return ``True`` if the number is finite with integral value.
|
| 309 |
+
|
| 310 |
+
.. versionadded:: 1.22
|
| 311 |
+
|
| 312 |
+
Examples
|
| 313 |
+
--------
|
| 314 |
+
>>> np.int64(-2).is_integer()
|
| 315 |
+
True
|
| 316 |
+
>>> np.uint32(5).is_integer()
|
| 317 |
+
True
|
| 318 |
+
"""))
|
| 319 |
+
|
| 320 |
+
# TODO: work out how to put this on the base class, np.floating
|
| 321 |
+
for float_name in ('half', 'single', 'double', 'longdouble'):
|
| 322 |
+
add_newdoc('numpy.core.numerictypes', float_name, ('as_integer_ratio',
|
| 323 |
+
"""
|
| 324 |
+
{ftype}.as_integer_ratio() -> (int, int)
|
| 325 |
+
|
| 326 |
+
Return a pair of integers, whose ratio is exactly equal to the original
|
| 327 |
+
floating point number, and with a positive denominator.
|
| 328 |
+
Raise `OverflowError` on infinities and a `ValueError` on NaNs.
|
| 329 |
+
|
| 330 |
+
>>> np.{ftype}(10.0).as_integer_ratio()
|
| 331 |
+
(10, 1)
|
| 332 |
+
>>> np.{ftype}(0.0).as_integer_ratio()
|
| 333 |
+
(0, 1)
|
| 334 |
+
>>> np.{ftype}(-.25).as_integer_ratio()
|
| 335 |
+
(-1, 4)
|
| 336 |
+
""".format(ftype=float_name)))
|
| 337 |
+
|
| 338 |
+
add_newdoc('numpy.core.numerictypes', float_name, ('is_integer',
|
| 339 |
+
f"""
|
| 340 |
+
{float_name}.is_integer() -> bool
|
| 341 |
+
|
| 342 |
+
Return ``True`` if the floating point number is finite with integral
|
| 343 |
+
value, and ``False`` otherwise.
|
| 344 |
+
|
| 345 |
+
.. versionadded:: 1.22
|
| 346 |
+
|
| 347 |
+
Examples
|
| 348 |
+
--------
|
| 349 |
+
>>> np.{float_name}(-2.0).is_integer()
|
| 350 |
+
True
|
| 351 |
+
>>> np.{float_name}(3.2).is_integer()
|
| 352 |
+
False
|
| 353 |
+
"""))
|
| 354 |
+
|
| 355 |
+
for int_name in ('int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32',
|
| 356 |
+
'int64', 'uint64', 'int64', 'uint64', 'int64', 'uint64'):
|
| 357 |
+
# Add negative examples for signed cases by checking typecode
|
| 358 |
+
add_newdoc('numpy.core.numerictypes', int_name, ('bit_count',
|
| 359 |
+
f"""
|
| 360 |
+
{int_name}.bit_count() -> int
|
| 361 |
+
|
| 362 |
+
Computes the number of 1-bits in the absolute value of the input.
|
| 363 |
+
Analogous to the builtin `int.bit_count` or ``popcount`` in C++.
|
| 364 |
+
|
| 365 |
+
Examples
|
| 366 |
+
--------
|
| 367 |
+
>>> np.{int_name}(127).bit_count()
|
| 368 |
+
7""" +
|
| 369 |
+
(f"""
|
| 370 |
+
>>> np.{int_name}(-127).bit_count()
|
| 371 |
+
7
|
| 372 |
+
""" if dtype(int_name).char.islower() else "")))
|
.venv/lib/python3.11/site-packages/numpy/core/_asarray.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Functions in the ``as*array`` family that promote array-likes into arrays.
|
| 3 |
+
|
| 4 |
+
`require` fits this category despite its name not matching this pattern.
|
| 5 |
+
"""
|
| 6 |
+
from .overrides import (
|
| 7 |
+
array_function_dispatch,
|
| 8 |
+
set_array_function_like_doc,
|
| 9 |
+
set_module,
|
| 10 |
+
)
|
| 11 |
+
from .multiarray import array, asanyarray
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
__all__ = ["require"]
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
POSSIBLE_FLAGS = {
|
| 18 |
+
'C': 'C', 'C_CONTIGUOUS': 'C', 'CONTIGUOUS': 'C',
|
| 19 |
+
'F': 'F', 'F_CONTIGUOUS': 'F', 'FORTRAN': 'F',
|
| 20 |
+
'A': 'A', 'ALIGNED': 'A',
|
| 21 |
+
'W': 'W', 'WRITEABLE': 'W',
|
| 22 |
+
'O': 'O', 'OWNDATA': 'O',
|
| 23 |
+
'E': 'E', 'ENSUREARRAY': 'E'
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@set_array_function_like_doc
|
| 28 |
+
@set_module('numpy')
|
| 29 |
+
def require(a, dtype=None, requirements=None, *, like=None):
|
| 30 |
+
"""
|
| 31 |
+
Return an ndarray of the provided type that satisfies requirements.
|
| 32 |
+
|
| 33 |
+
This function is useful to be sure that an array with the correct flags
|
| 34 |
+
is returned for passing to compiled code (perhaps through ctypes).
|
| 35 |
+
|
| 36 |
+
Parameters
|
| 37 |
+
----------
|
| 38 |
+
a : array_like
|
| 39 |
+
The object to be converted to a type-and-requirement-satisfying array.
|
| 40 |
+
dtype : data-type
|
| 41 |
+
The required data-type. If None preserve the current dtype. If your
|
| 42 |
+
application requires the data to be in native byteorder, include
|
| 43 |
+
a byteorder specification as a part of the dtype specification.
|
| 44 |
+
requirements : str or sequence of str
|
| 45 |
+
The requirements list can be any of the following
|
| 46 |
+
|
| 47 |
+
* 'F_CONTIGUOUS' ('F') - ensure a Fortran-contiguous array
|
| 48 |
+
* 'C_CONTIGUOUS' ('C') - ensure a C-contiguous array
|
| 49 |
+
* 'ALIGNED' ('A') - ensure a data-type aligned array
|
| 50 |
+
* 'WRITEABLE' ('W') - ensure a writable array
|
| 51 |
+
* 'OWNDATA' ('O') - ensure an array that owns its own data
|
| 52 |
+
* 'ENSUREARRAY', ('E') - ensure a base array, instead of a subclass
|
| 53 |
+
${ARRAY_FUNCTION_LIKE}
|
| 54 |
+
|
| 55 |
+
.. versionadded:: 1.20.0
|
| 56 |
+
|
| 57 |
+
Returns
|
| 58 |
+
-------
|
| 59 |
+
out : ndarray
|
| 60 |
+
Array with specified requirements and type if given.
|
| 61 |
+
|
| 62 |
+
See Also
|
| 63 |
+
--------
|
| 64 |
+
asarray : Convert input to an ndarray.
|
| 65 |
+
asanyarray : Convert to an ndarray, but pass through ndarray subclasses.
|
| 66 |
+
ascontiguousarray : Convert input to a contiguous array.
|
| 67 |
+
asfortranarray : Convert input to an ndarray with column-major
|
| 68 |
+
memory order.
|
| 69 |
+
ndarray.flags : Information about the memory layout of the array.
|
| 70 |
+
|
| 71 |
+
Notes
|
| 72 |
+
-----
|
| 73 |
+
The returned array will be guaranteed to have the listed requirements
|
| 74 |
+
by making a copy if needed.
|
| 75 |
+
|
| 76 |
+
Examples
|
| 77 |
+
--------
|
| 78 |
+
>>> x = np.arange(6).reshape(2,3)
|
| 79 |
+
>>> x.flags
|
| 80 |
+
C_CONTIGUOUS : True
|
| 81 |
+
F_CONTIGUOUS : False
|
| 82 |
+
OWNDATA : False
|
| 83 |
+
WRITEABLE : True
|
| 84 |
+
ALIGNED : True
|
| 85 |
+
WRITEBACKIFCOPY : False
|
| 86 |
+
|
| 87 |
+
>>> y = np.require(x, dtype=np.float32, requirements=['A', 'O', 'W', 'F'])
|
| 88 |
+
>>> y.flags
|
| 89 |
+
C_CONTIGUOUS : False
|
| 90 |
+
F_CONTIGUOUS : True
|
| 91 |
+
OWNDATA : True
|
| 92 |
+
WRITEABLE : True
|
| 93 |
+
ALIGNED : True
|
| 94 |
+
WRITEBACKIFCOPY : False
|
| 95 |
+
|
| 96 |
+
"""
|
| 97 |
+
if like is not None:
|
| 98 |
+
return _require_with_like(
|
| 99 |
+
like,
|
| 100 |
+
a,
|
| 101 |
+
dtype=dtype,
|
| 102 |
+
requirements=requirements,
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
if not requirements:
|
| 106 |
+
return asanyarray(a, dtype=dtype)
|
| 107 |
+
|
| 108 |
+
requirements = {POSSIBLE_FLAGS[x.upper()] for x in requirements}
|
| 109 |
+
|
| 110 |
+
if 'E' in requirements:
|
| 111 |
+
requirements.remove('E')
|
| 112 |
+
subok = False
|
| 113 |
+
else:
|
| 114 |
+
subok = True
|
| 115 |
+
|
| 116 |
+
order = 'A'
|
| 117 |
+
if requirements >= {'C', 'F'}:
|
| 118 |
+
raise ValueError('Cannot specify both "C" and "F" order')
|
| 119 |
+
elif 'F' in requirements:
|
| 120 |
+
order = 'F'
|
| 121 |
+
requirements.remove('F')
|
| 122 |
+
elif 'C' in requirements:
|
| 123 |
+
order = 'C'
|
| 124 |
+
requirements.remove('C')
|
| 125 |
+
|
| 126 |
+
arr = array(a, dtype=dtype, order=order, copy=False, subok=subok)
|
| 127 |
+
|
| 128 |
+
for prop in requirements:
|
| 129 |
+
if not arr.flags[prop]:
|
| 130 |
+
return arr.copy(order)
|
| 131 |
+
return arr
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
_require_with_like = array_function_dispatch()(require)
|
.venv/lib/python3.11/site-packages/numpy/core/_asarray.pyi
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Iterable
|
| 2 |
+
from typing import Any, TypeVar, Union, overload, Literal
|
| 3 |
+
|
| 4 |
+
from numpy import ndarray
|
| 5 |
+
from numpy._typing import DTypeLike, _SupportsArrayFunc
|
| 6 |
+
|
| 7 |
+
_ArrayType = TypeVar("_ArrayType", bound=ndarray[Any, Any])
|
| 8 |
+
|
| 9 |
+
_Requirements = Literal[
|
| 10 |
+
"C", "C_CONTIGUOUS", "CONTIGUOUS",
|
| 11 |
+
"F", "F_CONTIGUOUS", "FORTRAN",
|
| 12 |
+
"A", "ALIGNED",
|
| 13 |
+
"W", "WRITEABLE",
|
| 14 |
+
"O", "OWNDATA"
|
| 15 |
+
]
|
| 16 |
+
_E = Literal["E", "ENSUREARRAY"]
|
| 17 |
+
_RequirementsWithE = Union[_Requirements, _E]
|
| 18 |
+
|
| 19 |
+
@overload
|
| 20 |
+
def require(
|
| 21 |
+
a: _ArrayType,
|
| 22 |
+
dtype: None = ...,
|
| 23 |
+
requirements: None | _Requirements | Iterable[_Requirements] = ...,
|
| 24 |
+
*,
|
| 25 |
+
like: _SupportsArrayFunc = ...
|
| 26 |
+
) -> _ArrayType: ...
|
| 27 |
+
@overload
|
| 28 |
+
def require(
|
| 29 |
+
a: object,
|
| 30 |
+
dtype: DTypeLike = ...,
|
| 31 |
+
requirements: _E | Iterable[_RequirementsWithE] = ...,
|
| 32 |
+
*,
|
| 33 |
+
like: _SupportsArrayFunc = ...
|
| 34 |
+
) -> ndarray[Any, Any]: ...
|
| 35 |
+
@overload
|
| 36 |
+
def require(
|
| 37 |
+
a: object,
|
| 38 |
+
dtype: DTypeLike = ...,
|
| 39 |
+
requirements: None | _Requirements | Iterable[_Requirements] = ...,
|
| 40 |
+
*,
|
| 41 |
+
like: _SupportsArrayFunc = ...
|
| 42 |
+
) -> ndarray[Any, Any]: ...
|
.venv/lib/python3.11/site-packages/numpy/core/_dtype.py
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
A place for code to be called from the implementation of np.dtype
|
| 3 |
+
|
| 4 |
+
String handling is much easier to do correctly in python.
|
| 5 |
+
"""
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
_kind_to_stem = {
|
| 10 |
+
'u': 'uint',
|
| 11 |
+
'i': 'int',
|
| 12 |
+
'c': 'complex',
|
| 13 |
+
'f': 'float',
|
| 14 |
+
'b': 'bool',
|
| 15 |
+
'V': 'void',
|
| 16 |
+
'O': 'object',
|
| 17 |
+
'M': 'datetime',
|
| 18 |
+
'm': 'timedelta',
|
| 19 |
+
'S': 'bytes',
|
| 20 |
+
'U': 'str',
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _kind_name(dtype):
|
| 25 |
+
try:
|
| 26 |
+
return _kind_to_stem[dtype.kind]
|
| 27 |
+
except KeyError as e:
|
| 28 |
+
raise RuntimeError(
|
| 29 |
+
"internal dtype error, unknown kind {!r}"
|
| 30 |
+
.format(dtype.kind)
|
| 31 |
+
) from None
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def __str__(dtype):
|
| 35 |
+
if dtype.fields is not None:
|
| 36 |
+
return _struct_str(dtype, include_align=True)
|
| 37 |
+
elif dtype.subdtype:
|
| 38 |
+
return _subarray_str(dtype)
|
| 39 |
+
elif issubclass(dtype.type, np.flexible) or not dtype.isnative:
|
| 40 |
+
return dtype.str
|
| 41 |
+
else:
|
| 42 |
+
return dtype.name
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def __repr__(dtype):
|
| 46 |
+
arg_str = _construction_repr(dtype, include_align=False)
|
| 47 |
+
if dtype.isalignedstruct:
|
| 48 |
+
arg_str = arg_str + ", align=True"
|
| 49 |
+
return "dtype({})".format(arg_str)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def _unpack_field(dtype, offset, title=None):
|
| 53 |
+
"""
|
| 54 |
+
Helper function to normalize the items in dtype.fields.
|
| 55 |
+
|
| 56 |
+
Call as:
|
| 57 |
+
|
| 58 |
+
dtype, offset, title = _unpack_field(*dtype.fields[name])
|
| 59 |
+
"""
|
| 60 |
+
return dtype, offset, title
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def _isunsized(dtype):
|
| 64 |
+
# PyDataType_ISUNSIZED
|
| 65 |
+
return dtype.itemsize == 0
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _construction_repr(dtype, include_align=False, short=False):
|
| 69 |
+
"""
|
| 70 |
+
Creates a string repr of the dtype, excluding the 'dtype()' part
|
| 71 |
+
surrounding the object. This object may be a string, a list, or
|
| 72 |
+
a dict depending on the nature of the dtype. This
|
| 73 |
+
is the object passed as the first parameter to the dtype
|
| 74 |
+
constructor, and if no additional constructor parameters are
|
| 75 |
+
given, will reproduce the exact memory layout.
|
| 76 |
+
|
| 77 |
+
Parameters
|
| 78 |
+
----------
|
| 79 |
+
short : bool
|
| 80 |
+
If true, this creates a shorter repr using 'kind' and 'itemsize', instead
|
| 81 |
+
of the longer type name.
|
| 82 |
+
|
| 83 |
+
include_align : bool
|
| 84 |
+
If true, this includes the 'align=True' parameter
|
| 85 |
+
inside the struct dtype construction dict when needed. Use this flag
|
| 86 |
+
if you want a proper repr string without the 'dtype()' part around it.
|
| 87 |
+
|
| 88 |
+
If false, this does not preserve the
|
| 89 |
+
'align=True' parameter or sticky NPY_ALIGNED_STRUCT flag for
|
| 90 |
+
struct arrays like the regular repr does, because the 'align'
|
| 91 |
+
flag is not part of first dtype constructor parameter. This
|
| 92 |
+
mode is intended for a full 'repr', where the 'align=True' is
|
| 93 |
+
provided as the second parameter.
|
| 94 |
+
"""
|
| 95 |
+
if dtype.fields is not None:
|
| 96 |
+
return _struct_str(dtype, include_align=include_align)
|
| 97 |
+
elif dtype.subdtype:
|
| 98 |
+
return _subarray_str(dtype)
|
| 99 |
+
else:
|
| 100 |
+
return _scalar_str(dtype, short=short)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def _scalar_str(dtype, short):
|
| 104 |
+
byteorder = _byte_order_str(dtype)
|
| 105 |
+
|
| 106 |
+
if dtype.type == np.bool_:
|
| 107 |
+
if short:
|
| 108 |
+
return "'?'"
|
| 109 |
+
else:
|
| 110 |
+
return "'bool'"
|
| 111 |
+
|
| 112 |
+
elif dtype.type == np.object_:
|
| 113 |
+
# The object reference may be different sizes on different
|
| 114 |
+
# platforms, so it should never include the itemsize here.
|
| 115 |
+
return "'O'"
|
| 116 |
+
|
| 117 |
+
elif dtype.type == np.bytes_:
|
| 118 |
+
if _isunsized(dtype):
|
| 119 |
+
return "'S'"
|
| 120 |
+
else:
|
| 121 |
+
return "'S%d'" % dtype.itemsize
|
| 122 |
+
|
| 123 |
+
elif dtype.type == np.str_:
|
| 124 |
+
if _isunsized(dtype):
|
| 125 |
+
return "'%sU'" % byteorder
|
| 126 |
+
else:
|
| 127 |
+
return "'%sU%d'" % (byteorder, dtype.itemsize / 4)
|
| 128 |
+
|
| 129 |
+
# unlike the other types, subclasses of void are preserved - but
|
| 130 |
+
# historically the repr does not actually reveal the subclass
|
| 131 |
+
elif issubclass(dtype.type, np.void):
|
| 132 |
+
if _isunsized(dtype):
|
| 133 |
+
return "'V'"
|
| 134 |
+
else:
|
| 135 |
+
return "'V%d'" % dtype.itemsize
|
| 136 |
+
|
| 137 |
+
elif dtype.type == np.datetime64:
|
| 138 |
+
return "'%sM8%s'" % (byteorder, _datetime_metadata_str(dtype))
|
| 139 |
+
|
| 140 |
+
elif dtype.type == np.timedelta64:
|
| 141 |
+
return "'%sm8%s'" % (byteorder, _datetime_metadata_str(dtype))
|
| 142 |
+
|
| 143 |
+
elif np.issubdtype(dtype, np.number):
|
| 144 |
+
# Short repr with endianness, like '<f8'
|
| 145 |
+
if short or dtype.byteorder not in ('=', '|'):
|
| 146 |
+
return "'%s%c%d'" % (byteorder, dtype.kind, dtype.itemsize)
|
| 147 |
+
|
| 148 |
+
# Longer repr, like 'float64'
|
| 149 |
+
else:
|
| 150 |
+
return "'%s%d'" % (_kind_name(dtype), 8*dtype.itemsize)
|
| 151 |
+
|
| 152 |
+
elif dtype.isbuiltin == 2:
|
| 153 |
+
return dtype.type.__name__
|
| 154 |
+
|
| 155 |
+
else:
|
| 156 |
+
raise RuntimeError(
|
| 157 |
+
"Internal error: NumPy dtype unrecognized type number")
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def _byte_order_str(dtype):
|
| 161 |
+
""" Normalize byteorder to '<' or '>' """
|
| 162 |
+
# hack to obtain the native and swapped byte order characters
|
| 163 |
+
swapped = np.dtype(int).newbyteorder('S')
|
| 164 |
+
native = swapped.newbyteorder('S')
|
| 165 |
+
|
| 166 |
+
byteorder = dtype.byteorder
|
| 167 |
+
if byteorder == '=':
|
| 168 |
+
return native.byteorder
|
| 169 |
+
if byteorder == 'S':
|
| 170 |
+
# TODO: this path can never be reached
|
| 171 |
+
return swapped.byteorder
|
| 172 |
+
elif byteorder == '|':
|
| 173 |
+
return ''
|
| 174 |
+
else:
|
| 175 |
+
return byteorder
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def _datetime_metadata_str(dtype):
|
| 179 |
+
# TODO: this duplicates the C metastr_to_unicode functionality
|
| 180 |
+
unit, count = np.datetime_data(dtype)
|
| 181 |
+
if unit == 'generic':
|
| 182 |
+
return ''
|
| 183 |
+
elif count == 1:
|
| 184 |
+
return '[{}]'.format(unit)
|
| 185 |
+
else:
|
| 186 |
+
return '[{}{}]'.format(count, unit)
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def _struct_dict_str(dtype, includealignedflag):
|
| 190 |
+
# unpack the fields dictionary into ls
|
| 191 |
+
names = dtype.names
|
| 192 |
+
fld_dtypes = []
|
| 193 |
+
offsets = []
|
| 194 |
+
titles = []
|
| 195 |
+
for name in names:
|
| 196 |
+
fld_dtype, offset, title = _unpack_field(*dtype.fields[name])
|
| 197 |
+
fld_dtypes.append(fld_dtype)
|
| 198 |
+
offsets.append(offset)
|
| 199 |
+
titles.append(title)
|
| 200 |
+
|
| 201 |
+
# Build up a string to make the dictionary
|
| 202 |
+
|
| 203 |
+
if np.core.arrayprint._get_legacy_print_mode() <= 121:
|
| 204 |
+
colon = ":"
|
| 205 |
+
fieldsep = ","
|
| 206 |
+
else:
|
| 207 |
+
colon = ": "
|
| 208 |
+
fieldsep = ", "
|
| 209 |
+
|
| 210 |
+
# First, the names
|
| 211 |
+
ret = "{'names'%s[" % colon
|
| 212 |
+
ret += fieldsep.join(repr(name) for name in names)
|
| 213 |
+
|
| 214 |
+
# Second, the formats
|
| 215 |
+
ret += "], 'formats'%s[" % colon
|
| 216 |
+
ret += fieldsep.join(
|
| 217 |
+
_construction_repr(fld_dtype, short=True) for fld_dtype in fld_dtypes)
|
| 218 |
+
|
| 219 |
+
# Third, the offsets
|
| 220 |
+
ret += "], 'offsets'%s[" % colon
|
| 221 |
+
ret += fieldsep.join("%d" % offset for offset in offsets)
|
| 222 |
+
|
| 223 |
+
# Fourth, the titles
|
| 224 |
+
if any(title is not None for title in titles):
|
| 225 |
+
ret += "], 'titles'%s[" % colon
|
| 226 |
+
ret += fieldsep.join(repr(title) for title in titles)
|
| 227 |
+
|
| 228 |
+
# Fifth, the itemsize
|
| 229 |
+
ret += "], 'itemsize'%s%d" % (colon, dtype.itemsize)
|
| 230 |
+
|
| 231 |
+
if (includealignedflag and dtype.isalignedstruct):
|
| 232 |
+
# Finally, the aligned flag
|
| 233 |
+
ret += ", 'aligned'%sTrue}" % colon
|
| 234 |
+
else:
|
| 235 |
+
ret += "}"
|
| 236 |
+
|
| 237 |
+
return ret
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
def _aligned_offset(offset, alignment):
|
| 241 |
+
# round up offset:
|
| 242 |
+
return - (-offset // alignment) * alignment
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def _is_packed(dtype):
|
| 246 |
+
"""
|
| 247 |
+
Checks whether the structured data type in 'dtype'
|
| 248 |
+
has a simple layout, where all the fields are in order,
|
| 249 |
+
and follow each other with no alignment padding.
|
| 250 |
+
|
| 251 |
+
When this returns true, the dtype can be reconstructed
|
| 252 |
+
from a list of the field names and dtypes with no additional
|
| 253 |
+
dtype parameters.
|
| 254 |
+
|
| 255 |
+
Duplicates the C `is_dtype_struct_simple_unaligned_layout` function.
|
| 256 |
+
"""
|
| 257 |
+
align = dtype.isalignedstruct
|
| 258 |
+
max_alignment = 1
|
| 259 |
+
total_offset = 0
|
| 260 |
+
for name in dtype.names:
|
| 261 |
+
fld_dtype, fld_offset, title = _unpack_field(*dtype.fields[name])
|
| 262 |
+
|
| 263 |
+
if align:
|
| 264 |
+
total_offset = _aligned_offset(total_offset, fld_dtype.alignment)
|
| 265 |
+
max_alignment = max(max_alignment, fld_dtype.alignment)
|
| 266 |
+
|
| 267 |
+
if fld_offset != total_offset:
|
| 268 |
+
return False
|
| 269 |
+
total_offset += fld_dtype.itemsize
|
| 270 |
+
|
| 271 |
+
if align:
|
| 272 |
+
total_offset = _aligned_offset(total_offset, max_alignment)
|
| 273 |
+
|
| 274 |
+
if total_offset != dtype.itemsize:
|
| 275 |
+
return False
|
| 276 |
+
return True
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
def _struct_list_str(dtype):
|
| 280 |
+
items = []
|
| 281 |
+
for name in dtype.names:
|
| 282 |
+
fld_dtype, fld_offset, title = _unpack_field(*dtype.fields[name])
|
| 283 |
+
|
| 284 |
+
item = "("
|
| 285 |
+
if title is not None:
|
| 286 |
+
item += "({!r}, {!r}), ".format(title, name)
|
| 287 |
+
else:
|
| 288 |
+
item += "{!r}, ".format(name)
|
| 289 |
+
# Special case subarray handling here
|
| 290 |
+
if fld_dtype.subdtype is not None:
|
| 291 |
+
base, shape = fld_dtype.subdtype
|
| 292 |
+
item += "{}, {}".format(
|
| 293 |
+
_construction_repr(base, short=True),
|
| 294 |
+
shape
|
| 295 |
+
)
|
| 296 |
+
else:
|
| 297 |
+
item += _construction_repr(fld_dtype, short=True)
|
| 298 |
+
|
| 299 |
+
item += ")"
|
| 300 |
+
items.append(item)
|
| 301 |
+
|
| 302 |
+
return "[" + ", ".join(items) + "]"
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def _struct_str(dtype, include_align):
|
| 306 |
+
# The list str representation can't include the 'align=' flag,
|
| 307 |
+
# so if it is requested and the struct has the aligned flag set,
|
| 308 |
+
# we must use the dict str instead.
|
| 309 |
+
if not (include_align and dtype.isalignedstruct) and _is_packed(dtype):
|
| 310 |
+
sub = _struct_list_str(dtype)
|
| 311 |
+
|
| 312 |
+
else:
|
| 313 |
+
sub = _struct_dict_str(dtype, include_align)
|
| 314 |
+
|
| 315 |
+
# If the data type isn't the default, void, show it
|
| 316 |
+
if dtype.type != np.void:
|
| 317 |
+
return "({t.__module__}.{t.__name__}, {f})".format(t=dtype.type, f=sub)
|
| 318 |
+
else:
|
| 319 |
+
return sub
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
def _subarray_str(dtype):
|
| 323 |
+
base, shape = dtype.subdtype
|
| 324 |
+
return "({}, {})".format(
|
| 325 |
+
_construction_repr(base, short=True),
|
| 326 |
+
shape
|
| 327 |
+
)
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
def _name_includes_bit_suffix(dtype):
|
| 331 |
+
if dtype.type == np.object_:
|
| 332 |
+
# pointer size varies by system, best to omit it
|
| 333 |
+
return False
|
| 334 |
+
elif dtype.type == np.bool_:
|
| 335 |
+
# implied
|
| 336 |
+
return False
|
| 337 |
+
elif dtype.type is None:
|
| 338 |
+
return True
|
| 339 |
+
elif np.issubdtype(dtype, np.flexible) and _isunsized(dtype):
|
| 340 |
+
# unspecified
|
| 341 |
+
return False
|
| 342 |
+
else:
|
| 343 |
+
return True
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
def _name_get(dtype):
|
| 347 |
+
# provides dtype.name.__get__, documented as returning a "bit name"
|
| 348 |
+
|
| 349 |
+
if dtype.isbuiltin == 2:
|
| 350 |
+
# user dtypes don't promise to do anything special
|
| 351 |
+
return dtype.type.__name__
|
| 352 |
+
|
| 353 |
+
if dtype.kind == '\x00':
|
| 354 |
+
name = type(dtype).__name__
|
| 355 |
+
elif issubclass(dtype.type, np.void):
|
| 356 |
+
# historically, void subclasses preserve their name, eg `record64`
|
| 357 |
+
name = dtype.type.__name__
|
| 358 |
+
else:
|
| 359 |
+
name = _kind_name(dtype)
|
| 360 |
+
|
| 361 |
+
# append bit counts
|
| 362 |
+
if _name_includes_bit_suffix(dtype):
|
| 363 |
+
name += "{}".format(dtype.itemsize * 8)
|
| 364 |
+
|
| 365 |
+
# append metadata to datetimes
|
| 366 |
+
if dtype.type in (np.datetime64, np.timedelta64):
|
| 367 |
+
name += _datetime_metadata_str(dtype)
|
| 368 |
+
|
| 369 |
+
return name
|
.venv/lib/python3.11/site-packages/numpy/core/_dtype_ctypes.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Conversion from ctypes to dtype.
|
| 3 |
+
|
| 4 |
+
In an ideal world, we could achieve this through the PEP3118 buffer protocol,
|
| 5 |
+
something like::
|
| 6 |
+
|
| 7 |
+
def dtype_from_ctypes_type(t):
|
| 8 |
+
# needed to ensure that the shape of `t` is within memoryview.format
|
| 9 |
+
class DummyStruct(ctypes.Structure):
|
| 10 |
+
_fields_ = [('a', t)]
|
| 11 |
+
|
| 12 |
+
# empty to avoid memory allocation
|
| 13 |
+
ctype_0 = (DummyStruct * 0)()
|
| 14 |
+
mv = memoryview(ctype_0)
|
| 15 |
+
|
| 16 |
+
# convert the struct, and slice back out the field
|
| 17 |
+
return _dtype_from_pep3118(mv.format)['a']
|
| 18 |
+
|
| 19 |
+
Unfortunately, this fails because:
|
| 20 |
+
|
| 21 |
+
* ctypes cannot handle length-0 arrays with PEP3118 (bpo-32782)
|
| 22 |
+
* PEP3118 cannot represent unions, but both numpy and ctypes can
|
| 23 |
+
* ctypes cannot handle big-endian structs with PEP3118 (bpo-32780)
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
# We delay-import ctypes for distributions that do not include it.
|
| 27 |
+
# While this module is not used unless the user passes in ctypes
|
| 28 |
+
# members, it is eagerly imported from numpy/core/__init__.py.
|
| 29 |
+
import numpy as np
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def _from_ctypes_array(t):
|
| 33 |
+
return np.dtype((dtype_from_ctypes_type(t._type_), (t._length_,)))
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _from_ctypes_structure(t):
|
| 37 |
+
for item in t._fields_:
|
| 38 |
+
if len(item) > 2:
|
| 39 |
+
raise TypeError(
|
| 40 |
+
"ctypes bitfields have no dtype equivalent")
|
| 41 |
+
|
| 42 |
+
if hasattr(t, "_pack_"):
|
| 43 |
+
import ctypes
|
| 44 |
+
formats = []
|
| 45 |
+
offsets = []
|
| 46 |
+
names = []
|
| 47 |
+
current_offset = 0
|
| 48 |
+
for fname, ftyp in t._fields_:
|
| 49 |
+
names.append(fname)
|
| 50 |
+
formats.append(dtype_from_ctypes_type(ftyp))
|
| 51 |
+
# Each type has a default offset, this is platform dependent for some types.
|
| 52 |
+
effective_pack = min(t._pack_, ctypes.alignment(ftyp))
|
| 53 |
+
current_offset = ((current_offset + effective_pack - 1) // effective_pack) * effective_pack
|
| 54 |
+
offsets.append(current_offset)
|
| 55 |
+
current_offset += ctypes.sizeof(ftyp)
|
| 56 |
+
|
| 57 |
+
return np.dtype(dict(
|
| 58 |
+
formats=formats,
|
| 59 |
+
offsets=offsets,
|
| 60 |
+
names=names,
|
| 61 |
+
itemsize=ctypes.sizeof(t)))
|
| 62 |
+
else:
|
| 63 |
+
fields = []
|
| 64 |
+
for fname, ftyp in t._fields_:
|
| 65 |
+
fields.append((fname, dtype_from_ctypes_type(ftyp)))
|
| 66 |
+
|
| 67 |
+
# by default, ctypes structs are aligned
|
| 68 |
+
return np.dtype(fields, align=True)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def _from_ctypes_scalar(t):
|
| 72 |
+
"""
|
| 73 |
+
Return the dtype type with endianness included if it's the case
|
| 74 |
+
"""
|
| 75 |
+
if getattr(t, '__ctype_be__', None) is t:
|
| 76 |
+
return np.dtype('>' + t._type_)
|
| 77 |
+
elif getattr(t, '__ctype_le__', None) is t:
|
| 78 |
+
return np.dtype('<' + t._type_)
|
| 79 |
+
else:
|
| 80 |
+
return np.dtype(t._type_)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _from_ctypes_union(t):
|
| 84 |
+
import ctypes
|
| 85 |
+
formats = []
|
| 86 |
+
offsets = []
|
| 87 |
+
names = []
|
| 88 |
+
for fname, ftyp in t._fields_:
|
| 89 |
+
names.append(fname)
|
| 90 |
+
formats.append(dtype_from_ctypes_type(ftyp))
|
| 91 |
+
offsets.append(0) # Union fields are offset to 0
|
| 92 |
+
|
| 93 |
+
return np.dtype(dict(
|
| 94 |
+
formats=formats,
|
| 95 |
+
offsets=offsets,
|
| 96 |
+
names=names,
|
| 97 |
+
itemsize=ctypes.sizeof(t)))
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def dtype_from_ctypes_type(t):
|
| 101 |
+
"""
|
| 102 |
+
Construct a dtype object from a ctypes type
|
| 103 |
+
"""
|
| 104 |
+
import _ctypes
|
| 105 |
+
if issubclass(t, _ctypes.Array):
|
| 106 |
+
return _from_ctypes_array(t)
|
| 107 |
+
elif issubclass(t, _ctypes._Pointer):
|
| 108 |
+
raise TypeError("ctypes pointers have no dtype equivalent")
|
| 109 |
+
elif issubclass(t, _ctypes.Structure):
|
| 110 |
+
return _from_ctypes_structure(t)
|
| 111 |
+
elif issubclass(t, _ctypes.Union):
|
| 112 |
+
return _from_ctypes_union(t)
|
| 113 |
+
elif isinstance(getattr(t, '_type_', None), str):
|
| 114 |
+
return _from_ctypes_scalar(t)
|
| 115 |
+
else:
|
| 116 |
+
raise NotImplementedError(
|
| 117 |
+
"Unknown ctypes type {}".format(t.__name__))
|
.venv/lib/python3.11/site-packages/numpy/core/_exceptions.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Various richly-typed exceptions, that also help us deal with string formatting
|
| 3 |
+
in python where it's easier.
|
| 4 |
+
|
| 5 |
+
By putting the formatting in `__str__`, we also avoid paying the cost for
|
| 6 |
+
users who silence the exceptions.
|
| 7 |
+
"""
|
| 8 |
+
from .._utils import set_module
|
| 9 |
+
|
| 10 |
+
def _unpack_tuple(tup):
|
| 11 |
+
if len(tup) == 1:
|
| 12 |
+
return tup[0]
|
| 13 |
+
else:
|
| 14 |
+
return tup
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def _display_as_base(cls):
|
| 18 |
+
"""
|
| 19 |
+
A decorator that makes an exception class look like its base.
|
| 20 |
+
|
| 21 |
+
We use this to hide subclasses that are implementation details - the user
|
| 22 |
+
should catch the base type, which is what the traceback will show them.
|
| 23 |
+
|
| 24 |
+
Classes decorated with this decorator are subject to removal without a
|
| 25 |
+
deprecation warning.
|
| 26 |
+
"""
|
| 27 |
+
assert issubclass(cls, Exception)
|
| 28 |
+
cls.__name__ = cls.__base__.__name__
|
| 29 |
+
return cls
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class UFuncTypeError(TypeError):
|
| 33 |
+
""" Base class for all ufunc exceptions """
|
| 34 |
+
def __init__(self, ufunc):
|
| 35 |
+
self.ufunc = ufunc
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@_display_as_base
|
| 39 |
+
class _UFuncNoLoopError(UFuncTypeError):
|
| 40 |
+
""" Thrown when a ufunc loop cannot be found """
|
| 41 |
+
def __init__(self, ufunc, dtypes):
|
| 42 |
+
super().__init__(ufunc)
|
| 43 |
+
self.dtypes = tuple(dtypes)
|
| 44 |
+
|
| 45 |
+
def __str__(self):
|
| 46 |
+
return (
|
| 47 |
+
"ufunc {!r} did not contain a loop with signature matching types "
|
| 48 |
+
"{!r} -> {!r}"
|
| 49 |
+
).format(
|
| 50 |
+
self.ufunc.__name__,
|
| 51 |
+
_unpack_tuple(self.dtypes[:self.ufunc.nin]),
|
| 52 |
+
_unpack_tuple(self.dtypes[self.ufunc.nin:])
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
@_display_as_base
|
| 57 |
+
class _UFuncBinaryResolutionError(_UFuncNoLoopError):
|
| 58 |
+
""" Thrown when a binary resolution fails """
|
| 59 |
+
def __init__(self, ufunc, dtypes):
|
| 60 |
+
super().__init__(ufunc, dtypes)
|
| 61 |
+
assert len(self.dtypes) == 2
|
| 62 |
+
|
| 63 |
+
def __str__(self):
|
| 64 |
+
return (
|
| 65 |
+
"ufunc {!r} cannot use operands with types {!r} and {!r}"
|
| 66 |
+
).format(
|
| 67 |
+
self.ufunc.__name__, *self.dtypes
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
@_display_as_base
|
| 72 |
+
class _UFuncCastingError(UFuncTypeError):
|
| 73 |
+
def __init__(self, ufunc, casting, from_, to):
|
| 74 |
+
super().__init__(ufunc)
|
| 75 |
+
self.casting = casting
|
| 76 |
+
self.from_ = from_
|
| 77 |
+
self.to = to
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
@_display_as_base
|
| 81 |
+
class _UFuncInputCastingError(_UFuncCastingError):
|
| 82 |
+
""" Thrown when a ufunc input cannot be casted """
|
| 83 |
+
def __init__(self, ufunc, casting, from_, to, i):
|
| 84 |
+
super().__init__(ufunc, casting, from_, to)
|
| 85 |
+
self.in_i = i
|
| 86 |
+
|
| 87 |
+
def __str__(self):
|
| 88 |
+
# only show the number if more than one input exists
|
| 89 |
+
i_str = "{} ".format(self.in_i) if self.ufunc.nin != 1 else ""
|
| 90 |
+
return (
|
| 91 |
+
"Cannot cast ufunc {!r} input {}from {!r} to {!r} with casting "
|
| 92 |
+
"rule {!r}"
|
| 93 |
+
).format(
|
| 94 |
+
self.ufunc.__name__, i_str, self.from_, self.to, self.casting
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
@_display_as_base
|
| 99 |
+
class _UFuncOutputCastingError(_UFuncCastingError):
|
| 100 |
+
""" Thrown when a ufunc output cannot be casted """
|
| 101 |
+
def __init__(self, ufunc, casting, from_, to, i):
|
| 102 |
+
super().__init__(ufunc, casting, from_, to)
|
| 103 |
+
self.out_i = i
|
| 104 |
+
|
| 105 |
+
def __str__(self):
|
| 106 |
+
# only show the number if more than one output exists
|
| 107 |
+
i_str = "{} ".format(self.out_i) if self.ufunc.nout != 1 else ""
|
| 108 |
+
return (
|
| 109 |
+
"Cannot cast ufunc {!r} output {}from {!r} to {!r} with casting "
|
| 110 |
+
"rule {!r}"
|
| 111 |
+
).format(
|
| 112 |
+
self.ufunc.__name__, i_str, self.from_, self.to, self.casting
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
@_display_as_base
|
| 117 |
+
class _ArrayMemoryError(MemoryError):
|
| 118 |
+
""" Thrown when an array cannot be allocated"""
|
| 119 |
+
def __init__(self, shape, dtype):
|
| 120 |
+
self.shape = shape
|
| 121 |
+
self.dtype = dtype
|
| 122 |
+
|
| 123 |
+
@property
|
| 124 |
+
def _total_size(self):
|
| 125 |
+
num_bytes = self.dtype.itemsize
|
| 126 |
+
for dim in self.shape:
|
| 127 |
+
num_bytes *= dim
|
| 128 |
+
return num_bytes
|
| 129 |
+
|
| 130 |
+
@staticmethod
|
| 131 |
+
def _size_to_string(num_bytes):
|
| 132 |
+
""" Convert a number of bytes into a binary size string """
|
| 133 |
+
|
| 134 |
+
# https://en.wikipedia.org/wiki/Binary_prefix
|
| 135 |
+
LOG2_STEP = 10
|
| 136 |
+
STEP = 1024
|
| 137 |
+
units = ['bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB']
|
| 138 |
+
|
| 139 |
+
unit_i = max(num_bytes.bit_length() - 1, 1) // LOG2_STEP
|
| 140 |
+
unit_val = 1 << (unit_i * LOG2_STEP)
|
| 141 |
+
n_units = num_bytes / unit_val
|
| 142 |
+
del unit_val
|
| 143 |
+
|
| 144 |
+
# ensure we pick a unit that is correct after rounding
|
| 145 |
+
if round(n_units) == STEP:
|
| 146 |
+
unit_i += 1
|
| 147 |
+
n_units /= STEP
|
| 148 |
+
|
| 149 |
+
# deal with sizes so large that we don't have units for them
|
| 150 |
+
if unit_i >= len(units):
|
| 151 |
+
new_unit_i = len(units) - 1
|
| 152 |
+
n_units *= 1 << ((unit_i - new_unit_i) * LOG2_STEP)
|
| 153 |
+
unit_i = new_unit_i
|
| 154 |
+
|
| 155 |
+
unit_name = units[unit_i]
|
| 156 |
+
# format with a sensible number of digits
|
| 157 |
+
if unit_i == 0:
|
| 158 |
+
# no decimal point on bytes
|
| 159 |
+
return '{:.0f} {}'.format(n_units, unit_name)
|
| 160 |
+
elif round(n_units) < 1000:
|
| 161 |
+
# 3 significant figures, if none are dropped to the left of the .
|
| 162 |
+
return '{:#.3g} {}'.format(n_units, unit_name)
|
| 163 |
+
else:
|
| 164 |
+
# just give all the digits otherwise
|
| 165 |
+
return '{:#.0f} {}'.format(n_units, unit_name)
|
| 166 |
+
|
| 167 |
+
def __str__(self):
|
| 168 |
+
size_str = self._size_to_string(self._total_size)
|
| 169 |
+
return (
|
| 170 |
+
"Unable to allocate {} for an array with shape {} and data type {}"
|
| 171 |
+
.format(size_str, self.shape, self.dtype)
|
| 172 |
+
)
|
.venv/lib/python3.11/site-packages/numpy/core/_internal.pyi
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, TypeVar, overload, Generic
|
| 2 |
+
import ctypes as ct
|
| 3 |
+
|
| 4 |
+
from numpy import ndarray
|
| 5 |
+
from numpy.ctypeslib import c_intp
|
| 6 |
+
|
| 7 |
+
_CastT = TypeVar("_CastT", bound=ct._CanCastTo) # Copied from `ctypes.cast`
|
| 8 |
+
_CT = TypeVar("_CT", bound=ct._CData)
|
| 9 |
+
_PT = TypeVar("_PT", bound=None | int)
|
| 10 |
+
|
| 11 |
+
# TODO: Let the likes of `shape_as` and `strides_as` return `None`
|
| 12 |
+
# for 0D arrays once we've got shape-support
|
| 13 |
+
|
| 14 |
+
class _ctypes(Generic[_PT]):
|
| 15 |
+
@overload
|
| 16 |
+
def __new__(cls, array: ndarray[Any, Any], ptr: None = ...) -> _ctypes[None]: ...
|
| 17 |
+
@overload
|
| 18 |
+
def __new__(cls, array: ndarray[Any, Any], ptr: _PT) -> _ctypes[_PT]: ...
|
| 19 |
+
@property
|
| 20 |
+
def data(self) -> _PT: ...
|
| 21 |
+
@property
|
| 22 |
+
def shape(self) -> ct.Array[c_intp]: ...
|
| 23 |
+
@property
|
| 24 |
+
def strides(self) -> ct.Array[c_intp]: ...
|
| 25 |
+
@property
|
| 26 |
+
def _as_parameter_(self) -> ct.c_void_p: ...
|
| 27 |
+
|
| 28 |
+
def data_as(self, obj: type[_CastT]) -> _CastT: ...
|
| 29 |
+
def shape_as(self, obj: type[_CT]) -> ct.Array[_CT]: ...
|
| 30 |
+
def strides_as(self, obj: type[_CT]) -> ct.Array[_CT]: ...
|
.venv/lib/python3.11/site-packages/numpy/core/_machar.py
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Machine arithmetic - determine the parameters of the
|
| 3 |
+
floating-point arithmetic system
|
| 4 |
+
|
| 5 |
+
Author: Pearu Peterson, September 2003
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
__all__ = ['MachAr']
|
| 9 |
+
|
| 10 |
+
from .fromnumeric import any
|
| 11 |
+
from ._ufunc_config import errstate
|
| 12 |
+
from .._utils import set_module
|
| 13 |
+
|
| 14 |
+
# Need to speed this up...especially for longfloat
|
| 15 |
+
|
| 16 |
+
# Deprecated 2021-10-20, NumPy 1.22
|
| 17 |
+
class MachAr:
|
| 18 |
+
"""
|
| 19 |
+
Diagnosing machine parameters.
|
| 20 |
+
|
| 21 |
+
Attributes
|
| 22 |
+
----------
|
| 23 |
+
ibeta : int
|
| 24 |
+
Radix in which numbers are represented.
|
| 25 |
+
it : int
|
| 26 |
+
Number of base-`ibeta` digits in the floating point mantissa M.
|
| 27 |
+
machep : int
|
| 28 |
+
Exponent of the smallest (most negative) power of `ibeta` that,
|
| 29 |
+
added to 1.0, gives something different from 1.0
|
| 30 |
+
eps : float
|
| 31 |
+
Floating-point number ``beta**machep`` (floating point precision)
|
| 32 |
+
negep : int
|
| 33 |
+
Exponent of the smallest power of `ibeta` that, subtracted
|
| 34 |
+
from 1.0, gives something different from 1.0.
|
| 35 |
+
epsneg : float
|
| 36 |
+
Floating-point number ``beta**negep``.
|
| 37 |
+
iexp : int
|
| 38 |
+
Number of bits in the exponent (including its sign and bias).
|
| 39 |
+
minexp : int
|
| 40 |
+
Smallest (most negative) power of `ibeta` consistent with there
|
| 41 |
+
being no leading zeros in the mantissa.
|
| 42 |
+
xmin : float
|
| 43 |
+
Floating-point number ``beta**minexp`` (the smallest [in
|
| 44 |
+
magnitude] positive floating point number with full precision).
|
| 45 |
+
maxexp : int
|
| 46 |
+
Smallest (positive) power of `ibeta` that causes overflow.
|
| 47 |
+
xmax : float
|
| 48 |
+
``(1-epsneg) * beta**maxexp`` (the largest [in magnitude]
|
| 49 |
+
usable floating value).
|
| 50 |
+
irnd : int
|
| 51 |
+
In ``range(6)``, information on what kind of rounding is done
|
| 52 |
+
in addition, and on how underflow is handled.
|
| 53 |
+
ngrd : int
|
| 54 |
+
Number of 'guard digits' used when truncating the product
|
| 55 |
+
of two mantissas to fit the representation.
|
| 56 |
+
epsilon : float
|
| 57 |
+
Same as `eps`.
|
| 58 |
+
tiny : float
|
| 59 |
+
An alias for `smallest_normal`, kept for backwards compatibility.
|
| 60 |
+
huge : float
|
| 61 |
+
Same as `xmax`.
|
| 62 |
+
precision : float
|
| 63 |
+
``- int(-log10(eps))``
|
| 64 |
+
resolution : float
|
| 65 |
+
``- 10**(-precision)``
|
| 66 |
+
smallest_normal : float
|
| 67 |
+
The smallest positive floating point number with 1 as leading bit in
|
| 68 |
+
the mantissa following IEEE-754. Same as `xmin`.
|
| 69 |
+
smallest_subnormal : float
|
| 70 |
+
The smallest positive floating point number with 0 as leading bit in
|
| 71 |
+
the mantissa following IEEE-754.
|
| 72 |
+
|
| 73 |
+
Parameters
|
| 74 |
+
----------
|
| 75 |
+
float_conv : function, optional
|
| 76 |
+
Function that converts an integer or integer array to a float
|
| 77 |
+
or float array. Default is `float`.
|
| 78 |
+
int_conv : function, optional
|
| 79 |
+
Function that converts a float or float array to an integer or
|
| 80 |
+
integer array. Default is `int`.
|
| 81 |
+
float_to_float : function, optional
|
| 82 |
+
Function that converts a float array to float. Default is `float`.
|
| 83 |
+
Note that this does not seem to do anything useful in the current
|
| 84 |
+
implementation.
|
| 85 |
+
float_to_str : function, optional
|
| 86 |
+
Function that converts a single float to a string. Default is
|
| 87 |
+
``lambda v:'%24.16e' %v``.
|
| 88 |
+
title : str, optional
|
| 89 |
+
Title that is printed in the string representation of `MachAr`.
|
| 90 |
+
|
| 91 |
+
See Also
|
| 92 |
+
--------
|
| 93 |
+
finfo : Machine limits for floating point types.
|
| 94 |
+
iinfo : Machine limits for integer types.
|
| 95 |
+
|
| 96 |
+
References
|
| 97 |
+
----------
|
| 98 |
+
.. [1] Press, Teukolsky, Vetterling and Flannery,
|
| 99 |
+
"Numerical Recipes in C++," 2nd ed,
|
| 100 |
+
Cambridge University Press, 2002, p. 31.
|
| 101 |
+
|
| 102 |
+
"""
|
| 103 |
+
|
| 104 |
+
def __init__(self, float_conv=float,int_conv=int,
|
| 105 |
+
float_to_float=float,
|
| 106 |
+
float_to_str=lambda v:'%24.16e' % v,
|
| 107 |
+
title='Python floating point number'):
|
| 108 |
+
"""
|
| 109 |
+
|
| 110 |
+
float_conv - convert integer to float (array)
|
| 111 |
+
int_conv - convert float (array) to integer
|
| 112 |
+
float_to_float - convert float array to float
|
| 113 |
+
float_to_str - convert array float to str
|
| 114 |
+
title - description of used floating point numbers
|
| 115 |
+
|
| 116 |
+
"""
|
| 117 |
+
# We ignore all errors here because we are purposely triggering
|
| 118 |
+
# underflow to detect the properties of the runninng arch.
|
| 119 |
+
with errstate(under='ignore'):
|
| 120 |
+
self._do_init(float_conv, int_conv, float_to_float, float_to_str, title)
|
| 121 |
+
|
| 122 |
+
def _do_init(self, float_conv, int_conv, float_to_float, float_to_str, title):
|
| 123 |
+
max_iterN = 10000
|
| 124 |
+
msg = "Did not converge after %d tries with %s"
|
| 125 |
+
one = float_conv(1)
|
| 126 |
+
two = one + one
|
| 127 |
+
zero = one - one
|
| 128 |
+
|
| 129 |
+
# Do we really need to do this? Aren't they 2 and 2.0?
|
| 130 |
+
# Determine ibeta and beta
|
| 131 |
+
a = one
|
| 132 |
+
for _ in range(max_iterN):
|
| 133 |
+
a = a + a
|
| 134 |
+
temp = a + one
|
| 135 |
+
temp1 = temp - a
|
| 136 |
+
if any(temp1 - one != zero):
|
| 137 |
+
break
|
| 138 |
+
else:
|
| 139 |
+
raise RuntimeError(msg % (_, one.dtype))
|
| 140 |
+
b = one
|
| 141 |
+
for _ in range(max_iterN):
|
| 142 |
+
b = b + b
|
| 143 |
+
temp = a + b
|
| 144 |
+
itemp = int_conv(temp-a)
|
| 145 |
+
if any(itemp != 0):
|
| 146 |
+
break
|
| 147 |
+
else:
|
| 148 |
+
raise RuntimeError(msg % (_, one.dtype))
|
| 149 |
+
ibeta = itemp
|
| 150 |
+
beta = float_conv(ibeta)
|
| 151 |
+
|
| 152 |
+
# Determine it and irnd
|
| 153 |
+
it = -1
|
| 154 |
+
b = one
|
| 155 |
+
for _ in range(max_iterN):
|
| 156 |
+
it = it + 1
|
| 157 |
+
b = b * beta
|
| 158 |
+
temp = b + one
|
| 159 |
+
temp1 = temp - b
|
| 160 |
+
if any(temp1 - one != zero):
|
| 161 |
+
break
|
| 162 |
+
else:
|
| 163 |
+
raise RuntimeError(msg % (_, one.dtype))
|
| 164 |
+
|
| 165 |
+
betah = beta / two
|
| 166 |
+
a = one
|
| 167 |
+
for _ in range(max_iterN):
|
| 168 |
+
a = a + a
|
| 169 |
+
temp = a + one
|
| 170 |
+
temp1 = temp - a
|
| 171 |
+
if any(temp1 - one != zero):
|
| 172 |
+
break
|
| 173 |
+
else:
|
| 174 |
+
raise RuntimeError(msg % (_, one.dtype))
|
| 175 |
+
temp = a + betah
|
| 176 |
+
irnd = 0
|
| 177 |
+
if any(temp-a != zero):
|
| 178 |
+
irnd = 1
|
| 179 |
+
tempa = a + beta
|
| 180 |
+
temp = tempa + betah
|
| 181 |
+
if irnd == 0 and any(temp-tempa != zero):
|
| 182 |
+
irnd = 2
|
| 183 |
+
|
| 184 |
+
# Determine negep and epsneg
|
| 185 |
+
negep = it + 3
|
| 186 |
+
betain = one / beta
|
| 187 |
+
a = one
|
| 188 |
+
for i in range(negep):
|
| 189 |
+
a = a * betain
|
| 190 |
+
b = a
|
| 191 |
+
for _ in range(max_iterN):
|
| 192 |
+
temp = one - a
|
| 193 |
+
if any(temp-one != zero):
|
| 194 |
+
break
|
| 195 |
+
a = a * beta
|
| 196 |
+
negep = negep - 1
|
| 197 |
+
# Prevent infinite loop on PPC with gcc 4.0:
|
| 198 |
+
if negep < 0:
|
| 199 |
+
raise RuntimeError("could not determine machine tolerance "
|
| 200 |
+
"for 'negep', locals() -> %s" % (locals()))
|
| 201 |
+
else:
|
| 202 |
+
raise RuntimeError(msg % (_, one.dtype))
|
| 203 |
+
negep = -negep
|
| 204 |
+
epsneg = a
|
| 205 |
+
|
| 206 |
+
# Determine machep and eps
|
| 207 |
+
machep = - it - 3
|
| 208 |
+
a = b
|
| 209 |
+
|
| 210 |
+
for _ in range(max_iterN):
|
| 211 |
+
temp = one + a
|
| 212 |
+
if any(temp-one != zero):
|
| 213 |
+
break
|
| 214 |
+
a = a * beta
|
| 215 |
+
machep = machep + 1
|
| 216 |
+
else:
|
| 217 |
+
raise RuntimeError(msg % (_, one.dtype))
|
| 218 |
+
eps = a
|
| 219 |
+
|
| 220 |
+
# Determine ngrd
|
| 221 |
+
ngrd = 0
|
| 222 |
+
temp = one + eps
|
| 223 |
+
if irnd == 0 and any(temp*one - one != zero):
|
| 224 |
+
ngrd = 1
|
| 225 |
+
|
| 226 |
+
# Determine iexp
|
| 227 |
+
i = 0
|
| 228 |
+
k = 1
|
| 229 |
+
z = betain
|
| 230 |
+
t = one + eps
|
| 231 |
+
nxres = 0
|
| 232 |
+
for _ in range(max_iterN):
|
| 233 |
+
y = z
|
| 234 |
+
z = y*y
|
| 235 |
+
a = z*one # Check here for underflow
|
| 236 |
+
temp = z*t
|
| 237 |
+
if any(a+a == zero) or any(abs(z) >= y):
|
| 238 |
+
break
|
| 239 |
+
temp1 = temp * betain
|
| 240 |
+
if any(temp1*beta == z):
|
| 241 |
+
break
|
| 242 |
+
i = i + 1
|
| 243 |
+
k = k + k
|
| 244 |
+
else:
|
| 245 |
+
raise RuntimeError(msg % (_, one.dtype))
|
| 246 |
+
if ibeta != 10:
|
| 247 |
+
iexp = i + 1
|
| 248 |
+
mx = k + k
|
| 249 |
+
else:
|
| 250 |
+
iexp = 2
|
| 251 |
+
iz = ibeta
|
| 252 |
+
while k >= iz:
|
| 253 |
+
iz = iz * ibeta
|
| 254 |
+
iexp = iexp + 1
|
| 255 |
+
mx = iz + iz - 1
|
| 256 |
+
|
| 257 |
+
# Determine minexp and xmin
|
| 258 |
+
for _ in range(max_iterN):
|
| 259 |
+
xmin = y
|
| 260 |
+
y = y * betain
|
| 261 |
+
a = y * one
|
| 262 |
+
temp = y * t
|
| 263 |
+
if any((a + a) != zero) and any(abs(y) < xmin):
|
| 264 |
+
k = k + 1
|
| 265 |
+
temp1 = temp * betain
|
| 266 |
+
if any(temp1*beta == y) and any(temp != y):
|
| 267 |
+
nxres = 3
|
| 268 |
+
xmin = y
|
| 269 |
+
break
|
| 270 |
+
else:
|
| 271 |
+
break
|
| 272 |
+
else:
|
| 273 |
+
raise RuntimeError(msg % (_, one.dtype))
|
| 274 |
+
minexp = -k
|
| 275 |
+
|
| 276 |
+
# Determine maxexp, xmax
|
| 277 |
+
if mx <= k + k - 3 and ibeta != 10:
|
| 278 |
+
mx = mx + mx
|
| 279 |
+
iexp = iexp + 1
|
| 280 |
+
maxexp = mx + minexp
|
| 281 |
+
irnd = irnd + nxres
|
| 282 |
+
if irnd >= 2:
|
| 283 |
+
maxexp = maxexp - 2
|
| 284 |
+
i = maxexp + minexp
|
| 285 |
+
if ibeta == 2 and not i:
|
| 286 |
+
maxexp = maxexp - 1
|
| 287 |
+
if i > 20:
|
| 288 |
+
maxexp = maxexp - 1
|
| 289 |
+
if any(a != y):
|
| 290 |
+
maxexp = maxexp - 2
|
| 291 |
+
xmax = one - epsneg
|
| 292 |
+
if any(xmax*one != xmax):
|
| 293 |
+
xmax = one - beta*epsneg
|
| 294 |
+
xmax = xmax / (xmin*beta*beta*beta)
|
| 295 |
+
i = maxexp + minexp + 3
|
| 296 |
+
for j in range(i):
|
| 297 |
+
if ibeta == 2:
|
| 298 |
+
xmax = xmax + xmax
|
| 299 |
+
else:
|
| 300 |
+
xmax = xmax * beta
|
| 301 |
+
|
| 302 |
+
smallest_subnormal = abs(xmin / beta ** (it))
|
| 303 |
+
|
| 304 |
+
self.ibeta = ibeta
|
| 305 |
+
self.it = it
|
| 306 |
+
self.negep = negep
|
| 307 |
+
self.epsneg = float_to_float(epsneg)
|
| 308 |
+
self._str_epsneg = float_to_str(epsneg)
|
| 309 |
+
self.machep = machep
|
| 310 |
+
self.eps = float_to_float(eps)
|
| 311 |
+
self._str_eps = float_to_str(eps)
|
| 312 |
+
self.ngrd = ngrd
|
| 313 |
+
self.iexp = iexp
|
| 314 |
+
self.minexp = minexp
|
| 315 |
+
self.xmin = float_to_float(xmin)
|
| 316 |
+
self._str_xmin = float_to_str(xmin)
|
| 317 |
+
self.maxexp = maxexp
|
| 318 |
+
self.xmax = float_to_float(xmax)
|
| 319 |
+
self._str_xmax = float_to_str(xmax)
|
| 320 |
+
self.irnd = irnd
|
| 321 |
+
|
| 322 |
+
self.title = title
|
| 323 |
+
# Commonly used parameters
|
| 324 |
+
self.epsilon = self.eps
|
| 325 |
+
self.tiny = self.xmin
|
| 326 |
+
self.huge = self.xmax
|
| 327 |
+
self.smallest_normal = self.xmin
|
| 328 |
+
self._str_smallest_normal = float_to_str(self.xmin)
|
| 329 |
+
self.smallest_subnormal = float_to_float(smallest_subnormal)
|
| 330 |
+
self._str_smallest_subnormal = float_to_str(smallest_subnormal)
|
| 331 |
+
|
| 332 |
+
import math
|
| 333 |
+
self.precision = int(-math.log10(float_to_float(self.eps)))
|
| 334 |
+
ten = two + two + two + two + two
|
| 335 |
+
resolution = ten ** (-self.precision)
|
| 336 |
+
self.resolution = float_to_float(resolution)
|
| 337 |
+
self._str_resolution = float_to_str(resolution)
|
| 338 |
+
|
| 339 |
+
def __str__(self):
|
| 340 |
+
fmt = (
|
| 341 |
+
'Machine parameters for %(title)s\n'
|
| 342 |
+
'---------------------------------------------------------------------\n'
|
| 343 |
+
'ibeta=%(ibeta)s it=%(it)s iexp=%(iexp)s ngrd=%(ngrd)s irnd=%(irnd)s\n'
|
| 344 |
+
'machep=%(machep)s eps=%(_str_eps)s (beta**machep == epsilon)\n'
|
| 345 |
+
'negep =%(negep)s epsneg=%(_str_epsneg)s (beta**epsneg)\n'
|
| 346 |
+
'minexp=%(minexp)s xmin=%(_str_xmin)s (beta**minexp == tiny)\n'
|
| 347 |
+
'maxexp=%(maxexp)s xmax=%(_str_xmax)s ((1-epsneg)*beta**maxexp == huge)\n'
|
| 348 |
+
'smallest_normal=%(smallest_normal)s '
|
| 349 |
+
'smallest_subnormal=%(smallest_subnormal)s\n'
|
| 350 |
+
'---------------------------------------------------------------------\n'
|
| 351 |
+
)
|
| 352 |
+
return fmt % self.__dict__
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
if __name__ == '__main__':
|
| 356 |
+
print(MachAr())
|
.venv/lib/python3.11/site-packages/numpy/core/_methods.py
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Array methods which are called by both the C-code for the method
|
| 3 |
+
and the Python code for the NumPy-namespace function
|
| 4 |
+
|
| 5 |
+
"""
|
| 6 |
+
import warnings
|
| 7 |
+
from contextlib import nullcontext
|
| 8 |
+
|
| 9 |
+
from numpy.core import multiarray as mu
|
| 10 |
+
from numpy.core import umath as um
|
| 11 |
+
from numpy.core.multiarray import asanyarray
|
| 12 |
+
from numpy.core import numerictypes as nt
|
| 13 |
+
from numpy.core import _exceptions
|
| 14 |
+
from numpy.core._ufunc_config import _no_nep50_warning
|
| 15 |
+
from numpy._globals import _NoValue
|
| 16 |
+
from numpy.compat import pickle, os_fspath
|
| 17 |
+
|
| 18 |
+
# save those O(100) nanoseconds!
|
| 19 |
+
umr_maximum = um.maximum.reduce
|
| 20 |
+
umr_minimum = um.minimum.reduce
|
| 21 |
+
umr_sum = um.add.reduce
|
| 22 |
+
umr_prod = um.multiply.reduce
|
| 23 |
+
umr_any = um.logical_or.reduce
|
| 24 |
+
umr_all = um.logical_and.reduce
|
| 25 |
+
|
| 26 |
+
# Complex types to -> (2,)float view for fast-path computation in _var()
|
| 27 |
+
_complex_to_float = {
|
| 28 |
+
nt.dtype(nt.csingle) : nt.dtype(nt.single),
|
| 29 |
+
nt.dtype(nt.cdouble) : nt.dtype(nt.double),
|
| 30 |
+
}
|
| 31 |
+
# Special case for windows: ensure double takes precedence
|
| 32 |
+
if nt.dtype(nt.longdouble) != nt.dtype(nt.double):
|
| 33 |
+
_complex_to_float.update({
|
| 34 |
+
nt.dtype(nt.clongdouble) : nt.dtype(nt.longdouble),
|
| 35 |
+
})
|
| 36 |
+
|
| 37 |
+
# avoid keyword arguments to speed up parsing, saves about 15%-20% for very
|
| 38 |
+
# small reductions
|
| 39 |
+
def _amax(a, axis=None, out=None, keepdims=False,
|
| 40 |
+
initial=_NoValue, where=True):
|
| 41 |
+
return umr_maximum(a, axis, None, out, keepdims, initial, where)
|
| 42 |
+
|
| 43 |
+
def _amin(a, axis=None, out=None, keepdims=False,
|
| 44 |
+
initial=_NoValue, where=True):
|
| 45 |
+
return umr_minimum(a, axis, None, out, keepdims, initial, where)
|
| 46 |
+
|
| 47 |
+
def _sum(a, axis=None, dtype=None, out=None, keepdims=False,
|
| 48 |
+
initial=_NoValue, where=True):
|
| 49 |
+
return umr_sum(a, axis, dtype, out, keepdims, initial, where)
|
| 50 |
+
|
| 51 |
+
def _prod(a, axis=None, dtype=None, out=None, keepdims=False,
|
| 52 |
+
initial=_NoValue, where=True):
|
| 53 |
+
return umr_prod(a, axis, dtype, out, keepdims, initial, where)
|
| 54 |
+
|
| 55 |
+
def _any(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True):
|
| 56 |
+
# Parsing keyword arguments is currently fairly slow, so avoid it for now
|
| 57 |
+
if where is True:
|
| 58 |
+
return umr_any(a, axis, dtype, out, keepdims)
|
| 59 |
+
return umr_any(a, axis, dtype, out, keepdims, where=where)
|
| 60 |
+
|
| 61 |
+
def _all(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True):
|
| 62 |
+
# Parsing keyword arguments is currently fairly slow, so avoid it for now
|
| 63 |
+
if where is True:
|
| 64 |
+
return umr_all(a, axis, dtype, out, keepdims)
|
| 65 |
+
return umr_all(a, axis, dtype, out, keepdims, where=where)
|
| 66 |
+
|
| 67 |
+
def _count_reduce_items(arr, axis, keepdims=False, where=True):
|
| 68 |
+
# fast-path for the default case
|
| 69 |
+
if where is True:
|
| 70 |
+
# no boolean mask given, calculate items according to axis
|
| 71 |
+
if axis is None:
|
| 72 |
+
axis = tuple(range(arr.ndim))
|
| 73 |
+
elif not isinstance(axis, tuple):
|
| 74 |
+
axis = (axis,)
|
| 75 |
+
items = 1
|
| 76 |
+
for ax in axis:
|
| 77 |
+
items *= arr.shape[mu.normalize_axis_index(ax, arr.ndim)]
|
| 78 |
+
items = nt.intp(items)
|
| 79 |
+
else:
|
| 80 |
+
# TODO: Optimize case when `where` is broadcast along a non-reduction
|
| 81 |
+
# axis and full sum is more excessive than needed.
|
| 82 |
+
|
| 83 |
+
# guarded to protect circular imports
|
| 84 |
+
from numpy.lib.stride_tricks import broadcast_to
|
| 85 |
+
# count True values in (potentially broadcasted) boolean mask
|
| 86 |
+
items = umr_sum(broadcast_to(where, arr.shape), axis, nt.intp, None,
|
| 87 |
+
keepdims)
|
| 88 |
+
return items
|
| 89 |
+
|
| 90 |
+
def _clip(a, min=None, max=None, out=None, **kwargs):
|
| 91 |
+
if min is None and max is None:
|
| 92 |
+
raise ValueError("One of max or min must be given")
|
| 93 |
+
|
| 94 |
+
if min is None:
|
| 95 |
+
return um.minimum(a, max, out=out, **kwargs)
|
| 96 |
+
elif max is None:
|
| 97 |
+
return um.maximum(a, min, out=out, **kwargs)
|
| 98 |
+
else:
|
| 99 |
+
return um.clip(a, min, max, out=out, **kwargs)
|
| 100 |
+
|
| 101 |
+
def _mean(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True):
|
| 102 |
+
arr = asanyarray(a)
|
| 103 |
+
|
| 104 |
+
is_float16_result = False
|
| 105 |
+
|
| 106 |
+
rcount = _count_reduce_items(arr, axis, keepdims=keepdims, where=where)
|
| 107 |
+
if rcount == 0 if where is True else umr_any(rcount == 0, axis=None):
|
| 108 |
+
warnings.warn("Mean of empty slice.", RuntimeWarning, stacklevel=2)
|
| 109 |
+
|
| 110 |
+
# Cast bool, unsigned int, and int to float64 by default
|
| 111 |
+
if dtype is None:
|
| 112 |
+
if issubclass(arr.dtype.type, (nt.integer, nt.bool_)):
|
| 113 |
+
dtype = mu.dtype('f8')
|
| 114 |
+
elif issubclass(arr.dtype.type, nt.float16):
|
| 115 |
+
dtype = mu.dtype('f4')
|
| 116 |
+
is_float16_result = True
|
| 117 |
+
|
| 118 |
+
ret = umr_sum(arr, axis, dtype, out, keepdims, where=where)
|
| 119 |
+
if isinstance(ret, mu.ndarray):
|
| 120 |
+
with _no_nep50_warning():
|
| 121 |
+
ret = um.true_divide(
|
| 122 |
+
ret, rcount, out=ret, casting='unsafe', subok=False)
|
| 123 |
+
if is_float16_result and out is None:
|
| 124 |
+
ret = arr.dtype.type(ret)
|
| 125 |
+
elif hasattr(ret, 'dtype'):
|
| 126 |
+
if is_float16_result:
|
| 127 |
+
ret = arr.dtype.type(ret / rcount)
|
| 128 |
+
else:
|
| 129 |
+
ret = ret.dtype.type(ret / rcount)
|
| 130 |
+
else:
|
| 131 |
+
ret = ret / rcount
|
| 132 |
+
|
| 133 |
+
return ret
|
| 134 |
+
|
| 135 |
+
def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *,
|
| 136 |
+
where=True):
|
| 137 |
+
arr = asanyarray(a)
|
| 138 |
+
|
| 139 |
+
rcount = _count_reduce_items(arr, axis, keepdims=keepdims, where=where)
|
| 140 |
+
# Make this warning show up on top.
|
| 141 |
+
if ddof >= rcount if where is True else umr_any(ddof >= rcount, axis=None):
|
| 142 |
+
warnings.warn("Degrees of freedom <= 0 for slice", RuntimeWarning,
|
| 143 |
+
stacklevel=2)
|
| 144 |
+
|
| 145 |
+
# Cast bool, unsigned int, and int to float64 by default
|
| 146 |
+
if dtype is None and issubclass(arr.dtype.type, (nt.integer, nt.bool_)):
|
| 147 |
+
dtype = mu.dtype('f8')
|
| 148 |
+
|
| 149 |
+
# Compute the mean.
|
| 150 |
+
# Note that if dtype is not of inexact type then arraymean will
|
| 151 |
+
# not be either.
|
| 152 |
+
arrmean = umr_sum(arr, axis, dtype, keepdims=True, where=where)
|
| 153 |
+
# The shape of rcount has to match arrmean to not change the shape of out
|
| 154 |
+
# in broadcasting. Otherwise, it cannot be stored back to arrmean.
|
| 155 |
+
if rcount.ndim == 0:
|
| 156 |
+
# fast-path for default case when where is True
|
| 157 |
+
div = rcount
|
| 158 |
+
else:
|
| 159 |
+
# matching rcount to arrmean when where is specified as array
|
| 160 |
+
div = rcount.reshape(arrmean.shape)
|
| 161 |
+
if isinstance(arrmean, mu.ndarray):
|
| 162 |
+
with _no_nep50_warning():
|
| 163 |
+
arrmean = um.true_divide(arrmean, div, out=arrmean,
|
| 164 |
+
casting='unsafe', subok=False)
|
| 165 |
+
elif hasattr(arrmean, "dtype"):
|
| 166 |
+
arrmean = arrmean.dtype.type(arrmean / rcount)
|
| 167 |
+
else:
|
| 168 |
+
arrmean = arrmean / rcount
|
| 169 |
+
|
| 170 |
+
# Compute sum of squared deviations from mean
|
| 171 |
+
# Note that x may not be inexact and that we need it to be an array,
|
| 172 |
+
# not a scalar.
|
| 173 |
+
x = asanyarray(arr - arrmean)
|
| 174 |
+
|
| 175 |
+
if issubclass(arr.dtype.type, (nt.floating, nt.integer)):
|
| 176 |
+
x = um.multiply(x, x, out=x)
|
| 177 |
+
# Fast-paths for built-in complex types
|
| 178 |
+
elif x.dtype in _complex_to_float:
|
| 179 |
+
xv = x.view(dtype=(_complex_to_float[x.dtype], (2,)))
|
| 180 |
+
um.multiply(xv, xv, out=xv)
|
| 181 |
+
x = um.add(xv[..., 0], xv[..., 1], out=x.real).real
|
| 182 |
+
# Most general case; includes handling object arrays containing imaginary
|
| 183 |
+
# numbers and complex types with non-native byteorder
|
| 184 |
+
else:
|
| 185 |
+
x = um.multiply(x, um.conjugate(x), out=x).real
|
| 186 |
+
|
| 187 |
+
ret = umr_sum(x, axis, dtype, out, keepdims=keepdims, where=where)
|
| 188 |
+
|
| 189 |
+
# Compute degrees of freedom and make sure it is not negative.
|
| 190 |
+
rcount = um.maximum(rcount - ddof, 0)
|
| 191 |
+
|
| 192 |
+
# divide by degrees of freedom
|
| 193 |
+
if isinstance(ret, mu.ndarray):
|
| 194 |
+
with _no_nep50_warning():
|
| 195 |
+
ret = um.true_divide(
|
| 196 |
+
ret, rcount, out=ret, casting='unsafe', subok=False)
|
| 197 |
+
elif hasattr(ret, 'dtype'):
|
| 198 |
+
ret = ret.dtype.type(ret / rcount)
|
| 199 |
+
else:
|
| 200 |
+
ret = ret / rcount
|
| 201 |
+
|
| 202 |
+
return ret
|
| 203 |
+
|
| 204 |
+
def _std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *,
|
| 205 |
+
where=True):
|
| 206 |
+
ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
|
| 207 |
+
keepdims=keepdims, where=where)
|
| 208 |
+
|
| 209 |
+
if isinstance(ret, mu.ndarray):
|
| 210 |
+
ret = um.sqrt(ret, out=ret)
|
| 211 |
+
elif hasattr(ret, 'dtype'):
|
| 212 |
+
ret = ret.dtype.type(um.sqrt(ret))
|
| 213 |
+
else:
|
| 214 |
+
ret = um.sqrt(ret)
|
| 215 |
+
|
| 216 |
+
return ret
|
| 217 |
+
|
| 218 |
+
def _ptp(a, axis=None, out=None, keepdims=False):
|
| 219 |
+
return um.subtract(
|
| 220 |
+
umr_maximum(a, axis, None, out, keepdims),
|
| 221 |
+
umr_minimum(a, axis, None, None, keepdims),
|
| 222 |
+
out
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
def _dump(self, file, protocol=2):
|
| 226 |
+
if hasattr(file, 'write'):
|
| 227 |
+
ctx = nullcontext(file)
|
| 228 |
+
else:
|
| 229 |
+
ctx = open(os_fspath(file), "wb")
|
| 230 |
+
with ctx as f:
|
| 231 |
+
pickle.dump(self, f, protocol=protocol)
|
| 232 |
+
|
| 233 |
+
def _dumps(self, protocol=2):
|
| 234 |
+
return pickle.dumps(self, protocol=protocol)
|
.venv/lib/python3.11/site-packages/numpy/core/_operand_flag_tests.cpython-311-x86_64-linux-gnu.so
ADDED
|
Binary file (16.9 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/core/_rational_tests.cpython-311-x86_64-linux-gnu.so
ADDED
|
Binary file (59.8 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/core/_string_helpers.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
String-handling utilities to avoid locale-dependence.
|
| 3 |
+
|
| 4 |
+
Used primarily to generate type name aliases.
|
| 5 |
+
"""
|
| 6 |
+
# "import string" is costly to import!
|
| 7 |
+
# Construct the translation tables directly
|
| 8 |
+
# "A" = chr(65), "a" = chr(97)
|
| 9 |
+
_all_chars = tuple(map(chr, range(256)))
|
| 10 |
+
_ascii_upper = _all_chars[65:65+26]
|
| 11 |
+
_ascii_lower = _all_chars[97:97+26]
|
| 12 |
+
LOWER_TABLE = "".join(_all_chars[:65] + _ascii_lower + _all_chars[65+26:])
|
| 13 |
+
UPPER_TABLE = "".join(_all_chars[:97] + _ascii_upper + _all_chars[97+26:])
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def english_lower(s):
|
| 17 |
+
""" Apply English case rules to convert ASCII strings to all lower case.
|
| 18 |
+
|
| 19 |
+
This is an internal utility function to replace calls to str.lower() such
|
| 20 |
+
that we can avoid changing behavior with changing locales. In particular,
|
| 21 |
+
Turkish has distinct dotted and dotless variants of the Latin letter "I" in
|
| 22 |
+
both lowercase and uppercase. Thus, "I".lower() != "i" in a "tr" locale.
|
| 23 |
+
|
| 24 |
+
Parameters
|
| 25 |
+
----------
|
| 26 |
+
s : str
|
| 27 |
+
|
| 28 |
+
Returns
|
| 29 |
+
-------
|
| 30 |
+
lowered : str
|
| 31 |
+
|
| 32 |
+
Examples
|
| 33 |
+
--------
|
| 34 |
+
>>> from numpy.core.numerictypes import english_lower
|
| 35 |
+
>>> english_lower('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_')
|
| 36 |
+
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789_'
|
| 37 |
+
>>> english_lower('')
|
| 38 |
+
''
|
| 39 |
+
"""
|
| 40 |
+
lowered = s.translate(LOWER_TABLE)
|
| 41 |
+
return lowered
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def english_upper(s):
|
| 45 |
+
""" Apply English case rules to convert ASCII strings to all upper case.
|
| 46 |
+
|
| 47 |
+
This is an internal utility function to replace calls to str.upper() such
|
| 48 |
+
that we can avoid changing behavior with changing locales. In particular,
|
| 49 |
+
Turkish has distinct dotted and dotless variants of the Latin letter "I" in
|
| 50 |
+
both lowercase and uppercase. Thus, "i".upper() != "I" in a "tr" locale.
|
| 51 |
+
|
| 52 |
+
Parameters
|
| 53 |
+
----------
|
| 54 |
+
s : str
|
| 55 |
+
|
| 56 |
+
Returns
|
| 57 |
+
-------
|
| 58 |
+
uppered : str
|
| 59 |
+
|
| 60 |
+
Examples
|
| 61 |
+
--------
|
| 62 |
+
>>> from numpy.core.numerictypes import english_upper
|
| 63 |
+
>>> english_upper('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_')
|
| 64 |
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
|
| 65 |
+
>>> english_upper('')
|
| 66 |
+
''
|
| 67 |
+
"""
|
| 68 |
+
uppered = s.translate(UPPER_TABLE)
|
| 69 |
+
return uppered
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def english_capitalize(s):
|
| 73 |
+
""" Apply English case rules to convert the first character of an ASCII
|
| 74 |
+
string to upper case.
|
| 75 |
+
|
| 76 |
+
This is an internal utility function to replace calls to str.capitalize()
|
| 77 |
+
such that we can avoid changing behavior with changing locales.
|
| 78 |
+
|
| 79 |
+
Parameters
|
| 80 |
+
----------
|
| 81 |
+
s : str
|
| 82 |
+
|
| 83 |
+
Returns
|
| 84 |
+
-------
|
| 85 |
+
capitalized : str
|
| 86 |
+
|
| 87 |
+
Examples
|
| 88 |
+
--------
|
| 89 |
+
>>> from numpy.core.numerictypes import english_capitalize
|
| 90 |
+
>>> english_capitalize('int8')
|
| 91 |
+
'Int8'
|
| 92 |
+
>>> english_capitalize('Int8')
|
| 93 |
+
'Int8'
|
| 94 |
+
>>> english_capitalize('')
|
| 95 |
+
''
|
| 96 |
+
"""
|
| 97 |
+
if s:
|
| 98 |
+
return english_upper(s[0]) + s[1:]
|
| 99 |
+
else:
|
| 100 |
+
return s
|
.venv/lib/python3.11/site-packages/numpy/core/_struct_ufunc_tests.cpython-311-x86_64-linux-gnu.so
ADDED
|
Binary file (17 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/core/_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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Due to compatibility, numpy has a very large number of different naming
|
| 3 |
+
conventions for the scalar types (those subclassing from `numpy.generic`).
|
| 4 |
+
This file produces a convoluted set of dictionaries mapping names to types,
|
| 5 |
+
and sometimes other mappings too.
|
| 6 |
+
|
| 7 |
+
.. data:: allTypes
|
| 8 |
+
A dictionary of names to types that will be exposed as attributes through
|
| 9 |
+
``np.core.numerictypes.*``
|
| 10 |
+
|
| 11 |
+
.. data:: sctypeDict
|
| 12 |
+
Similar to `allTypes`, but maps a broader set of aliases to their types.
|
| 13 |
+
|
| 14 |
+
.. data:: sctypes
|
| 15 |
+
A dictionary keyed by a "type group" string, providing a list of types
|
| 16 |
+
under that group.
|
| 17 |
+
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
from numpy.compat import unicode
|
| 21 |
+
from numpy.core._string_helpers import english_lower
|
| 22 |
+
from numpy.core.multiarray import typeinfo, dtype
|
| 23 |
+
from numpy.core._dtype import _kind_name
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
sctypeDict = {} # Contains all leaf-node scalar types with aliases
|
| 27 |
+
allTypes = {} # Collect the types we will add to the module
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# separate the actual type info from the abstract base classes
|
| 31 |
+
_abstract_types = {}
|
| 32 |
+
_concrete_typeinfo = {}
|
| 33 |
+
for k, v in typeinfo.items():
|
| 34 |
+
# make all the keys lowercase too
|
| 35 |
+
k = english_lower(k)
|
| 36 |
+
if isinstance(v, type):
|
| 37 |
+
_abstract_types[k] = v
|
| 38 |
+
else:
|
| 39 |
+
_concrete_typeinfo[k] = v
|
| 40 |
+
|
| 41 |
+
_concrete_types = {v.type for k, v in _concrete_typeinfo.items()}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def _bits_of(obj):
|
| 45 |
+
try:
|
| 46 |
+
info = next(v for v in _concrete_typeinfo.values() if v.type is obj)
|
| 47 |
+
except StopIteration:
|
| 48 |
+
if obj in _abstract_types.values():
|
| 49 |
+
msg = "Cannot count the bits of an abstract type"
|
| 50 |
+
raise ValueError(msg) from None
|
| 51 |
+
|
| 52 |
+
# some third-party type - make a best-guess
|
| 53 |
+
return dtype(obj).itemsize * 8
|
| 54 |
+
else:
|
| 55 |
+
return info.bits
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def bitname(obj):
|
| 59 |
+
"""Return a bit-width name for a given type object"""
|
| 60 |
+
bits = _bits_of(obj)
|
| 61 |
+
dt = dtype(obj)
|
| 62 |
+
char = dt.kind
|
| 63 |
+
base = _kind_name(dt)
|
| 64 |
+
|
| 65 |
+
if base == 'object':
|
| 66 |
+
bits = 0
|
| 67 |
+
|
| 68 |
+
if bits != 0:
|
| 69 |
+
char = "%s%d" % (char, bits // 8)
|
| 70 |
+
|
| 71 |
+
return base, bits, char
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _add_types():
|
| 75 |
+
for name, info in _concrete_typeinfo.items():
|
| 76 |
+
# define C-name and insert typenum and typechar references also
|
| 77 |
+
allTypes[name] = info.type
|
| 78 |
+
sctypeDict[name] = info.type
|
| 79 |
+
sctypeDict[info.char] = info.type
|
| 80 |
+
sctypeDict[info.num] = info.type
|
| 81 |
+
|
| 82 |
+
for name, cls in _abstract_types.items():
|
| 83 |
+
allTypes[name] = cls
|
| 84 |
+
_add_types()
|
| 85 |
+
|
| 86 |
+
# This is the priority order used to assign the bit-sized NPY_INTxx names, which
|
| 87 |
+
# must match the order in npy_common.h in order for NPY_INTxx and np.intxx to be
|
| 88 |
+
# consistent.
|
| 89 |
+
# If two C types have the same size, then the earliest one in this list is used
|
| 90 |
+
# as the sized name.
|
| 91 |
+
_int_ctypes = ['long', 'longlong', 'int', 'short', 'byte']
|
| 92 |
+
_uint_ctypes = list('u' + t for t in _int_ctypes)
|
| 93 |
+
|
| 94 |
+
def _add_aliases():
|
| 95 |
+
for name, info in _concrete_typeinfo.items():
|
| 96 |
+
# these are handled by _add_integer_aliases
|
| 97 |
+
if name in _int_ctypes or name in _uint_ctypes:
|
| 98 |
+
continue
|
| 99 |
+
|
| 100 |
+
# insert bit-width version for this class (if relevant)
|
| 101 |
+
base, bit, char = bitname(info.type)
|
| 102 |
+
|
| 103 |
+
myname = "%s%d" % (base, bit)
|
| 104 |
+
|
| 105 |
+
# ensure that (c)longdouble does not overwrite the aliases assigned to
|
| 106 |
+
# (c)double
|
| 107 |
+
if name in ('longdouble', 'clongdouble') and myname in allTypes:
|
| 108 |
+
continue
|
| 109 |
+
|
| 110 |
+
# Add to the main namespace if desired:
|
| 111 |
+
if bit != 0 and base != "bool":
|
| 112 |
+
allTypes[myname] = info.type
|
| 113 |
+
|
| 114 |
+
# add forward, reverse, and string mapping to numarray
|
| 115 |
+
sctypeDict[char] = info.type
|
| 116 |
+
|
| 117 |
+
# add mapping for both the bit name
|
| 118 |
+
sctypeDict[myname] = info.type
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
_add_aliases()
|
| 122 |
+
|
| 123 |
+
def _add_integer_aliases():
|
| 124 |
+
seen_bits = set()
|
| 125 |
+
for i_ctype, u_ctype in zip(_int_ctypes, _uint_ctypes):
|
| 126 |
+
i_info = _concrete_typeinfo[i_ctype]
|
| 127 |
+
u_info = _concrete_typeinfo[u_ctype]
|
| 128 |
+
bits = i_info.bits # same for both
|
| 129 |
+
|
| 130 |
+
for info, charname, intname in [
|
| 131 |
+
(i_info,'i%d' % (bits//8,), 'int%d' % bits),
|
| 132 |
+
(u_info,'u%d' % (bits//8,), 'uint%d' % bits)]:
|
| 133 |
+
if bits not in seen_bits:
|
| 134 |
+
# sometimes two different types have the same number of bits
|
| 135 |
+
# if so, the one iterated over first takes precedence
|
| 136 |
+
allTypes[intname] = info.type
|
| 137 |
+
sctypeDict[intname] = info.type
|
| 138 |
+
sctypeDict[charname] = info.type
|
| 139 |
+
|
| 140 |
+
seen_bits.add(bits)
|
| 141 |
+
|
| 142 |
+
_add_integer_aliases()
|
| 143 |
+
|
| 144 |
+
# We use these later
|
| 145 |
+
void = allTypes['void']
|
| 146 |
+
|
| 147 |
+
#
|
| 148 |
+
# Rework the Python names (so that float and complex and int are consistent
|
| 149 |
+
# with Python usage)
|
| 150 |
+
#
|
| 151 |
+
def _set_up_aliases():
|
| 152 |
+
type_pairs = [('complex_', 'cdouble'),
|
| 153 |
+
('single', 'float'),
|
| 154 |
+
('csingle', 'cfloat'),
|
| 155 |
+
('singlecomplex', 'cfloat'),
|
| 156 |
+
('float_', 'double'),
|
| 157 |
+
('intc', 'int'),
|
| 158 |
+
('uintc', 'uint'),
|
| 159 |
+
('int_', 'long'),
|
| 160 |
+
('uint', 'ulong'),
|
| 161 |
+
('cfloat', 'cdouble'),
|
| 162 |
+
('longfloat', 'longdouble'),
|
| 163 |
+
('clongfloat', 'clongdouble'),
|
| 164 |
+
('longcomplex', 'clongdouble'),
|
| 165 |
+
('bool_', 'bool'),
|
| 166 |
+
('bytes_', 'string'),
|
| 167 |
+
('string_', 'string'),
|
| 168 |
+
('str_', 'unicode'),
|
| 169 |
+
('unicode_', 'unicode'),
|
| 170 |
+
('object_', 'object')]
|
| 171 |
+
for alias, t in type_pairs:
|
| 172 |
+
allTypes[alias] = allTypes[t]
|
| 173 |
+
sctypeDict[alias] = sctypeDict[t]
|
| 174 |
+
# Remove aliases overriding python types and modules
|
| 175 |
+
to_remove = ['object', 'int', 'float',
|
| 176 |
+
'complex', 'bool', 'string', 'datetime', 'timedelta',
|
| 177 |
+
'bytes', 'str']
|
| 178 |
+
|
| 179 |
+
for t in to_remove:
|
| 180 |
+
try:
|
| 181 |
+
del allTypes[t]
|
| 182 |
+
del sctypeDict[t]
|
| 183 |
+
except KeyError:
|
| 184 |
+
pass
|
| 185 |
+
|
| 186 |
+
# Additional aliases in sctypeDict that should not be exposed as attributes
|
| 187 |
+
attrs_to_remove = ['ulong']
|
| 188 |
+
|
| 189 |
+
for t in attrs_to_remove:
|
| 190 |
+
try:
|
| 191 |
+
del allTypes[t]
|
| 192 |
+
except KeyError:
|
| 193 |
+
pass
|
| 194 |
+
_set_up_aliases()
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
sctypes = {'int': [],
|
| 198 |
+
'uint':[],
|
| 199 |
+
'float':[],
|
| 200 |
+
'complex':[],
|
| 201 |
+
'others':[bool, object, bytes, unicode, void]}
|
| 202 |
+
|
| 203 |
+
def _add_array_type(typename, bits):
|
| 204 |
+
try:
|
| 205 |
+
t = allTypes['%s%d' % (typename, bits)]
|
| 206 |
+
except KeyError:
|
| 207 |
+
pass
|
| 208 |
+
else:
|
| 209 |
+
sctypes[typename].append(t)
|
| 210 |
+
|
| 211 |
+
def _set_array_types():
|
| 212 |
+
ibytes = [1, 2, 4, 8, 16, 32, 64]
|
| 213 |
+
fbytes = [2, 4, 8, 10, 12, 16, 32, 64]
|
| 214 |
+
for bytes in ibytes:
|
| 215 |
+
bits = 8*bytes
|
| 216 |
+
_add_array_type('int', bits)
|
| 217 |
+
_add_array_type('uint', bits)
|
| 218 |
+
for bytes in fbytes:
|
| 219 |
+
bits = 8*bytes
|
| 220 |
+
_add_array_type('float', bits)
|
| 221 |
+
_add_array_type('complex', 2*bits)
|
| 222 |
+
_gi = dtype('p')
|
| 223 |
+
if _gi.type not in sctypes['int']:
|
| 224 |
+
indx = 0
|
| 225 |
+
sz = _gi.itemsize
|
| 226 |
+
_lst = sctypes['int']
|
| 227 |
+
while (indx < len(_lst) and sz >= _lst[indx](0).itemsize):
|
| 228 |
+
indx += 1
|
| 229 |
+
sctypes['int'].insert(indx, _gi.type)
|
| 230 |
+
sctypes['uint'].insert(indx, dtype('P').type)
|
| 231 |
+
_set_array_types()
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
# Add additional strings to the sctypeDict
|
| 235 |
+
_toadd = ['int', 'float', 'complex', 'bool', 'object',
|
| 236 |
+
'str', 'bytes', ('a', 'bytes_'),
|
| 237 |
+
('int0', 'intp'), ('uint0', 'uintp')]
|
| 238 |
+
|
| 239 |
+
for name in _toadd:
|
| 240 |
+
if isinstance(name, tuple):
|
| 241 |
+
sctypeDict[name[0]] = allTypes[name[1]]
|
| 242 |
+
else:
|
| 243 |
+
sctypeDict[name] = allTypes['%s_' % name]
|
| 244 |
+
|
| 245 |
+
del _toadd, name
|
.venv/lib/python3.11/site-packages/numpy/core/_ufunc_config.py
ADDED
|
@@ -0,0 +1,466 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Functions for changing global ufunc configuration
|
| 3 |
+
|
| 4 |
+
This provides helpers which wrap `umath.geterrobj` and `umath.seterrobj`
|
| 5 |
+
"""
|
| 6 |
+
import collections.abc
|
| 7 |
+
import contextlib
|
| 8 |
+
import contextvars
|
| 9 |
+
|
| 10 |
+
from .._utils import set_module
|
| 11 |
+
from .umath import (
|
| 12 |
+
UFUNC_BUFSIZE_DEFAULT,
|
| 13 |
+
ERR_IGNORE, ERR_WARN, ERR_RAISE, ERR_CALL, ERR_PRINT, ERR_LOG, ERR_DEFAULT,
|
| 14 |
+
SHIFT_DIVIDEBYZERO, SHIFT_OVERFLOW, SHIFT_UNDERFLOW, SHIFT_INVALID,
|
| 15 |
+
)
|
| 16 |
+
from . import umath
|
| 17 |
+
|
| 18 |
+
__all__ = [
|
| 19 |
+
"seterr", "geterr", "setbufsize", "getbufsize", "seterrcall", "geterrcall",
|
| 20 |
+
"errstate", '_no_nep50_warning'
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
_errdict = {"ignore": ERR_IGNORE,
|
| 24 |
+
"warn": ERR_WARN,
|
| 25 |
+
"raise": ERR_RAISE,
|
| 26 |
+
"call": ERR_CALL,
|
| 27 |
+
"print": ERR_PRINT,
|
| 28 |
+
"log": ERR_LOG}
|
| 29 |
+
|
| 30 |
+
_errdict_rev = {value: key for key, value in _errdict.items()}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@set_module('numpy')
|
| 34 |
+
def seterr(all=None, divide=None, over=None, under=None, invalid=None):
|
| 35 |
+
"""
|
| 36 |
+
Set how floating-point errors are handled.
|
| 37 |
+
|
| 38 |
+
Note that operations on integer scalar types (such as `int16`) are
|
| 39 |
+
handled like floating point, and are affected by these settings.
|
| 40 |
+
|
| 41 |
+
Parameters
|
| 42 |
+
----------
|
| 43 |
+
all : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
|
| 44 |
+
Set treatment for all types of floating-point errors at once:
|
| 45 |
+
|
| 46 |
+
- ignore: Take no action when the exception occurs.
|
| 47 |
+
- warn: Print a `RuntimeWarning` (via the Python `warnings` module).
|
| 48 |
+
- raise: Raise a `FloatingPointError`.
|
| 49 |
+
- call: Call a function specified using the `seterrcall` function.
|
| 50 |
+
- print: Print a warning directly to ``stdout``.
|
| 51 |
+
- log: Record error in a Log object specified by `seterrcall`.
|
| 52 |
+
|
| 53 |
+
The default is not to change the current behavior.
|
| 54 |
+
divide : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
|
| 55 |
+
Treatment for division by zero.
|
| 56 |
+
over : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
|
| 57 |
+
Treatment for floating-point overflow.
|
| 58 |
+
under : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
|
| 59 |
+
Treatment for floating-point underflow.
|
| 60 |
+
invalid : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
|
| 61 |
+
Treatment for invalid floating-point operation.
|
| 62 |
+
|
| 63 |
+
Returns
|
| 64 |
+
-------
|
| 65 |
+
old_settings : dict
|
| 66 |
+
Dictionary containing the old settings.
|
| 67 |
+
|
| 68 |
+
See also
|
| 69 |
+
--------
|
| 70 |
+
seterrcall : Set a callback function for the 'call' mode.
|
| 71 |
+
geterr, geterrcall, errstate
|
| 72 |
+
|
| 73 |
+
Notes
|
| 74 |
+
-----
|
| 75 |
+
The floating-point exceptions are defined in the IEEE 754 standard [1]_:
|
| 76 |
+
|
| 77 |
+
- Division by zero: infinite result obtained from finite numbers.
|
| 78 |
+
- Overflow: result too large to be expressed.
|
| 79 |
+
- Underflow: result so close to zero that some precision
|
| 80 |
+
was lost.
|
| 81 |
+
- Invalid operation: result is not an expressible number, typically
|
| 82 |
+
indicates that a NaN was produced.
|
| 83 |
+
|
| 84 |
+
.. [1] https://en.wikipedia.org/wiki/IEEE_754
|
| 85 |
+
|
| 86 |
+
Examples
|
| 87 |
+
--------
|
| 88 |
+
>>> old_settings = np.seterr(all='ignore') #seterr to known value
|
| 89 |
+
>>> np.seterr(over='raise')
|
| 90 |
+
{'divide': 'ignore', 'over': 'ignore', 'under': 'ignore', 'invalid': 'ignore'}
|
| 91 |
+
>>> np.seterr(**old_settings) # reset to default
|
| 92 |
+
{'divide': 'ignore', 'over': 'raise', 'under': 'ignore', 'invalid': 'ignore'}
|
| 93 |
+
|
| 94 |
+
>>> np.int16(32000) * np.int16(3)
|
| 95 |
+
30464
|
| 96 |
+
>>> old_settings = np.seterr(all='warn', over='raise')
|
| 97 |
+
>>> np.int16(32000) * np.int16(3)
|
| 98 |
+
Traceback (most recent call last):
|
| 99 |
+
File "<stdin>", line 1, in <module>
|
| 100 |
+
FloatingPointError: overflow encountered in scalar multiply
|
| 101 |
+
|
| 102 |
+
>>> old_settings = np.seterr(all='print')
|
| 103 |
+
>>> np.geterr()
|
| 104 |
+
{'divide': 'print', 'over': 'print', 'under': 'print', 'invalid': 'print'}
|
| 105 |
+
>>> np.int16(32000) * np.int16(3)
|
| 106 |
+
30464
|
| 107 |
+
|
| 108 |
+
"""
|
| 109 |
+
|
| 110 |
+
pyvals = umath.geterrobj()
|
| 111 |
+
old = geterr()
|
| 112 |
+
|
| 113 |
+
if divide is None:
|
| 114 |
+
divide = all or old['divide']
|
| 115 |
+
if over is None:
|
| 116 |
+
over = all or old['over']
|
| 117 |
+
if under is None:
|
| 118 |
+
under = all or old['under']
|
| 119 |
+
if invalid is None:
|
| 120 |
+
invalid = all or old['invalid']
|
| 121 |
+
|
| 122 |
+
maskvalue = ((_errdict[divide] << SHIFT_DIVIDEBYZERO) +
|
| 123 |
+
(_errdict[over] << SHIFT_OVERFLOW) +
|
| 124 |
+
(_errdict[under] << SHIFT_UNDERFLOW) +
|
| 125 |
+
(_errdict[invalid] << SHIFT_INVALID))
|
| 126 |
+
|
| 127 |
+
pyvals[1] = maskvalue
|
| 128 |
+
umath.seterrobj(pyvals)
|
| 129 |
+
return old
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
@set_module('numpy')
|
| 133 |
+
def geterr():
|
| 134 |
+
"""
|
| 135 |
+
Get the current way of handling floating-point errors.
|
| 136 |
+
|
| 137 |
+
Returns
|
| 138 |
+
-------
|
| 139 |
+
res : dict
|
| 140 |
+
A dictionary with keys "divide", "over", "under", and "invalid",
|
| 141 |
+
whose values are from the strings "ignore", "print", "log", "warn",
|
| 142 |
+
"raise", and "call". The keys represent possible floating-point
|
| 143 |
+
exceptions, and the values define how these exceptions are handled.
|
| 144 |
+
|
| 145 |
+
See Also
|
| 146 |
+
--------
|
| 147 |
+
geterrcall, seterr, seterrcall
|
| 148 |
+
|
| 149 |
+
Notes
|
| 150 |
+
-----
|
| 151 |
+
For complete documentation of the types of floating-point exceptions and
|
| 152 |
+
treatment options, see `seterr`.
|
| 153 |
+
|
| 154 |
+
Examples
|
| 155 |
+
--------
|
| 156 |
+
>>> np.geterr()
|
| 157 |
+
{'divide': 'warn', 'over': 'warn', 'under': 'ignore', 'invalid': 'warn'}
|
| 158 |
+
>>> np.arange(3.) / np.arange(3.)
|
| 159 |
+
array([nan, 1., 1.])
|
| 160 |
+
|
| 161 |
+
>>> oldsettings = np.seterr(all='warn', over='raise')
|
| 162 |
+
>>> np.geterr()
|
| 163 |
+
{'divide': 'warn', 'over': 'raise', 'under': 'warn', 'invalid': 'warn'}
|
| 164 |
+
>>> np.arange(3.) / np.arange(3.)
|
| 165 |
+
array([nan, 1., 1.])
|
| 166 |
+
|
| 167 |
+
"""
|
| 168 |
+
maskvalue = umath.geterrobj()[1]
|
| 169 |
+
mask = 7
|
| 170 |
+
res = {}
|
| 171 |
+
val = (maskvalue >> SHIFT_DIVIDEBYZERO) & mask
|
| 172 |
+
res['divide'] = _errdict_rev[val]
|
| 173 |
+
val = (maskvalue >> SHIFT_OVERFLOW) & mask
|
| 174 |
+
res['over'] = _errdict_rev[val]
|
| 175 |
+
val = (maskvalue >> SHIFT_UNDERFLOW) & mask
|
| 176 |
+
res['under'] = _errdict_rev[val]
|
| 177 |
+
val = (maskvalue >> SHIFT_INVALID) & mask
|
| 178 |
+
res['invalid'] = _errdict_rev[val]
|
| 179 |
+
return res
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
@set_module('numpy')
|
| 183 |
+
def setbufsize(size):
|
| 184 |
+
"""
|
| 185 |
+
Set the size of the buffer used in ufuncs.
|
| 186 |
+
|
| 187 |
+
Parameters
|
| 188 |
+
----------
|
| 189 |
+
size : int
|
| 190 |
+
Size of buffer.
|
| 191 |
+
|
| 192 |
+
"""
|
| 193 |
+
if size > 10e6:
|
| 194 |
+
raise ValueError("Buffer size, %s, is too big." % size)
|
| 195 |
+
if size < 5:
|
| 196 |
+
raise ValueError("Buffer size, %s, is too small." % size)
|
| 197 |
+
if size % 16 != 0:
|
| 198 |
+
raise ValueError("Buffer size, %s, is not a multiple of 16." % size)
|
| 199 |
+
|
| 200 |
+
pyvals = umath.geterrobj()
|
| 201 |
+
old = getbufsize()
|
| 202 |
+
pyvals[0] = size
|
| 203 |
+
umath.seterrobj(pyvals)
|
| 204 |
+
return old
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
@set_module('numpy')
|
| 208 |
+
def getbufsize():
|
| 209 |
+
"""
|
| 210 |
+
Return the size of the buffer used in ufuncs.
|
| 211 |
+
|
| 212 |
+
Returns
|
| 213 |
+
-------
|
| 214 |
+
getbufsize : int
|
| 215 |
+
Size of ufunc buffer in bytes.
|
| 216 |
+
|
| 217 |
+
"""
|
| 218 |
+
return umath.geterrobj()[0]
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
@set_module('numpy')
|
| 222 |
+
def seterrcall(func):
|
| 223 |
+
"""
|
| 224 |
+
Set the floating-point error callback function or log object.
|
| 225 |
+
|
| 226 |
+
There are two ways to capture floating-point error messages. The first
|
| 227 |
+
is to set the error-handler to 'call', using `seterr`. Then, set
|
| 228 |
+
the function to call using this function.
|
| 229 |
+
|
| 230 |
+
The second is to set the error-handler to 'log', using `seterr`.
|
| 231 |
+
Floating-point errors then trigger a call to the 'write' method of
|
| 232 |
+
the provided object.
|
| 233 |
+
|
| 234 |
+
Parameters
|
| 235 |
+
----------
|
| 236 |
+
func : callable f(err, flag) or object with write method
|
| 237 |
+
Function to call upon floating-point errors ('call'-mode) or
|
| 238 |
+
object whose 'write' method is used to log such message ('log'-mode).
|
| 239 |
+
|
| 240 |
+
The call function takes two arguments. The first is a string describing
|
| 241 |
+
the type of error (such as "divide by zero", "overflow", "underflow",
|
| 242 |
+
or "invalid value"), and the second is the status flag. The flag is a
|
| 243 |
+
byte, whose four least-significant bits indicate the type of error, one
|
| 244 |
+
of "divide", "over", "under", "invalid"::
|
| 245 |
+
|
| 246 |
+
[0 0 0 0 divide over under invalid]
|
| 247 |
+
|
| 248 |
+
In other words, ``flags = divide + 2*over + 4*under + 8*invalid``.
|
| 249 |
+
|
| 250 |
+
If an object is provided, its write method should take one argument,
|
| 251 |
+
a string.
|
| 252 |
+
|
| 253 |
+
Returns
|
| 254 |
+
-------
|
| 255 |
+
h : callable, log instance or None
|
| 256 |
+
The old error handler.
|
| 257 |
+
|
| 258 |
+
See Also
|
| 259 |
+
--------
|
| 260 |
+
seterr, geterr, geterrcall
|
| 261 |
+
|
| 262 |
+
Examples
|
| 263 |
+
--------
|
| 264 |
+
Callback upon error:
|
| 265 |
+
|
| 266 |
+
>>> def err_handler(type, flag):
|
| 267 |
+
... print("Floating point error (%s), with flag %s" % (type, flag))
|
| 268 |
+
...
|
| 269 |
+
|
| 270 |
+
>>> saved_handler = np.seterrcall(err_handler)
|
| 271 |
+
>>> save_err = np.seterr(all='call')
|
| 272 |
+
|
| 273 |
+
>>> np.array([1, 2, 3]) / 0.0
|
| 274 |
+
Floating point error (divide by zero), with flag 1
|
| 275 |
+
array([inf, inf, inf])
|
| 276 |
+
|
| 277 |
+
>>> np.seterrcall(saved_handler)
|
| 278 |
+
<function err_handler at 0x...>
|
| 279 |
+
>>> np.seterr(**save_err)
|
| 280 |
+
{'divide': 'call', 'over': 'call', 'under': 'call', 'invalid': 'call'}
|
| 281 |
+
|
| 282 |
+
Log error message:
|
| 283 |
+
|
| 284 |
+
>>> class Log:
|
| 285 |
+
... def write(self, msg):
|
| 286 |
+
... print("LOG: %s" % msg)
|
| 287 |
+
...
|
| 288 |
+
|
| 289 |
+
>>> log = Log()
|
| 290 |
+
>>> saved_handler = np.seterrcall(log)
|
| 291 |
+
>>> save_err = np.seterr(all='log')
|
| 292 |
+
|
| 293 |
+
>>> np.array([1, 2, 3]) / 0.0
|
| 294 |
+
LOG: Warning: divide by zero encountered in divide
|
| 295 |
+
array([inf, inf, inf])
|
| 296 |
+
|
| 297 |
+
>>> np.seterrcall(saved_handler)
|
| 298 |
+
<numpy.core.numeric.Log object at 0x...>
|
| 299 |
+
>>> np.seterr(**save_err)
|
| 300 |
+
{'divide': 'log', 'over': 'log', 'under': 'log', 'invalid': 'log'}
|
| 301 |
+
|
| 302 |
+
"""
|
| 303 |
+
if func is not None and not isinstance(func, collections.abc.Callable):
|
| 304 |
+
if (not hasattr(func, 'write') or
|
| 305 |
+
not isinstance(func.write, collections.abc.Callable)):
|
| 306 |
+
raise ValueError("Only callable can be used as callback")
|
| 307 |
+
pyvals = umath.geterrobj()
|
| 308 |
+
old = geterrcall()
|
| 309 |
+
pyvals[2] = func
|
| 310 |
+
umath.seterrobj(pyvals)
|
| 311 |
+
return old
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
@set_module('numpy')
|
| 315 |
+
def geterrcall():
|
| 316 |
+
"""
|
| 317 |
+
Return the current callback function used on floating-point errors.
|
| 318 |
+
|
| 319 |
+
When the error handling for a floating-point error (one of "divide",
|
| 320 |
+
"over", "under", or "invalid") is set to 'call' or 'log', the function
|
| 321 |
+
that is called or the log instance that is written to is returned by
|
| 322 |
+
`geterrcall`. This function or log instance has been set with
|
| 323 |
+
`seterrcall`.
|
| 324 |
+
|
| 325 |
+
Returns
|
| 326 |
+
-------
|
| 327 |
+
errobj : callable, log instance or None
|
| 328 |
+
The current error handler. If no handler was set through `seterrcall`,
|
| 329 |
+
``None`` is returned.
|
| 330 |
+
|
| 331 |
+
See Also
|
| 332 |
+
--------
|
| 333 |
+
seterrcall, seterr, geterr
|
| 334 |
+
|
| 335 |
+
Notes
|
| 336 |
+
-----
|
| 337 |
+
For complete documentation of the types of floating-point exceptions and
|
| 338 |
+
treatment options, see `seterr`.
|
| 339 |
+
|
| 340 |
+
Examples
|
| 341 |
+
--------
|
| 342 |
+
>>> np.geterrcall() # we did not yet set a handler, returns None
|
| 343 |
+
|
| 344 |
+
>>> oldsettings = np.seterr(all='call')
|
| 345 |
+
>>> def err_handler(type, flag):
|
| 346 |
+
... print("Floating point error (%s), with flag %s" % (type, flag))
|
| 347 |
+
>>> oldhandler = np.seterrcall(err_handler)
|
| 348 |
+
>>> np.array([1, 2, 3]) / 0.0
|
| 349 |
+
Floating point error (divide by zero), with flag 1
|
| 350 |
+
array([inf, inf, inf])
|
| 351 |
+
|
| 352 |
+
>>> cur_handler = np.geterrcall()
|
| 353 |
+
>>> cur_handler is err_handler
|
| 354 |
+
True
|
| 355 |
+
|
| 356 |
+
"""
|
| 357 |
+
return umath.geterrobj()[2]
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
class _unspecified:
|
| 361 |
+
pass
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
_Unspecified = _unspecified()
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
@set_module('numpy')
|
| 368 |
+
class errstate(contextlib.ContextDecorator):
|
| 369 |
+
"""
|
| 370 |
+
errstate(**kwargs)
|
| 371 |
+
|
| 372 |
+
Context manager for floating-point error handling.
|
| 373 |
+
|
| 374 |
+
Using an instance of `errstate` as a context manager allows statements in
|
| 375 |
+
that context to execute with a known error handling behavior. Upon entering
|
| 376 |
+
the context the error handling is set with `seterr` and `seterrcall`, and
|
| 377 |
+
upon exiting it is reset to what it was before.
|
| 378 |
+
|
| 379 |
+
.. versionchanged:: 1.17.0
|
| 380 |
+
`errstate` is also usable as a function decorator, saving
|
| 381 |
+
a level of indentation if an entire function is wrapped.
|
| 382 |
+
See :py:class:`contextlib.ContextDecorator` for more information.
|
| 383 |
+
|
| 384 |
+
Parameters
|
| 385 |
+
----------
|
| 386 |
+
kwargs : {divide, over, under, invalid}
|
| 387 |
+
Keyword arguments. The valid keywords are the possible floating-point
|
| 388 |
+
exceptions. Each keyword should have a string value that defines the
|
| 389 |
+
treatment for the particular error. Possible values are
|
| 390 |
+
{'ignore', 'warn', 'raise', 'call', 'print', 'log'}.
|
| 391 |
+
|
| 392 |
+
See Also
|
| 393 |
+
--------
|
| 394 |
+
seterr, geterr, seterrcall, geterrcall
|
| 395 |
+
|
| 396 |
+
Notes
|
| 397 |
+
-----
|
| 398 |
+
For complete documentation of the types of floating-point exceptions and
|
| 399 |
+
treatment options, see `seterr`.
|
| 400 |
+
|
| 401 |
+
Examples
|
| 402 |
+
--------
|
| 403 |
+
>>> olderr = np.seterr(all='ignore') # Set error handling to known state.
|
| 404 |
+
|
| 405 |
+
>>> np.arange(3) / 0.
|
| 406 |
+
array([nan, inf, inf])
|
| 407 |
+
>>> with np.errstate(divide='warn'):
|
| 408 |
+
... np.arange(3) / 0.
|
| 409 |
+
array([nan, inf, inf])
|
| 410 |
+
|
| 411 |
+
>>> np.sqrt(-1)
|
| 412 |
+
nan
|
| 413 |
+
>>> with np.errstate(invalid='raise'):
|
| 414 |
+
... np.sqrt(-1)
|
| 415 |
+
Traceback (most recent call last):
|
| 416 |
+
File "<stdin>", line 2, in <module>
|
| 417 |
+
FloatingPointError: invalid value encountered in sqrt
|
| 418 |
+
|
| 419 |
+
Outside the context the error handling behavior has not changed:
|
| 420 |
+
|
| 421 |
+
>>> np.geterr()
|
| 422 |
+
{'divide': 'ignore', 'over': 'ignore', 'under': 'ignore', 'invalid': 'ignore'}
|
| 423 |
+
|
| 424 |
+
"""
|
| 425 |
+
|
| 426 |
+
def __init__(self, *, call=_Unspecified, **kwargs):
|
| 427 |
+
self.call = call
|
| 428 |
+
self.kwargs = kwargs
|
| 429 |
+
|
| 430 |
+
def __enter__(self):
|
| 431 |
+
self.oldstate = seterr(**self.kwargs)
|
| 432 |
+
if self.call is not _Unspecified:
|
| 433 |
+
self.oldcall = seterrcall(self.call)
|
| 434 |
+
|
| 435 |
+
def __exit__(self, *exc_info):
|
| 436 |
+
seterr(**self.oldstate)
|
| 437 |
+
if self.call is not _Unspecified:
|
| 438 |
+
seterrcall(self.oldcall)
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
def _setdef():
|
| 442 |
+
defval = [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT, None]
|
| 443 |
+
umath.seterrobj(defval)
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
# set the default values
|
| 447 |
+
_setdef()
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
NO_NEP50_WARNING = contextvars.ContextVar("_no_nep50_warning", default=False)
|
| 451 |
+
|
| 452 |
+
@set_module('numpy')
|
| 453 |
+
@contextlib.contextmanager
|
| 454 |
+
def _no_nep50_warning():
|
| 455 |
+
"""
|
| 456 |
+
Context manager to disable NEP 50 warnings. This context manager is
|
| 457 |
+
only relevant if the NEP 50 warnings are enabled globally (which is not
|
| 458 |
+
thread/context safe).
|
| 459 |
+
|
| 460 |
+
This warning context manager itself is fully safe, however.
|
| 461 |
+
"""
|
| 462 |
+
token = NO_NEP50_WARNING.set(True)
|
| 463 |
+
try:
|
| 464 |
+
yield
|
| 465 |
+
finally:
|
| 466 |
+
NO_NEP50_WARNING.reset(token)
|
.venv/lib/python3.11/site-packages/numpy/core/_ufunc_config.pyi
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Callable
|
| 2 |
+
from typing import Any, Literal, TypedDict
|
| 3 |
+
|
| 4 |
+
from numpy import _SupportsWrite
|
| 5 |
+
|
| 6 |
+
_ErrKind = Literal["ignore", "warn", "raise", "call", "print", "log"]
|
| 7 |
+
_ErrFunc = Callable[[str, int], Any]
|
| 8 |
+
|
| 9 |
+
class _ErrDict(TypedDict):
|
| 10 |
+
divide: _ErrKind
|
| 11 |
+
over: _ErrKind
|
| 12 |
+
under: _ErrKind
|
| 13 |
+
invalid: _ErrKind
|
| 14 |
+
|
| 15 |
+
class _ErrDictOptional(TypedDict, total=False):
|
| 16 |
+
all: None | _ErrKind
|
| 17 |
+
divide: None | _ErrKind
|
| 18 |
+
over: None | _ErrKind
|
| 19 |
+
under: None | _ErrKind
|
| 20 |
+
invalid: None | _ErrKind
|
| 21 |
+
|
| 22 |
+
def seterr(
|
| 23 |
+
all: None | _ErrKind = ...,
|
| 24 |
+
divide: None | _ErrKind = ...,
|
| 25 |
+
over: None | _ErrKind = ...,
|
| 26 |
+
under: None | _ErrKind = ...,
|
| 27 |
+
invalid: None | _ErrKind = ...,
|
| 28 |
+
) -> _ErrDict: ...
|
| 29 |
+
def geterr() -> _ErrDict: ...
|
| 30 |
+
def setbufsize(size: int) -> int: ...
|
| 31 |
+
def getbufsize() -> int: ...
|
| 32 |
+
def seterrcall(
|
| 33 |
+
func: None | _ErrFunc | _SupportsWrite[str]
|
| 34 |
+
) -> None | _ErrFunc | _SupportsWrite[str]: ...
|
| 35 |
+
def geterrcall() -> None | _ErrFunc | _SupportsWrite[str]: ...
|
| 36 |
+
|
| 37 |
+
# See `numpy/__init__.pyi` for the `errstate` class and `no_nep5_warnings`
|
.venv/lib/python3.11/site-packages/numpy/core/arrayprint.py
ADDED
|
@@ -0,0 +1,1725 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Array printing function
|
| 2 |
+
|
| 3 |
+
$Id: arrayprint.py,v 1.9 2005/09/13 13:58:44 teoliphant Exp $
|
| 4 |
+
|
| 5 |
+
"""
|
| 6 |
+
__all__ = ["array2string", "array_str", "array_repr", "set_string_function",
|
| 7 |
+
"set_printoptions", "get_printoptions", "printoptions",
|
| 8 |
+
"format_float_positional", "format_float_scientific"]
|
| 9 |
+
__docformat__ = 'restructuredtext'
|
| 10 |
+
|
| 11 |
+
#
|
| 12 |
+
# Written by Konrad Hinsen <hinsenk@ere.umontreal.ca>
|
| 13 |
+
# last revision: 1996-3-13
|
| 14 |
+
# modified by Jim Hugunin 1997-3-3 for repr's and str's (and other details)
|
| 15 |
+
# and by Perry Greenfield 2000-4-1 for numarray
|
| 16 |
+
# and by Travis Oliphant 2005-8-22 for numpy
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Note: Both scalartypes.c.src and arrayprint.py implement strs for numpy
|
| 20 |
+
# scalars but for different purposes. scalartypes.c.src has str/reprs for when
|
| 21 |
+
# the scalar is printed on its own, while arrayprint.py has strs for when
|
| 22 |
+
# scalars are printed inside an ndarray. Only the latter strs are currently
|
| 23 |
+
# user-customizable.
|
| 24 |
+
|
| 25 |
+
import functools
|
| 26 |
+
import numbers
|
| 27 |
+
import sys
|
| 28 |
+
try:
|
| 29 |
+
from _thread import get_ident
|
| 30 |
+
except ImportError:
|
| 31 |
+
from _dummy_thread import get_ident
|
| 32 |
+
|
| 33 |
+
import numpy as np
|
| 34 |
+
from . import numerictypes as _nt
|
| 35 |
+
from .umath import absolute, isinf, isfinite, isnat
|
| 36 |
+
from . import multiarray
|
| 37 |
+
from .multiarray import (array, dragon4_positional, dragon4_scientific,
|
| 38 |
+
datetime_as_string, datetime_data, ndarray,
|
| 39 |
+
set_legacy_print_mode)
|
| 40 |
+
from .fromnumeric import any
|
| 41 |
+
from .numeric import concatenate, asarray, errstate
|
| 42 |
+
from .numerictypes import (longlong, intc, int_, float_, complex_, bool_,
|
| 43 |
+
flexible)
|
| 44 |
+
from .overrides import array_function_dispatch, set_module
|
| 45 |
+
import operator
|
| 46 |
+
import warnings
|
| 47 |
+
import contextlib
|
| 48 |
+
|
| 49 |
+
_format_options = {
|
| 50 |
+
'edgeitems': 3, # repr N leading and trailing items of each dimension
|
| 51 |
+
'threshold': 1000, # total items > triggers array summarization
|
| 52 |
+
'floatmode': 'maxprec',
|
| 53 |
+
'precision': 8, # precision of floating point representations
|
| 54 |
+
'suppress': False, # suppress printing small floating values in exp format
|
| 55 |
+
'linewidth': 75,
|
| 56 |
+
'nanstr': 'nan',
|
| 57 |
+
'infstr': 'inf',
|
| 58 |
+
'sign': '-',
|
| 59 |
+
'formatter': None,
|
| 60 |
+
# Internally stored as an int to simplify comparisons; converted from/to
|
| 61 |
+
# str/False on the way in/out.
|
| 62 |
+
'legacy': sys.maxsize}
|
| 63 |
+
|
| 64 |
+
def _make_options_dict(precision=None, threshold=None, edgeitems=None,
|
| 65 |
+
linewidth=None, suppress=None, nanstr=None, infstr=None,
|
| 66 |
+
sign=None, formatter=None, floatmode=None, legacy=None):
|
| 67 |
+
"""
|
| 68 |
+
Make a dictionary out of the non-None arguments, plus conversion of
|
| 69 |
+
*legacy* and sanity checks.
|
| 70 |
+
"""
|
| 71 |
+
|
| 72 |
+
options = {k: v for k, v in locals().items() if v is not None}
|
| 73 |
+
|
| 74 |
+
if suppress is not None:
|
| 75 |
+
options['suppress'] = bool(suppress)
|
| 76 |
+
|
| 77 |
+
modes = ['fixed', 'unique', 'maxprec', 'maxprec_equal']
|
| 78 |
+
if floatmode not in modes + [None]:
|
| 79 |
+
raise ValueError("floatmode option must be one of " +
|
| 80 |
+
", ".join('"{}"'.format(m) for m in modes))
|
| 81 |
+
|
| 82 |
+
if sign not in [None, '-', '+', ' ']:
|
| 83 |
+
raise ValueError("sign option must be one of ' ', '+', or '-'")
|
| 84 |
+
|
| 85 |
+
if legacy == False:
|
| 86 |
+
options['legacy'] = sys.maxsize
|
| 87 |
+
elif legacy == '1.13':
|
| 88 |
+
options['legacy'] = 113
|
| 89 |
+
elif legacy == '1.21':
|
| 90 |
+
options['legacy'] = 121
|
| 91 |
+
elif legacy is None:
|
| 92 |
+
pass # OK, do nothing.
|
| 93 |
+
else:
|
| 94 |
+
warnings.warn(
|
| 95 |
+
"legacy printing option can currently only be '1.13', '1.21', or "
|
| 96 |
+
"`False`", stacklevel=3)
|
| 97 |
+
|
| 98 |
+
if threshold is not None:
|
| 99 |
+
# forbid the bad threshold arg suggested by stack overflow, gh-12351
|
| 100 |
+
if not isinstance(threshold, numbers.Number):
|
| 101 |
+
raise TypeError("threshold must be numeric")
|
| 102 |
+
if np.isnan(threshold):
|
| 103 |
+
raise ValueError("threshold must be non-NAN, try "
|
| 104 |
+
"sys.maxsize for untruncated representation")
|
| 105 |
+
|
| 106 |
+
if precision is not None:
|
| 107 |
+
# forbid the bad precision arg as suggested by issue #18254
|
| 108 |
+
try:
|
| 109 |
+
options['precision'] = operator.index(precision)
|
| 110 |
+
except TypeError as e:
|
| 111 |
+
raise TypeError('precision must be an integer') from e
|
| 112 |
+
|
| 113 |
+
return options
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
@set_module('numpy')
|
| 117 |
+
def set_printoptions(precision=None, threshold=None, edgeitems=None,
|
| 118 |
+
linewidth=None, suppress=None, nanstr=None, infstr=None,
|
| 119 |
+
formatter=None, sign=None, floatmode=None, *, legacy=None):
|
| 120 |
+
"""
|
| 121 |
+
Set printing options.
|
| 122 |
+
|
| 123 |
+
These options determine the way floating point numbers, arrays and
|
| 124 |
+
other NumPy objects are displayed.
|
| 125 |
+
|
| 126 |
+
Parameters
|
| 127 |
+
----------
|
| 128 |
+
precision : int or None, optional
|
| 129 |
+
Number of digits of precision for floating point output (default 8).
|
| 130 |
+
May be None if `floatmode` is not `fixed`, to print as many digits as
|
| 131 |
+
necessary to uniquely specify the value.
|
| 132 |
+
threshold : int, optional
|
| 133 |
+
Total number of array elements which trigger summarization
|
| 134 |
+
rather than full repr (default 1000).
|
| 135 |
+
To always use the full repr without summarization, pass `sys.maxsize`.
|
| 136 |
+
edgeitems : int, optional
|
| 137 |
+
Number of array items in summary at beginning and end of
|
| 138 |
+
each dimension (default 3).
|
| 139 |
+
linewidth : int, optional
|
| 140 |
+
The number of characters per line for the purpose of inserting
|
| 141 |
+
line breaks (default 75).
|
| 142 |
+
suppress : bool, optional
|
| 143 |
+
If True, always print floating point numbers using fixed point
|
| 144 |
+
notation, in which case numbers equal to zero in the current precision
|
| 145 |
+
will print as zero. If False, then scientific notation is used when
|
| 146 |
+
absolute value of the smallest number is < 1e-4 or the ratio of the
|
| 147 |
+
maximum absolute value to the minimum is > 1e3. The default is False.
|
| 148 |
+
nanstr : str, optional
|
| 149 |
+
String representation of floating point not-a-number (default nan).
|
| 150 |
+
infstr : str, optional
|
| 151 |
+
String representation of floating point infinity (default inf).
|
| 152 |
+
sign : string, either '-', '+', or ' ', optional
|
| 153 |
+
Controls printing of the sign of floating-point types. If '+', always
|
| 154 |
+
print the sign of positive values. If ' ', always prints a space
|
| 155 |
+
(whitespace character) in the sign position of positive values. If
|
| 156 |
+
'-', omit the sign character of positive values. (default '-')
|
| 157 |
+
formatter : dict of callables, optional
|
| 158 |
+
If not None, the keys should indicate the type(s) that the respective
|
| 159 |
+
formatting function applies to. Callables should return a string.
|
| 160 |
+
Types that are not specified (by their corresponding keys) are handled
|
| 161 |
+
by the default formatters. Individual types for which a formatter
|
| 162 |
+
can be set are:
|
| 163 |
+
|
| 164 |
+
- 'bool'
|
| 165 |
+
- 'int'
|
| 166 |
+
- 'timedelta' : a `numpy.timedelta64`
|
| 167 |
+
- 'datetime' : a `numpy.datetime64`
|
| 168 |
+
- 'float'
|
| 169 |
+
- 'longfloat' : 128-bit floats
|
| 170 |
+
- 'complexfloat'
|
| 171 |
+
- 'longcomplexfloat' : composed of two 128-bit floats
|
| 172 |
+
- 'numpystr' : types `numpy.bytes_` and `numpy.str_`
|
| 173 |
+
- 'object' : `np.object_` arrays
|
| 174 |
+
|
| 175 |
+
Other keys that can be used to set a group of types at once are:
|
| 176 |
+
|
| 177 |
+
- 'all' : sets all types
|
| 178 |
+
- 'int_kind' : sets 'int'
|
| 179 |
+
- 'float_kind' : sets 'float' and 'longfloat'
|
| 180 |
+
- 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat'
|
| 181 |
+
- 'str_kind' : sets 'numpystr'
|
| 182 |
+
floatmode : str, optional
|
| 183 |
+
Controls the interpretation of the `precision` option for
|
| 184 |
+
floating-point types. Can take the following values
|
| 185 |
+
(default maxprec_equal):
|
| 186 |
+
|
| 187 |
+
* 'fixed': Always print exactly `precision` fractional digits,
|
| 188 |
+
even if this would print more or fewer digits than
|
| 189 |
+
necessary to specify the value uniquely.
|
| 190 |
+
* 'unique': Print the minimum number of fractional digits necessary
|
| 191 |
+
to represent each value uniquely. Different elements may
|
| 192 |
+
have a different number of digits. The value of the
|
| 193 |
+
`precision` option is ignored.
|
| 194 |
+
* 'maxprec': Print at most `precision` fractional digits, but if
|
| 195 |
+
an element can be uniquely represented with fewer digits
|
| 196 |
+
only print it with that many.
|
| 197 |
+
* 'maxprec_equal': Print at most `precision` fractional digits,
|
| 198 |
+
but if every element in the array can be uniquely
|
| 199 |
+
represented with an equal number of fewer digits, use that
|
| 200 |
+
many digits for all elements.
|
| 201 |
+
legacy : string or `False`, optional
|
| 202 |
+
If set to the string `'1.13'` enables 1.13 legacy printing mode. This
|
| 203 |
+
approximates numpy 1.13 print output by including a space in the sign
|
| 204 |
+
position of floats and different behavior for 0d arrays. This also
|
| 205 |
+
enables 1.21 legacy printing mode (described below).
|
| 206 |
+
|
| 207 |
+
If set to the string `'1.21'` enables 1.21 legacy printing mode. This
|
| 208 |
+
approximates numpy 1.21 print output of complex structured dtypes
|
| 209 |
+
by not inserting spaces after commas that separate fields and after
|
| 210 |
+
colons.
|
| 211 |
+
|
| 212 |
+
If set to `False`, disables legacy mode.
|
| 213 |
+
|
| 214 |
+
Unrecognized strings will be ignored with a warning for forward
|
| 215 |
+
compatibility.
|
| 216 |
+
|
| 217 |
+
.. versionadded:: 1.14.0
|
| 218 |
+
.. versionchanged:: 1.22.0
|
| 219 |
+
|
| 220 |
+
See Also
|
| 221 |
+
--------
|
| 222 |
+
get_printoptions, printoptions, set_string_function, array2string
|
| 223 |
+
|
| 224 |
+
Notes
|
| 225 |
+
-----
|
| 226 |
+
`formatter` is always reset with a call to `set_printoptions`.
|
| 227 |
+
|
| 228 |
+
Use `printoptions` as a context manager to set the values temporarily.
|
| 229 |
+
|
| 230 |
+
Examples
|
| 231 |
+
--------
|
| 232 |
+
Floating point precision can be set:
|
| 233 |
+
|
| 234 |
+
>>> np.set_printoptions(precision=4)
|
| 235 |
+
>>> np.array([1.123456789])
|
| 236 |
+
[1.1235]
|
| 237 |
+
|
| 238 |
+
Long arrays can be summarised:
|
| 239 |
+
|
| 240 |
+
>>> np.set_printoptions(threshold=5)
|
| 241 |
+
>>> np.arange(10)
|
| 242 |
+
array([0, 1, 2, ..., 7, 8, 9])
|
| 243 |
+
|
| 244 |
+
Small results can be suppressed:
|
| 245 |
+
|
| 246 |
+
>>> eps = np.finfo(float).eps
|
| 247 |
+
>>> x = np.arange(4.)
|
| 248 |
+
>>> x**2 - (x + eps)**2
|
| 249 |
+
array([-4.9304e-32, -4.4409e-16, 0.0000e+00, 0.0000e+00])
|
| 250 |
+
>>> np.set_printoptions(suppress=True)
|
| 251 |
+
>>> x**2 - (x + eps)**2
|
| 252 |
+
array([-0., -0., 0., 0.])
|
| 253 |
+
|
| 254 |
+
A custom formatter can be used to display array elements as desired:
|
| 255 |
+
|
| 256 |
+
>>> np.set_printoptions(formatter={'all':lambda x: 'int: '+str(-x)})
|
| 257 |
+
>>> x = np.arange(3)
|
| 258 |
+
>>> x
|
| 259 |
+
array([int: 0, int: -1, int: -2])
|
| 260 |
+
>>> np.set_printoptions() # formatter gets reset
|
| 261 |
+
>>> x
|
| 262 |
+
array([0, 1, 2])
|
| 263 |
+
|
| 264 |
+
To put back the default options, you can use:
|
| 265 |
+
|
| 266 |
+
>>> np.set_printoptions(edgeitems=3, infstr='inf',
|
| 267 |
+
... linewidth=75, nanstr='nan', precision=8,
|
| 268 |
+
... suppress=False, threshold=1000, formatter=None)
|
| 269 |
+
|
| 270 |
+
Also to temporarily override options, use `printoptions` as a context manager:
|
| 271 |
+
|
| 272 |
+
>>> with np.printoptions(precision=2, suppress=True, threshold=5):
|
| 273 |
+
... np.linspace(0, 10, 10)
|
| 274 |
+
array([ 0. , 1.11, 2.22, ..., 7.78, 8.89, 10. ])
|
| 275 |
+
|
| 276 |
+
"""
|
| 277 |
+
opt = _make_options_dict(precision, threshold, edgeitems, linewidth,
|
| 278 |
+
suppress, nanstr, infstr, sign, formatter,
|
| 279 |
+
floatmode, legacy)
|
| 280 |
+
# formatter is always reset
|
| 281 |
+
opt['formatter'] = formatter
|
| 282 |
+
_format_options.update(opt)
|
| 283 |
+
|
| 284 |
+
# set the C variable for legacy mode
|
| 285 |
+
if _format_options['legacy'] == 113:
|
| 286 |
+
set_legacy_print_mode(113)
|
| 287 |
+
# reset the sign option in legacy mode to avoid confusion
|
| 288 |
+
_format_options['sign'] = '-'
|
| 289 |
+
elif _format_options['legacy'] == 121:
|
| 290 |
+
set_legacy_print_mode(121)
|
| 291 |
+
elif _format_options['legacy'] == sys.maxsize:
|
| 292 |
+
set_legacy_print_mode(0)
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
@set_module('numpy')
|
| 296 |
+
def get_printoptions():
|
| 297 |
+
"""
|
| 298 |
+
Return the current print options.
|
| 299 |
+
|
| 300 |
+
Returns
|
| 301 |
+
-------
|
| 302 |
+
print_opts : dict
|
| 303 |
+
Dictionary of current print options with keys
|
| 304 |
+
|
| 305 |
+
- precision : int
|
| 306 |
+
- threshold : int
|
| 307 |
+
- edgeitems : int
|
| 308 |
+
- linewidth : int
|
| 309 |
+
- suppress : bool
|
| 310 |
+
- nanstr : str
|
| 311 |
+
- infstr : str
|
| 312 |
+
- formatter : dict of callables
|
| 313 |
+
- sign : str
|
| 314 |
+
|
| 315 |
+
For a full description of these options, see `set_printoptions`.
|
| 316 |
+
|
| 317 |
+
See Also
|
| 318 |
+
--------
|
| 319 |
+
set_printoptions, printoptions, set_string_function
|
| 320 |
+
|
| 321 |
+
"""
|
| 322 |
+
opts = _format_options.copy()
|
| 323 |
+
opts['legacy'] = {
|
| 324 |
+
113: '1.13', 121: '1.21', sys.maxsize: False,
|
| 325 |
+
}[opts['legacy']]
|
| 326 |
+
return opts
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
def _get_legacy_print_mode():
|
| 330 |
+
"""Return the legacy print mode as an int."""
|
| 331 |
+
return _format_options['legacy']
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
@set_module('numpy')
|
| 335 |
+
@contextlib.contextmanager
|
| 336 |
+
def printoptions(*args, **kwargs):
|
| 337 |
+
"""Context manager for setting print options.
|
| 338 |
+
|
| 339 |
+
Set print options for the scope of the `with` block, and restore the old
|
| 340 |
+
options at the end. See `set_printoptions` for the full description of
|
| 341 |
+
available options.
|
| 342 |
+
|
| 343 |
+
Examples
|
| 344 |
+
--------
|
| 345 |
+
|
| 346 |
+
>>> from numpy.testing import assert_equal
|
| 347 |
+
>>> with np.printoptions(precision=2):
|
| 348 |
+
... np.array([2.0]) / 3
|
| 349 |
+
array([0.67])
|
| 350 |
+
|
| 351 |
+
The `as`-clause of the `with`-statement gives the current print options:
|
| 352 |
+
|
| 353 |
+
>>> with np.printoptions(precision=2) as opts:
|
| 354 |
+
... assert_equal(opts, np.get_printoptions())
|
| 355 |
+
|
| 356 |
+
See Also
|
| 357 |
+
--------
|
| 358 |
+
set_printoptions, get_printoptions
|
| 359 |
+
|
| 360 |
+
"""
|
| 361 |
+
opts = np.get_printoptions()
|
| 362 |
+
try:
|
| 363 |
+
np.set_printoptions(*args, **kwargs)
|
| 364 |
+
yield np.get_printoptions()
|
| 365 |
+
finally:
|
| 366 |
+
np.set_printoptions(**opts)
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
def _leading_trailing(a, edgeitems, index=()):
|
| 370 |
+
"""
|
| 371 |
+
Keep only the N-D corners (leading and trailing edges) of an array.
|
| 372 |
+
|
| 373 |
+
Should be passed a base-class ndarray, since it makes no guarantees about
|
| 374 |
+
preserving subclasses.
|
| 375 |
+
"""
|
| 376 |
+
axis = len(index)
|
| 377 |
+
if axis == a.ndim:
|
| 378 |
+
return a[index]
|
| 379 |
+
|
| 380 |
+
if a.shape[axis] > 2*edgeitems:
|
| 381 |
+
return concatenate((
|
| 382 |
+
_leading_trailing(a, edgeitems, index + np.index_exp[ :edgeitems]),
|
| 383 |
+
_leading_trailing(a, edgeitems, index + np.index_exp[-edgeitems:])
|
| 384 |
+
), axis=axis)
|
| 385 |
+
else:
|
| 386 |
+
return _leading_trailing(a, edgeitems, index + np.index_exp[:])
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
def _object_format(o):
|
| 390 |
+
""" Object arrays containing lists should be printed unambiguously """
|
| 391 |
+
if type(o) is list:
|
| 392 |
+
fmt = 'list({!r})'
|
| 393 |
+
else:
|
| 394 |
+
fmt = '{!r}'
|
| 395 |
+
return fmt.format(o)
|
| 396 |
+
|
| 397 |
+
def repr_format(x):
|
| 398 |
+
return repr(x)
|
| 399 |
+
|
| 400 |
+
def str_format(x):
|
| 401 |
+
return str(x)
|
| 402 |
+
|
| 403 |
+
def _get_formatdict(data, *, precision, floatmode, suppress, sign, legacy,
|
| 404 |
+
formatter, **kwargs):
|
| 405 |
+
# note: extra arguments in kwargs are ignored
|
| 406 |
+
|
| 407 |
+
# wrapped in lambdas to avoid taking a code path with the wrong type of data
|
| 408 |
+
formatdict = {
|
| 409 |
+
'bool': lambda: BoolFormat(data),
|
| 410 |
+
'int': lambda: IntegerFormat(data),
|
| 411 |
+
'float': lambda: FloatingFormat(
|
| 412 |
+
data, precision, floatmode, suppress, sign, legacy=legacy),
|
| 413 |
+
'longfloat': lambda: FloatingFormat(
|
| 414 |
+
data, precision, floatmode, suppress, sign, legacy=legacy),
|
| 415 |
+
'complexfloat': lambda: ComplexFloatingFormat(
|
| 416 |
+
data, precision, floatmode, suppress, sign, legacy=legacy),
|
| 417 |
+
'longcomplexfloat': lambda: ComplexFloatingFormat(
|
| 418 |
+
data, precision, floatmode, suppress, sign, legacy=legacy),
|
| 419 |
+
'datetime': lambda: DatetimeFormat(data, legacy=legacy),
|
| 420 |
+
'timedelta': lambda: TimedeltaFormat(data),
|
| 421 |
+
'object': lambda: _object_format,
|
| 422 |
+
'void': lambda: str_format,
|
| 423 |
+
'numpystr': lambda: repr_format}
|
| 424 |
+
|
| 425 |
+
# we need to wrap values in `formatter` in a lambda, so that the interface
|
| 426 |
+
# is the same as the above values.
|
| 427 |
+
def indirect(x):
|
| 428 |
+
return lambda: x
|
| 429 |
+
|
| 430 |
+
if formatter is not None:
|
| 431 |
+
fkeys = [k for k in formatter.keys() if formatter[k] is not None]
|
| 432 |
+
if 'all' in fkeys:
|
| 433 |
+
for key in formatdict.keys():
|
| 434 |
+
formatdict[key] = indirect(formatter['all'])
|
| 435 |
+
if 'int_kind' in fkeys:
|
| 436 |
+
for key in ['int']:
|
| 437 |
+
formatdict[key] = indirect(formatter['int_kind'])
|
| 438 |
+
if 'float_kind' in fkeys:
|
| 439 |
+
for key in ['float', 'longfloat']:
|
| 440 |
+
formatdict[key] = indirect(formatter['float_kind'])
|
| 441 |
+
if 'complex_kind' in fkeys:
|
| 442 |
+
for key in ['complexfloat', 'longcomplexfloat']:
|
| 443 |
+
formatdict[key] = indirect(formatter['complex_kind'])
|
| 444 |
+
if 'str_kind' in fkeys:
|
| 445 |
+
formatdict['numpystr'] = indirect(formatter['str_kind'])
|
| 446 |
+
for key in formatdict.keys():
|
| 447 |
+
if key in fkeys:
|
| 448 |
+
formatdict[key] = indirect(formatter[key])
|
| 449 |
+
|
| 450 |
+
return formatdict
|
| 451 |
+
|
| 452 |
+
def _get_format_function(data, **options):
|
| 453 |
+
"""
|
| 454 |
+
find the right formatting function for the dtype_
|
| 455 |
+
"""
|
| 456 |
+
dtype_ = data.dtype
|
| 457 |
+
dtypeobj = dtype_.type
|
| 458 |
+
formatdict = _get_formatdict(data, **options)
|
| 459 |
+
if dtypeobj is None:
|
| 460 |
+
return formatdict["numpystr"]()
|
| 461 |
+
elif issubclass(dtypeobj, _nt.bool_):
|
| 462 |
+
return formatdict['bool']()
|
| 463 |
+
elif issubclass(dtypeobj, _nt.integer):
|
| 464 |
+
if issubclass(dtypeobj, _nt.timedelta64):
|
| 465 |
+
return formatdict['timedelta']()
|
| 466 |
+
else:
|
| 467 |
+
return formatdict['int']()
|
| 468 |
+
elif issubclass(dtypeobj, _nt.floating):
|
| 469 |
+
if issubclass(dtypeobj, _nt.longfloat):
|
| 470 |
+
return formatdict['longfloat']()
|
| 471 |
+
else:
|
| 472 |
+
return formatdict['float']()
|
| 473 |
+
elif issubclass(dtypeobj, _nt.complexfloating):
|
| 474 |
+
if issubclass(dtypeobj, _nt.clongfloat):
|
| 475 |
+
return formatdict['longcomplexfloat']()
|
| 476 |
+
else:
|
| 477 |
+
return formatdict['complexfloat']()
|
| 478 |
+
elif issubclass(dtypeobj, (_nt.str_, _nt.bytes_)):
|
| 479 |
+
return formatdict['numpystr']()
|
| 480 |
+
elif issubclass(dtypeobj, _nt.datetime64):
|
| 481 |
+
return formatdict['datetime']()
|
| 482 |
+
elif issubclass(dtypeobj, _nt.object_):
|
| 483 |
+
return formatdict['object']()
|
| 484 |
+
elif issubclass(dtypeobj, _nt.void):
|
| 485 |
+
if dtype_.names is not None:
|
| 486 |
+
return StructuredVoidFormat.from_data(data, **options)
|
| 487 |
+
else:
|
| 488 |
+
return formatdict['void']()
|
| 489 |
+
else:
|
| 490 |
+
return formatdict['numpystr']()
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
def _recursive_guard(fillvalue='...'):
|
| 494 |
+
"""
|
| 495 |
+
Like the python 3.2 reprlib.recursive_repr, but forwards *args and **kwargs
|
| 496 |
+
|
| 497 |
+
Decorates a function such that if it calls itself with the same first
|
| 498 |
+
argument, it returns `fillvalue` instead of recursing.
|
| 499 |
+
|
| 500 |
+
Largely copied from reprlib.recursive_repr
|
| 501 |
+
"""
|
| 502 |
+
|
| 503 |
+
def decorating_function(f):
|
| 504 |
+
repr_running = set()
|
| 505 |
+
|
| 506 |
+
@functools.wraps(f)
|
| 507 |
+
def wrapper(self, *args, **kwargs):
|
| 508 |
+
key = id(self), get_ident()
|
| 509 |
+
if key in repr_running:
|
| 510 |
+
return fillvalue
|
| 511 |
+
repr_running.add(key)
|
| 512 |
+
try:
|
| 513 |
+
return f(self, *args, **kwargs)
|
| 514 |
+
finally:
|
| 515 |
+
repr_running.discard(key)
|
| 516 |
+
|
| 517 |
+
return wrapper
|
| 518 |
+
|
| 519 |
+
return decorating_function
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
# gracefully handle recursive calls, when object arrays contain themselves
|
| 523 |
+
@_recursive_guard()
|
| 524 |
+
def _array2string(a, options, separator=' ', prefix=""):
|
| 525 |
+
# The formatter __init__s in _get_format_function cannot deal with
|
| 526 |
+
# subclasses yet, and we also need to avoid recursion issues in
|
| 527 |
+
# _formatArray with subclasses which return 0d arrays in place of scalars
|
| 528 |
+
data = asarray(a)
|
| 529 |
+
if a.shape == ():
|
| 530 |
+
a = data
|
| 531 |
+
|
| 532 |
+
if a.size > options['threshold']:
|
| 533 |
+
summary_insert = "..."
|
| 534 |
+
data = _leading_trailing(data, options['edgeitems'])
|
| 535 |
+
else:
|
| 536 |
+
summary_insert = ""
|
| 537 |
+
|
| 538 |
+
# find the right formatting function for the array
|
| 539 |
+
format_function = _get_format_function(data, **options)
|
| 540 |
+
|
| 541 |
+
# skip over "["
|
| 542 |
+
next_line_prefix = " "
|
| 543 |
+
# skip over array(
|
| 544 |
+
next_line_prefix += " "*len(prefix)
|
| 545 |
+
|
| 546 |
+
lst = _formatArray(a, format_function, options['linewidth'],
|
| 547 |
+
next_line_prefix, separator, options['edgeitems'],
|
| 548 |
+
summary_insert, options['legacy'])
|
| 549 |
+
return lst
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
def _array2string_dispatcher(
|
| 553 |
+
a, max_line_width=None, precision=None,
|
| 554 |
+
suppress_small=None, separator=None, prefix=None,
|
| 555 |
+
style=None, formatter=None, threshold=None,
|
| 556 |
+
edgeitems=None, sign=None, floatmode=None, suffix=None,
|
| 557 |
+
*, legacy=None):
|
| 558 |
+
return (a,)
|
| 559 |
+
|
| 560 |
+
|
| 561 |
+
@array_function_dispatch(_array2string_dispatcher, module='numpy')
|
| 562 |
+
def array2string(a, max_line_width=None, precision=None,
|
| 563 |
+
suppress_small=None, separator=' ', prefix="",
|
| 564 |
+
style=np._NoValue, formatter=None, threshold=None,
|
| 565 |
+
edgeitems=None, sign=None, floatmode=None, suffix="",
|
| 566 |
+
*, legacy=None):
|
| 567 |
+
"""
|
| 568 |
+
Return a string representation of an array.
|
| 569 |
+
|
| 570 |
+
Parameters
|
| 571 |
+
----------
|
| 572 |
+
a : ndarray
|
| 573 |
+
Input array.
|
| 574 |
+
max_line_width : int, optional
|
| 575 |
+
Inserts newlines if text is longer than `max_line_width`.
|
| 576 |
+
Defaults to ``numpy.get_printoptions()['linewidth']``.
|
| 577 |
+
precision : int or None, optional
|
| 578 |
+
Floating point precision.
|
| 579 |
+
Defaults to ``numpy.get_printoptions()['precision']``.
|
| 580 |
+
suppress_small : bool, optional
|
| 581 |
+
Represent numbers "very close" to zero as zero; default is False.
|
| 582 |
+
Very close is defined by precision: if the precision is 8, e.g.,
|
| 583 |
+
numbers smaller (in absolute value) than 5e-9 are represented as
|
| 584 |
+
zero.
|
| 585 |
+
Defaults to ``numpy.get_printoptions()['suppress']``.
|
| 586 |
+
separator : str, optional
|
| 587 |
+
Inserted between elements.
|
| 588 |
+
prefix : str, optional
|
| 589 |
+
suffix : str, optional
|
| 590 |
+
The length of the prefix and suffix strings are used to respectively
|
| 591 |
+
align and wrap the output. An array is typically printed as::
|
| 592 |
+
|
| 593 |
+
prefix + array2string(a) + suffix
|
| 594 |
+
|
| 595 |
+
The output is left-padded by the length of the prefix string, and
|
| 596 |
+
wrapping is forced at the column ``max_line_width - len(suffix)``.
|
| 597 |
+
It should be noted that the content of prefix and suffix strings are
|
| 598 |
+
not included in the output.
|
| 599 |
+
style : _NoValue, optional
|
| 600 |
+
Has no effect, do not use.
|
| 601 |
+
|
| 602 |
+
.. deprecated:: 1.14.0
|
| 603 |
+
formatter : dict of callables, optional
|
| 604 |
+
If not None, the keys should indicate the type(s) that the respective
|
| 605 |
+
formatting function applies to. Callables should return a string.
|
| 606 |
+
Types that are not specified (by their corresponding keys) are handled
|
| 607 |
+
by the default formatters. Individual types for which a formatter
|
| 608 |
+
can be set are:
|
| 609 |
+
|
| 610 |
+
- 'bool'
|
| 611 |
+
- 'int'
|
| 612 |
+
- 'timedelta' : a `numpy.timedelta64`
|
| 613 |
+
- 'datetime' : a `numpy.datetime64`
|
| 614 |
+
- 'float'
|
| 615 |
+
- 'longfloat' : 128-bit floats
|
| 616 |
+
- 'complexfloat'
|
| 617 |
+
- 'longcomplexfloat' : composed of two 128-bit floats
|
| 618 |
+
- 'void' : type `numpy.void`
|
| 619 |
+
- 'numpystr' : types `numpy.bytes_` and `numpy.str_`
|
| 620 |
+
|
| 621 |
+
Other keys that can be used to set a group of types at once are:
|
| 622 |
+
|
| 623 |
+
- 'all' : sets all types
|
| 624 |
+
- 'int_kind' : sets 'int'
|
| 625 |
+
- 'float_kind' : sets 'float' and 'longfloat'
|
| 626 |
+
- 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat'
|
| 627 |
+
- 'str_kind' : sets 'numpystr'
|
| 628 |
+
threshold : int, optional
|
| 629 |
+
Total number of array elements which trigger summarization
|
| 630 |
+
rather than full repr.
|
| 631 |
+
Defaults to ``numpy.get_printoptions()['threshold']``.
|
| 632 |
+
edgeitems : int, optional
|
| 633 |
+
Number of array items in summary at beginning and end of
|
| 634 |
+
each dimension.
|
| 635 |
+
Defaults to ``numpy.get_printoptions()['edgeitems']``.
|
| 636 |
+
sign : string, either '-', '+', or ' ', optional
|
| 637 |
+
Controls printing of the sign of floating-point types. If '+', always
|
| 638 |
+
print the sign of positive values. If ' ', always prints a space
|
| 639 |
+
(whitespace character) in the sign position of positive values. If
|
| 640 |
+
'-', omit the sign character of positive values.
|
| 641 |
+
Defaults to ``numpy.get_printoptions()['sign']``.
|
| 642 |
+
floatmode : str, optional
|
| 643 |
+
Controls the interpretation of the `precision` option for
|
| 644 |
+
floating-point types.
|
| 645 |
+
Defaults to ``numpy.get_printoptions()['floatmode']``.
|
| 646 |
+
Can take the following values:
|
| 647 |
+
|
| 648 |
+
- 'fixed': Always print exactly `precision` fractional digits,
|
| 649 |
+
even if this would print more or fewer digits than
|
| 650 |
+
necessary to specify the value uniquely.
|
| 651 |
+
- 'unique': Print the minimum number of fractional digits necessary
|
| 652 |
+
to represent each value uniquely. Different elements may
|
| 653 |
+
have a different number of digits. The value of the
|
| 654 |
+
`precision` option is ignored.
|
| 655 |
+
- 'maxprec': Print at most `precision` fractional digits, but if
|
| 656 |
+
an element can be uniquely represented with fewer digits
|
| 657 |
+
only print it with that many.
|
| 658 |
+
- 'maxprec_equal': Print at most `precision` fractional digits,
|
| 659 |
+
but if every element in the array can be uniquely
|
| 660 |
+
represented with an equal number of fewer digits, use that
|
| 661 |
+
many digits for all elements.
|
| 662 |
+
legacy : string or `False`, optional
|
| 663 |
+
If set to the string `'1.13'` enables 1.13 legacy printing mode. This
|
| 664 |
+
approximates numpy 1.13 print output by including a space in the sign
|
| 665 |
+
position of floats and different behavior for 0d arrays. If set to
|
| 666 |
+
`False`, disables legacy mode. Unrecognized strings will be ignored
|
| 667 |
+
with a warning for forward compatibility.
|
| 668 |
+
|
| 669 |
+
.. versionadded:: 1.14.0
|
| 670 |
+
|
| 671 |
+
Returns
|
| 672 |
+
-------
|
| 673 |
+
array_str : str
|
| 674 |
+
String representation of the array.
|
| 675 |
+
|
| 676 |
+
Raises
|
| 677 |
+
------
|
| 678 |
+
TypeError
|
| 679 |
+
if a callable in `formatter` does not return a string.
|
| 680 |
+
|
| 681 |
+
See Also
|
| 682 |
+
--------
|
| 683 |
+
array_str, array_repr, set_printoptions, get_printoptions
|
| 684 |
+
|
| 685 |
+
Notes
|
| 686 |
+
-----
|
| 687 |
+
If a formatter is specified for a certain type, the `precision` keyword is
|
| 688 |
+
ignored for that type.
|
| 689 |
+
|
| 690 |
+
This is a very flexible function; `array_repr` and `array_str` are using
|
| 691 |
+
`array2string` internally so keywords with the same name should work
|
| 692 |
+
identically in all three functions.
|
| 693 |
+
|
| 694 |
+
Examples
|
| 695 |
+
--------
|
| 696 |
+
>>> x = np.array([1e-16,1,2,3])
|
| 697 |
+
>>> np.array2string(x, precision=2, separator=',',
|
| 698 |
+
... suppress_small=True)
|
| 699 |
+
'[0.,1.,2.,3.]'
|
| 700 |
+
|
| 701 |
+
>>> x = np.arange(3.)
|
| 702 |
+
>>> np.array2string(x, formatter={'float_kind':lambda x: "%.2f" % x})
|
| 703 |
+
'[0.00 1.00 2.00]'
|
| 704 |
+
|
| 705 |
+
>>> x = np.arange(3)
|
| 706 |
+
>>> np.array2string(x, formatter={'int':lambda x: hex(x)})
|
| 707 |
+
'[0x0 0x1 0x2]'
|
| 708 |
+
|
| 709 |
+
"""
|
| 710 |
+
|
| 711 |
+
overrides = _make_options_dict(precision, threshold, edgeitems,
|
| 712 |
+
max_line_width, suppress_small, None, None,
|
| 713 |
+
sign, formatter, floatmode, legacy)
|
| 714 |
+
options = _format_options.copy()
|
| 715 |
+
options.update(overrides)
|
| 716 |
+
|
| 717 |
+
if options['legacy'] <= 113:
|
| 718 |
+
if style is np._NoValue:
|
| 719 |
+
style = repr
|
| 720 |
+
|
| 721 |
+
if a.shape == () and a.dtype.names is None:
|
| 722 |
+
return style(a.item())
|
| 723 |
+
elif style is not np._NoValue:
|
| 724 |
+
# Deprecation 11-9-2017 v1.14
|
| 725 |
+
warnings.warn("'style' argument is deprecated and no longer functional"
|
| 726 |
+
" except in 1.13 'legacy' mode",
|
| 727 |
+
DeprecationWarning, stacklevel=2)
|
| 728 |
+
|
| 729 |
+
if options['legacy'] > 113:
|
| 730 |
+
options['linewidth'] -= len(suffix)
|
| 731 |
+
|
| 732 |
+
# treat as a null array if any of shape elements == 0
|
| 733 |
+
if a.size == 0:
|
| 734 |
+
return "[]"
|
| 735 |
+
|
| 736 |
+
return _array2string(a, options, separator, prefix)
|
| 737 |
+
|
| 738 |
+
|
| 739 |
+
def _extendLine(s, line, word, line_width, next_line_prefix, legacy):
|
| 740 |
+
needs_wrap = len(line) + len(word) > line_width
|
| 741 |
+
if legacy > 113:
|
| 742 |
+
# don't wrap lines if it won't help
|
| 743 |
+
if len(line) <= len(next_line_prefix):
|
| 744 |
+
needs_wrap = False
|
| 745 |
+
|
| 746 |
+
if needs_wrap:
|
| 747 |
+
s += line.rstrip() + "\n"
|
| 748 |
+
line = next_line_prefix
|
| 749 |
+
line += word
|
| 750 |
+
return s, line
|
| 751 |
+
|
| 752 |
+
|
| 753 |
+
def _extendLine_pretty(s, line, word, line_width, next_line_prefix, legacy):
|
| 754 |
+
"""
|
| 755 |
+
Extends line with nicely formatted (possibly multi-line) string ``word``.
|
| 756 |
+
"""
|
| 757 |
+
words = word.splitlines()
|
| 758 |
+
if len(words) == 1 or legacy <= 113:
|
| 759 |
+
return _extendLine(s, line, word, line_width, next_line_prefix, legacy)
|
| 760 |
+
|
| 761 |
+
max_word_length = max(len(word) for word in words)
|
| 762 |
+
if (len(line) + max_word_length > line_width and
|
| 763 |
+
len(line) > len(next_line_prefix)):
|
| 764 |
+
s += line.rstrip() + '\n'
|
| 765 |
+
line = next_line_prefix + words[0]
|
| 766 |
+
indent = next_line_prefix
|
| 767 |
+
else:
|
| 768 |
+
indent = len(line)*' '
|
| 769 |
+
line += words[0]
|
| 770 |
+
|
| 771 |
+
for word in words[1::]:
|
| 772 |
+
s += line.rstrip() + '\n'
|
| 773 |
+
line = indent + word
|
| 774 |
+
|
| 775 |
+
suffix_length = max_word_length - len(words[-1])
|
| 776 |
+
line += suffix_length*' '
|
| 777 |
+
|
| 778 |
+
return s, line
|
| 779 |
+
|
| 780 |
+
def _formatArray(a, format_function, line_width, next_line_prefix,
|
| 781 |
+
separator, edge_items, summary_insert, legacy):
|
| 782 |
+
"""formatArray is designed for two modes of operation:
|
| 783 |
+
|
| 784 |
+
1. Full output
|
| 785 |
+
|
| 786 |
+
2. Summarized output
|
| 787 |
+
|
| 788 |
+
"""
|
| 789 |
+
def recurser(index, hanging_indent, curr_width):
|
| 790 |
+
"""
|
| 791 |
+
By using this local function, we don't need to recurse with all the
|
| 792 |
+
arguments. Since this function is not created recursively, the cost is
|
| 793 |
+
not significant
|
| 794 |
+
"""
|
| 795 |
+
axis = len(index)
|
| 796 |
+
axes_left = a.ndim - axis
|
| 797 |
+
|
| 798 |
+
if axes_left == 0:
|
| 799 |
+
return format_function(a[index])
|
| 800 |
+
|
| 801 |
+
# when recursing, add a space to align with the [ added, and reduce the
|
| 802 |
+
# length of the line by 1
|
| 803 |
+
next_hanging_indent = hanging_indent + ' '
|
| 804 |
+
if legacy <= 113:
|
| 805 |
+
next_width = curr_width
|
| 806 |
+
else:
|
| 807 |
+
next_width = curr_width - len(']')
|
| 808 |
+
|
| 809 |
+
a_len = a.shape[axis]
|
| 810 |
+
show_summary = summary_insert and 2*edge_items < a_len
|
| 811 |
+
if show_summary:
|
| 812 |
+
leading_items = edge_items
|
| 813 |
+
trailing_items = edge_items
|
| 814 |
+
else:
|
| 815 |
+
leading_items = 0
|
| 816 |
+
trailing_items = a_len
|
| 817 |
+
|
| 818 |
+
# stringify the array with the hanging indent on the first line too
|
| 819 |
+
s = ''
|
| 820 |
+
|
| 821 |
+
# last axis (rows) - wrap elements if they would not fit on one line
|
| 822 |
+
if axes_left == 1:
|
| 823 |
+
# the length up until the beginning of the separator / bracket
|
| 824 |
+
if legacy <= 113:
|
| 825 |
+
elem_width = curr_width - len(separator.rstrip())
|
| 826 |
+
else:
|
| 827 |
+
elem_width = curr_width - max(len(separator.rstrip()), len(']'))
|
| 828 |
+
|
| 829 |
+
line = hanging_indent
|
| 830 |
+
for i in range(leading_items):
|
| 831 |
+
word = recurser(index + (i,), next_hanging_indent, next_width)
|
| 832 |
+
s, line = _extendLine_pretty(
|
| 833 |
+
s, line, word, elem_width, hanging_indent, legacy)
|
| 834 |
+
line += separator
|
| 835 |
+
|
| 836 |
+
if show_summary:
|
| 837 |
+
s, line = _extendLine(
|
| 838 |
+
s, line, summary_insert, elem_width, hanging_indent, legacy)
|
| 839 |
+
if legacy <= 113:
|
| 840 |
+
line += ", "
|
| 841 |
+
else:
|
| 842 |
+
line += separator
|
| 843 |
+
|
| 844 |
+
for i in range(trailing_items, 1, -1):
|
| 845 |
+
word = recurser(index + (-i,), next_hanging_indent, next_width)
|
| 846 |
+
s, line = _extendLine_pretty(
|
| 847 |
+
s, line, word, elem_width, hanging_indent, legacy)
|
| 848 |
+
line += separator
|
| 849 |
+
|
| 850 |
+
if legacy <= 113:
|
| 851 |
+
# width of the separator is not considered on 1.13
|
| 852 |
+
elem_width = curr_width
|
| 853 |
+
word = recurser(index + (-1,), next_hanging_indent, next_width)
|
| 854 |
+
s, line = _extendLine_pretty(
|
| 855 |
+
s, line, word, elem_width, hanging_indent, legacy)
|
| 856 |
+
|
| 857 |
+
s += line
|
| 858 |
+
|
| 859 |
+
# other axes - insert newlines between rows
|
| 860 |
+
else:
|
| 861 |
+
s = ''
|
| 862 |
+
line_sep = separator.rstrip() + '\n'*(axes_left - 1)
|
| 863 |
+
|
| 864 |
+
for i in range(leading_items):
|
| 865 |
+
nested = recurser(index + (i,), next_hanging_indent, next_width)
|
| 866 |
+
s += hanging_indent + nested + line_sep
|
| 867 |
+
|
| 868 |
+
if show_summary:
|
| 869 |
+
if legacy <= 113:
|
| 870 |
+
# trailing space, fixed nbr of newlines, and fixed separator
|
| 871 |
+
s += hanging_indent + summary_insert + ", \n"
|
| 872 |
+
else:
|
| 873 |
+
s += hanging_indent + summary_insert + line_sep
|
| 874 |
+
|
| 875 |
+
for i in range(trailing_items, 1, -1):
|
| 876 |
+
nested = recurser(index + (-i,), next_hanging_indent,
|
| 877 |
+
next_width)
|
| 878 |
+
s += hanging_indent + nested + line_sep
|
| 879 |
+
|
| 880 |
+
nested = recurser(index + (-1,), next_hanging_indent, next_width)
|
| 881 |
+
s += hanging_indent + nested
|
| 882 |
+
|
| 883 |
+
# remove the hanging indent, and wrap in []
|
| 884 |
+
s = '[' + s[len(hanging_indent):] + ']'
|
| 885 |
+
return s
|
| 886 |
+
|
| 887 |
+
try:
|
| 888 |
+
# invoke the recursive part with an initial index and prefix
|
| 889 |
+
return recurser(index=(),
|
| 890 |
+
hanging_indent=next_line_prefix,
|
| 891 |
+
curr_width=line_width)
|
| 892 |
+
finally:
|
| 893 |
+
# recursive closures have a cyclic reference to themselves, which
|
| 894 |
+
# requires gc to collect (gh-10620). To avoid this problem, for
|
| 895 |
+
# performance and PyPy friendliness, we break the cycle:
|
| 896 |
+
recurser = None
|
| 897 |
+
|
| 898 |
+
def _none_or_positive_arg(x, name):
|
| 899 |
+
if x is None:
|
| 900 |
+
return -1
|
| 901 |
+
if x < 0:
|
| 902 |
+
raise ValueError("{} must be >= 0".format(name))
|
| 903 |
+
return x
|
| 904 |
+
|
| 905 |
+
class FloatingFormat:
|
| 906 |
+
""" Formatter for subtypes of np.floating """
|
| 907 |
+
def __init__(self, data, precision, floatmode, suppress_small, sign=False,
|
| 908 |
+
*, legacy=None):
|
| 909 |
+
# for backcompatibility, accept bools
|
| 910 |
+
if isinstance(sign, bool):
|
| 911 |
+
sign = '+' if sign else '-'
|
| 912 |
+
|
| 913 |
+
self._legacy = legacy
|
| 914 |
+
if self._legacy <= 113:
|
| 915 |
+
# when not 0d, legacy does not support '-'
|
| 916 |
+
if data.shape != () and sign == '-':
|
| 917 |
+
sign = ' '
|
| 918 |
+
|
| 919 |
+
self.floatmode = floatmode
|
| 920 |
+
if floatmode == 'unique':
|
| 921 |
+
self.precision = None
|
| 922 |
+
else:
|
| 923 |
+
self.precision = precision
|
| 924 |
+
|
| 925 |
+
self.precision = _none_or_positive_arg(self.precision, 'precision')
|
| 926 |
+
|
| 927 |
+
self.suppress_small = suppress_small
|
| 928 |
+
self.sign = sign
|
| 929 |
+
self.exp_format = False
|
| 930 |
+
self.large_exponent = False
|
| 931 |
+
|
| 932 |
+
self.fillFormat(data)
|
| 933 |
+
|
| 934 |
+
def fillFormat(self, data):
|
| 935 |
+
# only the finite values are used to compute the number of digits
|
| 936 |
+
finite_vals = data[isfinite(data)]
|
| 937 |
+
|
| 938 |
+
# choose exponential mode based on the non-zero finite values:
|
| 939 |
+
abs_non_zero = absolute(finite_vals[finite_vals != 0])
|
| 940 |
+
if len(abs_non_zero) != 0:
|
| 941 |
+
max_val = np.max(abs_non_zero)
|
| 942 |
+
min_val = np.min(abs_non_zero)
|
| 943 |
+
with errstate(over='ignore'): # division can overflow
|
| 944 |
+
if max_val >= 1.e8 or (not self.suppress_small and
|
| 945 |
+
(min_val < 0.0001 or max_val/min_val > 1000.)):
|
| 946 |
+
self.exp_format = True
|
| 947 |
+
|
| 948 |
+
# do a first pass of printing all the numbers, to determine sizes
|
| 949 |
+
if len(finite_vals) == 0:
|
| 950 |
+
self.pad_left = 0
|
| 951 |
+
self.pad_right = 0
|
| 952 |
+
self.trim = '.'
|
| 953 |
+
self.exp_size = -1
|
| 954 |
+
self.unique = True
|
| 955 |
+
self.min_digits = None
|
| 956 |
+
elif self.exp_format:
|
| 957 |
+
trim, unique = '.', True
|
| 958 |
+
if self.floatmode == 'fixed' or self._legacy <= 113:
|
| 959 |
+
trim, unique = 'k', False
|
| 960 |
+
strs = (dragon4_scientific(x, precision=self.precision,
|
| 961 |
+
unique=unique, trim=trim, sign=self.sign == '+')
|
| 962 |
+
for x in finite_vals)
|
| 963 |
+
frac_strs, _, exp_strs = zip(*(s.partition('e') for s in strs))
|
| 964 |
+
int_part, frac_part = zip(*(s.split('.') for s in frac_strs))
|
| 965 |
+
self.exp_size = max(len(s) for s in exp_strs) - 1
|
| 966 |
+
|
| 967 |
+
self.trim = 'k'
|
| 968 |
+
self.precision = max(len(s) for s in frac_part)
|
| 969 |
+
self.min_digits = self.precision
|
| 970 |
+
self.unique = unique
|
| 971 |
+
|
| 972 |
+
# for back-compat with np 1.13, use 2 spaces & sign and full prec
|
| 973 |
+
if self._legacy <= 113:
|
| 974 |
+
self.pad_left = 3
|
| 975 |
+
else:
|
| 976 |
+
# this should be only 1 or 2. Can be calculated from sign.
|
| 977 |
+
self.pad_left = max(len(s) for s in int_part)
|
| 978 |
+
# pad_right is only needed for nan length calculation
|
| 979 |
+
self.pad_right = self.exp_size + 2 + self.precision
|
| 980 |
+
else:
|
| 981 |
+
trim, unique = '.', True
|
| 982 |
+
if self.floatmode == 'fixed':
|
| 983 |
+
trim, unique = 'k', False
|
| 984 |
+
strs = (dragon4_positional(x, precision=self.precision,
|
| 985 |
+
fractional=True,
|
| 986 |
+
unique=unique, trim=trim,
|
| 987 |
+
sign=self.sign == '+')
|
| 988 |
+
for x in finite_vals)
|
| 989 |
+
int_part, frac_part = zip(*(s.split('.') for s in strs))
|
| 990 |
+
if self._legacy <= 113:
|
| 991 |
+
self.pad_left = 1 + max(len(s.lstrip('-+')) for s in int_part)
|
| 992 |
+
else:
|
| 993 |
+
self.pad_left = max(len(s) for s in int_part)
|
| 994 |
+
self.pad_right = max(len(s) for s in frac_part)
|
| 995 |
+
self.exp_size = -1
|
| 996 |
+
self.unique = unique
|
| 997 |
+
|
| 998 |
+
if self.floatmode in ['fixed', 'maxprec_equal']:
|
| 999 |
+
self.precision = self.min_digits = self.pad_right
|
| 1000 |
+
self.trim = 'k'
|
| 1001 |
+
else:
|
| 1002 |
+
self.trim = '.'
|
| 1003 |
+
self.min_digits = 0
|
| 1004 |
+
|
| 1005 |
+
if self._legacy > 113:
|
| 1006 |
+
# account for sign = ' ' by adding one to pad_left
|
| 1007 |
+
if self.sign == ' ' and not any(np.signbit(finite_vals)):
|
| 1008 |
+
self.pad_left += 1
|
| 1009 |
+
|
| 1010 |
+
# if there are non-finite values, may need to increase pad_left
|
| 1011 |
+
if data.size != finite_vals.size:
|
| 1012 |
+
neginf = self.sign != '-' or any(data[isinf(data)] < 0)
|
| 1013 |
+
nanlen = len(_format_options['nanstr'])
|
| 1014 |
+
inflen = len(_format_options['infstr']) + neginf
|
| 1015 |
+
offset = self.pad_right + 1 # +1 for decimal pt
|
| 1016 |
+
self.pad_left = max(self.pad_left, nanlen - offset, inflen - offset)
|
| 1017 |
+
|
| 1018 |
+
def __call__(self, x):
|
| 1019 |
+
if not np.isfinite(x):
|
| 1020 |
+
with errstate(invalid='ignore'):
|
| 1021 |
+
if np.isnan(x):
|
| 1022 |
+
sign = '+' if self.sign == '+' else ''
|
| 1023 |
+
ret = sign + _format_options['nanstr']
|
| 1024 |
+
else: # isinf
|
| 1025 |
+
sign = '-' if x < 0 else '+' if self.sign == '+' else ''
|
| 1026 |
+
ret = sign + _format_options['infstr']
|
| 1027 |
+
return ' '*(self.pad_left + self.pad_right + 1 - len(ret)) + ret
|
| 1028 |
+
|
| 1029 |
+
if self.exp_format:
|
| 1030 |
+
return dragon4_scientific(x,
|
| 1031 |
+
precision=self.precision,
|
| 1032 |
+
min_digits=self.min_digits,
|
| 1033 |
+
unique=self.unique,
|
| 1034 |
+
trim=self.trim,
|
| 1035 |
+
sign=self.sign == '+',
|
| 1036 |
+
pad_left=self.pad_left,
|
| 1037 |
+
exp_digits=self.exp_size)
|
| 1038 |
+
else:
|
| 1039 |
+
return dragon4_positional(x,
|
| 1040 |
+
precision=self.precision,
|
| 1041 |
+
min_digits=self.min_digits,
|
| 1042 |
+
unique=self.unique,
|
| 1043 |
+
fractional=True,
|
| 1044 |
+
trim=self.trim,
|
| 1045 |
+
sign=self.sign == '+',
|
| 1046 |
+
pad_left=self.pad_left,
|
| 1047 |
+
pad_right=self.pad_right)
|
| 1048 |
+
|
| 1049 |
+
|
| 1050 |
+
@set_module('numpy')
|
| 1051 |
+
def format_float_scientific(x, precision=None, unique=True, trim='k',
|
| 1052 |
+
sign=False, pad_left=None, exp_digits=None,
|
| 1053 |
+
min_digits=None):
|
| 1054 |
+
"""
|
| 1055 |
+
Format a floating-point scalar as a decimal string in scientific notation.
|
| 1056 |
+
|
| 1057 |
+
Provides control over rounding, trimming and padding. Uses and assumes
|
| 1058 |
+
IEEE unbiased rounding. Uses the "Dragon4" algorithm.
|
| 1059 |
+
|
| 1060 |
+
Parameters
|
| 1061 |
+
----------
|
| 1062 |
+
x : python float or numpy floating scalar
|
| 1063 |
+
Value to format.
|
| 1064 |
+
precision : non-negative integer or None, optional
|
| 1065 |
+
Maximum number of digits to print. May be None if `unique` is
|
| 1066 |
+
`True`, but must be an integer if unique is `False`.
|
| 1067 |
+
unique : boolean, optional
|
| 1068 |
+
If `True`, use a digit-generation strategy which gives the shortest
|
| 1069 |
+
representation which uniquely identifies the floating-point number from
|
| 1070 |
+
other values of the same type, by judicious rounding. If `precision`
|
| 1071 |
+
is given fewer digits than necessary can be printed. If `min_digits`
|
| 1072 |
+
is given more can be printed, in which cases the last digit is rounded
|
| 1073 |
+
with unbiased rounding.
|
| 1074 |
+
If `False`, digits are generated as if printing an infinite-precision
|
| 1075 |
+
value and stopping after `precision` digits, rounding the remaining
|
| 1076 |
+
value with unbiased rounding
|
| 1077 |
+
trim : one of 'k', '.', '0', '-', optional
|
| 1078 |
+
Controls post-processing trimming of trailing digits, as follows:
|
| 1079 |
+
|
| 1080 |
+
* 'k' : keep trailing zeros, keep decimal point (no trimming)
|
| 1081 |
+
* '.' : trim all trailing zeros, leave decimal point
|
| 1082 |
+
* '0' : trim all but the zero before the decimal point. Insert the
|
| 1083 |
+
zero if it is missing.
|
| 1084 |
+
* '-' : trim trailing zeros and any trailing decimal point
|
| 1085 |
+
sign : boolean, optional
|
| 1086 |
+
Whether to show the sign for positive values.
|
| 1087 |
+
pad_left : non-negative integer, optional
|
| 1088 |
+
Pad the left side of the string with whitespace until at least that
|
| 1089 |
+
many characters are to the left of the decimal point.
|
| 1090 |
+
exp_digits : non-negative integer, optional
|
| 1091 |
+
Pad the exponent with zeros until it contains at least this many digits.
|
| 1092 |
+
If omitted, the exponent will be at least 2 digits.
|
| 1093 |
+
min_digits : non-negative integer or None, optional
|
| 1094 |
+
Minimum number of digits to print. This only has an effect for
|
| 1095 |
+
`unique=True`. In that case more digits than necessary to uniquely
|
| 1096 |
+
identify the value may be printed and rounded unbiased.
|
| 1097 |
+
|
| 1098 |
+
-- versionadded:: 1.21.0
|
| 1099 |
+
|
| 1100 |
+
Returns
|
| 1101 |
+
-------
|
| 1102 |
+
rep : string
|
| 1103 |
+
The string representation of the floating point value
|
| 1104 |
+
|
| 1105 |
+
See Also
|
| 1106 |
+
--------
|
| 1107 |
+
format_float_positional
|
| 1108 |
+
|
| 1109 |
+
Examples
|
| 1110 |
+
--------
|
| 1111 |
+
>>> np.format_float_scientific(np.float32(np.pi))
|
| 1112 |
+
'3.1415927e+00'
|
| 1113 |
+
>>> s = np.float32(1.23e24)
|
| 1114 |
+
>>> np.format_float_scientific(s, unique=False, precision=15)
|
| 1115 |
+
'1.230000071797338e+24'
|
| 1116 |
+
>>> np.format_float_scientific(s, exp_digits=4)
|
| 1117 |
+
'1.23e+0024'
|
| 1118 |
+
"""
|
| 1119 |
+
precision = _none_or_positive_arg(precision, 'precision')
|
| 1120 |
+
pad_left = _none_or_positive_arg(pad_left, 'pad_left')
|
| 1121 |
+
exp_digits = _none_or_positive_arg(exp_digits, 'exp_digits')
|
| 1122 |
+
min_digits = _none_or_positive_arg(min_digits, 'min_digits')
|
| 1123 |
+
if min_digits > 0 and precision > 0 and min_digits > precision:
|
| 1124 |
+
raise ValueError("min_digits must be less than or equal to precision")
|
| 1125 |
+
return dragon4_scientific(x, precision=precision, unique=unique,
|
| 1126 |
+
trim=trim, sign=sign, pad_left=pad_left,
|
| 1127 |
+
exp_digits=exp_digits, min_digits=min_digits)
|
| 1128 |
+
|
| 1129 |
+
|
| 1130 |
+
@set_module('numpy')
|
| 1131 |
+
def format_float_positional(x, precision=None, unique=True,
|
| 1132 |
+
fractional=True, trim='k', sign=False,
|
| 1133 |
+
pad_left=None, pad_right=None, min_digits=None):
|
| 1134 |
+
"""
|
| 1135 |
+
Format a floating-point scalar as a decimal string in positional notation.
|
| 1136 |
+
|
| 1137 |
+
Provides control over rounding, trimming and padding. Uses and assumes
|
| 1138 |
+
IEEE unbiased rounding. Uses the "Dragon4" algorithm.
|
| 1139 |
+
|
| 1140 |
+
Parameters
|
| 1141 |
+
----------
|
| 1142 |
+
x : python float or numpy floating scalar
|
| 1143 |
+
Value to format.
|
| 1144 |
+
precision : non-negative integer or None, optional
|
| 1145 |
+
Maximum number of digits to print. May be None if `unique` is
|
| 1146 |
+
`True`, but must be an integer if unique is `False`.
|
| 1147 |
+
unique : boolean, optional
|
| 1148 |
+
If `True`, use a digit-generation strategy which gives the shortest
|
| 1149 |
+
representation which uniquely identifies the floating-point number from
|
| 1150 |
+
other values of the same type, by judicious rounding. If `precision`
|
| 1151 |
+
is given fewer digits than necessary can be printed, or if `min_digits`
|
| 1152 |
+
is given more can be printed, in which cases the last digit is rounded
|
| 1153 |
+
with unbiased rounding.
|
| 1154 |
+
If `False`, digits are generated as if printing an infinite-precision
|
| 1155 |
+
value and stopping after `precision` digits, rounding the remaining
|
| 1156 |
+
value with unbiased rounding
|
| 1157 |
+
fractional : boolean, optional
|
| 1158 |
+
If `True`, the cutoffs of `precision` and `min_digits` refer to the
|
| 1159 |
+
total number of digits after the decimal point, including leading
|
| 1160 |
+
zeros.
|
| 1161 |
+
If `False`, `precision` and `min_digits` refer to the total number of
|
| 1162 |
+
significant digits, before or after the decimal point, ignoring leading
|
| 1163 |
+
zeros.
|
| 1164 |
+
trim : one of 'k', '.', '0', '-', optional
|
| 1165 |
+
Controls post-processing trimming of trailing digits, as follows:
|
| 1166 |
+
|
| 1167 |
+
* 'k' : keep trailing zeros, keep decimal point (no trimming)
|
| 1168 |
+
* '.' : trim all trailing zeros, leave decimal point
|
| 1169 |
+
* '0' : trim all but the zero before the decimal point. Insert the
|
| 1170 |
+
zero if it is missing.
|
| 1171 |
+
* '-' : trim trailing zeros and any trailing decimal point
|
| 1172 |
+
sign : boolean, optional
|
| 1173 |
+
Whether to show the sign for positive values.
|
| 1174 |
+
pad_left : non-negative integer, optional
|
| 1175 |
+
Pad the left side of the string with whitespace until at least that
|
| 1176 |
+
many characters are to the left of the decimal point.
|
| 1177 |
+
pad_right : non-negative integer, optional
|
| 1178 |
+
Pad the right side of the string with whitespace until at least that
|
| 1179 |
+
many characters are to the right of the decimal point.
|
| 1180 |
+
min_digits : non-negative integer or None, optional
|
| 1181 |
+
Minimum number of digits to print. Only has an effect if `unique=True`
|
| 1182 |
+
in which case additional digits past those necessary to uniquely
|
| 1183 |
+
identify the value may be printed, rounding the last additional digit.
|
| 1184 |
+
|
| 1185 |
+
-- versionadded:: 1.21.0
|
| 1186 |
+
|
| 1187 |
+
Returns
|
| 1188 |
+
-------
|
| 1189 |
+
rep : string
|
| 1190 |
+
The string representation of the floating point value
|
| 1191 |
+
|
| 1192 |
+
See Also
|
| 1193 |
+
--------
|
| 1194 |
+
format_float_scientific
|
| 1195 |
+
|
| 1196 |
+
Examples
|
| 1197 |
+
--------
|
| 1198 |
+
>>> np.format_float_positional(np.float32(np.pi))
|
| 1199 |
+
'3.1415927'
|
| 1200 |
+
>>> np.format_float_positional(np.float16(np.pi))
|
| 1201 |
+
'3.14'
|
| 1202 |
+
>>> np.format_float_positional(np.float16(0.3))
|
| 1203 |
+
'0.3'
|
| 1204 |
+
>>> np.format_float_positional(np.float16(0.3), unique=False, precision=10)
|
| 1205 |
+
'0.3000488281'
|
| 1206 |
+
"""
|
| 1207 |
+
precision = _none_or_positive_arg(precision, 'precision')
|
| 1208 |
+
pad_left = _none_or_positive_arg(pad_left, 'pad_left')
|
| 1209 |
+
pad_right = _none_or_positive_arg(pad_right, 'pad_right')
|
| 1210 |
+
min_digits = _none_or_positive_arg(min_digits, 'min_digits')
|
| 1211 |
+
if not fractional and precision == 0:
|
| 1212 |
+
raise ValueError("precision must be greater than 0 if "
|
| 1213 |
+
"fractional=False")
|
| 1214 |
+
if min_digits > 0 and precision > 0 and min_digits > precision:
|
| 1215 |
+
raise ValueError("min_digits must be less than or equal to precision")
|
| 1216 |
+
return dragon4_positional(x, precision=precision, unique=unique,
|
| 1217 |
+
fractional=fractional, trim=trim,
|
| 1218 |
+
sign=sign, pad_left=pad_left,
|
| 1219 |
+
pad_right=pad_right, min_digits=min_digits)
|
| 1220 |
+
|
| 1221 |
+
|
| 1222 |
+
class IntegerFormat:
|
| 1223 |
+
def __init__(self, data):
|
| 1224 |
+
if data.size > 0:
|
| 1225 |
+
max_str_len = max(len(str(np.max(data))),
|
| 1226 |
+
len(str(np.min(data))))
|
| 1227 |
+
else:
|
| 1228 |
+
max_str_len = 0
|
| 1229 |
+
self.format = '%{}d'.format(max_str_len)
|
| 1230 |
+
|
| 1231 |
+
def __call__(self, x):
|
| 1232 |
+
return self.format % x
|
| 1233 |
+
|
| 1234 |
+
|
| 1235 |
+
class BoolFormat:
|
| 1236 |
+
def __init__(self, data, **kwargs):
|
| 1237 |
+
# add an extra space so " True" and "False" have the same length and
|
| 1238 |
+
# array elements align nicely when printed, except in 0d arrays
|
| 1239 |
+
self.truestr = ' True' if data.shape != () else 'True'
|
| 1240 |
+
|
| 1241 |
+
def __call__(self, x):
|
| 1242 |
+
return self.truestr if x else "False"
|
| 1243 |
+
|
| 1244 |
+
|
| 1245 |
+
class ComplexFloatingFormat:
|
| 1246 |
+
""" Formatter for subtypes of np.complexfloating """
|
| 1247 |
+
def __init__(self, x, precision, floatmode, suppress_small,
|
| 1248 |
+
sign=False, *, legacy=None):
|
| 1249 |
+
# for backcompatibility, accept bools
|
| 1250 |
+
if isinstance(sign, bool):
|
| 1251 |
+
sign = '+' if sign else '-'
|
| 1252 |
+
|
| 1253 |
+
floatmode_real = floatmode_imag = floatmode
|
| 1254 |
+
if legacy <= 113:
|
| 1255 |
+
floatmode_real = 'maxprec_equal'
|
| 1256 |
+
floatmode_imag = 'maxprec'
|
| 1257 |
+
|
| 1258 |
+
self.real_format = FloatingFormat(
|
| 1259 |
+
x.real, precision, floatmode_real, suppress_small,
|
| 1260 |
+
sign=sign, legacy=legacy
|
| 1261 |
+
)
|
| 1262 |
+
self.imag_format = FloatingFormat(
|
| 1263 |
+
x.imag, precision, floatmode_imag, suppress_small,
|
| 1264 |
+
sign='+', legacy=legacy
|
| 1265 |
+
)
|
| 1266 |
+
|
| 1267 |
+
def __call__(self, x):
|
| 1268 |
+
r = self.real_format(x.real)
|
| 1269 |
+
i = self.imag_format(x.imag)
|
| 1270 |
+
|
| 1271 |
+
# add the 'j' before the terminal whitespace in i
|
| 1272 |
+
sp = len(i.rstrip())
|
| 1273 |
+
i = i[:sp] + 'j' + i[sp:]
|
| 1274 |
+
|
| 1275 |
+
return r + i
|
| 1276 |
+
|
| 1277 |
+
|
| 1278 |
+
class _TimelikeFormat:
|
| 1279 |
+
def __init__(self, data):
|
| 1280 |
+
non_nat = data[~isnat(data)]
|
| 1281 |
+
if len(non_nat) > 0:
|
| 1282 |
+
# Max str length of non-NaT elements
|
| 1283 |
+
max_str_len = max(len(self._format_non_nat(np.max(non_nat))),
|
| 1284 |
+
len(self._format_non_nat(np.min(non_nat))))
|
| 1285 |
+
else:
|
| 1286 |
+
max_str_len = 0
|
| 1287 |
+
if len(non_nat) < data.size:
|
| 1288 |
+
# data contains a NaT
|
| 1289 |
+
max_str_len = max(max_str_len, 5)
|
| 1290 |
+
self._format = '%{}s'.format(max_str_len)
|
| 1291 |
+
self._nat = "'NaT'".rjust(max_str_len)
|
| 1292 |
+
|
| 1293 |
+
def _format_non_nat(self, x):
|
| 1294 |
+
# override in subclass
|
| 1295 |
+
raise NotImplementedError
|
| 1296 |
+
|
| 1297 |
+
def __call__(self, x):
|
| 1298 |
+
if isnat(x):
|
| 1299 |
+
return self._nat
|
| 1300 |
+
else:
|
| 1301 |
+
return self._format % self._format_non_nat(x)
|
| 1302 |
+
|
| 1303 |
+
|
| 1304 |
+
class DatetimeFormat(_TimelikeFormat):
|
| 1305 |
+
def __init__(self, x, unit=None, timezone=None, casting='same_kind',
|
| 1306 |
+
legacy=False):
|
| 1307 |
+
# Get the unit from the dtype
|
| 1308 |
+
if unit is None:
|
| 1309 |
+
if x.dtype.kind == 'M':
|
| 1310 |
+
unit = datetime_data(x.dtype)[0]
|
| 1311 |
+
else:
|
| 1312 |
+
unit = 's'
|
| 1313 |
+
|
| 1314 |
+
if timezone is None:
|
| 1315 |
+
timezone = 'naive'
|
| 1316 |
+
self.timezone = timezone
|
| 1317 |
+
self.unit = unit
|
| 1318 |
+
self.casting = casting
|
| 1319 |
+
self.legacy = legacy
|
| 1320 |
+
|
| 1321 |
+
# must be called after the above are configured
|
| 1322 |
+
super().__init__(x)
|
| 1323 |
+
|
| 1324 |
+
def __call__(self, x):
|
| 1325 |
+
if self.legacy <= 113:
|
| 1326 |
+
return self._format_non_nat(x)
|
| 1327 |
+
return super().__call__(x)
|
| 1328 |
+
|
| 1329 |
+
def _format_non_nat(self, x):
|
| 1330 |
+
return "'%s'" % datetime_as_string(x,
|
| 1331 |
+
unit=self.unit,
|
| 1332 |
+
timezone=self.timezone,
|
| 1333 |
+
casting=self.casting)
|
| 1334 |
+
|
| 1335 |
+
|
| 1336 |
+
class TimedeltaFormat(_TimelikeFormat):
|
| 1337 |
+
def _format_non_nat(self, x):
|
| 1338 |
+
return str(x.astype('i8'))
|
| 1339 |
+
|
| 1340 |
+
|
| 1341 |
+
class SubArrayFormat:
|
| 1342 |
+
def __init__(self, format_function, **options):
|
| 1343 |
+
self.format_function = format_function
|
| 1344 |
+
self.threshold = options['threshold']
|
| 1345 |
+
self.edge_items = options['edgeitems']
|
| 1346 |
+
|
| 1347 |
+
def __call__(self, a):
|
| 1348 |
+
self.summary_insert = "..." if a.size > self.threshold else ""
|
| 1349 |
+
return self.format_array(a)
|
| 1350 |
+
|
| 1351 |
+
def format_array(self, a):
|
| 1352 |
+
if np.ndim(a) == 0:
|
| 1353 |
+
return self.format_function(a)
|
| 1354 |
+
|
| 1355 |
+
if self.summary_insert and a.shape[0] > 2*self.edge_items:
|
| 1356 |
+
formatted = (
|
| 1357 |
+
[self.format_array(a_) for a_ in a[:self.edge_items]]
|
| 1358 |
+
+ [self.summary_insert]
|
| 1359 |
+
+ [self.format_array(a_) for a_ in a[-self.edge_items:]]
|
| 1360 |
+
)
|
| 1361 |
+
else:
|
| 1362 |
+
formatted = [self.format_array(a_) for a_ in a]
|
| 1363 |
+
|
| 1364 |
+
return "[" + ", ".join(formatted) + "]"
|
| 1365 |
+
|
| 1366 |
+
|
| 1367 |
+
class StructuredVoidFormat:
|
| 1368 |
+
"""
|
| 1369 |
+
Formatter for structured np.void objects.
|
| 1370 |
+
|
| 1371 |
+
This does not work on structured alias types like np.dtype(('i4', 'i2,i2')),
|
| 1372 |
+
as alias scalars lose their field information, and the implementation
|
| 1373 |
+
relies upon np.void.__getitem__.
|
| 1374 |
+
"""
|
| 1375 |
+
def __init__(self, format_functions):
|
| 1376 |
+
self.format_functions = format_functions
|
| 1377 |
+
|
| 1378 |
+
@classmethod
|
| 1379 |
+
def from_data(cls, data, **options):
|
| 1380 |
+
"""
|
| 1381 |
+
This is a second way to initialize StructuredVoidFormat, using the raw data
|
| 1382 |
+
as input. Added to avoid changing the signature of __init__.
|
| 1383 |
+
"""
|
| 1384 |
+
format_functions = []
|
| 1385 |
+
for field_name in data.dtype.names:
|
| 1386 |
+
format_function = _get_format_function(data[field_name], **options)
|
| 1387 |
+
if data.dtype[field_name].shape != ():
|
| 1388 |
+
format_function = SubArrayFormat(format_function, **options)
|
| 1389 |
+
format_functions.append(format_function)
|
| 1390 |
+
return cls(format_functions)
|
| 1391 |
+
|
| 1392 |
+
def __call__(self, x):
|
| 1393 |
+
str_fields = [
|
| 1394 |
+
format_function(field)
|
| 1395 |
+
for field, format_function in zip(x, self.format_functions)
|
| 1396 |
+
]
|
| 1397 |
+
if len(str_fields) == 1:
|
| 1398 |
+
return "({},)".format(str_fields[0])
|
| 1399 |
+
else:
|
| 1400 |
+
return "({})".format(", ".join(str_fields))
|
| 1401 |
+
|
| 1402 |
+
|
| 1403 |
+
def _void_scalar_repr(x):
|
| 1404 |
+
"""
|
| 1405 |
+
Implements the repr for structured-void scalars. It is called from the
|
| 1406 |
+
scalartypes.c.src code, and is placed here because it uses the elementwise
|
| 1407 |
+
formatters defined above.
|
| 1408 |
+
"""
|
| 1409 |
+
return StructuredVoidFormat.from_data(array(x), **_format_options)(x)
|
| 1410 |
+
|
| 1411 |
+
|
| 1412 |
+
_typelessdata = [int_, float_, complex_, bool_]
|
| 1413 |
+
|
| 1414 |
+
|
| 1415 |
+
def dtype_is_implied(dtype):
|
| 1416 |
+
"""
|
| 1417 |
+
Determine if the given dtype is implied by the representation of its values.
|
| 1418 |
+
|
| 1419 |
+
Parameters
|
| 1420 |
+
----------
|
| 1421 |
+
dtype : dtype
|
| 1422 |
+
Data type
|
| 1423 |
+
|
| 1424 |
+
Returns
|
| 1425 |
+
-------
|
| 1426 |
+
implied : bool
|
| 1427 |
+
True if the dtype is implied by the representation of its values.
|
| 1428 |
+
|
| 1429 |
+
Examples
|
| 1430 |
+
--------
|
| 1431 |
+
>>> np.core.arrayprint.dtype_is_implied(int)
|
| 1432 |
+
True
|
| 1433 |
+
>>> np.array([1, 2, 3], int)
|
| 1434 |
+
array([1, 2, 3])
|
| 1435 |
+
>>> np.core.arrayprint.dtype_is_implied(np.int8)
|
| 1436 |
+
False
|
| 1437 |
+
>>> np.array([1, 2, 3], np.int8)
|
| 1438 |
+
array([1, 2, 3], dtype=int8)
|
| 1439 |
+
"""
|
| 1440 |
+
dtype = np.dtype(dtype)
|
| 1441 |
+
if _format_options['legacy'] <= 113 and dtype.type == bool_:
|
| 1442 |
+
return False
|
| 1443 |
+
|
| 1444 |
+
# not just void types can be structured, and names are not part of the repr
|
| 1445 |
+
if dtype.names is not None:
|
| 1446 |
+
return False
|
| 1447 |
+
|
| 1448 |
+
# should care about endianness *unless size is 1* (e.g., int8, bool)
|
| 1449 |
+
if not dtype.isnative:
|
| 1450 |
+
return False
|
| 1451 |
+
|
| 1452 |
+
return dtype.type in _typelessdata
|
| 1453 |
+
|
| 1454 |
+
|
| 1455 |
+
def dtype_short_repr(dtype):
|
| 1456 |
+
"""
|
| 1457 |
+
Convert a dtype to a short form which evaluates to the same dtype.
|
| 1458 |
+
|
| 1459 |
+
The intent is roughly that the following holds
|
| 1460 |
+
|
| 1461 |
+
>>> from numpy import *
|
| 1462 |
+
>>> dt = np.int64([1, 2]).dtype
|
| 1463 |
+
>>> assert eval(dtype_short_repr(dt)) == dt
|
| 1464 |
+
"""
|
| 1465 |
+
if type(dtype).__repr__ != np.dtype.__repr__:
|
| 1466 |
+
# TODO: Custom repr for user DTypes, logic should likely move.
|
| 1467 |
+
return repr(dtype)
|
| 1468 |
+
if dtype.names is not None:
|
| 1469 |
+
# structured dtypes give a list or tuple repr
|
| 1470 |
+
return str(dtype)
|
| 1471 |
+
elif issubclass(dtype.type, flexible):
|
| 1472 |
+
# handle these separately so they don't give garbage like str256
|
| 1473 |
+
return "'%s'" % str(dtype)
|
| 1474 |
+
|
| 1475 |
+
typename = dtype.name
|
| 1476 |
+
if not dtype.isnative:
|
| 1477 |
+
# deal with cases like dtype('<u2') that are identical to an
|
| 1478 |
+
# established dtype (in this case uint16)
|
| 1479 |
+
# except that they have a different endianness.
|
| 1480 |
+
return "'%s'" % str(dtype)
|
| 1481 |
+
# quote typenames which can't be represented as python variable names
|
| 1482 |
+
if typename and not (typename[0].isalpha() and typename.isalnum()):
|
| 1483 |
+
typename = repr(typename)
|
| 1484 |
+
return typename
|
| 1485 |
+
|
| 1486 |
+
|
| 1487 |
+
def _array_repr_implementation(
|
| 1488 |
+
arr, max_line_width=None, precision=None, suppress_small=None,
|
| 1489 |
+
array2string=array2string):
|
| 1490 |
+
"""Internal version of array_repr() that allows overriding array2string."""
|
| 1491 |
+
if max_line_width is None:
|
| 1492 |
+
max_line_width = _format_options['linewidth']
|
| 1493 |
+
|
| 1494 |
+
if type(arr) is not ndarray:
|
| 1495 |
+
class_name = type(arr).__name__
|
| 1496 |
+
else:
|
| 1497 |
+
class_name = "array"
|
| 1498 |
+
|
| 1499 |
+
skipdtype = dtype_is_implied(arr.dtype) and arr.size > 0
|
| 1500 |
+
|
| 1501 |
+
prefix = class_name + "("
|
| 1502 |
+
suffix = ")" if skipdtype else ","
|
| 1503 |
+
|
| 1504 |
+
if (_format_options['legacy'] <= 113 and
|
| 1505 |
+
arr.shape == () and not arr.dtype.names):
|
| 1506 |
+
lst = repr(arr.item())
|
| 1507 |
+
elif arr.size > 0 or arr.shape == (0,):
|
| 1508 |
+
lst = array2string(arr, max_line_width, precision, suppress_small,
|
| 1509 |
+
', ', prefix, suffix=suffix)
|
| 1510 |
+
else: # show zero-length shape unless it is (0,)
|
| 1511 |
+
lst = "[], shape=%s" % (repr(arr.shape),)
|
| 1512 |
+
|
| 1513 |
+
arr_str = prefix + lst + suffix
|
| 1514 |
+
|
| 1515 |
+
if skipdtype:
|
| 1516 |
+
return arr_str
|
| 1517 |
+
|
| 1518 |
+
dtype_str = "dtype={})".format(dtype_short_repr(arr.dtype))
|
| 1519 |
+
|
| 1520 |
+
# compute whether we should put dtype on a new line: Do so if adding the
|
| 1521 |
+
# dtype would extend the last line past max_line_width.
|
| 1522 |
+
# Note: This line gives the correct result even when rfind returns -1.
|
| 1523 |
+
last_line_len = len(arr_str) - (arr_str.rfind('\n') + 1)
|
| 1524 |
+
spacer = " "
|
| 1525 |
+
if _format_options['legacy'] <= 113:
|
| 1526 |
+
if issubclass(arr.dtype.type, flexible):
|
| 1527 |
+
spacer = '\n' + ' '*len(class_name + "(")
|
| 1528 |
+
elif last_line_len + len(dtype_str) + 1 > max_line_width:
|
| 1529 |
+
spacer = '\n' + ' '*len(class_name + "(")
|
| 1530 |
+
|
| 1531 |
+
return arr_str + spacer + dtype_str
|
| 1532 |
+
|
| 1533 |
+
|
| 1534 |
+
def _array_repr_dispatcher(
|
| 1535 |
+
arr, max_line_width=None, precision=None, suppress_small=None):
|
| 1536 |
+
return (arr,)
|
| 1537 |
+
|
| 1538 |
+
|
| 1539 |
+
@array_function_dispatch(_array_repr_dispatcher, module='numpy')
|
| 1540 |
+
def array_repr(arr, max_line_width=None, precision=None, suppress_small=None):
|
| 1541 |
+
"""
|
| 1542 |
+
Return the string representation of an array.
|
| 1543 |
+
|
| 1544 |
+
Parameters
|
| 1545 |
+
----------
|
| 1546 |
+
arr : ndarray
|
| 1547 |
+
Input array.
|
| 1548 |
+
max_line_width : int, optional
|
| 1549 |
+
Inserts newlines if text is longer than `max_line_width`.
|
| 1550 |
+
Defaults to ``numpy.get_printoptions()['linewidth']``.
|
| 1551 |
+
precision : int, optional
|
| 1552 |
+
Floating point precision.
|
| 1553 |
+
Defaults to ``numpy.get_printoptions()['precision']``.
|
| 1554 |
+
suppress_small : bool, optional
|
| 1555 |
+
Represent numbers "very close" to zero as zero; default is False.
|
| 1556 |
+
Very close is defined by precision: if the precision is 8, e.g.,
|
| 1557 |
+
numbers smaller (in absolute value) than 5e-9 are represented as
|
| 1558 |
+
zero.
|
| 1559 |
+
Defaults to ``numpy.get_printoptions()['suppress']``.
|
| 1560 |
+
|
| 1561 |
+
Returns
|
| 1562 |
+
-------
|
| 1563 |
+
string : str
|
| 1564 |
+
The string representation of an array.
|
| 1565 |
+
|
| 1566 |
+
See Also
|
| 1567 |
+
--------
|
| 1568 |
+
array_str, array2string, set_printoptions
|
| 1569 |
+
|
| 1570 |
+
Examples
|
| 1571 |
+
--------
|
| 1572 |
+
>>> np.array_repr(np.array([1,2]))
|
| 1573 |
+
'array([1, 2])'
|
| 1574 |
+
>>> np.array_repr(np.ma.array([0.]))
|
| 1575 |
+
'MaskedArray([0.])'
|
| 1576 |
+
>>> np.array_repr(np.array([], np.int32))
|
| 1577 |
+
'array([], dtype=int32)'
|
| 1578 |
+
|
| 1579 |
+
>>> x = np.array([1e-6, 4e-7, 2, 3])
|
| 1580 |
+
>>> np.array_repr(x, precision=6, suppress_small=True)
|
| 1581 |
+
'array([0.000001, 0. , 2. , 3. ])'
|
| 1582 |
+
|
| 1583 |
+
"""
|
| 1584 |
+
return _array_repr_implementation(
|
| 1585 |
+
arr, max_line_width, precision, suppress_small)
|
| 1586 |
+
|
| 1587 |
+
|
| 1588 |
+
@_recursive_guard()
|
| 1589 |
+
def _guarded_repr_or_str(v):
|
| 1590 |
+
if isinstance(v, bytes):
|
| 1591 |
+
return repr(v)
|
| 1592 |
+
return str(v)
|
| 1593 |
+
|
| 1594 |
+
|
| 1595 |
+
def _array_str_implementation(
|
| 1596 |
+
a, max_line_width=None, precision=None, suppress_small=None,
|
| 1597 |
+
array2string=array2string):
|
| 1598 |
+
"""Internal version of array_str() that allows overriding array2string."""
|
| 1599 |
+
if (_format_options['legacy'] <= 113 and
|
| 1600 |
+
a.shape == () and not a.dtype.names):
|
| 1601 |
+
return str(a.item())
|
| 1602 |
+
|
| 1603 |
+
# the str of 0d arrays is a special case: It should appear like a scalar,
|
| 1604 |
+
# so floats are not truncated by `precision`, and strings are not wrapped
|
| 1605 |
+
# in quotes. So we return the str of the scalar value.
|
| 1606 |
+
if a.shape == ():
|
| 1607 |
+
# obtain a scalar and call str on it, avoiding problems for subclasses
|
| 1608 |
+
# for which indexing with () returns a 0d instead of a scalar by using
|
| 1609 |
+
# ndarray's getindex. Also guard against recursive 0d object arrays.
|
| 1610 |
+
return _guarded_repr_or_str(np.ndarray.__getitem__(a, ()))
|
| 1611 |
+
|
| 1612 |
+
return array2string(a, max_line_width, precision, suppress_small, ' ', "")
|
| 1613 |
+
|
| 1614 |
+
|
| 1615 |
+
def _array_str_dispatcher(
|
| 1616 |
+
a, max_line_width=None, precision=None, suppress_small=None):
|
| 1617 |
+
return (a,)
|
| 1618 |
+
|
| 1619 |
+
|
| 1620 |
+
@array_function_dispatch(_array_str_dispatcher, module='numpy')
|
| 1621 |
+
def array_str(a, max_line_width=None, precision=None, suppress_small=None):
|
| 1622 |
+
"""
|
| 1623 |
+
Return a string representation of the data in an array.
|
| 1624 |
+
|
| 1625 |
+
The data in the array is returned as a single string. This function is
|
| 1626 |
+
similar to `array_repr`, the difference being that `array_repr` also
|
| 1627 |
+
returns information on the kind of array and its data type.
|
| 1628 |
+
|
| 1629 |
+
Parameters
|
| 1630 |
+
----------
|
| 1631 |
+
a : ndarray
|
| 1632 |
+
Input array.
|
| 1633 |
+
max_line_width : int, optional
|
| 1634 |
+
Inserts newlines if text is longer than `max_line_width`.
|
| 1635 |
+
Defaults to ``numpy.get_printoptions()['linewidth']``.
|
| 1636 |
+
precision : int, optional
|
| 1637 |
+
Floating point precision.
|
| 1638 |
+
Defaults to ``numpy.get_printoptions()['precision']``.
|
| 1639 |
+
suppress_small : bool, optional
|
| 1640 |
+
Represent numbers "very close" to zero as zero; default is False.
|
| 1641 |
+
Very close is defined by precision: if the precision is 8, e.g.,
|
| 1642 |
+
numbers smaller (in absolute value) than 5e-9 are represented as
|
| 1643 |
+
zero.
|
| 1644 |
+
Defaults to ``numpy.get_printoptions()['suppress']``.
|
| 1645 |
+
|
| 1646 |
+
See Also
|
| 1647 |
+
--------
|
| 1648 |
+
array2string, array_repr, set_printoptions
|
| 1649 |
+
|
| 1650 |
+
Examples
|
| 1651 |
+
--------
|
| 1652 |
+
>>> np.array_str(np.arange(3))
|
| 1653 |
+
'[0 1 2]'
|
| 1654 |
+
|
| 1655 |
+
"""
|
| 1656 |
+
return _array_str_implementation(
|
| 1657 |
+
a, max_line_width, precision, suppress_small)
|
| 1658 |
+
|
| 1659 |
+
|
| 1660 |
+
# needed if __array_function__ is disabled
|
| 1661 |
+
_array2string_impl = getattr(array2string, '__wrapped__', array2string)
|
| 1662 |
+
_default_array_str = functools.partial(_array_str_implementation,
|
| 1663 |
+
array2string=_array2string_impl)
|
| 1664 |
+
_default_array_repr = functools.partial(_array_repr_implementation,
|
| 1665 |
+
array2string=_array2string_impl)
|
| 1666 |
+
|
| 1667 |
+
|
| 1668 |
+
def set_string_function(f, repr=True):
|
| 1669 |
+
"""
|
| 1670 |
+
Set a Python function to be used when pretty printing arrays.
|
| 1671 |
+
|
| 1672 |
+
Parameters
|
| 1673 |
+
----------
|
| 1674 |
+
f : function or None
|
| 1675 |
+
Function to be used to pretty print arrays. The function should expect
|
| 1676 |
+
a single array argument and return a string of the representation of
|
| 1677 |
+
the array. If None, the function is reset to the default NumPy function
|
| 1678 |
+
to print arrays.
|
| 1679 |
+
repr : bool, optional
|
| 1680 |
+
If True (default), the function for pretty printing (``__repr__``)
|
| 1681 |
+
is set, if False the function that returns the default string
|
| 1682 |
+
representation (``__str__``) is set.
|
| 1683 |
+
|
| 1684 |
+
See Also
|
| 1685 |
+
--------
|
| 1686 |
+
set_printoptions, get_printoptions
|
| 1687 |
+
|
| 1688 |
+
Examples
|
| 1689 |
+
--------
|
| 1690 |
+
>>> def pprint(arr):
|
| 1691 |
+
... return 'HA! - What are you going to do now?'
|
| 1692 |
+
...
|
| 1693 |
+
>>> np.set_string_function(pprint)
|
| 1694 |
+
>>> a = np.arange(10)
|
| 1695 |
+
>>> a
|
| 1696 |
+
HA! - What are you going to do now?
|
| 1697 |
+
>>> _ = a
|
| 1698 |
+
>>> # [0 1 2 3 4 5 6 7 8 9]
|
| 1699 |
+
|
| 1700 |
+
We can reset the function to the default:
|
| 1701 |
+
|
| 1702 |
+
>>> np.set_string_function(None)
|
| 1703 |
+
>>> a
|
| 1704 |
+
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
|
| 1705 |
+
|
| 1706 |
+
`repr` affects either pretty printing or normal string representation.
|
| 1707 |
+
Note that ``__repr__`` is still affected by setting ``__str__``
|
| 1708 |
+
because the width of each array element in the returned string becomes
|
| 1709 |
+
equal to the length of the result of ``__str__()``.
|
| 1710 |
+
|
| 1711 |
+
>>> x = np.arange(4)
|
| 1712 |
+
>>> np.set_string_function(lambda x:'random', repr=False)
|
| 1713 |
+
>>> x.__str__()
|
| 1714 |
+
'random'
|
| 1715 |
+
>>> x.__repr__()
|
| 1716 |
+
'array([0, 1, 2, 3])'
|
| 1717 |
+
|
| 1718 |
+
"""
|
| 1719 |
+
if f is None:
|
| 1720 |
+
if repr:
|
| 1721 |
+
return multiarray.set_string_function(_default_array_repr, 1)
|
| 1722 |
+
else:
|
| 1723 |
+
return multiarray.set_string_function(_default_array_str, 0)
|
| 1724 |
+
else:
|
| 1725 |
+
return multiarray.set_string_function(f, repr)
|
.venv/lib/python3.11/site-packages/numpy/core/arrayprint.pyi
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from types import TracebackType
|
| 2 |
+
from collections.abc import Callable
|
| 3 |
+
from typing import Any, Literal, TypedDict, SupportsIndex
|
| 4 |
+
|
| 5 |
+
# Using a private class is by no means ideal, but it is simply a consequence
|
| 6 |
+
# of a `contextlib.context` returning an instance of aforementioned class
|
| 7 |
+
from contextlib import _GeneratorContextManager
|
| 8 |
+
|
| 9 |
+
from numpy import (
|
| 10 |
+
ndarray,
|
| 11 |
+
generic,
|
| 12 |
+
bool_,
|
| 13 |
+
integer,
|
| 14 |
+
timedelta64,
|
| 15 |
+
datetime64,
|
| 16 |
+
floating,
|
| 17 |
+
complexfloating,
|
| 18 |
+
void,
|
| 19 |
+
str_,
|
| 20 |
+
bytes_,
|
| 21 |
+
longdouble,
|
| 22 |
+
clongdouble,
|
| 23 |
+
)
|
| 24 |
+
from numpy._typing import ArrayLike, _CharLike_co, _FloatLike_co
|
| 25 |
+
|
| 26 |
+
_FloatMode = Literal["fixed", "unique", "maxprec", "maxprec_equal"]
|
| 27 |
+
|
| 28 |
+
class _FormatDict(TypedDict, total=False):
|
| 29 |
+
bool: Callable[[bool_], str]
|
| 30 |
+
int: Callable[[integer[Any]], str]
|
| 31 |
+
timedelta: Callable[[timedelta64], str]
|
| 32 |
+
datetime: Callable[[datetime64], str]
|
| 33 |
+
float: Callable[[floating[Any]], str]
|
| 34 |
+
longfloat: Callable[[longdouble], str]
|
| 35 |
+
complexfloat: Callable[[complexfloating[Any, Any]], str]
|
| 36 |
+
longcomplexfloat: Callable[[clongdouble], str]
|
| 37 |
+
void: Callable[[void], str]
|
| 38 |
+
numpystr: Callable[[_CharLike_co], str]
|
| 39 |
+
object: Callable[[object], str]
|
| 40 |
+
all: Callable[[object], str]
|
| 41 |
+
int_kind: Callable[[integer[Any]], str]
|
| 42 |
+
float_kind: Callable[[floating[Any]], str]
|
| 43 |
+
complex_kind: Callable[[complexfloating[Any, Any]], str]
|
| 44 |
+
str_kind: Callable[[_CharLike_co], str]
|
| 45 |
+
|
| 46 |
+
class _FormatOptions(TypedDict):
|
| 47 |
+
precision: int
|
| 48 |
+
threshold: int
|
| 49 |
+
edgeitems: int
|
| 50 |
+
linewidth: int
|
| 51 |
+
suppress: bool
|
| 52 |
+
nanstr: str
|
| 53 |
+
infstr: str
|
| 54 |
+
formatter: None | _FormatDict
|
| 55 |
+
sign: Literal["-", "+", " "]
|
| 56 |
+
floatmode: _FloatMode
|
| 57 |
+
legacy: Literal[False, "1.13", "1.21"]
|
| 58 |
+
|
| 59 |
+
def set_printoptions(
|
| 60 |
+
precision: None | SupportsIndex = ...,
|
| 61 |
+
threshold: None | int = ...,
|
| 62 |
+
edgeitems: None | int = ...,
|
| 63 |
+
linewidth: None | int = ...,
|
| 64 |
+
suppress: None | bool = ...,
|
| 65 |
+
nanstr: None | str = ...,
|
| 66 |
+
infstr: None | str = ...,
|
| 67 |
+
formatter: None | _FormatDict = ...,
|
| 68 |
+
sign: Literal[None, "-", "+", " "] = ...,
|
| 69 |
+
floatmode: None | _FloatMode = ...,
|
| 70 |
+
*,
|
| 71 |
+
legacy: Literal[None, False, "1.13", "1.21"] = ...
|
| 72 |
+
) -> None: ...
|
| 73 |
+
def get_printoptions() -> _FormatOptions: ...
|
| 74 |
+
def array2string(
|
| 75 |
+
a: ndarray[Any, Any],
|
| 76 |
+
max_line_width: None | int = ...,
|
| 77 |
+
precision: None | SupportsIndex = ...,
|
| 78 |
+
suppress_small: None | bool = ...,
|
| 79 |
+
separator: str = ...,
|
| 80 |
+
prefix: str = ...,
|
| 81 |
+
# NOTE: With the `style` argument being deprecated,
|
| 82 |
+
# all arguments between `formatter` and `suffix` are de facto
|
| 83 |
+
# keyworld-only arguments
|
| 84 |
+
*,
|
| 85 |
+
formatter: None | _FormatDict = ...,
|
| 86 |
+
threshold: None | int = ...,
|
| 87 |
+
edgeitems: None | int = ...,
|
| 88 |
+
sign: Literal[None, "-", "+", " "] = ...,
|
| 89 |
+
floatmode: None | _FloatMode = ...,
|
| 90 |
+
suffix: str = ...,
|
| 91 |
+
legacy: Literal[None, False, "1.13", "1.21"] = ...,
|
| 92 |
+
) -> str: ...
|
| 93 |
+
def format_float_scientific(
|
| 94 |
+
x: _FloatLike_co,
|
| 95 |
+
precision: None | int = ...,
|
| 96 |
+
unique: bool = ...,
|
| 97 |
+
trim: Literal["k", ".", "0", "-"] = ...,
|
| 98 |
+
sign: bool = ...,
|
| 99 |
+
pad_left: None | int = ...,
|
| 100 |
+
exp_digits: None | int = ...,
|
| 101 |
+
min_digits: None | int = ...,
|
| 102 |
+
) -> str: ...
|
| 103 |
+
def format_float_positional(
|
| 104 |
+
x: _FloatLike_co,
|
| 105 |
+
precision: None | int = ...,
|
| 106 |
+
unique: bool = ...,
|
| 107 |
+
fractional: bool = ...,
|
| 108 |
+
trim: Literal["k", ".", "0", "-"] = ...,
|
| 109 |
+
sign: bool = ...,
|
| 110 |
+
pad_left: None | int = ...,
|
| 111 |
+
pad_right: None | int = ...,
|
| 112 |
+
min_digits: None | int = ...,
|
| 113 |
+
) -> str: ...
|
| 114 |
+
def array_repr(
|
| 115 |
+
arr: ndarray[Any, Any],
|
| 116 |
+
max_line_width: None | int = ...,
|
| 117 |
+
precision: None | SupportsIndex = ...,
|
| 118 |
+
suppress_small: None | bool = ...,
|
| 119 |
+
) -> str: ...
|
| 120 |
+
def array_str(
|
| 121 |
+
a: ndarray[Any, Any],
|
| 122 |
+
max_line_width: None | int = ...,
|
| 123 |
+
precision: None | SupportsIndex = ...,
|
| 124 |
+
suppress_small: None | bool = ...,
|
| 125 |
+
) -> str: ...
|
| 126 |
+
def set_string_function(
|
| 127 |
+
f: None | Callable[[ndarray[Any, Any]], str], repr: bool = ...
|
| 128 |
+
) -> None: ...
|
| 129 |
+
def printoptions(
|
| 130 |
+
precision: None | SupportsIndex = ...,
|
| 131 |
+
threshold: None | int = ...,
|
| 132 |
+
edgeitems: None | int = ...,
|
| 133 |
+
linewidth: None | int = ...,
|
| 134 |
+
suppress: None | bool = ...,
|
| 135 |
+
nanstr: None | str = ...,
|
| 136 |
+
infstr: None | str = ...,
|
| 137 |
+
formatter: None | _FormatDict = ...,
|
| 138 |
+
sign: Literal[None, "-", "+", " "] = ...,
|
| 139 |
+
floatmode: None | _FloatMode = ...,
|
| 140 |
+
*,
|
| 141 |
+
legacy: Literal[None, False, "1.13", "1.21"] = ...
|
| 142 |
+
) -> _GeneratorContextManager[_FormatOptions]: ...
|
.venv/lib/python3.11/site-packages/numpy/core/defchararray.py
ADDED
|
@@ -0,0 +1,2914 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ations and methods.
|
| 4 |
+
|
| 5 |
+
.. note::
|
| 6 |
+
The `chararray` class exists for backwards compatibility with
|
| 7 |
+
Numarray, it is not recommended for new development. Starting from numpy
|
| 8 |
+
1.4, if one needs arrays of strings, it is recommended to use arrays of
|
| 9 |
+
`dtype` `object_`, `bytes_` or `str_`, and use the free functions
|
| 10 |
+
in the `numpy.char` module for fast vectorized string operations.
|
| 11 |
+
|
| 12 |
+
Some methods will only be available if the corresponding string method is
|
| 13 |
+
available in your version of Python.
|
| 14 |
+
|
| 15 |
+
The preferred alias for `defchararray` is `numpy.char`.
|
| 16 |
+
|
| 17 |
+
"""
|
| 18 |
+
import functools
|
| 19 |
+
|
| 20 |
+
from .._utils import set_module
|
| 21 |
+
from .numerictypes import (
|
| 22 |
+
bytes_, str_, integer, int_, object_, bool_, character)
|
| 23 |
+
from .numeric import ndarray, compare_chararrays
|
| 24 |
+
from .numeric import array as narray
|
| 25 |
+
from numpy.core.multiarray import _vec_string
|
| 26 |
+
from numpy.core import overrides
|
| 27 |
+
from numpy.compat import asbytes
|
| 28 |
+
import numpy
|
| 29 |
+
|
| 30 |
+
__all__ = [
|
| 31 |
+
'equal', 'not_equal', 'greater_equal', 'less_equal',
|
| 32 |
+
'greater', 'less', 'str_len', 'add', 'multiply', 'mod', 'capitalize',
|
| 33 |
+
'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs',
|
| 34 |
+
'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace',
|
| 35 |
+
'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition',
|
| 36 |
+
'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit',
|
| 37 |
+
'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase',
|
| 38 |
+
'title', 'translate', 'upper', 'zfill', 'isnumeric', 'isdecimal',
|
| 39 |
+
'array', 'asarray'
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
_globalvar = 0
|
| 44 |
+
|
| 45 |
+
array_function_dispatch = functools.partial(
|
| 46 |
+
overrides.array_function_dispatch, module='numpy.char')
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _is_unicode(arr):
|
| 50 |
+
"""Returns True if arr is a string or a string array with a dtype that
|
| 51 |
+
represents a unicode string, otherwise returns False.
|
| 52 |
+
|
| 53 |
+
"""
|
| 54 |
+
if (isinstance(arr, str) or
|
| 55 |
+
issubclass(numpy.asarray(arr).dtype.type, str)):
|
| 56 |
+
return True
|
| 57 |
+
return False
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _to_bytes_or_str_array(result, output_dtype_like=None):
|
| 61 |
+
"""
|
| 62 |
+
Helper function to cast a result back into an array
|
| 63 |
+
with the appropriate dtype if an object array must be used
|
| 64 |
+
as an intermediary.
|
| 65 |
+
"""
|
| 66 |
+
ret = numpy.asarray(result.tolist())
|
| 67 |
+
dtype = getattr(output_dtype_like, 'dtype', None)
|
| 68 |
+
if dtype is not None:
|
| 69 |
+
return ret.astype(type(dtype)(_get_num_chars(ret)), copy=False)
|
| 70 |
+
return ret
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _clean_args(*args):
|
| 74 |
+
"""
|
| 75 |
+
Helper function for delegating arguments to Python string
|
| 76 |
+
functions.
|
| 77 |
+
|
| 78 |
+
Many of the Python string operations that have optional arguments
|
| 79 |
+
do not use 'None' to indicate a default value. In these cases,
|
| 80 |
+
we need to remove all None arguments, and those following them.
|
| 81 |
+
"""
|
| 82 |
+
newargs = []
|
| 83 |
+
for chk in args:
|
| 84 |
+
if chk is None:
|
| 85 |
+
break
|
| 86 |
+
newargs.append(chk)
|
| 87 |
+
return newargs
|
| 88 |
+
|
| 89 |
+
def _get_num_chars(a):
|
| 90 |
+
"""
|
| 91 |
+
Helper function that returns the number of characters per field in
|
| 92 |
+
a string or unicode array. This is to abstract out the fact that
|
| 93 |
+
for a unicode array this is itemsize / 4.
|
| 94 |
+
"""
|
| 95 |
+
if issubclass(a.dtype.type, str_):
|
| 96 |
+
return a.itemsize // 4
|
| 97 |
+
return a.itemsize
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def _binary_op_dispatcher(x1, x2):
|
| 101 |
+
return (x1, x2)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
@array_function_dispatch(_binary_op_dispatcher)
|
| 105 |
+
def equal(x1, x2):
|
| 106 |
+
"""
|
| 107 |
+
Return (x1 == x2) element-wise.
|
| 108 |
+
|
| 109 |
+
Unlike `numpy.equal`, this comparison is performed by first
|
| 110 |
+
stripping whitespace characters from the end of the string. This
|
| 111 |
+
behavior is provided for backward-compatibility with numarray.
|
| 112 |
+
|
| 113 |
+
Parameters
|
| 114 |
+
----------
|
| 115 |
+
x1, x2 : array_like of str or unicode
|
| 116 |
+
Input arrays of the same shape.
|
| 117 |
+
|
| 118 |
+
Returns
|
| 119 |
+
-------
|
| 120 |
+
out : ndarray
|
| 121 |
+
Output array of bools.
|
| 122 |
+
|
| 123 |
+
See Also
|
| 124 |
+
--------
|
| 125 |
+
not_equal, greater_equal, less_equal, greater, less
|
| 126 |
+
"""
|
| 127 |
+
return compare_chararrays(x1, x2, '==', True)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
@array_function_dispatch(_binary_op_dispatcher)
|
| 131 |
+
def not_equal(x1, x2):
|
| 132 |
+
"""
|
| 133 |
+
Return (x1 != x2) element-wise.
|
| 134 |
+
|
| 135 |
+
Unlike `numpy.not_equal`, this comparison is performed by first
|
| 136 |
+
stripping whitespace characters from the end of the string. This
|
| 137 |
+
behavior is provided for backward-compatibility with numarray.
|
| 138 |
+
|
| 139 |
+
Parameters
|
| 140 |
+
----------
|
| 141 |
+
x1, x2 : array_like of str or unicode
|
| 142 |
+
Input arrays of the same shape.
|
| 143 |
+
|
| 144 |
+
Returns
|
| 145 |
+
-------
|
| 146 |
+
out : ndarray
|
| 147 |
+
Output array of bools.
|
| 148 |
+
|
| 149 |
+
See Also
|
| 150 |
+
--------
|
| 151 |
+
equal, greater_equal, less_equal, greater, less
|
| 152 |
+
"""
|
| 153 |
+
return compare_chararrays(x1, x2, '!=', True)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
@array_function_dispatch(_binary_op_dispatcher)
|
| 157 |
+
def greater_equal(x1, x2):
|
| 158 |
+
"""
|
| 159 |
+
Return (x1 >= x2) element-wise.
|
| 160 |
+
|
| 161 |
+
Unlike `numpy.greater_equal`, this comparison is performed by
|
| 162 |
+
first stripping whitespace characters from the end of the string.
|
| 163 |
+
This behavior is provided for backward-compatibility with
|
| 164 |
+
numarray.
|
| 165 |
+
|
| 166 |
+
Parameters
|
| 167 |
+
----------
|
| 168 |
+
x1, x2 : array_like of str or unicode
|
| 169 |
+
Input arrays of the same shape.
|
| 170 |
+
|
| 171 |
+
Returns
|
| 172 |
+
-------
|
| 173 |
+
out : ndarray
|
| 174 |
+
Output array of bools.
|
| 175 |
+
|
| 176 |
+
See Also
|
| 177 |
+
--------
|
| 178 |
+
equal, not_equal, less_equal, greater, less
|
| 179 |
+
"""
|
| 180 |
+
return compare_chararrays(x1, x2, '>=', True)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
@array_function_dispatch(_binary_op_dispatcher)
|
| 184 |
+
def less_equal(x1, x2):
|
| 185 |
+
"""
|
| 186 |
+
Return (x1 <= x2) element-wise.
|
| 187 |
+
|
| 188 |
+
Unlike `numpy.less_equal`, this comparison is performed by first
|
| 189 |
+
stripping whitespace characters from the end of the string. This
|
| 190 |
+
behavior is provided for backward-compatibility with numarray.
|
| 191 |
+
|
| 192 |
+
Parameters
|
| 193 |
+
----------
|
| 194 |
+
x1, x2 : array_like of str or unicode
|
| 195 |
+
Input arrays of the same shape.
|
| 196 |
+
|
| 197 |
+
Returns
|
| 198 |
+
-------
|
| 199 |
+
out : ndarray
|
| 200 |
+
Output array of bools.
|
| 201 |
+
|
| 202 |
+
See Also
|
| 203 |
+
--------
|
| 204 |
+
equal, not_equal, greater_equal, greater, less
|
| 205 |
+
"""
|
| 206 |
+
return compare_chararrays(x1, x2, '<=', True)
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
@array_function_dispatch(_binary_op_dispatcher)
|
| 210 |
+
def greater(x1, x2):
|
| 211 |
+
"""
|
| 212 |
+
Return (x1 > x2) element-wise.
|
| 213 |
+
|
| 214 |
+
Unlike `numpy.greater`, this comparison is performed by first
|
| 215 |
+
stripping whitespace characters from the end of the string. This
|
| 216 |
+
behavior is provided for backward-compatibility with numarray.
|
| 217 |
+
|
| 218 |
+
Parameters
|
| 219 |
+
----------
|
| 220 |
+
x1, x2 : array_like of str or unicode
|
| 221 |
+
Input arrays of the same shape.
|
| 222 |
+
|
| 223 |
+
Returns
|
| 224 |
+
-------
|
| 225 |
+
out : ndarray
|
| 226 |
+
Output array of bools.
|
| 227 |
+
|
| 228 |
+
See Also
|
| 229 |
+
--------
|
| 230 |
+
equal, not_equal, greater_equal, less_equal, less
|
| 231 |
+
"""
|
| 232 |
+
return compare_chararrays(x1, x2, '>', True)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
@array_function_dispatch(_binary_op_dispatcher)
|
| 236 |
+
def less(x1, x2):
|
| 237 |
+
"""
|
| 238 |
+
Return (x1 < x2) element-wise.
|
| 239 |
+
|
| 240 |
+
Unlike `numpy.greater`, this comparison is performed by first
|
| 241 |
+
stripping whitespace characters from the end of the string. This
|
| 242 |
+
behavior is provided for backward-compatibility with numarray.
|
| 243 |
+
|
| 244 |
+
Parameters
|
| 245 |
+
----------
|
| 246 |
+
x1, x2 : array_like of str or unicode
|
| 247 |
+
Input arrays of the same shape.
|
| 248 |
+
|
| 249 |
+
Returns
|
| 250 |
+
-------
|
| 251 |
+
out : ndarray
|
| 252 |
+
Output array of bools.
|
| 253 |
+
|
| 254 |
+
See Also
|
| 255 |
+
--------
|
| 256 |
+
equal, not_equal, greater_equal, less_equal, greater
|
| 257 |
+
"""
|
| 258 |
+
return compare_chararrays(x1, x2, '<', True)
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
def _unary_op_dispatcher(a):
|
| 262 |
+
return (a,)
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 266 |
+
def str_len(a):
|
| 267 |
+
"""
|
| 268 |
+
Return len(a) element-wise.
|
| 269 |
+
|
| 270 |
+
Parameters
|
| 271 |
+
----------
|
| 272 |
+
a : array_like of str or unicode
|
| 273 |
+
|
| 274 |
+
Returns
|
| 275 |
+
-------
|
| 276 |
+
out : ndarray
|
| 277 |
+
Output array of integers
|
| 278 |
+
|
| 279 |
+
See Also
|
| 280 |
+
--------
|
| 281 |
+
len
|
| 282 |
+
|
| 283 |
+
Examples
|
| 284 |
+
--------
|
| 285 |
+
>>> a = np.array(['Grace Hopper Conference', 'Open Source Day'])
|
| 286 |
+
>>> np.char.str_len(a)
|
| 287 |
+
array([23, 15])
|
| 288 |
+
>>> a = np.array([u'\u0420', u'\u043e'])
|
| 289 |
+
>>> np.char.str_len(a)
|
| 290 |
+
array([1, 1])
|
| 291 |
+
>>> a = np.array([['hello', 'world'], [u'\u0420', u'\u043e']])
|
| 292 |
+
>>> np.char.str_len(a)
|
| 293 |
+
array([[5, 5], [1, 1]])
|
| 294 |
+
"""
|
| 295 |
+
# Note: __len__, etc. currently return ints, which are not C-integers.
|
| 296 |
+
# Generally intp would be expected for lengths, although int is sufficient
|
| 297 |
+
# due to the dtype itemsize limitation.
|
| 298 |
+
return _vec_string(a, int_, '__len__')
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
@array_function_dispatch(_binary_op_dispatcher)
|
| 302 |
+
def add(x1, x2):
|
| 303 |
+
"""
|
| 304 |
+
Return element-wise string concatenation for two arrays of str or unicode.
|
| 305 |
+
|
| 306 |
+
Arrays `x1` and `x2` must have the same shape.
|
| 307 |
+
|
| 308 |
+
Parameters
|
| 309 |
+
----------
|
| 310 |
+
x1 : array_like of str or unicode
|
| 311 |
+
Input array.
|
| 312 |
+
x2 : array_like of str or unicode
|
| 313 |
+
Input array.
|
| 314 |
+
|
| 315 |
+
Returns
|
| 316 |
+
-------
|
| 317 |
+
add : ndarray
|
| 318 |
+
Output array of `bytes_` or `str_`, depending on input types
|
| 319 |
+
of the same shape as `x1` and `x2`.
|
| 320 |
+
|
| 321 |
+
"""
|
| 322 |
+
arr1 = numpy.asarray(x1)
|
| 323 |
+
arr2 = numpy.asarray(x2)
|
| 324 |
+
out_size = _get_num_chars(arr1) + _get_num_chars(arr2)
|
| 325 |
+
|
| 326 |
+
if type(arr1.dtype) != type(arr2.dtype):
|
| 327 |
+
# Enforce this for now. The solution to it will be implement add
|
| 328 |
+
# as a ufunc. It never worked right on Python 3: bytes + unicode gave
|
| 329 |
+
# nonsense unicode + bytes errored, and unicode + object used the
|
| 330 |
+
# object dtype itemsize as num chars (worked on short strings).
|
| 331 |
+
# bytes + void worked but promoting void->bytes is dubious also.
|
| 332 |
+
raise TypeError(
|
| 333 |
+
"np.char.add() requires both arrays of the same dtype kind, but "
|
| 334 |
+
f"got dtypes: '{arr1.dtype}' and '{arr2.dtype}' (the few cases "
|
| 335 |
+
"where this used to work often lead to incorrect results).")
|
| 336 |
+
|
| 337 |
+
return _vec_string(arr1, type(arr1.dtype)(out_size), '__add__', (arr2,))
|
| 338 |
+
|
| 339 |
+
def _multiply_dispatcher(a, i):
|
| 340 |
+
return (a,)
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
@array_function_dispatch(_multiply_dispatcher)
|
| 344 |
+
def multiply(a, i):
|
| 345 |
+
"""
|
| 346 |
+
Return (a * i), that is string multiple concatenation,
|
| 347 |
+
element-wise.
|
| 348 |
+
|
| 349 |
+
Values in `i` of less than 0 are treated as 0 (which yields an
|
| 350 |
+
empty string).
|
| 351 |
+
|
| 352 |
+
Parameters
|
| 353 |
+
----------
|
| 354 |
+
a : array_like of str or unicode
|
| 355 |
+
|
| 356 |
+
i : array_like of ints
|
| 357 |
+
|
| 358 |
+
Returns
|
| 359 |
+
-------
|
| 360 |
+
out : ndarray
|
| 361 |
+
Output array of str or unicode, depending on input types
|
| 362 |
+
|
| 363 |
+
Examples
|
| 364 |
+
--------
|
| 365 |
+
>>> a = np.array(["a", "b", "c"])
|
| 366 |
+
>>> np.char.multiply(x, 3)
|
| 367 |
+
array(['aaa', 'bbb', 'ccc'], dtype='<U3')
|
| 368 |
+
>>> i = np.array([1, 2, 3])
|
| 369 |
+
>>> np.char.multiply(a, i)
|
| 370 |
+
array(['a', 'bb', 'ccc'], dtype='<U3')
|
| 371 |
+
>>> np.char.multiply(np.array(['a']), i)
|
| 372 |
+
array(['a', 'aa', 'aaa'], dtype='<U3')
|
| 373 |
+
>>> a = np.array(['a', 'b', 'c', 'd', 'e', 'f']).reshape((2, 3))
|
| 374 |
+
>>> np.char.multiply(a, 3)
|
| 375 |
+
array([['aaa', 'bbb', 'ccc'],
|
| 376 |
+
['ddd', 'eee', 'fff']], dtype='<U3')
|
| 377 |
+
>>> np.char.multiply(a, i)
|
| 378 |
+
array([['a', 'bb', 'ccc'],
|
| 379 |
+
['d', 'ee', 'fff']], dtype='<U3')
|
| 380 |
+
"""
|
| 381 |
+
a_arr = numpy.asarray(a)
|
| 382 |
+
i_arr = numpy.asarray(i)
|
| 383 |
+
if not issubclass(i_arr.dtype.type, integer):
|
| 384 |
+
raise ValueError("Can only multiply by integers")
|
| 385 |
+
out_size = _get_num_chars(a_arr) * max(int(i_arr.max()), 0)
|
| 386 |
+
return _vec_string(
|
| 387 |
+
a_arr, type(a_arr.dtype)(out_size), '__mul__', (i_arr,))
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
def _mod_dispatcher(a, values):
|
| 391 |
+
return (a, values)
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
@array_function_dispatch(_mod_dispatcher)
|
| 395 |
+
def mod(a, values):
|
| 396 |
+
"""
|
| 397 |
+
Return (a % i), that is pre-Python 2.6 string formatting
|
| 398 |
+
(interpolation), element-wise for a pair of array_likes of str
|
| 399 |
+
or unicode.
|
| 400 |
+
|
| 401 |
+
Parameters
|
| 402 |
+
----------
|
| 403 |
+
a : array_like of str or unicode
|
| 404 |
+
|
| 405 |
+
values : array_like of values
|
| 406 |
+
These values will be element-wise interpolated into the string.
|
| 407 |
+
|
| 408 |
+
Returns
|
| 409 |
+
-------
|
| 410 |
+
out : ndarray
|
| 411 |
+
Output array of str or unicode, depending on input types
|
| 412 |
+
|
| 413 |
+
See Also
|
| 414 |
+
--------
|
| 415 |
+
str.__mod__
|
| 416 |
+
|
| 417 |
+
"""
|
| 418 |
+
return _to_bytes_or_str_array(
|
| 419 |
+
_vec_string(a, object_, '__mod__', (values,)), a)
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 423 |
+
def capitalize(a):
|
| 424 |
+
"""
|
| 425 |
+
Return a copy of `a` with only the first character of each element
|
| 426 |
+
capitalized.
|
| 427 |
+
|
| 428 |
+
Calls `str.capitalize` element-wise.
|
| 429 |
+
|
| 430 |
+
For 8-bit strings, this method is locale-dependent.
|
| 431 |
+
|
| 432 |
+
Parameters
|
| 433 |
+
----------
|
| 434 |
+
a : array_like of str or unicode
|
| 435 |
+
Input array of strings to capitalize.
|
| 436 |
+
|
| 437 |
+
Returns
|
| 438 |
+
-------
|
| 439 |
+
out : ndarray
|
| 440 |
+
Output array of str or unicode, depending on input
|
| 441 |
+
types
|
| 442 |
+
|
| 443 |
+
See Also
|
| 444 |
+
--------
|
| 445 |
+
str.capitalize
|
| 446 |
+
|
| 447 |
+
Examples
|
| 448 |
+
--------
|
| 449 |
+
>>> c = np.array(['a1b2','1b2a','b2a1','2a1b'],'S4'); c
|
| 450 |
+
array(['a1b2', '1b2a', 'b2a1', '2a1b'],
|
| 451 |
+
dtype='|S4')
|
| 452 |
+
>>> np.char.capitalize(c)
|
| 453 |
+
array(['A1b2', '1b2a', 'B2a1', '2a1b'],
|
| 454 |
+
dtype='|S4')
|
| 455 |
+
|
| 456 |
+
"""
|
| 457 |
+
a_arr = numpy.asarray(a)
|
| 458 |
+
return _vec_string(a_arr, a_arr.dtype, 'capitalize')
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
def _center_dispatcher(a, width, fillchar=None):
|
| 462 |
+
return (a,)
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
@array_function_dispatch(_center_dispatcher)
|
| 466 |
+
def center(a, width, fillchar=' '):
|
| 467 |
+
"""
|
| 468 |
+
Return a copy of `a` with its elements centered in a string of
|
| 469 |
+
length `width`.
|
| 470 |
+
|
| 471 |
+
Calls `str.center` element-wise.
|
| 472 |
+
|
| 473 |
+
Parameters
|
| 474 |
+
----------
|
| 475 |
+
a : array_like of str or unicode
|
| 476 |
+
|
| 477 |
+
width : int
|
| 478 |
+
The length of the resulting strings
|
| 479 |
+
fillchar : str or unicode, optional
|
| 480 |
+
The padding character to use (default is space).
|
| 481 |
+
|
| 482 |
+
Returns
|
| 483 |
+
-------
|
| 484 |
+
out : ndarray
|
| 485 |
+
Output array of str or unicode, depending on input
|
| 486 |
+
types
|
| 487 |
+
|
| 488 |
+
See Also
|
| 489 |
+
--------
|
| 490 |
+
str.center
|
| 491 |
+
|
| 492 |
+
Notes
|
| 493 |
+
-----
|
| 494 |
+
This function is intended to work with arrays of strings. The
|
| 495 |
+
fill character is not applied to numeric types.
|
| 496 |
+
|
| 497 |
+
Examples
|
| 498 |
+
--------
|
| 499 |
+
>>> c = np.array(['a1b2','1b2a','b2a1','2a1b']); c
|
| 500 |
+
array(['a1b2', '1b2a', 'b2a1', '2a1b'], dtype='<U4')
|
| 501 |
+
>>> np.char.center(c, width=9)
|
| 502 |
+
array([' a1b2 ', ' 1b2a ', ' b2a1 ', ' 2a1b '], dtype='<U9')
|
| 503 |
+
>>> np.char.center(c, width=9, fillchar='*')
|
| 504 |
+
array(['***a1b2**', '***1b2a**', '***b2a1**', '***2a1b**'], dtype='<U9')
|
| 505 |
+
>>> np.char.center(c, width=1)
|
| 506 |
+
array(['a', '1', 'b', '2'], dtype='<U1')
|
| 507 |
+
|
| 508 |
+
"""
|
| 509 |
+
a_arr = numpy.asarray(a)
|
| 510 |
+
width_arr = numpy.asarray(width)
|
| 511 |
+
size = int(numpy.max(width_arr.flat))
|
| 512 |
+
if numpy.issubdtype(a_arr.dtype, numpy.bytes_):
|
| 513 |
+
fillchar = asbytes(fillchar)
|
| 514 |
+
return _vec_string(
|
| 515 |
+
a_arr, type(a_arr.dtype)(size), 'center', (width_arr, fillchar))
|
| 516 |
+
|
| 517 |
+
|
| 518 |
+
def _count_dispatcher(a, sub, start=None, end=None):
|
| 519 |
+
return (a,)
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
@array_function_dispatch(_count_dispatcher)
|
| 523 |
+
def count(a, sub, start=0, end=None):
|
| 524 |
+
"""
|
| 525 |
+
Returns an array with the number of non-overlapping occurrences of
|
| 526 |
+
substring `sub` in the range [`start`, `end`].
|
| 527 |
+
|
| 528 |
+
Calls `str.count` element-wise.
|
| 529 |
+
|
| 530 |
+
Parameters
|
| 531 |
+
----------
|
| 532 |
+
a : array_like of str or unicode
|
| 533 |
+
|
| 534 |
+
sub : str or unicode
|
| 535 |
+
The substring to search for.
|
| 536 |
+
|
| 537 |
+
start, end : int, optional
|
| 538 |
+
Optional arguments `start` and `end` are interpreted as slice
|
| 539 |
+
notation to specify the range in which to count.
|
| 540 |
+
|
| 541 |
+
Returns
|
| 542 |
+
-------
|
| 543 |
+
out : ndarray
|
| 544 |
+
Output array of ints.
|
| 545 |
+
|
| 546 |
+
See Also
|
| 547 |
+
--------
|
| 548 |
+
str.count
|
| 549 |
+
|
| 550 |
+
Examples
|
| 551 |
+
--------
|
| 552 |
+
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
|
| 553 |
+
>>> c
|
| 554 |
+
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
|
| 555 |
+
>>> np.char.count(c, 'A')
|
| 556 |
+
array([3, 1, 1])
|
| 557 |
+
>>> np.char.count(c, 'aA')
|
| 558 |
+
array([3, 1, 0])
|
| 559 |
+
>>> np.char.count(c, 'A', start=1, end=4)
|
| 560 |
+
array([2, 1, 1])
|
| 561 |
+
>>> np.char.count(c, 'A', start=1, end=3)
|
| 562 |
+
array([1, 0, 0])
|
| 563 |
+
|
| 564 |
+
"""
|
| 565 |
+
return _vec_string(a, int_, 'count', [sub, start] + _clean_args(end))
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
def _code_dispatcher(a, encoding=None, errors=None):
|
| 569 |
+
return (a,)
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
@array_function_dispatch(_code_dispatcher)
|
| 573 |
+
def decode(a, encoding=None, errors=None):
|
| 574 |
+
r"""
|
| 575 |
+
Calls ``bytes.decode`` element-wise.
|
| 576 |
+
|
| 577 |
+
The set of available codecs comes from the Python standard library,
|
| 578 |
+
and may be extended at runtime. For more information, see the
|
| 579 |
+
:mod:`codecs` module.
|
| 580 |
+
|
| 581 |
+
Parameters
|
| 582 |
+
----------
|
| 583 |
+
a : array_like of str or unicode
|
| 584 |
+
|
| 585 |
+
encoding : str, optional
|
| 586 |
+
The name of an encoding
|
| 587 |
+
|
| 588 |
+
errors : str, optional
|
| 589 |
+
Specifies how to handle encoding errors
|
| 590 |
+
|
| 591 |
+
Returns
|
| 592 |
+
-------
|
| 593 |
+
out : ndarray
|
| 594 |
+
|
| 595 |
+
See Also
|
| 596 |
+
--------
|
| 597 |
+
:py:meth:`bytes.decode`
|
| 598 |
+
|
| 599 |
+
Notes
|
| 600 |
+
-----
|
| 601 |
+
The type of the result will depend on the encoding specified.
|
| 602 |
+
|
| 603 |
+
Examples
|
| 604 |
+
--------
|
| 605 |
+
>>> c = np.array([b'\x81\xc1\x81\xc1\x81\xc1', b'@@\x81\xc1@@',
|
| 606 |
+
... b'\x81\x82\xc2\xc1\xc2\x82\x81'])
|
| 607 |
+
>>> c
|
| 608 |
+
array([b'\x81\xc1\x81\xc1\x81\xc1', b'@@\x81\xc1@@',
|
| 609 |
+
... b'\x81\x82\xc2\xc1\xc2\x82\x81'], dtype='|S7')
|
| 610 |
+
>>> np.char.decode(c, encoding='cp037')
|
| 611 |
+
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
|
| 612 |
+
|
| 613 |
+
"""
|
| 614 |
+
return _to_bytes_or_str_array(
|
| 615 |
+
_vec_string(a, object_, 'decode', _clean_args(encoding, errors)))
|
| 616 |
+
|
| 617 |
+
|
| 618 |
+
@array_function_dispatch(_code_dispatcher)
|
| 619 |
+
def encode(a, encoding=None, errors=None):
|
| 620 |
+
"""
|
| 621 |
+
Calls `str.encode` element-wise.
|
| 622 |
+
|
| 623 |
+
The set of available codecs comes from the Python standard library,
|
| 624 |
+
and may be extended at runtime. For more information, see the codecs
|
| 625 |
+
module.
|
| 626 |
+
|
| 627 |
+
Parameters
|
| 628 |
+
----------
|
| 629 |
+
a : array_like of str or unicode
|
| 630 |
+
|
| 631 |
+
encoding : str, optional
|
| 632 |
+
The name of an encoding
|
| 633 |
+
|
| 634 |
+
errors : str, optional
|
| 635 |
+
Specifies how to handle encoding errors
|
| 636 |
+
|
| 637 |
+
Returns
|
| 638 |
+
-------
|
| 639 |
+
out : ndarray
|
| 640 |
+
|
| 641 |
+
See Also
|
| 642 |
+
--------
|
| 643 |
+
str.encode
|
| 644 |
+
|
| 645 |
+
Notes
|
| 646 |
+
-----
|
| 647 |
+
The type of the result will depend on the encoding specified.
|
| 648 |
+
|
| 649 |
+
"""
|
| 650 |
+
return _to_bytes_or_str_array(
|
| 651 |
+
_vec_string(a, object_, 'encode', _clean_args(encoding, errors)))
|
| 652 |
+
|
| 653 |
+
|
| 654 |
+
def _endswith_dispatcher(a, suffix, start=None, end=None):
|
| 655 |
+
return (a,)
|
| 656 |
+
|
| 657 |
+
|
| 658 |
+
@array_function_dispatch(_endswith_dispatcher)
|
| 659 |
+
def endswith(a, suffix, start=0, end=None):
|
| 660 |
+
"""
|
| 661 |
+
Returns a boolean array which is `True` where the string element
|
| 662 |
+
in `a` ends with `suffix`, otherwise `False`.
|
| 663 |
+
|
| 664 |
+
Calls `str.endswith` element-wise.
|
| 665 |
+
|
| 666 |
+
Parameters
|
| 667 |
+
----------
|
| 668 |
+
a : array_like of str or unicode
|
| 669 |
+
|
| 670 |
+
suffix : str
|
| 671 |
+
|
| 672 |
+
start, end : int, optional
|
| 673 |
+
With optional `start`, test beginning at that position. With
|
| 674 |
+
optional `end`, stop comparing at that position.
|
| 675 |
+
|
| 676 |
+
Returns
|
| 677 |
+
-------
|
| 678 |
+
out : ndarray
|
| 679 |
+
Outputs an array of bools.
|
| 680 |
+
|
| 681 |
+
See Also
|
| 682 |
+
--------
|
| 683 |
+
str.endswith
|
| 684 |
+
|
| 685 |
+
Examples
|
| 686 |
+
--------
|
| 687 |
+
>>> s = np.array(['foo', 'bar'])
|
| 688 |
+
>>> s[0] = 'foo'
|
| 689 |
+
>>> s[1] = 'bar'
|
| 690 |
+
>>> s
|
| 691 |
+
array(['foo', 'bar'], dtype='<U3')
|
| 692 |
+
>>> np.char.endswith(s, 'ar')
|
| 693 |
+
array([False, True])
|
| 694 |
+
>>> np.char.endswith(s, 'a', start=1, end=2)
|
| 695 |
+
array([False, True])
|
| 696 |
+
|
| 697 |
+
"""
|
| 698 |
+
return _vec_string(
|
| 699 |
+
a, bool_, 'endswith', [suffix, start] + _clean_args(end))
|
| 700 |
+
|
| 701 |
+
|
| 702 |
+
def _expandtabs_dispatcher(a, tabsize=None):
|
| 703 |
+
return (a,)
|
| 704 |
+
|
| 705 |
+
|
| 706 |
+
@array_function_dispatch(_expandtabs_dispatcher)
|
| 707 |
+
def expandtabs(a, tabsize=8):
|
| 708 |
+
"""
|
| 709 |
+
Return a copy of each string element where all tab characters are
|
| 710 |
+
replaced by one or more spaces.
|
| 711 |
+
|
| 712 |
+
Calls `str.expandtabs` element-wise.
|
| 713 |
+
|
| 714 |
+
Return a copy of each string element where all tab characters are
|
| 715 |
+
replaced by one or more spaces, depending on the current column
|
| 716 |
+
and the given `tabsize`. The column number is reset to zero after
|
| 717 |
+
each newline occurring in the string. This doesn't understand other
|
| 718 |
+
non-printing characters or escape sequences.
|
| 719 |
+
|
| 720 |
+
Parameters
|
| 721 |
+
----------
|
| 722 |
+
a : array_like of str or unicode
|
| 723 |
+
Input array
|
| 724 |
+
tabsize : int, optional
|
| 725 |
+
Replace tabs with `tabsize` number of spaces. If not given defaults
|
| 726 |
+
to 8 spaces.
|
| 727 |
+
|
| 728 |
+
Returns
|
| 729 |
+
-------
|
| 730 |
+
out : ndarray
|
| 731 |
+
Output array of str or unicode, depending on input type
|
| 732 |
+
|
| 733 |
+
See Also
|
| 734 |
+
--------
|
| 735 |
+
str.expandtabs
|
| 736 |
+
|
| 737 |
+
"""
|
| 738 |
+
return _to_bytes_or_str_array(
|
| 739 |
+
_vec_string(a, object_, 'expandtabs', (tabsize,)), a)
|
| 740 |
+
|
| 741 |
+
|
| 742 |
+
@array_function_dispatch(_count_dispatcher)
|
| 743 |
+
def find(a, sub, start=0, end=None):
|
| 744 |
+
"""
|
| 745 |
+
For each element, return the lowest index in the string where
|
| 746 |
+
substring `sub` is found.
|
| 747 |
+
|
| 748 |
+
Calls `str.find` element-wise.
|
| 749 |
+
|
| 750 |
+
For each element, return the lowest index in the string where
|
| 751 |
+
substring `sub` is found, such that `sub` is contained in the
|
| 752 |
+
range [`start`, `end`].
|
| 753 |
+
|
| 754 |
+
Parameters
|
| 755 |
+
----------
|
| 756 |
+
a : array_like of str or unicode
|
| 757 |
+
|
| 758 |
+
sub : str or unicode
|
| 759 |
+
|
| 760 |
+
start, end : int, optional
|
| 761 |
+
Optional arguments `start` and `end` are interpreted as in
|
| 762 |
+
slice notation.
|
| 763 |
+
|
| 764 |
+
Returns
|
| 765 |
+
-------
|
| 766 |
+
out : ndarray or int
|
| 767 |
+
Output array of ints. Returns -1 if `sub` is not found.
|
| 768 |
+
|
| 769 |
+
See Also
|
| 770 |
+
--------
|
| 771 |
+
str.find
|
| 772 |
+
|
| 773 |
+
Examples
|
| 774 |
+
--------
|
| 775 |
+
>>> a = np.array(["NumPy is a Python library"])
|
| 776 |
+
>>> np.char.find(a, "Python", start=0, end=None)
|
| 777 |
+
array([11])
|
| 778 |
+
|
| 779 |
+
"""
|
| 780 |
+
return _vec_string(
|
| 781 |
+
a, int_, 'find', [sub, start] + _clean_args(end))
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
@array_function_dispatch(_count_dispatcher)
|
| 785 |
+
def index(a, sub, start=0, end=None):
|
| 786 |
+
"""
|
| 787 |
+
Like `find`, but raises `ValueError` when the substring is not found.
|
| 788 |
+
|
| 789 |
+
Calls `str.index` element-wise.
|
| 790 |
+
|
| 791 |
+
Parameters
|
| 792 |
+
----------
|
| 793 |
+
a : array_like of str or unicode
|
| 794 |
+
|
| 795 |
+
sub : str or unicode
|
| 796 |
+
|
| 797 |
+
start, end : int, optional
|
| 798 |
+
|
| 799 |
+
Returns
|
| 800 |
+
-------
|
| 801 |
+
out : ndarray
|
| 802 |
+
Output array of ints. Returns -1 if `sub` is not found.
|
| 803 |
+
|
| 804 |
+
See Also
|
| 805 |
+
--------
|
| 806 |
+
find, str.find
|
| 807 |
+
|
| 808 |
+
Examples
|
| 809 |
+
--------
|
| 810 |
+
>>> a = np.array(["Computer Science"])
|
| 811 |
+
>>> np.char.index(a, "Science", start=0, end=None)
|
| 812 |
+
array([9])
|
| 813 |
+
|
| 814 |
+
"""
|
| 815 |
+
return _vec_string(
|
| 816 |
+
a, int_, 'index', [sub, start] + _clean_args(end))
|
| 817 |
+
|
| 818 |
+
|
| 819 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 820 |
+
def isalnum(a):
|
| 821 |
+
"""
|
| 822 |
+
Returns true for each element if all characters in the string are
|
| 823 |
+
alphanumeric and there is at least one character, false otherwise.
|
| 824 |
+
|
| 825 |
+
Calls `str.isalnum` element-wise.
|
| 826 |
+
|
| 827 |
+
For 8-bit strings, this method is locale-dependent.
|
| 828 |
+
|
| 829 |
+
Parameters
|
| 830 |
+
----------
|
| 831 |
+
a : array_like of str or unicode
|
| 832 |
+
|
| 833 |
+
Returns
|
| 834 |
+
-------
|
| 835 |
+
out : ndarray
|
| 836 |
+
Output array of str or unicode, depending on input type
|
| 837 |
+
|
| 838 |
+
See Also
|
| 839 |
+
--------
|
| 840 |
+
str.isalnum
|
| 841 |
+
"""
|
| 842 |
+
return _vec_string(a, bool_, 'isalnum')
|
| 843 |
+
|
| 844 |
+
|
| 845 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 846 |
+
def isalpha(a):
|
| 847 |
+
"""
|
| 848 |
+
Returns true for each element if all characters in the string are
|
| 849 |
+
alphabetic and there is at least one character, false otherwise.
|
| 850 |
+
|
| 851 |
+
Calls `str.isalpha` element-wise.
|
| 852 |
+
|
| 853 |
+
For 8-bit strings, this method is locale-dependent.
|
| 854 |
+
|
| 855 |
+
Parameters
|
| 856 |
+
----------
|
| 857 |
+
a : array_like of str or unicode
|
| 858 |
+
|
| 859 |
+
Returns
|
| 860 |
+
-------
|
| 861 |
+
out : ndarray
|
| 862 |
+
Output array of bools
|
| 863 |
+
|
| 864 |
+
See Also
|
| 865 |
+
--------
|
| 866 |
+
str.isalpha
|
| 867 |
+
"""
|
| 868 |
+
return _vec_string(a, bool_, 'isalpha')
|
| 869 |
+
|
| 870 |
+
|
| 871 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 872 |
+
def isdigit(a):
|
| 873 |
+
"""
|
| 874 |
+
Returns true for each element if all characters in the string are
|
| 875 |
+
digits and there is at least one character, false otherwise.
|
| 876 |
+
|
| 877 |
+
Calls `str.isdigit` element-wise.
|
| 878 |
+
|
| 879 |
+
For 8-bit strings, this method is locale-dependent.
|
| 880 |
+
|
| 881 |
+
Parameters
|
| 882 |
+
----------
|
| 883 |
+
a : array_like of str or unicode
|
| 884 |
+
|
| 885 |
+
Returns
|
| 886 |
+
-------
|
| 887 |
+
out : ndarray
|
| 888 |
+
Output array of bools
|
| 889 |
+
|
| 890 |
+
See Also
|
| 891 |
+
--------
|
| 892 |
+
str.isdigit
|
| 893 |
+
|
| 894 |
+
Examples
|
| 895 |
+
--------
|
| 896 |
+
>>> a = np.array(['a', 'b', '0'])
|
| 897 |
+
>>> np.char.isdigit(a)
|
| 898 |
+
array([False, False, True])
|
| 899 |
+
>>> a = np.array([['a', 'b', '0'], ['c', '1', '2']])
|
| 900 |
+
>>> np.char.isdigit(a)
|
| 901 |
+
array([[False, False, True], [False, True, True]])
|
| 902 |
+
"""
|
| 903 |
+
return _vec_string(a, bool_, 'isdigit')
|
| 904 |
+
|
| 905 |
+
|
| 906 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 907 |
+
def islower(a):
|
| 908 |
+
"""
|
| 909 |
+
Returns true for each element if all cased characters in the
|
| 910 |
+
string are lowercase and there is at least one cased character,
|
| 911 |
+
false otherwise.
|
| 912 |
+
|
| 913 |
+
Calls `str.islower` element-wise.
|
| 914 |
+
|
| 915 |
+
For 8-bit strings, this method is locale-dependent.
|
| 916 |
+
|
| 917 |
+
Parameters
|
| 918 |
+
----------
|
| 919 |
+
a : array_like of str or unicode
|
| 920 |
+
|
| 921 |
+
Returns
|
| 922 |
+
-------
|
| 923 |
+
out : ndarray
|
| 924 |
+
Output array of bools
|
| 925 |
+
|
| 926 |
+
See Also
|
| 927 |
+
--------
|
| 928 |
+
str.islower
|
| 929 |
+
"""
|
| 930 |
+
return _vec_string(a, bool_, 'islower')
|
| 931 |
+
|
| 932 |
+
|
| 933 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 934 |
+
def isspace(a):
|
| 935 |
+
"""
|
| 936 |
+
Returns true for each element if there are only whitespace
|
| 937 |
+
characters in the string and there is at least one character,
|
| 938 |
+
false otherwise.
|
| 939 |
+
|
| 940 |
+
Calls `str.isspace` element-wise.
|
| 941 |
+
|
| 942 |
+
For 8-bit strings, this method is locale-dependent.
|
| 943 |
+
|
| 944 |
+
Parameters
|
| 945 |
+
----------
|
| 946 |
+
a : array_like of str or unicode
|
| 947 |
+
|
| 948 |
+
Returns
|
| 949 |
+
-------
|
| 950 |
+
out : ndarray
|
| 951 |
+
Output array of bools
|
| 952 |
+
|
| 953 |
+
See Also
|
| 954 |
+
--------
|
| 955 |
+
str.isspace
|
| 956 |
+
"""
|
| 957 |
+
return _vec_string(a, bool_, 'isspace')
|
| 958 |
+
|
| 959 |
+
|
| 960 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 961 |
+
def istitle(a):
|
| 962 |
+
"""
|
| 963 |
+
Returns true for each element if the element is a titlecased
|
| 964 |
+
string and there is at least one character, false otherwise.
|
| 965 |
+
|
| 966 |
+
Call `str.istitle` element-wise.
|
| 967 |
+
|
| 968 |
+
For 8-bit strings, this method is locale-dependent.
|
| 969 |
+
|
| 970 |
+
Parameters
|
| 971 |
+
----------
|
| 972 |
+
a : array_like of str or unicode
|
| 973 |
+
|
| 974 |
+
Returns
|
| 975 |
+
-------
|
| 976 |
+
out : ndarray
|
| 977 |
+
Output array of bools
|
| 978 |
+
|
| 979 |
+
See Also
|
| 980 |
+
--------
|
| 981 |
+
str.istitle
|
| 982 |
+
"""
|
| 983 |
+
return _vec_string(a, bool_, 'istitle')
|
| 984 |
+
|
| 985 |
+
|
| 986 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 987 |
+
def isupper(a):
|
| 988 |
+
"""
|
| 989 |
+
Return true for each element if all cased characters in the
|
| 990 |
+
string are uppercase and there is at least one character, false
|
| 991 |
+
otherwise.
|
| 992 |
+
|
| 993 |
+
Call `str.isupper` element-wise.
|
| 994 |
+
|
| 995 |
+
For 8-bit strings, this method is locale-dependent.
|
| 996 |
+
|
| 997 |
+
Parameters
|
| 998 |
+
----------
|
| 999 |
+
a : array_like of str or unicode
|
| 1000 |
+
|
| 1001 |
+
Returns
|
| 1002 |
+
-------
|
| 1003 |
+
out : ndarray
|
| 1004 |
+
Output array of bools
|
| 1005 |
+
|
| 1006 |
+
See Also
|
| 1007 |
+
--------
|
| 1008 |
+
str.isupper
|
| 1009 |
+
|
| 1010 |
+
Examples
|
| 1011 |
+
--------
|
| 1012 |
+
>>> str = "GHC"
|
| 1013 |
+
>>> np.char.isupper(str)
|
| 1014 |
+
array(True)
|
| 1015 |
+
>>> a = np.array(["hello", "HELLO", "Hello"])
|
| 1016 |
+
>>> np.char.isupper(a)
|
| 1017 |
+
array([False, True, False])
|
| 1018 |
+
|
| 1019 |
+
"""
|
| 1020 |
+
return _vec_string(a, bool_, 'isupper')
|
| 1021 |
+
|
| 1022 |
+
|
| 1023 |
+
def _join_dispatcher(sep, seq):
|
| 1024 |
+
return (sep, seq)
|
| 1025 |
+
|
| 1026 |
+
|
| 1027 |
+
@array_function_dispatch(_join_dispatcher)
|
| 1028 |
+
def join(sep, seq):
|
| 1029 |
+
"""
|
| 1030 |
+
Return a string which is the concatenation of the strings in the
|
| 1031 |
+
sequence `seq`.
|
| 1032 |
+
|
| 1033 |
+
Calls `str.join` element-wise.
|
| 1034 |
+
|
| 1035 |
+
Parameters
|
| 1036 |
+
----------
|
| 1037 |
+
sep : array_like of str or unicode
|
| 1038 |
+
seq : array_like of str or unicode
|
| 1039 |
+
|
| 1040 |
+
Returns
|
| 1041 |
+
-------
|
| 1042 |
+
out : ndarray
|
| 1043 |
+
Output array of str or unicode, depending on input types
|
| 1044 |
+
|
| 1045 |
+
See Also
|
| 1046 |
+
--------
|
| 1047 |
+
str.join
|
| 1048 |
+
|
| 1049 |
+
Examples
|
| 1050 |
+
--------
|
| 1051 |
+
>>> np.char.join('-', 'osd')
|
| 1052 |
+
array('o-s-d', dtype='<U5')
|
| 1053 |
+
|
| 1054 |
+
>>> np.char.join(['-', '.'], ['ghc', 'osd'])
|
| 1055 |
+
array(['g-h-c', 'o.s.d'], dtype='<U5')
|
| 1056 |
+
|
| 1057 |
+
"""
|
| 1058 |
+
return _to_bytes_or_str_array(
|
| 1059 |
+
_vec_string(sep, object_, 'join', (seq,)), seq)
|
| 1060 |
+
|
| 1061 |
+
|
| 1062 |
+
|
| 1063 |
+
def _just_dispatcher(a, width, fillchar=None):
|
| 1064 |
+
return (a,)
|
| 1065 |
+
|
| 1066 |
+
|
| 1067 |
+
@array_function_dispatch(_just_dispatcher)
|
| 1068 |
+
def ljust(a, width, fillchar=' '):
|
| 1069 |
+
"""
|
| 1070 |
+
Return an array with the elements of `a` left-justified in a
|
| 1071 |
+
string of length `width`.
|
| 1072 |
+
|
| 1073 |
+
Calls `str.ljust` element-wise.
|
| 1074 |
+
|
| 1075 |
+
Parameters
|
| 1076 |
+
----------
|
| 1077 |
+
a : array_like of str or unicode
|
| 1078 |
+
|
| 1079 |
+
width : int
|
| 1080 |
+
The length of the resulting strings
|
| 1081 |
+
fillchar : str or unicode, optional
|
| 1082 |
+
The character to use for padding
|
| 1083 |
+
|
| 1084 |
+
Returns
|
| 1085 |
+
-------
|
| 1086 |
+
out : ndarray
|
| 1087 |
+
Output array of str or unicode, depending on input type
|
| 1088 |
+
|
| 1089 |
+
See Also
|
| 1090 |
+
--------
|
| 1091 |
+
str.ljust
|
| 1092 |
+
|
| 1093 |
+
"""
|
| 1094 |
+
a_arr = numpy.asarray(a)
|
| 1095 |
+
width_arr = numpy.asarray(width)
|
| 1096 |
+
size = int(numpy.max(width_arr.flat))
|
| 1097 |
+
if numpy.issubdtype(a_arr.dtype, numpy.bytes_):
|
| 1098 |
+
fillchar = asbytes(fillchar)
|
| 1099 |
+
return _vec_string(
|
| 1100 |
+
a_arr, type(a_arr.dtype)(size), 'ljust', (width_arr, fillchar))
|
| 1101 |
+
|
| 1102 |
+
|
| 1103 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 1104 |
+
def lower(a):
|
| 1105 |
+
"""
|
| 1106 |
+
Return an array with the elements converted to lowercase.
|
| 1107 |
+
|
| 1108 |
+
Call `str.lower` element-wise.
|
| 1109 |
+
|
| 1110 |
+
For 8-bit strings, this method is locale-dependent.
|
| 1111 |
+
|
| 1112 |
+
Parameters
|
| 1113 |
+
----------
|
| 1114 |
+
a : array_like, {str, unicode}
|
| 1115 |
+
Input array.
|
| 1116 |
+
|
| 1117 |
+
Returns
|
| 1118 |
+
-------
|
| 1119 |
+
out : ndarray, {str, unicode}
|
| 1120 |
+
Output array of str or unicode, depending on input type
|
| 1121 |
+
|
| 1122 |
+
See Also
|
| 1123 |
+
--------
|
| 1124 |
+
str.lower
|
| 1125 |
+
|
| 1126 |
+
Examples
|
| 1127 |
+
--------
|
| 1128 |
+
>>> c = np.array(['A1B C', '1BCA', 'BCA1']); c
|
| 1129 |
+
array(['A1B C', '1BCA', 'BCA1'], dtype='<U5')
|
| 1130 |
+
>>> np.char.lower(c)
|
| 1131 |
+
array(['a1b c', '1bca', 'bca1'], dtype='<U5')
|
| 1132 |
+
|
| 1133 |
+
"""
|
| 1134 |
+
a_arr = numpy.asarray(a)
|
| 1135 |
+
return _vec_string(a_arr, a_arr.dtype, 'lower')
|
| 1136 |
+
|
| 1137 |
+
|
| 1138 |
+
def _strip_dispatcher(a, chars=None):
|
| 1139 |
+
return (a,)
|
| 1140 |
+
|
| 1141 |
+
|
| 1142 |
+
@array_function_dispatch(_strip_dispatcher)
|
| 1143 |
+
def lstrip(a, chars=None):
|
| 1144 |
+
"""
|
| 1145 |
+
For each element in `a`, return a copy with the leading characters
|
| 1146 |
+
removed.
|
| 1147 |
+
|
| 1148 |
+
Calls `str.lstrip` element-wise.
|
| 1149 |
+
|
| 1150 |
+
Parameters
|
| 1151 |
+
----------
|
| 1152 |
+
a : array-like, {str, unicode}
|
| 1153 |
+
Input array.
|
| 1154 |
+
|
| 1155 |
+
chars : {str, unicode}, optional
|
| 1156 |
+
The `chars` argument is a string specifying the set of
|
| 1157 |
+
characters to be removed. If omitted or None, the `chars`
|
| 1158 |
+
argument defaults to removing whitespace. The `chars` argument
|
| 1159 |
+
is not a prefix; rather, all combinations of its values are
|
| 1160 |
+
stripped.
|
| 1161 |
+
|
| 1162 |
+
Returns
|
| 1163 |
+
-------
|
| 1164 |
+
out : ndarray, {str, unicode}
|
| 1165 |
+
Output array of str or unicode, depending on input type
|
| 1166 |
+
|
| 1167 |
+
See Also
|
| 1168 |
+
--------
|
| 1169 |
+
str.lstrip
|
| 1170 |
+
|
| 1171 |
+
Examples
|
| 1172 |
+
--------
|
| 1173 |
+
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
|
| 1174 |
+
>>> c
|
| 1175 |
+
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
|
| 1176 |
+
|
| 1177 |
+
The 'a' variable is unstripped from c[1] because whitespace leading.
|
| 1178 |
+
|
| 1179 |
+
>>> np.char.lstrip(c, 'a')
|
| 1180 |
+
array(['AaAaA', ' aA ', 'bBABba'], dtype='<U7')
|
| 1181 |
+
|
| 1182 |
+
|
| 1183 |
+
>>> np.char.lstrip(c, 'A') # leaves c unchanged
|
| 1184 |
+
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
|
| 1185 |
+
>>> (np.char.lstrip(c, ' ') == np.char.lstrip(c, '')).all()
|
| 1186 |
+
... # XXX: is this a regression? This used to return True
|
| 1187 |
+
... # np.char.lstrip(c,'') does not modify c at all.
|
| 1188 |
+
False
|
| 1189 |
+
>>> (np.char.lstrip(c, ' ') == np.char.lstrip(c, None)).all()
|
| 1190 |
+
True
|
| 1191 |
+
|
| 1192 |
+
"""
|
| 1193 |
+
a_arr = numpy.asarray(a)
|
| 1194 |
+
return _vec_string(a_arr, a_arr.dtype, 'lstrip', (chars,))
|
| 1195 |
+
|
| 1196 |
+
|
| 1197 |
+
def _partition_dispatcher(a, sep):
|
| 1198 |
+
return (a,)
|
| 1199 |
+
|
| 1200 |
+
|
| 1201 |
+
@array_function_dispatch(_partition_dispatcher)
|
| 1202 |
+
def partition(a, sep):
|
| 1203 |
+
"""
|
| 1204 |
+
Partition each element in `a` around `sep`.
|
| 1205 |
+
|
| 1206 |
+
Calls `str.partition` element-wise.
|
| 1207 |
+
|
| 1208 |
+
For each element in `a`, split the element as the first
|
| 1209 |
+
occurrence of `sep`, and return 3 strings containing the part
|
| 1210 |
+
before the separator, the separator itself, and the part after
|
| 1211 |
+
the separator. If the separator is not found, return 3 strings
|
| 1212 |
+
containing the string itself, followed by two empty strings.
|
| 1213 |
+
|
| 1214 |
+
Parameters
|
| 1215 |
+
----------
|
| 1216 |
+
a : array_like, {str, unicode}
|
| 1217 |
+
Input array
|
| 1218 |
+
sep : {str, unicode}
|
| 1219 |
+
Separator to split each string element in `a`.
|
| 1220 |
+
|
| 1221 |
+
Returns
|
| 1222 |
+
-------
|
| 1223 |
+
out : ndarray, {str, unicode}
|
| 1224 |
+
Output array of str or unicode, depending on input type.
|
| 1225 |
+
The output array will have an extra dimension with 3
|
| 1226 |
+
elements per input element.
|
| 1227 |
+
|
| 1228 |
+
See Also
|
| 1229 |
+
--------
|
| 1230 |
+
str.partition
|
| 1231 |
+
|
| 1232 |
+
"""
|
| 1233 |
+
return _to_bytes_or_str_array(
|
| 1234 |
+
_vec_string(a, object_, 'partition', (sep,)), a)
|
| 1235 |
+
|
| 1236 |
+
|
| 1237 |
+
def _replace_dispatcher(a, old, new, count=None):
|
| 1238 |
+
return (a,)
|
| 1239 |
+
|
| 1240 |
+
|
| 1241 |
+
@array_function_dispatch(_replace_dispatcher)
|
| 1242 |
+
def replace(a, old, new, count=None):
|
| 1243 |
+
"""
|
| 1244 |
+
For each element in `a`, return a copy of the string with all
|
| 1245 |
+
occurrences of substring `old` replaced by `new`.
|
| 1246 |
+
|
| 1247 |
+
Calls `str.replace` element-wise.
|
| 1248 |
+
|
| 1249 |
+
Parameters
|
| 1250 |
+
----------
|
| 1251 |
+
a : array-like of str or unicode
|
| 1252 |
+
|
| 1253 |
+
old, new : str or unicode
|
| 1254 |
+
|
| 1255 |
+
count : int, optional
|
| 1256 |
+
If the optional argument `count` is given, only the first
|
| 1257 |
+
`count` occurrences are replaced.
|
| 1258 |
+
|
| 1259 |
+
Returns
|
| 1260 |
+
-------
|
| 1261 |
+
out : ndarray
|
| 1262 |
+
Output array of str or unicode, depending on input type
|
| 1263 |
+
|
| 1264 |
+
See Also
|
| 1265 |
+
--------
|
| 1266 |
+
str.replace
|
| 1267 |
+
|
| 1268 |
+
Examples
|
| 1269 |
+
--------
|
| 1270 |
+
>>> a = np.array(["That is a mango", "Monkeys eat mangos"])
|
| 1271 |
+
>>> np.char.replace(a, 'mango', 'banana')
|
| 1272 |
+
array(['That is a banana', 'Monkeys eat bananas'], dtype='<U19')
|
| 1273 |
+
|
| 1274 |
+
>>> a = np.array(["The dish is fresh", "This is it"])
|
| 1275 |
+
>>> np.char.replace(a, 'is', 'was')
|
| 1276 |
+
array(['The dwash was fresh', 'Thwas was it'], dtype='<U19')
|
| 1277 |
+
"""
|
| 1278 |
+
return _to_bytes_or_str_array(
|
| 1279 |
+
_vec_string(a, object_, 'replace', [old, new] + _clean_args(count)), a)
|
| 1280 |
+
|
| 1281 |
+
|
| 1282 |
+
@array_function_dispatch(_count_dispatcher)
|
| 1283 |
+
def rfind(a, sub, start=0, end=None):
|
| 1284 |
+
"""
|
| 1285 |
+
For each element in `a`, return the highest index in the string
|
| 1286 |
+
where substring `sub` is found, such that `sub` is contained
|
| 1287 |
+
within [`start`, `end`].
|
| 1288 |
+
|
| 1289 |
+
Calls `str.rfind` element-wise.
|
| 1290 |
+
|
| 1291 |
+
Parameters
|
| 1292 |
+
----------
|
| 1293 |
+
a : array-like of str or unicode
|
| 1294 |
+
|
| 1295 |
+
sub : str or unicode
|
| 1296 |
+
|
| 1297 |
+
start, end : int, optional
|
| 1298 |
+
Optional arguments `start` and `end` are interpreted as in
|
| 1299 |
+
slice notation.
|
| 1300 |
+
|
| 1301 |
+
Returns
|
| 1302 |
+
-------
|
| 1303 |
+
out : ndarray
|
| 1304 |
+
Output array of ints. Return -1 on failure.
|
| 1305 |
+
|
| 1306 |
+
See Also
|
| 1307 |
+
--------
|
| 1308 |
+
str.rfind
|
| 1309 |
+
|
| 1310 |
+
"""
|
| 1311 |
+
return _vec_string(
|
| 1312 |
+
a, int_, 'rfind', [sub, start] + _clean_args(end))
|
| 1313 |
+
|
| 1314 |
+
|
| 1315 |
+
@array_function_dispatch(_count_dispatcher)
|
| 1316 |
+
def rindex(a, sub, start=0, end=None):
|
| 1317 |
+
"""
|
| 1318 |
+
Like `rfind`, but raises `ValueError` when the substring `sub` is
|
| 1319 |
+
not found.
|
| 1320 |
+
|
| 1321 |
+
Calls `str.rindex` element-wise.
|
| 1322 |
+
|
| 1323 |
+
Parameters
|
| 1324 |
+
----------
|
| 1325 |
+
a : array-like of str or unicode
|
| 1326 |
+
|
| 1327 |
+
sub : str or unicode
|
| 1328 |
+
|
| 1329 |
+
start, end : int, optional
|
| 1330 |
+
|
| 1331 |
+
Returns
|
| 1332 |
+
-------
|
| 1333 |
+
out : ndarray
|
| 1334 |
+
Output array of ints.
|
| 1335 |
+
|
| 1336 |
+
See Also
|
| 1337 |
+
--------
|
| 1338 |
+
rfind, str.rindex
|
| 1339 |
+
|
| 1340 |
+
"""
|
| 1341 |
+
return _vec_string(
|
| 1342 |
+
a, int_, 'rindex', [sub, start] + _clean_args(end))
|
| 1343 |
+
|
| 1344 |
+
|
| 1345 |
+
@array_function_dispatch(_just_dispatcher)
|
| 1346 |
+
def rjust(a, width, fillchar=' '):
|
| 1347 |
+
"""
|
| 1348 |
+
Return an array with the elements of `a` right-justified in a
|
| 1349 |
+
string of length `width`.
|
| 1350 |
+
|
| 1351 |
+
Calls `str.rjust` element-wise.
|
| 1352 |
+
|
| 1353 |
+
Parameters
|
| 1354 |
+
----------
|
| 1355 |
+
a : array_like of str or unicode
|
| 1356 |
+
|
| 1357 |
+
width : int
|
| 1358 |
+
The length of the resulting strings
|
| 1359 |
+
fillchar : str or unicode, optional
|
| 1360 |
+
The character to use for padding
|
| 1361 |
+
|
| 1362 |
+
Returns
|
| 1363 |
+
-------
|
| 1364 |
+
out : ndarray
|
| 1365 |
+
Output array of str or unicode, depending on input type
|
| 1366 |
+
|
| 1367 |
+
See Also
|
| 1368 |
+
--------
|
| 1369 |
+
str.rjust
|
| 1370 |
+
|
| 1371 |
+
"""
|
| 1372 |
+
a_arr = numpy.asarray(a)
|
| 1373 |
+
width_arr = numpy.asarray(width)
|
| 1374 |
+
size = int(numpy.max(width_arr.flat))
|
| 1375 |
+
if numpy.issubdtype(a_arr.dtype, numpy.bytes_):
|
| 1376 |
+
fillchar = asbytes(fillchar)
|
| 1377 |
+
return _vec_string(
|
| 1378 |
+
a_arr, type(a_arr.dtype)(size), 'rjust', (width_arr, fillchar))
|
| 1379 |
+
|
| 1380 |
+
|
| 1381 |
+
@array_function_dispatch(_partition_dispatcher)
|
| 1382 |
+
def rpartition(a, sep):
|
| 1383 |
+
"""
|
| 1384 |
+
Partition (split) each element around the right-most separator.
|
| 1385 |
+
|
| 1386 |
+
Calls `str.rpartition` element-wise.
|
| 1387 |
+
|
| 1388 |
+
For each element in `a`, split the element as the last
|
| 1389 |
+
occurrence of `sep`, and return 3 strings containing the part
|
| 1390 |
+
before the separator, the separator itself, and the part after
|
| 1391 |
+
the separator. If the separator is not found, return 3 strings
|
| 1392 |
+
containing the string itself, followed by two empty strings.
|
| 1393 |
+
|
| 1394 |
+
Parameters
|
| 1395 |
+
----------
|
| 1396 |
+
a : array_like of str or unicode
|
| 1397 |
+
Input array
|
| 1398 |
+
sep : str or unicode
|
| 1399 |
+
Right-most separator to split each element in array.
|
| 1400 |
+
|
| 1401 |
+
Returns
|
| 1402 |
+
-------
|
| 1403 |
+
out : ndarray
|
| 1404 |
+
Output array of string or unicode, depending on input
|
| 1405 |
+
type. The output array will have an extra dimension with
|
| 1406 |
+
3 elements per input element.
|
| 1407 |
+
|
| 1408 |
+
See Also
|
| 1409 |
+
--------
|
| 1410 |
+
str.rpartition
|
| 1411 |
+
|
| 1412 |
+
"""
|
| 1413 |
+
return _to_bytes_or_str_array(
|
| 1414 |
+
_vec_string(a, object_, 'rpartition', (sep,)), a)
|
| 1415 |
+
|
| 1416 |
+
|
| 1417 |
+
def _split_dispatcher(a, sep=None, maxsplit=None):
|
| 1418 |
+
return (a,)
|
| 1419 |
+
|
| 1420 |
+
|
| 1421 |
+
@array_function_dispatch(_split_dispatcher)
|
| 1422 |
+
def rsplit(a, sep=None, maxsplit=None):
|
| 1423 |
+
"""
|
| 1424 |
+
For each element in `a`, return a list of the words in the
|
| 1425 |
+
string, using `sep` as the delimiter string.
|
| 1426 |
+
|
| 1427 |
+
Calls `str.rsplit` element-wise.
|
| 1428 |
+
|
| 1429 |
+
Except for splitting from the right, `rsplit`
|
| 1430 |
+
behaves like `split`.
|
| 1431 |
+
|
| 1432 |
+
Parameters
|
| 1433 |
+
----------
|
| 1434 |
+
a : array_like of str or unicode
|
| 1435 |
+
|
| 1436 |
+
sep : str or unicode, optional
|
| 1437 |
+
If `sep` is not specified or None, any whitespace string
|
| 1438 |
+
is a separator.
|
| 1439 |
+
maxsplit : int, optional
|
| 1440 |
+
If `maxsplit` is given, at most `maxsplit` splits are done,
|
| 1441 |
+
the rightmost ones.
|
| 1442 |
+
|
| 1443 |
+
Returns
|
| 1444 |
+
-------
|
| 1445 |
+
out : ndarray
|
| 1446 |
+
Array of list objects
|
| 1447 |
+
|
| 1448 |
+
See Also
|
| 1449 |
+
--------
|
| 1450 |
+
str.rsplit, split
|
| 1451 |
+
|
| 1452 |
+
"""
|
| 1453 |
+
# This will return an array of lists of different sizes, so we
|
| 1454 |
+
# leave it as an object array
|
| 1455 |
+
return _vec_string(
|
| 1456 |
+
a, object_, 'rsplit', [sep] + _clean_args(maxsplit))
|
| 1457 |
+
|
| 1458 |
+
|
| 1459 |
+
def _strip_dispatcher(a, chars=None):
|
| 1460 |
+
return (a,)
|
| 1461 |
+
|
| 1462 |
+
|
| 1463 |
+
@array_function_dispatch(_strip_dispatcher)
|
| 1464 |
+
def rstrip(a, chars=None):
|
| 1465 |
+
"""
|
| 1466 |
+
For each element in `a`, return a copy with the trailing
|
| 1467 |
+
characters removed.
|
| 1468 |
+
|
| 1469 |
+
Calls `str.rstrip` element-wise.
|
| 1470 |
+
|
| 1471 |
+
Parameters
|
| 1472 |
+
----------
|
| 1473 |
+
a : array-like of str or unicode
|
| 1474 |
+
|
| 1475 |
+
chars : str or unicode, optional
|
| 1476 |
+
The `chars` argument is a string specifying the set of
|
| 1477 |
+
characters to be removed. If omitted or None, the `chars`
|
| 1478 |
+
argument defaults to removing whitespace. The `chars` argument
|
| 1479 |
+
is not a suffix; rather, all combinations of its values are
|
| 1480 |
+
stripped.
|
| 1481 |
+
|
| 1482 |
+
Returns
|
| 1483 |
+
-------
|
| 1484 |
+
out : ndarray
|
| 1485 |
+
Output array of str or unicode, depending on input type
|
| 1486 |
+
|
| 1487 |
+
See Also
|
| 1488 |
+
--------
|
| 1489 |
+
str.rstrip
|
| 1490 |
+
|
| 1491 |
+
Examples
|
| 1492 |
+
--------
|
| 1493 |
+
>>> c = np.array(['aAaAaA', 'abBABba'], dtype='S7'); c
|
| 1494 |
+
array(['aAaAaA', 'abBABba'],
|
| 1495 |
+
dtype='|S7')
|
| 1496 |
+
>>> np.char.rstrip(c, b'a')
|
| 1497 |
+
array(['aAaAaA', 'abBABb'],
|
| 1498 |
+
dtype='|S7')
|
| 1499 |
+
>>> np.char.rstrip(c, b'A')
|
| 1500 |
+
array(['aAaAa', 'abBABba'],
|
| 1501 |
+
dtype='|S7')
|
| 1502 |
+
|
| 1503 |
+
"""
|
| 1504 |
+
a_arr = numpy.asarray(a)
|
| 1505 |
+
return _vec_string(a_arr, a_arr.dtype, 'rstrip', (chars,))
|
| 1506 |
+
|
| 1507 |
+
|
| 1508 |
+
@array_function_dispatch(_split_dispatcher)
|
| 1509 |
+
def split(a, sep=None, maxsplit=None):
|
| 1510 |
+
"""
|
| 1511 |
+
For each element in `a`, return a list of the words in the
|
| 1512 |
+
string, using `sep` as the delimiter string.
|
| 1513 |
+
|
| 1514 |
+
Calls `str.split` element-wise.
|
| 1515 |
+
|
| 1516 |
+
Parameters
|
| 1517 |
+
----------
|
| 1518 |
+
a : array_like of str or unicode
|
| 1519 |
+
|
| 1520 |
+
sep : str or unicode, optional
|
| 1521 |
+
If `sep` is not specified or None, any whitespace string is a
|
| 1522 |
+
separator.
|
| 1523 |
+
|
| 1524 |
+
maxsplit : int, optional
|
| 1525 |
+
If `maxsplit` is given, at most `maxsplit` splits are done.
|
| 1526 |
+
|
| 1527 |
+
Returns
|
| 1528 |
+
-------
|
| 1529 |
+
out : ndarray
|
| 1530 |
+
Array of list objects
|
| 1531 |
+
|
| 1532 |
+
See Also
|
| 1533 |
+
--------
|
| 1534 |
+
str.split, rsplit
|
| 1535 |
+
|
| 1536 |
+
"""
|
| 1537 |
+
# This will return an array of lists of different sizes, so we
|
| 1538 |
+
# leave it as an object array
|
| 1539 |
+
return _vec_string(
|
| 1540 |
+
a, object_, 'split', [sep] + _clean_args(maxsplit))
|
| 1541 |
+
|
| 1542 |
+
|
| 1543 |
+
def _splitlines_dispatcher(a, keepends=None):
|
| 1544 |
+
return (a,)
|
| 1545 |
+
|
| 1546 |
+
|
| 1547 |
+
@array_function_dispatch(_splitlines_dispatcher)
|
| 1548 |
+
def splitlines(a, keepends=None):
|
| 1549 |
+
"""
|
| 1550 |
+
For each element in `a`, return a list of the lines in the
|
| 1551 |
+
element, breaking at line boundaries.
|
| 1552 |
+
|
| 1553 |
+
Calls `str.splitlines` element-wise.
|
| 1554 |
+
|
| 1555 |
+
Parameters
|
| 1556 |
+
----------
|
| 1557 |
+
a : array_like of str or unicode
|
| 1558 |
+
|
| 1559 |
+
keepends : bool, optional
|
| 1560 |
+
Line breaks are not included in the resulting list unless
|
| 1561 |
+
keepends is given and true.
|
| 1562 |
+
|
| 1563 |
+
Returns
|
| 1564 |
+
-------
|
| 1565 |
+
out : ndarray
|
| 1566 |
+
Array of list objects
|
| 1567 |
+
|
| 1568 |
+
See Also
|
| 1569 |
+
--------
|
| 1570 |
+
str.splitlines
|
| 1571 |
+
|
| 1572 |
+
"""
|
| 1573 |
+
return _vec_string(
|
| 1574 |
+
a, object_, 'splitlines', _clean_args(keepends))
|
| 1575 |
+
|
| 1576 |
+
|
| 1577 |
+
def _startswith_dispatcher(a, prefix, start=None, end=None):
|
| 1578 |
+
return (a,)
|
| 1579 |
+
|
| 1580 |
+
|
| 1581 |
+
@array_function_dispatch(_startswith_dispatcher)
|
| 1582 |
+
def startswith(a, prefix, start=0, end=None):
|
| 1583 |
+
"""
|
| 1584 |
+
Returns a boolean array which is `True` where the string element
|
| 1585 |
+
in `a` starts with `prefix`, otherwise `False`.
|
| 1586 |
+
|
| 1587 |
+
Calls `str.startswith` element-wise.
|
| 1588 |
+
|
| 1589 |
+
Parameters
|
| 1590 |
+
----------
|
| 1591 |
+
a : array_like of str or unicode
|
| 1592 |
+
|
| 1593 |
+
prefix : str
|
| 1594 |
+
|
| 1595 |
+
start, end : int, optional
|
| 1596 |
+
With optional `start`, test beginning at that position. With
|
| 1597 |
+
optional `end`, stop comparing at that position.
|
| 1598 |
+
|
| 1599 |
+
Returns
|
| 1600 |
+
-------
|
| 1601 |
+
out : ndarray
|
| 1602 |
+
Array of booleans
|
| 1603 |
+
|
| 1604 |
+
See Also
|
| 1605 |
+
--------
|
| 1606 |
+
str.startswith
|
| 1607 |
+
|
| 1608 |
+
"""
|
| 1609 |
+
return _vec_string(
|
| 1610 |
+
a, bool_, 'startswith', [prefix, start] + _clean_args(end))
|
| 1611 |
+
|
| 1612 |
+
|
| 1613 |
+
@array_function_dispatch(_strip_dispatcher)
|
| 1614 |
+
def strip(a, chars=None):
|
| 1615 |
+
"""
|
| 1616 |
+
For each element in `a`, return a copy with the leading and
|
| 1617 |
+
trailing characters removed.
|
| 1618 |
+
|
| 1619 |
+
Calls `str.strip` element-wise.
|
| 1620 |
+
|
| 1621 |
+
Parameters
|
| 1622 |
+
----------
|
| 1623 |
+
a : array-like of str or unicode
|
| 1624 |
+
|
| 1625 |
+
chars : str or unicode, optional
|
| 1626 |
+
The `chars` argument is a string specifying the set of
|
| 1627 |
+
characters to be removed. If omitted or None, the `chars`
|
| 1628 |
+
argument defaults to removing whitespace. The `chars` argument
|
| 1629 |
+
is not a prefix or suffix; rather, all combinations of its
|
| 1630 |
+
values are stripped.
|
| 1631 |
+
|
| 1632 |
+
Returns
|
| 1633 |
+
-------
|
| 1634 |
+
out : ndarray
|
| 1635 |
+
Output array of str or unicode, depending on input type
|
| 1636 |
+
|
| 1637 |
+
See Also
|
| 1638 |
+
--------
|
| 1639 |
+
str.strip
|
| 1640 |
+
|
| 1641 |
+
Examples
|
| 1642 |
+
--------
|
| 1643 |
+
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
|
| 1644 |
+
>>> c
|
| 1645 |
+
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
|
| 1646 |
+
>>> np.char.strip(c)
|
| 1647 |
+
array(['aAaAaA', 'aA', 'abBABba'], dtype='<U7')
|
| 1648 |
+
>>> np.char.strip(c, 'a') # 'a' unstripped from c[1] because whitespace leads
|
| 1649 |
+
array(['AaAaA', ' aA ', 'bBABb'], dtype='<U7')
|
| 1650 |
+
>>> np.char.strip(c, 'A') # 'A' unstripped from c[1] because (unprinted) ws trails
|
| 1651 |
+
array(['aAaAa', ' aA ', 'abBABba'], dtype='<U7')
|
| 1652 |
+
|
| 1653 |
+
"""
|
| 1654 |
+
a_arr = numpy.asarray(a)
|
| 1655 |
+
return _vec_string(a_arr, a_arr.dtype, 'strip', _clean_args(chars))
|
| 1656 |
+
|
| 1657 |
+
|
| 1658 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 1659 |
+
def swapcase(a):
|
| 1660 |
+
"""
|
| 1661 |
+
Return element-wise a copy of the string with
|
| 1662 |
+
uppercase characters converted to lowercase and vice versa.
|
| 1663 |
+
|
| 1664 |
+
Calls `str.swapcase` element-wise.
|
| 1665 |
+
|
| 1666 |
+
For 8-bit strings, this method is locale-dependent.
|
| 1667 |
+
|
| 1668 |
+
Parameters
|
| 1669 |
+
----------
|
| 1670 |
+
a : array_like, {str, unicode}
|
| 1671 |
+
Input array.
|
| 1672 |
+
|
| 1673 |
+
Returns
|
| 1674 |
+
-------
|
| 1675 |
+
out : ndarray, {str, unicode}
|
| 1676 |
+
Output array of str or unicode, depending on input type
|
| 1677 |
+
|
| 1678 |
+
See Also
|
| 1679 |
+
--------
|
| 1680 |
+
str.swapcase
|
| 1681 |
+
|
| 1682 |
+
Examples
|
| 1683 |
+
--------
|
| 1684 |
+
>>> c=np.array(['a1B c','1b Ca','b Ca1','cA1b'],'S5'); c
|
| 1685 |
+
array(['a1B c', '1b Ca', 'b Ca1', 'cA1b'],
|
| 1686 |
+
dtype='|S5')
|
| 1687 |
+
>>> np.char.swapcase(c)
|
| 1688 |
+
array(['A1b C', '1B cA', 'B cA1', 'Ca1B'],
|
| 1689 |
+
dtype='|S5')
|
| 1690 |
+
|
| 1691 |
+
"""
|
| 1692 |
+
a_arr = numpy.asarray(a)
|
| 1693 |
+
return _vec_string(a_arr, a_arr.dtype, 'swapcase')
|
| 1694 |
+
|
| 1695 |
+
|
| 1696 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 1697 |
+
def title(a):
|
| 1698 |
+
"""
|
| 1699 |
+
Return element-wise title cased version of string or unicode.
|
| 1700 |
+
|
| 1701 |
+
Title case words start with uppercase characters, all remaining cased
|
| 1702 |
+
characters are lowercase.
|
| 1703 |
+
|
| 1704 |
+
Calls `str.title` element-wise.
|
| 1705 |
+
|
| 1706 |
+
For 8-bit strings, this method is locale-dependent.
|
| 1707 |
+
|
| 1708 |
+
Parameters
|
| 1709 |
+
----------
|
| 1710 |
+
a : array_like, {str, unicode}
|
| 1711 |
+
Input array.
|
| 1712 |
+
|
| 1713 |
+
Returns
|
| 1714 |
+
-------
|
| 1715 |
+
out : ndarray
|
| 1716 |
+
Output array of str or unicode, depending on input type
|
| 1717 |
+
|
| 1718 |
+
See Also
|
| 1719 |
+
--------
|
| 1720 |
+
str.title
|
| 1721 |
+
|
| 1722 |
+
Examples
|
| 1723 |
+
--------
|
| 1724 |
+
>>> c=np.array(['a1b c','1b ca','b ca1','ca1b'],'S5'); c
|
| 1725 |
+
array(['a1b c', '1b ca', 'b ca1', 'ca1b'],
|
| 1726 |
+
dtype='|S5')
|
| 1727 |
+
>>> np.char.title(c)
|
| 1728 |
+
array(['A1B C', '1B Ca', 'B Ca1', 'Ca1B'],
|
| 1729 |
+
dtype='|S5')
|
| 1730 |
+
|
| 1731 |
+
"""
|
| 1732 |
+
a_arr = numpy.asarray(a)
|
| 1733 |
+
return _vec_string(a_arr, a_arr.dtype, 'title')
|
| 1734 |
+
|
| 1735 |
+
|
| 1736 |
+
def _translate_dispatcher(a, table, deletechars=None):
|
| 1737 |
+
return (a,)
|
| 1738 |
+
|
| 1739 |
+
|
| 1740 |
+
@array_function_dispatch(_translate_dispatcher)
|
| 1741 |
+
def translate(a, table, deletechars=None):
|
| 1742 |
+
"""
|
| 1743 |
+
For each element in `a`, return a copy of the string where all
|
| 1744 |
+
characters occurring in the optional argument `deletechars` are
|
| 1745 |
+
removed, and the remaining characters have been mapped through the
|
| 1746 |
+
given translation table.
|
| 1747 |
+
|
| 1748 |
+
Calls `str.translate` element-wise.
|
| 1749 |
+
|
| 1750 |
+
Parameters
|
| 1751 |
+
----------
|
| 1752 |
+
a : array-like of str or unicode
|
| 1753 |
+
|
| 1754 |
+
table : str of length 256
|
| 1755 |
+
|
| 1756 |
+
deletechars : str
|
| 1757 |
+
|
| 1758 |
+
Returns
|
| 1759 |
+
-------
|
| 1760 |
+
out : ndarray
|
| 1761 |
+
Output array of str or unicode, depending on input type
|
| 1762 |
+
|
| 1763 |
+
See Also
|
| 1764 |
+
--------
|
| 1765 |
+
str.translate
|
| 1766 |
+
|
| 1767 |
+
"""
|
| 1768 |
+
a_arr = numpy.asarray(a)
|
| 1769 |
+
if issubclass(a_arr.dtype.type, str_):
|
| 1770 |
+
return _vec_string(
|
| 1771 |
+
a_arr, a_arr.dtype, 'translate', (table,))
|
| 1772 |
+
else:
|
| 1773 |
+
return _vec_string(
|
| 1774 |
+
a_arr, a_arr.dtype, 'translate', [table] + _clean_args(deletechars))
|
| 1775 |
+
|
| 1776 |
+
|
| 1777 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 1778 |
+
def upper(a):
|
| 1779 |
+
"""
|
| 1780 |
+
Return an array with the elements converted to uppercase.
|
| 1781 |
+
|
| 1782 |
+
Calls `str.upper` element-wise.
|
| 1783 |
+
|
| 1784 |
+
For 8-bit strings, this method is locale-dependent.
|
| 1785 |
+
|
| 1786 |
+
Parameters
|
| 1787 |
+
----------
|
| 1788 |
+
a : array_like, {str, unicode}
|
| 1789 |
+
Input array.
|
| 1790 |
+
|
| 1791 |
+
Returns
|
| 1792 |
+
-------
|
| 1793 |
+
out : ndarray, {str, unicode}
|
| 1794 |
+
Output array of str or unicode, depending on input type
|
| 1795 |
+
|
| 1796 |
+
See Also
|
| 1797 |
+
--------
|
| 1798 |
+
str.upper
|
| 1799 |
+
|
| 1800 |
+
Examples
|
| 1801 |
+
--------
|
| 1802 |
+
>>> c = np.array(['a1b c', '1bca', 'bca1']); c
|
| 1803 |
+
array(['a1b c', '1bca', 'bca1'], dtype='<U5')
|
| 1804 |
+
>>> np.char.upper(c)
|
| 1805 |
+
array(['A1B C', '1BCA', 'BCA1'], dtype='<U5')
|
| 1806 |
+
|
| 1807 |
+
"""
|
| 1808 |
+
a_arr = numpy.asarray(a)
|
| 1809 |
+
return _vec_string(a_arr, a_arr.dtype, 'upper')
|
| 1810 |
+
|
| 1811 |
+
|
| 1812 |
+
def _zfill_dispatcher(a, width):
|
| 1813 |
+
return (a,)
|
| 1814 |
+
|
| 1815 |
+
|
| 1816 |
+
@array_function_dispatch(_zfill_dispatcher)
|
| 1817 |
+
def zfill(a, width):
|
| 1818 |
+
"""
|
| 1819 |
+
Return the numeric string left-filled with zeros
|
| 1820 |
+
|
| 1821 |
+
Calls `str.zfill` element-wise.
|
| 1822 |
+
|
| 1823 |
+
Parameters
|
| 1824 |
+
----------
|
| 1825 |
+
a : array_like, {str, unicode}
|
| 1826 |
+
Input array.
|
| 1827 |
+
width : int
|
| 1828 |
+
Width of string to left-fill elements in `a`.
|
| 1829 |
+
|
| 1830 |
+
Returns
|
| 1831 |
+
-------
|
| 1832 |
+
out : ndarray, {str, unicode}
|
| 1833 |
+
Output array of str or unicode, depending on input type
|
| 1834 |
+
|
| 1835 |
+
See Also
|
| 1836 |
+
--------
|
| 1837 |
+
str.zfill
|
| 1838 |
+
|
| 1839 |
+
"""
|
| 1840 |
+
a_arr = numpy.asarray(a)
|
| 1841 |
+
width_arr = numpy.asarray(width)
|
| 1842 |
+
size = int(numpy.max(width_arr.flat))
|
| 1843 |
+
return _vec_string(
|
| 1844 |
+
a_arr, type(a_arr.dtype)(size), 'zfill', (width_arr,))
|
| 1845 |
+
|
| 1846 |
+
|
| 1847 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 1848 |
+
def isnumeric(a):
|
| 1849 |
+
"""
|
| 1850 |
+
For each element, return True if there are only numeric
|
| 1851 |
+
characters in the element.
|
| 1852 |
+
|
| 1853 |
+
Calls `str.isnumeric` element-wise.
|
| 1854 |
+
|
| 1855 |
+
Numeric characters include digit characters, and all characters
|
| 1856 |
+
that have the Unicode numeric value property, e.g. ``U+2155,
|
| 1857 |
+
VULGAR FRACTION ONE FIFTH``.
|
| 1858 |
+
|
| 1859 |
+
Parameters
|
| 1860 |
+
----------
|
| 1861 |
+
a : array_like, unicode
|
| 1862 |
+
Input array.
|
| 1863 |
+
|
| 1864 |
+
Returns
|
| 1865 |
+
-------
|
| 1866 |
+
out : ndarray, bool
|
| 1867 |
+
Array of booleans of same shape as `a`.
|
| 1868 |
+
|
| 1869 |
+
See Also
|
| 1870 |
+
--------
|
| 1871 |
+
str.isnumeric
|
| 1872 |
+
|
| 1873 |
+
Examples
|
| 1874 |
+
--------
|
| 1875 |
+
>>> np.char.isnumeric(['123', '123abc', '9.0', '1/4', 'VIII'])
|
| 1876 |
+
array([ True, False, False, False, False])
|
| 1877 |
+
|
| 1878 |
+
"""
|
| 1879 |
+
if not _is_unicode(a):
|
| 1880 |
+
raise TypeError("isnumeric is only available for Unicode strings and arrays")
|
| 1881 |
+
return _vec_string(a, bool_, 'isnumeric')
|
| 1882 |
+
|
| 1883 |
+
|
| 1884 |
+
@array_function_dispatch(_unary_op_dispatcher)
|
| 1885 |
+
def isdecimal(a):
|
| 1886 |
+
"""
|
| 1887 |
+
For each element, return True if there are only decimal
|
| 1888 |
+
characters in the element.
|
| 1889 |
+
|
| 1890 |
+
Calls `str.isdecimal` element-wise.
|
| 1891 |
+
|
| 1892 |
+
Decimal characters include digit characters, and all characters
|
| 1893 |
+
that can be used to form decimal-radix numbers,
|
| 1894 |
+
e.g. ``U+0660, ARABIC-INDIC DIGIT ZERO``.
|
| 1895 |
+
|
| 1896 |
+
Parameters
|
| 1897 |
+
----------
|
| 1898 |
+
a : array_like, unicode
|
| 1899 |
+
Input array.
|
| 1900 |
+
|
| 1901 |
+
Returns
|
| 1902 |
+
-------
|
| 1903 |
+
out : ndarray, bool
|
| 1904 |
+
Array of booleans identical in shape to `a`.
|
| 1905 |
+
|
| 1906 |
+
See Also
|
| 1907 |
+
--------
|
| 1908 |
+
str.isdecimal
|
| 1909 |
+
|
| 1910 |
+
Examples
|
| 1911 |
+
--------
|
| 1912 |
+
>>> np.char.isdecimal(['12345', '4.99', '123ABC', ''])
|
| 1913 |
+
array([ True, False, False, False])
|
| 1914 |
+
|
| 1915 |
+
"""
|
| 1916 |
+
if not _is_unicode(a):
|
| 1917 |
+
raise TypeError(
|
| 1918 |
+
"isdecimal is only available for Unicode strings and arrays")
|
| 1919 |
+
return _vec_string(a, bool_, 'isdecimal')
|
| 1920 |
+
|
| 1921 |
+
|
| 1922 |
+
@set_module('numpy')
|
| 1923 |
+
class chararray(ndarray):
|
| 1924 |
+
"""
|
| 1925 |
+
chararray(shape, itemsize=1, unicode=False, buffer=None, offset=0,
|
| 1926 |
+
strides=None, order=None)
|
| 1927 |
+
|
| 1928 |
+
Provides a convenient view on arrays of string and unicode values.
|
| 1929 |
+
|
| 1930 |
+
.. note::
|
| 1931 |
+
The `chararray` class exists for backwards compatibility with
|
| 1932 |
+
Numarray, it is not recommended for new development. Starting from numpy
|
| 1933 |
+
1.4, if one needs arrays of strings, it is recommended to use arrays of
|
| 1934 |
+
`dtype` `object_`, `bytes_` or `str_`, and use the free functions
|
| 1935 |
+
in the `numpy.char` module for fast vectorized string operations.
|
| 1936 |
+
|
| 1937 |
+
Versus a regular NumPy array of type `str` or `unicode`, this
|
| 1938 |
+
class adds the following functionality:
|
| 1939 |
+
|
| 1940 |
+
1) values automatically have whitespace removed from the end
|
| 1941 |
+
when indexed
|
| 1942 |
+
|
| 1943 |
+
2) comparison operators automatically remove whitespace from the
|
| 1944 |
+
end when comparing values
|
| 1945 |
+
|
| 1946 |
+
3) vectorized string operations are provided as methods
|
| 1947 |
+
(e.g. `.endswith`) and infix operators (e.g. ``"+", "*", "%"``)
|
| 1948 |
+
|
| 1949 |
+
chararrays should be created using `numpy.char.array` or
|
| 1950 |
+
`numpy.char.asarray`, rather than this constructor directly.
|
| 1951 |
+
|
| 1952 |
+
This constructor creates the array, using `buffer` (with `offset`
|
| 1953 |
+
and `strides`) if it is not ``None``. If `buffer` is ``None``, then
|
| 1954 |
+
constructs a new array with `strides` in "C order", unless both
|
| 1955 |
+
``len(shape) >= 2`` and ``order='F'``, in which case `strides`
|
| 1956 |
+
is in "Fortran order".
|
| 1957 |
+
|
| 1958 |
+
Methods
|
| 1959 |
+
-------
|
| 1960 |
+
astype
|
| 1961 |
+
argsort
|
| 1962 |
+
copy
|
| 1963 |
+
count
|
| 1964 |
+
decode
|
| 1965 |
+
dump
|
| 1966 |
+
dumps
|
| 1967 |
+
encode
|
| 1968 |
+
endswith
|
| 1969 |
+
expandtabs
|
| 1970 |
+
fill
|
| 1971 |
+
find
|
| 1972 |
+
flatten
|
| 1973 |
+
getfield
|
| 1974 |
+
index
|
| 1975 |
+
isalnum
|
| 1976 |
+
isalpha
|
| 1977 |
+
isdecimal
|
| 1978 |
+
isdigit
|
| 1979 |
+
islower
|
| 1980 |
+
isnumeric
|
| 1981 |
+
isspace
|
| 1982 |
+
istitle
|
| 1983 |
+
isupper
|
| 1984 |
+
item
|
| 1985 |
+
join
|
| 1986 |
+
ljust
|
| 1987 |
+
lower
|
| 1988 |
+
lstrip
|
| 1989 |
+
nonzero
|
| 1990 |
+
put
|
| 1991 |
+
ravel
|
| 1992 |
+
repeat
|
| 1993 |
+
replace
|
| 1994 |
+
reshape
|
| 1995 |
+
resize
|
| 1996 |
+
rfind
|
| 1997 |
+
rindex
|
| 1998 |
+
rjust
|
| 1999 |
+
rsplit
|
| 2000 |
+
rstrip
|
| 2001 |
+
searchsorted
|
| 2002 |
+
setfield
|
| 2003 |
+
setflags
|
| 2004 |
+
sort
|
| 2005 |
+
split
|
| 2006 |
+
splitlines
|
| 2007 |
+
squeeze
|
| 2008 |
+
startswith
|
| 2009 |
+
strip
|
| 2010 |
+
swapaxes
|
| 2011 |
+
swapcase
|
| 2012 |
+
take
|
| 2013 |
+
title
|
| 2014 |
+
tofile
|
| 2015 |
+
tolist
|
| 2016 |
+
tostring
|
| 2017 |
+
translate
|
| 2018 |
+
transpose
|
| 2019 |
+
upper
|
| 2020 |
+
view
|
| 2021 |
+
zfill
|
| 2022 |
+
|
| 2023 |
+
Parameters
|
| 2024 |
+
----------
|
| 2025 |
+
shape : tuple
|
| 2026 |
+
Shape of the array.
|
| 2027 |
+
itemsize : int, optional
|
| 2028 |
+
Length of each array element, in number of characters. Default is 1.
|
| 2029 |
+
unicode : bool, optional
|
| 2030 |
+
Are the array elements of type unicode (True) or string (False).
|
| 2031 |
+
Default is False.
|
| 2032 |
+
buffer : object exposing the buffer interface or str, optional
|
| 2033 |
+
Memory address of the start of the array data. Default is None,
|
| 2034 |
+
in which case a new array is created.
|
| 2035 |
+
offset : int, optional
|
| 2036 |
+
Fixed stride displacement from the beginning of an axis?
|
| 2037 |
+
Default is 0. Needs to be >=0.
|
| 2038 |
+
strides : array_like of ints, optional
|
| 2039 |
+
Strides for the array (see `ndarray.strides` for full description).
|
| 2040 |
+
Default is None.
|
| 2041 |
+
order : {'C', 'F'}, optional
|
| 2042 |
+
The order in which the array data is stored in memory: 'C' ->
|
| 2043 |
+
"row major" order (the default), 'F' -> "column major"
|
| 2044 |
+
(Fortran) order.
|
| 2045 |
+
|
| 2046 |
+
Examples
|
| 2047 |
+
--------
|
| 2048 |
+
>>> charar = np.chararray((3, 3))
|
| 2049 |
+
>>> charar[:] = 'a'
|
| 2050 |
+
>>> charar
|
| 2051 |
+
chararray([[b'a', b'a', b'a'],
|
| 2052 |
+
[b'a', b'a', b'a'],
|
| 2053 |
+
[b'a', b'a', b'a']], dtype='|S1')
|
| 2054 |
+
|
| 2055 |
+
>>> charar = np.chararray(charar.shape, itemsize=5)
|
| 2056 |
+
>>> charar[:] = 'abc'
|
| 2057 |
+
>>> charar
|
| 2058 |
+
chararray([[b'abc', b'abc', b'abc'],
|
| 2059 |
+
[b'abc', b'abc', b'abc'],
|
| 2060 |
+
[b'abc', b'abc', b'abc']], dtype='|S5')
|
| 2061 |
+
|
| 2062 |
+
"""
|
| 2063 |
+
def __new__(subtype, shape, itemsize=1, unicode=False, buffer=None,
|
| 2064 |
+
offset=0, strides=None, order='C'):
|
| 2065 |
+
global _globalvar
|
| 2066 |
+
|
| 2067 |
+
if unicode:
|
| 2068 |
+
dtype = str_
|
| 2069 |
+
else:
|
| 2070 |
+
dtype = bytes_
|
| 2071 |
+
|
| 2072 |
+
# force itemsize to be a Python int, since using NumPy integer
|
| 2073 |
+
# types results in itemsize.itemsize being used as the size of
|
| 2074 |
+
# strings in the new array.
|
| 2075 |
+
itemsize = int(itemsize)
|
| 2076 |
+
|
| 2077 |
+
if isinstance(buffer, str):
|
| 2078 |
+
# unicode objects do not have the buffer interface
|
| 2079 |
+
filler = buffer
|
| 2080 |
+
buffer = None
|
| 2081 |
+
else:
|
| 2082 |
+
filler = None
|
| 2083 |
+
|
| 2084 |
+
_globalvar = 1
|
| 2085 |
+
if buffer is None:
|
| 2086 |
+
self = ndarray.__new__(subtype, shape, (dtype, itemsize),
|
| 2087 |
+
order=order)
|
| 2088 |
+
else:
|
| 2089 |
+
self = ndarray.__new__(subtype, shape, (dtype, itemsize),
|
| 2090 |
+
buffer=buffer,
|
| 2091 |
+
offset=offset, strides=strides,
|
| 2092 |
+
order=order)
|
| 2093 |
+
if filler is not None:
|
| 2094 |
+
self[...] = filler
|
| 2095 |
+
_globalvar = 0
|
| 2096 |
+
return self
|
| 2097 |
+
|
| 2098 |
+
def __array_finalize__(self, obj):
|
| 2099 |
+
# The b is a special case because it is used for reconstructing.
|
| 2100 |
+
if not _globalvar and self.dtype.char not in 'SUbc':
|
| 2101 |
+
raise ValueError("Can only create a chararray from string data.")
|
| 2102 |
+
|
| 2103 |
+
def __getitem__(self, obj):
|
| 2104 |
+
val = ndarray.__getitem__(self, obj)
|
| 2105 |
+
|
| 2106 |
+
if isinstance(val, character):
|
| 2107 |
+
temp = val.rstrip()
|
| 2108 |
+
if len(temp) == 0:
|
| 2109 |
+
val = ''
|
| 2110 |
+
else:
|
| 2111 |
+
val = temp
|
| 2112 |
+
|
| 2113 |
+
return val
|
| 2114 |
+
|
| 2115 |
+
# IMPLEMENTATION NOTE: Most of the methods of this class are
|
| 2116 |
+
# direct delegations to the free functions in this module.
|
| 2117 |
+
# However, those that return an array of strings should instead
|
| 2118 |
+
# return a chararray, so some extra wrapping is required.
|
| 2119 |
+
|
| 2120 |
+
def __eq__(self, other):
|
| 2121 |
+
"""
|
| 2122 |
+
Return (self == other) element-wise.
|
| 2123 |
+
|
| 2124 |
+
See Also
|
| 2125 |
+
--------
|
| 2126 |
+
equal
|
| 2127 |
+
"""
|
| 2128 |
+
return equal(self, other)
|
| 2129 |
+
|
| 2130 |
+
def __ne__(self, other):
|
| 2131 |
+
"""
|
| 2132 |
+
Return (self != other) element-wise.
|
| 2133 |
+
|
| 2134 |
+
See Also
|
| 2135 |
+
--------
|
| 2136 |
+
not_equal
|
| 2137 |
+
"""
|
| 2138 |
+
return not_equal(self, other)
|
| 2139 |
+
|
| 2140 |
+
def __ge__(self, other):
|
| 2141 |
+
"""
|
| 2142 |
+
Return (self >= other) element-wise.
|
| 2143 |
+
|
| 2144 |
+
See Also
|
| 2145 |
+
--------
|
| 2146 |
+
greater_equal
|
| 2147 |
+
"""
|
| 2148 |
+
return greater_equal(self, other)
|
| 2149 |
+
|
| 2150 |
+
def __le__(self, other):
|
| 2151 |
+
"""
|
| 2152 |
+
Return (self <= other) element-wise.
|
| 2153 |
+
|
| 2154 |
+
See Also
|
| 2155 |
+
--------
|
| 2156 |
+
less_equal
|
| 2157 |
+
"""
|
| 2158 |
+
return less_equal(self, other)
|
| 2159 |
+
|
| 2160 |
+
def __gt__(self, other):
|
| 2161 |
+
"""
|
| 2162 |
+
Return (self > other) element-wise.
|
| 2163 |
+
|
| 2164 |
+
See Also
|
| 2165 |
+
--------
|
| 2166 |
+
greater
|
| 2167 |
+
"""
|
| 2168 |
+
return greater(self, other)
|
| 2169 |
+
|
| 2170 |
+
def __lt__(self, other):
|
| 2171 |
+
"""
|
| 2172 |
+
Return (self < other) element-wise.
|
| 2173 |
+
|
| 2174 |
+
See Also
|
| 2175 |
+
--------
|
| 2176 |
+
less
|
| 2177 |
+
"""
|
| 2178 |
+
return less(self, other)
|
| 2179 |
+
|
| 2180 |
+
def __add__(self, other):
|
| 2181 |
+
"""
|
| 2182 |
+
Return (self + other), that is string concatenation,
|
| 2183 |
+
element-wise for a pair of array_likes of str or unicode.
|
| 2184 |
+
|
| 2185 |
+
See Also
|
| 2186 |
+
--------
|
| 2187 |
+
add
|
| 2188 |
+
"""
|
| 2189 |
+
return asarray(add(self, other))
|
| 2190 |
+
|
| 2191 |
+
def __radd__(self, other):
|
| 2192 |
+
"""
|
| 2193 |
+
Return (other + self), that is string concatenation,
|
| 2194 |
+
element-wise for a pair of array_likes of `bytes_` or `str_`.
|
| 2195 |
+
|
| 2196 |
+
See Also
|
| 2197 |
+
--------
|
| 2198 |
+
add
|
| 2199 |
+
"""
|
| 2200 |
+
return asarray(add(numpy.asarray(other), self))
|
| 2201 |
+
|
| 2202 |
+
def __mul__(self, i):
|
| 2203 |
+
"""
|
| 2204 |
+
Return (self * i), that is string multiple concatenation,
|
| 2205 |
+
element-wise.
|
| 2206 |
+
|
| 2207 |
+
See Also
|
| 2208 |
+
--------
|
| 2209 |
+
multiply
|
| 2210 |
+
"""
|
| 2211 |
+
return asarray(multiply(self, i))
|
| 2212 |
+
|
| 2213 |
+
def __rmul__(self, i):
|
| 2214 |
+
"""
|
| 2215 |
+
Return (self * i), that is string multiple concatenation,
|
| 2216 |
+
element-wise.
|
| 2217 |
+
|
| 2218 |
+
See Also
|
| 2219 |
+
--------
|
| 2220 |
+
multiply
|
| 2221 |
+
"""
|
| 2222 |
+
return asarray(multiply(self, i))
|
| 2223 |
+
|
| 2224 |
+
def __mod__(self, i):
|
| 2225 |
+
"""
|
| 2226 |
+
Return (self % i), that is pre-Python 2.6 string formatting
|
| 2227 |
+
(interpolation), element-wise for a pair of array_likes of `bytes_`
|
| 2228 |
+
or `str_`.
|
| 2229 |
+
|
| 2230 |
+
See Also
|
| 2231 |
+
--------
|
| 2232 |
+
mod
|
| 2233 |
+
"""
|
| 2234 |
+
return asarray(mod(self, i))
|
| 2235 |
+
|
| 2236 |
+
def __rmod__(self, other):
|
| 2237 |
+
return NotImplemented
|
| 2238 |
+
|
| 2239 |
+
def argsort(self, axis=-1, kind=None, order=None):
|
| 2240 |
+
"""
|
| 2241 |
+
Return the indices that sort the array lexicographically.
|
| 2242 |
+
|
| 2243 |
+
For full documentation see `numpy.argsort`, for which this method is
|
| 2244 |
+
in fact merely a "thin wrapper."
|
| 2245 |
+
|
| 2246 |
+
Examples
|
| 2247 |
+
--------
|
| 2248 |
+
>>> c = np.array(['a1b c', '1b ca', 'b ca1', 'Ca1b'], 'S5')
|
| 2249 |
+
>>> c = c.view(np.chararray); c
|
| 2250 |
+
chararray(['a1b c', '1b ca', 'b ca1', 'Ca1b'],
|
| 2251 |
+
dtype='|S5')
|
| 2252 |
+
>>> c[c.argsort()]
|
| 2253 |
+
chararray(['1b ca', 'Ca1b', 'a1b c', 'b ca1'],
|
| 2254 |
+
dtype='|S5')
|
| 2255 |
+
|
| 2256 |
+
"""
|
| 2257 |
+
return self.__array__().argsort(axis, kind, order)
|
| 2258 |
+
argsort.__doc__ = ndarray.argsort.__doc__
|
| 2259 |
+
|
| 2260 |
+
def capitalize(self):
|
| 2261 |
+
"""
|
| 2262 |
+
Return a copy of `self` with only the first character of each element
|
| 2263 |
+
capitalized.
|
| 2264 |
+
|
| 2265 |
+
See Also
|
| 2266 |
+
--------
|
| 2267 |
+
char.capitalize
|
| 2268 |
+
|
| 2269 |
+
"""
|
| 2270 |
+
return asarray(capitalize(self))
|
| 2271 |
+
|
| 2272 |
+
def center(self, width, fillchar=' '):
|
| 2273 |
+
"""
|
| 2274 |
+
Return a copy of `self` with its elements centered in a
|
| 2275 |
+
string of length `width`.
|
| 2276 |
+
|
| 2277 |
+
See Also
|
| 2278 |
+
--------
|
| 2279 |
+
center
|
| 2280 |
+
"""
|
| 2281 |
+
return asarray(center(self, width, fillchar))
|
| 2282 |
+
|
| 2283 |
+
def count(self, sub, start=0, end=None):
|
| 2284 |
+
"""
|
| 2285 |
+
Returns an array with the number of non-overlapping occurrences of
|
| 2286 |
+
substring `sub` in the range [`start`, `end`].
|
| 2287 |
+
|
| 2288 |
+
See Also
|
| 2289 |
+
--------
|
| 2290 |
+
char.count
|
| 2291 |
+
|
| 2292 |
+
"""
|
| 2293 |
+
return count(self, sub, start, end)
|
| 2294 |
+
|
| 2295 |
+
def decode(self, encoding=None, errors=None):
|
| 2296 |
+
"""
|
| 2297 |
+
Calls ``bytes.decode`` element-wise.
|
| 2298 |
+
|
| 2299 |
+
See Also
|
| 2300 |
+
--------
|
| 2301 |
+
char.decode
|
| 2302 |
+
|
| 2303 |
+
"""
|
| 2304 |
+
return decode(self, encoding, errors)
|
| 2305 |
+
|
| 2306 |
+
def encode(self, encoding=None, errors=None):
|
| 2307 |
+
"""
|
| 2308 |
+
Calls `str.encode` element-wise.
|
| 2309 |
+
|
| 2310 |
+
See Also
|
| 2311 |
+
--------
|
| 2312 |
+
char.encode
|
| 2313 |
+
|
| 2314 |
+
"""
|
| 2315 |
+
return encode(self, encoding, errors)
|
| 2316 |
+
|
| 2317 |
+
def endswith(self, suffix, start=0, end=None):
|
| 2318 |
+
"""
|
| 2319 |
+
Returns a boolean array which is `True` where the string element
|
| 2320 |
+
in `self` ends with `suffix`, otherwise `False`.
|
| 2321 |
+
|
| 2322 |
+
See Also
|
| 2323 |
+
--------
|
| 2324 |
+
char.endswith
|
| 2325 |
+
|
| 2326 |
+
"""
|
| 2327 |
+
return endswith(self, suffix, start, end)
|
| 2328 |
+
|
| 2329 |
+
def expandtabs(self, tabsize=8):
|
| 2330 |
+
"""
|
| 2331 |
+
Return a copy of each string element where all tab characters are
|
| 2332 |
+
replaced by one or more spaces.
|
| 2333 |
+
|
| 2334 |
+
See Also
|
| 2335 |
+
--------
|
| 2336 |
+
char.expandtabs
|
| 2337 |
+
|
| 2338 |
+
"""
|
| 2339 |
+
return asarray(expandtabs(self, tabsize))
|
| 2340 |
+
|
| 2341 |
+
def find(self, sub, start=0, end=None):
|
| 2342 |
+
"""
|
| 2343 |
+
For each element, return the lowest index in the string where
|
| 2344 |
+
substring `sub` is found.
|
| 2345 |
+
|
| 2346 |
+
See Also
|
| 2347 |
+
--------
|
| 2348 |
+
char.find
|
| 2349 |
+
|
| 2350 |
+
"""
|
| 2351 |
+
return find(self, sub, start, end)
|
| 2352 |
+
|
| 2353 |
+
def index(self, sub, start=0, end=None):
|
| 2354 |
+
"""
|
| 2355 |
+
Like `find`, but raises `ValueError` when the substring is not found.
|
| 2356 |
+
|
| 2357 |
+
See Also
|
| 2358 |
+
--------
|
| 2359 |
+
char.index
|
| 2360 |
+
|
| 2361 |
+
"""
|
| 2362 |
+
return index(self, sub, start, end)
|
| 2363 |
+
|
| 2364 |
+
def isalnum(self):
|
| 2365 |
+
"""
|
| 2366 |
+
Returns true for each element if all characters in the string
|
| 2367 |
+
are alphanumeric and there is at least one character, false
|
| 2368 |
+
otherwise.
|
| 2369 |
+
|
| 2370 |
+
See Also
|
| 2371 |
+
--------
|
| 2372 |
+
char.isalnum
|
| 2373 |
+
|
| 2374 |
+
"""
|
| 2375 |
+
return isalnum(self)
|
| 2376 |
+
|
| 2377 |
+
def isalpha(self):
|
| 2378 |
+
"""
|
| 2379 |
+
Returns true for each element if all characters in the string
|
| 2380 |
+
are alphabetic and there is at least one character, false
|
| 2381 |
+
otherwise.
|
| 2382 |
+
|
| 2383 |
+
See Also
|
| 2384 |
+
--------
|
| 2385 |
+
char.isalpha
|
| 2386 |
+
|
| 2387 |
+
"""
|
| 2388 |
+
return isalpha(self)
|
| 2389 |
+
|
| 2390 |
+
def isdigit(self):
|
| 2391 |
+
"""
|
| 2392 |
+
Returns true for each element if all characters in the string are
|
| 2393 |
+
digits and there is at least one character, false otherwise.
|
| 2394 |
+
|
| 2395 |
+
See Also
|
| 2396 |
+
--------
|
| 2397 |
+
char.isdigit
|
| 2398 |
+
|
| 2399 |
+
"""
|
| 2400 |
+
return isdigit(self)
|
| 2401 |
+
|
| 2402 |
+
def islower(self):
|
| 2403 |
+
"""
|
| 2404 |
+
Returns true for each element if all cased characters in the
|
| 2405 |
+
string are lowercase and there is at least one cased character,
|
| 2406 |
+
false otherwise.
|
| 2407 |
+
|
| 2408 |
+
See Also
|
| 2409 |
+
--------
|
| 2410 |
+
char.islower
|
| 2411 |
+
|
| 2412 |
+
"""
|
| 2413 |
+
return islower(self)
|
| 2414 |
+
|
| 2415 |
+
def isspace(self):
|
| 2416 |
+
"""
|
| 2417 |
+
Returns true for each element if there are only whitespace
|
| 2418 |
+
characters in the string and there is at least one character,
|
| 2419 |
+
false otherwise.
|
| 2420 |
+
|
| 2421 |
+
See Also
|
| 2422 |
+
--------
|
| 2423 |
+
char.isspace
|
| 2424 |
+
|
| 2425 |
+
"""
|
| 2426 |
+
return isspace(self)
|
| 2427 |
+
|
| 2428 |
+
def istitle(self):
|
| 2429 |
+
"""
|
| 2430 |
+
Returns true for each element if the element is a titlecased
|
| 2431 |
+
string and there is at least one character, false otherwise.
|
| 2432 |
+
|
| 2433 |
+
See Also
|
| 2434 |
+
--------
|
| 2435 |
+
char.istitle
|
| 2436 |
+
|
| 2437 |
+
"""
|
| 2438 |
+
return istitle(self)
|
| 2439 |
+
|
| 2440 |
+
def isupper(self):
|
| 2441 |
+
"""
|
| 2442 |
+
Returns true for each element if all cased characters in the
|
| 2443 |
+
string are uppercase and there is at least one character, false
|
| 2444 |
+
otherwise.
|
| 2445 |
+
|
| 2446 |
+
See Also
|
| 2447 |
+
--------
|
| 2448 |
+
char.isupper
|
| 2449 |
+
|
| 2450 |
+
"""
|
| 2451 |
+
return isupper(self)
|
| 2452 |
+
|
| 2453 |
+
def join(self, seq):
|
| 2454 |
+
"""
|
| 2455 |
+
Return a string which is the concatenation of the strings in the
|
| 2456 |
+
sequence `seq`.
|
| 2457 |
+
|
| 2458 |
+
See Also
|
| 2459 |
+
--------
|
| 2460 |
+
char.join
|
| 2461 |
+
|
| 2462 |
+
"""
|
| 2463 |
+
return join(self, seq)
|
| 2464 |
+
|
| 2465 |
+
def ljust(self, width, fillchar=' '):
|
| 2466 |
+
"""
|
| 2467 |
+
Return an array with the elements of `self` left-justified in a
|
| 2468 |
+
string of length `width`.
|
| 2469 |
+
|
| 2470 |
+
See Also
|
| 2471 |
+
--------
|
| 2472 |
+
char.ljust
|
| 2473 |
+
|
| 2474 |
+
"""
|
| 2475 |
+
return asarray(ljust(self, width, fillchar))
|
| 2476 |
+
|
| 2477 |
+
def lower(self):
|
| 2478 |
+
"""
|
| 2479 |
+
Return an array with the elements of `self` converted to
|
| 2480 |
+
lowercase.
|
| 2481 |
+
|
| 2482 |
+
See Also
|
| 2483 |
+
--------
|
| 2484 |
+
char.lower
|
| 2485 |
+
|
| 2486 |
+
"""
|
| 2487 |
+
return asarray(lower(self))
|
| 2488 |
+
|
| 2489 |
+
def lstrip(self, chars=None):
|
| 2490 |
+
"""
|
| 2491 |
+
For each element in `self`, return a copy with the leading characters
|
| 2492 |
+
removed.
|
| 2493 |
+
|
| 2494 |
+
See Also
|
| 2495 |
+
--------
|
| 2496 |
+
char.lstrip
|
| 2497 |
+
|
| 2498 |
+
"""
|
| 2499 |
+
return asarray(lstrip(self, chars))
|
| 2500 |
+
|
| 2501 |
+
def partition(self, sep):
|
| 2502 |
+
"""
|
| 2503 |
+
Partition each element in `self` around `sep`.
|
| 2504 |
+
|
| 2505 |
+
See Also
|
| 2506 |
+
--------
|
| 2507 |
+
partition
|
| 2508 |
+
"""
|
| 2509 |
+
return asarray(partition(self, sep))
|
| 2510 |
+
|
| 2511 |
+
def replace(self, old, new, count=None):
|
| 2512 |
+
"""
|
| 2513 |
+
For each element in `self`, return a copy of the string with all
|
| 2514 |
+
occurrences of substring `old` replaced by `new`.
|
| 2515 |
+
|
| 2516 |
+
See Also
|
| 2517 |
+
--------
|
| 2518 |
+
char.replace
|
| 2519 |
+
|
| 2520 |
+
"""
|
| 2521 |
+
return asarray(replace(self, old, new, count))
|
| 2522 |
+
|
| 2523 |
+
def rfind(self, sub, start=0, end=None):
|
| 2524 |
+
"""
|
| 2525 |
+
For each element in `self`, return the highest index in the string
|
| 2526 |
+
where substring `sub` is found, such that `sub` is contained
|
| 2527 |
+
within [`start`, `end`].
|
| 2528 |
+
|
| 2529 |
+
See Also
|
| 2530 |
+
--------
|
| 2531 |
+
char.rfind
|
| 2532 |
+
|
| 2533 |
+
"""
|
| 2534 |
+
return rfind(self, sub, start, end)
|
| 2535 |
+
|
| 2536 |
+
def rindex(self, sub, start=0, end=None):
|
| 2537 |
+
"""
|
| 2538 |
+
Like `rfind`, but raises `ValueError` when the substring `sub` is
|
| 2539 |
+
not found.
|
| 2540 |
+
|
| 2541 |
+
See Also
|
| 2542 |
+
--------
|
| 2543 |
+
char.rindex
|
| 2544 |
+
|
| 2545 |
+
"""
|
| 2546 |
+
return rindex(self, sub, start, end)
|
| 2547 |
+
|
| 2548 |
+
def rjust(self, width, fillchar=' '):
|
| 2549 |
+
"""
|
| 2550 |
+
Return an array with the elements of `self`
|
| 2551 |
+
right-justified in a string of length `width`.
|
| 2552 |
+
|
| 2553 |
+
See Also
|
| 2554 |
+
--------
|
| 2555 |
+
char.rjust
|
| 2556 |
+
|
| 2557 |
+
"""
|
| 2558 |
+
return asarray(rjust(self, width, fillchar))
|
| 2559 |
+
|
| 2560 |
+
def rpartition(self, sep):
|
| 2561 |
+
"""
|
| 2562 |
+
Partition each element in `self` around `sep`.
|
| 2563 |
+
|
| 2564 |
+
See Also
|
| 2565 |
+
--------
|
| 2566 |
+
rpartition
|
| 2567 |
+
"""
|
| 2568 |
+
return asarray(rpartition(self, sep))
|
| 2569 |
+
|
| 2570 |
+
def rsplit(self, sep=None, maxsplit=None):
|
| 2571 |
+
"""
|
| 2572 |
+
For each element in `self`, return a list of the words in
|
| 2573 |
+
the string, using `sep` as the delimiter string.
|
| 2574 |
+
|
| 2575 |
+
See Also
|
| 2576 |
+
--------
|
| 2577 |
+
char.rsplit
|
| 2578 |
+
|
| 2579 |
+
"""
|
| 2580 |
+
return rsplit(self, sep, maxsplit)
|
| 2581 |
+
|
| 2582 |
+
def rstrip(self, chars=None):
|
| 2583 |
+
"""
|
| 2584 |
+
For each element in `self`, return a copy with the trailing
|
| 2585 |
+
characters removed.
|
| 2586 |
+
|
| 2587 |
+
See Also
|
| 2588 |
+
--------
|
| 2589 |
+
char.rstrip
|
| 2590 |
+
|
| 2591 |
+
"""
|
| 2592 |
+
return asarray(rstrip(self, chars))
|
| 2593 |
+
|
| 2594 |
+
def split(self, sep=None, maxsplit=None):
|
| 2595 |
+
"""
|
| 2596 |
+
For each element in `self`, return a list of the words in the
|
| 2597 |
+
string, using `sep` as the delimiter string.
|
| 2598 |
+
|
| 2599 |
+
See Also
|
| 2600 |
+
--------
|
| 2601 |
+
char.split
|
| 2602 |
+
|
| 2603 |
+
"""
|
| 2604 |
+
return split(self, sep, maxsplit)
|
| 2605 |
+
|
| 2606 |
+
def splitlines(self, keepends=None):
|
| 2607 |
+
"""
|
| 2608 |
+
For each element in `self`, return a list of the lines in the
|
| 2609 |
+
element, breaking at line boundaries.
|
| 2610 |
+
|
| 2611 |
+
See Also
|
| 2612 |
+
--------
|
| 2613 |
+
char.splitlines
|
| 2614 |
+
|
| 2615 |
+
"""
|
| 2616 |
+
return splitlines(self, keepends)
|
| 2617 |
+
|
| 2618 |
+
def startswith(self, prefix, start=0, end=None):
|
| 2619 |
+
"""
|
| 2620 |
+
Returns a boolean array which is `True` where the string element
|
| 2621 |
+
in `self` starts with `prefix`, otherwise `False`.
|
| 2622 |
+
|
| 2623 |
+
See Also
|
| 2624 |
+
--------
|
| 2625 |
+
char.startswith
|
| 2626 |
+
|
| 2627 |
+
"""
|
| 2628 |
+
return startswith(self, prefix, start, end)
|
| 2629 |
+
|
| 2630 |
+
def strip(self, chars=None):
|
| 2631 |
+
"""
|
| 2632 |
+
For each element in `self`, return a copy with the leading and
|
| 2633 |
+
trailing characters removed.
|
| 2634 |
+
|
| 2635 |
+
See Also
|
| 2636 |
+
--------
|
| 2637 |
+
char.strip
|
| 2638 |
+
|
| 2639 |
+
"""
|
| 2640 |
+
return asarray(strip(self, chars))
|
| 2641 |
+
|
| 2642 |
+
def swapcase(self):
|
| 2643 |
+
"""
|
| 2644 |
+
For each element in `self`, return a copy of the string with
|
| 2645 |
+
uppercase characters converted to lowercase and vice versa.
|
| 2646 |
+
|
| 2647 |
+
See Also
|
| 2648 |
+
--------
|
| 2649 |
+
char.swapcase
|
| 2650 |
+
|
| 2651 |
+
"""
|
| 2652 |
+
return asarray(swapcase(self))
|
| 2653 |
+
|
| 2654 |
+
def title(self):
|
| 2655 |
+
"""
|
| 2656 |
+
For each element in `self`, return a titlecased version of the
|
| 2657 |
+
string: words start with uppercase characters, all remaining cased
|
| 2658 |
+
characters are lowercase.
|
| 2659 |
+
|
| 2660 |
+
See Also
|
| 2661 |
+
--------
|
| 2662 |
+
char.title
|
| 2663 |
+
|
| 2664 |
+
"""
|
| 2665 |
+
return asarray(title(self))
|
| 2666 |
+
|
| 2667 |
+
def translate(self, table, deletechars=None):
|
| 2668 |
+
"""
|
| 2669 |
+
For each element in `self`, return a copy of the string where
|
| 2670 |
+
all characters occurring in the optional argument
|
| 2671 |
+
`deletechars` are removed, and the remaining characters have
|
| 2672 |
+
been mapped through the given translation table.
|
| 2673 |
+
|
| 2674 |
+
See Also
|
| 2675 |
+
--------
|
| 2676 |
+
char.translate
|
| 2677 |
+
|
| 2678 |
+
"""
|
| 2679 |
+
return asarray(translate(self, table, deletechars))
|
| 2680 |
+
|
| 2681 |
+
def upper(self):
|
| 2682 |
+
"""
|
| 2683 |
+
Return an array with the elements of `self` converted to
|
| 2684 |
+
uppercase.
|
| 2685 |
+
|
| 2686 |
+
See Also
|
| 2687 |
+
--------
|
| 2688 |
+
char.upper
|
| 2689 |
+
|
| 2690 |
+
"""
|
| 2691 |
+
return asarray(upper(self))
|
| 2692 |
+
|
| 2693 |
+
def zfill(self, width):
|
| 2694 |
+
"""
|
| 2695 |
+
Return the numeric string left-filled with zeros in a string of
|
| 2696 |
+
length `width`.
|
| 2697 |
+
|
| 2698 |
+
See Also
|
| 2699 |
+
--------
|
| 2700 |
+
char.zfill
|
| 2701 |
+
|
| 2702 |
+
"""
|
| 2703 |
+
return asarray(zfill(self, width))
|
| 2704 |
+
|
| 2705 |
+
def isnumeric(self):
|
| 2706 |
+
"""
|
| 2707 |
+
For each element in `self`, return True if there are only
|
| 2708 |
+
numeric characters in the element.
|
| 2709 |
+
|
| 2710 |
+
See Also
|
| 2711 |
+
--------
|
| 2712 |
+
char.isnumeric
|
| 2713 |
+
|
| 2714 |
+
"""
|
| 2715 |
+
return isnumeric(self)
|
| 2716 |
+
|
| 2717 |
+
def isdecimal(self):
|
| 2718 |
+
"""
|
| 2719 |
+
For each element in `self`, return True if there are only
|
| 2720 |
+
decimal characters in the element.
|
| 2721 |
+
|
| 2722 |
+
See Also
|
| 2723 |
+
--------
|
| 2724 |
+
char.isdecimal
|
| 2725 |
+
|
| 2726 |
+
"""
|
| 2727 |
+
return isdecimal(self)
|
| 2728 |
+
|
| 2729 |
+
|
| 2730 |
+
@set_module("numpy.char")
|
| 2731 |
+
def array(obj, itemsize=None, copy=True, unicode=None, order=None):
|
| 2732 |
+
"""
|
| 2733 |
+
Create a `chararray`.
|
| 2734 |
+
|
| 2735 |
+
.. note::
|
| 2736 |
+
This class is provided for numarray backward-compatibility.
|
| 2737 |
+
New code (not concerned with numarray compatibility) should use
|
| 2738 |
+
arrays of type `bytes_` or `str_` and use the free functions
|
| 2739 |
+
in :mod:`numpy.char <numpy.core.defchararray>` for fast
|
| 2740 |
+
vectorized string operations instead.
|
| 2741 |
+
|
| 2742 |
+
Versus a regular NumPy array of type `str` or `unicode`, this
|
| 2743 |
+
class adds the following functionality:
|
| 2744 |
+
|
| 2745 |
+
1) values automatically have whitespace removed from the end
|
| 2746 |
+
when indexed
|
| 2747 |
+
|
| 2748 |
+
2) comparison operators automatically remove whitespace from the
|
| 2749 |
+
end when comparing values
|
| 2750 |
+
|
| 2751 |
+
3) vectorized string operations are provided as methods
|
| 2752 |
+
(e.g. `str.endswith`) and infix operators (e.g. ``+, *, %``)
|
| 2753 |
+
|
| 2754 |
+
Parameters
|
| 2755 |
+
----------
|
| 2756 |
+
obj : array of str or unicode-like
|
| 2757 |
+
|
| 2758 |
+
itemsize : int, optional
|
| 2759 |
+
`itemsize` is the number of characters per scalar in the
|
| 2760 |
+
resulting array. If `itemsize` is None, and `obj` is an
|
| 2761 |
+
object array or a Python list, the `itemsize` will be
|
| 2762 |
+
automatically determined. If `itemsize` is provided and `obj`
|
| 2763 |
+
is of type str or unicode, then the `obj` string will be
|
| 2764 |
+
chunked into `itemsize` pieces.
|
| 2765 |
+
|
| 2766 |
+
copy : bool, optional
|
| 2767 |
+
If true (default), then the object is copied. Otherwise, a copy
|
| 2768 |
+
will only be made if __array__ returns a copy, if obj is a
|
| 2769 |
+
nested sequence, or if a copy is needed to satisfy any of the other
|
| 2770 |
+
requirements (`itemsize`, unicode, `order`, etc.).
|
| 2771 |
+
|
| 2772 |
+
unicode : bool, optional
|
| 2773 |
+
When true, the resulting `chararray` can contain Unicode
|
| 2774 |
+
characters, when false only 8-bit characters. If unicode is
|
| 2775 |
+
None and `obj` is one of the following:
|
| 2776 |
+
|
| 2777 |
+
- a `chararray`,
|
| 2778 |
+
- an ndarray of type `str` or `unicode`
|
| 2779 |
+
- a Python str or unicode object,
|
| 2780 |
+
|
| 2781 |
+
then the unicode setting of the output array will be
|
| 2782 |
+
automatically determined.
|
| 2783 |
+
|
| 2784 |
+
order : {'C', 'F', 'A'}, optional
|
| 2785 |
+
Specify the order of the array. If order is 'C' (default), then the
|
| 2786 |
+
array will be in C-contiguous order (last-index varies the
|
| 2787 |
+
fastest). If order is 'F', then the returned array
|
| 2788 |
+
will be in Fortran-contiguous order (first-index varies the
|
| 2789 |
+
fastest). If order is 'A', then the returned array may
|
| 2790 |
+
be in any order (either C-, Fortran-contiguous, or even
|
| 2791 |
+
discontiguous).
|
| 2792 |
+
"""
|
| 2793 |
+
if isinstance(obj, (bytes, str)):
|
| 2794 |
+
if unicode is None:
|
| 2795 |
+
if isinstance(obj, str):
|
| 2796 |
+
unicode = True
|
| 2797 |
+
else:
|
| 2798 |
+
unicode = False
|
| 2799 |
+
|
| 2800 |
+
if itemsize is None:
|
| 2801 |
+
itemsize = len(obj)
|
| 2802 |
+
shape = len(obj) // itemsize
|
| 2803 |
+
|
| 2804 |
+
return chararray(shape, itemsize=itemsize, unicode=unicode,
|
| 2805 |
+
buffer=obj, order=order)
|
| 2806 |
+
|
| 2807 |
+
if isinstance(obj, (list, tuple)):
|
| 2808 |
+
obj = numpy.asarray(obj)
|
| 2809 |
+
|
| 2810 |
+
if isinstance(obj, ndarray) and issubclass(obj.dtype.type, character):
|
| 2811 |
+
# If we just have a vanilla chararray, create a chararray
|
| 2812 |
+
# view around it.
|
| 2813 |
+
if not isinstance(obj, chararray):
|
| 2814 |
+
obj = obj.view(chararray)
|
| 2815 |
+
|
| 2816 |
+
if itemsize is None:
|
| 2817 |
+
itemsize = obj.itemsize
|
| 2818 |
+
# itemsize is in 8-bit chars, so for Unicode, we need
|
| 2819 |
+
# to divide by the size of a single Unicode character,
|
| 2820 |
+
# which for NumPy is always 4
|
| 2821 |
+
if issubclass(obj.dtype.type, str_):
|
| 2822 |
+
itemsize //= 4
|
| 2823 |
+
|
| 2824 |
+
if unicode is None:
|
| 2825 |
+
if issubclass(obj.dtype.type, str_):
|
| 2826 |
+
unicode = True
|
| 2827 |
+
else:
|
| 2828 |
+
unicode = False
|
| 2829 |
+
|
| 2830 |
+
if unicode:
|
| 2831 |
+
dtype = str_
|
| 2832 |
+
else:
|
| 2833 |
+
dtype = bytes_
|
| 2834 |
+
|
| 2835 |
+
if order is not None:
|
| 2836 |
+
obj = numpy.asarray(obj, order=order)
|
| 2837 |
+
if (copy or
|
| 2838 |
+
(itemsize != obj.itemsize) or
|
| 2839 |
+
(not unicode and isinstance(obj, str_)) or
|
| 2840 |
+
(unicode and isinstance(obj, bytes_))):
|
| 2841 |
+
obj = obj.astype((dtype, int(itemsize)))
|
| 2842 |
+
return obj
|
| 2843 |
+
|
| 2844 |
+
if isinstance(obj, ndarray) and issubclass(obj.dtype.type, object):
|
| 2845 |
+
if itemsize is None:
|
| 2846 |
+
# Since no itemsize was specified, convert the input array to
|
| 2847 |
+
# a list so the ndarray constructor will automatically
|
| 2848 |
+
# determine the itemsize for us.
|
| 2849 |
+
obj = obj.tolist()
|
| 2850 |
+
# Fall through to the default case
|
| 2851 |
+
|
| 2852 |
+
if unicode:
|
| 2853 |
+
dtype = str_
|
| 2854 |
+
else:
|
| 2855 |
+
dtype = bytes_
|
| 2856 |
+
|
| 2857 |
+
if itemsize is None:
|
| 2858 |
+
val = narray(obj, dtype=dtype, order=order, subok=True)
|
| 2859 |
+
else:
|
| 2860 |
+
val = narray(obj, dtype=(dtype, itemsize), order=order, subok=True)
|
| 2861 |
+
return val.view(chararray)
|
| 2862 |
+
|
| 2863 |
+
|
| 2864 |
+
@set_module("numpy.char")
|
| 2865 |
+
def asarray(obj, itemsize=None, unicode=None, order=None):
|
| 2866 |
+
"""
|
| 2867 |
+
Convert the input to a `chararray`, copying the data only if
|
| 2868 |
+
necessary.
|
| 2869 |
+
|
| 2870 |
+
Versus a regular NumPy array of type `str` or `unicode`, this
|
| 2871 |
+
class adds the following functionality:
|
| 2872 |
+
|
| 2873 |
+
1) values automatically have whitespace removed from the end
|
| 2874 |
+
when indexed
|
| 2875 |
+
|
| 2876 |
+
2) comparison operators automatically remove whitespace from the
|
| 2877 |
+
end when comparing values
|
| 2878 |
+
|
| 2879 |
+
3) vectorized string operations are provided as methods
|
| 2880 |
+
(e.g. `str.endswith`) and infix operators (e.g. ``+``, ``*``,``%``)
|
| 2881 |
+
|
| 2882 |
+
Parameters
|
| 2883 |
+
----------
|
| 2884 |
+
obj : array of str or unicode-like
|
| 2885 |
+
|
| 2886 |
+
itemsize : int, optional
|
| 2887 |
+
`itemsize` is the number of characters per scalar in the
|
| 2888 |
+
resulting array. If `itemsize` is None, and `obj` is an
|
| 2889 |
+
object array or a Python list, the `itemsize` will be
|
| 2890 |
+
automatically determined. If `itemsize` is provided and `obj`
|
| 2891 |
+
is of type str or unicode, then the `obj` string will be
|
| 2892 |
+
chunked into `itemsize` pieces.
|
| 2893 |
+
|
| 2894 |
+
unicode : bool, optional
|
| 2895 |
+
When true, the resulting `chararray` can contain Unicode
|
| 2896 |
+
characters, when false only 8-bit characters. If unicode is
|
| 2897 |
+
None and `obj` is one of the following:
|
| 2898 |
+
|
| 2899 |
+
- a `chararray`,
|
| 2900 |
+
- an ndarray of type `str` or 'unicode`
|
| 2901 |
+
- a Python str or unicode object,
|
| 2902 |
+
|
| 2903 |
+
then the unicode setting of the output array will be
|
| 2904 |
+
automatically determined.
|
| 2905 |
+
|
| 2906 |
+
order : {'C', 'F'}, optional
|
| 2907 |
+
Specify the order of the array. If order is 'C' (default), then the
|
| 2908 |
+
array will be in C-contiguous order (last-index varies the
|
| 2909 |
+
fastest). If order is 'F', then the returned array
|
| 2910 |
+
will be in Fortran-contiguous order (first-index varies the
|
| 2911 |
+
fastest).
|
| 2912 |
+
"""
|
| 2913 |
+
return array(obj, itemsize, copy=False,
|
| 2914 |
+
unicode=unicode, order=order)
|
.venv/lib/python3.11/site-packages/numpy/core/defchararray.pyi
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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rderKACF,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
from numpy._typing import (
|
| 20 |
+
NDArray,
|
| 21 |
+
_ArrayLikeStr_co as U_co,
|
| 22 |
+
_ArrayLikeBytes_co as S_co,
|
| 23 |
+
_ArrayLikeInt_co as i_co,
|
| 24 |
+
_ArrayLikeBool_co as b_co,
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
from numpy.core.multiarray import compare_chararrays as compare_chararrays
|
| 28 |
+
|
| 29 |
+
_SCT = TypeVar("_SCT", str_, bytes_)
|
| 30 |
+
_CharArray = chararray[Any, dtype[_SCT]]
|
| 31 |
+
|
| 32 |
+
__all__: list[str]
|
| 33 |
+
|
| 34 |
+
# Comparison
|
| 35 |
+
@overload
|
| 36 |
+
def equal(x1: U_co, x2: U_co) -> NDArray[bool_]: ...
|
| 37 |
+
@overload
|
| 38 |
+
def equal(x1: S_co, x2: S_co) -> NDArray[bool_]: ...
|
| 39 |
+
|
| 40 |
+
@overload
|
| 41 |
+
def not_equal(x1: U_co, x2: U_co) -> NDArray[bool_]: ...
|
| 42 |
+
@overload
|
| 43 |
+
def not_equal(x1: S_co, x2: S_co) -> NDArray[bool_]: ...
|
| 44 |
+
|
| 45 |
+
@overload
|
| 46 |
+
def greater_equal(x1: U_co, x2: U_co) -> NDArray[bool_]: ...
|
| 47 |
+
@overload
|
| 48 |
+
def greater_equal(x1: S_co, x2: S_co) -> NDArray[bool_]: ...
|
| 49 |
+
|
| 50 |
+
@overload
|
| 51 |
+
def less_equal(x1: U_co, x2: U_co) -> NDArray[bool_]: ...
|
| 52 |
+
@overload
|
| 53 |
+
def less_equal(x1: S_co, x2: S_co) -> NDArray[bool_]: ...
|
| 54 |
+
|
| 55 |
+
@overload
|
| 56 |
+
def greater(x1: U_co, x2: U_co) -> NDArray[bool_]: ...
|
| 57 |
+
@overload
|
| 58 |
+
def greater(x1: S_co, x2: S_co) -> NDArray[bool_]: ...
|
| 59 |
+
|
| 60 |
+
@overload
|
| 61 |
+
def less(x1: U_co, x2: U_co) -> NDArray[bool_]: ...
|
| 62 |
+
@overload
|
| 63 |
+
def less(x1: S_co, x2: S_co) -> NDArray[bool_]: ...
|
| 64 |
+
|
| 65 |
+
# String operations
|
| 66 |
+
@overload
|
| 67 |
+
def add(x1: U_co, x2: U_co) -> NDArray[str_]: ...
|
| 68 |
+
@overload
|
| 69 |
+
def add(x1: S_co, x2: S_co) -> NDArray[bytes_]: ...
|
| 70 |
+
|
| 71 |
+
@overload
|
| 72 |
+
def multiply(a: U_co, i: i_co) -> NDArray[str_]: ...
|
| 73 |
+
@overload
|
| 74 |
+
def multiply(a: S_co, i: i_co) -> NDArray[bytes_]: ...
|
| 75 |
+
|
| 76 |
+
@overload
|
| 77 |
+
def mod(a: U_co, value: Any) -> NDArray[str_]: ...
|
| 78 |
+
@overload
|
| 79 |
+
def mod(a: S_co, value: Any) -> NDArray[bytes_]: ...
|
| 80 |
+
|
| 81 |
+
@overload
|
| 82 |
+
def capitalize(a: U_co) -> NDArray[str_]: ...
|
| 83 |
+
@overload
|
| 84 |
+
def capitalize(a: S_co) -> NDArray[bytes_]: ...
|
| 85 |
+
|
| 86 |
+
@overload
|
| 87 |
+
def center(a: U_co, width: i_co, fillchar: U_co = ...) -> NDArray[str_]: ...
|
| 88 |
+
@overload
|
| 89 |
+
def center(a: S_co, width: i_co, fillchar: S_co = ...) -> NDArray[bytes_]: ...
|
| 90 |
+
|
| 91 |
+
def decode(
|
| 92 |
+
a: S_co,
|
| 93 |
+
encoding: None | str = ...,
|
| 94 |
+
errors: None | str = ...,
|
| 95 |
+
) -> NDArray[str_]: ...
|
| 96 |
+
|
| 97 |
+
def encode(
|
| 98 |
+
a: U_co,
|
| 99 |
+
encoding: None | str = ...,
|
| 100 |
+
errors: None | str = ...,
|
| 101 |
+
) -> NDArray[bytes_]: ...
|
| 102 |
+
|
| 103 |
+
@overload
|
| 104 |
+
def expandtabs(a: U_co, tabsize: i_co = ...) -> NDArray[str_]: ...
|
| 105 |
+
@overload
|
| 106 |
+
def expandtabs(a: S_co, tabsize: i_co = ...) -> NDArray[bytes_]: ...
|
| 107 |
+
|
| 108 |
+
@overload
|
| 109 |
+
def join(sep: U_co, seq: U_co) -> NDArray[str_]: ...
|
| 110 |
+
@overload
|
| 111 |
+
def join(sep: S_co, seq: S_co) -> NDArray[bytes_]: ...
|
| 112 |
+
|
| 113 |
+
@overload
|
| 114 |
+
def ljust(a: U_co, width: i_co, fillchar: U_co = ...) -> NDArray[str_]: ...
|
| 115 |
+
@overload
|
| 116 |
+
def ljust(a: S_co, width: i_co, fillchar: S_co = ...) -> NDArray[bytes_]: ...
|
| 117 |
+
|
| 118 |
+
@overload
|
| 119 |
+
def lower(a: U_co) -> NDArray[str_]: ...
|
| 120 |
+
@overload
|
| 121 |
+
def lower(a: S_co) -> NDArray[bytes_]: ...
|
| 122 |
+
|
| 123 |
+
@overload
|
| 124 |
+
def lstrip(a: U_co, chars: None | U_co = ...) -> NDArray[str_]: ...
|
| 125 |
+
@overload
|
| 126 |
+
def lstrip(a: S_co, chars: None | S_co = ...) -> NDArray[bytes_]: ...
|
| 127 |
+
|
| 128 |
+
@overload
|
| 129 |
+
def partition(a: U_co, sep: U_co) -> NDArray[str_]: ...
|
| 130 |
+
@overload
|
| 131 |
+
def partition(a: S_co, sep: S_co) -> NDArray[bytes_]: ...
|
| 132 |
+
|
| 133 |
+
@overload
|
| 134 |
+
def replace(
|
| 135 |
+
a: U_co,
|
| 136 |
+
old: U_co,
|
| 137 |
+
new: U_co,
|
| 138 |
+
count: None | i_co = ...,
|
| 139 |
+
) -> NDArray[str_]: ...
|
| 140 |
+
@overload
|
| 141 |
+
def replace(
|
| 142 |
+
a: S_co,
|
| 143 |
+
old: S_co,
|
| 144 |
+
new: S_co,
|
| 145 |
+
count: None | i_co = ...,
|
| 146 |
+
) -> NDArray[bytes_]: ...
|
| 147 |
+
|
| 148 |
+
@overload
|
| 149 |
+
def rjust(
|
| 150 |
+
a: U_co,
|
| 151 |
+
width: i_co,
|
| 152 |
+
fillchar: U_co = ...,
|
| 153 |
+
) -> NDArray[str_]: ...
|
| 154 |
+
@overload
|
| 155 |
+
def rjust(
|
| 156 |
+
a: S_co,
|
| 157 |
+
width: i_co,
|
| 158 |
+
fillchar: S_co = ...,
|
| 159 |
+
) -> NDArray[bytes_]: ...
|
| 160 |
+
|
| 161 |
+
@overload
|
| 162 |
+
def rpartition(a: U_co, sep: U_co) -> NDArray[str_]: ...
|
| 163 |
+
@overload
|
| 164 |
+
def rpartition(a: S_co, sep: S_co) -> NDArray[bytes_]: ...
|
| 165 |
+
|
| 166 |
+
@overload
|
| 167 |
+
def rsplit(
|
| 168 |
+
a: U_co,
|
| 169 |
+
sep: None | U_co = ...,
|
| 170 |
+
maxsplit: None | i_co = ...,
|
| 171 |
+
) -> NDArray[object_]: ...
|
| 172 |
+
@overload
|
| 173 |
+
def rsplit(
|
| 174 |
+
a: S_co,
|
| 175 |
+
sep: None | S_co = ...,
|
| 176 |
+
maxsplit: None | i_co = ...,
|
| 177 |
+
) -> NDArray[object_]: ...
|
| 178 |
+
|
| 179 |
+
@overload
|
| 180 |
+
def rstrip(a: U_co, chars: None | U_co = ...) -> NDArray[str_]: ...
|
| 181 |
+
@overload
|
| 182 |
+
def rstrip(a: S_co, chars: None | S_co = ...) -> NDArray[bytes_]: ...
|
| 183 |
+
|
| 184 |
+
@overload
|
| 185 |
+
def split(
|
| 186 |
+
a: U_co,
|
| 187 |
+
sep: None | U_co = ...,
|
| 188 |
+
maxsplit: None | i_co = ...,
|
| 189 |
+
) -> NDArray[object_]: ...
|
| 190 |
+
@overload
|
| 191 |
+
def split(
|
| 192 |
+
a: S_co,
|
| 193 |
+
sep: None | S_co = ...,
|
| 194 |
+
maxsplit: None | i_co = ...,
|
| 195 |
+
) -> NDArray[object_]: ...
|
| 196 |
+
|
| 197 |
+
@overload
|
| 198 |
+
def splitlines(a: U_co, keepends: None | b_co = ...) -> NDArray[object_]: ...
|
| 199 |
+
@overload
|
| 200 |
+
def splitlines(a: S_co, keepends: None | b_co = ...) -> NDArray[object_]: ...
|
| 201 |
+
|
| 202 |
+
@overload
|
| 203 |
+
def strip(a: U_co, chars: None | U_co = ...) -> NDArray[str_]: ...
|
| 204 |
+
@overload
|
| 205 |
+
def strip(a: S_co, chars: None | S_co = ...) -> NDArray[bytes_]: ...
|
| 206 |
+
|
| 207 |
+
@overload
|
| 208 |
+
def swapcase(a: U_co) -> NDArray[str_]: ...
|
| 209 |
+
@overload
|
| 210 |
+
def swapcase(a: S_co) -> NDArray[bytes_]: ...
|
| 211 |
+
|
| 212 |
+
@overload
|
| 213 |
+
def title(a: U_co) -> NDArray[str_]: ...
|
| 214 |
+
@overload
|
| 215 |
+
def title(a: S_co) -> NDArray[bytes_]: ...
|
| 216 |
+
|
| 217 |
+
@overload
|
| 218 |
+
def translate(
|
| 219 |
+
a: U_co,
|
| 220 |
+
table: U_co,
|
| 221 |
+
deletechars: None | U_co = ...,
|
| 222 |
+
) -> NDArray[str_]: ...
|
| 223 |
+
@overload
|
| 224 |
+
def translate(
|
| 225 |
+
a: S_co,
|
| 226 |
+
table: S_co,
|
| 227 |
+
deletechars: None | S_co = ...,
|
| 228 |
+
) -> NDArray[bytes_]: ...
|
| 229 |
+
|
| 230 |
+
@overload
|
| 231 |
+
def upper(a: U_co) -> NDArray[str_]: ...
|
| 232 |
+
@overload
|
| 233 |
+
def upper(a: S_co) -> NDArray[bytes_]: ...
|
| 234 |
+
|
| 235 |
+
@overload
|
| 236 |
+
def zfill(a: U_co, width: i_co) -> NDArray[str_]: ...
|
| 237 |
+
@overload
|
| 238 |
+
def zfill(a: S_co, width: i_co) -> NDArray[bytes_]: ...
|
| 239 |
+
|
| 240 |
+
# String information
|
| 241 |
+
@overload
|
| 242 |
+
def count(
|
| 243 |
+
a: U_co,
|
| 244 |
+
sub: U_co,
|
| 245 |
+
start: i_co = ...,
|
| 246 |
+
end: None | i_co = ...,
|
| 247 |
+
) -> NDArray[int_]: ...
|
| 248 |
+
@overload
|
| 249 |
+
def count(
|
| 250 |
+
a: S_co,
|
| 251 |
+
sub: S_co,
|
| 252 |
+
start: i_co = ...,
|
| 253 |
+
end: None | i_co = ...,
|
| 254 |
+
) -> NDArray[int_]: ...
|
| 255 |
+
|
| 256 |
+
@overload
|
| 257 |
+
def endswith(
|
| 258 |
+
a: U_co,
|
| 259 |
+
suffix: U_co,
|
| 260 |
+
start: i_co = ...,
|
| 261 |
+
end: None | i_co = ...,
|
| 262 |
+
) -> NDArray[bool_]: ...
|
| 263 |
+
@overload
|
| 264 |
+
def endswith(
|
| 265 |
+
a: S_co,
|
| 266 |
+
suffix: S_co,
|
| 267 |
+
start: i_co = ...,
|
| 268 |
+
end: None | i_co = ...,
|
| 269 |
+
) -> NDArray[bool_]: ...
|
| 270 |
+
|
| 271 |
+
@overload
|
| 272 |
+
def find(
|
| 273 |
+
a: U_co,
|
| 274 |
+
sub: U_co,
|
| 275 |
+
start: i_co = ...,
|
| 276 |
+
end: None | i_co = ...,
|
| 277 |
+
) -> NDArray[int_]: ...
|
| 278 |
+
@overload
|
| 279 |
+
def find(
|
| 280 |
+
a: S_co,
|
| 281 |
+
sub: S_co,
|
| 282 |
+
start: i_co = ...,
|
| 283 |
+
end: None | i_co = ...,
|
| 284 |
+
) -> NDArray[int_]: ...
|
| 285 |
+
|
| 286 |
+
@overload
|
| 287 |
+
def index(
|
| 288 |
+
a: U_co,
|
| 289 |
+
sub: U_co,
|
| 290 |
+
start: i_co = ...,
|
| 291 |
+
end: None | i_co = ...,
|
| 292 |
+
) -> NDArray[int_]: ...
|
| 293 |
+
@overload
|
| 294 |
+
def index(
|
| 295 |
+
a: S_co,
|
| 296 |
+
sub: S_co,
|
| 297 |
+
start: i_co = ...,
|
| 298 |
+
end: None | i_co = ...,
|
| 299 |
+
) -> NDArray[int_]: ...
|
| 300 |
+
|
| 301 |
+
def isalpha(a: U_co | S_co) -> NDArray[bool_]: ...
|
| 302 |
+
def isalnum(a: U_co | S_co) -> NDArray[bool_]: ...
|
| 303 |
+
def isdecimal(a: U_co | S_co) -> NDArray[bool_]: ...
|
| 304 |
+
def isdigit(a: U_co | S_co) -> NDArray[bool_]: ...
|
| 305 |
+
def islower(a: U_co | S_co) -> NDArray[bool_]: ...
|
| 306 |
+
def isnumeric(a: U_co | S_co) -> NDArray[bool_]: ...
|
| 307 |
+
def isspace(a: U_co | S_co) -> NDArray[bool_]: ...
|
| 308 |
+
def istitle(a: U_co | S_co) -> NDArray[bool_]: ...
|
| 309 |
+
def isupper(a: U_co | S_co) -> NDArray[bool_]: ...
|
| 310 |
+
|
| 311 |
+
@overload
|
| 312 |
+
def rfind(
|
| 313 |
+
a: U_co,
|
| 314 |
+
sub: U_co,
|
| 315 |
+
start: i_co = ...,
|
| 316 |
+
end: None | i_co = ...,
|
| 317 |
+
) -> NDArray[int_]: ...
|
| 318 |
+
@overload
|
| 319 |
+
def rfind(
|
| 320 |
+
a: S_co,
|
| 321 |
+
sub: S_co,
|
| 322 |
+
start: i_co = ...,
|
| 323 |
+
end: None | i_co = ...,
|
| 324 |
+
) -> NDArray[int_]: ...
|
| 325 |
+
|
| 326 |
+
@overload
|
| 327 |
+
def rindex(
|
| 328 |
+
a: U_co,
|
| 329 |
+
sub: U_co,
|
| 330 |
+
start: i_co = ...,
|
| 331 |
+
end: None | i_co = ...,
|
| 332 |
+
) -> NDArray[int_]: ...
|
| 333 |
+
@overload
|
| 334 |
+
def rindex(
|
| 335 |
+
a: S_co,
|
| 336 |
+
sub: S_co,
|
| 337 |
+
start: i_co = ...,
|
| 338 |
+
end: None | i_co = ...,
|
| 339 |
+
) -> NDArray[int_]: ...
|
| 340 |
+
|
| 341 |
+
@overload
|
| 342 |
+
def startswith(
|
| 343 |
+
a: U_co,
|
| 344 |
+
prefix: U_co,
|
| 345 |
+
start: i_co = ...,
|
| 346 |
+
end: None | i_co = ...,
|
| 347 |
+
) -> NDArray[bool_]: ...
|
| 348 |
+
@overload
|
| 349 |
+
def startswith(
|
| 350 |
+
a: S_co,
|
| 351 |
+
prefix: S_co,
|
| 352 |
+
start: i_co = ...,
|
| 353 |
+
end: None | i_co = ...,
|
| 354 |
+
) -> NDArray[bool_]: ...
|
| 355 |
+
|
| 356 |
+
def str_len(A: U_co | S_co) -> NDArray[int_]: ...
|
| 357 |
+
|
| 358 |
+
# Overload 1 and 2: str- or bytes-based array-likes
|
| 359 |
+
# overload 3: arbitrary object with unicode=False (-> bytes_)
|
| 360 |
+
# overload 4: arbitrary object with unicode=True (-> str_)
|
| 361 |
+
@overload
|
| 362 |
+
def array(
|
| 363 |
+
obj: U_co,
|
| 364 |
+
itemsize: None | int = ...,
|
| 365 |
+
copy: bool = ...,
|
| 366 |
+
unicode: L[False] = ...,
|
| 367 |
+
order: _OrderKACF = ...,
|
| 368 |
+
) -> _CharArray[str_]: ...
|
| 369 |
+
@overload
|
| 370 |
+
def array(
|
| 371 |
+
obj: S_co,
|
| 372 |
+
itemsize: None | int = ...,
|
| 373 |
+
copy: bool = ...,
|
| 374 |
+
unicode: L[False] = ...,
|
| 375 |
+
order: _OrderKACF = ...,
|
| 376 |
+
) -> _CharArray[bytes_]: ...
|
| 377 |
+
@overload
|
| 378 |
+
def array(
|
| 379 |
+
obj: object,
|
| 380 |
+
itemsize: None | int = ...,
|
| 381 |
+
copy: bool = ...,
|
| 382 |
+
unicode: L[False] = ...,
|
| 383 |
+
order: _OrderKACF = ...,
|
| 384 |
+
) -> _CharArray[bytes_]: ...
|
| 385 |
+
@overload
|
| 386 |
+
def array(
|
| 387 |
+
obj: object,
|
| 388 |
+
itemsize: None | int = ...,
|
| 389 |
+
copy: bool = ...,
|
| 390 |
+
unicode: L[True] = ...,
|
| 391 |
+
order: _OrderKACF = ...,
|
| 392 |
+
) -> _CharArray[str_]: ...
|
| 393 |
+
|
| 394 |
+
@overload
|
| 395 |
+
def asarray(
|
| 396 |
+
obj: U_co,
|
| 397 |
+
itemsize: None | int = ...,
|
| 398 |
+
unicode: L[False] = ...,
|
| 399 |
+
order: _OrderKACF = ...,
|
| 400 |
+
) -> _CharArray[str_]: ...
|
| 401 |
+
@overload
|
| 402 |
+
def asarray(
|
| 403 |
+
obj: S_co,
|
| 404 |
+
itemsize: None | int = ...,
|
| 405 |
+
unicode: L[False] = ...,
|
| 406 |
+
order: _OrderKACF = ...,
|
| 407 |
+
) -> _CharArray[bytes_]: ...
|
| 408 |
+
@overload
|
| 409 |
+
def asarray(
|
| 410 |
+
obj: object,
|
| 411 |
+
itemsize: None | int = ...,
|
| 412 |
+
unicode: L[False] = ...,
|
| 413 |
+
order: _OrderKACF = ...,
|
| 414 |
+
) -> _CharArray[bytes_]: ...
|
| 415 |
+
@overload
|
| 416 |
+
def asarray(
|
| 417 |
+
obj: object,
|
| 418 |
+
itemsize: None | int = ...,
|
| 419 |
+
unicode: L[True] = ...,
|
| 420 |
+
order: _OrderKACF = ...,
|
| 421 |
+
) -> _CharArray[str_]: ...
|
.venv/lib/python3.11/site-packages/numpy/core/einsumfunc.py
ADDED
|
@@ -0,0 +1,1443 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
Implementation of optimized einsum.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
import itertools
|
| 6 |
+
import operator
|
| 7 |
+
|
| 8 |
+
from numpy.core.multiarray import c_einsum
|
| 9 |
+
from numpy.core.numeric import asanyarray, tensordot
|
| 10 |
+
from numpy.core.overrides import array_function_dispatch
|
| 11 |
+
|
| 12 |
+
__all__ = ['einsum', 'einsum_path']
|
| 13 |
+
|
| 14 |
+
einsum_symbols = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
| 15 |
+
einsum_symbols_set = set(einsum_symbols)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def _flop_count(idx_contraction, inner, num_terms, size_dictionary):
|
| 19 |
+
"""
|
| 20 |
+
Computes the number of FLOPS in the contraction.
|
| 21 |
+
|
| 22 |
+
Parameters
|
| 23 |
+
----------
|
| 24 |
+
idx_contraction : iterable
|
| 25 |
+
The indices involved in the contraction
|
| 26 |
+
inner : bool
|
| 27 |
+
Does this contraction require an inner product?
|
| 28 |
+
num_terms : int
|
| 29 |
+
The number of terms in a contraction
|
| 30 |
+
size_dictionary : dict
|
| 31 |
+
The size of each of the indices in idx_contraction
|
| 32 |
+
|
| 33 |
+
Returns
|
| 34 |
+
-------
|
| 35 |
+
flop_count : int
|
| 36 |
+
The total number of FLOPS required for the contraction.
|
| 37 |
+
|
| 38 |
+
Examples
|
| 39 |
+
--------
|
| 40 |
+
|
| 41 |
+
>>> _flop_count('abc', False, 1, {'a': 2, 'b':3, 'c':5})
|
| 42 |
+
30
|
| 43 |
+
|
| 44 |
+
>>> _flop_count('abc', True, 2, {'a': 2, 'b':3, 'c':5})
|
| 45 |
+
60
|
| 46 |
+
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
overall_size = _compute_size_by_dict(idx_contraction, size_dictionary)
|
| 50 |
+
op_factor = max(1, num_terms - 1)
|
| 51 |
+
if inner:
|
| 52 |
+
op_factor += 1
|
| 53 |
+
|
| 54 |
+
return overall_size * op_factor
|
| 55 |
+
|
| 56 |
+
def _compute_size_by_dict(indices, idx_dict):
|
| 57 |
+
"""
|
| 58 |
+
Computes the product of the elements in indices based on the dictionary
|
| 59 |
+
idx_dict.
|
| 60 |
+
|
| 61 |
+
Parameters
|
| 62 |
+
----------
|
| 63 |
+
indices : iterable
|
| 64 |
+
Indices to base the product on.
|
| 65 |
+
idx_dict : dictionary
|
| 66 |
+
Dictionary of index sizes
|
| 67 |
+
|
| 68 |
+
Returns
|
| 69 |
+
-------
|
| 70 |
+
ret : int
|
| 71 |
+
The resulting product.
|
| 72 |
+
|
| 73 |
+
Examples
|
| 74 |
+
--------
|
| 75 |
+
>>> _compute_size_by_dict('abbc', {'a': 2, 'b':3, 'c':5})
|
| 76 |
+
90
|
| 77 |
+
|
| 78 |
+
"""
|
| 79 |
+
ret = 1
|
| 80 |
+
for i in indices:
|
| 81 |
+
ret *= idx_dict[i]
|
| 82 |
+
return ret
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def _find_contraction(positions, input_sets, output_set):
|
| 86 |
+
"""
|
| 87 |
+
Finds the contraction for a given set of input and output sets.
|
| 88 |
+
|
| 89 |
+
Parameters
|
| 90 |
+
----------
|
| 91 |
+
positions : iterable
|
| 92 |
+
Integer positions of terms used in the contraction.
|
| 93 |
+
input_sets : list
|
| 94 |
+
List of sets that represent the lhs side of the einsum subscript
|
| 95 |
+
output_set : set
|
| 96 |
+
Set that represents the rhs side of the overall einsum subscript
|
| 97 |
+
|
| 98 |
+
Returns
|
| 99 |
+
-------
|
| 100 |
+
new_result : set
|
| 101 |
+
The indices of the resulting contraction
|
| 102 |
+
remaining : list
|
| 103 |
+
List of sets that have not been contracted, the new set is appended to
|
| 104 |
+
the end of this list
|
| 105 |
+
idx_removed : set
|
| 106 |
+
Indices removed from the entire contraction
|
| 107 |
+
idx_contraction : set
|
| 108 |
+
The indices used in the current contraction
|
| 109 |
+
|
| 110 |
+
Examples
|
| 111 |
+
--------
|
| 112 |
+
|
| 113 |
+
# A simple dot product test case
|
| 114 |
+
>>> pos = (0, 1)
|
| 115 |
+
>>> isets = [set('ab'), set('bc')]
|
| 116 |
+
>>> oset = set('ac')
|
| 117 |
+
>>> _find_contraction(pos, isets, oset)
|
| 118 |
+
({'a', 'c'}, [{'a', 'c'}], {'b'}, {'a', 'b', 'c'})
|
| 119 |
+
|
| 120 |
+
# A more complex case with additional terms in the contraction
|
| 121 |
+
>>> pos = (0, 2)
|
| 122 |
+
>>> isets = [set('abd'), set('ac'), set('bdc')]
|
| 123 |
+
>>> oset = set('ac')
|
| 124 |
+
>>> _find_contraction(pos, isets, oset)
|
| 125 |
+
({'a', 'c'}, [{'a', 'c'}, {'a', 'c'}], {'b', 'd'}, {'a', 'b', 'c', 'd'})
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
idx_contract = set()
|
| 129 |
+
idx_remain = output_set.copy()
|
| 130 |
+
remaining = []
|
| 131 |
+
for ind, value in enumerate(input_sets):
|
| 132 |
+
if ind in positions:
|
| 133 |
+
idx_contract |= value
|
| 134 |
+
else:
|
| 135 |
+
remaining.append(value)
|
| 136 |
+
idx_remain |= value
|
| 137 |
+
|
| 138 |
+
new_result = idx_remain & idx_contract
|
| 139 |
+
idx_removed = (idx_contract - new_result)
|
| 140 |
+
remaining.append(new_result)
|
| 141 |
+
|
| 142 |
+
return (new_result, remaining, idx_removed, idx_contract)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def _optimal_path(input_sets, output_set, idx_dict, memory_limit):
|
| 146 |
+
"""
|
| 147 |
+
Computes all possible pair contractions, sieves the results based
|
| 148 |
+
on ``memory_limit`` and returns the lowest cost path. This algorithm
|
| 149 |
+
scales factorial with respect to the elements in the list ``input_sets``.
|
| 150 |
+
|
| 151 |
+
Parameters
|
| 152 |
+
----------
|
| 153 |
+
input_sets : list
|
| 154 |
+
List of sets that represent the lhs side of the einsum subscript
|
| 155 |
+
output_set : set
|
| 156 |
+
Set that represents the rhs side of the overall einsum subscript
|
| 157 |
+
idx_dict : dictionary
|
| 158 |
+
Dictionary of index sizes
|
| 159 |
+
memory_limit : int
|
| 160 |
+
The maximum number of elements in a temporary array
|
| 161 |
+
|
| 162 |
+
Returns
|
| 163 |
+
-------
|
| 164 |
+
path : list
|
| 165 |
+
The optimal contraction order within the memory limit constraint.
|
| 166 |
+
|
| 167 |
+
Examples
|
| 168 |
+
--------
|
| 169 |
+
>>> isets = [set('abd'), set('ac'), set('bdc')]
|
| 170 |
+
>>> oset = set()
|
| 171 |
+
>>> idx_sizes = {'a': 1, 'b':2, 'c':3, 'd':4}
|
| 172 |
+
>>> _optimal_path(isets, oset, idx_sizes, 5000)
|
| 173 |
+
[(0, 2), (0, 1)]
|
| 174 |
+
"""
|
| 175 |
+
|
| 176 |
+
full_results = [(0, [], input_sets)]
|
| 177 |
+
for iteration in range(len(input_sets) - 1):
|
| 178 |
+
iter_results = []
|
| 179 |
+
|
| 180 |
+
# Compute all unique pairs
|
| 181 |
+
for curr in full_results:
|
| 182 |
+
cost, positions, remaining = curr
|
| 183 |
+
for con in itertools.combinations(range(len(input_sets) - iteration), 2):
|
| 184 |
+
|
| 185 |
+
# Find the contraction
|
| 186 |
+
cont = _find_contraction(con, remaining, output_set)
|
| 187 |
+
new_result, new_input_sets, idx_removed, idx_contract = cont
|
| 188 |
+
|
| 189 |
+
# Sieve the results based on memory_limit
|
| 190 |
+
new_size = _compute_size_by_dict(new_result, idx_dict)
|
| 191 |
+
if new_size > memory_limit:
|
| 192 |
+
continue
|
| 193 |
+
|
| 194 |
+
# Build (total_cost, positions, indices_remaining)
|
| 195 |
+
total_cost = cost + _flop_count(idx_contract, idx_removed, len(con), idx_dict)
|
| 196 |
+
new_pos = positions + [con]
|
| 197 |
+
iter_results.append((total_cost, new_pos, new_input_sets))
|
| 198 |
+
|
| 199 |
+
# Update combinatorial list, if we did not find anything return best
|
| 200 |
+
# path + remaining contractions
|
| 201 |
+
if iter_results:
|
| 202 |
+
full_results = iter_results
|
| 203 |
+
else:
|
| 204 |
+
path = min(full_results, key=lambda x: x[0])[1]
|
| 205 |
+
path += [tuple(range(len(input_sets) - iteration))]
|
| 206 |
+
return path
|
| 207 |
+
|
| 208 |
+
# If we have not found anything return single einsum contraction
|
| 209 |
+
if len(full_results) == 0:
|
| 210 |
+
return [tuple(range(len(input_sets)))]
|
| 211 |
+
|
| 212 |
+
path = min(full_results, key=lambda x: x[0])[1]
|
| 213 |
+
return path
|
| 214 |
+
|
| 215 |
+
def _parse_possible_contraction(positions, input_sets, output_set, idx_dict, memory_limit, path_cost, naive_cost):
|
| 216 |
+
"""Compute the cost (removed size + flops) and resultant indices for
|
| 217 |
+
performing the contraction specified by ``positions``.
|
| 218 |
+
|
| 219 |
+
Parameters
|
| 220 |
+
----------
|
| 221 |
+
positions : tuple of int
|
| 222 |
+
The locations of the proposed tensors to contract.
|
| 223 |
+
input_sets : list of sets
|
| 224 |
+
The indices found on each tensors.
|
| 225 |
+
output_set : set
|
| 226 |
+
The output indices of the expression.
|
| 227 |
+
idx_dict : dict
|
| 228 |
+
Mapping of each index to its size.
|
| 229 |
+
memory_limit : int
|
| 230 |
+
The total allowed size for an intermediary tensor.
|
| 231 |
+
path_cost : int
|
| 232 |
+
The contraction cost so far.
|
| 233 |
+
naive_cost : int
|
| 234 |
+
The cost of the unoptimized expression.
|
| 235 |
+
|
| 236 |
+
Returns
|
| 237 |
+
-------
|
| 238 |
+
cost : (int, int)
|
| 239 |
+
A tuple containing the size of any indices removed, and the flop cost.
|
| 240 |
+
positions : tuple of int
|
| 241 |
+
The locations of the proposed tensors to contract.
|
| 242 |
+
new_input_sets : list of sets
|
| 243 |
+
The resulting new list of indices if this proposed contraction is performed.
|
| 244 |
+
|
| 245 |
+
"""
|
| 246 |
+
|
| 247 |
+
# Find the contraction
|
| 248 |
+
contract = _find_contraction(positions, input_sets, output_set)
|
| 249 |
+
idx_result, new_input_sets, idx_removed, idx_contract = contract
|
| 250 |
+
|
| 251 |
+
# Sieve the results based on memory_limit
|
| 252 |
+
new_size = _compute_size_by_dict(idx_result, idx_dict)
|
| 253 |
+
if new_size > memory_limit:
|
| 254 |
+
return None
|
| 255 |
+
|
| 256 |
+
# Build sort tuple
|
| 257 |
+
old_sizes = (_compute_size_by_dict(input_sets[p], idx_dict) for p in positions)
|
| 258 |
+
removed_size = sum(old_sizes) - new_size
|
| 259 |
+
|
| 260 |
+
# NB: removed_size used to be just the size of any removed indices i.e.:
|
| 261 |
+
# helpers.compute_size_by_dict(idx_removed, idx_dict)
|
| 262 |
+
cost = _flop_count(idx_contract, idx_removed, len(positions), idx_dict)
|
| 263 |
+
sort = (-removed_size, cost)
|
| 264 |
+
|
| 265 |
+
# Sieve based on total cost as well
|
| 266 |
+
if (path_cost + cost) > naive_cost:
|
| 267 |
+
return None
|
| 268 |
+
|
| 269 |
+
# Add contraction to possible choices
|
| 270 |
+
return [sort, positions, new_input_sets]
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def _update_other_results(results, best):
|
| 274 |
+
"""Update the positions and provisional input_sets of ``results`` based on
|
| 275 |
+
performing the contraction result ``best``. Remove any involving the tensors
|
| 276 |
+
contracted.
|
| 277 |
+
|
| 278 |
+
Parameters
|
| 279 |
+
----------
|
| 280 |
+
results : list
|
| 281 |
+
List of contraction results produced by ``_parse_possible_contraction``.
|
| 282 |
+
best : list
|
| 283 |
+
The best contraction of ``results`` i.e. the one that will be performed.
|
| 284 |
+
|
| 285 |
+
Returns
|
| 286 |
+
-------
|
| 287 |
+
mod_results : list
|
| 288 |
+
The list of modified results, updated with outcome of ``best`` contraction.
|
| 289 |
+
"""
|
| 290 |
+
|
| 291 |
+
best_con = best[1]
|
| 292 |
+
bx, by = best_con
|
| 293 |
+
mod_results = []
|
| 294 |
+
|
| 295 |
+
for cost, (x, y), con_sets in results:
|
| 296 |
+
|
| 297 |
+
# Ignore results involving tensors just contracted
|
| 298 |
+
if x in best_con or y in best_con:
|
| 299 |
+
continue
|
| 300 |
+
|
| 301 |
+
# Update the input_sets
|
| 302 |
+
del con_sets[by - int(by > x) - int(by > y)]
|
| 303 |
+
del con_sets[bx - int(bx > x) - int(bx > y)]
|
| 304 |
+
con_sets.insert(-1, best[2][-1])
|
| 305 |
+
|
| 306 |
+
# Update the position indices
|
| 307 |
+
mod_con = x - int(x > bx) - int(x > by), y - int(y > bx) - int(y > by)
|
| 308 |
+
mod_results.append((cost, mod_con, con_sets))
|
| 309 |
+
|
| 310 |
+
return mod_results
|
| 311 |
+
|
| 312 |
+
def _greedy_path(input_sets, output_set, idx_dict, memory_limit):
|
| 313 |
+
"""
|
| 314 |
+
Finds the path by contracting the best pair until the input list is
|
| 315 |
+
exhausted. The best pair is found by minimizing the tuple
|
| 316 |
+
``(-prod(indices_removed), cost)``. What this amounts to is prioritizing
|
| 317 |
+
matrix multiplication or inner product operations, then Hadamard like
|
| 318 |
+
operations, and finally outer operations. Outer products are limited by
|
| 319 |
+
``memory_limit``. This algorithm scales cubically with respect to the
|
| 320 |
+
number of elements in the list ``input_sets``.
|
| 321 |
+
|
| 322 |
+
Parameters
|
| 323 |
+
----------
|
| 324 |
+
input_sets : list
|
| 325 |
+
List of sets that represent the lhs side of the einsum subscript
|
| 326 |
+
output_set : set
|
| 327 |
+
Set that represents the rhs side of the overall einsum subscript
|
| 328 |
+
idx_dict : dictionary
|
| 329 |
+
Dictionary of index sizes
|
| 330 |
+
memory_limit : int
|
| 331 |
+
The maximum number of elements in a temporary array
|
| 332 |
+
|
| 333 |
+
Returns
|
| 334 |
+
-------
|
| 335 |
+
path : list
|
| 336 |
+
The greedy contraction order within the memory limit constraint.
|
| 337 |
+
|
| 338 |
+
Examples
|
| 339 |
+
--------
|
| 340 |
+
>>> isets = [set('abd'), set('ac'), set('bdc')]
|
| 341 |
+
>>> oset = set()
|
| 342 |
+
>>> idx_sizes = {'a': 1, 'b':2, 'c':3, 'd':4}
|
| 343 |
+
>>> _greedy_path(isets, oset, idx_sizes, 5000)
|
| 344 |
+
[(0, 2), (0, 1)]
|
| 345 |
+
"""
|
| 346 |
+
|
| 347 |
+
# Handle trivial cases that leaked through
|
| 348 |
+
if len(input_sets) == 1:
|
| 349 |
+
return [(0,)]
|
| 350 |
+
elif len(input_sets) == 2:
|
| 351 |
+
return [(0, 1)]
|
| 352 |
+
|
| 353 |
+
# Build up a naive cost
|
| 354 |
+
contract = _find_contraction(range(len(input_sets)), input_sets, output_set)
|
| 355 |
+
idx_result, new_input_sets, idx_removed, idx_contract = contract
|
| 356 |
+
naive_cost = _flop_count(idx_contract, idx_removed, len(input_sets), idx_dict)
|
| 357 |
+
|
| 358 |
+
# Initially iterate over all pairs
|
| 359 |
+
comb_iter = itertools.combinations(range(len(input_sets)), 2)
|
| 360 |
+
known_contractions = []
|
| 361 |
+
|
| 362 |
+
path_cost = 0
|
| 363 |
+
path = []
|
| 364 |
+
|
| 365 |
+
for iteration in range(len(input_sets) - 1):
|
| 366 |
+
|
| 367 |
+
# Iterate over all pairs on first step, only previously found pairs on subsequent steps
|
| 368 |
+
for positions in comb_iter:
|
| 369 |
+
|
| 370 |
+
# Always initially ignore outer products
|
| 371 |
+
if input_sets[positions[0]].isdisjoint(input_sets[positions[1]]):
|
| 372 |
+
continue
|
| 373 |
+
|
| 374 |
+
result = _parse_possible_contraction(positions, input_sets, output_set, idx_dict, memory_limit, path_cost,
|
| 375 |
+
naive_cost)
|
| 376 |
+
if result is not None:
|
| 377 |
+
known_contractions.append(result)
|
| 378 |
+
|
| 379 |
+
# If we do not have a inner contraction, rescan pairs including outer products
|
| 380 |
+
if len(known_contractions) == 0:
|
| 381 |
+
|
| 382 |
+
# Then check the outer products
|
| 383 |
+
for positions in itertools.combinations(range(len(input_sets)), 2):
|
| 384 |
+
result = _parse_possible_contraction(positions, input_sets, output_set, idx_dict, memory_limit,
|
| 385 |
+
path_cost, naive_cost)
|
| 386 |
+
if result is not None:
|
| 387 |
+
known_contractions.append(result)
|
| 388 |
+
|
| 389 |
+
# If we still did not find any remaining contractions, default back to einsum like behavior
|
| 390 |
+
if len(known_contractions) == 0:
|
| 391 |
+
path.append(tuple(range(len(input_sets))))
|
| 392 |
+
break
|
| 393 |
+
|
| 394 |
+
# Sort based on first index
|
| 395 |
+
best = min(known_contractions, key=lambda x: x[0])
|
| 396 |
+
|
| 397 |
+
# Now propagate as many unused contractions as possible to next iteration
|
| 398 |
+
known_contractions = _update_other_results(known_contractions, best)
|
| 399 |
+
|
| 400 |
+
# Next iteration only compute contractions with the new tensor
|
| 401 |
+
# All other contractions have been accounted for
|
| 402 |
+
input_sets = best[2]
|
| 403 |
+
new_tensor_pos = len(input_sets) - 1
|
| 404 |
+
comb_iter = ((i, new_tensor_pos) for i in range(new_tensor_pos))
|
| 405 |
+
|
| 406 |
+
# Update path and total cost
|
| 407 |
+
path.append(best[1])
|
| 408 |
+
path_cost += best[0][1]
|
| 409 |
+
|
| 410 |
+
return path
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def _can_dot(inputs, result, idx_removed):
|
| 414 |
+
"""
|
| 415 |
+
Checks if we can use BLAS (np.tensordot) call and its beneficial to do so.
|
| 416 |
+
|
| 417 |
+
Parameters
|
| 418 |
+
----------
|
| 419 |
+
inputs : list of str
|
| 420 |
+
Specifies the subscripts for summation.
|
| 421 |
+
result : str
|
| 422 |
+
Resulting summation.
|
| 423 |
+
idx_removed : set
|
| 424 |
+
Indices that are removed in the summation
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
Returns
|
| 428 |
+
-------
|
| 429 |
+
type : bool
|
| 430 |
+
Returns true if BLAS should and can be used, else False
|
| 431 |
+
|
| 432 |
+
Notes
|
| 433 |
+
-----
|
| 434 |
+
If the operations is BLAS level 1 or 2 and is not already aligned
|
| 435 |
+
we default back to einsum as the memory movement to copy is more
|
| 436 |
+
costly than the operation itself.
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
Examples
|
| 440 |
+
--------
|
| 441 |
+
|
| 442 |
+
# Standard GEMM operation
|
| 443 |
+
>>> _can_dot(['ij', 'jk'], 'ik', set('j'))
|
| 444 |
+
True
|
| 445 |
+
|
| 446 |
+
# Can use the standard BLAS, but requires odd data movement
|
| 447 |
+
>>> _can_dot(['ijj', 'jk'], 'ik', set('j'))
|
| 448 |
+
False
|
| 449 |
+
|
| 450 |
+
# DDOT where the memory is not aligned
|
| 451 |
+
>>> _can_dot(['ijk', 'ikj'], '', set('ijk'))
|
| 452 |
+
False
|
| 453 |
+
|
| 454 |
+
"""
|
| 455 |
+
|
| 456 |
+
# All `dot` calls remove indices
|
| 457 |
+
if len(idx_removed) == 0:
|
| 458 |
+
return False
|
| 459 |
+
|
| 460 |
+
# BLAS can only handle two operands
|
| 461 |
+
if len(inputs) != 2:
|
| 462 |
+
return False
|
| 463 |
+
|
| 464 |
+
input_left, input_right = inputs
|
| 465 |
+
|
| 466 |
+
for c in set(input_left + input_right):
|
| 467 |
+
# can't deal with repeated indices on same input or more than 2 total
|
| 468 |
+
nl, nr = input_left.count(c), input_right.count(c)
|
| 469 |
+
if (nl > 1) or (nr > 1) or (nl + nr > 2):
|
| 470 |
+
return False
|
| 471 |
+
|
| 472 |
+
# can't do implicit summation or dimension collapse e.g.
|
| 473 |
+
# "ab,bc->c" (implicitly sum over 'a')
|
| 474 |
+
# "ab,ca->ca" (take diagonal of 'a')
|
| 475 |
+
if nl + nr - 1 == int(c in result):
|
| 476 |
+
return False
|
| 477 |
+
|
| 478 |
+
# Build a few temporaries
|
| 479 |
+
set_left = set(input_left)
|
| 480 |
+
set_right = set(input_right)
|
| 481 |
+
keep_left = set_left - idx_removed
|
| 482 |
+
keep_right = set_right - idx_removed
|
| 483 |
+
rs = len(idx_removed)
|
| 484 |
+
|
| 485 |
+
# At this point we are a DOT, GEMV, or GEMM operation
|
| 486 |
+
|
| 487 |
+
# Handle inner products
|
| 488 |
+
|
| 489 |
+
# DDOT with aligned data
|
| 490 |
+
if input_left == input_right:
|
| 491 |
+
return True
|
| 492 |
+
|
| 493 |
+
# DDOT without aligned data (better to use einsum)
|
| 494 |
+
if set_left == set_right:
|
| 495 |
+
return False
|
| 496 |
+
|
| 497 |
+
# Handle the 4 possible (aligned) GEMV or GEMM cases
|
| 498 |
+
|
| 499 |
+
# GEMM or GEMV no transpose
|
| 500 |
+
if input_left[-rs:] == input_right[:rs]:
|
| 501 |
+
return True
|
| 502 |
+
|
| 503 |
+
# GEMM or GEMV transpose both
|
| 504 |
+
if input_left[:rs] == input_right[-rs:]:
|
| 505 |
+
return True
|
| 506 |
+
|
| 507 |
+
# GEMM or GEMV transpose right
|
| 508 |
+
if input_left[-rs:] == input_right[-rs:]:
|
| 509 |
+
return True
|
| 510 |
+
|
| 511 |
+
# GEMM or GEMV transpose left
|
| 512 |
+
if input_left[:rs] == input_right[:rs]:
|
| 513 |
+
return True
|
| 514 |
+
|
| 515 |
+
# Einsum is faster than GEMV if we have to copy data
|
| 516 |
+
if not keep_left or not keep_right:
|
| 517 |
+
return False
|
| 518 |
+
|
| 519 |
+
# We are a matrix-matrix product, but we need to copy data
|
| 520 |
+
return True
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
def _parse_einsum_input(operands):
|
| 524 |
+
"""
|
| 525 |
+
A reproduction of einsum c side einsum parsing in python.
|
| 526 |
+
|
| 527 |
+
Returns
|
| 528 |
+
-------
|
| 529 |
+
input_strings : str
|
| 530 |
+
Parsed input strings
|
| 531 |
+
output_string : str
|
| 532 |
+
Parsed output string
|
| 533 |
+
operands : list of array_like
|
| 534 |
+
The operands to use in the numpy contraction
|
| 535 |
+
|
| 536 |
+
Examples
|
| 537 |
+
--------
|
| 538 |
+
The operand list is simplified to reduce printing:
|
| 539 |
+
|
| 540 |
+
>>> np.random.seed(123)
|
| 541 |
+
>>> a = np.random.rand(4, 4)
|
| 542 |
+
>>> b = np.random.rand(4, 4, 4)
|
| 543 |
+
>>> _parse_einsum_input(('...a,...a->...', a, b))
|
| 544 |
+
('za,xza', 'xz', [a, b]) # may vary
|
| 545 |
+
|
| 546 |
+
>>> _parse_einsum_input((a, [Ellipsis, 0], b, [Ellipsis, 0]))
|
| 547 |
+
('za,xza', 'xz', [a, b]) # may vary
|
| 548 |
+
"""
|
| 549 |
+
|
| 550 |
+
if len(operands) == 0:
|
| 551 |
+
raise ValueError("No input operands")
|
| 552 |
+
|
| 553 |
+
if isinstance(operands[0], str):
|
| 554 |
+
subscripts = operands[0].replace(" ", "")
|
| 555 |
+
operands = [asanyarray(v) for v in operands[1:]]
|
| 556 |
+
|
| 557 |
+
# Ensure all characters are valid
|
| 558 |
+
for s in subscripts:
|
| 559 |
+
if s in '.,->':
|
| 560 |
+
continue
|
| 561 |
+
if s not in einsum_symbols:
|
| 562 |
+
raise ValueError("Character %s is not a valid symbol." % s)
|
| 563 |
+
|
| 564 |
+
else:
|
| 565 |
+
tmp_operands = list(operands)
|
| 566 |
+
operand_list = []
|
| 567 |
+
subscript_list = []
|
| 568 |
+
for p in range(len(operands) // 2):
|
| 569 |
+
operand_list.append(tmp_operands.pop(0))
|
| 570 |
+
subscript_list.append(tmp_operands.pop(0))
|
| 571 |
+
|
| 572 |
+
output_list = tmp_operands[-1] if len(tmp_operands) else None
|
| 573 |
+
operands = [asanyarray(v) for v in operand_list]
|
| 574 |
+
subscripts = ""
|
| 575 |
+
last = len(subscript_list) - 1
|
| 576 |
+
for num, sub in enumerate(subscript_list):
|
| 577 |
+
for s in sub:
|
| 578 |
+
if s is Ellipsis:
|
| 579 |
+
subscripts += "..."
|
| 580 |
+
else:
|
| 581 |
+
try:
|
| 582 |
+
s = operator.index(s)
|
| 583 |
+
except TypeError as e:
|
| 584 |
+
raise TypeError("For this input type lists must contain "
|
| 585 |
+
"either int or Ellipsis") from e
|
| 586 |
+
subscripts += einsum_symbols[s]
|
| 587 |
+
if num != last:
|
| 588 |
+
subscripts += ","
|
| 589 |
+
|
| 590 |
+
if output_list is not None:
|
| 591 |
+
subscripts += "->"
|
| 592 |
+
for s in output_list:
|
| 593 |
+
if s is Ellipsis:
|
| 594 |
+
subscripts += "..."
|
| 595 |
+
else:
|
| 596 |
+
try:
|
| 597 |
+
s = operator.index(s)
|
| 598 |
+
except TypeError as e:
|
| 599 |
+
raise TypeError("For this input type lists must contain "
|
| 600 |
+
"either int or Ellipsis") from e
|
| 601 |
+
subscripts += einsum_symbols[s]
|
| 602 |
+
# Check for proper "->"
|
| 603 |
+
if ("-" in subscripts) or (">" in subscripts):
|
| 604 |
+
invalid = (subscripts.count("-") > 1) or (subscripts.count(">") > 1)
|
| 605 |
+
if invalid or (subscripts.count("->") != 1):
|
| 606 |
+
raise ValueError("Subscripts can only contain one '->'.")
|
| 607 |
+
|
| 608 |
+
# Parse ellipses
|
| 609 |
+
if "." in subscripts:
|
| 610 |
+
used = subscripts.replace(".", "").replace(",", "").replace("->", "")
|
| 611 |
+
unused = list(einsum_symbols_set - set(used))
|
| 612 |
+
ellipse_inds = "".join(unused)
|
| 613 |
+
longest = 0
|
| 614 |
+
|
| 615 |
+
if "->" in subscripts:
|
| 616 |
+
input_tmp, output_sub = subscripts.split("->")
|
| 617 |
+
split_subscripts = input_tmp.split(",")
|
| 618 |
+
out_sub = True
|
| 619 |
+
else:
|
| 620 |
+
split_subscripts = subscripts.split(',')
|
| 621 |
+
out_sub = False
|
| 622 |
+
|
| 623 |
+
for num, sub in enumerate(split_subscripts):
|
| 624 |
+
if "." in sub:
|
| 625 |
+
if (sub.count(".") != 3) or (sub.count("...") != 1):
|
| 626 |
+
raise ValueError("Invalid Ellipses.")
|
| 627 |
+
|
| 628 |
+
# Take into account numerical values
|
| 629 |
+
if operands[num].shape == ():
|
| 630 |
+
ellipse_count = 0
|
| 631 |
+
else:
|
| 632 |
+
ellipse_count = max(operands[num].ndim, 1)
|
| 633 |
+
ellipse_count -= (len(sub) - 3)
|
| 634 |
+
|
| 635 |
+
if ellipse_count > longest:
|
| 636 |
+
longest = ellipse_count
|
| 637 |
+
|
| 638 |
+
if ellipse_count < 0:
|
| 639 |
+
raise ValueError("Ellipses lengths do not match.")
|
| 640 |
+
elif ellipse_count == 0:
|
| 641 |
+
split_subscripts[num] = sub.replace('...', '')
|
| 642 |
+
else:
|
| 643 |
+
rep_inds = ellipse_inds[-ellipse_count:]
|
| 644 |
+
split_subscripts[num] = sub.replace('...', rep_inds)
|
| 645 |
+
|
| 646 |
+
subscripts = ",".join(split_subscripts)
|
| 647 |
+
if longest == 0:
|
| 648 |
+
out_ellipse = ""
|
| 649 |
+
else:
|
| 650 |
+
out_ellipse = ellipse_inds[-longest:]
|
| 651 |
+
|
| 652 |
+
if out_sub:
|
| 653 |
+
subscripts += "->" + output_sub.replace("...", out_ellipse)
|
| 654 |
+
else:
|
| 655 |
+
# Special care for outputless ellipses
|
| 656 |
+
output_subscript = ""
|
| 657 |
+
tmp_subscripts = subscripts.replace(",", "")
|
| 658 |
+
for s in sorted(set(tmp_subscripts)):
|
| 659 |
+
if s not in (einsum_symbols):
|
| 660 |
+
raise ValueError("Character %s is not a valid symbol." % s)
|
| 661 |
+
if tmp_subscripts.count(s) == 1:
|
| 662 |
+
output_subscript += s
|
| 663 |
+
normal_inds = ''.join(sorted(set(output_subscript) -
|
| 664 |
+
set(out_ellipse)))
|
| 665 |
+
|
| 666 |
+
subscripts += "->" + out_ellipse + normal_inds
|
| 667 |
+
|
| 668 |
+
# Build output string if does not exist
|
| 669 |
+
if "->" in subscripts:
|
| 670 |
+
input_subscripts, output_subscript = subscripts.split("->")
|
| 671 |
+
else:
|
| 672 |
+
input_subscripts = subscripts
|
| 673 |
+
# Build output subscripts
|
| 674 |
+
tmp_subscripts = subscripts.replace(",", "")
|
| 675 |
+
output_subscript = ""
|
| 676 |
+
for s in sorted(set(tmp_subscripts)):
|
| 677 |
+
if s not in einsum_symbols:
|
| 678 |
+
raise ValueError("Character %s is not a valid symbol." % s)
|
| 679 |
+
if tmp_subscripts.count(s) == 1:
|
| 680 |
+
output_subscript += s
|
| 681 |
+
|
| 682 |
+
# Make sure output subscripts are in the input
|
| 683 |
+
for char in output_subscript:
|
| 684 |
+
if char not in input_subscripts:
|
| 685 |
+
raise ValueError("Output character %s did not appear in the input"
|
| 686 |
+
% char)
|
| 687 |
+
|
| 688 |
+
# Make sure number operands is equivalent to the number of terms
|
| 689 |
+
if len(input_subscripts.split(',')) != len(operands):
|
| 690 |
+
raise ValueError("Number of einsum subscripts must be equal to the "
|
| 691 |
+
"number of operands.")
|
| 692 |
+
|
| 693 |
+
return (input_subscripts, output_subscript, operands)
|
| 694 |
+
|
| 695 |
+
|
| 696 |
+
def _einsum_path_dispatcher(*operands, optimize=None, einsum_call=None):
|
| 697 |
+
# NOTE: technically, we should only dispatch on array-like arguments, not
|
| 698 |
+
# subscripts (given as strings). But separating operands into
|
| 699 |
+
# arrays/subscripts is a little tricky/slow (given einsum's two supported
|
| 700 |
+
# signatures), so as a practical shortcut we dispatch on everything.
|
| 701 |
+
# Strings will be ignored for dispatching since they don't define
|
| 702 |
+
# __array_function__.
|
| 703 |
+
return operands
|
| 704 |
+
|
| 705 |
+
|
| 706 |
+
@array_function_dispatch(_einsum_path_dispatcher, module='numpy')
|
| 707 |
+
def einsum_path(*operands, optimize='greedy', einsum_call=False):
|
| 708 |
+
"""
|
| 709 |
+
einsum_path(subscripts, *operands, optimize='greedy')
|
| 710 |
+
|
| 711 |
+
Evaluates the lowest cost contraction order for an einsum expression by
|
| 712 |
+
considering the creation of intermediate arrays.
|
| 713 |
+
|
| 714 |
+
Parameters
|
| 715 |
+
----------
|
| 716 |
+
subscripts : str
|
| 717 |
+
Specifies the subscripts for summation.
|
| 718 |
+
*operands : list of array_like
|
| 719 |
+
These are the arrays for the operation.
|
| 720 |
+
optimize : {bool, list, tuple, 'greedy', 'optimal'}
|
| 721 |
+
Choose the type of path. If a tuple is provided, the second argument is
|
| 722 |
+
assumed to be the maximum intermediate size created. If only a single
|
| 723 |
+
argument is provided the largest input or output array size is used
|
| 724 |
+
as a maximum intermediate size.
|
| 725 |
+
|
| 726 |
+
* if a list is given that starts with ``einsum_path``, uses this as the
|
| 727 |
+
contraction path
|
| 728 |
+
* if False no optimization is taken
|
| 729 |
+
* if True defaults to the 'greedy' algorithm
|
| 730 |
+
* 'optimal' An algorithm that combinatorially explores all possible
|
| 731 |
+
ways of contracting the listed tensors and chooses the least costly
|
| 732 |
+
path. Scales exponentially with the number of terms in the
|
| 733 |
+
contraction.
|
| 734 |
+
* 'greedy' An algorithm that chooses the best pair contraction
|
| 735 |
+
at each step. Effectively, this algorithm searches the largest inner,
|
| 736 |
+
Hadamard, and then outer products at each step. Scales cubically with
|
| 737 |
+
the number of terms in the contraction. Equivalent to the 'optimal'
|
| 738 |
+
path for most contractions.
|
| 739 |
+
|
| 740 |
+
Default is 'greedy'.
|
| 741 |
+
|
| 742 |
+
Returns
|
| 743 |
+
-------
|
| 744 |
+
path : list of tuples
|
| 745 |
+
A list representation of the einsum path.
|
| 746 |
+
string_repr : str
|
| 747 |
+
A printable representation of the einsum path.
|
| 748 |
+
|
| 749 |
+
Notes
|
| 750 |
+
-----
|
| 751 |
+
The resulting path indicates which terms of the input contraction should be
|
| 752 |
+
contracted first, the result of this contraction is then appended to the
|
| 753 |
+
end of the contraction list. This list can then be iterated over until all
|
| 754 |
+
intermediate contractions are complete.
|
| 755 |
+
|
| 756 |
+
See Also
|
| 757 |
+
--------
|
| 758 |
+
einsum, linalg.multi_dot
|
| 759 |
+
|
| 760 |
+
Examples
|
| 761 |
+
--------
|
| 762 |
+
|
| 763 |
+
We can begin with a chain dot example. In this case, it is optimal to
|
| 764 |
+
contract the ``b`` and ``c`` tensors first as represented by the first
|
| 765 |
+
element of the path ``(1, 2)``. The resulting tensor is added to the end
|
| 766 |
+
of the contraction and the remaining contraction ``(0, 1)`` is then
|
| 767 |
+
completed.
|
| 768 |
+
|
| 769 |
+
>>> np.random.seed(123)
|
| 770 |
+
>>> a = np.random.rand(2, 2)
|
| 771 |
+
>>> b = np.random.rand(2, 5)
|
| 772 |
+
>>> c = np.random.rand(5, 2)
|
| 773 |
+
>>> path_info = np.einsum_path('ij,jk,kl->il', a, b, c, optimize='greedy')
|
| 774 |
+
>>> print(path_info[0])
|
| 775 |
+
['einsum_path', (1, 2), (0, 1)]
|
| 776 |
+
>>> print(path_info[1])
|
| 777 |
+
Complete contraction: ij,jk,kl->il # may vary
|
| 778 |
+
Naive scaling: 4
|
| 779 |
+
Optimized scaling: 3
|
| 780 |
+
Naive FLOP count: 1.600e+02
|
| 781 |
+
Optimized FLOP count: 5.600e+01
|
| 782 |
+
Theoretical speedup: 2.857
|
| 783 |
+
Largest intermediate: 4.000e+00 elements
|
| 784 |
+
-------------------------------------------------------------------------
|
| 785 |
+
scaling current remaining
|
| 786 |
+
-------------------------------------------------------------------------
|
| 787 |
+
3 kl,jk->jl ij,jl->il
|
| 788 |
+
3 jl,ij->il il->il
|
| 789 |
+
|
| 790 |
+
|
| 791 |
+
A more complex index transformation example.
|
| 792 |
+
|
| 793 |
+
>>> I = np.random.rand(10, 10, 10, 10)
|
| 794 |
+
>>> C = np.random.rand(10, 10)
|
| 795 |
+
>>> path_info = np.einsum_path('ea,fb,abcd,gc,hd->efgh', C, C, I, C, C,
|
| 796 |
+
... optimize='greedy')
|
| 797 |
+
|
| 798 |
+
>>> print(path_info[0])
|
| 799 |
+
['einsum_path', (0, 2), (0, 3), (0, 2), (0, 1)]
|
| 800 |
+
>>> print(path_info[1])
|
| 801 |
+
Complete contraction: ea,fb,abcd,gc,hd->efgh # may vary
|
| 802 |
+
Naive scaling: 8
|
| 803 |
+
Optimized scaling: 5
|
| 804 |
+
Naive FLOP count: 8.000e+08
|
| 805 |
+
Optimized FLOP count: 8.000e+05
|
| 806 |
+
Theoretical speedup: 1000.000
|
| 807 |
+
Largest intermediate: 1.000e+04 elements
|
| 808 |
+
--------------------------------------------------------------------------
|
| 809 |
+
scaling current remaining
|
| 810 |
+
--------------------------------------------------------------------------
|
| 811 |
+
5 abcd,ea->bcde fb,gc,hd,bcde->efgh
|
| 812 |
+
5 bcde,fb->cdef gc,hd,cdef->efgh
|
| 813 |
+
5 cdef,gc->defg hd,defg->efgh
|
| 814 |
+
5 defg,hd->efgh efgh->efgh
|
| 815 |
+
"""
|
| 816 |
+
|
| 817 |
+
# Figure out what the path really is
|
| 818 |
+
path_type = optimize
|
| 819 |
+
if path_type is True:
|
| 820 |
+
path_type = 'greedy'
|
| 821 |
+
if path_type is None:
|
| 822 |
+
path_type = False
|
| 823 |
+
|
| 824 |
+
explicit_einsum_path = False
|
| 825 |
+
memory_limit = None
|
| 826 |
+
|
| 827 |
+
# No optimization or a named path algorithm
|
| 828 |
+
if (path_type is False) or isinstance(path_type, str):
|
| 829 |
+
pass
|
| 830 |
+
|
| 831 |
+
# Given an explicit path
|
| 832 |
+
elif len(path_type) and (path_type[0] == 'einsum_path'):
|
| 833 |
+
explicit_einsum_path = True
|
| 834 |
+
|
| 835 |
+
# Path tuple with memory limit
|
| 836 |
+
elif ((len(path_type) == 2) and isinstance(path_type[0], str) and
|
| 837 |
+
isinstance(path_type[1], (int, float))):
|
| 838 |
+
memory_limit = int(path_type[1])
|
| 839 |
+
path_type = path_type[0]
|
| 840 |
+
|
| 841 |
+
else:
|
| 842 |
+
raise TypeError("Did not understand the path: %s" % str(path_type))
|
| 843 |
+
|
| 844 |
+
# Hidden option, only einsum should call this
|
| 845 |
+
einsum_call_arg = einsum_call
|
| 846 |
+
|
| 847 |
+
# Python side parsing
|
| 848 |
+
input_subscripts, output_subscript, operands = _parse_einsum_input(operands)
|
| 849 |
+
|
| 850 |
+
# Build a few useful list and sets
|
| 851 |
+
input_list = input_subscripts.split(',')
|
| 852 |
+
input_sets = [set(x) for x in input_list]
|
| 853 |
+
output_set = set(output_subscript)
|
| 854 |
+
indices = set(input_subscripts.replace(',', ''))
|
| 855 |
+
|
| 856 |
+
# Get length of each unique dimension and ensure all dimensions are correct
|
| 857 |
+
dimension_dict = {}
|
| 858 |
+
broadcast_indices = [[] for x in range(len(input_list))]
|
| 859 |
+
for tnum, term in enumerate(input_list):
|
| 860 |
+
sh = operands[tnum].shape
|
| 861 |
+
if len(sh) != len(term):
|
| 862 |
+
raise ValueError("Einstein sum subscript %s does not contain the "
|
| 863 |
+
"correct number of indices for operand %d."
|
| 864 |
+
% (input_subscripts[tnum], tnum))
|
| 865 |
+
for cnum, char in enumerate(term):
|
| 866 |
+
dim = sh[cnum]
|
| 867 |
+
|
| 868 |
+
# Build out broadcast indices
|
| 869 |
+
if dim == 1:
|
| 870 |
+
broadcast_indices[tnum].append(char)
|
| 871 |
+
|
| 872 |
+
if char in dimension_dict.keys():
|
| 873 |
+
# For broadcasting cases we always want the largest dim size
|
| 874 |
+
if dimension_dict[char] == 1:
|
| 875 |
+
dimension_dict[char] = dim
|
| 876 |
+
elif dim not in (1, dimension_dict[char]):
|
| 877 |
+
raise ValueError("Size of label '%s' for operand %d (%d) "
|
| 878 |
+
"does not match previous terms (%d)."
|
| 879 |
+
% (char, tnum, dimension_dict[char], dim))
|
| 880 |
+
else:
|
| 881 |
+
dimension_dict[char] = dim
|
| 882 |
+
|
| 883 |
+
# Convert broadcast inds to sets
|
| 884 |
+
broadcast_indices = [set(x) for x in broadcast_indices]
|
| 885 |
+
|
| 886 |
+
# Compute size of each input array plus the output array
|
| 887 |
+
size_list = [_compute_size_by_dict(term, dimension_dict)
|
| 888 |
+
for term in input_list + [output_subscript]]
|
| 889 |
+
max_size = max(size_list)
|
| 890 |
+
|
| 891 |
+
if memory_limit is None:
|
| 892 |
+
memory_arg = max_size
|
| 893 |
+
else:
|
| 894 |
+
memory_arg = memory_limit
|
| 895 |
+
|
| 896 |
+
# Compute naive cost
|
| 897 |
+
# This isn't quite right, need to look into exactly how einsum does this
|
| 898 |
+
inner_product = (sum(len(x) for x in input_sets) - len(indices)) > 0
|
| 899 |
+
naive_cost = _flop_count(indices, inner_product, len(input_list), dimension_dict)
|
| 900 |
+
|
| 901 |
+
# Compute the path
|
| 902 |
+
if explicit_einsum_path:
|
| 903 |
+
path = path_type[1:]
|
| 904 |
+
elif (
|
| 905 |
+
(path_type is False)
|
| 906 |
+
or (len(input_list) in [1, 2])
|
| 907 |
+
or (indices == output_set)
|
| 908 |
+
):
|
| 909 |
+
# Nothing to be optimized, leave it to einsum
|
| 910 |
+
path = [tuple(range(len(input_list)))]
|
| 911 |
+
elif path_type == "greedy":
|
| 912 |
+
path = _greedy_path(input_sets, output_set, dimension_dict, memory_arg)
|
| 913 |
+
elif path_type == "optimal":
|
| 914 |
+
path = _optimal_path(input_sets, output_set, dimension_dict, memory_arg)
|
| 915 |
+
else:
|
| 916 |
+
raise KeyError("Path name %s not found", path_type)
|
| 917 |
+
|
| 918 |
+
cost_list, scale_list, size_list, contraction_list = [], [], [], []
|
| 919 |
+
|
| 920 |
+
# Build contraction tuple (positions, gemm, einsum_str, remaining)
|
| 921 |
+
for cnum, contract_inds in enumerate(path):
|
| 922 |
+
# Make sure we remove inds from right to left
|
| 923 |
+
contract_inds = tuple(sorted(list(contract_inds), reverse=True))
|
| 924 |
+
|
| 925 |
+
contract = _find_contraction(contract_inds, input_sets, output_set)
|
| 926 |
+
out_inds, input_sets, idx_removed, idx_contract = contract
|
| 927 |
+
|
| 928 |
+
cost = _flop_count(idx_contract, idx_removed, len(contract_inds), dimension_dict)
|
| 929 |
+
cost_list.append(cost)
|
| 930 |
+
scale_list.append(len(idx_contract))
|
| 931 |
+
size_list.append(_compute_size_by_dict(out_inds, dimension_dict))
|
| 932 |
+
|
| 933 |
+
bcast = set()
|
| 934 |
+
tmp_inputs = []
|
| 935 |
+
for x in contract_inds:
|
| 936 |
+
tmp_inputs.append(input_list.pop(x))
|
| 937 |
+
bcast |= broadcast_indices.pop(x)
|
| 938 |
+
|
| 939 |
+
new_bcast_inds = bcast - idx_removed
|
| 940 |
+
|
| 941 |
+
# If we're broadcasting, nix blas
|
| 942 |
+
if not len(idx_removed & bcast):
|
| 943 |
+
do_blas = _can_dot(tmp_inputs, out_inds, idx_removed)
|
| 944 |
+
else:
|
| 945 |
+
do_blas = False
|
| 946 |
+
|
| 947 |
+
# Last contraction
|
| 948 |
+
if (cnum - len(path)) == -1:
|
| 949 |
+
idx_result = output_subscript
|
| 950 |
+
else:
|
| 951 |
+
sort_result = [(dimension_dict[ind], ind) for ind in out_inds]
|
| 952 |
+
idx_result = "".join([x[1] for x in sorted(sort_result)])
|
| 953 |
+
|
| 954 |
+
input_list.append(idx_result)
|
| 955 |
+
broadcast_indices.append(new_bcast_inds)
|
| 956 |
+
einsum_str = ",".join(tmp_inputs) + "->" + idx_result
|
| 957 |
+
|
| 958 |
+
contraction = (contract_inds, idx_removed, einsum_str, input_list[:], do_blas)
|
| 959 |
+
contraction_list.append(contraction)
|
| 960 |
+
|
| 961 |
+
opt_cost = sum(cost_list) + 1
|
| 962 |
+
|
| 963 |
+
if len(input_list) != 1:
|
| 964 |
+
# Explicit "einsum_path" is usually trusted, but we detect this kind of
|
| 965 |
+
# mistake in order to prevent from returning an intermediate value.
|
| 966 |
+
raise RuntimeError(
|
| 967 |
+
"Invalid einsum_path is specified: {} more operands has to be "
|
| 968 |
+
"contracted.".format(len(input_list) - 1))
|
| 969 |
+
|
| 970 |
+
if einsum_call_arg:
|
| 971 |
+
return (operands, contraction_list)
|
| 972 |
+
|
| 973 |
+
# Return the path along with a nice string representation
|
| 974 |
+
overall_contraction = input_subscripts + "->" + output_subscript
|
| 975 |
+
header = ("scaling", "current", "remaining")
|
| 976 |
+
|
| 977 |
+
speedup = naive_cost / opt_cost
|
| 978 |
+
max_i = max(size_list)
|
| 979 |
+
|
| 980 |
+
path_print = " Complete contraction: %s\n" % overall_contraction
|
| 981 |
+
path_print += " Naive scaling: %d\n" % len(indices)
|
| 982 |
+
path_print += " Optimized scaling: %d\n" % max(scale_list)
|
| 983 |
+
path_print += " Naive FLOP count: %.3e\n" % naive_cost
|
| 984 |
+
path_print += " Optimized FLOP count: %.3e\n" % opt_cost
|
| 985 |
+
path_print += " Theoretical speedup: %3.3f\n" % speedup
|
| 986 |
+
path_print += " Largest intermediate: %.3e elements\n" % max_i
|
| 987 |
+
path_print += "-" * 74 + "\n"
|
| 988 |
+
path_print += "%6s %24s %40s\n" % header
|
| 989 |
+
path_print += "-" * 74
|
| 990 |
+
|
| 991 |
+
for n, contraction in enumerate(contraction_list):
|
| 992 |
+
inds, idx_rm, einsum_str, remaining, blas = contraction
|
| 993 |
+
remaining_str = ",".join(remaining) + "->" + output_subscript
|
| 994 |
+
path_run = (scale_list[n], einsum_str, remaining_str)
|
| 995 |
+
path_print += "\n%4d %24s %40s" % path_run
|
| 996 |
+
|
| 997 |
+
path = ['einsum_path'] + path
|
| 998 |
+
return (path, path_print)
|
| 999 |
+
|
| 1000 |
+
|
| 1001 |
+
def _einsum_dispatcher(*operands, out=None, optimize=None, **kwargs):
|
| 1002 |
+
# Arguably we dispatch on more arguments than we really should; see note in
|
| 1003 |
+
# _einsum_path_dispatcher for why.
|
| 1004 |
+
yield from operands
|
| 1005 |
+
yield out
|
| 1006 |
+
|
| 1007 |
+
|
| 1008 |
+
# Rewrite einsum to handle different cases
|
| 1009 |
+
@array_function_dispatch(_einsum_dispatcher, module='numpy')
|
| 1010 |
+
def einsum(*operands, out=None, optimize=False, **kwargs):
|
| 1011 |
+
"""
|
| 1012 |
+
einsum(subscripts, *operands, out=None, dtype=None, order='K',
|
| 1013 |
+
casting='safe', optimize=False)
|
| 1014 |
+
|
| 1015 |
+
Evaluates the Einstein summation convention on the operands.
|
| 1016 |
+
|
| 1017 |
+
Using the Einstein summation convention, many common multi-dimensional,
|
| 1018 |
+
linear algebraic array operations can be represented in a simple fashion.
|
| 1019 |
+
In *implicit* mode `einsum` computes these values.
|
| 1020 |
+
|
| 1021 |
+
In *explicit* mode, `einsum` provides further flexibility to compute
|
| 1022 |
+
other array operations that might not be considered classical Einstein
|
| 1023 |
+
summation operations, by disabling, or forcing summation over specified
|
| 1024 |
+
subscript labels.
|
| 1025 |
+
|
| 1026 |
+
See the notes and examples for clarification.
|
| 1027 |
+
|
| 1028 |
+
Parameters
|
| 1029 |
+
----------
|
| 1030 |
+
subscripts : str
|
| 1031 |
+
Specifies the subscripts for summation as comma separated list of
|
| 1032 |
+
subscript labels. An implicit (classical Einstein summation)
|
| 1033 |
+
calculation is performed unless the explicit indicator '->' is
|
| 1034 |
+
included as well as subscript labels of the precise output form.
|
| 1035 |
+
operands : list of array_like
|
| 1036 |
+
These are the arrays for the operation.
|
| 1037 |
+
out : ndarray, optional
|
| 1038 |
+
If provided, the calculation is done into this array.
|
| 1039 |
+
dtype : {data-type, None}, optional
|
| 1040 |
+
If provided, forces the calculation to use the data type specified.
|
| 1041 |
+
Note that you may have to also give a more liberal `casting`
|
| 1042 |
+
parameter to allow the conversions. Default is None.
|
| 1043 |
+
order : {'C', 'F', 'A', 'K'}, optional
|
| 1044 |
+
Controls the memory layout of the output. 'C' means it should
|
| 1045 |
+
be C contiguous. 'F' means it should be Fortran contiguous,
|
| 1046 |
+
'A' means it should be 'F' if the inputs are all 'F', 'C' otherwise.
|
| 1047 |
+
'K' means it should be as close to the layout as the inputs as
|
| 1048 |
+
is possible, including arbitrarily permuted axes.
|
| 1049 |
+
Default is 'K'.
|
| 1050 |
+
casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
|
| 1051 |
+
Controls what kind of data casting may occur. Setting this to
|
| 1052 |
+
'unsafe' is not recommended, as it can adversely affect accumulations.
|
| 1053 |
+
|
| 1054 |
+
* 'no' means the data types should not be cast at all.
|
| 1055 |
+
* 'equiv' means only byte-order changes are allowed.
|
| 1056 |
+
* 'safe' means only casts which can preserve values are allowed.
|
| 1057 |
+
* 'same_kind' means only safe casts or casts within a kind,
|
| 1058 |
+
like float64 to float32, are allowed.
|
| 1059 |
+
* 'unsafe' means any data conversions may be done.
|
| 1060 |
+
|
| 1061 |
+
Default is 'safe'.
|
| 1062 |
+
optimize : {False, True, 'greedy', 'optimal'}, optional
|
| 1063 |
+
Controls if intermediate optimization should occur. No optimization
|
| 1064 |
+
will occur if False and True will default to the 'greedy' algorithm.
|
| 1065 |
+
Also accepts an explicit contraction list from the ``np.einsum_path``
|
| 1066 |
+
function. See ``np.einsum_path`` for more details. Defaults to False.
|
| 1067 |
+
|
| 1068 |
+
Returns
|
| 1069 |
+
-------
|
| 1070 |
+
output : ndarray
|
| 1071 |
+
The calculation based on the Einstein summation convention.
|
| 1072 |
+
|
| 1073 |
+
See Also
|
| 1074 |
+
--------
|
| 1075 |
+
einsum_path, dot, inner, outer, tensordot, linalg.multi_dot
|
| 1076 |
+
einops :
|
| 1077 |
+
similar verbose interface is provided by
|
| 1078 |
+
`einops <https://github.com/arogozhnikov/einops>`_ package to cover
|
| 1079 |
+
additional operations: transpose, reshape/flatten, repeat/tile,
|
| 1080 |
+
squeeze/unsqueeze and reductions.
|
| 1081 |
+
opt_einsum :
|
| 1082 |
+
`opt_einsum <https://optimized-einsum.readthedocs.io/en/stable/>`_
|
| 1083 |
+
optimizes contraction order for einsum-like expressions
|
| 1084 |
+
in backend-agnostic manner.
|
| 1085 |
+
|
| 1086 |
+
Notes
|
| 1087 |
+
-----
|
| 1088 |
+
.. versionadded:: 1.6.0
|
| 1089 |
+
|
| 1090 |
+
The Einstein summation convention can be used to compute
|
| 1091 |
+
many multi-dimensional, linear algebraic array operations. `einsum`
|
| 1092 |
+
provides a succinct way of representing these.
|
| 1093 |
+
|
| 1094 |
+
A non-exhaustive list of these operations,
|
| 1095 |
+
which can be computed by `einsum`, is shown below along with examples:
|
| 1096 |
+
|
| 1097 |
+
* Trace of an array, :py:func:`numpy.trace`.
|
| 1098 |
+
* Return a diagonal, :py:func:`numpy.diag`.
|
| 1099 |
+
* Array axis summations, :py:func:`numpy.sum`.
|
| 1100 |
+
* Transpositions and permutations, :py:func:`numpy.transpose`.
|
| 1101 |
+
* Matrix multiplication and dot product, :py:func:`numpy.matmul` :py:func:`numpy.dot`.
|
| 1102 |
+
* Vector inner and outer products, :py:func:`numpy.inner` :py:func:`numpy.outer`.
|
| 1103 |
+
* Broadcasting, element-wise and scalar multiplication, :py:func:`numpy.multiply`.
|
| 1104 |
+
* Tensor contractions, :py:func:`numpy.tensordot`.
|
| 1105 |
+
* Chained array operations, in efficient calculation order, :py:func:`numpy.einsum_path`.
|
| 1106 |
+
|
| 1107 |
+
The subscripts string is a comma-separated list of subscript labels,
|
| 1108 |
+
where each label refers to a dimension of the corresponding operand.
|
| 1109 |
+
Whenever a label is repeated it is summed, so ``np.einsum('i,i', a, b)``
|
| 1110 |
+
is equivalent to :py:func:`np.inner(a,b) <numpy.inner>`. If a label
|
| 1111 |
+
appears only once, it is not summed, so ``np.einsum('i', a)`` produces a
|
| 1112 |
+
view of ``a`` with no changes. A further example ``np.einsum('ij,jk', a, b)``
|
| 1113 |
+
describes traditional matrix multiplication and is equivalent to
|
| 1114 |
+
:py:func:`np.matmul(a,b) <numpy.matmul>`. Repeated subscript labels in one
|
| 1115 |
+
operand take the diagonal. For example, ``np.einsum('ii', a)`` is equivalent
|
| 1116 |
+
to :py:func:`np.trace(a) <numpy.trace>`.
|
| 1117 |
+
|
| 1118 |
+
In *implicit mode*, the chosen subscripts are important
|
| 1119 |
+
since the axes of the output are reordered alphabetically. This
|
| 1120 |
+
means that ``np.einsum('ij', a)`` doesn't affect a 2D array, while
|
| 1121 |
+
``np.einsum('ji', a)`` takes its transpose. Additionally,
|
| 1122 |
+
``np.einsum('ij,jk', a, b)`` returns a matrix multiplication, while,
|
| 1123 |
+
``np.einsum('ij,jh', a, b)`` returns the transpose of the
|
| 1124 |
+
multiplication since subscript 'h' precedes subscript 'i'.
|
| 1125 |
+
|
| 1126 |
+
In *explicit mode* the output can be directly controlled by
|
| 1127 |
+
specifying output subscript labels. This requires the
|
| 1128 |
+
identifier '->' as well as the list of output subscript labels.
|
| 1129 |
+
This feature increases the flexibility of the function since
|
| 1130 |
+
summing can be disabled or forced when required. The call
|
| 1131 |
+
``np.einsum('i->', a)`` is like :py:func:`np.sum(a, axis=-1) <numpy.sum>`,
|
| 1132 |
+
and ``np.einsum('ii->i', a)`` is like :py:func:`np.diag(a) <numpy.diag>`.
|
| 1133 |
+
The difference is that `einsum` does not allow broadcasting by default.
|
| 1134 |
+
Additionally ``np.einsum('ij,jh->ih', a, b)`` directly specifies the
|
| 1135 |
+
order of the output subscript labels and therefore returns matrix
|
| 1136 |
+
multiplication, unlike the example above in implicit mode.
|
| 1137 |
+
|
| 1138 |
+
To enable and control broadcasting, use an ellipsis. Default
|
| 1139 |
+
NumPy-style broadcasting is done by adding an ellipsis
|
| 1140 |
+
to the left of each term, like ``np.einsum('...ii->...i', a)``.
|
| 1141 |
+
To take the trace along the first and last axes,
|
| 1142 |
+
you can do ``np.einsum('i...i', a)``, or to do a matrix-matrix
|
| 1143 |
+
product with the left-most indices instead of rightmost, one can do
|
| 1144 |
+
``np.einsum('ij...,jk...->ik...', a, b)``.
|
| 1145 |
+
|
| 1146 |
+
When there is only one operand, no axes are summed, and no output
|
| 1147 |
+
parameter is provided, a view into the operand is returned instead
|
| 1148 |
+
of a new array. Thus, taking the diagonal as ``np.einsum('ii->i', a)``
|
| 1149 |
+
produces a view (changed in version 1.10.0).
|
| 1150 |
+
|
| 1151 |
+
`einsum` also provides an alternative way to provide the subscripts
|
| 1152 |
+
and operands as ``einsum(op0, sublist0, op1, sublist1, ..., [sublistout])``.
|
| 1153 |
+
If the output shape is not provided in this format `einsum` will be
|
| 1154 |
+
calculated in implicit mode, otherwise it will be performed explicitly.
|
| 1155 |
+
The examples below have corresponding `einsum` calls with the two
|
| 1156 |
+
parameter methods.
|
| 1157 |
+
|
| 1158 |
+
.. versionadded:: 1.10.0
|
| 1159 |
+
|
| 1160 |
+
Views returned from einsum are now writeable whenever the input array
|
| 1161 |
+
is writeable. For example, ``np.einsum('ijk...->kji...', a)`` will now
|
| 1162 |
+
have the same effect as :py:func:`np.swapaxes(a, 0, 2) <numpy.swapaxes>`
|
| 1163 |
+
and ``np.einsum('ii->i', a)`` will return a writeable view of the diagonal
|
| 1164 |
+
of a 2D array.
|
| 1165 |
+
|
| 1166 |
+
.. versionadded:: 1.12.0
|
| 1167 |
+
|
| 1168 |
+
Added the ``optimize`` argument which will optimize the contraction order
|
| 1169 |
+
of an einsum expression. For a contraction with three or more operands this
|
| 1170 |
+
can greatly increase the computational efficiency at the cost of a larger
|
| 1171 |
+
memory footprint during computation.
|
| 1172 |
+
|
| 1173 |
+
Typically a 'greedy' algorithm is applied which empirical tests have shown
|
| 1174 |
+
returns the optimal path in the majority of cases. In some cases 'optimal'
|
| 1175 |
+
will return the superlative path through a more expensive, exhaustive search.
|
| 1176 |
+
For iterative calculations it may be advisable to calculate the optimal path
|
| 1177 |
+
once and reuse that path by supplying it as an argument. An example is given
|
| 1178 |
+
below.
|
| 1179 |
+
|
| 1180 |
+
See :py:func:`numpy.einsum_path` for more details.
|
| 1181 |
+
|
| 1182 |
+
Examples
|
| 1183 |
+
--------
|
| 1184 |
+
>>> a = np.arange(25).reshape(5,5)
|
| 1185 |
+
>>> b = np.arange(5)
|
| 1186 |
+
>>> c = np.arange(6).reshape(2,3)
|
| 1187 |
+
|
| 1188 |
+
Trace of a matrix:
|
| 1189 |
+
|
| 1190 |
+
>>> np.einsum('ii', a)
|
| 1191 |
+
60
|
| 1192 |
+
>>> np.einsum(a, [0,0])
|
| 1193 |
+
60
|
| 1194 |
+
>>> np.trace(a)
|
| 1195 |
+
60
|
| 1196 |
+
|
| 1197 |
+
Extract the diagonal (requires explicit form):
|
| 1198 |
+
|
| 1199 |
+
>>> np.einsum('ii->i', a)
|
| 1200 |
+
array([ 0, 6, 12, 18, 24])
|
| 1201 |
+
>>> np.einsum(a, [0,0], [0])
|
| 1202 |
+
array([ 0, 6, 12, 18, 24])
|
| 1203 |
+
>>> np.diag(a)
|
| 1204 |
+
array([ 0, 6, 12, 18, 24])
|
| 1205 |
+
|
| 1206 |
+
Sum over an axis (requires explicit form):
|
| 1207 |
+
|
| 1208 |
+
>>> np.einsum('ij->i', a)
|
| 1209 |
+
array([ 10, 35, 60, 85, 110])
|
| 1210 |
+
>>> np.einsum(a, [0,1], [0])
|
| 1211 |
+
array([ 10, 35, 60, 85, 110])
|
| 1212 |
+
>>> np.sum(a, axis=1)
|
| 1213 |
+
array([ 10, 35, 60, 85, 110])
|
| 1214 |
+
|
| 1215 |
+
For higher dimensional arrays summing a single axis can be done with ellipsis:
|
| 1216 |
+
|
| 1217 |
+
>>> np.einsum('...j->...', a)
|
| 1218 |
+
array([ 10, 35, 60, 85, 110])
|
| 1219 |
+
>>> np.einsum(a, [Ellipsis,1], [Ellipsis])
|
| 1220 |
+
array([ 10, 35, 60, 85, 110])
|
| 1221 |
+
|
| 1222 |
+
Compute a matrix transpose, or reorder any number of axes:
|
| 1223 |
+
|
| 1224 |
+
>>> np.einsum('ji', c)
|
| 1225 |
+
array([[0, 3],
|
| 1226 |
+
[1, 4],
|
| 1227 |
+
[2, 5]])
|
| 1228 |
+
>>> np.einsum('ij->ji', c)
|
| 1229 |
+
array([[0, 3],
|
| 1230 |
+
[1, 4],
|
| 1231 |
+
[2, 5]])
|
| 1232 |
+
>>> np.einsum(c, [1,0])
|
| 1233 |
+
array([[0, 3],
|
| 1234 |
+
[1, 4],
|
| 1235 |
+
[2, 5]])
|
| 1236 |
+
>>> np.transpose(c)
|
| 1237 |
+
array([[0, 3],
|
| 1238 |
+
[1, 4],
|
| 1239 |
+
[2, 5]])
|
| 1240 |
+
|
| 1241 |
+
Vector inner products:
|
| 1242 |
+
|
| 1243 |
+
>>> np.einsum('i,i', b, b)
|
| 1244 |
+
30
|
| 1245 |
+
>>> np.einsum(b, [0], b, [0])
|
| 1246 |
+
30
|
| 1247 |
+
>>> np.inner(b,b)
|
| 1248 |
+
30
|
| 1249 |
+
|
| 1250 |
+
Matrix vector multiplication:
|
| 1251 |
+
|
| 1252 |
+
>>> np.einsum('ij,j', a, b)
|
| 1253 |
+
array([ 30, 80, 130, 180, 230])
|
| 1254 |
+
>>> np.einsum(a, [0,1], b, [1])
|
| 1255 |
+
array([ 30, 80, 130, 180, 230])
|
| 1256 |
+
>>> np.dot(a, b)
|
| 1257 |
+
array([ 30, 80, 130, 180, 230])
|
| 1258 |
+
>>> np.einsum('...j,j', a, b)
|
| 1259 |
+
array([ 30, 80, 130, 180, 230])
|
| 1260 |
+
|
| 1261 |
+
Broadcasting and scalar multiplication:
|
| 1262 |
+
|
| 1263 |
+
>>> np.einsum('..., ...', 3, c)
|
| 1264 |
+
array([[ 0, 3, 6],
|
| 1265 |
+
[ 9, 12, 15]])
|
| 1266 |
+
>>> np.einsum(',ij', 3, c)
|
| 1267 |
+
array([[ 0, 3, 6],
|
| 1268 |
+
[ 9, 12, 15]])
|
| 1269 |
+
>>> np.einsum(3, [Ellipsis], c, [Ellipsis])
|
| 1270 |
+
array([[ 0, 3, 6],
|
| 1271 |
+
[ 9, 12, 15]])
|
| 1272 |
+
>>> np.multiply(3, c)
|
| 1273 |
+
array([[ 0, 3, 6],
|
| 1274 |
+
[ 9, 12, 15]])
|
| 1275 |
+
|
| 1276 |
+
Vector outer product:
|
| 1277 |
+
|
| 1278 |
+
>>> np.einsum('i,j', np.arange(2)+1, b)
|
| 1279 |
+
array([[0, 1, 2, 3, 4],
|
| 1280 |
+
[0, 2, 4, 6, 8]])
|
| 1281 |
+
>>> np.einsum(np.arange(2)+1, [0], b, [1])
|
| 1282 |
+
array([[0, 1, 2, 3, 4],
|
| 1283 |
+
[0, 2, 4, 6, 8]])
|
| 1284 |
+
>>> np.outer(np.arange(2)+1, b)
|
| 1285 |
+
array([[0, 1, 2, 3, 4],
|
| 1286 |
+
[0, 2, 4, 6, 8]])
|
| 1287 |
+
|
| 1288 |
+
Tensor contraction:
|
| 1289 |
+
|
| 1290 |
+
>>> a = np.arange(60.).reshape(3,4,5)
|
| 1291 |
+
>>> b = np.arange(24.).reshape(4,3,2)
|
| 1292 |
+
>>> np.einsum('ijk,jil->kl', a, b)
|
| 1293 |
+
array([[4400., 4730.],
|
| 1294 |
+
[4532., 4874.],
|
| 1295 |
+
[4664., 5018.],
|
| 1296 |
+
[4796., 5162.],
|
| 1297 |
+
[4928., 5306.]])
|
| 1298 |
+
>>> np.einsum(a, [0,1,2], b, [1,0,3], [2,3])
|
| 1299 |
+
array([[4400., 4730.],
|
| 1300 |
+
[4532., 4874.],
|
| 1301 |
+
[4664., 5018.],
|
| 1302 |
+
[4796., 5162.],
|
| 1303 |
+
[4928., 5306.]])
|
| 1304 |
+
>>> np.tensordot(a,b, axes=([1,0],[0,1]))
|
| 1305 |
+
array([[4400., 4730.],
|
| 1306 |
+
[4532., 4874.],
|
| 1307 |
+
[4664., 5018.],
|
| 1308 |
+
[4796., 5162.],
|
| 1309 |
+
[4928., 5306.]])
|
| 1310 |
+
|
| 1311 |
+
Writeable returned arrays (since version 1.10.0):
|
| 1312 |
+
|
| 1313 |
+
>>> a = np.zeros((3, 3))
|
| 1314 |
+
>>> np.einsum('ii->i', a)[:] = 1
|
| 1315 |
+
>>> a
|
| 1316 |
+
array([[1., 0., 0.],
|
| 1317 |
+
[0., 1., 0.],
|
| 1318 |
+
[0., 0., 1.]])
|
| 1319 |
+
|
| 1320 |
+
Example of ellipsis use:
|
| 1321 |
+
|
| 1322 |
+
>>> a = np.arange(6).reshape((3,2))
|
| 1323 |
+
>>> b = np.arange(12).reshape((4,3))
|
| 1324 |
+
>>> np.einsum('ki,jk->ij', a, b)
|
| 1325 |
+
array([[10, 28, 46, 64],
|
| 1326 |
+
[13, 40, 67, 94]])
|
| 1327 |
+
>>> np.einsum('ki,...k->i...', a, b)
|
| 1328 |
+
array([[10, 28, 46, 64],
|
| 1329 |
+
[13, 40, 67, 94]])
|
| 1330 |
+
>>> np.einsum('k...,jk', a, b)
|
| 1331 |
+
array([[10, 28, 46, 64],
|
| 1332 |
+
[13, 40, 67, 94]])
|
| 1333 |
+
|
| 1334 |
+
Chained array operations. For more complicated contractions, speed ups
|
| 1335 |
+
might be achieved by repeatedly computing a 'greedy' path or pre-computing the
|
| 1336 |
+
'optimal' path and repeatedly applying it, using an
|
| 1337 |
+
`einsum_path` insertion (since version 1.12.0). Performance improvements can be
|
| 1338 |
+
particularly significant with larger arrays:
|
| 1339 |
+
|
| 1340 |
+
>>> a = np.ones(64).reshape(2,4,8)
|
| 1341 |
+
|
| 1342 |
+
Basic `einsum`: ~1520ms (benchmarked on 3.1GHz Intel i5.)
|
| 1343 |
+
|
| 1344 |
+
>>> for iteration in range(500):
|
| 1345 |
+
... _ = np.einsum('ijk,ilm,njm,nlk,abc->',a,a,a,a,a)
|
| 1346 |
+
|
| 1347 |
+
Sub-optimal `einsum` (due to repeated path calculation time): ~330ms
|
| 1348 |
+
|
| 1349 |
+
>>> for iteration in range(500):
|
| 1350 |
+
... _ = np.einsum('ijk,ilm,njm,nlk,abc->',a,a,a,a,a, optimize='optimal')
|
| 1351 |
+
|
| 1352 |
+
Greedy `einsum` (faster optimal path approximation): ~160ms
|
| 1353 |
+
|
| 1354 |
+
>>> for iteration in range(500):
|
| 1355 |
+
... _ = np.einsum('ijk,ilm,njm,nlk,abc->',a,a,a,a,a, optimize='greedy')
|
| 1356 |
+
|
| 1357 |
+
Optimal `einsum` (best usage pattern in some use cases): ~110ms
|
| 1358 |
+
|
| 1359 |
+
>>> path = np.einsum_path('ijk,ilm,njm,nlk,abc->',a,a,a,a,a, optimize='optimal')[0]
|
| 1360 |
+
>>> for iteration in range(500):
|
| 1361 |
+
... _ = np.einsum('ijk,ilm,njm,nlk,abc->',a,a,a,a,a, optimize=path)
|
| 1362 |
+
|
| 1363 |
+
"""
|
| 1364 |
+
# Special handling if out is specified
|
| 1365 |
+
specified_out = out is not None
|
| 1366 |
+
|
| 1367 |
+
# If no optimization, run pure einsum
|
| 1368 |
+
if optimize is False:
|
| 1369 |
+
if specified_out:
|
| 1370 |
+
kwargs['out'] = out
|
| 1371 |
+
return c_einsum(*operands, **kwargs)
|
| 1372 |
+
|
| 1373 |
+
# Check the kwargs to avoid a more cryptic error later, without having to
|
| 1374 |
+
# repeat default values here
|
| 1375 |
+
valid_einsum_kwargs = ['dtype', 'order', 'casting']
|
| 1376 |
+
unknown_kwargs = [k for (k, v) in kwargs.items() if
|
| 1377 |
+
k not in valid_einsum_kwargs]
|
| 1378 |
+
if len(unknown_kwargs):
|
| 1379 |
+
raise TypeError("Did not understand the following kwargs: %s"
|
| 1380 |
+
% unknown_kwargs)
|
| 1381 |
+
|
| 1382 |
+
# Build the contraction list and operand
|
| 1383 |
+
operands, contraction_list = einsum_path(*operands, optimize=optimize,
|
| 1384 |
+
einsum_call=True)
|
| 1385 |
+
|
| 1386 |
+
# Handle order kwarg for output array, c_einsum allows mixed case
|
| 1387 |
+
output_order = kwargs.pop('order', 'K')
|
| 1388 |
+
if output_order.upper() == 'A':
|
| 1389 |
+
if all(arr.flags.f_contiguous for arr in operands):
|
| 1390 |
+
output_order = 'F'
|
| 1391 |
+
else:
|
| 1392 |
+
output_order = 'C'
|
| 1393 |
+
|
| 1394 |
+
# Start contraction loop
|
| 1395 |
+
for num, contraction in enumerate(contraction_list):
|
| 1396 |
+
inds, idx_rm, einsum_str, remaining, blas = contraction
|
| 1397 |
+
tmp_operands = [operands.pop(x) for x in inds]
|
| 1398 |
+
|
| 1399 |
+
# Do we need to deal with the output?
|
| 1400 |
+
handle_out = specified_out and ((num + 1) == len(contraction_list))
|
| 1401 |
+
|
| 1402 |
+
# Call tensordot if still possible
|
| 1403 |
+
if blas:
|
| 1404 |
+
# Checks have already been handled
|
| 1405 |
+
input_str, results_index = einsum_str.split('->')
|
| 1406 |
+
input_left, input_right = input_str.split(',')
|
| 1407 |
+
|
| 1408 |
+
tensor_result = input_left + input_right
|
| 1409 |
+
for s in idx_rm:
|
| 1410 |
+
tensor_result = tensor_result.replace(s, "")
|
| 1411 |
+
|
| 1412 |
+
# Find indices to contract over
|
| 1413 |
+
left_pos, right_pos = [], []
|
| 1414 |
+
for s in sorted(idx_rm):
|
| 1415 |
+
left_pos.append(input_left.find(s))
|
| 1416 |
+
right_pos.append(input_right.find(s))
|
| 1417 |
+
|
| 1418 |
+
# Contract!
|
| 1419 |
+
new_view = tensordot(*tmp_operands, axes=(tuple(left_pos), tuple(right_pos)))
|
| 1420 |
+
|
| 1421 |
+
# Build a new view if needed
|
| 1422 |
+
if (tensor_result != results_index) or handle_out:
|
| 1423 |
+
if handle_out:
|
| 1424 |
+
kwargs["out"] = out
|
| 1425 |
+
new_view = c_einsum(tensor_result + '->' + results_index, new_view, **kwargs)
|
| 1426 |
+
|
| 1427 |
+
# Call einsum
|
| 1428 |
+
else:
|
| 1429 |
+
# If out was specified
|
| 1430 |
+
if handle_out:
|
| 1431 |
+
kwargs["out"] = out
|
| 1432 |
+
|
| 1433 |
+
# Do the contraction
|
| 1434 |
+
new_view = c_einsum(einsum_str, *tmp_operands, **kwargs)
|
| 1435 |
+
|
| 1436 |
+
# Append new items and dereference what we can
|
| 1437 |
+
operands.append(new_view)
|
| 1438 |
+
del tmp_operands, new_view
|
| 1439 |
+
|
| 1440 |
+
if specified_out:
|
| 1441 |
+
return out
|
| 1442 |
+
else:
|
| 1443 |
+
return asanyarray(operands[0], order=output_order)
|
.venv/lib/python3.11/site-packages/numpy/core/einsumfunc.pyi
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Sequence
|
| 2 |
+
from typing import TypeVar, Any, overload, Union, Literal
|
| 3 |
+
|
| 4 |
+
from numpy import (
|
| 5 |
+
ndarray,
|
| 6 |
+
dtype,
|
| 7 |
+
bool_,
|
| 8 |
+
number,
|
| 9 |
+
_OrderKACF,
|
| 10 |
+
)
|
| 11 |
+
from numpy._typing import (
|
| 12 |
+
_ArrayLikeBool_co,
|
| 13 |
+
_ArrayLikeUInt_co,
|
| 14 |
+
_ArrayLikeInt_co,
|
| 15 |
+
_ArrayLikeFloat_co,
|
| 16 |
+
_ArrayLikeComplex_co,
|
| 17 |
+
_ArrayLikeObject_co,
|
| 18 |
+
_DTypeLikeBool,
|
| 19 |
+
_DTypeLikeUInt,
|
| 20 |
+
_DTypeLikeInt,
|
| 21 |
+
_DTypeLikeFloat,
|
| 22 |
+
_DTypeLikeComplex,
|
| 23 |
+
_DTypeLikeComplex_co,
|
| 24 |
+
_DTypeLikeObject,
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
_ArrayType = TypeVar(
|
| 28 |
+
"_ArrayType",
|
| 29 |
+
bound=ndarray[Any, dtype[Union[bool_, number[Any]]]],
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
_OptimizeKind = None | bool | Literal["greedy", "optimal"] | Sequence[Any]
|
| 33 |
+
_CastingSafe = Literal["no", "equiv", "safe", "same_kind"]
|
| 34 |
+
_CastingUnsafe = Literal["unsafe"]
|
| 35 |
+
|
| 36 |
+
__all__: list[str]
|
| 37 |
+
|
| 38 |
+
# TODO: Properly handle the `casting`-based combinatorics
|
| 39 |
+
# TODO: We need to evaluate the content `__subscripts` in order
|
| 40 |
+
# to identify whether or an array or scalar is returned. At a cursory
|
| 41 |
+
# glance this seems like something that can quite easily be done with
|
| 42 |
+
# a mypy plugin.
|
| 43 |
+
# Something like `is_scalar = bool(__subscripts.partition("->")[-1])`
|
| 44 |
+
@overload
|
| 45 |
+
def einsum(
|
| 46 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 47 |
+
/,
|
| 48 |
+
*operands: _ArrayLikeBool_co,
|
| 49 |
+
out: None = ...,
|
| 50 |
+
dtype: None | _DTypeLikeBool = ...,
|
| 51 |
+
order: _OrderKACF = ...,
|
| 52 |
+
casting: _CastingSafe = ...,
|
| 53 |
+
optimize: _OptimizeKind = ...,
|
| 54 |
+
) -> Any: ...
|
| 55 |
+
@overload
|
| 56 |
+
def einsum(
|
| 57 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 58 |
+
/,
|
| 59 |
+
*operands: _ArrayLikeUInt_co,
|
| 60 |
+
out: None = ...,
|
| 61 |
+
dtype: None | _DTypeLikeUInt = ...,
|
| 62 |
+
order: _OrderKACF = ...,
|
| 63 |
+
casting: _CastingSafe = ...,
|
| 64 |
+
optimize: _OptimizeKind = ...,
|
| 65 |
+
) -> Any: ...
|
| 66 |
+
@overload
|
| 67 |
+
def einsum(
|
| 68 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 69 |
+
/,
|
| 70 |
+
*operands: _ArrayLikeInt_co,
|
| 71 |
+
out: None = ...,
|
| 72 |
+
dtype: None | _DTypeLikeInt = ...,
|
| 73 |
+
order: _OrderKACF = ...,
|
| 74 |
+
casting: _CastingSafe = ...,
|
| 75 |
+
optimize: _OptimizeKind = ...,
|
| 76 |
+
) -> Any: ...
|
| 77 |
+
@overload
|
| 78 |
+
def einsum(
|
| 79 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 80 |
+
/,
|
| 81 |
+
*operands: _ArrayLikeFloat_co,
|
| 82 |
+
out: None = ...,
|
| 83 |
+
dtype: None | _DTypeLikeFloat = ...,
|
| 84 |
+
order: _OrderKACF = ...,
|
| 85 |
+
casting: _CastingSafe = ...,
|
| 86 |
+
optimize: _OptimizeKind = ...,
|
| 87 |
+
) -> Any: ...
|
| 88 |
+
@overload
|
| 89 |
+
def einsum(
|
| 90 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 91 |
+
/,
|
| 92 |
+
*operands: _ArrayLikeComplex_co,
|
| 93 |
+
out: None = ...,
|
| 94 |
+
dtype: None | _DTypeLikeComplex = ...,
|
| 95 |
+
order: _OrderKACF = ...,
|
| 96 |
+
casting: _CastingSafe = ...,
|
| 97 |
+
optimize: _OptimizeKind = ...,
|
| 98 |
+
) -> Any: ...
|
| 99 |
+
@overload
|
| 100 |
+
def einsum(
|
| 101 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 102 |
+
/,
|
| 103 |
+
*operands: Any,
|
| 104 |
+
casting: _CastingUnsafe,
|
| 105 |
+
dtype: None | _DTypeLikeComplex_co = ...,
|
| 106 |
+
out: None = ...,
|
| 107 |
+
order: _OrderKACF = ...,
|
| 108 |
+
optimize: _OptimizeKind = ...,
|
| 109 |
+
) -> Any: ...
|
| 110 |
+
@overload
|
| 111 |
+
def einsum(
|
| 112 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 113 |
+
/,
|
| 114 |
+
*operands: _ArrayLikeComplex_co,
|
| 115 |
+
out: _ArrayType,
|
| 116 |
+
dtype: None | _DTypeLikeComplex_co = ...,
|
| 117 |
+
order: _OrderKACF = ...,
|
| 118 |
+
casting: _CastingSafe = ...,
|
| 119 |
+
optimize: _OptimizeKind = ...,
|
| 120 |
+
) -> _ArrayType: ...
|
| 121 |
+
@overload
|
| 122 |
+
def einsum(
|
| 123 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 124 |
+
/,
|
| 125 |
+
*operands: Any,
|
| 126 |
+
out: _ArrayType,
|
| 127 |
+
casting: _CastingUnsafe,
|
| 128 |
+
dtype: None | _DTypeLikeComplex_co = ...,
|
| 129 |
+
order: _OrderKACF = ...,
|
| 130 |
+
optimize: _OptimizeKind = ...,
|
| 131 |
+
) -> _ArrayType: ...
|
| 132 |
+
|
| 133 |
+
@overload
|
| 134 |
+
def einsum(
|
| 135 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 136 |
+
/,
|
| 137 |
+
*operands: _ArrayLikeObject_co,
|
| 138 |
+
out: None = ...,
|
| 139 |
+
dtype: None | _DTypeLikeObject = ...,
|
| 140 |
+
order: _OrderKACF = ...,
|
| 141 |
+
casting: _CastingSafe = ...,
|
| 142 |
+
optimize: _OptimizeKind = ...,
|
| 143 |
+
) -> Any: ...
|
| 144 |
+
@overload
|
| 145 |
+
def einsum(
|
| 146 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 147 |
+
/,
|
| 148 |
+
*operands: Any,
|
| 149 |
+
casting: _CastingUnsafe,
|
| 150 |
+
dtype: None | _DTypeLikeObject = ...,
|
| 151 |
+
out: None = ...,
|
| 152 |
+
order: _OrderKACF = ...,
|
| 153 |
+
optimize: _OptimizeKind = ...,
|
| 154 |
+
) -> Any: ...
|
| 155 |
+
@overload
|
| 156 |
+
def einsum(
|
| 157 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 158 |
+
/,
|
| 159 |
+
*operands: _ArrayLikeObject_co,
|
| 160 |
+
out: _ArrayType,
|
| 161 |
+
dtype: None | _DTypeLikeObject = ...,
|
| 162 |
+
order: _OrderKACF = ...,
|
| 163 |
+
casting: _CastingSafe = ...,
|
| 164 |
+
optimize: _OptimizeKind = ...,
|
| 165 |
+
) -> _ArrayType: ...
|
| 166 |
+
@overload
|
| 167 |
+
def einsum(
|
| 168 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 169 |
+
/,
|
| 170 |
+
*operands: Any,
|
| 171 |
+
out: _ArrayType,
|
| 172 |
+
casting: _CastingUnsafe,
|
| 173 |
+
dtype: None | _DTypeLikeObject = ...,
|
| 174 |
+
order: _OrderKACF = ...,
|
| 175 |
+
optimize: _OptimizeKind = ...,
|
| 176 |
+
) -> _ArrayType: ...
|
| 177 |
+
|
| 178 |
+
# NOTE: `einsum_call` is a hidden kwarg unavailable for public use.
|
| 179 |
+
# It is therefore excluded from the signatures below.
|
| 180 |
+
# NOTE: In practice the list consists of a `str` (first element)
|
| 181 |
+
# and a variable number of integer tuples.
|
| 182 |
+
def einsum_path(
|
| 183 |
+
subscripts: str | _ArrayLikeInt_co,
|
| 184 |
+
/,
|
| 185 |
+
*operands: _ArrayLikeComplex_co | _DTypeLikeObject,
|
| 186 |
+
optimize: _OptimizeKind = ...,
|
| 187 |
+
) -> tuple[list[Any], str]: ...
|
.venv/lib/python3.11/site-packages/numpy/core/fromnumeric.pyi
ADDED
|
@@ -0,0 +1,1060 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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1 |
+
import datetime as dt
|
| 2 |
+
from collections.abc import Sequence
|
| 3 |
+
from typing import Union, Any, overload, TypeVar, Literal, SupportsIndex
|
| 4 |
+
|
| 5 |
+
from numpy import (
|
| 6 |
+
ndarray,
|
| 7 |
+
number,
|
| 8 |
+
uint64,
|
| 9 |
+
int_,
|
| 10 |
+
int64,
|
| 11 |
+
intp,
|
| 12 |
+
float16,
|
| 13 |
+
bool_,
|
| 14 |
+
floating,
|
| 15 |
+
complexfloating,
|
| 16 |
+
object_,
|
| 17 |
+
generic,
|
| 18 |
+
_OrderKACF,
|
| 19 |
+
_OrderACF,
|
| 20 |
+
_ModeKind,
|
| 21 |
+
_PartitionKind,
|
| 22 |
+
_SortKind,
|
| 23 |
+
_SortSide,
|
| 24 |
+
_CastingKind,
|
| 25 |
+
)
|
| 26 |
+
from numpy._typing import (
|
| 27 |
+
DTypeLike,
|
| 28 |
+
_DTypeLike,
|
| 29 |
+
ArrayLike,
|
| 30 |
+
_ArrayLike,
|
| 31 |
+
NDArray,
|
| 32 |
+
_ShapeLike,
|
| 33 |
+
_Shape,
|
| 34 |
+
_ArrayLikeBool_co,
|
| 35 |
+
_ArrayLikeUInt_co,
|
| 36 |
+
_ArrayLikeInt_co,
|
| 37 |
+
_ArrayLikeFloat_co,
|
| 38 |
+
_ArrayLikeComplex_co,
|
| 39 |
+
_ArrayLikeObject_co,
|
| 40 |
+
_IntLike_co,
|
| 41 |
+
_BoolLike_co,
|
| 42 |
+
_ComplexLike_co,
|
| 43 |
+
_NumberLike_co,
|
| 44 |
+
_ScalarLike_co,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
_SCT = TypeVar("_SCT", bound=generic)
|
| 48 |
+
_SCT_uifcO = TypeVar("_SCT_uifcO", bound=number[Any] | object_)
|
| 49 |
+
_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
|
| 50 |
+
|
| 51 |
+
__all__: list[str]
|
| 52 |
+
|
| 53 |
+
@overload
|
| 54 |
+
def take(
|
| 55 |
+
a: _ArrayLike[_SCT],
|
| 56 |
+
indices: _IntLike_co,
|
| 57 |
+
axis: None = ...,
|
| 58 |
+
out: None = ...,
|
| 59 |
+
mode: _ModeKind = ...,
|
| 60 |
+
) -> _SCT: ...
|
| 61 |
+
@overload
|
| 62 |
+
def take(
|
| 63 |
+
a: ArrayLike,
|
| 64 |
+
indices: _IntLike_co,
|
| 65 |
+
axis: None | SupportsIndex = ...,
|
| 66 |
+
out: None = ...,
|
| 67 |
+
mode: _ModeKind = ...,
|
| 68 |
+
) -> Any: ...
|
| 69 |
+
@overload
|
| 70 |
+
def take(
|
| 71 |
+
a: _ArrayLike[_SCT],
|
| 72 |
+
indices: _ArrayLikeInt_co,
|
| 73 |
+
axis: None | SupportsIndex = ...,
|
| 74 |
+
out: None = ...,
|
| 75 |
+
mode: _ModeKind = ...,
|
| 76 |
+
) -> NDArray[_SCT]: ...
|
| 77 |
+
@overload
|
| 78 |
+
def take(
|
| 79 |
+
a: ArrayLike,
|
| 80 |
+
indices: _ArrayLikeInt_co,
|
| 81 |
+
axis: None | SupportsIndex = ...,
|
| 82 |
+
out: None = ...,
|
| 83 |
+
mode: _ModeKind = ...,
|
| 84 |
+
) -> NDArray[Any]: ...
|
| 85 |
+
@overload
|
| 86 |
+
def take(
|
| 87 |
+
a: ArrayLike,
|
| 88 |
+
indices: _ArrayLikeInt_co,
|
| 89 |
+
axis: None | SupportsIndex = ...,
|
| 90 |
+
out: _ArrayType = ...,
|
| 91 |
+
mode: _ModeKind = ...,
|
| 92 |
+
) -> _ArrayType: ...
|
| 93 |
+
|
| 94 |
+
@overload
|
| 95 |
+
def reshape(
|
| 96 |
+
a: _ArrayLike[_SCT],
|
| 97 |
+
newshape: _ShapeLike,
|
| 98 |
+
order: _OrderACF = ...,
|
| 99 |
+
) -> NDArray[_SCT]: ...
|
| 100 |
+
@overload
|
| 101 |
+
def reshape(
|
| 102 |
+
a: ArrayLike,
|
| 103 |
+
newshape: _ShapeLike,
|
| 104 |
+
order: _OrderACF = ...,
|
| 105 |
+
) -> NDArray[Any]: ...
|
| 106 |
+
|
| 107 |
+
@overload
|
| 108 |
+
def choose(
|
| 109 |
+
a: _IntLike_co,
|
| 110 |
+
choices: ArrayLike,
|
| 111 |
+
out: None = ...,
|
| 112 |
+
mode: _ModeKind = ...,
|
| 113 |
+
) -> Any: ...
|
| 114 |
+
@overload
|
| 115 |
+
def choose(
|
| 116 |
+
a: _ArrayLikeInt_co,
|
| 117 |
+
choices: _ArrayLike[_SCT],
|
| 118 |
+
out: None = ...,
|
| 119 |
+
mode: _ModeKind = ...,
|
| 120 |
+
) -> NDArray[_SCT]: ...
|
| 121 |
+
@overload
|
| 122 |
+
def choose(
|
| 123 |
+
a: _ArrayLikeInt_co,
|
| 124 |
+
choices: ArrayLike,
|
| 125 |
+
out: None = ...,
|
| 126 |
+
mode: _ModeKind = ...,
|
| 127 |
+
) -> NDArray[Any]: ...
|
| 128 |
+
@overload
|
| 129 |
+
def choose(
|
| 130 |
+
a: _ArrayLikeInt_co,
|
| 131 |
+
choices: ArrayLike,
|
| 132 |
+
out: _ArrayType = ...,
|
| 133 |
+
mode: _ModeKind = ...,
|
| 134 |
+
) -> _ArrayType: ...
|
| 135 |
+
|
| 136 |
+
@overload
|
| 137 |
+
def repeat(
|
| 138 |
+
a: _ArrayLike[_SCT],
|
| 139 |
+
repeats: _ArrayLikeInt_co,
|
| 140 |
+
axis: None | SupportsIndex = ...,
|
| 141 |
+
) -> NDArray[_SCT]: ...
|
| 142 |
+
@overload
|
| 143 |
+
def repeat(
|
| 144 |
+
a: ArrayLike,
|
| 145 |
+
repeats: _ArrayLikeInt_co,
|
| 146 |
+
axis: None | SupportsIndex = ...,
|
| 147 |
+
) -> NDArray[Any]: ...
|
| 148 |
+
|
| 149 |
+
def put(
|
| 150 |
+
a: NDArray[Any],
|
| 151 |
+
ind: _ArrayLikeInt_co,
|
| 152 |
+
v: ArrayLike,
|
| 153 |
+
mode: _ModeKind = ...,
|
| 154 |
+
) -> None: ...
|
| 155 |
+
|
| 156 |
+
@overload
|
| 157 |
+
def swapaxes(
|
| 158 |
+
a: _ArrayLike[_SCT],
|
| 159 |
+
axis1: SupportsIndex,
|
| 160 |
+
axis2: SupportsIndex,
|
| 161 |
+
) -> NDArray[_SCT]: ...
|
| 162 |
+
@overload
|
| 163 |
+
def swapaxes(
|
| 164 |
+
a: ArrayLike,
|
| 165 |
+
axis1: SupportsIndex,
|
| 166 |
+
axis2: SupportsIndex,
|
| 167 |
+
) -> NDArray[Any]: ...
|
| 168 |
+
|
| 169 |
+
@overload
|
| 170 |
+
def transpose(
|
| 171 |
+
a: _ArrayLike[_SCT],
|
| 172 |
+
axes: None | _ShapeLike = ...
|
| 173 |
+
) -> NDArray[_SCT]: ...
|
| 174 |
+
@overload
|
| 175 |
+
def transpose(
|
| 176 |
+
a: ArrayLike,
|
| 177 |
+
axes: None | _ShapeLike = ...
|
| 178 |
+
) -> NDArray[Any]: ...
|
| 179 |
+
|
| 180 |
+
@overload
|
| 181 |
+
def partition(
|
| 182 |
+
a: _ArrayLike[_SCT],
|
| 183 |
+
kth: _ArrayLikeInt_co,
|
| 184 |
+
axis: None | SupportsIndex = ...,
|
| 185 |
+
kind: _PartitionKind = ...,
|
| 186 |
+
order: None | str | Sequence[str] = ...,
|
| 187 |
+
) -> NDArray[_SCT]: ...
|
| 188 |
+
@overload
|
| 189 |
+
def partition(
|
| 190 |
+
a: ArrayLike,
|
| 191 |
+
kth: _ArrayLikeInt_co,
|
| 192 |
+
axis: None | SupportsIndex = ...,
|
| 193 |
+
kind: _PartitionKind = ...,
|
| 194 |
+
order: None | str | Sequence[str] = ...,
|
| 195 |
+
) -> NDArray[Any]: ...
|
| 196 |
+
|
| 197 |
+
def argpartition(
|
| 198 |
+
a: ArrayLike,
|
| 199 |
+
kth: _ArrayLikeInt_co,
|
| 200 |
+
axis: None | SupportsIndex = ...,
|
| 201 |
+
kind: _PartitionKind = ...,
|
| 202 |
+
order: None | str | Sequence[str] = ...,
|
| 203 |
+
) -> NDArray[intp]: ...
|
| 204 |
+
|
| 205 |
+
@overload
|
| 206 |
+
def sort(
|
| 207 |
+
a: _ArrayLike[_SCT],
|
| 208 |
+
axis: None | SupportsIndex = ...,
|
| 209 |
+
kind: None | _SortKind = ...,
|
| 210 |
+
order: None | str | Sequence[str] = ...,
|
| 211 |
+
) -> NDArray[_SCT]: ...
|
| 212 |
+
@overload
|
| 213 |
+
def sort(
|
| 214 |
+
a: ArrayLike,
|
| 215 |
+
axis: None | SupportsIndex = ...,
|
| 216 |
+
kind: None | _SortKind = ...,
|
| 217 |
+
order: None | str | Sequence[str] = ...,
|
| 218 |
+
) -> NDArray[Any]: ...
|
| 219 |
+
|
| 220 |
+
def argsort(
|
| 221 |
+
a: ArrayLike,
|
| 222 |
+
axis: None | SupportsIndex = ...,
|
| 223 |
+
kind: None | _SortKind = ...,
|
| 224 |
+
order: None | str | Sequence[str] = ...,
|
| 225 |
+
) -> NDArray[intp]: ...
|
| 226 |
+
|
| 227 |
+
@overload
|
| 228 |
+
def argmax(
|
| 229 |
+
a: ArrayLike,
|
| 230 |
+
axis: None = ...,
|
| 231 |
+
out: None = ...,
|
| 232 |
+
*,
|
| 233 |
+
keepdims: Literal[False] = ...,
|
| 234 |
+
) -> intp: ...
|
| 235 |
+
@overload
|
| 236 |
+
def argmax(
|
| 237 |
+
a: ArrayLike,
|
| 238 |
+
axis: None | SupportsIndex = ...,
|
| 239 |
+
out: None = ...,
|
| 240 |
+
*,
|
| 241 |
+
keepdims: bool = ...,
|
| 242 |
+
) -> Any: ...
|
| 243 |
+
@overload
|
| 244 |
+
def argmax(
|
| 245 |
+
a: ArrayLike,
|
| 246 |
+
axis: None | SupportsIndex = ...,
|
| 247 |
+
out: _ArrayType = ...,
|
| 248 |
+
*,
|
| 249 |
+
keepdims: bool = ...,
|
| 250 |
+
) -> _ArrayType: ...
|
| 251 |
+
|
| 252 |
+
@overload
|
| 253 |
+
def argmin(
|
| 254 |
+
a: ArrayLike,
|
| 255 |
+
axis: None = ...,
|
| 256 |
+
out: None = ...,
|
| 257 |
+
*,
|
| 258 |
+
keepdims: Literal[False] = ...,
|
| 259 |
+
) -> intp: ...
|
| 260 |
+
@overload
|
| 261 |
+
def argmin(
|
| 262 |
+
a: ArrayLike,
|
| 263 |
+
axis: None | SupportsIndex = ...,
|
| 264 |
+
out: None = ...,
|
| 265 |
+
*,
|
| 266 |
+
keepdims: bool = ...,
|
| 267 |
+
) -> Any: ...
|
| 268 |
+
@overload
|
| 269 |
+
def argmin(
|
| 270 |
+
a: ArrayLike,
|
| 271 |
+
axis: None | SupportsIndex = ...,
|
| 272 |
+
out: _ArrayType = ...,
|
| 273 |
+
*,
|
| 274 |
+
keepdims: bool = ...,
|
| 275 |
+
) -> _ArrayType: ...
|
| 276 |
+
|
| 277 |
+
@overload
|
| 278 |
+
def searchsorted(
|
| 279 |
+
a: ArrayLike,
|
| 280 |
+
v: _ScalarLike_co,
|
| 281 |
+
side: _SortSide = ...,
|
| 282 |
+
sorter: None | _ArrayLikeInt_co = ..., # 1D int array
|
| 283 |
+
) -> intp: ...
|
| 284 |
+
@overload
|
| 285 |
+
def searchsorted(
|
| 286 |
+
a: ArrayLike,
|
| 287 |
+
v: ArrayLike,
|
| 288 |
+
side: _SortSide = ...,
|
| 289 |
+
sorter: None | _ArrayLikeInt_co = ..., # 1D int array
|
| 290 |
+
) -> NDArray[intp]: ...
|
| 291 |
+
|
| 292 |
+
@overload
|
| 293 |
+
def resize(
|
| 294 |
+
a: _ArrayLike[_SCT],
|
| 295 |
+
new_shape: _ShapeLike,
|
| 296 |
+
) -> NDArray[_SCT]: ...
|
| 297 |
+
@overload
|
| 298 |
+
def resize(
|
| 299 |
+
a: ArrayLike,
|
| 300 |
+
new_shape: _ShapeLike,
|
| 301 |
+
) -> NDArray[Any]: ...
|
| 302 |
+
|
| 303 |
+
@overload
|
| 304 |
+
def squeeze(
|
| 305 |
+
a: _SCT,
|
| 306 |
+
axis: None | _ShapeLike = ...,
|
| 307 |
+
) -> _SCT: ...
|
| 308 |
+
@overload
|
| 309 |
+
def squeeze(
|
| 310 |
+
a: _ArrayLike[_SCT],
|
| 311 |
+
axis: None | _ShapeLike = ...,
|
| 312 |
+
) -> NDArray[_SCT]: ...
|
| 313 |
+
@overload
|
| 314 |
+
def squeeze(
|
| 315 |
+
a: ArrayLike,
|
| 316 |
+
axis: None | _ShapeLike = ...,
|
| 317 |
+
) -> NDArray[Any]: ...
|
| 318 |
+
|
| 319 |
+
@overload
|
| 320 |
+
def diagonal(
|
| 321 |
+
a: _ArrayLike[_SCT],
|
| 322 |
+
offset: SupportsIndex = ...,
|
| 323 |
+
axis1: SupportsIndex = ...,
|
| 324 |
+
axis2: SupportsIndex = ..., # >= 2D array
|
| 325 |
+
) -> NDArray[_SCT]: ...
|
| 326 |
+
@overload
|
| 327 |
+
def diagonal(
|
| 328 |
+
a: ArrayLike,
|
| 329 |
+
offset: SupportsIndex = ...,
|
| 330 |
+
axis1: SupportsIndex = ...,
|
| 331 |
+
axis2: SupportsIndex = ..., # >= 2D array
|
| 332 |
+
) -> NDArray[Any]: ...
|
| 333 |
+
|
| 334 |
+
@overload
|
| 335 |
+
def trace(
|
| 336 |
+
a: ArrayLike, # >= 2D array
|
| 337 |
+
offset: SupportsIndex = ...,
|
| 338 |
+
axis1: SupportsIndex = ...,
|
| 339 |
+
axis2: SupportsIndex = ...,
|
| 340 |
+
dtype: DTypeLike = ...,
|
| 341 |
+
out: None = ...,
|
| 342 |
+
) -> Any: ...
|
| 343 |
+
@overload
|
| 344 |
+
def trace(
|
| 345 |
+
a: ArrayLike, # >= 2D array
|
| 346 |
+
offset: SupportsIndex = ...,
|
| 347 |
+
axis1: SupportsIndex = ...,
|
| 348 |
+
axis2: SupportsIndex = ...,
|
| 349 |
+
dtype: DTypeLike = ...,
|
| 350 |
+
out: _ArrayType = ...,
|
| 351 |
+
) -> _ArrayType: ...
|
| 352 |
+
|
| 353 |
+
@overload
|
| 354 |
+
def ravel(a: _ArrayLike[_SCT], order: _OrderKACF = ...) -> NDArray[_SCT]: ...
|
| 355 |
+
@overload
|
| 356 |
+
def ravel(a: ArrayLike, order: _OrderKACF = ...) -> NDArray[Any]: ...
|
| 357 |
+
|
| 358 |
+
def nonzero(a: ArrayLike) -> tuple[NDArray[intp], ...]: ...
|
| 359 |
+
|
| 360 |
+
def shape(a: ArrayLike) -> _Shape: ...
|
| 361 |
+
|
| 362 |
+
@overload
|
| 363 |
+
def compress(
|
| 364 |
+
condition: _ArrayLikeBool_co, # 1D bool array
|
| 365 |
+
a: _ArrayLike[_SCT],
|
| 366 |
+
axis: None | SupportsIndex = ...,
|
| 367 |
+
out: None = ...,
|
| 368 |
+
) -> NDArray[_SCT]: ...
|
| 369 |
+
@overload
|
| 370 |
+
def compress(
|
| 371 |
+
condition: _ArrayLikeBool_co, # 1D bool array
|
| 372 |
+
a: ArrayLike,
|
| 373 |
+
axis: None | SupportsIndex = ...,
|
| 374 |
+
out: None = ...,
|
| 375 |
+
) -> NDArray[Any]: ...
|
| 376 |
+
@overload
|
| 377 |
+
def compress(
|
| 378 |
+
condition: _ArrayLikeBool_co, # 1D bool array
|
| 379 |
+
a: ArrayLike,
|
| 380 |
+
axis: None | SupportsIndex = ...,
|
| 381 |
+
out: _ArrayType = ...,
|
| 382 |
+
) -> _ArrayType: ...
|
| 383 |
+
|
| 384 |
+
@overload
|
| 385 |
+
def clip(
|
| 386 |
+
a: _SCT,
|
| 387 |
+
a_min: None | ArrayLike,
|
| 388 |
+
a_max: None | ArrayLike,
|
| 389 |
+
out: None = ...,
|
| 390 |
+
*,
|
| 391 |
+
dtype: None = ...,
|
| 392 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 393 |
+
order: _OrderKACF = ...,
|
| 394 |
+
subok: bool = ...,
|
| 395 |
+
signature: str | tuple[None | str, ...] = ...,
|
| 396 |
+
extobj: list[Any] = ...,
|
| 397 |
+
casting: _CastingKind = ...,
|
| 398 |
+
) -> _SCT: ...
|
| 399 |
+
@overload
|
| 400 |
+
def clip(
|
| 401 |
+
a: _ScalarLike_co,
|
| 402 |
+
a_min: None | ArrayLike,
|
| 403 |
+
a_max: None | ArrayLike,
|
| 404 |
+
out: None = ...,
|
| 405 |
+
*,
|
| 406 |
+
dtype: None = ...,
|
| 407 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 408 |
+
order: _OrderKACF = ...,
|
| 409 |
+
subok: bool = ...,
|
| 410 |
+
signature: str | tuple[None | str, ...] = ...,
|
| 411 |
+
extobj: list[Any] = ...,
|
| 412 |
+
casting: _CastingKind = ...,
|
| 413 |
+
) -> Any: ...
|
| 414 |
+
@overload
|
| 415 |
+
def clip(
|
| 416 |
+
a: _ArrayLike[_SCT],
|
| 417 |
+
a_min: None | ArrayLike,
|
| 418 |
+
a_max: None | ArrayLike,
|
| 419 |
+
out: None = ...,
|
| 420 |
+
*,
|
| 421 |
+
dtype: None = ...,
|
| 422 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 423 |
+
order: _OrderKACF = ...,
|
| 424 |
+
subok: bool = ...,
|
| 425 |
+
signature: str | tuple[None | str, ...] = ...,
|
| 426 |
+
extobj: list[Any] = ...,
|
| 427 |
+
casting: _CastingKind = ...,
|
| 428 |
+
) -> NDArray[_SCT]: ...
|
| 429 |
+
@overload
|
| 430 |
+
def clip(
|
| 431 |
+
a: ArrayLike,
|
| 432 |
+
a_min: None | ArrayLike,
|
| 433 |
+
a_max: None | ArrayLike,
|
| 434 |
+
out: None = ...,
|
| 435 |
+
*,
|
| 436 |
+
dtype: None = ...,
|
| 437 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 438 |
+
order: _OrderKACF = ...,
|
| 439 |
+
subok: bool = ...,
|
| 440 |
+
signature: str | tuple[None | str, ...] = ...,
|
| 441 |
+
extobj: list[Any] = ...,
|
| 442 |
+
casting: _CastingKind = ...,
|
| 443 |
+
) -> NDArray[Any]: ...
|
| 444 |
+
@overload
|
| 445 |
+
def clip(
|
| 446 |
+
a: ArrayLike,
|
| 447 |
+
a_min: None | ArrayLike,
|
| 448 |
+
a_max: None | ArrayLike,
|
| 449 |
+
out: _ArrayType = ...,
|
| 450 |
+
*,
|
| 451 |
+
dtype: DTypeLike,
|
| 452 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 453 |
+
order: _OrderKACF = ...,
|
| 454 |
+
subok: bool = ...,
|
| 455 |
+
signature: str | tuple[None | str, ...] = ...,
|
| 456 |
+
extobj: list[Any] = ...,
|
| 457 |
+
casting: _CastingKind = ...,
|
| 458 |
+
) -> Any: ...
|
| 459 |
+
@overload
|
| 460 |
+
def clip(
|
| 461 |
+
a: ArrayLike,
|
| 462 |
+
a_min: None | ArrayLike,
|
| 463 |
+
a_max: None | ArrayLike,
|
| 464 |
+
out: _ArrayType,
|
| 465 |
+
*,
|
| 466 |
+
dtype: DTypeLike = ...,
|
| 467 |
+
where: None | _ArrayLikeBool_co = ...,
|
| 468 |
+
order: _OrderKACF = ...,
|
| 469 |
+
subok: bool = ...,
|
| 470 |
+
signature: str | tuple[None | str, ...] = ...,
|
| 471 |
+
extobj: list[Any] = ...,
|
| 472 |
+
casting: _CastingKind = ...,
|
| 473 |
+
) -> _ArrayType: ...
|
| 474 |
+
|
| 475 |
+
@overload
|
| 476 |
+
def sum(
|
| 477 |
+
a: _ArrayLike[_SCT],
|
| 478 |
+
axis: None = ...,
|
| 479 |
+
dtype: None = ...,
|
| 480 |
+
out: None = ...,
|
| 481 |
+
keepdims: bool = ...,
|
| 482 |
+
initial: _NumberLike_co = ...,
|
| 483 |
+
where: _ArrayLikeBool_co = ...,
|
| 484 |
+
) -> _SCT: ...
|
| 485 |
+
@overload
|
| 486 |
+
def sum(
|
| 487 |
+
a: ArrayLike,
|
| 488 |
+
axis: None | _ShapeLike = ...,
|
| 489 |
+
dtype: DTypeLike = ...,
|
| 490 |
+
out: None = ...,
|
| 491 |
+
keepdims: bool = ...,
|
| 492 |
+
initial: _NumberLike_co = ...,
|
| 493 |
+
where: _ArrayLikeBool_co = ...,
|
| 494 |
+
) -> Any: ...
|
| 495 |
+
@overload
|
| 496 |
+
def sum(
|
| 497 |
+
a: ArrayLike,
|
| 498 |
+
axis: None | _ShapeLike = ...,
|
| 499 |
+
dtype: DTypeLike = ...,
|
| 500 |
+
out: _ArrayType = ...,
|
| 501 |
+
keepdims: bool = ...,
|
| 502 |
+
initial: _NumberLike_co = ...,
|
| 503 |
+
where: _ArrayLikeBool_co = ...,
|
| 504 |
+
) -> _ArrayType: ...
|
| 505 |
+
|
| 506 |
+
@overload
|
| 507 |
+
def all(
|
| 508 |
+
a: ArrayLike,
|
| 509 |
+
axis: None = ...,
|
| 510 |
+
out: None = ...,
|
| 511 |
+
keepdims: Literal[False] = ...,
|
| 512 |
+
*,
|
| 513 |
+
where: _ArrayLikeBool_co = ...,
|
| 514 |
+
) -> bool_: ...
|
| 515 |
+
@overload
|
| 516 |
+
def all(
|
| 517 |
+
a: ArrayLike,
|
| 518 |
+
axis: None | _ShapeLike = ...,
|
| 519 |
+
out: None = ...,
|
| 520 |
+
keepdims: bool = ...,
|
| 521 |
+
*,
|
| 522 |
+
where: _ArrayLikeBool_co = ...,
|
| 523 |
+
) -> Any: ...
|
| 524 |
+
@overload
|
| 525 |
+
def all(
|
| 526 |
+
a: ArrayLike,
|
| 527 |
+
axis: None | _ShapeLike = ...,
|
| 528 |
+
out: _ArrayType = ...,
|
| 529 |
+
keepdims: bool = ...,
|
| 530 |
+
*,
|
| 531 |
+
where: _ArrayLikeBool_co = ...,
|
| 532 |
+
) -> _ArrayType: ...
|
| 533 |
+
|
| 534 |
+
@overload
|
| 535 |
+
def any(
|
| 536 |
+
a: ArrayLike,
|
| 537 |
+
axis: None = ...,
|
| 538 |
+
out: None = ...,
|
| 539 |
+
keepdims: Literal[False] = ...,
|
| 540 |
+
*,
|
| 541 |
+
where: _ArrayLikeBool_co = ...,
|
| 542 |
+
) -> bool_: ...
|
| 543 |
+
@overload
|
| 544 |
+
def any(
|
| 545 |
+
a: ArrayLike,
|
| 546 |
+
axis: None | _ShapeLike = ...,
|
| 547 |
+
out: None = ...,
|
| 548 |
+
keepdims: bool = ...,
|
| 549 |
+
*,
|
| 550 |
+
where: _ArrayLikeBool_co = ...,
|
| 551 |
+
) -> Any: ...
|
| 552 |
+
@overload
|
| 553 |
+
def any(
|
| 554 |
+
a: ArrayLike,
|
| 555 |
+
axis: None | _ShapeLike = ...,
|
| 556 |
+
out: _ArrayType = ...,
|
| 557 |
+
keepdims: bool = ...,
|
| 558 |
+
*,
|
| 559 |
+
where: _ArrayLikeBool_co = ...,
|
| 560 |
+
) -> _ArrayType: ...
|
| 561 |
+
|
| 562 |
+
@overload
|
| 563 |
+
def cumsum(
|
| 564 |
+
a: _ArrayLike[_SCT],
|
| 565 |
+
axis: None | SupportsIndex = ...,
|
| 566 |
+
dtype: None = ...,
|
| 567 |
+
out: None = ...,
|
| 568 |
+
) -> NDArray[_SCT]: ...
|
| 569 |
+
@overload
|
| 570 |
+
def cumsum(
|
| 571 |
+
a: ArrayLike,
|
| 572 |
+
axis: None | SupportsIndex = ...,
|
| 573 |
+
dtype: None = ...,
|
| 574 |
+
out: None = ...,
|
| 575 |
+
) -> NDArray[Any]: ...
|
| 576 |
+
@overload
|
| 577 |
+
def cumsum(
|
| 578 |
+
a: ArrayLike,
|
| 579 |
+
axis: None | SupportsIndex = ...,
|
| 580 |
+
dtype: _DTypeLike[_SCT] = ...,
|
| 581 |
+
out: None = ...,
|
| 582 |
+
) -> NDArray[_SCT]: ...
|
| 583 |
+
@overload
|
| 584 |
+
def cumsum(
|
| 585 |
+
a: ArrayLike,
|
| 586 |
+
axis: None | SupportsIndex = ...,
|
| 587 |
+
dtype: DTypeLike = ...,
|
| 588 |
+
out: None = ...,
|
| 589 |
+
) -> NDArray[Any]: ...
|
| 590 |
+
@overload
|
| 591 |
+
def cumsum(
|
| 592 |
+
a: ArrayLike,
|
| 593 |
+
axis: None | SupportsIndex = ...,
|
| 594 |
+
dtype: DTypeLike = ...,
|
| 595 |
+
out: _ArrayType = ...,
|
| 596 |
+
) -> _ArrayType: ...
|
| 597 |
+
|
| 598 |
+
@overload
|
| 599 |
+
def ptp(
|
| 600 |
+
a: _ArrayLike[_SCT],
|
| 601 |
+
axis: None = ...,
|
| 602 |
+
out: None = ...,
|
| 603 |
+
keepdims: Literal[False] = ...,
|
| 604 |
+
) -> _SCT: ...
|
| 605 |
+
@overload
|
| 606 |
+
def ptp(
|
| 607 |
+
a: ArrayLike,
|
| 608 |
+
axis: None | _ShapeLike = ...,
|
| 609 |
+
out: None = ...,
|
| 610 |
+
keepdims: bool = ...,
|
| 611 |
+
) -> Any: ...
|
| 612 |
+
@overload
|
| 613 |
+
def ptp(
|
| 614 |
+
a: ArrayLike,
|
| 615 |
+
axis: None | _ShapeLike = ...,
|
| 616 |
+
out: _ArrayType = ...,
|
| 617 |
+
keepdims: bool = ...,
|
| 618 |
+
) -> _ArrayType: ...
|
| 619 |
+
|
| 620 |
+
@overload
|
| 621 |
+
def amax(
|
| 622 |
+
a: _ArrayLike[_SCT],
|
| 623 |
+
axis: None = ...,
|
| 624 |
+
out: None = ...,
|
| 625 |
+
keepdims: Literal[False] = ...,
|
| 626 |
+
initial: _NumberLike_co = ...,
|
| 627 |
+
where: _ArrayLikeBool_co = ...,
|
| 628 |
+
) -> _SCT: ...
|
| 629 |
+
@overload
|
| 630 |
+
def amax(
|
| 631 |
+
a: ArrayLike,
|
| 632 |
+
axis: None | _ShapeLike = ...,
|
| 633 |
+
out: None = ...,
|
| 634 |
+
keepdims: bool = ...,
|
| 635 |
+
initial: _NumberLike_co = ...,
|
| 636 |
+
where: _ArrayLikeBool_co = ...,
|
| 637 |
+
) -> Any: ...
|
| 638 |
+
@overload
|
| 639 |
+
def amax(
|
| 640 |
+
a: ArrayLike,
|
| 641 |
+
axis: None | _ShapeLike = ...,
|
| 642 |
+
out: _ArrayType = ...,
|
| 643 |
+
keepdims: bool = ...,
|
| 644 |
+
initial: _NumberLike_co = ...,
|
| 645 |
+
where: _ArrayLikeBool_co = ...,
|
| 646 |
+
) -> _ArrayType: ...
|
| 647 |
+
|
| 648 |
+
@overload
|
| 649 |
+
def amin(
|
| 650 |
+
a: _ArrayLike[_SCT],
|
| 651 |
+
axis: None = ...,
|
| 652 |
+
out: None = ...,
|
| 653 |
+
keepdims: Literal[False] = ...,
|
| 654 |
+
initial: _NumberLike_co = ...,
|
| 655 |
+
where: _ArrayLikeBool_co = ...,
|
| 656 |
+
) -> _SCT: ...
|
| 657 |
+
@overload
|
| 658 |
+
def amin(
|
| 659 |
+
a: ArrayLike,
|
| 660 |
+
axis: None | _ShapeLike = ...,
|
| 661 |
+
out: None = ...,
|
| 662 |
+
keepdims: bool = ...,
|
| 663 |
+
initial: _NumberLike_co = ...,
|
| 664 |
+
where: _ArrayLikeBool_co = ...,
|
| 665 |
+
) -> Any: ...
|
| 666 |
+
@overload
|
| 667 |
+
def amin(
|
| 668 |
+
a: ArrayLike,
|
| 669 |
+
axis: None | _ShapeLike = ...,
|
| 670 |
+
out: _ArrayType = ...,
|
| 671 |
+
keepdims: bool = ...,
|
| 672 |
+
initial: _NumberLike_co = ...,
|
| 673 |
+
where: _ArrayLikeBool_co = ...,
|
| 674 |
+
) -> _ArrayType: ...
|
| 675 |
+
|
| 676 |
+
# TODO: `np.prod()``: For object arrays `initial` does not necessarily
|
| 677 |
+
# have to be a numerical scalar.
|
| 678 |
+
# The only requirement is that it is compatible
|
| 679 |
+
# with the `.__mul__()` method(s) of the passed array's elements.
|
| 680 |
+
|
| 681 |
+
# Note that the same situation holds for all wrappers around
|
| 682 |
+
# `np.ufunc.reduce`, e.g. `np.sum()` (`.__add__()`).
|
| 683 |
+
@overload
|
| 684 |
+
def prod(
|
| 685 |
+
a: _ArrayLikeBool_co,
|
| 686 |
+
axis: None = ...,
|
| 687 |
+
dtype: None = ...,
|
| 688 |
+
out: None = ...,
|
| 689 |
+
keepdims: Literal[False] = ...,
|
| 690 |
+
initial: _NumberLike_co = ...,
|
| 691 |
+
where: _ArrayLikeBool_co = ...,
|
| 692 |
+
) -> int_: ...
|
| 693 |
+
@overload
|
| 694 |
+
def prod(
|
| 695 |
+
a: _ArrayLikeUInt_co,
|
| 696 |
+
axis: None = ...,
|
| 697 |
+
dtype: None = ...,
|
| 698 |
+
out: None = ...,
|
| 699 |
+
keepdims: Literal[False] = ...,
|
| 700 |
+
initial: _NumberLike_co = ...,
|
| 701 |
+
where: _ArrayLikeBool_co = ...,
|
| 702 |
+
) -> uint64: ...
|
| 703 |
+
@overload
|
| 704 |
+
def prod(
|
| 705 |
+
a: _ArrayLikeInt_co,
|
| 706 |
+
axis: None = ...,
|
| 707 |
+
dtype: None = ...,
|
| 708 |
+
out: None = ...,
|
| 709 |
+
keepdims: Literal[False] = ...,
|
| 710 |
+
initial: _NumberLike_co = ...,
|
| 711 |
+
where: _ArrayLikeBool_co = ...,
|
| 712 |
+
) -> int64: ...
|
| 713 |
+
@overload
|
| 714 |
+
def prod(
|
| 715 |
+
a: _ArrayLikeFloat_co,
|
| 716 |
+
axis: None = ...,
|
| 717 |
+
dtype: None = ...,
|
| 718 |
+
out: None = ...,
|
| 719 |
+
keepdims: Literal[False] = ...,
|
| 720 |
+
initial: _NumberLike_co = ...,
|
| 721 |
+
where: _ArrayLikeBool_co = ...,
|
| 722 |
+
) -> floating[Any]: ...
|
| 723 |
+
@overload
|
| 724 |
+
def prod(
|
| 725 |
+
a: _ArrayLikeComplex_co,
|
| 726 |
+
axis: None = ...,
|
| 727 |
+
dtype: None = ...,
|
| 728 |
+
out: None = ...,
|
| 729 |
+
keepdims: Literal[False] = ...,
|
| 730 |
+
initial: _NumberLike_co = ...,
|
| 731 |
+
where: _ArrayLikeBool_co = ...,
|
| 732 |
+
) -> complexfloating[Any, Any]: ...
|
| 733 |
+
@overload
|
| 734 |
+
def prod(
|
| 735 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 736 |
+
axis: None | _ShapeLike = ...,
|
| 737 |
+
dtype: None = ...,
|
| 738 |
+
out: None = ...,
|
| 739 |
+
keepdims: bool = ...,
|
| 740 |
+
initial: _NumberLike_co = ...,
|
| 741 |
+
where: _ArrayLikeBool_co = ...,
|
| 742 |
+
) -> Any: ...
|
| 743 |
+
@overload
|
| 744 |
+
def prod(
|
| 745 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 746 |
+
axis: None = ...,
|
| 747 |
+
dtype: _DTypeLike[_SCT] = ...,
|
| 748 |
+
out: None = ...,
|
| 749 |
+
keepdims: Literal[False] = ...,
|
| 750 |
+
initial: _NumberLike_co = ...,
|
| 751 |
+
where: _ArrayLikeBool_co = ...,
|
| 752 |
+
) -> _SCT: ...
|
| 753 |
+
@overload
|
| 754 |
+
def prod(
|
| 755 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 756 |
+
axis: None | _ShapeLike = ...,
|
| 757 |
+
dtype: None | DTypeLike = ...,
|
| 758 |
+
out: None = ...,
|
| 759 |
+
keepdims: bool = ...,
|
| 760 |
+
initial: _NumberLike_co = ...,
|
| 761 |
+
where: _ArrayLikeBool_co = ...,
|
| 762 |
+
) -> Any: ...
|
| 763 |
+
@overload
|
| 764 |
+
def prod(
|
| 765 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 766 |
+
axis: None | _ShapeLike = ...,
|
| 767 |
+
dtype: None | DTypeLike = ...,
|
| 768 |
+
out: _ArrayType = ...,
|
| 769 |
+
keepdims: bool = ...,
|
| 770 |
+
initial: _NumberLike_co = ...,
|
| 771 |
+
where: _ArrayLikeBool_co = ...,
|
| 772 |
+
) -> _ArrayType: ...
|
| 773 |
+
|
| 774 |
+
@overload
|
| 775 |
+
def cumprod(
|
| 776 |
+
a: _ArrayLikeBool_co,
|
| 777 |
+
axis: None | SupportsIndex = ...,
|
| 778 |
+
dtype: None = ...,
|
| 779 |
+
out: None = ...,
|
| 780 |
+
) -> NDArray[int_]: ...
|
| 781 |
+
@overload
|
| 782 |
+
def cumprod(
|
| 783 |
+
a: _ArrayLikeUInt_co,
|
| 784 |
+
axis: None | SupportsIndex = ...,
|
| 785 |
+
dtype: None = ...,
|
| 786 |
+
out: None = ...,
|
| 787 |
+
) -> NDArray[uint64]: ...
|
| 788 |
+
@overload
|
| 789 |
+
def cumprod(
|
| 790 |
+
a: _ArrayLikeInt_co,
|
| 791 |
+
axis: None | SupportsIndex = ...,
|
| 792 |
+
dtype: None = ...,
|
| 793 |
+
out: None = ...,
|
| 794 |
+
) -> NDArray[int64]: ...
|
| 795 |
+
@overload
|
| 796 |
+
def cumprod(
|
| 797 |
+
a: _ArrayLikeFloat_co,
|
| 798 |
+
axis: None | SupportsIndex = ...,
|
| 799 |
+
dtype: None = ...,
|
| 800 |
+
out: None = ...,
|
| 801 |
+
) -> NDArray[floating[Any]]: ...
|
| 802 |
+
@overload
|
| 803 |
+
def cumprod(
|
| 804 |
+
a: _ArrayLikeComplex_co,
|
| 805 |
+
axis: None | SupportsIndex = ...,
|
| 806 |
+
dtype: None = ...,
|
| 807 |
+
out: None = ...,
|
| 808 |
+
) -> NDArray[complexfloating[Any, Any]]: ...
|
| 809 |
+
@overload
|
| 810 |
+
def cumprod(
|
| 811 |
+
a: _ArrayLikeObject_co,
|
| 812 |
+
axis: None | SupportsIndex = ...,
|
| 813 |
+
dtype: None = ...,
|
| 814 |
+
out: None = ...,
|
| 815 |
+
) -> NDArray[object_]: ...
|
| 816 |
+
@overload
|
| 817 |
+
def cumprod(
|
| 818 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 819 |
+
axis: None | SupportsIndex = ...,
|
| 820 |
+
dtype: _DTypeLike[_SCT] = ...,
|
| 821 |
+
out: None = ...,
|
| 822 |
+
) -> NDArray[_SCT]: ...
|
| 823 |
+
@overload
|
| 824 |
+
def cumprod(
|
| 825 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 826 |
+
axis: None | SupportsIndex = ...,
|
| 827 |
+
dtype: DTypeLike = ...,
|
| 828 |
+
out: None = ...,
|
| 829 |
+
) -> NDArray[Any]: ...
|
| 830 |
+
@overload
|
| 831 |
+
def cumprod(
|
| 832 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 833 |
+
axis: None | SupportsIndex = ...,
|
| 834 |
+
dtype: DTypeLike = ...,
|
| 835 |
+
out: _ArrayType = ...,
|
| 836 |
+
) -> _ArrayType: ...
|
| 837 |
+
|
| 838 |
+
def ndim(a: ArrayLike) -> int: ...
|
| 839 |
+
|
| 840 |
+
def size(a: ArrayLike, axis: None | int = ...) -> int: ...
|
| 841 |
+
|
| 842 |
+
@overload
|
| 843 |
+
def around(
|
| 844 |
+
a: _BoolLike_co,
|
| 845 |
+
decimals: SupportsIndex = ...,
|
| 846 |
+
out: None = ...,
|
| 847 |
+
) -> float16: ...
|
| 848 |
+
@overload
|
| 849 |
+
def around(
|
| 850 |
+
a: _SCT_uifcO,
|
| 851 |
+
decimals: SupportsIndex = ...,
|
| 852 |
+
out: None = ...,
|
| 853 |
+
) -> _SCT_uifcO: ...
|
| 854 |
+
@overload
|
| 855 |
+
def around(
|
| 856 |
+
a: _ComplexLike_co | object_,
|
| 857 |
+
decimals: SupportsIndex = ...,
|
| 858 |
+
out: None = ...,
|
| 859 |
+
) -> Any: ...
|
| 860 |
+
@overload
|
| 861 |
+
def around(
|
| 862 |
+
a: _ArrayLikeBool_co,
|
| 863 |
+
decimals: SupportsIndex = ...,
|
| 864 |
+
out: None = ...,
|
| 865 |
+
) -> NDArray[float16]: ...
|
| 866 |
+
@overload
|
| 867 |
+
def around(
|
| 868 |
+
a: _ArrayLike[_SCT_uifcO],
|
| 869 |
+
decimals: SupportsIndex = ...,
|
| 870 |
+
out: None = ...,
|
| 871 |
+
) -> NDArray[_SCT_uifcO]: ...
|
| 872 |
+
@overload
|
| 873 |
+
def around(
|
| 874 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 875 |
+
decimals: SupportsIndex = ...,
|
| 876 |
+
out: None = ...,
|
| 877 |
+
) -> NDArray[Any]: ...
|
| 878 |
+
@overload
|
| 879 |
+
def around(
|
| 880 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 881 |
+
decimals: SupportsIndex = ...,
|
| 882 |
+
out: _ArrayType = ...,
|
| 883 |
+
) -> _ArrayType: ...
|
| 884 |
+
|
| 885 |
+
@overload
|
| 886 |
+
def mean(
|
| 887 |
+
a: _ArrayLikeFloat_co,
|
| 888 |
+
axis: None = ...,
|
| 889 |
+
dtype: None = ...,
|
| 890 |
+
out: None = ...,
|
| 891 |
+
keepdims: Literal[False] = ...,
|
| 892 |
+
*,
|
| 893 |
+
where: _ArrayLikeBool_co = ...,
|
| 894 |
+
) -> floating[Any]: ...
|
| 895 |
+
@overload
|
| 896 |
+
def mean(
|
| 897 |
+
a: _ArrayLikeComplex_co,
|
| 898 |
+
axis: None = ...,
|
| 899 |
+
dtype: None = ...,
|
| 900 |
+
out: None = ...,
|
| 901 |
+
keepdims: Literal[False] = ...,
|
| 902 |
+
*,
|
| 903 |
+
where: _ArrayLikeBool_co = ...,
|
| 904 |
+
) -> complexfloating[Any, Any]: ...
|
| 905 |
+
@overload
|
| 906 |
+
def mean(
|
| 907 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 908 |
+
axis: None | _ShapeLike = ...,
|
| 909 |
+
dtype: None = ...,
|
| 910 |
+
out: None = ...,
|
| 911 |
+
keepdims: bool = ...,
|
| 912 |
+
*,
|
| 913 |
+
where: _ArrayLikeBool_co = ...,
|
| 914 |
+
) -> Any: ...
|
| 915 |
+
@overload
|
| 916 |
+
def mean(
|
| 917 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 918 |
+
axis: None = ...,
|
| 919 |
+
dtype: _DTypeLike[_SCT] = ...,
|
| 920 |
+
out: None = ...,
|
| 921 |
+
keepdims: Literal[False] = ...,
|
| 922 |
+
*,
|
| 923 |
+
where: _ArrayLikeBool_co = ...,
|
| 924 |
+
) -> _SCT: ...
|
| 925 |
+
@overload
|
| 926 |
+
def mean(
|
| 927 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 928 |
+
axis: None | _ShapeLike = ...,
|
| 929 |
+
dtype: DTypeLike = ...,
|
| 930 |
+
out: None = ...,
|
| 931 |
+
keepdims: bool = ...,
|
| 932 |
+
*,
|
| 933 |
+
where: _ArrayLikeBool_co = ...,
|
| 934 |
+
) -> Any: ...
|
| 935 |
+
@overload
|
| 936 |
+
def mean(
|
| 937 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 938 |
+
axis: None | _ShapeLike = ...,
|
| 939 |
+
dtype: DTypeLike = ...,
|
| 940 |
+
out: _ArrayType = ...,
|
| 941 |
+
keepdims: bool = ...,
|
| 942 |
+
*,
|
| 943 |
+
where: _ArrayLikeBool_co = ...,
|
| 944 |
+
) -> _ArrayType: ...
|
| 945 |
+
|
| 946 |
+
@overload
|
| 947 |
+
def std(
|
| 948 |
+
a: _ArrayLikeComplex_co,
|
| 949 |
+
axis: None = ...,
|
| 950 |
+
dtype: None = ...,
|
| 951 |
+
out: None = ...,
|
| 952 |
+
ddof: float = ...,
|
| 953 |
+
keepdims: Literal[False] = ...,
|
| 954 |
+
*,
|
| 955 |
+
where: _ArrayLikeBool_co = ...,
|
| 956 |
+
) -> floating[Any]: ...
|
| 957 |
+
@overload
|
| 958 |
+
def std(
|
| 959 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 960 |
+
axis: None | _ShapeLike = ...,
|
| 961 |
+
dtype: None = ...,
|
| 962 |
+
out: None = ...,
|
| 963 |
+
ddof: float = ...,
|
| 964 |
+
keepdims: bool = ...,
|
| 965 |
+
*,
|
| 966 |
+
where: _ArrayLikeBool_co = ...,
|
| 967 |
+
) -> Any: ...
|
| 968 |
+
@overload
|
| 969 |
+
def std(
|
| 970 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 971 |
+
axis: None = ...,
|
| 972 |
+
dtype: _DTypeLike[_SCT] = ...,
|
| 973 |
+
out: None = ...,
|
| 974 |
+
ddof: float = ...,
|
| 975 |
+
keepdims: Literal[False] = ...,
|
| 976 |
+
*,
|
| 977 |
+
where: _ArrayLikeBool_co = ...,
|
| 978 |
+
) -> _SCT: ...
|
| 979 |
+
@overload
|
| 980 |
+
def std(
|
| 981 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 982 |
+
axis: None | _ShapeLike = ...,
|
| 983 |
+
dtype: DTypeLike = ...,
|
| 984 |
+
out: None = ...,
|
| 985 |
+
ddof: float = ...,
|
| 986 |
+
keepdims: bool = ...,
|
| 987 |
+
*,
|
| 988 |
+
where: _ArrayLikeBool_co = ...,
|
| 989 |
+
) -> Any: ...
|
| 990 |
+
@overload
|
| 991 |
+
def std(
|
| 992 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 993 |
+
axis: None | _ShapeLike = ...,
|
| 994 |
+
dtype: DTypeLike = ...,
|
| 995 |
+
out: _ArrayType = ...,
|
| 996 |
+
ddof: float = ...,
|
| 997 |
+
keepdims: bool = ...,
|
| 998 |
+
*,
|
| 999 |
+
where: _ArrayLikeBool_co = ...,
|
| 1000 |
+
) -> _ArrayType: ...
|
| 1001 |
+
|
| 1002 |
+
@overload
|
| 1003 |
+
def var(
|
| 1004 |
+
a: _ArrayLikeComplex_co,
|
| 1005 |
+
axis: None = ...,
|
| 1006 |
+
dtype: None = ...,
|
| 1007 |
+
out: None = ...,
|
| 1008 |
+
ddof: float = ...,
|
| 1009 |
+
keepdims: Literal[False] = ...,
|
| 1010 |
+
*,
|
| 1011 |
+
where: _ArrayLikeBool_co = ...,
|
| 1012 |
+
) -> floating[Any]: ...
|
| 1013 |
+
@overload
|
| 1014 |
+
def var(
|
| 1015 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 1016 |
+
axis: None | _ShapeLike = ...,
|
| 1017 |
+
dtype: None = ...,
|
| 1018 |
+
out: None = ...,
|
| 1019 |
+
ddof: float = ...,
|
| 1020 |
+
keepdims: bool = ...,
|
| 1021 |
+
*,
|
| 1022 |
+
where: _ArrayLikeBool_co = ...,
|
| 1023 |
+
) -> Any: ...
|
| 1024 |
+
@overload
|
| 1025 |
+
def var(
|
| 1026 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 1027 |
+
axis: None = ...,
|
| 1028 |
+
dtype: _DTypeLike[_SCT] = ...,
|
| 1029 |
+
out: None = ...,
|
| 1030 |
+
ddof: float = ...,
|
| 1031 |
+
keepdims: Literal[False] = ...,
|
| 1032 |
+
*,
|
| 1033 |
+
where: _ArrayLikeBool_co = ...,
|
| 1034 |
+
) -> _SCT: ...
|
| 1035 |
+
@overload
|
| 1036 |
+
def var(
|
| 1037 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 1038 |
+
axis: None | _ShapeLike = ...,
|
| 1039 |
+
dtype: DTypeLike = ...,
|
| 1040 |
+
out: None = ...,
|
| 1041 |
+
ddof: float = ...,
|
| 1042 |
+
keepdims: bool = ...,
|
| 1043 |
+
*,
|
| 1044 |
+
where: _ArrayLikeBool_co = ...,
|
| 1045 |
+
) -> Any: ...
|
| 1046 |
+
@overload
|
| 1047 |
+
def var(
|
| 1048 |
+
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
|
| 1049 |
+
axis: None | _ShapeLike = ...,
|
| 1050 |
+
dtype: DTypeLike = ...,
|
| 1051 |
+
out: _ArrayType = ...,
|
| 1052 |
+
ddof: float = ...,
|
| 1053 |
+
keepdims: bool = ...,
|
| 1054 |
+
*,
|
| 1055 |
+
where: _ArrayLikeBool_co = ...,
|
| 1056 |
+
) -> _ArrayType: ...
|
| 1057 |
+
|
| 1058 |
+
max = amax
|
| 1059 |
+
min = amin
|
| 1060 |
+
round = around
|
.venv/lib/python3.11/site-packages/numpy/core/function_base.py
ADDED
|
@@ -0,0 +1,551 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import warnings
|
| 3 |
+
import operator
|
| 4 |
+
import types
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
from . import numeric as _nx
|
| 8 |
+
from .numeric import result_type, NaN, asanyarray, ndim
|
| 9 |
+
from numpy.core.multiarray import add_docstring
|
| 10 |
+
from numpy.core import overrides
|
| 11 |
+
|
| 12 |
+
__all__ = ['logspace', 'linspace', 'geomspace']
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
array_function_dispatch = functools.partial(
|
| 16 |
+
overrides.array_function_dispatch, module='numpy')
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def _linspace_dispatcher(start, stop, num=None, endpoint=None, retstep=None,
|
| 20 |
+
dtype=None, axis=None):
|
| 21 |
+
return (start, stop)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@array_function_dispatch(_linspace_dispatcher)
|
| 25 |
+
def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None,
|
| 26 |
+
axis=0):
|
| 27 |
+
"""
|
| 28 |
+
Return evenly spaced numbers over a specified interval.
|
| 29 |
+
|
| 30 |
+
Returns `num` evenly spaced samples, calculated over the
|
| 31 |
+
interval [`start`, `stop`].
|
| 32 |
+
|
| 33 |
+
The endpoint of the interval can optionally be excluded.
|
| 34 |
+
|
| 35 |
+
.. versionchanged:: 1.16.0
|
| 36 |
+
Non-scalar `start` and `stop` are now supported.
|
| 37 |
+
|
| 38 |
+
.. versionchanged:: 1.20.0
|
| 39 |
+
Values are rounded towards ``-inf`` instead of ``0`` when an
|
| 40 |
+
integer ``dtype`` is specified. The old behavior can
|
| 41 |
+
still be obtained with ``np.linspace(start, stop, num).astype(int)``
|
| 42 |
+
|
| 43 |
+
Parameters
|
| 44 |
+
----------
|
| 45 |
+
start : array_like
|
| 46 |
+
The starting value of the sequence.
|
| 47 |
+
stop : array_like
|
| 48 |
+
The end value of the sequence, unless `endpoint` is set to False.
|
| 49 |
+
In that case, the sequence consists of all but the last of ``num + 1``
|
| 50 |
+
evenly spaced samples, so that `stop` is excluded. Note that the step
|
| 51 |
+
size changes when `endpoint` is False.
|
| 52 |
+
num : int, optional
|
| 53 |
+
Number of samples to generate. Default is 50. Must be non-negative.
|
| 54 |
+
endpoint : bool, optional
|
| 55 |
+
If True, `stop` is the last sample. Otherwise, it is not included.
|
| 56 |
+
Default is True.
|
| 57 |
+
retstep : bool, optional
|
| 58 |
+
If True, return (`samples`, `step`), where `step` is the spacing
|
| 59 |
+
between samples.
|
| 60 |
+
dtype : dtype, optional
|
| 61 |
+
The type of the output array. If `dtype` is not given, the data type
|
| 62 |
+
is inferred from `start` and `stop`. The inferred dtype will never be
|
| 63 |
+
an integer; `float` is chosen even if the arguments would produce an
|
| 64 |
+
array of integers.
|
| 65 |
+
|
| 66 |
+
.. versionadded:: 1.9.0
|
| 67 |
+
|
| 68 |
+
axis : int, optional
|
| 69 |
+
The axis in the result to store the samples. Relevant only if start
|
| 70 |
+
or stop are array-like. By default (0), the samples will be along a
|
| 71 |
+
new axis inserted at the beginning. Use -1 to get an axis at the end.
|
| 72 |
+
|
| 73 |
+
.. versionadded:: 1.16.0
|
| 74 |
+
|
| 75 |
+
Returns
|
| 76 |
+
-------
|
| 77 |
+
samples : ndarray
|
| 78 |
+
There are `num` equally spaced samples in the closed interval
|
| 79 |
+
``[start, stop]`` or the half-open interval ``[start, stop)``
|
| 80 |
+
(depending on whether `endpoint` is True or False).
|
| 81 |
+
step : float, optional
|
| 82 |
+
Only returned if `retstep` is True
|
| 83 |
+
|
| 84 |
+
Size of spacing between samples.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
See Also
|
| 88 |
+
--------
|
| 89 |
+
arange : Similar to `linspace`, but uses a step size (instead of the
|
| 90 |
+
number of samples).
|
| 91 |
+
geomspace : Similar to `linspace`, but with numbers spaced evenly on a log
|
| 92 |
+
scale (a geometric progression).
|
| 93 |
+
logspace : Similar to `geomspace`, but with the end points specified as
|
| 94 |
+
logarithms.
|
| 95 |
+
:ref:`how-to-partition`
|
| 96 |
+
|
| 97 |
+
Examples
|
| 98 |
+
--------
|
| 99 |
+
>>> np.linspace(2.0, 3.0, num=5)
|
| 100 |
+
array([2. , 2.25, 2.5 , 2.75, 3. ])
|
| 101 |
+
>>> np.linspace(2.0, 3.0, num=5, endpoint=False)
|
| 102 |
+
array([2. , 2.2, 2.4, 2.6, 2.8])
|
| 103 |
+
>>> np.linspace(2.0, 3.0, num=5, retstep=True)
|
| 104 |
+
(array([2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)
|
| 105 |
+
|
| 106 |
+
Graphical illustration:
|
| 107 |
+
|
| 108 |
+
>>> import matplotlib.pyplot as plt
|
| 109 |
+
>>> N = 8
|
| 110 |
+
>>> y = np.zeros(N)
|
| 111 |
+
>>> x1 = np.linspace(0, 10, N, endpoint=True)
|
| 112 |
+
>>> x2 = np.linspace(0, 10, N, endpoint=False)
|
| 113 |
+
>>> plt.plot(x1, y, 'o')
|
| 114 |
+
[<matplotlib.lines.Line2D object at 0x...>]
|
| 115 |
+
>>> plt.plot(x2, y + 0.5, 'o')
|
| 116 |
+
[<matplotlib.lines.Line2D object at 0x...>]
|
| 117 |
+
>>> plt.ylim([-0.5, 1])
|
| 118 |
+
(-0.5, 1)
|
| 119 |
+
>>> plt.show()
|
| 120 |
+
|
| 121 |
+
"""
|
| 122 |
+
num = operator.index(num)
|
| 123 |
+
if num < 0:
|
| 124 |
+
raise ValueError("Number of samples, %s, must be non-negative." % num)
|
| 125 |
+
div = (num - 1) if endpoint else num
|
| 126 |
+
|
| 127 |
+
# Convert float/complex array scalars to float, gh-3504
|
| 128 |
+
# and make sure one can use variables that have an __array_interface__, gh-6634
|
| 129 |
+
start = asanyarray(start) * 1.0
|
| 130 |
+
stop = asanyarray(stop) * 1.0
|
| 131 |
+
|
| 132 |
+
dt = result_type(start, stop, float(num))
|
| 133 |
+
if dtype is None:
|
| 134 |
+
dtype = dt
|
| 135 |
+
integer_dtype = False
|
| 136 |
+
else:
|
| 137 |
+
integer_dtype = _nx.issubdtype(dtype, _nx.integer)
|
| 138 |
+
|
| 139 |
+
delta = stop - start
|
| 140 |
+
y = _nx.arange(0, num, dtype=dt).reshape((-1,) + (1,) * ndim(delta))
|
| 141 |
+
# In-place multiplication y *= delta/div is faster, but prevents the multiplicant
|
| 142 |
+
# from overriding what class is produced, and thus prevents, e.g. use of Quantities,
|
| 143 |
+
# see gh-7142. Hence, we multiply in place only for standard scalar types.
|
| 144 |
+
if div > 0:
|
| 145 |
+
_mult_inplace = _nx.isscalar(delta)
|
| 146 |
+
step = delta / div
|
| 147 |
+
any_step_zero = (
|
| 148 |
+
step == 0 if _mult_inplace else _nx.asanyarray(step == 0).any())
|
| 149 |
+
if any_step_zero:
|
| 150 |
+
# Special handling for denormal numbers, gh-5437
|
| 151 |
+
y /= div
|
| 152 |
+
if _mult_inplace:
|
| 153 |
+
y *= delta
|
| 154 |
+
else:
|
| 155 |
+
y = y * delta
|
| 156 |
+
else:
|
| 157 |
+
if _mult_inplace:
|
| 158 |
+
y *= step
|
| 159 |
+
else:
|
| 160 |
+
y = y * step
|
| 161 |
+
else:
|
| 162 |
+
# sequences with 0 items or 1 item with endpoint=True (i.e. div <= 0)
|
| 163 |
+
# have an undefined step
|
| 164 |
+
step = NaN
|
| 165 |
+
# Multiply with delta to allow possible override of output class.
|
| 166 |
+
y = y * delta
|
| 167 |
+
|
| 168 |
+
y += start
|
| 169 |
+
|
| 170 |
+
if endpoint and num > 1:
|
| 171 |
+
y[-1, ...] = stop
|
| 172 |
+
|
| 173 |
+
if axis != 0:
|
| 174 |
+
y = _nx.moveaxis(y, 0, axis)
|
| 175 |
+
|
| 176 |
+
if integer_dtype:
|
| 177 |
+
_nx.floor(y, out=y)
|
| 178 |
+
|
| 179 |
+
if retstep:
|
| 180 |
+
return y.astype(dtype, copy=False), step
|
| 181 |
+
else:
|
| 182 |
+
return y.astype(dtype, copy=False)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def _logspace_dispatcher(start, stop, num=None, endpoint=None, base=None,
|
| 186 |
+
dtype=None, axis=None):
|
| 187 |
+
return (start, stop, base)
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
@array_function_dispatch(_logspace_dispatcher)
|
| 191 |
+
def logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None,
|
| 192 |
+
axis=0):
|
| 193 |
+
"""
|
| 194 |
+
Return numbers spaced evenly on a log scale.
|
| 195 |
+
|
| 196 |
+
In linear space, the sequence starts at ``base ** start``
|
| 197 |
+
(`base` to the power of `start`) and ends with ``base ** stop``
|
| 198 |
+
(see `endpoint` below).
|
| 199 |
+
|
| 200 |
+
.. versionchanged:: 1.16.0
|
| 201 |
+
Non-scalar `start` and `stop` are now supported.
|
| 202 |
+
|
| 203 |
+
.. versionchanged:: 1.25.0
|
| 204 |
+
Non-scalar 'base` is now supported
|
| 205 |
+
|
| 206 |
+
Parameters
|
| 207 |
+
----------
|
| 208 |
+
start : array_like
|
| 209 |
+
``base ** start`` is the starting value of the sequence.
|
| 210 |
+
stop : array_like
|
| 211 |
+
``base ** stop`` is the final value of the sequence, unless `endpoint`
|
| 212 |
+
is False. In that case, ``num + 1`` values are spaced over the
|
| 213 |
+
interval in log-space, of which all but the last (a sequence of
|
| 214 |
+
length `num`) are returned.
|
| 215 |
+
num : integer, optional
|
| 216 |
+
Number of samples to generate. Default is 50.
|
| 217 |
+
endpoint : boolean, optional
|
| 218 |
+
If true, `stop` is the last sample. Otherwise, it is not included.
|
| 219 |
+
Default is True.
|
| 220 |
+
base : array_like, optional
|
| 221 |
+
The base of the log space. The step size between the elements in
|
| 222 |
+
``ln(samples) / ln(base)`` (or ``log_base(samples)``) is uniform.
|
| 223 |
+
Default is 10.0.
|
| 224 |
+
dtype : dtype
|
| 225 |
+
The type of the output array. If `dtype` is not given, the data type
|
| 226 |
+
is inferred from `start` and `stop`. The inferred type will never be
|
| 227 |
+
an integer; `float` is chosen even if the arguments would produce an
|
| 228 |
+
array of integers.
|
| 229 |
+
axis : int, optional
|
| 230 |
+
The axis in the result to store the samples. Relevant only if start,
|
| 231 |
+
stop, or base are array-like. By default (0), the samples will be
|
| 232 |
+
along a new axis inserted at the beginning. Use -1 to get an axis at
|
| 233 |
+
the end.
|
| 234 |
+
|
| 235 |
+
.. versionadded:: 1.16.0
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
Returns
|
| 239 |
+
-------
|
| 240 |
+
samples : ndarray
|
| 241 |
+
`num` samples, equally spaced on a log scale.
|
| 242 |
+
|
| 243 |
+
See Also
|
| 244 |
+
--------
|
| 245 |
+
arange : Similar to linspace, with the step size specified instead of the
|
| 246 |
+
number of samples. Note that, when used with a float endpoint, the
|
| 247 |
+
endpoint may or may not be included.
|
| 248 |
+
linspace : Similar to logspace, but with the samples uniformly distributed
|
| 249 |
+
in linear space, instead of log space.
|
| 250 |
+
geomspace : Similar to logspace, but with endpoints specified directly.
|
| 251 |
+
:ref:`how-to-partition`
|
| 252 |
+
|
| 253 |
+
Notes
|
| 254 |
+
-----
|
| 255 |
+
If base is a scalar, logspace is equivalent to the code
|
| 256 |
+
|
| 257 |
+
>>> y = np.linspace(start, stop, num=num, endpoint=endpoint)
|
| 258 |
+
... # doctest: +SKIP
|
| 259 |
+
>>> power(base, y).astype(dtype)
|
| 260 |
+
... # doctest: +SKIP
|
| 261 |
+
|
| 262 |
+
Examples
|
| 263 |
+
--------
|
| 264 |
+
>>> np.logspace(2.0, 3.0, num=4)
|
| 265 |
+
array([ 100. , 215.443469 , 464.15888336, 1000. ])
|
| 266 |
+
>>> np.logspace(2.0, 3.0, num=4, endpoint=False)
|
| 267 |
+
array([100. , 177.827941 , 316.22776602, 562.34132519])
|
| 268 |
+
>>> np.logspace(2.0, 3.0, num=4, base=2.0)
|
| 269 |
+
array([4. , 5.0396842 , 6.34960421, 8. ])
|
| 270 |
+
>>> np.logspace(2.0, 3.0, num=4, base=[2.0, 3.0], axis=-1)
|
| 271 |
+
array([[ 4. , 5.0396842 , 6.34960421, 8. ],
|
| 272 |
+
[ 9. , 12.98024613, 18.72075441, 27. ]])
|
| 273 |
+
|
| 274 |
+
Graphical illustration:
|
| 275 |
+
|
| 276 |
+
>>> import matplotlib.pyplot as plt
|
| 277 |
+
>>> N = 10
|
| 278 |
+
>>> x1 = np.logspace(0.1, 1, N, endpoint=True)
|
| 279 |
+
>>> x2 = np.logspace(0.1, 1, N, endpoint=False)
|
| 280 |
+
>>> y = np.zeros(N)
|
| 281 |
+
>>> plt.plot(x1, y, 'o')
|
| 282 |
+
[<matplotlib.lines.Line2D object at 0x...>]
|
| 283 |
+
>>> plt.plot(x2, y + 0.5, 'o')
|
| 284 |
+
[<matplotlib.lines.Line2D object at 0x...>]
|
| 285 |
+
>>> plt.ylim([-0.5, 1])
|
| 286 |
+
(-0.5, 1)
|
| 287 |
+
>>> plt.show()
|
| 288 |
+
|
| 289 |
+
"""
|
| 290 |
+
ndmax = np.broadcast(start, stop, base).ndim
|
| 291 |
+
start, stop, base = (
|
| 292 |
+
np.array(a, copy=False, subok=True, ndmin=ndmax)
|
| 293 |
+
for a in (start, stop, base)
|
| 294 |
+
)
|
| 295 |
+
y = linspace(start, stop, num=num, endpoint=endpoint, axis=axis)
|
| 296 |
+
base = np.expand_dims(base, axis=axis)
|
| 297 |
+
if dtype is None:
|
| 298 |
+
return _nx.power(base, y)
|
| 299 |
+
return _nx.power(base, y).astype(dtype, copy=False)
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def _geomspace_dispatcher(start, stop, num=None, endpoint=None, dtype=None,
|
| 303 |
+
axis=None):
|
| 304 |
+
return (start, stop)
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
@array_function_dispatch(_geomspace_dispatcher)
|
| 308 |
+
def geomspace(start, stop, num=50, endpoint=True, dtype=None, axis=0):
|
| 309 |
+
"""
|
| 310 |
+
Return numbers spaced evenly on a log scale (a geometric progression).
|
| 311 |
+
|
| 312 |
+
This is similar to `logspace`, but with endpoints specified directly.
|
| 313 |
+
Each output sample is a constant multiple of the previous.
|
| 314 |
+
|
| 315 |
+
.. versionchanged:: 1.16.0
|
| 316 |
+
Non-scalar `start` and `stop` are now supported.
|
| 317 |
+
|
| 318 |
+
Parameters
|
| 319 |
+
----------
|
| 320 |
+
start : array_like
|
| 321 |
+
The starting value of the sequence.
|
| 322 |
+
stop : array_like
|
| 323 |
+
The final value of the sequence, unless `endpoint` is False.
|
| 324 |
+
In that case, ``num + 1`` values are spaced over the
|
| 325 |
+
interval in log-space, of which all but the last (a sequence of
|
| 326 |
+
length `num`) are returned.
|
| 327 |
+
num : integer, optional
|
| 328 |
+
Number of samples to generate. Default is 50.
|
| 329 |
+
endpoint : boolean, optional
|
| 330 |
+
If true, `stop` is the last sample. Otherwise, it is not included.
|
| 331 |
+
Default is True.
|
| 332 |
+
dtype : dtype
|
| 333 |
+
The type of the output array. If `dtype` is not given, the data type
|
| 334 |
+
is inferred from `start` and `stop`. The inferred dtype will never be
|
| 335 |
+
an integer; `float` is chosen even if the arguments would produce an
|
| 336 |
+
array of integers.
|
| 337 |
+
axis : int, optional
|
| 338 |
+
The axis in the result to store the samples. Relevant only if start
|
| 339 |
+
or stop are array-like. By default (0), the samples will be along a
|
| 340 |
+
new axis inserted at the beginning. Use -1 to get an axis at the end.
|
| 341 |
+
|
| 342 |
+
.. versionadded:: 1.16.0
|
| 343 |
+
|
| 344 |
+
Returns
|
| 345 |
+
-------
|
| 346 |
+
samples : ndarray
|
| 347 |
+
`num` samples, equally spaced on a log scale.
|
| 348 |
+
|
| 349 |
+
See Also
|
| 350 |
+
--------
|
| 351 |
+
logspace : Similar to geomspace, but with endpoints specified using log
|
| 352 |
+
and base.
|
| 353 |
+
linspace : Similar to geomspace, but with arithmetic instead of geometric
|
| 354 |
+
progression.
|
| 355 |
+
arange : Similar to linspace, with the step size specified instead of the
|
| 356 |
+
number of samples.
|
| 357 |
+
:ref:`how-to-partition`
|
| 358 |
+
|
| 359 |
+
Notes
|
| 360 |
+
-----
|
| 361 |
+
If the inputs or dtype are complex, the output will follow a logarithmic
|
| 362 |
+
spiral in the complex plane. (There are an infinite number of spirals
|
| 363 |
+
passing through two points; the output will follow the shortest such path.)
|
| 364 |
+
|
| 365 |
+
Examples
|
| 366 |
+
--------
|
| 367 |
+
>>> np.geomspace(1, 1000, num=4)
|
| 368 |
+
array([ 1., 10., 100., 1000.])
|
| 369 |
+
>>> np.geomspace(1, 1000, num=3, endpoint=False)
|
| 370 |
+
array([ 1., 10., 100.])
|
| 371 |
+
>>> np.geomspace(1, 1000, num=4, endpoint=False)
|
| 372 |
+
array([ 1. , 5.62341325, 31.6227766 , 177.827941 ])
|
| 373 |
+
>>> np.geomspace(1, 256, num=9)
|
| 374 |
+
array([ 1., 2., 4., 8., 16., 32., 64., 128., 256.])
|
| 375 |
+
|
| 376 |
+
Note that the above may not produce exact integers:
|
| 377 |
+
|
| 378 |
+
>>> np.geomspace(1, 256, num=9, dtype=int)
|
| 379 |
+
array([ 1, 2, 4, 7, 16, 32, 63, 127, 256])
|
| 380 |
+
>>> np.around(np.geomspace(1, 256, num=9)).astype(int)
|
| 381 |
+
array([ 1, 2, 4, 8, 16, 32, 64, 128, 256])
|
| 382 |
+
|
| 383 |
+
Negative, decreasing, and complex inputs are allowed:
|
| 384 |
+
|
| 385 |
+
>>> np.geomspace(1000, 1, num=4)
|
| 386 |
+
array([1000., 100., 10., 1.])
|
| 387 |
+
>>> np.geomspace(-1000, -1, num=4)
|
| 388 |
+
array([-1000., -100., -10., -1.])
|
| 389 |
+
>>> np.geomspace(1j, 1000j, num=4) # Straight line
|
| 390 |
+
array([0. +1.j, 0. +10.j, 0. +100.j, 0.+1000.j])
|
| 391 |
+
>>> np.geomspace(-1+0j, 1+0j, num=5) # Circle
|
| 392 |
+
array([-1.00000000e+00+1.22464680e-16j, -7.07106781e-01+7.07106781e-01j,
|
| 393 |
+
6.12323400e-17+1.00000000e+00j, 7.07106781e-01+7.07106781e-01j,
|
| 394 |
+
1.00000000e+00+0.00000000e+00j])
|
| 395 |
+
|
| 396 |
+
Graphical illustration of `endpoint` parameter:
|
| 397 |
+
|
| 398 |
+
>>> import matplotlib.pyplot as plt
|
| 399 |
+
>>> N = 10
|
| 400 |
+
>>> y = np.zeros(N)
|
| 401 |
+
>>> plt.semilogx(np.geomspace(1, 1000, N, endpoint=True), y + 1, 'o')
|
| 402 |
+
[<matplotlib.lines.Line2D object at 0x...>]
|
| 403 |
+
>>> plt.semilogx(np.geomspace(1, 1000, N, endpoint=False), y + 2, 'o')
|
| 404 |
+
[<matplotlib.lines.Line2D object at 0x...>]
|
| 405 |
+
>>> plt.axis([0.5, 2000, 0, 3])
|
| 406 |
+
[0.5, 2000, 0, 3]
|
| 407 |
+
>>> plt.grid(True, color='0.7', linestyle='-', which='both', axis='both')
|
| 408 |
+
>>> plt.show()
|
| 409 |
+
|
| 410 |
+
"""
|
| 411 |
+
start = asanyarray(start)
|
| 412 |
+
stop = asanyarray(stop)
|
| 413 |
+
if _nx.any(start == 0) or _nx.any(stop == 0):
|
| 414 |
+
raise ValueError('Geometric sequence cannot include zero')
|
| 415 |
+
|
| 416 |
+
dt = result_type(start, stop, float(num), _nx.zeros((), dtype))
|
| 417 |
+
if dtype is None:
|
| 418 |
+
dtype = dt
|
| 419 |
+
else:
|
| 420 |
+
# complex to dtype('complex128'), for instance
|
| 421 |
+
dtype = _nx.dtype(dtype)
|
| 422 |
+
|
| 423 |
+
# Promote both arguments to the same dtype in case, for instance, one is
|
| 424 |
+
# complex and another is negative and log would produce NaN otherwise.
|
| 425 |
+
# Copy since we may change things in-place further down.
|
| 426 |
+
start = start.astype(dt, copy=True)
|
| 427 |
+
stop = stop.astype(dt, copy=True)
|
| 428 |
+
|
| 429 |
+
out_sign = _nx.ones(_nx.broadcast(start, stop).shape, dt)
|
| 430 |
+
# Avoid negligible real or imaginary parts in output by rotating to
|
| 431 |
+
# positive real, calculating, then undoing rotation
|
| 432 |
+
if _nx.issubdtype(dt, _nx.complexfloating):
|
| 433 |
+
all_imag = (start.real == 0.) & (stop.real == 0.)
|
| 434 |
+
if _nx.any(all_imag):
|
| 435 |
+
start[all_imag] = start[all_imag].imag
|
| 436 |
+
stop[all_imag] = stop[all_imag].imag
|
| 437 |
+
out_sign[all_imag] = 1j
|
| 438 |
+
|
| 439 |
+
both_negative = (_nx.sign(start) == -1) & (_nx.sign(stop) == -1)
|
| 440 |
+
if _nx.any(both_negative):
|
| 441 |
+
_nx.negative(start, out=start, where=both_negative)
|
| 442 |
+
_nx.negative(stop, out=stop, where=both_negative)
|
| 443 |
+
_nx.negative(out_sign, out=out_sign, where=both_negative)
|
| 444 |
+
|
| 445 |
+
log_start = _nx.log10(start)
|
| 446 |
+
log_stop = _nx.log10(stop)
|
| 447 |
+
result = logspace(log_start, log_stop, num=num,
|
| 448 |
+
endpoint=endpoint, base=10.0, dtype=dtype)
|
| 449 |
+
|
| 450 |
+
# Make sure the endpoints match the start and stop arguments. This is
|
| 451 |
+
# necessary because np.exp(np.log(x)) is not necessarily equal to x.
|
| 452 |
+
if num > 0:
|
| 453 |
+
result[0] = start
|
| 454 |
+
if num > 1 and endpoint:
|
| 455 |
+
result[-1] = stop
|
| 456 |
+
|
| 457 |
+
result = out_sign * result
|
| 458 |
+
|
| 459 |
+
if axis != 0:
|
| 460 |
+
result = _nx.moveaxis(result, 0, axis)
|
| 461 |
+
|
| 462 |
+
return result.astype(dtype, copy=False)
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
def _needs_add_docstring(obj):
|
| 466 |
+
"""
|
| 467 |
+
Returns true if the only way to set the docstring of `obj` from python is
|
| 468 |
+
via add_docstring.
|
| 469 |
+
|
| 470 |
+
This function errs on the side of being overly conservative.
|
| 471 |
+
"""
|
| 472 |
+
Py_TPFLAGS_HEAPTYPE = 1 << 9
|
| 473 |
+
|
| 474 |
+
if isinstance(obj, (types.FunctionType, types.MethodType, property)):
|
| 475 |
+
return False
|
| 476 |
+
|
| 477 |
+
if isinstance(obj, type) and obj.__flags__ & Py_TPFLAGS_HEAPTYPE:
|
| 478 |
+
return False
|
| 479 |
+
|
| 480 |
+
return True
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
def _add_docstring(obj, doc, warn_on_python):
|
| 484 |
+
if warn_on_python and not _needs_add_docstring(obj):
|
| 485 |
+
warnings.warn(
|
| 486 |
+
"add_newdoc was used on a pure-python object {}. "
|
| 487 |
+
"Prefer to attach it directly to the source."
|
| 488 |
+
.format(obj),
|
| 489 |
+
UserWarning,
|
| 490 |
+
stacklevel=3)
|
| 491 |
+
try:
|
| 492 |
+
add_docstring(obj, doc)
|
| 493 |
+
except Exception:
|
| 494 |
+
pass
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
def add_newdoc(place, obj, doc, warn_on_python=True):
|
| 498 |
+
"""
|
| 499 |
+
Add documentation to an existing object, typically one defined in C
|
| 500 |
+
|
| 501 |
+
The purpose is to allow easier editing of the docstrings without requiring
|
| 502 |
+
a re-compile. This exists primarily for internal use within numpy itself.
|
| 503 |
+
|
| 504 |
+
Parameters
|
| 505 |
+
----------
|
| 506 |
+
place : str
|
| 507 |
+
The absolute name of the module to import from
|
| 508 |
+
obj : str
|
| 509 |
+
The name of the object to add documentation to, typically a class or
|
| 510 |
+
function name
|
| 511 |
+
doc : {str, Tuple[str, str], List[Tuple[str, str]]}
|
| 512 |
+
If a string, the documentation to apply to `obj`
|
| 513 |
+
|
| 514 |
+
If a tuple, then the first element is interpreted as an attribute of
|
| 515 |
+
`obj` and the second as the docstring to apply - ``(method, docstring)``
|
| 516 |
+
|
| 517 |
+
If a list, then each element of the list should be a tuple of length
|
| 518 |
+
two - ``[(method1, docstring1), (method2, docstring2), ...]``
|
| 519 |
+
warn_on_python : bool
|
| 520 |
+
If True, the default, emit `UserWarning` if this is used to attach
|
| 521 |
+
documentation to a pure-python object.
|
| 522 |
+
|
| 523 |
+
Notes
|
| 524 |
+
-----
|
| 525 |
+
This routine never raises an error if the docstring can't be written, but
|
| 526 |
+
will raise an error if the object being documented does not exist.
|
| 527 |
+
|
| 528 |
+
This routine cannot modify read-only docstrings, as appear
|
| 529 |
+
in new-style classes or built-in functions. Because this
|
| 530 |
+
routine never raises an error the caller must check manually
|
| 531 |
+
that the docstrings were changed.
|
| 532 |
+
|
| 533 |
+
Since this function grabs the ``char *`` from a c-level str object and puts
|
| 534 |
+
it into the ``tp_doc`` slot of the type of `obj`, it violates a number of
|
| 535 |
+
C-API best-practices, by:
|
| 536 |
+
|
| 537 |
+
- modifying a `PyTypeObject` after calling `PyType_Ready`
|
| 538 |
+
- calling `Py_INCREF` on the str and losing the reference, so the str
|
| 539 |
+
will never be released
|
| 540 |
+
|
| 541 |
+
If possible it should be avoided.
|
| 542 |
+
"""
|
| 543 |
+
new = getattr(__import__(place, globals(), {}, [obj]), obj)
|
| 544 |
+
if isinstance(doc, str):
|
| 545 |
+
_add_docstring(new, doc.strip(), warn_on_python)
|
| 546 |
+
elif isinstance(doc, tuple):
|
| 547 |
+
attr, docstring = doc
|
| 548 |
+
_add_docstring(getattr(new, attr), docstring.strip(), warn_on_python)
|
| 549 |
+
elif isinstance(doc, list):
|
| 550 |
+
for attr, docstring in doc:
|
| 551 |
+
_add_docstring(getattr(new, attr), docstring.strip(), warn_on_python)
|
.venv/lib/python3.11/site-packages/numpy/core/function_base.pyi
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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literal as L,
|
| 3 |
+
overload,
|
| 4 |
+
Any,
|
| 5 |
+
SupportsIndex,
|
| 6 |
+
TypeVar,
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
from numpy import floating, complexfloating, generic
|
| 10 |
+
from numpy._typing import (
|
| 11 |
+
NDArray,
|
| 12 |
+
DTypeLike,
|
| 13 |
+
_DTypeLike,
|
| 14 |
+
_ArrayLikeFloat_co,
|
| 15 |
+
_ArrayLikeComplex_co,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
_SCT = TypeVar("_SCT", bound=generic)
|
| 19 |
+
|
| 20 |
+
__all__: list[str]
|
| 21 |
+
|
| 22 |
+
@overload
|
| 23 |
+
def linspace(
|
| 24 |
+
start: _ArrayLikeFloat_co,
|
| 25 |
+
stop: _ArrayLikeFloat_co,
|
| 26 |
+
num: SupportsIndex = ...,
|
| 27 |
+
endpoint: bool = ...,
|
| 28 |
+
retstep: L[False] = ...,
|
| 29 |
+
dtype: None = ...,
|
| 30 |
+
axis: SupportsIndex = ...,
|
| 31 |
+
) -> NDArray[floating[Any]]: ...
|
| 32 |
+
@overload
|
| 33 |
+
def linspace(
|
| 34 |
+
start: _ArrayLikeComplex_co,
|
| 35 |
+
stop: _ArrayLikeComplex_co,
|
| 36 |
+
num: SupportsIndex = ...,
|
| 37 |
+
endpoint: bool = ...,
|
| 38 |
+
retstep: L[False] = ...,
|
| 39 |
+
dtype: None = ...,
|
| 40 |
+
axis: SupportsIndex = ...,
|
| 41 |
+
) -> NDArray[complexfloating[Any, Any]]: ...
|
| 42 |
+
@overload
|
| 43 |
+
def linspace(
|
| 44 |
+
start: _ArrayLikeComplex_co,
|
| 45 |
+
stop: _ArrayLikeComplex_co,
|
| 46 |
+
num: SupportsIndex = ...,
|
| 47 |
+
endpoint: bool = ...,
|
| 48 |
+
retstep: L[False] = ...,
|
| 49 |
+
dtype: _DTypeLike[_SCT] = ...,
|
| 50 |
+
axis: SupportsIndex = ...,
|
| 51 |
+
) -> NDArray[_SCT]: ...
|
| 52 |
+
@overload
|
| 53 |
+
def linspace(
|
| 54 |
+
start: _ArrayLikeComplex_co,
|
| 55 |
+
stop: _ArrayLikeComplex_co,
|
| 56 |
+
num: SupportsIndex = ...,
|
| 57 |
+
endpoint: bool = ...,
|
| 58 |
+
retstep: L[False] = ...,
|
| 59 |
+
dtype: DTypeLike = ...,
|
| 60 |
+
axis: SupportsIndex = ...,
|
| 61 |
+
) -> NDArray[Any]: ...
|
| 62 |
+
@overload
|
| 63 |
+
def linspace(
|
| 64 |
+
start: _ArrayLikeFloat_co,
|
| 65 |
+
stop: _ArrayLikeFloat_co,
|
| 66 |
+
num: SupportsIndex = ...,
|
| 67 |
+
endpoint: bool = ...,
|
| 68 |
+
retstep: L[True] = ...,
|
| 69 |
+
dtype: None = ...,
|
| 70 |
+
axis: SupportsIndex = ...,
|
| 71 |
+
) -> tuple[NDArray[floating[Any]], floating[Any]]: ...
|
| 72 |
+
@overload
|
| 73 |
+
def linspace(
|
| 74 |
+
start: _ArrayLikeComplex_co,
|
| 75 |
+
stop: _ArrayLikeComplex_co,
|
| 76 |
+
num: SupportsIndex = ...,
|
| 77 |
+
endpoint: bool = ...,
|
| 78 |
+
retstep: L[True] = ...,
|
| 79 |
+
dtype: None = ...,
|
| 80 |
+
axis: SupportsIndex = ...,
|
| 81 |
+
) -> tuple[NDArray[complexfloating[Any, Any]], complexfloating[Any, Any]]: ...
|
| 82 |
+
@overload
|
| 83 |
+
def linspace(
|
| 84 |
+
start: _ArrayLikeComplex_co,
|
| 85 |
+
stop: _ArrayLikeComplex_co,
|
| 86 |
+
num: SupportsIndex = ...,
|
| 87 |
+
endpoint: bool = ...,
|
| 88 |
+
retstep: L[True] = ...,
|
| 89 |
+
dtype: _DTypeLike[_SCT] = ...,
|
| 90 |
+
axis: SupportsIndex = ...,
|
| 91 |
+
) -> tuple[NDArray[_SCT], _SCT]: ...
|
| 92 |
+
@overload
|
| 93 |
+
def linspace(
|
| 94 |
+
start: _ArrayLikeComplex_co,
|
| 95 |
+
stop: _ArrayLikeComplex_co,
|
| 96 |
+
num: SupportsIndex = ...,
|
| 97 |
+
endpoint: bool = ...,
|
| 98 |
+
retstep: L[True] = ...,
|
| 99 |
+
dtype: DTypeLike = ...,
|
| 100 |
+
axis: SupportsIndex = ...,
|
| 101 |
+
) -> tuple[NDArray[Any], Any]: ...
|
| 102 |
+
|
| 103 |
+
@overload
|
| 104 |
+
def logspace(
|
| 105 |
+
start: _ArrayLikeFloat_co,
|
| 106 |
+
stop: _ArrayLikeFloat_co,
|
| 107 |
+
num: SupportsIndex = ...,
|
| 108 |
+
endpoint: bool = ...,
|
| 109 |
+
base: _ArrayLikeFloat_co = ...,
|
| 110 |
+
dtype: None = ...,
|
| 111 |
+
axis: SupportsIndex = ...,
|
| 112 |
+
) -> NDArray[floating[Any]]: ...
|
| 113 |
+
@overload
|
| 114 |
+
def logspace(
|
| 115 |
+
start: _ArrayLikeComplex_co,
|
| 116 |
+
stop: _ArrayLikeComplex_co,
|
| 117 |
+
num: SupportsIndex = ...,
|
| 118 |
+
endpoint: bool = ...,
|
| 119 |
+
base: _ArrayLikeComplex_co = ...,
|
| 120 |
+
dtype: None = ...,
|
| 121 |
+
axis: SupportsIndex = ...,
|
| 122 |
+
) -> NDArray[complexfloating[Any, Any]]: ...
|
| 123 |
+
@overload
|
| 124 |
+
def logspace(
|
| 125 |
+
start: _ArrayLikeComplex_co,
|
| 126 |
+
stop: _ArrayLikeComplex_co,
|
| 127 |
+
num: SupportsIndex = ...,
|
| 128 |
+
endpoint: bool = ...,
|
| 129 |
+
base: _ArrayLikeComplex_co = ...,
|
| 130 |
+
dtype: _DTypeLike[_SCT] = ...,
|
| 131 |
+
axis: SupportsIndex = ...,
|
| 132 |
+
) -> NDArray[_SCT]: ...
|
| 133 |
+
@overload
|
| 134 |
+
def logspace(
|
| 135 |
+
start: _ArrayLikeComplex_co,
|
| 136 |
+
stop: _ArrayLikeComplex_co,
|
| 137 |
+
num: SupportsIndex = ...,
|
| 138 |
+
endpoint: bool = ...,
|
| 139 |
+
base: _ArrayLikeComplex_co = ...,
|
| 140 |
+
dtype: DTypeLike = ...,
|
| 141 |
+
axis: SupportsIndex = ...,
|
| 142 |
+
) -> NDArray[Any]: ...
|
| 143 |
+
|
| 144 |
+
@overload
|
| 145 |
+
def geomspace(
|
| 146 |
+
start: _ArrayLikeFloat_co,
|
| 147 |
+
stop: _ArrayLikeFloat_co,
|
| 148 |
+
num: SupportsIndex = ...,
|
| 149 |
+
endpoint: bool = ...,
|
| 150 |
+
dtype: None = ...,
|
| 151 |
+
axis: SupportsIndex = ...,
|
| 152 |
+
) -> NDArray[floating[Any]]: ...
|
| 153 |
+
@overload
|
| 154 |
+
def geomspace(
|
| 155 |
+
start: _ArrayLikeComplex_co,
|
| 156 |
+
stop: _ArrayLikeComplex_co,
|
| 157 |
+
num: SupportsIndex = ...,
|
| 158 |
+
endpoint: bool = ...,
|
| 159 |
+
dtype: None = ...,
|
| 160 |
+
axis: SupportsIndex = ...,
|
| 161 |
+
) -> NDArray[complexfloating[Any, Any]]: ...
|
| 162 |
+
@overload
|
| 163 |
+
def geomspace(
|
| 164 |
+
start: _ArrayLikeComplex_co,
|
| 165 |
+
stop: _ArrayLikeComplex_co,
|
| 166 |
+
num: SupportsIndex = ...,
|
| 167 |
+
endpoint: bool = ...,
|
| 168 |
+
dtype: _DTypeLike[_SCT] = ...,
|
| 169 |
+
axis: SupportsIndex = ...,
|
| 170 |
+
) -> NDArray[_SCT]: ...
|
| 171 |
+
@overload
|
| 172 |
+
def geomspace(
|
| 173 |
+
start: _ArrayLikeComplex_co,
|
| 174 |
+
stop: _ArrayLikeComplex_co,
|
| 175 |
+
num: SupportsIndex = ...,
|
| 176 |
+
endpoint: bool = ...,
|
| 177 |
+
dtype: DTypeLike = ...,
|
| 178 |
+
axis: SupportsIndex = ...,
|
| 179 |
+
) -> NDArray[Any]: ...
|
| 180 |
+
|
| 181 |
+
# Re-exported to `np.lib.function_base`
|
| 182 |
+
def add_newdoc(
|
| 183 |
+
place: str,
|
| 184 |
+
obj: str,
|
| 185 |
+
doc: str | tuple[str, str] | list[tuple[str, str]],
|
| 186 |
+
warn_on_python: bool = ...,
|
| 187 |
+
) -> None: ...
|
.venv/lib/python3.11/site-packages/numpy/core/getlimits.py
ADDED
|
@@ -0,0 +1,735 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Machine limits for Float32 and Float64 and (long double) if available...
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
__all__ = ['finfo', 'iinfo']
|
| 5 |
+
|
| 6 |
+
import warnings
|
| 7 |
+
|
| 8 |
+
from .._utils import set_module
|
| 9 |
+
from ._machar import MachAr
|
| 10 |
+
from . import numeric
|
| 11 |
+
from . import numerictypes as ntypes
|
| 12 |
+
from .numeric import array, inf, NaN
|
| 13 |
+
from .umath import log10, exp2, nextafter, isnan
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _fr0(a):
|
| 17 |
+
"""fix rank-0 --> rank-1"""
|
| 18 |
+
if a.ndim == 0:
|
| 19 |
+
a = a.copy()
|
| 20 |
+
a.shape = (1,)
|
| 21 |
+
return a
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _fr1(a):
|
| 25 |
+
"""fix rank > 0 --> rank-0"""
|
| 26 |
+
if a.size == 1:
|
| 27 |
+
a = a.copy()
|
| 28 |
+
a.shape = ()
|
| 29 |
+
return a
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class MachArLike:
|
| 33 |
+
""" Object to simulate MachAr instance """
|
| 34 |
+
def __init__(self, ftype, *, eps, epsneg, huge, tiny,
|
| 35 |
+
ibeta, smallest_subnormal=None, **kwargs):
|
| 36 |
+
self.params = _MACHAR_PARAMS[ftype]
|
| 37 |
+
self.ftype = ftype
|
| 38 |
+
self.title = self.params['title']
|
| 39 |
+
# Parameter types same as for discovered MachAr object.
|
| 40 |
+
if not smallest_subnormal:
|
| 41 |
+
self._smallest_subnormal = nextafter(
|
| 42 |
+
self.ftype(0), self.ftype(1), dtype=self.ftype)
|
| 43 |
+
else:
|
| 44 |
+
self._smallest_subnormal = smallest_subnormal
|
| 45 |
+
self.epsilon = self.eps = self._float_to_float(eps)
|
| 46 |
+
self.epsneg = self._float_to_float(epsneg)
|
| 47 |
+
self.xmax = self.huge = self._float_to_float(huge)
|
| 48 |
+
self.xmin = self._float_to_float(tiny)
|
| 49 |
+
self.smallest_normal = self.tiny = self._float_to_float(tiny)
|
| 50 |
+
self.ibeta = self.params['itype'](ibeta)
|
| 51 |
+
self.__dict__.update(kwargs)
|
| 52 |
+
self.precision = int(-log10(self.eps))
|
| 53 |
+
self.resolution = self._float_to_float(
|
| 54 |
+
self._float_conv(10) ** (-self.precision))
|
| 55 |
+
self._str_eps = self._float_to_str(self.eps)
|
| 56 |
+
self._str_epsneg = self._float_to_str(self.epsneg)
|
| 57 |
+
self._str_xmin = self._float_to_str(self.xmin)
|
| 58 |
+
self._str_xmax = self._float_to_str(self.xmax)
|
| 59 |
+
self._str_resolution = self._float_to_str(self.resolution)
|
| 60 |
+
self._str_smallest_normal = self._float_to_str(self.xmin)
|
| 61 |
+
|
| 62 |
+
@property
|
| 63 |
+
def smallest_subnormal(self):
|
| 64 |
+
"""Return the value for the smallest subnormal.
|
| 65 |
+
|
| 66 |
+
Returns
|
| 67 |
+
-------
|
| 68 |
+
smallest_subnormal : float
|
| 69 |
+
value for the smallest subnormal.
|
| 70 |
+
|
| 71 |
+
Warns
|
| 72 |
+
-----
|
| 73 |
+
UserWarning
|
| 74 |
+
If the calculated value for the smallest subnormal is zero.
|
| 75 |
+
"""
|
| 76 |
+
# Check that the calculated value is not zero, in case it raises a
|
| 77 |
+
# warning.
|
| 78 |
+
value = self._smallest_subnormal
|
| 79 |
+
if self.ftype(0) == value:
|
| 80 |
+
warnings.warn(
|
| 81 |
+
'The value of the smallest subnormal for {} type '
|
| 82 |
+
'is zero.'.format(self.ftype), UserWarning, stacklevel=2)
|
| 83 |
+
|
| 84 |
+
return self._float_to_float(value)
|
| 85 |
+
|
| 86 |
+
@property
|
| 87 |
+
def _str_smallest_subnormal(self):
|
| 88 |
+
"""Return the string representation of the smallest subnormal."""
|
| 89 |
+
return self._float_to_str(self.smallest_subnormal)
|
| 90 |
+
|
| 91 |
+
def _float_to_float(self, value):
|
| 92 |
+
"""Converts float to float.
|
| 93 |
+
|
| 94 |
+
Parameters
|
| 95 |
+
----------
|
| 96 |
+
value : float
|
| 97 |
+
value to be converted.
|
| 98 |
+
"""
|
| 99 |
+
return _fr1(self._float_conv(value))
|
| 100 |
+
|
| 101 |
+
def _float_conv(self, value):
|
| 102 |
+
"""Converts float to conv.
|
| 103 |
+
|
| 104 |
+
Parameters
|
| 105 |
+
----------
|
| 106 |
+
value : float
|
| 107 |
+
value to be converted.
|
| 108 |
+
"""
|
| 109 |
+
return array([value], self.ftype)
|
| 110 |
+
|
| 111 |
+
def _float_to_str(self, value):
|
| 112 |
+
"""Converts float to str.
|
| 113 |
+
|
| 114 |
+
Parameters
|
| 115 |
+
----------
|
| 116 |
+
value : float
|
| 117 |
+
value to be converted.
|
| 118 |
+
"""
|
| 119 |
+
return self.params['fmt'] % array(_fr0(value)[0], self.ftype)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
_convert_to_float = {
|
| 123 |
+
ntypes.csingle: ntypes.single,
|
| 124 |
+
ntypes.complex_: ntypes.float_,
|
| 125 |
+
ntypes.clongfloat: ntypes.longfloat
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
# Parameters for creating MachAr / MachAr-like objects
|
| 129 |
+
_title_fmt = 'numpy {} precision floating point number'
|
| 130 |
+
_MACHAR_PARAMS = {
|
| 131 |
+
ntypes.double: dict(
|
| 132 |
+
itype = ntypes.int64,
|
| 133 |
+
fmt = '%24.16e',
|
| 134 |
+
title = _title_fmt.format('double')),
|
| 135 |
+
ntypes.single: dict(
|
| 136 |
+
itype = ntypes.int32,
|
| 137 |
+
fmt = '%15.7e',
|
| 138 |
+
title = _title_fmt.format('single')),
|
| 139 |
+
ntypes.longdouble: dict(
|
| 140 |
+
itype = ntypes.longlong,
|
| 141 |
+
fmt = '%s',
|
| 142 |
+
title = _title_fmt.format('long double')),
|
| 143 |
+
ntypes.half: dict(
|
| 144 |
+
itype = ntypes.int16,
|
| 145 |
+
fmt = '%12.5e',
|
| 146 |
+
title = _title_fmt.format('half'))}
|
| 147 |
+
|
| 148 |
+
# Key to identify the floating point type. Key is result of
|
| 149 |
+
# ftype('-0.1').newbyteorder('<').tobytes()
|
| 150 |
+
#
|
| 151 |
+
# 20230201 - use (ftype(-1.0) / ftype(10.0)).newbyteorder('<').tobytes()
|
| 152 |
+
# instead because stold may have deficiencies on some platforms.
|
| 153 |
+
# See:
|
| 154 |
+
# https://perl5.git.perl.org/perl.git/blob/3118d7d684b56cbeb702af874f4326683c45f045:/Configure
|
| 155 |
+
|
| 156 |
+
_KNOWN_TYPES = {}
|
| 157 |
+
def _register_type(machar, bytepat):
|
| 158 |
+
_KNOWN_TYPES[bytepat] = machar
|
| 159 |
+
_float_ma = {}
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def _register_known_types():
|
| 163 |
+
# Known parameters for float16
|
| 164 |
+
# See docstring of MachAr class for description of parameters.
|
| 165 |
+
f16 = ntypes.float16
|
| 166 |
+
float16_ma = MachArLike(f16,
|
| 167 |
+
machep=-10,
|
| 168 |
+
negep=-11,
|
| 169 |
+
minexp=-14,
|
| 170 |
+
maxexp=16,
|
| 171 |
+
it=10,
|
| 172 |
+
iexp=5,
|
| 173 |
+
ibeta=2,
|
| 174 |
+
irnd=5,
|
| 175 |
+
ngrd=0,
|
| 176 |
+
eps=exp2(f16(-10)),
|
| 177 |
+
epsneg=exp2(f16(-11)),
|
| 178 |
+
huge=f16(65504),
|
| 179 |
+
tiny=f16(2 ** -14))
|
| 180 |
+
_register_type(float16_ma, b'f\xae')
|
| 181 |
+
_float_ma[16] = float16_ma
|
| 182 |
+
|
| 183 |
+
# Known parameters for float32
|
| 184 |
+
f32 = ntypes.float32
|
| 185 |
+
float32_ma = MachArLike(f32,
|
| 186 |
+
machep=-23,
|
| 187 |
+
negep=-24,
|
| 188 |
+
minexp=-126,
|
| 189 |
+
maxexp=128,
|
| 190 |
+
it=23,
|
| 191 |
+
iexp=8,
|
| 192 |
+
ibeta=2,
|
| 193 |
+
irnd=5,
|
| 194 |
+
ngrd=0,
|
| 195 |
+
eps=exp2(f32(-23)),
|
| 196 |
+
epsneg=exp2(f32(-24)),
|
| 197 |
+
huge=f32((1 - 2 ** -24) * 2**128),
|
| 198 |
+
tiny=exp2(f32(-126)))
|
| 199 |
+
_register_type(float32_ma, b'\xcd\xcc\xcc\xbd')
|
| 200 |
+
_float_ma[32] = float32_ma
|
| 201 |
+
|
| 202 |
+
# Known parameters for float64
|
| 203 |
+
f64 = ntypes.float64
|
| 204 |
+
epsneg_f64 = 2.0 ** -53.0
|
| 205 |
+
tiny_f64 = 2.0 ** -1022.0
|
| 206 |
+
float64_ma = MachArLike(f64,
|
| 207 |
+
machep=-52,
|
| 208 |
+
negep=-53,
|
| 209 |
+
minexp=-1022,
|
| 210 |
+
maxexp=1024,
|
| 211 |
+
it=52,
|
| 212 |
+
iexp=11,
|
| 213 |
+
ibeta=2,
|
| 214 |
+
irnd=5,
|
| 215 |
+
ngrd=0,
|
| 216 |
+
eps=2.0 ** -52.0,
|
| 217 |
+
epsneg=epsneg_f64,
|
| 218 |
+
huge=(1.0 - epsneg_f64) / tiny_f64 * f64(4),
|
| 219 |
+
tiny=tiny_f64)
|
| 220 |
+
_register_type(float64_ma, b'\x9a\x99\x99\x99\x99\x99\xb9\xbf')
|
| 221 |
+
_float_ma[64] = float64_ma
|
| 222 |
+
|
| 223 |
+
# Known parameters for IEEE 754 128-bit binary float
|
| 224 |
+
ld = ntypes.longdouble
|
| 225 |
+
epsneg_f128 = exp2(ld(-113))
|
| 226 |
+
tiny_f128 = exp2(ld(-16382))
|
| 227 |
+
# Ignore runtime error when this is not f128
|
| 228 |
+
with numeric.errstate(all='ignore'):
|
| 229 |
+
huge_f128 = (ld(1) - epsneg_f128) / tiny_f128 * ld(4)
|
| 230 |
+
float128_ma = MachArLike(ld,
|
| 231 |
+
machep=-112,
|
| 232 |
+
negep=-113,
|
| 233 |
+
minexp=-16382,
|
| 234 |
+
maxexp=16384,
|
| 235 |
+
it=112,
|
| 236 |
+
iexp=15,
|
| 237 |
+
ibeta=2,
|
| 238 |
+
irnd=5,
|
| 239 |
+
ngrd=0,
|
| 240 |
+
eps=exp2(ld(-112)),
|
| 241 |
+
epsneg=epsneg_f128,
|
| 242 |
+
huge=huge_f128,
|
| 243 |
+
tiny=tiny_f128)
|
| 244 |
+
# IEEE 754 128-bit binary float
|
| 245 |
+
_register_type(float128_ma,
|
| 246 |
+
b'\x9a\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\xfb\xbf')
|
| 247 |
+
_float_ma[128] = float128_ma
|
| 248 |
+
|
| 249 |
+
# Known parameters for float80 (Intel 80-bit extended precision)
|
| 250 |
+
epsneg_f80 = exp2(ld(-64))
|
| 251 |
+
tiny_f80 = exp2(ld(-16382))
|
| 252 |
+
# Ignore runtime error when this is not f80
|
| 253 |
+
with numeric.errstate(all='ignore'):
|
| 254 |
+
huge_f80 = (ld(1) - epsneg_f80) / tiny_f80 * ld(4)
|
| 255 |
+
float80_ma = MachArLike(ld,
|
| 256 |
+
machep=-63,
|
| 257 |
+
negep=-64,
|
| 258 |
+
minexp=-16382,
|
| 259 |
+
maxexp=16384,
|
| 260 |
+
it=63,
|
| 261 |
+
iexp=15,
|
| 262 |
+
ibeta=2,
|
| 263 |
+
irnd=5,
|
| 264 |
+
ngrd=0,
|
| 265 |
+
eps=exp2(ld(-63)),
|
| 266 |
+
epsneg=epsneg_f80,
|
| 267 |
+
huge=huge_f80,
|
| 268 |
+
tiny=tiny_f80)
|
| 269 |
+
# float80, first 10 bytes containing actual storage
|
| 270 |
+
_register_type(float80_ma, b'\xcd\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xfb\xbf')
|
| 271 |
+
_float_ma[80] = float80_ma
|
| 272 |
+
|
| 273 |
+
# Guessed / known parameters for double double; see:
|
| 274 |
+
# https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format#Double-double_arithmetic
|
| 275 |
+
# These numbers have the same exponent range as float64, but extended number of
|
| 276 |
+
# digits in the significand.
|
| 277 |
+
huge_dd = nextafter(ld(inf), ld(0), dtype=ld)
|
| 278 |
+
# As the smallest_normal in double double is so hard to calculate we set
|
| 279 |
+
# it to NaN.
|
| 280 |
+
smallest_normal_dd = NaN
|
| 281 |
+
# Leave the same value for the smallest subnormal as double
|
| 282 |
+
smallest_subnormal_dd = ld(nextafter(0., 1.))
|
| 283 |
+
float_dd_ma = MachArLike(ld,
|
| 284 |
+
machep=-105,
|
| 285 |
+
negep=-106,
|
| 286 |
+
minexp=-1022,
|
| 287 |
+
maxexp=1024,
|
| 288 |
+
it=105,
|
| 289 |
+
iexp=11,
|
| 290 |
+
ibeta=2,
|
| 291 |
+
irnd=5,
|
| 292 |
+
ngrd=0,
|
| 293 |
+
eps=exp2(ld(-105)),
|
| 294 |
+
epsneg=exp2(ld(-106)),
|
| 295 |
+
huge=huge_dd,
|
| 296 |
+
tiny=smallest_normal_dd,
|
| 297 |
+
smallest_subnormal=smallest_subnormal_dd)
|
| 298 |
+
# double double; low, high order (e.g. PPC 64)
|
| 299 |
+
_register_type(float_dd_ma,
|
| 300 |
+
b'\x9a\x99\x99\x99\x99\x99Y<\x9a\x99\x99\x99\x99\x99\xb9\xbf')
|
| 301 |
+
# double double; high, low order (e.g. PPC 64 le)
|
| 302 |
+
_register_type(float_dd_ma,
|
| 303 |
+
b'\x9a\x99\x99\x99\x99\x99\xb9\xbf\x9a\x99\x99\x99\x99\x99Y<')
|
| 304 |
+
_float_ma['dd'] = float_dd_ma
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
def _get_machar(ftype):
|
| 308 |
+
""" Get MachAr instance or MachAr-like instance
|
| 309 |
+
|
| 310 |
+
Get parameters for floating point type, by first trying signatures of
|
| 311 |
+
various known floating point types, then, if none match, attempting to
|
| 312 |
+
identify parameters by analysis.
|
| 313 |
+
|
| 314 |
+
Parameters
|
| 315 |
+
----------
|
| 316 |
+
ftype : class
|
| 317 |
+
Numpy floating point type class (e.g. ``np.float64``)
|
| 318 |
+
|
| 319 |
+
Returns
|
| 320 |
+
-------
|
| 321 |
+
ma_like : instance of :class:`MachAr` or :class:`MachArLike`
|
| 322 |
+
Object giving floating point parameters for `ftype`.
|
| 323 |
+
|
| 324 |
+
Warns
|
| 325 |
+
-----
|
| 326 |
+
UserWarning
|
| 327 |
+
If the binary signature of the float type is not in the dictionary of
|
| 328 |
+
known float types.
|
| 329 |
+
"""
|
| 330 |
+
params = _MACHAR_PARAMS.get(ftype)
|
| 331 |
+
if params is None:
|
| 332 |
+
raise ValueError(repr(ftype))
|
| 333 |
+
# Detect known / suspected types
|
| 334 |
+
# ftype(-1.0) / ftype(10.0) is better than ftype('-0.1') because stold
|
| 335 |
+
# may be deficient
|
| 336 |
+
key = (ftype(-1.0) / ftype(10.)).newbyteorder('<').tobytes()
|
| 337 |
+
ma_like = None
|
| 338 |
+
if ftype == ntypes.longdouble:
|
| 339 |
+
# Could be 80 bit == 10 byte extended precision, where last bytes can
|
| 340 |
+
# be random garbage.
|
| 341 |
+
# Comparing first 10 bytes to pattern first to avoid branching on the
|
| 342 |
+
# random garbage.
|
| 343 |
+
ma_like = _KNOWN_TYPES.get(key[:10])
|
| 344 |
+
if ma_like is None:
|
| 345 |
+
# see if the full key is known.
|
| 346 |
+
ma_like = _KNOWN_TYPES.get(key)
|
| 347 |
+
if ma_like is None and len(key) == 16:
|
| 348 |
+
# machine limits could be f80 masquerading as np.float128,
|
| 349 |
+
# find all keys with length 16 and make new dict, but make the keys
|
| 350 |
+
# only 10 bytes long, the last bytes can be random garbage
|
| 351 |
+
_kt = {k[:10]: v for k, v in _KNOWN_TYPES.items() if len(k) == 16}
|
| 352 |
+
ma_like = _kt.get(key[:10])
|
| 353 |
+
if ma_like is not None:
|
| 354 |
+
return ma_like
|
| 355 |
+
# Fall back to parameter discovery
|
| 356 |
+
warnings.warn(
|
| 357 |
+
f'Signature {key} for {ftype} does not match any known type: '
|
| 358 |
+
'falling back to type probe function.\n'
|
| 359 |
+
'This warnings indicates broken support for the dtype!',
|
| 360 |
+
UserWarning, stacklevel=2)
|
| 361 |
+
return _discovered_machar(ftype)
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def _discovered_machar(ftype):
|
| 365 |
+
""" Create MachAr instance with found information on float types
|
| 366 |
+
|
| 367 |
+
TODO: MachAr should be retired completely ideally. We currently only
|
| 368 |
+
ever use it system with broken longdouble (valgrind, WSL).
|
| 369 |
+
"""
|
| 370 |
+
params = _MACHAR_PARAMS[ftype]
|
| 371 |
+
return MachAr(lambda v: array([v], ftype),
|
| 372 |
+
lambda v:_fr0(v.astype(params['itype']))[0],
|
| 373 |
+
lambda v:array(_fr0(v)[0], ftype),
|
| 374 |
+
lambda v: params['fmt'] % array(_fr0(v)[0], ftype),
|
| 375 |
+
params['title'])
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
@set_module('numpy')
|
| 379 |
+
class finfo:
|
| 380 |
+
"""
|
| 381 |
+
finfo(dtype)
|
| 382 |
+
|
| 383 |
+
Machine limits for floating point types.
|
| 384 |
+
|
| 385 |
+
Attributes
|
| 386 |
+
----------
|
| 387 |
+
bits : int
|
| 388 |
+
The number of bits occupied by the type.
|
| 389 |
+
dtype : dtype
|
| 390 |
+
Returns the dtype for which `finfo` returns information. For complex
|
| 391 |
+
input, the returned dtype is the associated ``float*`` dtype for its
|
| 392 |
+
real and complex components.
|
| 393 |
+
eps : float
|
| 394 |
+
The difference between 1.0 and the next smallest representable float
|
| 395 |
+
larger than 1.0. For example, for 64-bit binary floats in the IEEE-754
|
| 396 |
+
standard, ``eps = 2**-52``, approximately 2.22e-16.
|
| 397 |
+
epsneg : float
|
| 398 |
+
The difference between 1.0 and the next smallest representable float
|
| 399 |
+
less than 1.0. For example, for 64-bit binary floats in the IEEE-754
|
| 400 |
+
standard, ``epsneg = 2**-53``, approximately 1.11e-16.
|
| 401 |
+
iexp : int
|
| 402 |
+
The number of bits in the exponent portion of the floating point
|
| 403 |
+
representation.
|
| 404 |
+
machep : int
|
| 405 |
+
The exponent that yields `eps`.
|
| 406 |
+
max : floating point number of the appropriate type
|
| 407 |
+
The largest representable number.
|
| 408 |
+
maxexp : int
|
| 409 |
+
The smallest positive power of the base (2) that causes overflow.
|
| 410 |
+
min : floating point number of the appropriate type
|
| 411 |
+
The smallest representable number, typically ``-max``.
|
| 412 |
+
minexp : int
|
| 413 |
+
The most negative power of the base (2) consistent with there
|
| 414 |
+
being no leading 0's in the mantissa.
|
| 415 |
+
negep : int
|
| 416 |
+
The exponent that yields `epsneg`.
|
| 417 |
+
nexp : int
|
| 418 |
+
The number of bits in the exponent including its sign and bias.
|
| 419 |
+
nmant : int
|
| 420 |
+
The number of bits in the mantissa.
|
| 421 |
+
precision : int
|
| 422 |
+
The approximate number of decimal digits to which this kind of
|
| 423 |
+
float is precise.
|
| 424 |
+
resolution : floating point number of the appropriate type
|
| 425 |
+
The approximate decimal resolution of this type, i.e.,
|
| 426 |
+
``10**-precision``.
|
| 427 |
+
tiny : float
|
| 428 |
+
An alias for `smallest_normal`, kept for backwards compatibility.
|
| 429 |
+
smallest_normal : float
|
| 430 |
+
The smallest positive floating point number with 1 as leading bit in
|
| 431 |
+
the mantissa following IEEE-754 (see Notes).
|
| 432 |
+
smallest_subnormal : float
|
| 433 |
+
The smallest positive floating point number with 0 as leading bit in
|
| 434 |
+
the mantissa following IEEE-754.
|
| 435 |
+
|
| 436 |
+
Parameters
|
| 437 |
+
----------
|
| 438 |
+
dtype : float, dtype, or instance
|
| 439 |
+
Kind of floating point or complex floating point
|
| 440 |
+
data-type about which to get information.
|
| 441 |
+
|
| 442 |
+
See Also
|
| 443 |
+
--------
|
| 444 |
+
iinfo : The equivalent for integer data types.
|
| 445 |
+
spacing : The distance between a value and the nearest adjacent number
|
| 446 |
+
nextafter : The next floating point value after x1 towards x2
|
| 447 |
+
|
| 448 |
+
Notes
|
| 449 |
+
-----
|
| 450 |
+
For developers of NumPy: do not instantiate this at the module level.
|
| 451 |
+
The initial calculation of these parameters is expensive and negatively
|
| 452 |
+
impacts import times. These objects are cached, so calling ``finfo()``
|
| 453 |
+
repeatedly inside your functions is not a problem.
|
| 454 |
+
|
| 455 |
+
Note that ``smallest_normal`` is not actually the smallest positive
|
| 456 |
+
representable value in a NumPy floating point type. As in the IEEE-754
|
| 457 |
+
standard [1]_, NumPy floating point types make use of subnormal numbers to
|
| 458 |
+
fill the gap between 0 and ``smallest_normal``. However, subnormal numbers
|
| 459 |
+
may have significantly reduced precision [2]_.
|
| 460 |
+
|
| 461 |
+
This function can also be used for complex data types as well. If used,
|
| 462 |
+
the output will be the same as the corresponding real float type
|
| 463 |
+
(e.g. numpy.finfo(numpy.csingle) is the same as numpy.finfo(numpy.single)).
|
| 464 |
+
However, the output is true for the real and imaginary components.
|
| 465 |
+
|
| 466 |
+
References
|
| 467 |
+
----------
|
| 468 |
+
.. [1] IEEE Standard for Floating-Point Arithmetic, IEEE Std 754-2008,
|
| 469 |
+
pp.1-70, 2008, http://www.doi.org/10.1109/IEEESTD.2008.4610935
|
| 470 |
+
.. [2] Wikipedia, "Denormal Numbers",
|
| 471 |
+
https://en.wikipedia.org/wiki/Denormal_number
|
| 472 |
+
|
| 473 |
+
Examples
|
| 474 |
+
--------
|
| 475 |
+
>>> np.finfo(np.float64).dtype
|
| 476 |
+
dtype('float64')
|
| 477 |
+
>>> np.finfo(np.complex64).dtype
|
| 478 |
+
dtype('float32')
|
| 479 |
+
|
| 480 |
+
"""
|
| 481 |
+
|
| 482 |
+
_finfo_cache = {}
|
| 483 |
+
|
| 484 |
+
def __new__(cls, dtype):
|
| 485 |
+
try:
|
| 486 |
+
obj = cls._finfo_cache.get(dtype) # most common path
|
| 487 |
+
if obj is not None:
|
| 488 |
+
return obj
|
| 489 |
+
except TypeError:
|
| 490 |
+
pass
|
| 491 |
+
|
| 492 |
+
if dtype is None:
|
| 493 |
+
# Deprecated in NumPy 1.25, 2023-01-16
|
| 494 |
+
warnings.warn(
|
| 495 |
+
"finfo() dtype cannot be None. This behavior will "
|
| 496 |
+
"raise an error in the future. (Deprecated in NumPy 1.25)",
|
| 497 |
+
DeprecationWarning,
|
| 498 |
+
stacklevel=2
|
| 499 |
+
)
|
| 500 |
+
|
| 501 |
+
try:
|
| 502 |
+
dtype = numeric.dtype(dtype)
|
| 503 |
+
except TypeError:
|
| 504 |
+
# In case a float instance was given
|
| 505 |
+
dtype = numeric.dtype(type(dtype))
|
| 506 |
+
|
| 507 |
+
obj = cls._finfo_cache.get(dtype)
|
| 508 |
+
if obj is not None:
|
| 509 |
+
return obj
|
| 510 |
+
dtypes = [dtype]
|
| 511 |
+
newdtype = numeric.obj2sctype(dtype)
|
| 512 |
+
if newdtype is not dtype:
|
| 513 |
+
dtypes.append(newdtype)
|
| 514 |
+
dtype = newdtype
|
| 515 |
+
if not issubclass(dtype, numeric.inexact):
|
| 516 |
+
raise ValueError("data type %r not inexact" % (dtype))
|
| 517 |
+
obj = cls._finfo_cache.get(dtype)
|
| 518 |
+
if obj is not None:
|
| 519 |
+
return obj
|
| 520 |
+
if not issubclass(dtype, numeric.floating):
|
| 521 |
+
newdtype = _convert_to_float[dtype]
|
| 522 |
+
if newdtype is not dtype:
|
| 523 |
+
# dtype changed, for example from complex128 to float64
|
| 524 |
+
dtypes.append(newdtype)
|
| 525 |
+
dtype = newdtype
|
| 526 |
+
|
| 527 |
+
obj = cls._finfo_cache.get(dtype, None)
|
| 528 |
+
if obj is not None:
|
| 529 |
+
# the original dtype was not in the cache, but the new
|
| 530 |
+
# dtype is in the cache. we add the original dtypes to
|
| 531 |
+
# the cache and return the result
|
| 532 |
+
for dt in dtypes:
|
| 533 |
+
cls._finfo_cache[dt] = obj
|
| 534 |
+
return obj
|
| 535 |
+
obj = object.__new__(cls)._init(dtype)
|
| 536 |
+
for dt in dtypes:
|
| 537 |
+
cls._finfo_cache[dt] = obj
|
| 538 |
+
return obj
|
| 539 |
+
|
| 540 |
+
def _init(self, dtype):
|
| 541 |
+
self.dtype = numeric.dtype(dtype)
|
| 542 |
+
machar = _get_machar(dtype)
|
| 543 |
+
|
| 544 |
+
for word in ['precision', 'iexp',
|
| 545 |
+
'maxexp', 'minexp', 'negep',
|
| 546 |
+
'machep']:
|
| 547 |
+
setattr(self, word, getattr(machar, word))
|
| 548 |
+
for word in ['resolution', 'epsneg', 'smallest_subnormal']:
|
| 549 |
+
setattr(self, word, getattr(machar, word).flat[0])
|
| 550 |
+
self.bits = self.dtype.itemsize * 8
|
| 551 |
+
self.max = machar.huge.flat[0]
|
| 552 |
+
self.min = -self.max
|
| 553 |
+
self.eps = machar.eps.flat[0]
|
| 554 |
+
self.nexp = machar.iexp
|
| 555 |
+
self.nmant = machar.it
|
| 556 |
+
self._machar = machar
|
| 557 |
+
self._str_tiny = machar._str_xmin.strip()
|
| 558 |
+
self._str_max = machar._str_xmax.strip()
|
| 559 |
+
self._str_epsneg = machar._str_epsneg.strip()
|
| 560 |
+
self._str_eps = machar._str_eps.strip()
|
| 561 |
+
self._str_resolution = machar._str_resolution.strip()
|
| 562 |
+
self._str_smallest_normal = machar._str_smallest_normal.strip()
|
| 563 |
+
self._str_smallest_subnormal = machar._str_smallest_subnormal.strip()
|
| 564 |
+
return self
|
| 565 |
+
|
| 566 |
+
def __str__(self):
|
| 567 |
+
fmt = (
|
| 568 |
+
'Machine parameters for %(dtype)s\n'
|
| 569 |
+
'---------------------------------------------------------------\n'
|
| 570 |
+
'precision = %(precision)3s resolution = %(_str_resolution)s\n'
|
| 571 |
+
'machep = %(machep)6s eps = %(_str_eps)s\n'
|
| 572 |
+
'negep = %(negep)6s epsneg = %(_str_epsneg)s\n'
|
| 573 |
+
'minexp = %(minexp)6s tiny = %(_str_tiny)s\n'
|
| 574 |
+
'maxexp = %(maxexp)6s max = %(_str_max)s\n'
|
| 575 |
+
'nexp = %(nexp)6s min = -max\n'
|
| 576 |
+
'smallest_normal = %(_str_smallest_normal)s '
|
| 577 |
+
'smallest_subnormal = %(_str_smallest_subnormal)s\n'
|
| 578 |
+
'---------------------------------------------------------------\n'
|
| 579 |
+
)
|
| 580 |
+
return fmt % self.__dict__
|
| 581 |
+
|
| 582 |
+
def __repr__(self):
|
| 583 |
+
c = self.__class__.__name__
|
| 584 |
+
d = self.__dict__.copy()
|
| 585 |
+
d['klass'] = c
|
| 586 |
+
return (("%(klass)s(resolution=%(resolution)s, min=-%(_str_max)s,"
|
| 587 |
+
" max=%(_str_max)s, dtype=%(dtype)s)") % d)
|
| 588 |
+
|
| 589 |
+
@property
|
| 590 |
+
def smallest_normal(self):
|
| 591 |
+
"""Return the value for the smallest normal.
|
| 592 |
+
|
| 593 |
+
Returns
|
| 594 |
+
-------
|
| 595 |
+
smallest_normal : float
|
| 596 |
+
Value for the smallest normal.
|
| 597 |
+
|
| 598 |
+
Warns
|
| 599 |
+
-----
|
| 600 |
+
UserWarning
|
| 601 |
+
If the calculated value for the smallest normal is requested for
|
| 602 |
+
double-double.
|
| 603 |
+
"""
|
| 604 |
+
# This check is necessary because the value for smallest_normal is
|
| 605 |
+
# platform dependent for longdouble types.
|
| 606 |
+
if isnan(self._machar.smallest_normal.flat[0]):
|
| 607 |
+
warnings.warn(
|
| 608 |
+
'The value of smallest normal is undefined for double double',
|
| 609 |
+
UserWarning, stacklevel=2)
|
| 610 |
+
return self._machar.smallest_normal.flat[0]
|
| 611 |
+
|
| 612 |
+
@property
|
| 613 |
+
def tiny(self):
|
| 614 |
+
"""Return the value for tiny, alias of smallest_normal.
|
| 615 |
+
|
| 616 |
+
Returns
|
| 617 |
+
-------
|
| 618 |
+
tiny : float
|
| 619 |
+
Value for the smallest normal, alias of smallest_normal.
|
| 620 |
+
|
| 621 |
+
Warns
|
| 622 |
+
-----
|
| 623 |
+
UserWarning
|
| 624 |
+
If the calculated value for the smallest normal is requested for
|
| 625 |
+
double-double.
|
| 626 |
+
"""
|
| 627 |
+
return self.smallest_normal
|
| 628 |
+
|
| 629 |
+
|
| 630 |
+
@set_module('numpy')
|
| 631 |
+
class iinfo:
|
| 632 |
+
"""
|
| 633 |
+
iinfo(type)
|
| 634 |
+
|
| 635 |
+
Machine limits for integer types.
|
| 636 |
+
|
| 637 |
+
Attributes
|
| 638 |
+
----------
|
| 639 |
+
bits : int
|
| 640 |
+
The number of bits occupied by the type.
|
| 641 |
+
dtype : dtype
|
| 642 |
+
Returns the dtype for which `iinfo` returns information.
|
| 643 |
+
min : int
|
| 644 |
+
The smallest integer expressible by the type.
|
| 645 |
+
max : int
|
| 646 |
+
The largest integer expressible by the type.
|
| 647 |
+
|
| 648 |
+
Parameters
|
| 649 |
+
----------
|
| 650 |
+
int_type : integer type, dtype, or instance
|
| 651 |
+
The kind of integer data type to get information about.
|
| 652 |
+
|
| 653 |
+
See Also
|
| 654 |
+
--------
|
| 655 |
+
finfo : The equivalent for floating point data types.
|
| 656 |
+
|
| 657 |
+
Examples
|
| 658 |
+
--------
|
| 659 |
+
With types:
|
| 660 |
+
|
| 661 |
+
>>> ii16 = np.iinfo(np.int16)
|
| 662 |
+
>>> ii16.min
|
| 663 |
+
-32768
|
| 664 |
+
>>> ii16.max
|
| 665 |
+
32767
|
| 666 |
+
>>> ii32 = np.iinfo(np.int32)
|
| 667 |
+
>>> ii32.min
|
| 668 |
+
-2147483648
|
| 669 |
+
>>> ii32.max
|
| 670 |
+
2147483647
|
| 671 |
+
|
| 672 |
+
With instances:
|
| 673 |
+
|
| 674 |
+
>>> ii32 = np.iinfo(np.int32(10))
|
| 675 |
+
>>> ii32.min
|
| 676 |
+
-2147483648
|
| 677 |
+
>>> ii32.max
|
| 678 |
+
2147483647
|
| 679 |
+
|
| 680 |
+
"""
|
| 681 |
+
|
| 682 |
+
_min_vals = {}
|
| 683 |
+
_max_vals = {}
|
| 684 |
+
|
| 685 |
+
def __init__(self, int_type):
|
| 686 |
+
try:
|
| 687 |
+
self.dtype = numeric.dtype(int_type)
|
| 688 |
+
except TypeError:
|
| 689 |
+
self.dtype = numeric.dtype(type(int_type))
|
| 690 |
+
self.kind = self.dtype.kind
|
| 691 |
+
self.bits = self.dtype.itemsize * 8
|
| 692 |
+
self.key = "%s%d" % (self.kind, self.bits)
|
| 693 |
+
if self.kind not in 'iu':
|
| 694 |
+
raise ValueError("Invalid integer data type %r." % (self.kind,))
|
| 695 |
+
|
| 696 |
+
@property
|
| 697 |
+
def min(self):
|
| 698 |
+
"""Minimum value of given dtype."""
|
| 699 |
+
if self.kind == 'u':
|
| 700 |
+
return 0
|
| 701 |
+
else:
|
| 702 |
+
try:
|
| 703 |
+
val = iinfo._min_vals[self.key]
|
| 704 |
+
except KeyError:
|
| 705 |
+
val = int(-(1 << (self.bits-1)))
|
| 706 |
+
iinfo._min_vals[self.key] = val
|
| 707 |
+
return val
|
| 708 |
+
|
| 709 |
+
@property
|
| 710 |
+
def max(self):
|
| 711 |
+
"""Maximum value of given dtype."""
|
| 712 |
+
try:
|
| 713 |
+
val = iinfo._max_vals[self.key]
|
| 714 |
+
except KeyError:
|
| 715 |
+
if self.kind == 'u':
|
| 716 |
+
val = int((1 << self.bits) - 1)
|
| 717 |
+
else:
|
| 718 |
+
val = int((1 << (self.bits-1)) - 1)
|
| 719 |
+
iinfo._max_vals[self.key] = val
|
| 720 |
+
return val
|
| 721 |
+
|
| 722 |
+
def __str__(self):
|
| 723 |
+
"""String representation."""
|
| 724 |
+
fmt = (
|
| 725 |
+
'Machine parameters for %(dtype)s\n'
|
| 726 |
+
'---------------------------------------------------------------\n'
|
| 727 |
+
'min = %(min)s\n'
|
| 728 |
+
'max = %(max)s\n'
|
| 729 |
+
'---------------------------------------------------------------\n'
|
| 730 |
+
)
|
| 731 |
+
return fmt % {'dtype': self.dtype, 'min': self.min, 'max': self.max}
|
| 732 |
+
|
| 733 |
+
def __repr__(self):
|
| 734 |
+
return "%s(min=%s, max=%s, dtype=%s)" % (self.__class__.__name__,
|
| 735 |
+
self.min, self.max, self.dtype)
|
.venv/lib/python3.11/site-packages/numpy/core/getlimits.pyi
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from numpy import (
|
| 2 |
+
finfo as finfo,
|
| 3 |
+
iinfo as iinfo,
|
| 4 |
+
)
|
| 5 |
+
|
| 6 |
+
__all__: list[str]
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/__multiarray_api.c
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/* These pointers will be stored in the C-object for use in other
|
| 3 |
+
extension modules
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
void *PyArray_API[] = {
|
| 7 |
+
(void *) PyArray_GetNDArrayCVersion,
|
| 8 |
+
(void *) &PyBigArray_Type,
|
| 9 |
+
(void *) &PyArray_Type,
|
| 10 |
+
(void *) &PyArrayDescr_Type,
|
| 11 |
+
(void *) &PyArrayFlags_Type,
|
| 12 |
+
(void *) &PyArrayIter_Type,
|
| 13 |
+
(void *) &PyArrayMultiIter_Type,
|
| 14 |
+
(int *) &NPY_NUMUSERTYPES,
|
| 15 |
+
(void *) &PyBoolArrType_Type,
|
| 16 |
+
(void *) &_PyArrayScalar_BoolValues,
|
| 17 |
+
(void *) &PyGenericArrType_Type,
|
| 18 |
+
(void *) &PyNumberArrType_Type,
|
| 19 |
+
(void *) &PyIntegerArrType_Type,
|
| 20 |
+
(void *) &PySignedIntegerArrType_Type,
|
| 21 |
+
(void *) &PyUnsignedIntegerArrType_Type,
|
| 22 |
+
(void *) &PyInexactArrType_Type,
|
| 23 |
+
(void *) &PyFloatingArrType_Type,
|
| 24 |
+
(void *) &PyComplexFloatingArrType_Type,
|
| 25 |
+
(void *) &PyFlexibleArrType_Type,
|
| 26 |
+
(void *) &PyCharacterArrType_Type,
|
| 27 |
+
(void *) &PyByteArrType_Type,
|
| 28 |
+
(void *) &PyShortArrType_Type,
|
| 29 |
+
(void *) &PyIntArrType_Type,
|
| 30 |
+
(void *) &PyLongArrType_Type,
|
| 31 |
+
(void *) &PyLongLongArrType_Type,
|
| 32 |
+
(void *) &PyUByteArrType_Type,
|
| 33 |
+
(void *) &PyUShortArrType_Type,
|
| 34 |
+
(void *) &PyUIntArrType_Type,
|
| 35 |
+
(void *) &PyULongArrType_Type,
|
| 36 |
+
(void *) &PyULongLongArrType_Type,
|
| 37 |
+
(void *) &PyFloatArrType_Type,
|
| 38 |
+
(void *) &PyDoubleArrType_Type,
|
| 39 |
+
(void *) &PyLongDoubleArrType_Type,
|
| 40 |
+
(void *) &PyCFloatArrType_Type,
|
| 41 |
+
(void *) &PyCDoubleArrType_Type,
|
| 42 |
+
(void *) &PyCLongDoubleArrType_Type,
|
| 43 |
+
(void *) &PyObjectArrType_Type,
|
| 44 |
+
(void *) &PyStringArrType_Type,
|
| 45 |
+
(void *) &PyUnicodeArrType_Type,
|
| 46 |
+
(void *) &PyVoidArrType_Type,
|
| 47 |
+
(void *) PyArray_SetNumericOps,
|
| 48 |
+
(void *) PyArray_GetNumericOps,
|
| 49 |
+
(void *) PyArray_INCREF,
|
| 50 |
+
(void *) PyArray_XDECREF,
|
| 51 |
+
(void *) PyArray_SetStringFunction,
|
| 52 |
+
(void *) PyArray_DescrFromType,
|
| 53 |
+
(void *) PyArray_TypeObjectFromType,
|
| 54 |
+
(void *) PyArray_Zero,
|
| 55 |
+
(void *) PyArray_One,
|
| 56 |
+
(void *) PyArray_CastToType,
|
| 57 |
+
(void *) PyArray_CastTo,
|
| 58 |
+
(void *) PyArray_CastAnyTo,
|
| 59 |
+
(void *) PyArray_CanCastSafely,
|
| 60 |
+
(void *) PyArray_CanCastTo,
|
| 61 |
+
(void *) PyArray_ObjectType,
|
| 62 |
+
(void *) PyArray_DescrFromObject,
|
| 63 |
+
(void *) PyArray_ConvertToCommonType,
|
| 64 |
+
(void *) PyArray_DescrFromScalar,
|
| 65 |
+
(void *) PyArray_DescrFromTypeObject,
|
| 66 |
+
(void *) PyArray_Size,
|
| 67 |
+
(void *) PyArray_Scalar,
|
| 68 |
+
(void *) PyArray_FromScalar,
|
| 69 |
+
(void *) PyArray_ScalarAsCtype,
|
| 70 |
+
(void *) PyArray_CastScalarToCtype,
|
| 71 |
+
(void *) PyArray_CastScalarDirect,
|
| 72 |
+
(void *) PyArray_ScalarFromObject,
|
| 73 |
+
(void *) PyArray_GetCastFunc,
|
| 74 |
+
(void *) PyArray_FromDims,
|
| 75 |
+
(void *) PyArray_FromDimsAndDataAndDescr,
|
| 76 |
+
(void *) PyArray_FromAny,
|
| 77 |
+
(void *) PyArray_EnsureArray,
|
| 78 |
+
(void *) PyArray_EnsureAnyArray,
|
| 79 |
+
(void *) PyArray_FromFile,
|
| 80 |
+
(void *) PyArray_FromString,
|
| 81 |
+
(void *) PyArray_FromBuffer,
|
| 82 |
+
(void *) PyArray_FromIter,
|
| 83 |
+
(void *) PyArray_Return,
|
| 84 |
+
(void *) PyArray_GetField,
|
| 85 |
+
(void *) PyArray_SetField,
|
| 86 |
+
(void *) PyArray_Byteswap,
|
| 87 |
+
(void *) PyArray_Resize,
|
| 88 |
+
(void *) PyArray_MoveInto,
|
| 89 |
+
(void *) PyArray_CopyInto,
|
| 90 |
+
(void *) PyArray_CopyAnyInto,
|
| 91 |
+
(void *) PyArray_CopyObject,
|
| 92 |
+
(void *) PyArray_NewCopy,
|
| 93 |
+
(void *) PyArray_ToList,
|
| 94 |
+
(void *) PyArray_ToString,
|
| 95 |
+
(void *) PyArray_ToFile,
|
| 96 |
+
(void *) PyArray_Dump,
|
| 97 |
+
(void *) PyArray_Dumps,
|
| 98 |
+
(void *) PyArray_ValidType,
|
| 99 |
+
(void *) PyArray_UpdateFlags,
|
| 100 |
+
(void *) PyArray_New,
|
| 101 |
+
(void *) PyArray_NewFromDescr,
|
| 102 |
+
(void *) PyArray_DescrNew,
|
| 103 |
+
(void *) PyArray_DescrNewFromType,
|
| 104 |
+
(void *) PyArray_GetPriority,
|
| 105 |
+
(void *) PyArray_IterNew,
|
| 106 |
+
(void *) PyArray_MultiIterNew,
|
| 107 |
+
(void *) PyArray_PyIntAsInt,
|
| 108 |
+
(void *) PyArray_PyIntAsIntp,
|
| 109 |
+
(void *) PyArray_Broadcast,
|
| 110 |
+
(void *) PyArray_FillObjectArray,
|
| 111 |
+
(void *) PyArray_FillWithScalar,
|
| 112 |
+
(void *) PyArray_CheckStrides,
|
| 113 |
+
(void *) PyArray_DescrNewByteorder,
|
| 114 |
+
(void *) PyArray_IterAllButAxis,
|
| 115 |
+
(void *) PyArray_CheckFromAny,
|
| 116 |
+
(void *) PyArray_FromArray,
|
| 117 |
+
(void *) PyArray_FromInterface,
|
| 118 |
+
(void *) PyArray_FromStructInterface,
|
| 119 |
+
(void *) PyArray_FromArrayAttr,
|
| 120 |
+
(void *) PyArray_ScalarKind,
|
| 121 |
+
(void *) PyArray_CanCoerceScalar,
|
| 122 |
+
(void *) PyArray_NewFlagsObject,
|
| 123 |
+
(void *) PyArray_CanCastScalar,
|
| 124 |
+
(void *) PyArray_CompareUCS4,
|
| 125 |
+
(void *) PyArray_RemoveSmallest,
|
| 126 |
+
(void *) PyArray_ElementStrides,
|
| 127 |
+
(void *) PyArray_Item_INCREF,
|
| 128 |
+
(void *) PyArray_Item_XDECREF,
|
| 129 |
+
(void *) PyArray_FieldNames,
|
| 130 |
+
(void *) PyArray_Transpose,
|
| 131 |
+
(void *) PyArray_TakeFrom,
|
| 132 |
+
(void *) PyArray_PutTo,
|
| 133 |
+
(void *) PyArray_PutMask,
|
| 134 |
+
(void *) PyArray_Repeat,
|
| 135 |
+
(void *) PyArray_Choose,
|
| 136 |
+
(void *) PyArray_Sort,
|
| 137 |
+
(void *) PyArray_ArgSort,
|
| 138 |
+
(void *) PyArray_SearchSorted,
|
| 139 |
+
(void *) PyArray_ArgMax,
|
| 140 |
+
(void *) PyArray_ArgMin,
|
| 141 |
+
(void *) PyArray_Reshape,
|
| 142 |
+
(void *) PyArray_Newshape,
|
| 143 |
+
(void *) PyArray_Squeeze,
|
| 144 |
+
(void *) PyArray_View,
|
| 145 |
+
(void *) PyArray_SwapAxes,
|
| 146 |
+
(void *) PyArray_Max,
|
| 147 |
+
(void *) PyArray_Min,
|
| 148 |
+
(void *) PyArray_Ptp,
|
| 149 |
+
(void *) PyArray_Mean,
|
| 150 |
+
(void *) PyArray_Trace,
|
| 151 |
+
(void *) PyArray_Diagonal,
|
| 152 |
+
(void *) PyArray_Clip,
|
| 153 |
+
(void *) PyArray_Conjugate,
|
| 154 |
+
(void *) PyArray_Nonzero,
|
| 155 |
+
(void *) PyArray_Std,
|
| 156 |
+
(void *) PyArray_Sum,
|
| 157 |
+
(void *) PyArray_CumSum,
|
| 158 |
+
(void *) PyArray_Prod,
|
| 159 |
+
(void *) PyArray_CumProd,
|
| 160 |
+
(void *) PyArray_All,
|
| 161 |
+
(void *) PyArray_Any,
|
| 162 |
+
(void *) PyArray_Compress,
|
| 163 |
+
(void *) PyArray_Flatten,
|
| 164 |
+
(void *) PyArray_Ravel,
|
| 165 |
+
(void *) PyArray_MultiplyList,
|
| 166 |
+
(void *) PyArray_MultiplyIntList,
|
| 167 |
+
(void *) PyArray_GetPtr,
|
| 168 |
+
(void *) PyArray_CompareLists,
|
| 169 |
+
(void *) PyArray_AsCArray,
|
| 170 |
+
(void *) PyArray_As1D,
|
| 171 |
+
(void *) PyArray_As2D,
|
| 172 |
+
(void *) PyArray_Free,
|
| 173 |
+
(void *) PyArray_Converter,
|
| 174 |
+
(void *) PyArray_IntpFromSequence,
|
| 175 |
+
(void *) PyArray_Concatenate,
|
| 176 |
+
(void *) PyArray_InnerProduct,
|
| 177 |
+
(void *) PyArray_MatrixProduct,
|
| 178 |
+
(void *) PyArray_CopyAndTranspose,
|
| 179 |
+
(void *) PyArray_Correlate,
|
| 180 |
+
(void *) PyArray_TypestrConvert,
|
| 181 |
+
(void *) PyArray_DescrConverter,
|
| 182 |
+
(void *) PyArray_DescrConverter2,
|
| 183 |
+
(void *) PyArray_IntpConverter,
|
| 184 |
+
(void *) PyArray_BufferConverter,
|
| 185 |
+
(void *) PyArray_AxisConverter,
|
| 186 |
+
(void *) PyArray_BoolConverter,
|
| 187 |
+
(void *) PyArray_ByteorderConverter,
|
| 188 |
+
(void *) PyArray_OrderConverter,
|
| 189 |
+
(void *) PyArray_EquivTypes,
|
| 190 |
+
(void *) PyArray_Zeros,
|
| 191 |
+
(void *) PyArray_Empty,
|
| 192 |
+
(void *) PyArray_Where,
|
| 193 |
+
(void *) PyArray_Arange,
|
| 194 |
+
(void *) PyArray_ArangeObj,
|
| 195 |
+
(void *) PyArray_SortkindConverter,
|
| 196 |
+
(void *) PyArray_LexSort,
|
| 197 |
+
(void *) PyArray_Round,
|
| 198 |
+
(void *) PyArray_EquivTypenums,
|
| 199 |
+
(void *) PyArray_RegisterDataType,
|
| 200 |
+
(void *) PyArray_RegisterCastFunc,
|
| 201 |
+
(void *) PyArray_RegisterCanCast,
|
| 202 |
+
(void *) PyArray_InitArrFuncs,
|
| 203 |
+
(void *) PyArray_IntTupleFromIntp,
|
| 204 |
+
(void *) PyArray_TypeNumFromName,
|
| 205 |
+
(void *) PyArray_ClipmodeConverter,
|
| 206 |
+
(void *) PyArray_OutputConverter,
|
| 207 |
+
(void *) PyArray_BroadcastToShape,
|
| 208 |
+
(void *) _PyArray_SigintHandler,
|
| 209 |
+
(void *) _PyArray_GetSigintBuf,
|
| 210 |
+
(void *) PyArray_DescrAlignConverter,
|
| 211 |
+
(void *) PyArray_DescrAlignConverter2,
|
| 212 |
+
(void *) PyArray_SearchsideConverter,
|
| 213 |
+
(void *) PyArray_CheckAxis,
|
| 214 |
+
(void *) PyArray_OverflowMultiplyList,
|
| 215 |
+
(void *) PyArray_CompareString,
|
| 216 |
+
(void *) PyArray_MultiIterFromObjects,
|
| 217 |
+
(void *) PyArray_GetEndianness,
|
| 218 |
+
(void *) PyArray_GetNDArrayCFeatureVersion,
|
| 219 |
+
(void *) PyArray_Correlate2,
|
| 220 |
+
(void *) PyArray_NeighborhoodIterNew,
|
| 221 |
+
(void *) &PyTimeIntegerArrType_Type,
|
| 222 |
+
(void *) &PyDatetimeArrType_Type,
|
| 223 |
+
(void *) &PyTimedeltaArrType_Type,
|
| 224 |
+
(void *) &PyHalfArrType_Type,
|
| 225 |
+
(void *) &NpyIter_Type,
|
| 226 |
+
(void *) PyArray_SetDatetimeParseFunction,
|
| 227 |
+
(void *) PyArray_DatetimeToDatetimeStruct,
|
| 228 |
+
(void *) PyArray_TimedeltaToTimedeltaStruct,
|
| 229 |
+
(void *) PyArray_DatetimeStructToDatetime,
|
| 230 |
+
(void *) PyArray_TimedeltaStructToTimedelta,
|
| 231 |
+
(void *) NpyIter_New,
|
| 232 |
+
(void *) NpyIter_MultiNew,
|
| 233 |
+
(void *) NpyIter_AdvancedNew,
|
| 234 |
+
(void *) NpyIter_Copy,
|
| 235 |
+
(void *) NpyIter_Deallocate,
|
| 236 |
+
(void *) NpyIter_HasDelayedBufAlloc,
|
| 237 |
+
(void *) NpyIter_HasExternalLoop,
|
| 238 |
+
(void *) NpyIter_EnableExternalLoop,
|
| 239 |
+
(void *) NpyIter_GetInnerStrideArray,
|
| 240 |
+
(void *) NpyIter_GetInnerLoopSizePtr,
|
| 241 |
+
(void *) NpyIter_Reset,
|
| 242 |
+
(void *) NpyIter_ResetBasePointers,
|
| 243 |
+
(void *) NpyIter_ResetToIterIndexRange,
|
| 244 |
+
(void *) NpyIter_GetNDim,
|
| 245 |
+
(void *) NpyIter_GetNOp,
|
| 246 |
+
(void *) NpyIter_GetIterNext,
|
| 247 |
+
(void *) NpyIter_GetIterSize,
|
| 248 |
+
(void *) NpyIter_GetIterIndexRange,
|
| 249 |
+
(void *) NpyIter_GetIterIndex,
|
| 250 |
+
(void *) NpyIter_GotoIterIndex,
|
| 251 |
+
(void *) NpyIter_HasMultiIndex,
|
| 252 |
+
(void *) NpyIter_GetShape,
|
| 253 |
+
(void *) NpyIter_GetGetMultiIndex,
|
| 254 |
+
(void *) NpyIter_GotoMultiIndex,
|
| 255 |
+
(void *) NpyIter_RemoveMultiIndex,
|
| 256 |
+
(void *) NpyIter_HasIndex,
|
| 257 |
+
(void *) NpyIter_IsBuffered,
|
| 258 |
+
(void *) NpyIter_IsGrowInner,
|
| 259 |
+
(void *) NpyIter_GetBufferSize,
|
| 260 |
+
(void *) NpyIter_GetIndexPtr,
|
| 261 |
+
(void *) NpyIter_GotoIndex,
|
| 262 |
+
(void *) NpyIter_GetDataPtrArray,
|
| 263 |
+
(void *) NpyIter_GetDescrArray,
|
| 264 |
+
(void *) NpyIter_GetOperandArray,
|
| 265 |
+
(void *) NpyIter_GetIterView,
|
| 266 |
+
(void *) NpyIter_GetReadFlags,
|
| 267 |
+
(void *) NpyIter_GetWriteFlags,
|
| 268 |
+
(void *) NpyIter_DebugPrint,
|
| 269 |
+
(void *) NpyIter_IterationNeedsAPI,
|
| 270 |
+
(void *) NpyIter_GetInnerFixedStrideArray,
|
| 271 |
+
(void *) NpyIter_RemoveAxis,
|
| 272 |
+
(void *) NpyIter_GetAxisStrideArray,
|
| 273 |
+
(void *) NpyIter_RequiresBuffering,
|
| 274 |
+
(void *) NpyIter_GetInitialDataPtrArray,
|
| 275 |
+
(void *) NpyIter_CreateCompatibleStrides,
|
| 276 |
+
(void *) PyArray_CastingConverter,
|
| 277 |
+
(void *) PyArray_CountNonzero,
|
| 278 |
+
(void *) PyArray_PromoteTypes,
|
| 279 |
+
(void *) PyArray_MinScalarType,
|
| 280 |
+
(void *) PyArray_ResultType,
|
| 281 |
+
(void *) PyArray_CanCastArrayTo,
|
| 282 |
+
(void *) PyArray_CanCastTypeTo,
|
| 283 |
+
(void *) PyArray_EinsteinSum,
|
| 284 |
+
(void *) PyArray_NewLikeArray,
|
| 285 |
+
(void *) PyArray_GetArrayParamsFromObject,
|
| 286 |
+
(void *) PyArray_ConvertClipmodeSequence,
|
| 287 |
+
(void *) PyArray_MatrixProduct2,
|
| 288 |
+
(void *) NpyIter_IsFirstVisit,
|
| 289 |
+
(void *) PyArray_SetBaseObject,
|
| 290 |
+
(void *) PyArray_CreateSortedStridePerm,
|
| 291 |
+
(void *) PyArray_RemoveAxesInPlace,
|
| 292 |
+
(void *) PyArray_DebugPrint,
|
| 293 |
+
(void *) PyArray_FailUnlessWriteable,
|
| 294 |
+
(void *) PyArray_SetUpdateIfCopyBase,
|
| 295 |
+
(void *) PyDataMem_NEW,
|
| 296 |
+
(void *) PyDataMem_FREE,
|
| 297 |
+
(void *) PyDataMem_RENEW,
|
| 298 |
+
(void *) PyDataMem_SetEventHook,
|
| 299 |
+
(NPY_CASTING *) &NPY_DEFAULT_ASSIGN_CASTING,
|
| 300 |
+
(void *) PyArray_MapIterSwapAxes,
|
| 301 |
+
(void *) PyArray_MapIterArray,
|
| 302 |
+
(void *) PyArray_MapIterNext,
|
| 303 |
+
(void *) PyArray_Partition,
|
| 304 |
+
(void *) PyArray_ArgPartition,
|
| 305 |
+
(void *) PyArray_SelectkindConverter,
|
| 306 |
+
(void *) PyDataMem_NEW_ZEROED,
|
| 307 |
+
(void *) PyArray_CheckAnyScalarExact,
|
| 308 |
+
(void *) PyArray_MapIterArrayCopyIfOverlap,
|
| 309 |
+
(void *) PyArray_ResolveWritebackIfCopy,
|
| 310 |
+
(void *) PyArray_SetWritebackIfCopyBase,
|
| 311 |
+
(void *) PyDataMem_SetHandler,
|
| 312 |
+
(void *) PyDataMem_GetHandler,
|
| 313 |
+
(PyObject* *) &PyDataMem_DefaultHandler
|
| 314 |
+
};
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/__multiarray_api.h
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#if defined(_MULTIARRAYMODULE) || defined(WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE)
|
| 3 |
+
|
| 4 |
+
typedef struct {
|
| 5 |
+
PyObject_HEAD
|
| 6 |
+
npy_bool obval;
|
| 7 |
+
} PyBoolScalarObject;
|
| 8 |
+
|
| 9 |
+
extern NPY_NO_EXPORT PyTypeObject PyArrayMapIter_Type;
|
| 10 |
+
extern NPY_NO_EXPORT PyTypeObject PyArrayNeighborhoodIter_Type;
|
| 11 |
+
extern NPY_NO_EXPORT PyBoolScalarObject _PyArrayScalar_BoolValues[2];
|
| 12 |
+
|
| 13 |
+
NPY_NO_EXPORT unsigned int PyArray_GetNDArrayCVersion \
|
| 14 |
+
(void);
|
| 15 |
+
extern NPY_NO_EXPORT PyTypeObject PyBigArray_Type;
|
| 16 |
+
|
| 17 |
+
extern NPY_NO_EXPORT PyTypeObject PyArray_Type;
|
| 18 |
+
|
| 19 |
+
extern NPY_NO_EXPORT PyArray_DTypeMeta PyArrayDescr_TypeFull;
|
| 20 |
+
#define PyArrayDescr_Type (*(PyTypeObject *)(&PyArrayDescr_TypeFull))
|
| 21 |
+
|
| 22 |
+
extern NPY_NO_EXPORT PyTypeObject PyArrayFlags_Type;
|
| 23 |
+
|
| 24 |
+
extern NPY_NO_EXPORT PyTypeObject PyArrayIter_Type;
|
| 25 |
+
|
| 26 |
+
extern NPY_NO_EXPORT PyTypeObject PyArrayMultiIter_Type;
|
| 27 |
+
|
| 28 |
+
extern NPY_NO_EXPORT int NPY_NUMUSERTYPES;
|
| 29 |
+
|
| 30 |
+
extern NPY_NO_EXPORT PyTypeObject PyBoolArrType_Type;
|
| 31 |
+
|
| 32 |
+
extern NPY_NO_EXPORT PyBoolScalarObject _PyArrayScalar_BoolValues[2];
|
| 33 |
+
|
| 34 |
+
extern NPY_NO_EXPORT PyTypeObject PyGenericArrType_Type;
|
| 35 |
+
|
| 36 |
+
extern NPY_NO_EXPORT PyTypeObject PyNumberArrType_Type;
|
| 37 |
+
|
| 38 |
+
extern NPY_NO_EXPORT PyTypeObject PyIntegerArrType_Type;
|
| 39 |
+
|
| 40 |
+
extern NPY_NO_EXPORT PyTypeObject PySignedIntegerArrType_Type;
|
| 41 |
+
|
| 42 |
+
extern NPY_NO_EXPORT PyTypeObject PyUnsignedIntegerArrType_Type;
|
| 43 |
+
|
| 44 |
+
extern NPY_NO_EXPORT PyTypeObject PyInexactArrType_Type;
|
| 45 |
+
|
| 46 |
+
extern NPY_NO_EXPORT PyTypeObject PyFloatingArrType_Type;
|
| 47 |
+
|
| 48 |
+
extern NPY_NO_EXPORT PyTypeObject PyComplexFloatingArrType_Type;
|
| 49 |
+
|
| 50 |
+
extern NPY_NO_EXPORT PyTypeObject PyFlexibleArrType_Type;
|
| 51 |
+
|
| 52 |
+
extern NPY_NO_EXPORT PyTypeObject PyCharacterArrType_Type;
|
| 53 |
+
|
| 54 |
+
extern NPY_NO_EXPORT PyTypeObject PyByteArrType_Type;
|
| 55 |
+
|
| 56 |
+
extern NPY_NO_EXPORT PyTypeObject PyShortArrType_Type;
|
| 57 |
+
|
| 58 |
+
extern NPY_NO_EXPORT PyTypeObject PyIntArrType_Type;
|
| 59 |
+
|
| 60 |
+
extern NPY_NO_EXPORT PyTypeObject PyLongArrType_Type;
|
| 61 |
+
|
| 62 |
+
extern NPY_NO_EXPORT PyTypeObject PyLongLongArrType_Type;
|
| 63 |
+
|
| 64 |
+
extern NPY_NO_EXPORT PyTypeObject PyUByteArrType_Type;
|
| 65 |
+
|
| 66 |
+
extern NPY_NO_EXPORT PyTypeObject PyUShortArrType_Type;
|
| 67 |
+
|
| 68 |
+
extern NPY_NO_EXPORT PyTypeObject PyUIntArrType_Type;
|
| 69 |
+
|
| 70 |
+
extern NPY_NO_EXPORT PyTypeObject PyULongArrType_Type;
|
| 71 |
+
|
| 72 |
+
extern NPY_NO_EXPORT PyTypeObject PyULongLongArrType_Type;
|
| 73 |
+
|
| 74 |
+
extern NPY_NO_EXPORT PyTypeObject PyFloatArrType_Type;
|
| 75 |
+
|
| 76 |
+
extern NPY_NO_EXPORT PyTypeObject PyDoubleArrType_Type;
|
| 77 |
+
|
| 78 |
+
extern NPY_NO_EXPORT PyTypeObject PyLongDoubleArrType_Type;
|
| 79 |
+
|
| 80 |
+
extern NPY_NO_EXPORT PyTypeObject PyCFloatArrType_Type;
|
| 81 |
+
|
| 82 |
+
extern NPY_NO_EXPORT PyTypeObject PyCDoubleArrType_Type;
|
| 83 |
+
|
| 84 |
+
extern NPY_NO_EXPORT PyTypeObject PyCLongDoubleArrType_Type;
|
| 85 |
+
|
| 86 |
+
extern NPY_NO_EXPORT PyTypeObject PyObjectArrType_Type;
|
| 87 |
+
|
| 88 |
+
extern NPY_NO_EXPORT PyTypeObject PyStringArrType_Type;
|
| 89 |
+
|
| 90 |
+
extern NPY_NO_EXPORT PyTypeObject PyUnicodeArrType_Type;
|
| 91 |
+
|
| 92 |
+
extern NPY_NO_EXPORT PyTypeObject PyVoidArrType_Type;
|
| 93 |
+
|
| 94 |
+
NPY_NO_EXPORT int PyArray_SetNumericOps \
|
| 95 |
+
(PyObject *);
|
| 96 |
+
NPY_NO_EXPORT PyObject * PyArray_GetNumericOps \
|
| 97 |
+
(void);
|
| 98 |
+
NPY_NO_EXPORT int PyArray_INCREF \
|
| 99 |
+
(PyArrayObject *);
|
| 100 |
+
NPY_NO_EXPORT int PyArray_XDECREF \
|
| 101 |
+
(PyArrayObject *);
|
| 102 |
+
NPY_NO_EXPORT void PyArray_SetStringFunction \
|
| 103 |
+
(PyObject *, int);
|
| 104 |
+
NPY_NO_EXPORT PyArray_Descr * PyArray_DescrFromType \
|
| 105 |
+
(int);
|
| 106 |
+
NPY_NO_EXPORT PyObject * PyArray_TypeObjectFromType \
|
| 107 |
+
(int);
|
| 108 |
+
NPY_NO_EXPORT char * PyArray_Zero \
|
| 109 |
+
(PyArrayObject *);
|
| 110 |
+
NPY_NO_EXPORT char * PyArray_One \
|
| 111 |
+
(PyArrayObject *);
|
| 112 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_CastToType \
|
| 113 |
+
(PyArrayObject *, PyArray_Descr *, int);
|
| 114 |
+
NPY_NO_EXPORT int PyArray_CastTo \
|
| 115 |
+
(PyArrayObject *, PyArrayObject *);
|
| 116 |
+
NPY_NO_EXPORT int PyArray_CastAnyTo \
|
| 117 |
+
(PyArrayObject *, PyArrayObject *);
|
| 118 |
+
NPY_NO_EXPORT int PyArray_CanCastSafely \
|
| 119 |
+
(int, int);
|
| 120 |
+
NPY_NO_EXPORT npy_bool PyArray_CanCastTo \
|
| 121 |
+
(PyArray_Descr *, PyArray_Descr *);
|
| 122 |
+
NPY_NO_EXPORT int PyArray_ObjectType \
|
| 123 |
+
(PyObject *, int);
|
| 124 |
+
NPY_NO_EXPORT PyArray_Descr * PyArray_DescrFromObject \
|
| 125 |
+
(PyObject *, PyArray_Descr *);
|
| 126 |
+
NPY_NO_EXPORT PyArrayObject ** PyArray_ConvertToCommonType \
|
| 127 |
+
(PyObject *, int *);
|
| 128 |
+
NPY_NO_EXPORT PyArray_Descr * PyArray_DescrFromScalar \
|
| 129 |
+
(PyObject *);
|
| 130 |
+
NPY_NO_EXPORT PyArray_Descr * PyArray_DescrFromTypeObject \
|
| 131 |
+
(PyObject *);
|
| 132 |
+
NPY_NO_EXPORT npy_intp PyArray_Size \
|
| 133 |
+
(PyObject *);
|
| 134 |
+
NPY_NO_EXPORT PyObject * PyArray_Scalar \
|
| 135 |
+
(void *, PyArray_Descr *, PyObject *);
|
| 136 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromScalar \
|
| 137 |
+
(PyObject *, PyArray_Descr *);
|
| 138 |
+
NPY_NO_EXPORT void PyArray_ScalarAsCtype \
|
| 139 |
+
(PyObject *, void *);
|
| 140 |
+
NPY_NO_EXPORT int PyArray_CastScalarToCtype \
|
| 141 |
+
(PyObject *, void *, PyArray_Descr *);
|
| 142 |
+
NPY_NO_EXPORT int PyArray_CastScalarDirect \
|
| 143 |
+
(PyObject *, PyArray_Descr *, void *, int);
|
| 144 |
+
NPY_NO_EXPORT PyObject * PyArray_ScalarFromObject \
|
| 145 |
+
(PyObject *);
|
| 146 |
+
NPY_NO_EXPORT PyArray_VectorUnaryFunc * PyArray_GetCastFunc \
|
| 147 |
+
(PyArray_Descr *, int);
|
| 148 |
+
NPY_NO_EXPORT PyObject * PyArray_FromDims \
|
| 149 |
+
(int NPY_UNUSED(nd), int *NPY_UNUSED(d), int NPY_UNUSED(type));
|
| 150 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_FromDimsAndDataAndDescr \
|
| 151 |
+
(int NPY_UNUSED(nd), int *NPY_UNUSED(d), PyArray_Descr *, char *NPY_UNUSED(data));
|
| 152 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromAny \
|
| 153 |
+
(PyObject *, PyArray_Descr *, int, int, int, PyObject *);
|
| 154 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(1) PyObject * PyArray_EnsureArray \
|
| 155 |
+
(PyObject *);
|
| 156 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(1) PyObject * PyArray_EnsureAnyArray \
|
| 157 |
+
(PyObject *);
|
| 158 |
+
NPY_NO_EXPORT PyObject * PyArray_FromFile \
|
| 159 |
+
(FILE *, PyArray_Descr *, npy_intp, char *);
|
| 160 |
+
NPY_NO_EXPORT PyObject * PyArray_FromString \
|
| 161 |
+
(char *, npy_intp, PyArray_Descr *, npy_intp, char *);
|
| 162 |
+
NPY_NO_EXPORT PyObject * PyArray_FromBuffer \
|
| 163 |
+
(PyObject *, PyArray_Descr *, npy_intp, npy_intp);
|
| 164 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromIter \
|
| 165 |
+
(PyObject *, PyArray_Descr *, npy_intp);
|
| 166 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(1) PyObject * PyArray_Return \
|
| 167 |
+
(PyArrayObject *);
|
| 168 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_GetField \
|
| 169 |
+
(PyArrayObject *, PyArray_Descr *, int);
|
| 170 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) int PyArray_SetField \
|
| 171 |
+
(PyArrayObject *, PyArray_Descr *, int, PyObject *);
|
| 172 |
+
NPY_NO_EXPORT PyObject * PyArray_Byteswap \
|
| 173 |
+
(PyArrayObject *, npy_bool);
|
| 174 |
+
NPY_NO_EXPORT PyObject * PyArray_Resize \
|
| 175 |
+
(PyArrayObject *, PyArray_Dims *, int, NPY_ORDER NPY_UNUSED(order));
|
| 176 |
+
NPY_NO_EXPORT int PyArray_MoveInto \
|
| 177 |
+
(PyArrayObject *, PyArrayObject *);
|
| 178 |
+
NPY_NO_EXPORT int PyArray_CopyInto \
|
| 179 |
+
(PyArrayObject *, PyArrayObject *);
|
| 180 |
+
NPY_NO_EXPORT int PyArray_CopyAnyInto \
|
| 181 |
+
(PyArrayObject *, PyArrayObject *);
|
| 182 |
+
NPY_NO_EXPORT int PyArray_CopyObject \
|
| 183 |
+
(PyArrayObject *, PyObject *);
|
| 184 |
+
NPY_NO_EXPORT PyObject * PyArray_NewCopy \
|
| 185 |
+
(PyArrayObject *, NPY_ORDER);
|
| 186 |
+
NPY_NO_EXPORT PyObject * PyArray_ToList \
|
| 187 |
+
(PyArrayObject *);
|
| 188 |
+
NPY_NO_EXPORT PyObject * PyArray_ToString \
|
| 189 |
+
(PyArrayObject *, NPY_ORDER);
|
| 190 |
+
NPY_NO_EXPORT int PyArray_ToFile \
|
| 191 |
+
(PyArrayObject *, FILE *, char *, char *);
|
| 192 |
+
NPY_NO_EXPORT int PyArray_Dump \
|
| 193 |
+
(PyObject *, PyObject *, int);
|
| 194 |
+
NPY_NO_EXPORT PyObject * PyArray_Dumps \
|
| 195 |
+
(PyObject *, int);
|
| 196 |
+
NPY_NO_EXPORT int PyArray_ValidType \
|
| 197 |
+
(int);
|
| 198 |
+
NPY_NO_EXPORT void PyArray_UpdateFlags \
|
| 199 |
+
(PyArrayObject *, int);
|
| 200 |
+
NPY_NO_EXPORT PyObject * PyArray_New \
|
| 201 |
+
(PyTypeObject *, int, npy_intp const *, int, npy_intp const *, void *, int, int, PyObject *);
|
| 202 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_NewFromDescr \
|
| 203 |
+
(PyTypeObject *, PyArray_Descr *, int, npy_intp const *, npy_intp const *, void *, int, PyObject *);
|
| 204 |
+
NPY_NO_EXPORT PyArray_Descr * PyArray_DescrNew \
|
| 205 |
+
(PyArray_Descr *);
|
| 206 |
+
NPY_NO_EXPORT PyArray_Descr * PyArray_DescrNewFromType \
|
| 207 |
+
(int);
|
| 208 |
+
NPY_NO_EXPORT double PyArray_GetPriority \
|
| 209 |
+
(PyObject *, double);
|
| 210 |
+
NPY_NO_EXPORT PyObject * PyArray_IterNew \
|
| 211 |
+
(PyObject *);
|
| 212 |
+
NPY_NO_EXPORT PyObject* PyArray_MultiIterNew \
|
| 213 |
+
(int, ...);
|
| 214 |
+
NPY_NO_EXPORT int PyArray_PyIntAsInt \
|
| 215 |
+
(PyObject *);
|
| 216 |
+
NPY_NO_EXPORT npy_intp PyArray_PyIntAsIntp \
|
| 217 |
+
(PyObject *);
|
| 218 |
+
NPY_NO_EXPORT int PyArray_Broadcast \
|
| 219 |
+
(PyArrayMultiIterObject *);
|
| 220 |
+
NPY_NO_EXPORT void PyArray_FillObjectArray \
|
| 221 |
+
(PyArrayObject *, PyObject *);
|
| 222 |
+
NPY_NO_EXPORT int PyArray_FillWithScalar \
|
| 223 |
+
(PyArrayObject *, PyObject *);
|
| 224 |
+
NPY_NO_EXPORT npy_bool PyArray_CheckStrides \
|
| 225 |
+
(int, int, npy_intp, npy_intp, npy_intp const *, npy_intp const *);
|
| 226 |
+
NPY_NO_EXPORT PyArray_Descr * PyArray_DescrNewByteorder \
|
| 227 |
+
(PyArray_Descr *, char);
|
| 228 |
+
NPY_NO_EXPORT PyObject * PyArray_IterAllButAxis \
|
| 229 |
+
(PyObject *, int *);
|
| 230 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_CheckFromAny \
|
| 231 |
+
(PyObject *, PyArray_Descr *, int, int, int, PyObject *);
|
| 232 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromArray \
|
| 233 |
+
(PyArrayObject *, PyArray_Descr *, int);
|
| 234 |
+
NPY_NO_EXPORT PyObject * PyArray_FromInterface \
|
| 235 |
+
(PyObject *);
|
| 236 |
+
NPY_NO_EXPORT PyObject * PyArray_FromStructInterface \
|
| 237 |
+
(PyObject *);
|
| 238 |
+
NPY_NO_EXPORT PyObject * PyArray_FromArrayAttr \
|
| 239 |
+
(PyObject *, PyArray_Descr *, PyObject *);
|
| 240 |
+
NPY_NO_EXPORT NPY_SCALARKIND PyArray_ScalarKind \
|
| 241 |
+
(int, PyArrayObject **);
|
| 242 |
+
NPY_NO_EXPORT int PyArray_CanCoerceScalar \
|
| 243 |
+
(int, int, NPY_SCALARKIND);
|
| 244 |
+
NPY_NO_EXPORT PyObject * PyArray_NewFlagsObject \
|
| 245 |
+
(PyObject *);
|
| 246 |
+
NPY_NO_EXPORT npy_bool PyArray_CanCastScalar \
|
| 247 |
+
(PyTypeObject *, PyTypeObject *);
|
| 248 |
+
NPY_NO_EXPORT int PyArray_CompareUCS4 \
|
| 249 |
+
(npy_ucs4 const *, npy_ucs4 const *, size_t);
|
| 250 |
+
NPY_NO_EXPORT int PyArray_RemoveSmallest \
|
| 251 |
+
(PyArrayMultiIterObject *);
|
| 252 |
+
NPY_NO_EXPORT int PyArray_ElementStrides \
|
| 253 |
+
(PyObject *);
|
| 254 |
+
NPY_NO_EXPORT void PyArray_Item_INCREF \
|
| 255 |
+
(char *, PyArray_Descr *);
|
| 256 |
+
NPY_NO_EXPORT void PyArray_Item_XDECREF \
|
| 257 |
+
(char *, PyArray_Descr *);
|
| 258 |
+
NPY_NO_EXPORT PyObject * PyArray_FieldNames \
|
| 259 |
+
(PyObject *);
|
| 260 |
+
NPY_NO_EXPORT PyObject * PyArray_Transpose \
|
| 261 |
+
(PyArrayObject *, PyArray_Dims *);
|
| 262 |
+
NPY_NO_EXPORT PyObject * PyArray_TakeFrom \
|
| 263 |
+
(PyArrayObject *, PyObject *, int, PyArrayObject *, NPY_CLIPMODE);
|
| 264 |
+
NPY_NO_EXPORT PyObject * PyArray_PutTo \
|
| 265 |
+
(PyArrayObject *, PyObject*, PyObject *, NPY_CLIPMODE);
|
| 266 |
+
NPY_NO_EXPORT PyObject * PyArray_PutMask \
|
| 267 |
+
(PyArrayObject *, PyObject*, PyObject*);
|
| 268 |
+
NPY_NO_EXPORT PyObject * PyArray_Repeat \
|
| 269 |
+
(PyArrayObject *, PyObject *, int);
|
| 270 |
+
NPY_NO_EXPORT PyObject * PyArray_Choose \
|
| 271 |
+
(PyArrayObject *, PyObject *, PyArrayObject *, NPY_CLIPMODE);
|
| 272 |
+
NPY_NO_EXPORT int PyArray_Sort \
|
| 273 |
+
(PyArrayObject *, int, NPY_SORTKIND);
|
| 274 |
+
NPY_NO_EXPORT PyObject * PyArray_ArgSort \
|
| 275 |
+
(PyArrayObject *, int, NPY_SORTKIND);
|
| 276 |
+
NPY_NO_EXPORT PyObject * PyArray_SearchSorted \
|
| 277 |
+
(PyArrayObject *, PyObject *, NPY_SEARCHSIDE, PyObject *);
|
| 278 |
+
NPY_NO_EXPORT PyObject * PyArray_ArgMax \
|
| 279 |
+
(PyArrayObject *, int, PyArrayObject *);
|
| 280 |
+
NPY_NO_EXPORT PyObject * PyArray_ArgMin \
|
| 281 |
+
(PyArrayObject *, int, PyArrayObject *);
|
| 282 |
+
NPY_NO_EXPORT PyObject * PyArray_Reshape \
|
| 283 |
+
(PyArrayObject *, PyObject *);
|
| 284 |
+
NPY_NO_EXPORT PyObject * PyArray_Newshape \
|
| 285 |
+
(PyArrayObject *, PyArray_Dims *, NPY_ORDER);
|
| 286 |
+
NPY_NO_EXPORT PyObject * PyArray_Squeeze \
|
| 287 |
+
(PyArrayObject *);
|
| 288 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_View \
|
| 289 |
+
(PyArrayObject *, PyArray_Descr *, PyTypeObject *);
|
| 290 |
+
NPY_NO_EXPORT PyObject * PyArray_SwapAxes \
|
| 291 |
+
(PyArrayObject *, int, int);
|
| 292 |
+
NPY_NO_EXPORT PyObject * PyArray_Max \
|
| 293 |
+
(PyArrayObject *, int, PyArrayObject *);
|
| 294 |
+
NPY_NO_EXPORT PyObject * PyArray_Min \
|
| 295 |
+
(PyArrayObject *, int, PyArrayObject *);
|
| 296 |
+
NPY_NO_EXPORT PyObject * PyArray_Ptp \
|
| 297 |
+
(PyArrayObject *, int, PyArrayObject *);
|
| 298 |
+
NPY_NO_EXPORT PyObject * PyArray_Mean \
|
| 299 |
+
(PyArrayObject *, int, int, PyArrayObject *);
|
| 300 |
+
NPY_NO_EXPORT PyObject * PyArray_Trace \
|
| 301 |
+
(PyArrayObject *, int, int, int, int, PyArrayObject *);
|
| 302 |
+
NPY_NO_EXPORT PyObject * PyArray_Diagonal \
|
| 303 |
+
(PyArrayObject *, int, int, int);
|
| 304 |
+
NPY_NO_EXPORT PyObject * PyArray_Clip \
|
| 305 |
+
(PyArrayObject *, PyObject *, PyObject *, PyArrayObject *);
|
| 306 |
+
NPY_NO_EXPORT PyObject * PyArray_Conjugate \
|
| 307 |
+
(PyArrayObject *, PyArrayObject *);
|
| 308 |
+
NPY_NO_EXPORT PyObject * PyArray_Nonzero \
|
| 309 |
+
(PyArrayObject *);
|
| 310 |
+
NPY_NO_EXPORT PyObject * PyArray_Std \
|
| 311 |
+
(PyArrayObject *, int, int, PyArrayObject *, int);
|
| 312 |
+
NPY_NO_EXPORT PyObject * PyArray_Sum \
|
| 313 |
+
(PyArrayObject *, int, int, PyArrayObject *);
|
| 314 |
+
NPY_NO_EXPORT PyObject * PyArray_CumSum \
|
| 315 |
+
(PyArrayObject *, int, int, PyArrayObject *);
|
| 316 |
+
NPY_NO_EXPORT PyObject * PyArray_Prod \
|
| 317 |
+
(PyArrayObject *, int, int, PyArrayObject *);
|
| 318 |
+
NPY_NO_EXPORT PyObject * PyArray_CumProd \
|
| 319 |
+
(PyArrayObject *, int, int, PyArrayObject *);
|
| 320 |
+
NPY_NO_EXPORT PyObject * PyArray_All \
|
| 321 |
+
(PyArrayObject *, int, PyArrayObject *);
|
| 322 |
+
NPY_NO_EXPORT PyObject * PyArray_Any \
|
| 323 |
+
(PyArrayObject *, int, PyArrayObject *);
|
| 324 |
+
NPY_NO_EXPORT PyObject * PyArray_Compress \
|
| 325 |
+
(PyArrayObject *, PyObject *, int, PyArrayObject *);
|
| 326 |
+
NPY_NO_EXPORT PyObject * PyArray_Flatten \
|
| 327 |
+
(PyArrayObject *, NPY_ORDER);
|
| 328 |
+
NPY_NO_EXPORT PyObject * PyArray_Ravel \
|
| 329 |
+
(PyArrayObject *, NPY_ORDER);
|
| 330 |
+
NPY_NO_EXPORT npy_intp PyArray_MultiplyList \
|
| 331 |
+
(npy_intp const *, int);
|
| 332 |
+
NPY_NO_EXPORT int PyArray_MultiplyIntList \
|
| 333 |
+
(int const *, int);
|
| 334 |
+
NPY_NO_EXPORT void * PyArray_GetPtr \
|
| 335 |
+
(PyArrayObject *, npy_intp const*);
|
| 336 |
+
NPY_NO_EXPORT int PyArray_CompareLists \
|
| 337 |
+
(npy_intp const *, npy_intp const *, int);
|
| 338 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(5) int PyArray_AsCArray \
|
| 339 |
+
(PyObject **, void *, npy_intp *, int, PyArray_Descr*);
|
| 340 |
+
NPY_NO_EXPORT int PyArray_As1D \
|
| 341 |
+
(PyObject **NPY_UNUSED(op), char **NPY_UNUSED(ptr), int *NPY_UNUSED(d1), int NPY_UNUSED(typecode));
|
| 342 |
+
NPY_NO_EXPORT int PyArray_As2D \
|
| 343 |
+
(PyObject **NPY_UNUSED(op), char ***NPY_UNUSED(ptr), int *NPY_UNUSED(d1), int *NPY_UNUSED(d2), int NPY_UNUSED(typecode));
|
| 344 |
+
NPY_NO_EXPORT int PyArray_Free \
|
| 345 |
+
(PyObject *, void *);
|
| 346 |
+
NPY_NO_EXPORT int PyArray_Converter \
|
| 347 |
+
(PyObject *, PyObject **);
|
| 348 |
+
NPY_NO_EXPORT int PyArray_IntpFromSequence \
|
| 349 |
+
(PyObject *, npy_intp *, int);
|
| 350 |
+
NPY_NO_EXPORT PyObject * PyArray_Concatenate \
|
| 351 |
+
(PyObject *, int);
|
| 352 |
+
NPY_NO_EXPORT PyObject * PyArray_InnerProduct \
|
| 353 |
+
(PyObject *, PyObject *);
|
| 354 |
+
NPY_NO_EXPORT PyObject * PyArray_MatrixProduct \
|
| 355 |
+
(PyObject *, PyObject *);
|
| 356 |
+
NPY_NO_EXPORT PyObject * PyArray_CopyAndTranspose \
|
| 357 |
+
(PyObject *);
|
| 358 |
+
NPY_NO_EXPORT PyObject * PyArray_Correlate \
|
| 359 |
+
(PyObject *, PyObject *, int);
|
| 360 |
+
NPY_NO_EXPORT int PyArray_TypestrConvert \
|
| 361 |
+
(int, int);
|
| 362 |
+
NPY_NO_EXPORT int PyArray_DescrConverter \
|
| 363 |
+
(PyObject *, PyArray_Descr **);
|
| 364 |
+
NPY_NO_EXPORT int PyArray_DescrConverter2 \
|
| 365 |
+
(PyObject *, PyArray_Descr **);
|
| 366 |
+
NPY_NO_EXPORT int PyArray_IntpConverter \
|
| 367 |
+
(PyObject *, PyArray_Dims *);
|
| 368 |
+
NPY_NO_EXPORT int PyArray_BufferConverter \
|
| 369 |
+
(PyObject *, PyArray_Chunk *);
|
| 370 |
+
NPY_NO_EXPORT int PyArray_AxisConverter \
|
| 371 |
+
(PyObject *, int *);
|
| 372 |
+
NPY_NO_EXPORT int PyArray_BoolConverter \
|
| 373 |
+
(PyObject *, npy_bool *);
|
| 374 |
+
NPY_NO_EXPORT int PyArray_ByteorderConverter \
|
| 375 |
+
(PyObject *, char *);
|
| 376 |
+
NPY_NO_EXPORT int PyArray_OrderConverter \
|
| 377 |
+
(PyObject *, NPY_ORDER *);
|
| 378 |
+
NPY_NO_EXPORT unsigned char PyArray_EquivTypes \
|
| 379 |
+
(PyArray_Descr *, PyArray_Descr *);
|
| 380 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_Zeros \
|
| 381 |
+
(int, npy_intp const *, PyArray_Descr *, int);
|
| 382 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_Empty \
|
| 383 |
+
(int, npy_intp const *, PyArray_Descr *, int);
|
| 384 |
+
NPY_NO_EXPORT PyObject * PyArray_Where \
|
| 385 |
+
(PyObject *, PyObject *, PyObject *);
|
| 386 |
+
NPY_NO_EXPORT PyObject * PyArray_Arange \
|
| 387 |
+
(double, double, double, int);
|
| 388 |
+
NPY_NO_EXPORT PyObject * PyArray_ArangeObj \
|
| 389 |
+
(PyObject *, PyObject *, PyObject *, PyArray_Descr *);
|
| 390 |
+
NPY_NO_EXPORT int PyArray_SortkindConverter \
|
| 391 |
+
(PyObject *, NPY_SORTKIND *);
|
| 392 |
+
NPY_NO_EXPORT PyObject * PyArray_LexSort \
|
| 393 |
+
(PyObject *, int);
|
| 394 |
+
NPY_NO_EXPORT PyObject * PyArray_Round \
|
| 395 |
+
(PyArrayObject *, int, PyArrayObject *);
|
| 396 |
+
NPY_NO_EXPORT unsigned char PyArray_EquivTypenums \
|
| 397 |
+
(int, int);
|
| 398 |
+
NPY_NO_EXPORT int PyArray_RegisterDataType \
|
| 399 |
+
(PyArray_Descr *);
|
| 400 |
+
NPY_NO_EXPORT int PyArray_RegisterCastFunc \
|
| 401 |
+
(PyArray_Descr *, int, PyArray_VectorUnaryFunc *);
|
| 402 |
+
NPY_NO_EXPORT int PyArray_RegisterCanCast \
|
| 403 |
+
(PyArray_Descr *, int, NPY_SCALARKIND);
|
| 404 |
+
NPY_NO_EXPORT void PyArray_InitArrFuncs \
|
| 405 |
+
(PyArray_ArrFuncs *);
|
| 406 |
+
NPY_NO_EXPORT PyObject * PyArray_IntTupleFromIntp \
|
| 407 |
+
(int, npy_intp const *);
|
| 408 |
+
NPY_NO_EXPORT int PyArray_TypeNumFromName \
|
| 409 |
+
(char const *);
|
| 410 |
+
NPY_NO_EXPORT int PyArray_ClipmodeConverter \
|
| 411 |
+
(PyObject *, NPY_CLIPMODE *);
|
| 412 |
+
NPY_NO_EXPORT int PyArray_OutputConverter \
|
| 413 |
+
(PyObject *, PyArrayObject **);
|
| 414 |
+
NPY_NO_EXPORT PyObject * PyArray_BroadcastToShape \
|
| 415 |
+
(PyObject *, npy_intp *, int);
|
| 416 |
+
NPY_NO_EXPORT void _PyArray_SigintHandler \
|
| 417 |
+
(int);
|
| 418 |
+
NPY_NO_EXPORT void* _PyArray_GetSigintBuf \
|
| 419 |
+
(void);
|
| 420 |
+
NPY_NO_EXPORT int PyArray_DescrAlignConverter \
|
| 421 |
+
(PyObject *, PyArray_Descr **);
|
| 422 |
+
NPY_NO_EXPORT int PyArray_DescrAlignConverter2 \
|
| 423 |
+
(PyObject *, PyArray_Descr **);
|
| 424 |
+
NPY_NO_EXPORT int PyArray_SearchsideConverter \
|
| 425 |
+
(PyObject *, void *);
|
| 426 |
+
NPY_NO_EXPORT PyObject * PyArray_CheckAxis \
|
| 427 |
+
(PyArrayObject *, int *, int);
|
| 428 |
+
NPY_NO_EXPORT npy_intp PyArray_OverflowMultiplyList \
|
| 429 |
+
(npy_intp const *, int);
|
| 430 |
+
NPY_NO_EXPORT int PyArray_CompareString \
|
| 431 |
+
(const char *, const char *, size_t);
|
| 432 |
+
NPY_NO_EXPORT PyObject* PyArray_MultiIterFromObjects \
|
| 433 |
+
(PyObject **, int, int, ...);
|
| 434 |
+
NPY_NO_EXPORT int PyArray_GetEndianness \
|
| 435 |
+
(void);
|
| 436 |
+
NPY_NO_EXPORT unsigned int PyArray_GetNDArrayCFeatureVersion \
|
| 437 |
+
(void);
|
| 438 |
+
NPY_NO_EXPORT PyObject * PyArray_Correlate2 \
|
| 439 |
+
(PyObject *, PyObject *, int);
|
| 440 |
+
NPY_NO_EXPORT PyObject* PyArray_NeighborhoodIterNew \
|
| 441 |
+
(PyArrayIterObject *, const npy_intp *, int, PyArrayObject*);
|
| 442 |
+
extern NPY_NO_EXPORT PyTypeObject PyTimeIntegerArrType_Type;
|
| 443 |
+
|
| 444 |
+
extern NPY_NO_EXPORT PyTypeObject PyDatetimeArrType_Type;
|
| 445 |
+
|
| 446 |
+
extern NPY_NO_EXPORT PyTypeObject PyTimedeltaArrType_Type;
|
| 447 |
+
|
| 448 |
+
extern NPY_NO_EXPORT PyTypeObject PyHalfArrType_Type;
|
| 449 |
+
|
| 450 |
+
extern NPY_NO_EXPORT PyTypeObject NpyIter_Type;
|
| 451 |
+
|
| 452 |
+
NPY_NO_EXPORT void PyArray_SetDatetimeParseFunction \
|
| 453 |
+
(PyObject *NPY_UNUSED(op));
|
| 454 |
+
NPY_NO_EXPORT void PyArray_DatetimeToDatetimeStruct \
|
| 455 |
+
(npy_datetime NPY_UNUSED(val), NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_datetimestruct *);
|
| 456 |
+
NPY_NO_EXPORT void PyArray_TimedeltaToTimedeltaStruct \
|
| 457 |
+
(npy_timedelta NPY_UNUSED(val), NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_timedeltastruct *);
|
| 458 |
+
NPY_NO_EXPORT npy_datetime PyArray_DatetimeStructToDatetime \
|
| 459 |
+
(NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_datetimestruct *NPY_UNUSED(d));
|
| 460 |
+
NPY_NO_EXPORT npy_datetime PyArray_TimedeltaStructToTimedelta \
|
| 461 |
+
(NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_timedeltastruct *NPY_UNUSED(d));
|
| 462 |
+
NPY_NO_EXPORT NpyIter * NpyIter_New \
|
| 463 |
+
(PyArrayObject *, npy_uint32, NPY_ORDER, NPY_CASTING, PyArray_Descr*);
|
| 464 |
+
NPY_NO_EXPORT NpyIter * NpyIter_MultiNew \
|
| 465 |
+
(int, PyArrayObject **, npy_uint32, NPY_ORDER, NPY_CASTING, npy_uint32 *, PyArray_Descr **);
|
| 466 |
+
NPY_NO_EXPORT NpyIter * NpyIter_AdvancedNew \
|
| 467 |
+
(int, PyArrayObject **, npy_uint32, NPY_ORDER, NPY_CASTING, npy_uint32 *, PyArray_Descr **, int, int **, npy_intp *, npy_intp);
|
| 468 |
+
NPY_NO_EXPORT NpyIter * NpyIter_Copy \
|
| 469 |
+
(NpyIter *);
|
| 470 |
+
NPY_NO_EXPORT int NpyIter_Deallocate \
|
| 471 |
+
(NpyIter *);
|
| 472 |
+
NPY_NO_EXPORT npy_bool NpyIter_HasDelayedBufAlloc \
|
| 473 |
+
(NpyIter *);
|
| 474 |
+
NPY_NO_EXPORT npy_bool NpyIter_HasExternalLoop \
|
| 475 |
+
(NpyIter *);
|
| 476 |
+
NPY_NO_EXPORT int NpyIter_EnableExternalLoop \
|
| 477 |
+
(NpyIter *);
|
| 478 |
+
NPY_NO_EXPORT npy_intp * NpyIter_GetInnerStrideArray \
|
| 479 |
+
(NpyIter *);
|
| 480 |
+
NPY_NO_EXPORT npy_intp * NpyIter_GetInnerLoopSizePtr \
|
| 481 |
+
(NpyIter *);
|
| 482 |
+
NPY_NO_EXPORT int NpyIter_Reset \
|
| 483 |
+
(NpyIter *, char **);
|
| 484 |
+
NPY_NO_EXPORT int NpyIter_ResetBasePointers \
|
| 485 |
+
(NpyIter *, char **, char **);
|
| 486 |
+
NPY_NO_EXPORT int NpyIter_ResetToIterIndexRange \
|
| 487 |
+
(NpyIter *, npy_intp, npy_intp, char **);
|
| 488 |
+
NPY_NO_EXPORT int NpyIter_GetNDim \
|
| 489 |
+
(NpyIter *);
|
| 490 |
+
NPY_NO_EXPORT int NpyIter_GetNOp \
|
| 491 |
+
(NpyIter *);
|
| 492 |
+
NPY_NO_EXPORT NpyIter_IterNextFunc * NpyIter_GetIterNext \
|
| 493 |
+
(NpyIter *, char **);
|
| 494 |
+
NPY_NO_EXPORT npy_intp NpyIter_GetIterSize \
|
| 495 |
+
(NpyIter *);
|
| 496 |
+
NPY_NO_EXPORT void NpyIter_GetIterIndexRange \
|
| 497 |
+
(NpyIter *, npy_intp *, npy_intp *);
|
| 498 |
+
NPY_NO_EXPORT npy_intp NpyIter_GetIterIndex \
|
| 499 |
+
(NpyIter *);
|
| 500 |
+
NPY_NO_EXPORT int NpyIter_GotoIterIndex \
|
| 501 |
+
(NpyIter *, npy_intp);
|
| 502 |
+
NPY_NO_EXPORT npy_bool NpyIter_HasMultiIndex \
|
| 503 |
+
(NpyIter *);
|
| 504 |
+
NPY_NO_EXPORT int NpyIter_GetShape \
|
| 505 |
+
(NpyIter *, npy_intp *);
|
| 506 |
+
NPY_NO_EXPORT NpyIter_GetMultiIndexFunc * NpyIter_GetGetMultiIndex \
|
| 507 |
+
(NpyIter *, char **);
|
| 508 |
+
NPY_NO_EXPORT int NpyIter_GotoMultiIndex \
|
| 509 |
+
(NpyIter *, npy_intp const *);
|
| 510 |
+
NPY_NO_EXPORT int NpyIter_RemoveMultiIndex \
|
| 511 |
+
(NpyIter *);
|
| 512 |
+
NPY_NO_EXPORT npy_bool NpyIter_HasIndex \
|
| 513 |
+
(NpyIter *);
|
| 514 |
+
NPY_NO_EXPORT npy_bool NpyIter_IsBuffered \
|
| 515 |
+
(NpyIter *);
|
| 516 |
+
NPY_NO_EXPORT npy_bool NpyIter_IsGrowInner \
|
| 517 |
+
(NpyIter *);
|
| 518 |
+
NPY_NO_EXPORT npy_intp NpyIter_GetBufferSize \
|
| 519 |
+
(NpyIter *);
|
| 520 |
+
NPY_NO_EXPORT npy_intp * NpyIter_GetIndexPtr \
|
| 521 |
+
(NpyIter *);
|
| 522 |
+
NPY_NO_EXPORT int NpyIter_GotoIndex \
|
| 523 |
+
(NpyIter *, npy_intp);
|
| 524 |
+
NPY_NO_EXPORT char ** NpyIter_GetDataPtrArray \
|
| 525 |
+
(NpyIter *);
|
| 526 |
+
NPY_NO_EXPORT PyArray_Descr ** NpyIter_GetDescrArray \
|
| 527 |
+
(NpyIter *);
|
| 528 |
+
NPY_NO_EXPORT PyArrayObject ** NpyIter_GetOperandArray \
|
| 529 |
+
(NpyIter *);
|
| 530 |
+
NPY_NO_EXPORT PyArrayObject * NpyIter_GetIterView \
|
| 531 |
+
(NpyIter *, npy_intp);
|
| 532 |
+
NPY_NO_EXPORT void NpyIter_GetReadFlags \
|
| 533 |
+
(NpyIter *, char *);
|
| 534 |
+
NPY_NO_EXPORT void NpyIter_GetWriteFlags \
|
| 535 |
+
(NpyIter *, char *);
|
| 536 |
+
NPY_NO_EXPORT void NpyIter_DebugPrint \
|
| 537 |
+
(NpyIter *);
|
| 538 |
+
NPY_NO_EXPORT npy_bool NpyIter_IterationNeedsAPI \
|
| 539 |
+
(NpyIter *);
|
| 540 |
+
NPY_NO_EXPORT void NpyIter_GetInnerFixedStrideArray \
|
| 541 |
+
(NpyIter *, npy_intp *);
|
| 542 |
+
NPY_NO_EXPORT int NpyIter_RemoveAxis \
|
| 543 |
+
(NpyIter *, int);
|
| 544 |
+
NPY_NO_EXPORT npy_intp * NpyIter_GetAxisStrideArray \
|
| 545 |
+
(NpyIter *, int);
|
| 546 |
+
NPY_NO_EXPORT npy_bool NpyIter_RequiresBuffering \
|
| 547 |
+
(NpyIter *);
|
| 548 |
+
NPY_NO_EXPORT char ** NpyIter_GetInitialDataPtrArray \
|
| 549 |
+
(NpyIter *);
|
| 550 |
+
NPY_NO_EXPORT int NpyIter_CreateCompatibleStrides \
|
| 551 |
+
(NpyIter *, npy_intp, npy_intp *);
|
| 552 |
+
NPY_NO_EXPORT int PyArray_CastingConverter \
|
| 553 |
+
(PyObject *, NPY_CASTING *);
|
| 554 |
+
NPY_NO_EXPORT npy_intp PyArray_CountNonzero \
|
| 555 |
+
(PyArrayObject *);
|
| 556 |
+
NPY_NO_EXPORT PyArray_Descr * PyArray_PromoteTypes \
|
| 557 |
+
(PyArray_Descr *, PyArray_Descr *);
|
| 558 |
+
NPY_NO_EXPORT PyArray_Descr * PyArray_MinScalarType \
|
| 559 |
+
(PyArrayObject *);
|
| 560 |
+
NPY_NO_EXPORT PyArray_Descr * PyArray_ResultType \
|
| 561 |
+
(npy_intp, PyArrayObject *arrs[], npy_intp, PyArray_Descr *descrs[]);
|
| 562 |
+
NPY_NO_EXPORT npy_bool PyArray_CanCastArrayTo \
|
| 563 |
+
(PyArrayObject *, PyArray_Descr *, NPY_CASTING);
|
| 564 |
+
NPY_NO_EXPORT npy_bool PyArray_CanCastTypeTo \
|
| 565 |
+
(PyArray_Descr *, PyArray_Descr *, NPY_CASTING);
|
| 566 |
+
NPY_NO_EXPORT PyArrayObject * PyArray_EinsteinSum \
|
| 567 |
+
(char *, npy_intp, PyArrayObject **, PyArray_Descr *, NPY_ORDER, NPY_CASTING, PyArrayObject *);
|
| 568 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_NewLikeArray \
|
| 569 |
+
(PyArrayObject *, NPY_ORDER, PyArray_Descr *, int);
|
| 570 |
+
NPY_NO_EXPORT int PyArray_GetArrayParamsFromObject \
|
| 571 |
+
(PyObject *NPY_UNUSED(op), PyArray_Descr *NPY_UNUSED(requested_dtype), npy_bool NPY_UNUSED(writeable), PyArray_Descr **NPY_UNUSED(out_dtype), int *NPY_UNUSED(out_ndim), npy_intp *NPY_UNUSED(out_dims), PyArrayObject **NPY_UNUSED(out_arr), PyObject *NPY_UNUSED(context));
|
| 572 |
+
NPY_NO_EXPORT int PyArray_ConvertClipmodeSequence \
|
| 573 |
+
(PyObject *, NPY_CLIPMODE *, int);
|
| 574 |
+
NPY_NO_EXPORT PyObject * PyArray_MatrixProduct2 \
|
| 575 |
+
(PyObject *, PyObject *, PyArrayObject*);
|
| 576 |
+
NPY_NO_EXPORT npy_bool NpyIter_IsFirstVisit \
|
| 577 |
+
(NpyIter *, int);
|
| 578 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) int PyArray_SetBaseObject \
|
| 579 |
+
(PyArrayObject *, PyObject *);
|
| 580 |
+
NPY_NO_EXPORT void PyArray_CreateSortedStridePerm \
|
| 581 |
+
(int, npy_intp const *, npy_stride_sort_item *);
|
| 582 |
+
NPY_NO_EXPORT void PyArray_RemoveAxesInPlace \
|
| 583 |
+
(PyArrayObject *, const npy_bool *);
|
| 584 |
+
NPY_NO_EXPORT void PyArray_DebugPrint \
|
| 585 |
+
(PyArrayObject *);
|
| 586 |
+
NPY_NO_EXPORT int PyArray_FailUnlessWriteable \
|
| 587 |
+
(PyArrayObject *, const char *);
|
| 588 |
+
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) int PyArray_SetUpdateIfCopyBase \
|
| 589 |
+
(PyArrayObject *, PyArrayObject *);
|
| 590 |
+
NPY_NO_EXPORT void * PyDataMem_NEW \
|
| 591 |
+
(size_t);
|
| 592 |
+
NPY_NO_EXPORT void PyDataMem_FREE \
|
| 593 |
+
(void *);
|
| 594 |
+
NPY_NO_EXPORT void * PyDataMem_RENEW \
|
| 595 |
+
(void *, size_t);
|
| 596 |
+
NPY_NO_EXPORT PyDataMem_EventHookFunc * PyDataMem_SetEventHook \
|
| 597 |
+
(PyDataMem_EventHookFunc *, void *, void **);
|
| 598 |
+
extern NPY_NO_EXPORT NPY_CASTING NPY_DEFAULT_ASSIGN_CASTING;
|
| 599 |
+
|
| 600 |
+
NPY_NO_EXPORT void PyArray_MapIterSwapAxes \
|
| 601 |
+
(PyArrayMapIterObject *, PyArrayObject **, int);
|
| 602 |
+
NPY_NO_EXPORT PyObject * PyArray_MapIterArray \
|
| 603 |
+
(PyArrayObject *, PyObject *);
|
| 604 |
+
NPY_NO_EXPORT void PyArray_MapIterNext \
|
| 605 |
+
(PyArrayMapIterObject *);
|
| 606 |
+
NPY_NO_EXPORT int PyArray_Partition \
|
| 607 |
+
(PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND);
|
| 608 |
+
NPY_NO_EXPORT PyObject * PyArray_ArgPartition \
|
| 609 |
+
(PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND);
|
| 610 |
+
NPY_NO_EXPORT int PyArray_SelectkindConverter \
|
| 611 |
+
(PyObject *, NPY_SELECTKIND *);
|
| 612 |
+
NPY_NO_EXPORT void * PyDataMem_NEW_ZEROED \
|
| 613 |
+
(size_t, size_t);
|
| 614 |
+
NPY_NO_EXPORT int PyArray_CheckAnyScalarExact \
|
| 615 |
+
(PyObject *);
|
| 616 |
+
NPY_NO_EXPORT PyObject * PyArray_MapIterArrayCopyIfOverlap \
|
| 617 |
+
(PyArrayObject *, PyObject *, int, PyArrayObject *);
|
| 618 |
+
NPY_NO_EXPORT int PyArray_ResolveWritebackIfCopy \
|
| 619 |
+
(PyArrayObject *);
|
| 620 |
+
NPY_NO_EXPORT int PyArray_SetWritebackIfCopyBase \
|
| 621 |
+
(PyArrayObject *, PyArrayObject *);
|
| 622 |
+
NPY_NO_EXPORT PyObject * PyDataMem_SetHandler \
|
| 623 |
+
(PyObject *);
|
| 624 |
+
NPY_NO_EXPORT PyObject * PyDataMem_GetHandler \
|
| 625 |
+
(void);
|
| 626 |
+
extern NPY_NO_EXPORT PyObject* PyDataMem_DefaultHandler;
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
#else
|
| 630 |
+
|
| 631 |
+
#if defined(PY_ARRAY_UNIQUE_SYMBOL)
|
| 632 |
+
#define PyArray_API PY_ARRAY_UNIQUE_SYMBOL
|
| 633 |
+
#endif
|
| 634 |
+
|
| 635 |
+
#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
|
| 636 |
+
extern void **PyArray_API;
|
| 637 |
+
#else
|
| 638 |
+
#if defined(PY_ARRAY_UNIQUE_SYMBOL)
|
| 639 |
+
void **PyArray_API;
|
| 640 |
+
#else
|
| 641 |
+
static void **PyArray_API=NULL;
|
| 642 |
+
#endif
|
| 643 |
+
#endif
|
| 644 |
+
|
| 645 |
+
#define PyArray_GetNDArrayCVersion \
|
| 646 |
+
(*(unsigned int (*)(void)) \
|
| 647 |
+
PyArray_API[0])
|
| 648 |
+
#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[1])
|
| 649 |
+
#define PyArray_Type (*(PyTypeObject *)PyArray_API[2])
|
| 650 |
+
#define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[3])
|
| 651 |
+
#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[4])
|
| 652 |
+
#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[5])
|
| 653 |
+
#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[6])
|
| 654 |
+
#define NPY_NUMUSERTYPES (*(int *)PyArray_API[7])
|
| 655 |
+
#define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[8])
|
| 656 |
+
#define _PyArrayScalar_BoolValues ((PyBoolScalarObject *)PyArray_API[9])
|
| 657 |
+
#define PyGenericArrType_Type (*(PyTypeObject *)PyArray_API[10])
|
| 658 |
+
#define PyNumberArrType_Type (*(PyTypeObject *)PyArray_API[11])
|
| 659 |
+
#define PyIntegerArrType_Type (*(PyTypeObject *)PyArray_API[12])
|
| 660 |
+
#define PySignedIntegerArrType_Type (*(PyTypeObject *)PyArray_API[13])
|
| 661 |
+
#define PyUnsignedIntegerArrType_Type (*(PyTypeObject *)PyArray_API[14])
|
| 662 |
+
#define PyInexactArrType_Type (*(PyTypeObject *)PyArray_API[15])
|
| 663 |
+
#define PyFloatingArrType_Type (*(PyTypeObject *)PyArray_API[16])
|
| 664 |
+
#define PyComplexFloatingArrType_Type (*(PyTypeObject *)PyArray_API[17])
|
| 665 |
+
#define PyFlexibleArrType_Type (*(PyTypeObject *)PyArray_API[18])
|
| 666 |
+
#define PyCharacterArrType_Type (*(PyTypeObject *)PyArray_API[19])
|
| 667 |
+
#define PyByteArrType_Type (*(PyTypeObject *)PyArray_API[20])
|
| 668 |
+
#define PyShortArrType_Type (*(PyTypeObject *)PyArray_API[21])
|
| 669 |
+
#define PyIntArrType_Type (*(PyTypeObject *)PyArray_API[22])
|
| 670 |
+
#define PyLongArrType_Type (*(PyTypeObject *)PyArray_API[23])
|
| 671 |
+
#define PyLongLongArrType_Type (*(PyTypeObject *)PyArray_API[24])
|
| 672 |
+
#define PyUByteArrType_Type (*(PyTypeObject *)PyArray_API[25])
|
| 673 |
+
#define PyUShortArrType_Type (*(PyTypeObject *)PyArray_API[26])
|
| 674 |
+
#define PyUIntArrType_Type (*(PyTypeObject *)PyArray_API[27])
|
| 675 |
+
#define PyULongArrType_Type (*(PyTypeObject *)PyArray_API[28])
|
| 676 |
+
#define PyULongLongArrType_Type (*(PyTypeObject *)PyArray_API[29])
|
| 677 |
+
#define PyFloatArrType_Type (*(PyTypeObject *)PyArray_API[30])
|
| 678 |
+
#define PyDoubleArrType_Type (*(PyTypeObject *)PyArray_API[31])
|
| 679 |
+
#define PyLongDoubleArrType_Type (*(PyTypeObject *)PyArray_API[32])
|
| 680 |
+
#define PyCFloatArrType_Type (*(PyTypeObject *)PyArray_API[33])
|
| 681 |
+
#define PyCDoubleArrType_Type (*(PyTypeObject *)PyArray_API[34])
|
| 682 |
+
#define PyCLongDoubleArrType_Type (*(PyTypeObject *)PyArray_API[35])
|
| 683 |
+
#define PyObjectArrType_Type (*(PyTypeObject *)PyArray_API[36])
|
| 684 |
+
#define PyStringArrType_Type (*(PyTypeObject *)PyArray_API[37])
|
| 685 |
+
#define PyUnicodeArrType_Type (*(PyTypeObject *)PyArray_API[38])
|
| 686 |
+
#define PyVoidArrType_Type (*(PyTypeObject *)PyArray_API[39])
|
| 687 |
+
#define PyArray_SetNumericOps \
|
| 688 |
+
(*(int (*)(PyObject *)) \
|
| 689 |
+
PyArray_API[40])
|
| 690 |
+
#define PyArray_GetNumericOps \
|
| 691 |
+
(*(PyObject * (*)(void)) \
|
| 692 |
+
PyArray_API[41])
|
| 693 |
+
#define PyArray_INCREF \
|
| 694 |
+
(*(int (*)(PyArrayObject *)) \
|
| 695 |
+
PyArray_API[42])
|
| 696 |
+
#define PyArray_XDECREF \
|
| 697 |
+
(*(int (*)(PyArrayObject *)) \
|
| 698 |
+
PyArray_API[43])
|
| 699 |
+
#define PyArray_SetStringFunction \
|
| 700 |
+
(*(void (*)(PyObject *, int)) \
|
| 701 |
+
PyArray_API[44])
|
| 702 |
+
#define PyArray_DescrFromType \
|
| 703 |
+
(*(PyArray_Descr * (*)(int)) \
|
| 704 |
+
PyArray_API[45])
|
| 705 |
+
#define PyArray_TypeObjectFromType \
|
| 706 |
+
(*(PyObject * (*)(int)) \
|
| 707 |
+
PyArray_API[46])
|
| 708 |
+
#define PyArray_Zero \
|
| 709 |
+
(*(char * (*)(PyArrayObject *)) \
|
| 710 |
+
PyArray_API[47])
|
| 711 |
+
#define PyArray_One \
|
| 712 |
+
(*(char * (*)(PyArrayObject *)) \
|
| 713 |
+
PyArray_API[48])
|
| 714 |
+
#define PyArray_CastToType \
|
| 715 |
+
(*(PyObject * (*)(PyArrayObject *, PyArray_Descr *, int)) \
|
| 716 |
+
PyArray_API[49])
|
| 717 |
+
#define PyArray_CastTo \
|
| 718 |
+
(*(int (*)(PyArrayObject *, PyArrayObject *)) \
|
| 719 |
+
PyArray_API[50])
|
| 720 |
+
#define PyArray_CastAnyTo \
|
| 721 |
+
(*(int (*)(PyArrayObject *, PyArrayObject *)) \
|
| 722 |
+
PyArray_API[51])
|
| 723 |
+
#define PyArray_CanCastSafely \
|
| 724 |
+
(*(int (*)(int, int)) \
|
| 725 |
+
PyArray_API[52])
|
| 726 |
+
#define PyArray_CanCastTo \
|
| 727 |
+
(*(npy_bool (*)(PyArray_Descr *, PyArray_Descr *)) \
|
| 728 |
+
PyArray_API[53])
|
| 729 |
+
#define PyArray_ObjectType \
|
| 730 |
+
(*(int (*)(PyObject *, int)) \
|
| 731 |
+
PyArray_API[54])
|
| 732 |
+
#define PyArray_DescrFromObject \
|
| 733 |
+
(*(PyArray_Descr * (*)(PyObject *, PyArray_Descr *)) \
|
| 734 |
+
PyArray_API[55])
|
| 735 |
+
#define PyArray_ConvertToCommonType \
|
| 736 |
+
(*(PyArrayObject ** (*)(PyObject *, int *)) \
|
| 737 |
+
PyArray_API[56])
|
| 738 |
+
#define PyArray_DescrFromScalar \
|
| 739 |
+
(*(PyArray_Descr * (*)(PyObject *)) \
|
| 740 |
+
PyArray_API[57])
|
| 741 |
+
#define PyArray_DescrFromTypeObject \
|
| 742 |
+
(*(PyArray_Descr * (*)(PyObject *)) \
|
| 743 |
+
PyArray_API[58])
|
| 744 |
+
#define PyArray_Size \
|
| 745 |
+
(*(npy_intp (*)(PyObject *)) \
|
| 746 |
+
PyArray_API[59])
|
| 747 |
+
#define PyArray_Scalar \
|
| 748 |
+
(*(PyObject * (*)(void *, PyArray_Descr *, PyObject *)) \
|
| 749 |
+
PyArray_API[60])
|
| 750 |
+
#define PyArray_FromScalar \
|
| 751 |
+
(*(PyObject * (*)(PyObject *, PyArray_Descr *)) \
|
| 752 |
+
PyArray_API[61])
|
| 753 |
+
#define PyArray_ScalarAsCtype \
|
| 754 |
+
(*(void (*)(PyObject *, void *)) \
|
| 755 |
+
PyArray_API[62])
|
| 756 |
+
#define PyArray_CastScalarToCtype \
|
| 757 |
+
(*(int (*)(PyObject *, void *, PyArray_Descr *)) \
|
| 758 |
+
PyArray_API[63])
|
| 759 |
+
#define PyArray_CastScalarDirect \
|
| 760 |
+
(*(int (*)(PyObject *, PyArray_Descr *, void *, int)) \
|
| 761 |
+
PyArray_API[64])
|
| 762 |
+
#define PyArray_ScalarFromObject \
|
| 763 |
+
(*(PyObject * (*)(PyObject *)) \
|
| 764 |
+
PyArray_API[65])
|
| 765 |
+
#define PyArray_GetCastFunc \
|
| 766 |
+
(*(PyArray_VectorUnaryFunc * (*)(PyArray_Descr *, int)) \
|
| 767 |
+
PyArray_API[66])
|
| 768 |
+
#define PyArray_FromDims \
|
| 769 |
+
(*(PyObject * (*)(int NPY_UNUSED(nd), int *NPY_UNUSED(d), int NPY_UNUSED(type))) \
|
| 770 |
+
PyArray_API[67])
|
| 771 |
+
#define PyArray_FromDimsAndDataAndDescr \
|
| 772 |
+
(*(PyObject * (*)(int NPY_UNUSED(nd), int *NPY_UNUSED(d), PyArray_Descr *, char *NPY_UNUSED(data))) \
|
| 773 |
+
PyArray_API[68])
|
| 774 |
+
#define PyArray_FromAny \
|
| 775 |
+
(*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) \
|
| 776 |
+
PyArray_API[69])
|
| 777 |
+
#define PyArray_EnsureArray \
|
| 778 |
+
(*(PyObject * (*)(PyObject *)) \
|
| 779 |
+
PyArray_API[70])
|
| 780 |
+
#define PyArray_EnsureAnyArray \
|
| 781 |
+
(*(PyObject * (*)(PyObject *)) \
|
| 782 |
+
PyArray_API[71])
|
| 783 |
+
#define PyArray_FromFile \
|
| 784 |
+
(*(PyObject * (*)(FILE *, PyArray_Descr *, npy_intp, char *)) \
|
| 785 |
+
PyArray_API[72])
|
| 786 |
+
#define PyArray_FromString \
|
| 787 |
+
(*(PyObject * (*)(char *, npy_intp, PyArray_Descr *, npy_intp, char *)) \
|
| 788 |
+
PyArray_API[73])
|
| 789 |
+
#define PyArray_FromBuffer \
|
| 790 |
+
(*(PyObject * (*)(PyObject *, PyArray_Descr *, npy_intp, npy_intp)) \
|
| 791 |
+
PyArray_API[74])
|
| 792 |
+
#define PyArray_FromIter \
|
| 793 |
+
(*(PyObject * (*)(PyObject *, PyArray_Descr *, npy_intp)) \
|
| 794 |
+
PyArray_API[75])
|
| 795 |
+
#define PyArray_Return \
|
| 796 |
+
(*(PyObject * (*)(PyArrayObject *)) \
|
| 797 |
+
PyArray_API[76])
|
| 798 |
+
#define PyArray_GetField \
|
| 799 |
+
(*(PyObject * (*)(PyArrayObject *, PyArray_Descr *, int)) \
|
| 800 |
+
PyArray_API[77])
|
| 801 |
+
#define PyArray_SetField \
|
| 802 |
+
(*(int (*)(PyArrayObject *, PyArray_Descr *, int, PyObject *)) \
|
| 803 |
+
PyArray_API[78])
|
| 804 |
+
#define PyArray_Byteswap \
|
| 805 |
+
(*(PyObject * (*)(PyArrayObject *, npy_bool)) \
|
| 806 |
+
PyArray_API[79])
|
| 807 |
+
#define PyArray_Resize \
|
| 808 |
+
(*(PyObject * (*)(PyArrayObject *, PyArray_Dims *, int, NPY_ORDER NPY_UNUSED(order))) \
|
| 809 |
+
PyArray_API[80])
|
| 810 |
+
#define PyArray_MoveInto \
|
| 811 |
+
(*(int (*)(PyArrayObject *, PyArrayObject *)) \
|
| 812 |
+
PyArray_API[81])
|
| 813 |
+
#define PyArray_CopyInto \
|
| 814 |
+
(*(int (*)(PyArrayObject *, PyArrayObject *)) \
|
| 815 |
+
PyArray_API[82])
|
| 816 |
+
#define PyArray_CopyAnyInto \
|
| 817 |
+
(*(int (*)(PyArrayObject *, PyArrayObject *)) \
|
| 818 |
+
PyArray_API[83])
|
| 819 |
+
#define PyArray_CopyObject \
|
| 820 |
+
(*(int (*)(PyArrayObject *, PyObject *)) \
|
| 821 |
+
PyArray_API[84])
|
| 822 |
+
#define PyArray_NewCopy \
|
| 823 |
+
(*(PyObject * (*)(PyArrayObject *, NPY_ORDER)) \
|
| 824 |
+
PyArray_API[85])
|
| 825 |
+
#define PyArray_ToList \
|
| 826 |
+
(*(PyObject * (*)(PyArrayObject *)) \
|
| 827 |
+
PyArray_API[86])
|
| 828 |
+
#define PyArray_ToString \
|
| 829 |
+
(*(PyObject * (*)(PyArrayObject *, NPY_ORDER)) \
|
| 830 |
+
PyArray_API[87])
|
| 831 |
+
#define PyArray_ToFile \
|
| 832 |
+
(*(int (*)(PyArrayObject *, FILE *, char *, char *)) \
|
| 833 |
+
PyArray_API[88])
|
| 834 |
+
#define PyArray_Dump \
|
| 835 |
+
(*(int (*)(PyObject *, PyObject *, int)) \
|
| 836 |
+
PyArray_API[89])
|
| 837 |
+
#define PyArray_Dumps \
|
| 838 |
+
(*(PyObject * (*)(PyObject *, int)) \
|
| 839 |
+
PyArray_API[90])
|
| 840 |
+
#define PyArray_ValidType \
|
| 841 |
+
(*(int (*)(int)) \
|
| 842 |
+
PyArray_API[91])
|
| 843 |
+
#define PyArray_UpdateFlags \
|
| 844 |
+
(*(void (*)(PyArrayObject *, int)) \
|
| 845 |
+
PyArray_API[92])
|
| 846 |
+
#define PyArray_New \
|
| 847 |
+
(*(PyObject * (*)(PyTypeObject *, int, npy_intp const *, int, npy_intp const *, void *, int, int, PyObject *)) \
|
| 848 |
+
PyArray_API[93])
|
| 849 |
+
#define PyArray_NewFromDescr \
|
| 850 |
+
(*(PyObject * (*)(PyTypeObject *, PyArray_Descr *, int, npy_intp const *, npy_intp const *, void *, int, PyObject *)) \
|
| 851 |
+
PyArray_API[94])
|
| 852 |
+
#define PyArray_DescrNew \
|
| 853 |
+
(*(PyArray_Descr * (*)(PyArray_Descr *)) \
|
| 854 |
+
PyArray_API[95])
|
| 855 |
+
#define PyArray_DescrNewFromType \
|
| 856 |
+
(*(PyArray_Descr * (*)(int)) \
|
| 857 |
+
PyArray_API[96])
|
| 858 |
+
#define PyArray_GetPriority \
|
| 859 |
+
(*(double (*)(PyObject *, double)) \
|
| 860 |
+
PyArray_API[97])
|
| 861 |
+
#define PyArray_IterNew \
|
| 862 |
+
(*(PyObject * (*)(PyObject *)) \
|
| 863 |
+
PyArray_API[98])
|
| 864 |
+
#define PyArray_MultiIterNew \
|
| 865 |
+
(*(PyObject* (*)(int, ...)) \
|
| 866 |
+
PyArray_API[99])
|
| 867 |
+
#define PyArray_PyIntAsInt \
|
| 868 |
+
(*(int (*)(PyObject *)) \
|
| 869 |
+
PyArray_API[100])
|
| 870 |
+
#define PyArray_PyIntAsIntp \
|
| 871 |
+
(*(npy_intp (*)(PyObject *)) \
|
| 872 |
+
PyArray_API[101])
|
| 873 |
+
#define PyArray_Broadcast \
|
| 874 |
+
(*(int (*)(PyArrayMultiIterObject *)) \
|
| 875 |
+
PyArray_API[102])
|
| 876 |
+
#define PyArray_FillObjectArray \
|
| 877 |
+
(*(void (*)(PyArrayObject *, PyObject *)) \
|
| 878 |
+
PyArray_API[103])
|
| 879 |
+
#define PyArray_FillWithScalar \
|
| 880 |
+
(*(int (*)(PyArrayObject *, PyObject *)) \
|
| 881 |
+
PyArray_API[104])
|
| 882 |
+
#define PyArray_CheckStrides \
|
| 883 |
+
(*(npy_bool (*)(int, int, npy_intp, npy_intp, npy_intp const *, npy_intp const *)) \
|
| 884 |
+
PyArray_API[105])
|
| 885 |
+
#define PyArray_DescrNewByteorder \
|
| 886 |
+
(*(PyArray_Descr * (*)(PyArray_Descr *, char)) \
|
| 887 |
+
PyArray_API[106])
|
| 888 |
+
#define PyArray_IterAllButAxis \
|
| 889 |
+
(*(PyObject * (*)(PyObject *, int *)) \
|
| 890 |
+
PyArray_API[107])
|
| 891 |
+
#define PyArray_CheckFromAny \
|
| 892 |
+
(*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) \
|
| 893 |
+
PyArray_API[108])
|
| 894 |
+
#define PyArray_FromArray \
|
| 895 |
+
(*(PyObject * (*)(PyArrayObject *, PyArray_Descr *, int)) \
|
| 896 |
+
PyArray_API[109])
|
| 897 |
+
#define PyArray_FromInterface \
|
| 898 |
+
(*(PyObject * (*)(PyObject *)) \
|
| 899 |
+
PyArray_API[110])
|
| 900 |
+
#define PyArray_FromStructInterface \
|
| 901 |
+
(*(PyObject * (*)(PyObject *)) \
|
| 902 |
+
PyArray_API[111])
|
| 903 |
+
#define PyArray_FromArrayAttr \
|
| 904 |
+
(*(PyObject * (*)(PyObject *, PyArray_Descr *, PyObject *)) \
|
| 905 |
+
PyArray_API[112])
|
| 906 |
+
#define PyArray_ScalarKind \
|
| 907 |
+
(*(NPY_SCALARKIND (*)(int, PyArrayObject **)) \
|
| 908 |
+
PyArray_API[113])
|
| 909 |
+
#define PyArray_CanCoerceScalar \
|
| 910 |
+
(*(int (*)(int, int, NPY_SCALARKIND)) \
|
| 911 |
+
PyArray_API[114])
|
| 912 |
+
#define PyArray_NewFlagsObject \
|
| 913 |
+
(*(PyObject * (*)(PyObject *)) \
|
| 914 |
+
PyArray_API[115])
|
| 915 |
+
#define PyArray_CanCastScalar \
|
| 916 |
+
(*(npy_bool (*)(PyTypeObject *, PyTypeObject *)) \
|
| 917 |
+
PyArray_API[116])
|
| 918 |
+
#define PyArray_CompareUCS4 \
|
| 919 |
+
(*(int (*)(npy_ucs4 const *, npy_ucs4 const *, size_t)) \
|
| 920 |
+
PyArray_API[117])
|
| 921 |
+
#define PyArray_RemoveSmallest \
|
| 922 |
+
(*(int (*)(PyArrayMultiIterObject *)) \
|
| 923 |
+
PyArray_API[118])
|
| 924 |
+
#define PyArray_ElementStrides \
|
| 925 |
+
(*(int (*)(PyObject *)) \
|
| 926 |
+
PyArray_API[119])
|
| 927 |
+
#define PyArray_Item_INCREF \
|
| 928 |
+
(*(void (*)(char *, PyArray_Descr *)) \
|
| 929 |
+
PyArray_API[120])
|
| 930 |
+
#define PyArray_Item_XDECREF \
|
| 931 |
+
(*(void (*)(char *, PyArray_Descr *)) \
|
| 932 |
+
PyArray_API[121])
|
| 933 |
+
#define PyArray_FieldNames \
|
| 934 |
+
(*(PyObject * (*)(PyObject *)) \
|
| 935 |
+
PyArray_API[122])
|
| 936 |
+
#define PyArray_Transpose \
|
| 937 |
+
(*(PyObject * (*)(PyArrayObject *, PyArray_Dims *)) \
|
| 938 |
+
PyArray_API[123])
|
| 939 |
+
#define PyArray_TakeFrom \
|
| 940 |
+
(*(PyObject * (*)(PyArrayObject *, PyObject *, int, PyArrayObject *, NPY_CLIPMODE)) \
|
| 941 |
+
PyArray_API[124])
|
| 942 |
+
#define PyArray_PutTo \
|
| 943 |
+
(*(PyObject * (*)(PyArrayObject *, PyObject*, PyObject *, NPY_CLIPMODE)) \
|
| 944 |
+
PyArray_API[125])
|
| 945 |
+
#define PyArray_PutMask \
|
| 946 |
+
(*(PyObject * (*)(PyArrayObject *, PyObject*, PyObject*)) \
|
| 947 |
+
PyArray_API[126])
|
| 948 |
+
#define PyArray_Repeat \
|
| 949 |
+
(*(PyObject * (*)(PyArrayObject *, PyObject *, int)) \
|
| 950 |
+
PyArray_API[127])
|
| 951 |
+
#define PyArray_Choose \
|
| 952 |
+
(*(PyObject * (*)(PyArrayObject *, PyObject *, PyArrayObject *, NPY_CLIPMODE)) \
|
| 953 |
+
PyArray_API[128])
|
| 954 |
+
#define PyArray_Sort \
|
| 955 |
+
(*(int (*)(PyArrayObject *, int, NPY_SORTKIND)) \
|
| 956 |
+
PyArray_API[129])
|
| 957 |
+
#define PyArray_ArgSort \
|
| 958 |
+
(*(PyObject * (*)(PyArrayObject *, int, NPY_SORTKIND)) \
|
| 959 |
+
PyArray_API[130])
|
| 960 |
+
#define PyArray_SearchSorted \
|
| 961 |
+
(*(PyObject * (*)(PyArrayObject *, PyObject *, NPY_SEARCHSIDE, PyObject *)) \
|
| 962 |
+
PyArray_API[131])
|
| 963 |
+
#define PyArray_ArgMax \
|
| 964 |
+
(*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
|
| 965 |
+
PyArray_API[132])
|
| 966 |
+
#define PyArray_ArgMin \
|
| 967 |
+
(*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
|
| 968 |
+
PyArray_API[133])
|
| 969 |
+
#define PyArray_Reshape \
|
| 970 |
+
(*(PyObject * (*)(PyArrayObject *, PyObject *)) \
|
| 971 |
+
PyArray_API[134])
|
| 972 |
+
#define PyArray_Newshape \
|
| 973 |
+
(*(PyObject * (*)(PyArrayObject *, PyArray_Dims *, NPY_ORDER)) \
|
| 974 |
+
PyArray_API[135])
|
| 975 |
+
#define PyArray_Squeeze \
|
| 976 |
+
(*(PyObject * (*)(PyArrayObject *)) \
|
| 977 |
+
PyArray_API[136])
|
| 978 |
+
#define PyArray_View \
|
| 979 |
+
(*(PyObject * (*)(PyArrayObject *, PyArray_Descr *, PyTypeObject *)) \
|
| 980 |
+
PyArray_API[137])
|
| 981 |
+
#define PyArray_SwapAxes \
|
| 982 |
+
(*(PyObject * (*)(PyArrayObject *, int, int)) \
|
| 983 |
+
PyArray_API[138])
|
| 984 |
+
#define PyArray_Max \
|
| 985 |
+
(*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
|
| 986 |
+
PyArray_API[139])
|
| 987 |
+
#define PyArray_Min \
|
| 988 |
+
(*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
|
| 989 |
+
PyArray_API[140])
|
| 990 |
+
#define PyArray_Ptp \
|
| 991 |
+
(*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
|
| 992 |
+
PyArray_API[141])
|
| 993 |
+
#define PyArray_Mean \
|
| 994 |
+
(*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
|
| 995 |
+
PyArray_API[142])
|
| 996 |
+
#define PyArray_Trace \
|
| 997 |
+
(*(PyObject * (*)(PyArrayObject *, int, int, int, int, PyArrayObject *)) \
|
| 998 |
+
PyArray_API[143])
|
| 999 |
+
#define PyArray_Diagonal \
|
| 1000 |
+
(*(PyObject * (*)(PyArrayObject *, int, int, int)) \
|
| 1001 |
+
PyArray_API[144])
|
| 1002 |
+
#define PyArray_Clip \
|
| 1003 |
+
(*(PyObject * (*)(PyArrayObject *, PyObject *, PyObject *, PyArrayObject *)) \
|
| 1004 |
+
PyArray_API[145])
|
| 1005 |
+
#define PyArray_Conjugate \
|
| 1006 |
+
(*(PyObject * (*)(PyArrayObject *, PyArrayObject *)) \
|
| 1007 |
+
PyArray_API[146])
|
| 1008 |
+
#define PyArray_Nonzero \
|
| 1009 |
+
(*(PyObject * (*)(PyArrayObject *)) \
|
| 1010 |
+
PyArray_API[147])
|
| 1011 |
+
#define PyArray_Std \
|
| 1012 |
+
(*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *, int)) \
|
| 1013 |
+
PyArray_API[148])
|
| 1014 |
+
#define PyArray_Sum \
|
| 1015 |
+
(*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
|
| 1016 |
+
PyArray_API[149])
|
| 1017 |
+
#define PyArray_CumSum \
|
| 1018 |
+
(*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
|
| 1019 |
+
PyArray_API[150])
|
| 1020 |
+
#define PyArray_Prod \
|
| 1021 |
+
(*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
|
| 1022 |
+
PyArray_API[151])
|
| 1023 |
+
#define PyArray_CumProd \
|
| 1024 |
+
(*(PyObject * (*)(PyArrayObject *, int, int, PyArrayObject *)) \
|
| 1025 |
+
PyArray_API[152])
|
| 1026 |
+
#define PyArray_All \
|
| 1027 |
+
(*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
|
| 1028 |
+
PyArray_API[153])
|
| 1029 |
+
#define PyArray_Any \
|
| 1030 |
+
(*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
|
| 1031 |
+
PyArray_API[154])
|
| 1032 |
+
#define PyArray_Compress \
|
| 1033 |
+
(*(PyObject * (*)(PyArrayObject *, PyObject *, int, PyArrayObject *)) \
|
| 1034 |
+
PyArray_API[155])
|
| 1035 |
+
#define PyArray_Flatten \
|
| 1036 |
+
(*(PyObject * (*)(PyArrayObject *, NPY_ORDER)) \
|
| 1037 |
+
PyArray_API[156])
|
| 1038 |
+
#define PyArray_Ravel \
|
| 1039 |
+
(*(PyObject * (*)(PyArrayObject *, NPY_ORDER)) \
|
| 1040 |
+
PyArray_API[157])
|
| 1041 |
+
#define PyArray_MultiplyList \
|
| 1042 |
+
(*(npy_intp (*)(npy_intp const *, int)) \
|
| 1043 |
+
PyArray_API[158])
|
| 1044 |
+
#define PyArray_MultiplyIntList \
|
| 1045 |
+
(*(int (*)(int const *, int)) \
|
| 1046 |
+
PyArray_API[159])
|
| 1047 |
+
#define PyArray_GetPtr \
|
| 1048 |
+
(*(void * (*)(PyArrayObject *, npy_intp const*)) \
|
| 1049 |
+
PyArray_API[160])
|
| 1050 |
+
#define PyArray_CompareLists \
|
| 1051 |
+
(*(int (*)(npy_intp const *, npy_intp const *, int)) \
|
| 1052 |
+
PyArray_API[161])
|
| 1053 |
+
#define PyArray_AsCArray \
|
| 1054 |
+
(*(int (*)(PyObject **, void *, npy_intp *, int, PyArray_Descr*)) \
|
| 1055 |
+
PyArray_API[162])
|
| 1056 |
+
#define PyArray_As1D \
|
| 1057 |
+
(*(int (*)(PyObject **NPY_UNUSED(op), char **NPY_UNUSED(ptr), int *NPY_UNUSED(d1), int NPY_UNUSED(typecode))) \
|
| 1058 |
+
PyArray_API[163])
|
| 1059 |
+
#define PyArray_As2D \
|
| 1060 |
+
(*(int (*)(PyObject **NPY_UNUSED(op), char ***NPY_UNUSED(ptr), int *NPY_UNUSED(d1), int *NPY_UNUSED(d2), int NPY_UNUSED(typecode))) \
|
| 1061 |
+
PyArray_API[164])
|
| 1062 |
+
#define PyArray_Free \
|
| 1063 |
+
(*(int (*)(PyObject *, void *)) \
|
| 1064 |
+
PyArray_API[165])
|
| 1065 |
+
#define PyArray_Converter \
|
| 1066 |
+
(*(int (*)(PyObject *, PyObject **)) \
|
| 1067 |
+
PyArray_API[166])
|
| 1068 |
+
#define PyArray_IntpFromSequence \
|
| 1069 |
+
(*(int (*)(PyObject *, npy_intp *, int)) \
|
| 1070 |
+
PyArray_API[167])
|
| 1071 |
+
#define PyArray_Concatenate \
|
| 1072 |
+
(*(PyObject * (*)(PyObject *, int)) \
|
| 1073 |
+
PyArray_API[168])
|
| 1074 |
+
#define PyArray_InnerProduct \
|
| 1075 |
+
(*(PyObject * (*)(PyObject *, PyObject *)) \
|
| 1076 |
+
PyArray_API[169])
|
| 1077 |
+
#define PyArray_MatrixProduct \
|
| 1078 |
+
(*(PyObject * (*)(PyObject *, PyObject *)) \
|
| 1079 |
+
PyArray_API[170])
|
| 1080 |
+
#define PyArray_CopyAndTranspose \
|
| 1081 |
+
(*(PyObject * (*)(PyObject *)) \
|
| 1082 |
+
PyArray_API[171])
|
| 1083 |
+
#define PyArray_Correlate \
|
| 1084 |
+
(*(PyObject * (*)(PyObject *, PyObject *, int)) \
|
| 1085 |
+
PyArray_API[172])
|
| 1086 |
+
#define PyArray_TypestrConvert \
|
| 1087 |
+
(*(int (*)(int, int)) \
|
| 1088 |
+
PyArray_API[173])
|
| 1089 |
+
#define PyArray_DescrConverter \
|
| 1090 |
+
(*(int (*)(PyObject *, PyArray_Descr **)) \
|
| 1091 |
+
PyArray_API[174])
|
| 1092 |
+
#define PyArray_DescrConverter2 \
|
| 1093 |
+
(*(int (*)(PyObject *, PyArray_Descr **)) \
|
| 1094 |
+
PyArray_API[175])
|
| 1095 |
+
#define PyArray_IntpConverter \
|
| 1096 |
+
(*(int (*)(PyObject *, PyArray_Dims *)) \
|
| 1097 |
+
PyArray_API[176])
|
| 1098 |
+
#define PyArray_BufferConverter \
|
| 1099 |
+
(*(int (*)(PyObject *, PyArray_Chunk *)) \
|
| 1100 |
+
PyArray_API[177])
|
| 1101 |
+
#define PyArray_AxisConverter \
|
| 1102 |
+
(*(int (*)(PyObject *, int *)) \
|
| 1103 |
+
PyArray_API[178])
|
| 1104 |
+
#define PyArray_BoolConverter \
|
| 1105 |
+
(*(int (*)(PyObject *, npy_bool *)) \
|
| 1106 |
+
PyArray_API[179])
|
| 1107 |
+
#define PyArray_ByteorderConverter \
|
| 1108 |
+
(*(int (*)(PyObject *, char *)) \
|
| 1109 |
+
PyArray_API[180])
|
| 1110 |
+
#define PyArray_OrderConverter \
|
| 1111 |
+
(*(int (*)(PyObject *, NPY_ORDER *)) \
|
| 1112 |
+
PyArray_API[181])
|
| 1113 |
+
#define PyArray_EquivTypes \
|
| 1114 |
+
(*(unsigned char (*)(PyArray_Descr *, PyArray_Descr *)) \
|
| 1115 |
+
PyArray_API[182])
|
| 1116 |
+
#define PyArray_Zeros \
|
| 1117 |
+
(*(PyObject * (*)(int, npy_intp const *, PyArray_Descr *, int)) \
|
| 1118 |
+
PyArray_API[183])
|
| 1119 |
+
#define PyArray_Empty \
|
| 1120 |
+
(*(PyObject * (*)(int, npy_intp const *, PyArray_Descr *, int)) \
|
| 1121 |
+
PyArray_API[184])
|
| 1122 |
+
#define PyArray_Where \
|
| 1123 |
+
(*(PyObject * (*)(PyObject *, PyObject *, PyObject *)) \
|
| 1124 |
+
PyArray_API[185])
|
| 1125 |
+
#define PyArray_Arange \
|
| 1126 |
+
(*(PyObject * (*)(double, double, double, int)) \
|
| 1127 |
+
PyArray_API[186])
|
| 1128 |
+
#define PyArray_ArangeObj \
|
| 1129 |
+
(*(PyObject * (*)(PyObject *, PyObject *, PyObject *, PyArray_Descr *)) \
|
| 1130 |
+
PyArray_API[187])
|
| 1131 |
+
#define PyArray_SortkindConverter \
|
| 1132 |
+
(*(int (*)(PyObject *, NPY_SORTKIND *)) \
|
| 1133 |
+
PyArray_API[188])
|
| 1134 |
+
#define PyArray_LexSort \
|
| 1135 |
+
(*(PyObject * (*)(PyObject *, int)) \
|
| 1136 |
+
PyArray_API[189])
|
| 1137 |
+
#define PyArray_Round \
|
| 1138 |
+
(*(PyObject * (*)(PyArrayObject *, int, PyArrayObject *)) \
|
| 1139 |
+
PyArray_API[190])
|
| 1140 |
+
#define PyArray_EquivTypenums \
|
| 1141 |
+
(*(unsigned char (*)(int, int)) \
|
| 1142 |
+
PyArray_API[191])
|
| 1143 |
+
#define PyArray_RegisterDataType \
|
| 1144 |
+
(*(int (*)(PyArray_Descr *)) \
|
| 1145 |
+
PyArray_API[192])
|
| 1146 |
+
#define PyArray_RegisterCastFunc \
|
| 1147 |
+
(*(int (*)(PyArray_Descr *, int, PyArray_VectorUnaryFunc *)) \
|
| 1148 |
+
PyArray_API[193])
|
| 1149 |
+
#define PyArray_RegisterCanCast \
|
| 1150 |
+
(*(int (*)(PyArray_Descr *, int, NPY_SCALARKIND)) \
|
| 1151 |
+
PyArray_API[194])
|
| 1152 |
+
#define PyArray_InitArrFuncs \
|
| 1153 |
+
(*(void (*)(PyArray_ArrFuncs *)) \
|
| 1154 |
+
PyArray_API[195])
|
| 1155 |
+
#define PyArray_IntTupleFromIntp \
|
| 1156 |
+
(*(PyObject * (*)(int, npy_intp const *)) \
|
| 1157 |
+
PyArray_API[196])
|
| 1158 |
+
#define PyArray_TypeNumFromName \
|
| 1159 |
+
(*(int (*)(char const *)) \
|
| 1160 |
+
PyArray_API[197])
|
| 1161 |
+
#define PyArray_ClipmodeConverter \
|
| 1162 |
+
(*(int (*)(PyObject *, NPY_CLIPMODE *)) \
|
| 1163 |
+
PyArray_API[198])
|
| 1164 |
+
#define PyArray_OutputConverter \
|
| 1165 |
+
(*(int (*)(PyObject *, PyArrayObject **)) \
|
| 1166 |
+
PyArray_API[199])
|
| 1167 |
+
#define PyArray_BroadcastToShape \
|
| 1168 |
+
(*(PyObject * (*)(PyObject *, npy_intp *, int)) \
|
| 1169 |
+
PyArray_API[200])
|
| 1170 |
+
#define _PyArray_SigintHandler \
|
| 1171 |
+
(*(void (*)(int)) \
|
| 1172 |
+
PyArray_API[201])
|
| 1173 |
+
#define _PyArray_GetSigintBuf \
|
| 1174 |
+
(*(void* (*)(void)) \
|
| 1175 |
+
PyArray_API[202])
|
| 1176 |
+
#define PyArray_DescrAlignConverter \
|
| 1177 |
+
(*(int (*)(PyObject *, PyArray_Descr **)) \
|
| 1178 |
+
PyArray_API[203])
|
| 1179 |
+
#define PyArray_DescrAlignConverter2 \
|
| 1180 |
+
(*(int (*)(PyObject *, PyArray_Descr **)) \
|
| 1181 |
+
PyArray_API[204])
|
| 1182 |
+
#define PyArray_SearchsideConverter \
|
| 1183 |
+
(*(int (*)(PyObject *, void *)) \
|
| 1184 |
+
PyArray_API[205])
|
| 1185 |
+
#define PyArray_CheckAxis \
|
| 1186 |
+
(*(PyObject * (*)(PyArrayObject *, int *, int)) \
|
| 1187 |
+
PyArray_API[206])
|
| 1188 |
+
#define PyArray_OverflowMultiplyList \
|
| 1189 |
+
(*(npy_intp (*)(npy_intp const *, int)) \
|
| 1190 |
+
PyArray_API[207])
|
| 1191 |
+
#define PyArray_CompareString \
|
| 1192 |
+
(*(int (*)(const char *, const char *, size_t)) \
|
| 1193 |
+
PyArray_API[208])
|
| 1194 |
+
#define PyArray_MultiIterFromObjects \
|
| 1195 |
+
(*(PyObject* (*)(PyObject **, int, int, ...)) \
|
| 1196 |
+
PyArray_API[209])
|
| 1197 |
+
#define PyArray_GetEndianness \
|
| 1198 |
+
(*(int (*)(void)) \
|
| 1199 |
+
PyArray_API[210])
|
| 1200 |
+
#define PyArray_GetNDArrayCFeatureVersion \
|
| 1201 |
+
(*(unsigned int (*)(void)) \
|
| 1202 |
+
PyArray_API[211])
|
| 1203 |
+
#define PyArray_Correlate2 \
|
| 1204 |
+
(*(PyObject * (*)(PyObject *, PyObject *, int)) \
|
| 1205 |
+
PyArray_API[212])
|
| 1206 |
+
#define PyArray_NeighborhoodIterNew \
|
| 1207 |
+
(*(PyObject* (*)(PyArrayIterObject *, const npy_intp *, int, PyArrayObject*)) \
|
| 1208 |
+
PyArray_API[213])
|
| 1209 |
+
#define PyTimeIntegerArrType_Type (*(PyTypeObject *)PyArray_API[214])
|
| 1210 |
+
#define PyDatetimeArrType_Type (*(PyTypeObject *)PyArray_API[215])
|
| 1211 |
+
#define PyTimedeltaArrType_Type (*(PyTypeObject *)PyArray_API[216])
|
| 1212 |
+
#define PyHalfArrType_Type (*(PyTypeObject *)PyArray_API[217])
|
| 1213 |
+
#define NpyIter_Type (*(PyTypeObject *)PyArray_API[218])
|
| 1214 |
+
#define PyArray_SetDatetimeParseFunction \
|
| 1215 |
+
(*(void (*)(PyObject *NPY_UNUSED(op))) \
|
| 1216 |
+
PyArray_API[219])
|
| 1217 |
+
#define PyArray_DatetimeToDatetimeStruct \
|
| 1218 |
+
(*(void (*)(npy_datetime NPY_UNUSED(val), NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_datetimestruct *)) \
|
| 1219 |
+
PyArray_API[220])
|
| 1220 |
+
#define PyArray_TimedeltaToTimedeltaStruct \
|
| 1221 |
+
(*(void (*)(npy_timedelta NPY_UNUSED(val), NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_timedeltastruct *)) \
|
| 1222 |
+
PyArray_API[221])
|
| 1223 |
+
#define PyArray_DatetimeStructToDatetime \
|
| 1224 |
+
(*(npy_datetime (*)(NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_datetimestruct *NPY_UNUSED(d))) \
|
| 1225 |
+
PyArray_API[222])
|
| 1226 |
+
#define PyArray_TimedeltaStructToTimedelta \
|
| 1227 |
+
(*(npy_datetime (*)(NPY_DATETIMEUNIT NPY_UNUSED(fr), npy_timedeltastruct *NPY_UNUSED(d))) \
|
| 1228 |
+
PyArray_API[223])
|
| 1229 |
+
#define NpyIter_New \
|
| 1230 |
+
(*(NpyIter * (*)(PyArrayObject *, npy_uint32, NPY_ORDER, NPY_CASTING, PyArray_Descr*)) \
|
| 1231 |
+
PyArray_API[224])
|
| 1232 |
+
#define NpyIter_MultiNew \
|
| 1233 |
+
(*(NpyIter * (*)(int, PyArrayObject **, npy_uint32, NPY_ORDER, NPY_CASTING, npy_uint32 *, PyArray_Descr **)) \
|
| 1234 |
+
PyArray_API[225])
|
| 1235 |
+
#define NpyIter_AdvancedNew \
|
| 1236 |
+
(*(NpyIter * (*)(int, PyArrayObject **, npy_uint32, NPY_ORDER, NPY_CASTING, npy_uint32 *, PyArray_Descr **, int, int **, npy_intp *, npy_intp)) \
|
| 1237 |
+
PyArray_API[226])
|
| 1238 |
+
#define NpyIter_Copy \
|
| 1239 |
+
(*(NpyIter * (*)(NpyIter *)) \
|
| 1240 |
+
PyArray_API[227])
|
| 1241 |
+
#define NpyIter_Deallocate \
|
| 1242 |
+
(*(int (*)(NpyIter *)) \
|
| 1243 |
+
PyArray_API[228])
|
| 1244 |
+
#define NpyIter_HasDelayedBufAlloc \
|
| 1245 |
+
(*(npy_bool (*)(NpyIter *)) \
|
| 1246 |
+
PyArray_API[229])
|
| 1247 |
+
#define NpyIter_HasExternalLoop \
|
| 1248 |
+
(*(npy_bool (*)(NpyIter *)) \
|
| 1249 |
+
PyArray_API[230])
|
| 1250 |
+
#define NpyIter_EnableExternalLoop \
|
| 1251 |
+
(*(int (*)(NpyIter *)) \
|
| 1252 |
+
PyArray_API[231])
|
| 1253 |
+
#define NpyIter_GetInnerStrideArray \
|
| 1254 |
+
(*(npy_intp * (*)(NpyIter *)) \
|
| 1255 |
+
PyArray_API[232])
|
| 1256 |
+
#define NpyIter_GetInnerLoopSizePtr \
|
| 1257 |
+
(*(npy_intp * (*)(NpyIter *)) \
|
| 1258 |
+
PyArray_API[233])
|
| 1259 |
+
#define NpyIter_Reset \
|
| 1260 |
+
(*(int (*)(NpyIter *, char **)) \
|
| 1261 |
+
PyArray_API[234])
|
| 1262 |
+
#define NpyIter_ResetBasePointers \
|
| 1263 |
+
(*(int (*)(NpyIter *, char **, char **)) \
|
| 1264 |
+
PyArray_API[235])
|
| 1265 |
+
#define NpyIter_ResetToIterIndexRange \
|
| 1266 |
+
(*(int (*)(NpyIter *, npy_intp, npy_intp, char **)) \
|
| 1267 |
+
PyArray_API[236])
|
| 1268 |
+
#define NpyIter_GetNDim \
|
| 1269 |
+
(*(int (*)(NpyIter *)) \
|
| 1270 |
+
PyArray_API[237])
|
| 1271 |
+
#define NpyIter_GetNOp \
|
| 1272 |
+
(*(int (*)(NpyIter *)) \
|
| 1273 |
+
PyArray_API[238])
|
| 1274 |
+
#define NpyIter_GetIterNext \
|
| 1275 |
+
(*(NpyIter_IterNextFunc * (*)(NpyIter *, char **)) \
|
| 1276 |
+
PyArray_API[239])
|
| 1277 |
+
#define NpyIter_GetIterSize \
|
| 1278 |
+
(*(npy_intp (*)(NpyIter *)) \
|
| 1279 |
+
PyArray_API[240])
|
| 1280 |
+
#define NpyIter_GetIterIndexRange \
|
| 1281 |
+
(*(void (*)(NpyIter *, npy_intp *, npy_intp *)) \
|
| 1282 |
+
PyArray_API[241])
|
| 1283 |
+
#define NpyIter_GetIterIndex \
|
| 1284 |
+
(*(npy_intp (*)(NpyIter *)) \
|
| 1285 |
+
PyArray_API[242])
|
| 1286 |
+
#define NpyIter_GotoIterIndex \
|
| 1287 |
+
(*(int (*)(NpyIter *, npy_intp)) \
|
| 1288 |
+
PyArray_API[243])
|
| 1289 |
+
#define NpyIter_HasMultiIndex \
|
| 1290 |
+
(*(npy_bool (*)(NpyIter *)) \
|
| 1291 |
+
PyArray_API[244])
|
| 1292 |
+
#define NpyIter_GetShape \
|
| 1293 |
+
(*(int (*)(NpyIter *, npy_intp *)) \
|
| 1294 |
+
PyArray_API[245])
|
| 1295 |
+
#define NpyIter_GetGetMultiIndex \
|
| 1296 |
+
(*(NpyIter_GetMultiIndexFunc * (*)(NpyIter *, char **)) \
|
| 1297 |
+
PyArray_API[246])
|
| 1298 |
+
#define NpyIter_GotoMultiIndex \
|
| 1299 |
+
(*(int (*)(NpyIter *, npy_intp const *)) \
|
| 1300 |
+
PyArray_API[247])
|
| 1301 |
+
#define NpyIter_RemoveMultiIndex \
|
| 1302 |
+
(*(int (*)(NpyIter *)) \
|
| 1303 |
+
PyArray_API[248])
|
| 1304 |
+
#define NpyIter_HasIndex \
|
| 1305 |
+
(*(npy_bool (*)(NpyIter *)) \
|
| 1306 |
+
PyArray_API[249])
|
| 1307 |
+
#define NpyIter_IsBuffered \
|
| 1308 |
+
(*(npy_bool (*)(NpyIter *)) \
|
| 1309 |
+
PyArray_API[250])
|
| 1310 |
+
#define NpyIter_IsGrowInner \
|
| 1311 |
+
(*(npy_bool (*)(NpyIter *)) \
|
| 1312 |
+
PyArray_API[251])
|
| 1313 |
+
#define NpyIter_GetBufferSize \
|
| 1314 |
+
(*(npy_intp (*)(NpyIter *)) \
|
| 1315 |
+
PyArray_API[252])
|
| 1316 |
+
#define NpyIter_GetIndexPtr \
|
| 1317 |
+
(*(npy_intp * (*)(NpyIter *)) \
|
| 1318 |
+
PyArray_API[253])
|
| 1319 |
+
#define NpyIter_GotoIndex \
|
| 1320 |
+
(*(int (*)(NpyIter *, npy_intp)) \
|
| 1321 |
+
PyArray_API[254])
|
| 1322 |
+
#define NpyIter_GetDataPtrArray \
|
| 1323 |
+
(*(char ** (*)(NpyIter *)) \
|
| 1324 |
+
PyArray_API[255])
|
| 1325 |
+
#define NpyIter_GetDescrArray \
|
| 1326 |
+
(*(PyArray_Descr ** (*)(NpyIter *)) \
|
| 1327 |
+
PyArray_API[256])
|
| 1328 |
+
#define NpyIter_GetOperandArray \
|
| 1329 |
+
(*(PyArrayObject ** (*)(NpyIter *)) \
|
| 1330 |
+
PyArray_API[257])
|
| 1331 |
+
#define NpyIter_GetIterView \
|
| 1332 |
+
(*(PyArrayObject * (*)(NpyIter *, npy_intp)) \
|
| 1333 |
+
PyArray_API[258])
|
| 1334 |
+
#define NpyIter_GetReadFlags \
|
| 1335 |
+
(*(void (*)(NpyIter *, char *)) \
|
| 1336 |
+
PyArray_API[259])
|
| 1337 |
+
#define NpyIter_GetWriteFlags \
|
| 1338 |
+
(*(void (*)(NpyIter *, char *)) \
|
| 1339 |
+
PyArray_API[260])
|
| 1340 |
+
#define NpyIter_DebugPrint \
|
| 1341 |
+
(*(void (*)(NpyIter *)) \
|
| 1342 |
+
PyArray_API[261])
|
| 1343 |
+
#define NpyIter_IterationNeedsAPI \
|
| 1344 |
+
(*(npy_bool (*)(NpyIter *)) \
|
| 1345 |
+
PyArray_API[262])
|
| 1346 |
+
#define NpyIter_GetInnerFixedStrideArray \
|
| 1347 |
+
(*(void (*)(NpyIter *, npy_intp *)) \
|
| 1348 |
+
PyArray_API[263])
|
| 1349 |
+
#define NpyIter_RemoveAxis \
|
| 1350 |
+
(*(int (*)(NpyIter *, int)) \
|
| 1351 |
+
PyArray_API[264])
|
| 1352 |
+
#define NpyIter_GetAxisStrideArray \
|
| 1353 |
+
(*(npy_intp * (*)(NpyIter *, int)) \
|
| 1354 |
+
PyArray_API[265])
|
| 1355 |
+
#define NpyIter_RequiresBuffering \
|
| 1356 |
+
(*(npy_bool (*)(NpyIter *)) \
|
| 1357 |
+
PyArray_API[266])
|
| 1358 |
+
#define NpyIter_GetInitialDataPtrArray \
|
| 1359 |
+
(*(char ** (*)(NpyIter *)) \
|
| 1360 |
+
PyArray_API[267])
|
| 1361 |
+
#define NpyIter_CreateCompatibleStrides \
|
| 1362 |
+
(*(int (*)(NpyIter *, npy_intp, npy_intp *)) \
|
| 1363 |
+
PyArray_API[268])
|
| 1364 |
+
#define PyArray_CastingConverter \
|
| 1365 |
+
(*(int (*)(PyObject *, NPY_CASTING *)) \
|
| 1366 |
+
PyArray_API[269])
|
| 1367 |
+
#define PyArray_CountNonzero \
|
| 1368 |
+
(*(npy_intp (*)(PyArrayObject *)) \
|
| 1369 |
+
PyArray_API[270])
|
| 1370 |
+
#define PyArray_PromoteTypes \
|
| 1371 |
+
(*(PyArray_Descr * (*)(PyArray_Descr *, PyArray_Descr *)) \
|
| 1372 |
+
PyArray_API[271])
|
| 1373 |
+
#define PyArray_MinScalarType \
|
| 1374 |
+
(*(PyArray_Descr * (*)(PyArrayObject *)) \
|
| 1375 |
+
PyArray_API[272])
|
| 1376 |
+
#define PyArray_ResultType \
|
| 1377 |
+
(*(PyArray_Descr * (*)(npy_intp, PyArrayObject *arrs[], npy_intp, PyArray_Descr *descrs[])) \
|
| 1378 |
+
PyArray_API[273])
|
| 1379 |
+
#define PyArray_CanCastArrayTo \
|
| 1380 |
+
(*(npy_bool (*)(PyArrayObject *, PyArray_Descr *, NPY_CASTING)) \
|
| 1381 |
+
PyArray_API[274])
|
| 1382 |
+
#define PyArray_CanCastTypeTo \
|
| 1383 |
+
(*(npy_bool (*)(PyArray_Descr *, PyArray_Descr *, NPY_CASTING)) \
|
| 1384 |
+
PyArray_API[275])
|
| 1385 |
+
#define PyArray_EinsteinSum \
|
| 1386 |
+
(*(PyArrayObject * (*)(char *, npy_intp, PyArrayObject **, PyArray_Descr *, NPY_ORDER, NPY_CASTING, PyArrayObject *)) \
|
| 1387 |
+
PyArray_API[276])
|
| 1388 |
+
#define PyArray_NewLikeArray \
|
| 1389 |
+
(*(PyObject * (*)(PyArrayObject *, NPY_ORDER, PyArray_Descr *, int)) \
|
| 1390 |
+
PyArray_API[277])
|
| 1391 |
+
#define PyArray_GetArrayParamsFromObject \
|
| 1392 |
+
(*(int (*)(PyObject *NPY_UNUSED(op), PyArray_Descr *NPY_UNUSED(requested_dtype), npy_bool NPY_UNUSED(writeable), PyArray_Descr **NPY_UNUSED(out_dtype), int *NPY_UNUSED(out_ndim), npy_intp *NPY_UNUSED(out_dims), PyArrayObject **NPY_UNUSED(out_arr), PyObject *NPY_UNUSED(context))) \
|
| 1393 |
+
PyArray_API[278])
|
| 1394 |
+
#define PyArray_ConvertClipmodeSequence \
|
| 1395 |
+
(*(int (*)(PyObject *, NPY_CLIPMODE *, int)) \
|
| 1396 |
+
PyArray_API[279])
|
| 1397 |
+
#define PyArray_MatrixProduct2 \
|
| 1398 |
+
(*(PyObject * (*)(PyObject *, PyObject *, PyArrayObject*)) \
|
| 1399 |
+
PyArray_API[280])
|
| 1400 |
+
#define NpyIter_IsFirstVisit \
|
| 1401 |
+
(*(npy_bool (*)(NpyIter *, int)) \
|
| 1402 |
+
PyArray_API[281])
|
| 1403 |
+
#define PyArray_SetBaseObject \
|
| 1404 |
+
(*(int (*)(PyArrayObject *, PyObject *)) \
|
| 1405 |
+
PyArray_API[282])
|
| 1406 |
+
#define PyArray_CreateSortedStridePerm \
|
| 1407 |
+
(*(void (*)(int, npy_intp const *, npy_stride_sort_item *)) \
|
| 1408 |
+
PyArray_API[283])
|
| 1409 |
+
#define PyArray_RemoveAxesInPlace \
|
| 1410 |
+
(*(void (*)(PyArrayObject *, const npy_bool *)) \
|
| 1411 |
+
PyArray_API[284])
|
| 1412 |
+
#define PyArray_DebugPrint \
|
| 1413 |
+
(*(void (*)(PyArrayObject *)) \
|
| 1414 |
+
PyArray_API[285])
|
| 1415 |
+
#define PyArray_FailUnlessWriteable \
|
| 1416 |
+
(*(int (*)(PyArrayObject *, const char *)) \
|
| 1417 |
+
PyArray_API[286])
|
| 1418 |
+
#define PyArray_SetUpdateIfCopyBase \
|
| 1419 |
+
(*(int (*)(PyArrayObject *, PyArrayObject *)) \
|
| 1420 |
+
PyArray_API[287])
|
| 1421 |
+
#define PyDataMem_NEW \
|
| 1422 |
+
(*(void * (*)(size_t)) \
|
| 1423 |
+
PyArray_API[288])
|
| 1424 |
+
#define PyDataMem_FREE \
|
| 1425 |
+
(*(void (*)(void *)) \
|
| 1426 |
+
PyArray_API[289])
|
| 1427 |
+
#define PyDataMem_RENEW \
|
| 1428 |
+
(*(void * (*)(void *, size_t)) \
|
| 1429 |
+
PyArray_API[290])
|
| 1430 |
+
#define PyDataMem_SetEventHook \
|
| 1431 |
+
(*(PyDataMem_EventHookFunc * (*)(PyDataMem_EventHookFunc *, void *, void **)) \
|
| 1432 |
+
PyArray_API[291])
|
| 1433 |
+
#define NPY_DEFAULT_ASSIGN_CASTING (*(NPY_CASTING *)PyArray_API[292])
|
| 1434 |
+
#define PyArray_MapIterSwapAxes \
|
| 1435 |
+
(*(void (*)(PyArrayMapIterObject *, PyArrayObject **, int)) \
|
| 1436 |
+
PyArray_API[293])
|
| 1437 |
+
#define PyArray_MapIterArray \
|
| 1438 |
+
(*(PyObject * (*)(PyArrayObject *, PyObject *)) \
|
| 1439 |
+
PyArray_API[294])
|
| 1440 |
+
#define PyArray_MapIterNext \
|
| 1441 |
+
(*(void (*)(PyArrayMapIterObject *)) \
|
| 1442 |
+
PyArray_API[295])
|
| 1443 |
+
#define PyArray_Partition \
|
| 1444 |
+
(*(int (*)(PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND)) \
|
| 1445 |
+
PyArray_API[296])
|
| 1446 |
+
#define PyArray_ArgPartition \
|
| 1447 |
+
(*(PyObject * (*)(PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND)) \
|
| 1448 |
+
PyArray_API[297])
|
| 1449 |
+
#define PyArray_SelectkindConverter \
|
| 1450 |
+
(*(int (*)(PyObject *, NPY_SELECTKIND *)) \
|
| 1451 |
+
PyArray_API[298])
|
| 1452 |
+
#define PyDataMem_NEW_ZEROED \
|
| 1453 |
+
(*(void * (*)(size_t, size_t)) \
|
| 1454 |
+
PyArray_API[299])
|
| 1455 |
+
#define PyArray_CheckAnyScalarExact \
|
| 1456 |
+
(*(int (*)(PyObject *)) \
|
| 1457 |
+
PyArray_API[300])
|
| 1458 |
+
#define PyArray_MapIterArrayCopyIfOverlap \
|
| 1459 |
+
(*(PyObject * (*)(PyArrayObject *, PyObject *, int, PyArrayObject *)) \
|
| 1460 |
+
PyArray_API[301])
|
| 1461 |
+
#define PyArray_ResolveWritebackIfCopy \
|
| 1462 |
+
(*(int (*)(PyArrayObject *)) \
|
| 1463 |
+
PyArray_API[302])
|
| 1464 |
+
#define PyArray_SetWritebackIfCopyBase \
|
| 1465 |
+
(*(int (*)(PyArrayObject *, PyArrayObject *)) \
|
| 1466 |
+
PyArray_API[303])
|
| 1467 |
+
|
| 1468 |
+
#if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
|
| 1469 |
+
#define PyDataMem_SetHandler \
|
| 1470 |
+
(*(PyObject * (*)(PyObject *)) \
|
| 1471 |
+
PyArray_API[304])
|
| 1472 |
+
#endif
|
| 1473 |
+
|
| 1474 |
+
#if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
|
| 1475 |
+
#define PyDataMem_GetHandler \
|
| 1476 |
+
(*(PyObject * (*)(void)) \
|
| 1477 |
+
PyArray_API[305])
|
| 1478 |
+
#endif
|
| 1479 |
+
#define PyDataMem_DefaultHandler (*(PyObject* *)PyArray_API[306])
|
| 1480 |
+
|
| 1481 |
+
#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)
|
| 1482 |
+
static int
|
| 1483 |
+
_import_array(void)
|
| 1484 |
+
{
|
| 1485 |
+
int st;
|
| 1486 |
+
PyObject *numpy = PyImport_ImportModule("numpy.core._multiarray_umath");
|
| 1487 |
+
PyObject *c_api = NULL;
|
| 1488 |
+
|
| 1489 |
+
if (numpy == NULL) {
|
| 1490 |
+
return -1;
|
| 1491 |
+
}
|
| 1492 |
+
c_api = PyObject_GetAttrString(numpy, "_ARRAY_API");
|
| 1493 |
+
Py_DECREF(numpy);
|
| 1494 |
+
if (c_api == NULL) {
|
| 1495 |
+
return -1;
|
| 1496 |
+
}
|
| 1497 |
+
|
| 1498 |
+
if (!PyCapsule_CheckExact(c_api)) {
|
| 1499 |
+
PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is not PyCapsule object");
|
| 1500 |
+
Py_DECREF(c_api);
|
| 1501 |
+
return -1;
|
| 1502 |
+
}
|
| 1503 |
+
PyArray_API = (void **)PyCapsule_GetPointer(c_api, NULL);
|
| 1504 |
+
Py_DECREF(c_api);
|
| 1505 |
+
if (PyArray_API == NULL) {
|
| 1506 |
+
PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is NULL pointer");
|
| 1507 |
+
return -1;
|
| 1508 |
+
}
|
| 1509 |
+
|
| 1510 |
+
/* Perform runtime check of C API version */
|
| 1511 |
+
if (NPY_VERSION != PyArray_GetNDArrayCVersion()) {
|
| 1512 |
+
PyErr_Format(PyExc_RuntimeError, "module compiled against "\
|
| 1513 |
+
"ABI version 0x%x but this version of numpy is 0x%x", \
|
| 1514 |
+
(int) NPY_VERSION, (int) PyArray_GetNDArrayCVersion());
|
| 1515 |
+
return -1;
|
| 1516 |
+
}
|
| 1517 |
+
if (NPY_FEATURE_VERSION > PyArray_GetNDArrayCFeatureVersion()) {
|
| 1518 |
+
PyErr_Format(PyExc_RuntimeError, "module compiled against "\
|
| 1519 |
+
"API version 0x%x but this version of numpy is 0x%x . "\
|
| 1520 |
+
"Check the section C-API incompatibility at the "\
|
| 1521 |
+
"Troubleshooting ImportError section at "\
|
| 1522 |
+
"https://numpy.org/devdocs/user/troubleshooting-importerror.html"\
|
| 1523 |
+
"#c-api-incompatibility "\
|
| 1524 |
+
"for indications on how to solve this problem .", \
|
| 1525 |
+
(int) NPY_FEATURE_VERSION, (int) PyArray_GetNDArrayCFeatureVersion());
|
| 1526 |
+
return -1;
|
| 1527 |
+
}
|
| 1528 |
+
|
| 1529 |
+
/*
|
| 1530 |
+
* Perform runtime check of endianness and check it matches the one set by
|
| 1531 |
+
* the headers (npy_endian.h) as a safeguard
|
| 1532 |
+
*/
|
| 1533 |
+
st = PyArray_GetEndianness();
|
| 1534 |
+
if (st == NPY_CPU_UNKNOWN_ENDIAN) {
|
| 1535 |
+
PyErr_SetString(PyExc_RuntimeError,
|
| 1536 |
+
"FATAL: module compiled as unknown endian");
|
| 1537 |
+
return -1;
|
| 1538 |
+
}
|
| 1539 |
+
#if NPY_BYTE_ORDER == NPY_BIG_ENDIAN
|
| 1540 |
+
if (st != NPY_CPU_BIG) {
|
| 1541 |
+
PyErr_SetString(PyExc_RuntimeError,
|
| 1542 |
+
"FATAL: module compiled as big endian, but "
|
| 1543 |
+
"detected different endianness at runtime");
|
| 1544 |
+
return -1;
|
| 1545 |
+
}
|
| 1546 |
+
#elif NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN
|
| 1547 |
+
if (st != NPY_CPU_LITTLE) {
|
| 1548 |
+
PyErr_SetString(PyExc_RuntimeError,
|
| 1549 |
+
"FATAL: module compiled as little endian, but "
|
| 1550 |
+
"detected different endianness at runtime");
|
| 1551 |
+
return -1;
|
| 1552 |
+
}
|
| 1553 |
+
#endif
|
| 1554 |
+
|
| 1555 |
+
return 0;
|
| 1556 |
+
}
|
| 1557 |
+
|
| 1558 |
+
#define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NULL; } }
|
| 1559 |
+
|
| 1560 |
+
#define import_array1(ret) {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return ret; } }
|
| 1561 |
+
|
| 1562 |
+
#define import_array2(msg, ret) {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, msg); return ret; } }
|
| 1563 |
+
|
| 1564 |
+
#endif
|
| 1565 |
+
|
| 1566 |
+
#endif
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/__ufunc_api.c
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/* These pointers will be stored in the C-object for use in other
|
| 3 |
+
extension modules
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
void *PyUFunc_API[] = {
|
| 7 |
+
(void *) &PyUFunc_Type,
|
| 8 |
+
(void *) PyUFunc_FromFuncAndData,
|
| 9 |
+
(void *) PyUFunc_RegisterLoopForType,
|
| 10 |
+
(void *) PyUFunc_GenericFunction,
|
| 11 |
+
(void *) PyUFunc_f_f_As_d_d,
|
| 12 |
+
(void *) PyUFunc_d_d,
|
| 13 |
+
(void *) PyUFunc_f_f,
|
| 14 |
+
(void *) PyUFunc_g_g,
|
| 15 |
+
(void *) PyUFunc_F_F_As_D_D,
|
| 16 |
+
(void *) PyUFunc_F_F,
|
| 17 |
+
(void *) PyUFunc_D_D,
|
| 18 |
+
(void *) PyUFunc_G_G,
|
| 19 |
+
(void *) PyUFunc_O_O,
|
| 20 |
+
(void *) PyUFunc_ff_f_As_dd_d,
|
| 21 |
+
(void *) PyUFunc_ff_f,
|
| 22 |
+
(void *) PyUFunc_dd_d,
|
| 23 |
+
(void *) PyUFunc_gg_g,
|
| 24 |
+
(void *) PyUFunc_FF_F_As_DD_D,
|
| 25 |
+
(void *) PyUFunc_DD_D,
|
| 26 |
+
(void *) PyUFunc_FF_F,
|
| 27 |
+
(void *) PyUFunc_GG_G,
|
| 28 |
+
(void *) PyUFunc_OO_O,
|
| 29 |
+
(void *) PyUFunc_O_O_method,
|
| 30 |
+
(void *) PyUFunc_OO_O_method,
|
| 31 |
+
(void *) PyUFunc_On_Om,
|
| 32 |
+
(void *) PyUFunc_GetPyValues,
|
| 33 |
+
(void *) PyUFunc_checkfperr,
|
| 34 |
+
(void *) PyUFunc_clearfperr,
|
| 35 |
+
(void *) PyUFunc_getfperr,
|
| 36 |
+
(void *) PyUFunc_handlefperr,
|
| 37 |
+
(void *) PyUFunc_ReplaceLoopBySignature,
|
| 38 |
+
(void *) PyUFunc_FromFuncAndDataAndSignature,
|
| 39 |
+
(void *) PyUFunc_SetUsesArraysAsData,
|
| 40 |
+
(void *) PyUFunc_e_e,
|
| 41 |
+
(void *) PyUFunc_e_e_As_f_f,
|
| 42 |
+
(void *) PyUFunc_e_e_As_d_d,
|
| 43 |
+
(void *) PyUFunc_ee_e,
|
| 44 |
+
(void *) PyUFunc_ee_e_As_ff_f,
|
| 45 |
+
(void *) PyUFunc_ee_e_As_dd_d,
|
| 46 |
+
(void *) PyUFunc_DefaultTypeResolver,
|
| 47 |
+
(void *) PyUFunc_ValidateCasting,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1 |
+
|
| 2 |
+
#ifdef _UMATHMODULE
|
| 3 |
+
|
| 4 |
+
extern NPY_NO_EXPORT PyTypeObject PyUFunc_Type;
|
| 5 |
+
|
| 6 |
+
extern NPY_NO_EXPORT PyTypeObject PyUFunc_Type;
|
| 7 |
+
|
| 8 |
+
NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndData \
|
| 9 |
+
(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int);
|
| 10 |
+
NPY_NO_EXPORT int PyUFunc_RegisterLoopForType \
|
| 11 |
+
(PyUFuncObject *, int, PyUFuncGenericFunction, const int *, void *);
|
| 12 |
+
NPY_NO_EXPORT int PyUFunc_GenericFunction \
|
| 13 |
+
(PyUFuncObject *NPY_UNUSED(ufunc), PyObject *NPY_UNUSED(args), PyObject *NPY_UNUSED(kwds), PyArrayObject **NPY_UNUSED(op));
|
| 14 |
+
NPY_NO_EXPORT void PyUFunc_f_f_As_d_d \
|
| 15 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 16 |
+
NPY_NO_EXPORT void PyUFunc_d_d \
|
| 17 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 18 |
+
NPY_NO_EXPORT void PyUFunc_f_f \
|
| 19 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 20 |
+
NPY_NO_EXPORT void PyUFunc_g_g \
|
| 21 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 22 |
+
NPY_NO_EXPORT void PyUFunc_F_F_As_D_D \
|
| 23 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 24 |
+
NPY_NO_EXPORT void PyUFunc_F_F \
|
| 25 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 26 |
+
NPY_NO_EXPORT void PyUFunc_D_D \
|
| 27 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 28 |
+
NPY_NO_EXPORT void PyUFunc_G_G \
|
| 29 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 30 |
+
NPY_NO_EXPORT void PyUFunc_O_O \
|
| 31 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 32 |
+
NPY_NO_EXPORT void PyUFunc_ff_f_As_dd_d \
|
| 33 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 34 |
+
NPY_NO_EXPORT void PyUFunc_ff_f \
|
| 35 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 36 |
+
NPY_NO_EXPORT void PyUFunc_dd_d \
|
| 37 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 38 |
+
NPY_NO_EXPORT void PyUFunc_gg_g \
|
| 39 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 40 |
+
NPY_NO_EXPORT void PyUFunc_FF_F_As_DD_D \
|
| 41 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 42 |
+
NPY_NO_EXPORT void PyUFunc_DD_D \
|
| 43 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 44 |
+
NPY_NO_EXPORT void PyUFunc_FF_F \
|
| 45 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 46 |
+
NPY_NO_EXPORT void PyUFunc_GG_G \
|
| 47 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 48 |
+
NPY_NO_EXPORT void PyUFunc_OO_O \
|
| 49 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 50 |
+
NPY_NO_EXPORT void PyUFunc_O_O_method \
|
| 51 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 52 |
+
NPY_NO_EXPORT void PyUFunc_OO_O_method \
|
| 53 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 54 |
+
NPY_NO_EXPORT void PyUFunc_On_Om \
|
| 55 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 56 |
+
NPY_NO_EXPORT int PyUFunc_GetPyValues \
|
| 57 |
+
(char *, int *, int *, PyObject **);
|
| 58 |
+
NPY_NO_EXPORT int PyUFunc_checkfperr \
|
| 59 |
+
(int, PyObject *, int *);
|
| 60 |
+
NPY_NO_EXPORT void PyUFunc_clearfperr \
|
| 61 |
+
(void);
|
| 62 |
+
NPY_NO_EXPORT int PyUFunc_getfperr \
|
| 63 |
+
(void);
|
| 64 |
+
NPY_NO_EXPORT int PyUFunc_handlefperr \
|
| 65 |
+
(int, PyObject *, int, int *);
|
| 66 |
+
NPY_NO_EXPORT int PyUFunc_ReplaceLoopBySignature \
|
| 67 |
+
(PyUFuncObject *, PyUFuncGenericFunction, const int *, PyUFuncGenericFunction *);
|
| 68 |
+
NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndDataAndSignature \
|
| 69 |
+
(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int, const char *);
|
| 70 |
+
NPY_NO_EXPORT int PyUFunc_SetUsesArraysAsData \
|
| 71 |
+
(void **NPY_UNUSED(data), size_t NPY_UNUSED(i));
|
| 72 |
+
NPY_NO_EXPORT void PyUFunc_e_e \
|
| 73 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 74 |
+
NPY_NO_EXPORT void PyUFunc_e_e_As_f_f \
|
| 75 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 76 |
+
NPY_NO_EXPORT void PyUFunc_e_e_As_d_d \
|
| 77 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 78 |
+
NPY_NO_EXPORT void PyUFunc_ee_e \
|
| 79 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 80 |
+
NPY_NO_EXPORT void PyUFunc_ee_e_As_ff_f \
|
| 81 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 82 |
+
NPY_NO_EXPORT void PyUFunc_ee_e_As_dd_d \
|
| 83 |
+
(char **, npy_intp const *, npy_intp const *, void *);
|
| 84 |
+
NPY_NO_EXPORT int PyUFunc_DefaultTypeResolver \
|
| 85 |
+
(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyObject *, PyArray_Descr **);
|
| 86 |
+
NPY_NO_EXPORT int PyUFunc_ValidateCasting \
|
| 87 |
+
(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyArray_Descr **);
|
| 88 |
+
NPY_NO_EXPORT int PyUFunc_RegisterLoopForDescr \
|
| 89 |
+
(PyUFuncObject *, PyArray_Descr *, PyUFuncGenericFunction, PyArray_Descr **, void *);
|
| 90 |
+
NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndDataAndSignatureAndIdentity \
|
| 91 |
+
(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, const int, const char *, PyObject *);
|
| 92 |
+
|
| 93 |
+
#else
|
| 94 |
+
|
| 95 |
+
#if defined(PY_UFUNC_UNIQUE_SYMBOL)
|
| 96 |
+
#define PyUFunc_API PY_UFUNC_UNIQUE_SYMBOL
|
| 97 |
+
#endif
|
| 98 |
+
|
| 99 |
+
#if defined(NO_IMPORT) || defined(NO_IMPORT_UFUNC)
|
| 100 |
+
extern void **PyUFunc_API;
|
| 101 |
+
#else
|
| 102 |
+
#if defined(PY_UFUNC_UNIQUE_SYMBOL)
|
| 103 |
+
void **PyUFunc_API;
|
| 104 |
+
#else
|
| 105 |
+
static void **PyUFunc_API=NULL;
|
| 106 |
+
#endif
|
| 107 |
+
#endif
|
| 108 |
+
|
| 109 |
+
#define PyUFunc_Type (*(PyTypeObject *)PyUFunc_API[0])
|
| 110 |
+
#define PyUFunc_FromFuncAndData \
|
| 111 |
+
(*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int)) \
|
| 112 |
+
PyUFunc_API[1])
|
| 113 |
+
#define PyUFunc_RegisterLoopForType \
|
| 114 |
+
(*(int (*)(PyUFuncObject *, int, PyUFuncGenericFunction, const int *, void *)) \
|
| 115 |
+
PyUFunc_API[2])
|
| 116 |
+
#define PyUFunc_GenericFunction \
|
| 117 |
+
(*(int (*)(PyUFuncObject *NPY_UNUSED(ufunc), PyObject *NPY_UNUSED(args), PyObject *NPY_UNUSED(kwds), PyArrayObject **NPY_UNUSED(op))) \
|
| 118 |
+
PyUFunc_API[3])
|
| 119 |
+
#define PyUFunc_f_f_As_d_d \
|
| 120 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 121 |
+
PyUFunc_API[4])
|
| 122 |
+
#define PyUFunc_d_d \
|
| 123 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 124 |
+
PyUFunc_API[5])
|
| 125 |
+
#define PyUFunc_f_f \
|
| 126 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 127 |
+
PyUFunc_API[6])
|
| 128 |
+
#define PyUFunc_g_g \
|
| 129 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 130 |
+
PyUFunc_API[7])
|
| 131 |
+
#define PyUFunc_F_F_As_D_D \
|
| 132 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 133 |
+
PyUFunc_API[8])
|
| 134 |
+
#define PyUFunc_F_F \
|
| 135 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 136 |
+
PyUFunc_API[9])
|
| 137 |
+
#define PyUFunc_D_D \
|
| 138 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 139 |
+
PyUFunc_API[10])
|
| 140 |
+
#define PyUFunc_G_G \
|
| 141 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 142 |
+
PyUFunc_API[11])
|
| 143 |
+
#define PyUFunc_O_O \
|
| 144 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 145 |
+
PyUFunc_API[12])
|
| 146 |
+
#define PyUFunc_ff_f_As_dd_d \
|
| 147 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 148 |
+
PyUFunc_API[13])
|
| 149 |
+
#define PyUFunc_ff_f \
|
| 150 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 151 |
+
PyUFunc_API[14])
|
| 152 |
+
#define PyUFunc_dd_d \
|
| 153 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 154 |
+
PyUFunc_API[15])
|
| 155 |
+
#define PyUFunc_gg_g \
|
| 156 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 157 |
+
PyUFunc_API[16])
|
| 158 |
+
#define PyUFunc_FF_F_As_DD_D \
|
| 159 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 160 |
+
PyUFunc_API[17])
|
| 161 |
+
#define PyUFunc_DD_D \
|
| 162 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 163 |
+
PyUFunc_API[18])
|
| 164 |
+
#define PyUFunc_FF_F \
|
| 165 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 166 |
+
PyUFunc_API[19])
|
| 167 |
+
#define PyUFunc_GG_G \
|
| 168 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 169 |
+
PyUFunc_API[20])
|
| 170 |
+
#define PyUFunc_OO_O \
|
| 171 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 172 |
+
PyUFunc_API[21])
|
| 173 |
+
#define PyUFunc_O_O_method \
|
| 174 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 175 |
+
PyUFunc_API[22])
|
| 176 |
+
#define PyUFunc_OO_O_method \
|
| 177 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 178 |
+
PyUFunc_API[23])
|
| 179 |
+
#define PyUFunc_On_Om \
|
| 180 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 181 |
+
PyUFunc_API[24])
|
| 182 |
+
#define PyUFunc_GetPyValues \
|
| 183 |
+
(*(int (*)(char *, int *, int *, PyObject **)) \
|
| 184 |
+
PyUFunc_API[25])
|
| 185 |
+
#define PyUFunc_checkfperr \
|
| 186 |
+
(*(int (*)(int, PyObject *, int *)) \
|
| 187 |
+
PyUFunc_API[26])
|
| 188 |
+
#define PyUFunc_clearfperr \
|
| 189 |
+
(*(void (*)(void)) \
|
| 190 |
+
PyUFunc_API[27])
|
| 191 |
+
#define PyUFunc_getfperr \
|
| 192 |
+
(*(int (*)(void)) \
|
| 193 |
+
PyUFunc_API[28])
|
| 194 |
+
#define PyUFunc_handlefperr \
|
| 195 |
+
(*(int (*)(int, PyObject *, int, int *)) \
|
| 196 |
+
PyUFunc_API[29])
|
| 197 |
+
#define PyUFunc_ReplaceLoopBySignature \
|
| 198 |
+
(*(int (*)(PyUFuncObject *, PyUFuncGenericFunction, const int *, PyUFuncGenericFunction *)) \
|
| 199 |
+
PyUFunc_API[30])
|
| 200 |
+
#define PyUFunc_FromFuncAndDataAndSignature \
|
| 201 |
+
(*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int, const char *)) \
|
| 202 |
+
PyUFunc_API[31])
|
| 203 |
+
#define PyUFunc_SetUsesArraysAsData \
|
| 204 |
+
(*(int (*)(void **NPY_UNUSED(data), size_t NPY_UNUSED(i))) \
|
| 205 |
+
PyUFunc_API[32])
|
| 206 |
+
#define PyUFunc_e_e \
|
| 207 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 208 |
+
PyUFunc_API[33])
|
| 209 |
+
#define PyUFunc_e_e_As_f_f \
|
| 210 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 211 |
+
PyUFunc_API[34])
|
| 212 |
+
#define PyUFunc_e_e_As_d_d \
|
| 213 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 214 |
+
PyUFunc_API[35])
|
| 215 |
+
#define PyUFunc_ee_e \
|
| 216 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 217 |
+
PyUFunc_API[36])
|
| 218 |
+
#define PyUFunc_ee_e_As_ff_f \
|
| 219 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 220 |
+
PyUFunc_API[37])
|
| 221 |
+
#define PyUFunc_ee_e_As_dd_d \
|
| 222 |
+
(*(void (*)(char **, npy_intp const *, npy_intp const *, void *)) \
|
| 223 |
+
PyUFunc_API[38])
|
| 224 |
+
#define PyUFunc_DefaultTypeResolver \
|
| 225 |
+
(*(int (*)(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyObject *, PyArray_Descr **)) \
|
| 226 |
+
PyUFunc_API[39])
|
| 227 |
+
#define PyUFunc_ValidateCasting \
|
| 228 |
+
(*(int (*)(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyArray_Descr **)) \
|
| 229 |
+
PyUFunc_API[40])
|
| 230 |
+
#define PyUFunc_RegisterLoopForDescr \
|
| 231 |
+
(*(int (*)(PyUFuncObject *, PyArray_Descr *, PyUFuncGenericFunction, PyArray_Descr **, void *)) \
|
| 232 |
+
PyUFunc_API[41])
|
| 233 |
+
|
| 234 |
+
#if NPY_FEATURE_VERSION >= NPY_1_16_API_VERSION
|
| 235 |
+
#define PyUFunc_FromFuncAndDataAndSignatureAndIdentity \
|
| 236 |
+
(*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, const int, const char *, PyObject *)) \
|
| 237 |
+
PyUFunc_API[42])
|
| 238 |
+
#endif
|
| 239 |
+
|
| 240 |
+
static inline int
|
| 241 |
+
_import_umath(void)
|
| 242 |
+
{
|
| 243 |
+
PyObject *numpy = PyImport_ImportModule("numpy.core._multiarray_umath");
|
| 244 |
+
PyObject *c_api = NULL;
|
| 245 |
+
|
| 246 |
+
if (numpy == NULL) {
|
| 247 |
+
PyErr_SetString(PyExc_ImportError,
|
| 248 |
+
"numpy.core._multiarray_umath failed to import");
|
| 249 |
+
return -1;
|
| 250 |
+
}
|
| 251 |
+
c_api = PyObject_GetAttrString(numpy, "_UFUNC_API");
|
| 252 |
+
Py_DECREF(numpy);
|
| 253 |
+
if (c_api == NULL) {
|
| 254 |
+
PyErr_SetString(PyExc_AttributeError, "_UFUNC_API not found");
|
| 255 |
+
return -1;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
if (!PyCapsule_CheckExact(c_api)) {
|
| 259 |
+
PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is not PyCapsule object");
|
| 260 |
+
Py_DECREF(c_api);
|
| 261 |
+
return -1;
|
| 262 |
+
}
|
| 263 |
+
PyUFunc_API = (void **)PyCapsule_GetPointer(c_api, NULL);
|
| 264 |
+
Py_DECREF(c_api);
|
| 265 |
+
if (PyUFunc_API == NULL) {
|
| 266 |
+
PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is NULL pointer");
|
| 267 |
+
return -1;
|
| 268 |
+
}
|
| 269 |
+
return 0;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
#define import_umath() \
|
| 273 |
+
do {\
|
| 274 |
+
UFUNC_NOFPE\
|
| 275 |
+
if (_import_umath() < 0) {\
|
| 276 |
+
PyErr_Print();\
|
| 277 |
+
PyErr_SetString(PyExc_ImportError,\
|
| 278 |
+
"numpy.core.umath failed to import");\
|
| 279 |
+
return NULL;\
|
| 280 |
+
}\
|
| 281 |
+
} while(0)
|
| 282 |
+
|
| 283 |
+
#define import_umath1(ret) \
|
| 284 |
+
do {\
|
| 285 |
+
UFUNC_NOFPE\
|
| 286 |
+
if (_import_umath() < 0) {\
|
| 287 |
+
PyErr_Print();\
|
| 288 |
+
PyErr_SetString(PyExc_ImportError,\
|
| 289 |
+
"numpy.core.umath failed to import");\
|
| 290 |
+
return ret;\
|
| 291 |
+
}\
|
| 292 |
+
} while(0)
|
| 293 |
+
|
| 294 |
+
#define import_umath2(ret, msg) \
|
| 295 |
+
do {\
|
| 296 |
+
UFUNC_NOFPE\
|
| 297 |
+
if (_import_umath() < 0) {\
|
| 298 |
+
PyErr_Print();\
|
| 299 |
+
PyErr_SetString(PyExc_ImportError, msg);\
|
| 300 |
+
return ret;\
|
| 301 |
+
}\
|
| 302 |
+
} while(0)
|
| 303 |
+
|
| 304 |
+
#define import_ufunc() \
|
| 305 |
+
do {\
|
| 306 |
+
UFUNC_NOFPE\
|
| 307 |
+
if (_import_umath() < 0) {\
|
| 308 |
+
PyErr_Print();\
|
| 309 |
+
PyErr_SetString(PyExc_ImportError,\
|
| 310 |
+
"numpy.core.umath failed to import");\
|
| 311 |
+
}\
|
| 312 |
+
} while(0)
|
| 313 |
+
|
| 314 |
+
#endif
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/_dtype_api.h
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* DType related API shared by the (experimental) public API And internal API.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
#ifndef NUMPY_CORE_INCLUDE_NUMPY___DTYPE_API_H_
|
| 6 |
+
#define NUMPY_CORE_INCLUDE_NUMPY___DTYPE_API_H_
|
| 7 |
+
|
| 8 |
+
#define __EXPERIMENTAL_DTYPE_API_VERSION 11
|
| 9 |
+
|
| 10 |
+
struct PyArrayMethodObject_tag;
|
| 11 |
+
|
| 12 |
+
/*
|
| 13 |
+
* Largely opaque struct for DType classes (i.e. metaclass instances).
|
| 14 |
+
* The internal definition is currently in `ndarraytypes.h` (export is a bit
|
| 15 |
+
* more complex because `PyArray_Descr` is a DTypeMeta internally but not
|
| 16 |
+
* externally).
|
| 17 |
+
*/
|
| 18 |
+
#if !(defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD)
|
| 19 |
+
|
| 20 |
+
typedef struct PyArray_DTypeMeta_tag {
|
| 21 |
+
PyHeapTypeObject super;
|
| 22 |
+
|
| 23 |
+
/*
|
| 24 |
+
* Most DTypes will have a singleton default instance, for the
|
| 25 |
+
* parametric legacy DTypes (bytes, string, void, datetime) this
|
| 26 |
+
* may be a pointer to the *prototype* instance?
|
| 27 |
+
*/
|
| 28 |
+
PyArray_Descr *singleton;
|
| 29 |
+
/* Copy of the legacy DTypes type number, usually invalid. */
|
| 30 |
+
int type_num;
|
| 31 |
+
|
| 32 |
+
/* The type object of the scalar instances (may be NULL?) */
|
| 33 |
+
PyTypeObject *scalar_type;
|
| 34 |
+
/*
|
| 35 |
+
* DType flags to signal legacy, parametric, or
|
| 36 |
+
* abstract. But plenty of space for additional information/flags.
|
| 37 |
+
*/
|
| 38 |
+
npy_uint64 flags;
|
| 39 |
+
|
| 40 |
+
/*
|
| 41 |
+
* Use indirection in order to allow a fixed size for this struct.
|
| 42 |
+
* A stable ABI size makes creating a static DType less painful
|
| 43 |
+
* while also ensuring flexibility for all opaque API (with one
|
| 44 |
+
* indirection due the pointer lookup).
|
| 45 |
+
*/
|
| 46 |
+
void *dt_slots;
|
| 47 |
+
/* Allow growing (at the moment also beyond this) */
|
| 48 |
+
void *reserved[3];
|
| 49 |
+
} PyArray_DTypeMeta;
|
| 50 |
+
|
| 51 |
+
#endif /* not internal build */
|
| 52 |
+
|
| 53 |
+
/*
|
| 54 |
+
* ******************************************************
|
| 55 |
+
* ArrayMethod API (Casting and UFuncs)
|
| 56 |
+
* ******************************************************
|
| 57 |
+
*/
|
| 58 |
+
/*
|
| 59 |
+
* NOTE: Expected changes:
|
| 60 |
+
* * probably split runtime and general flags into two
|
| 61 |
+
* * should possibly not use an enum for typedef for more stable ABI?
|
| 62 |
+
*/
|
| 63 |
+
typedef enum {
|
| 64 |
+
/* Flag for whether the GIL is required */
|
| 65 |
+
NPY_METH_REQUIRES_PYAPI = 1 << 0,
|
| 66 |
+
/*
|
| 67 |
+
* Some functions cannot set floating point error flags, this flag
|
| 68 |
+
* gives us the option (not requirement) to skip floating point error
|
| 69 |
+
* setup/check. No function should set error flags and ignore them
|
| 70 |
+
* since it would interfere with chaining operations (e.g. casting).
|
| 71 |
+
*/
|
| 72 |
+
NPY_METH_NO_FLOATINGPOINT_ERRORS = 1 << 1,
|
| 73 |
+
/* Whether the method supports unaligned access (not runtime) */
|
| 74 |
+
NPY_METH_SUPPORTS_UNALIGNED = 1 << 2,
|
| 75 |
+
/*
|
| 76 |
+
* Used for reductions to allow reordering the operation. At this point
|
| 77 |
+
* assume that if set, it also applies to normal operations though!
|
| 78 |
+
*/
|
| 79 |
+
NPY_METH_IS_REORDERABLE = 1 << 3,
|
| 80 |
+
/*
|
| 81 |
+
* Private flag for now for *logic* functions. The logical functions
|
| 82 |
+
* `logical_or` and `logical_and` can always cast the inputs to booleans
|
| 83 |
+
* "safely" (because that is how the cast to bool is defined).
|
| 84 |
+
* @seberg: I am not sure this is the best way to handle this, so its
|
| 85 |
+
* private for now (also it is very limited anyway).
|
| 86 |
+
* There is one "exception". NA aware dtypes cannot cast to bool
|
| 87 |
+
* (hopefully), so the `??->?` loop should error even with this flag.
|
| 88 |
+
* But a second NA fallback loop will be necessary.
|
| 89 |
+
*/
|
| 90 |
+
_NPY_METH_FORCE_CAST_INPUTS = 1 << 17,
|
| 91 |
+
|
| 92 |
+
/* All flags which can change at runtime */
|
| 93 |
+
NPY_METH_RUNTIME_FLAGS = (
|
| 94 |
+
NPY_METH_REQUIRES_PYAPI |
|
| 95 |
+
NPY_METH_NO_FLOATINGPOINT_ERRORS),
|
| 96 |
+
} NPY_ARRAYMETHOD_FLAGS;
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
typedef struct PyArrayMethod_Context_tag {
|
| 100 |
+
/* The caller, which is typically the original ufunc. May be NULL */
|
| 101 |
+
PyObject *caller;
|
| 102 |
+
/* The method "self". Publically currentl an opaque object. */
|
| 103 |
+
struct PyArrayMethodObject_tag *method;
|
| 104 |
+
|
| 105 |
+
/* Operand descriptors, filled in by resolve_descriptors */
|
| 106 |
+
PyArray_Descr **descriptors;
|
| 107 |
+
/* Structure may grow (this is harmless for DType authors) */
|
| 108 |
+
} PyArrayMethod_Context;
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
/*
|
| 112 |
+
* The main object for creating a new ArrayMethod. We use the typical `slots`
|
| 113 |
+
* mechanism used by the Python limited API (see below for the slot defs).
|
| 114 |
+
*/
|
| 115 |
+
typedef struct {
|
| 116 |
+
const char *name;
|
| 117 |
+
int nin, nout;
|
| 118 |
+
NPY_CASTING casting;
|
| 119 |
+
NPY_ARRAYMETHOD_FLAGS flags;
|
| 120 |
+
PyArray_DTypeMeta **dtypes;
|
| 121 |
+
PyType_Slot *slots;
|
| 122 |
+
} PyArrayMethod_Spec;
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
/*
|
| 126 |
+
* ArrayMethod slots
|
| 127 |
+
* -----------------
|
| 128 |
+
*
|
| 129 |
+
* SLOTS IDs For the ArrayMethod creation, once fully public, IDs are fixed
|
| 130 |
+
* but can be deprecated and arbitrarily extended.
|
| 131 |
+
*/
|
| 132 |
+
#define NPY_METH_resolve_descriptors 1
|
| 133 |
+
/* We may want to adapt the `get_loop` signature a bit: */
|
| 134 |
+
#define _NPY_METH_get_loop 2
|
| 135 |
+
#define NPY_METH_get_reduction_initial 3
|
| 136 |
+
/* specific loops for constructions/default get_loop: */
|
| 137 |
+
#define NPY_METH_strided_loop 4
|
| 138 |
+
#define NPY_METH_contiguous_loop 5
|
| 139 |
+
#define NPY_METH_unaligned_strided_loop 6
|
| 140 |
+
#define NPY_METH_unaligned_contiguous_loop 7
|
| 141 |
+
#define NPY_METH_contiguous_indexed_loop 8
|
| 142 |
+
|
| 143 |
+
/*
|
| 144 |
+
* The resolve descriptors function, must be able to handle NULL values for
|
| 145 |
+
* all output (but not input) `given_descrs` and fill `loop_descrs`.
|
| 146 |
+
* Return -1 on error or 0 if the operation is not possible without an error
|
| 147 |
+
* set. (This may still be in flux.)
|
| 148 |
+
* Otherwise must return the "casting safety", for normal functions, this is
|
| 149 |
+
* almost always "safe" (or even "equivalent"?).
|
| 150 |
+
*
|
| 151 |
+
* `resolve_descriptors` is optional if all output DTypes are non-parametric.
|
| 152 |
+
*/
|
| 153 |
+
typedef NPY_CASTING (resolve_descriptors_function)(
|
| 154 |
+
/* "method" is currently opaque (necessary e.g. to wrap Python) */
|
| 155 |
+
struct PyArrayMethodObject_tag *method,
|
| 156 |
+
/* DTypes the method was created for */
|
| 157 |
+
PyArray_DTypeMeta **dtypes,
|
| 158 |
+
/* Input descriptors (instances). Outputs may be NULL. */
|
| 159 |
+
PyArray_Descr **given_descrs,
|
| 160 |
+
/* Exact loop descriptors to use, must not hold references on error */
|
| 161 |
+
PyArray_Descr **loop_descrs,
|
| 162 |
+
npy_intp *view_offset);
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
typedef int (PyArrayMethod_StridedLoop)(PyArrayMethod_Context *context,
|
| 166 |
+
char *const *data, const npy_intp *dimensions, const npy_intp *strides,
|
| 167 |
+
NpyAuxData *transferdata);
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
typedef int (get_loop_function)(
|
| 171 |
+
PyArrayMethod_Context *context,
|
| 172 |
+
int aligned, int move_references,
|
| 173 |
+
const npy_intp *strides,
|
| 174 |
+
PyArrayMethod_StridedLoop **out_loop,
|
| 175 |
+
NpyAuxData **out_transferdata,
|
| 176 |
+
NPY_ARRAYMETHOD_FLAGS *flags);
|
| 177 |
+
|
| 178 |
+
/**
|
| 179 |
+
* Query an ArrayMethod for the initial value for use in reduction.
|
| 180 |
+
*
|
| 181 |
+
* @param context The arraymethod context, mainly to access the descriptors.
|
| 182 |
+
* @param reduction_is_empty Whether the reduction is empty. When it is, the
|
| 183 |
+
* value returned may differ. In this case it is a "default" value that
|
| 184 |
+
* may differ from the "identity" value normally used. For example:
|
| 185 |
+
* - `0.0` is the default for `sum([])`. But `-0.0` is the correct
|
| 186 |
+
* identity otherwise as it preserves the sign for `sum([-0.0])`.
|
| 187 |
+
* - We use no identity for object, but return the default of `0` and `1`
|
| 188 |
+
* for the empty `sum([], dtype=object)` and `prod([], dtype=object)`.
|
| 189 |
+
* This allows `np.sum(np.array(["a", "b"], dtype=object))` to work.
|
| 190 |
+
* - `-inf` or `INT_MIN` for `max` is an identity, but at least `INT_MIN`
|
| 191 |
+
* not a good *default* when there are no items.
|
| 192 |
+
* @param initial Pointer to initial data to be filled (if possible)
|
| 193 |
+
*
|
| 194 |
+
* @returns -1, 0, or 1 indicating error, no initial value, and initial being
|
| 195 |
+
* successfully filled. Errors must not be given where 0 is correct, NumPy
|
| 196 |
+
* may call this even when not strictly necessary.
|
| 197 |
+
*/
|
| 198 |
+
typedef int (get_reduction_initial_function)(
|
| 199 |
+
PyArrayMethod_Context *context, npy_bool reduction_is_empty,
|
| 200 |
+
char *initial);
|
| 201 |
+
|
| 202 |
+
/*
|
| 203 |
+
* The following functions are only used by the wrapping array method defined
|
| 204 |
+
* in umath/wrapping_array_method.c
|
| 205 |
+
*/
|
| 206 |
+
|
| 207 |
+
/*
|
| 208 |
+
* The function to convert the given descriptors (passed in to
|
| 209 |
+
* `resolve_descriptors`) and translates them for the wrapped loop.
|
| 210 |
+
* The new descriptors MUST be viewable with the old ones, `NULL` must be
|
| 211 |
+
* supported (for outputs) and should normally be forwarded.
|
| 212 |
+
*
|
| 213 |
+
* The function must clean up on error.
|
| 214 |
+
*
|
| 215 |
+
* NOTE: We currently assume that this translation gives "viewable" results.
|
| 216 |
+
* I.e. there is no additional casting related to the wrapping process.
|
| 217 |
+
* In principle that could be supported, but not sure it is useful.
|
| 218 |
+
* This currently also means that e.g. alignment must apply identically
|
| 219 |
+
* to the new dtypes.
|
| 220 |
+
*
|
| 221 |
+
* TODO: Due to the fact that `resolve_descriptors` is also used for `can_cast`
|
| 222 |
+
* there is no way to "pass out" the result of this function. This means
|
| 223 |
+
* it will be called twice for every ufunc call.
|
| 224 |
+
* (I am considering including `auxdata` as an "optional" parameter to
|
| 225 |
+
* `resolve_descriptors`, so that it can be filled there if not NULL.)
|
| 226 |
+
*/
|
| 227 |
+
typedef int translate_given_descrs_func(int nin, int nout,
|
| 228 |
+
PyArray_DTypeMeta *wrapped_dtypes[],
|
| 229 |
+
PyArray_Descr *given_descrs[], PyArray_Descr *new_descrs[]);
|
| 230 |
+
|
| 231 |
+
/**
|
| 232 |
+
* The function to convert the actual loop descriptors (as returned by the
|
| 233 |
+
* original `resolve_descriptors` function) to the ones the output array
|
| 234 |
+
* should use.
|
| 235 |
+
* This function must return "viewable" types, it must not mutate them in any
|
| 236 |
+
* form that would break the inner-loop logic. Does not need to support NULL.
|
| 237 |
+
*
|
| 238 |
+
* The function must clean up on error.
|
| 239 |
+
*
|
| 240 |
+
* @param nargs Number of arguments
|
| 241 |
+
* @param new_dtypes The DTypes of the output (usually probably not needed)
|
| 242 |
+
* @param given_descrs Original given_descrs to the resolver, necessary to
|
| 243 |
+
* fetch any information related to the new dtypes from the original.
|
| 244 |
+
* @param original_descrs The `loop_descrs` returned by the wrapped loop.
|
| 245 |
+
* @param loop_descrs The output descriptors, compatible to `original_descrs`.
|
| 246 |
+
*
|
| 247 |
+
* @returns 0 on success, -1 on failure.
|
| 248 |
+
*/
|
| 249 |
+
typedef int translate_loop_descrs_func(int nin, int nout,
|
| 250 |
+
PyArray_DTypeMeta *new_dtypes[], PyArray_Descr *given_descrs[],
|
| 251 |
+
PyArray_Descr *original_descrs[], PyArray_Descr *loop_descrs[]);
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
/*
|
| 255 |
+
* A traverse loop working on a single array. This is similar to the general
|
| 256 |
+
* strided-loop function. This is designed for loops that need to visit every
|
| 257 |
+
* element of a single array.
|
| 258 |
+
*
|
| 259 |
+
* Currently this is used for array clearing, via the NPY_DT_get_clear_loop
|
| 260 |
+
* API hook, and zero-filling, via the NPY_DT_get_fill_zero_loop API hook.
|
| 261 |
+
* These are most useful for handling arrays storing embedded references to
|
| 262 |
+
* python objects or heap-allocated data.
|
| 263 |
+
*
|
| 264 |
+
* The `void *traverse_context` is passed in because we may need to pass in
|
| 265 |
+
* Intepreter state or similar in the future, but we don't want to pass in
|
| 266 |
+
* a full context (with pointers to dtypes, method, caller which all make
|
| 267 |
+
* no sense for a traverse function).
|
| 268 |
+
*
|
| 269 |
+
* We assume for now that this context can be just passed through in the
|
| 270 |
+
* the future (for structured dtypes).
|
| 271 |
+
*
|
| 272 |
+
*/
|
| 273 |
+
typedef int (traverse_loop_function)(
|
| 274 |
+
void *traverse_context, PyArray_Descr *descr, char *data,
|
| 275 |
+
npy_intp size, npy_intp stride, NpyAuxData *auxdata);
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
/*
|
| 279 |
+
* Simplified get_loop function specific to dtype traversal
|
| 280 |
+
*
|
| 281 |
+
* It should set the flags needed for the traversal loop and set out_loop to the
|
| 282 |
+
* loop function, which must be a valid traverse_loop_function
|
| 283 |
+
* pointer. Currently this is used for zero-filling and clearing arrays storing
|
| 284 |
+
* embedded references.
|
| 285 |
+
*
|
| 286 |
+
*/
|
| 287 |
+
typedef int (get_traverse_loop_function)(
|
| 288 |
+
void *traverse_context, PyArray_Descr *descr,
|
| 289 |
+
int aligned, npy_intp fixed_stride,
|
| 290 |
+
traverse_loop_function **out_loop, NpyAuxData **out_auxdata,
|
| 291 |
+
NPY_ARRAYMETHOD_FLAGS *flags);
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
/*
|
| 295 |
+
* ****************************
|
| 296 |
+
* DTYPE API
|
| 297 |
+
* ****************************
|
| 298 |
+
*/
|
| 299 |
+
|
| 300 |
+
#define NPY_DT_ABSTRACT 1 << 1
|
| 301 |
+
#define NPY_DT_PARAMETRIC 1 << 2
|
| 302 |
+
#define NPY_DT_NUMERIC 1 << 3
|
| 303 |
+
|
| 304 |
+
/*
|
| 305 |
+
* These correspond to slots in the NPY_DType_Slots struct and must
|
| 306 |
+
* be in the same order as the members of that struct. If new slots
|
| 307 |
+
* get added or old slots get removed NPY_NUM_DTYPE_SLOTS must also
|
| 308 |
+
* be updated
|
| 309 |
+
*/
|
| 310 |
+
|
| 311 |
+
#define NPY_DT_discover_descr_from_pyobject 1
|
| 312 |
+
// this slot is considered private because its API hasn't beed decided
|
| 313 |
+
#define _NPY_DT_is_known_scalar_type 2
|
| 314 |
+
#define NPY_DT_default_descr 3
|
| 315 |
+
#define NPY_DT_common_dtype 4
|
| 316 |
+
#define NPY_DT_common_instance 5
|
| 317 |
+
#define NPY_DT_ensure_canonical 6
|
| 318 |
+
#define NPY_DT_setitem 7
|
| 319 |
+
#define NPY_DT_getitem 8
|
| 320 |
+
#define NPY_DT_get_clear_loop 9
|
| 321 |
+
#define NPY_DT_get_fill_zero_loop 10
|
| 322 |
+
|
| 323 |
+
// These PyArray_ArrFunc slots will be deprecated and replaced eventually
|
| 324 |
+
// getitem and setitem can be defined as a performance optimization;
|
| 325 |
+
// by default the user dtypes call `legacy_getitem_using_DType` and
|
| 326 |
+
// `legacy_setitem_using_DType`, respectively. This functionality is
|
| 327 |
+
// only supported for basic NumPy DTypes.
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
// used to separate dtype slots from arrfuncs slots
|
| 331 |
+
// intended only for internal use but defined here for clarity
|
| 332 |
+
#define _NPY_DT_ARRFUNCS_OFFSET (1 << 10)
|
| 333 |
+
|
| 334 |
+
// Cast is disabled
|
| 335 |
+
// #define NPY_DT_PyArray_ArrFuncs_cast 0 + _NPY_DT_ARRFUNCS_OFFSET
|
| 336 |
+
|
| 337 |
+
#define NPY_DT_PyArray_ArrFuncs_getitem 1 + _NPY_DT_ARRFUNCS_OFFSET
|
| 338 |
+
#define NPY_DT_PyArray_ArrFuncs_setitem 2 + _NPY_DT_ARRFUNCS_OFFSET
|
| 339 |
+
|
| 340 |
+
#define NPY_DT_PyArray_ArrFuncs_copyswapn 3 + _NPY_DT_ARRFUNCS_OFFSET
|
| 341 |
+
#define NPY_DT_PyArray_ArrFuncs_copyswap 4 + _NPY_DT_ARRFUNCS_OFFSET
|
| 342 |
+
#define NPY_DT_PyArray_ArrFuncs_compare 5 + _NPY_DT_ARRFUNCS_OFFSET
|
| 343 |
+
#define NPY_DT_PyArray_ArrFuncs_argmax 6 + _NPY_DT_ARRFUNCS_OFFSET
|
| 344 |
+
#define NPY_DT_PyArray_ArrFuncs_dotfunc 7 + _NPY_DT_ARRFUNCS_OFFSET
|
| 345 |
+
#define NPY_DT_PyArray_ArrFuncs_scanfunc 8 + _NPY_DT_ARRFUNCS_OFFSET
|
| 346 |
+
#define NPY_DT_PyArray_ArrFuncs_fromstr 9 + _NPY_DT_ARRFUNCS_OFFSET
|
| 347 |
+
#define NPY_DT_PyArray_ArrFuncs_nonzero 10 + _NPY_DT_ARRFUNCS_OFFSET
|
| 348 |
+
#define NPY_DT_PyArray_ArrFuncs_fill 11 + _NPY_DT_ARRFUNCS_OFFSET
|
| 349 |
+
#define NPY_DT_PyArray_ArrFuncs_fillwithscalar 12 + _NPY_DT_ARRFUNCS_OFFSET
|
| 350 |
+
#define NPY_DT_PyArray_ArrFuncs_sort 13 + _NPY_DT_ARRFUNCS_OFFSET
|
| 351 |
+
#define NPY_DT_PyArray_ArrFuncs_argsort 14 + _NPY_DT_ARRFUNCS_OFFSET
|
| 352 |
+
|
| 353 |
+
// Casting related slots are disabled. See
|
| 354 |
+
// https://github.com/numpy/numpy/pull/23173#discussion_r1101098163
|
| 355 |
+
// #define NPY_DT_PyArray_ArrFuncs_castdict 15 + _NPY_DT_ARRFUNCS_OFFSET
|
| 356 |
+
// #define NPY_DT_PyArray_ArrFuncs_scalarkind 16 + _NPY_DT_ARRFUNCS_OFFSET
|
| 357 |
+
// #define NPY_DT_PyArray_ArrFuncs_cancastscalarkindto 17 + _NPY_DT_ARRFUNCS_OFFSET
|
| 358 |
+
// #define NPY_DT_PyArray_ArrFuncs_cancastto 18 + _NPY_DT_ARRFUNCS_OFFSET
|
| 359 |
+
|
| 360 |
+
// These are deprecated in NumPy 1.19, so are disabled here.
|
| 361 |
+
// #define NPY_DT_PyArray_ArrFuncs_fastclip 19 + _NPY_DT_ARRFUNCS_OFFSET
|
| 362 |
+
// #define NPY_DT_PyArray_ArrFuncs_fastputmask 20 + _NPY_DT_ARRFUNCS_OFFSET
|
| 363 |
+
// #define NPY_DT_PyArray_ArrFuncs_fasttake 21 + _NPY_DT_ARRFUNCS_OFFSET
|
| 364 |
+
#define NPY_DT_PyArray_ArrFuncs_argmin 22 + _NPY_DT_ARRFUNCS_OFFSET
|
| 365 |
+
|
| 366 |
+
// TODO: These slots probably still need some thought, and/or a way to "grow"?
|
| 367 |
+
typedef struct {
|
| 368 |
+
PyTypeObject *typeobj; /* type of python scalar or NULL */
|
| 369 |
+
int flags; /* flags, including parametric and abstract */
|
| 370 |
+
/* NULL terminated cast definitions. Use NULL for the newly created DType */
|
| 371 |
+
PyArrayMethod_Spec **casts;
|
| 372 |
+
PyType_Slot *slots;
|
| 373 |
+
/* Baseclass or NULL (will always subclass `np.dtype`) */
|
| 374 |
+
PyTypeObject *baseclass;
|
| 375 |
+
} PyArrayDTypeMeta_Spec;
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
typedef PyArray_Descr *(discover_descr_from_pyobject_function)(
|
| 379 |
+
PyArray_DTypeMeta *cls, PyObject *obj);
|
| 380 |
+
|
| 381 |
+
/*
|
| 382 |
+
* Before making this public, we should decide whether it should pass
|
| 383 |
+
* the type, or allow looking at the object. A possible use-case:
|
| 384 |
+
* `np.array(np.array([0]), dtype=np.ndarray)`
|
| 385 |
+
* Could consider arrays that are not `dtype=ndarray` "scalars".
|
| 386 |
+
*/
|
| 387 |
+
typedef int (is_known_scalar_type_function)(
|
| 388 |
+
PyArray_DTypeMeta *cls, PyTypeObject *obj);
|
| 389 |
+
|
| 390 |
+
typedef PyArray_Descr *(default_descr_function)(PyArray_DTypeMeta *cls);
|
| 391 |
+
typedef PyArray_DTypeMeta *(common_dtype_function)(
|
| 392 |
+
PyArray_DTypeMeta *dtype1, PyArray_DTypeMeta *dtype2);
|
| 393 |
+
typedef PyArray_Descr *(common_instance_function)(
|
| 394 |
+
PyArray_Descr *dtype1, PyArray_Descr *dtype2);
|
| 395 |
+
typedef PyArray_Descr *(ensure_canonical_function)(PyArray_Descr *dtype);
|
| 396 |
+
|
| 397 |
+
/*
|
| 398 |
+
* TODO: These two functions are currently only used for experimental DType
|
| 399 |
+
* API support. Their relation should be "reversed": NumPy should
|
| 400 |
+
* always use them internally.
|
| 401 |
+
* There are open points about "casting safety" though, e.g. setting
|
| 402 |
+
* elements is currently always unsafe.
|
| 403 |
+
*/
|
| 404 |
+
typedef int(setitemfunction)(PyArray_Descr *, PyObject *, char *);
|
| 405 |
+
typedef PyObject *(getitemfunction)(PyArray_Descr *, char *);
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
#endif /* NUMPY_CORE_INCLUDE_NUMPY___DTYPE_API_H_ */
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/_neighborhood_iterator_imp.h
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef NUMPY_CORE_INCLUDE_NUMPY__NEIGHBORHOOD_IMP_H_
|
| 2 |
+
#error You should not include this header directly
|
| 3 |
+
#endif
|
| 4 |
+
/*
|
| 5 |
+
* Private API (here for inline)
|
| 6 |
+
*/
|
| 7 |
+
static inline int
|
| 8 |
+
_PyArrayNeighborhoodIter_IncrCoord(PyArrayNeighborhoodIterObject* iter);
|
| 9 |
+
|
| 10 |
+
/*
|
| 11 |
+
* Update to next item of the iterator
|
| 12 |
+
*
|
| 13 |
+
* Note: this simply increment the coordinates vector, last dimension
|
| 14 |
+
* incremented first , i.e, for dimension 3
|
| 15 |
+
* ...
|
| 16 |
+
* -1, -1, -1
|
| 17 |
+
* -1, -1, 0
|
| 18 |
+
* -1, -1, 1
|
| 19 |
+
* ....
|
| 20 |
+
* -1, 0, -1
|
| 21 |
+
* -1, 0, 0
|
| 22 |
+
* ....
|
| 23 |
+
* 0, -1, -1
|
| 24 |
+
* 0, -1, 0
|
| 25 |
+
* ....
|
| 26 |
+
*/
|
| 27 |
+
#define _UPDATE_COORD_ITER(c) \
|
| 28 |
+
wb = iter->coordinates[c] < iter->bounds[c][1]; \
|
| 29 |
+
if (wb) { \
|
| 30 |
+
iter->coordinates[c] += 1; \
|
| 31 |
+
return 0; \
|
| 32 |
+
} \
|
| 33 |
+
else { \
|
| 34 |
+
iter->coordinates[c] = iter->bounds[c][0]; \
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
static inline int
|
| 38 |
+
_PyArrayNeighborhoodIter_IncrCoord(PyArrayNeighborhoodIterObject* iter)
|
| 39 |
+
{
|
| 40 |
+
npy_intp i, wb;
|
| 41 |
+
|
| 42 |
+
for (i = iter->nd - 1; i >= 0; --i) {
|
| 43 |
+
_UPDATE_COORD_ITER(i)
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return 0;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/*
|
| 50 |
+
* Version optimized for 2d arrays, manual loop unrolling
|
| 51 |
+
*/
|
| 52 |
+
static inline int
|
| 53 |
+
_PyArrayNeighborhoodIter_IncrCoord2D(PyArrayNeighborhoodIterObject* iter)
|
| 54 |
+
{
|
| 55 |
+
npy_intp wb;
|
| 56 |
+
|
| 57 |
+
_UPDATE_COORD_ITER(1)
|
| 58 |
+
_UPDATE_COORD_ITER(0)
|
| 59 |
+
|
| 60 |
+
return 0;
|
| 61 |
+
}
|
| 62 |
+
#undef _UPDATE_COORD_ITER
|
| 63 |
+
|
| 64 |
+
/*
|
| 65 |
+
* Advance to the next neighbour
|
| 66 |
+
*/
|
| 67 |
+
static inline int
|
| 68 |
+
PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter)
|
| 69 |
+
{
|
| 70 |
+
_PyArrayNeighborhoodIter_IncrCoord (iter);
|
| 71 |
+
iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates);
|
| 72 |
+
|
| 73 |
+
return 0;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
/*
|
| 77 |
+
* Reset functions
|
| 78 |
+
*/
|
| 79 |
+
static inline int
|
| 80 |
+
PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter)
|
| 81 |
+
{
|
| 82 |
+
npy_intp i;
|
| 83 |
+
|
| 84 |
+
for (i = 0; i < iter->nd; ++i) {
|
| 85 |
+
iter->coordinates[i] = iter->bounds[i][0];
|
| 86 |
+
}
|
| 87 |
+
iter->dataptr = iter->translate((PyArrayIterObject*)iter, iter->coordinates);
|
| 88 |
+
|
| 89 |
+
return 0;
|
| 90 |
+
}
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/_numpyconfig.h
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define NPY_HAVE_ENDIAN_H 1
|
| 2 |
+
|
| 3 |
+
#define NPY_SIZEOF_SHORT 2
|
| 4 |
+
#define NPY_SIZEOF_INT 4
|
| 5 |
+
#define NPY_SIZEOF_LONG 8
|
| 6 |
+
#define NPY_SIZEOF_FLOAT 4
|
| 7 |
+
#define NPY_SIZEOF_COMPLEX_FLOAT 8
|
| 8 |
+
#define NPY_SIZEOF_DOUBLE 8
|
| 9 |
+
#define NPY_SIZEOF_COMPLEX_DOUBLE 16
|
| 10 |
+
#define NPY_SIZEOF_LONGDOUBLE 16
|
| 11 |
+
#define NPY_SIZEOF_COMPLEX_LONGDOUBLE 32
|
| 12 |
+
#define NPY_SIZEOF_PY_INTPTR_T 8
|
| 13 |
+
#define NPY_SIZEOF_OFF_T 8
|
| 14 |
+
#define NPY_SIZEOF_PY_LONG_LONG 8
|
| 15 |
+
#define NPY_SIZEOF_LONGLONG 8
|
| 16 |
+
|
| 17 |
+
#define NPY_USE_C99_COMPLEX 1
|
| 18 |
+
#define NPY_HAVE_COMPLEX_DOUBLE 1
|
| 19 |
+
#define NPY_HAVE_COMPLEX_FLOAT 1
|
| 20 |
+
#define NPY_HAVE_COMPLEX_LONG_DOUBLE 1
|
| 21 |
+
#define NPY_USE_C99_FORMATS 1
|
| 22 |
+
|
| 23 |
+
/* #undef NPY_NO_SIGNAL */
|
| 24 |
+
#define NPY_NO_SMP 0
|
| 25 |
+
|
| 26 |
+
#define NPY_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
|
| 27 |
+
#define NPY_ABI_VERSION 0x01000009
|
| 28 |
+
#define NPY_API_VERSION 0x00000011
|
| 29 |
+
|
| 30 |
+
#ifndef __STDC_FORMAT_MACROS
|
| 31 |
+
#define __STDC_FORMAT_MACROS 1
|
| 32 |
+
#endif
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/arrayobject.h
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef NUMPY_CORE_INCLUDE_NUMPY_ARRAYOBJECT_H_
|
| 2 |
+
#define NUMPY_CORE_INCLUDE_NUMPY_ARRAYOBJECT_H_
|
| 3 |
+
#define Py_ARRAYOBJECT_H
|
| 4 |
+
|
| 5 |
+
#include "ndarrayobject.h"
|
| 6 |
+
#include "npy_interrupt.h"
|
| 7 |
+
|
| 8 |
+
#ifdef NPY_NO_PREFIX
|
| 9 |
+
#include "noprefix.h"
|
| 10 |
+
#endif
|
| 11 |
+
|
| 12 |
+
#endif /* NUMPY_CORE_INCLUDE_NUMPY_ARRAYOBJECT_H_ */
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/arrayscalars.h
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
| 7 |
+
npy_bool obval;
|
| 8 |
+
} PyBoolScalarObject;
|
| 9 |
+
#endif
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
typedef struct {
|
| 13 |
+
PyObject_HEAD
|
| 14 |
+
signed char obval;
|
| 15 |
+
} PyByteScalarObject;
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
typedef struct {
|
| 19 |
+
PyObject_HEAD
|
| 20 |
+
short obval;
|
| 21 |
+
} PyShortScalarObject;
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
typedef struct {
|
| 25 |
+
PyObject_HEAD
|
| 26 |
+
int obval;
|
| 27 |
+
} PyIntScalarObject;
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
typedef struct {
|
| 31 |
+
PyObject_HEAD
|
| 32 |
+
long obval;
|
| 33 |
+
} PyLongScalarObject;
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
typedef struct {
|
| 37 |
+
PyObject_HEAD
|
| 38 |
+
npy_longlong obval;
|
| 39 |
+
} PyLongLongScalarObject;
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
typedef struct {
|
| 43 |
+
PyObject_HEAD
|
| 44 |
+
unsigned char obval;
|
| 45 |
+
} PyUByteScalarObject;
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
typedef struct {
|
| 49 |
+
PyObject_HEAD
|
| 50 |
+
unsigned short obval;
|
| 51 |
+
} PyUShortScalarObject;
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
typedef struct {
|
| 55 |
+
PyObject_HEAD
|
| 56 |
+
unsigned int obval;
|
| 57 |
+
} PyUIntScalarObject;
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
typedef struct {
|
| 61 |
+
PyObject_HEAD
|
| 62 |
+
unsigned long obval;
|
| 63 |
+
} PyULongScalarObject;
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
typedef struct {
|
| 67 |
+
PyObject_HEAD
|
| 68 |
+
npy_ulonglong obval;
|
| 69 |
+
} PyULongLongScalarObject;
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
typedef struct {
|
| 73 |
+
PyObject_HEAD
|
| 74 |
+
npy_half obval;
|
| 75 |
+
} PyHalfScalarObject;
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
typedef struct {
|
| 79 |
+
PyObject_HEAD
|
| 80 |
+
float obval;
|
| 81 |
+
} PyFloatScalarObject;
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
typedef struct {
|
| 85 |
+
PyObject_HEAD
|
| 86 |
+
double obval;
|
| 87 |
+
} PyDoubleScalarObject;
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
typedef struct {
|
| 91 |
+
PyObject_HEAD
|
| 92 |
+
npy_longdouble obval;
|
| 93 |
+
} PyLongDoubleScalarObject;
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
typedef struct {
|
| 97 |
+
PyObject_HEAD
|
| 98 |
+
npy_cfloat obval;
|
| 99 |
+
} PyCFloatScalarObject;
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
typedef struct {
|
| 103 |
+
PyObject_HEAD
|
| 104 |
+
npy_cdouble obval;
|
| 105 |
+
} PyCDoubleScalarObject;
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
typedef struct {
|
| 109 |
+
PyObject_HEAD
|
| 110 |
+
npy_clongdouble obval;
|
| 111 |
+
} PyCLongDoubleScalarObject;
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
typedef struct {
|
| 115 |
+
PyObject_HEAD
|
| 116 |
+
PyObject * obval;
|
| 117 |
+
} PyObjectScalarObject;
|
| 118 |
+
|
| 119 |
+
typedef struct {
|
| 120 |
+
PyObject_HEAD
|
| 121 |
+
npy_datetime obval;
|
| 122 |
+
PyArray_DatetimeMetaData obmeta;
|
| 123 |
+
} PyDatetimeScalarObject;
|
| 124 |
+
|
| 125 |
+
typedef struct {
|
| 126 |
+
PyObject_HEAD
|
| 127 |
+
npy_timedelta obval;
|
| 128 |
+
PyArray_DatetimeMetaData obmeta;
|
| 129 |
+
} PyTimedeltaScalarObject;
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
typedef struct {
|
| 133 |
+
PyObject_HEAD
|
| 134 |
+
char obval;
|
| 135 |
+
} PyScalarObject;
|
| 136 |
+
|
| 137 |
+
#define PyStringScalarObject PyBytesObject
|
| 138 |
+
typedef struct {
|
| 139 |
+
/* note that the PyObject_HEAD macro lives right here */
|
| 140 |
+
PyUnicodeObject base;
|
| 141 |
+
Py_UCS4 *obval;
|
| 142 |
+
#if NPY_FEATURE_VERSION >= NPY_1_20_API_VERSION
|
| 143 |
+
char *buffer_fmt;
|
| 144 |
+
#endif
|
| 145 |
+
} PyUnicodeScalarObject;
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
typedef struct {
|
| 149 |
+
PyObject_VAR_HEAD
|
| 150 |
+
char *obval;
|
| 151 |
+
PyArray_Descr *descr;
|
| 152 |
+
int flags;
|
| 153 |
+
PyObject *base;
|
| 154 |
+
#if NPY_FEATURE_VERSION >= NPY_1_20_API_VERSION
|
| 155 |
+
void *_buffer_info; /* private buffer info, tagged to allow warning */
|
| 156 |
+
#endif
|
| 157 |
+
} PyVoidScalarObject;
|
| 158 |
+
|
| 159 |
+
/* Macros
|
| 160 |
+
Py<Cls><bitsize>ScalarObject
|
| 161 |
+
Py<Cls><bitsize>ArrType_Type
|
| 162 |
+
are defined in ndarrayobject.h
|
| 163 |
+
*/
|
| 164 |
+
|
| 165 |
+
#define PyArrayScalar_False ((PyObject *)(&(_PyArrayScalar_BoolValues[0])))
|
| 166 |
+
#define PyArrayScalar_True ((PyObject *)(&(_PyArrayScalar_BoolValues[1])))
|
| 167 |
+
#define PyArrayScalar_FromLong(i) \
|
| 168 |
+
((PyObject *)(&(_PyArrayScalar_BoolValues[((i)!=0)])))
|
| 169 |
+
#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i) \
|
| 170 |
+
return Py_INCREF(PyArrayScalar_FromLong(i)), \
|
| 171 |
+
PyArrayScalar_FromLong(i)
|
| 172 |
+
#define PyArrayScalar_RETURN_FALSE \
|
| 173 |
+
return Py_INCREF(PyArrayScalar_False), \
|
| 174 |
+
PyArrayScalar_False
|
| 175 |
+
#define PyArrayScalar_RETURN_TRUE \
|
| 176 |
+
return Py_INCREF(PyArrayScalar_True), \
|
| 177 |
+
PyArrayScalar_True
|
| 178 |
+
|
| 179 |
+
#define PyArrayScalar_New(cls) \
|
| 180 |
+
Py##cls##ArrType_Type.tp_alloc(&Py##cls##ArrType_Type, 0)
|
| 181 |
+
#define PyArrayScalar_VAL(obj, cls) \
|
| 182 |
+
((Py##cls##ScalarObject *)obj)->obval
|
| 183 |
+
#define PyArrayScalar_ASSIGN(obj, cls, val) \
|
| 184 |
+
PyArrayScalar_VAL(obj, cls) = val
|
| 185 |
+
|
| 186 |
+
#endif /* NUMPY_CORE_INCLUDE_NUMPY_ARRAYSCALARS_H_ */
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/experimental_dtype_api.h
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* This header exports the new experimental DType API as proposed in
|
| 3 |
+
* NEPs 41 to 43. For background, please check these NEPs. Otherwise,
|
| 4 |
+
* this header also serves as documentation for the time being.
|
| 5 |
+
*
|
| 6 |
+
* The header includes `_dtype_api.h` which holds most definition while this
|
| 7 |
+
* header mainly wraps functions for public consumption.
|
| 8 |
+
*
|
| 9 |
+
* Please do not hesitate to contact @seberg with questions. This is
|
| 10 |
+
* developed together with https://github.com/seberg/experimental_user_dtypes
|
| 11 |
+
* and those interested in experimenting are encouraged to contribute there.
|
| 12 |
+
*
|
| 13 |
+
* To use the functions defined in the header, call::
|
| 14 |
+
*
|
| 15 |
+
* if (import_experimental_dtype_api(version) < 0) {
|
| 16 |
+
* return NULL;
|
| 17 |
+
* }
|
| 18 |
+
*
|
| 19 |
+
* in your module init. (A version mismatch will be reported, just update
|
| 20 |
+
* to the correct one, this will alert you of possible changes.)
|
| 21 |
+
*
|
| 22 |
+
* The following lists the main symbols currently exported. Please do not
|
| 23 |
+
* hesitate to ask for help or clarification:
|
| 24 |
+
*
|
| 25 |
+
* - PyUFunc_AddLoopFromSpec:
|
| 26 |
+
*
|
| 27 |
+
* Register a new loop for a ufunc. This uses the `PyArrayMethod_Spec`
|
| 28 |
+
* which must be filled in (see in-line comments).
|
| 29 |
+
*
|
| 30 |
+
* - PyUFunc_AddWrappingLoop:
|
| 31 |
+
*
|
| 32 |
+
* Register a new loop which reuses an existing one, but modifies the
|
| 33 |
+
* result dtypes. Please search the internal NumPy docs for more info
|
| 34 |
+
* at this point. (Used for physical units dtype.)
|
| 35 |
+
*
|
| 36 |
+
* - PyUFunc_AddPromoter:
|
| 37 |
+
*
|
| 38 |
+
* Register a new promoter for a ufunc. A promoter is a function stored
|
| 39 |
+
* in a PyCapsule (see in-line comments). It is passed the operation and
|
| 40 |
+
* requested DType signatures and can mutate it to attempt a new search
|
| 41 |
+
* for a matching loop/promoter.
|
| 42 |
+
* I.e. for Numba a promoter could even add the desired loop.
|
| 43 |
+
*
|
| 44 |
+
* - PyArrayInitDTypeMeta_FromSpec:
|
| 45 |
+
*
|
| 46 |
+
* Initialize a new DType. It must currently be a static Python C type
|
| 47 |
+
* that is declared as `PyArray_DTypeMeta` and not `PyTypeObject`.
|
| 48 |
+
* Further, it must subclass `np.dtype` and set its type to
|
| 49 |
+
* `PyArrayDTypeMeta_Type` (before calling `PyType_Read()`).
|
| 50 |
+
*
|
| 51 |
+
* - PyArray_CommonDType:
|
| 52 |
+
*
|
| 53 |
+
* Find the common-dtype ("promotion") for two DType classes. Similar
|
| 54 |
+
* to `np.result_type`, but works on the classes and not instances.
|
| 55 |
+
*
|
| 56 |
+
* - PyArray_PromoteDTypeSequence:
|
| 57 |
+
*
|
| 58 |
+
* Same as CommonDType, but works with an arbitrary number of DTypes.
|
| 59 |
+
* This function is smarter and can often return successful and unambiguous
|
| 60 |
+
* results when `common_dtype(common_dtype(dt1, dt2), dt3)` would
|
| 61 |
+
* depend on the operation order or fail. Nevertheless, DTypes should
|
| 62 |
+
* aim to ensure that their common-dtype implementation is associative
|
| 63 |
+
* and commutative! (Mainly, unsigned and signed integers are not.)
|
| 64 |
+
*
|
| 65 |
+
* For guaranteed consistent results DTypes must implement common-Dtype
|
| 66 |
+
* "transitively". If A promotes B and B promotes C, than A must generally
|
| 67 |
+
* also promote C; where "promotes" means implements the promotion.
|
| 68 |
+
* (There are some exceptions for abstract DTypes)
|
| 69 |
+
*
|
| 70 |
+
* - PyArray_GetDefaultDescr:
|
| 71 |
+
*
|
| 72 |
+
* Given a DType class, returns the default instance (descriptor).
|
| 73 |
+
* This is an inline function checking for `singleton` first and only
|
| 74 |
+
* calls the `default_descr` function if necessary.
|
| 75 |
+
*
|
| 76 |
+
* - PyArray_DoubleDType, etc.:
|
| 77 |
+
*
|
| 78 |
+
* Aliases to the DType classes for the builtin NumPy DTypes.
|
| 79 |
+
*
|
| 80 |
+
* WARNING
|
| 81 |
+
* =======
|
| 82 |
+
*
|
| 83 |
+
* By using this header, you understand that this is a fully experimental
|
| 84 |
+
* exposure. Details are expected to change, and some options may have no
|
| 85 |
+
* effect. (Please contact @seberg if you have questions!)
|
| 86 |
+
* If the exposure stops working, please file a bug report with NumPy.
|
| 87 |
+
* Further, a DType created using this API/header should still be expected
|
| 88 |
+
* to be incompatible with some functionality inside and outside of NumPy.
|
| 89 |
+
* In this case crashes must be expected. Please report any such problems
|
| 90 |
+
* so that they can be fixed before final exposure.
|
| 91 |
+
* Furthermore, expect missing checks for programming errors which the final
|
| 92 |
+
* API is expected to have.
|
| 93 |
+
*
|
| 94 |
+
* Symbols with a leading underscore are likely to not be included in the
|
| 95 |
+
* first public version, if these are central to your use-case, please let
|
| 96 |
+
* us know, so that we can reconsider.
|
| 97 |
+
*
|
| 98 |
+
* "Array-like" consumer API not yet under considerations
|
| 99 |
+
* ======================================================
|
| 100 |
+
*
|
| 101 |
+
* The new DType API is designed in a way to make it potentially useful for
|
| 102 |
+
* alternative "array-like" implementations. This will require careful
|
| 103 |
+
* exposure of details and functions and is not part of this experimental API.
|
| 104 |
+
*
|
| 105 |
+
* Brief (incompatibility) changelog
|
| 106 |
+
* =================================
|
| 107 |
+
*
|
| 108 |
+
* 2. None (only additions).
|
| 109 |
+
* 3. New `npy_intp *view_offset` argument for `resolve_descriptors`.
|
| 110 |
+
* This replaces the `NPY_CAST_IS_VIEW` flag. It can be set to 0 if the
|
| 111 |
+
* operation is a view, and is pre-initialized to `NPY_MIN_INTP` indicating
|
| 112 |
+
* that the operation is not a view.
|
| 113 |
+
*/
|
| 114 |
+
|
| 115 |
+
#ifndef NUMPY_CORE_INCLUDE_NUMPY_EXPERIMENTAL_DTYPE_API_H_
|
| 116 |
+
#define NUMPY_CORE_INCLUDE_NUMPY_EXPERIMENTAL_DTYPE_API_H_
|
| 117 |
+
|
| 118 |
+
#include <Python.h>
|
| 119 |
+
#include "ndarraytypes.h"
|
| 120 |
+
#include "_dtype_api.h"
|
| 121 |
+
|
| 122 |
+
/*
|
| 123 |
+
* The contents of PyArrayMethodObject are currently opaque (is there a way
|
| 124 |
+
* good way to make them be `PyObject *`?)
|
| 125 |
+
*/
|
| 126 |
+
typedef struct PyArrayMethodObject_tag PyArrayMethodObject;
|
| 127 |
+
|
| 128 |
+
/*
|
| 129 |
+
* There must be a better way?! -- Oh well, this is experimental
|
| 130 |
+
* (my issue with it, is that I cannot undef those helpers).
|
| 131 |
+
*/
|
| 132 |
+
#if defined(PY_ARRAY_UNIQUE_SYMBOL)
|
| 133 |
+
#define NPY_EXP_DTYPE_API_CONCAT_HELPER2(x, y) x ## y
|
| 134 |
+
#define NPY_EXP_DTYPE_API_CONCAT_HELPER(arg) NPY_EXP_DTYPE_API_CONCAT_HELPER2(arg, __experimental_dtype_api_table)
|
| 135 |
+
#define __experimental_dtype_api_table NPY_EXP_DTYPE_API_CONCAT_HELPER(PY_ARRAY_UNIQUE_SYMBOL)
|
| 136 |
+
#else
|
| 137 |
+
#define __experimental_dtype_api_table __experimental_dtype_api_table
|
| 138 |
+
#endif
|
| 139 |
+
|
| 140 |
+
/* Support for correct multi-file projects: */
|
| 141 |
+
#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
|
| 142 |
+
extern void **__experimental_dtype_api_table;
|
| 143 |
+
#else
|
| 144 |
+
/*
|
| 145 |
+
* Just a hack so I don't forget importing as much myself, I spend way too
|
| 146 |
+
* much time noticing it the first time around :).
|
| 147 |
+
*/
|
| 148 |
+
static void
|
| 149 |
+
__not_imported(void)
|
| 150 |
+
{
|
| 151 |
+
printf("*****\nCritical error, dtype API not imported\n*****\n");
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
static void *__uninitialized_table[] = {
|
| 155 |
+
&__not_imported, &__not_imported, &__not_imported, &__not_imported,
|
| 156 |
+
&__not_imported, &__not_imported, &__not_imported, &__not_imported};
|
| 157 |
+
|
| 158 |
+
#if defined(PY_ARRAY_UNIQUE_SYMBOL)
|
| 159 |
+
void **__experimental_dtype_api_table = __uninitialized_table;
|
| 160 |
+
#else
|
| 161 |
+
static void **__experimental_dtype_api_table = __uninitialized_table;
|
| 162 |
+
#endif
|
| 163 |
+
#endif
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
typedef int _ufunc_addloop_fromspec_func(
|
| 167 |
+
PyObject *ufunc, PyArrayMethod_Spec *spec);
|
| 168 |
+
/*
|
| 169 |
+
* The main ufunc registration function. This adds a new implementation/loop
|
| 170 |
+
* to a ufunc. It replaces `PyUFunc_RegisterLoopForType`.
|
| 171 |
+
*/
|
| 172 |
+
#define PyUFunc_AddLoopFromSpec \
|
| 173 |
+
(*(_ufunc_addloop_fromspec_func *)(__experimental_dtype_api_table[0]))
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
/* Please see the NumPy definitions in `array_method.h` for details on these */
|
| 177 |
+
typedef int translate_given_descrs_func(int nin, int nout,
|
| 178 |
+
PyArray_DTypeMeta *wrapped_dtypes[],
|
| 179 |
+
PyArray_Descr *given_descrs[], PyArray_Descr *new_descrs[]);
|
| 180 |
+
typedef int translate_loop_descrs_func(int nin, int nout,
|
| 181 |
+
PyArray_DTypeMeta *new_dtypes[], PyArray_Descr *given_descrs[],
|
| 182 |
+
PyArray_Descr *original_descrs[], PyArray_Descr *loop_descrs[]);
|
| 183 |
+
|
| 184 |
+
typedef int _ufunc_wrapping_loop_func(PyObject *ufunc_obj,
|
| 185 |
+
PyArray_DTypeMeta *new_dtypes[], PyArray_DTypeMeta *wrapped_dtypes[],
|
| 186 |
+
translate_given_descrs_func *translate_given_descrs,
|
| 187 |
+
translate_loop_descrs_func *translate_loop_descrs);
|
| 188 |
+
#define PyUFunc_AddWrappingLoop \
|
| 189 |
+
(*(_ufunc_wrapping_loop_func *)(__experimental_dtype_api_table[7]))
|
| 190 |
+
|
| 191 |
+
/*
|
| 192 |
+
* Type of the C promoter function, which must be wrapped into a
|
| 193 |
+
* PyCapsule with name "numpy._ufunc_promoter".
|
| 194 |
+
*
|
| 195 |
+
* Note that currently the output dtypes are always NULL unless they are
|
| 196 |
+
* also part of the signature. This is an implementation detail and could
|
| 197 |
+
* change in the future. However, in general promoters should not have a
|
| 198 |
+
* need for output dtypes.
|
| 199 |
+
* (There are potential use-cases, these are currently unsupported.)
|
| 200 |
+
*/
|
| 201 |
+
typedef int promoter_function(PyObject *ufunc,
|
| 202 |
+
PyArray_DTypeMeta *op_dtypes[], PyArray_DTypeMeta *signature[],
|
| 203 |
+
PyArray_DTypeMeta *new_op_dtypes[]);
|
| 204 |
+
|
| 205 |
+
/*
|
| 206 |
+
* Function to register a promoter.
|
| 207 |
+
*
|
| 208 |
+
* @param ufunc The ufunc object to register the promoter with.
|
| 209 |
+
* @param DType_tuple A Python tuple containing DTypes or None matching the
|
| 210 |
+
* number of inputs and outputs of the ufunc.
|
| 211 |
+
* @param promoter A PyCapsule with name "numpy._ufunc_promoter" containing
|
| 212 |
+
* a pointer to a `promoter_function`.
|
| 213 |
+
*/
|
| 214 |
+
typedef int _ufunc_addpromoter_func(
|
| 215 |
+
PyObject *ufunc, PyObject *DType_tuple, PyObject *promoter);
|
| 216 |
+
#define PyUFunc_AddPromoter \
|
| 217 |
+
(*(_ufunc_addpromoter_func *)(__experimental_dtype_api_table[1]))
|
| 218 |
+
|
| 219 |
+
#define PyArrayDTypeMeta_Type \
|
| 220 |
+
(*(PyTypeObject *)__experimental_dtype_api_table[2])
|
| 221 |
+
typedef int __dtypemeta_fromspec(
|
| 222 |
+
PyArray_DTypeMeta *DType, PyArrayDTypeMeta_Spec *dtype_spec);
|
| 223 |
+
/*
|
| 224 |
+
* Finalize creation of a DTypeMeta. You must ensure that the DTypeMeta is
|
| 225 |
+
* a proper subclass. The DTypeMeta object has additional fields compared to
|
| 226 |
+
* a normal PyTypeObject!
|
| 227 |
+
* The only (easy) creation of a new DType is to create a static Type which
|
| 228 |
+
* inherits `PyArray_DescrType`, sets its type to `PyArrayDTypeMeta_Type` and
|
| 229 |
+
* uses `PyArray_DTypeMeta` defined above as the C-structure.
|
| 230 |
+
*/
|
| 231 |
+
#define PyArrayInitDTypeMeta_FromSpec \
|
| 232 |
+
((__dtypemeta_fromspec *)(__experimental_dtype_api_table[3]))
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
/*
|
| 236 |
+
* *************************************
|
| 237 |
+
* WORKING WITH DTYPES
|
| 238 |
+
* *************************************
|
| 239 |
+
*/
|
| 240 |
+
|
| 241 |
+
typedef PyArray_DTypeMeta *__common_dtype(
|
| 242 |
+
PyArray_DTypeMeta *DType1, PyArray_DTypeMeta *DType2);
|
| 243 |
+
#define PyArray_CommonDType \
|
| 244 |
+
((__common_dtype *)(__experimental_dtype_api_table[4]))
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
typedef PyArray_DTypeMeta *__promote_dtype_sequence(
|
| 248 |
+
npy_intp num, PyArray_DTypeMeta *DTypes[]);
|
| 249 |
+
#define PyArray_PromoteDTypeSequence \
|
| 250 |
+
((__promote_dtype_sequence *)(__experimental_dtype_api_table[5]))
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
typedef PyArray_Descr *__get_default_descr(
|
| 254 |
+
PyArray_DTypeMeta *DType);
|
| 255 |
+
#define _PyArray_GetDefaultDescr \
|
| 256 |
+
((__get_default_descr *)(__experimental_dtype_api_table[6]))
|
| 257 |
+
|
| 258 |
+
static inline PyArray_Descr *
|
| 259 |
+
PyArray_GetDefaultDescr(PyArray_DTypeMeta *DType)
|
| 260 |
+
{
|
| 261 |
+
if (DType->singleton != NULL) {
|
| 262 |
+
Py_INCREF(DType->singleton);
|
| 263 |
+
return DType->singleton;
|
| 264 |
+
}
|
| 265 |
+
return _PyArray_GetDefaultDescr(DType);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
/*
|
| 270 |
+
* NumPy's builtin DTypes:
|
| 271 |
+
*/
|
| 272 |
+
#define PyArray_BoolDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[10])
|
| 273 |
+
/* Integers */
|
| 274 |
+
#define PyArray_ByteDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[11])
|
| 275 |
+
#define PyArray_UByteDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[12])
|
| 276 |
+
#define PyArray_ShortDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[13])
|
| 277 |
+
#define PyArray_UShortDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[14])
|
| 278 |
+
#define PyArray_IntDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[15])
|
| 279 |
+
#define PyArray_UIntDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[16])
|
| 280 |
+
#define PyArray_LongDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[17])
|
| 281 |
+
#define PyArray_ULongDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[18])
|
| 282 |
+
#define PyArray_LongLongDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[19])
|
| 283 |
+
#define PyArray_ULongLongDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[20])
|
| 284 |
+
/* Integer aliases */
|
| 285 |
+
#define PyArray_Int8Type (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[21])
|
| 286 |
+
#define PyArray_UInt8DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[22])
|
| 287 |
+
#define PyArray_Int16DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[23])
|
| 288 |
+
#define PyArray_UInt16DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[24])
|
| 289 |
+
#define PyArray_Int32DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[25])
|
| 290 |
+
#define PyArray_UInt32DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[26])
|
| 291 |
+
#define PyArray_Int64DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[27])
|
| 292 |
+
#define PyArray_UInt64DType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[28])
|
| 293 |
+
#define PyArray_IntpDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[29])
|
| 294 |
+
#define PyArray_UIntpDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[30])
|
| 295 |
+
/* Floats */
|
| 296 |
+
#define PyArray_HalfType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[31])
|
| 297 |
+
#define PyArray_FloatDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[32])
|
| 298 |
+
#define PyArray_DoubleDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[33])
|
| 299 |
+
#define PyArray_LongDoubleDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[34])
|
| 300 |
+
/* Complex */
|
| 301 |
+
#define PyArray_CFloatDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[35])
|
| 302 |
+
#define PyArray_CDoubleDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[36])
|
| 303 |
+
#define PyArray_CLongDoubleDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[37])
|
| 304 |
+
/* String/Bytes */
|
| 305 |
+
#define PyArray_StringDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[38])
|
| 306 |
+
#define PyArray_UnicodeDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[39])
|
| 307 |
+
/* Datetime/Timedelta */
|
| 308 |
+
#define PyArray_DatetimeDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[40])
|
| 309 |
+
#define PyArray_TimedeltaDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[41])
|
| 310 |
+
/* Object/Void */
|
| 311 |
+
#define PyArray_ObjectDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[42])
|
| 312 |
+
#define PyArray_VoidDType (*(PyArray_DTypeMeta *)__experimental_dtype_api_table[43])
|
| 313 |
+
|
| 314 |
+
/*
|
| 315 |
+
* ********************************
|
| 316 |
+
* Initialization
|
| 317 |
+
* ********************************
|
| 318 |
+
*
|
| 319 |
+
* Import the experimental API, the version must match the one defined in
|
| 320 |
+
* the header to ensure changes are taken into account. NumPy will further
|
| 321 |
+
* runtime-check this.
|
| 322 |
+
* You must call this function to use the symbols defined in this file.
|
| 323 |
+
*/
|
| 324 |
+
#if !defined(NO_IMPORT) && !defined(NO_IMPORT_ARRAY)
|
| 325 |
+
|
| 326 |
+
static int
|
| 327 |
+
import_experimental_dtype_api(int version)
|
| 328 |
+
{
|
| 329 |
+
if (version != __EXPERIMENTAL_DTYPE_API_VERSION) {
|
| 330 |
+
PyErr_Format(PyExc_RuntimeError,
|
| 331 |
+
"DType API version %d did not match header version %d. Please "
|
| 332 |
+
"update the import statement and check for API changes.",
|
| 333 |
+
version, __EXPERIMENTAL_DTYPE_API_VERSION);
|
| 334 |
+
return -1;
|
| 335 |
+
}
|
| 336 |
+
if (__experimental_dtype_api_table != __uninitialized_table) {
|
| 337 |
+
/* already imported. */
|
| 338 |
+
return 0;
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
PyObject *multiarray = PyImport_ImportModule("numpy.core._multiarray_umath");
|
| 342 |
+
if (multiarray == NULL) {
|
| 343 |
+
return -1;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
PyObject *api = PyObject_CallMethod(multiarray,
|
| 347 |
+
"_get_experimental_dtype_api", "i", version);
|
| 348 |
+
Py_DECREF(multiarray);
|
| 349 |
+
if (api == NULL) {
|
| 350 |
+
return -1;
|
| 351 |
+
}
|
| 352 |
+
__experimental_dtype_api_table = (void **)PyCapsule_GetPointer(api,
|
| 353 |
+
"experimental_dtype_api_table");
|
| 354 |
+
Py_DECREF(api);
|
| 355 |
+
|
| 356 |
+
if (__experimental_dtype_api_table == NULL) {
|
| 357 |
+
__experimental_dtype_api_table = __uninitialized_table;
|
| 358 |
+
return -1;
|
| 359 |
+
}
|
| 360 |
+
return 0;
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
#endif /* !defined(NO_IMPORT) && !defined(NO_IMPORT_ARRAY) */
|
| 364 |
+
|
| 365 |
+
#endif /* NUMPY_CORE_INCLUDE_NUMPY_EXPERIMENTAL_DTYPE_API_H_ */
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/halffloat.h
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef NUMPY_CORE_INCLUDE_NUMPY_HALFFLOAT_H_
|
| 2 |
+
#define NUMPY_CORE_INCLUDE_NUMPY_HALFFLOAT_H_
|
| 3 |
+
|
| 4 |
+
#include <Python.h>
|
| 5 |
+
#include <numpy/npy_math.h>
|
| 6 |
+
|
| 7 |
+
#ifdef __cplusplus
|
| 8 |
+
extern "C" {
|
| 9 |
+
#endif
|
| 10 |
+
|
| 11 |
+
/*
|
| 12 |
+
* Half-precision routines
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
/* Conversions */
|
| 16 |
+
float npy_half_to_float(npy_half h);
|
| 17 |
+
double npy_half_to_double(npy_half h);
|
| 18 |
+
npy_half npy_float_to_half(float f);
|
| 19 |
+
npy_half npy_double_to_half(double d);
|
| 20 |
+
/* Comparisons */
|
| 21 |
+
int npy_half_eq(npy_half h1, npy_half h2);
|
| 22 |
+
int npy_half_ne(npy_half h1, npy_half h2);
|
| 23 |
+
int npy_half_le(npy_half h1, npy_half h2);
|
| 24 |
+
int npy_half_lt(npy_half h1, npy_half h2);
|
| 25 |
+
int npy_half_ge(npy_half h1, npy_half h2);
|
| 26 |
+
int npy_half_gt(npy_half h1, npy_half h2);
|
| 27 |
+
/* faster *_nonan variants for when you know h1 and h2 are not NaN */
|
| 28 |
+
int npy_half_eq_nonan(npy_half h1, npy_half h2);
|
| 29 |
+
int npy_half_lt_nonan(npy_half h1, npy_half h2);
|
| 30 |
+
int npy_half_le_nonan(npy_half h1, npy_half h2);
|
| 31 |
+
/* Miscellaneous functions */
|
| 32 |
+
int npy_half_iszero(npy_half h);
|
| 33 |
+
int npy_half_isnan(npy_half h);
|
| 34 |
+
int npy_half_isinf(npy_half h);
|
| 35 |
+
int npy_half_isfinite(npy_half h);
|
| 36 |
+
int npy_half_signbit(npy_half h);
|
| 37 |
+
npy_half npy_half_copysign(npy_half x, npy_half y);
|
| 38 |
+
npy_half npy_half_spacing(npy_half h);
|
| 39 |
+
npy_half npy_half_nextafter(npy_half x, npy_half y);
|
| 40 |
+
npy_half npy_half_divmod(npy_half x, npy_half y, npy_half *modulus);
|
| 41 |
+
|
| 42 |
+
/*
|
| 43 |
+
* Half-precision constants
|
| 44 |
+
*/
|
| 45 |
+
|
| 46 |
+
#define NPY_HALF_ZERO (0x0000u)
|
| 47 |
+
#define NPY_HALF_PZERO (0x0000u)
|
| 48 |
+
#define NPY_HALF_NZERO (0x8000u)
|
| 49 |
+
#define NPY_HALF_ONE (0x3c00u)
|
| 50 |
+
#define NPY_HALF_NEGONE (0xbc00u)
|
| 51 |
+
#define NPY_HALF_PINF (0x7c00u)
|
| 52 |
+
#define NPY_HALF_NINF (0xfc00u)
|
| 53 |
+
#define NPY_HALF_NAN (0x7e00u)
|
| 54 |
+
|
| 55 |
+
#define NPY_MAX_HALF (0x7bffu)
|
| 56 |
+
|
| 57 |
+
/*
|
| 58 |
+
* Bit-level conversions
|
| 59 |
+
*/
|
| 60 |
+
|
| 61 |
+
npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f);
|
| 62 |
+
npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d);
|
| 63 |
+
npy_uint32 npy_halfbits_to_floatbits(npy_uint16 h);
|
| 64 |
+
npy_uint64 npy_halfbits_to_doublebits(npy_uint16 h);
|
| 65 |
+
|
| 66 |
+
#ifdef __cplusplus
|
| 67 |
+
}
|
| 68 |
+
#endif
|
| 69 |
+
|
| 70 |
+
#endif /* NUMPY_CORE_INCLUDE_NUMPY_HALFFLOAT_H_ */
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/ndarrayobject.h
ADDED
|
@@ -0,0 +1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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* DON'T INCLUDE THIS DIRECTLY.
|
| 3 |
+
*/
|
| 4 |
+
#ifndef NUMPY_CORE_INCLUDE_NUMPY_NDARRAYOBJECT_H_
|
| 5 |
+
#define NUMPY_CORE_INCLUDE_NUMPY_NDARRAYOBJECT_H_
|
| 6 |
+
|
| 7 |
+
#ifdef __cplusplus
|
| 8 |
+
extern "C" {
|
| 9 |
+
#endif
|
| 10 |
+
|
| 11 |
+
#include <Python.h>
|
| 12 |
+
#include "ndarraytypes.h"
|
| 13 |
+
|
| 14 |
+
/* Includes the "function" C-API -- these are all stored in a
|
| 15 |
+
list of pointers --- one for each file
|
| 16 |
+
The two lists are concatenated into one in multiarray.
|
| 17 |
+
|
| 18 |
+
They are available as import_array()
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include "__multiarray_api.h"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
/* C-API that requires previous API to be defined */
|
| 25 |
+
|
| 26 |
+
#define PyArray_DescrCheck(op) PyObject_TypeCheck(op, &PyArrayDescr_Type)
|
| 27 |
+
|
| 28 |
+
#define PyArray_Check(op) PyObject_TypeCheck(op, &PyArray_Type)
|
| 29 |
+
#define PyArray_CheckExact(op) (((PyObject*)(op))->ob_type == &PyArray_Type)
|
| 30 |
+
|
| 31 |
+
#define PyArray_HasArrayInterfaceType(op, type, context, out) \
|
| 32 |
+
((((out)=PyArray_FromStructInterface(op)) != Py_NotImplemented) || \
|
| 33 |
+
(((out)=PyArray_FromInterface(op)) != Py_NotImplemented) || \
|
| 34 |
+
(((out)=PyArray_FromArrayAttr(op, type, context)) != \
|
| 35 |
+
Py_NotImplemented))
|
| 36 |
+
|
| 37 |
+
#define PyArray_HasArrayInterface(op, out) \
|
| 38 |
+
PyArray_HasArrayInterfaceType(op, NULL, NULL, out)
|
| 39 |
+
|
| 40 |
+
#define PyArray_IsZeroDim(op) (PyArray_Check(op) && \
|
| 41 |
+
(PyArray_NDIM((PyArrayObject *)op) == 0))
|
| 42 |
+
|
| 43 |
+
#define PyArray_IsScalar(obj, cls) \
|
| 44 |
+
(PyObject_TypeCheck(obj, &Py##cls##ArrType_Type))
|
| 45 |
+
|
| 46 |
+
#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \
|
| 47 |
+
PyArray_IsZeroDim(m))
|
| 48 |
+
#define PyArray_IsPythonNumber(obj) \
|
| 49 |
+
(PyFloat_Check(obj) || PyComplex_Check(obj) || \
|
| 50 |
+
PyLong_Check(obj) || PyBool_Check(obj))
|
| 51 |
+
#define PyArray_IsIntegerScalar(obj) (PyLong_Check(obj) \
|
| 52 |
+
|| PyArray_IsScalar((obj), Integer))
|
| 53 |
+
#define PyArray_IsPythonScalar(obj) \
|
| 54 |
+
(PyArray_IsPythonNumber(obj) || PyBytes_Check(obj) || \
|
| 55 |
+
PyUnicode_Check(obj))
|
| 56 |
+
|
| 57 |
+
#define PyArray_IsAnyScalar(obj) \
|
| 58 |
+
(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))
|
| 59 |
+
|
| 60 |
+
#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \
|
| 61 |
+
PyArray_CheckScalar(obj))
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? \
|
| 65 |
+
Py_INCREF(m), (m) : \
|
| 66 |
+
(PyArrayObject *)(PyArray_Copy(m)))
|
| 67 |
+
|
| 68 |
+
#define PyArray_SAMESHAPE(a1,a2) ((PyArray_NDIM(a1) == PyArray_NDIM(a2)) && \
|
| 69 |
+
PyArray_CompareLists(PyArray_DIMS(a1), \
|
| 70 |
+
PyArray_DIMS(a2), \
|
| 71 |
+
PyArray_NDIM(a1)))
|
| 72 |
+
|
| 73 |
+
#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))
|
| 74 |
+
#define PyArray_NBYTES(m) (PyArray_ITEMSIZE(m) * PyArray_SIZE(m))
|
| 75 |
+
#define PyArray_FROM_O(m) PyArray_FromAny(m, NULL, 0, 0, 0, NULL)
|
| 76 |
+
|
| 77 |
+
#define PyArray_FROM_OF(m,flags) PyArray_CheckFromAny(m, NULL, 0, 0, flags, \
|
| 78 |
+
NULL)
|
| 79 |
+
|
| 80 |
+
#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, \
|
| 81 |
+
PyArray_DescrFromType(type), 0, 0, 0, NULL)
|
| 82 |
+
|
| 83 |
+
#define PyArray_FROM_OTF(m, type, flags) \
|
| 84 |
+
PyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \
|
| 85 |
+
(((flags) & NPY_ARRAY_ENSURECOPY) ? \
|
| 86 |
+
((flags) | NPY_ARRAY_DEFAULT) : (flags)), NULL)
|
| 87 |
+
|
| 88 |
+
#define PyArray_FROMANY(m, type, min, max, flags) \
|
| 89 |
+
PyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \
|
| 90 |
+
(((flags) & NPY_ARRAY_ENSURECOPY) ? \
|
| 91 |
+
(flags) | NPY_ARRAY_DEFAULT : (flags)), NULL)
|
| 92 |
+
|
| 93 |
+
#define PyArray_ZEROS(m, dims, type, is_f_order) \
|
| 94 |
+
PyArray_Zeros(m, dims, PyArray_DescrFromType(type), is_f_order)
|
| 95 |
+
|
| 96 |
+
#define PyArray_EMPTY(m, dims, type, is_f_order) \
|
| 97 |
+
PyArray_Empty(m, dims, PyArray_DescrFromType(type), is_f_order)
|
| 98 |
+
|
| 99 |
+
#define PyArray_FILLWBYTE(obj, val) memset(PyArray_DATA(obj), val, \
|
| 100 |
+
PyArray_NBYTES(obj))
|
| 101 |
+
#ifndef PYPY_VERSION
|
| 102 |
+
#define PyArray_REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)
|
| 103 |
+
#define NPY_REFCOUNT PyArray_REFCOUNT
|
| 104 |
+
#endif
|
| 105 |
+
#define NPY_MAX_ELSIZE (2 * NPY_SIZEOF_LONGDOUBLE)
|
| 106 |
+
|
| 107 |
+
#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \
|
| 108 |
+
PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
|
| 109 |
+
max_depth, NPY_ARRAY_DEFAULT, NULL)
|
| 110 |
+
|
| 111 |
+
#define PyArray_EquivArrTypes(a1, a2) \
|
| 112 |
+
PyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))
|
| 113 |
+
|
| 114 |
+
#define PyArray_EquivByteorders(b1, b2) \
|
| 115 |
+
(((b1) == (b2)) || (PyArray_ISNBO(b1) == PyArray_ISNBO(b2)))
|
| 116 |
+
|
| 117 |
+
#define PyArray_SimpleNew(nd, dims, typenum) \
|
| 118 |
+
PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, NULL, 0, 0, NULL)
|
| 119 |
+
|
| 120 |
+
#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \
|
| 121 |
+
PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, \
|
| 122 |
+
data, 0, NPY_ARRAY_CARRAY, NULL)
|
| 123 |
+
|
| 124 |
+
#define PyArray_SimpleNewFromDescr(nd, dims, descr) \
|
| 125 |
+
PyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, \
|
| 126 |
+
NULL, NULL, 0, NULL)
|
| 127 |
+
|
| 128 |
+
#define PyArray_ToScalar(data, arr) \
|
| 129 |
+
PyArray_Scalar(data, PyArray_DESCR(arr), (PyObject *)arr)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
/* These might be faster without the dereferencing of obj
|
| 133 |
+
going on inside -- of course an optimizing compiler should
|
| 134 |
+
inline the constants inside a for loop making it a moot point
|
| 135 |
+
*/
|
| 136 |
+
|
| 137 |
+
#define PyArray_GETPTR1(obj, i) ((void *)(PyArray_BYTES(obj) + \
|
| 138 |
+
(i)*PyArray_STRIDES(obj)[0]))
|
| 139 |
+
|
| 140 |
+
#define PyArray_GETPTR2(obj, i, j) ((void *)(PyArray_BYTES(obj) + \
|
| 141 |
+
(i)*PyArray_STRIDES(obj)[0] + \
|
| 142 |
+
(j)*PyArray_STRIDES(obj)[1]))
|
| 143 |
+
|
| 144 |
+
#define PyArray_GETPTR3(obj, i, j, k) ((void *)(PyArray_BYTES(obj) + \
|
| 145 |
+
(i)*PyArray_STRIDES(obj)[0] + \
|
| 146 |
+
(j)*PyArray_STRIDES(obj)[1] + \
|
| 147 |
+
(k)*PyArray_STRIDES(obj)[2]))
|
| 148 |
+
|
| 149 |
+
#define PyArray_GETPTR4(obj, i, j, k, l) ((void *)(PyArray_BYTES(obj) + \
|
| 150 |
+
(i)*PyArray_STRIDES(obj)[0] + \
|
| 151 |
+
(j)*PyArray_STRIDES(obj)[1] + \
|
| 152 |
+
(k)*PyArray_STRIDES(obj)[2] + \
|
| 153 |
+
(l)*PyArray_STRIDES(obj)[3]))
|
| 154 |
+
|
| 155 |
+
static inline void
|
| 156 |
+
PyArray_DiscardWritebackIfCopy(PyArrayObject *arr)
|
| 157 |
+
{
|
| 158 |
+
PyArrayObject_fields *fa = (PyArrayObject_fields *)arr;
|
| 159 |
+
if (fa && fa->base) {
|
| 160 |
+
if (fa->flags & NPY_ARRAY_WRITEBACKIFCOPY) {
|
| 161 |
+
PyArray_ENABLEFLAGS((PyArrayObject*)fa->base, NPY_ARRAY_WRITEABLE);
|
| 162 |
+
Py_DECREF(fa->base);
|
| 163 |
+
fa->base = NULL;
|
| 164 |
+
PyArray_CLEARFLAGS(arr, NPY_ARRAY_WRITEBACKIFCOPY);
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
#define PyArray_DESCR_REPLACE(descr) do { \
|
| 170 |
+
PyArray_Descr *_new_; \
|
| 171 |
+
_new_ = PyArray_DescrNew(descr); \
|
| 172 |
+
Py_XDECREF(descr); \
|
| 173 |
+
descr = _new_; \
|
| 174 |
+
} while(0)
|
| 175 |
+
|
| 176 |
+
/* Copy should always return contiguous array */
|
| 177 |
+
#define PyArray_Copy(obj) PyArray_NewCopy(obj, NPY_CORDER)
|
| 178 |
+
|
| 179 |
+
#define PyArray_FromObject(op, type, min_depth, max_depth) \
|
| 180 |
+
PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
|
| 181 |
+
max_depth, NPY_ARRAY_BEHAVED | \
|
| 182 |
+
NPY_ARRAY_ENSUREARRAY, NULL)
|
| 183 |
+
|
| 184 |
+
#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth) \
|
| 185 |
+
PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
|
| 186 |
+
max_depth, NPY_ARRAY_DEFAULT | \
|
| 187 |
+
NPY_ARRAY_ENSUREARRAY, NULL)
|
| 188 |
+
|
| 189 |
+
#define PyArray_CopyFromObject(op, type, min_depth, max_depth) \
|
| 190 |
+
PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
|
| 191 |
+
max_depth, NPY_ARRAY_ENSURECOPY | \
|
| 192 |
+
NPY_ARRAY_DEFAULT | \
|
| 193 |
+
NPY_ARRAY_ENSUREARRAY, NULL)
|
| 194 |
+
|
| 195 |
+
#define PyArray_Cast(mp, type_num) \
|
| 196 |
+
PyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)
|
| 197 |
+
|
| 198 |
+
#define PyArray_Take(ap, items, axis) \
|
| 199 |
+
PyArray_TakeFrom(ap, items, axis, NULL, NPY_RAISE)
|
| 200 |
+
|
| 201 |
+
#define PyArray_Put(ap, items, values) \
|
| 202 |
+
PyArray_PutTo(ap, items, values, NPY_RAISE)
|
| 203 |
+
|
| 204 |
+
/* Compatibility with old Numeric stuff -- don't use in new code */
|
| 205 |
+
|
| 206 |
+
#define PyArray_FromDimsAndData(nd, d, type, data) \
|
| 207 |
+
PyArray_FromDimsAndDataAndDescr(nd, d, PyArray_DescrFromType(type), \
|
| 208 |
+
data)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
/*
|
| 212 |
+
Check to see if this key in the dictionary is the "title"
|
| 213 |
+
entry of the tuple (i.e. a duplicate dictionary entry in the fields
|
| 214 |
+
dict).
|
| 215 |
+
*/
|
| 216 |
+
|
| 217 |
+
static inline int
|
| 218 |
+
NPY_TITLE_KEY_check(PyObject *key, PyObject *value)
|
| 219 |
+
{
|
| 220 |
+
PyObject *title;
|
| 221 |
+
if (PyTuple_Size(value) != 3) {
|
| 222 |
+
return 0;
|
| 223 |
+
}
|
| 224 |
+
title = PyTuple_GetItem(value, 2);
|
| 225 |
+
if (key == title) {
|
| 226 |
+
return 1;
|
| 227 |
+
}
|
| 228 |
+
#ifdef PYPY_VERSION
|
| 229 |
+
/*
|
| 230 |
+
* On PyPy, dictionary keys do not always preserve object identity.
|
| 231 |
+
* Fall back to comparison by value.
|
| 232 |
+
*/
|
| 233 |
+
if (PyUnicode_Check(title) && PyUnicode_Check(key)) {
|
| 234 |
+
return PyUnicode_Compare(title, key) == 0 ? 1 : 0;
|
| 235 |
+
}
|
| 236 |
+
#endif
|
| 237 |
+
return 0;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/* Macro, for backward compat with "if NPY_TITLE_KEY(key, value) { ..." */
|
| 241 |
+
#define NPY_TITLE_KEY(key, value) (NPY_TITLE_KEY_check((key), (value)))
|
| 242 |
+
|
| 243 |
+
#define DEPRECATE(msg) PyErr_WarnEx(PyExc_DeprecationWarning,msg,1)
|
| 244 |
+
#define DEPRECATE_FUTUREWARNING(msg) PyErr_WarnEx(PyExc_FutureWarning,msg,1)
|
| 245 |
+
|
| 246 |
+
#ifdef __cplusplus
|
| 247 |
+
}
|
| 248 |
+
#endif
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
#endif /* NUMPY_CORE_INCLUDE_NUMPY_NDARRAYOBJECT_H_ */
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/ndarraytypes.h
ADDED
|
@@ -0,0 +1,1945 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
#include "npy_cpu.h"
|
| 7 |
+
#include "utils.h"
|
| 8 |
+
|
| 9 |
+
#define NPY_NO_EXPORT NPY_VISIBILITY_HIDDEN
|
| 10 |
+
|
| 11 |
+
/* Only use thread if configured in config and python supports it */
|
| 12 |
+
#if defined WITH_THREAD && !NPY_NO_SMP
|
| 13 |
+
#define NPY_ALLOW_THREADS 1
|
| 14 |
+
#else
|
| 15 |
+
#define NPY_ALLOW_THREADS 0
|
| 16 |
+
#endif
|
| 17 |
+
|
| 18 |
+
#ifndef __has_extension
|
| 19 |
+
#define __has_extension(x) 0
|
| 20 |
+
#endif
|
| 21 |
+
|
| 22 |
+
#if !defined(_NPY_NO_DEPRECATIONS) && \
|
| 23 |
+
((defined(__GNUC__)&& __GNUC__ >= 6) || \
|
| 24 |
+
__has_extension(attribute_deprecated_with_message))
|
| 25 |
+
#define NPY_ATTR_DEPRECATE(text) __attribute__ ((deprecated (text)))
|
| 26 |
+
#else
|
| 27 |
+
#define NPY_ATTR_DEPRECATE(text)
|
| 28 |
+
#endif
|
| 29 |
+
|
| 30 |
+
/*
|
| 31 |
+
* There are several places in the code where an array of dimensions
|
| 32 |
+
* is allocated statically. This is the size of that static
|
| 33 |
+
* allocation.
|
| 34 |
+
*
|
| 35 |
+
* The array creation itself could have arbitrary dimensions but all
|
| 36 |
+
* the places where static allocation is used would need to be changed
|
| 37 |
+
* to dynamic (including inside of several structures)
|
| 38 |
+
*/
|
| 39 |
+
|
| 40 |
+
#define NPY_MAXDIMS 32
|
| 41 |
+
#define NPY_MAXARGS 32
|
| 42 |
+
|
| 43 |
+
/* Used for Converter Functions "O&" code in ParseTuple */
|
| 44 |
+
#define NPY_FAIL 0
|
| 45 |
+
#define NPY_SUCCEED 1
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
enum NPY_TYPES { NPY_BOOL=0,
|
| 49 |
+
NPY_BYTE, NPY_UBYTE,
|
| 50 |
+
NPY_SHORT, NPY_USHORT,
|
| 51 |
+
NPY_INT, NPY_UINT,
|
| 52 |
+
NPY_LONG, NPY_ULONG,
|
| 53 |
+
NPY_LONGLONG, NPY_ULONGLONG,
|
| 54 |
+
NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE,
|
| 55 |
+
NPY_CFLOAT, NPY_CDOUBLE, NPY_CLONGDOUBLE,
|
| 56 |
+
NPY_OBJECT=17,
|
| 57 |
+
NPY_STRING, NPY_UNICODE,
|
| 58 |
+
NPY_VOID,
|
| 59 |
+
/*
|
| 60 |
+
* New 1.6 types appended, may be integrated
|
| 61 |
+
* into the above in 2.0.
|
| 62 |
+
*/
|
| 63 |
+
NPY_DATETIME, NPY_TIMEDELTA, NPY_HALF,
|
| 64 |
+
|
| 65 |
+
NPY_NTYPES,
|
| 66 |
+
NPY_NOTYPE,
|
| 67 |
+
NPY_CHAR NPY_ATTR_DEPRECATE("Use NPY_STRING"),
|
| 68 |
+
NPY_USERDEF=256, /* leave room for characters */
|
| 69 |
+
|
| 70 |
+
/* The number of types not including the new 1.6 types */
|
| 71 |
+
NPY_NTYPES_ABI_COMPATIBLE=21
|
| 72 |
+
};
|
| 73 |
+
#if defined(_MSC_VER) && !defined(__clang__)
|
| 74 |
+
#pragma deprecated(NPY_CHAR)
|
| 75 |
+
#endif
|
| 76 |
+
|
| 77 |
+
/* basetype array priority */
|
| 78 |
+
#define NPY_PRIORITY 0.0
|
| 79 |
+
|
| 80 |
+
/* default subtype priority */
|
| 81 |
+
#define NPY_SUBTYPE_PRIORITY 1.0
|
| 82 |
+
|
| 83 |
+
/* default scalar priority */
|
| 84 |
+
#define NPY_SCALAR_PRIORITY -1000000.0
|
| 85 |
+
|
| 86 |
+
/* How many floating point types are there (excluding half) */
|
| 87 |
+
#define NPY_NUM_FLOATTYPE 3
|
| 88 |
+
|
| 89 |
+
/*
|
| 90 |
+
* These characters correspond to the array type and the struct
|
| 91 |
+
* module
|
| 92 |
+
*/
|
| 93 |
+
|
| 94 |
+
enum NPY_TYPECHAR {
|
| 95 |
+
NPY_BOOLLTR = '?',
|
| 96 |
+
NPY_BYTELTR = 'b',
|
| 97 |
+
NPY_UBYTELTR = 'B',
|
| 98 |
+
NPY_SHORTLTR = 'h',
|
| 99 |
+
NPY_USHORTLTR = 'H',
|
| 100 |
+
NPY_INTLTR = 'i',
|
| 101 |
+
NPY_UINTLTR = 'I',
|
| 102 |
+
NPY_LONGLTR = 'l',
|
| 103 |
+
NPY_ULONGLTR = 'L',
|
| 104 |
+
NPY_LONGLONGLTR = 'q',
|
| 105 |
+
NPY_ULONGLONGLTR = 'Q',
|
| 106 |
+
NPY_HALFLTR = 'e',
|
| 107 |
+
NPY_FLOATLTR = 'f',
|
| 108 |
+
NPY_DOUBLELTR = 'd',
|
| 109 |
+
NPY_LONGDOUBLELTR = 'g',
|
| 110 |
+
NPY_CFLOATLTR = 'F',
|
| 111 |
+
NPY_CDOUBLELTR = 'D',
|
| 112 |
+
NPY_CLONGDOUBLELTR = 'G',
|
| 113 |
+
NPY_OBJECTLTR = 'O',
|
| 114 |
+
NPY_STRINGLTR = 'S',
|
| 115 |
+
NPY_STRINGLTR2 = 'a',
|
| 116 |
+
NPY_UNICODELTR = 'U',
|
| 117 |
+
NPY_VOIDLTR = 'V',
|
| 118 |
+
NPY_DATETIMELTR = 'M',
|
| 119 |
+
NPY_TIMEDELTALTR = 'm',
|
| 120 |
+
NPY_CHARLTR = 'c',
|
| 121 |
+
|
| 122 |
+
/*
|
| 123 |
+
* No Descriptor, just a define -- this let's
|
| 124 |
+
* Python users specify an array of integers
|
| 125 |
+
* large enough to hold a pointer on the
|
| 126 |
+
* platform
|
| 127 |
+
*/
|
| 128 |
+
NPY_INTPLTR = 'p',
|
| 129 |
+
NPY_UINTPLTR = 'P',
|
| 130 |
+
|
| 131 |
+
/*
|
| 132 |
+
* These are for dtype 'kinds', not dtype 'typecodes'
|
| 133 |
+
* as the above are for.
|
| 134 |
+
*/
|
| 135 |
+
NPY_GENBOOLLTR ='b',
|
| 136 |
+
NPY_SIGNEDLTR = 'i',
|
| 137 |
+
NPY_UNSIGNEDLTR = 'u',
|
| 138 |
+
NPY_FLOATINGLTR = 'f',
|
| 139 |
+
NPY_COMPLEXLTR = 'c'
|
| 140 |
+
};
|
| 141 |
+
|
| 142 |
+
/*
|
| 143 |
+
* Changing this may break Numpy API compatibility
|
| 144 |
+
* due to changing offsets in PyArray_ArrFuncs, so be
|
| 145 |
+
* careful. Here we have reused the mergesort slot for
|
| 146 |
+
* any kind of stable sort, the actual implementation will
|
| 147 |
+
* depend on the data type.
|
| 148 |
+
*/
|
| 149 |
+
typedef enum {
|
| 150 |
+
NPY_QUICKSORT=0,
|
| 151 |
+
NPY_HEAPSORT=1,
|
| 152 |
+
NPY_MERGESORT=2,
|
| 153 |
+
NPY_STABLESORT=2,
|
| 154 |
+
} NPY_SORTKIND;
|
| 155 |
+
#define NPY_NSORTS (NPY_STABLESORT + 1)
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
typedef enum {
|
| 159 |
+
NPY_INTROSELECT=0
|
| 160 |
+
} NPY_SELECTKIND;
|
| 161 |
+
#define NPY_NSELECTS (NPY_INTROSELECT + 1)
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
typedef enum {
|
| 165 |
+
NPY_SEARCHLEFT=0,
|
| 166 |
+
NPY_SEARCHRIGHT=1
|
| 167 |
+
} NPY_SEARCHSIDE;
|
| 168 |
+
#define NPY_NSEARCHSIDES (NPY_SEARCHRIGHT + 1)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
typedef enum {
|
| 172 |
+
NPY_NOSCALAR=-1,
|
| 173 |
+
NPY_BOOL_SCALAR,
|
| 174 |
+
NPY_INTPOS_SCALAR,
|
| 175 |
+
NPY_INTNEG_SCALAR,
|
| 176 |
+
NPY_FLOAT_SCALAR,
|
| 177 |
+
NPY_COMPLEX_SCALAR,
|
| 178 |
+
NPY_OBJECT_SCALAR
|
| 179 |
+
} NPY_SCALARKIND;
|
| 180 |
+
#define NPY_NSCALARKINDS (NPY_OBJECT_SCALAR + 1)
|
| 181 |
+
|
| 182 |
+
/* For specifying array memory layout or iteration order */
|
| 183 |
+
typedef enum {
|
| 184 |
+
/* Fortran order if inputs are all Fortran, C otherwise */
|
| 185 |
+
NPY_ANYORDER=-1,
|
| 186 |
+
/* C order */
|
| 187 |
+
NPY_CORDER=0,
|
| 188 |
+
/* Fortran order */
|
| 189 |
+
NPY_FORTRANORDER=1,
|
| 190 |
+
/* An order as close to the inputs as possible */
|
| 191 |
+
NPY_KEEPORDER=2
|
| 192 |
+
} NPY_ORDER;
|
| 193 |
+
|
| 194 |
+
/* For specifying allowed casting in operations which support it */
|
| 195 |
+
typedef enum {
|
| 196 |
+
_NPY_ERROR_OCCURRED_IN_CAST = -1,
|
| 197 |
+
/* Only allow identical types */
|
| 198 |
+
NPY_NO_CASTING=0,
|
| 199 |
+
/* Allow identical and byte swapped types */
|
| 200 |
+
NPY_EQUIV_CASTING=1,
|
| 201 |
+
/* Only allow safe casts */
|
| 202 |
+
NPY_SAFE_CASTING=2,
|
| 203 |
+
/* Allow safe casts or casts within the same kind */
|
| 204 |
+
NPY_SAME_KIND_CASTING=3,
|
| 205 |
+
/* Allow any casts */
|
| 206 |
+
NPY_UNSAFE_CASTING=4,
|
| 207 |
+
} NPY_CASTING;
|
| 208 |
+
|
| 209 |
+
typedef enum {
|
| 210 |
+
NPY_CLIP=0,
|
| 211 |
+
NPY_WRAP=1,
|
| 212 |
+
NPY_RAISE=2
|
| 213 |
+
} NPY_CLIPMODE;
|
| 214 |
+
|
| 215 |
+
typedef enum {
|
| 216 |
+
NPY_VALID=0,
|
| 217 |
+
NPY_SAME=1,
|
| 218 |
+
NPY_FULL=2
|
| 219 |
+
} NPY_CORRELATEMODE;
|
| 220 |
+
|
| 221 |
+
/* The special not-a-time (NaT) value */
|
| 222 |
+
#define NPY_DATETIME_NAT NPY_MIN_INT64
|
| 223 |
+
|
| 224 |
+
/*
|
| 225 |
+
* Upper bound on the length of a DATETIME ISO 8601 string
|
| 226 |
+
* YEAR: 21 (64-bit year)
|
| 227 |
+
* MONTH: 3
|
| 228 |
+
* DAY: 3
|
| 229 |
+
* HOURS: 3
|
| 230 |
+
* MINUTES: 3
|
| 231 |
+
* SECONDS: 3
|
| 232 |
+
* ATTOSECONDS: 1 + 3*6
|
| 233 |
+
* TIMEZONE: 5
|
| 234 |
+
* NULL TERMINATOR: 1
|
| 235 |
+
*/
|
| 236 |
+
#define NPY_DATETIME_MAX_ISO8601_STRLEN (21 + 3*5 + 1 + 3*6 + 6 + 1)
|
| 237 |
+
|
| 238 |
+
/* The FR in the unit names stands for frequency */
|
| 239 |
+
typedef enum {
|
| 240 |
+
/* Force signed enum type, must be -1 for code compatibility */
|
| 241 |
+
NPY_FR_ERROR = -1, /* error or undetermined */
|
| 242 |
+
|
| 243 |
+
/* Start of valid units */
|
| 244 |
+
NPY_FR_Y = 0, /* Years */
|
| 245 |
+
NPY_FR_M = 1, /* Months */
|
| 246 |
+
NPY_FR_W = 2, /* Weeks */
|
| 247 |
+
/* Gap where 1.6 NPY_FR_B (value 3) was */
|
| 248 |
+
NPY_FR_D = 4, /* Days */
|
| 249 |
+
NPY_FR_h = 5, /* hours */
|
| 250 |
+
NPY_FR_m = 6, /* minutes */
|
| 251 |
+
NPY_FR_s = 7, /* seconds */
|
| 252 |
+
NPY_FR_ms = 8, /* milliseconds */
|
| 253 |
+
NPY_FR_us = 9, /* microseconds */
|
| 254 |
+
NPY_FR_ns = 10, /* nanoseconds */
|
| 255 |
+
NPY_FR_ps = 11, /* picoseconds */
|
| 256 |
+
NPY_FR_fs = 12, /* femtoseconds */
|
| 257 |
+
NPY_FR_as = 13, /* attoseconds */
|
| 258 |
+
NPY_FR_GENERIC = 14 /* unbound units, can convert to anything */
|
| 259 |
+
} NPY_DATETIMEUNIT;
|
| 260 |
+
|
| 261 |
+
/*
|
| 262 |
+
* NOTE: With the NPY_FR_B gap for 1.6 ABI compatibility, NPY_DATETIME_NUMUNITS
|
| 263 |
+
* is technically one more than the actual number of units.
|
| 264 |
+
*/
|
| 265 |
+
#define NPY_DATETIME_NUMUNITS (NPY_FR_GENERIC + 1)
|
| 266 |
+
#define NPY_DATETIME_DEFAULTUNIT NPY_FR_GENERIC
|
| 267 |
+
|
| 268 |
+
/*
|
| 269 |
+
* Business day conventions for mapping invalid business
|
| 270 |
+
* days to valid business days.
|
| 271 |
+
*/
|
| 272 |
+
typedef enum {
|
| 273 |
+
/* Go forward in time to the following business day. */
|
| 274 |
+
NPY_BUSDAY_FORWARD,
|
| 275 |
+
NPY_BUSDAY_FOLLOWING = NPY_BUSDAY_FORWARD,
|
| 276 |
+
/* Go backward in time to the preceding business day. */
|
| 277 |
+
NPY_BUSDAY_BACKWARD,
|
| 278 |
+
NPY_BUSDAY_PRECEDING = NPY_BUSDAY_BACKWARD,
|
| 279 |
+
/*
|
| 280 |
+
* Go forward in time to the following business day, unless it
|
| 281 |
+
* crosses a month boundary, in which case go backward
|
| 282 |
+
*/
|
| 283 |
+
NPY_BUSDAY_MODIFIEDFOLLOWING,
|
| 284 |
+
/*
|
| 285 |
+
* Go backward in time to the preceding business day, unless it
|
| 286 |
+
* crosses a month boundary, in which case go forward.
|
| 287 |
+
*/
|
| 288 |
+
NPY_BUSDAY_MODIFIEDPRECEDING,
|
| 289 |
+
/* Produce a NaT for non-business days. */
|
| 290 |
+
NPY_BUSDAY_NAT,
|
| 291 |
+
/* Raise an exception for non-business days. */
|
| 292 |
+
NPY_BUSDAY_RAISE
|
| 293 |
+
} NPY_BUSDAY_ROLL;
|
| 294 |
+
|
| 295 |
+
/************************************************************
|
| 296 |
+
* NumPy Auxiliary Data for inner loops, sort functions, etc.
|
| 297 |
+
************************************************************/
|
| 298 |
+
|
| 299 |
+
/*
|
| 300 |
+
* When creating an auxiliary data struct, this should always appear
|
| 301 |
+
* as the first member, like this:
|
| 302 |
+
*
|
| 303 |
+
* typedef struct {
|
| 304 |
+
* NpyAuxData base;
|
| 305 |
+
* double constant;
|
| 306 |
+
* } constant_multiplier_aux_data;
|
| 307 |
+
*/
|
| 308 |
+
typedef struct NpyAuxData_tag NpyAuxData;
|
| 309 |
+
|
| 310 |
+
/* Function pointers for freeing or cloning auxiliary data */
|
| 311 |
+
typedef void (NpyAuxData_FreeFunc) (NpyAuxData *);
|
| 312 |
+
typedef NpyAuxData *(NpyAuxData_CloneFunc) (NpyAuxData *);
|
| 313 |
+
|
| 314 |
+
struct NpyAuxData_tag {
|
| 315 |
+
NpyAuxData_FreeFunc *free;
|
| 316 |
+
NpyAuxData_CloneFunc *clone;
|
| 317 |
+
/* To allow for a bit of expansion without breaking the ABI */
|
| 318 |
+
void *reserved[2];
|
| 319 |
+
};
|
| 320 |
+
|
| 321 |
+
/* Macros to use for freeing and cloning auxiliary data */
|
| 322 |
+
#define NPY_AUXDATA_FREE(auxdata) \
|
| 323 |
+
do { \
|
| 324 |
+
if ((auxdata) != NULL) { \
|
| 325 |
+
(auxdata)->free(auxdata); \
|
| 326 |
+
} \
|
| 327 |
+
} while(0)
|
| 328 |
+
#define NPY_AUXDATA_CLONE(auxdata) \
|
| 329 |
+
((auxdata)->clone(auxdata))
|
| 330 |
+
|
| 331 |
+
#define NPY_ERR(str) fprintf(stderr, #str); fflush(stderr);
|
| 332 |
+
#define NPY_ERR2(str) fprintf(stderr, str); fflush(stderr);
|
| 333 |
+
|
| 334 |
+
/*
|
| 335 |
+
* Macros to define how array, and dimension/strides data is
|
| 336 |
+
* allocated. These should be made private
|
| 337 |
+
*/
|
| 338 |
+
|
| 339 |
+
#define NPY_USE_PYMEM 1
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
#if NPY_USE_PYMEM == 1
|
| 343 |
+
/* use the Raw versions which are safe to call with the GIL released */
|
| 344 |
+
#define PyArray_malloc PyMem_RawMalloc
|
| 345 |
+
#define PyArray_free PyMem_RawFree
|
| 346 |
+
#define PyArray_realloc PyMem_RawRealloc
|
| 347 |
+
#else
|
| 348 |
+
#define PyArray_malloc malloc
|
| 349 |
+
#define PyArray_free free
|
| 350 |
+
#define PyArray_realloc realloc
|
| 351 |
+
#endif
|
| 352 |
+
|
| 353 |
+
/* Dimensions and strides */
|
| 354 |
+
#define PyDimMem_NEW(size) \
|
| 355 |
+
((npy_intp *)PyArray_malloc(size*sizeof(npy_intp)))
|
| 356 |
+
|
| 357 |
+
#define PyDimMem_FREE(ptr) PyArray_free(ptr)
|
| 358 |
+
|
| 359 |
+
#define PyDimMem_RENEW(ptr,size) \
|
| 360 |
+
((npy_intp *)PyArray_realloc(ptr,size*sizeof(npy_intp)))
|
| 361 |
+
|
| 362 |
+
/* forward declaration */
|
| 363 |
+
struct _PyArray_Descr;
|
| 364 |
+
|
| 365 |
+
/* These must deal with unaligned and swapped data if necessary */
|
| 366 |
+
typedef PyObject * (PyArray_GetItemFunc) (void *, void *);
|
| 367 |
+
typedef int (PyArray_SetItemFunc)(PyObject *, void *, void *);
|
| 368 |
+
|
| 369 |
+
typedef void (PyArray_CopySwapNFunc)(void *, npy_intp, void *, npy_intp,
|
| 370 |
+
npy_intp, int, void *);
|
| 371 |
+
|
| 372 |
+
typedef void (PyArray_CopySwapFunc)(void *, void *, int, void *);
|
| 373 |
+
typedef npy_bool (PyArray_NonzeroFunc)(void *, void *);
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
/*
|
| 377 |
+
* These assume aligned and notswapped data -- a buffer will be used
|
| 378 |
+
* before or contiguous data will be obtained
|
| 379 |
+
*/
|
| 380 |
+
|
| 381 |
+
typedef int (PyArray_CompareFunc)(const void *, const void *, void *);
|
| 382 |
+
typedef int (PyArray_ArgFunc)(void*, npy_intp, npy_intp*, void *);
|
| 383 |
+
|
| 384 |
+
typedef void (PyArray_DotFunc)(void *, npy_intp, void *, npy_intp, void *,
|
| 385 |
+
npy_intp, void *);
|
| 386 |
+
|
| 387 |
+
typedef void (PyArray_VectorUnaryFunc)(void *, void *, npy_intp, void *,
|
| 388 |
+
void *);
|
| 389 |
+
|
| 390 |
+
/*
|
| 391 |
+
* XXX the ignore argument should be removed next time the API version
|
| 392 |
+
* is bumped. It used to be the separator.
|
| 393 |
+
*/
|
| 394 |
+
typedef int (PyArray_ScanFunc)(FILE *fp, void *dptr,
|
| 395 |
+
char *ignore, struct _PyArray_Descr *);
|
| 396 |
+
typedef int (PyArray_FromStrFunc)(char *s, void *dptr, char **endptr,
|
| 397 |
+
struct _PyArray_Descr *);
|
| 398 |
+
|
| 399 |
+
typedef int (PyArray_FillFunc)(void *, npy_intp, void *);
|
| 400 |
+
|
| 401 |
+
typedef int (PyArray_SortFunc)(void *, npy_intp, void *);
|
| 402 |
+
typedef int (PyArray_ArgSortFunc)(void *, npy_intp *, npy_intp, void *);
|
| 403 |
+
typedef int (PyArray_PartitionFunc)(void *, npy_intp, npy_intp,
|
| 404 |
+
npy_intp *, npy_intp *,
|
| 405 |
+
void *);
|
| 406 |
+
typedef int (PyArray_ArgPartitionFunc)(void *, npy_intp *, npy_intp, npy_intp,
|
| 407 |
+
npy_intp *, npy_intp *,
|
| 408 |
+
void *);
|
| 409 |
+
|
| 410 |
+
typedef int (PyArray_FillWithScalarFunc)(void *, npy_intp, void *, void *);
|
| 411 |
+
|
| 412 |
+
typedef int (PyArray_ScalarKindFunc)(void *);
|
| 413 |
+
|
| 414 |
+
typedef void (PyArray_FastClipFunc)(void *in, npy_intp n_in, void *min,
|
| 415 |
+
void *max, void *out);
|
| 416 |
+
typedef void (PyArray_FastPutmaskFunc)(void *in, void *mask, npy_intp n_in,
|
| 417 |
+
void *values, npy_intp nv);
|
| 418 |
+
typedef int (PyArray_FastTakeFunc)(void *dest, void *src, npy_intp *indarray,
|
| 419 |
+
npy_intp nindarray, npy_intp n_outer,
|
| 420 |
+
npy_intp m_middle, npy_intp nelem,
|
| 421 |
+
NPY_CLIPMODE clipmode);
|
| 422 |
+
|
| 423 |
+
typedef struct {
|
| 424 |
+
npy_intp *ptr;
|
| 425 |
+
int len;
|
| 426 |
+
} PyArray_Dims;
|
| 427 |
+
|
| 428 |
+
typedef struct {
|
| 429 |
+
/*
|
| 430 |
+
* Functions to cast to most other standard types
|
| 431 |
+
* Can have some NULL entries. The types
|
| 432 |
+
* DATETIME, TIMEDELTA, and HALF go into the castdict
|
| 433 |
+
* even though they are built-in.
|
| 434 |
+
*/
|
| 435 |
+
PyArray_VectorUnaryFunc *cast[NPY_NTYPES_ABI_COMPATIBLE];
|
| 436 |
+
|
| 437 |
+
/* The next four functions *cannot* be NULL */
|
| 438 |
+
|
| 439 |
+
/*
|
| 440 |
+
* Functions to get and set items with standard Python types
|
| 441 |
+
* -- not array scalars
|
| 442 |
+
*/
|
| 443 |
+
PyArray_GetItemFunc *getitem;
|
| 444 |
+
PyArray_SetItemFunc *setitem;
|
| 445 |
+
|
| 446 |
+
/*
|
| 447 |
+
* Copy and/or swap data. Memory areas may not overlap
|
| 448 |
+
* Use memmove first if they might
|
| 449 |
+
*/
|
| 450 |
+
PyArray_CopySwapNFunc *copyswapn;
|
| 451 |
+
PyArray_CopySwapFunc *copyswap;
|
| 452 |
+
|
| 453 |
+
/*
|
| 454 |
+
* Function to compare items
|
| 455 |
+
* Can be NULL
|
| 456 |
+
*/
|
| 457 |
+
PyArray_CompareFunc *compare;
|
| 458 |
+
|
| 459 |
+
/*
|
| 460 |
+
* Function to select largest
|
| 461 |
+
* Can be NULL
|
| 462 |
+
*/
|
| 463 |
+
PyArray_ArgFunc *argmax;
|
| 464 |
+
|
| 465 |
+
/*
|
| 466 |
+
* Function to compute dot product
|
| 467 |
+
* Can be NULL
|
| 468 |
+
*/
|
| 469 |
+
PyArray_DotFunc *dotfunc;
|
| 470 |
+
|
| 471 |
+
/*
|
| 472 |
+
* Function to scan an ASCII file and
|
| 473 |
+
* place a single value plus possible separator
|
| 474 |
+
* Can be NULL
|
| 475 |
+
*/
|
| 476 |
+
PyArray_ScanFunc *scanfunc;
|
| 477 |
+
|
| 478 |
+
/*
|
| 479 |
+
* Function to read a single value from a string
|
| 480 |
+
* and adjust the pointer; Can be NULL
|
| 481 |
+
*/
|
| 482 |
+
PyArray_FromStrFunc *fromstr;
|
| 483 |
+
|
| 484 |
+
/*
|
| 485 |
+
* Function to determine if data is zero or not
|
| 486 |
+
* If NULL a default version is
|
| 487 |
+
* used at Registration time.
|
| 488 |
+
*/
|
| 489 |
+
PyArray_NonzeroFunc *nonzero;
|
| 490 |
+
|
| 491 |
+
/*
|
| 492 |
+
* Used for arange. Should return 0 on success
|
| 493 |
+
* and -1 on failure.
|
| 494 |
+
* Can be NULL.
|
| 495 |
+
*/
|
| 496 |
+
PyArray_FillFunc *fill;
|
| 497 |
+
|
| 498 |
+
/*
|
| 499 |
+
* Function to fill arrays with scalar values
|
| 500 |
+
* Can be NULL
|
| 501 |
+
*/
|
| 502 |
+
PyArray_FillWithScalarFunc *fillwithscalar;
|
| 503 |
+
|
| 504 |
+
/*
|
| 505 |
+
* Sorting functions
|
| 506 |
+
* Can be NULL
|
| 507 |
+
*/
|
| 508 |
+
PyArray_SortFunc *sort[NPY_NSORTS];
|
| 509 |
+
PyArray_ArgSortFunc *argsort[NPY_NSORTS];
|
| 510 |
+
|
| 511 |
+
/*
|
| 512 |
+
* Dictionary of additional casting functions
|
| 513 |
+
* PyArray_VectorUnaryFuncs
|
| 514 |
+
* which can be populated to support casting
|
| 515 |
+
* to other registered types. Can be NULL
|
| 516 |
+
*/
|
| 517 |
+
PyObject *castdict;
|
| 518 |
+
|
| 519 |
+
/*
|
| 520 |
+
* Functions useful for generalizing
|
| 521 |
+
* the casting rules.
|
| 522 |
+
* Can be NULL;
|
| 523 |
+
*/
|
| 524 |
+
PyArray_ScalarKindFunc *scalarkind;
|
| 525 |
+
int **cancastscalarkindto;
|
| 526 |
+
int *cancastto;
|
| 527 |
+
|
| 528 |
+
PyArray_FastClipFunc *fastclip;
|
| 529 |
+
PyArray_FastPutmaskFunc *fastputmask;
|
| 530 |
+
PyArray_FastTakeFunc *fasttake;
|
| 531 |
+
|
| 532 |
+
/*
|
| 533 |
+
* Function to select smallest
|
| 534 |
+
* Can be NULL
|
| 535 |
+
*/
|
| 536 |
+
PyArray_ArgFunc *argmin;
|
| 537 |
+
|
| 538 |
+
} PyArray_ArrFuncs;
|
| 539 |
+
|
| 540 |
+
/* The item must be reference counted when it is inserted or extracted. */
|
| 541 |
+
#define NPY_ITEM_REFCOUNT 0x01
|
| 542 |
+
/* Same as needing REFCOUNT */
|
| 543 |
+
#define NPY_ITEM_HASOBJECT 0x01
|
| 544 |
+
/* Convert to list for pickling */
|
| 545 |
+
#define NPY_LIST_PICKLE 0x02
|
| 546 |
+
/* The item is a POINTER */
|
| 547 |
+
#define NPY_ITEM_IS_POINTER 0x04
|
| 548 |
+
/* memory needs to be initialized for this data-type */
|
| 549 |
+
#define NPY_NEEDS_INIT 0x08
|
| 550 |
+
/* operations need Python C-API so don't give-up thread. */
|
| 551 |
+
#define NPY_NEEDS_PYAPI 0x10
|
| 552 |
+
/* Use f.getitem when extracting elements of this data-type */
|
| 553 |
+
#define NPY_USE_GETITEM 0x20
|
| 554 |
+
/* Use f.setitem when setting creating 0-d array from this data-type.*/
|
| 555 |
+
#define NPY_USE_SETITEM 0x40
|
| 556 |
+
/* A sticky flag specifically for structured arrays */
|
| 557 |
+
#define NPY_ALIGNED_STRUCT 0x80
|
| 558 |
+
|
| 559 |
+
/*
|
| 560 |
+
*These are inherited for global data-type if any data-types in the
|
| 561 |
+
* field have them
|
| 562 |
+
*/
|
| 563 |
+
#define NPY_FROM_FIELDS (NPY_NEEDS_INIT | NPY_LIST_PICKLE | \
|
| 564 |
+
NPY_ITEM_REFCOUNT | NPY_NEEDS_PYAPI)
|
| 565 |
+
|
| 566 |
+
#define NPY_OBJECT_DTYPE_FLAGS (NPY_LIST_PICKLE | NPY_USE_GETITEM | \
|
| 567 |
+
NPY_ITEM_IS_POINTER | NPY_ITEM_REFCOUNT | \
|
| 568 |
+
NPY_NEEDS_INIT | NPY_NEEDS_PYAPI)
|
| 569 |
+
|
| 570 |
+
#define PyDataType_FLAGCHK(dtype, flag) \
|
| 571 |
+
(((dtype)->flags & (flag)) == (flag))
|
| 572 |
+
|
| 573 |
+
#define PyDataType_REFCHK(dtype) \
|
| 574 |
+
PyDataType_FLAGCHK(dtype, NPY_ITEM_REFCOUNT)
|
| 575 |
+
|
| 576 |
+
typedef struct _PyArray_Descr {
|
| 577 |
+
PyObject_HEAD
|
| 578 |
+
/*
|
| 579 |
+
* the type object representing an
|
| 580 |
+
* instance of this type -- should not
|
| 581 |
+
* be two type_numbers with the same type
|
| 582 |
+
* object.
|
| 583 |
+
*/
|
| 584 |
+
PyTypeObject *typeobj;
|
| 585 |
+
/* kind for this type */
|
| 586 |
+
char kind;
|
| 587 |
+
/* unique-character representing this type */
|
| 588 |
+
char type;
|
| 589 |
+
/*
|
| 590 |
+
* '>' (big), '<' (little), '|'
|
| 591 |
+
* (not-applicable), or '=' (native).
|
| 592 |
+
*/
|
| 593 |
+
char byteorder;
|
| 594 |
+
/* flags describing data type */
|
| 595 |
+
char flags;
|
| 596 |
+
/* number representing this type */
|
| 597 |
+
int type_num;
|
| 598 |
+
/* element size (itemsize) for this type */
|
| 599 |
+
int elsize;
|
| 600 |
+
/* alignment needed for this type */
|
| 601 |
+
int alignment;
|
| 602 |
+
/*
|
| 603 |
+
* Non-NULL if this type is
|
| 604 |
+
* is an array (C-contiguous)
|
| 605 |
+
* of some other type
|
| 606 |
+
*/
|
| 607 |
+
struct _arr_descr *subarray;
|
| 608 |
+
/*
|
| 609 |
+
* The fields dictionary for this type
|
| 610 |
+
* For statically defined descr this
|
| 611 |
+
* is always Py_None
|
| 612 |
+
*/
|
| 613 |
+
PyObject *fields;
|
| 614 |
+
/*
|
| 615 |
+
* An ordered tuple of field names or NULL
|
| 616 |
+
* if no fields are defined
|
| 617 |
+
*/
|
| 618 |
+
PyObject *names;
|
| 619 |
+
/*
|
| 620 |
+
* a table of functions specific for each
|
| 621 |
+
* basic data descriptor
|
| 622 |
+
*/
|
| 623 |
+
PyArray_ArrFuncs *f;
|
| 624 |
+
/* Metadata about this dtype */
|
| 625 |
+
PyObject *metadata;
|
| 626 |
+
/*
|
| 627 |
+
* Metadata specific to the C implementation
|
| 628 |
+
* of the particular dtype. This was added
|
| 629 |
+
* for NumPy 1.7.0.
|
| 630 |
+
*/
|
| 631 |
+
NpyAuxData *c_metadata;
|
| 632 |
+
/* Cached hash value (-1 if not yet computed).
|
| 633 |
+
* This was added for NumPy 2.0.0.
|
| 634 |
+
*/
|
| 635 |
+
npy_hash_t hash;
|
| 636 |
+
} PyArray_Descr;
|
| 637 |
+
|
| 638 |
+
typedef struct _arr_descr {
|
| 639 |
+
PyArray_Descr *base;
|
| 640 |
+
PyObject *shape; /* a tuple */
|
| 641 |
+
} PyArray_ArrayDescr;
|
| 642 |
+
|
| 643 |
+
/*
|
| 644 |
+
* Memory handler structure for array data.
|
| 645 |
+
*/
|
| 646 |
+
/* The declaration of free differs from PyMemAllocatorEx */
|
| 647 |
+
typedef struct {
|
| 648 |
+
void *ctx;
|
| 649 |
+
void* (*malloc) (void *ctx, size_t size);
|
| 650 |
+
void* (*calloc) (void *ctx, size_t nelem, size_t elsize);
|
| 651 |
+
void* (*realloc) (void *ctx, void *ptr, size_t new_size);
|
| 652 |
+
void (*free) (void *ctx, void *ptr, size_t size);
|
| 653 |
+
/*
|
| 654 |
+
* This is the end of the version=1 struct. Only add new fields after
|
| 655 |
+
* this line
|
| 656 |
+
*/
|
| 657 |
+
} PyDataMemAllocator;
|
| 658 |
+
|
| 659 |
+
typedef struct {
|
| 660 |
+
char name[127]; /* multiple of 64 to keep the struct aligned */
|
| 661 |
+
uint8_t version; /* currently 1 */
|
| 662 |
+
PyDataMemAllocator allocator;
|
| 663 |
+
} PyDataMem_Handler;
|
| 664 |
+
|
| 665 |
+
|
| 666 |
+
/*
|
| 667 |
+
* The main array object structure.
|
| 668 |
+
*
|
| 669 |
+
* It has been recommended to use the inline functions defined below
|
| 670 |
+
* (PyArray_DATA and friends) to access fields here for a number of
|
| 671 |
+
* releases. Direct access to the members themselves is deprecated.
|
| 672 |
+
* To ensure that your code does not use deprecated access,
|
| 673 |
+
* #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
|
| 674 |
+
* (or NPY_1_8_API_VERSION or higher as required).
|
| 675 |
+
*/
|
| 676 |
+
/* This struct will be moved to a private header in a future release */
|
| 677 |
+
typedef struct tagPyArrayObject_fields {
|
| 678 |
+
PyObject_HEAD
|
| 679 |
+
/* Pointer to the raw data buffer */
|
| 680 |
+
char *data;
|
| 681 |
+
/* The number of dimensions, also called 'ndim' */
|
| 682 |
+
int nd;
|
| 683 |
+
/* The size in each dimension, also called 'shape' */
|
| 684 |
+
npy_intp *dimensions;
|
| 685 |
+
/*
|
| 686 |
+
* Number of bytes to jump to get to the
|
| 687 |
+
* next element in each dimension
|
| 688 |
+
*/
|
| 689 |
+
npy_intp *strides;
|
| 690 |
+
/*
|
| 691 |
+
* This object is decref'd upon
|
| 692 |
+
* deletion of array. Except in the
|
| 693 |
+
* case of WRITEBACKIFCOPY which has
|
| 694 |
+
* special handling.
|
| 695 |
+
*
|
| 696 |
+
* For views it points to the original
|
| 697 |
+
* array, collapsed so no chains of
|
| 698 |
+
* views occur.
|
| 699 |
+
*
|
| 700 |
+
* For creation from buffer object it
|
| 701 |
+
* points to an object that should be
|
| 702 |
+
* decref'd on deletion
|
| 703 |
+
*
|
| 704 |
+
* For WRITEBACKIFCOPY flag this is an
|
| 705 |
+
* array to-be-updated upon calling
|
| 706 |
+
* PyArray_ResolveWritebackIfCopy
|
| 707 |
+
*/
|
| 708 |
+
PyObject *base;
|
| 709 |
+
/* Pointer to type structure */
|
| 710 |
+
PyArray_Descr *descr;
|
| 711 |
+
/* Flags describing array -- see below */
|
| 712 |
+
int flags;
|
| 713 |
+
/* For weak references */
|
| 714 |
+
PyObject *weakreflist;
|
| 715 |
+
#if NPY_FEATURE_VERSION >= NPY_1_20_API_VERSION
|
| 716 |
+
void *_buffer_info; /* private buffer info, tagged to allow warning */
|
| 717 |
+
#endif
|
| 718 |
+
/*
|
| 719 |
+
* For malloc/calloc/realloc/free per object
|
| 720 |
+
*/
|
| 721 |
+
#if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
|
| 722 |
+
PyObject *mem_handler;
|
| 723 |
+
#endif
|
| 724 |
+
} PyArrayObject_fields;
|
| 725 |
+
|
| 726 |
+
/*
|
| 727 |
+
* To hide the implementation details, we only expose
|
| 728 |
+
* the Python struct HEAD.
|
| 729 |
+
*/
|
| 730 |
+
#if !defined(NPY_NO_DEPRECATED_API) || \
|
| 731 |
+
(NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION)
|
| 732 |
+
/*
|
| 733 |
+
* Can't put this in npy_deprecated_api.h like the others.
|
| 734 |
+
* PyArrayObject field access is deprecated as of NumPy 1.7.
|
| 735 |
+
*/
|
| 736 |
+
typedef PyArrayObject_fields PyArrayObject;
|
| 737 |
+
#else
|
| 738 |
+
typedef struct tagPyArrayObject {
|
| 739 |
+
PyObject_HEAD
|
| 740 |
+
} PyArrayObject;
|
| 741 |
+
#endif
|
| 742 |
+
|
| 743 |
+
/*
|
| 744 |
+
* Removed 2020-Nov-25, NumPy 1.20
|
| 745 |
+
* #define NPY_SIZEOF_PYARRAYOBJECT (sizeof(PyArrayObject_fields))
|
| 746 |
+
*
|
| 747 |
+
* The above macro was removed as it gave a false sense of a stable ABI
|
| 748 |
+
* with respect to the structures size. If you require a runtime constant,
|
| 749 |
+
* you can use `PyArray_Type.tp_basicsize` instead. Otherwise, please
|
| 750 |
+
* see the PyArrayObject documentation or ask the NumPy developers for
|
| 751 |
+
* information on how to correctly replace the macro in a way that is
|
| 752 |
+
* compatible with multiple NumPy versions.
|
| 753 |
+
*/
|
| 754 |
+
|
| 755 |
+
|
| 756 |
+
/* Array Flags Object */
|
| 757 |
+
typedef struct PyArrayFlagsObject {
|
| 758 |
+
PyObject_HEAD
|
| 759 |
+
PyObject *arr;
|
| 760 |
+
int flags;
|
| 761 |
+
} PyArrayFlagsObject;
|
| 762 |
+
|
| 763 |
+
/* Mirrors buffer object to ptr */
|
| 764 |
+
|
| 765 |
+
typedef struct {
|
| 766 |
+
PyObject_HEAD
|
| 767 |
+
PyObject *base;
|
| 768 |
+
void *ptr;
|
| 769 |
+
npy_intp len;
|
| 770 |
+
int flags;
|
| 771 |
+
} PyArray_Chunk;
|
| 772 |
+
|
| 773 |
+
typedef struct {
|
| 774 |
+
NPY_DATETIMEUNIT base;
|
| 775 |
+
int num;
|
| 776 |
+
} PyArray_DatetimeMetaData;
|
| 777 |
+
|
| 778 |
+
typedef struct {
|
| 779 |
+
NpyAuxData base;
|
| 780 |
+
PyArray_DatetimeMetaData meta;
|
| 781 |
+
} PyArray_DatetimeDTypeMetaData;
|
| 782 |
+
|
| 783 |
+
/*
|
| 784 |
+
* This structure contains an exploded view of a date-time value.
|
| 785 |
+
* NaT is represented by year == NPY_DATETIME_NAT.
|
| 786 |
+
*/
|
| 787 |
+
typedef struct {
|
| 788 |
+
npy_int64 year;
|
| 789 |
+
npy_int32 month, day, hour, min, sec, us, ps, as;
|
| 790 |
+
} npy_datetimestruct;
|
| 791 |
+
|
| 792 |
+
/* This is not used internally. */
|
| 793 |
+
typedef struct {
|
| 794 |
+
npy_int64 day;
|
| 795 |
+
npy_int32 sec, us, ps, as;
|
| 796 |
+
} npy_timedeltastruct;
|
| 797 |
+
|
| 798 |
+
typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
|
| 799 |
+
|
| 800 |
+
/*
|
| 801 |
+
* Means c-style contiguous (last index varies the fastest). The data
|
| 802 |
+
* elements right after each other.
|
| 803 |
+
*
|
| 804 |
+
* This flag may be requested in constructor functions.
|
| 805 |
+
* This flag may be tested for in PyArray_FLAGS(arr).
|
| 806 |
+
*/
|
| 807 |
+
#define NPY_ARRAY_C_CONTIGUOUS 0x0001
|
| 808 |
+
|
| 809 |
+
/*
|
| 810 |
+
* Set if array is a contiguous Fortran array: the first index varies
|
| 811 |
+
* the fastest in memory (strides array is reverse of C-contiguous
|
| 812 |
+
* array)
|
| 813 |
+
*
|
| 814 |
+
* This flag may be requested in constructor functions.
|
| 815 |
+
* This flag may be tested for in PyArray_FLAGS(arr).
|
| 816 |
+
*/
|
| 817 |
+
#define NPY_ARRAY_F_CONTIGUOUS 0x0002
|
| 818 |
+
|
| 819 |
+
/*
|
| 820 |
+
* Note: all 0-d arrays are C_CONTIGUOUS and F_CONTIGUOUS. If a
|
| 821 |
+
* 1-d array is C_CONTIGUOUS it is also F_CONTIGUOUS. Arrays with
|
| 822 |
+
* more then one dimension can be C_CONTIGUOUS and F_CONTIGUOUS
|
| 823 |
+
* at the same time if they have either zero or one element.
|
| 824 |
+
* A higher dimensional array always has the same contiguity flags as
|
| 825 |
+
* `array.squeeze()`; dimensions with `array.shape[dimension] == 1` are
|
| 826 |
+
* effectively ignored when checking for contiguity.
|
| 827 |
+
*/
|
| 828 |
+
|
| 829 |
+
/*
|
| 830 |
+
* If set, the array owns the data: it will be free'd when the array
|
| 831 |
+
* is deleted.
|
| 832 |
+
*
|
| 833 |
+
* This flag may be tested for in PyArray_FLAGS(arr).
|
| 834 |
+
*/
|
| 835 |
+
#define NPY_ARRAY_OWNDATA 0x0004
|
| 836 |
+
|
| 837 |
+
/*
|
| 838 |
+
* An array never has the next four set; they're only used as parameter
|
| 839 |
+
* flags to the various FromAny functions
|
| 840 |
+
*
|
| 841 |
+
* This flag may be requested in constructor functions.
|
| 842 |
+
*/
|
| 843 |
+
|
| 844 |
+
/* Cause a cast to occur regardless of whether or not it is safe. */
|
| 845 |
+
#define NPY_ARRAY_FORCECAST 0x0010
|
| 846 |
+
|
| 847 |
+
/*
|
| 848 |
+
* Always copy the array. Returned arrays are always CONTIGUOUS,
|
| 849 |
+
* ALIGNED, and WRITEABLE. See also: NPY_ARRAY_ENSURENOCOPY = 0x4000.
|
| 850 |
+
*
|
| 851 |
+
* This flag may be requested in constructor functions.
|
| 852 |
+
*/
|
| 853 |
+
#define NPY_ARRAY_ENSURECOPY 0x0020
|
| 854 |
+
|
| 855 |
+
/*
|
| 856 |
+
* Make sure the returned array is a base-class ndarray
|
| 857 |
+
*
|
| 858 |
+
* This flag may be requested in constructor functions.
|
| 859 |
+
*/
|
| 860 |
+
#define NPY_ARRAY_ENSUREARRAY 0x0040
|
| 861 |
+
|
| 862 |
+
/*
|
| 863 |
+
* Make sure that the strides are in units of the element size Needed
|
| 864 |
+
* for some operations with record-arrays.
|
| 865 |
+
*
|
| 866 |
+
* This flag may be requested in constructor functions.
|
| 867 |
+
*/
|
| 868 |
+
#define NPY_ARRAY_ELEMENTSTRIDES 0x0080
|
| 869 |
+
|
| 870 |
+
/*
|
| 871 |
+
* Array data is aligned on the appropriate memory address for the type
|
| 872 |
+
* stored according to how the compiler would align things (e.g., an
|
| 873 |
+
* array of integers (4 bytes each) starts on a memory address that's
|
| 874 |
+
* a multiple of 4)
|
| 875 |
+
*
|
| 876 |
+
* This flag may be requested in constructor functions.
|
| 877 |
+
* This flag may be tested for in PyArray_FLAGS(arr).
|
| 878 |
+
*/
|
| 879 |
+
#define NPY_ARRAY_ALIGNED 0x0100
|
| 880 |
+
|
| 881 |
+
/*
|
| 882 |
+
* Array data has the native endianness
|
| 883 |
+
*
|
| 884 |
+
* This flag may be requested in constructor functions.
|
| 885 |
+
*/
|
| 886 |
+
#define NPY_ARRAY_NOTSWAPPED 0x0200
|
| 887 |
+
|
| 888 |
+
/*
|
| 889 |
+
* Array data is writeable
|
| 890 |
+
*
|
| 891 |
+
* This flag may be requested in constructor functions.
|
| 892 |
+
* This flag may be tested for in PyArray_FLAGS(arr).
|
| 893 |
+
*/
|
| 894 |
+
#define NPY_ARRAY_WRITEABLE 0x0400
|
| 895 |
+
|
| 896 |
+
/*
|
| 897 |
+
* If this flag is set, then base contains a pointer to an array of
|
| 898 |
+
* the same size that should be updated with the current contents of
|
| 899 |
+
* this array when PyArray_ResolveWritebackIfCopy is called.
|
| 900 |
+
*
|
| 901 |
+
* This flag may be requested in constructor functions.
|
| 902 |
+
* This flag may be tested for in PyArray_FLAGS(arr).
|
| 903 |
+
*/
|
| 904 |
+
#define NPY_ARRAY_WRITEBACKIFCOPY 0x2000
|
| 905 |
+
|
| 906 |
+
/*
|
| 907 |
+
* No copy may be made while converting from an object/array (result is a view)
|
| 908 |
+
*
|
| 909 |
+
* This flag may be requested in constructor functions.
|
| 910 |
+
*/
|
| 911 |
+
#define NPY_ARRAY_ENSURENOCOPY 0x4000
|
| 912 |
+
|
| 913 |
+
/*
|
| 914 |
+
* NOTE: there are also internal flags defined in multiarray/arrayobject.h,
|
| 915 |
+
* which start at bit 31 and work down.
|
| 916 |
+
*/
|
| 917 |
+
|
| 918 |
+
#define NPY_ARRAY_BEHAVED (NPY_ARRAY_ALIGNED | \
|
| 919 |
+
NPY_ARRAY_WRITEABLE)
|
| 920 |
+
#define NPY_ARRAY_BEHAVED_NS (NPY_ARRAY_ALIGNED | \
|
| 921 |
+
NPY_ARRAY_WRITEABLE | \
|
| 922 |
+
NPY_ARRAY_NOTSWAPPED)
|
| 923 |
+
#define NPY_ARRAY_CARRAY (NPY_ARRAY_C_CONTIGUOUS | \
|
| 924 |
+
NPY_ARRAY_BEHAVED)
|
| 925 |
+
#define NPY_ARRAY_CARRAY_RO (NPY_ARRAY_C_CONTIGUOUS | \
|
| 926 |
+
NPY_ARRAY_ALIGNED)
|
| 927 |
+
#define NPY_ARRAY_FARRAY (NPY_ARRAY_F_CONTIGUOUS | \
|
| 928 |
+
NPY_ARRAY_BEHAVED)
|
| 929 |
+
#define NPY_ARRAY_FARRAY_RO (NPY_ARRAY_F_CONTIGUOUS | \
|
| 930 |
+
NPY_ARRAY_ALIGNED)
|
| 931 |
+
#define NPY_ARRAY_DEFAULT (NPY_ARRAY_CARRAY)
|
| 932 |
+
#define NPY_ARRAY_IN_ARRAY (NPY_ARRAY_CARRAY_RO)
|
| 933 |
+
#define NPY_ARRAY_OUT_ARRAY (NPY_ARRAY_CARRAY)
|
| 934 |
+
#define NPY_ARRAY_INOUT_ARRAY (NPY_ARRAY_CARRAY)
|
| 935 |
+
#define NPY_ARRAY_INOUT_ARRAY2 (NPY_ARRAY_CARRAY | \
|
| 936 |
+
NPY_ARRAY_WRITEBACKIFCOPY)
|
| 937 |
+
#define NPY_ARRAY_IN_FARRAY (NPY_ARRAY_FARRAY_RO)
|
| 938 |
+
#define NPY_ARRAY_OUT_FARRAY (NPY_ARRAY_FARRAY)
|
| 939 |
+
#define NPY_ARRAY_INOUT_FARRAY (NPY_ARRAY_FARRAY)
|
| 940 |
+
#define NPY_ARRAY_INOUT_FARRAY2 (NPY_ARRAY_FARRAY | \
|
| 941 |
+
NPY_ARRAY_WRITEBACKIFCOPY)
|
| 942 |
+
|
| 943 |
+
#define NPY_ARRAY_UPDATE_ALL (NPY_ARRAY_C_CONTIGUOUS | \
|
| 944 |
+
NPY_ARRAY_F_CONTIGUOUS | \
|
| 945 |
+
NPY_ARRAY_ALIGNED)
|
| 946 |
+
|
| 947 |
+
/* This flag is for the array interface, not PyArrayObject */
|
| 948 |
+
#define NPY_ARR_HAS_DESCR 0x0800
|
| 949 |
+
|
| 950 |
+
|
| 951 |
+
|
| 952 |
+
|
| 953 |
+
/*
|
| 954 |
+
* Size of internal buffers used for alignment Make BUFSIZE a multiple
|
| 955 |
+
* of sizeof(npy_cdouble) -- usually 16 so that ufunc buffers are aligned
|
| 956 |
+
*/
|
| 957 |
+
#define NPY_MIN_BUFSIZE ((int)sizeof(npy_cdouble))
|
| 958 |
+
#define NPY_MAX_BUFSIZE (((int)sizeof(npy_cdouble))*1000000)
|
| 959 |
+
#define NPY_BUFSIZE 8192
|
| 960 |
+
/* buffer stress test size: */
|
| 961 |
+
/*#define NPY_BUFSIZE 17*/
|
| 962 |
+
|
| 963 |
+
#define PyArray_MAX(a,b) (((a)>(b))?(a):(b))
|
| 964 |
+
#define PyArray_MIN(a,b) (((a)<(b))?(a):(b))
|
| 965 |
+
#define PyArray_CLT(p,q) ((((p).real==(q).real) ? ((p).imag < (q).imag) : \
|
| 966 |
+
((p).real < (q).real)))
|
| 967 |
+
#define PyArray_CGT(p,q) ((((p).real==(q).real) ? ((p).imag > (q).imag) : \
|
| 968 |
+
((p).real > (q).real)))
|
| 969 |
+
#define PyArray_CLE(p,q) ((((p).real==(q).real) ? ((p).imag <= (q).imag) : \
|
| 970 |
+
((p).real <= (q).real)))
|
| 971 |
+
#define PyArray_CGE(p,q) ((((p).real==(q).real) ? ((p).imag >= (q).imag) : \
|
| 972 |
+
((p).real >= (q).real)))
|
| 973 |
+
#define PyArray_CEQ(p,q) (((p).real==(q).real) && ((p).imag == (q).imag))
|
| 974 |
+
#define PyArray_CNE(p,q) (((p).real!=(q).real) || ((p).imag != (q).imag))
|
| 975 |
+
|
| 976 |
+
/*
|
| 977 |
+
* C API: consists of Macros and functions. The MACROS are defined
|
| 978 |
+
* here.
|
| 979 |
+
*/
|
| 980 |
+
|
| 981 |
+
|
| 982 |
+
#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS((m), NPY_ARRAY_C_CONTIGUOUS)
|
| 983 |
+
#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS((m), NPY_ARRAY_WRITEABLE)
|
| 984 |
+
#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS((m), NPY_ARRAY_ALIGNED)
|
| 985 |
+
|
| 986 |
+
#define PyArray_IS_C_CONTIGUOUS(m) PyArray_CHKFLAGS((m), NPY_ARRAY_C_CONTIGUOUS)
|
| 987 |
+
#define PyArray_IS_F_CONTIGUOUS(m) PyArray_CHKFLAGS((m), NPY_ARRAY_F_CONTIGUOUS)
|
| 988 |
+
|
| 989 |
+
/* the variable is used in some places, so always define it */
|
| 990 |
+
#define NPY_BEGIN_THREADS_DEF PyThreadState *_save=NULL;
|
| 991 |
+
#if NPY_ALLOW_THREADS
|
| 992 |
+
#define NPY_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
|
| 993 |
+
#define NPY_END_ALLOW_THREADS Py_END_ALLOW_THREADS
|
| 994 |
+
#define NPY_BEGIN_THREADS do {_save = PyEval_SaveThread();} while (0);
|
| 995 |
+
#define NPY_END_THREADS do { if (_save) \
|
| 996 |
+
{ PyEval_RestoreThread(_save); _save = NULL;} } while (0);
|
| 997 |
+
#define NPY_BEGIN_THREADS_THRESHOLDED(loop_size) do { if ((loop_size) > 500) \
|
| 998 |
+
{ _save = PyEval_SaveThread();} } while (0);
|
| 999 |
+
|
| 1000 |
+
#define NPY_BEGIN_THREADS_DESCR(dtype) \
|
| 1001 |
+
do {if (!(PyDataType_FLAGCHK((dtype), NPY_NEEDS_PYAPI))) \
|
| 1002 |
+
NPY_BEGIN_THREADS;} while (0);
|
| 1003 |
+
|
| 1004 |
+
#define NPY_END_THREADS_DESCR(dtype) \
|
| 1005 |
+
do {if (!(PyDataType_FLAGCHK((dtype), NPY_NEEDS_PYAPI))) \
|
| 1006 |
+
NPY_END_THREADS; } while (0);
|
| 1007 |
+
|
| 1008 |
+
#define NPY_ALLOW_C_API_DEF PyGILState_STATE __save__;
|
| 1009 |
+
#define NPY_ALLOW_C_API do {__save__ = PyGILState_Ensure();} while (0);
|
| 1010 |
+
#define NPY_DISABLE_C_API do {PyGILState_Release(__save__);} while (0);
|
| 1011 |
+
#else
|
| 1012 |
+
#define NPY_BEGIN_ALLOW_THREADS
|
| 1013 |
+
#define NPY_END_ALLOW_THREADS
|
| 1014 |
+
#define NPY_BEGIN_THREADS
|
| 1015 |
+
#define NPY_END_THREADS
|
| 1016 |
+
#define NPY_BEGIN_THREADS_THRESHOLDED(loop_size)
|
| 1017 |
+
#define NPY_BEGIN_THREADS_DESCR(dtype)
|
| 1018 |
+
#define NPY_END_THREADS_DESCR(dtype)
|
| 1019 |
+
#define NPY_ALLOW_C_API_DEF
|
| 1020 |
+
#define NPY_ALLOW_C_API
|
| 1021 |
+
#define NPY_DISABLE_C_API
|
| 1022 |
+
#endif
|
| 1023 |
+
|
| 1024 |
+
/**********************************
|
| 1025 |
+
* The nditer object, added in 1.6
|
| 1026 |
+
**********************************/
|
| 1027 |
+
|
| 1028 |
+
/* The actual structure of the iterator is an internal detail */
|
| 1029 |
+
typedef struct NpyIter_InternalOnly NpyIter;
|
| 1030 |
+
|
| 1031 |
+
/* Iterator function pointers that may be specialized */
|
| 1032 |
+
typedef int (NpyIter_IterNextFunc)(NpyIter *iter);
|
| 1033 |
+
typedef void (NpyIter_GetMultiIndexFunc)(NpyIter *iter,
|
| 1034 |
+
npy_intp *outcoords);
|
| 1035 |
+
|
| 1036 |
+
/*** Global flags that may be passed to the iterator constructors ***/
|
| 1037 |
+
|
| 1038 |
+
/* Track an index representing C order */
|
| 1039 |
+
#define NPY_ITER_C_INDEX 0x00000001
|
| 1040 |
+
/* Track an index representing Fortran order */
|
| 1041 |
+
#define NPY_ITER_F_INDEX 0x00000002
|
| 1042 |
+
/* Track a multi-index */
|
| 1043 |
+
#define NPY_ITER_MULTI_INDEX 0x00000004
|
| 1044 |
+
/* User code external to the iterator does the 1-dimensional innermost loop */
|
| 1045 |
+
#define NPY_ITER_EXTERNAL_LOOP 0x00000008
|
| 1046 |
+
/* Convert all the operands to a common data type */
|
| 1047 |
+
#define NPY_ITER_COMMON_DTYPE 0x00000010
|
| 1048 |
+
/* Operands may hold references, requiring API access during iteration */
|
| 1049 |
+
#define NPY_ITER_REFS_OK 0x00000020
|
| 1050 |
+
/* Zero-sized operands should be permitted, iteration checks IterSize for 0 */
|
| 1051 |
+
#define NPY_ITER_ZEROSIZE_OK 0x00000040
|
| 1052 |
+
/* Permits reductions (size-0 stride with dimension size > 1) */
|
| 1053 |
+
#define NPY_ITER_REDUCE_OK 0x00000080
|
| 1054 |
+
/* Enables sub-range iteration */
|
| 1055 |
+
#define NPY_ITER_RANGED 0x00000100
|
| 1056 |
+
/* Enables buffering */
|
| 1057 |
+
#define NPY_ITER_BUFFERED 0x00000200
|
| 1058 |
+
/* When buffering is enabled, grows the inner loop if possible */
|
| 1059 |
+
#define NPY_ITER_GROWINNER 0x00000400
|
| 1060 |
+
/* Delay allocation of buffers until first Reset* call */
|
| 1061 |
+
#define NPY_ITER_DELAY_BUFALLOC 0x00000800
|
| 1062 |
+
/* When NPY_KEEPORDER is specified, disable reversing negative-stride axes */
|
| 1063 |
+
#define NPY_ITER_DONT_NEGATE_STRIDES 0x00001000
|
| 1064 |
+
/*
|
| 1065 |
+
* If output operands overlap with other operands (based on heuristics that
|
| 1066 |
+
* has false positives but no false negatives), make temporary copies to
|
| 1067 |
+
* eliminate overlap.
|
| 1068 |
+
*/
|
| 1069 |
+
#define NPY_ITER_COPY_IF_OVERLAP 0x00002000
|
| 1070 |
+
|
| 1071 |
+
/*** Per-operand flags that may be passed to the iterator constructors ***/
|
| 1072 |
+
|
| 1073 |
+
/* The operand will be read from and written to */
|
| 1074 |
+
#define NPY_ITER_READWRITE 0x00010000
|
| 1075 |
+
/* The operand will only be read from */
|
| 1076 |
+
#define NPY_ITER_READONLY 0x00020000
|
| 1077 |
+
/* The operand will only be written to */
|
| 1078 |
+
#define NPY_ITER_WRITEONLY 0x00040000
|
| 1079 |
+
/* The operand's data must be in native byte order */
|
| 1080 |
+
#define NPY_ITER_NBO 0x00080000
|
| 1081 |
+
/* The operand's data must be aligned */
|
| 1082 |
+
#define NPY_ITER_ALIGNED 0x00100000
|
| 1083 |
+
/* The operand's data must be contiguous (within the inner loop) */
|
| 1084 |
+
#define NPY_ITER_CONTIG 0x00200000
|
| 1085 |
+
/* The operand may be copied to satisfy requirements */
|
| 1086 |
+
#define NPY_ITER_COPY 0x00400000
|
| 1087 |
+
/* The operand may be copied with WRITEBACKIFCOPY to satisfy requirements */
|
| 1088 |
+
#define NPY_ITER_UPDATEIFCOPY 0x00800000
|
| 1089 |
+
/* Allocate the operand if it is NULL */
|
| 1090 |
+
#define NPY_ITER_ALLOCATE 0x01000000
|
| 1091 |
+
/* If an operand is allocated, don't use any subtype */
|
| 1092 |
+
#define NPY_ITER_NO_SUBTYPE 0x02000000
|
| 1093 |
+
/* This is a virtual array slot, operand is NULL but temporary data is there */
|
| 1094 |
+
#define NPY_ITER_VIRTUAL 0x04000000
|
| 1095 |
+
/* Require that the dimension match the iterator dimensions exactly */
|
| 1096 |
+
#define NPY_ITER_NO_BROADCAST 0x08000000
|
| 1097 |
+
/* A mask is being used on this array, affects buffer -> array copy */
|
| 1098 |
+
#define NPY_ITER_WRITEMASKED 0x10000000
|
| 1099 |
+
/* This array is the mask for all WRITEMASKED operands */
|
| 1100 |
+
#define NPY_ITER_ARRAYMASK 0x20000000
|
| 1101 |
+
/* Assume iterator order data access for COPY_IF_OVERLAP */
|
| 1102 |
+
#define NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE 0x40000000
|
| 1103 |
+
|
| 1104 |
+
#define NPY_ITER_GLOBAL_FLAGS 0x0000ffff
|
| 1105 |
+
#define NPY_ITER_PER_OP_FLAGS 0xffff0000
|
| 1106 |
+
|
| 1107 |
+
|
| 1108 |
+
/*****************************
|
| 1109 |
+
* Basic iterator object
|
| 1110 |
+
*****************************/
|
| 1111 |
+
|
| 1112 |
+
/* FWD declaration */
|
| 1113 |
+
typedef struct PyArrayIterObject_tag PyArrayIterObject;
|
| 1114 |
+
|
| 1115 |
+
/*
|
| 1116 |
+
* type of the function which translates a set of coordinates to a
|
| 1117 |
+
* pointer to the data
|
| 1118 |
+
*/
|
| 1119 |
+
typedef char* (*npy_iter_get_dataptr_t)(
|
| 1120 |
+
PyArrayIterObject* iter, const npy_intp*);
|
| 1121 |
+
|
| 1122 |
+
struct PyArrayIterObject_tag {
|
| 1123 |
+
PyObject_HEAD
|
| 1124 |
+
int nd_m1; /* number of dimensions - 1 */
|
| 1125 |
+
npy_intp index, size;
|
| 1126 |
+
npy_intp coordinates[NPY_MAXDIMS];/* N-dimensional loop */
|
| 1127 |
+
npy_intp dims_m1[NPY_MAXDIMS]; /* ao->dimensions - 1 */
|
| 1128 |
+
npy_intp strides[NPY_MAXDIMS]; /* ao->strides or fake */
|
| 1129 |
+
npy_intp backstrides[NPY_MAXDIMS];/* how far to jump back */
|
| 1130 |
+
npy_intp factors[NPY_MAXDIMS]; /* shape factors */
|
| 1131 |
+
PyArrayObject *ao;
|
| 1132 |
+
char *dataptr; /* pointer to current item*/
|
| 1133 |
+
npy_bool contiguous;
|
| 1134 |
+
|
| 1135 |
+
npy_intp bounds[NPY_MAXDIMS][2];
|
| 1136 |
+
npy_intp limits[NPY_MAXDIMS][2];
|
| 1137 |
+
npy_intp limits_sizes[NPY_MAXDIMS];
|
| 1138 |
+
npy_iter_get_dataptr_t translate;
|
| 1139 |
+
} ;
|
| 1140 |
+
|
| 1141 |
+
|
| 1142 |
+
/* Iterator API */
|
| 1143 |
+
#define PyArrayIter_Check(op) PyObject_TypeCheck((op), &PyArrayIter_Type)
|
| 1144 |
+
|
| 1145 |
+
#define _PyAIT(it) ((PyArrayIterObject *)(it))
|
| 1146 |
+
#define PyArray_ITER_RESET(it) do { \
|
| 1147 |
+
_PyAIT(it)->index = 0; \
|
| 1148 |
+
_PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
|
| 1149 |
+
memset(_PyAIT(it)->coordinates, 0, \
|
| 1150 |
+
(_PyAIT(it)->nd_m1+1)*sizeof(npy_intp)); \
|
| 1151 |
+
} while (0)
|
| 1152 |
+
|
| 1153 |
+
#define _PyArray_ITER_NEXT1(it) do { \
|
| 1154 |
+
(it)->dataptr += _PyAIT(it)->strides[0]; \
|
| 1155 |
+
(it)->coordinates[0]++; \
|
| 1156 |
+
} while (0)
|
| 1157 |
+
|
| 1158 |
+
#define _PyArray_ITER_NEXT2(it) do { \
|
| 1159 |
+
if ((it)->coordinates[1] < (it)->dims_m1[1]) { \
|
| 1160 |
+
(it)->coordinates[1]++; \
|
| 1161 |
+
(it)->dataptr += (it)->strides[1]; \
|
| 1162 |
+
} \
|
| 1163 |
+
else { \
|
| 1164 |
+
(it)->coordinates[1] = 0; \
|
| 1165 |
+
(it)->coordinates[0]++; \
|
| 1166 |
+
(it)->dataptr += (it)->strides[0] - \
|
| 1167 |
+
(it)->backstrides[1]; \
|
| 1168 |
+
} \
|
| 1169 |
+
} while (0)
|
| 1170 |
+
|
| 1171 |
+
#define PyArray_ITER_NEXT(it) do { \
|
| 1172 |
+
_PyAIT(it)->index++; \
|
| 1173 |
+
if (_PyAIT(it)->nd_m1 == 0) { \
|
| 1174 |
+
_PyArray_ITER_NEXT1(_PyAIT(it)); \
|
| 1175 |
+
} \
|
| 1176 |
+
else if (_PyAIT(it)->contiguous) \
|
| 1177 |
+
_PyAIT(it)->dataptr += PyArray_DESCR(_PyAIT(it)->ao)->elsize; \
|
| 1178 |
+
else if (_PyAIT(it)->nd_m1 == 1) { \
|
| 1179 |
+
_PyArray_ITER_NEXT2(_PyAIT(it)); \
|
| 1180 |
+
} \
|
| 1181 |
+
else { \
|
| 1182 |
+
int __npy_i; \
|
| 1183 |
+
for (__npy_i=_PyAIT(it)->nd_m1; __npy_i >= 0; __npy_i--) { \
|
| 1184 |
+
if (_PyAIT(it)->coordinates[__npy_i] < \
|
| 1185 |
+
_PyAIT(it)->dims_m1[__npy_i]) { \
|
| 1186 |
+
_PyAIT(it)->coordinates[__npy_i]++; \
|
| 1187 |
+
_PyAIT(it)->dataptr += \
|
| 1188 |
+
_PyAIT(it)->strides[__npy_i]; \
|
| 1189 |
+
break; \
|
| 1190 |
+
} \
|
| 1191 |
+
else { \
|
| 1192 |
+
_PyAIT(it)->coordinates[__npy_i] = 0; \
|
| 1193 |
+
_PyAIT(it)->dataptr -= \
|
| 1194 |
+
_PyAIT(it)->backstrides[__npy_i]; \
|
| 1195 |
+
} \
|
| 1196 |
+
} \
|
| 1197 |
+
} \
|
| 1198 |
+
} while (0)
|
| 1199 |
+
|
| 1200 |
+
#define PyArray_ITER_GOTO(it, destination) do { \
|
| 1201 |
+
int __npy_i; \
|
| 1202 |
+
_PyAIT(it)->index = 0; \
|
| 1203 |
+
_PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
|
| 1204 |
+
for (__npy_i = _PyAIT(it)->nd_m1; __npy_i>=0; __npy_i--) { \
|
| 1205 |
+
if (destination[__npy_i] < 0) { \
|
| 1206 |
+
destination[__npy_i] += \
|
| 1207 |
+
_PyAIT(it)->dims_m1[__npy_i]+1; \
|
| 1208 |
+
} \
|
| 1209 |
+
_PyAIT(it)->dataptr += destination[__npy_i] * \
|
| 1210 |
+
_PyAIT(it)->strides[__npy_i]; \
|
| 1211 |
+
_PyAIT(it)->coordinates[__npy_i] = \
|
| 1212 |
+
destination[__npy_i]; \
|
| 1213 |
+
_PyAIT(it)->index += destination[__npy_i] * \
|
| 1214 |
+
( __npy_i==_PyAIT(it)->nd_m1 ? 1 : \
|
| 1215 |
+
_PyAIT(it)->dims_m1[__npy_i+1]+1) ; \
|
| 1216 |
+
} \
|
| 1217 |
+
} while (0)
|
| 1218 |
+
|
| 1219 |
+
#define PyArray_ITER_GOTO1D(it, ind) do { \
|
| 1220 |
+
int __npy_i; \
|
| 1221 |
+
npy_intp __npy_ind = (npy_intp)(ind); \
|
| 1222 |
+
if (__npy_ind < 0) __npy_ind += _PyAIT(it)->size; \
|
| 1223 |
+
_PyAIT(it)->index = __npy_ind; \
|
| 1224 |
+
if (_PyAIT(it)->nd_m1 == 0) { \
|
| 1225 |
+
_PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao) + \
|
| 1226 |
+
__npy_ind * _PyAIT(it)->strides[0]; \
|
| 1227 |
+
} \
|
| 1228 |
+
else if (_PyAIT(it)->contiguous) \
|
| 1229 |
+
_PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao) + \
|
| 1230 |
+
__npy_ind * PyArray_DESCR(_PyAIT(it)->ao)->elsize; \
|
| 1231 |
+
else { \
|
| 1232 |
+
_PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
|
| 1233 |
+
for (__npy_i = 0; __npy_i<=_PyAIT(it)->nd_m1; \
|
| 1234 |
+
__npy_i++) { \
|
| 1235 |
+
_PyAIT(it)->coordinates[__npy_i] = \
|
| 1236 |
+
(__npy_ind / _PyAIT(it)->factors[__npy_i]); \
|
| 1237 |
+
_PyAIT(it)->dataptr += \
|
| 1238 |
+
(__npy_ind / _PyAIT(it)->factors[__npy_i]) \
|
| 1239 |
+
* _PyAIT(it)->strides[__npy_i]; \
|
| 1240 |
+
__npy_ind %= _PyAIT(it)->factors[__npy_i]; \
|
| 1241 |
+
} \
|
| 1242 |
+
} \
|
| 1243 |
+
} while (0)
|
| 1244 |
+
|
| 1245 |
+
#define PyArray_ITER_DATA(it) ((void *)(_PyAIT(it)->dataptr))
|
| 1246 |
+
|
| 1247 |
+
#define PyArray_ITER_NOTDONE(it) (_PyAIT(it)->index < _PyAIT(it)->size)
|
| 1248 |
+
|
| 1249 |
+
|
| 1250 |
+
/*
|
| 1251 |
+
* Any object passed to PyArray_Broadcast must be binary compatible
|
| 1252 |
+
* with this structure.
|
| 1253 |
+
*/
|
| 1254 |
+
|
| 1255 |
+
typedef struct {
|
| 1256 |
+
PyObject_HEAD
|
| 1257 |
+
int numiter; /* number of iters */
|
| 1258 |
+
npy_intp size; /* broadcasted size */
|
| 1259 |
+
npy_intp index; /* current index */
|
| 1260 |
+
int nd; /* number of dims */
|
| 1261 |
+
npy_intp dimensions[NPY_MAXDIMS]; /* dimensions */
|
| 1262 |
+
PyArrayIterObject *iters[NPY_MAXARGS]; /* iterators */
|
| 1263 |
+
} PyArrayMultiIterObject;
|
| 1264 |
+
|
| 1265 |
+
#define _PyMIT(m) ((PyArrayMultiIterObject *)(m))
|
| 1266 |
+
#define PyArray_MultiIter_RESET(multi) do { \
|
| 1267 |
+
int __npy_mi; \
|
| 1268 |
+
_PyMIT(multi)->index = 0; \
|
| 1269 |
+
for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \
|
| 1270 |
+
PyArray_ITER_RESET(_PyMIT(multi)->iters[__npy_mi]); \
|
| 1271 |
+
} \
|
| 1272 |
+
} while (0)
|
| 1273 |
+
|
| 1274 |
+
#define PyArray_MultiIter_NEXT(multi) do { \
|
| 1275 |
+
int __npy_mi; \
|
| 1276 |
+
_PyMIT(multi)->index++; \
|
| 1277 |
+
for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \
|
| 1278 |
+
PyArray_ITER_NEXT(_PyMIT(multi)->iters[__npy_mi]); \
|
| 1279 |
+
} \
|
| 1280 |
+
} while (0)
|
| 1281 |
+
|
| 1282 |
+
#define PyArray_MultiIter_GOTO(multi, dest) do { \
|
| 1283 |
+
int __npy_mi; \
|
| 1284 |
+
for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \
|
| 1285 |
+
PyArray_ITER_GOTO(_PyMIT(multi)->iters[__npy_mi], dest); \
|
| 1286 |
+
} \
|
| 1287 |
+
_PyMIT(multi)->index = _PyMIT(multi)->iters[0]->index; \
|
| 1288 |
+
} while (0)
|
| 1289 |
+
|
| 1290 |
+
#define PyArray_MultiIter_GOTO1D(multi, ind) do { \
|
| 1291 |
+
int __npy_mi; \
|
| 1292 |
+
for (__npy_mi=0; __npy_mi < _PyMIT(multi)->numiter; __npy_mi++) { \
|
| 1293 |
+
PyArray_ITER_GOTO1D(_PyMIT(multi)->iters[__npy_mi], ind); \
|
| 1294 |
+
} \
|
| 1295 |
+
_PyMIT(multi)->index = _PyMIT(multi)->iters[0]->index; \
|
| 1296 |
+
} while (0)
|
| 1297 |
+
|
| 1298 |
+
#define PyArray_MultiIter_DATA(multi, i) \
|
| 1299 |
+
((void *)(_PyMIT(multi)->iters[i]->dataptr))
|
| 1300 |
+
|
| 1301 |
+
#define PyArray_MultiIter_NEXTi(multi, i) \
|
| 1302 |
+
PyArray_ITER_NEXT(_PyMIT(multi)->iters[i])
|
| 1303 |
+
|
| 1304 |
+
#define PyArray_MultiIter_NOTDONE(multi) \
|
| 1305 |
+
(_PyMIT(multi)->index < _PyMIT(multi)->size)
|
| 1306 |
+
|
| 1307 |
+
/*
|
| 1308 |
+
* Store the information needed for fancy-indexing over an array. The
|
| 1309 |
+
* fields are slightly unordered to keep consec, dataptr and subspace
|
| 1310 |
+
* where they were originally.
|
| 1311 |
+
*/
|
| 1312 |
+
typedef struct {
|
| 1313 |
+
PyObject_HEAD
|
| 1314 |
+
/*
|
| 1315 |
+
* Multi-iterator portion --- needs to be present in this
|
| 1316 |
+
* order to work with PyArray_Broadcast
|
| 1317 |
+
*/
|
| 1318 |
+
|
| 1319 |
+
int numiter; /* number of index-array
|
| 1320 |
+
iterators */
|
| 1321 |
+
npy_intp size; /* size of broadcasted
|
| 1322 |
+
result */
|
| 1323 |
+
npy_intp index; /* current index */
|
| 1324 |
+
int nd; /* number of dims */
|
| 1325 |
+
npy_intp dimensions[NPY_MAXDIMS]; /* dimensions */
|
| 1326 |
+
NpyIter *outer; /* index objects
|
| 1327 |
+
iterator */
|
| 1328 |
+
void *unused[NPY_MAXDIMS - 2];
|
| 1329 |
+
PyArrayObject *array;
|
| 1330 |
+
/* Flat iterator for the indexed array. For compatibility solely. */
|
| 1331 |
+
PyArrayIterObject *ait;
|
| 1332 |
+
|
| 1333 |
+
/*
|
| 1334 |
+
* Subspace array. For binary compatibility (was an iterator,
|
| 1335 |
+
* but only the check for NULL should be used).
|
| 1336 |
+
*/
|
| 1337 |
+
PyArrayObject *subspace;
|
| 1338 |
+
|
| 1339 |
+
/*
|
| 1340 |
+
* if subspace iteration, then this is the array of axes in
|
| 1341 |
+
* the underlying array represented by the index objects
|
| 1342 |
+
*/
|
| 1343 |
+
int iteraxes[NPY_MAXDIMS];
|
| 1344 |
+
npy_intp fancy_strides[NPY_MAXDIMS];
|
| 1345 |
+
|
| 1346 |
+
/* pointer when all fancy indices are 0 */
|
| 1347 |
+
char *baseoffset;
|
| 1348 |
+
|
| 1349 |
+
/*
|
| 1350 |
+
* after binding consec denotes at which axis the fancy axes
|
| 1351 |
+
* are inserted.
|
| 1352 |
+
*/
|
| 1353 |
+
int consec;
|
| 1354 |
+
char *dataptr;
|
| 1355 |
+
|
| 1356 |
+
int nd_fancy;
|
| 1357 |
+
npy_intp fancy_dims[NPY_MAXDIMS];
|
| 1358 |
+
|
| 1359 |
+
/*
|
| 1360 |
+
* Whether the iterator (any of the iterators) requires API. This is
|
| 1361 |
+
* unused by NumPy itself; ArrayMethod flags are more precise.
|
| 1362 |
+
*/
|
| 1363 |
+
int needs_api;
|
| 1364 |
+
|
| 1365 |
+
/*
|
| 1366 |
+
* Extra op information.
|
| 1367 |
+
*/
|
| 1368 |
+
PyArrayObject *extra_op;
|
| 1369 |
+
PyArray_Descr *extra_op_dtype; /* desired dtype */
|
| 1370 |
+
npy_uint32 *extra_op_flags; /* Iterator flags */
|
| 1371 |
+
|
| 1372 |
+
NpyIter *extra_op_iter;
|
| 1373 |
+
NpyIter_IterNextFunc *extra_op_next;
|
| 1374 |
+
char **extra_op_ptrs;
|
| 1375 |
+
|
| 1376 |
+
/*
|
| 1377 |
+
* Information about the iteration state.
|
| 1378 |
+
*/
|
| 1379 |
+
NpyIter_IterNextFunc *outer_next;
|
| 1380 |
+
char **outer_ptrs;
|
| 1381 |
+
npy_intp *outer_strides;
|
| 1382 |
+
|
| 1383 |
+
/*
|
| 1384 |
+
* Information about the subspace iterator.
|
| 1385 |
+
*/
|
| 1386 |
+
NpyIter *subspace_iter;
|
| 1387 |
+
NpyIter_IterNextFunc *subspace_next;
|
| 1388 |
+
char **subspace_ptrs;
|
| 1389 |
+
npy_intp *subspace_strides;
|
| 1390 |
+
|
| 1391 |
+
/* Count for the external loop (which ever it is) for API iteration */
|
| 1392 |
+
npy_intp iter_count;
|
| 1393 |
+
|
| 1394 |
+
} PyArrayMapIterObject;
|
| 1395 |
+
|
| 1396 |
+
enum {
|
| 1397 |
+
NPY_NEIGHBORHOOD_ITER_ZERO_PADDING,
|
| 1398 |
+
NPY_NEIGHBORHOOD_ITER_ONE_PADDING,
|
| 1399 |
+
NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING,
|
| 1400 |
+
NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING,
|
| 1401 |
+
NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING
|
| 1402 |
+
};
|
| 1403 |
+
|
| 1404 |
+
typedef struct {
|
| 1405 |
+
PyObject_HEAD
|
| 1406 |
+
|
| 1407 |
+
/*
|
| 1408 |
+
* PyArrayIterObject part: keep this in this exact order
|
| 1409 |
+
*/
|
| 1410 |
+
int nd_m1; /* number of dimensions - 1 */
|
| 1411 |
+
npy_intp index, size;
|
| 1412 |
+
npy_intp coordinates[NPY_MAXDIMS];/* N-dimensional loop */
|
| 1413 |
+
npy_intp dims_m1[NPY_MAXDIMS]; /* ao->dimensions - 1 */
|
| 1414 |
+
npy_intp strides[NPY_MAXDIMS]; /* ao->strides or fake */
|
| 1415 |
+
npy_intp backstrides[NPY_MAXDIMS];/* how far to jump back */
|
| 1416 |
+
npy_intp factors[NPY_MAXDIMS]; /* shape factors */
|
| 1417 |
+
PyArrayObject *ao;
|
| 1418 |
+
char *dataptr; /* pointer to current item*/
|
| 1419 |
+
npy_bool contiguous;
|
| 1420 |
+
|
| 1421 |
+
npy_intp bounds[NPY_MAXDIMS][2];
|
| 1422 |
+
npy_intp limits[NPY_MAXDIMS][2];
|
| 1423 |
+
npy_intp limits_sizes[NPY_MAXDIMS];
|
| 1424 |
+
npy_iter_get_dataptr_t translate;
|
| 1425 |
+
|
| 1426 |
+
/*
|
| 1427 |
+
* New members
|
| 1428 |
+
*/
|
| 1429 |
+
npy_intp nd;
|
| 1430 |
+
|
| 1431 |
+
/* Dimensions is the dimension of the array */
|
| 1432 |
+
npy_intp dimensions[NPY_MAXDIMS];
|
| 1433 |
+
|
| 1434 |
+
/*
|
| 1435 |
+
* Neighborhood points coordinates are computed relatively to the
|
| 1436 |
+
* point pointed by _internal_iter
|
| 1437 |
+
*/
|
| 1438 |
+
PyArrayIterObject* _internal_iter;
|
| 1439 |
+
/*
|
| 1440 |
+
* To keep a reference to the representation of the constant value
|
| 1441 |
+
* for constant padding
|
| 1442 |
+
*/
|
| 1443 |
+
char* constant;
|
| 1444 |
+
|
| 1445 |
+
int mode;
|
| 1446 |
+
} PyArrayNeighborhoodIterObject;
|
| 1447 |
+
|
| 1448 |
+
/*
|
| 1449 |
+
* Neighborhood iterator API
|
| 1450 |
+
*/
|
| 1451 |
+
|
| 1452 |
+
/* General: those work for any mode */
|
| 1453 |
+
static inline int
|
| 1454 |
+
PyArrayNeighborhoodIter_Reset(PyArrayNeighborhoodIterObject* iter);
|
| 1455 |
+
static inline int
|
| 1456 |
+
PyArrayNeighborhoodIter_Next(PyArrayNeighborhoodIterObject* iter);
|
| 1457 |
+
#if 0
|
| 1458 |
+
static inline int
|
| 1459 |
+
PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter);
|
| 1460 |
+
#endif
|
| 1461 |
+
|
| 1462 |
+
/*
|
| 1463 |
+
* Include inline implementations - functions defined there are not
|
| 1464 |
+
* considered public API
|
| 1465 |
+
*/
|
| 1466 |
+
#define NUMPY_CORE_INCLUDE_NUMPY__NEIGHBORHOOD_IMP_H_
|
| 1467 |
+
#include "_neighborhood_iterator_imp.h"
|
| 1468 |
+
#undef NUMPY_CORE_INCLUDE_NUMPY__NEIGHBORHOOD_IMP_H_
|
| 1469 |
+
|
| 1470 |
+
|
| 1471 |
+
|
| 1472 |
+
/* The default array type */
|
| 1473 |
+
#define NPY_DEFAULT_TYPE NPY_DOUBLE
|
| 1474 |
+
|
| 1475 |
+
/*
|
| 1476 |
+
* All sorts of useful ways to look into a PyArrayObject. It is recommended
|
| 1477 |
+
* to use PyArrayObject * objects instead of always casting from PyObject *,
|
| 1478 |
+
* for improved type checking.
|
| 1479 |
+
*
|
| 1480 |
+
* In many cases here the macro versions of the accessors are deprecated,
|
| 1481 |
+
* but can't be immediately changed to inline functions because the
|
| 1482 |
+
* preexisting macros accept PyObject * and do automatic casts. Inline
|
| 1483 |
+
* functions accepting PyArrayObject * provides for some compile-time
|
| 1484 |
+
* checking of correctness when working with these objects in C.
|
| 1485 |
+
*/
|
| 1486 |
+
|
| 1487 |
+
#define PyArray_ISONESEGMENT(m) (PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS) || \
|
| 1488 |
+
PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS))
|
| 1489 |
+
|
| 1490 |
+
#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) && \
|
| 1491 |
+
(!PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS)))
|
| 1492 |
+
|
| 1493 |
+
#define PyArray_FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) ? \
|
| 1494 |
+
NPY_ARRAY_F_CONTIGUOUS : 0))
|
| 1495 |
+
|
| 1496 |
+
#if (defined(NPY_NO_DEPRECATED_API) && (NPY_1_7_API_VERSION <= NPY_NO_DEPRECATED_API))
|
| 1497 |
+
/*
|
| 1498 |
+
* Changing access macros into functions, to allow for future hiding
|
| 1499 |
+
* of the internal memory layout. This later hiding will allow the 2.x series
|
| 1500 |
+
* to change the internal representation of arrays without affecting
|
| 1501 |
+
* ABI compatibility.
|
| 1502 |
+
*/
|
| 1503 |
+
|
| 1504 |
+
static inline int
|
| 1505 |
+
PyArray_NDIM(const PyArrayObject *arr)
|
| 1506 |
+
{
|
| 1507 |
+
return ((PyArrayObject_fields *)arr)->nd;
|
| 1508 |
+
}
|
| 1509 |
+
|
| 1510 |
+
static inline void *
|
| 1511 |
+
PyArray_DATA(PyArrayObject *arr)
|
| 1512 |
+
{
|
| 1513 |
+
return ((PyArrayObject_fields *)arr)->data;
|
| 1514 |
+
}
|
| 1515 |
+
|
| 1516 |
+
static inline char *
|
| 1517 |
+
PyArray_BYTES(PyArrayObject *arr)
|
| 1518 |
+
{
|
| 1519 |
+
return ((PyArrayObject_fields *)arr)->data;
|
| 1520 |
+
}
|
| 1521 |
+
|
| 1522 |
+
static inline npy_intp *
|
| 1523 |
+
PyArray_DIMS(PyArrayObject *arr)
|
| 1524 |
+
{
|
| 1525 |
+
return ((PyArrayObject_fields *)arr)->dimensions;
|
| 1526 |
+
}
|
| 1527 |
+
|
| 1528 |
+
static inline npy_intp *
|
| 1529 |
+
PyArray_STRIDES(PyArrayObject *arr)
|
| 1530 |
+
{
|
| 1531 |
+
return ((PyArrayObject_fields *)arr)->strides;
|
| 1532 |
+
}
|
| 1533 |
+
|
| 1534 |
+
static inline npy_intp
|
| 1535 |
+
PyArray_DIM(const PyArrayObject *arr, int idim)
|
| 1536 |
+
{
|
| 1537 |
+
return ((PyArrayObject_fields *)arr)->dimensions[idim];
|
| 1538 |
+
}
|
| 1539 |
+
|
| 1540 |
+
static inline npy_intp
|
| 1541 |
+
PyArray_STRIDE(const PyArrayObject *arr, int istride)
|
| 1542 |
+
{
|
| 1543 |
+
return ((PyArrayObject_fields *)arr)->strides[istride];
|
| 1544 |
+
}
|
| 1545 |
+
|
| 1546 |
+
static inline NPY_RETURNS_BORROWED_REF PyObject *
|
| 1547 |
+
PyArray_BASE(PyArrayObject *arr)
|
| 1548 |
+
{
|
| 1549 |
+
return ((PyArrayObject_fields *)arr)->base;
|
| 1550 |
+
}
|
| 1551 |
+
|
| 1552 |
+
static inline NPY_RETURNS_BORROWED_REF PyArray_Descr *
|
| 1553 |
+
PyArray_DESCR(PyArrayObject *arr)
|
| 1554 |
+
{
|
| 1555 |
+
return ((PyArrayObject_fields *)arr)->descr;
|
| 1556 |
+
}
|
| 1557 |
+
|
| 1558 |
+
static inline int
|
| 1559 |
+
PyArray_FLAGS(const PyArrayObject *arr)
|
| 1560 |
+
{
|
| 1561 |
+
return ((PyArrayObject_fields *)arr)->flags;
|
| 1562 |
+
}
|
| 1563 |
+
|
| 1564 |
+
static inline npy_intp
|
| 1565 |
+
PyArray_ITEMSIZE(const PyArrayObject *arr)
|
| 1566 |
+
{
|
| 1567 |
+
return ((PyArrayObject_fields *)arr)->descr->elsize;
|
| 1568 |
+
}
|
| 1569 |
+
|
| 1570 |
+
static inline int
|
| 1571 |
+
PyArray_TYPE(const PyArrayObject *arr)
|
| 1572 |
+
{
|
| 1573 |
+
return ((PyArrayObject_fields *)arr)->descr->type_num;
|
| 1574 |
+
}
|
| 1575 |
+
|
| 1576 |
+
static inline int
|
| 1577 |
+
PyArray_CHKFLAGS(const PyArrayObject *arr, int flags)
|
| 1578 |
+
{
|
| 1579 |
+
return (PyArray_FLAGS(arr) & flags) == flags;
|
| 1580 |
+
}
|
| 1581 |
+
|
| 1582 |
+
static inline PyObject *
|
| 1583 |
+
PyArray_GETITEM(const PyArrayObject *arr, const char *itemptr)
|
| 1584 |
+
{
|
| 1585 |
+
return ((PyArrayObject_fields *)arr)->descr->f->getitem(
|
| 1586 |
+
(void *)itemptr, (PyArrayObject *)arr);
|
| 1587 |
+
}
|
| 1588 |
+
|
| 1589 |
+
/*
|
| 1590 |
+
* SETITEM should only be used if it is known that the value is a scalar
|
| 1591 |
+
* and of a type understood by the arrays dtype.
|
| 1592 |
+
* Use `PyArray_Pack` if the value may be of a different dtype.
|
| 1593 |
+
*/
|
| 1594 |
+
static inline int
|
| 1595 |
+
PyArray_SETITEM(PyArrayObject *arr, char *itemptr, PyObject *v)
|
| 1596 |
+
{
|
| 1597 |
+
return ((PyArrayObject_fields *)arr)->descr->f->setitem(v, itemptr, arr);
|
| 1598 |
+
}
|
| 1599 |
+
|
| 1600 |
+
#else
|
| 1601 |
+
|
| 1602 |
+
/* These macros are deprecated as of NumPy 1.7. */
|
| 1603 |
+
#define PyArray_NDIM(obj) (((PyArrayObject_fields *)(obj))->nd)
|
| 1604 |
+
#define PyArray_BYTES(obj) (((PyArrayObject_fields *)(obj))->data)
|
| 1605 |
+
#define PyArray_DATA(obj) ((void *)((PyArrayObject_fields *)(obj))->data)
|
| 1606 |
+
#define PyArray_DIMS(obj) (((PyArrayObject_fields *)(obj))->dimensions)
|
| 1607 |
+
#define PyArray_STRIDES(obj) (((PyArrayObject_fields *)(obj))->strides)
|
| 1608 |
+
#define PyArray_DIM(obj,n) (PyArray_DIMS(obj)[n])
|
| 1609 |
+
#define PyArray_STRIDE(obj,n) (PyArray_STRIDES(obj)[n])
|
| 1610 |
+
#define PyArray_BASE(obj) (((PyArrayObject_fields *)(obj))->base)
|
| 1611 |
+
#define PyArray_DESCR(obj) (((PyArrayObject_fields *)(obj))->descr)
|
| 1612 |
+
#define PyArray_FLAGS(obj) (((PyArrayObject_fields *)(obj))->flags)
|
| 1613 |
+
#define PyArray_CHKFLAGS(m, FLAGS) \
|
| 1614 |
+
((((PyArrayObject_fields *)(m))->flags & (FLAGS)) == (FLAGS))
|
| 1615 |
+
#define PyArray_ITEMSIZE(obj) \
|
| 1616 |
+
(((PyArrayObject_fields *)(obj))->descr->elsize)
|
| 1617 |
+
#define PyArray_TYPE(obj) \
|
| 1618 |
+
(((PyArrayObject_fields *)(obj))->descr->type_num)
|
| 1619 |
+
#define PyArray_GETITEM(obj,itemptr) \
|
| 1620 |
+
PyArray_DESCR(obj)->f->getitem((char *)(itemptr), \
|
| 1621 |
+
(PyArrayObject *)(obj))
|
| 1622 |
+
|
| 1623 |
+
#define PyArray_SETITEM(obj,itemptr,v) \
|
| 1624 |
+
PyArray_DESCR(obj)->f->setitem((PyObject *)(v), \
|
| 1625 |
+
(char *)(itemptr), \
|
| 1626 |
+
(PyArrayObject *)(obj))
|
| 1627 |
+
#endif
|
| 1628 |
+
|
| 1629 |
+
static inline PyArray_Descr *
|
| 1630 |
+
PyArray_DTYPE(PyArrayObject *arr)
|
| 1631 |
+
{
|
| 1632 |
+
return ((PyArrayObject_fields *)arr)->descr;
|
| 1633 |
+
}
|
| 1634 |
+
|
| 1635 |
+
static inline npy_intp *
|
| 1636 |
+
PyArray_SHAPE(PyArrayObject *arr)
|
| 1637 |
+
{
|
| 1638 |
+
return ((PyArrayObject_fields *)arr)->dimensions;
|
| 1639 |
+
}
|
| 1640 |
+
|
| 1641 |
+
/*
|
| 1642 |
+
* Enables the specified array flags. Does no checking,
|
| 1643 |
+
* assumes you know what you're doing.
|
| 1644 |
+
*/
|
| 1645 |
+
static inline void
|
| 1646 |
+
PyArray_ENABLEFLAGS(PyArrayObject *arr, int flags)
|
| 1647 |
+
{
|
| 1648 |
+
((PyArrayObject_fields *)arr)->flags |= flags;
|
| 1649 |
+
}
|
| 1650 |
+
|
| 1651 |
+
/*
|
| 1652 |
+
* Clears the specified array flags. Does no checking,
|
| 1653 |
+
* assumes you know what you're doing.
|
| 1654 |
+
*/
|
| 1655 |
+
static inline void
|
| 1656 |
+
PyArray_CLEARFLAGS(PyArrayObject *arr, int flags)
|
| 1657 |
+
{
|
| 1658 |
+
((PyArrayObject_fields *)arr)->flags &= ~flags;
|
| 1659 |
+
}
|
| 1660 |
+
|
| 1661 |
+
#if NPY_FEATURE_VERSION >= NPY_1_22_API_VERSION
|
| 1662 |
+
static inline NPY_RETURNS_BORROWED_REF PyObject *
|
| 1663 |
+
PyArray_HANDLER(PyArrayObject *arr)
|
| 1664 |
+
{
|
| 1665 |
+
return ((PyArrayObject_fields *)arr)->mem_handler;
|
| 1666 |
+
}
|
| 1667 |
+
#endif
|
| 1668 |
+
|
| 1669 |
+
#define PyTypeNum_ISBOOL(type) ((type) == NPY_BOOL)
|
| 1670 |
+
|
| 1671 |
+
#define PyTypeNum_ISUNSIGNED(type) (((type) == NPY_UBYTE) || \
|
| 1672 |
+
((type) == NPY_USHORT) || \
|
| 1673 |
+
((type) == NPY_UINT) || \
|
| 1674 |
+
((type) == NPY_ULONG) || \
|
| 1675 |
+
((type) == NPY_ULONGLONG))
|
| 1676 |
+
|
| 1677 |
+
#define PyTypeNum_ISSIGNED(type) (((type) == NPY_BYTE) || \
|
| 1678 |
+
((type) == NPY_SHORT) || \
|
| 1679 |
+
((type) == NPY_INT) || \
|
| 1680 |
+
((type) == NPY_LONG) || \
|
| 1681 |
+
((type) == NPY_LONGLONG))
|
| 1682 |
+
|
| 1683 |
+
#define PyTypeNum_ISINTEGER(type) (((type) >= NPY_BYTE) && \
|
| 1684 |
+
((type) <= NPY_ULONGLONG))
|
| 1685 |
+
|
| 1686 |
+
#define PyTypeNum_ISFLOAT(type) ((((type) >= NPY_FLOAT) && \
|
| 1687 |
+
((type) <= NPY_LONGDOUBLE)) || \
|
| 1688 |
+
((type) == NPY_HALF))
|
| 1689 |
+
|
| 1690 |
+
#define PyTypeNum_ISNUMBER(type) (((type) <= NPY_CLONGDOUBLE) || \
|
| 1691 |
+
((type) == NPY_HALF))
|
| 1692 |
+
|
| 1693 |
+
#define PyTypeNum_ISSTRING(type) (((type) == NPY_STRING) || \
|
| 1694 |
+
((type) == NPY_UNICODE))
|
| 1695 |
+
|
| 1696 |
+
#define PyTypeNum_ISCOMPLEX(type) (((type) >= NPY_CFLOAT) && \
|
| 1697 |
+
((type) <= NPY_CLONGDOUBLE))
|
| 1698 |
+
|
| 1699 |
+
#define PyTypeNum_ISPYTHON(type) (((type) == NPY_LONG) || \
|
| 1700 |
+
((type) == NPY_DOUBLE) || \
|
| 1701 |
+
((type) == NPY_CDOUBLE) || \
|
| 1702 |
+
((type) == NPY_BOOL) || \
|
| 1703 |
+
((type) == NPY_OBJECT ))
|
| 1704 |
+
|
| 1705 |
+
#define PyTypeNum_ISFLEXIBLE(type) (((type) >=NPY_STRING) && \
|
| 1706 |
+
((type) <=NPY_VOID))
|
| 1707 |
+
|
| 1708 |
+
#define PyTypeNum_ISDATETIME(type) (((type) >=NPY_DATETIME) && \
|
| 1709 |
+
((type) <=NPY_TIMEDELTA))
|
| 1710 |
+
|
| 1711 |
+
#define PyTypeNum_ISUSERDEF(type) (((type) >= NPY_USERDEF) && \
|
| 1712 |
+
((type) < NPY_USERDEF+ \
|
| 1713 |
+
NPY_NUMUSERTYPES))
|
| 1714 |
+
|
| 1715 |
+
#define PyTypeNum_ISEXTENDED(type) (PyTypeNum_ISFLEXIBLE(type) || \
|
| 1716 |
+
PyTypeNum_ISUSERDEF(type))
|
| 1717 |
+
|
| 1718 |
+
#define PyTypeNum_ISOBJECT(type) ((type) == NPY_OBJECT)
|
| 1719 |
+
|
| 1720 |
+
|
| 1721 |
+
#define PyDataType_ISBOOL(obj) PyTypeNum_ISBOOL(((PyArray_Descr*)(obj))->type_num)
|
| 1722 |
+
#define PyDataType_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(((PyArray_Descr*)(obj))->type_num)
|
| 1723 |
+
#define PyDataType_ISSIGNED(obj) PyTypeNum_ISSIGNED(((PyArray_Descr*)(obj))->type_num)
|
| 1724 |
+
#define PyDataType_ISINTEGER(obj) PyTypeNum_ISINTEGER(((PyArray_Descr*)(obj))->type_num )
|
| 1725 |
+
#define PyDataType_ISFLOAT(obj) PyTypeNum_ISFLOAT(((PyArray_Descr*)(obj))->type_num)
|
| 1726 |
+
#define PyDataType_ISNUMBER(obj) PyTypeNum_ISNUMBER(((PyArray_Descr*)(obj))->type_num)
|
| 1727 |
+
#define PyDataType_ISSTRING(obj) PyTypeNum_ISSTRING(((PyArray_Descr*)(obj))->type_num)
|
| 1728 |
+
#define PyDataType_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(((PyArray_Descr*)(obj))->type_num)
|
| 1729 |
+
#define PyDataType_ISPYTHON(obj) PyTypeNum_ISPYTHON(((PyArray_Descr*)(obj))->type_num)
|
| 1730 |
+
#define PyDataType_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(((PyArray_Descr*)(obj))->type_num)
|
| 1731 |
+
#define PyDataType_ISDATETIME(obj) PyTypeNum_ISDATETIME(((PyArray_Descr*)(obj))->type_num)
|
| 1732 |
+
#define PyDataType_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(((PyArray_Descr*)(obj))->type_num)
|
| 1733 |
+
#define PyDataType_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(((PyArray_Descr*)(obj))->type_num)
|
| 1734 |
+
#define PyDataType_ISOBJECT(obj) PyTypeNum_ISOBJECT(((PyArray_Descr*)(obj))->type_num)
|
| 1735 |
+
#define PyDataType_HASFIELDS(obj) (((PyArray_Descr *)(obj))->names != NULL)
|
| 1736 |
+
#define PyDataType_HASSUBARRAY(dtype) ((dtype)->subarray != NULL)
|
| 1737 |
+
#define PyDataType_ISUNSIZED(dtype) ((dtype)->elsize == 0 && \
|
| 1738 |
+
!PyDataType_HASFIELDS(dtype))
|
| 1739 |
+
#define PyDataType_MAKEUNSIZED(dtype) ((dtype)->elsize = 0)
|
| 1740 |
+
|
| 1741 |
+
#define PyArray_ISBOOL(obj) PyTypeNum_ISBOOL(PyArray_TYPE(obj))
|
| 1742 |
+
#define PyArray_ISUNSIGNED(obj) PyTypeNum_ISUNSIGNED(PyArray_TYPE(obj))
|
| 1743 |
+
#define PyArray_ISSIGNED(obj) PyTypeNum_ISSIGNED(PyArray_TYPE(obj))
|
| 1744 |
+
#define PyArray_ISINTEGER(obj) PyTypeNum_ISINTEGER(PyArray_TYPE(obj))
|
| 1745 |
+
#define PyArray_ISFLOAT(obj) PyTypeNum_ISFLOAT(PyArray_TYPE(obj))
|
| 1746 |
+
#define PyArray_ISNUMBER(obj) PyTypeNum_ISNUMBER(PyArray_TYPE(obj))
|
| 1747 |
+
#define PyArray_ISSTRING(obj) PyTypeNum_ISSTRING(PyArray_TYPE(obj))
|
| 1748 |
+
#define PyArray_ISCOMPLEX(obj) PyTypeNum_ISCOMPLEX(PyArray_TYPE(obj))
|
| 1749 |
+
#define PyArray_ISPYTHON(obj) PyTypeNum_ISPYTHON(PyArray_TYPE(obj))
|
| 1750 |
+
#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))
|
| 1751 |
+
#define PyArray_ISDATETIME(obj) PyTypeNum_ISDATETIME(PyArray_TYPE(obj))
|
| 1752 |
+
#define PyArray_ISUSERDEF(obj) PyTypeNum_ISUSERDEF(PyArray_TYPE(obj))
|
| 1753 |
+
#define PyArray_ISEXTENDED(obj) PyTypeNum_ISEXTENDED(PyArray_TYPE(obj))
|
| 1754 |
+
#define PyArray_ISOBJECT(obj) PyTypeNum_ISOBJECT(PyArray_TYPE(obj))
|
| 1755 |
+
#define PyArray_HASFIELDS(obj) PyDataType_HASFIELDS(PyArray_DESCR(obj))
|
| 1756 |
+
|
| 1757 |
+
/*
|
| 1758 |
+
* FIXME: This should check for a flag on the data-type that
|
| 1759 |
+
* states whether or not it is variable length. Because the
|
| 1760 |
+
* ISFLEXIBLE check is hard-coded to the built-in data-types.
|
| 1761 |
+
*/
|
| 1762 |
+
#define PyArray_ISVARIABLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))
|
| 1763 |
+
|
| 1764 |
+
#define PyArray_SAFEALIGNEDCOPY(obj) (PyArray_ISALIGNED(obj) && !PyArray_ISVARIABLE(obj))
|
| 1765 |
+
|
| 1766 |
+
|
| 1767 |
+
#define NPY_LITTLE '<'
|
| 1768 |
+
#define NPY_BIG '>'
|
| 1769 |
+
#define NPY_NATIVE '='
|
| 1770 |
+
#define NPY_SWAP 's'
|
| 1771 |
+
#define NPY_IGNORE '|'
|
| 1772 |
+
|
| 1773 |
+
#if NPY_BYTE_ORDER == NPY_BIG_ENDIAN
|
| 1774 |
+
#define NPY_NATBYTE NPY_BIG
|
| 1775 |
+
#define NPY_OPPBYTE NPY_LITTLE
|
| 1776 |
+
#else
|
| 1777 |
+
#define NPY_NATBYTE NPY_LITTLE
|
| 1778 |
+
#define NPY_OPPBYTE NPY_BIG
|
| 1779 |
+
#endif
|
| 1780 |
+
|
| 1781 |
+
#define PyArray_ISNBO(arg) ((arg) != NPY_OPPBYTE)
|
| 1782 |
+
#define PyArray_IsNativeByteOrder PyArray_ISNBO
|
| 1783 |
+
#define PyArray_ISNOTSWAPPED(m) PyArray_ISNBO(PyArray_DESCR(m)->byteorder)
|
| 1784 |
+
#define PyArray_ISBYTESWAPPED(m) (!PyArray_ISNOTSWAPPED(m))
|
| 1785 |
+
|
| 1786 |
+
#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) && \
|
| 1787 |
+
PyArray_ISNOTSWAPPED(m))
|
| 1788 |
+
|
| 1789 |
+
#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, NPY_ARRAY_CARRAY)
|
| 1790 |
+
#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_CARRAY_RO)
|
| 1791 |
+
#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, NPY_ARRAY_FARRAY)
|
| 1792 |
+
#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_FARRAY_RO)
|
| 1793 |
+
#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, NPY_ARRAY_BEHAVED)
|
| 1794 |
+
#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_ALIGNED)
|
| 1795 |
+
|
| 1796 |
+
|
| 1797 |
+
#define PyDataType_ISNOTSWAPPED(d) PyArray_ISNBO(((PyArray_Descr *)(d))->byteorder)
|
| 1798 |
+
#define PyDataType_ISBYTESWAPPED(d) (!PyDataType_ISNOTSWAPPED(d))
|
| 1799 |
+
|
| 1800 |
+
/************************************************************
|
| 1801 |
+
* A struct used by PyArray_CreateSortedStridePerm, new in 1.7.
|
| 1802 |
+
************************************************************/
|
| 1803 |
+
|
| 1804 |
+
typedef struct {
|
| 1805 |
+
npy_intp perm, stride;
|
| 1806 |
+
} npy_stride_sort_item;
|
| 1807 |
+
|
| 1808 |
+
/************************************************************
|
| 1809 |
+
* This is the form of the struct that's stored in the
|
| 1810 |
+
* PyCapsule returned by an array's __array_struct__ attribute. See
|
| 1811 |
+
* https://docs.scipy.org/doc/numpy/reference/arrays.interface.html for the full
|
| 1812 |
+
* documentation.
|
| 1813 |
+
************************************************************/
|
| 1814 |
+
typedef struct {
|
| 1815 |
+
int two; /*
|
| 1816 |
+
* contains the integer 2 as a sanity
|
| 1817 |
+
* check
|
| 1818 |
+
*/
|
| 1819 |
+
|
| 1820 |
+
int nd; /* number of dimensions */
|
| 1821 |
+
|
| 1822 |
+
char typekind; /*
|
| 1823 |
+
* kind in array --- character code of
|
| 1824 |
+
* typestr
|
| 1825 |
+
*/
|
| 1826 |
+
|
| 1827 |
+
int itemsize; /* size of each element */
|
| 1828 |
+
|
| 1829 |
+
int flags; /*
|
| 1830 |
+
* how should be data interpreted. Valid
|
| 1831 |
+
* flags are CONTIGUOUS (1), F_CONTIGUOUS (2),
|
| 1832 |
+
* ALIGNED (0x100), NOTSWAPPED (0x200), and
|
| 1833 |
+
* WRITEABLE (0x400). ARR_HAS_DESCR (0x800)
|
| 1834 |
+
* states that arrdescr field is present in
|
| 1835 |
+
* structure
|
| 1836 |
+
*/
|
| 1837 |
+
|
| 1838 |
+
npy_intp *shape; /*
|
| 1839 |
+
* A length-nd array of shape
|
| 1840 |
+
* information
|
| 1841 |
+
*/
|
| 1842 |
+
|
| 1843 |
+
npy_intp *strides; /* A length-nd array of stride information */
|
| 1844 |
+
|
| 1845 |
+
void *data; /* A pointer to the first element of the array */
|
| 1846 |
+
|
| 1847 |
+
PyObject *descr; /*
|
| 1848 |
+
* A list of fields or NULL (ignored if flags
|
| 1849 |
+
* does not have ARR_HAS_DESCR flag set)
|
| 1850 |
+
*/
|
| 1851 |
+
} PyArrayInterface;
|
| 1852 |
+
|
| 1853 |
+
/*
|
| 1854 |
+
* This is a function for hooking into the PyDataMem_NEW/FREE/RENEW functions.
|
| 1855 |
+
* See the documentation for PyDataMem_SetEventHook.
|
| 1856 |
+
*/
|
| 1857 |
+
typedef void (PyDataMem_EventHookFunc)(void *inp, void *outp, size_t size,
|
| 1858 |
+
void *user_data);
|
| 1859 |
+
|
| 1860 |
+
|
| 1861 |
+
/*
|
| 1862 |
+
* PyArray_DTypeMeta related definitions.
|
| 1863 |
+
*
|
| 1864 |
+
* As of now, this API is preliminary and will be extended as necessary.
|
| 1865 |
+
*/
|
| 1866 |
+
#if defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD
|
| 1867 |
+
/*
|
| 1868 |
+
* The Structures defined in this block are currently considered
|
| 1869 |
+
* private API and may change without warning!
|
| 1870 |
+
* Part of this (at least the size) is expected to be public API without
|
| 1871 |
+
* further modifications.
|
| 1872 |
+
*/
|
| 1873 |
+
/* TODO: Make this definition public in the API, as soon as its settled */
|
| 1874 |
+
NPY_NO_EXPORT extern PyTypeObject PyArrayDTypeMeta_Type;
|
| 1875 |
+
|
| 1876 |
+
/*
|
| 1877 |
+
* While NumPy DTypes would not need to be heap types the plan is to
|
| 1878 |
+
* make DTypes available in Python at which point they will be heap types.
|
| 1879 |
+
* Since we also wish to add fields to the DType class, this looks like
|
| 1880 |
+
* a typical instance definition, but with PyHeapTypeObject instead of
|
| 1881 |
+
* only the PyObject_HEAD.
|
| 1882 |
+
* This must only be exposed very extremely careful consideration, since
|
| 1883 |
+
* it is a fairly complex construct which may be better to allow
|
| 1884 |
+
* refactoring of.
|
| 1885 |
+
*/
|
| 1886 |
+
typedef struct {
|
| 1887 |
+
PyHeapTypeObject super;
|
| 1888 |
+
|
| 1889 |
+
/*
|
| 1890 |
+
* Most DTypes will have a singleton default instance, for the
|
| 1891 |
+
* parametric legacy DTypes (bytes, string, void, datetime) this
|
| 1892 |
+
* may be a pointer to the *prototype* instance?
|
| 1893 |
+
*/
|
| 1894 |
+
PyArray_Descr *singleton;
|
| 1895 |
+
/* Copy of the legacy DTypes type number, usually invalid. */
|
| 1896 |
+
int type_num;
|
| 1897 |
+
|
| 1898 |
+
/* The type object of the scalar instances (may be NULL?) */
|
| 1899 |
+
PyTypeObject *scalar_type;
|
| 1900 |
+
/*
|
| 1901 |
+
* DType flags to signal legacy, parametric, or
|
| 1902 |
+
* abstract. But plenty of space for additional information/flags.
|
| 1903 |
+
*/
|
| 1904 |
+
npy_uint64 flags;
|
| 1905 |
+
|
| 1906 |
+
/*
|
| 1907 |
+
* Use indirection in order to allow a fixed size for this struct.
|
| 1908 |
+
* A stable ABI size makes creating a static DType less painful
|
| 1909 |
+
* while also ensuring flexibility for all opaque API (with one
|
| 1910 |
+
* indirection due the pointer lookup).
|
| 1911 |
+
*/
|
| 1912 |
+
void *dt_slots;
|
| 1913 |
+
void *reserved[3];
|
| 1914 |
+
} PyArray_DTypeMeta;
|
| 1915 |
+
|
| 1916 |
+
#endif /* NPY_INTERNAL_BUILD */
|
| 1917 |
+
|
| 1918 |
+
|
| 1919 |
+
/*
|
| 1920 |
+
* Use the keyword NPY_DEPRECATED_INCLUDES to ensure that the header files
|
| 1921 |
+
* npy_*_*_deprecated_api.h are only included from here and nowhere else.
|
| 1922 |
+
*/
|
| 1923 |
+
#ifdef NPY_DEPRECATED_INCLUDES
|
| 1924 |
+
#error "Do not use the reserved keyword NPY_DEPRECATED_INCLUDES."
|
| 1925 |
+
#endif
|
| 1926 |
+
#define NPY_DEPRECATED_INCLUDES
|
| 1927 |
+
#if !defined(NPY_NO_DEPRECATED_API) || \
|
| 1928 |
+
(NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION)
|
| 1929 |
+
#include "npy_1_7_deprecated_api.h"
|
| 1930 |
+
#endif
|
| 1931 |
+
/*
|
| 1932 |
+
* There is no file npy_1_8_deprecated_api.h since there are no additional
|
| 1933 |
+
* deprecated API features in NumPy 1.8.
|
| 1934 |
+
*
|
| 1935 |
+
* Note to maintainers: insert code like the following in future NumPy
|
| 1936 |
+
* versions.
|
| 1937 |
+
*
|
| 1938 |
+
* #if !defined(NPY_NO_DEPRECATED_API) || \
|
| 1939 |
+
* (NPY_NO_DEPRECATED_API < NPY_1_9_API_VERSION)
|
| 1940 |
+
* #include "npy_1_9_deprecated_api.h"
|
| 1941 |
+
* #endif
|
| 1942 |
+
*/
|
| 1943 |
+
#undef NPY_DEPRECATED_INCLUDES
|
| 1944 |
+
|
| 1945 |
+
#endif /* NUMPY_CORE_INCLUDE_NUMPY_NDARRAYTYPES_H_ */
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/noprefix.h
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef NUMPY_CORE_INCLUDE_NUMPY_NOPREFIX_H_
|
| 2 |
+
#define NUMPY_CORE_INCLUDE_NUMPY_NOPREFIX_H_
|
| 3 |
+
|
| 4 |
+
/*
|
| 5 |
+
* You can directly include noprefix.h as a backward
|
| 6 |
+
* compatibility measure
|
| 7 |
+
*/
|
| 8 |
+
#ifndef NPY_NO_PREFIX
|
| 9 |
+
#include "ndarrayobject.h"
|
| 10 |
+
#include "npy_interrupt.h"
|
| 11 |
+
#endif
|
| 12 |
+
|
| 13 |
+
#define SIGSETJMP NPY_SIGSETJMP
|
| 14 |
+
#define SIGLONGJMP NPY_SIGLONGJMP
|
| 15 |
+
#define SIGJMP_BUF NPY_SIGJMP_BUF
|
| 16 |
+
|
| 17 |
+
#define MAX_DIMS NPY_MAXDIMS
|
| 18 |
+
|
| 19 |
+
#define longlong npy_longlong
|
| 20 |
+
#define ulonglong npy_ulonglong
|
| 21 |
+
#define Bool npy_bool
|
| 22 |
+
#define longdouble npy_longdouble
|
| 23 |
+
#define byte npy_byte
|
| 24 |
+
|
| 25 |
+
#ifndef _BSD_SOURCE
|
| 26 |
+
#define ushort npy_ushort
|
| 27 |
+
#define uint npy_uint
|
| 28 |
+
#define ulong npy_ulong
|
| 29 |
+
#endif
|
| 30 |
+
|
| 31 |
+
#define ubyte npy_ubyte
|
| 32 |
+
#define ushort npy_ushort
|
| 33 |
+
#define uint npy_uint
|
| 34 |
+
#define ulong npy_ulong
|
| 35 |
+
#define cfloat npy_cfloat
|
| 36 |
+
#define cdouble npy_cdouble
|
| 37 |
+
#define clongdouble npy_clongdouble
|
| 38 |
+
#define Int8 npy_int8
|
| 39 |
+
#define UInt8 npy_uint8
|
| 40 |
+
#define Int16 npy_int16
|
| 41 |
+
#define UInt16 npy_uint16
|
| 42 |
+
#define Int32 npy_int32
|
| 43 |
+
#define UInt32 npy_uint32
|
| 44 |
+
#define Int64 npy_int64
|
| 45 |
+
#define UInt64 npy_uint64
|
| 46 |
+
#define Int128 npy_int128
|
| 47 |
+
#define UInt128 npy_uint128
|
| 48 |
+
#define Int256 npy_int256
|
| 49 |
+
#define UInt256 npy_uint256
|
| 50 |
+
#define Float16 npy_float16
|
| 51 |
+
#define Complex32 npy_complex32
|
| 52 |
+
#define Float32 npy_float32
|
| 53 |
+
#define Complex64 npy_complex64
|
| 54 |
+
#define Float64 npy_float64
|
| 55 |
+
#define Complex128 npy_complex128
|
| 56 |
+
#define Float80 npy_float80
|
| 57 |
+
#define Complex160 npy_complex160
|
| 58 |
+
#define Float96 npy_float96
|
| 59 |
+
#define Complex192 npy_complex192
|
| 60 |
+
#define Float128 npy_float128
|
| 61 |
+
#define Complex256 npy_complex256
|
| 62 |
+
#define intp npy_intp
|
| 63 |
+
#define uintp npy_uintp
|
| 64 |
+
#define datetime npy_datetime
|
| 65 |
+
#define timedelta npy_timedelta
|
| 66 |
+
|
| 67 |
+
#define SIZEOF_LONGLONG NPY_SIZEOF_LONGLONG
|
| 68 |
+
#define SIZEOF_INTP NPY_SIZEOF_INTP
|
| 69 |
+
#define SIZEOF_UINTP NPY_SIZEOF_UINTP
|
| 70 |
+
#define SIZEOF_HALF NPY_SIZEOF_HALF
|
| 71 |
+
#define SIZEOF_LONGDOUBLE NPY_SIZEOF_LONGDOUBLE
|
| 72 |
+
#define SIZEOF_DATETIME NPY_SIZEOF_DATETIME
|
| 73 |
+
#define SIZEOF_TIMEDELTA NPY_SIZEOF_TIMEDELTA
|
| 74 |
+
|
| 75 |
+
#define LONGLONG_FMT NPY_LONGLONG_FMT
|
| 76 |
+
#define ULONGLONG_FMT NPY_ULONGLONG_FMT
|
| 77 |
+
#define LONGLONG_SUFFIX NPY_LONGLONG_SUFFIX
|
| 78 |
+
#define ULONGLONG_SUFFIX NPY_ULONGLONG_SUFFIX
|
| 79 |
+
|
| 80 |
+
#define MAX_INT8 127
|
| 81 |
+
#define MIN_INT8 -128
|
| 82 |
+
#define MAX_UINT8 255
|
| 83 |
+
#define MAX_INT16 32767
|
| 84 |
+
#define MIN_INT16 -32768
|
| 85 |
+
#define MAX_UINT16 65535
|
| 86 |
+
#define MAX_INT32 2147483647
|
| 87 |
+
#define MIN_INT32 (-MAX_INT32 - 1)
|
| 88 |
+
#define MAX_UINT32 4294967295U
|
| 89 |
+
#define MAX_INT64 LONGLONG_SUFFIX(9223372036854775807)
|
| 90 |
+
#define MIN_INT64 (-MAX_INT64 - LONGLONG_SUFFIX(1))
|
| 91 |
+
#define MAX_UINT64 ULONGLONG_SUFFIX(18446744073709551615)
|
| 92 |
+
#define MAX_INT128 LONGLONG_SUFFIX(85070591730234615865843651857942052864)
|
| 93 |
+
#define MIN_INT128 (-MAX_INT128 - LONGLONG_SUFFIX(1))
|
| 94 |
+
#define MAX_UINT128 ULONGLONG_SUFFIX(170141183460469231731687303715884105728)
|
| 95 |
+
#define MAX_INT256 LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)
|
| 96 |
+
#define MIN_INT256 (-MAX_INT256 - LONGLONG_SUFFIX(1))
|
| 97 |
+
#define MAX_UINT256 ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)
|
| 98 |
+
|
| 99 |
+
#define MAX_BYTE NPY_MAX_BYTE
|
| 100 |
+
#define MIN_BYTE NPY_MIN_BYTE
|
| 101 |
+
#define MAX_UBYTE NPY_MAX_UBYTE
|
| 102 |
+
#define MAX_SHORT NPY_MAX_SHORT
|
| 103 |
+
#define MIN_SHORT NPY_MIN_SHORT
|
| 104 |
+
#define MAX_USHORT NPY_MAX_USHORT
|
| 105 |
+
#define MAX_INT NPY_MAX_INT
|
| 106 |
+
#define MIN_INT NPY_MIN_INT
|
| 107 |
+
#define MAX_UINT NPY_MAX_UINT
|
| 108 |
+
#define MAX_LONG NPY_MAX_LONG
|
| 109 |
+
#define MIN_LONG NPY_MIN_LONG
|
| 110 |
+
#define MAX_ULONG NPY_MAX_ULONG
|
| 111 |
+
#define MAX_LONGLONG NPY_MAX_LONGLONG
|
| 112 |
+
#define MIN_LONGLONG NPY_MIN_LONGLONG
|
| 113 |
+
#define MAX_ULONGLONG NPY_MAX_ULONGLONG
|
| 114 |
+
#define MIN_DATETIME NPY_MIN_DATETIME
|
| 115 |
+
#define MAX_DATETIME NPY_MAX_DATETIME
|
| 116 |
+
#define MIN_TIMEDELTA NPY_MIN_TIMEDELTA
|
| 117 |
+
#define MAX_TIMEDELTA NPY_MAX_TIMEDELTA
|
| 118 |
+
|
| 119 |
+
#define BITSOF_BOOL NPY_BITSOF_BOOL
|
| 120 |
+
#define BITSOF_CHAR NPY_BITSOF_CHAR
|
| 121 |
+
#define BITSOF_SHORT NPY_BITSOF_SHORT
|
| 122 |
+
#define BITSOF_INT NPY_BITSOF_INT
|
| 123 |
+
#define BITSOF_LONG NPY_BITSOF_LONG
|
| 124 |
+
#define BITSOF_LONGLONG NPY_BITSOF_LONGLONG
|
| 125 |
+
#define BITSOF_HALF NPY_BITSOF_HALF
|
| 126 |
+
#define BITSOF_FLOAT NPY_BITSOF_FLOAT
|
| 127 |
+
#define BITSOF_DOUBLE NPY_BITSOF_DOUBLE
|
| 128 |
+
#define BITSOF_LONGDOUBLE NPY_BITSOF_LONGDOUBLE
|
| 129 |
+
#define BITSOF_DATETIME NPY_BITSOF_DATETIME
|
| 130 |
+
#define BITSOF_TIMEDELTA NPY_BITSOF_TIMEDELTA
|
| 131 |
+
|
| 132 |
+
#define _pya_malloc PyArray_malloc
|
| 133 |
+
#define _pya_free PyArray_free
|
| 134 |
+
#define _pya_realloc PyArray_realloc
|
| 135 |
+
|
| 136 |
+
#define BEGIN_THREADS_DEF NPY_BEGIN_THREADS_DEF
|
| 137 |
+
#define BEGIN_THREADS NPY_BEGIN_THREADS
|
| 138 |
+
#define END_THREADS NPY_END_THREADS
|
| 139 |
+
#define ALLOW_C_API_DEF NPY_ALLOW_C_API_DEF
|
| 140 |
+
#define ALLOW_C_API NPY_ALLOW_C_API
|
| 141 |
+
#define DISABLE_C_API NPY_DISABLE_C_API
|
| 142 |
+
|
| 143 |
+
#define PY_FAIL NPY_FAIL
|
| 144 |
+
#define PY_SUCCEED NPY_SUCCEED
|
| 145 |
+
|
| 146 |
+
#ifndef TRUE
|
| 147 |
+
#define TRUE NPY_TRUE
|
| 148 |
+
#endif
|
| 149 |
+
|
| 150 |
+
#ifndef FALSE
|
| 151 |
+
#define FALSE NPY_FALSE
|
| 152 |
+
#endif
|
| 153 |
+
|
| 154 |
+
#define LONGDOUBLE_FMT NPY_LONGDOUBLE_FMT
|
| 155 |
+
|
| 156 |
+
#define CONTIGUOUS NPY_CONTIGUOUS
|
| 157 |
+
#define C_CONTIGUOUS NPY_C_CONTIGUOUS
|
| 158 |
+
#define FORTRAN NPY_FORTRAN
|
| 159 |
+
#define F_CONTIGUOUS NPY_F_CONTIGUOUS
|
| 160 |
+
#define OWNDATA NPY_OWNDATA
|
| 161 |
+
#define FORCECAST NPY_FORCECAST
|
| 162 |
+
#define ENSURECOPY NPY_ENSURECOPY
|
| 163 |
+
#define ENSUREARRAY NPY_ENSUREARRAY
|
| 164 |
+
#define ELEMENTSTRIDES NPY_ELEMENTSTRIDES
|
| 165 |
+
#define ALIGNED NPY_ALIGNED
|
| 166 |
+
#define NOTSWAPPED NPY_NOTSWAPPED
|
| 167 |
+
#define WRITEABLE NPY_WRITEABLE
|
| 168 |
+
#define WRITEBACKIFCOPY NPY_ARRAY_WRITEBACKIFCOPY
|
| 169 |
+
#define ARR_HAS_DESCR NPY_ARR_HAS_DESCR
|
| 170 |
+
#define BEHAVED NPY_BEHAVED
|
| 171 |
+
#define BEHAVED_NS NPY_BEHAVED_NS
|
| 172 |
+
#define CARRAY NPY_CARRAY
|
| 173 |
+
#define CARRAY_RO NPY_CARRAY_RO
|
| 174 |
+
#define FARRAY NPY_FARRAY
|
| 175 |
+
#define FARRAY_RO NPY_FARRAY_RO
|
| 176 |
+
#define DEFAULT NPY_DEFAULT
|
| 177 |
+
#define IN_ARRAY NPY_IN_ARRAY
|
| 178 |
+
#define OUT_ARRAY NPY_OUT_ARRAY
|
| 179 |
+
#define INOUT_ARRAY NPY_INOUT_ARRAY
|
| 180 |
+
#define IN_FARRAY NPY_IN_FARRAY
|
| 181 |
+
#define OUT_FARRAY NPY_OUT_FARRAY
|
| 182 |
+
#define INOUT_FARRAY NPY_INOUT_FARRAY
|
| 183 |
+
#define UPDATE_ALL NPY_UPDATE_ALL
|
| 184 |
+
|
| 185 |
+
#define OWN_DATA NPY_OWNDATA
|
| 186 |
+
#define BEHAVED_FLAGS NPY_BEHAVED
|
| 187 |
+
#define BEHAVED_FLAGS_NS NPY_BEHAVED_NS
|
| 188 |
+
#define CARRAY_FLAGS_RO NPY_CARRAY_RO
|
| 189 |
+
#define CARRAY_FLAGS NPY_CARRAY
|
| 190 |
+
#define FARRAY_FLAGS NPY_FARRAY
|
| 191 |
+
#define FARRAY_FLAGS_RO NPY_FARRAY_RO
|
| 192 |
+
#define DEFAULT_FLAGS NPY_DEFAULT
|
| 193 |
+
#define UPDATE_ALL_FLAGS NPY_UPDATE_ALL_FLAGS
|
| 194 |
+
|
| 195 |
+
#ifndef MIN
|
| 196 |
+
#define MIN PyArray_MIN
|
| 197 |
+
#endif
|
| 198 |
+
#ifndef MAX
|
| 199 |
+
#define MAX PyArray_MAX
|
| 200 |
+
#endif
|
| 201 |
+
#define MAX_INTP NPY_MAX_INTP
|
| 202 |
+
#define MIN_INTP NPY_MIN_INTP
|
| 203 |
+
#define MAX_UINTP NPY_MAX_UINTP
|
| 204 |
+
#define INTP_FMT NPY_INTP_FMT
|
| 205 |
+
|
| 206 |
+
#ifndef PYPY_VERSION
|
| 207 |
+
#define REFCOUNT PyArray_REFCOUNT
|
| 208 |
+
#define MAX_ELSIZE NPY_MAX_ELSIZE
|
| 209 |
+
#endif
|
| 210 |
+
|
| 211 |
+
#endif /* NUMPY_CORE_INCLUDE_NUMPY_NOPREFIX_H_ */
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef NPY_DEPRECATED_INCLUDES
|
| 2 |
+
#error "Should never include npy_*_*_deprecated_api directly."
|
| 3 |
+
#endif
|
| 4 |
+
|
| 5 |
+
#ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_1_7_DEPRECATED_API_H_
|
| 6 |
+
#define NUMPY_CORE_INCLUDE_NUMPY_NPY_1_7_DEPRECATED_API_H_
|
| 7 |
+
|
| 8 |
+
/* Emit a warning if the user did not specifically request the old API */
|
| 9 |
+
#ifndef NPY_NO_DEPRECATED_API
|
| 10 |
+
#if defined(_WIN32)
|
| 11 |
+
#define _WARN___STR2__(x) #x
|
| 12 |
+
#define _WARN___STR1__(x) _WARN___STR2__(x)
|
| 13 |
+
#define _WARN___LOC__ __FILE__ "(" _WARN___STR1__(__LINE__) ") : Warning Msg: "
|
| 14 |
+
#pragma message(_WARN___LOC__"Using deprecated NumPy API, disable it with " \
|
| 15 |
+
"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION")
|
| 16 |
+
#else
|
| 17 |
+
#warning "Using deprecated NumPy API, disable it with " \
|
| 18 |
+
"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION"
|
| 19 |
+
#endif
|
| 20 |
+
#endif
|
| 21 |
+
|
| 22 |
+
/*
|
| 23 |
+
* This header exists to collect all dangerous/deprecated NumPy API
|
| 24 |
+
* as of NumPy 1.7.
|
| 25 |
+
*
|
| 26 |
+
* This is an attempt to remove bad API, the proliferation of macros,
|
| 27 |
+
* and namespace pollution currently produced by the NumPy headers.
|
| 28 |
+
*/
|
| 29 |
+
|
| 30 |
+
/* These array flags are deprecated as of NumPy 1.7 */
|
| 31 |
+
#define NPY_CONTIGUOUS NPY_ARRAY_C_CONTIGUOUS
|
| 32 |
+
#define NPY_FORTRAN NPY_ARRAY_F_CONTIGUOUS
|
| 33 |
+
|
| 34 |
+
/*
|
| 35 |
+
* The consistent NPY_ARRAY_* names which don't pollute the NPY_*
|
| 36 |
+
* namespace were added in NumPy 1.7.
|
| 37 |
+
*
|
| 38 |
+
* These versions of the carray flags are deprecated, but
|
| 39 |
+
* probably should only be removed after two releases instead of one.
|
| 40 |
+
*/
|
| 41 |
+
#define NPY_C_CONTIGUOUS NPY_ARRAY_C_CONTIGUOUS
|
| 42 |
+
#define NPY_F_CONTIGUOUS NPY_ARRAY_F_CONTIGUOUS
|
| 43 |
+
#define NPY_OWNDATA NPY_ARRAY_OWNDATA
|
| 44 |
+
#define NPY_FORCECAST NPY_ARRAY_FORCECAST
|
| 45 |
+
#define NPY_ENSURECOPY NPY_ARRAY_ENSURECOPY
|
| 46 |
+
#define NPY_ENSUREARRAY NPY_ARRAY_ENSUREARRAY
|
| 47 |
+
#define NPY_ELEMENTSTRIDES NPY_ARRAY_ELEMENTSTRIDES
|
| 48 |
+
#define NPY_ALIGNED NPY_ARRAY_ALIGNED
|
| 49 |
+
#define NPY_NOTSWAPPED NPY_ARRAY_NOTSWAPPED
|
| 50 |
+
#define NPY_WRITEABLE NPY_ARRAY_WRITEABLE
|
| 51 |
+
#define NPY_BEHAVED NPY_ARRAY_BEHAVED
|
| 52 |
+
#define NPY_BEHAVED_NS NPY_ARRAY_BEHAVED_NS
|
| 53 |
+
#define NPY_CARRAY NPY_ARRAY_CARRAY
|
| 54 |
+
#define NPY_CARRAY_RO NPY_ARRAY_CARRAY_RO
|
| 55 |
+
#define NPY_FARRAY NPY_ARRAY_FARRAY
|
| 56 |
+
#define NPY_FARRAY_RO NPY_ARRAY_FARRAY_RO
|
| 57 |
+
#define NPY_DEFAULT NPY_ARRAY_DEFAULT
|
| 58 |
+
#define NPY_IN_ARRAY NPY_ARRAY_IN_ARRAY
|
| 59 |
+
#define NPY_OUT_ARRAY NPY_ARRAY_OUT_ARRAY
|
| 60 |
+
#define NPY_INOUT_ARRAY NPY_ARRAY_INOUT_ARRAY
|
| 61 |
+
#define NPY_IN_FARRAY NPY_ARRAY_IN_FARRAY
|
| 62 |
+
#define NPY_OUT_FARRAY NPY_ARRAY_OUT_FARRAY
|
| 63 |
+
#define NPY_INOUT_FARRAY NPY_ARRAY_INOUT_FARRAY
|
| 64 |
+
#define NPY_UPDATE_ALL NPY_ARRAY_UPDATE_ALL
|
| 65 |
+
|
| 66 |
+
/* This way of accessing the default type is deprecated as of NumPy 1.7 */
|
| 67 |
+
#define PyArray_DEFAULT NPY_DEFAULT_TYPE
|
| 68 |
+
|
| 69 |
+
/* These DATETIME bits aren't used internally */
|
| 70 |
+
#define PyDataType_GetDatetimeMetaData(descr) \
|
| 71 |
+
((descr->metadata == NULL) ? NULL : \
|
| 72 |
+
((PyArray_DatetimeMetaData *)(PyCapsule_GetPointer( \
|
| 73 |
+
PyDict_GetItemString( \
|
| 74 |
+
descr->metadata, NPY_METADATA_DTSTR), NULL))))
|
| 75 |
+
|
| 76 |
+
/*
|
| 77 |
+
* Deprecated as of NumPy 1.7, this kind of shortcut doesn't
|
| 78 |
+
* belong in the public API.
|
| 79 |
+
*/
|
| 80 |
+
#define NPY_AO PyArrayObject
|
| 81 |
+
|
| 82 |
+
/*
|
| 83 |
+
* Deprecated as of NumPy 1.7, an all-lowercase macro doesn't
|
| 84 |
+
* belong in the public API.
|
| 85 |
+
*/
|
| 86 |
+
#define fortran fortran_
|
| 87 |
+
|
| 88 |
+
/*
|
| 89 |
+
* Deprecated as of NumPy 1.7, as it is a namespace-polluting
|
| 90 |
+
* macro.
|
| 91 |
+
*/
|
| 92 |
+
#define FORTRAN_IF PyArray_FORTRAN_IF
|
| 93 |
+
|
| 94 |
+
/* Deprecated as of NumPy 1.7, datetime64 uses c_metadata instead */
|
| 95 |
+
#define NPY_METADATA_DTSTR "__timeunit__"
|
| 96 |
+
|
| 97 |
+
/*
|
| 98 |
+
* Deprecated as of NumPy 1.7.
|
| 99 |
+
* The reasoning:
|
| 100 |
+
* - These are for datetime, but there's no datetime "namespace".
|
| 101 |
+
* - They just turn NPY_STR_<x> into "<x>", which is just
|
| 102 |
+
* making something simple be indirected.
|
| 103 |
+
*/
|
| 104 |
+
#define NPY_STR_Y "Y"
|
| 105 |
+
#define NPY_STR_M "M"
|
| 106 |
+
#define NPY_STR_W "W"
|
| 107 |
+
#define NPY_STR_D "D"
|
| 108 |
+
#define NPY_STR_h "h"
|
| 109 |
+
#define NPY_STR_m "m"
|
| 110 |
+
#define NPY_STR_s "s"
|
| 111 |
+
#define NPY_STR_ms "ms"
|
| 112 |
+
#define NPY_STR_us "us"
|
| 113 |
+
#define NPY_STR_ns "ns"
|
| 114 |
+
#define NPY_STR_ps "ps"
|
| 115 |
+
#define NPY_STR_fs "fs"
|
| 116 |
+
#define NPY_STR_as "as"
|
| 117 |
+
|
| 118 |
+
/*
|
| 119 |
+
* The macros in old_defines.h are Deprecated as of NumPy 1.7 and will be
|
| 120 |
+
* removed in the next major release.
|
| 121 |
+
*/
|
| 122 |
+
#include "old_defines.h"
|
| 123 |
+
|
| 124 |
+
#endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_1_7_DEPRECATED_API_H_ */
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/npy_3kcompat.h
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 1 |
+
/*
|
| 2 |
+
* This is a convenience header file providing compatibility utilities
|
| 3 |
+
* for supporting different minor versions of Python 3.
|
| 4 |
+
* It was originally used to support the transition from Python 2,
|
| 5 |
+
* hence the "3k" naming.
|
| 6 |
+
*
|
| 7 |
+
* If you want to use this for your own projects, it's recommended to make a
|
| 8 |
+
* copy of it. Although the stuff below is unlikely to change, we don't provide
|
| 9 |
+
* strong backwards compatibility guarantees at the moment.
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
#ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_3KCOMPAT_H_
|
| 13 |
+
#define NUMPY_CORE_INCLUDE_NUMPY_NPY_3KCOMPAT_H_
|
| 14 |
+
|
| 15 |
+
#include <Python.h>
|
| 16 |
+
#include <stdio.h>
|
| 17 |
+
|
| 18 |
+
#ifndef NPY_PY3K
|
| 19 |
+
#define NPY_PY3K 1
|
| 20 |
+
#endif
|
| 21 |
+
|
| 22 |
+
#include "numpy/npy_common.h"
|
| 23 |
+
#include "numpy/ndarrayobject.h"
|
| 24 |
+
|
| 25 |
+
#ifdef __cplusplus
|
| 26 |
+
extern "C" {
|
| 27 |
+
#endif
|
| 28 |
+
|
| 29 |
+
/*
|
| 30 |
+
* PyInt -> PyLong
|
| 31 |
+
*/
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
/*
|
| 35 |
+
* This is a renamed copy of the Python non-limited API function _PyLong_AsInt. It is
|
| 36 |
+
* included here because it is missing from the PyPy API. It completes the PyLong_As*
|
| 37 |
+
* group of functions and can be useful in replacing PyInt_Check.
|
| 38 |
+
*/
|
| 39 |
+
static inline int
|
| 40 |
+
Npy__PyLong_AsInt(PyObject *obj)
|
| 41 |
+
{
|
| 42 |
+
int overflow;
|
| 43 |
+
long result = PyLong_AsLongAndOverflow(obj, &overflow);
|
| 44 |
+
|
| 45 |
+
/* INT_MAX and INT_MIN are defined in Python.h */
|
| 46 |
+
if (overflow || result > INT_MAX || result < INT_MIN) {
|
| 47 |
+
/* XXX: could be cute and give a different
|
| 48 |
+
message for overflow == -1 */
|
| 49 |
+
PyErr_SetString(PyExc_OverflowError,
|
| 50 |
+
"Python int too large to convert to C int");
|
| 51 |
+
return -1;
|
| 52 |
+
}
|
| 53 |
+
return (int)result;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
#if defined(NPY_PY3K)
|
| 58 |
+
/* Return True only if the long fits in a C long */
|
| 59 |
+
static inline int PyInt_Check(PyObject *op) {
|
| 60 |
+
int overflow = 0;
|
| 61 |
+
if (!PyLong_Check(op)) {
|
| 62 |
+
return 0;
|
| 63 |
+
}
|
| 64 |
+
PyLong_AsLongAndOverflow(op, &overflow);
|
| 65 |
+
return (overflow == 0);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
#define PyInt_FromLong PyLong_FromLong
|
| 70 |
+
#define PyInt_AsLong PyLong_AsLong
|
| 71 |
+
#define PyInt_AS_LONG PyLong_AsLong
|
| 72 |
+
#define PyInt_AsSsize_t PyLong_AsSsize_t
|
| 73 |
+
#define PyNumber_Int PyNumber_Long
|
| 74 |
+
|
| 75 |
+
/* NOTE:
|
| 76 |
+
*
|
| 77 |
+
* Since the PyLong type is very different from the fixed-range PyInt,
|
| 78 |
+
* we don't define PyInt_Type -> PyLong_Type.
|
| 79 |
+
*/
|
| 80 |
+
#endif /* NPY_PY3K */
|
| 81 |
+
|
| 82 |
+
/* Py3 changes PySlice_GetIndicesEx' first argument's type to PyObject* */
|
| 83 |
+
#ifdef NPY_PY3K
|
| 84 |
+
# define NpySlice_GetIndicesEx PySlice_GetIndicesEx
|
| 85 |
+
#else
|
| 86 |
+
# define NpySlice_GetIndicesEx(op, nop, start, end, step, slicelength) \
|
| 87 |
+
PySlice_GetIndicesEx((PySliceObject *)op, nop, start, end, step, slicelength)
|
| 88 |
+
#endif
|
| 89 |
+
|
| 90 |
+
#if PY_VERSION_HEX < 0x030900a4
|
| 91 |
+
/* Introduced in https://github.com/python/cpython/commit/d2ec81a8c99796b51fb8c49b77a7fe369863226f */
|
| 92 |
+
#define Py_SET_TYPE(obj, type) ((Py_TYPE(obj) = (type)), (void)0)
|
| 93 |
+
/* Introduced in https://github.com/python/cpython/commit/b10dc3e7a11fcdb97e285882eba6da92594f90f9 */
|
| 94 |
+
#define Py_SET_SIZE(obj, size) ((Py_SIZE(obj) = (size)), (void)0)
|
| 95 |
+
/* Introduced in https://github.com/python/cpython/commit/c86a11221df7e37da389f9c6ce6e47ea22dc44ff */
|
| 96 |
+
#define Py_SET_REFCNT(obj, refcnt) ((Py_REFCNT(obj) = (refcnt)), (void)0)
|
| 97 |
+
#endif
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
#define Npy_EnterRecursiveCall(x) Py_EnterRecursiveCall(x)
|
| 101 |
+
|
| 102 |
+
/*
|
| 103 |
+
* PyString -> PyBytes
|
| 104 |
+
*/
|
| 105 |
+
|
| 106 |
+
#if defined(NPY_PY3K)
|
| 107 |
+
|
| 108 |
+
#define PyString_Type PyBytes_Type
|
| 109 |
+
#define PyString_Check PyBytes_Check
|
| 110 |
+
#define PyStringObject PyBytesObject
|
| 111 |
+
#define PyString_FromString PyBytes_FromString
|
| 112 |
+
#define PyString_FromStringAndSize PyBytes_FromStringAndSize
|
| 113 |
+
#define PyString_AS_STRING PyBytes_AS_STRING
|
| 114 |
+
#define PyString_AsStringAndSize PyBytes_AsStringAndSize
|
| 115 |
+
#define PyString_FromFormat PyBytes_FromFormat
|
| 116 |
+
#define PyString_Concat PyBytes_Concat
|
| 117 |
+
#define PyString_ConcatAndDel PyBytes_ConcatAndDel
|
| 118 |
+
#define PyString_AsString PyBytes_AsString
|
| 119 |
+
#define PyString_GET_SIZE PyBytes_GET_SIZE
|
| 120 |
+
#define PyString_Size PyBytes_Size
|
| 121 |
+
|
| 122 |
+
#define PyUString_Type PyUnicode_Type
|
| 123 |
+
#define PyUString_Check PyUnicode_Check
|
| 124 |
+
#define PyUStringObject PyUnicodeObject
|
| 125 |
+
#define PyUString_FromString PyUnicode_FromString
|
| 126 |
+
#define PyUString_FromStringAndSize PyUnicode_FromStringAndSize
|
| 127 |
+
#define PyUString_FromFormat PyUnicode_FromFormat
|
| 128 |
+
#define PyUString_Concat PyUnicode_Concat2
|
| 129 |
+
#define PyUString_ConcatAndDel PyUnicode_ConcatAndDel
|
| 130 |
+
#define PyUString_GET_SIZE PyUnicode_GET_SIZE
|
| 131 |
+
#define PyUString_Size PyUnicode_Size
|
| 132 |
+
#define PyUString_InternFromString PyUnicode_InternFromString
|
| 133 |
+
#define PyUString_Format PyUnicode_Format
|
| 134 |
+
|
| 135 |
+
#define PyBaseString_Check(obj) (PyUnicode_Check(obj))
|
| 136 |
+
|
| 137 |
+
#else
|
| 138 |
+
|
| 139 |
+
#define PyBytes_Type PyString_Type
|
| 140 |
+
#define PyBytes_Check PyString_Check
|
| 141 |
+
#define PyBytesObject PyStringObject
|
| 142 |
+
#define PyBytes_FromString PyString_FromString
|
| 143 |
+
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
|
| 144 |
+
#define PyBytes_AS_STRING PyString_AS_STRING
|
| 145 |
+
#define PyBytes_AsStringAndSize PyString_AsStringAndSize
|
| 146 |
+
#define PyBytes_FromFormat PyString_FromFormat
|
| 147 |
+
#define PyBytes_Concat PyString_Concat
|
| 148 |
+
#define PyBytes_ConcatAndDel PyString_ConcatAndDel
|
| 149 |
+
#define PyBytes_AsString PyString_AsString
|
| 150 |
+
#define PyBytes_GET_SIZE PyString_GET_SIZE
|
| 151 |
+
#define PyBytes_Size PyString_Size
|
| 152 |
+
|
| 153 |
+
#define PyUString_Type PyString_Type
|
| 154 |
+
#define PyUString_Check PyString_Check
|
| 155 |
+
#define PyUStringObject PyStringObject
|
| 156 |
+
#define PyUString_FromString PyString_FromString
|
| 157 |
+
#define PyUString_FromStringAndSize PyString_FromStringAndSize
|
| 158 |
+
#define PyUString_FromFormat PyString_FromFormat
|
| 159 |
+
#define PyUString_Concat PyString_Concat
|
| 160 |
+
#define PyUString_ConcatAndDel PyString_ConcatAndDel
|
| 161 |
+
#define PyUString_GET_SIZE PyString_GET_SIZE
|
| 162 |
+
#define PyUString_Size PyString_Size
|
| 163 |
+
#define PyUString_InternFromString PyString_InternFromString
|
| 164 |
+
#define PyUString_Format PyString_Format
|
| 165 |
+
|
| 166 |
+
#define PyBaseString_Check(obj) (PyBytes_Check(obj) || PyUnicode_Check(obj))
|
| 167 |
+
|
| 168 |
+
#endif /* NPY_PY3K */
|
| 169 |
+
|
| 170 |
+
/*
|
| 171 |
+
* Macros to protect CRT calls against instant termination when passed an
|
| 172 |
+
* invalid parameter (https://bugs.python.org/issue23524).
|
| 173 |
+
*/
|
| 174 |
+
#if defined _MSC_VER && _MSC_VER >= 1900
|
| 175 |
+
|
| 176 |
+
#include <stdlib.h>
|
| 177 |
+
|
| 178 |
+
extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
|
| 179 |
+
#define NPY_BEGIN_SUPPRESS_IPH { _invalid_parameter_handler _Py_old_handler = \
|
| 180 |
+
_set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
|
| 181 |
+
#define NPY_END_SUPPRESS_IPH _set_thread_local_invalid_parameter_handler(_Py_old_handler); }
|
| 182 |
+
|
| 183 |
+
#else
|
| 184 |
+
|
| 185 |
+
#define NPY_BEGIN_SUPPRESS_IPH
|
| 186 |
+
#define NPY_END_SUPPRESS_IPH
|
| 187 |
+
|
| 188 |
+
#endif /* _MSC_VER >= 1900 */
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
static inline void
|
| 192 |
+
PyUnicode_ConcatAndDel(PyObject **left, PyObject *right)
|
| 193 |
+
{
|
| 194 |
+
Py_SETREF(*left, PyUnicode_Concat(*left, right));
|
| 195 |
+
Py_DECREF(right);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
static inline void
|
| 199 |
+
PyUnicode_Concat2(PyObject **left, PyObject *right)
|
| 200 |
+
{
|
| 201 |
+
Py_SETREF(*left, PyUnicode_Concat(*left, right));
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
/*
|
| 205 |
+
* PyFile_* compatibility
|
| 206 |
+
*/
|
| 207 |
+
|
| 208 |
+
/*
|
| 209 |
+
* Get a FILE* handle to the file represented by the Python object
|
| 210 |
+
*/
|
| 211 |
+
static inline FILE*
|
| 212 |
+
npy_PyFile_Dup2(PyObject *file, char *mode, npy_off_t *orig_pos)
|
| 213 |
+
{
|
| 214 |
+
int fd, fd2, unbuf;
|
| 215 |
+
Py_ssize_t fd2_tmp;
|
| 216 |
+
PyObject *ret, *os, *io, *io_raw;
|
| 217 |
+
npy_off_t pos;
|
| 218 |
+
FILE *handle;
|
| 219 |
+
|
| 220 |
+
/* For Python 2 PyFileObject, use PyFile_AsFile */
|
| 221 |
+
#if !defined(NPY_PY3K)
|
| 222 |
+
if (PyFile_Check(file)) {
|
| 223 |
+
return PyFile_AsFile(file);
|
| 224 |
+
}
|
| 225 |
+
#endif
|
| 226 |
+
|
| 227 |
+
/* Flush first to ensure things end up in the file in the correct order */
|
| 228 |
+
ret = PyObject_CallMethod(file, "flush", "");
|
| 229 |
+
if (ret == NULL) {
|
| 230 |
+
return NULL;
|
| 231 |
+
}
|
| 232 |
+
Py_DECREF(ret);
|
| 233 |
+
fd = PyObject_AsFileDescriptor(file);
|
| 234 |
+
if (fd == -1) {
|
| 235 |
+
return NULL;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
/*
|
| 239 |
+
* The handle needs to be dup'd because we have to call fclose
|
| 240 |
+
* at the end
|
| 241 |
+
*/
|
| 242 |
+
os = PyImport_ImportModule("os");
|
| 243 |
+
if (os == NULL) {
|
| 244 |
+
return NULL;
|
| 245 |
+
}
|
| 246 |
+
ret = PyObject_CallMethod(os, "dup", "i", fd);
|
| 247 |
+
Py_DECREF(os);
|
| 248 |
+
if (ret == NULL) {
|
| 249 |
+
return NULL;
|
| 250 |
+
}
|
| 251 |
+
fd2_tmp = PyNumber_AsSsize_t(ret, PyExc_IOError);
|
| 252 |
+
Py_DECREF(ret);
|
| 253 |
+
if (fd2_tmp == -1 && PyErr_Occurred()) {
|
| 254 |
+
return NULL;
|
| 255 |
+
}
|
| 256 |
+
if (fd2_tmp < INT_MIN || fd2_tmp > INT_MAX) {
|
| 257 |
+
PyErr_SetString(PyExc_IOError,
|
| 258 |
+
"Getting an 'int' from os.dup() failed");
|
| 259 |
+
return NULL;
|
| 260 |
+
}
|
| 261 |
+
fd2 = (int)fd2_tmp;
|
| 262 |
+
|
| 263 |
+
/* Convert to FILE* handle */
|
| 264 |
+
#ifdef _WIN32
|
| 265 |
+
NPY_BEGIN_SUPPRESS_IPH
|
| 266 |
+
handle = _fdopen(fd2, mode);
|
| 267 |
+
NPY_END_SUPPRESS_IPH
|
| 268 |
+
#else
|
| 269 |
+
handle = fdopen(fd2, mode);
|
| 270 |
+
#endif
|
| 271 |
+
if (handle == NULL) {
|
| 272 |
+
PyErr_SetString(PyExc_IOError,
|
| 273 |
+
"Getting a FILE* from a Python file object via "
|
| 274 |
+
"_fdopen failed. If you built NumPy, you probably "
|
| 275 |
+
"linked with the wrong debug/release runtime");
|
| 276 |
+
return NULL;
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
/* Record the original raw file handle position */
|
| 280 |
+
*orig_pos = npy_ftell(handle);
|
| 281 |
+
if (*orig_pos == -1) {
|
| 282 |
+
/* The io module is needed to determine if buffering is used */
|
| 283 |
+
io = PyImport_ImportModule("io");
|
| 284 |
+
if (io == NULL) {
|
| 285 |
+
fclose(handle);
|
| 286 |
+
return NULL;
|
| 287 |
+
}
|
| 288 |
+
/* File object instances of RawIOBase are unbuffered */
|
| 289 |
+
io_raw = PyObject_GetAttrString(io, "RawIOBase");
|
| 290 |
+
Py_DECREF(io);
|
| 291 |
+
if (io_raw == NULL) {
|
| 292 |
+
fclose(handle);
|
| 293 |
+
return NULL;
|
| 294 |
+
}
|
| 295 |
+
unbuf = PyObject_IsInstance(file, io_raw);
|
| 296 |
+
Py_DECREF(io_raw);
|
| 297 |
+
if (unbuf == 1) {
|
| 298 |
+
/* Succeed if the IO is unbuffered */
|
| 299 |
+
return handle;
|
| 300 |
+
}
|
| 301 |
+
else {
|
| 302 |
+
PyErr_SetString(PyExc_IOError, "obtaining file position failed");
|
| 303 |
+
fclose(handle);
|
| 304 |
+
return NULL;
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
/* Seek raw handle to the Python-side position */
|
| 309 |
+
ret = PyObject_CallMethod(file, "tell", "");
|
| 310 |
+
if (ret == NULL) {
|
| 311 |
+
fclose(handle);
|
| 312 |
+
return NULL;
|
| 313 |
+
}
|
| 314 |
+
pos = PyLong_AsLongLong(ret);
|
| 315 |
+
Py_DECREF(ret);
|
| 316 |
+
if (PyErr_Occurred()) {
|
| 317 |
+
fclose(handle);
|
| 318 |
+
return NULL;
|
| 319 |
+
}
|
| 320 |
+
if (npy_fseek(handle, pos, SEEK_SET) == -1) {
|
| 321 |
+
PyErr_SetString(PyExc_IOError, "seeking file failed");
|
| 322 |
+
fclose(handle);
|
| 323 |
+
return NULL;
|
| 324 |
+
}
|
| 325 |
+
return handle;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
/*
|
| 329 |
+
* Close the dup-ed file handle, and seek the Python one to the current position
|
| 330 |
+
*/
|
| 331 |
+
static inline int
|
| 332 |
+
npy_PyFile_DupClose2(PyObject *file, FILE* handle, npy_off_t orig_pos)
|
| 333 |
+
{
|
| 334 |
+
int fd, unbuf;
|
| 335 |
+
PyObject *ret, *io, *io_raw;
|
| 336 |
+
npy_off_t position;
|
| 337 |
+
|
| 338 |
+
/* For Python 2 PyFileObject, do nothing */
|
| 339 |
+
#if !defined(NPY_PY3K)
|
| 340 |
+
if (PyFile_Check(file)) {
|
| 341 |
+
return 0;
|
| 342 |
+
}
|
| 343 |
+
#endif
|
| 344 |
+
|
| 345 |
+
position = npy_ftell(handle);
|
| 346 |
+
|
| 347 |
+
/* Close the FILE* handle */
|
| 348 |
+
fclose(handle);
|
| 349 |
+
|
| 350 |
+
/*
|
| 351 |
+
* Restore original file handle position, in order to not confuse
|
| 352 |
+
* Python-side data structures
|
| 353 |
+
*/
|
| 354 |
+
fd = PyObject_AsFileDescriptor(file);
|
| 355 |
+
if (fd == -1) {
|
| 356 |
+
return -1;
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
if (npy_lseek(fd, orig_pos, SEEK_SET) == -1) {
|
| 360 |
+
|
| 361 |
+
/* The io module is needed to determine if buffering is used */
|
| 362 |
+
io = PyImport_ImportModule("io");
|
| 363 |
+
if (io == NULL) {
|
| 364 |
+
return -1;
|
| 365 |
+
}
|
| 366 |
+
/* File object instances of RawIOBase are unbuffered */
|
| 367 |
+
io_raw = PyObject_GetAttrString(io, "RawIOBase");
|
| 368 |
+
Py_DECREF(io);
|
| 369 |
+
if (io_raw == NULL) {
|
| 370 |
+
return -1;
|
| 371 |
+
}
|
| 372 |
+
unbuf = PyObject_IsInstance(file, io_raw);
|
| 373 |
+
Py_DECREF(io_raw);
|
| 374 |
+
if (unbuf == 1) {
|
| 375 |
+
/* Succeed if the IO is unbuffered */
|
| 376 |
+
return 0;
|
| 377 |
+
}
|
| 378 |
+
else {
|
| 379 |
+
PyErr_SetString(PyExc_IOError, "seeking file failed");
|
| 380 |
+
return -1;
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
if (position == -1) {
|
| 385 |
+
PyErr_SetString(PyExc_IOError, "obtaining file position failed");
|
| 386 |
+
return -1;
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
/* Seek Python-side handle to the FILE* handle position */
|
| 390 |
+
ret = PyObject_CallMethod(file, "seek", NPY_OFF_T_PYFMT "i", position, 0);
|
| 391 |
+
if (ret == NULL) {
|
| 392 |
+
return -1;
|
| 393 |
+
}
|
| 394 |
+
Py_DECREF(ret);
|
| 395 |
+
return 0;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
static inline int
|
| 399 |
+
npy_PyFile_Check(PyObject *file)
|
| 400 |
+
{
|
| 401 |
+
int fd;
|
| 402 |
+
/* For Python 2, check if it is a PyFileObject */
|
| 403 |
+
#if !defined(NPY_PY3K)
|
| 404 |
+
if (PyFile_Check(file)) {
|
| 405 |
+
return 1;
|
| 406 |
+
}
|
| 407 |
+
#endif
|
| 408 |
+
fd = PyObject_AsFileDescriptor(file);
|
| 409 |
+
if (fd == -1) {
|
| 410 |
+
PyErr_Clear();
|
| 411 |
+
return 0;
|
| 412 |
+
}
|
| 413 |
+
return 1;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
static inline PyObject*
|
| 417 |
+
npy_PyFile_OpenFile(PyObject *filename, const char *mode)
|
| 418 |
+
{
|
| 419 |
+
PyObject *open;
|
| 420 |
+
open = PyDict_GetItemString(PyEval_GetBuiltins(), "open");
|
| 421 |
+
if (open == NULL) {
|
| 422 |
+
return NULL;
|
| 423 |
+
}
|
| 424 |
+
return PyObject_CallFunction(open, "Os", filename, mode);
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
static inline int
|
| 428 |
+
npy_PyFile_CloseFile(PyObject *file)
|
| 429 |
+
{
|
| 430 |
+
PyObject *ret;
|
| 431 |
+
|
| 432 |
+
ret = PyObject_CallMethod(file, "close", NULL);
|
| 433 |
+
if (ret == NULL) {
|
| 434 |
+
return -1;
|
| 435 |
+
}
|
| 436 |
+
Py_DECREF(ret);
|
| 437 |
+
return 0;
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
/* This is a copy of _PyErr_ChainExceptions
|
| 442 |
+
*/
|
| 443 |
+
static inline void
|
| 444 |
+
npy_PyErr_ChainExceptions(PyObject *exc, PyObject *val, PyObject *tb)
|
| 445 |
+
{
|
| 446 |
+
if (exc == NULL)
|
| 447 |
+
return;
|
| 448 |
+
|
| 449 |
+
if (PyErr_Occurred()) {
|
| 450 |
+
/* only py3 supports this anyway */
|
| 451 |
+
#ifdef NPY_PY3K
|
| 452 |
+
PyObject *exc2, *val2, *tb2;
|
| 453 |
+
PyErr_Fetch(&exc2, &val2, &tb2);
|
| 454 |
+
PyErr_NormalizeException(&exc, &val, &tb);
|
| 455 |
+
if (tb != NULL) {
|
| 456 |
+
PyException_SetTraceback(val, tb);
|
| 457 |
+
Py_DECREF(tb);
|
| 458 |
+
}
|
| 459 |
+
Py_DECREF(exc);
|
| 460 |
+
PyErr_NormalizeException(&exc2, &val2, &tb2);
|
| 461 |
+
PyException_SetContext(val2, val);
|
| 462 |
+
PyErr_Restore(exc2, val2, tb2);
|
| 463 |
+
#endif
|
| 464 |
+
}
|
| 465 |
+
else {
|
| 466 |
+
PyErr_Restore(exc, val, tb);
|
| 467 |
+
}
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
/* This is a copy of _PyErr_ChainExceptions, with:
|
| 472 |
+
* - a minimal implementation for python 2
|
| 473 |
+
* - __cause__ used instead of __context__
|
| 474 |
+
*/
|
| 475 |
+
static inline void
|
| 476 |
+
npy_PyErr_ChainExceptionsCause(PyObject *exc, PyObject *val, PyObject *tb)
|
| 477 |
+
{
|
| 478 |
+
if (exc == NULL)
|
| 479 |
+
return;
|
| 480 |
+
|
| 481 |
+
if (PyErr_Occurred()) {
|
| 482 |
+
/* only py3 supports this anyway */
|
| 483 |
+
#ifdef NPY_PY3K
|
| 484 |
+
PyObject *exc2, *val2, *tb2;
|
| 485 |
+
PyErr_Fetch(&exc2, &val2, &tb2);
|
| 486 |
+
PyErr_NormalizeException(&exc, &val, &tb);
|
| 487 |
+
if (tb != NULL) {
|
| 488 |
+
PyException_SetTraceback(val, tb);
|
| 489 |
+
Py_DECREF(tb);
|
| 490 |
+
}
|
| 491 |
+
Py_DECREF(exc);
|
| 492 |
+
PyErr_NormalizeException(&exc2, &val2, &tb2);
|
| 493 |
+
PyException_SetCause(val2, val);
|
| 494 |
+
PyErr_Restore(exc2, val2, tb2);
|
| 495 |
+
#endif
|
| 496 |
+
}
|
| 497 |
+
else {
|
| 498 |
+
PyErr_Restore(exc, val, tb);
|
| 499 |
+
}
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
/*
|
| 503 |
+
* PyObject_Cmp
|
| 504 |
+
*/
|
| 505 |
+
#if defined(NPY_PY3K)
|
| 506 |
+
static inline int
|
| 507 |
+
PyObject_Cmp(PyObject *i1, PyObject *i2, int *cmp)
|
| 508 |
+
{
|
| 509 |
+
int v;
|
| 510 |
+
v = PyObject_RichCompareBool(i1, i2, Py_LT);
|
| 511 |
+
if (v == 1) {
|
| 512 |
+
*cmp = -1;
|
| 513 |
+
return 1;
|
| 514 |
+
}
|
| 515 |
+
else if (v == -1) {
|
| 516 |
+
return -1;
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
v = PyObject_RichCompareBool(i1, i2, Py_GT);
|
| 520 |
+
if (v == 1) {
|
| 521 |
+
*cmp = 1;
|
| 522 |
+
return 1;
|
| 523 |
+
}
|
| 524 |
+
else if (v == -1) {
|
| 525 |
+
return -1;
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
v = PyObject_RichCompareBool(i1, i2, Py_EQ);
|
| 529 |
+
if (v == 1) {
|
| 530 |
+
*cmp = 0;
|
| 531 |
+
return 1;
|
| 532 |
+
}
|
| 533 |
+
else {
|
| 534 |
+
*cmp = 0;
|
| 535 |
+
return -1;
|
| 536 |
+
}
|
| 537 |
+
}
|
| 538 |
+
#endif
|
| 539 |
+
|
| 540 |
+
/*
|
| 541 |
+
* PyCObject functions adapted to PyCapsules.
|
| 542 |
+
*
|
| 543 |
+
* The main job here is to get rid of the improved error handling
|
| 544 |
+
* of PyCapsules. It's a shame...
|
| 545 |
+
*/
|
| 546 |
+
static inline PyObject *
|
| 547 |
+
NpyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *))
|
| 548 |
+
{
|
| 549 |
+
PyObject *ret = PyCapsule_New(ptr, NULL, dtor);
|
| 550 |
+
if (ret == NULL) {
|
| 551 |
+
PyErr_Clear();
|
| 552 |
+
}
|
| 553 |
+
return ret;
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
static inline PyObject *
|
| 557 |
+
NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, void (*dtor)(PyObject *))
|
| 558 |
+
{
|
| 559 |
+
PyObject *ret = NpyCapsule_FromVoidPtr(ptr, dtor);
|
| 560 |
+
if (ret != NULL && PyCapsule_SetContext(ret, context) != 0) {
|
| 561 |
+
PyErr_Clear();
|
| 562 |
+
Py_DECREF(ret);
|
| 563 |
+
ret = NULL;
|
| 564 |
+
}
|
| 565 |
+
return ret;
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
static inline void *
|
| 569 |
+
NpyCapsule_AsVoidPtr(PyObject *obj)
|
| 570 |
+
{
|
| 571 |
+
void *ret = PyCapsule_GetPointer(obj, NULL);
|
| 572 |
+
if (ret == NULL) {
|
| 573 |
+
PyErr_Clear();
|
| 574 |
+
}
|
| 575 |
+
return ret;
|
| 576 |
+
}
|
| 577 |
+
|
| 578 |
+
static inline void *
|
| 579 |
+
NpyCapsule_GetDesc(PyObject *obj)
|
| 580 |
+
{
|
| 581 |
+
return PyCapsule_GetContext(obj);
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
static inline int
|
| 585 |
+
NpyCapsule_Check(PyObject *ptr)
|
| 586 |
+
{
|
| 587 |
+
return PyCapsule_CheckExact(ptr);
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
#ifdef __cplusplus
|
| 591 |
+
}
|
| 592 |
+
#endif
|
| 593 |
+
|
| 594 |
+
|
| 595 |
+
#endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_3KCOMPAT_H_ */
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/npy_common.h
ADDED
|
@@ -0,0 +1,1086 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_COMMON_H_
|
| 2 |
+
#define NUMPY_CORE_INCLUDE_NUMPY_NPY_COMMON_H_
|
| 3 |
+
|
| 4 |
+
/* need Python.h for npy_intp, npy_uintp */
|
| 5 |
+
#include <Python.h>
|
| 6 |
+
|
| 7 |
+
/* numpconfig.h is auto-generated */
|
| 8 |
+
#include "numpyconfig.h"
|
| 9 |
+
#ifdef HAVE_NPY_CONFIG_H
|
| 10 |
+
#include <npy_config.h>
|
| 11 |
+
#endif
|
| 12 |
+
|
| 13 |
+
/*
|
| 14 |
+
* using static inline modifiers when defining npy_math functions
|
| 15 |
+
* allows the compiler to make optimizations when possible
|
| 16 |
+
*/
|
| 17 |
+
#ifndef NPY_INLINE_MATH
|
| 18 |
+
#if defined(NPY_INTERNAL_BUILD) && NPY_INTERNAL_BUILD
|
| 19 |
+
#define NPY_INLINE_MATH 1
|
| 20 |
+
#else
|
| 21 |
+
#define NPY_INLINE_MATH 0
|
| 22 |
+
#endif
|
| 23 |
+
#endif
|
| 24 |
+
|
| 25 |
+
/*
|
| 26 |
+
* gcc does not unroll even with -O3
|
| 27 |
+
* use with care, unrolling on modern cpus rarely speeds things up
|
| 28 |
+
*/
|
| 29 |
+
#ifdef HAVE_ATTRIBUTE_OPTIMIZE_UNROLL_LOOPS
|
| 30 |
+
#define NPY_GCC_UNROLL_LOOPS \
|
| 31 |
+
__attribute__((optimize("unroll-loops")))
|
| 32 |
+
#else
|
| 33 |
+
#define NPY_GCC_UNROLL_LOOPS
|
| 34 |
+
#endif
|
| 35 |
+
|
| 36 |
+
/* highest gcc optimization level, enabled autovectorizer */
|
| 37 |
+
#ifdef HAVE_ATTRIBUTE_OPTIMIZE_OPT_3
|
| 38 |
+
#define NPY_GCC_OPT_3 __attribute__((optimize("O3")))
|
| 39 |
+
#else
|
| 40 |
+
#define NPY_GCC_OPT_3
|
| 41 |
+
#endif
|
| 42 |
+
|
| 43 |
+
/*
|
| 44 |
+
* mark an argument (starting from 1) that must not be NULL and is not checked
|
| 45 |
+
* DO NOT USE IF FUNCTION CHECKS FOR NULL!! the compiler will remove the check
|
| 46 |
+
*/
|
| 47 |
+
#ifdef HAVE_ATTRIBUTE_NONNULL
|
| 48 |
+
#define NPY_GCC_NONNULL(n) __attribute__((nonnull(n)))
|
| 49 |
+
#else
|
| 50 |
+
#define NPY_GCC_NONNULL(n)
|
| 51 |
+
#endif
|
| 52 |
+
|
| 53 |
+
/*
|
| 54 |
+
* give a hint to the compiler which branch is more likely or unlikely
|
| 55 |
+
* to occur, e.g. rare error cases:
|
| 56 |
+
*
|
| 57 |
+
* if (NPY_UNLIKELY(failure == 0))
|
| 58 |
+
* return NULL;
|
| 59 |
+
*
|
| 60 |
+
* the double !! is to cast the expression (e.g. NULL) to a boolean required by
|
| 61 |
+
* the intrinsic
|
| 62 |
+
*/
|
| 63 |
+
#ifdef HAVE___BUILTIN_EXPECT
|
| 64 |
+
#define NPY_LIKELY(x) __builtin_expect(!!(x), 1)
|
| 65 |
+
#define NPY_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
| 66 |
+
#else
|
| 67 |
+
#define NPY_LIKELY(x) (x)
|
| 68 |
+
#define NPY_UNLIKELY(x) (x)
|
| 69 |
+
#endif
|
| 70 |
+
|
| 71 |
+
#ifdef HAVE___BUILTIN_PREFETCH
|
| 72 |
+
/* unlike _mm_prefetch also works on non-x86 */
|
| 73 |
+
#define NPY_PREFETCH(x, rw, loc) __builtin_prefetch((x), (rw), (loc))
|
| 74 |
+
#else
|
| 75 |
+
#ifdef NPY_HAVE_SSE
|
| 76 |
+
/* _MM_HINT_ET[01] (rw = 1) unsupported, only available in gcc >= 4.9 */
|
| 77 |
+
#define NPY_PREFETCH(x, rw, loc) _mm_prefetch((x), loc == 0 ? _MM_HINT_NTA : \
|
| 78 |
+
(loc == 1 ? _MM_HINT_T2 : \
|
| 79 |
+
(loc == 2 ? _MM_HINT_T1 : \
|
| 80 |
+
(loc == 3 ? _MM_HINT_T0 : -1))))
|
| 81 |
+
#else
|
| 82 |
+
#define NPY_PREFETCH(x, rw,loc)
|
| 83 |
+
#endif
|
| 84 |
+
#endif
|
| 85 |
+
|
| 86 |
+
/* `NPY_INLINE` kept for backwards compatibility; use `inline` instead */
|
| 87 |
+
#if defined(_MSC_VER) && !defined(__clang__)
|
| 88 |
+
#define NPY_INLINE __inline
|
| 89 |
+
/* clang included here to handle clang-cl on Windows */
|
| 90 |
+
#elif defined(__GNUC__) || defined(__clang__)
|
| 91 |
+
#if defined(__STRICT_ANSI__)
|
| 92 |
+
#define NPY_INLINE __inline__
|
| 93 |
+
#else
|
| 94 |
+
#define NPY_INLINE inline
|
| 95 |
+
#endif
|
| 96 |
+
#else
|
| 97 |
+
#define NPY_INLINE
|
| 98 |
+
#endif
|
| 99 |
+
|
| 100 |
+
#ifdef _MSC_VER
|
| 101 |
+
#define NPY_FINLINE static __forceinline
|
| 102 |
+
#elif defined(__GNUC__)
|
| 103 |
+
#define NPY_FINLINE static inline __attribute__((always_inline))
|
| 104 |
+
#else
|
| 105 |
+
#define NPY_FINLINE static
|
| 106 |
+
#endif
|
| 107 |
+
|
| 108 |
+
#if defined(_MSC_VER)
|
| 109 |
+
#define NPY_NOINLINE static __declspec(noinline)
|
| 110 |
+
#elif defined(__GNUC__) || defined(__clang__)
|
| 111 |
+
#define NPY_NOINLINE static __attribute__((noinline))
|
| 112 |
+
#else
|
| 113 |
+
#define NPY_NOINLINE static
|
| 114 |
+
#endif
|
| 115 |
+
|
| 116 |
+
#ifdef HAVE___THREAD
|
| 117 |
+
#define NPY_TLS __thread
|
| 118 |
+
#else
|
| 119 |
+
#ifdef HAVE___DECLSPEC_THREAD_
|
| 120 |
+
#define NPY_TLS __declspec(thread)
|
| 121 |
+
#else
|
| 122 |
+
#define NPY_TLS
|
| 123 |
+
#endif
|
| 124 |
+
#endif
|
| 125 |
+
|
| 126 |
+
#ifdef WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE
|
| 127 |
+
#define NPY_RETURNS_BORROWED_REF \
|
| 128 |
+
__attribute__((cpychecker_returns_borrowed_ref))
|
| 129 |
+
#else
|
| 130 |
+
#define NPY_RETURNS_BORROWED_REF
|
| 131 |
+
#endif
|
| 132 |
+
|
| 133 |
+
#ifdef WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE
|
| 134 |
+
#define NPY_STEALS_REF_TO_ARG(n) \
|
| 135 |
+
__attribute__((cpychecker_steals_reference_to_arg(n)))
|
| 136 |
+
#else
|
| 137 |
+
#define NPY_STEALS_REF_TO_ARG(n)
|
| 138 |
+
#endif
|
| 139 |
+
|
| 140 |
+
/* 64 bit file position support, also on win-amd64. Issue gh-2256 */
|
| 141 |
+
#if defined(_MSC_VER) && defined(_WIN64) && (_MSC_VER > 1400) || \
|
| 142 |
+
defined(__MINGW32__) || defined(__MINGW64__)
|
| 143 |
+
#include <io.h>
|
| 144 |
+
|
| 145 |
+
#define npy_fseek _fseeki64
|
| 146 |
+
#define npy_ftell _ftelli64
|
| 147 |
+
#define npy_lseek _lseeki64
|
| 148 |
+
#define npy_off_t npy_int64
|
| 149 |
+
|
| 150 |
+
#if NPY_SIZEOF_INT == 8
|
| 151 |
+
#define NPY_OFF_T_PYFMT "i"
|
| 152 |
+
#elif NPY_SIZEOF_LONG == 8
|
| 153 |
+
#define NPY_OFF_T_PYFMT "l"
|
| 154 |
+
#elif NPY_SIZEOF_LONGLONG == 8
|
| 155 |
+
#define NPY_OFF_T_PYFMT "L"
|
| 156 |
+
#else
|
| 157 |
+
#error Unsupported size for type off_t
|
| 158 |
+
#endif
|
| 159 |
+
#else
|
| 160 |
+
#ifdef HAVE_FSEEKO
|
| 161 |
+
#define npy_fseek fseeko
|
| 162 |
+
#else
|
| 163 |
+
#define npy_fseek fseek
|
| 164 |
+
#endif
|
| 165 |
+
#ifdef HAVE_FTELLO
|
| 166 |
+
#define npy_ftell ftello
|
| 167 |
+
#else
|
| 168 |
+
#define npy_ftell ftell
|
| 169 |
+
#endif
|
| 170 |
+
#include <sys/types.h>
|
| 171 |
+
#ifndef _WIN32
|
| 172 |
+
#include <unistd.h>
|
| 173 |
+
#endif
|
| 174 |
+
#define npy_lseek lseek
|
| 175 |
+
#define npy_off_t off_t
|
| 176 |
+
|
| 177 |
+
#if NPY_SIZEOF_OFF_T == NPY_SIZEOF_SHORT
|
| 178 |
+
#define NPY_OFF_T_PYFMT "h"
|
| 179 |
+
#elif NPY_SIZEOF_OFF_T == NPY_SIZEOF_INT
|
| 180 |
+
#define NPY_OFF_T_PYFMT "i"
|
| 181 |
+
#elif NPY_SIZEOF_OFF_T == NPY_SIZEOF_LONG
|
| 182 |
+
#define NPY_OFF_T_PYFMT "l"
|
| 183 |
+
#elif NPY_SIZEOF_OFF_T == NPY_SIZEOF_LONGLONG
|
| 184 |
+
#define NPY_OFF_T_PYFMT "L"
|
| 185 |
+
#else
|
| 186 |
+
#error Unsupported size for type off_t
|
| 187 |
+
#endif
|
| 188 |
+
#endif
|
| 189 |
+
|
| 190 |
+
/* enums for detected endianness */
|
| 191 |
+
enum {
|
| 192 |
+
NPY_CPU_UNKNOWN_ENDIAN,
|
| 193 |
+
NPY_CPU_LITTLE,
|
| 194 |
+
NPY_CPU_BIG
|
| 195 |
+
};
|
| 196 |
+
|
| 197 |
+
/*
|
| 198 |
+
* This is to typedef npy_intp to the appropriate pointer size for this
|
| 199 |
+
* platform. Py_intptr_t, Py_uintptr_t are defined in pyport.h.
|
| 200 |
+
*/
|
| 201 |
+
typedef Py_intptr_t npy_intp;
|
| 202 |
+
typedef Py_uintptr_t npy_uintp;
|
| 203 |
+
|
| 204 |
+
/*
|
| 205 |
+
* Define sizes that were not defined in numpyconfig.h.
|
| 206 |
+
*/
|
| 207 |
+
#define NPY_SIZEOF_CHAR 1
|
| 208 |
+
#define NPY_SIZEOF_BYTE 1
|
| 209 |
+
#define NPY_SIZEOF_DATETIME 8
|
| 210 |
+
#define NPY_SIZEOF_TIMEDELTA 8
|
| 211 |
+
#define NPY_SIZEOF_INTP NPY_SIZEOF_PY_INTPTR_T
|
| 212 |
+
#define NPY_SIZEOF_UINTP NPY_SIZEOF_PY_INTPTR_T
|
| 213 |
+
#define NPY_SIZEOF_HALF 2
|
| 214 |
+
#define NPY_SIZEOF_CFLOAT NPY_SIZEOF_COMPLEX_FLOAT
|
| 215 |
+
#define NPY_SIZEOF_CDOUBLE NPY_SIZEOF_COMPLEX_DOUBLE
|
| 216 |
+
#define NPY_SIZEOF_CLONGDOUBLE NPY_SIZEOF_COMPLEX_LONGDOUBLE
|
| 217 |
+
|
| 218 |
+
#ifdef constchar
|
| 219 |
+
#undef constchar
|
| 220 |
+
#endif
|
| 221 |
+
|
| 222 |
+
#define NPY_SSIZE_T_PYFMT "n"
|
| 223 |
+
#define constchar char
|
| 224 |
+
|
| 225 |
+
/* NPY_INTP_FMT Note:
|
| 226 |
+
* Unlike the other NPY_*_FMT macros, which are used with PyOS_snprintf,
|
| 227 |
+
* NPY_INTP_FMT is used with PyErr_Format and PyUnicode_FromFormat. Those
|
| 228 |
+
* functions use different formatting codes that are portably specified
|
| 229 |
+
* according to the Python documentation. See issue gh-2388.
|
| 230 |
+
*/
|
| 231 |
+
#if NPY_SIZEOF_PY_INTPTR_T == NPY_SIZEOF_INT
|
| 232 |
+
#define NPY_INTP NPY_INT
|
| 233 |
+
#define NPY_UINTP NPY_UINT
|
| 234 |
+
#define PyIntpArrType_Type PyIntArrType_Type
|
| 235 |
+
#define PyUIntpArrType_Type PyUIntArrType_Type
|
| 236 |
+
#define NPY_MAX_INTP NPY_MAX_INT
|
| 237 |
+
#define NPY_MIN_INTP NPY_MIN_INT
|
| 238 |
+
#define NPY_MAX_UINTP NPY_MAX_UINT
|
| 239 |
+
#define NPY_INTP_FMT "d"
|
| 240 |
+
#elif NPY_SIZEOF_PY_INTPTR_T == NPY_SIZEOF_LONG
|
| 241 |
+
#define NPY_INTP NPY_LONG
|
| 242 |
+
#define NPY_UINTP NPY_ULONG
|
| 243 |
+
#define PyIntpArrType_Type PyLongArrType_Type
|
| 244 |
+
#define PyUIntpArrType_Type PyULongArrType_Type
|
| 245 |
+
#define NPY_MAX_INTP NPY_MAX_LONG
|
| 246 |
+
#define NPY_MIN_INTP NPY_MIN_LONG
|
| 247 |
+
#define NPY_MAX_UINTP NPY_MAX_ULONG
|
| 248 |
+
#define NPY_INTP_FMT "ld"
|
| 249 |
+
#elif defined(PY_LONG_LONG) && (NPY_SIZEOF_PY_INTPTR_T == NPY_SIZEOF_LONGLONG)
|
| 250 |
+
#define NPY_INTP NPY_LONGLONG
|
| 251 |
+
#define NPY_UINTP NPY_ULONGLONG
|
| 252 |
+
#define PyIntpArrType_Type PyLongLongArrType_Type
|
| 253 |
+
#define PyUIntpArrType_Type PyULongLongArrType_Type
|
| 254 |
+
#define NPY_MAX_INTP NPY_MAX_LONGLONG
|
| 255 |
+
#define NPY_MIN_INTP NPY_MIN_LONGLONG
|
| 256 |
+
#define NPY_MAX_UINTP NPY_MAX_ULONGLONG
|
| 257 |
+
#define NPY_INTP_FMT "lld"
|
| 258 |
+
#endif
|
| 259 |
+
|
| 260 |
+
/*
|
| 261 |
+
* We can only use C99 formats for npy_int_p if it is the same as
|
| 262 |
+
* intp_t, hence the condition on HAVE_UNITPTR_T
|
| 263 |
+
*/
|
| 264 |
+
#if (NPY_USE_C99_FORMATS) == 1 \
|
| 265 |
+
&& (defined HAVE_UINTPTR_T) \
|
| 266 |
+
&& (defined HAVE_INTTYPES_H)
|
| 267 |
+
#include <inttypes.h>
|
| 268 |
+
#undef NPY_INTP_FMT
|
| 269 |
+
#define NPY_INTP_FMT PRIdPTR
|
| 270 |
+
#endif
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
/*
|
| 274 |
+
* Some platforms don't define bool, long long, or long double.
|
| 275 |
+
* Handle that here.
|
| 276 |
+
*/
|
| 277 |
+
#define NPY_BYTE_FMT "hhd"
|
| 278 |
+
#define NPY_UBYTE_FMT "hhu"
|
| 279 |
+
#define NPY_SHORT_FMT "hd"
|
| 280 |
+
#define NPY_USHORT_FMT "hu"
|
| 281 |
+
#define NPY_INT_FMT "d"
|
| 282 |
+
#define NPY_UINT_FMT "u"
|
| 283 |
+
#define NPY_LONG_FMT "ld"
|
| 284 |
+
#define NPY_ULONG_FMT "lu"
|
| 285 |
+
#define NPY_HALF_FMT "g"
|
| 286 |
+
#define NPY_FLOAT_FMT "g"
|
| 287 |
+
#define NPY_DOUBLE_FMT "g"
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
#ifdef PY_LONG_LONG
|
| 291 |
+
typedef PY_LONG_LONG npy_longlong;
|
| 292 |
+
typedef unsigned PY_LONG_LONG npy_ulonglong;
|
| 293 |
+
# ifdef _MSC_VER
|
| 294 |
+
# define NPY_LONGLONG_FMT "I64d"
|
| 295 |
+
# define NPY_ULONGLONG_FMT "I64u"
|
| 296 |
+
# else
|
| 297 |
+
# define NPY_LONGLONG_FMT "lld"
|
| 298 |
+
# define NPY_ULONGLONG_FMT "llu"
|
| 299 |
+
# endif
|
| 300 |
+
# ifdef _MSC_VER
|
| 301 |
+
# define NPY_LONGLONG_SUFFIX(x) (x##i64)
|
| 302 |
+
# define NPY_ULONGLONG_SUFFIX(x) (x##Ui64)
|
| 303 |
+
# else
|
| 304 |
+
# define NPY_LONGLONG_SUFFIX(x) (x##LL)
|
| 305 |
+
# define NPY_ULONGLONG_SUFFIX(x) (x##ULL)
|
| 306 |
+
# endif
|
| 307 |
+
#else
|
| 308 |
+
typedef long npy_longlong;
|
| 309 |
+
typedef unsigned long npy_ulonglong;
|
| 310 |
+
# define NPY_LONGLONG_SUFFIX(x) (x##L)
|
| 311 |
+
# define NPY_ULONGLONG_SUFFIX(x) (x##UL)
|
| 312 |
+
#endif
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
typedef unsigned char npy_bool;
|
| 316 |
+
#define NPY_FALSE 0
|
| 317 |
+
#define NPY_TRUE 1
|
| 318 |
+
/*
|
| 319 |
+
* `NPY_SIZEOF_LONGDOUBLE` isn't usually equal to sizeof(long double).
|
| 320 |
+
* In some certain cases, it may forced to be equal to sizeof(double)
|
| 321 |
+
* even against the compiler implementation and the same goes for
|
| 322 |
+
* `complex long double`.
|
| 323 |
+
*
|
| 324 |
+
* Therefore, avoid `long double`, use `npy_longdouble` instead,
|
| 325 |
+
* and when it comes to standard math functions make sure of using
|
| 326 |
+
* the double version when `NPY_SIZEOF_LONGDOUBLE` == `NPY_SIZEOF_DOUBLE`.
|
| 327 |
+
* For example:
|
| 328 |
+
* npy_longdouble *ptr, x;
|
| 329 |
+
* #if NPY_SIZEOF_LONGDOUBLE == NPY_SIZEOF_DOUBLE
|
| 330 |
+
* npy_longdouble r = modf(x, ptr);
|
| 331 |
+
* #else
|
| 332 |
+
* npy_longdouble r = modfl(x, ptr);
|
| 333 |
+
* #endif
|
| 334 |
+
*
|
| 335 |
+
* See https://github.com/numpy/numpy/issues/20348
|
| 336 |
+
*/
|
| 337 |
+
#if NPY_SIZEOF_LONGDOUBLE == NPY_SIZEOF_DOUBLE
|
| 338 |
+
#define NPY_LONGDOUBLE_FMT "g"
|
| 339 |
+
typedef double npy_longdouble;
|
| 340 |
+
#else
|
| 341 |
+
#define NPY_LONGDOUBLE_FMT "Lg"
|
| 342 |
+
typedef long double npy_longdouble;
|
| 343 |
+
#endif
|
| 344 |
+
|
| 345 |
+
#ifndef Py_USING_UNICODE
|
| 346 |
+
#error Must use Python with unicode enabled.
|
| 347 |
+
#endif
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
typedef signed char npy_byte;
|
| 351 |
+
typedef unsigned char npy_ubyte;
|
| 352 |
+
typedef unsigned short npy_ushort;
|
| 353 |
+
typedef unsigned int npy_uint;
|
| 354 |
+
typedef unsigned long npy_ulong;
|
| 355 |
+
|
| 356 |
+
/* These are for completeness */
|
| 357 |
+
typedef char npy_char;
|
| 358 |
+
typedef short npy_short;
|
| 359 |
+
typedef int npy_int;
|
| 360 |
+
typedef long npy_long;
|
| 361 |
+
typedef float npy_float;
|
| 362 |
+
typedef double npy_double;
|
| 363 |
+
|
| 364 |
+
typedef Py_hash_t npy_hash_t;
|
| 365 |
+
#define NPY_SIZEOF_HASH_T NPY_SIZEOF_INTP
|
| 366 |
+
|
| 367 |
+
/*
|
| 368 |
+
* Disabling C99 complex usage: a lot of C code in numpy/scipy rely on being
|
| 369 |
+
* able to do .real/.imag. Will have to convert code first.
|
| 370 |
+
*/
|
| 371 |
+
#if 0
|
| 372 |
+
#if defined(NPY_USE_C99_COMPLEX) && defined(NPY_HAVE_COMPLEX_DOUBLE)
|
| 373 |
+
typedef complex npy_cdouble;
|
| 374 |
+
#else
|
| 375 |
+
typedef struct { double real, imag; } npy_cdouble;
|
| 376 |
+
#endif
|
| 377 |
+
|
| 378 |
+
#if defined(NPY_USE_C99_COMPLEX) && defined(NPY_HAVE_COMPLEX_FLOAT)
|
| 379 |
+
typedef complex float npy_cfloat;
|
| 380 |
+
#else
|
| 381 |
+
typedef struct { float real, imag; } npy_cfloat;
|
| 382 |
+
#endif
|
| 383 |
+
|
| 384 |
+
#if defined(NPY_USE_C99_COMPLEX) && defined(NPY_HAVE_COMPLEX_LONG_DOUBLE)
|
| 385 |
+
typedef complex long double npy_clongdouble;
|
| 386 |
+
#else
|
| 387 |
+
typedef struct {npy_longdouble real, imag;} npy_clongdouble;
|
| 388 |
+
#endif
|
| 389 |
+
#endif
|
| 390 |
+
#if NPY_SIZEOF_COMPLEX_DOUBLE != 2 * NPY_SIZEOF_DOUBLE
|
| 391 |
+
#error npy_cdouble definition is not compatible with C99 complex definition ! \
|
| 392 |
+
Please contact NumPy maintainers and give detailed information about your \
|
| 393 |
+
compiler and platform
|
| 394 |
+
#endif
|
| 395 |
+
typedef struct { double real, imag; } npy_cdouble;
|
| 396 |
+
|
| 397 |
+
#if NPY_SIZEOF_COMPLEX_FLOAT != 2 * NPY_SIZEOF_FLOAT
|
| 398 |
+
#error npy_cfloat definition is not compatible with C99 complex definition ! \
|
| 399 |
+
Please contact NumPy maintainers and give detailed information about your \
|
| 400 |
+
compiler and platform
|
| 401 |
+
#endif
|
| 402 |
+
typedef struct { float real, imag; } npy_cfloat;
|
| 403 |
+
|
| 404 |
+
#if NPY_SIZEOF_COMPLEX_LONGDOUBLE != 2 * NPY_SIZEOF_LONGDOUBLE
|
| 405 |
+
#error npy_clongdouble definition is not compatible with C99 complex definition ! \
|
| 406 |
+
Please contact NumPy maintainers and give detailed information about your \
|
| 407 |
+
compiler and platform
|
| 408 |
+
#endif
|
| 409 |
+
typedef struct { npy_longdouble real, imag; } npy_clongdouble;
|
| 410 |
+
|
| 411 |
+
/*
|
| 412 |
+
* numarray-style bit-width typedefs
|
| 413 |
+
*/
|
| 414 |
+
#define NPY_MAX_INT8 127
|
| 415 |
+
#define NPY_MIN_INT8 -128
|
| 416 |
+
#define NPY_MAX_UINT8 255
|
| 417 |
+
#define NPY_MAX_INT16 32767
|
| 418 |
+
#define NPY_MIN_INT16 -32768
|
| 419 |
+
#define NPY_MAX_UINT16 65535
|
| 420 |
+
#define NPY_MAX_INT32 2147483647
|
| 421 |
+
#define NPY_MIN_INT32 (-NPY_MAX_INT32 - 1)
|
| 422 |
+
#define NPY_MAX_UINT32 4294967295U
|
| 423 |
+
#define NPY_MAX_INT64 NPY_LONGLONG_SUFFIX(9223372036854775807)
|
| 424 |
+
#define NPY_MIN_INT64 (-NPY_MAX_INT64 - NPY_LONGLONG_SUFFIX(1))
|
| 425 |
+
#define NPY_MAX_UINT64 NPY_ULONGLONG_SUFFIX(18446744073709551615)
|
| 426 |
+
#define NPY_MAX_INT128 NPY_LONGLONG_SUFFIX(85070591730234615865843651857942052864)
|
| 427 |
+
#define NPY_MIN_INT128 (-NPY_MAX_INT128 - NPY_LONGLONG_SUFFIX(1))
|
| 428 |
+
#define NPY_MAX_UINT128 NPY_ULONGLONG_SUFFIX(170141183460469231731687303715884105728)
|
| 429 |
+
#define NPY_MAX_INT256 NPY_LONGLONG_SUFFIX(57896044618658097711785492504343953926634992332820282019728792003956564819967)
|
| 430 |
+
#define NPY_MIN_INT256 (-NPY_MAX_INT256 - NPY_LONGLONG_SUFFIX(1))
|
| 431 |
+
#define NPY_MAX_UINT256 NPY_ULONGLONG_SUFFIX(115792089237316195423570985008687907853269984665640564039457584007913129639935)
|
| 432 |
+
#define NPY_MIN_DATETIME NPY_MIN_INT64
|
| 433 |
+
#define NPY_MAX_DATETIME NPY_MAX_INT64
|
| 434 |
+
#define NPY_MIN_TIMEDELTA NPY_MIN_INT64
|
| 435 |
+
#define NPY_MAX_TIMEDELTA NPY_MAX_INT64
|
| 436 |
+
|
| 437 |
+
/* Need to find the number of bits for each type and
|
| 438 |
+
make definitions accordingly.
|
| 439 |
+
|
| 440 |
+
C states that sizeof(char) == 1 by definition
|
| 441 |
+
|
| 442 |
+
So, just using the sizeof keyword won't help.
|
| 443 |
+
|
| 444 |
+
It also looks like Python itself uses sizeof(char) quite a
|
| 445 |
+
bit, which by definition should be 1 all the time.
|
| 446 |
+
|
| 447 |
+
Idea: Make Use of CHAR_BIT which should tell us how many
|
| 448 |
+
BITS per CHARACTER
|
| 449 |
+
*/
|
| 450 |
+
|
| 451 |
+
/* Include platform definitions -- These are in the C89/90 standard */
|
| 452 |
+
#include <limits.h>
|
| 453 |
+
#define NPY_MAX_BYTE SCHAR_MAX
|
| 454 |
+
#define NPY_MIN_BYTE SCHAR_MIN
|
| 455 |
+
#define NPY_MAX_UBYTE UCHAR_MAX
|
| 456 |
+
#define NPY_MAX_SHORT SHRT_MAX
|
| 457 |
+
#define NPY_MIN_SHORT SHRT_MIN
|
| 458 |
+
#define NPY_MAX_USHORT USHRT_MAX
|
| 459 |
+
#define NPY_MAX_INT INT_MAX
|
| 460 |
+
#ifndef INT_MIN
|
| 461 |
+
#define INT_MIN (-INT_MAX - 1)
|
| 462 |
+
#endif
|
| 463 |
+
#define NPY_MIN_INT INT_MIN
|
| 464 |
+
#define NPY_MAX_UINT UINT_MAX
|
| 465 |
+
#define NPY_MAX_LONG LONG_MAX
|
| 466 |
+
#define NPY_MIN_LONG LONG_MIN
|
| 467 |
+
#define NPY_MAX_ULONG ULONG_MAX
|
| 468 |
+
|
| 469 |
+
#define NPY_BITSOF_BOOL (sizeof(npy_bool) * CHAR_BIT)
|
| 470 |
+
#define NPY_BITSOF_CHAR CHAR_BIT
|
| 471 |
+
#define NPY_BITSOF_BYTE (NPY_SIZEOF_BYTE * CHAR_BIT)
|
| 472 |
+
#define NPY_BITSOF_SHORT (NPY_SIZEOF_SHORT * CHAR_BIT)
|
| 473 |
+
#define NPY_BITSOF_INT (NPY_SIZEOF_INT * CHAR_BIT)
|
| 474 |
+
#define NPY_BITSOF_LONG (NPY_SIZEOF_LONG * CHAR_BIT)
|
| 475 |
+
#define NPY_BITSOF_LONGLONG (NPY_SIZEOF_LONGLONG * CHAR_BIT)
|
| 476 |
+
#define NPY_BITSOF_INTP (NPY_SIZEOF_INTP * CHAR_BIT)
|
| 477 |
+
#define NPY_BITSOF_HALF (NPY_SIZEOF_HALF * CHAR_BIT)
|
| 478 |
+
#define NPY_BITSOF_FLOAT (NPY_SIZEOF_FLOAT * CHAR_BIT)
|
| 479 |
+
#define NPY_BITSOF_DOUBLE (NPY_SIZEOF_DOUBLE * CHAR_BIT)
|
| 480 |
+
#define NPY_BITSOF_LONGDOUBLE (NPY_SIZEOF_LONGDOUBLE * CHAR_BIT)
|
| 481 |
+
#define NPY_BITSOF_CFLOAT (NPY_SIZEOF_CFLOAT * CHAR_BIT)
|
| 482 |
+
#define NPY_BITSOF_CDOUBLE (NPY_SIZEOF_CDOUBLE * CHAR_BIT)
|
| 483 |
+
#define NPY_BITSOF_CLONGDOUBLE (NPY_SIZEOF_CLONGDOUBLE * CHAR_BIT)
|
| 484 |
+
#define NPY_BITSOF_DATETIME (NPY_SIZEOF_DATETIME * CHAR_BIT)
|
| 485 |
+
#define NPY_BITSOF_TIMEDELTA (NPY_SIZEOF_TIMEDELTA * CHAR_BIT)
|
| 486 |
+
|
| 487 |
+
#if NPY_BITSOF_LONG == 8
|
| 488 |
+
#define NPY_INT8 NPY_LONG
|
| 489 |
+
#define NPY_UINT8 NPY_ULONG
|
| 490 |
+
typedef long npy_int8;
|
| 491 |
+
typedef unsigned long npy_uint8;
|
| 492 |
+
#define PyInt8ScalarObject PyLongScalarObject
|
| 493 |
+
#define PyInt8ArrType_Type PyLongArrType_Type
|
| 494 |
+
#define PyUInt8ScalarObject PyULongScalarObject
|
| 495 |
+
#define PyUInt8ArrType_Type PyULongArrType_Type
|
| 496 |
+
#define NPY_INT8_FMT NPY_LONG_FMT
|
| 497 |
+
#define NPY_UINT8_FMT NPY_ULONG_FMT
|
| 498 |
+
#elif NPY_BITSOF_LONG == 16
|
| 499 |
+
#define NPY_INT16 NPY_LONG
|
| 500 |
+
#define NPY_UINT16 NPY_ULONG
|
| 501 |
+
typedef long npy_int16;
|
| 502 |
+
typedef unsigned long npy_uint16;
|
| 503 |
+
#define PyInt16ScalarObject PyLongScalarObject
|
| 504 |
+
#define PyInt16ArrType_Type PyLongArrType_Type
|
| 505 |
+
#define PyUInt16ScalarObject PyULongScalarObject
|
| 506 |
+
#define PyUInt16ArrType_Type PyULongArrType_Type
|
| 507 |
+
#define NPY_INT16_FMT NPY_LONG_FMT
|
| 508 |
+
#define NPY_UINT16_FMT NPY_ULONG_FMT
|
| 509 |
+
#elif NPY_BITSOF_LONG == 32
|
| 510 |
+
#define NPY_INT32 NPY_LONG
|
| 511 |
+
#define NPY_UINT32 NPY_ULONG
|
| 512 |
+
typedef long npy_int32;
|
| 513 |
+
typedef unsigned long npy_uint32;
|
| 514 |
+
typedef unsigned long npy_ucs4;
|
| 515 |
+
#define PyInt32ScalarObject PyLongScalarObject
|
| 516 |
+
#define PyInt32ArrType_Type PyLongArrType_Type
|
| 517 |
+
#define PyUInt32ScalarObject PyULongScalarObject
|
| 518 |
+
#define PyUInt32ArrType_Type PyULongArrType_Type
|
| 519 |
+
#define NPY_INT32_FMT NPY_LONG_FMT
|
| 520 |
+
#define NPY_UINT32_FMT NPY_ULONG_FMT
|
| 521 |
+
#elif NPY_BITSOF_LONG == 64
|
| 522 |
+
#define NPY_INT64 NPY_LONG
|
| 523 |
+
#define NPY_UINT64 NPY_ULONG
|
| 524 |
+
typedef long npy_int64;
|
| 525 |
+
typedef unsigned long npy_uint64;
|
| 526 |
+
#define PyInt64ScalarObject PyLongScalarObject
|
| 527 |
+
#define PyInt64ArrType_Type PyLongArrType_Type
|
| 528 |
+
#define PyUInt64ScalarObject PyULongScalarObject
|
| 529 |
+
#define PyUInt64ArrType_Type PyULongArrType_Type
|
| 530 |
+
#define NPY_INT64_FMT NPY_LONG_FMT
|
| 531 |
+
#define NPY_UINT64_FMT NPY_ULONG_FMT
|
| 532 |
+
#define MyPyLong_FromInt64 PyLong_FromLong
|
| 533 |
+
#define MyPyLong_AsInt64 PyLong_AsLong
|
| 534 |
+
#elif NPY_BITSOF_LONG == 128
|
| 535 |
+
#define NPY_INT128 NPY_LONG
|
| 536 |
+
#define NPY_UINT128 NPY_ULONG
|
| 537 |
+
typedef long npy_int128;
|
| 538 |
+
typedef unsigned long npy_uint128;
|
| 539 |
+
#define PyInt128ScalarObject PyLongScalarObject
|
| 540 |
+
#define PyInt128ArrType_Type PyLongArrType_Type
|
| 541 |
+
#define PyUInt128ScalarObject PyULongScalarObject
|
| 542 |
+
#define PyUInt128ArrType_Type PyULongArrType_Type
|
| 543 |
+
#define NPY_INT128_FMT NPY_LONG_FMT
|
| 544 |
+
#define NPY_UINT128_FMT NPY_ULONG_FMT
|
| 545 |
+
#endif
|
| 546 |
+
|
| 547 |
+
#if NPY_BITSOF_LONGLONG == 8
|
| 548 |
+
# ifndef NPY_INT8
|
| 549 |
+
# define NPY_INT8 NPY_LONGLONG
|
| 550 |
+
# define NPY_UINT8 NPY_ULONGLONG
|
| 551 |
+
typedef npy_longlong npy_int8;
|
| 552 |
+
typedef npy_ulonglong npy_uint8;
|
| 553 |
+
# define PyInt8ScalarObject PyLongLongScalarObject
|
| 554 |
+
# define PyInt8ArrType_Type PyLongLongArrType_Type
|
| 555 |
+
# define PyUInt8ScalarObject PyULongLongScalarObject
|
| 556 |
+
# define PyUInt8ArrType_Type PyULongLongArrType_Type
|
| 557 |
+
#define NPY_INT8_FMT NPY_LONGLONG_FMT
|
| 558 |
+
#define NPY_UINT8_FMT NPY_ULONGLONG_FMT
|
| 559 |
+
# endif
|
| 560 |
+
# define NPY_MAX_LONGLONG NPY_MAX_INT8
|
| 561 |
+
# define NPY_MIN_LONGLONG NPY_MIN_INT8
|
| 562 |
+
# define NPY_MAX_ULONGLONG NPY_MAX_UINT8
|
| 563 |
+
#elif NPY_BITSOF_LONGLONG == 16
|
| 564 |
+
# ifndef NPY_INT16
|
| 565 |
+
# define NPY_INT16 NPY_LONGLONG
|
| 566 |
+
# define NPY_UINT16 NPY_ULONGLONG
|
| 567 |
+
typedef npy_longlong npy_int16;
|
| 568 |
+
typedef npy_ulonglong npy_uint16;
|
| 569 |
+
# define PyInt16ScalarObject PyLongLongScalarObject
|
| 570 |
+
# define PyInt16ArrType_Type PyLongLongArrType_Type
|
| 571 |
+
# define PyUInt16ScalarObject PyULongLongScalarObject
|
| 572 |
+
# define PyUInt16ArrType_Type PyULongLongArrType_Type
|
| 573 |
+
#define NPY_INT16_FMT NPY_LONGLONG_FMT
|
| 574 |
+
#define NPY_UINT16_FMT NPY_ULONGLONG_FMT
|
| 575 |
+
# endif
|
| 576 |
+
# define NPY_MAX_LONGLONG NPY_MAX_INT16
|
| 577 |
+
# define NPY_MIN_LONGLONG NPY_MIN_INT16
|
| 578 |
+
# define NPY_MAX_ULONGLONG NPY_MAX_UINT16
|
| 579 |
+
#elif NPY_BITSOF_LONGLONG == 32
|
| 580 |
+
# ifndef NPY_INT32
|
| 581 |
+
# define NPY_INT32 NPY_LONGLONG
|
| 582 |
+
# define NPY_UINT32 NPY_ULONGLONG
|
| 583 |
+
typedef npy_longlong npy_int32;
|
| 584 |
+
typedef npy_ulonglong npy_uint32;
|
| 585 |
+
typedef npy_ulonglong npy_ucs4;
|
| 586 |
+
# define PyInt32ScalarObject PyLongLongScalarObject
|
| 587 |
+
# define PyInt32ArrType_Type PyLongLongArrType_Type
|
| 588 |
+
# define PyUInt32ScalarObject PyULongLongScalarObject
|
| 589 |
+
# define PyUInt32ArrType_Type PyULongLongArrType_Type
|
| 590 |
+
#define NPY_INT32_FMT NPY_LONGLONG_FMT
|
| 591 |
+
#define NPY_UINT32_FMT NPY_ULONGLONG_FMT
|
| 592 |
+
# endif
|
| 593 |
+
# define NPY_MAX_LONGLONG NPY_MAX_INT32
|
| 594 |
+
# define NPY_MIN_LONGLONG NPY_MIN_INT32
|
| 595 |
+
# define NPY_MAX_ULONGLONG NPY_MAX_UINT32
|
| 596 |
+
#elif NPY_BITSOF_LONGLONG == 64
|
| 597 |
+
# ifndef NPY_INT64
|
| 598 |
+
# define NPY_INT64 NPY_LONGLONG
|
| 599 |
+
# define NPY_UINT64 NPY_ULONGLONG
|
| 600 |
+
typedef npy_longlong npy_int64;
|
| 601 |
+
typedef npy_ulonglong npy_uint64;
|
| 602 |
+
# define PyInt64ScalarObject PyLongLongScalarObject
|
| 603 |
+
# define PyInt64ArrType_Type PyLongLongArrType_Type
|
| 604 |
+
# define PyUInt64ScalarObject PyULongLongScalarObject
|
| 605 |
+
# define PyUInt64ArrType_Type PyULongLongArrType_Type
|
| 606 |
+
#define NPY_INT64_FMT NPY_LONGLONG_FMT
|
| 607 |
+
#define NPY_UINT64_FMT NPY_ULONGLONG_FMT
|
| 608 |
+
# define MyPyLong_FromInt64 PyLong_FromLongLong
|
| 609 |
+
# define MyPyLong_AsInt64 PyLong_AsLongLong
|
| 610 |
+
# endif
|
| 611 |
+
# define NPY_MAX_LONGLONG NPY_MAX_INT64
|
| 612 |
+
# define NPY_MIN_LONGLONG NPY_MIN_INT64
|
| 613 |
+
# define NPY_MAX_ULONGLONG NPY_MAX_UINT64
|
| 614 |
+
#elif NPY_BITSOF_LONGLONG == 128
|
| 615 |
+
# ifndef NPY_INT128
|
| 616 |
+
# define NPY_INT128 NPY_LONGLONG
|
| 617 |
+
# define NPY_UINT128 NPY_ULONGLONG
|
| 618 |
+
typedef npy_longlong npy_int128;
|
| 619 |
+
typedef npy_ulonglong npy_uint128;
|
| 620 |
+
# define PyInt128ScalarObject PyLongLongScalarObject
|
| 621 |
+
# define PyInt128ArrType_Type PyLongLongArrType_Type
|
| 622 |
+
# define PyUInt128ScalarObject PyULongLongScalarObject
|
| 623 |
+
# define PyUInt128ArrType_Type PyULongLongArrType_Type
|
| 624 |
+
#define NPY_INT128_FMT NPY_LONGLONG_FMT
|
| 625 |
+
#define NPY_UINT128_FMT NPY_ULONGLONG_FMT
|
| 626 |
+
# endif
|
| 627 |
+
# define NPY_MAX_LONGLONG NPY_MAX_INT128
|
| 628 |
+
# define NPY_MIN_LONGLONG NPY_MIN_INT128
|
| 629 |
+
# define NPY_MAX_ULONGLONG NPY_MAX_UINT128
|
| 630 |
+
#elif NPY_BITSOF_LONGLONG == 256
|
| 631 |
+
# define NPY_INT256 NPY_LONGLONG
|
| 632 |
+
# define NPY_UINT256 NPY_ULONGLONG
|
| 633 |
+
typedef npy_longlong npy_int256;
|
| 634 |
+
typedef npy_ulonglong npy_uint256;
|
| 635 |
+
# define PyInt256ScalarObject PyLongLongScalarObject
|
| 636 |
+
# define PyInt256ArrType_Type PyLongLongArrType_Type
|
| 637 |
+
# define PyUInt256ScalarObject PyULongLongScalarObject
|
| 638 |
+
# define PyUInt256ArrType_Type PyULongLongArrType_Type
|
| 639 |
+
#define NPY_INT256_FMT NPY_LONGLONG_FMT
|
| 640 |
+
#define NPY_UINT256_FMT NPY_ULONGLONG_FMT
|
| 641 |
+
# define NPY_MAX_LONGLONG NPY_MAX_INT256
|
| 642 |
+
# define NPY_MIN_LONGLONG NPY_MIN_INT256
|
| 643 |
+
# define NPY_MAX_ULONGLONG NPY_MAX_UINT256
|
| 644 |
+
#endif
|
| 645 |
+
|
| 646 |
+
#if NPY_BITSOF_INT == 8
|
| 647 |
+
#ifndef NPY_INT8
|
| 648 |
+
#define NPY_INT8 NPY_INT
|
| 649 |
+
#define NPY_UINT8 NPY_UINT
|
| 650 |
+
typedef int npy_int8;
|
| 651 |
+
typedef unsigned int npy_uint8;
|
| 652 |
+
# define PyInt8ScalarObject PyIntScalarObject
|
| 653 |
+
# define PyInt8ArrType_Type PyIntArrType_Type
|
| 654 |
+
# define PyUInt8ScalarObject PyUIntScalarObject
|
| 655 |
+
# define PyUInt8ArrType_Type PyUIntArrType_Type
|
| 656 |
+
#define NPY_INT8_FMT NPY_INT_FMT
|
| 657 |
+
#define NPY_UINT8_FMT NPY_UINT_FMT
|
| 658 |
+
#endif
|
| 659 |
+
#elif NPY_BITSOF_INT == 16
|
| 660 |
+
#ifndef NPY_INT16
|
| 661 |
+
#define NPY_INT16 NPY_INT
|
| 662 |
+
#define NPY_UINT16 NPY_UINT
|
| 663 |
+
typedef int npy_int16;
|
| 664 |
+
typedef unsigned int npy_uint16;
|
| 665 |
+
# define PyInt16ScalarObject PyIntScalarObject
|
| 666 |
+
# define PyInt16ArrType_Type PyIntArrType_Type
|
| 667 |
+
# define PyUInt16ScalarObject PyIntUScalarObject
|
| 668 |
+
# define PyUInt16ArrType_Type PyIntUArrType_Type
|
| 669 |
+
#define NPY_INT16_FMT NPY_INT_FMT
|
| 670 |
+
#define NPY_UINT16_FMT NPY_UINT_FMT
|
| 671 |
+
#endif
|
| 672 |
+
#elif NPY_BITSOF_INT == 32
|
| 673 |
+
#ifndef NPY_INT32
|
| 674 |
+
#define NPY_INT32 NPY_INT
|
| 675 |
+
#define NPY_UINT32 NPY_UINT
|
| 676 |
+
typedef int npy_int32;
|
| 677 |
+
typedef unsigned int npy_uint32;
|
| 678 |
+
typedef unsigned int npy_ucs4;
|
| 679 |
+
# define PyInt32ScalarObject PyIntScalarObject
|
| 680 |
+
# define PyInt32ArrType_Type PyIntArrType_Type
|
| 681 |
+
# define PyUInt32ScalarObject PyUIntScalarObject
|
| 682 |
+
# define PyUInt32ArrType_Type PyUIntArrType_Type
|
| 683 |
+
#define NPY_INT32_FMT NPY_INT_FMT
|
| 684 |
+
#define NPY_UINT32_FMT NPY_UINT_FMT
|
| 685 |
+
#endif
|
| 686 |
+
#elif NPY_BITSOF_INT == 64
|
| 687 |
+
#ifndef NPY_INT64
|
| 688 |
+
#define NPY_INT64 NPY_INT
|
| 689 |
+
#define NPY_UINT64 NPY_UINT
|
| 690 |
+
typedef int npy_int64;
|
| 691 |
+
typedef unsigned int npy_uint64;
|
| 692 |
+
# define PyInt64ScalarObject PyIntScalarObject
|
| 693 |
+
# define PyInt64ArrType_Type PyIntArrType_Type
|
| 694 |
+
# define PyUInt64ScalarObject PyUIntScalarObject
|
| 695 |
+
# define PyUInt64ArrType_Type PyUIntArrType_Type
|
| 696 |
+
#define NPY_INT64_FMT NPY_INT_FMT
|
| 697 |
+
#define NPY_UINT64_FMT NPY_UINT_FMT
|
| 698 |
+
# define MyPyLong_FromInt64 PyLong_FromLong
|
| 699 |
+
# define MyPyLong_AsInt64 PyLong_AsLong
|
| 700 |
+
#endif
|
| 701 |
+
#elif NPY_BITSOF_INT == 128
|
| 702 |
+
#ifndef NPY_INT128
|
| 703 |
+
#define NPY_INT128 NPY_INT
|
| 704 |
+
#define NPY_UINT128 NPY_UINT
|
| 705 |
+
typedef int npy_int128;
|
| 706 |
+
typedef unsigned int npy_uint128;
|
| 707 |
+
# define PyInt128ScalarObject PyIntScalarObject
|
| 708 |
+
# define PyInt128ArrType_Type PyIntArrType_Type
|
| 709 |
+
# define PyUInt128ScalarObject PyUIntScalarObject
|
| 710 |
+
# define PyUInt128ArrType_Type PyUIntArrType_Type
|
| 711 |
+
#define NPY_INT128_FMT NPY_INT_FMT
|
| 712 |
+
#define NPY_UINT128_FMT NPY_UINT_FMT
|
| 713 |
+
#endif
|
| 714 |
+
#endif
|
| 715 |
+
|
| 716 |
+
#if NPY_BITSOF_SHORT == 8
|
| 717 |
+
#ifndef NPY_INT8
|
| 718 |
+
#define NPY_INT8 NPY_SHORT
|
| 719 |
+
#define NPY_UINT8 NPY_USHORT
|
| 720 |
+
typedef short npy_int8;
|
| 721 |
+
typedef unsigned short npy_uint8;
|
| 722 |
+
# define PyInt8ScalarObject PyShortScalarObject
|
| 723 |
+
# define PyInt8ArrType_Type PyShortArrType_Type
|
| 724 |
+
# define PyUInt8ScalarObject PyUShortScalarObject
|
| 725 |
+
# define PyUInt8ArrType_Type PyUShortArrType_Type
|
| 726 |
+
#define NPY_INT8_FMT NPY_SHORT_FMT
|
| 727 |
+
#define NPY_UINT8_FMT NPY_USHORT_FMT
|
| 728 |
+
#endif
|
| 729 |
+
#elif NPY_BITSOF_SHORT == 16
|
| 730 |
+
#ifndef NPY_INT16
|
| 731 |
+
#define NPY_INT16 NPY_SHORT
|
| 732 |
+
#define NPY_UINT16 NPY_USHORT
|
| 733 |
+
typedef short npy_int16;
|
| 734 |
+
typedef unsigned short npy_uint16;
|
| 735 |
+
# define PyInt16ScalarObject PyShortScalarObject
|
| 736 |
+
# define PyInt16ArrType_Type PyShortArrType_Type
|
| 737 |
+
# define PyUInt16ScalarObject PyUShortScalarObject
|
| 738 |
+
# define PyUInt16ArrType_Type PyUShortArrType_Type
|
| 739 |
+
#define NPY_INT16_FMT NPY_SHORT_FMT
|
| 740 |
+
#define NPY_UINT16_FMT NPY_USHORT_FMT
|
| 741 |
+
#endif
|
| 742 |
+
#elif NPY_BITSOF_SHORT == 32
|
| 743 |
+
#ifndef NPY_INT32
|
| 744 |
+
#define NPY_INT32 NPY_SHORT
|
| 745 |
+
#define NPY_UINT32 NPY_USHORT
|
| 746 |
+
typedef short npy_int32;
|
| 747 |
+
typedef unsigned short npy_uint32;
|
| 748 |
+
typedef unsigned short npy_ucs4;
|
| 749 |
+
# define PyInt32ScalarObject PyShortScalarObject
|
| 750 |
+
# define PyInt32ArrType_Type PyShortArrType_Type
|
| 751 |
+
# define PyUInt32ScalarObject PyUShortScalarObject
|
| 752 |
+
# define PyUInt32ArrType_Type PyUShortArrType_Type
|
| 753 |
+
#define NPY_INT32_FMT NPY_SHORT_FMT
|
| 754 |
+
#define NPY_UINT32_FMT NPY_USHORT_FMT
|
| 755 |
+
#endif
|
| 756 |
+
#elif NPY_BITSOF_SHORT == 64
|
| 757 |
+
#ifndef NPY_INT64
|
| 758 |
+
#define NPY_INT64 NPY_SHORT
|
| 759 |
+
#define NPY_UINT64 NPY_USHORT
|
| 760 |
+
typedef short npy_int64;
|
| 761 |
+
typedef unsigned short npy_uint64;
|
| 762 |
+
# define PyInt64ScalarObject PyShortScalarObject
|
| 763 |
+
# define PyInt64ArrType_Type PyShortArrType_Type
|
| 764 |
+
# define PyUInt64ScalarObject PyUShortScalarObject
|
| 765 |
+
# define PyUInt64ArrType_Type PyUShortArrType_Type
|
| 766 |
+
#define NPY_INT64_FMT NPY_SHORT_FMT
|
| 767 |
+
#define NPY_UINT64_FMT NPY_USHORT_FMT
|
| 768 |
+
# define MyPyLong_FromInt64 PyLong_FromLong
|
| 769 |
+
# define MyPyLong_AsInt64 PyLong_AsLong
|
| 770 |
+
#endif
|
| 771 |
+
#elif NPY_BITSOF_SHORT == 128
|
| 772 |
+
#ifndef NPY_INT128
|
| 773 |
+
#define NPY_INT128 NPY_SHORT
|
| 774 |
+
#define NPY_UINT128 NPY_USHORT
|
| 775 |
+
typedef short npy_int128;
|
| 776 |
+
typedef unsigned short npy_uint128;
|
| 777 |
+
# define PyInt128ScalarObject PyShortScalarObject
|
| 778 |
+
# define PyInt128ArrType_Type PyShortArrType_Type
|
| 779 |
+
# define PyUInt128ScalarObject PyUShortScalarObject
|
| 780 |
+
# define PyUInt128ArrType_Type PyUShortArrType_Type
|
| 781 |
+
#define NPY_INT128_FMT NPY_SHORT_FMT
|
| 782 |
+
#define NPY_UINT128_FMT NPY_USHORT_FMT
|
| 783 |
+
#endif
|
| 784 |
+
#endif
|
| 785 |
+
|
| 786 |
+
|
| 787 |
+
#if NPY_BITSOF_CHAR == 8
|
| 788 |
+
#ifndef NPY_INT8
|
| 789 |
+
#define NPY_INT8 NPY_BYTE
|
| 790 |
+
#define NPY_UINT8 NPY_UBYTE
|
| 791 |
+
typedef signed char npy_int8;
|
| 792 |
+
typedef unsigned char npy_uint8;
|
| 793 |
+
# define PyInt8ScalarObject PyByteScalarObject
|
| 794 |
+
# define PyInt8ArrType_Type PyByteArrType_Type
|
| 795 |
+
# define PyUInt8ScalarObject PyUByteScalarObject
|
| 796 |
+
# define PyUInt8ArrType_Type PyUByteArrType_Type
|
| 797 |
+
#define NPY_INT8_FMT NPY_BYTE_FMT
|
| 798 |
+
#define NPY_UINT8_FMT NPY_UBYTE_FMT
|
| 799 |
+
#endif
|
| 800 |
+
#elif NPY_BITSOF_CHAR == 16
|
| 801 |
+
#ifndef NPY_INT16
|
| 802 |
+
#define NPY_INT16 NPY_BYTE
|
| 803 |
+
#define NPY_UINT16 NPY_UBYTE
|
| 804 |
+
typedef signed char npy_int16;
|
| 805 |
+
typedef unsigned char npy_uint16;
|
| 806 |
+
# define PyInt16ScalarObject PyByteScalarObject
|
| 807 |
+
# define PyInt16ArrType_Type PyByteArrType_Type
|
| 808 |
+
# define PyUInt16ScalarObject PyUByteScalarObject
|
| 809 |
+
# define PyUInt16ArrType_Type PyUByteArrType_Type
|
| 810 |
+
#define NPY_INT16_FMT NPY_BYTE_FMT
|
| 811 |
+
#define NPY_UINT16_FMT NPY_UBYTE_FMT
|
| 812 |
+
#endif
|
| 813 |
+
#elif NPY_BITSOF_CHAR == 32
|
| 814 |
+
#ifndef NPY_INT32
|
| 815 |
+
#define NPY_INT32 NPY_BYTE
|
| 816 |
+
#define NPY_UINT32 NPY_UBYTE
|
| 817 |
+
typedef signed char npy_int32;
|
| 818 |
+
typedef unsigned char npy_uint32;
|
| 819 |
+
typedef unsigned char npy_ucs4;
|
| 820 |
+
# define PyInt32ScalarObject PyByteScalarObject
|
| 821 |
+
# define PyInt32ArrType_Type PyByteArrType_Type
|
| 822 |
+
# define PyUInt32ScalarObject PyUByteScalarObject
|
| 823 |
+
# define PyUInt32ArrType_Type PyUByteArrType_Type
|
| 824 |
+
#define NPY_INT32_FMT NPY_BYTE_FMT
|
| 825 |
+
#define NPY_UINT32_FMT NPY_UBYTE_FMT
|
| 826 |
+
#endif
|
| 827 |
+
#elif NPY_BITSOF_CHAR == 64
|
| 828 |
+
#ifndef NPY_INT64
|
| 829 |
+
#define NPY_INT64 NPY_BYTE
|
| 830 |
+
#define NPY_UINT64 NPY_UBYTE
|
| 831 |
+
typedef signed char npy_int64;
|
| 832 |
+
typedef unsigned char npy_uint64;
|
| 833 |
+
# define PyInt64ScalarObject PyByteScalarObject
|
| 834 |
+
# define PyInt64ArrType_Type PyByteArrType_Type
|
| 835 |
+
# define PyUInt64ScalarObject PyUByteScalarObject
|
| 836 |
+
# define PyUInt64ArrType_Type PyUByteArrType_Type
|
| 837 |
+
#define NPY_INT64_FMT NPY_BYTE_FMT
|
| 838 |
+
#define NPY_UINT64_FMT NPY_UBYTE_FMT
|
| 839 |
+
# define MyPyLong_FromInt64 PyLong_FromLong
|
| 840 |
+
# define MyPyLong_AsInt64 PyLong_AsLong
|
| 841 |
+
#endif
|
| 842 |
+
#elif NPY_BITSOF_CHAR == 128
|
| 843 |
+
#ifndef NPY_INT128
|
| 844 |
+
#define NPY_INT128 NPY_BYTE
|
| 845 |
+
#define NPY_UINT128 NPY_UBYTE
|
| 846 |
+
typedef signed char npy_int128;
|
| 847 |
+
typedef unsigned char npy_uint128;
|
| 848 |
+
# define PyInt128ScalarObject PyByteScalarObject
|
| 849 |
+
# define PyInt128ArrType_Type PyByteArrType_Type
|
| 850 |
+
# define PyUInt128ScalarObject PyUByteScalarObject
|
| 851 |
+
# define PyUInt128ArrType_Type PyUByteArrType_Type
|
| 852 |
+
#define NPY_INT128_FMT NPY_BYTE_FMT
|
| 853 |
+
#define NPY_UINT128_FMT NPY_UBYTE_FMT
|
| 854 |
+
#endif
|
| 855 |
+
#endif
|
| 856 |
+
|
| 857 |
+
|
| 858 |
+
|
| 859 |
+
#if NPY_BITSOF_DOUBLE == 32
|
| 860 |
+
#ifndef NPY_FLOAT32
|
| 861 |
+
#define NPY_FLOAT32 NPY_DOUBLE
|
| 862 |
+
#define NPY_COMPLEX64 NPY_CDOUBLE
|
| 863 |
+
typedef double npy_float32;
|
| 864 |
+
typedef npy_cdouble npy_complex64;
|
| 865 |
+
# define PyFloat32ScalarObject PyDoubleScalarObject
|
| 866 |
+
# define PyComplex64ScalarObject PyCDoubleScalarObject
|
| 867 |
+
# define PyFloat32ArrType_Type PyDoubleArrType_Type
|
| 868 |
+
# define PyComplex64ArrType_Type PyCDoubleArrType_Type
|
| 869 |
+
#define NPY_FLOAT32_FMT NPY_DOUBLE_FMT
|
| 870 |
+
#define NPY_COMPLEX64_FMT NPY_CDOUBLE_FMT
|
| 871 |
+
#endif
|
| 872 |
+
#elif NPY_BITSOF_DOUBLE == 64
|
| 873 |
+
#ifndef NPY_FLOAT64
|
| 874 |
+
#define NPY_FLOAT64 NPY_DOUBLE
|
| 875 |
+
#define NPY_COMPLEX128 NPY_CDOUBLE
|
| 876 |
+
typedef double npy_float64;
|
| 877 |
+
typedef npy_cdouble npy_complex128;
|
| 878 |
+
# define PyFloat64ScalarObject PyDoubleScalarObject
|
| 879 |
+
# define PyComplex128ScalarObject PyCDoubleScalarObject
|
| 880 |
+
# define PyFloat64ArrType_Type PyDoubleArrType_Type
|
| 881 |
+
# define PyComplex128ArrType_Type PyCDoubleArrType_Type
|
| 882 |
+
#define NPY_FLOAT64_FMT NPY_DOUBLE_FMT
|
| 883 |
+
#define NPY_COMPLEX128_FMT NPY_CDOUBLE_FMT
|
| 884 |
+
#endif
|
| 885 |
+
#elif NPY_BITSOF_DOUBLE == 80
|
| 886 |
+
#ifndef NPY_FLOAT80
|
| 887 |
+
#define NPY_FLOAT80 NPY_DOUBLE
|
| 888 |
+
#define NPY_COMPLEX160 NPY_CDOUBLE
|
| 889 |
+
typedef double npy_float80;
|
| 890 |
+
typedef npy_cdouble npy_complex160;
|
| 891 |
+
# define PyFloat80ScalarObject PyDoubleScalarObject
|
| 892 |
+
# define PyComplex160ScalarObject PyCDoubleScalarObject
|
| 893 |
+
# define PyFloat80ArrType_Type PyDoubleArrType_Type
|
| 894 |
+
# define PyComplex160ArrType_Type PyCDoubleArrType_Type
|
| 895 |
+
#define NPY_FLOAT80_FMT NPY_DOUBLE_FMT
|
| 896 |
+
#define NPY_COMPLEX160_FMT NPY_CDOUBLE_FMT
|
| 897 |
+
#endif
|
| 898 |
+
#elif NPY_BITSOF_DOUBLE == 96
|
| 899 |
+
#ifndef NPY_FLOAT96
|
| 900 |
+
#define NPY_FLOAT96 NPY_DOUBLE
|
| 901 |
+
#define NPY_COMPLEX192 NPY_CDOUBLE
|
| 902 |
+
typedef double npy_float96;
|
| 903 |
+
typedef npy_cdouble npy_complex192;
|
| 904 |
+
# define PyFloat96ScalarObject PyDoubleScalarObject
|
| 905 |
+
# define PyComplex192ScalarObject PyCDoubleScalarObject
|
| 906 |
+
# define PyFloat96ArrType_Type PyDoubleArrType_Type
|
| 907 |
+
# define PyComplex192ArrType_Type PyCDoubleArrType_Type
|
| 908 |
+
#define NPY_FLOAT96_FMT NPY_DOUBLE_FMT
|
| 909 |
+
#define NPY_COMPLEX192_FMT NPY_CDOUBLE_FMT
|
| 910 |
+
#endif
|
| 911 |
+
#elif NPY_BITSOF_DOUBLE == 128
|
| 912 |
+
#ifndef NPY_FLOAT128
|
| 913 |
+
#define NPY_FLOAT128 NPY_DOUBLE
|
| 914 |
+
#define NPY_COMPLEX256 NPY_CDOUBLE
|
| 915 |
+
typedef double npy_float128;
|
| 916 |
+
typedef npy_cdouble npy_complex256;
|
| 917 |
+
# define PyFloat128ScalarObject PyDoubleScalarObject
|
| 918 |
+
# define PyComplex256ScalarObject PyCDoubleScalarObject
|
| 919 |
+
# define PyFloat128ArrType_Type PyDoubleArrType_Type
|
| 920 |
+
# define PyComplex256ArrType_Type PyCDoubleArrType_Type
|
| 921 |
+
#define NPY_FLOAT128_FMT NPY_DOUBLE_FMT
|
| 922 |
+
#define NPY_COMPLEX256_FMT NPY_CDOUBLE_FMT
|
| 923 |
+
#endif
|
| 924 |
+
#endif
|
| 925 |
+
|
| 926 |
+
|
| 927 |
+
|
| 928 |
+
#if NPY_BITSOF_FLOAT == 32
|
| 929 |
+
#ifndef NPY_FLOAT32
|
| 930 |
+
#define NPY_FLOAT32 NPY_FLOAT
|
| 931 |
+
#define NPY_COMPLEX64 NPY_CFLOAT
|
| 932 |
+
typedef float npy_float32;
|
| 933 |
+
typedef npy_cfloat npy_complex64;
|
| 934 |
+
# define PyFloat32ScalarObject PyFloatScalarObject
|
| 935 |
+
# define PyComplex64ScalarObject PyCFloatScalarObject
|
| 936 |
+
# define PyFloat32ArrType_Type PyFloatArrType_Type
|
| 937 |
+
# define PyComplex64ArrType_Type PyCFloatArrType_Type
|
| 938 |
+
#define NPY_FLOAT32_FMT NPY_FLOAT_FMT
|
| 939 |
+
#define NPY_COMPLEX64_FMT NPY_CFLOAT_FMT
|
| 940 |
+
#endif
|
| 941 |
+
#elif NPY_BITSOF_FLOAT == 64
|
| 942 |
+
#ifndef NPY_FLOAT64
|
| 943 |
+
#define NPY_FLOAT64 NPY_FLOAT
|
| 944 |
+
#define NPY_COMPLEX128 NPY_CFLOAT
|
| 945 |
+
typedef float npy_float64;
|
| 946 |
+
typedef npy_cfloat npy_complex128;
|
| 947 |
+
# define PyFloat64ScalarObject PyFloatScalarObject
|
| 948 |
+
# define PyComplex128ScalarObject PyCFloatScalarObject
|
| 949 |
+
# define PyFloat64ArrType_Type PyFloatArrType_Type
|
| 950 |
+
# define PyComplex128ArrType_Type PyCFloatArrType_Type
|
| 951 |
+
#define NPY_FLOAT64_FMT NPY_FLOAT_FMT
|
| 952 |
+
#define NPY_COMPLEX128_FMT NPY_CFLOAT_FMT
|
| 953 |
+
#endif
|
| 954 |
+
#elif NPY_BITSOF_FLOAT == 80
|
| 955 |
+
#ifndef NPY_FLOAT80
|
| 956 |
+
#define NPY_FLOAT80 NPY_FLOAT
|
| 957 |
+
#define NPY_COMPLEX160 NPY_CFLOAT
|
| 958 |
+
typedef float npy_float80;
|
| 959 |
+
typedef npy_cfloat npy_complex160;
|
| 960 |
+
# define PyFloat80ScalarObject PyFloatScalarObject
|
| 961 |
+
# define PyComplex160ScalarObject PyCFloatScalarObject
|
| 962 |
+
# define PyFloat80ArrType_Type PyFloatArrType_Type
|
| 963 |
+
# define PyComplex160ArrType_Type PyCFloatArrType_Type
|
| 964 |
+
#define NPY_FLOAT80_FMT NPY_FLOAT_FMT
|
| 965 |
+
#define NPY_COMPLEX160_FMT NPY_CFLOAT_FMT
|
| 966 |
+
#endif
|
| 967 |
+
#elif NPY_BITSOF_FLOAT == 96
|
| 968 |
+
#ifndef NPY_FLOAT96
|
| 969 |
+
#define NPY_FLOAT96 NPY_FLOAT
|
| 970 |
+
#define NPY_COMPLEX192 NPY_CFLOAT
|
| 971 |
+
typedef float npy_float96;
|
| 972 |
+
typedef npy_cfloat npy_complex192;
|
| 973 |
+
# define PyFloat96ScalarObject PyFloatScalarObject
|
| 974 |
+
# define PyComplex192ScalarObject PyCFloatScalarObject
|
| 975 |
+
# define PyFloat96ArrType_Type PyFloatArrType_Type
|
| 976 |
+
# define PyComplex192ArrType_Type PyCFloatArrType_Type
|
| 977 |
+
#define NPY_FLOAT96_FMT NPY_FLOAT_FMT
|
| 978 |
+
#define NPY_COMPLEX192_FMT NPY_CFLOAT_FMT
|
| 979 |
+
#endif
|
| 980 |
+
#elif NPY_BITSOF_FLOAT == 128
|
| 981 |
+
#ifndef NPY_FLOAT128
|
| 982 |
+
#define NPY_FLOAT128 NPY_FLOAT
|
| 983 |
+
#define NPY_COMPLEX256 NPY_CFLOAT
|
| 984 |
+
typedef float npy_float128;
|
| 985 |
+
typedef npy_cfloat npy_complex256;
|
| 986 |
+
# define PyFloat128ScalarObject PyFloatScalarObject
|
| 987 |
+
# define PyComplex256ScalarObject PyCFloatScalarObject
|
| 988 |
+
# define PyFloat128ArrType_Type PyFloatArrType_Type
|
| 989 |
+
# define PyComplex256ArrType_Type PyCFloatArrType_Type
|
| 990 |
+
#define NPY_FLOAT128_FMT NPY_FLOAT_FMT
|
| 991 |
+
#define NPY_COMPLEX256_FMT NPY_CFLOAT_FMT
|
| 992 |
+
#endif
|
| 993 |
+
#endif
|
| 994 |
+
|
| 995 |
+
/* half/float16 isn't a floating-point type in C */
|
| 996 |
+
#define NPY_FLOAT16 NPY_HALF
|
| 997 |
+
typedef npy_uint16 npy_half;
|
| 998 |
+
typedef npy_half npy_float16;
|
| 999 |
+
|
| 1000 |
+
#if NPY_BITSOF_LONGDOUBLE == 32
|
| 1001 |
+
#ifndef NPY_FLOAT32
|
| 1002 |
+
#define NPY_FLOAT32 NPY_LONGDOUBLE
|
| 1003 |
+
#define NPY_COMPLEX64 NPY_CLONGDOUBLE
|
| 1004 |
+
typedef npy_longdouble npy_float32;
|
| 1005 |
+
typedef npy_clongdouble npy_complex64;
|
| 1006 |
+
# define PyFloat32ScalarObject PyLongDoubleScalarObject
|
| 1007 |
+
# define PyComplex64ScalarObject PyCLongDoubleScalarObject
|
| 1008 |
+
# define PyFloat32ArrType_Type PyLongDoubleArrType_Type
|
| 1009 |
+
# define PyComplex64ArrType_Type PyCLongDoubleArrType_Type
|
| 1010 |
+
#define NPY_FLOAT32_FMT NPY_LONGDOUBLE_FMT
|
| 1011 |
+
#define NPY_COMPLEX64_FMT NPY_CLONGDOUBLE_FMT
|
| 1012 |
+
#endif
|
| 1013 |
+
#elif NPY_BITSOF_LONGDOUBLE == 64
|
| 1014 |
+
#ifndef NPY_FLOAT64
|
| 1015 |
+
#define NPY_FLOAT64 NPY_LONGDOUBLE
|
| 1016 |
+
#define NPY_COMPLEX128 NPY_CLONGDOUBLE
|
| 1017 |
+
typedef npy_longdouble npy_float64;
|
| 1018 |
+
typedef npy_clongdouble npy_complex128;
|
| 1019 |
+
# define PyFloat64ScalarObject PyLongDoubleScalarObject
|
| 1020 |
+
# define PyComplex128ScalarObject PyCLongDoubleScalarObject
|
| 1021 |
+
# define PyFloat64ArrType_Type PyLongDoubleArrType_Type
|
| 1022 |
+
# define PyComplex128ArrType_Type PyCLongDoubleArrType_Type
|
| 1023 |
+
#define NPY_FLOAT64_FMT NPY_LONGDOUBLE_FMT
|
| 1024 |
+
#define NPY_COMPLEX128_FMT NPY_CLONGDOUBLE_FMT
|
| 1025 |
+
#endif
|
| 1026 |
+
#elif NPY_BITSOF_LONGDOUBLE == 80
|
| 1027 |
+
#ifndef NPY_FLOAT80
|
| 1028 |
+
#define NPY_FLOAT80 NPY_LONGDOUBLE
|
| 1029 |
+
#define NPY_COMPLEX160 NPY_CLONGDOUBLE
|
| 1030 |
+
typedef npy_longdouble npy_float80;
|
| 1031 |
+
typedef npy_clongdouble npy_complex160;
|
| 1032 |
+
# define PyFloat80ScalarObject PyLongDoubleScalarObject
|
| 1033 |
+
# define PyComplex160ScalarObject PyCLongDoubleScalarObject
|
| 1034 |
+
# define PyFloat80ArrType_Type PyLongDoubleArrType_Type
|
| 1035 |
+
# define PyComplex160ArrType_Type PyCLongDoubleArrType_Type
|
| 1036 |
+
#define NPY_FLOAT80_FMT NPY_LONGDOUBLE_FMT
|
| 1037 |
+
#define NPY_COMPLEX160_FMT NPY_CLONGDOUBLE_FMT
|
| 1038 |
+
#endif
|
| 1039 |
+
#elif NPY_BITSOF_LONGDOUBLE == 96
|
| 1040 |
+
#ifndef NPY_FLOAT96
|
| 1041 |
+
#define NPY_FLOAT96 NPY_LONGDOUBLE
|
| 1042 |
+
#define NPY_COMPLEX192 NPY_CLONGDOUBLE
|
| 1043 |
+
typedef npy_longdouble npy_float96;
|
| 1044 |
+
typedef npy_clongdouble npy_complex192;
|
| 1045 |
+
# define PyFloat96ScalarObject PyLongDoubleScalarObject
|
| 1046 |
+
# define PyComplex192ScalarObject PyCLongDoubleScalarObject
|
| 1047 |
+
# define PyFloat96ArrType_Type PyLongDoubleArrType_Type
|
| 1048 |
+
# define PyComplex192ArrType_Type PyCLongDoubleArrType_Type
|
| 1049 |
+
#define NPY_FLOAT96_FMT NPY_LONGDOUBLE_FMT
|
| 1050 |
+
#define NPY_COMPLEX192_FMT NPY_CLONGDOUBLE_FMT
|
| 1051 |
+
#endif
|
| 1052 |
+
#elif NPY_BITSOF_LONGDOUBLE == 128
|
| 1053 |
+
#ifndef NPY_FLOAT128
|
| 1054 |
+
#define NPY_FLOAT128 NPY_LONGDOUBLE
|
| 1055 |
+
#define NPY_COMPLEX256 NPY_CLONGDOUBLE
|
| 1056 |
+
typedef npy_longdouble npy_float128;
|
| 1057 |
+
typedef npy_clongdouble npy_complex256;
|
| 1058 |
+
# define PyFloat128ScalarObject PyLongDoubleScalarObject
|
| 1059 |
+
# define PyComplex256ScalarObject PyCLongDoubleScalarObject
|
| 1060 |
+
# define PyFloat128ArrType_Type PyLongDoubleArrType_Type
|
| 1061 |
+
# define PyComplex256ArrType_Type PyCLongDoubleArrType_Type
|
| 1062 |
+
#define NPY_FLOAT128_FMT NPY_LONGDOUBLE_FMT
|
| 1063 |
+
#define NPY_COMPLEX256_FMT NPY_CLONGDOUBLE_FMT
|
| 1064 |
+
#endif
|
| 1065 |
+
#elif NPY_BITSOF_LONGDOUBLE == 256
|
| 1066 |
+
#define NPY_FLOAT256 NPY_LONGDOUBLE
|
| 1067 |
+
#define NPY_COMPLEX512 NPY_CLONGDOUBLE
|
| 1068 |
+
typedef npy_longdouble npy_float256;
|
| 1069 |
+
typedef npy_clongdouble npy_complex512;
|
| 1070 |
+
# define PyFloat256ScalarObject PyLongDoubleScalarObject
|
| 1071 |
+
# define PyComplex512ScalarObject PyCLongDoubleScalarObject
|
| 1072 |
+
# define PyFloat256ArrType_Type PyLongDoubleArrType_Type
|
| 1073 |
+
# define PyComplex512ArrType_Type PyCLongDoubleArrType_Type
|
| 1074 |
+
#define NPY_FLOAT256_FMT NPY_LONGDOUBLE_FMT
|
| 1075 |
+
#define NPY_COMPLEX512_FMT NPY_CLONGDOUBLE_FMT
|
| 1076 |
+
#endif
|
| 1077 |
+
|
| 1078 |
+
/* datetime typedefs */
|
| 1079 |
+
typedef npy_int64 npy_timedelta;
|
| 1080 |
+
typedef npy_int64 npy_datetime;
|
| 1081 |
+
#define NPY_DATETIME_FMT NPY_INT64_FMT
|
| 1082 |
+
#define NPY_TIMEDELTA_FMT NPY_INT64_FMT
|
| 1083 |
+
|
| 1084 |
+
/* End of typedefs for numarray style bit-width names */
|
| 1085 |
+
|
| 1086 |
+
#endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_COMMON_H_ */
|
.venv/lib/python3.11/site-packages/numpy/core/include/numpy/npy_cpu.h
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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PY_NPY_CPU_H_
|
| 26 |
+
|
| 27 |
+
#include "numpyconfig.h"
|
| 28 |
+
|
| 29 |
+
#if defined( __i386__ ) || defined(i386) || defined(_M_IX86)
|
| 30 |
+
/*
|
| 31 |
+
* __i386__ is defined by gcc and Intel compiler on Linux,
|
| 32 |
+
* _M_IX86 by VS compiler,
|
| 33 |
+
* i386 by Sun compilers on opensolaris at least
|
| 34 |
+
*/
|
| 35 |
+
#define NPY_CPU_X86
|
| 36 |
+
#elif defined(__x86_64__) || defined(__amd64__) || defined(__x86_64) || defined(_M_AMD64)
|
| 37 |
+
/*
|
| 38 |
+
* both __x86_64__ and __amd64__ are defined by gcc
|
| 39 |
+
* __x86_64 defined by sun compiler on opensolaris at least
|
| 40 |
+
* _M_AMD64 defined by MS compiler
|
| 41 |
+
*/
|
| 42 |
+
#define NPY_CPU_AMD64
|
| 43 |
+
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)
|
| 44 |
+
#define NPY_CPU_PPC64LE
|
| 45 |
+
#elif defined(__powerpc64__) && defined(__BIG_ENDIAN__)
|
| 46 |
+
#define NPY_CPU_PPC64
|
| 47 |
+
#elif defined(__ppc__) || defined(__powerpc__) || defined(_ARCH_PPC)
|
| 48 |
+
/*
|
| 49 |
+
* __ppc__ is defined by gcc, I remember having seen __powerpc__ once,
|
| 50 |
+
* but can't find it ATM
|
| 51 |
+
* _ARCH_PPC is used by at least gcc on AIX
|
| 52 |
+
* As __powerpc__ and _ARCH_PPC are also defined by PPC64 check
|
| 53 |
+
* for those specifically first before defaulting to ppc
|
| 54 |
+
*/
|
| 55 |
+
#define NPY_CPU_PPC
|
| 56 |
+
#elif defined(__sparc__) || defined(__sparc)
|
| 57 |
+
/* __sparc__ is defined by gcc and Forte (e.g. Sun) compilers */
|
| 58 |
+
#define NPY_CPU_SPARC
|
| 59 |
+
#elif defined(__s390__)
|
| 60 |
+
#define NPY_CPU_S390
|
| 61 |
+
#elif defined(__ia64)
|
| 62 |
+
#define NPY_CPU_IA64
|
| 63 |
+
#elif defined(__hppa)
|
| 64 |
+
#define NPY_CPU_HPPA
|
| 65 |
+
#elif defined(__alpha__)
|
| 66 |
+
#define NPY_CPU_ALPHA
|
| 67 |
+
#elif defined(__arm__) || defined(__aarch64__) || defined(_M_ARM64)
|
| 68 |
+
/* _M_ARM64 is defined in MSVC for ARM64 compilation on Windows */
|
| 69 |
+
#if defined(__ARMEB__) || defined(__AARCH64EB__)
|
| 70 |
+
#if defined(__ARM_32BIT_STATE)
|
| 71 |
+
#define NPY_CPU_ARMEB_AARCH32
|
| 72 |
+
#elif defined(__ARM_64BIT_STATE)
|
| 73 |
+
#define NPY_CPU_ARMEB_AARCH64
|
| 74 |
+
#else
|
| 75 |
+
#define NPY_CPU_ARMEB
|
| 76 |
+
#endif
|
| 77 |
+
#elif defined(__ARMEL__) || defined(__AARCH64EL__) || defined(_M_ARM64)
|
| 78 |
+
#if defined(__ARM_32BIT_STATE)
|
| 79 |
+
#define NPY_CPU_ARMEL_AARCH32
|
| 80 |
+
#elif defined(__ARM_64BIT_STATE) || defined(_M_ARM64) || defined(__AARCH64EL__)
|
| 81 |
+
#define NPY_CPU_ARMEL_AARCH64
|
| 82 |
+
#else
|
| 83 |
+
#define NPY_CPU_ARMEL
|
| 84 |
+
#endif
|
| 85 |
+
#else
|
| 86 |
+
# error Unknown ARM CPU, please report this to numpy maintainers with \
|
| 87 |
+
information about your platform (OS, CPU and compiler)
|
| 88 |
+
#endif
|
| 89 |
+
#elif defined(__sh__) && defined(__LITTLE_ENDIAN__)
|
| 90 |
+
#define NPY_CPU_SH_LE
|
| 91 |
+
#elif defined(__sh__) && defined(__BIG_ENDIAN__)
|
| 92 |
+
#define NPY_CPU_SH_BE
|
| 93 |
+
#elif defined(__MIPSEL__)
|
| 94 |
+
#define NPY_CPU_MIPSEL
|
| 95 |
+
#elif defined(__MIPSEB__)
|
| 96 |
+
#define NPY_CPU_MIPSEB
|
| 97 |
+
#elif defined(__or1k__)
|
| 98 |
+
#define NPY_CPU_OR1K
|
| 99 |
+
#elif defined(__mc68000__)
|
| 100 |
+
#define NPY_CPU_M68K
|
| 101 |
+
#elif defined(__arc__) && defined(__LITTLE_ENDIAN__)
|
| 102 |
+
#define NPY_CPU_ARCEL
|
| 103 |
+
#elif defined(__arc__) && defined(__BIG_ENDIAN__)
|
| 104 |
+
#define NPY_CPU_ARCEB
|
| 105 |
+
#elif defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64
|
| 106 |
+
#define NPY_CPU_RISCV64
|
| 107 |
+
#elif defined(__loongarch__)
|
| 108 |
+
#define NPY_CPU_LOONGARCH
|
| 109 |
+
#elif defined(__EMSCRIPTEN__)
|
| 110 |
+
/* __EMSCRIPTEN__ is defined by emscripten: an LLVM-to-Web compiler */
|
| 111 |
+
#define NPY_CPU_WASM
|
| 112 |
+
#else
|
| 113 |
+
#error Unknown CPU, please report this to numpy maintainers with \
|
| 114 |
+
information about your platform (OS, CPU and compiler)
|
| 115 |
+
#endif
|
| 116 |
+
|
| 117 |
+
/*
|
| 118 |
+
* Except for the following architectures, memory access is limited to the natural
|
| 119 |
+
* alignment of data types otherwise it may lead to bus error or performance regression.
|
| 120 |
+
* For more details about unaligned access, see https://www.kernel.org/doc/Documentation/unaligned-memory-access.txt.
|
| 121 |
+
*/
|
| 122 |
+
#if defined(NPY_CPU_X86) || defined(NPY_CPU_AMD64) || defined(__aarch64__) || defined(__powerpc64__)
|
| 123 |
+
#define NPY_ALIGNMENT_REQUIRED 0
|
| 124 |
+
#endif
|
| 125 |
+
#ifndef NPY_ALIGNMENT_REQUIRED
|
| 126 |
+
#define NPY_ALIGNMENT_REQUIRED 1
|
| 127 |
+
#endif
|
| 128 |
+
|
| 129 |
+
#endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_CPU_H_ */
|