Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_methods.py +234 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/defchararray.pyi +421 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/multiarray.py +1715 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/numerictypes.py +689 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/__init__.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/__main__.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/__version__.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/_isocbind.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/capi_maps.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/cb_rules.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/f2py2e.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/f90mod_rules.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/func2subr.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/rules.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/setup.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/symbolic.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/use_rules.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/_backends/__init__.py +9 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/_backends/_backend.py +46 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/_backends/_distutils.py +75 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/_backends/_meson.py +205 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/_backends/meson.build.template +54 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/src/fortranobject.c +1423 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/src/fortranobject.h +173 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/tests/__pycache__/test_abstract_interface.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/tests/__pycache__/test_return_complex.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/tests/__pycache__/test_value_attrspec.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/fft/_pocketfft.py +1424 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/fft/_pocketfft_internal.cpython-312-x86_64-linux-gnu.so +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/fft/helper.pyi +47 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/typing/tests/data/pass/__pycache__/array_like.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/typing/tests/data/pass/__pycache__/simple.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_acc/__init__.pyi +15 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_dynamo/__init__.pyi +4 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_dynamo/compiled_autograd.pyi +13 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_dynamo/eval_frame.pyi +84 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_dynamo/guards.pyi +452 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_export/__init__.pyi +9 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_export/pt2_archive_constants.pyi +25 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_custom_op/__pycache__/__init__.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_custom_op/__pycache__/autograd.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_custom_op/__pycache__/impl.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/amp/__pycache__/__init__.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/amp/__pycache__/autocast_mode.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/amp/__pycache__/grad_scaler.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/contrib/__pycache__/__init__.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/contrib/__pycache__/_tensorboard_vis.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/amp/__pycache__/__init__.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/amp/__pycache__/autocast_mode.cpython-312.pyc +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/amp/__pycache__/common.cpython-312.pyc +0 -0
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/_methods.py
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/defchararray.pyi
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import (
|
| 2 |
+
Literal as L,
|
| 3 |
+
overload,
|
| 4 |
+
TypeVar,
|
| 5 |
+
Any,
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
from numpy import (
|
| 9 |
+
chararray as chararray,
|
| 10 |
+
dtype,
|
| 11 |
+
str_,
|
| 12 |
+
bytes_,
|
| 13 |
+
int_,
|
| 14 |
+
bool_,
|
| 15 |
+
object_,
|
| 16 |
+
_OrderKACF,
|
| 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_]: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/multiarray.py
ADDED
|
@@ -0,0 +1,1715 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Create the numpy.core.multiarray namespace for backward compatibility. In v1.16
|
| 3 |
+
the multiarray and umath c-extension modules were merged into a single
|
| 4 |
+
_multiarray_umath extension module. So we replicate the old namespace
|
| 5 |
+
by importing from the extension module.
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import functools
|
| 10 |
+
from . import overrides
|
| 11 |
+
from . import _multiarray_umath
|
| 12 |
+
from ._multiarray_umath import * # noqa: F403
|
| 13 |
+
# These imports are needed for backward compatibility,
|
| 14 |
+
# do not change them. issue gh-15518
|
| 15 |
+
# _get_ndarray_c_version is semi-public, on purpose not added to __all__
|
| 16 |
+
from ._multiarray_umath import (
|
| 17 |
+
fastCopyAndTranspose, _flagdict, from_dlpack, _place, _reconstruct,
|
| 18 |
+
_vec_string, _ARRAY_API, _monotonicity, _get_ndarray_c_version,
|
| 19 |
+
_get_madvise_hugepage, _set_madvise_hugepage,
|
| 20 |
+
_get_promotion_state, _set_promotion_state, _using_numpy2_behavior
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
__all__ = [
|
| 24 |
+
'_ARRAY_API', 'ALLOW_THREADS', 'BUFSIZE', 'CLIP', 'DATETIMEUNITS',
|
| 25 |
+
'ITEM_HASOBJECT', 'ITEM_IS_POINTER', 'LIST_PICKLE', 'MAXDIMS',
|
| 26 |
+
'MAY_SHARE_BOUNDS', 'MAY_SHARE_EXACT', 'NEEDS_INIT', 'NEEDS_PYAPI',
|
| 27 |
+
'RAISE', 'USE_GETITEM', 'USE_SETITEM', 'WRAP',
|
| 28 |
+
'_flagdict', 'from_dlpack', '_place', '_reconstruct', '_vec_string',
|
| 29 |
+
'_monotonicity', 'add_docstring', 'arange', 'array', 'asarray',
|
| 30 |
+
'asanyarray', 'ascontiguousarray', 'asfortranarray', 'bincount',
|
| 31 |
+
'broadcast', 'busday_count', 'busday_offset', 'busdaycalendar', 'can_cast',
|
| 32 |
+
'compare_chararrays', 'concatenate', 'copyto', 'correlate', 'correlate2',
|
| 33 |
+
'count_nonzero', 'c_einsum', 'datetime_as_string', 'datetime_data',
|
| 34 |
+
'dot', 'dragon4_positional', 'dragon4_scientific', 'dtype',
|
| 35 |
+
'empty', 'empty_like', 'error', 'flagsobj', 'flatiter', 'format_longfloat',
|
| 36 |
+
'frombuffer', 'fromfile', 'fromiter', 'fromstring',
|
| 37 |
+
'get_handler_name', 'get_handler_version', 'inner', 'interp',
|
| 38 |
+
'interp_complex', 'is_busday', 'lexsort', 'matmul', 'may_share_memory',
|
| 39 |
+
'min_scalar_type', 'ndarray', 'nditer', 'nested_iters',
|
| 40 |
+
'normalize_axis_index', 'packbits', 'promote_types', 'putmask',
|
| 41 |
+
'ravel_multi_index', 'result_type', 'scalar', 'set_datetimeparse_function',
|
| 42 |
+
'set_legacy_print_mode', 'set_numeric_ops', 'set_string_function',
|
| 43 |
+
'set_typeDict', 'shares_memory', 'tracemalloc_domain', 'typeinfo',
|
| 44 |
+
'unpackbits', 'unravel_index', 'vdot', 'where', 'zeros',
|
| 45 |
+
'_get_promotion_state', '_set_promotion_state', '_using_numpy2_behavior']
|
| 46 |
+
|
| 47 |
+
# For backward compatibility, make sure pickle imports these functions from here
|
| 48 |
+
_reconstruct.__module__ = 'numpy.core.multiarray'
|
| 49 |
+
scalar.__module__ = 'numpy.core.multiarray'
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
from_dlpack.__module__ = 'numpy'
|
| 53 |
+
arange.__module__ = 'numpy'
|
| 54 |
+
array.__module__ = 'numpy'
|
| 55 |
+
asarray.__module__ = 'numpy'
|
| 56 |
+
asanyarray.__module__ = 'numpy'
|
| 57 |
+
ascontiguousarray.__module__ = 'numpy'
|
| 58 |
+
asfortranarray.__module__ = 'numpy'
|
| 59 |
+
datetime_data.__module__ = 'numpy'
|
| 60 |
+
empty.__module__ = 'numpy'
|
| 61 |
+
frombuffer.__module__ = 'numpy'
|
| 62 |
+
fromfile.__module__ = 'numpy'
|
| 63 |
+
fromiter.__module__ = 'numpy'
|
| 64 |
+
frompyfunc.__module__ = 'numpy'
|
| 65 |
+
fromstring.__module__ = 'numpy'
|
| 66 |
+
geterrobj.__module__ = 'numpy'
|
| 67 |
+
may_share_memory.__module__ = 'numpy'
|
| 68 |
+
nested_iters.__module__ = 'numpy'
|
| 69 |
+
promote_types.__module__ = 'numpy'
|
| 70 |
+
set_numeric_ops.__module__ = 'numpy'
|
| 71 |
+
seterrobj.__module__ = 'numpy'
|
| 72 |
+
zeros.__module__ = 'numpy'
|
| 73 |
+
_get_promotion_state.__module__ = 'numpy'
|
| 74 |
+
_set_promotion_state.__module__ = 'numpy'
|
| 75 |
+
_using_numpy2_behavior.__module__ = 'numpy'
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
# We can't verify dispatcher signatures because NumPy's C functions don't
|
| 79 |
+
# support introspection.
|
| 80 |
+
array_function_from_c_func_and_dispatcher = functools.partial(
|
| 81 |
+
overrides.array_function_from_dispatcher,
|
| 82 |
+
module='numpy', docs_from_dispatcher=True, verify=False)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.empty_like)
|
| 86 |
+
def empty_like(prototype, dtype=None, order=None, subok=None, shape=None):
|
| 87 |
+
"""
|
| 88 |
+
empty_like(prototype, dtype=None, order='K', subok=True, shape=None)
|
| 89 |
+
|
| 90 |
+
Return a new array with the same shape and type as a given array.
|
| 91 |
+
|
| 92 |
+
Parameters
|
| 93 |
+
----------
|
| 94 |
+
prototype : array_like
|
| 95 |
+
The shape and data-type of `prototype` define these same attributes
|
| 96 |
+
of the returned array.
|
| 97 |
+
dtype : data-type, optional
|
| 98 |
+
Overrides the data type of the result.
|
| 99 |
+
|
| 100 |
+
.. versionadded:: 1.6.0
|
| 101 |
+
order : {'C', 'F', 'A', or 'K'}, optional
|
| 102 |
+
Overrides the memory layout of the result. 'C' means C-order,
|
| 103 |
+
'F' means F-order, 'A' means 'F' if `prototype` is Fortran
|
| 104 |
+
contiguous, 'C' otherwise. 'K' means match the layout of `prototype`
|
| 105 |
+
as closely as possible.
|
| 106 |
+
|
| 107 |
+
.. versionadded:: 1.6.0
|
| 108 |
+
subok : bool, optional.
|
| 109 |
+
If True, then the newly created array will use the sub-class
|
| 110 |
+
type of `prototype`, otherwise it will be a base-class array. Defaults
|
| 111 |
+
to True.
|
| 112 |
+
shape : int or sequence of ints, optional.
|
| 113 |
+
Overrides the shape of the result. If order='K' and the number of
|
| 114 |
+
dimensions is unchanged, will try to keep order, otherwise,
|
| 115 |
+
order='C' is implied.
|
| 116 |
+
|
| 117 |
+
.. versionadded:: 1.17.0
|
| 118 |
+
|
| 119 |
+
Returns
|
| 120 |
+
-------
|
| 121 |
+
out : ndarray
|
| 122 |
+
Array of uninitialized (arbitrary) data with the same
|
| 123 |
+
shape and type as `prototype`.
|
| 124 |
+
|
| 125 |
+
See Also
|
| 126 |
+
--------
|
| 127 |
+
ones_like : Return an array of ones with shape and type of input.
|
| 128 |
+
zeros_like : Return an array of zeros with shape and type of input.
|
| 129 |
+
full_like : Return a new array with shape of input filled with value.
|
| 130 |
+
empty : Return a new uninitialized array.
|
| 131 |
+
|
| 132 |
+
Notes
|
| 133 |
+
-----
|
| 134 |
+
This function does *not* initialize the returned array; to do that use
|
| 135 |
+
`zeros_like` or `ones_like` instead. It may be marginally faster than
|
| 136 |
+
the functions that do set the array values.
|
| 137 |
+
|
| 138 |
+
Examples
|
| 139 |
+
--------
|
| 140 |
+
>>> a = ([1,2,3], [4,5,6]) # a is array-like
|
| 141 |
+
>>> np.empty_like(a)
|
| 142 |
+
array([[-1073741821, -1073741821, 3], # uninitialized
|
| 143 |
+
[ 0, 0, -1073741821]])
|
| 144 |
+
>>> a = np.array([[1., 2., 3.],[4.,5.,6.]])
|
| 145 |
+
>>> np.empty_like(a)
|
| 146 |
+
array([[ -2.00000715e+000, 1.48219694e-323, -2.00000572e+000], # uninitialized
|
| 147 |
+
[ 4.38791518e-305, -2.00000715e+000, 4.17269252e-309]])
|
| 148 |
+
|
| 149 |
+
"""
|
| 150 |
+
return (prototype,)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.concatenate)
|
| 154 |
+
def concatenate(arrays, axis=None, out=None, *, dtype=None, casting=None):
|
| 155 |
+
"""
|
| 156 |
+
concatenate((a1, a2, ...), axis=0, out=None, dtype=None, casting="same_kind")
|
| 157 |
+
|
| 158 |
+
Join a sequence of arrays along an existing axis.
|
| 159 |
+
|
| 160 |
+
Parameters
|
| 161 |
+
----------
|
| 162 |
+
a1, a2, ... : sequence of array_like
|
| 163 |
+
The arrays must have the same shape, except in the dimension
|
| 164 |
+
corresponding to `axis` (the first, by default).
|
| 165 |
+
axis : int, optional
|
| 166 |
+
The axis along which the arrays will be joined. If axis is None,
|
| 167 |
+
arrays are flattened before use. Default is 0.
|
| 168 |
+
out : ndarray, optional
|
| 169 |
+
If provided, the destination to place the result. The shape must be
|
| 170 |
+
correct, matching that of what concatenate would have returned if no
|
| 171 |
+
out argument were specified.
|
| 172 |
+
dtype : str or dtype
|
| 173 |
+
If provided, the destination array will have this dtype. Cannot be
|
| 174 |
+
provided together with `out`.
|
| 175 |
+
|
| 176 |
+
.. versionadded:: 1.20.0
|
| 177 |
+
|
| 178 |
+
casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
|
| 179 |
+
Controls what kind of data casting may occur. Defaults to 'same_kind'.
|
| 180 |
+
|
| 181 |
+
.. versionadded:: 1.20.0
|
| 182 |
+
|
| 183 |
+
Returns
|
| 184 |
+
-------
|
| 185 |
+
res : ndarray
|
| 186 |
+
The concatenated array.
|
| 187 |
+
|
| 188 |
+
See Also
|
| 189 |
+
--------
|
| 190 |
+
ma.concatenate : Concatenate function that preserves input masks.
|
| 191 |
+
array_split : Split an array into multiple sub-arrays of equal or
|
| 192 |
+
near-equal size.
|
| 193 |
+
split : Split array into a list of multiple sub-arrays of equal size.
|
| 194 |
+
hsplit : Split array into multiple sub-arrays horizontally (column wise).
|
| 195 |
+
vsplit : Split array into multiple sub-arrays vertically (row wise).
|
| 196 |
+
dsplit : Split array into multiple sub-arrays along the 3rd axis (depth).
|
| 197 |
+
stack : Stack a sequence of arrays along a new axis.
|
| 198 |
+
block : Assemble arrays from blocks.
|
| 199 |
+
hstack : Stack arrays in sequence horizontally (column wise).
|
| 200 |
+
vstack : Stack arrays in sequence vertically (row wise).
|
| 201 |
+
dstack : Stack arrays in sequence depth wise (along third dimension).
|
| 202 |
+
column_stack : Stack 1-D arrays as columns into a 2-D array.
|
| 203 |
+
|
| 204 |
+
Notes
|
| 205 |
+
-----
|
| 206 |
+
When one or more of the arrays to be concatenated is a MaskedArray,
|
| 207 |
+
this function will return a MaskedArray object instead of an ndarray,
|
| 208 |
+
but the input masks are *not* preserved. In cases where a MaskedArray
|
| 209 |
+
is expected as input, use the ma.concatenate function from the masked
|
| 210 |
+
array module instead.
|
| 211 |
+
|
| 212 |
+
Examples
|
| 213 |
+
--------
|
| 214 |
+
>>> a = np.array([[1, 2], [3, 4]])
|
| 215 |
+
>>> b = np.array([[5, 6]])
|
| 216 |
+
>>> np.concatenate((a, b), axis=0)
|
| 217 |
+
array([[1, 2],
|
| 218 |
+
[3, 4],
|
| 219 |
+
[5, 6]])
|
| 220 |
+
>>> np.concatenate((a, b.T), axis=1)
|
| 221 |
+
array([[1, 2, 5],
|
| 222 |
+
[3, 4, 6]])
|
| 223 |
+
>>> np.concatenate((a, b), axis=None)
|
| 224 |
+
array([1, 2, 3, 4, 5, 6])
|
| 225 |
+
|
| 226 |
+
This function will not preserve masking of MaskedArray inputs.
|
| 227 |
+
|
| 228 |
+
>>> a = np.ma.arange(3)
|
| 229 |
+
>>> a[1] = np.ma.masked
|
| 230 |
+
>>> b = np.arange(2, 5)
|
| 231 |
+
>>> a
|
| 232 |
+
masked_array(data=[0, --, 2],
|
| 233 |
+
mask=[False, True, False],
|
| 234 |
+
fill_value=999999)
|
| 235 |
+
>>> b
|
| 236 |
+
array([2, 3, 4])
|
| 237 |
+
>>> np.concatenate([a, b])
|
| 238 |
+
masked_array(data=[0, 1, 2, 2, 3, 4],
|
| 239 |
+
mask=False,
|
| 240 |
+
fill_value=999999)
|
| 241 |
+
>>> np.ma.concatenate([a, b])
|
| 242 |
+
masked_array(data=[0, --, 2, 2, 3, 4],
|
| 243 |
+
mask=[False, True, False, False, False, False],
|
| 244 |
+
fill_value=999999)
|
| 245 |
+
|
| 246 |
+
"""
|
| 247 |
+
if out is not None:
|
| 248 |
+
# optimize for the typical case where only arrays is provided
|
| 249 |
+
arrays = list(arrays)
|
| 250 |
+
arrays.append(out)
|
| 251 |
+
return arrays
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.inner)
|
| 255 |
+
def inner(a, b):
|
| 256 |
+
"""
|
| 257 |
+
inner(a, b, /)
|
| 258 |
+
|
| 259 |
+
Inner product of two arrays.
|
| 260 |
+
|
| 261 |
+
Ordinary inner product of vectors for 1-D arrays (without complex
|
| 262 |
+
conjugation), in higher dimensions a sum product over the last axes.
|
| 263 |
+
|
| 264 |
+
Parameters
|
| 265 |
+
----------
|
| 266 |
+
a, b : array_like
|
| 267 |
+
If `a` and `b` are nonscalar, their last dimensions must match.
|
| 268 |
+
|
| 269 |
+
Returns
|
| 270 |
+
-------
|
| 271 |
+
out : ndarray
|
| 272 |
+
If `a` and `b` are both
|
| 273 |
+
scalars or both 1-D arrays then a scalar is returned; otherwise
|
| 274 |
+
an array is returned.
|
| 275 |
+
``out.shape = (*a.shape[:-1], *b.shape[:-1])``
|
| 276 |
+
|
| 277 |
+
Raises
|
| 278 |
+
------
|
| 279 |
+
ValueError
|
| 280 |
+
If both `a` and `b` are nonscalar and their last dimensions have
|
| 281 |
+
different sizes.
|
| 282 |
+
|
| 283 |
+
See Also
|
| 284 |
+
--------
|
| 285 |
+
tensordot : Sum products over arbitrary axes.
|
| 286 |
+
dot : Generalised matrix product, using second last dimension of `b`.
|
| 287 |
+
einsum : Einstein summation convention.
|
| 288 |
+
|
| 289 |
+
Notes
|
| 290 |
+
-----
|
| 291 |
+
For vectors (1-D arrays) it computes the ordinary inner-product::
|
| 292 |
+
|
| 293 |
+
np.inner(a, b) = sum(a[:]*b[:])
|
| 294 |
+
|
| 295 |
+
More generally, if ``ndim(a) = r > 0`` and ``ndim(b) = s > 0``::
|
| 296 |
+
|
| 297 |
+
np.inner(a, b) = np.tensordot(a, b, axes=(-1,-1))
|
| 298 |
+
|
| 299 |
+
or explicitly::
|
| 300 |
+
|
| 301 |
+
np.inner(a, b)[i0,...,ir-2,j0,...,js-2]
|
| 302 |
+
= sum(a[i0,...,ir-2,:]*b[j0,...,js-2,:])
|
| 303 |
+
|
| 304 |
+
In addition `a` or `b` may be scalars, in which case::
|
| 305 |
+
|
| 306 |
+
np.inner(a,b) = a*b
|
| 307 |
+
|
| 308 |
+
Examples
|
| 309 |
+
--------
|
| 310 |
+
Ordinary inner product for vectors:
|
| 311 |
+
|
| 312 |
+
>>> a = np.array([1,2,3])
|
| 313 |
+
>>> b = np.array([0,1,0])
|
| 314 |
+
>>> np.inner(a, b)
|
| 315 |
+
2
|
| 316 |
+
|
| 317 |
+
Some multidimensional examples:
|
| 318 |
+
|
| 319 |
+
>>> a = np.arange(24).reshape((2,3,4))
|
| 320 |
+
>>> b = np.arange(4)
|
| 321 |
+
>>> c = np.inner(a, b)
|
| 322 |
+
>>> c.shape
|
| 323 |
+
(2, 3)
|
| 324 |
+
>>> c
|
| 325 |
+
array([[ 14, 38, 62],
|
| 326 |
+
[ 86, 110, 134]])
|
| 327 |
+
|
| 328 |
+
>>> a = np.arange(2).reshape((1,1,2))
|
| 329 |
+
>>> b = np.arange(6).reshape((3,2))
|
| 330 |
+
>>> c = np.inner(a, b)
|
| 331 |
+
>>> c.shape
|
| 332 |
+
(1, 1, 3)
|
| 333 |
+
>>> c
|
| 334 |
+
array([[[1, 3, 5]]])
|
| 335 |
+
|
| 336 |
+
An example where `b` is a scalar:
|
| 337 |
+
|
| 338 |
+
>>> np.inner(np.eye(2), 7)
|
| 339 |
+
array([[7., 0.],
|
| 340 |
+
[0., 7.]])
|
| 341 |
+
|
| 342 |
+
"""
|
| 343 |
+
return (a, b)
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.where)
|
| 347 |
+
def where(condition, x=None, y=None):
|
| 348 |
+
"""
|
| 349 |
+
where(condition, [x, y], /)
|
| 350 |
+
|
| 351 |
+
Return elements chosen from `x` or `y` depending on `condition`.
|
| 352 |
+
|
| 353 |
+
.. note::
|
| 354 |
+
When only `condition` is provided, this function is a shorthand for
|
| 355 |
+
``np.asarray(condition).nonzero()``. Using `nonzero` directly should be
|
| 356 |
+
preferred, as it behaves correctly for subclasses. The rest of this
|
| 357 |
+
documentation covers only the case where all three arguments are
|
| 358 |
+
provided.
|
| 359 |
+
|
| 360 |
+
Parameters
|
| 361 |
+
----------
|
| 362 |
+
condition : array_like, bool
|
| 363 |
+
Where True, yield `x`, otherwise yield `y`.
|
| 364 |
+
x, y : array_like
|
| 365 |
+
Values from which to choose. `x`, `y` and `condition` need to be
|
| 366 |
+
broadcastable to some shape.
|
| 367 |
+
|
| 368 |
+
Returns
|
| 369 |
+
-------
|
| 370 |
+
out : ndarray
|
| 371 |
+
An array with elements from `x` where `condition` is True, and elements
|
| 372 |
+
from `y` elsewhere.
|
| 373 |
+
|
| 374 |
+
See Also
|
| 375 |
+
--------
|
| 376 |
+
choose
|
| 377 |
+
nonzero : The function that is called when x and y are omitted
|
| 378 |
+
|
| 379 |
+
Notes
|
| 380 |
+
-----
|
| 381 |
+
If all the arrays are 1-D, `where` is equivalent to::
|
| 382 |
+
|
| 383 |
+
[xv if c else yv
|
| 384 |
+
for c, xv, yv in zip(condition, x, y)]
|
| 385 |
+
|
| 386 |
+
Examples
|
| 387 |
+
--------
|
| 388 |
+
>>> a = np.arange(10)
|
| 389 |
+
>>> a
|
| 390 |
+
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
|
| 391 |
+
>>> np.where(a < 5, a, 10*a)
|
| 392 |
+
array([ 0, 1, 2, 3, 4, 50, 60, 70, 80, 90])
|
| 393 |
+
|
| 394 |
+
This can be used on multidimensional arrays too:
|
| 395 |
+
|
| 396 |
+
>>> np.where([[True, False], [True, True]],
|
| 397 |
+
... [[1, 2], [3, 4]],
|
| 398 |
+
... [[9, 8], [7, 6]])
|
| 399 |
+
array([[1, 8],
|
| 400 |
+
[3, 4]])
|
| 401 |
+
|
| 402 |
+
The shapes of x, y, and the condition are broadcast together:
|
| 403 |
+
|
| 404 |
+
>>> x, y = np.ogrid[:3, :4]
|
| 405 |
+
>>> np.where(x < y, x, 10 + y) # both x and 10+y are broadcast
|
| 406 |
+
array([[10, 0, 0, 0],
|
| 407 |
+
[10, 11, 1, 1],
|
| 408 |
+
[10, 11, 12, 2]])
|
| 409 |
+
|
| 410 |
+
>>> a = np.array([[0, 1, 2],
|
| 411 |
+
... [0, 2, 4],
|
| 412 |
+
... [0, 3, 6]])
|
| 413 |
+
>>> np.where(a < 4, a, -1) # -1 is broadcast
|
| 414 |
+
array([[ 0, 1, 2],
|
| 415 |
+
[ 0, 2, -1],
|
| 416 |
+
[ 0, 3, -1]])
|
| 417 |
+
"""
|
| 418 |
+
return (condition, x, y)
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.lexsort)
|
| 422 |
+
def lexsort(keys, axis=None):
|
| 423 |
+
"""
|
| 424 |
+
lexsort(keys, axis=-1)
|
| 425 |
+
|
| 426 |
+
Perform an indirect stable sort using a sequence of keys.
|
| 427 |
+
|
| 428 |
+
Given multiple sorting keys, which can be interpreted as columns in a
|
| 429 |
+
spreadsheet, lexsort returns an array of integer indices that describes
|
| 430 |
+
the sort order by multiple columns. The last key in the sequence is used
|
| 431 |
+
for the primary sort order, the second-to-last key for the secondary sort
|
| 432 |
+
order, and so on. The keys argument must be a sequence of objects that
|
| 433 |
+
can be converted to arrays of the same shape. If a 2D array is provided
|
| 434 |
+
for the keys argument, its rows are interpreted as the sorting keys and
|
| 435 |
+
sorting is according to the last row, second last row etc.
|
| 436 |
+
|
| 437 |
+
Parameters
|
| 438 |
+
----------
|
| 439 |
+
keys : (k, N) array or tuple containing k (N,)-shaped sequences
|
| 440 |
+
The `k` different "columns" to be sorted. The last column (or row if
|
| 441 |
+
`keys` is a 2D array) is the primary sort key.
|
| 442 |
+
axis : int, optional
|
| 443 |
+
Axis to be indirectly sorted. By default, sort over the last axis.
|
| 444 |
+
|
| 445 |
+
Returns
|
| 446 |
+
-------
|
| 447 |
+
indices : (N,) ndarray of ints
|
| 448 |
+
Array of indices that sort the keys along the specified axis.
|
| 449 |
+
|
| 450 |
+
See Also
|
| 451 |
+
--------
|
| 452 |
+
argsort : Indirect sort.
|
| 453 |
+
ndarray.sort : In-place sort.
|
| 454 |
+
sort : Return a sorted copy of an array.
|
| 455 |
+
|
| 456 |
+
Examples
|
| 457 |
+
--------
|
| 458 |
+
Sort names: first by surname, then by name.
|
| 459 |
+
|
| 460 |
+
>>> surnames = ('Hertz', 'Galilei', 'Hertz')
|
| 461 |
+
>>> first_names = ('Heinrich', 'Galileo', 'Gustav')
|
| 462 |
+
>>> ind = np.lexsort((first_names, surnames))
|
| 463 |
+
>>> ind
|
| 464 |
+
array([1, 2, 0])
|
| 465 |
+
|
| 466 |
+
>>> [surnames[i] + ", " + first_names[i] for i in ind]
|
| 467 |
+
['Galilei, Galileo', 'Hertz, Gustav', 'Hertz, Heinrich']
|
| 468 |
+
|
| 469 |
+
Sort two columns of numbers:
|
| 470 |
+
|
| 471 |
+
>>> a = [1,5,1,4,3,4,4] # First column
|
| 472 |
+
>>> b = [9,4,0,4,0,2,1] # Second column
|
| 473 |
+
>>> ind = np.lexsort((b,a)) # Sort by a, then by b
|
| 474 |
+
>>> ind
|
| 475 |
+
array([2, 0, 4, 6, 5, 3, 1])
|
| 476 |
+
|
| 477 |
+
>>> [(a[i],b[i]) for i in ind]
|
| 478 |
+
[(1, 0), (1, 9), (3, 0), (4, 1), (4, 2), (4, 4), (5, 4)]
|
| 479 |
+
|
| 480 |
+
Note that sorting is first according to the elements of ``a``.
|
| 481 |
+
Secondary sorting is according to the elements of ``b``.
|
| 482 |
+
|
| 483 |
+
A normal ``argsort`` would have yielded:
|
| 484 |
+
|
| 485 |
+
>>> [(a[i],b[i]) for i in np.argsort(a)]
|
| 486 |
+
[(1, 9), (1, 0), (3, 0), (4, 4), (4, 2), (4, 1), (5, 4)]
|
| 487 |
+
|
| 488 |
+
Structured arrays are sorted lexically by ``argsort``:
|
| 489 |
+
|
| 490 |
+
>>> x = np.array([(1,9), (5,4), (1,0), (4,4), (3,0), (4,2), (4,1)],
|
| 491 |
+
... dtype=np.dtype([('x', int), ('y', int)]))
|
| 492 |
+
|
| 493 |
+
>>> np.argsort(x) # or np.argsort(x, order=('x', 'y'))
|
| 494 |
+
array([2, 0, 4, 6, 5, 3, 1])
|
| 495 |
+
|
| 496 |
+
"""
|
| 497 |
+
if isinstance(keys, tuple):
|
| 498 |
+
return keys
|
| 499 |
+
else:
|
| 500 |
+
return (keys,)
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.can_cast)
|
| 504 |
+
def can_cast(from_, to, casting=None):
|
| 505 |
+
"""
|
| 506 |
+
can_cast(from_, to, casting='safe')
|
| 507 |
+
|
| 508 |
+
Returns True if cast between data types can occur according to the
|
| 509 |
+
casting rule. If from is a scalar or array scalar, also returns
|
| 510 |
+
True if the scalar value can be cast without overflow or truncation
|
| 511 |
+
to an integer.
|
| 512 |
+
|
| 513 |
+
Parameters
|
| 514 |
+
----------
|
| 515 |
+
from_ : dtype, dtype specifier, scalar, or array
|
| 516 |
+
Data type, scalar, or array to cast from.
|
| 517 |
+
to : dtype or dtype specifier
|
| 518 |
+
Data type to cast to.
|
| 519 |
+
casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
|
| 520 |
+
Controls what kind of data casting may occur.
|
| 521 |
+
|
| 522 |
+
* 'no' means the data types should not be cast at all.
|
| 523 |
+
* 'equiv' means only byte-order changes are allowed.
|
| 524 |
+
* 'safe' means only casts which can preserve values are allowed.
|
| 525 |
+
* 'same_kind' means only safe casts or casts within a kind,
|
| 526 |
+
like float64 to float32, are allowed.
|
| 527 |
+
* 'unsafe' means any data conversions may be done.
|
| 528 |
+
|
| 529 |
+
Returns
|
| 530 |
+
-------
|
| 531 |
+
out : bool
|
| 532 |
+
True if cast can occur according to the casting rule.
|
| 533 |
+
|
| 534 |
+
Notes
|
| 535 |
+
-----
|
| 536 |
+
.. versionchanged:: 1.17.0
|
| 537 |
+
Casting between a simple data type and a structured one is possible only
|
| 538 |
+
for "unsafe" casting. Casting to multiple fields is allowed, but
|
| 539 |
+
casting from multiple fields is not.
|
| 540 |
+
|
| 541 |
+
.. versionchanged:: 1.9.0
|
| 542 |
+
Casting from numeric to string types in 'safe' casting mode requires
|
| 543 |
+
that the string dtype length is long enough to store the maximum
|
| 544 |
+
integer/float value converted.
|
| 545 |
+
|
| 546 |
+
See also
|
| 547 |
+
--------
|
| 548 |
+
dtype, result_type
|
| 549 |
+
|
| 550 |
+
Examples
|
| 551 |
+
--------
|
| 552 |
+
Basic examples
|
| 553 |
+
|
| 554 |
+
>>> np.can_cast(np.int32, np.int64)
|
| 555 |
+
True
|
| 556 |
+
>>> np.can_cast(np.float64, complex)
|
| 557 |
+
True
|
| 558 |
+
>>> np.can_cast(complex, float)
|
| 559 |
+
False
|
| 560 |
+
|
| 561 |
+
>>> np.can_cast('i8', 'f8')
|
| 562 |
+
True
|
| 563 |
+
>>> np.can_cast('i8', 'f4')
|
| 564 |
+
False
|
| 565 |
+
>>> np.can_cast('i4', 'S4')
|
| 566 |
+
False
|
| 567 |
+
|
| 568 |
+
Casting scalars
|
| 569 |
+
|
| 570 |
+
>>> np.can_cast(100, 'i1')
|
| 571 |
+
True
|
| 572 |
+
>>> np.can_cast(150, 'i1')
|
| 573 |
+
False
|
| 574 |
+
>>> np.can_cast(150, 'u1')
|
| 575 |
+
True
|
| 576 |
+
|
| 577 |
+
>>> np.can_cast(3.5e100, np.float32)
|
| 578 |
+
False
|
| 579 |
+
>>> np.can_cast(1000.0, np.float32)
|
| 580 |
+
True
|
| 581 |
+
|
| 582 |
+
Array scalar checks the value, array does not
|
| 583 |
+
|
| 584 |
+
>>> np.can_cast(np.array(1000.0), np.float32)
|
| 585 |
+
True
|
| 586 |
+
>>> np.can_cast(np.array([1000.0]), np.float32)
|
| 587 |
+
False
|
| 588 |
+
|
| 589 |
+
Using the casting rules
|
| 590 |
+
|
| 591 |
+
>>> np.can_cast('i8', 'i8', 'no')
|
| 592 |
+
True
|
| 593 |
+
>>> np.can_cast('<i8', '>i8', 'no')
|
| 594 |
+
False
|
| 595 |
+
|
| 596 |
+
>>> np.can_cast('<i8', '>i8', 'equiv')
|
| 597 |
+
True
|
| 598 |
+
>>> np.can_cast('<i4', '>i8', 'equiv')
|
| 599 |
+
False
|
| 600 |
+
|
| 601 |
+
>>> np.can_cast('<i4', '>i8', 'safe')
|
| 602 |
+
True
|
| 603 |
+
>>> np.can_cast('<i8', '>i4', 'safe')
|
| 604 |
+
False
|
| 605 |
+
|
| 606 |
+
>>> np.can_cast('<i8', '>i4', 'same_kind')
|
| 607 |
+
True
|
| 608 |
+
>>> np.can_cast('<i8', '>u4', 'same_kind')
|
| 609 |
+
False
|
| 610 |
+
|
| 611 |
+
>>> np.can_cast('<i8', '>u4', 'unsafe')
|
| 612 |
+
True
|
| 613 |
+
|
| 614 |
+
"""
|
| 615 |
+
return (from_,)
|
| 616 |
+
|
| 617 |
+
|
| 618 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.min_scalar_type)
|
| 619 |
+
def min_scalar_type(a):
|
| 620 |
+
"""
|
| 621 |
+
min_scalar_type(a, /)
|
| 622 |
+
|
| 623 |
+
For scalar ``a``, returns the data type with the smallest size
|
| 624 |
+
and smallest scalar kind which can hold its value. For non-scalar
|
| 625 |
+
array ``a``, returns the vector's dtype unmodified.
|
| 626 |
+
|
| 627 |
+
Floating point values are not demoted to integers,
|
| 628 |
+
and complex values are not demoted to floats.
|
| 629 |
+
|
| 630 |
+
Parameters
|
| 631 |
+
----------
|
| 632 |
+
a : scalar or array_like
|
| 633 |
+
The value whose minimal data type is to be found.
|
| 634 |
+
|
| 635 |
+
Returns
|
| 636 |
+
-------
|
| 637 |
+
out : dtype
|
| 638 |
+
The minimal data type.
|
| 639 |
+
|
| 640 |
+
Notes
|
| 641 |
+
-----
|
| 642 |
+
.. versionadded:: 1.6.0
|
| 643 |
+
|
| 644 |
+
See Also
|
| 645 |
+
--------
|
| 646 |
+
result_type, promote_types, dtype, can_cast
|
| 647 |
+
|
| 648 |
+
Examples
|
| 649 |
+
--------
|
| 650 |
+
>>> np.min_scalar_type(10)
|
| 651 |
+
dtype('uint8')
|
| 652 |
+
|
| 653 |
+
>>> np.min_scalar_type(-260)
|
| 654 |
+
dtype('int16')
|
| 655 |
+
|
| 656 |
+
>>> np.min_scalar_type(3.1)
|
| 657 |
+
dtype('float16')
|
| 658 |
+
|
| 659 |
+
>>> np.min_scalar_type(1e50)
|
| 660 |
+
dtype('float64')
|
| 661 |
+
|
| 662 |
+
>>> np.min_scalar_type(np.arange(4,dtype='f8'))
|
| 663 |
+
dtype('float64')
|
| 664 |
+
|
| 665 |
+
"""
|
| 666 |
+
return (a,)
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.result_type)
|
| 670 |
+
def result_type(*arrays_and_dtypes):
|
| 671 |
+
"""
|
| 672 |
+
result_type(*arrays_and_dtypes)
|
| 673 |
+
|
| 674 |
+
Returns the type that results from applying the NumPy
|
| 675 |
+
type promotion rules to the arguments.
|
| 676 |
+
|
| 677 |
+
Type promotion in NumPy works similarly to the rules in languages
|
| 678 |
+
like C++, with some slight differences. When both scalars and
|
| 679 |
+
arrays are used, the array's type takes precedence and the actual value
|
| 680 |
+
of the scalar is taken into account.
|
| 681 |
+
|
| 682 |
+
For example, calculating 3*a, where a is an array of 32-bit floats,
|
| 683 |
+
intuitively should result in a 32-bit float output. If the 3 is a
|
| 684 |
+
32-bit integer, the NumPy rules indicate it can't convert losslessly
|
| 685 |
+
into a 32-bit float, so a 64-bit float should be the result type.
|
| 686 |
+
By examining the value of the constant, '3', we see that it fits in
|
| 687 |
+
an 8-bit integer, which can be cast losslessly into the 32-bit float.
|
| 688 |
+
|
| 689 |
+
Parameters
|
| 690 |
+
----------
|
| 691 |
+
arrays_and_dtypes : list of arrays and dtypes
|
| 692 |
+
The operands of some operation whose result type is needed.
|
| 693 |
+
|
| 694 |
+
Returns
|
| 695 |
+
-------
|
| 696 |
+
out : dtype
|
| 697 |
+
The result type.
|
| 698 |
+
|
| 699 |
+
See also
|
| 700 |
+
--------
|
| 701 |
+
dtype, promote_types, min_scalar_type, can_cast
|
| 702 |
+
|
| 703 |
+
Notes
|
| 704 |
+
-----
|
| 705 |
+
.. versionadded:: 1.6.0
|
| 706 |
+
|
| 707 |
+
The specific algorithm used is as follows.
|
| 708 |
+
|
| 709 |
+
Categories are determined by first checking which of boolean,
|
| 710 |
+
integer (int/uint), or floating point (float/complex) the maximum
|
| 711 |
+
kind of all the arrays and the scalars are.
|
| 712 |
+
|
| 713 |
+
If there are only scalars or the maximum category of the scalars
|
| 714 |
+
is higher than the maximum category of the arrays,
|
| 715 |
+
the data types are combined with :func:`promote_types`
|
| 716 |
+
to produce the return value.
|
| 717 |
+
|
| 718 |
+
Otherwise, `min_scalar_type` is called on each scalar, and
|
| 719 |
+
the resulting data types are all combined with :func:`promote_types`
|
| 720 |
+
to produce the return value.
|
| 721 |
+
|
| 722 |
+
The set of int values is not a subset of the uint values for types
|
| 723 |
+
with the same number of bits, something not reflected in
|
| 724 |
+
:func:`min_scalar_type`, but handled as a special case in `result_type`.
|
| 725 |
+
|
| 726 |
+
Examples
|
| 727 |
+
--------
|
| 728 |
+
>>> np.result_type(3, np.arange(7, dtype='i1'))
|
| 729 |
+
dtype('int8')
|
| 730 |
+
|
| 731 |
+
>>> np.result_type('i4', 'c8')
|
| 732 |
+
dtype('complex128')
|
| 733 |
+
|
| 734 |
+
>>> np.result_type(3.0, -2)
|
| 735 |
+
dtype('float64')
|
| 736 |
+
|
| 737 |
+
"""
|
| 738 |
+
return arrays_and_dtypes
|
| 739 |
+
|
| 740 |
+
|
| 741 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.dot)
|
| 742 |
+
def dot(a, b, out=None):
|
| 743 |
+
"""
|
| 744 |
+
dot(a, b, out=None)
|
| 745 |
+
|
| 746 |
+
Dot product of two arrays. Specifically,
|
| 747 |
+
|
| 748 |
+
- If both `a` and `b` are 1-D arrays, it is inner product of vectors
|
| 749 |
+
(without complex conjugation).
|
| 750 |
+
|
| 751 |
+
- If both `a` and `b` are 2-D arrays, it is matrix multiplication,
|
| 752 |
+
but using :func:`matmul` or ``a @ b`` is preferred.
|
| 753 |
+
|
| 754 |
+
- If either `a` or `b` is 0-D (scalar), it is equivalent to
|
| 755 |
+
:func:`multiply` and using ``numpy.multiply(a, b)`` or ``a * b`` is
|
| 756 |
+
preferred.
|
| 757 |
+
|
| 758 |
+
- If `a` is an N-D array and `b` is a 1-D array, it is a sum product over
|
| 759 |
+
the last axis of `a` and `b`.
|
| 760 |
+
|
| 761 |
+
- If `a` is an N-D array and `b` is an M-D array (where ``M>=2``), it is a
|
| 762 |
+
sum product over the last axis of `a` and the second-to-last axis of
|
| 763 |
+
`b`::
|
| 764 |
+
|
| 765 |
+
dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])
|
| 766 |
+
|
| 767 |
+
It uses an optimized BLAS library when possible (see `numpy.linalg`).
|
| 768 |
+
|
| 769 |
+
Parameters
|
| 770 |
+
----------
|
| 771 |
+
a : array_like
|
| 772 |
+
First argument.
|
| 773 |
+
b : array_like
|
| 774 |
+
Second argument.
|
| 775 |
+
out : ndarray, optional
|
| 776 |
+
Output argument. This must have the exact kind that would be returned
|
| 777 |
+
if it was not used. In particular, it must have the right type, must be
|
| 778 |
+
C-contiguous, and its dtype must be the dtype that would be returned
|
| 779 |
+
for `dot(a,b)`. This is a performance feature. Therefore, if these
|
| 780 |
+
conditions are not met, an exception is raised, instead of attempting
|
| 781 |
+
to be flexible.
|
| 782 |
+
|
| 783 |
+
Returns
|
| 784 |
+
-------
|
| 785 |
+
output : ndarray
|
| 786 |
+
Returns the dot product of `a` and `b`. If `a` and `b` are both
|
| 787 |
+
scalars or both 1-D arrays then a scalar is returned; otherwise
|
| 788 |
+
an array is returned.
|
| 789 |
+
If `out` is given, then it is returned.
|
| 790 |
+
|
| 791 |
+
Raises
|
| 792 |
+
------
|
| 793 |
+
ValueError
|
| 794 |
+
If the last dimension of `a` is not the same size as
|
| 795 |
+
the second-to-last dimension of `b`.
|
| 796 |
+
|
| 797 |
+
See Also
|
| 798 |
+
--------
|
| 799 |
+
vdot : Complex-conjugating dot product.
|
| 800 |
+
tensordot : Sum products over arbitrary axes.
|
| 801 |
+
einsum : Einstein summation convention.
|
| 802 |
+
matmul : '@' operator as method with out parameter.
|
| 803 |
+
linalg.multi_dot : Chained dot product.
|
| 804 |
+
|
| 805 |
+
Examples
|
| 806 |
+
--------
|
| 807 |
+
>>> np.dot(3, 4)
|
| 808 |
+
12
|
| 809 |
+
|
| 810 |
+
Neither argument is complex-conjugated:
|
| 811 |
+
|
| 812 |
+
>>> np.dot([2j, 3j], [2j, 3j])
|
| 813 |
+
(-13+0j)
|
| 814 |
+
|
| 815 |
+
For 2-D arrays it is the matrix product:
|
| 816 |
+
|
| 817 |
+
>>> a = [[1, 0], [0, 1]]
|
| 818 |
+
>>> b = [[4, 1], [2, 2]]
|
| 819 |
+
>>> np.dot(a, b)
|
| 820 |
+
array([[4, 1],
|
| 821 |
+
[2, 2]])
|
| 822 |
+
|
| 823 |
+
>>> a = np.arange(3*4*5*6).reshape((3,4,5,6))
|
| 824 |
+
>>> b = np.arange(3*4*5*6)[::-1].reshape((5,4,6,3))
|
| 825 |
+
>>> np.dot(a, b)[2,3,2,1,2,2]
|
| 826 |
+
499128
|
| 827 |
+
>>> sum(a[2,3,2,:] * b[1,2,:,2])
|
| 828 |
+
499128
|
| 829 |
+
|
| 830 |
+
"""
|
| 831 |
+
return (a, b, out)
|
| 832 |
+
|
| 833 |
+
|
| 834 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.vdot)
|
| 835 |
+
def vdot(a, b):
|
| 836 |
+
"""
|
| 837 |
+
vdot(a, b, /)
|
| 838 |
+
|
| 839 |
+
Return the dot product of two vectors.
|
| 840 |
+
|
| 841 |
+
The vdot(`a`, `b`) function handles complex numbers differently than
|
| 842 |
+
dot(`a`, `b`). If the first argument is complex the complex conjugate
|
| 843 |
+
of the first argument is used for the calculation of the dot product.
|
| 844 |
+
|
| 845 |
+
Note that `vdot` handles multidimensional arrays differently than `dot`:
|
| 846 |
+
it does *not* perform a matrix product, but flattens input arguments
|
| 847 |
+
to 1-D vectors first. Consequently, it should only be used for vectors.
|
| 848 |
+
|
| 849 |
+
Parameters
|
| 850 |
+
----------
|
| 851 |
+
a : array_like
|
| 852 |
+
If `a` is complex the complex conjugate is taken before calculation
|
| 853 |
+
of the dot product.
|
| 854 |
+
b : array_like
|
| 855 |
+
Second argument to the dot product.
|
| 856 |
+
|
| 857 |
+
Returns
|
| 858 |
+
-------
|
| 859 |
+
output : ndarray
|
| 860 |
+
Dot product of `a` and `b`. Can be an int, float, or
|
| 861 |
+
complex depending on the types of `a` and `b`.
|
| 862 |
+
|
| 863 |
+
See Also
|
| 864 |
+
--------
|
| 865 |
+
dot : Return the dot product without using the complex conjugate of the
|
| 866 |
+
first argument.
|
| 867 |
+
|
| 868 |
+
Examples
|
| 869 |
+
--------
|
| 870 |
+
>>> a = np.array([1+2j,3+4j])
|
| 871 |
+
>>> b = np.array([5+6j,7+8j])
|
| 872 |
+
>>> np.vdot(a, b)
|
| 873 |
+
(70-8j)
|
| 874 |
+
>>> np.vdot(b, a)
|
| 875 |
+
(70+8j)
|
| 876 |
+
|
| 877 |
+
Note that higher-dimensional arrays are flattened!
|
| 878 |
+
|
| 879 |
+
>>> a = np.array([[1, 4], [5, 6]])
|
| 880 |
+
>>> b = np.array([[4, 1], [2, 2]])
|
| 881 |
+
>>> np.vdot(a, b)
|
| 882 |
+
30
|
| 883 |
+
>>> np.vdot(b, a)
|
| 884 |
+
30
|
| 885 |
+
>>> 1*4 + 4*1 + 5*2 + 6*2
|
| 886 |
+
30
|
| 887 |
+
|
| 888 |
+
"""
|
| 889 |
+
return (a, b)
|
| 890 |
+
|
| 891 |
+
|
| 892 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.bincount)
|
| 893 |
+
def bincount(x, weights=None, minlength=None):
|
| 894 |
+
"""
|
| 895 |
+
bincount(x, /, weights=None, minlength=0)
|
| 896 |
+
|
| 897 |
+
Count number of occurrences of each value in array of non-negative ints.
|
| 898 |
+
|
| 899 |
+
The number of bins (of size 1) is one larger than the largest value in
|
| 900 |
+
`x`. If `minlength` is specified, there will be at least this number
|
| 901 |
+
of bins in the output array (though it will be longer if necessary,
|
| 902 |
+
depending on the contents of `x`).
|
| 903 |
+
Each bin gives the number of occurrences of its index value in `x`.
|
| 904 |
+
If `weights` is specified the input array is weighted by it, i.e. if a
|
| 905 |
+
value ``n`` is found at position ``i``, ``out[n] += weight[i]`` instead
|
| 906 |
+
of ``out[n] += 1``.
|
| 907 |
+
|
| 908 |
+
Parameters
|
| 909 |
+
----------
|
| 910 |
+
x : array_like, 1 dimension, nonnegative ints
|
| 911 |
+
Input array.
|
| 912 |
+
weights : array_like, optional
|
| 913 |
+
Weights, array of the same shape as `x`.
|
| 914 |
+
minlength : int, optional
|
| 915 |
+
A minimum number of bins for the output array.
|
| 916 |
+
|
| 917 |
+
.. versionadded:: 1.6.0
|
| 918 |
+
|
| 919 |
+
Returns
|
| 920 |
+
-------
|
| 921 |
+
out : ndarray of ints
|
| 922 |
+
The result of binning the input array.
|
| 923 |
+
The length of `out` is equal to ``np.amax(x)+1``.
|
| 924 |
+
|
| 925 |
+
Raises
|
| 926 |
+
------
|
| 927 |
+
ValueError
|
| 928 |
+
If the input is not 1-dimensional, or contains elements with negative
|
| 929 |
+
values, or if `minlength` is negative.
|
| 930 |
+
TypeError
|
| 931 |
+
If the type of the input is float or complex.
|
| 932 |
+
|
| 933 |
+
See Also
|
| 934 |
+
--------
|
| 935 |
+
histogram, digitize, unique
|
| 936 |
+
|
| 937 |
+
Examples
|
| 938 |
+
--------
|
| 939 |
+
>>> np.bincount(np.arange(5))
|
| 940 |
+
array([1, 1, 1, 1, 1])
|
| 941 |
+
>>> np.bincount(np.array([0, 1, 1, 3, 2, 1, 7]))
|
| 942 |
+
array([1, 3, 1, 1, 0, 0, 0, 1])
|
| 943 |
+
|
| 944 |
+
>>> x = np.array([0, 1, 1, 3, 2, 1, 7, 23])
|
| 945 |
+
>>> np.bincount(x).size == np.amax(x)+1
|
| 946 |
+
True
|
| 947 |
+
|
| 948 |
+
The input array needs to be of integer dtype, otherwise a
|
| 949 |
+
TypeError is raised:
|
| 950 |
+
|
| 951 |
+
>>> np.bincount(np.arange(5, dtype=float))
|
| 952 |
+
Traceback (most recent call last):
|
| 953 |
+
...
|
| 954 |
+
TypeError: Cannot cast array data from dtype('float64') to dtype('int64')
|
| 955 |
+
according to the rule 'safe'
|
| 956 |
+
|
| 957 |
+
A possible use of ``bincount`` is to perform sums over
|
| 958 |
+
variable-size chunks of an array, using the ``weights`` keyword.
|
| 959 |
+
|
| 960 |
+
>>> w = np.array([0.3, 0.5, 0.2, 0.7, 1., -0.6]) # weights
|
| 961 |
+
>>> x = np.array([0, 1, 1, 2, 2, 2])
|
| 962 |
+
>>> np.bincount(x, weights=w)
|
| 963 |
+
array([ 0.3, 0.7, 1.1])
|
| 964 |
+
|
| 965 |
+
"""
|
| 966 |
+
return (x, weights)
|
| 967 |
+
|
| 968 |
+
|
| 969 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.ravel_multi_index)
|
| 970 |
+
def ravel_multi_index(multi_index, dims, mode=None, order=None):
|
| 971 |
+
"""
|
| 972 |
+
ravel_multi_index(multi_index, dims, mode='raise', order='C')
|
| 973 |
+
|
| 974 |
+
Converts a tuple of index arrays into an array of flat
|
| 975 |
+
indices, applying boundary modes to the multi-index.
|
| 976 |
+
|
| 977 |
+
Parameters
|
| 978 |
+
----------
|
| 979 |
+
multi_index : tuple of array_like
|
| 980 |
+
A tuple of integer arrays, one array for each dimension.
|
| 981 |
+
dims : tuple of ints
|
| 982 |
+
The shape of array into which the indices from ``multi_index`` apply.
|
| 983 |
+
mode : {'raise', 'wrap', 'clip'}, optional
|
| 984 |
+
Specifies how out-of-bounds indices are handled. Can specify
|
| 985 |
+
either one mode or a tuple of modes, one mode per index.
|
| 986 |
+
|
| 987 |
+
* 'raise' -- raise an error (default)
|
| 988 |
+
* 'wrap' -- wrap around
|
| 989 |
+
* 'clip' -- clip to the range
|
| 990 |
+
|
| 991 |
+
In 'clip' mode, a negative index which would normally
|
| 992 |
+
wrap will clip to 0 instead.
|
| 993 |
+
order : {'C', 'F'}, optional
|
| 994 |
+
Determines whether the multi-index should be viewed as
|
| 995 |
+
indexing in row-major (C-style) or column-major
|
| 996 |
+
(Fortran-style) order.
|
| 997 |
+
|
| 998 |
+
Returns
|
| 999 |
+
-------
|
| 1000 |
+
raveled_indices : ndarray
|
| 1001 |
+
An array of indices into the flattened version of an array
|
| 1002 |
+
of dimensions ``dims``.
|
| 1003 |
+
|
| 1004 |
+
See Also
|
| 1005 |
+
--------
|
| 1006 |
+
unravel_index
|
| 1007 |
+
|
| 1008 |
+
Notes
|
| 1009 |
+
-----
|
| 1010 |
+
.. versionadded:: 1.6.0
|
| 1011 |
+
|
| 1012 |
+
Examples
|
| 1013 |
+
--------
|
| 1014 |
+
>>> arr = np.array([[3,6,6],[4,5,1]])
|
| 1015 |
+
>>> np.ravel_multi_index(arr, (7,6))
|
| 1016 |
+
array([22, 41, 37])
|
| 1017 |
+
>>> np.ravel_multi_index(arr, (7,6), order='F')
|
| 1018 |
+
array([31, 41, 13])
|
| 1019 |
+
>>> np.ravel_multi_index(arr, (4,6), mode='clip')
|
| 1020 |
+
array([22, 23, 19])
|
| 1021 |
+
>>> np.ravel_multi_index(arr, (4,4), mode=('clip','wrap'))
|
| 1022 |
+
array([12, 13, 13])
|
| 1023 |
+
|
| 1024 |
+
>>> np.ravel_multi_index((3,1,4,1), (6,7,8,9))
|
| 1025 |
+
1621
|
| 1026 |
+
"""
|
| 1027 |
+
return multi_index
|
| 1028 |
+
|
| 1029 |
+
|
| 1030 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.unravel_index)
|
| 1031 |
+
def unravel_index(indices, shape=None, order=None):
|
| 1032 |
+
"""
|
| 1033 |
+
unravel_index(indices, shape, order='C')
|
| 1034 |
+
|
| 1035 |
+
Converts a flat index or array of flat indices into a tuple
|
| 1036 |
+
of coordinate arrays.
|
| 1037 |
+
|
| 1038 |
+
Parameters
|
| 1039 |
+
----------
|
| 1040 |
+
indices : array_like
|
| 1041 |
+
An integer array whose elements are indices into the flattened
|
| 1042 |
+
version of an array of dimensions ``shape``. Before version 1.6.0,
|
| 1043 |
+
this function accepted just one index value.
|
| 1044 |
+
shape : tuple of ints
|
| 1045 |
+
The shape of the array to use for unraveling ``indices``.
|
| 1046 |
+
|
| 1047 |
+
.. versionchanged:: 1.16.0
|
| 1048 |
+
Renamed from ``dims`` to ``shape``.
|
| 1049 |
+
|
| 1050 |
+
order : {'C', 'F'}, optional
|
| 1051 |
+
Determines whether the indices should be viewed as indexing in
|
| 1052 |
+
row-major (C-style) or column-major (Fortran-style) order.
|
| 1053 |
+
|
| 1054 |
+
.. versionadded:: 1.6.0
|
| 1055 |
+
|
| 1056 |
+
Returns
|
| 1057 |
+
-------
|
| 1058 |
+
unraveled_coords : tuple of ndarray
|
| 1059 |
+
Each array in the tuple has the same shape as the ``indices``
|
| 1060 |
+
array.
|
| 1061 |
+
|
| 1062 |
+
See Also
|
| 1063 |
+
--------
|
| 1064 |
+
ravel_multi_index
|
| 1065 |
+
|
| 1066 |
+
Examples
|
| 1067 |
+
--------
|
| 1068 |
+
>>> np.unravel_index([22, 41, 37], (7,6))
|
| 1069 |
+
(array([3, 6, 6]), array([4, 5, 1]))
|
| 1070 |
+
>>> np.unravel_index([31, 41, 13], (7,6), order='F')
|
| 1071 |
+
(array([3, 6, 6]), array([4, 5, 1]))
|
| 1072 |
+
|
| 1073 |
+
>>> np.unravel_index(1621, (6,7,8,9))
|
| 1074 |
+
(3, 1, 4, 1)
|
| 1075 |
+
|
| 1076 |
+
"""
|
| 1077 |
+
return (indices,)
|
| 1078 |
+
|
| 1079 |
+
|
| 1080 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.copyto)
|
| 1081 |
+
def copyto(dst, src, casting=None, where=None):
|
| 1082 |
+
"""
|
| 1083 |
+
copyto(dst, src, casting='same_kind', where=True)
|
| 1084 |
+
|
| 1085 |
+
Copies values from one array to another, broadcasting as necessary.
|
| 1086 |
+
|
| 1087 |
+
Raises a TypeError if the `casting` rule is violated, and if
|
| 1088 |
+
`where` is provided, it selects which elements to copy.
|
| 1089 |
+
|
| 1090 |
+
.. versionadded:: 1.7.0
|
| 1091 |
+
|
| 1092 |
+
Parameters
|
| 1093 |
+
----------
|
| 1094 |
+
dst : ndarray
|
| 1095 |
+
The array into which values are copied.
|
| 1096 |
+
src : array_like
|
| 1097 |
+
The array from which values are copied.
|
| 1098 |
+
casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
|
| 1099 |
+
Controls what kind of data casting may occur when copying.
|
| 1100 |
+
|
| 1101 |
+
* 'no' means the data types should not be cast at all.
|
| 1102 |
+
* 'equiv' means only byte-order changes are allowed.
|
| 1103 |
+
* 'safe' means only casts which can preserve values are allowed.
|
| 1104 |
+
* 'same_kind' means only safe casts or casts within a kind,
|
| 1105 |
+
like float64 to float32, are allowed.
|
| 1106 |
+
* 'unsafe' means any data conversions may be done.
|
| 1107 |
+
where : array_like of bool, optional
|
| 1108 |
+
A boolean array which is broadcasted to match the dimensions
|
| 1109 |
+
of `dst`, and selects elements to copy from `src` to `dst`
|
| 1110 |
+
wherever it contains the value True.
|
| 1111 |
+
|
| 1112 |
+
Examples
|
| 1113 |
+
--------
|
| 1114 |
+
>>> A = np.array([4, 5, 6])
|
| 1115 |
+
>>> B = [1, 2, 3]
|
| 1116 |
+
>>> np.copyto(A, B)
|
| 1117 |
+
>>> A
|
| 1118 |
+
array([1, 2, 3])
|
| 1119 |
+
|
| 1120 |
+
>>> A = np.array([[1, 2, 3], [4, 5, 6]])
|
| 1121 |
+
>>> B = [[4, 5, 6], [7, 8, 9]]
|
| 1122 |
+
>>> np.copyto(A, B)
|
| 1123 |
+
>>> A
|
| 1124 |
+
array([[4, 5, 6],
|
| 1125 |
+
[7, 8, 9]])
|
| 1126 |
+
|
| 1127 |
+
"""
|
| 1128 |
+
return (dst, src, where)
|
| 1129 |
+
|
| 1130 |
+
|
| 1131 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.putmask)
|
| 1132 |
+
def putmask(a, /, mask, values):
|
| 1133 |
+
"""
|
| 1134 |
+
putmask(a, mask, values)
|
| 1135 |
+
|
| 1136 |
+
Changes elements of an array based on conditional and input values.
|
| 1137 |
+
|
| 1138 |
+
Sets ``a.flat[n] = values[n]`` for each n where ``mask.flat[n]==True``.
|
| 1139 |
+
|
| 1140 |
+
If `values` is not the same size as `a` and `mask` then it will repeat.
|
| 1141 |
+
This gives behavior different from ``a[mask] = values``.
|
| 1142 |
+
|
| 1143 |
+
Parameters
|
| 1144 |
+
----------
|
| 1145 |
+
a : ndarray
|
| 1146 |
+
Target array.
|
| 1147 |
+
mask : array_like
|
| 1148 |
+
Boolean mask array. It has to be the same shape as `a`.
|
| 1149 |
+
values : array_like
|
| 1150 |
+
Values to put into `a` where `mask` is True. If `values` is smaller
|
| 1151 |
+
than `a` it will be repeated.
|
| 1152 |
+
|
| 1153 |
+
See Also
|
| 1154 |
+
--------
|
| 1155 |
+
place, put, take, copyto
|
| 1156 |
+
|
| 1157 |
+
Examples
|
| 1158 |
+
--------
|
| 1159 |
+
>>> x = np.arange(6).reshape(2, 3)
|
| 1160 |
+
>>> np.putmask(x, x>2, x**2)
|
| 1161 |
+
>>> x
|
| 1162 |
+
array([[ 0, 1, 2],
|
| 1163 |
+
[ 9, 16, 25]])
|
| 1164 |
+
|
| 1165 |
+
If `values` is smaller than `a` it is repeated:
|
| 1166 |
+
|
| 1167 |
+
>>> x = np.arange(5)
|
| 1168 |
+
>>> np.putmask(x, x>1, [-33, -44])
|
| 1169 |
+
>>> x
|
| 1170 |
+
array([ 0, 1, -33, -44, -33])
|
| 1171 |
+
|
| 1172 |
+
"""
|
| 1173 |
+
return (a, mask, values)
|
| 1174 |
+
|
| 1175 |
+
|
| 1176 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.packbits)
|
| 1177 |
+
def packbits(a, axis=None, bitorder='big'):
|
| 1178 |
+
"""
|
| 1179 |
+
packbits(a, /, axis=None, bitorder='big')
|
| 1180 |
+
|
| 1181 |
+
Packs the elements of a binary-valued array into bits in a uint8 array.
|
| 1182 |
+
|
| 1183 |
+
The result is padded to full bytes by inserting zero bits at the end.
|
| 1184 |
+
|
| 1185 |
+
Parameters
|
| 1186 |
+
----------
|
| 1187 |
+
a : array_like
|
| 1188 |
+
An array of integers or booleans whose elements should be packed to
|
| 1189 |
+
bits.
|
| 1190 |
+
axis : int, optional
|
| 1191 |
+
The dimension over which bit-packing is done.
|
| 1192 |
+
``None`` implies packing the flattened array.
|
| 1193 |
+
bitorder : {'big', 'little'}, optional
|
| 1194 |
+
The order of the input bits. 'big' will mimic bin(val),
|
| 1195 |
+
``[0, 0, 0, 0, 0, 0, 1, 1] => 3 = 0b00000011``, 'little' will
|
| 1196 |
+
reverse the order so ``[1, 1, 0, 0, 0, 0, 0, 0] => 3``.
|
| 1197 |
+
Defaults to 'big'.
|
| 1198 |
+
|
| 1199 |
+
.. versionadded:: 1.17.0
|
| 1200 |
+
|
| 1201 |
+
Returns
|
| 1202 |
+
-------
|
| 1203 |
+
packed : ndarray
|
| 1204 |
+
Array of type uint8 whose elements represent bits corresponding to the
|
| 1205 |
+
logical (0 or nonzero) value of the input elements. The shape of
|
| 1206 |
+
`packed` has the same number of dimensions as the input (unless `axis`
|
| 1207 |
+
is None, in which case the output is 1-D).
|
| 1208 |
+
|
| 1209 |
+
See Also
|
| 1210 |
+
--------
|
| 1211 |
+
unpackbits: Unpacks elements of a uint8 array into a binary-valued output
|
| 1212 |
+
array.
|
| 1213 |
+
|
| 1214 |
+
Examples
|
| 1215 |
+
--------
|
| 1216 |
+
>>> a = np.array([[[1,0,1],
|
| 1217 |
+
... [0,1,0]],
|
| 1218 |
+
... [[1,1,0],
|
| 1219 |
+
... [0,0,1]]])
|
| 1220 |
+
>>> b = np.packbits(a, axis=-1)
|
| 1221 |
+
>>> b
|
| 1222 |
+
array([[[160],
|
| 1223 |
+
[ 64]],
|
| 1224 |
+
[[192],
|
| 1225 |
+
[ 32]]], dtype=uint8)
|
| 1226 |
+
|
| 1227 |
+
Note that in binary 160 = 1010 0000, 64 = 0100 0000, 192 = 1100 0000,
|
| 1228 |
+
and 32 = 0010 0000.
|
| 1229 |
+
|
| 1230 |
+
"""
|
| 1231 |
+
return (a,)
|
| 1232 |
+
|
| 1233 |
+
|
| 1234 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.unpackbits)
|
| 1235 |
+
def unpackbits(a, axis=None, count=None, bitorder='big'):
|
| 1236 |
+
"""
|
| 1237 |
+
unpackbits(a, /, axis=None, count=None, bitorder='big')
|
| 1238 |
+
|
| 1239 |
+
Unpacks elements of a uint8 array into a binary-valued output array.
|
| 1240 |
+
|
| 1241 |
+
Each element of `a` represents a bit-field that should be unpacked
|
| 1242 |
+
into a binary-valued output array. The shape of the output array is
|
| 1243 |
+
either 1-D (if `axis` is ``None``) or the same shape as the input
|
| 1244 |
+
array with unpacking done along the axis specified.
|
| 1245 |
+
|
| 1246 |
+
Parameters
|
| 1247 |
+
----------
|
| 1248 |
+
a : ndarray, uint8 type
|
| 1249 |
+
Input array.
|
| 1250 |
+
axis : int, optional
|
| 1251 |
+
The dimension over which bit-unpacking is done.
|
| 1252 |
+
``None`` implies unpacking the flattened array.
|
| 1253 |
+
count : int or None, optional
|
| 1254 |
+
The number of elements to unpack along `axis`, provided as a way
|
| 1255 |
+
of undoing the effect of packing a size that is not a multiple
|
| 1256 |
+
of eight. A non-negative number means to only unpack `count`
|
| 1257 |
+
bits. A negative number means to trim off that many bits from
|
| 1258 |
+
the end. ``None`` means to unpack the entire array (the
|
| 1259 |
+
default). Counts larger than the available number of bits will
|
| 1260 |
+
add zero padding to the output. Negative counts must not
|
| 1261 |
+
exceed the available number of bits.
|
| 1262 |
+
|
| 1263 |
+
.. versionadded:: 1.17.0
|
| 1264 |
+
|
| 1265 |
+
bitorder : {'big', 'little'}, optional
|
| 1266 |
+
The order of the returned bits. 'big' will mimic bin(val),
|
| 1267 |
+
``3 = 0b00000011 => [0, 0, 0, 0, 0, 0, 1, 1]``, 'little' will reverse
|
| 1268 |
+
the order to ``[1, 1, 0, 0, 0, 0, 0, 0]``.
|
| 1269 |
+
Defaults to 'big'.
|
| 1270 |
+
|
| 1271 |
+
.. versionadded:: 1.17.0
|
| 1272 |
+
|
| 1273 |
+
Returns
|
| 1274 |
+
-------
|
| 1275 |
+
unpacked : ndarray, uint8 type
|
| 1276 |
+
The elements are binary-valued (0 or 1).
|
| 1277 |
+
|
| 1278 |
+
See Also
|
| 1279 |
+
--------
|
| 1280 |
+
packbits : Packs the elements of a binary-valued array into bits in
|
| 1281 |
+
a uint8 array.
|
| 1282 |
+
|
| 1283 |
+
Examples
|
| 1284 |
+
--------
|
| 1285 |
+
>>> a = np.array([[2], [7], [23]], dtype=np.uint8)
|
| 1286 |
+
>>> a
|
| 1287 |
+
array([[ 2],
|
| 1288 |
+
[ 7],
|
| 1289 |
+
[23]], dtype=uint8)
|
| 1290 |
+
>>> b = np.unpackbits(a, axis=1)
|
| 1291 |
+
>>> b
|
| 1292 |
+
array([[0, 0, 0, 0, 0, 0, 1, 0],
|
| 1293 |
+
[0, 0, 0, 0, 0, 1, 1, 1],
|
| 1294 |
+
[0, 0, 0, 1, 0, 1, 1, 1]], dtype=uint8)
|
| 1295 |
+
>>> c = np.unpackbits(a, axis=1, count=-3)
|
| 1296 |
+
>>> c
|
| 1297 |
+
array([[0, 0, 0, 0, 0],
|
| 1298 |
+
[0, 0, 0, 0, 0],
|
| 1299 |
+
[0, 0, 0, 1, 0]], dtype=uint8)
|
| 1300 |
+
|
| 1301 |
+
>>> p = np.packbits(b, axis=0)
|
| 1302 |
+
>>> np.unpackbits(p, axis=0)
|
| 1303 |
+
array([[0, 0, 0, 0, 0, 0, 1, 0],
|
| 1304 |
+
[0, 0, 0, 0, 0, 1, 1, 1],
|
| 1305 |
+
[0, 0, 0, 1, 0, 1, 1, 1],
|
| 1306 |
+
[0, 0, 0, 0, 0, 0, 0, 0],
|
| 1307 |
+
[0, 0, 0, 0, 0, 0, 0, 0],
|
| 1308 |
+
[0, 0, 0, 0, 0, 0, 0, 0],
|
| 1309 |
+
[0, 0, 0, 0, 0, 0, 0, 0],
|
| 1310 |
+
[0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
|
| 1311 |
+
>>> np.array_equal(b, np.unpackbits(p, axis=0, count=b.shape[0]))
|
| 1312 |
+
True
|
| 1313 |
+
|
| 1314 |
+
"""
|
| 1315 |
+
return (a,)
|
| 1316 |
+
|
| 1317 |
+
|
| 1318 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.shares_memory)
|
| 1319 |
+
def shares_memory(a, b, max_work=None):
|
| 1320 |
+
"""
|
| 1321 |
+
shares_memory(a, b, /, max_work=None)
|
| 1322 |
+
|
| 1323 |
+
Determine if two arrays share memory.
|
| 1324 |
+
|
| 1325 |
+
.. warning::
|
| 1326 |
+
|
| 1327 |
+
This function can be exponentially slow for some inputs, unless
|
| 1328 |
+
`max_work` is set to a finite number or ``MAY_SHARE_BOUNDS``.
|
| 1329 |
+
If in doubt, use `numpy.may_share_memory` instead.
|
| 1330 |
+
|
| 1331 |
+
Parameters
|
| 1332 |
+
----------
|
| 1333 |
+
a, b : ndarray
|
| 1334 |
+
Input arrays
|
| 1335 |
+
max_work : int, optional
|
| 1336 |
+
Effort to spend on solving the overlap problem (maximum number
|
| 1337 |
+
of candidate solutions to consider). The following special
|
| 1338 |
+
values are recognized:
|
| 1339 |
+
|
| 1340 |
+
max_work=MAY_SHARE_EXACT (default)
|
| 1341 |
+
The problem is solved exactly. In this case, the function returns
|
| 1342 |
+
True only if there is an element shared between the arrays. Finding
|
| 1343 |
+
the exact solution may take extremely long in some cases.
|
| 1344 |
+
max_work=MAY_SHARE_BOUNDS
|
| 1345 |
+
Only the memory bounds of a and b are checked.
|
| 1346 |
+
|
| 1347 |
+
Raises
|
| 1348 |
+
------
|
| 1349 |
+
numpy.exceptions.TooHardError
|
| 1350 |
+
Exceeded max_work.
|
| 1351 |
+
|
| 1352 |
+
Returns
|
| 1353 |
+
-------
|
| 1354 |
+
out : bool
|
| 1355 |
+
|
| 1356 |
+
See Also
|
| 1357 |
+
--------
|
| 1358 |
+
may_share_memory
|
| 1359 |
+
|
| 1360 |
+
Examples
|
| 1361 |
+
--------
|
| 1362 |
+
>>> x = np.array([1, 2, 3, 4])
|
| 1363 |
+
>>> np.shares_memory(x, np.array([5, 6, 7]))
|
| 1364 |
+
False
|
| 1365 |
+
>>> np.shares_memory(x[::2], x)
|
| 1366 |
+
True
|
| 1367 |
+
>>> np.shares_memory(x[::2], x[1::2])
|
| 1368 |
+
False
|
| 1369 |
+
|
| 1370 |
+
Checking whether two arrays share memory is NP-complete, and
|
| 1371 |
+
runtime may increase exponentially in the number of
|
| 1372 |
+
dimensions. Hence, `max_work` should generally be set to a finite
|
| 1373 |
+
number, as it is possible to construct examples that take
|
| 1374 |
+
extremely long to run:
|
| 1375 |
+
|
| 1376 |
+
>>> from numpy.lib.stride_tricks import as_strided
|
| 1377 |
+
>>> x = np.zeros([192163377], dtype=np.int8)
|
| 1378 |
+
>>> x1 = as_strided(x, strides=(36674, 61119, 85569), shape=(1049, 1049, 1049))
|
| 1379 |
+
>>> x2 = as_strided(x[64023025:], strides=(12223, 12224, 1), shape=(1049, 1049, 1))
|
| 1380 |
+
>>> np.shares_memory(x1, x2, max_work=1000)
|
| 1381 |
+
Traceback (most recent call last):
|
| 1382 |
+
...
|
| 1383 |
+
numpy.exceptions.TooHardError: Exceeded max_work
|
| 1384 |
+
|
| 1385 |
+
Running ``np.shares_memory(x1, x2)`` without `max_work` set takes
|
| 1386 |
+
around 1 minute for this case. It is possible to find problems
|
| 1387 |
+
that take still significantly longer.
|
| 1388 |
+
|
| 1389 |
+
"""
|
| 1390 |
+
return (a, b)
|
| 1391 |
+
|
| 1392 |
+
|
| 1393 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.may_share_memory)
|
| 1394 |
+
def may_share_memory(a, b, max_work=None):
|
| 1395 |
+
"""
|
| 1396 |
+
may_share_memory(a, b, /, max_work=None)
|
| 1397 |
+
|
| 1398 |
+
Determine if two arrays might share memory
|
| 1399 |
+
|
| 1400 |
+
A return of True does not necessarily mean that the two arrays
|
| 1401 |
+
share any element. It just means that they *might*.
|
| 1402 |
+
|
| 1403 |
+
Only the memory bounds of a and b are checked by default.
|
| 1404 |
+
|
| 1405 |
+
Parameters
|
| 1406 |
+
----------
|
| 1407 |
+
a, b : ndarray
|
| 1408 |
+
Input arrays
|
| 1409 |
+
max_work : int, optional
|
| 1410 |
+
Effort to spend on solving the overlap problem. See
|
| 1411 |
+
`shares_memory` for details. Default for ``may_share_memory``
|
| 1412 |
+
is to do a bounds check.
|
| 1413 |
+
|
| 1414 |
+
Returns
|
| 1415 |
+
-------
|
| 1416 |
+
out : bool
|
| 1417 |
+
|
| 1418 |
+
See Also
|
| 1419 |
+
--------
|
| 1420 |
+
shares_memory
|
| 1421 |
+
|
| 1422 |
+
Examples
|
| 1423 |
+
--------
|
| 1424 |
+
>>> np.may_share_memory(np.array([1,2]), np.array([5,8,9]))
|
| 1425 |
+
False
|
| 1426 |
+
>>> x = np.zeros([3, 4])
|
| 1427 |
+
>>> np.may_share_memory(x[:,0], x[:,1])
|
| 1428 |
+
True
|
| 1429 |
+
|
| 1430 |
+
"""
|
| 1431 |
+
return (a, b)
|
| 1432 |
+
|
| 1433 |
+
|
| 1434 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.is_busday)
|
| 1435 |
+
def is_busday(dates, weekmask=None, holidays=None, busdaycal=None, out=None):
|
| 1436 |
+
"""
|
| 1437 |
+
is_busday(dates, weekmask='1111100', holidays=None, busdaycal=None, out=None)
|
| 1438 |
+
|
| 1439 |
+
Calculates which of the given dates are valid days, and which are not.
|
| 1440 |
+
|
| 1441 |
+
.. versionadded:: 1.7.0
|
| 1442 |
+
|
| 1443 |
+
Parameters
|
| 1444 |
+
----------
|
| 1445 |
+
dates : array_like of datetime64[D]
|
| 1446 |
+
The array of dates to process.
|
| 1447 |
+
weekmask : str or array_like of bool, optional
|
| 1448 |
+
A seven-element array indicating which of Monday through Sunday are
|
| 1449 |
+
valid days. May be specified as a length-seven list or array, like
|
| 1450 |
+
[1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string
|
| 1451 |
+
like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for
|
| 1452 |
+
weekdays, optionally separated by white space. Valid abbreviations
|
| 1453 |
+
are: Mon Tue Wed Thu Fri Sat Sun
|
| 1454 |
+
holidays : array_like of datetime64[D], optional
|
| 1455 |
+
An array of dates to consider as invalid dates. They may be
|
| 1456 |
+
specified in any order, and NaT (not-a-time) dates are ignored.
|
| 1457 |
+
This list is saved in a normalized form that is suited for
|
| 1458 |
+
fast calculations of valid days.
|
| 1459 |
+
busdaycal : busdaycalendar, optional
|
| 1460 |
+
A `busdaycalendar` object which specifies the valid days. If this
|
| 1461 |
+
parameter is provided, neither weekmask nor holidays may be
|
| 1462 |
+
provided.
|
| 1463 |
+
out : array of bool, optional
|
| 1464 |
+
If provided, this array is filled with the result.
|
| 1465 |
+
|
| 1466 |
+
Returns
|
| 1467 |
+
-------
|
| 1468 |
+
out : array of bool
|
| 1469 |
+
An array with the same shape as ``dates``, containing True for
|
| 1470 |
+
each valid day, and False for each invalid day.
|
| 1471 |
+
|
| 1472 |
+
See Also
|
| 1473 |
+
--------
|
| 1474 |
+
busdaycalendar : An object that specifies a custom set of valid days.
|
| 1475 |
+
busday_offset : Applies an offset counted in valid days.
|
| 1476 |
+
busday_count : Counts how many valid days are in a half-open date range.
|
| 1477 |
+
|
| 1478 |
+
Examples
|
| 1479 |
+
--------
|
| 1480 |
+
>>> # The weekdays are Friday, Saturday, and Monday
|
| 1481 |
+
... np.is_busday(['2011-07-01', '2011-07-02', '2011-07-18'],
|
| 1482 |
+
... holidays=['2011-07-01', '2011-07-04', '2011-07-17'])
|
| 1483 |
+
array([False, False, True])
|
| 1484 |
+
"""
|
| 1485 |
+
return (dates, weekmask, holidays, out)
|
| 1486 |
+
|
| 1487 |
+
|
| 1488 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.busday_offset)
|
| 1489 |
+
def busday_offset(dates, offsets, roll=None, weekmask=None, holidays=None,
|
| 1490 |
+
busdaycal=None, out=None):
|
| 1491 |
+
"""
|
| 1492 |
+
busday_offset(dates, offsets, roll='raise', weekmask='1111100', holidays=None, busdaycal=None, out=None)
|
| 1493 |
+
|
| 1494 |
+
First adjusts the date to fall on a valid day according to
|
| 1495 |
+
the ``roll`` rule, then applies offsets to the given dates
|
| 1496 |
+
counted in valid days.
|
| 1497 |
+
|
| 1498 |
+
.. versionadded:: 1.7.0
|
| 1499 |
+
|
| 1500 |
+
Parameters
|
| 1501 |
+
----------
|
| 1502 |
+
dates : array_like of datetime64[D]
|
| 1503 |
+
The array of dates to process.
|
| 1504 |
+
offsets : array_like of int
|
| 1505 |
+
The array of offsets, which is broadcast with ``dates``.
|
| 1506 |
+
roll : {'raise', 'nat', 'forward', 'following', 'backward', 'preceding', 'modifiedfollowing', 'modifiedpreceding'}, optional
|
| 1507 |
+
How to treat dates that do not fall on a valid day. The default
|
| 1508 |
+
is 'raise'.
|
| 1509 |
+
|
| 1510 |
+
* 'raise' means to raise an exception for an invalid day.
|
| 1511 |
+
* 'nat' means to return a NaT (not-a-time) for an invalid day.
|
| 1512 |
+
* 'forward' and 'following' mean to take the first valid day
|
| 1513 |
+
later in time.
|
| 1514 |
+
* 'backward' and 'preceding' mean to take the first valid day
|
| 1515 |
+
earlier in time.
|
| 1516 |
+
* 'modifiedfollowing' means to take the first valid day
|
| 1517 |
+
later in time unless it is across a Month boundary, in which
|
| 1518 |
+
case to take the first valid day earlier in time.
|
| 1519 |
+
* 'modifiedpreceding' means to take the first valid day
|
| 1520 |
+
earlier in time unless it is across a Month boundary, in which
|
| 1521 |
+
case to take the first valid day later in time.
|
| 1522 |
+
weekmask : str or array_like of bool, optional
|
| 1523 |
+
A seven-element array indicating which of Monday through Sunday are
|
| 1524 |
+
valid days. May be specified as a length-seven list or array, like
|
| 1525 |
+
[1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string
|
| 1526 |
+
like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for
|
| 1527 |
+
weekdays, optionally separated by white space. Valid abbreviations
|
| 1528 |
+
are: Mon Tue Wed Thu Fri Sat Sun
|
| 1529 |
+
holidays : array_like of datetime64[D], optional
|
| 1530 |
+
An array of dates to consider as invalid dates. They may be
|
| 1531 |
+
specified in any order, and NaT (not-a-time) dates are ignored.
|
| 1532 |
+
This list is saved in a normalized form that is suited for
|
| 1533 |
+
fast calculations of valid days.
|
| 1534 |
+
busdaycal : busdaycalendar, optional
|
| 1535 |
+
A `busdaycalendar` object which specifies the valid days. If this
|
| 1536 |
+
parameter is provided, neither weekmask nor holidays may be
|
| 1537 |
+
provided.
|
| 1538 |
+
out : array of datetime64[D], optional
|
| 1539 |
+
If provided, this array is filled with the result.
|
| 1540 |
+
|
| 1541 |
+
Returns
|
| 1542 |
+
-------
|
| 1543 |
+
out : array of datetime64[D]
|
| 1544 |
+
An array with a shape from broadcasting ``dates`` and ``offsets``
|
| 1545 |
+
together, containing the dates with offsets applied.
|
| 1546 |
+
|
| 1547 |
+
See Also
|
| 1548 |
+
--------
|
| 1549 |
+
busdaycalendar : An object that specifies a custom set of valid days.
|
| 1550 |
+
is_busday : Returns a boolean array indicating valid days.
|
| 1551 |
+
busday_count : Counts how many valid days are in a half-open date range.
|
| 1552 |
+
|
| 1553 |
+
Examples
|
| 1554 |
+
--------
|
| 1555 |
+
>>> # First business day in October 2011 (not accounting for holidays)
|
| 1556 |
+
... np.busday_offset('2011-10', 0, roll='forward')
|
| 1557 |
+
numpy.datetime64('2011-10-03')
|
| 1558 |
+
>>> # Last business day in February 2012 (not accounting for holidays)
|
| 1559 |
+
... np.busday_offset('2012-03', -1, roll='forward')
|
| 1560 |
+
numpy.datetime64('2012-02-29')
|
| 1561 |
+
>>> # Third Wednesday in January 2011
|
| 1562 |
+
... np.busday_offset('2011-01', 2, roll='forward', weekmask='Wed')
|
| 1563 |
+
numpy.datetime64('2011-01-19')
|
| 1564 |
+
>>> # 2012 Mother's Day in Canada and the U.S.
|
| 1565 |
+
... np.busday_offset('2012-05', 1, roll='forward', weekmask='Sun')
|
| 1566 |
+
numpy.datetime64('2012-05-13')
|
| 1567 |
+
|
| 1568 |
+
>>> # First business day on or after a date
|
| 1569 |
+
... np.busday_offset('2011-03-20', 0, roll='forward')
|
| 1570 |
+
numpy.datetime64('2011-03-21')
|
| 1571 |
+
>>> np.busday_offset('2011-03-22', 0, roll='forward')
|
| 1572 |
+
numpy.datetime64('2011-03-22')
|
| 1573 |
+
>>> # First business day after a date
|
| 1574 |
+
... np.busday_offset('2011-03-20', 1, roll='backward')
|
| 1575 |
+
numpy.datetime64('2011-03-21')
|
| 1576 |
+
>>> np.busday_offset('2011-03-22', 1, roll='backward')
|
| 1577 |
+
numpy.datetime64('2011-03-23')
|
| 1578 |
+
"""
|
| 1579 |
+
return (dates, offsets, weekmask, holidays, out)
|
| 1580 |
+
|
| 1581 |
+
|
| 1582 |
+
@array_function_from_c_func_and_dispatcher(_multiarray_umath.busday_count)
|
| 1583 |
+
def busday_count(begindates, enddates, weekmask=None, holidays=None,
|
| 1584 |
+
busdaycal=None, out=None):
|
| 1585 |
+
"""
|
| 1586 |
+
busday_count(begindates, enddates, weekmask='1111100', holidays=[], busdaycal=None, out=None)
|
| 1587 |
+
|
| 1588 |
+
Counts the number of valid days between `begindates` and
|
| 1589 |
+
`enddates`, not including the day of `enddates`.
|
| 1590 |
+
|
| 1591 |
+
If ``enddates`` specifies a date value that is earlier than the
|
| 1592 |
+
corresponding ``begindates`` date value, the count will be negative.
|
| 1593 |
+
|
| 1594 |
+
.. versionadded:: 1.7.0
|
| 1595 |
+
|
| 1596 |
+
Parameters
|
| 1597 |
+
----------
|
| 1598 |
+
begindates : array_like of datetime64[D]
|
| 1599 |
+
The array of the first dates for counting.
|
| 1600 |
+
enddates : array_like of datetime64[D]
|
| 1601 |
+
The array of the end dates for counting, which are excluded
|
| 1602 |
+
from the count themselves.
|
| 1603 |
+
weekmask : str or array_like of bool, optional
|
| 1604 |
+
A seven-element array indicating which of Monday through Sunday are
|
| 1605 |
+
valid days. May be specified as a length-seven list or array, like
|
| 1606 |
+
[1,1,1,1,1,0,0]; a length-seven string, like '1111100'; or a string
|
| 1607 |
+
like "Mon Tue Wed Thu Fri", made up of 3-character abbreviations for
|
| 1608 |
+
weekdays, optionally separated by white space. Valid abbreviations
|
| 1609 |
+
are: Mon Tue Wed Thu Fri Sat Sun
|
| 1610 |
+
holidays : array_like of datetime64[D], optional
|
| 1611 |
+
An array of dates to consider as invalid dates. They may be
|
| 1612 |
+
specified in any order, and NaT (not-a-time) dates are ignored.
|
| 1613 |
+
This list is saved in a normalized form that is suited for
|
| 1614 |
+
fast calculations of valid days.
|
| 1615 |
+
busdaycal : busdaycalendar, optional
|
| 1616 |
+
A `busdaycalendar` object which specifies the valid days. If this
|
| 1617 |
+
parameter is provided, neither weekmask nor holidays may be
|
| 1618 |
+
provided.
|
| 1619 |
+
out : array of int, optional
|
| 1620 |
+
If provided, this array is filled with the result.
|
| 1621 |
+
|
| 1622 |
+
Returns
|
| 1623 |
+
-------
|
| 1624 |
+
out : array of int
|
| 1625 |
+
An array with a shape from broadcasting ``begindates`` and ``enddates``
|
| 1626 |
+
together, containing the number of valid days between
|
| 1627 |
+
the begin and end dates.
|
| 1628 |
+
|
| 1629 |
+
See Also
|
| 1630 |
+
--------
|
| 1631 |
+
busdaycalendar : An object that specifies a custom set of valid days.
|
| 1632 |
+
is_busday : Returns a boolean array indicating valid days.
|
| 1633 |
+
busday_offset : Applies an offset counted in valid days.
|
| 1634 |
+
|
| 1635 |
+
Examples
|
| 1636 |
+
--------
|
| 1637 |
+
>>> # Number of weekdays in January 2011
|
| 1638 |
+
... np.busday_count('2011-01', '2011-02')
|
| 1639 |
+
21
|
| 1640 |
+
>>> # Number of weekdays in 2011
|
| 1641 |
+
>>> np.busday_count('2011', '2012')
|
| 1642 |
+
260
|
| 1643 |
+
>>> # Number of Saturdays in 2011
|
| 1644 |
+
... np.busday_count('2011', '2012', weekmask='Sat')
|
| 1645 |
+
53
|
| 1646 |
+
"""
|
| 1647 |
+
return (begindates, enddates, weekmask, holidays, out)
|
| 1648 |
+
|
| 1649 |
+
|
| 1650 |
+
@array_function_from_c_func_and_dispatcher(
|
| 1651 |
+
_multiarray_umath.datetime_as_string)
|
| 1652 |
+
def datetime_as_string(arr, unit=None, timezone=None, casting=None):
|
| 1653 |
+
"""
|
| 1654 |
+
datetime_as_string(arr, unit=None, timezone='naive', casting='same_kind')
|
| 1655 |
+
|
| 1656 |
+
Convert an array of datetimes into an array of strings.
|
| 1657 |
+
|
| 1658 |
+
Parameters
|
| 1659 |
+
----------
|
| 1660 |
+
arr : array_like of datetime64
|
| 1661 |
+
The array of UTC timestamps to format.
|
| 1662 |
+
unit : str
|
| 1663 |
+
One of None, 'auto', or a :ref:`datetime unit <arrays.dtypes.dateunits>`.
|
| 1664 |
+
timezone : {'naive', 'UTC', 'local'} or tzinfo
|
| 1665 |
+
Timezone information to use when displaying the datetime. If 'UTC', end
|
| 1666 |
+
with a Z to indicate UTC time. If 'local', convert to the local timezone
|
| 1667 |
+
first, and suffix with a +-#### timezone offset. If a tzinfo object,
|
| 1668 |
+
then do as with 'local', but use the specified timezone.
|
| 1669 |
+
casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}
|
| 1670 |
+
Casting to allow when changing between datetime units.
|
| 1671 |
+
|
| 1672 |
+
Returns
|
| 1673 |
+
-------
|
| 1674 |
+
str_arr : ndarray
|
| 1675 |
+
An array of strings the same shape as `arr`.
|
| 1676 |
+
|
| 1677 |
+
Examples
|
| 1678 |
+
--------
|
| 1679 |
+
>>> import pytz
|
| 1680 |
+
>>> d = np.arange('2002-10-27T04:30', 4*60, 60, dtype='M8[m]')
|
| 1681 |
+
>>> d
|
| 1682 |
+
array(['2002-10-27T04:30', '2002-10-27T05:30', '2002-10-27T06:30',
|
| 1683 |
+
'2002-10-27T07:30'], dtype='datetime64[m]')
|
| 1684 |
+
|
| 1685 |
+
Setting the timezone to UTC shows the same information, but with a Z suffix
|
| 1686 |
+
|
| 1687 |
+
>>> np.datetime_as_string(d, timezone='UTC')
|
| 1688 |
+
array(['2002-10-27T04:30Z', '2002-10-27T05:30Z', '2002-10-27T06:30Z',
|
| 1689 |
+
'2002-10-27T07:30Z'], dtype='<U35')
|
| 1690 |
+
|
| 1691 |
+
Note that we picked datetimes that cross a DST boundary. Passing in a
|
| 1692 |
+
``pytz`` timezone object will print the appropriate offset
|
| 1693 |
+
|
| 1694 |
+
>>> np.datetime_as_string(d, timezone=pytz.timezone('US/Eastern'))
|
| 1695 |
+
array(['2002-10-27T00:30-0400', '2002-10-27T01:30-0400',
|
| 1696 |
+
'2002-10-27T01:30-0500', '2002-10-27T02:30-0500'], dtype='<U39')
|
| 1697 |
+
|
| 1698 |
+
Passing in a unit will change the precision
|
| 1699 |
+
|
| 1700 |
+
>>> np.datetime_as_string(d, unit='h')
|
| 1701 |
+
array(['2002-10-27T04', '2002-10-27T05', '2002-10-27T06', '2002-10-27T07'],
|
| 1702 |
+
dtype='<U32')
|
| 1703 |
+
>>> np.datetime_as_string(d, unit='s')
|
| 1704 |
+
array(['2002-10-27T04:30:00', '2002-10-27T05:30:00', '2002-10-27T06:30:00',
|
| 1705 |
+
'2002-10-27T07:30:00'], dtype='<U38')
|
| 1706 |
+
|
| 1707 |
+
'casting' can be used to specify whether precision can be changed
|
| 1708 |
+
|
| 1709 |
+
>>> np.datetime_as_string(d, unit='h', casting='safe')
|
| 1710 |
+
Traceback (most recent call last):
|
| 1711 |
+
...
|
| 1712 |
+
TypeError: Cannot create a datetime string as units 'h' from a NumPy
|
| 1713 |
+
datetime with units 'm' according to the rule 'safe'
|
| 1714 |
+
"""
|
| 1715 |
+
return (arr,)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/core/numerictypes.py
ADDED
|
@@ -0,0 +1,689 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
numerictypes: Define the numeric type objects
|
| 3 |
+
|
| 4 |
+
This module is designed so "from numerictypes import \\*" is safe.
|
| 5 |
+
Exported symbols include:
|
| 6 |
+
|
| 7 |
+
Dictionary with all registered number types (including aliases):
|
| 8 |
+
sctypeDict
|
| 9 |
+
|
| 10 |
+
Type objects (not all will be available, depends on platform):
|
| 11 |
+
see variable sctypes for which ones you have
|
| 12 |
+
|
| 13 |
+
Bit-width names
|
| 14 |
+
|
| 15 |
+
int8 int16 int32 int64 int128
|
| 16 |
+
uint8 uint16 uint32 uint64 uint128
|
| 17 |
+
float16 float32 float64 float96 float128 float256
|
| 18 |
+
complex32 complex64 complex128 complex192 complex256 complex512
|
| 19 |
+
datetime64 timedelta64
|
| 20 |
+
|
| 21 |
+
c-based names
|
| 22 |
+
|
| 23 |
+
bool_
|
| 24 |
+
|
| 25 |
+
object_
|
| 26 |
+
|
| 27 |
+
void, str_, unicode_
|
| 28 |
+
|
| 29 |
+
byte, ubyte,
|
| 30 |
+
short, ushort
|
| 31 |
+
intc, uintc,
|
| 32 |
+
intp, uintp,
|
| 33 |
+
int_, uint,
|
| 34 |
+
longlong, ulonglong,
|
| 35 |
+
|
| 36 |
+
single, csingle,
|
| 37 |
+
float_, complex_,
|
| 38 |
+
longfloat, clongfloat,
|
| 39 |
+
|
| 40 |
+
As part of the type-hierarchy: xx -- is bit-width
|
| 41 |
+
|
| 42 |
+
generic
|
| 43 |
+
+-> bool_ (kind=b)
|
| 44 |
+
+-> number
|
| 45 |
+
| +-> integer
|
| 46 |
+
| | +-> signedinteger (intxx) (kind=i)
|
| 47 |
+
| | | byte
|
| 48 |
+
| | | short
|
| 49 |
+
| | | intc
|
| 50 |
+
| | | intp
|
| 51 |
+
| | | int_
|
| 52 |
+
| | | longlong
|
| 53 |
+
| | \\-> unsignedinteger (uintxx) (kind=u)
|
| 54 |
+
| | ubyte
|
| 55 |
+
| | ushort
|
| 56 |
+
| | uintc
|
| 57 |
+
| | uintp
|
| 58 |
+
| | uint_
|
| 59 |
+
| | ulonglong
|
| 60 |
+
| +-> inexact
|
| 61 |
+
| +-> floating (floatxx) (kind=f)
|
| 62 |
+
| | half
|
| 63 |
+
| | single
|
| 64 |
+
| | float_ (double)
|
| 65 |
+
| | longfloat
|
| 66 |
+
| \\-> complexfloating (complexxx) (kind=c)
|
| 67 |
+
| csingle (singlecomplex)
|
| 68 |
+
| complex_ (cfloat, cdouble)
|
| 69 |
+
| clongfloat (longcomplex)
|
| 70 |
+
+-> flexible
|
| 71 |
+
| +-> character
|
| 72 |
+
| | str_ (string_, bytes_) (kind=S) [Python 2]
|
| 73 |
+
| | unicode_ (kind=U) [Python 2]
|
| 74 |
+
| |
|
| 75 |
+
| | bytes_ (string_) (kind=S) [Python 3]
|
| 76 |
+
| | str_ (unicode_) (kind=U) [Python 3]
|
| 77 |
+
| |
|
| 78 |
+
| \\-> void (kind=V)
|
| 79 |
+
\\-> object_ (not used much) (kind=O)
|
| 80 |
+
|
| 81 |
+
"""
|
| 82 |
+
import numbers
|
| 83 |
+
import warnings
|
| 84 |
+
|
| 85 |
+
from .multiarray import (
|
| 86 |
+
ndarray, array, dtype, datetime_data, datetime_as_string,
|
| 87 |
+
busday_offset, busday_count, is_busday, busdaycalendar
|
| 88 |
+
)
|
| 89 |
+
from .._utils import set_module
|
| 90 |
+
|
| 91 |
+
# we add more at the bottom
|
| 92 |
+
__all__ = ['sctypeDict', 'sctypes',
|
| 93 |
+
'ScalarType', 'obj2sctype', 'cast', 'nbytes', 'sctype2char',
|
| 94 |
+
'maximum_sctype', 'issctype', 'typecodes', 'find_common_type',
|
| 95 |
+
'issubdtype', 'datetime_data', 'datetime_as_string',
|
| 96 |
+
'busday_offset', 'busday_count', 'is_busday', 'busdaycalendar',
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
# we don't need all these imports, but we need to keep them for compatibility
|
| 100 |
+
# for users using np.core.numerictypes.UPPER_TABLE
|
| 101 |
+
from ._string_helpers import (
|
| 102 |
+
english_lower, english_upper, english_capitalize, LOWER_TABLE, UPPER_TABLE
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
from ._type_aliases import (
|
| 106 |
+
sctypeDict,
|
| 107 |
+
allTypes,
|
| 108 |
+
bitname,
|
| 109 |
+
sctypes,
|
| 110 |
+
_concrete_types,
|
| 111 |
+
_concrete_typeinfo,
|
| 112 |
+
_bits_of,
|
| 113 |
+
)
|
| 114 |
+
from ._dtype import _kind_name
|
| 115 |
+
|
| 116 |
+
# we don't export these for import *, but we do want them accessible
|
| 117 |
+
# as numerictypes.bool, etc.
|
| 118 |
+
from builtins import bool, int, float, complex, object, str, bytes
|
| 119 |
+
from numpy.compat import long, unicode
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
# We use this later
|
| 123 |
+
generic = allTypes['generic']
|
| 124 |
+
|
| 125 |
+
genericTypeRank = ['bool', 'int8', 'uint8', 'int16', 'uint16',
|
| 126 |
+
'int32', 'uint32', 'int64', 'uint64', 'int128',
|
| 127 |
+
'uint128', 'float16',
|
| 128 |
+
'float32', 'float64', 'float80', 'float96', 'float128',
|
| 129 |
+
'float256',
|
| 130 |
+
'complex32', 'complex64', 'complex128', 'complex160',
|
| 131 |
+
'complex192', 'complex256', 'complex512', 'object']
|
| 132 |
+
|
| 133 |
+
@set_module('numpy')
|
| 134 |
+
def maximum_sctype(t):
|
| 135 |
+
"""
|
| 136 |
+
Return the scalar type of highest precision of the same kind as the input.
|
| 137 |
+
|
| 138 |
+
Parameters
|
| 139 |
+
----------
|
| 140 |
+
t : dtype or dtype specifier
|
| 141 |
+
The input data type. This can be a `dtype` object or an object that
|
| 142 |
+
is convertible to a `dtype`.
|
| 143 |
+
|
| 144 |
+
Returns
|
| 145 |
+
-------
|
| 146 |
+
out : dtype
|
| 147 |
+
The highest precision data type of the same kind (`dtype.kind`) as `t`.
|
| 148 |
+
|
| 149 |
+
See Also
|
| 150 |
+
--------
|
| 151 |
+
obj2sctype, mintypecode, sctype2char
|
| 152 |
+
dtype
|
| 153 |
+
|
| 154 |
+
Examples
|
| 155 |
+
--------
|
| 156 |
+
>>> np.maximum_sctype(int)
|
| 157 |
+
<class 'numpy.int64'>
|
| 158 |
+
>>> np.maximum_sctype(np.uint8)
|
| 159 |
+
<class 'numpy.uint64'>
|
| 160 |
+
>>> np.maximum_sctype(complex)
|
| 161 |
+
<class 'numpy.complex256'> # may vary
|
| 162 |
+
|
| 163 |
+
>>> np.maximum_sctype(str)
|
| 164 |
+
<class 'numpy.str_'>
|
| 165 |
+
|
| 166 |
+
>>> np.maximum_sctype('i2')
|
| 167 |
+
<class 'numpy.int64'>
|
| 168 |
+
>>> np.maximum_sctype('f4')
|
| 169 |
+
<class 'numpy.float128'> # may vary
|
| 170 |
+
|
| 171 |
+
"""
|
| 172 |
+
g = obj2sctype(t)
|
| 173 |
+
if g is None:
|
| 174 |
+
return t
|
| 175 |
+
t = g
|
| 176 |
+
base = _kind_name(dtype(t))
|
| 177 |
+
if base in sctypes:
|
| 178 |
+
return sctypes[base][-1]
|
| 179 |
+
else:
|
| 180 |
+
return t
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
@set_module('numpy')
|
| 184 |
+
def issctype(rep):
|
| 185 |
+
"""
|
| 186 |
+
Determines whether the given object represents a scalar data-type.
|
| 187 |
+
|
| 188 |
+
Parameters
|
| 189 |
+
----------
|
| 190 |
+
rep : any
|
| 191 |
+
If `rep` is an instance of a scalar dtype, True is returned. If not,
|
| 192 |
+
False is returned.
|
| 193 |
+
|
| 194 |
+
Returns
|
| 195 |
+
-------
|
| 196 |
+
out : bool
|
| 197 |
+
Boolean result of check whether `rep` is a scalar dtype.
|
| 198 |
+
|
| 199 |
+
See Also
|
| 200 |
+
--------
|
| 201 |
+
issubsctype, issubdtype, obj2sctype, sctype2char
|
| 202 |
+
|
| 203 |
+
Examples
|
| 204 |
+
--------
|
| 205 |
+
>>> np.issctype(np.int32)
|
| 206 |
+
True
|
| 207 |
+
>>> np.issctype(list)
|
| 208 |
+
False
|
| 209 |
+
>>> np.issctype(1.1)
|
| 210 |
+
False
|
| 211 |
+
|
| 212 |
+
Strings are also a scalar type:
|
| 213 |
+
|
| 214 |
+
>>> np.issctype(np.dtype('str'))
|
| 215 |
+
True
|
| 216 |
+
|
| 217 |
+
"""
|
| 218 |
+
if not isinstance(rep, (type, dtype)):
|
| 219 |
+
return False
|
| 220 |
+
try:
|
| 221 |
+
res = obj2sctype(rep)
|
| 222 |
+
if res and res != object_:
|
| 223 |
+
return True
|
| 224 |
+
return False
|
| 225 |
+
except Exception:
|
| 226 |
+
return False
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
@set_module('numpy')
|
| 230 |
+
def obj2sctype(rep, default=None):
|
| 231 |
+
"""
|
| 232 |
+
Return the scalar dtype or NumPy equivalent of Python type of an object.
|
| 233 |
+
|
| 234 |
+
Parameters
|
| 235 |
+
----------
|
| 236 |
+
rep : any
|
| 237 |
+
The object of which the type is returned.
|
| 238 |
+
default : any, optional
|
| 239 |
+
If given, this is returned for objects whose types can not be
|
| 240 |
+
determined. If not given, None is returned for those objects.
|
| 241 |
+
|
| 242 |
+
Returns
|
| 243 |
+
-------
|
| 244 |
+
dtype : dtype or Python type
|
| 245 |
+
The data type of `rep`.
|
| 246 |
+
|
| 247 |
+
See Also
|
| 248 |
+
--------
|
| 249 |
+
sctype2char, issctype, issubsctype, issubdtype, maximum_sctype
|
| 250 |
+
|
| 251 |
+
Examples
|
| 252 |
+
--------
|
| 253 |
+
>>> np.obj2sctype(np.int32)
|
| 254 |
+
<class 'numpy.int32'>
|
| 255 |
+
>>> np.obj2sctype(np.array([1., 2.]))
|
| 256 |
+
<class 'numpy.float64'>
|
| 257 |
+
>>> np.obj2sctype(np.array([1.j]))
|
| 258 |
+
<class 'numpy.complex128'>
|
| 259 |
+
|
| 260 |
+
>>> np.obj2sctype(dict)
|
| 261 |
+
<class 'numpy.object_'>
|
| 262 |
+
>>> np.obj2sctype('string')
|
| 263 |
+
|
| 264 |
+
>>> np.obj2sctype(1, default=list)
|
| 265 |
+
<class 'list'>
|
| 266 |
+
|
| 267 |
+
"""
|
| 268 |
+
# prevent abstract classes being upcast
|
| 269 |
+
if isinstance(rep, type) and issubclass(rep, generic):
|
| 270 |
+
return rep
|
| 271 |
+
# extract dtype from arrays
|
| 272 |
+
if isinstance(rep, ndarray):
|
| 273 |
+
return rep.dtype.type
|
| 274 |
+
# fall back on dtype to convert
|
| 275 |
+
try:
|
| 276 |
+
res = dtype(rep)
|
| 277 |
+
except Exception:
|
| 278 |
+
return default
|
| 279 |
+
else:
|
| 280 |
+
return res.type
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
@set_module('numpy')
|
| 284 |
+
def issubclass_(arg1, arg2):
|
| 285 |
+
"""
|
| 286 |
+
Determine if a class is a subclass of a second class.
|
| 287 |
+
|
| 288 |
+
`issubclass_` is equivalent to the Python built-in ``issubclass``,
|
| 289 |
+
except that it returns False instead of raising a TypeError if one
|
| 290 |
+
of the arguments is not a class.
|
| 291 |
+
|
| 292 |
+
Parameters
|
| 293 |
+
----------
|
| 294 |
+
arg1 : class
|
| 295 |
+
Input class. True is returned if `arg1` is a subclass of `arg2`.
|
| 296 |
+
arg2 : class or tuple of classes.
|
| 297 |
+
Input class. If a tuple of classes, True is returned if `arg1` is a
|
| 298 |
+
subclass of any of the tuple elements.
|
| 299 |
+
|
| 300 |
+
Returns
|
| 301 |
+
-------
|
| 302 |
+
out : bool
|
| 303 |
+
Whether `arg1` is a subclass of `arg2` or not.
|
| 304 |
+
|
| 305 |
+
See Also
|
| 306 |
+
--------
|
| 307 |
+
issubsctype, issubdtype, issctype
|
| 308 |
+
|
| 309 |
+
Examples
|
| 310 |
+
--------
|
| 311 |
+
>>> np.issubclass_(np.int32, int)
|
| 312 |
+
False
|
| 313 |
+
>>> np.issubclass_(np.int32, float)
|
| 314 |
+
False
|
| 315 |
+
>>> np.issubclass_(np.float64, float)
|
| 316 |
+
True
|
| 317 |
+
|
| 318 |
+
"""
|
| 319 |
+
try:
|
| 320 |
+
return issubclass(arg1, arg2)
|
| 321 |
+
except TypeError:
|
| 322 |
+
return False
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
@set_module('numpy')
|
| 326 |
+
def issubsctype(arg1, arg2):
|
| 327 |
+
"""
|
| 328 |
+
Determine if the first argument is a subclass of the second argument.
|
| 329 |
+
|
| 330 |
+
Parameters
|
| 331 |
+
----------
|
| 332 |
+
arg1, arg2 : dtype or dtype specifier
|
| 333 |
+
Data-types.
|
| 334 |
+
|
| 335 |
+
Returns
|
| 336 |
+
-------
|
| 337 |
+
out : bool
|
| 338 |
+
The result.
|
| 339 |
+
|
| 340 |
+
See Also
|
| 341 |
+
--------
|
| 342 |
+
issctype, issubdtype, obj2sctype
|
| 343 |
+
|
| 344 |
+
Examples
|
| 345 |
+
--------
|
| 346 |
+
>>> np.issubsctype('S8', str)
|
| 347 |
+
False
|
| 348 |
+
>>> np.issubsctype(np.array([1]), int)
|
| 349 |
+
True
|
| 350 |
+
>>> np.issubsctype(np.array([1]), float)
|
| 351 |
+
False
|
| 352 |
+
|
| 353 |
+
"""
|
| 354 |
+
return issubclass(obj2sctype(arg1), obj2sctype(arg2))
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
@set_module('numpy')
|
| 358 |
+
def issubdtype(arg1, arg2):
|
| 359 |
+
r"""
|
| 360 |
+
Returns True if first argument is a typecode lower/equal in type hierarchy.
|
| 361 |
+
|
| 362 |
+
This is like the builtin :func:`issubclass`, but for `dtype`\ s.
|
| 363 |
+
|
| 364 |
+
Parameters
|
| 365 |
+
----------
|
| 366 |
+
arg1, arg2 : dtype_like
|
| 367 |
+
`dtype` or object coercible to one
|
| 368 |
+
|
| 369 |
+
Returns
|
| 370 |
+
-------
|
| 371 |
+
out : bool
|
| 372 |
+
|
| 373 |
+
See Also
|
| 374 |
+
--------
|
| 375 |
+
:ref:`arrays.scalars` : Overview of the numpy type hierarchy.
|
| 376 |
+
issubsctype, issubclass_
|
| 377 |
+
|
| 378 |
+
Examples
|
| 379 |
+
--------
|
| 380 |
+
`issubdtype` can be used to check the type of arrays:
|
| 381 |
+
|
| 382 |
+
>>> ints = np.array([1, 2, 3], dtype=np.int32)
|
| 383 |
+
>>> np.issubdtype(ints.dtype, np.integer)
|
| 384 |
+
True
|
| 385 |
+
>>> np.issubdtype(ints.dtype, np.floating)
|
| 386 |
+
False
|
| 387 |
+
|
| 388 |
+
>>> floats = np.array([1, 2, 3], dtype=np.float32)
|
| 389 |
+
>>> np.issubdtype(floats.dtype, np.integer)
|
| 390 |
+
False
|
| 391 |
+
>>> np.issubdtype(floats.dtype, np.floating)
|
| 392 |
+
True
|
| 393 |
+
|
| 394 |
+
Similar types of different sizes are not subdtypes of each other:
|
| 395 |
+
|
| 396 |
+
>>> np.issubdtype(np.float64, np.float32)
|
| 397 |
+
False
|
| 398 |
+
>>> np.issubdtype(np.float32, np.float64)
|
| 399 |
+
False
|
| 400 |
+
|
| 401 |
+
but both are subtypes of `floating`:
|
| 402 |
+
|
| 403 |
+
>>> np.issubdtype(np.float64, np.floating)
|
| 404 |
+
True
|
| 405 |
+
>>> np.issubdtype(np.float32, np.floating)
|
| 406 |
+
True
|
| 407 |
+
|
| 408 |
+
For convenience, dtype-like objects are allowed too:
|
| 409 |
+
|
| 410 |
+
>>> np.issubdtype('S1', np.string_)
|
| 411 |
+
True
|
| 412 |
+
>>> np.issubdtype('i4', np.signedinteger)
|
| 413 |
+
True
|
| 414 |
+
|
| 415 |
+
"""
|
| 416 |
+
if not issubclass_(arg1, generic):
|
| 417 |
+
arg1 = dtype(arg1).type
|
| 418 |
+
if not issubclass_(arg2, generic):
|
| 419 |
+
arg2 = dtype(arg2).type
|
| 420 |
+
|
| 421 |
+
return issubclass(arg1, arg2)
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
# This dictionary allows look up based on any alias for an array data-type
|
| 425 |
+
class _typedict(dict):
|
| 426 |
+
"""
|
| 427 |
+
Base object for a dictionary for look-up with any alias for an array dtype.
|
| 428 |
+
|
| 429 |
+
Instances of `_typedict` can not be used as dictionaries directly,
|
| 430 |
+
first they have to be populated.
|
| 431 |
+
|
| 432 |
+
"""
|
| 433 |
+
|
| 434 |
+
def __getitem__(self, obj):
|
| 435 |
+
return dict.__getitem__(self, obj2sctype(obj))
|
| 436 |
+
|
| 437 |
+
nbytes = _typedict()
|
| 438 |
+
_alignment = _typedict()
|
| 439 |
+
_maxvals = _typedict()
|
| 440 |
+
_minvals = _typedict()
|
| 441 |
+
def _construct_lookups():
|
| 442 |
+
for name, info in _concrete_typeinfo.items():
|
| 443 |
+
obj = info.type
|
| 444 |
+
nbytes[obj] = info.bits // 8
|
| 445 |
+
_alignment[obj] = info.alignment
|
| 446 |
+
if len(info) > 5:
|
| 447 |
+
_maxvals[obj] = info.max
|
| 448 |
+
_minvals[obj] = info.min
|
| 449 |
+
else:
|
| 450 |
+
_maxvals[obj] = None
|
| 451 |
+
_minvals[obj] = None
|
| 452 |
+
|
| 453 |
+
_construct_lookups()
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
@set_module('numpy')
|
| 457 |
+
def sctype2char(sctype):
|
| 458 |
+
"""
|
| 459 |
+
Return the string representation of a scalar dtype.
|
| 460 |
+
|
| 461 |
+
Parameters
|
| 462 |
+
----------
|
| 463 |
+
sctype : scalar dtype or object
|
| 464 |
+
If a scalar dtype, the corresponding string character is
|
| 465 |
+
returned. If an object, `sctype2char` tries to infer its scalar type
|
| 466 |
+
and then return the corresponding string character.
|
| 467 |
+
|
| 468 |
+
Returns
|
| 469 |
+
-------
|
| 470 |
+
typechar : str
|
| 471 |
+
The string character corresponding to the scalar type.
|
| 472 |
+
|
| 473 |
+
Raises
|
| 474 |
+
------
|
| 475 |
+
ValueError
|
| 476 |
+
If `sctype` is an object for which the type can not be inferred.
|
| 477 |
+
|
| 478 |
+
See Also
|
| 479 |
+
--------
|
| 480 |
+
obj2sctype, issctype, issubsctype, mintypecode
|
| 481 |
+
|
| 482 |
+
Examples
|
| 483 |
+
--------
|
| 484 |
+
>>> for sctype in [np.int32, np.double, np.complex_, np.string_, np.ndarray]:
|
| 485 |
+
... print(np.sctype2char(sctype))
|
| 486 |
+
l # may vary
|
| 487 |
+
d
|
| 488 |
+
D
|
| 489 |
+
S
|
| 490 |
+
O
|
| 491 |
+
|
| 492 |
+
>>> x = np.array([1., 2-1.j])
|
| 493 |
+
>>> np.sctype2char(x)
|
| 494 |
+
'D'
|
| 495 |
+
>>> np.sctype2char(list)
|
| 496 |
+
'O'
|
| 497 |
+
|
| 498 |
+
"""
|
| 499 |
+
sctype = obj2sctype(sctype)
|
| 500 |
+
if sctype is None:
|
| 501 |
+
raise ValueError("unrecognized type")
|
| 502 |
+
if sctype not in _concrete_types:
|
| 503 |
+
# for compatibility
|
| 504 |
+
raise KeyError(sctype)
|
| 505 |
+
return dtype(sctype).char
|
| 506 |
+
|
| 507 |
+
# Create dictionary of casting functions that wrap sequences
|
| 508 |
+
# indexed by type or type character
|
| 509 |
+
cast = _typedict()
|
| 510 |
+
for key in _concrete_types:
|
| 511 |
+
cast[key] = lambda x, k=key: array(x, copy=False).astype(k)
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def _scalar_type_key(typ):
|
| 515 |
+
"""A ``key`` function for `sorted`."""
|
| 516 |
+
dt = dtype(typ)
|
| 517 |
+
return (dt.kind.lower(), dt.itemsize)
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
ScalarType = [int, float, complex, bool, bytes, str, memoryview]
|
| 521 |
+
ScalarType += sorted(_concrete_types, key=_scalar_type_key)
|
| 522 |
+
ScalarType = tuple(ScalarType)
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
# Now add the types we've determined to this module
|
| 526 |
+
for key in allTypes:
|
| 527 |
+
globals()[key] = allTypes[key]
|
| 528 |
+
__all__.append(key)
|
| 529 |
+
|
| 530 |
+
del key
|
| 531 |
+
|
| 532 |
+
typecodes = {'Character':'c',
|
| 533 |
+
'Integer':'bhilqp',
|
| 534 |
+
'UnsignedInteger':'BHILQP',
|
| 535 |
+
'Float':'efdg',
|
| 536 |
+
'Complex':'FDG',
|
| 537 |
+
'AllInteger':'bBhHiIlLqQpP',
|
| 538 |
+
'AllFloat':'efdgFDG',
|
| 539 |
+
'Datetime': 'Mm',
|
| 540 |
+
'All':'?bhilqpBHILQPefdgFDGSUVOMm'}
|
| 541 |
+
|
| 542 |
+
# backwards compatibility --- deprecated name
|
| 543 |
+
# Formal deprecation: Numpy 1.20.0, 2020-10-19 (see numpy/__init__.py)
|
| 544 |
+
typeDict = sctypeDict
|
| 545 |
+
|
| 546 |
+
# b -> boolean
|
| 547 |
+
# u -> unsigned integer
|
| 548 |
+
# i -> signed integer
|
| 549 |
+
# f -> floating point
|
| 550 |
+
# c -> complex
|
| 551 |
+
# M -> datetime
|
| 552 |
+
# m -> timedelta
|
| 553 |
+
# S -> string
|
| 554 |
+
# U -> Unicode string
|
| 555 |
+
# V -> record
|
| 556 |
+
# O -> Python object
|
| 557 |
+
_kind_list = ['b', 'u', 'i', 'f', 'c', 'S', 'U', 'V', 'O', 'M', 'm']
|
| 558 |
+
|
| 559 |
+
__test_types = '?'+typecodes['AllInteger'][:-2]+typecodes['AllFloat']+'O'
|
| 560 |
+
__len_test_types = len(__test_types)
|
| 561 |
+
|
| 562 |
+
# Keep incrementing until a common type both can be coerced to
|
| 563 |
+
# is found. Otherwise, return None
|
| 564 |
+
def _find_common_coerce(a, b):
|
| 565 |
+
if a > b:
|
| 566 |
+
return a
|
| 567 |
+
try:
|
| 568 |
+
thisind = __test_types.index(a.char)
|
| 569 |
+
except ValueError:
|
| 570 |
+
return None
|
| 571 |
+
return _can_coerce_all([a, b], start=thisind)
|
| 572 |
+
|
| 573 |
+
# Find a data-type that all data-types in a list can be coerced to
|
| 574 |
+
def _can_coerce_all(dtypelist, start=0):
|
| 575 |
+
N = len(dtypelist)
|
| 576 |
+
if N == 0:
|
| 577 |
+
return None
|
| 578 |
+
if N == 1:
|
| 579 |
+
return dtypelist[0]
|
| 580 |
+
thisind = start
|
| 581 |
+
while thisind < __len_test_types:
|
| 582 |
+
newdtype = dtype(__test_types[thisind])
|
| 583 |
+
numcoerce = len([x for x in dtypelist if newdtype >= x])
|
| 584 |
+
if numcoerce == N:
|
| 585 |
+
return newdtype
|
| 586 |
+
thisind += 1
|
| 587 |
+
return None
|
| 588 |
+
|
| 589 |
+
def _register_types():
|
| 590 |
+
numbers.Integral.register(integer)
|
| 591 |
+
numbers.Complex.register(inexact)
|
| 592 |
+
numbers.Real.register(floating)
|
| 593 |
+
numbers.Number.register(number)
|
| 594 |
+
|
| 595 |
+
_register_types()
|
| 596 |
+
|
| 597 |
+
|
| 598 |
+
@set_module('numpy')
|
| 599 |
+
def find_common_type(array_types, scalar_types):
|
| 600 |
+
"""
|
| 601 |
+
Determine common type following standard coercion rules.
|
| 602 |
+
|
| 603 |
+
.. deprecated:: NumPy 1.25
|
| 604 |
+
|
| 605 |
+
This function is deprecated, use `numpy.promote_types` or
|
| 606 |
+
`numpy.result_type` instead. To achieve semantics for the
|
| 607 |
+
`scalar_types` argument, use `numpy.result_type` and pass the Python
|
| 608 |
+
values `0`, `0.0`, or `0j`.
|
| 609 |
+
This will give the same results in almost all cases.
|
| 610 |
+
More information and rare exception can be found in the
|
| 611 |
+
`NumPy 1.25 release notes <https://numpy.org/devdocs/release/1.25.0-notes.html>`_.
|
| 612 |
+
|
| 613 |
+
Parameters
|
| 614 |
+
----------
|
| 615 |
+
array_types : sequence
|
| 616 |
+
A list of dtypes or dtype convertible objects representing arrays.
|
| 617 |
+
scalar_types : sequence
|
| 618 |
+
A list of dtypes or dtype convertible objects representing scalars.
|
| 619 |
+
|
| 620 |
+
Returns
|
| 621 |
+
-------
|
| 622 |
+
datatype : dtype
|
| 623 |
+
The common data type, which is the maximum of `array_types` ignoring
|
| 624 |
+
`scalar_types`, unless the maximum of `scalar_types` is of a
|
| 625 |
+
different kind (`dtype.kind`). If the kind is not understood, then
|
| 626 |
+
None is returned.
|
| 627 |
+
|
| 628 |
+
See Also
|
| 629 |
+
--------
|
| 630 |
+
dtype, common_type, can_cast, mintypecode
|
| 631 |
+
|
| 632 |
+
Examples
|
| 633 |
+
--------
|
| 634 |
+
>>> np.find_common_type([], [np.int64, np.float32, complex])
|
| 635 |
+
dtype('complex128')
|
| 636 |
+
>>> np.find_common_type([np.int64, np.float32], [])
|
| 637 |
+
dtype('float64')
|
| 638 |
+
|
| 639 |
+
The standard casting rules ensure that a scalar cannot up-cast an
|
| 640 |
+
array unless the scalar is of a fundamentally different kind of data
|
| 641 |
+
(i.e. under a different hierarchy in the data type hierarchy) then
|
| 642 |
+
the array:
|
| 643 |
+
|
| 644 |
+
>>> np.find_common_type([np.float32], [np.int64, np.float64])
|
| 645 |
+
dtype('float32')
|
| 646 |
+
|
| 647 |
+
Complex is of a different type, so it up-casts the float in the
|
| 648 |
+
`array_types` argument:
|
| 649 |
+
|
| 650 |
+
>>> np.find_common_type([np.float32], [complex])
|
| 651 |
+
dtype('complex128')
|
| 652 |
+
|
| 653 |
+
Type specifier strings are convertible to dtypes and can therefore
|
| 654 |
+
be used instead of dtypes:
|
| 655 |
+
|
| 656 |
+
>>> np.find_common_type(['f4', 'f4', 'i4'], ['c8'])
|
| 657 |
+
dtype('complex128')
|
| 658 |
+
|
| 659 |
+
"""
|
| 660 |
+
# Deprecated 2022-11-07, NumPy 1.25
|
| 661 |
+
warnings.warn(
|
| 662 |
+
"np.find_common_type is deprecated. Please use `np.result_type` "
|
| 663 |
+
"or `np.promote_types`.\n"
|
| 664 |
+
"See https://numpy.org/devdocs/release/1.25.0-notes.html and the "
|
| 665 |
+
"docs for more information. (Deprecated NumPy 1.25)",
|
| 666 |
+
DeprecationWarning, stacklevel=2)
|
| 667 |
+
|
| 668 |
+
array_types = [dtype(x) for x in array_types]
|
| 669 |
+
scalar_types = [dtype(x) for x in scalar_types]
|
| 670 |
+
|
| 671 |
+
maxa = _can_coerce_all(array_types)
|
| 672 |
+
maxsc = _can_coerce_all(scalar_types)
|
| 673 |
+
|
| 674 |
+
if maxa is None:
|
| 675 |
+
return maxsc
|
| 676 |
+
|
| 677 |
+
if maxsc is None:
|
| 678 |
+
return maxa
|
| 679 |
+
|
| 680 |
+
try:
|
| 681 |
+
index_a = _kind_list.index(maxa.kind)
|
| 682 |
+
index_sc = _kind_list.index(maxsc.kind)
|
| 683 |
+
except ValueError:
|
| 684 |
+
return None
|
| 685 |
+
|
| 686 |
+
if index_sc > index_a:
|
| 687 |
+
return _find_common_coerce(maxsc, maxa)
|
| 688 |
+
else:
|
| 689 |
+
return maxa
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (6.68 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/__main__.cpython-312.pyc
ADDED
|
Binary file (286 Bytes). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/__version__.cpython-312.pyc
ADDED
|
Binary file (267 Bytes). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/_isocbind.cpython-312.pyc
ADDED
|
Binary file (1.93 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/capi_maps.cpython-312.pyc
ADDED
|
Binary file (31 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/cb_rules.cpython-312.pyc
ADDED
|
Binary file (22.5 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/f2py2e.cpython-312.pyc
ADDED
|
Binary file (33.2 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/f90mod_rules.cpython-312.pyc
ADDED
|
Binary file (11.7 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/func2subr.cpython-312.pyc
ADDED
|
Binary file (11.4 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/rules.cpython-312.pyc
ADDED
|
Binary file (52.6 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/setup.cpython-312.pyc
ADDED
|
Binary file (2.72 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/symbolic.cpython-312.pyc
ADDED
|
Binary file (79.9 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/__pycache__/use_rules.cpython-312.pyc
ADDED
|
Binary file (4.25 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/_backends/__init__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def f2py_build_generator(name):
|
| 2 |
+
if name == "meson":
|
| 3 |
+
from ._meson import MesonBackend
|
| 4 |
+
return MesonBackend
|
| 5 |
+
elif name == "distutils":
|
| 6 |
+
from ._distutils import DistutilsBackend
|
| 7 |
+
return DistutilsBackend
|
| 8 |
+
else:
|
| 9 |
+
raise ValueError(f"Unknown backend: {name}")
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/_backends/_backend.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from abc import ABC, abstractmethod
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Backend(ABC):
|
| 7 |
+
def __init__(
|
| 8 |
+
self,
|
| 9 |
+
modulename,
|
| 10 |
+
sources,
|
| 11 |
+
extra_objects,
|
| 12 |
+
build_dir,
|
| 13 |
+
include_dirs,
|
| 14 |
+
library_dirs,
|
| 15 |
+
libraries,
|
| 16 |
+
define_macros,
|
| 17 |
+
undef_macros,
|
| 18 |
+
f2py_flags,
|
| 19 |
+
sysinfo_flags,
|
| 20 |
+
fc_flags,
|
| 21 |
+
flib_flags,
|
| 22 |
+
setup_flags,
|
| 23 |
+
remove_build_dir,
|
| 24 |
+
extra_dat,
|
| 25 |
+
):
|
| 26 |
+
self.modulename = modulename
|
| 27 |
+
self.sources = sources
|
| 28 |
+
self.extra_objects = extra_objects
|
| 29 |
+
self.build_dir = build_dir
|
| 30 |
+
self.include_dirs = include_dirs
|
| 31 |
+
self.library_dirs = library_dirs
|
| 32 |
+
self.libraries = libraries
|
| 33 |
+
self.define_macros = define_macros
|
| 34 |
+
self.undef_macros = undef_macros
|
| 35 |
+
self.f2py_flags = f2py_flags
|
| 36 |
+
self.sysinfo_flags = sysinfo_flags
|
| 37 |
+
self.fc_flags = fc_flags
|
| 38 |
+
self.flib_flags = flib_flags
|
| 39 |
+
self.setup_flags = setup_flags
|
| 40 |
+
self.remove_build_dir = remove_build_dir
|
| 41 |
+
self.extra_dat = extra_dat
|
| 42 |
+
|
| 43 |
+
@abstractmethod
|
| 44 |
+
def compile(self) -> None:
|
| 45 |
+
"""Compile the wrapper."""
|
| 46 |
+
pass
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/_backends/_distutils.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ._backend import Backend
|
| 2 |
+
|
| 3 |
+
from numpy.distutils.core import setup, Extension
|
| 4 |
+
from numpy.distutils.system_info import get_info
|
| 5 |
+
from numpy.distutils.misc_util import dict_append
|
| 6 |
+
from numpy.exceptions import VisibleDeprecationWarning
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
import shutil
|
| 10 |
+
import warnings
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class DistutilsBackend(Backend):
|
| 14 |
+
def __init__(sef, *args, **kwargs):
|
| 15 |
+
warnings.warn(
|
| 16 |
+
"distutils has been deprecated since NumPy 1.26.x"
|
| 17 |
+
"Use the Meson backend instead, or generate wrappers"
|
| 18 |
+
"without -c and use a custom build script",
|
| 19 |
+
VisibleDeprecationWarning,
|
| 20 |
+
stacklevel=2,
|
| 21 |
+
)
|
| 22 |
+
super().__init__(*args, **kwargs)
|
| 23 |
+
|
| 24 |
+
def compile(self):
|
| 25 |
+
num_info = {}
|
| 26 |
+
if num_info:
|
| 27 |
+
self.include_dirs.extend(num_info.get("include_dirs", []))
|
| 28 |
+
ext_args = {
|
| 29 |
+
"name": self.modulename,
|
| 30 |
+
"sources": self.sources,
|
| 31 |
+
"include_dirs": self.include_dirs,
|
| 32 |
+
"library_dirs": self.library_dirs,
|
| 33 |
+
"libraries": self.libraries,
|
| 34 |
+
"define_macros": self.define_macros,
|
| 35 |
+
"undef_macros": self.undef_macros,
|
| 36 |
+
"extra_objects": self.extra_objects,
|
| 37 |
+
"f2py_options": self.f2py_flags,
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
if self.sysinfo_flags:
|
| 41 |
+
for n in self.sysinfo_flags:
|
| 42 |
+
i = get_info(n)
|
| 43 |
+
if not i:
|
| 44 |
+
print(
|
| 45 |
+
f"No {repr(n)} resources found"
|
| 46 |
+
"in system (try `f2py --help-link`)"
|
| 47 |
+
)
|
| 48 |
+
dict_append(ext_args, **i)
|
| 49 |
+
|
| 50 |
+
ext = Extension(**ext_args)
|
| 51 |
+
|
| 52 |
+
sys.argv = [sys.argv[0]] + self.setup_flags
|
| 53 |
+
sys.argv.extend(
|
| 54 |
+
[
|
| 55 |
+
"build",
|
| 56 |
+
"--build-temp",
|
| 57 |
+
self.build_dir,
|
| 58 |
+
"--build-base",
|
| 59 |
+
self.build_dir,
|
| 60 |
+
"--build-platlib",
|
| 61 |
+
".",
|
| 62 |
+
"--disable-optimization",
|
| 63 |
+
]
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
if self.fc_flags:
|
| 67 |
+
sys.argv.extend(["config_fc"] + self.fc_flags)
|
| 68 |
+
if self.flib_flags:
|
| 69 |
+
sys.argv.extend(["build_ext"] + self.flib_flags)
|
| 70 |
+
|
| 71 |
+
setup(ext_modules=[ext])
|
| 72 |
+
|
| 73 |
+
if self.remove_build_dir and os.path.exists(self.build_dir):
|
| 74 |
+
print(f"Removing build directory {self.build_dir}")
|
| 75 |
+
shutil.rmtree(self.build_dir)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/_backends/_meson.py
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import errno
|
| 5 |
+
import shutil
|
| 6 |
+
import subprocess
|
| 7 |
+
import sys
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
from ._backend import Backend
|
| 11 |
+
from string import Template
|
| 12 |
+
from itertools import chain
|
| 13 |
+
|
| 14 |
+
import warnings
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class MesonTemplate:
|
| 18 |
+
"""Template meson build file generation class."""
|
| 19 |
+
|
| 20 |
+
def __init__(
|
| 21 |
+
self,
|
| 22 |
+
modulename: str,
|
| 23 |
+
sources: list[Path],
|
| 24 |
+
deps: list[str],
|
| 25 |
+
libraries: list[str],
|
| 26 |
+
library_dirs: list[Path],
|
| 27 |
+
include_dirs: list[Path],
|
| 28 |
+
object_files: list[Path],
|
| 29 |
+
linker_args: list[str],
|
| 30 |
+
c_args: list[str],
|
| 31 |
+
build_type: str,
|
| 32 |
+
python_exe: str,
|
| 33 |
+
):
|
| 34 |
+
self.modulename = modulename
|
| 35 |
+
self.build_template_path = (
|
| 36 |
+
Path(__file__).parent.absolute() / "meson.build.template"
|
| 37 |
+
)
|
| 38 |
+
self.sources = sources
|
| 39 |
+
self.deps = deps
|
| 40 |
+
self.libraries = libraries
|
| 41 |
+
self.library_dirs = library_dirs
|
| 42 |
+
if include_dirs is not None:
|
| 43 |
+
self.include_dirs = include_dirs
|
| 44 |
+
else:
|
| 45 |
+
self.include_dirs = []
|
| 46 |
+
self.substitutions = {}
|
| 47 |
+
self.objects = object_files
|
| 48 |
+
self.pipeline = [
|
| 49 |
+
self.initialize_template,
|
| 50 |
+
self.sources_substitution,
|
| 51 |
+
self.deps_substitution,
|
| 52 |
+
self.include_substitution,
|
| 53 |
+
self.libraries_substitution,
|
| 54 |
+
]
|
| 55 |
+
self.build_type = build_type
|
| 56 |
+
self.python_exe = python_exe
|
| 57 |
+
|
| 58 |
+
def meson_build_template(self) -> str:
|
| 59 |
+
if not self.build_template_path.is_file():
|
| 60 |
+
raise FileNotFoundError(
|
| 61 |
+
errno.ENOENT,
|
| 62 |
+
"Meson build template"
|
| 63 |
+
f" {self.build_template_path.absolute()}"
|
| 64 |
+
" does not exist.",
|
| 65 |
+
)
|
| 66 |
+
return self.build_template_path.read_text()
|
| 67 |
+
|
| 68 |
+
def initialize_template(self) -> None:
|
| 69 |
+
self.substitutions["modulename"] = self.modulename
|
| 70 |
+
self.substitutions["buildtype"] = self.build_type
|
| 71 |
+
self.substitutions["python"] = self.python_exe
|
| 72 |
+
|
| 73 |
+
def sources_substitution(self) -> None:
|
| 74 |
+
indent = " " * 21
|
| 75 |
+
self.substitutions["source_list"] = f",\n{indent}".join(
|
| 76 |
+
[f"{indent}'{source}'" for source in self.sources]
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
def deps_substitution(self) -> None:
|
| 80 |
+
indent = " " * 21
|
| 81 |
+
self.substitutions["dep_list"] = f",\n{indent}".join(
|
| 82 |
+
[f"{indent}dependency('{dep}')" for dep in self.deps]
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
def libraries_substitution(self) -> None:
|
| 86 |
+
self.substitutions["lib_dir_declarations"] = "\n".join(
|
| 87 |
+
[
|
| 88 |
+
f"lib_dir_{i} = declare_dependency(link_args : ['-L{lib_dir}'])"
|
| 89 |
+
for i, lib_dir in enumerate(self.library_dirs)
|
| 90 |
+
]
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
self.substitutions["lib_declarations"] = "\n".join(
|
| 94 |
+
[
|
| 95 |
+
f"{lib} = declare_dependency(link_args : ['-l{lib}'])"
|
| 96 |
+
for lib in self.libraries
|
| 97 |
+
]
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
indent = " " * 21
|
| 101 |
+
self.substitutions["lib_list"] = f"\n{indent}".join(
|
| 102 |
+
[f"{indent}{lib}," for lib in self.libraries]
|
| 103 |
+
)
|
| 104 |
+
self.substitutions["lib_dir_list"] = f"\n{indent}".join(
|
| 105 |
+
[f"{indent}lib_dir_{i}," for i in range(len(self.library_dirs))]
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
def include_substitution(self) -> None:
|
| 109 |
+
indent = " " * 21
|
| 110 |
+
self.substitutions["inc_list"] = f",\n{indent}".join(
|
| 111 |
+
[f"{indent}'{inc}'" for inc in self.include_dirs]
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
def generate_meson_build(self):
|
| 115 |
+
for node in self.pipeline:
|
| 116 |
+
node()
|
| 117 |
+
template = Template(self.meson_build_template())
|
| 118 |
+
return template.substitute(self.substitutions)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
class MesonBackend(Backend):
|
| 122 |
+
def __init__(self, *args, **kwargs):
|
| 123 |
+
super().__init__(*args, **kwargs)
|
| 124 |
+
self.dependencies = self.extra_dat.get("dependencies", [])
|
| 125 |
+
self.meson_build_dir = "bbdir"
|
| 126 |
+
self.build_type = (
|
| 127 |
+
"debug" if any("debug" in flag for flag in self.fc_flags) else "release"
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
def _move_exec_to_root(self, build_dir: Path):
|
| 131 |
+
walk_dir = Path(build_dir) / self.meson_build_dir
|
| 132 |
+
path_objects = chain(
|
| 133 |
+
walk_dir.glob(f"{self.modulename}*.so"),
|
| 134 |
+
walk_dir.glob(f"{self.modulename}*.pyd"),
|
| 135 |
+
)
|
| 136 |
+
# Same behavior as distutils
|
| 137 |
+
# https://github.com/numpy/numpy/issues/24874#issuecomment-1835632293
|
| 138 |
+
for path_object in path_objects:
|
| 139 |
+
dest_path = Path.cwd() / path_object.name
|
| 140 |
+
if dest_path.exists():
|
| 141 |
+
dest_path.unlink()
|
| 142 |
+
shutil.copy2(path_object, dest_path)
|
| 143 |
+
os.remove(path_object)
|
| 144 |
+
|
| 145 |
+
def write_meson_build(self, build_dir: Path) -> None:
|
| 146 |
+
"""Writes the meson build file at specified location"""
|
| 147 |
+
meson_template = MesonTemplate(
|
| 148 |
+
self.modulename,
|
| 149 |
+
self.sources,
|
| 150 |
+
self.dependencies,
|
| 151 |
+
self.libraries,
|
| 152 |
+
self.library_dirs,
|
| 153 |
+
self.include_dirs,
|
| 154 |
+
self.extra_objects,
|
| 155 |
+
self.flib_flags,
|
| 156 |
+
self.fc_flags,
|
| 157 |
+
self.build_type,
|
| 158 |
+
sys.executable,
|
| 159 |
+
)
|
| 160 |
+
src = meson_template.generate_meson_build()
|
| 161 |
+
Path(build_dir).mkdir(parents=True, exist_ok=True)
|
| 162 |
+
meson_build_file = Path(build_dir) / "meson.build"
|
| 163 |
+
meson_build_file.write_text(src)
|
| 164 |
+
return meson_build_file
|
| 165 |
+
|
| 166 |
+
def _run_subprocess_command(self, command, cwd):
|
| 167 |
+
subprocess.run(command, cwd=cwd, check=True)
|
| 168 |
+
|
| 169 |
+
def run_meson(self, build_dir: Path):
|
| 170 |
+
setup_command = ["meson", "setup", self.meson_build_dir]
|
| 171 |
+
self._run_subprocess_command(setup_command, build_dir)
|
| 172 |
+
compile_command = ["meson", "compile", "-C", self.meson_build_dir]
|
| 173 |
+
self._run_subprocess_command(compile_command, build_dir)
|
| 174 |
+
|
| 175 |
+
def compile(self) -> None:
|
| 176 |
+
self.sources = _prepare_sources(self.modulename, self.sources, self.build_dir)
|
| 177 |
+
self.write_meson_build(self.build_dir)
|
| 178 |
+
self.run_meson(self.build_dir)
|
| 179 |
+
self._move_exec_to_root(self.build_dir)
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def _prepare_sources(mname, sources, bdir):
|
| 183 |
+
extended_sources = sources.copy()
|
| 184 |
+
Path(bdir).mkdir(parents=True, exist_ok=True)
|
| 185 |
+
# Copy sources
|
| 186 |
+
for source in sources:
|
| 187 |
+
if Path(source).exists() and Path(source).is_file():
|
| 188 |
+
shutil.copy(source, bdir)
|
| 189 |
+
generated_sources = [
|
| 190 |
+
Path(f"{mname}module.c"),
|
| 191 |
+
Path(f"{mname}-f2pywrappers2.f90"),
|
| 192 |
+
Path(f"{mname}-f2pywrappers.f"),
|
| 193 |
+
]
|
| 194 |
+
bdir = Path(bdir)
|
| 195 |
+
for generated_source in generated_sources:
|
| 196 |
+
if generated_source.exists():
|
| 197 |
+
shutil.copy(generated_source, bdir / generated_source.name)
|
| 198 |
+
extended_sources.append(generated_source.name)
|
| 199 |
+
generated_source.unlink()
|
| 200 |
+
extended_sources = [
|
| 201 |
+
Path(source).name
|
| 202 |
+
for source in extended_sources
|
| 203 |
+
if not Path(source).suffix == ".pyf"
|
| 204 |
+
]
|
| 205 |
+
return extended_sources
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/_backends/meson.build.template
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
project('${modulename}',
|
| 2 |
+
['c', 'fortran'],
|
| 3 |
+
version : '0.1',
|
| 4 |
+
meson_version: '>= 1.1.0',
|
| 5 |
+
default_options : [
|
| 6 |
+
'warning_level=1',
|
| 7 |
+
'buildtype=${buildtype}'
|
| 8 |
+
])
|
| 9 |
+
fc = meson.get_compiler('fortran')
|
| 10 |
+
|
| 11 |
+
py = import('python').find_installation('${python}', pure: false)
|
| 12 |
+
py_dep = py.dependency()
|
| 13 |
+
|
| 14 |
+
incdir_numpy = run_command(py,
|
| 15 |
+
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'],
|
| 16 |
+
check : true
|
| 17 |
+
).stdout().strip()
|
| 18 |
+
|
| 19 |
+
incdir_f2py = run_command(py,
|
| 20 |
+
['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'],
|
| 21 |
+
check : true
|
| 22 |
+
).stdout().strip()
|
| 23 |
+
|
| 24 |
+
inc_np = include_directories(incdir_numpy)
|
| 25 |
+
np_dep = declare_dependency(include_directories: inc_np)
|
| 26 |
+
|
| 27 |
+
incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src'
|
| 28 |
+
inc_f2py = include_directories(incdir_f2py)
|
| 29 |
+
fortranobject_c = incdir_f2py / 'fortranobject.c'
|
| 30 |
+
|
| 31 |
+
inc_np = include_directories(incdir_numpy, incdir_f2py)
|
| 32 |
+
# gh-25000
|
| 33 |
+
quadmath_dep = fc.find_library('quadmath', required: false)
|
| 34 |
+
|
| 35 |
+
${lib_declarations}
|
| 36 |
+
${lib_dir_declarations}
|
| 37 |
+
|
| 38 |
+
py.extension_module('${modulename}',
|
| 39 |
+
[
|
| 40 |
+
${source_list},
|
| 41 |
+
fortranobject_c
|
| 42 |
+
],
|
| 43 |
+
include_directories: [
|
| 44 |
+
inc_np,
|
| 45 |
+
${inc_list}
|
| 46 |
+
],
|
| 47 |
+
dependencies : [
|
| 48 |
+
py_dep,
|
| 49 |
+
quadmath_dep,
|
| 50 |
+
${dep_list}
|
| 51 |
+
${lib_list}
|
| 52 |
+
${lib_dir_list}
|
| 53 |
+
],
|
| 54 |
+
install : true)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/src/fortranobject.c
ADDED
|
@@ -0,0 +1,1423 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define FORTRANOBJECT_C
|
| 2 |
+
#include "fortranobject.h"
|
| 3 |
+
|
| 4 |
+
#ifdef __cplusplus
|
| 5 |
+
extern "C" {
|
| 6 |
+
#endif
|
| 7 |
+
|
| 8 |
+
#include <stdarg.h>
|
| 9 |
+
#include <stdlib.h>
|
| 10 |
+
#include <string.h>
|
| 11 |
+
|
| 12 |
+
/*
|
| 13 |
+
This file implements: FortranObject, array_from_pyobj, copy_ND_array
|
| 14 |
+
|
| 15 |
+
Author: Pearu Peterson <pearu@cens.ioc.ee>
|
| 16 |
+
$Revision: 1.52 $
|
| 17 |
+
$Date: 2005/07/11 07:44:20 $
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
int
|
| 21 |
+
F2PyDict_SetItemString(PyObject *dict, char *name, PyObject *obj)
|
| 22 |
+
{
|
| 23 |
+
if (obj == NULL) {
|
| 24 |
+
fprintf(stderr, "Error loading %s\n", name);
|
| 25 |
+
if (PyErr_Occurred()) {
|
| 26 |
+
PyErr_Print();
|
| 27 |
+
PyErr_Clear();
|
| 28 |
+
}
|
| 29 |
+
return -1;
|
| 30 |
+
}
|
| 31 |
+
return PyDict_SetItemString(dict, name, obj);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
/*
|
| 35 |
+
* Python-only fallback for thread-local callback pointers
|
| 36 |
+
*/
|
| 37 |
+
void *
|
| 38 |
+
F2PySwapThreadLocalCallbackPtr(char *key, void *ptr)
|
| 39 |
+
{
|
| 40 |
+
PyObject *local_dict, *value;
|
| 41 |
+
void *prev;
|
| 42 |
+
|
| 43 |
+
local_dict = PyThreadState_GetDict();
|
| 44 |
+
if (local_dict == NULL) {
|
| 45 |
+
Py_FatalError(
|
| 46 |
+
"F2PySwapThreadLocalCallbackPtr: PyThreadState_GetDict "
|
| 47 |
+
"failed");
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
value = PyDict_GetItemString(local_dict, key);
|
| 51 |
+
if (value != NULL) {
|
| 52 |
+
prev = PyLong_AsVoidPtr(value);
|
| 53 |
+
if (PyErr_Occurred()) {
|
| 54 |
+
Py_FatalError(
|
| 55 |
+
"F2PySwapThreadLocalCallbackPtr: PyLong_AsVoidPtr failed");
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
else {
|
| 59 |
+
prev = NULL;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
value = PyLong_FromVoidPtr((void *)ptr);
|
| 63 |
+
if (value == NULL) {
|
| 64 |
+
Py_FatalError(
|
| 65 |
+
"F2PySwapThreadLocalCallbackPtr: PyLong_FromVoidPtr failed");
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
if (PyDict_SetItemString(local_dict, key, value) != 0) {
|
| 69 |
+
Py_FatalError(
|
| 70 |
+
"F2PySwapThreadLocalCallbackPtr: PyDict_SetItemString failed");
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
Py_DECREF(value);
|
| 74 |
+
|
| 75 |
+
return prev;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
void *
|
| 79 |
+
F2PyGetThreadLocalCallbackPtr(char *key)
|
| 80 |
+
{
|
| 81 |
+
PyObject *local_dict, *value;
|
| 82 |
+
void *prev;
|
| 83 |
+
|
| 84 |
+
local_dict = PyThreadState_GetDict();
|
| 85 |
+
if (local_dict == NULL) {
|
| 86 |
+
Py_FatalError(
|
| 87 |
+
"F2PyGetThreadLocalCallbackPtr: PyThreadState_GetDict failed");
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
value = PyDict_GetItemString(local_dict, key);
|
| 91 |
+
if (value != NULL) {
|
| 92 |
+
prev = PyLong_AsVoidPtr(value);
|
| 93 |
+
if (PyErr_Occurred()) {
|
| 94 |
+
Py_FatalError(
|
| 95 |
+
"F2PyGetThreadLocalCallbackPtr: PyLong_AsVoidPtr failed");
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
else {
|
| 99 |
+
prev = NULL;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
return prev;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
static PyArray_Descr *
|
| 106 |
+
get_descr_from_type_and_elsize(const int type_num, const int elsize) {
|
| 107 |
+
PyArray_Descr * descr = PyArray_DescrFromType(type_num);
|
| 108 |
+
if (type_num == NPY_STRING) {
|
| 109 |
+
// PyArray_DescrFromType returns descr with elsize = 0.
|
| 110 |
+
PyArray_DESCR_REPLACE(descr);
|
| 111 |
+
if (descr == NULL) {
|
| 112 |
+
return NULL;
|
| 113 |
+
}
|
| 114 |
+
descr->elsize = elsize;
|
| 115 |
+
}
|
| 116 |
+
return descr;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/************************* FortranObject *******************************/
|
| 120 |
+
|
| 121 |
+
typedef PyObject *(*fortranfunc)(PyObject *, PyObject *, PyObject *, void *);
|
| 122 |
+
|
| 123 |
+
PyObject *
|
| 124 |
+
PyFortranObject_New(FortranDataDef *defs, f2py_void_func init)
|
| 125 |
+
{
|
| 126 |
+
int i;
|
| 127 |
+
PyFortranObject *fp = NULL;
|
| 128 |
+
PyObject *v = NULL;
|
| 129 |
+
if (init != NULL) { /* Initialize F90 module objects */
|
| 130 |
+
(*(init))();
|
| 131 |
+
}
|
| 132 |
+
fp = PyObject_New(PyFortranObject, &PyFortran_Type);
|
| 133 |
+
if (fp == NULL) {
|
| 134 |
+
return NULL;
|
| 135 |
+
}
|
| 136 |
+
if ((fp->dict = PyDict_New()) == NULL) {
|
| 137 |
+
Py_DECREF(fp);
|
| 138 |
+
return NULL;
|
| 139 |
+
}
|
| 140 |
+
fp->len = 0;
|
| 141 |
+
while (defs[fp->len].name != NULL) {
|
| 142 |
+
fp->len++;
|
| 143 |
+
}
|
| 144 |
+
if (fp->len == 0) {
|
| 145 |
+
goto fail;
|
| 146 |
+
}
|
| 147 |
+
fp->defs = defs;
|
| 148 |
+
for (i = 0; i < fp->len; i++) {
|
| 149 |
+
if (fp->defs[i].rank == -1) { /* Is Fortran routine */
|
| 150 |
+
v = PyFortranObject_NewAsAttr(&(fp->defs[i]));
|
| 151 |
+
if (v == NULL) {
|
| 152 |
+
goto fail;
|
| 153 |
+
}
|
| 154 |
+
PyDict_SetItemString(fp->dict, fp->defs[i].name, v);
|
| 155 |
+
Py_XDECREF(v);
|
| 156 |
+
}
|
| 157 |
+
else if ((fp->defs[i].data) !=
|
| 158 |
+
NULL) { /* Is Fortran variable or array (not allocatable) */
|
| 159 |
+
PyArray_Descr *
|
| 160 |
+
descr = get_descr_from_type_and_elsize(fp->defs[i].type,
|
| 161 |
+
fp->defs[i].elsize);
|
| 162 |
+
if (descr == NULL) {
|
| 163 |
+
goto fail;
|
| 164 |
+
}
|
| 165 |
+
v = PyArray_NewFromDescr(&PyArray_Type, descr, fp->defs[i].rank,
|
| 166 |
+
fp->defs[i].dims.d, NULL, fp->defs[i].data,
|
| 167 |
+
NPY_ARRAY_FARRAY, NULL);
|
| 168 |
+
if (v == NULL) {
|
| 169 |
+
Py_DECREF(descr);
|
| 170 |
+
goto fail;
|
| 171 |
+
}
|
| 172 |
+
PyDict_SetItemString(fp->dict, fp->defs[i].name, v);
|
| 173 |
+
Py_XDECREF(v);
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
return (PyObject *)fp;
|
| 177 |
+
fail:
|
| 178 |
+
Py_XDECREF(fp);
|
| 179 |
+
return NULL;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
PyObject *
|
| 183 |
+
PyFortranObject_NewAsAttr(FortranDataDef *defs)
|
| 184 |
+
{ /* used for calling F90 module routines */
|
| 185 |
+
PyFortranObject *fp = NULL;
|
| 186 |
+
fp = PyObject_New(PyFortranObject, &PyFortran_Type);
|
| 187 |
+
if (fp == NULL)
|
| 188 |
+
return NULL;
|
| 189 |
+
if ((fp->dict = PyDict_New()) == NULL) {
|
| 190 |
+
PyObject_Del(fp);
|
| 191 |
+
return NULL;
|
| 192 |
+
}
|
| 193 |
+
fp->len = 1;
|
| 194 |
+
fp->defs = defs;
|
| 195 |
+
if (defs->rank == -1) {
|
| 196 |
+
PyDict_SetItemString(fp->dict, "__name__", PyUnicode_FromFormat("function %s", defs->name));
|
| 197 |
+
} else if (defs->rank == 0) {
|
| 198 |
+
PyDict_SetItemString(fp->dict, "__name__", PyUnicode_FromFormat("scalar %s", defs->name));
|
| 199 |
+
} else {
|
| 200 |
+
PyDict_SetItemString(fp->dict, "__name__", PyUnicode_FromFormat("array %s", defs->name));
|
| 201 |
+
}
|
| 202 |
+
return (PyObject *)fp;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
/* Fortran methods */
|
| 206 |
+
|
| 207 |
+
static void
|
| 208 |
+
fortran_dealloc(PyFortranObject *fp)
|
| 209 |
+
{
|
| 210 |
+
Py_XDECREF(fp->dict);
|
| 211 |
+
PyObject_Del(fp);
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
/* Returns number of bytes consumed from buf, or -1 on error. */
|
| 215 |
+
static Py_ssize_t
|
| 216 |
+
format_def(char *buf, Py_ssize_t size, FortranDataDef def)
|
| 217 |
+
{
|
| 218 |
+
char *p = buf;
|
| 219 |
+
int i;
|
| 220 |
+
npy_intp n;
|
| 221 |
+
|
| 222 |
+
n = PyOS_snprintf(p, size, "array(%" NPY_INTP_FMT, def.dims.d[0]);
|
| 223 |
+
if (n < 0 || n >= size) {
|
| 224 |
+
return -1;
|
| 225 |
+
}
|
| 226 |
+
p += n;
|
| 227 |
+
size -= n;
|
| 228 |
+
|
| 229 |
+
for (i = 1; i < def.rank; i++) {
|
| 230 |
+
n = PyOS_snprintf(p, size, ",%" NPY_INTP_FMT, def.dims.d[i]);
|
| 231 |
+
if (n < 0 || n >= size) {
|
| 232 |
+
return -1;
|
| 233 |
+
}
|
| 234 |
+
p += n;
|
| 235 |
+
size -= n;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
if (size <= 0) {
|
| 239 |
+
return -1;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
*p++ = ')';
|
| 243 |
+
size--;
|
| 244 |
+
|
| 245 |
+
if (def.data == NULL) {
|
| 246 |
+
static const char notalloc[] = ", not allocated";
|
| 247 |
+
if ((size_t)size < sizeof(notalloc)) {
|
| 248 |
+
return -1;
|
| 249 |
+
}
|
| 250 |
+
memcpy(p, notalloc, sizeof(notalloc));
|
| 251 |
+
p += sizeof(notalloc);
|
| 252 |
+
size -= sizeof(notalloc);
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
return p - buf;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
static PyObject *
|
| 259 |
+
fortran_doc(FortranDataDef def)
|
| 260 |
+
{
|
| 261 |
+
char *buf, *p;
|
| 262 |
+
PyObject *s = NULL;
|
| 263 |
+
Py_ssize_t n, origsize, size = 100;
|
| 264 |
+
|
| 265 |
+
if (def.doc != NULL) {
|
| 266 |
+
size += strlen(def.doc);
|
| 267 |
+
}
|
| 268 |
+
origsize = size;
|
| 269 |
+
buf = p = (char *)PyMem_Malloc(size);
|
| 270 |
+
if (buf == NULL) {
|
| 271 |
+
return PyErr_NoMemory();
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
if (def.rank == -1) {
|
| 275 |
+
if (def.doc) {
|
| 276 |
+
n = strlen(def.doc);
|
| 277 |
+
if (n > size) {
|
| 278 |
+
goto fail;
|
| 279 |
+
}
|
| 280 |
+
memcpy(p, def.doc, n);
|
| 281 |
+
p += n;
|
| 282 |
+
size -= n;
|
| 283 |
+
}
|
| 284 |
+
else {
|
| 285 |
+
n = PyOS_snprintf(p, size, "%s - no docs available", def.name);
|
| 286 |
+
if (n < 0 || n >= size) {
|
| 287 |
+
goto fail;
|
| 288 |
+
}
|
| 289 |
+
p += n;
|
| 290 |
+
size -= n;
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
else {
|
| 294 |
+
PyArray_Descr *d = PyArray_DescrFromType(def.type);
|
| 295 |
+
n = PyOS_snprintf(p, size, "%s : '%c'-", def.name, d->type);
|
| 296 |
+
Py_DECREF(d);
|
| 297 |
+
if (n < 0 || n >= size) {
|
| 298 |
+
goto fail;
|
| 299 |
+
}
|
| 300 |
+
p += n;
|
| 301 |
+
size -= n;
|
| 302 |
+
|
| 303 |
+
if (def.data == NULL) {
|
| 304 |
+
n = format_def(p, size, def);
|
| 305 |
+
if (n < 0) {
|
| 306 |
+
goto fail;
|
| 307 |
+
}
|
| 308 |
+
p += n;
|
| 309 |
+
size -= n;
|
| 310 |
+
}
|
| 311 |
+
else if (def.rank > 0) {
|
| 312 |
+
n = format_def(p, size, def);
|
| 313 |
+
if (n < 0) {
|
| 314 |
+
goto fail;
|
| 315 |
+
}
|
| 316 |
+
p += n;
|
| 317 |
+
size -= n;
|
| 318 |
+
}
|
| 319 |
+
else {
|
| 320 |
+
n = strlen("scalar");
|
| 321 |
+
if (size < n) {
|
| 322 |
+
goto fail;
|
| 323 |
+
}
|
| 324 |
+
memcpy(p, "scalar", n);
|
| 325 |
+
p += n;
|
| 326 |
+
size -= n;
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
if (size <= 1) {
|
| 330 |
+
goto fail;
|
| 331 |
+
}
|
| 332 |
+
*p++ = '\n';
|
| 333 |
+
size--;
|
| 334 |
+
|
| 335 |
+
/* p now points one beyond the last character of the string in buf */
|
| 336 |
+
s = PyUnicode_FromStringAndSize(buf, p - buf);
|
| 337 |
+
|
| 338 |
+
PyMem_Free(buf);
|
| 339 |
+
return s;
|
| 340 |
+
|
| 341 |
+
fail:
|
| 342 |
+
fprintf(stderr,
|
| 343 |
+
"fortranobject.c: fortran_doc: len(p)=%zd>%zd=size:"
|
| 344 |
+
" too long docstring required, increase size\n",
|
| 345 |
+
p - buf, origsize);
|
| 346 |
+
PyMem_Free(buf);
|
| 347 |
+
return NULL;
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
static FortranDataDef *save_def; /* save pointer of an allocatable array */
|
| 351 |
+
static void
|
| 352 |
+
set_data(char *d, npy_intp *f)
|
| 353 |
+
{ /* callback from Fortran */
|
| 354 |
+
if (*f) /* In fortran f=allocated(d) */
|
| 355 |
+
save_def->data = d;
|
| 356 |
+
else
|
| 357 |
+
save_def->data = NULL;
|
| 358 |
+
/* printf("set_data: d=%p,f=%d\n",d,*f); */
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
static PyObject *
|
| 362 |
+
fortran_getattr(PyFortranObject *fp, char *name)
|
| 363 |
+
{
|
| 364 |
+
int i, j, k, flag;
|
| 365 |
+
if (fp->dict != NULL) {
|
| 366 |
+
PyObject *v = _PyDict_GetItemStringWithError(fp->dict, name);
|
| 367 |
+
if (v == NULL && PyErr_Occurred()) {
|
| 368 |
+
return NULL;
|
| 369 |
+
}
|
| 370 |
+
else if (v != NULL) {
|
| 371 |
+
Py_INCREF(v);
|
| 372 |
+
return v;
|
| 373 |
+
}
|
| 374 |
+
}
|
| 375 |
+
for (i = 0, j = 1; i < fp->len && (j = strcmp(name, fp->defs[i].name));
|
| 376 |
+
i++)
|
| 377 |
+
;
|
| 378 |
+
if (j == 0)
|
| 379 |
+
if (fp->defs[i].rank != -1) { /* F90 allocatable array */
|
| 380 |
+
if (fp->defs[i].func == NULL)
|
| 381 |
+
return NULL;
|
| 382 |
+
for (k = 0; k < fp->defs[i].rank; ++k) fp->defs[i].dims.d[k] = -1;
|
| 383 |
+
save_def = &fp->defs[i];
|
| 384 |
+
(*(fp->defs[i].func))(&fp->defs[i].rank, fp->defs[i].dims.d,
|
| 385 |
+
set_data, &flag);
|
| 386 |
+
if (flag == 2)
|
| 387 |
+
k = fp->defs[i].rank + 1;
|
| 388 |
+
else
|
| 389 |
+
k = fp->defs[i].rank;
|
| 390 |
+
if (fp->defs[i].data != NULL) { /* array is allocated */
|
| 391 |
+
PyObject *v = PyArray_New(
|
| 392 |
+
&PyArray_Type, k, fp->defs[i].dims.d, fp->defs[i].type,
|
| 393 |
+
NULL, fp->defs[i].data, 0, NPY_ARRAY_FARRAY, NULL);
|
| 394 |
+
if (v == NULL)
|
| 395 |
+
return NULL;
|
| 396 |
+
/* Py_INCREF(v); */
|
| 397 |
+
return v;
|
| 398 |
+
}
|
| 399 |
+
else { /* array is not allocated */
|
| 400 |
+
Py_RETURN_NONE;
|
| 401 |
+
}
|
| 402 |
+
}
|
| 403 |
+
if (strcmp(name, "__dict__") == 0) {
|
| 404 |
+
Py_INCREF(fp->dict);
|
| 405 |
+
return fp->dict;
|
| 406 |
+
}
|
| 407 |
+
if (strcmp(name, "__doc__") == 0) {
|
| 408 |
+
PyObject *s = PyUnicode_FromString(""), *s2, *s3;
|
| 409 |
+
for (i = 0; i < fp->len; i++) {
|
| 410 |
+
s2 = fortran_doc(fp->defs[i]);
|
| 411 |
+
s3 = PyUnicode_Concat(s, s2);
|
| 412 |
+
Py_DECREF(s2);
|
| 413 |
+
Py_DECREF(s);
|
| 414 |
+
s = s3;
|
| 415 |
+
}
|
| 416 |
+
if (PyDict_SetItemString(fp->dict, name, s))
|
| 417 |
+
return NULL;
|
| 418 |
+
return s;
|
| 419 |
+
}
|
| 420 |
+
if ((strcmp(name, "_cpointer") == 0) && (fp->len == 1)) {
|
| 421 |
+
PyObject *cobj =
|
| 422 |
+
F2PyCapsule_FromVoidPtr((void *)(fp->defs[0].data), NULL);
|
| 423 |
+
if (PyDict_SetItemString(fp->dict, name, cobj))
|
| 424 |
+
return NULL;
|
| 425 |
+
return cobj;
|
| 426 |
+
}
|
| 427 |
+
PyObject *str, *ret;
|
| 428 |
+
str = PyUnicode_FromString(name);
|
| 429 |
+
ret = PyObject_GenericGetAttr((PyObject *)fp, str);
|
| 430 |
+
Py_DECREF(str);
|
| 431 |
+
return ret;
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
static int
|
| 435 |
+
fortran_setattr(PyFortranObject *fp, char *name, PyObject *v)
|
| 436 |
+
{
|
| 437 |
+
int i, j, flag;
|
| 438 |
+
PyArrayObject *arr = NULL;
|
| 439 |
+
for (i = 0, j = 1; i < fp->len && (j = strcmp(name, fp->defs[i].name));
|
| 440 |
+
i++)
|
| 441 |
+
;
|
| 442 |
+
if (j == 0) {
|
| 443 |
+
if (fp->defs[i].rank == -1) {
|
| 444 |
+
PyErr_SetString(PyExc_AttributeError,
|
| 445 |
+
"over-writing fortran routine");
|
| 446 |
+
return -1;
|
| 447 |
+
}
|
| 448 |
+
if (fp->defs[i].func != NULL) { /* is allocatable array */
|
| 449 |
+
npy_intp dims[F2PY_MAX_DIMS];
|
| 450 |
+
int k;
|
| 451 |
+
save_def = &fp->defs[i];
|
| 452 |
+
if (v != Py_None) { /* set new value (reallocate if needed --
|
| 453 |
+
see f2py generated code for more
|
| 454 |
+
details ) */
|
| 455 |
+
for (k = 0; k < fp->defs[i].rank; k++) dims[k] = -1;
|
| 456 |
+
if ((arr = array_from_pyobj(fp->defs[i].type, dims,
|
| 457 |
+
fp->defs[i].rank, F2PY_INTENT_IN,
|
| 458 |
+
v)) == NULL)
|
| 459 |
+
return -1;
|
| 460 |
+
(*(fp->defs[i].func))(&fp->defs[i].rank, PyArray_DIMS(arr),
|
| 461 |
+
set_data, &flag);
|
| 462 |
+
}
|
| 463 |
+
else { /* deallocate */
|
| 464 |
+
for (k = 0; k < fp->defs[i].rank; k++) dims[k] = 0;
|
| 465 |
+
(*(fp->defs[i].func))(&fp->defs[i].rank, dims, set_data,
|
| 466 |
+
&flag);
|
| 467 |
+
for (k = 0; k < fp->defs[i].rank; k++) dims[k] = -1;
|
| 468 |
+
}
|
| 469 |
+
memcpy(fp->defs[i].dims.d, dims,
|
| 470 |
+
fp->defs[i].rank * sizeof(npy_intp));
|
| 471 |
+
}
|
| 472 |
+
else { /* not allocatable array */
|
| 473 |
+
if ((arr = array_from_pyobj(fp->defs[i].type, fp->defs[i].dims.d,
|
| 474 |
+
fp->defs[i].rank, F2PY_INTENT_IN,
|
| 475 |
+
v)) == NULL)
|
| 476 |
+
return -1;
|
| 477 |
+
}
|
| 478 |
+
if (fp->defs[i].data !=
|
| 479 |
+
NULL) { /* copy Python object to Fortran array */
|
| 480 |
+
npy_intp s = PyArray_MultiplyList(fp->defs[i].dims.d,
|
| 481 |
+
PyArray_NDIM(arr));
|
| 482 |
+
if (s == -1)
|
| 483 |
+
s = PyArray_MultiplyList(PyArray_DIMS(arr), PyArray_NDIM(arr));
|
| 484 |
+
if (s < 0 || (memcpy(fp->defs[i].data, PyArray_DATA(arr),
|
| 485 |
+
s * PyArray_ITEMSIZE(arr))) == NULL) {
|
| 486 |
+
if ((PyObject *)arr != v) {
|
| 487 |
+
Py_DECREF(arr);
|
| 488 |
+
}
|
| 489 |
+
return -1;
|
| 490 |
+
}
|
| 491 |
+
if ((PyObject *)arr != v) {
|
| 492 |
+
Py_DECREF(arr);
|
| 493 |
+
}
|
| 494 |
+
}
|
| 495 |
+
else
|
| 496 |
+
return (fp->defs[i].func == NULL ? -1 : 0);
|
| 497 |
+
return 0; /* successful */
|
| 498 |
+
}
|
| 499 |
+
if (fp->dict == NULL) {
|
| 500 |
+
fp->dict = PyDict_New();
|
| 501 |
+
if (fp->dict == NULL)
|
| 502 |
+
return -1;
|
| 503 |
+
}
|
| 504 |
+
if (v == NULL) {
|
| 505 |
+
int rv = PyDict_DelItemString(fp->dict, name);
|
| 506 |
+
if (rv < 0)
|
| 507 |
+
PyErr_SetString(PyExc_AttributeError,
|
| 508 |
+
"delete non-existing fortran attribute");
|
| 509 |
+
return rv;
|
| 510 |
+
}
|
| 511 |
+
else
|
| 512 |
+
return PyDict_SetItemString(fp->dict, name, v);
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
static PyObject *
|
| 516 |
+
fortran_call(PyFortranObject *fp, PyObject *arg, PyObject *kw)
|
| 517 |
+
{
|
| 518 |
+
int i = 0;
|
| 519 |
+
/* printf("fortran call
|
| 520 |
+
name=%s,func=%p,data=%p,%p\n",fp->defs[i].name,
|
| 521 |
+
fp->defs[i].func,fp->defs[i].data,&fp->defs[i].data); */
|
| 522 |
+
if (fp->defs[i].rank == -1) { /* is Fortran routine */
|
| 523 |
+
if (fp->defs[i].func == NULL) {
|
| 524 |
+
PyErr_Format(PyExc_RuntimeError, "no function to call");
|
| 525 |
+
return NULL;
|
| 526 |
+
}
|
| 527 |
+
else if (fp->defs[i].data == NULL)
|
| 528 |
+
/* dummy routine */
|
| 529 |
+
return (*((fortranfunc)(fp->defs[i].func)))((PyObject *)fp, arg,
|
| 530 |
+
kw, NULL);
|
| 531 |
+
else
|
| 532 |
+
return (*((fortranfunc)(fp->defs[i].func)))(
|
| 533 |
+
(PyObject *)fp, arg, kw, (void *)fp->defs[i].data);
|
| 534 |
+
}
|
| 535 |
+
PyErr_Format(PyExc_TypeError, "this fortran object is not callable");
|
| 536 |
+
return NULL;
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
static PyObject *
|
| 540 |
+
fortran_repr(PyFortranObject *fp)
|
| 541 |
+
{
|
| 542 |
+
PyObject *name = NULL, *repr = NULL;
|
| 543 |
+
name = PyObject_GetAttrString((PyObject *)fp, "__name__");
|
| 544 |
+
PyErr_Clear();
|
| 545 |
+
if (name != NULL && PyUnicode_Check(name)) {
|
| 546 |
+
repr = PyUnicode_FromFormat("<fortran %U>", name);
|
| 547 |
+
}
|
| 548 |
+
else {
|
| 549 |
+
repr = PyUnicode_FromString("<fortran object>");
|
| 550 |
+
}
|
| 551 |
+
Py_XDECREF(name);
|
| 552 |
+
return repr;
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
PyTypeObject PyFortran_Type = {
|
| 556 |
+
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "fortran",
|
| 557 |
+
.tp_basicsize = sizeof(PyFortranObject),
|
| 558 |
+
.tp_dealloc = (destructor)fortran_dealloc,
|
| 559 |
+
.tp_getattr = (getattrfunc)fortran_getattr,
|
| 560 |
+
.tp_setattr = (setattrfunc)fortran_setattr,
|
| 561 |
+
.tp_repr = (reprfunc)fortran_repr,
|
| 562 |
+
.tp_call = (ternaryfunc)fortran_call,
|
| 563 |
+
};
|
| 564 |
+
|
| 565 |
+
/************************* f2py_report_atexit *******************************/
|
| 566 |
+
|
| 567 |
+
#ifdef F2PY_REPORT_ATEXIT
|
| 568 |
+
static int passed_time = 0;
|
| 569 |
+
static int passed_counter = 0;
|
| 570 |
+
static int passed_call_time = 0;
|
| 571 |
+
static struct timeb start_time;
|
| 572 |
+
static struct timeb stop_time;
|
| 573 |
+
static struct timeb start_call_time;
|
| 574 |
+
static struct timeb stop_call_time;
|
| 575 |
+
static int cb_passed_time = 0;
|
| 576 |
+
static int cb_passed_counter = 0;
|
| 577 |
+
static int cb_passed_call_time = 0;
|
| 578 |
+
static struct timeb cb_start_time;
|
| 579 |
+
static struct timeb cb_stop_time;
|
| 580 |
+
static struct timeb cb_start_call_time;
|
| 581 |
+
static struct timeb cb_stop_call_time;
|
| 582 |
+
|
| 583 |
+
extern void
|
| 584 |
+
f2py_start_clock(void)
|
| 585 |
+
{
|
| 586 |
+
ftime(&start_time);
|
| 587 |
+
}
|
| 588 |
+
extern void
|
| 589 |
+
f2py_start_call_clock(void)
|
| 590 |
+
{
|
| 591 |
+
f2py_stop_clock();
|
| 592 |
+
ftime(&start_call_time);
|
| 593 |
+
}
|
| 594 |
+
extern void
|
| 595 |
+
f2py_stop_clock(void)
|
| 596 |
+
{
|
| 597 |
+
ftime(&stop_time);
|
| 598 |
+
passed_time += 1000 * (stop_time.time - start_time.time);
|
| 599 |
+
passed_time += stop_time.millitm - start_time.millitm;
|
| 600 |
+
}
|
| 601 |
+
extern void
|
| 602 |
+
f2py_stop_call_clock(void)
|
| 603 |
+
{
|
| 604 |
+
ftime(&stop_call_time);
|
| 605 |
+
passed_call_time += 1000 * (stop_call_time.time - start_call_time.time);
|
| 606 |
+
passed_call_time += stop_call_time.millitm - start_call_time.millitm;
|
| 607 |
+
passed_counter += 1;
|
| 608 |
+
f2py_start_clock();
|
| 609 |
+
}
|
| 610 |
+
|
| 611 |
+
extern void
|
| 612 |
+
f2py_cb_start_clock(void)
|
| 613 |
+
{
|
| 614 |
+
ftime(&cb_start_time);
|
| 615 |
+
}
|
| 616 |
+
extern void
|
| 617 |
+
f2py_cb_start_call_clock(void)
|
| 618 |
+
{
|
| 619 |
+
f2py_cb_stop_clock();
|
| 620 |
+
ftime(&cb_start_call_time);
|
| 621 |
+
}
|
| 622 |
+
extern void
|
| 623 |
+
f2py_cb_stop_clock(void)
|
| 624 |
+
{
|
| 625 |
+
ftime(&cb_stop_time);
|
| 626 |
+
cb_passed_time += 1000 * (cb_stop_time.time - cb_start_time.time);
|
| 627 |
+
cb_passed_time += cb_stop_time.millitm - cb_start_time.millitm;
|
| 628 |
+
}
|
| 629 |
+
extern void
|
| 630 |
+
f2py_cb_stop_call_clock(void)
|
| 631 |
+
{
|
| 632 |
+
ftime(&cb_stop_call_time);
|
| 633 |
+
cb_passed_call_time +=
|
| 634 |
+
1000 * (cb_stop_call_time.time - cb_start_call_time.time);
|
| 635 |
+
cb_passed_call_time +=
|
| 636 |
+
cb_stop_call_time.millitm - cb_start_call_time.millitm;
|
| 637 |
+
cb_passed_counter += 1;
|
| 638 |
+
f2py_cb_start_clock();
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
static int f2py_report_on_exit_been_here = 0;
|
| 642 |
+
extern void
|
| 643 |
+
f2py_report_on_exit(int exit_flag, void *name)
|
| 644 |
+
{
|
| 645 |
+
if (f2py_report_on_exit_been_here) {
|
| 646 |
+
fprintf(stderr, " %s\n", (char *)name);
|
| 647 |
+
return;
|
| 648 |
+
}
|
| 649 |
+
f2py_report_on_exit_been_here = 1;
|
| 650 |
+
fprintf(stderr, " /-----------------------\\\n");
|
| 651 |
+
fprintf(stderr, " < F2PY performance report >\n");
|
| 652 |
+
fprintf(stderr, " \\-----------------------/\n");
|
| 653 |
+
fprintf(stderr, "Overall time spent in ...\n");
|
| 654 |
+
fprintf(stderr, "(a) wrapped (Fortran/C) functions : %8d msec\n",
|
| 655 |
+
passed_call_time);
|
| 656 |
+
fprintf(stderr, "(b) f2py interface, %6d calls : %8d msec\n",
|
| 657 |
+
passed_counter, passed_time);
|
| 658 |
+
fprintf(stderr, "(c) call-back (Python) functions : %8d msec\n",
|
| 659 |
+
cb_passed_call_time);
|
| 660 |
+
fprintf(stderr, "(d) f2py call-back interface, %6d calls : %8d msec\n",
|
| 661 |
+
cb_passed_counter, cb_passed_time);
|
| 662 |
+
|
| 663 |
+
fprintf(stderr,
|
| 664 |
+
"(e) wrapped (Fortran/C) functions (actual) : %8d msec\n\n",
|
| 665 |
+
passed_call_time - cb_passed_call_time - cb_passed_time);
|
| 666 |
+
fprintf(stderr,
|
| 667 |
+
"Use -DF2PY_REPORT_ATEXIT_DISABLE to disable this message.\n");
|
| 668 |
+
fprintf(stderr, "Exit status: %d\n", exit_flag);
|
| 669 |
+
fprintf(stderr, "Modules : %s\n", (char *)name);
|
| 670 |
+
}
|
| 671 |
+
#endif
|
| 672 |
+
|
| 673 |
+
/********************** report on array copy ****************************/
|
| 674 |
+
|
| 675 |
+
#ifdef F2PY_REPORT_ON_ARRAY_COPY
|
| 676 |
+
static void
|
| 677 |
+
f2py_report_on_array_copy(PyArrayObject *arr)
|
| 678 |
+
{
|
| 679 |
+
const npy_intp arr_size = PyArray_Size((PyObject *)arr);
|
| 680 |
+
if (arr_size > F2PY_REPORT_ON_ARRAY_COPY) {
|
| 681 |
+
fprintf(stderr,
|
| 682 |
+
"copied an array: size=%ld, elsize=%" NPY_INTP_FMT "\n",
|
| 683 |
+
arr_size, (npy_intp)PyArray_ITEMSIZE(arr));
|
| 684 |
+
}
|
| 685 |
+
}
|
| 686 |
+
static void
|
| 687 |
+
f2py_report_on_array_copy_fromany(void)
|
| 688 |
+
{
|
| 689 |
+
fprintf(stderr, "created an array from object\n");
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
#define F2PY_REPORT_ON_ARRAY_COPY_FROMARR \
|
| 693 |
+
f2py_report_on_array_copy((PyArrayObject *)arr)
|
| 694 |
+
#define F2PY_REPORT_ON_ARRAY_COPY_FROMANY f2py_report_on_array_copy_fromany()
|
| 695 |
+
#else
|
| 696 |
+
#define F2PY_REPORT_ON_ARRAY_COPY_FROMARR
|
| 697 |
+
#define F2PY_REPORT_ON_ARRAY_COPY_FROMANY
|
| 698 |
+
#endif
|
| 699 |
+
|
| 700 |
+
/************************* array_from_obj *******************************/
|
| 701 |
+
|
| 702 |
+
/*
|
| 703 |
+
* File: array_from_pyobj.c
|
| 704 |
+
*
|
| 705 |
+
* Description:
|
| 706 |
+
* ------------
|
| 707 |
+
* Provides array_from_pyobj function that returns a contiguous array
|
| 708 |
+
* object with the given dimensions and required storage order, either
|
| 709 |
+
* in row-major (C) or column-major (Fortran) order. The function
|
| 710 |
+
* array_from_pyobj is very flexible about its Python object argument
|
| 711 |
+
* that can be any number, list, tuple, or array.
|
| 712 |
+
*
|
| 713 |
+
* array_from_pyobj is used in f2py generated Python extension
|
| 714 |
+
* modules.
|
| 715 |
+
*
|
| 716 |
+
* Author: Pearu Peterson <pearu@cens.ioc.ee>
|
| 717 |
+
* Created: 13-16 January 2002
|
| 718 |
+
* $Id: fortranobject.c,v 1.52 2005/07/11 07:44:20 pearu Exp $
|
| 719 |
+
*/
|
| 720 |
+
|
| 721 |
+
static int check_and_fix_dimensions(const PyArrayObject* arr,
|
| 722 |
+
const int rank,
|
| 723 |
+
npy_intp *dims,
|
| 724 |
+
const char *errmess);
|
| 725 |
+
|
| 726 |
+
static int
|
| 727 |
+
find_first_negative_dimension(const int rank, const npy_intp *dims)
|
| 728 |
+
{
|
| 729 |
+
int i;
|
| 730 |
+
for (i = 0; i < rank; ++i) {
|
| 731 |
+
if (dims[i] < 0) {
|
| 732 |
+
return i;
|
| 733 |
+
}
|
| 734 |
+
}
|
| 735 |
+
return -1;
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
#ifdef DEBUG_COPY_ND_ARRAY
|
| 739 |
+
void
|
| 740 |
+
dump_dims(int rank, npy_intp const *dims)
|
| 741 |
+
{
|
| 742 |
+
int i;
|
| 743 |
+
printf("[");
|
| 744 |
+
for (i = 0; i < rank; ++i) {
|
| 745 |
+
printf("%3" NPY_INTP_FMT, dims[i]);
|
| 746 |
+
}
|
| 747 |
+
printf("]\n");
|
| 748 |
+
}
|
| 749 |
+
void
|
| 750 |
+
dump_attrs(const PyArrayObject *obj)
|
| 751 |
+
{
|
| 752 |
+
const PyArrayObject_fields *arr = (const PyArrayObject_fields *)obj;
|
| 753 |
+
int rank = PyArray_NDIM(arr);
|
| 754 |
+
npy_intp size = PyArray_Size((PyObject *)arr);
|
| 755 |
+
printf("\trank = %d, flags = %d, size = %" NPY_INTP_FMT "\n", rank,
|
| 756 |
+
arr->flags, size);
|
| 757 |
+
printf("\tstrides = ");
|
| 758 |
+
dump_dims(rank, arr->strides);
|
| 759 |
+
printf("\tdimensions = ");
|
| 760 |
+
dump_dims(rank, arr->dimensions);
|
| 761 |
+
}
|
| 762 |
+
#endif
|
| 763 |
+
|
| 764 |
+
#define SWAPTYPE(a, b, t) \
|
| 765 |
+
{ \
|
| 766 |
+
t c; \
|
| 767 |
+
c = (a); \
|
| 768 |
+
(a) = (b); \
|
| 769 |
+
(b) = c; \
|
| 770 |
+
}
|
| 771 |
+
|
| 772 |
+
static int
|
| 773 |
+
swap_arrays(PyArrayObject *obj1, PyArrayObject *obj2)
|
| 774 |
+
{
|
| 775 |
+
PyArrayObject_fields *arr1 = (PyArrayObject_fields *)obj1,
|
| 776 |
+
*arr2 = (PyArrayObject_fields *)obj2;
|
| 777 |
+
SWAPTYPE(arr1->data, arr2->data, char *);
|
| 778 |
+
SWAPTYPE(arr1->nd, arr2->nd, int);
|
| 779 |
+
SWAPTYPE(arr1->dimensions, arr2->dimensions, npy_intp *);
|
| 780 |
+
SWAPTYPE(arr1->strides, arr2->strides, npy_intp *);
|
| 781 |
+
SWAPTYPE(arr1->base, arr2->base, PyObject *);
|
| 782 |
+
SWAPTYPE(arr1->descr, arr2->descr, PyArray_Descr *);
|
| 783 |
+
SWAPTYPE(arr1->flags, arr2->flags, int);
|
| 784 |
+
/* SWAPTYPE(arr1->weakreflist,arr2->weakreflist,PyObject*); */
|
| 785 |
+
return 0;
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
#define ARRAY_ISCOMPATIBLE(arr,type_num) \
|
| 789 |
+
((PyArray_ISINTEGER(arr) && PyTypeNum_ISINTEGER(type_num)) || \
|
| 790 |
+
(PyArray_ISFLOAT(arr) && PyTypeNum_ISFLOAT(type_num)) || \
|
| 791 |
+
(PyArray_ISCOMPLEX(arr) && PyTypeNum_ISCOMPLEX(type_num)) || \
|
| 792 |
+
(PyArray_ISBOOL(arr) && PyTypeNum_ISBOOL(type_num)) || \
|
| 793 |
+
(PyArray_ISSTRING(arr) && PyTypeNum_ISSTRING(type_num)))
|
| 794 |
+
|
| 795 |
+
static int
|
| 796 |
+
get_elsize(PyObject *obj) {
|
| 797 |
+
/*
|
| 798 |
+
get_elsize determines array itemsize from a Python object. Returns
|
| 799 |
+
elsize if successful, -1 otherwise.
|
| 800 |
+
|
| 801 |
+
Supported types of the input are: numpy.ndarray, bytes, str, tuple,
|
| 802 |
+
list.
|
| 803 |
+
*/
|
| 804 |
+
|
| 805 |
+
if (PyArray_Check(obj)) {
|
| 806 |
+
return PyArray_DESCR((PyArrayObject *)obj)->elsize;
|
| 807 |
+
} else if (PyBytes_Check(obj)) {
|
| 808 |
+
return PyBytes_GET_SIZE(obj);
|
| 809 |
+
} else if (PyUnicode_Check(obj)) {
|
| 810 |
+
return PyUnicode_GET_LENGTH(obj);
|
| 811 |
+
} else if (PySequence_Check(obj)) {
|
| 812 |
+
PyObject* fast = PySequence_Fast(obj, "f2py:fortranobject.c:get_elsize");
|
| 813 |
+
if (fast != NULL) {
|
| 814 |
+
Py_ssize_t i, n = PySequence_Fast_GET_SIZE(fast);
|
| 815 |
+
int sz, elsize = 0;
|
| 816 |
+
for (i=0; i<n; i++) {
|
| 817 |
+
sz = get_elsize(PySequence_Fast_GET_ITEM(fast, i) /* borrowed */);
|
| 818 |
+
if (sz > elsize) {
|
| 819 |
+
elsize = sz;
|
| 820 |
+
}
|
| 821 |
+
}
|
| 822 |
+
Py_DECREF(fast);
|
| 823 |
+
return elsize;
|
| 824 |
+
}
|
| 825 |
+
}
|
| 826 |
+
return -1;
|
| 827 |
+
}
|
| 828 |
+
|
| 829 |
+
extern PyArrayObject *
|
| 830 |
+
ndarray_from_pyobj(const int type_num,
|
| 831 |
+
const int elsize_,
|
| 832 |
+
npy_intp *dims,
|
| 833 |
+
const int rank,
|
| 834 |
+
const int intent,
|
| 835 |
+
PyObject *obj,
|
| 836 |
+
const char *errmess) {
|
| 837 |
+
/*
|
| 838 |
+
* Return an array with given element type and shape from a Python
|
| 839 |
+
* object while taking into account the usage intent of the array.
|
| 840 |
+
*
|
| 841 |
+
* - element type is defined by type_num and elsize
|
| 842 |
+
* - shape is defined by dims and rank
|
| 843 |
+
*
|
| 844 |
+
* ndarray_from_pyobj is used to convert Python object arguments
|
| 845 |
+
* to numpy ndarrays with given type and shape that data is passed
|
| 846 |
+
* to interfaced Fortran or C functions.
|
| 847 |
+
*
|
| 848 |
+
* errmess (if not NULL), contains a prefix of an error message
|
| 849 |
+
* for an exception to be triggered within this function.
|
| 850 |
+
*
|
| 851 |
+
* Negative elsize value means that elsize is to be determined
|
| 852 |
+
* from the Python object in runtime.
|
| 853 |
+
*
|
| 854 |
+
* Note on strings
|
| 855 |
+
* ---------------
|
| 856 |
+
*
|
| 857 |
+
* String type (type_num == NPY_STRING) does not have fixed
|
| 858 |
+
* element size and, by default, the type object sets it to
|
| 859 |
+
* 0. Therefore, for string types, one has to use elsize
|
| 860 |
+
* argument. For other types, elsize value is ignored.
|
| 861 |
+
*
|
| 862 |
+
* NumPy defines the type of a fixed-width string as
|
| 863 |
+
* dtype('S<width>'). In addition, there is also dtype('c'), that
|
| 864 |
+
* appears as dtype('S1') (these have the same type_num value),
|
| 865 |
+
* but is actually different (.char attribute is either 'S' or
|
| 866 |
+
* 'c', respecitely).
|
| 867 |
+
*
|
| 868 |
+
* In Fortran, character arrays and strings are different
|
| 869 |
+
* concepts. The relation between Fortran types, NumPy dtypes,
|
| 870 |
+
* and type_num-elsize pairs, is defined as follows:
|
| 871 |
+
*
|
| 872 |
+
* character*5 foo | dtype('S5') | elsize=5, shape=()
|
| 873 |
+
* character(5) foo | dtype('S1') | elsize=1, shape=(5)
|
| 874 |
+
* character*5 foo(n) | dtype('S5') | elsize=5, shape=(n,)
|
| 875 |
+
* character(5) foo(n) | dtype('S1') | elsize=1, shape=(5, n)
|
| 876 |
+
* character*(*) foo | dtype('S') | elsize=-1, shape=()
|
| 877 |
+
*
|
| 878 |
+
* Note about reference counting
|
| 879 |
+
* -----------------------------
|
| 880 |
+
*
|
| 881 |
+
* If the caller returns the array to Python, it must be done with
|
| 882 |
+
* Py_BuildValue("N",arr). Otherwise, if obj!=arr then the caller
|
| 883 |
+
* must call Py_DECREF(arr).
|
| 884 |
+
*
|
| 885 |
+
* Note on intent(cache,out,..)
|
| 886 |
+
* ----------------------------
|
| 887 |
+
* Don't expect correct data when returning intent(cache) array.
|
| 888 |
+
*
|
| 889 |
+
*/
|
| 890 |
+
char mess[F2PY_MESSAGE_BUFFER_SIZE];
|
| 891 |
+
PyArrayObject *arr = NULL;
|
| 892 |
+
int elsize = (elsize_ < 0 ? get_elsize(obj) : elsize_);
|
| 893 |
+
if (elsize < 0) {
|
| 894 |
+
if (errmess != NULL) {
|
| 895 |
+
strcpy(mess, errmess);
|
| 896 |
+
}
|
| 897 |
+
sprintf(mess + strlen(mess),
|
| 898 |
+
" -- failed to determine element size from %s",
|
| 899 |
+
Py_TYPE(obj)->tp_name);
|
| 900 |
+
PyErr_SetString(PyExc_SystemError, mess);
|
| 901 |
+
return NULL;
|
| 902 |
+
}
|
| 903 |
+
PyArray_Descr * descr = get_descr_from_type_and_elsize(type_num, elsize); // new reference
|
| 904 |
+
if (descr == NULL) {
|
| 905 |
+
return NULL;
|
| 906 |
+
}
|
| 907 |
+
elsize = descr->elsize;
|
| 908 |
+
if ((intent & F2PY_INTENT_HIDE)
|
| 909 |
+
|| ((intent & F2PY_INTENT_CACHE) && (obj == Py_None))
|
| 910 |
+
|| ((intent & F2PY_OPTIONAL) && (obj == Py_None))
|
| 911 |
+
) {
|
| 912 |
+
/* intent(cache), optional, intent(hide) */
|
| 913 |
+
int ineg = find_first_negative_dimension(rank, dims);
|
| 914 |
+
if (ineg >= 0) {
|
| 915 |
+
int i;
|
| 916 |
+
strcpy(mess, "failed to create intent(cache|hide)|optional array"
|
| 917 |
+
"-- must have defined dimensions but got (");
|
| 918 |
+
for(i = 0; i < rank; ++i)
|
| 919 |
+
sprintf(mess + strlen(mess), "%" NPY_INTP_FMT ",", dims[i]);
|
| 920 |
+
strcat(mess, ")");
|
| 921 |
+
PyErr_SetString(PyExc_ValueError, mess);
|
| 922 |
+
Py_DECREF(descr);
|
| 923 |
+
return NULL;
|
| 924 |
+
}
|
| 925 |
+
arr = (PyArrayObject *) \
|
| 926 |
+
PyArray_NewFromDescr(&PyArray_Type, descr, rank, dims,
|
| 927 |
+
NULL, NULL, !(intent & F2PY_INTENT_C), NULL);
|
| 928 |
+
if (arr == NULL) {
|
| 929 |
+
Py_DECREF(descr);
|
| 930 |
+
return NULL;
|
| 931 |
+
}
|
| 932 |
+
if (PyArray_ITEMSIZE(arr) != elsize) {
|
| 933 |
+
strcpy(mess, "failed to create intent(cache|hide)|optional array");
|
| 934 |
+
sprintf(mess+strlen(mess)," -- expected elsize=%d got %" NPY_INTP_FMT, elsize, (npy_intp)PyArray_ITEMSIZE(arr));
|
| 935 |
+
PyErr_SetString(PyExc_ValueError,mess);
|
| 936 |
+
Py_DECREF(arr);
|
| 937 |
+
return NULL;
|
| 938 |
+
}
|
| 939 |
+
if (!(intent & F2PY_INTENT_CACHE)) {
|
| 940 |
+
PyArray_FILLWBYTE(arr, 0);
|
| 941 |
+
}
|
| 942 |
+
return arr;
|
| 943 |
+
}
|
| 944 |
+
|
| 945 |
+
if (PyArray_Check(obj)) {
|
| 946 |
+
arr = (PyArrayObject *)obj;
|
| 947 |
+
if (intent & F2PY_INTENT_CACHE) {
|
| 948 |
+
/* intent(cache) */
|
| 949 |
+
if (PyArray_ISONESEGMENT(arr)
|
| 950 |
+
&& PyArray_ITEMSIZE(arr) >= elsize) {
|
| 951 |
+
if (check_and_fix_dimensions(arr, rank, dims, errmess)) {
|
| 952 |
+
Py_DECREF(descr);
|
| 953 |
+
return NULL;
|
| 954 |
+
}
|
| 955 |
+
if (intent & F2PY_INTENT_OUT)
|
| 956 |
+
Py_INCREF(arr);
|
| 957 |
+
Py_DECREF(descr);
|
| 958 |
+
return arr;
|
| 959 |
+
}
|
| 960 |
+
strcpy(mess, "failed to initialize intent(cache) array");
|
| 961 |
+
if (!PyArray_ISONESEGMENT(arr))
|
| 962 |
+
strcat(mess, " -- input must be in one segment");
|
| 963 |
+
if (PyArray_ITEMSIZE(arr) < elsize)
|
| 964 |
+
sprintf(mess + strlen(mess),
|
| 965 |
+
" -- expected at least elsize=%d but got "
|
| 966 |
+
"%" NPY_INTP_FMT,
|
| 967 |
+
elsize, (npy_intp)PyArray_ITEMSIZE(arr));
|
| 968 |
+
PyErr_SetString(PyExc_ValueError, mess);
|
| 969 |
+
Py_DECREF(descr);
|
| 970 |
+
return NULL;
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
/* here we have always intent(in) or intent(inout) or intent(inplace)
|
| 974 |
+
*/
|
| 975 |
+
|
| 976 |
+
if (check_and_fix_dimensions(arr, rank, dims, errmess)) {
|
| 977 |
+
Py_DECREF(descr);
|
| 978 |
+
return NULL;
|
| 979 |
+
}
|
| 980 |
+
/*
|
| 981 |
+
printf("intent alignment=%d\n", F2PY_GET_ALIGNMENT(intent));
|
| 982 |
+
printf("alignment check=%d\n", F2PY_CHECK_ALIGNMENT(arr, intent));
|
| 983 |
+
int i;
|
| 984 |
+
for (i=1;i<=16;i++)
|
| 985 |
+
printf("i=%d isaligned=%d\n", i, ARRAY_ISALIGNED(arr, i));
|
| 986 |
+
*/
|
| 987 |
+
if ((! (intent & F2PY_INTENT_COPY)) &&
|
| 988 |
+
PyArray_ITEMSIZE(arr) == elsize &&
|
| 989 |
+
ARRAY_ISCOMPATIBLE(arr,type_num) &&
|
| 990 |
+
F2PY_CHECK_ALIGNMENT(arr, intent)) {
|
| 991 |
+
if ((intent & F2PY_INTENT_INOUT || intent & F2PY_INTENT_INPLACE)
|
| 992 |
+
? ((intent & F2PY_INTENT_C) ? PyArray_ISCARRAY(arr) : PyArray_ISFARRAY(arr))
|
| 993 |
+
: ((intent & F2PY_INTENT_C) ? PyArray_ISCARRAY_RO(arr) : PyArray_ISFARRAY_RO(arr))) {
|
| 994 |
+
if ((intent & F2PY_INTENT_OUT)) {
|
| 995 |
+
Py_INCREF(arr);
|
| 996 |
+
}
|
| 997 |
+
/* Returning input array */
|
| 998 |
+
Py_DECREF(descr);
|
| 999 |
+
return arr;
|
| 1000 |
+
}
|
| 1001 |
+
}
|
| 1002 |
+
if (intent & F2PY_INTENT_INOUT) {
|
| 1003 |
+
strcpy(mess, "failed to initialize intent(inout) array");
|
| 1004 |
+
/* Must use PyArray_IS*ARRAY because intent(inout) requires
|
| 1005 |
+
* writable input */
|
| 1006 |
+
if ((intent & F2PY_INTENT_C) && !PyArray_ISCARRAY(arr))
|
| 1007 |
+
strcat(mess, " -- input not contiguous");
|
| 1008 |
+
if (!(intent & F2PY_INTENT_C) && !PyArray_ISFARRAY(arr))
|
| 1009 |
+
strcat(mess, " -- input not fortran contiguous");
|
| 1010 |
+
if (PyArray_ITEMSIZE(arr) != elsize)
|
| 1011 |
+
sprintf(mess + strlen(mess),
|
| 1012 |
+
" -- expected elsize=%d but got %" NPY_INTP_FMT,
|
| 1013 |
+
elsize,
|
| 1014 |
+
(npy_intp)PyArray_ITEMSIZE(arr)
|
| 1015 |
+
);
|
| 1016 |
+
if (!(ARRAY_ISCOMPATIBLE(arr, type_num))) {
|
| 1017 |
+
sprintf(mess + strlen(mess),
|
| 1018 |
+
" -- input '%c' not compatible to '%c'",
|
| 1019 |
+
PyArray_DESCR(arr)->type, descr->type);
|
| 1020 |
+
}
|
| 1021 |
+
if (!(F2PY_CHECK_ALIGNMENT(arr, intent)))
|
| 1022 |
+
sprintf(mess + strlen(mess), " -- input not %d-aligned",
|
| 1023 |
+
F2PY_GET_ALIGNMENT(intent));
|
| 1024 |
+
PyErr_SetString(PyExc_ValueError, mess);
|
| 1025 |
+
Py_DECREF(descr);
|
| 1026 |
+
return NULL;
|
| 1027 |
+
}
|
| 1028 |
+
|
| 1029 |
+
/* here we have always intent(in) or intent(inplace) */
|
| 1030 |
+
|
| 1031 |
+
{
|
| 1032 |
+
PyArrayObject * retarr = (PyArrayObject *) \
|
| 1033 |
+
PyArray_NewFromDescr(&PyArray_Type, descr, PyArray_NDIM(arr), PyArray_DIMS(arr),
|
| 1034 |
+
NULL, NULL, !(intent & F2PY_INTENT_C), NULL);
|
| 1035 |
+
if (retarr==NULL) {
|
| 1036 |
+
Py_DECREF(descr);
|
| 1037 |
+
return NULL;
|
| 1038 |
+
}
|
| 1039 |
+
F2PY_REPORT_ON_ARRAY_COPY_FROMARR;
|
| 1040 |
+
if (PyArray_CopyInto(retarr, arr)) {
|
| 1041 |
+
Py_DECREF(retarr);
|
| 1042 |
+
return NULL;
|
| 1043 |
+
}
|
| 1044 |
+
if (intent & F2PY_INTENT_INPLACE) {
|
| 1045 |
+
if (swap_arrays(arr,retarr)) {
|
| 1046 |
+
Py_DECREF(retarr);
|
| 1047 |
+
return NULL; /* XXX: set exception */
|
| 1048 |
+
}
|
| 1049 |
+
Py_XDECREF(retarr);
|
| 1050 |
+
if (intent & F2PY_INTENT_OUT)
|
| 1051 |
+
Py_INCREF(arr);
|
| 1052 |
+
} else {
|
| 1053 |
+
arr = retarr;
|
| 1054 |
+
}
|
| 1055 |
+
}
|
| 1056 |
+
return arr;
|
| 1057 |
+
}
|
| 1058 |
+
|
| 1059 |
+
if ((intent & F2PY_INTENT_INOUT) || (intent & F2PY_INTENT_INPLACE) ||
|
| 1060 |
+
(intent & F2PY_INTENT_CACHE)) {
|
| 1061 |
+
PyErr_Format(PyExc_TypeError,
|
| 1062 |
+
"failed to initialize intent(inout|inplace|cache) "
|
| 1063 |
+
"array, input '%s' object is not an array",
|
| 1064 |
+
Py_TYPE(obj)->tp_name);
|
| 1065 |
+
Py_DECREF(descr);
|
| 1066 |
+
return NULL;
|
| 1067 |
+
}
|
| 1068 |
+
|
| 1069 |
+
{
|
| 1070 |
+
F2PY_REPORT_ON_ARRAY_COPY_FROMANY;
|
| 1071 |
+
arr = (PyArrayObject *)PyArray_FromAny(
|
| 1072 |
+
obj, descr, 0, 0,
|
| 1073 |
+
((intent & F2PY_INTENT_C) ? NPY_ARRAY_CARRAY
|
| 1074 |
+
: NPY_ARRAY_FARRAY) |
|
| 1075 |
+
NPY_ARRAY_FORCECAST,
|
| 1076 |
+
NULL);
|
| 1077 |
+
// Warning: in the case of NPY_STRING, PyArray_FromAny may
|
| 1078 |
+
// reset descr->elsize, e.g. dtype('S0') becomes dtype('S1').
|
| 1079 |
+
if (arr == NULL) {
|
| 1080 |
+
Py_DECREF(descr);
|
| 1081 |
+
return NULL;
|
| 1082 |
+
}
|
| 1083 |
+
if (type_num != NPY_STRING && PyArray_ITEMSIZE(arr) != elsize) {
|
| 1084 |
+
// This is internal sanity tests: elsize has been set to
|
| 1085 |
+
// descr->elsize in the beginning of this function.
|
| 1086 |
+
strcpy(mess, "failed to initialize intent(in) array");
|
| 1087 |
+
sprintf(mess + strlen(mess),
|
| 1088 |
+
" -- expected elsize=%d got %" NPY_INTP_FMT, elsize,
|
| 1089 |
+
(npy_intp)PyArray_ITEMSIZE(arr));
|
| 1090 |
+
PyErr_SetString(PyExc_ValueError, mess);
|
| 1091 |
+
Py_DECREF(arr);
|
| 1092 |
+
return NULL;
|
| 1093 |
+
}
|
| 1094 |
+
if (check_and_fix_dimensions(arr, rank, dims, errmess)) {
|
| 1095 |
+
Py_DECREF(arr);
|
| 1096 |
+
return NULL;
|
| 1097 |
+
}
|
| 1098 |
+
return arr;
|
| 1099 |
+
}
|
| 1100 |
+
}
|
| 1101 |
+
|
| 1102 |
+
extern PyArrayObject *
|
| 1103 |
+
array_from_pyobj(const int type_num,
|
| 1104 |
+
npy_intp *dims,
|
| 1105 |
+
const int rank,
|
| 1106 |
+
const int intent,
|
| 1107 |
+
PyObject *obj) {
|
| 1108 |
+
/*
|
| 1109 |
+
Same as ndarray_from_pyobj but with elsize determined from type,
|
| 1110 |
+
if possible. Provided for backward compatibility.
|
| 1111 |
+
*/
|
| 1112 |
+
PyArray_Descr* descr = PyArray_DescrFromType(type_num);
|
| 1113 |
+
int elsize = descr->elsize;
|
| 1114 |
+
Py_DECREF(descr);
|
| 1115 |
+
return ndarray_from_pyobj(type_num, elsize, dims, rank, intent, obj, NULL);
|
| 1116 |
+
}
|
| 1117 |
+
|
| 1118 |
+
/*****************************************/
|
| 1119 |
+
/* Helper functions for array_from_pyobj */
|
| 1120 |
+
/*****************************************/
|
| 1121 |
+
|
| 1122 |
+
static int
|
| 1123 |
+
check_and_fix_dimensions(const PyArrayObject* arr, const int rank,
|
| 1124 |
+
npy_intp *dims, const char *errmess)
|
| 1125 |
+
{
|
| 1126 |
+
/*
|
| 1127 |
+
* This function fills in blanks (that are -1's) in dims list using
|
| 1128 |
+
* the dimensions from arr. It also checks that non-blank dims will
|
| 1129 |
+
* match with the corresponding values in arr dimensions.
|
| 1130 |
+
*
|
| 1131 |
+
* Returns 0 if the function is successful.
|
| 1132 |
+
*
|
| 1133 |
+
* If an error condition is detected, an exception is set and 1 is
|
| 1134 |
+
* returned.
|
| 1135 |
+
*/
|
| 1136 |
+
char mess[F2PY_MESSAGE_BUFFER_SIZE];
|
| 1137 |
+
const npy_intp arr_size =
|
| 1138 |
+
(PyArray_NDIM(arr)) ? PyArray_Size((PyObject *)arr) : 1;
|
| 1139 |
+
#ifdef DEBUG_COPY_ND_ARRAY
|
| 1140 |
+
dump_attrs(arr);
|
| 1141 |
+
printf("check_and_fix_dimensions:init: dims=");
|
| 1142 |
+
dump_dims(rank, dims);
|
| 1143 |
+
#endif
|
| 1144 |
+
if (rank > PyArray_NDIM(arr)) { /* [1,2] -> [[1],[2]]; 1 -> [[1]] */
|
| 1145 |
+
npy_intp new_size = 1;
|
| 1146 |
+
int free_axe = -1;
|
| 1147 |
+
int i;
|
| 1148 |
+
npy_intp d;
|
| 1149 |
+
/* Fill dims where -1 or 0; check dimensions; calc new_size; */
|
| 1150 |
+
for (i = 0; i < PyArray_NDIM(arr); ++i) {
|
| 1151 |
+
d = PyArray_DIM(arr, i);
|
| 1152 |
+
if (dims[i] >= 0) {
|
| 1153 |
+
if (d > 1 && dims[i] != d) {
|
| 1154 |
+
PyErr_Format(
|
| 1155 |
+
PyExc_ValueError,
|
| 1156 |
+
"%d-th dimension must be fixed to %" NPY_INTP_FMT
|
| 1157 |
+
" but got %" NPY_INTP_FMT "\n",
|
| 1158 |
+
i, dims[i], d);
|
| 1159 |
+
return 1;
|
| 1160 |
+
}
|
| 1161 |
+
if (!dims[i])
|
| 1162 |
+
dims[i] = 1;
|
| 1163 |
+
}
|
| 1164 |
+
else {
|
| 1165 |
+
dims[i] = d ? d : 1;
|
| 1166 |
+
}
|
| 1167 |
+
new_size *= dims[i];
|
| 1168 |
+
}
|
| 1169 |
+
for (i = PyArray_NDIM(arr); i < rank; ++i)
|
| 1170 |
+
if (dims[i] > 1) {
|
| 1171 |
+
PyErr_Format(PyExc_ValueError,
|
| 1172 |
+
"%d-th dimension must be %" NPY_INTP_FMT
|
| 1173 |
+
" but got 0 (not defined).\n",
|
| 1174 |
+
i, dims[i]);
|
| 1175 |
+
return 1;
|
| 1176 |
+
}
|
| 1177 |
+
else if (free_axe < 0)
|
| 1178 |
+
free_axe = i;
|
| 1179 |
+
else
|
| 1180 |
+
dims[i] = 1;
|
| 1181 |
+
if (free_axe >= 0) {
|
| 1182 |
+
dims[free_axe] = arr_size / new_size;
|
| 1183 |
+
new_size *= dims[free_axe];
|
| 1184 |
+
}
|
| 1185 |
+
if (new_size != arr_size) {
|
| 1186 |
+
PyErr_Format(PyExc_ValueError,
|
| 1187 |
+
"unexpected array size: new_size=%" NPY_INTP_FMT
|
| 1188 |
+
", got array with arr_size=%" NPY_INTP_FMT
|
| 1189 |
+
" (maybe too many free indices)\n",
|
| 1190 |
+
new_size, arr_size);
|
| 1191 |
+
return 1;
|
| 1192 |
+
}
|
| 1193 |
+
}
|
| 1194 |
+
else if (rank == PyArray_NDIM(arr)) {
|
| 1195 |
+
npy_intp new_size = 1;
|
| 1196 |
+
int i;
|
| 1197 |
+
npy_intp d;
|
| 1198 |
+
for (i = 0; i < rank; ++i) {
|
| 1199 |
+
d = PyArray_DIM(arr, i);
|
| 1200 |
+
if (dims[i] >= 0) {
|
| 1201 |
+
if (d > 1 && d != dims[i]) {
|
| 1202 |
+
if (errmess != NULL) {
|
| 1203 |
+
strcpy(mess, errmess);
|
| 1204 |
+
}
|
| 1205 |
+
sprintf(mess + strlen(mess),
|
| 1206 |
+
" -- %d-th dimension must be fixed to %"
|
| 1207 |
+
NPY_INTP_FMT " but got %" NPY_INTP_FMT,
|
| 1208 |
+
i, dims[i], d);
|
| 1209 |
+
PyErr_SetString(PyExc_ValueError, mess);
|
| 1210 |
+
return 1;
|
| 1211 |
+
}
|
| 1212 |
+
if (!dims[i])
|
| 1213 |
+
dims[i] = 1;
|
| 1214 |
+
}
|
| 1215 |
+
else
|
| 1216 |
+
dims[i] = d;
|
| 1217 |
+
new_size *= dims[i];
|
| 1218 |
+
}
|
| 1219 |
+
if (new_size != arr_size) {
|
| 1220 |
+
PyErr_Format(PyExc_ValueError,
|
| 1221 |
+
"unexpected array size: new_size=%" NPY_INTP_FMT
|
| 1222 |
+
", got array with arr_size=%" NPY_INTP_FMT "\n",
|
| 1223 |
+
new_size, arr_size);
|
| 1224 |
+
return 1;
|
| 1225 |
+
}
|
| 1226 |
+
}
|
| 1227 |
+
else { /* [[1,2]] -> [[1],[2]] */
|
| 1228 |
+
int i, j;
|
| 1229 |
+
npy_intp d;
|
| 1230 |
+
int effrank;
|
| 1231 |
+
npy_intp size;
|
| 1232 |
+
for (i = 0, effrank = 0; i < PyArray_NDIM(arr); ++i)
|
| 1233 |
+
if (PyArray_DIM(arr, i) > 1)
|
| 1234 |
+
++effrank;
|
| 1235 |
+
if (dims[rank - 1] >= 0)
|
| 1236 |
+
if (effrank > rank) {
|
| 1237 |
+
PyErr_Format(PyExc_ValueError,
|
| 1238 |
+
"too many axes: %d (effrank=%d), "
|
| 1239 |
+
"expected rank=%d\n",
|
| 1240 |
+
PyArray_NDIM(arr), effrank, rank);
|
| 1241 |
+
return 1;
|
| 1242 |
+
}
|
| 1243 |
+
|
| 1244 |
+
for (i = 0, j = 0; i < rank; ++i) {
|
| 1245 |
+
while (j < PyArray_NDIM(arr) && PyArray_DIM(arr, j) < 2) ++j;
|
| 1246 |
+
if (j >= PyArray_NDIM(arr))
|
| 1247 |
+
d = 1;
|
| 1248 |
+
else
|
| 1249 |
+
d = PyArray_DIM(arr, j++);
|
| 1250 |
+
if (dims[i] >= 0) {
|
| 1251 |
+
if (d > 1 && d != dims[i]) {
|
| 1252 |
+
if (errmess != NULL) {
|
| 1253 |
+
strcpy(mess, errmess);
|
| 1254 |
+
}
|
| 1255 |
+
sprintf(mess + strlen(mess),
|
| 1256 |
+
" -- %d-th dimension must be fixed to %"
|
| 1257 |
+
NPY_INTP_FMT " but got %" NPY_INTP_FMT
|
| 1258 |
+
" (real index=%d)\n",
|
| 1259 |
+
i, dims[i], d, j-1);
|
| 1260 |
+
PyErr_SetString(PyExc_ValueError, mess);
|
| 1261 |
+
return 1;
|
| 1262 |
+
}
|
| 1263 |
+
if (!dims[i])
|
| 1264 |
+
dims[i] = 1;
|
| 1265 |
+
}
|
| 1266 |
+
else
|
| 1267 |
+
dims[i] = d;
|
| 1268 |
+
}
|
| 1269 |
+
|
| 1270 |
+
for (i = rank; i < PyArray_NDIM(arr);
|
| 1271 |
+
++i) { /* [[1,2],[3,4]] -> [1,2,3,4] */
|
| 1272 |
+
while (j < PyArray_NDIM(arr) && PyArray_DIM(arr, j) < 2) ++j;
|
| 1273 |
+
if (j >= PyArray_NDIM(arr))
|
| 1274 |
+
d = 1;
|
| 1275 |
+
else
|
| 1276 |
+
d = PyArray_DIM(arr, j++);
|
| 1277 |
+
dims[rank - 1] *= d;
|
| 1278 |
+
}
|
| 1279 |
+
for (i = 0, size = 1; i < rank; ++i) size *= dims[i];
|
| 1280 |
+
if (size != arr_size) {
|
| 1281 |
+
char msg[200];
|
| 1282 |
+
int len;
|
| 1283 |
+
snprintf(msg, sizeof(msg),
|
| 1284 |
+
"unexpected array size: size=%" NPY_INTP_FMT
|
| 1285 |
+
", arr_size=%" NPY_INTP_FMT
|
| 1286 |
+
", rank=%d, effrank=%d, arr.nd=%d, dims=[",
|
| 1287 |
+
size, arr_size, rank, effrank, PyArray_NDIM(arr));
|
| 1288 |
+
for (i = 0; i < rank; ++i) {
|
| 1289 |
+
len = strlen(msg);
|
| 1290 |
+
snprintf(msg + len, sizeof(msg) - len, " %" NPY_INTP_FMT,
|
| 1291 |
+
dims[i]);
|
| 1292 |
+
}
|
| 1293 |
+
len = strlen(msg);
|
| 1294 |
+
snprintf(msg + len, sizeof(msg) - len, " ], arr.dims=[");
|
| 1295 |
+
for (i = 0; i < PyArray_NDIM(arr); ++i) {
|
| 1296 |
+
len = strlen(msg);
|
| 1297 |
+
snprintf(msg + len, sizeof(msg) - len, " %" NPY_INTP_FMT,
|
| 1298 |
+
PyArray_DIM(arr, i));
|
| 1299 |
+
}
|
| 1300 |
+
len = strlen(msg);
|
| 1301 |
+
snprintf(msg + len, sizeof(msg) - len, " ]\n");
|
| 1302 |
+
PyErr_SetString(PyExc_ValueError, msg);
|
| 1303 |
+
return 1;
|
| 1304 |
+
}
|
| 1305 |
+
}
|
| 1306 |
+
#ifdef DEBUG_COPY_ND_ARRAY
|
| 1307 |
+
printf("check_and_fix_dimensions:end: dims=");
|
| 1308 |
+
dump_dims(rank, dims);
|
| 1309 |
+
#endif
|
| 1310 |
+
return 0;
|
| 1311 |
+
}
|
| 1312 |
+
|
| 1313 |
+
/* End of file: array_from_pyobj.c */
|
| 1314 |
+
|
| 1315 |
+
/************************* copy_ND_array *******************************/
|
| 1316 |
+
|
| 1317 |
+
extern int
|
| 1318 |
+
copy_ND_array(const PyArrayObject *arr, PyArrayObject *out)
|
| 1319 |
+
{
|
| 1320 |
+
F2PY_REPORT_ON_ARRAY_COPY_FROMARR;
|
| 1321 |
+
return PyArray_CopyInto(out, (PyArrayObject *)arr);
|
| 1322 |
+
}
|
| 1323 |
+
|
| 1324 |
+
/********************* Various utility functions ***********************/
|
| 1325 |
+
|
| 1326 |
+
extern int
|
| 1327 |
+
f2py_describe(PyObject *obj, char *buf) {
|
| 1328 |
+
/*
|
| 1329 |
+
Write the description of a Python object to buf. The caller must
|
| 1330 |
+
provide buffer with size sufficient to write the description.
|
| 1331 |
+
|
| 1332 |
+
Return 1 on success.
|
| 1333 |
+
*/
|
| 1334 |
+
char localbuf[F2PY_MESSAGE_BUFFER_SIZE];
|
| 1335 |
+
if (PyBytes_Check(obj)) {
|
| 1336 |
+
sprintf(localbuf, "%d-%s", (npy_int)PyBytes_GET_SIZE(obj), Py_TYPE(obj)->tp_name);
|
| 1337 |
+
} else if (PyUnicode_Check(obj)) {
|
| 1338 |
+
sprintf(localbuf, "%d-%s", (npy_int)PyUnicode_GET_LENGTH(obj), Py_TYPE(obj)->tp_name);
|
| 1339 |
+
} else if (PyArray_CheckScalar(obj)) {
|
| 1340 |
+
PyArrayObject* arr = (PyArrayObject*)obj;
|
| 1341 |
+
sprintf(localbuf, "%c%" NPY_INTP_FMT "-%s-scalar", PyArray_DESCR(arr)->kind, PyArray_ITEMSIZE(arr), Py_TYPE(obj)->tp_name);
|
| 1342 |
+
} else if (PyArray_Check(obj)) {
|
| 1343 |
+
int i;
|
| 1344 |
+
PyArrayObject* arr = (PyArrayObject*)obj;
|
| 1345 |
+
strcpy(localbuf, "(");
|
| 1346 |
+
for (i=0; i<PyArray_NDIM(arr); i++) {
|
| 1347 |
+
if (i) {
|
| 1348 |
+
strcat(localbuf, " ");
|
| 1349 |
+
}
|
| 1350 |
+
sprintf(localbuf + strlen(localbuf), "%" NPY_INTP_FMT ",", PyArray_DIM(arr, i));
|
| 1351 |
+
}
|
| 1352 |
+
sprintf(localbuf + strlen(localbuf), ")-%c%" NPY_INTP_FMT "-%s", PyArray_DESCR(arr)->kind, PyArray_ITEMSIZE(arr), Py_TYPE(obj)->tp_name);
|
| 1353 |
+
} else if (PySequence_Check(obj)) {
|
| 1354 |
+
sprintf(localbuf, "%d-%s", (npy_int)PySequence_Length(obj), Py_TYPE(obj)->tp_name);
|
| 1355 |
+
} else {
|
| 1356 |
+
sprintf(localbuf, "%s instance", Py_TYPE(obj)->tp_name);
|
| 1357 |
+
}
|
| 1358 |
+
// TODO: detect the size of buf and make sure that size(buf) >= size(localbuf).
|
| 1359 |
+
strcpy(buf, localbuf);
|
| 1360 |
+
return 1;
|
| 1361 |
+
}
|
| 1362 |
+
|
| 1363 |
+
extern npy_intp
|
| 1364 |
+
f2py_size_impl(PyArrayObject* var, ...)
|
| 1365 |
+
{
|
| 1366 |
+
npy_intp sz = 0;
|
| 1367 |
+
npy_intp dim;
|
| 1368 |
+
npy_intp rank;
|
| 1369 |
+
va_list argp;
|
| 1370 |
+
va_start(argp, var);
|
| 1371 |
+
dim = va_arg(argp, npy_int);
|
| 1372 |
+
if (dim==-1)
|
| 1373 |
+
{
|
| 1374 |
+
sz = PyArray_SIZE(var);
|
| 1375 |
+
}
|
| 1376 |
+
else
|
| 1377 |
+
{
|
| 1378 |
+
rank = PyArray_NDIM(var);
|
| 1379 |
+
if (dim>=1 && dim<=rank)
|
| 1380 |
+
sz = PyArray_DIM(var, dim-1);
|
| 1381 |
+
else
|
| 1382 |
+
fprintf(stderr, "f2py_size: 2nd argument value=%" NPY_INTP_FMT
|
| 1383 |
+
" fails to satisfy 1<=value<=%" NPY_INTP_FMT
|
| 1384 |
+
". Result will be 0.\n", dim, rank);
|
| 1385 |
+
}
|
| 1386 |
+
va_end(argp);
|
| 1387 |
+
return sz;
|
| 1388 |
+
}
|
| 1389 |
+
|
| 1390 |
+
/*********************************************/
|
| 1391 |
+
/* Compatibility functions for Python >= 3.0 */
|
| 1392 |
+
/*********************************************/
|
| 1393 |
+
|
| 1394 |
+
PyObject *
|
| 1395 |
+
F2PyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *))
|
| 1396 |
+
{
|
| 1397 |
+
PyObject *ret = PyCapsule_New(ptr, NULL, dtor);
|
| 1398 |
+
if (ret == NULL) {
|
| 1399 |
+
PyErr_Clear();
|
| 1400 |
+
}
|
| 1401 |
+
return ret;
|
| 1402 |
+
}
|
| 1403 |
+
|
| 1404 |
+
void *
|
| 1405 |
+
F2PyCapsule_AsVoidPtr(PyObject *obj)
|
| 1406 |
+
{
|
| 1407 |
+
void *ret = PyCapsule_GetPointer(obj, NULL);
|
| 1408 |
+
if (ret == NULL) {
|
| 1409 |
+
PyErr_Clear();
|
| 1410 |
+
}
|
| 1411 |
+
return ret;
|
| 1412 |
+
}
|
| 1413 |
+
|
| 1414 |
+
int
|
| 1415 |
+
F2PyCapsule_Check(PyObject *ptr)
|
| 1416 |
+
{
|
| 1417 |
+
return PyCapsule_CheckExact(ptr);
|
| 1418 |
+
}
|
| 1419 |
+
|
| 1420 |
+
#ifdef __cplusplus
|
| 1421 |
+
}
|
| 1422 |
+
#endif
|
| 1423 |
+
/************************* EOF fortranobject.c *******************************/
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/src/fortranobject.h
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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plusplus
|
| 4 |
+
extern "C" {
|
| 5 |
+
#endif
|
| 6 |
+
|
| 7 |
+
#include <Python.h>
|
| 8 |
+
|
| 9 |
+
#ifndef NPY_NO_DEPRECATED_API
|
| 10 |
+
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
|
| 11 |
+
#endif
|
| 12 |
+
#ifdef FORTRANOBJECT_C
|
| 13 |
+
#define NO_IMPORT_ARRAY
|
| 14 |
+
#endif
|
| 15 |
+
#define PY_ARRAY_UNIQUE_SYMBOL _npy_f2py_ARRAY_API
|
| 16 |
+
#include "numpy/arrayobject.h"
|
| 17 |
+
#include "numpy/npy_3kcompat.h"
|
| 18 |
+
|
| 19 |
+
#ifdef F2PY_REPORT_ATEXIT
|
| 20 |
+
#include <sys/timeb.h>
|
| 21 |
+
// clang-format off
|
| 22 |
+
extern void f2py_start_clock(void);
|
| 23 |
+
extern void f2py_stop_clock(void);
|
| 24 |
+
extern void f2py_start_call_clock(void);
|
| 25 |
+
extern void f2py_stop_call_clock(void);
|
| 26 |
+
extern void f2py_cb_start_clock(void);
|
| 27 |
+
extern void f2py_cb_stop_clock(void);
|
| 28 |
+
extern void f2py_cb_start_call_clock(void);
|
| 29 |
+
extern void f2py_cb_stop_call_clock(void);
|
| 30 |
+
extern void f2py_report_on_exit(int, void *);
|
| 31 |
+
// clang-format on
|
| 32 |
+
#endif
|
| 33 |
+
|
| 34 |
+
#ifdef DMALLOC
|
| 35 |
+
#include "dmalloc.h"
|
| 36 |
+
#endif
|
| 37 |
+
|
| 38 |
+
/* Fortran object interface */
|
| 39 |
+
|
| 40 |
+
/*
|
| 41 |
+
123456789-123456789-123456789-123456789-123456789-123456789-123456789-12
|
| 42 |
+
|
| 43 |
+
PyFortranObject represents various Fortran objects:
|
| 44 |
+
Fortran (module) routines, COMMON blocks, module data.
|
| 45 |
+
|
| 46 |
+
Author: Pearu Peterson <pearu@cens.ioc.ee>
|
| 47 |
+
*/
|
| 48 |
+
|
| 49 |
+
#define F2PY_MAX_DIMS 40
|
| 50 |
+
#define F2PY_MESSAGE_BUFFER_SIZE 300 // Increase on "stack smashing detected"
|
| 51 |
+
|
| 52 |
+
typedef void (*f2py_set_data_func)(char *, npy_intp *);
|
| 53 |
+
typedef void (*f2py_void_func)(void);
|
| 54 |
+
typedef void (*f2py_init_func)(int *, npy_intp *, f2py_set_data_func, int *);
|
| 55 |
+
|
| 56 |
+
/*typedef void* (*f2py_c_func)(void*,...);*/
|
| 57 |
+
|
| 58 |
+
typedef void *(*f2pycfunc)(void);
|
| 59 |
+
|
| 60 |
+
typedef struct {
|
| 61 |
+
char *name; /* attribute (array||routine) name */
|
| 62 |
+
int rank; /* array rank, 0 for scalar, max is F2PY_MAX_DIMS,
|
| 63 |
+
|| rank=-1 for Fortran routine */
|
| 64 |
+
struct {
|
| 65 |
+
npy_intp d[F2PY_MAX_DIMS];
|
| 66 |
+
} dims; /* dimensions of the array, || not used */
|
| 67 |
+
int type; /* PyArray_<type> || not used */
|
| 68 |
+
int elsize; /* Element size || not used */
|
| 69 |
+
char *data; /* pointer to array || Fortran routine */
|
| 70 |
+
f2py_init_func func; /* initialization function for
|
| 71 |
+
allocatable arrays:
|
| 72 |
+
func(&rank,dims,set_ptr_func,name,len(name))
|
| 73 |
+
|| C/API wrapper for Fortran routine */
|
| 74 |
+
char *doc; /* documentation string; only recommended
|
| 75 |
+
for routines. */
|
| 76 |
+
} FortranDataDef;
|
| 77 |
+
|
| 78 |
+
typedef struct {
|
| 79 |
+
PyObject_HEAD
|
| 80 |
+
int len; /* Number of attributes */
|
| 81 |
+
FortranDataDef *defs; /* An array of FortranDataDef's */
|
| 82 |
+
PyObject *dict; /* Fortran object attribute dictionary */
|
| 83 |
+
} PyFortranObject;
|
| 84 |
+
|
| 85 |
+
#define PyFortran_Check(op) (Py_TYPE(op) == &PyFortran_Type)
|
| 86 |
+
#define PyFortran_Check1(op) (0 == strcmp(Py_TYPE(op)->tp_name, "fortran"))
|
| 87 |
+
|
| 88 |
+
extern PyTypeObject PyFortran_Type;
|
| 89 |
+
extern int
|
| 90 |
+
F2PyDict_SetItemString(PyObject *dict, char *name, PyObject *obj);
|
| 91 |
+
extern PyObject *
|
| 92 |
+
PyFortranObject_New(FortranDataDef *defs, f2py_void_func init);
|
| 93 |
+
extern PyObject *
|
| 94 |
+
PyFortranObject_NewAsAttr(FortranDataDef *defs);
|
| 95 |
+
|
| 96 |
+
PyObject *
|
| 97 |
+
F2PyCapsule_FromVoidPtr(void *ptr, void (*dtor)(PyObject *));
|
| 98 |
+
void *
|
| 99 |
+
F2PyCapsule_AsVoidPtr(PyObject *obj);
|
| 100 |
+
int
|
| 101 |
+
F2PyCapsule_Check(PyObject *ptr);
|
| 102 |
+
|
| 103 |
+
extern void *
|
| 104 |
+
F2PySwapThreadLocalCallbackPtr(char *key, void *ptr);
|
| 105 |
+
extern void *
|
| 106 |
+
F2PyGetThreadLocalCallbackPtr(char *key);
|
| 107 |
+
|
| 108 |
+
#define ISCONTIGUOUS(m) (PyArray_FLAGS(m) & NPY_ARRAY_C_CONTIGUOUS)
|
| 109 |
+
#define F2PY_INTENT_IN 1
|
| 110 |
+
#define F2PY_INTENT_INOUT 2
|
| 111 |
+
#define F2PY_INTENT_OUT 4
|
| 112 |
+
#define F2PY_INTENT_HIDE 8
|
| 113 |
+
#define F2PY_INTENT_CACHE 16
|
| 114 |
+
#define F2PY_INTENT_COPY 32
|
| 115 |
+
#define F2PY_INTENT_C 64
|
| 116 |
+
#define F2PY_OPTIONAL 128
|
| 117 |
+
#define F2PY_INTENT_INPLACE 256
|
| 118 |
+
#define F2PY_INTENT_ALIGNED4 512
|
| 119 |
+
#define F2PY_INTENT_ALIGNED8 1024
|
| 120 |
+
#define F2PY_INTENT_ALIGNED16 2048
|
| 121 |
+
|
| 122 |
+
#define ARRAY_ISALIGNED(ARR, SIZE) ((size_t)(PyArray_DATA(ARR)) % (SIZE) == 0)
|
| 123 |
+
#define F2PY_ALIGN4(intent) (intent & F2PY_INTENT_ALIGNED4)
|
| 124 |
+
#define F2PY_ALIGN8(intent) (intent & F2PY_INTENT_ALIGNED8)
|
| 125 |
+
#define F2PY_ALIGN16(intent) (intent & F2PY_INTENT_ALIGNED16)
|
| 126 |
+
|
| 127 |
+
#define F2PY_GET_ALIGNMENT(intent) \
|
| 128 |
+
(F2PY_ALIGN4(intent) \
|
| 129 |
+
? 4 \
|
| 130 |
+
: (F2PY_ALIGN8(intent) ? 8 : (F2PY_ALIGN16(intent) ? 16 : 1)))
|
| 131 |
+
#define F2PY_CHECK_ALIGNMENT(arr, intent) \
|
| 132 |
+
ARRAY_ISALIGNED(arr, F2PY_GET_ALIGNMENT(intent))
|
| 133 |
+
#define F2PY_ARRAY_IS_CHARACTER_COMPATIBLE(arr) ((PyArray_DESCR(arr)->type_num == NPY_STRING && PyArray_DESCR(arr)->elsize >= 1) \
|
| 134 |
+
|| PyArray_DESCR(arr)->type_num == NPY_UINT8)
|
| 135 |
+
#define F2PY_IS_UNICODE_ARRAY(arr) (PyArray_DESCR(arr)->type_num == NPY_UNICODE)
|
| 136 |
+
|
| 137 |
+
extern PyArrayObject *
|
| 138 |
+
ndarray_from_pyobj(const int type_num, const int elsize_, npy_intp *dims,
|
| 139 |
+
const int rank, const int intent, PyObject *obj,
|
| 140 |
+
const char *errmess);
|
| 141 |
+
|
| 142 |
+
extern PyArrayObject *
|
| 143 |
+
array_from_pyobj(const int type_num, npy_intp *dims, const int rank,
|
| 144 |
+
const int intent, PyObject *obj);
|
| 145 |
+
extern int
|
| 146 |
+
copy_ND_array(const PyArrayObject *in, PyArrayObject *out);
|
| 147 |
+
|
| 148 |
+
#ifdef DEBUG_COPY_ND_ARRAY
|
| 149 |
+
extern void
|
| 150 |
+
dump_attrs(const PyArrayObject *arr);
|
| 151 |
+
#endif
|
| 152 |
+
|
| 153 |
+
extern int f2py_describe(PyObject *obj, char *buf);
|
| 154 |
+
|
| 155 |
+
/* Utility CPP macros and functions that can be used in signature file
|
| 156 |
+
expressions. See signature-file.rst for documentation.
|
| 157 |
+
*/
|
| 158 |
+
|
| 159 |
+
#define f2py_itemsize(var) (PyArray_DESCR((capi_ ## var ## _as_array))->elsize)
|
| 160 |
+
#define f2py_size(var, ...) f2py_size_impl((PyArrayObject *)(capi_ ## var ## _as_array), ## __VA_ARGS__, -1)
|
| 161 |
+
#define f2py_rank(var) var ## _Rank
|
| 162 |
+
#define f2py_shape(var,dim) var ## _Dims[dim]
|
| 163 |
+
#define f2py_len(var) f2py_shape(var,0)
|
| 164 |
+
#define f2py_fshape(var,dim) f2py_shape(var,rank(var)-dim-1)
|
| 165 |
+
#define f2py_flen(var) f2py_fshape(var,0)
|
| 166 |
+
#define f2py_slen(var) capi_ ## var ## _len
|
| 167 |
+
|
| 168 |
+
extern npy_intp f2py_size_impl(PyArrayObject* var, ...);
|
| 169 |
+
|
| 170 |
+
#ifdef __cplusplus
|
| 171 |
+
}
|
| 172 |
+
#endif
|
| 173 |
+
#endif /* !Py_FORTRANOBJECT_H */
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/tests/__pycache__/test_abstract_interface.cpython-312.pyc
ADDED
|
Binary file (1.95 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/tests/__pycache__/test_return_complex.cpython-312.pyc
ADDED
|
Binary file (4.81 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/f2py/tests/__pycache__/test_value_attrspec.cpython-312.pyc
ADDED
|
Binary file (994 Bytes). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/fft/_pocketfft.py
ADDED
|
@@ -0,0 +1,1424 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Discrete Fourier Transforms
|
| 3 |
+
|
| 4 |
+
Routines in this module:
|
| 5 |
+
|
| 6 |
+
fft(a, n=None, axis=-1, norm="backward")
|
| 7 |
+
ifft(a, n=None, axis=-1, norm="backward")
|
| 8 |
+
rfft(a, n=None, axis=-1, norm="backward")
|
| 9 |
+
irfft(a, n=None, axis=-1, norm="backward")
|
| 10 |
+
hfft(a, n=None, axis=-1, norm="backward")
|
| 11 |
+
ihfft(a, n=None, axis=-1, norm="backward")
|
| 12 |
+
fftn(a, s=None, axes=None, norm="backward")
|
| 13 |
+
ifftn(a, s=None, axes=None, norm="backward")
|
| 14 |
+
rfftn(a, s=None, axes=None, norm="backward")
|
| 15 |
+
irfftn(a, s=None, axes=None, norm="backward")
|
| 16 |
+
fft2(a, s=None, axes=(-2,-1), norm="backward")
|
| 17 |
+
ifft2(a, s=None, axes=(-2, -1), norm="backward")
|
| 18 |
+
rfft2(a, s=None, axes=(-2,-1), norm="backward")
|
| 19 |
+
irfft2(a, s=None, axes=(-2, -1), norm="backward")
|
| 20 |
+
|
| 21 |
+
i = inverse transform
|
| 22 |
+
r = transform of purely real data
|
| 23 |
+
h = Hermite transform
|
| 24 |
+
n = n-dimensional transform
|
| 25 |
+
2 = 2-dimensional transform
|
| 26 |
+
(Note: 2D routines are just nD routines with different default
|
| 27 |
+
behavior.)
|
| 28 |
+
|
| 29 |
+
"""
|
| 30 |
+
__all__ = ['fft', 'ifft', 'rfft', 'irfft', 'hfft', 'ihfft', 'rfftn',
|
| 31 |
+
'irfftn', 'rfft2', 'irfft2', 'fft2', 'ifft2', 'fftn', 'ifftn']
|
| 32 |
+
|
| 33 |
+
import functools
|
| 34 |
+
|
| 35 |
+
from numpy.core import asarray, zeros, swapaxes, conjugate, take, sqrt
|
| 36 |
+
from . import _pocketfft_internal as pfi
|
| 37 |
+
from numpy.core.multiarray import normalize_axis_index
|
| 38 |
+
from numpy.core import overrides
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
array_function_dispatch = functools.partial(
|
| 42 |
+
overrides.array_function_dispatch, module='numpy.fft')
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# `inv_norm` is a float by which the result of the transform needs to be
|
| 46 |
+
# divided. This replaces the original, more intuitive 'fct` parameter to avoid
|
| 47 |
+
# divisions by zero (or alternatively additional checks) in the case of
|
| 48 |
+
# zero-length axes during its computation.
|
| 49 |
+
def _raw_fft(a, n, axis, is_real, is_forward, inv_norm):
|
| 50 |
+
axis = normalize_axis_index(axis, a.ndim)
|
| 51 |
+
if n is None:
|
| 52 |
+
n = a.shape[axis]
|
| 53 |
+
|
| 54 |
+
fct = 1/inv_norm
|
| 55 |
+
|
| 56 |
+
if a.shape[axis] != n:
|
| 57 |
+
s = list(a.shape)
|
| 58 |
+
index = [slice(None)]*len(s)
|
| 59 |
+
if s[axis] > n:
|
| 60 |
+
index[axis] = slice(0, n)
|
| 61 |
+
a = a[tuple(index)]
|
| 62 |
+
else:
|
| 63 |
+
index[axis] = slice(0, s[axis])
|
| 64 |
+
s[axis] = n
|
| 65 |
+
z = zeros(s, a.dtype.char)
|
| 66 |
+
z[tuple(index)] = a
|
| 67 |
+
a = z
|
| 68 |
+
|
| 69 |
+
if axis == a.ndim-1:
|
| 70 |
+
r = pfi.execute(a, is_real, is_forward, fct)
|
| 71 |
+
else:
|
| 72 |
+
a = swapaxes(a, axis, -1)
|
| 73 |
+
r = pfi.execute(a, is_real, is_forward, fct)
|
| 74 |
+
r = swapaxes(r, axis, -1)
|
| 75 |
+
return r
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def _get_forward_norm(n, norm):
|
| 79 |
+
if n < 1:
|
| 80 |
+
raise ValueError(f"Invalid number of FFT data points ({n}) specified.")
|
| 81 |
+
|
| 82 |
+
if norm is None or norm == "backward":
|
| 83 |
+
return 1
|
| 84 |
+
elif norm == "ortho":
|
| 85 |
+
return sqrt(n)
|
| 86 |
+
elif norm == "forward":
|
| 87 |
+
return n
|
| 88 |
+
raise ValueError(f'Invalid norm value {norm}; should be "backward",'
|
| 89 |
+
'"ortho" or "forward".')
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def _get_backward_norm(n, norm):
|
| 93 |
+
if n < 1:
|
| 94 |
+
raise ValueError(f"Invalid number of FFT data points ({n}) specified.")
|
| 95 |
+
|
| 96 |
+
if norm is None or norm == "backward":
|
| 97 |
+
return n
|
| 98 |
+
elif norm == "ortho":
|
| 99 |
+
return sqrt(n)
|
| 100 |
+
elif norm == "forward":
|
| 101 |
+
return 1
|
| 102 |
+
raise ValueError(f'Invalid norm value {norm}; should be "backward", '
|
| 103 |
+
'"ortho" or "forward".')
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
_SWAP_DIRECTION_MAP = {"backward": "forward", None: "forward",
|
| 107 |
+
"ortho": "ortho", "forward": "backward"}
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def _swap_direction(norm):
|
| 111 |
+
try:
|
| 112 |
+
return _SWAP_DIRECTION_MAP[norm]
|
| 113 |
+
except KeyError:
|
| 114 |
+
raise ValueError(f'Invalid norm value {norm}; should be "backward", '
|
| 115 |
+
'"ortho" or "forward".') from None
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def _fft_dispatcher(a, n=None, axis=None, norm=None):
|
| 119 |
+
return (a,)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@array_function_dispatch(_fft_dispatcher)
|
| 123 |
+
def fft(a, n=None, axis=-1, norm=None):
|
| 124 |
+
"""
|
| 125 |
+
Compute the one-dimensional discrete Fourier Transform.
|
| 126 |
+
|
| 127 |
+
This function computes the one-dimensional *n*-point discrete Fourier
|
| 128 |
+
Transform (DFT) with the efficient Fast Fourier Transform (FFT)
|
| 129 |
+
algorithm [CT].
|
| 130 |
+
|
| 131 |
+
Parameters
|
| 132 |
+
----------
|
| 133 |
+
a : array_like
|
| 134 |
+
Input array, can be complex.
|
| 135 |
+
n : int, optional
|
| 136 |
+
Length of the transformed axis of the output.
|
| 137 |
+
If `n` is smaller than the length of the input, the input is cropped.
|
| 138 |
+
If it is larger, the input is padded with zeros. If `n` is not given,
|
| 139 |
+
the length of the input along the axis specified by `axis` is used.
|
| 140 |
+
axis : int, optional
|
| 141 |
+
Axis over which to compute the FFT. If not given, the last axis is
|
| 142 |
+
used.
|
| 143 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 144 |
+
.. versionadded:: 1.10.0
|
| 145 |
+
|
| 146 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 147 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 148 |
+
is scaled and with what normalization factor.
|
| 149 |
+
|
| 150 |
+
.. versionadded:: 1.20.0
|
| 151 |
+
|
| 152 |
+
The "backward", "forward" values were added.
|
| 153 |
+
|
| 154 |
+
Returns
|
| 155 |
+
-------
|
| 156 |
+
out : complex ndarray
|
| 157 |
+
The truncated or zero-padded input, transformed along the axis
|
| 158 |
+
indicated by `axis`, or the last one if `axis` is not specified.
|
| 159 |
+
|
| 160 |
+
Raises
|
| 161 |
+
------
|
| 162 |
+
IndexError
|
| 163 |
+
If `axis` is not a valid axis of `a`.
|
| 164 |
+
|
| 165 |
+
See Also
|
| 166 |
+
--------
|
| 167 |
+
numpy.fft : for definition of the DFT and conventions used.
|
| 168 |
+
ifft : The inverse of `fft`.
|
| 169 |
+
fft2 : The two-dimensional FFT.
|
| 170 |
+
fftn : The *n*-dimensional FFT.
|
| 171 |
+
rfftn : The *n*-dimensional FFT of real input.
|
| 172 |
+
fftfreq : Frequency bins for given FFT parameters.
|
| 173 |
+
|
| 174 |
+
Notes
|
| 175 |
+
-----
|
| 176 |
+
FFT (Fast Fourier Transform) refers to a way the discrete Fourier
|
| 177 |
+
Transform (DFT) can be calculated efficiently, by using symmetries in the
|
| 178 |
+
calculated terms. The symmetry is highest when `n` is a power of 2, and
|
| 179 |
+
the transform is therefore most efficient for these sizes.
|
| 180 |
+
|
| 181 |
+
The DFT is defined, with the conventions used in this implementation, in
|
| 182 |
+
the documentation for the `numpy.fft` module.
|
| 183 |
+
|
| 184 |
+
References
|
| 185 |
+
----------
|
| 186 |
+
.. [CT] Cooley, James W., and John W. Tukey, 1965, "An algorithm for the
|
| 187 |
+
machine calculation of complex Fourier series," *Math. Comput.*
|
| 188 |
+
19: 297-301.
|
| 189 |
+
|
| 190 |
+
Examples
|
| 191 |
+
--------
|
| 192 |
+
>>> np.fft.fft(np.exp(2j * np.pi * np.arange(8) / 8))
|
| 193 |
+
array([-2.33486982e-16+1.14423775e-17j, 8.00000000e+00-1.25557246e-15j,
|
| 194 |
+
2.33486982e-16+2.33486982e-16j, 0.00000000e+00+1.22464680e-16j,
|
| 195 |
+
-1.14423775e-17+2.33486982e-16j, 0.00000000e+00+5.20784380e-16j,
|
| 196 |
+
1.14423775e-17+1.14423775e-17j, 0.00000000e+00+1.22464680e-16j])
|
| 197 |
+
|
| 198 |
+
In this example, real input has an FFT which is Hermitian, i.e., symmetric
|
| 199 |
+
in the real part and anti-symmetric in the imaginary part, as described in
|
| 200 |
+
the `numpy.fft` documentation:
|
| 201 |
+
|
| 202 |
+
>>> import matplotlib.pyplot as plt
|
| 203 |
+
>>> t = np.arange(256)
|
| 204 |
+
>>> sp = np.fft.fft(np.sin(t))
|
| 205 |
+
>>> freq = np.fft.fftfreq(t.shape[-1])
|
| 206 |
+
>>> plt.plot(freq, sp.real, freq, sp.imag)
|
| 207 |
+
[<matplotlib.lines.Line2D object at 0x...>, <matplotlib.lines.Line2D object at 0x...>]
|
| 208 |
+
>>> plt.show()
|
| 209 |
+
|
| 210 |
+
"""
|
| 211 |
+
a = asarray(a)
|
| 212 |
+
if n is None:
|
| 213 |
+
n = a.shape[axis]
|
| 214 |
+
inv_norm = _get_forward_norm(n, norm)
|
| 215 |
+
output = _raw_fft(a, n, axis, False, True, inv_norm)
|
| 216 |
+
return output
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
@array_function_dispatch(_fft_dispatcher)
|
| 220 |
+
def ifft(a, n=None, axis=-1, norm=None):
|
| 221 |
+
"""
|
| 222 |
+
Compute the one-dimensional inverse discrete Fourier Transform.
|
| 223 |
+
|
| 224 |
+
This function computes the inverse of the one-dimensional *n*-point
|
| 225 |
+
discrete Fourier transform computed by `fft`. In other words,
|
| 226 |
+
``ifft(fft(a)) == a`` to within numerical accuracy.
|
| 227 |
+
For a general description of the algorithm and definitions,
|
| 228 |
+
see `numpy.fft`.
|
| 229 |
+
|
| 230 |
+
The input should be ordered in the same way as is returned by `fft`,
|
| 231 |
+
i.e.,
|
| 232 |
+
|
| 233 |
+
* ``a[0]`` should contain the zero frequency term,
|
| 234 |
+
* ``a[1:n//2]`` should contain the positive-frequency terms,
|
| 235 |
+
* ``a[n//2 + 1:]`` should contain the negative-frequency terms, in
|
| 236 |
+
increasing order starting from the most negative frequency.
|
| 237 |
+
|
| 238 |
+
For an even number of input points, ``A[n//2]`` represents the sum of
|
| 239 |
+
the values at the positive and negative Nyquist frequencies, as the two
|
| 240 |
+
are aliased together. See `numpy.fft` for details.
|
| 241 |
+
|
| 242 |
+
Parameters
|
| 243 |
+
----------
|
| 244 |
+
a : array_like
|
| 245 |
+
Input array, can be complex.
|
| 246 |
+
n : int, optional
|
| 247 |
+
Length of the transformed axis of the output.
|
| 248 |
+
If `n` is smaller than the length of the input, the input is cropped.
|
| 249 |
+
If it is larger, the input is padded with zeros. If `n` is not given,
|
| 250 |
+
the length of the input along the axis specified by `axis` is used.
|
| 251 |
+
See notes about padding issues.
|
| 252 |
+
axis : int, optional
|
| 253 |
+
Axis over which to compute the inverse DFT. If not given, the last
|
| 254 |
+
axis is used.
|
| 255 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 256 |
+
.. versionadded:: 1.10.0
|
| 257 |
+
|
| 258 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 259 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 260 |
+
is scaled and with what normalization factor.
|
| 261 |
+
|
| 262 |
+
.. versionadded:: 1.20.0
|
| 263 |
+
|
| 264 |
+
The "backward", "forward" values were added.
|
| 265 |
+
|
| 266 |
+
Returns
|
| 267 |
+
-------
|
| 268 |
+
out : complex ndarray
|
| 269 |
+
The truncated or zero-padded input, transformed along the axis
|
| 270 |
+
indicated by `axis`, or the last one if `axis` is not specified.
|
| 271 |
+
|
| 272 |
+
Raises
|
| 273 |
+
------
|
| 274 |
+
IndexError
|
| 275 |
+
If `axis` is not a valid axis of `a`.
|
| 276 |
+
|
| 277 |
+
See Also
|
| 278 |
+
--------
|
| 279 |
+
numpy.fft : An introduction, with definitions and general explanations.
|
| 280 |
+
fft : The one-dimensional (forward) FFT, of which `ifft` is the inverse
|
| 281 |
+
ifft2 : The two-dimensional inverse FFT.
|
| 282 |
+
ifftn : The n-dimensional inverse FFT.
|
| 283 |
+
|
| 284 |
+
Notes
|
| 285 |
+
-----
|
| 286 |
+
If the input parameter `n` is larger than the size of the input, the input
|
| 287 |
+
is padded by appending zeros at the end. Even though this is the common
|
| 288 |
+
approach, it might lead to surprising results. If a different padding is
|
| 289 |
+
desired, it must be performed before calling `ifft`.
|
| 290 |
+
|
| 291 |
+
Examples
|
| 292 |
+
--------
|
| 293 |
+
>>> np.fft.ifft([0, 4, 0, 0])
|
| 294 |
+
array([ 1.+0.j, 0.+1.j, -1.+0.j, 0.-1.j]) # may vary
|
| 295 |
+
|
| 296 |
+
Create and plot a band-limited signal with random phases:
|
| 297 |
+
|
| 298 |
+
>>> import matplotlib.pyplot as plt
|
| 299 |
+
>>> t = np.arange(400)
|
| 300 |
+
>>> n = np.zeros((400,), dtype=complex)
|
| 301 |
+
>>> n[40:60] = np.exp(1j*np.random.uniform(0, 2*np.pi, (20,)))
|
| 302 |
+
>>> s = np.fft.ifft(n)
|
| 303 |
+
>>> plt.plot(t, s.real, label='real')
|
| 304 |
+
[<matplotlib.lines.Line2D object at ...>]
|
| 305 |
+
>>> plt.plot(t, s.imag, '--', label='imaginary')
|
| 306 |
+
[<matplotlib.lines.Line2D object at ...>]
|
| 307 |
+
>>> plt.legend()
|
| 308 |
+
<matplotlib.legend.Legend object at ...>
|
| 309 |
+
>>> plt.show()
|
| 310 |
+
|
| 311 |
+
"""
|
| 312 |
+
a = asarray(a)
|
| 313 |
+
if n is None:
|
| 314 |
+
n = a.shape[axis]
|
| 315 |
+
inv_norm = _get_backward_norm(n, norm)
|
| 316 |
+
output = _raw_fft(a, n, axis, False, False, inv_norm)
|
| 317 |
+
return output
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
@array_function_dispatch(_fft_dispatcher)
|
| 321 |
+
def rfft(a, n=None, axis=-1, norm=None):
|
| 322 |
+
"""
|
| 323 |
+
Compute the one-dimensional discrete Fourier Transform for real input.
|
| 324 |
+
|
| 325 |
+
This function computes the one-dimensional *n*-point discrete Fourier
|
| 326 |
+
Transform (DFT) of a real-valued array by means of an efficient algorithm
|
| 327 |
+
called the Fast Fourier Transform (FFT).
|
| 328 |
+
|
| 329 |
+
Parameters
|
| 330 |
+
----------
|
| 331 |
+
a : array_like
|
| 332 |
+
Input array
|
| 333 |
+
n : int, optional
|
| 334 |
+
Number of points along transformation axis in the input to use.
|
| 335 |
+
If `n` is smaller than the length of the input, the input is cropped.
|
| 336 |
+
If it is larger, the input is padded with zeros. If `n` is not given,
|
| 337 |
+
the length of the input along the axis specified by `axis` is used.
|
| 338 |
+
axis : int, optional
|
| 339 |
+
Axis over which to compute the FFT. If not given, the last axis is
|
| 340 |
+
used.
|
| 341 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 342 |
+
.. versionadded:: 1.10.0
|
| 343 |
+
|
| 344 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 345 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 346 |
+
is scaled and with what normalization factor.
|
| 347 |
+
|
| 348 |
+
.. versionadded:: 1.20.0
|
| 349 |
+
|
| 350 |
+
The "backward", "forward" values were added.
|
| 351 |
+
|
| 352 |
+
Returns
|
| 353 |
+
-------
|
| 354 |
+
out : complex ndarray
|
| 355 |
+
The truncated or zero-padded input, transformed along the axis
|
| 356 |
+
indicated by `axis`, or the last one if `axis` is not specified.
|
| 357 |
+
If `n` is even, the length of the transformed axis is ``(n/2)+1``.
|
| 358 |
+
If `n` is odd, the length is ``(n+1)/2``.
|
| 359 |
+
|
| 360 |
+
Raises
|
| 361 |
+
------
|
| 362 |
+
IndexError
|
| 363 |
+
If `axis` is not a valid axis of `a`.
|
| 364 |
+
|
| 365 |
+
See Also
|
| 366 |
+
--------
|
| 367 |
+
numpy.fft : For definition of the DFT and conventions used.
|
| 368 |
+
irfft : The inverse of `rfft`.
|
| 369 |
+
fft : The one-dimensional FFT of general (complex) input.
|
| 370 |
+
fftn : The *n*-dimensional FFT.
|
| 371 |
+
rfftn : The *n*-dimensional FFT of real input.
|
| 372 |
+
|
| 373 |
+
Notes
|
| 374 |
+
-----
|
| 375 |
+
When the DFT is computed for purely real input, the output is
|
| 376 |
+
Hermitian-symmetric, i.e. the negative frequency terms are just the complex
|
| 377 |
+
conjugates of the corresponding positive-frequency terms, and the
|
| 378 |
+
negative-frequency terms are therefore redundant. This function does not
|
| 379 |
+
compute the negative frequency terms, and the length of the transformed
|
| 380 |
+
axis of the output is therefore ``n//2 + 1``.
|
| 381 |
+
|
| 382 |
+
When ``A = rfft(a)`` and fs is the sampling frequency, ``A[0]`` contains
|
| 383 |
+
the zero-frequency term 0*fs, which is real due to Hermitian symmetry.
|
| 384 |
+
|
| 385 |
+
If `n` is even, ``A[-1]`` contains the term representing both positive
|
| 386 |
+
and negative Nyquist frequency (+fs/2 and -fs/2), and must also be purely
|
| 387 |
+
real. If `n` is odd, there is no term at fs/2; ``A[-1]`` contains
|
| 388 |
+
the largest positive frequency (fs/2*(n-1)/n), and is complex in the
|
| 389 |
+
general case.
|
| 390 |
+
|
| 391 |
+
If the input `a` contains an imaginary part, it is silently discarded.
|
| 392 |
+
|
| 393 |
+
Examples
|
| 394 |
+
--------
|
| 395 |
+
>>> np.fft.fft([0, 1, 0, 0])
|
| 396 |
+
array([ 1.+0.j, 0.-1.j, -1.+0.j, 0.+1.j]) # may vary
|
| 397 |
+
>>> np.fft.rfft([0, 1, 0, 0])
|
| 398 |
+
array([ 1.+0.j, 0.-1.j, -1.+0.j]) # may vary
|
| 399 |
+
|
| 400 |
+
Notice how the final element of the `fft` output is the complex conjugate
|
| 401 |
+
of the second element, for real input. For `rfft`, this symmetry is
|
| 402 |
+
exploited to compute only the non-negative frequency terms.
|
| 403 |
+
|
| 404 |
+
"""
|
| 405 |
+
a = asarray(a)
|
| 406 |
+
if n is None:
|
| 407 |
+
n = a.shape[axis]
|
| 408 |
+
inv_norm = _get_forward_norm(n, norm)
|
| 409 |
+
output = _raw_fft(a, n, axis, True, True, inv_norm)
|
| 410 |
+
return output
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
@array_function_dispatch(_fft_dispatcher)
|
| 414 |
+
def irfft(a, n=None, axis=-1, norm=None):
|
| 415 |
+
"""
|
| 416 |
+
Computes the inverse of `rfft`.
|
| 417 |
+
|
| 418 |
+
This function computes the inverse of the one-dimensional *n*-point
|
| 419 |
+
discrete Fourier Transform of real input computed by `rfft`.
|
| 420 |
+
In other words, ``irfft(rfft(a), len(a)) == a`` to within numerical
|
| 421 |
+
accuracy. (See Notes below for why ``len(a)`` is necessary here.)
|
| 422 |
+
|
| 423 |
+
The input is expected to be in the form returned by `rfft`, i.e. the
|
| 424 |
+
real zero-frequency term followed by the complex positive frequency terms
|
| 425 |
+
in order of increasing frequency. Since the discrete Fourier Transform of
|
| 426 |
+
real input is Hermitian-symmetric, the negative frequency terms are taken
|
| 427 |
+
to be the complex conjugates of the corresponding positive frequency terms.
|
| 428 |
+
|
| 429 |
+
Parameters
|
| 430 |
+
----------
|
| 431 |
+
a : array_like
|
| 432 |
+
The input array.
|
| 433 |
+
n : int, optional
|
| 434 |
+
Length of the transformed axis of the output.
|
| 435 |
+
For `n` output points, ``n//2+1`` input points are necessary. If the
|
| 436 |
+
input is longer than this, it is cropped. If it is shorter than this,
|
| 437 |
+
it is padded with zeros. If `n` is not given, it is taken to be
|
| 438 |
+
``2*(m-1)`` where ``m`` is the length of the input along the axis
|
| 439 |
+
specified by `axis`.
|
| 440 |
+
axis : int, optional
|
| 441 |
+
Axis over which to compute the inverse FFT. If not given, the last
|
| 442 |
+
axis is used.
|
| 443 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 444 |
+
.. versionadded:: 1.10.0
|
| 445 |
+
|
| 446 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 447 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 448 |
+
is scaled and with what normalization factor.
|
| 449 |
+
|
| 450 |
+
.. versionadded:: 1.20.0
|
| 451 |
+
|
| 452 |
+
The "backward", "forward" values were added.
|
| 453 |
+
|
| 454 |
+
Returns
|
| 455 |
+
-------
|
| 456 |
+
out : ndarray
|
| 457 |
+
The truncated or zero-padded input, transformed along the axis
|
| 458 |
+
indicated by `axis`, or the last one if `axis` is not specified.
|
| 459 |
+
The length of the transformed axis is `n`, or, if `n` is not given,
|
| 460 |
+
``2*(m-1)`` where ``m`` is the length of the transformed axis of the
|
| 461 |
+
input. To get an odd number of output points, `n` must be specified.
|
| 462 |
+
|
| 463 |
+
Raises
|
| 464 |
+
------
|
| 465 |
+
IndexError
|
| 466 |
+
If `axis` is not a valid axis of `a`.
|
| 467 |
+
|
| 468 |
+
See Also
|
| 469 |
+
--------
|
| 470 |
+
numpy.fft : For definition of the DFT and conventions used.
|
| 471 |
+
rfft : The one-dimensional FFT of real input, of which `irfft` is inverse.
|
| 472 |
+
fft : The one-dimensional FFT.
|
| 473 |
+
irfft2 : The inverse of the two-dimensional FFT of real input.
|
| 474 |
+
irfftn : The inverse of the *n*-dimensional FFT of real input.
|
| 475 |
+
|
| 476 |
+
Notes
|
| 477 |
+
-----
|
| 478 |
+
Returns the real valued `n`-point inverse discrete Fourier transform
|
| 479 |
+
of `a`, where `a` contains the non-negative frequency terms of a
|
| 480 |
+
Hermitian-symmetric sequence. `n` is the length of the result, not the
|
| 481 |
+
input.
|
| 482 |
+
|
| 483 |
+
If you specify an `n` such that `a` must be zero-padded or truncated, the
|
| 484 |
+
extra/removed values will be added/removed at high frequencies. One can
|
| 485 |
+
thus resample a series to `m` points via Fourier interpolation by:
|
| 486 |
+
``a_resamp = irfft(rfft(a), m)``.
|
| 487 |
+
|
| 488 |
+
The correct interpretation of the hermitian input depends on the length of
|
| 489 |
+
the original data, as given by `n`. This is because each input shape could
|
| 490 |
+
correspond to either an odd or even length signal. By default, `irfft`
|
| 491 |
+
assumes an even output length which puts the last entry at the Nyquist
|
| 492 |
+
frequency; aliasing with its symmetric counterpart. By Hermitian symmetry,
|
| 493 |
+
the value is thus treated as purely real. To avoid losing information, the
|
| 494 |
+
correct length of the real input **must** be given.
|
| 495 |
+
|
| 496 |
+
Examples
|
| 497 |
+
--------
|
| 498 |
+
>>> np.fft.ifft([1, -1j, -1, 1j])
|
| 499 |
+
array([0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]) # may vary
|
| 500 |
+
>>> np.fft.irfft([1, -1j, -1])
|
| 501 |
+
array([0., 1., 0., 0.])
|
| 502 |
+
|
| 503 |
+
Notice how the last term in the input to the ordinary `ifft` is the
|
| 504 |
+
complex conjugate of the second term, and the output has zero imaginary
|
| 505 |
+
part everywhere. When calling `irfft`, the negative frequencies are not
|
| 506 |
+
specified, and the output array is purely real.
|
| 507 |
+
|
| 508 |
+
"""
|
| 509 |
+
a = asarray(a)
|
| 510 |
+
if n is None:
|
| 511 |
+
n = (a.shape[axis] - 1) * 2
|
| 512 |
+
inv_norm = _get_backward_norm(n, norm)
|
| 513 |
+
output = _raw_fft(a, n, axis, True, False, inv_norm)
|
| 514 |
+
return output
|
| 515 |
+
|
| 516 |
+
|
| 517 |
+
@array_function_dispatch(_fft_dispatcher)
|
| 518 |
+
def hfft(a, n=None, axis=-1, norm=None):
|
| 519 |
+
"""
|
| 520 |
+
Compute the FFT of a signal that has Hermitian symmetry, i.e., a real
|
| 521 |
+
spectrum.
|
| 522 |
+
|
| 523 |
+
Parameters
|
| 524 |
+
----------
|
| 525 |
+
a : array_like
|
| 526 |
+
The input array.
|
| 527 |
+
n : int, optional
|
| 528 |
+
Length of the transformed axis of the output. For `n` output
|
| 529 |
+
points, ``n//2 + 1`` input points are necessary. If the input is
|
| 530 |
+
longer than this, it is cropped. If it is shorter than this, it is
|
| 531 |
+
padded with zeros. If `n` is not given, it is taken to be ``2*(m-1)``
|
| 532 |
+
where ``m`` is the length of the input along the axis specified by
|
| 533 |
+
`axis`.
|
| 534 |
+
axis : int, optional
|
| 535 |
+
Axis over which to compute the FFT. If not given, the last
|
| 536 |
+
axis is used.
|
| 537 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 538 |
+
.. versionadded:: 1.10.0
|
| 539 |
+
|
| 540 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 541 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 542 |
+
is scaled and with what normalization factor.
|
| 543 |
+
|
| 544 |
+
.. versionadded:: 1.20.0
|
| 545 |
+
|
| 546 |
+
The "backward", "forward" values were added.
|
| 547 |
+
|
| 548 |
+
Returns
|
| 549 |
+
-------
|
| 550 |
+
out : ndarray
|
| 551 |
+
The truncated or zero-padded input, transformed along the axis
|
| 552 |
+
indicated by `axis`, or the last one if `axis` is not specified.
|
| 553 |
+
The length of the transformed axis is `n`, or, if `n` is not given,
|
| 554 |
+
``2*m - 2`` where ``m`` is the length of the transformed axis of
|
| 555 |
+
the input. To get an odd number of output points, `n` must be
|
| 556 |
+
specified, for instance as ``2*m - 1`` in the typical case,
|
| 557 |
+
|
| 558 |
+
Raises
|
| 559 |
+
------
|
| 560 |
+
IndexError
|
| 561 |
+
If `axis` is not a valid axis of `a`.
|
| 562 |
+
|
| 563 |
+
See also
|
| 564 |
+
--------
|
| 565 |
+
rfft : Compute the one-dimensional FFT for real input.
|
| 566 |
+
ihfft : The inverse of `hfft`.
|
| 567 |
+
|
| 568 |
+
Notes
|
| 569 |
+
-----
|
| 570 |
+
`hfft`/`ihfft` are a pair analogous to `rfft`/`irfft`, but for the
|
| 571 |
+
opposite case: here the signal has Hermitian symmetry in the time
|
| 572 |
+
domain and is real in the frequency domain. So here it's `hfft` for
|
| 573 |
+
which you must supply the length of the result if it is to be odd.
|
| 574 |
+
|
| 575 |
+
* even: ``ihfft(hfft(a, 2*len(a) - 2)) == a``, within roundoff error,
|
| 576 |
+
* odd: ``ihfft(hfft(a, 2*len(a) - 1)) == a``, within roundoff error.
|
| 577 |
+
|
| 578 |
+
The correct interpretation of the hermitian input depends on the length of
|
| 579 |
+
the original data, as given by `n`. This is because each input shape could
|
| 580 |
+
correspond to either an odd or even length signal. By default, `hfft`
|
| 581 |
+
assumes an even output length which puts the last entry at the Nyquist
|
| 582 |
+
frequency; aliasing with its symmetric counterpart. By Hermitian symmetry,
|
| 583 |
+
the value is thus treated as purely real. To avoid losing information, the
|
| 584 |
+
shape of the full signal **must** be given.
|
| 585 |
+
|
| 586 |
+
Examples
|
| 587 |
+
--------
|
| 588 |
+
>>> signal = np.array([1, 2, 3, 4, 3, 2])
|
| 589 |
+
>>> np.fft.fft(signal)
|
| 590 |
+
array([15.+0.j, -4.+0.j, 0.+0.j, -1.-0.j, 0.+0.j, -4.+0.j]) # may vary
|
| 591 |
+
>>> np.fft.hfft(signal[:4]) # Input first half of signal
|
| 592 |
+
array([15., -4., 0., -1., 0., -4.])
|
| 593 |
+
>>> np.fft.hfft(signal, 6) # Input entire signal and truncate
|
| 594 |
+
array([15., -4., 0., -1., 0., -4.])
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
>>> signal = np.array([[1, 1.j], [-1.j, 2]])
|
| 598 |
+
>>> np.conj(signal.T) - signal # check Hermitian symmetry
|
| 599 |
+
array([[ 0.-0.j, -0.+0.j], # may vary
|
| 600 |
+
[ 0.+0.j, 0.-0.j]])
|
| 601 |
+
>>> freq_spectrum = np.fft.hfft(signal)
|
| 602 |
+
>>> freq_spectrum
|
| 603 |
+
array([[ 1., 1.],
|
| 604 |
+
[ 2., -2.]])
|
| 605 |
+
|
| 606 |
+
"""
|
| 607 |
+
a = asarray(a)
|
| 608 |
+
if n is None:
|
| 609 |
+
n = (a.shape[axis] - 1) * 2
|
| 610 |
+
new_norm = _swap_direction(norm)
|
| 611 |
+
output = irfft(conjugate(a), n, axis, norm=new_norm)
|
| 612 |
+
return output
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
@array_function_dispatch(_fft_dispatcher)
|
| 616 |
+
def ihfft(a, n=None, axis=-1, norm=None):
|
| 617 |
+
"""
|
| 618 |
+
Compute the inverse FFT of a signal that has Hermitian symmetry.
|
| 619 |
+
|
| 620 |
+
Parameters
|
| 621 |
+
----------
|
| 622 |
+
a : array_like
|
| 623 |
+
Input array.
|
| 624 |
+
n : int, optional
|
| 625 |
+
Length of the inverse FFT, the number of points along
|
| 626 |
+
transformation axis in the input to use. If `n` is smaller than
|
| 627 |
+
the length of the input, the input is cropped. If it is larger,
|
| 628 |
+
the input is padded with zeros. If `n` is not given, the length of
|
| 629 |
+
the input along the axis specified by `axis` is used.
|
| 630 |
+
axis : int, optional
|
| 631 |
+
Axis over which to compute the inverse FFT. If not given, the last
|
| 632 |
+
axis is used.
|
| 633 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 634 |
+
.. versionadded:: 1.10.0
|
| 635 |
+
|
| 636 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 637 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 638 |
+
is scaled and with what normalization factor.
|
| 639 |
+
|
| 640 |
+
.. versionadded:: 1.20.0
|
| 641 |
+
|
| 642 |
+
The "backward", "forward" values were added.
|
| 643 |
+
|
| 644 |
+
Returns
|
| 645 |
+
-------
|
| 646 |
+
out : complex ndarray
|
| 647 |
+
The truncated or zero-padded input, transformed along the axis
|
| 648 |
+
indicated by `axis`, or the last one if `axis` is not specified.
|
| 649 |
+
The length of the transformed axis is ``n//2 + 1``.
|
| 650 |
+
|
| 651 |
+
See also
|
| 652 |
+
--------
|
| 653 |
+
hfft, irfft
|
| 654 |
+
|
| 655 |
+
Notes
|
| 656 |
+
-----
|
| 657 |
+
`hfft`/`ihfft` are a pair analogous to `rfft`/`irfft`, but for the
|
| 658 |
+
opposite case: here the signal has Hermitian symmetry in the time
|
| 659 |
+
domain and is real in the frequency domain. So here it's `hfft` for
|
| 660 |
+
which you must supply the length of the result if it is to be odd:
|
| 661 |
+
|
| 662 |
+
* even: ``ihfft(hfft(a, 2*len(a) - 2)) == a``, within roundoff error,
|
| 663 |
+
* odd: ``ihfft(hfft(a, 2*len(a) - 1)) == a``, within roundoff error.
|
| 664 |
+
|
| 665 |
+
Examples
|
| 666 |
+
--------
|
| 667 |
+
>>> spectrum = np.array([ 15, -4, 0, -1, 0, -4])
|
| 668 |
+
>>> np.fft.ifft(spectrum)
|
| 669 |
+
array([1.+0.j, 2.+0.j, 3.+0.j, 4.+0.j, 3.+0.j, 2.+0.j]) # may vary
|
| 670 |
+
>>> np.fft.ihfft(spectrum)
|
| 671 |
+
array([ 1.-0.j, 2.-0.j, 3.-0.j, 4.-0.j]) # may vary
|
| 672 |
+
|
| 673 |
+
"""
|
| 674 |
+
a = asarray(a)
|
| 675 |
+
if n is None:
|
| 676 |
+
n = a.shape[axis]
|
| 677 |
+
new_norm = _swap_direction(norm)
|
| 678 |
+
output = conjugate(rfft(a, n, axis, norm=new_norm))
|
| 679 |
+
return output
|
| 680 |
+
|
| 681 |
+
|
| 682 |
+
def _cook_nd_args(a, s=None, axes=None, invreal=0):
|
| 683 |
+
if s is None:
|
| 684 |
+
shapeless = 1
|
| 685 |
+
if axes is None:
|
| 686 |
+
s = list(a.shape)
|
| 687 |
+
else:
|
| 688 |
+
s = take(a.shape, axes)
|
| 689 |
+
else:
|
| 690 |
+
shapeless = 0
|
| 691 |
+
s = list(s)
|
| 692 |
+
if axes is None:
|
| 693 |
+
axes = list(range(-len(s), 0))
|
| 694 |
+
if len(s) != len(axes):
|
| 695 |
+
raise ValueError("Shape and axes have different lengths.")
|
| 696 |
+
if invreal and shapeless:
|
| 697 |
+
s[-1] = (a.shape[axes[-1]] - 1) * 2
|
| 698 |
+
return s, axes
|
| 699 |
+
|
| 700 |
+
|
| 701 |
+
def _raw_fftnd(a, s=None, axes=None, function=fft, norm=None):
|
| 702 |
+
a = asarray(a)
|
| 703 |
+
s, axes = _cook_nd_args(a, s, axes)
|
| 704 |
+
itl = list(range(len(axes)))
|
| 705 |
+
itl.reverse()
|
| 706 |
+
for ii in itl:
|
| 707 |
+
a = function(a, n=s[ii], axis=axes[ii], norm=norm)
|
| 708 |
+
return a
|
| 709 |
+
|
| 710 |
+
|
| 711 |
+
def _fftn_dispatcher(a, s=None, axes=None, norm=None):
|
| 712 |
+
return (a,)
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 716 |
+
def fftn(a, s=None, axes=None, norm=None):
|
| 717 |
+
"""
|
| 718 |
+
Compute the N-dimensional discrete Fourier Transform.
|
| 719 |
+
|
| 720 |
+
This function computes the *N*-dimensional discrete Fourier Transform over
|
| 721 |
+
any number of axes in an *M*-dimensional array by means of the Fast Fourier
|
| 722 |
+
Transform (FFT).
|
| 723 |
+
|
| 724 |
+
Parameters
|
| 725 |
+
----------
|
| 726 |
+
a : array_like
|
| 727 |
+
Input array, can be complex.
|
| 728 |
+
s : sequence of ints, optional
|
| 729 |
+
Shape (length of each transformed axis) of the output
|
| 730 |
+
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
| 731 |
+
This corresponds to ``n`` for ``fft(x, n)``.
|
| 732 |
+
Along any axis, if the given shape is smaller than that of the input,
|
| 733 |
+
the input is cropped. If it is larger, the input is padded with zeros.
|
| 734 |
+
if `s` is not given, the shape of the input along the axes specified
|
| 735 |
+
by `axes` is used.
|
| 736 |
+
axes : sequence of ints, optional
|
| 737 |
+
Axes over which to compute the FFT. If not given, the last ``len(s)``
|
| 738 |
+
axes are used, or all axes if `s` is also not specified.
|
| 739 |
+
Repeated indices in `axes` means that the transform over that axis is
|
| 740 |
+
performed multiple times.
|
| 741 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 742 |
+
.. versionadded:: 1.10.0
|
| 743 |
+
|
| 744 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 745 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 746 |
+
is scaled and with what normalization factor.
|
| 747 |
+
|
| 748 |
+
.. versionadded:: 1.20.0
|
| 749 |
+
|
| 750 |
+
The "backward", "forward" values were added.
|
| 751 |
+
|
| 752 |
+
Returns
|
| 753 |
+
-------
|
| 754 |
+
out : complex ndarray
|
| 755 |
+
The truncated or zero-padded input, transformed along the axes
|
| 756 |
+
indicated by `axes`, or by a combination of `s` and `a`,
|
| 757 |
+
as explained in the parameters section above.
|
| 758 |
+
|
| 759 |
+
Raises
|
| 760 |
+
------
|
| 761 |
+
ValueError
|
| 762 |
+
If `s` and `axes` have different length.
|
| 763 |
+
IndexError
|
| 764 |
+
If an element of `axes` is larger than than the number of axes of `a`.
|
| 765 |
+
|
| 766 |
+
See Also
|
| 767 |
+
--------
|
| 768 |
+
numpy.fft : Overall view of discrete Fourier transforms, with definitions
|
| 769 |
+
and conventions used.
|
| 770 |
+
ifftn : The inverse of `fftn`, the inverse *n*-dimensional FFT.
|
| 771 |
+
fft : The one-dimensional FFT, with definitions and conventions used.
|
| 772 |
+
rfftn : The *n*-dimensional FFT of real input.
|
| 773 |
+
fft2 : The two-dimensional FFT.
|
| 774 |
+
fftshift : Shifts zero-frequency terms to centre of array
|
| 775 |
+
|
| 776 |
+
Notes
|
| 777 |
+
-----
|
| 778 |
+
The output, analogously to `fft`, contains the term for zero frequency in
|
| 779 |
+
the low-order corner of all axes, the positive frequency terms in the
|
| 780 |
+
first half of all axes, the term for the Nyquist frequency in the middle
|
| 781 |
+
of all axes and the negative frequency terms in the second half of all
|
| 782 |
+
axes, in order of decreasingly negative frequency.
|
| 783 |
+
|
| 784 |
+
See `numpy.fft` for details, definitions and conventions used.
|
| 785 |
+
|
| 786 |
+
Examples
|
| 787 |
+
--------
|
| 788 |
+
>>> a = np.mgrid[:3, :3, :3][0]
|
| 789 |
+
>>> np.fft.fftn(a, axes=(1, 2))
|
| 790 |
+
array([[[ 0.+0.j, 0.+0.j, 0.+0.j], # may vary
|
| 791 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j],
|
| 792 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j]],
|
| 793 |
+
[[ 9.+0.j, 0.+0.j, 0.+0.j],
|
| 794 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j],
|
| 795 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j]],
|
| 796 |
+
[[18.+0.j, 0.+0.j, 0.+0.j],
|
| 797 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j],
|
| 798 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j]]])
|
| 799 |
+
>>> np.fft.fftn(a, (2, 2), axes=(0, 1))
|
| 800 |
+
array([[[ 2.+0.j, 2.+0.j, 2.+0.j], # may vary
|
| 801 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j]],
|
| 802 |
+
[[-2.+0.j, -2.+0.j, -2.+0.j],
|
| 803 |
+
[ 0.+0.j, 0.+0.j, 0.+0.j]]])
|
| 804 |
+
|
| 805 |
+
>>> import matplotlib.pyplot as plt
|
| 806 |
+
>>> [X, Y] = np.meshgrid(2 * np.pi * np.arange(200) / 12,
|
| 807 |
+
... 2 * np.pi * np.arange(200) / 34)
|
| 808 |
+
>>> S = np.sin(X) + np.cos(Y) + np.random.uniform(0, 1, X.shape)
|
| 809 |
+
>>> FS = np.fft.fftn(S)
|
| 810 |
+
>>> plt.imshow(np.log(np.abs(np.fft.fftshift(FS))**2))
|
| 811 |
+
<matplotlib.image.AxesImage object at 0x...>
|
| 812 |
+
>>> plt.show()
|
| 813 |
+
|
| 814 |
+
"""
|
| 815 |
+
return _raw_fftnd(a, s, axes, fft, norm)
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 819 |
+
def ifftn(a, s=None, axes=None, norm=None):
|
| 820 |
+
"""
|
| 821 |
+
Compute the N-dimensional inverse discrete Fourier Transform.
|
| 822 |
+
|
| 823 |
+
This function computes the inverse of the N-dimensional discrete
|
| 824 |
+
Fourier Transform over any number of axes in an M-dimensional array by
|
| 825 |
+
means of the Fast Fourier Transform (FFT). In other words,
|
| 826 |
+
``ifftn(fftn(a)) == a`` to within numerical accuracy.
|
| 827 |
+
For a description of the definitions and conventions used, see `numpy.fft`.
|
| 828 |
+
|
| 829 |
+
The input, analogously to `ifft`, should be ordered in the same way as is
|
| 830 |
+
returned by `fftn`, i.e. it should have the term for zero frequency
|
| 831 |
+
in all axes in the low-order corner, the positive frequency terms in the
|
| 832 |
+
first half of all axes, the term for the Nyquist frequency in the middle
|
| 833 |
+
of all axes and the negative frequency terms in the second half of all
|
| 834 |
+
axes, in order of decreasingly negative frequency.
|
| 835 |
+
|
| 836 |
+
Parameters
|
| 837 |
+
----------
|
| 838 |
+
a : array_like
|
| 839 |
+
Input array, can be complex.
|
| 840 |
+
s : sequence of ints, optional
|
| 841 |
+
Shape (length of each transformed axis) of the output
|
| 842 |
+
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
| 843 |
+
This corresponds to ``n`` for ``ifft(x, n)``.
|
| 844 |
+
Along any axis, if the given shape is smaller than that of the input,
|
| 845 |
+
the input is cropped. If it is larger, the input is padded with zeros.
|
| 846 |
+
if `s` is not given, the shape of the input along the axes specified
|
| 847 |
+
by `axes` is used. See notes for issue on `ifft` zero padding.
|
| 848 |
+
axes : sequence of ints, optional
|
| 849 |
+
Axes over which to compute the IFFT. If not given, the last ``len(s)``
|
| 850 |
+
axes are used, or all axes if `s` is also not specified.
|
| 851 |
+
Repeated indices in `axes` means that the inverse transform over that
|
| 852 |
+
axis is performed multiple times.
|
| 853 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 854 |
+
.. versionadded:: 1.10.0
|
| 855 |
+
|
| 856 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 857 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 858 |
+
is scaled and with what normalization factor.
|
| 859 |
+
|
| 860 |
+
.. versionadded:: 1.20.0
|
| 861 |
+
|
| 862 |
+
The "backward", "forward" values were added.
|
| 863 |
+
|
| 864 |
+
Returns
|
| 865 |
+
-------
|
| 866 |
+
out : complex ndarray
|
| 867 |
+
The truncated or zero-padded input, transformed along the axes
|
| 868 |
+
indicated by `axes`, or by a combination of `s` or `a`,
|
| 869 |
+
as explained in the parameters section above.
|
| 870 |
+
|
| 871 |
+
Raises
|
| 872 |
+
------
|
| 873 |
+
ValueError
|
| 874 |
+
If `s` and `axes` have different length.
|
| 875 |
+
IndexError
|
| 876 |
+
If an element of `axes` is larger than than the number of axes of `a`.
|
| 877 |
+
|
| 878 |
+
See Also
|
| 879 |
+
--------
|
| 880 |
+
numpy.fft : Overall view of discrete Fourier transforms, with definitions
|
| 881 |
+
and conventions used.
|
| 882 |
+
fftn : The forward *n*-dimensional FFT, of which `ifftn` is the inverse.
|
| 883 |
+
ifft : The one-dimensional inverse FFT.
|
| 884 |
+
ifft2 : The two-dimensional inverse FFT.
|
| 885 |
+
ifftshift : Undoes `fftshift`, shifts zero-frequency terms to beginning
|
| 886 |
+
of array.
|
| 887 |
+
|
| 888 |
+
Notes
|
| 889 |
+
-----
|
| 890 |
+
See `numpy.fft` for definitions and conventions used.
|
| 891 |
+
|
| 892 |
+
Zero-padding, analogously with `ifft`, is performed by appending zeros to
|
| 893 |
+
the input along the specified dimension. Although this is the common
|
| 894 |
+
approach, it might lead to surprising results. If another form of zero
|
| 895 |
+
padding is desired, it must be performed before `ifftn` is called.
|
| 896 |
+
|
| 897 |
+
Examples
|
| 898 |
+
--------
|
| 899 |
+
>>> a = np.eye(4)
|
| 900 |
+
>>> np.fft.ifftn(np.fft.fftn(a, axes=(0,)), axes=(1,))
|
| 901 |
+
array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], # may vary
|
| 902 |
+
[0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
|
| 903 |
+
[0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
|
| 904 |
+
[0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])
|
| 905 |
+
|
| 906 |
+
|
| 907 |
+
Create and plot an image with band-limited frequency content:
|
| 908 |
+
|
| 909 |
+
>>> import matplotlib.pyplot as plt
|
| 910 |
+
>>> n = np.zeros((200,200), dtype=complex)
|
| 911 |
+
>>> n[60:80, 20:40] = np.exp(1j*np.random.uniform(0, 2*np.pi, (20, 20)))
|
| 912 |
+
>>> im = np.fft.ifftn(n).real
|
| 913 |
+
>>> plt.imshow(im)
|
| 914 |
+
<matplotlib.image.AxesImage object at 0x...>
|
| 915 |
+
>>> plt.show()
|
| 916 |
+
|
| 917 |
+
"""
|
| 918 |
+
return _raw_fftnd(a, s, axes, ifft, norm)
|
| 919 |
+
|
| 920 |
+
|
| 921 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 922 |
+
def fft2(a, s=None, axes=(-2, -1), norm=None):
|
| 923 |
+
"""
|
| 924 |
+
Compute the 2-dimensional discrete Fourier Transform.
|
| 925 |
+
|
| 926 |
+
This function computes the *n*-dimensional discrete Fourier Transform
|
| 927 |
+
over any axes in an *M*-dimensional array by means of the
|
| 928 |
+
Fast Fourier Transform (FFT). By default, the transform is computed over
|
| 929 |
+
the last two axes of the input array, i.e., a 2-dimensional FFT.
|
| 930 |
+
|
| 931 |
+
Parameters
|
| 932 |
+
----------
|
| 933 |
+
a : array_like
|
| 934 |
+
Input array, can be complex
|
| 935 |
+
s : sequence of ints, optional
|
| 936 |
+
Shape (length of each transformed axis) of the output
|
| 937 |
+
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
| 938 |
+
This corresponds to ``n`` for ``fft(x, n)``.
|
| 939 |
+
Along each axis, if the given shape is smaller than that of the input,
|
| 940 |
+
the input is cropped. If it is larger, the input is padded with zeros.
|
| 941 |
+
if `s` is not given, the shape of the input along the axes specified
|
| 942 |
+
by `axes` is used.
|
| 943 |
+
axes : sequence of ints, optional
|
| 944 |
+
Axes over which to compute the FFT. If not given, the last two
|
| 945 |
+
axes are used. A repeated index in `axes` means the transform over
|
| 946 |
+
that axis is performed multiple times. A one-element sequence means
|
| 947 |
+
that a one-dimensional FFT is performed.
|
| 948 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 949 |
+
.. versionadded:: 1.10.0
|
| 950 |
+
|
| 951 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 952 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 953 |
+
is scaled and with what normalization factor.
|
| 954 |
+
|
| 955 |
+
.. versionadded:: 1.20.0
|
| 956 |
+
|
| 957 |
+
The "backward", "forward" values were added.
|
| 958 |
+
|
| 959 |
+
Returns
|
| 960 |
+
-------
|
| 961 |
+
out : complex ndarray
|
| 962 |
+
The truncated or zero-padded input, transformed along the axes
|
| 963 |
+
indicated by `axes`, or the last two axes if `axes` is not given.
|
| 964 |
+
|
| 965 |
+
Raises
|
| 966 |
+
------
|
| 967 |
+
ValueError
|
| 968 |
+
If `s` and `axes` have different length, or `axes` not given and
|
| 969 |
+
``len(s) != 2``.
|
| 970 |
+
IndexError
|
| 971 |
+
If an element of `axes` is larger than than the number of axes of `a`.
|
| 972 |
+
|
| 973 |
+
See Also
|
| 974 |
+
--------
|
| 975 |
+
numpy.fft : Overall view of discrete Fourier transforms, with definitions
|
| 976 |
+
and conventions used.
|
| 977 |
+
ifft2 : The inverse two-dimensional FFT.
|
| 978 |
+
fft : The one-dimensional FFT.
|
| 979 |
+
fftn : The *n*-dimensional FFT.
|
| 980 |
+
fftshift : Shifts zero-frequency terms to the center of the array.
|
| 981 |
+
For two-dimensional input, swaps first and third quadrants, and second
|
| 982 |
+
and fourth quadrants.
|
| 983 |
+
|
| 984 |
+
Notes
|
| 985 |
+
-----
|
| 986 |
+
`fft2` is just `fftn` with a different default for `axes`.
|
| 987 |
+
|
| 988 |
+
The output, analogously to `fft`, contains the term for zero frequency in
|
| 989 |
+
the low-order corner of the transformed axes, the positive frequency terms
|
| 990 |
+
in the first half of these axes, the term for the Nyquist frequency in the
|
| 991 |
+
middle of the axes and the negative frequency terms in the second half of
|
| 992 |
+
the axes, in order of decreasingly negative frequency.
|
| 993 |
+
|
| 994 |
+
See `fftn` for details and a plotting example, and `numpy.fft` for
|
| 995 |
+
definitions and conventions used.
|
| 996 |
+
|
| 997 |
+
|
| 998 |
+
Examples
|
| 999 |
+
--------
|
| 1000 |
+
>>> a = np.mgrid[:5, :5][0]
|
| 1001 |
+
>>> np.fft.fft2(a)
|
| 1002 |
+
array([[ 50. +0.j , 0. +0.j , 0. +0.j , # may vary
|
| 1003 |
+
0. +0.j , 0. +0.j ],
|
| 1004 |
+
[-12.5+17.20477401j, 0. +0.j , 0. +0.j ,
|
| 1005 |
+
0. +0.j , 0. +0.j ],
|
| 1006 |
+
[-12.5 +4.0614962j , 0. +0.j , 0. +0.j ,
|
| 1007 |
+
0. +0.j , 0. +0.j ],
|
| 1008 |
+
[-12.5 -4.0614962j , 0. +0.j , 0. +0.j ,
|
| 1009 |
+
0. +0.j , 0. +0.j ],
|
| 1010 |
+
[-12.5-17.20477401j, 0. +0.j , 0. +0.j ,
|
| 1011 |
+
0. +0.j , 0. +0.j ]])
|
| 1012 |
+
|
| 1013 |
+
"""
|
| 1014 |
+
return _raw_fftnd(a, s, axes, fft, norm)
|
| 1015 |
+
|
| 1016 |
+
|
| 1017 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 1018 |
+
def ifft2(a, s=None, axes=(-2, -1), norm=None):
|
| 1019 |
+
"""
|
| 1020 |
+
Compute the 2-dimensional inverse discrete Fourier Transform.
|
| 1021 |
+
|
| 1022 |
+
This function computes the inverse of the 2-dimensional discrete Fourier
|
| 1023 |
+
Transform over any number of axes in an M-dimensional array by means of
|
| 1024 |
+
the Fast Fourier Transform (FFT). In other words, ``ifft2(fft2(a)) == a``
|
| 1025 |
+
to within numerical accuracy. By default, the inverse transform is
|
| 1026 |
+
computed over the last two axes of the input array.
|
| 1027 |
+
|
| 1028 |
+
The input, analogously to `ifft`, should be ordered in the same way as is
|
| 1029 |
+
returned by `fft2`, i.e. it should have the term for zero frequency
|
| 1030 |
+
in the low-order corner of the two axes, the positive frequency terms in
|
| 1031 |
+
the first half of these axes, the term for the Nyquist frequency in the
|
| 1032 |
+
middle of the axes and the negative frequency terms in the second half of
|
| 1033 |
+
both axes, in order of decreasingly negative frequency.
|
| 1034 |
+
|
| 1035 |
+
Parameters
|
| 1036 |
+
----------
|
| 1037 |
+
a : array_like
|
| 1038 |
+
Input array, can be complex.
|
| 1039 |
+
s : sequence of ints, optional
|
| 1040 |
+
Shape (length of each axis) of the output (``s[0]`` refers to axis 0,
|
| 1041 |
+
``s[1]`` to axis 1, etc.). This corresponds to `n` for ``ifft(x, n)``.
|
| 1042 |
+
Along each axis, if the given shape is smaller than that of the input,
|
| 1043 |
+
the input is cropped. If it is larger, the input is padded with zeros.
|
| 1044 |
+
if `s` is not given, the shape of the input along the axes specified
|
| 1045 |
+
by `axes` is used. See notes for issue on `ifft` zero padding.
|
| 1046 |
+
axes : sequence of ints, optional
|
| 1047 |
+
Axes over which to compute the FFT. If not given, the last two
|
| 1048 |
+
axes are used. A repeated index in `axes` means the transform over
|
| 1049 |
+
that axis is performed multiple times. A one-element sequence means
|
| 1050 |
+
that a one-dimensional FFT is performed.
|
| 1051 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 1052 |
+
.. versionadded:: 1.10.0
|
| 1053 |
+
|
| 1054 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 1055 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 1056 |
+
is scaled and with what normalization factor.
|
| 1057 |
+
|
| 1058 |
+
.. versionadded:: 1.20.0
|
| 1059 |
+
|
| 1060 |
+
The "backward", "forward" values were added.
|
| 1061 |
+
|
| 1062 |
+
Returns
|
| 1063 |
+
-------
|
| 1064 |
+
out : complex ndarray
|
| 1065 |
+
The truncated or zero-padded input, transformed along the axes
|
| 1066 |
+
indicated by `axes`, or the last two axes if `axes` is not given.
|
| 1067 |
+
|
| 1068 |
+
Raises
|
| 1069 |
+
------
|
| 1070 |
+
ValueError
|
| 1071 |
+
If `s` and `axes` have different length, or `axes` not given and
|
| 1072 |
+
``len(s) != 2``.
|
| 1073 |
+
IndexError
|
| 1074 |
+
If an element of `axes` is larger than than the number of axes of `a`.
|
| 1075 |
+
|
| 1076 |
+
See Also
|
| 1077 |
+
--------
|
| 1078 |
+
numpy.fft : Overall view of discrete Fourier transforms, with definitions
|
| 1079 |
+
and conventions used.
|
| 1080 |
+
fft2 : The forward 2-dimensional FFT, of which `ifft2` is the inverse.
|
| 1081 |
+
ifftn : The inverse of the *n*-dimensional FFT.
|
| 1082 |
+
fft : The one-dimensional FFT.
|
| 1083 |
+
ifft : The one-dimensional inverse FFT.
|
| 1084 |
+
|
| 1085 |
+
Notes
|
| 1086 |
+
-----
|
| 1087 |
+
`ifft2` is just `ifftn` with a different default for `axes`.
|
| 1088 |
+
|
| 1089 |
+
See `ifftn` for details and a plotting example, and `numpy.fft` for
|
| 1090 |
+
definition and conventions used.
|
| 1091 |
+
|
| 1092 |
+
Zero-padding, analogously with `ifft`, is performed by appending zeros to
|
| 1093 |
+
the input along the specified dimension. Although this is the common
|
| 1094 |
+
approach, it might lead to surprising results. If another form of zero
|
| 1095 |
+
padding is desired, it must be performed before `ifft2` is called.
|
| 1096 |
+
|
| 1097 |
+
Examples
|
| 1098 |
+
--------
|
| 1099 |
+
>>> a = 4 * np.eye(4)
|
| 1100 |
+
>>> np.fft.ifft2(a)
|
| 1101 |
+
array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], # may vary
|
| 1102 |
+
[0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],
|
| 1103 |
+
[0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
|
| 1104 |
+
[0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]])
|
| 1105 |
+
|
| 1106 |
+
"""
|
| 1107 |
+
return _raw_fftnd(a, s, axes, ifft, norm)
|
| 1108 |
+
|
| 1109 |
+
|
| 1110 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 1111 |
+
def rfftn(a, s=None, axes=None, norm=None):
|
| 1112 |
+
"""
|
| 1113 |
+
Compute the N-dimensional discrete Fourier Transform for real input.
|
| 1114 |
+
|
| 1115 |
+
This function computes the N-dimensional discrete Fourier Transform over
|
| 1116 |
+
any number of axes in an M-dimensional real array by means of the Fast
|
| 1117 |
+
Fourier Transform (FFT). By default, all axes are transformed, with the
|
| 1118 |
+
real transform performed over the last axis, while the remaining
|
| 1119 |
+
transforms are complex.
|
| 1120 |
+
|
| 1121 |
+
Parameters
|
| 1122 |
+
----------
|
| 1123 |
+
a : array_like
|
| 1124 |
+
Input array, taken to be real.
|
| 1125 |
+
s : sequence of ints, optional
|
| 1126 |
+
Shape (length along each transformed axis) to use from the input.
|
| 1127 |
+
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
| 1128 |
+
The final element of `s` corresponds to `n` for ``rfft(x, n)``, while
|
| 1129 |
+
for the remaining axes, it corresponds to `n` for ``fft(x, n)``.
|
| 1130 |
+
Along any axis, if the given shape is smaller than that of the input,
|
| 1131 |
+
the input is cropped. If it is larger, the input is padded with zeros.
|
| 1132 |
+
if `s` is not given, the shape of the input along the axes specified
|
| 1133 |
+
by `axes` is used.
|
| 1134 |
+
axes : sequence of ints, optional
|
| 1135 |
+
Axes over which to compute the FFT. If not given, the last ``len(s)``
|
| 1136 |
+
axes are used, or all axes if `s` is also not specified.
|
| 1137 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 1138 |
+
.. versionadded:: 1.10.0
|
| 1139 |
+
|
| 1140 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 1141 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 1142 |
+
is scaled and with what normalization factor.
|
| 1143 |
+
|
| 1144 |
+
.. versionadded:: 1.20.0
|
| 1145 |
+
|
| 1146 |
+
The "backward", "forward" values were added.
|
| 1147 |
+
|
| 1148 |
+
Returns
|
| 1149 |
+
-------
|
| 1150 |
+
out : complex ndarray
|
| 1151 |
+
The truncated or zero-padded input, transformed along the axes
|
| 1152 |
+
indicated by `axes`, or by a combination of `s` and `a`,
|
| 1153 |
+
as explained in the parameters section above.
|
| 1154 |
+
The length of the last axis transformed will be ``s[-1]//2+1``,
|
| 1155 |
+
while the remaining transformed axes will have lengths according to
|
| 1156 |
+
`s`, or unchanged from the input.
|
| 1157 |
+
|
| 1158 |
+
Raises
|
| 1159 |
+
------
|
| 1160 |
+
ValueError
|
| 1161 |
+
If `s` and `axes` have different length.
|
| 1162 |
+
IndexError
|
| 1163 |
+
If an element of `axes` is larger than than the number of axes of `a`.
|
| 1164 |
+
|
| 1165 |
+
See Also
|
| 1166 |
+
--------
|
| 1167 |
+
irfftn : The inverse of `rfftn`, i.e. the inverse of the n-dimensional FFT
|
| 1168 |
+
of real input.
|
| 1169 |
+
fft : The one-dimensional FFT, with definitions and conventions used.
|
| 1170 |
+
rfft : The one-dimensional FFT of real input.
|
| 1171 |
+
fftn : The n-dimensional FFT.
|
| 1172 |
+
rfft2 : The two-dimensional FFT of real input.
|
| 1173 |
+
|
| 1174 |
+
Notes
|
| 1175 |
+
-----
|
| 1176 |
+
The transform for real input is performed over the last transformation
|
| 1177 |
+
axis, as by `rfft`, then the transform over the remaining axes is
|
| 1178 |
+
performed as by `fftn`. The order of the output is as for `rfft` for the
|
| 1179 |
+
final transformation axis, and as for `fftn` for the remaining
|
| 1180 |
+
transformation axes.
|
| 1181 |
+
|
| 1182 |
+
See `fft` for details, definitions and conventions used.
|
| 1183 |
+
|
| 1184 |
+
Examples
|
| 1185 |
+
--------
|
| 1186 |
+
>>> a = np.ones((2, 2, 2))
|
| 1187 |
+
>>> np.fft.rfftn(a)
|
| 1188 |
+
array([[[8.+0.j, 0.+0.j], # may vary
|
| 1189 |
+
[0.+0.j, 0.+0.j]],
|
| 1190 |
+
[[0.+0.j, 0.+0.j],
|
| 1191 |
+
[0.+0.j, 0.+0.j]]])
|
| 1192 |
+
|
| 1193 |
+
>>> np.fft.rfftn(a, axes=(2, 0))
|
| 1194 |
+
array([[[4.+0.j, 0.+0.j], # may vary
|
| 1195 |
+
[4.+0.j, 0.+0.j]],
|
| 1196 |
+
[[0.+0.j, 0.+0.j],
|
| 1197 |
+
[0.+0.j, 0.+0.j]]])
|
| 1198 |
+
|
| 1199 |
+
"""
|
| 1200 |
+
a = asarray(a)
|
| 1201 |
+
s, axes = _cook_nd_args(a, s, axes)
|
| 1202 |
+
a = rfft(a, s[-1], axes[-1], norm)
|
| 1203 |
+
for ii in range(len(axes)-1):
|
| 1204 |
+
a = fft(a, s[ii], axes[ii], norm)
|
| 1205 |
+
return a
|
| 1206 |
+
|
| 1207 |
+
|
| 1208 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 1209 |
+
def rfft2(a, s=None, axes=(-2, -1), norm=None):
|
| 1210 |
+
"""
|
| 1211 |
+
Compute the 2-dimensional FFT of a real array.
|
| 1212 |
+
|
| 1213 |
+
Parameters
|
| 1214 |
+
----------
|
| 1215 |
+
a : array
|
| 1216 |
+
Input array, taken to be real.
|
| 1217 |
+
s : sequence of ints, optional
|
| 1218 |
+
Shape of the FFT.
|
| 1219 |
+
axes : sequence of ints, optional
|
| 1220 |
+
Axes over which to compute the FFT.
|
| 1221 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 1222 |
+
.. versionadded:: 1.10.0
|
| 1223 |
+
|
| 1224 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 1225 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 1226 |
+
is scaled and with what normalization factor.
|
| 1227 |
+
|
| 1228 |
+
.. versionadded:: 1.20.0
|
| 1229 |
+
|
| 1230 |
+
The "backward", "forward" values were added.
|
| 1231 |
+
|
| 1232 |
+
Returns
|
| 1233 |
+
-------
|
| 1234 |
+
out : ndarray
|
| 1235 |
+
The result of the real 2-D FFT.
|
| 1236 |
+
|
| 1237 |
+
See Also
|
| 1238 |
+
--------
|
| 1239 |
+
rfftn : Compute the N-dimensional discrete Fourier Transform for real
|
| 1240 |
+
input.
|
| 1241 |
+
|
| 1242 |
+
Notes
|
| 1243 |
+
-----
|
| 1244 |
+
This is really just `rfftn` with different default behavior.
|
| 1245 |
+
For more details see `rfftn`.
|
| 1246 |
+
|
| 1247 |
+
Examples
|
| 1248 |
+
--------
|
| 1249 |
+
>>> a = np.mgrid[:5, :5][0]
|
| 1250 |
+
>>> np.fft.rfft2(a)
|
| 1251 |
+
array([[ 50. +0.j , 0. +0.j , 0. +0.j ],
|
| 1252 |
+
[-12.5+17.20477401j, 0. +0.j , 0. +0.j ],
|
| 1253 |
+
[-12.5 +4.0614962j , 0. +0.j , 0. +0.j ],
|
| 1254 |
+
[-12.5 -4.0614962j , 0. +0.j , 0. +0.j ],
|
| 1255 |
+
[-12.5-17.20477401j, 0. +0.j , 0. +0.j ]])
|
| 1256 |
+
"""
|
| 1257 |
+
return rfftn(a, s, axes, norm)
|
| 1258 |
+
|
| 1259 |
+
|
| 1260 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 1261 |
+
def irfftn(a, s=None, axes=None, norm=None):
|
| 1262 |
+
"""
|
| 1263 |
+
Computes the inverse of `rfftn`.
|
| 1264 |
+
|
| 1265 |
+
This function computes the inverse of the N-dimensional discrete
|
| 1266 |
+
Fourier Transform for real input over any number of axes in an
|
| 1267 |
+
M-dimensional array by means of the Fast Fourier Transform (FFT). In
|
| 1268 |
+
other words, ``irfftn(rfftn(a), a.shape) == a`` to within numerical
|
| 1269 |
+
accuracy. (The ``a.shape`` is necessary like ``len(a)`` is for `irfft`,
|
| 1270 |
+
and for the same reason.)
|
| 1271 |
+
|
| 1272 |
+
The input should be ordered in the same way as is returned by `rfftn`,
|
| 1273 |
+
i.e. as for `irfft` for the final transformation axis, and as for `ifftn`
|
| 1274 |
+
along all the other axes.
|
| 1275 |
+
|
| 1276 |
+
Parameters
|
| 1277 |
+
----------
|
| 1278 |
+
a : array_like
|
| 1279 |
+
Input array.
|
| 1280 |
+
s : sequence of ints, optional
|
| 1281 |
+
Shape (length of each transformed axis) of the output
|
| 1282 |
+
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.). `s` is also the
|
| 1283 |
+
number of input points used along this axis, except for the last axis,
|
| 1284 |
+
where ``s[-1]//2+1`` points of the input are used.
|
| 1285 |
+
Along any axis, if the shape indicated by `s` is smaller than that of
|
| 1286 |
+
the input, the input is cropped. If it is larger, the input is padded
|
| 1287 |
+
with zeros. If `s` is not given, the shape of the input along the axes
|
| 1288 |
+
specified by axes is used. Except for the last axis which is taken to
|
| 1289 |
+
be ``2*(m-1)`` where ``m`` is the length of the input along that axis.
|
| 1290 |
+
axes : sequence of ints, optional
|
| 1291 |
+
Axes over which to compute the inverse FFT. If not given, the last
|
| 1292 |
+
`len(s)` axes are used, or all axes if `s` is also not specified.
|
| 1293 |
+
Repeated indices in `axes` means that the inverse transform over that
|
| 1294 |
+
axis is performed multiple times.
|
| 1295 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 1296 |
+
.. versionadded:: 1.10.0
|
| 1297 |
+
|
| 1298 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 1299 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 1300 |
+
is scaled and with what normalization factor.
|
| 1301 |
+
|
| 1302 |
+
.. versionadded:: 1.20.0
|
| 1303 |
+
|
| 1304 |
+
The "backward", "forward" values were added.
|
| 1305 |
+
|
| 1306 |
+
Returns
|
| 1307 |
+
-------
|
| 1308 |
+
out : ndarray
|
| 1309 |
+
The truncated or zero-padded input, transformed along the axes
|
| 1310 |
+
indicated by `axes`, or by a combination of `s` or `a`,
|
| 1311 |
+
as explained in the parameters section above.
|
| 1312 |
+
The length of each transformed axis is as given by the corresponding
|
| 1313 |
+
element of `s`, or the length of the input in every axis except for the
|
| 1314 |
+
last one if `s` is not given. In the final transformed axis the length
|
| 1315 |
+
of the output when `s` is not given is ``2*(m-1)`` where ``m`` is the
|
| 1316 |
+
length of the final transformed axis of the input. To get an odd
|
| 1317 |
+
number of output points in the final axis, `s` must be specified.
|
| 1318 |
+
|
| 1319 |
+
Raises
|
| 1320 |
+
------
|
| 1321 |
+
ValueError
|
| 1322 |
+
If `s` and `axes` have different length.
|
| 1323 |
+
IndexError
|
| 1324 |
+
If an element of `axes` is larger than than the number of axes of `a`.
|
| 1325 |
+
|
| 1326 |
+
See Also
|
| 1327 |
+
--------
|
| 1328 |
+
rfftn : The forward n-dimensional FFT of real input,
|
| 1329 |
+
of which `ifftn` is the inverse.
|
| 1330 |
+
fft : The one-dimensional FFT, with definitions and conventions used.
|
| 1331 |
+
irfft : The inverse of the one-dimensional FFT of real input.
|
| 1332 |
+
irfft2 : The inverse of the two-dimensional FFT of real input.
|
| 1333 |
+
|
| 1334 |
+
Notes
|
| 1335 |
+
-----
|
| 1336 |
+
See `fft` for definitions and conventions used.
|
| 1337 |
+
|
| 1338 |
+
See `rfft` for definitions and conventions used for real input.
|
| 1339 |
+
|
| 1340 |
+
The correct interpretation of the hermitian input depends on the shape of
|
| 1341 |
+
the original data, as given by `s`. This is because each input shape could
|
| 1342 |
+
correspond to either an odd or even length signal. By default, `irfftn`
|
| 1343 |
+
assumes an even output length which puts the last entry at the Nyquist
|
| 1344 |
+
frequency; aliasing with its symmetric counterpart. When performing the
|
| 1345 |
+
final complex to real transform, the last value is thus treated as purely
|
| 1346 |
+
real. To avoid losing information, the correct shape of the real input
|
| 1347 |
+
**must** be given.
|
| 1348 |
+
|
| 1349 |
+
Examples
|
| 1350 |
+
--------
|
| 1351 |
+
>>> a = np.zeros((3, 2, 2))
|
| 1352 |
+
>>> a[0, 0, 0] = 3 * 2 * 2
|
| 1353 |
+
>>> np.fft.irfftn(a)
|
| 1354 |
+
array([[[1., 1.],
|
| 1355 |
+
[1., 1.]],
|
| 1356 |
+
[[1., 1.],
|
| 1357 |
+
[1., 1.]],
|
| 1358 |
+
[[1., 1.],
|
| 1359 |
+
[1., 1.]]])
|
| 1360 |
+
|
| 1361 |
+
"""
|
| 1362 |
+
a = asarray(a)
|
| 1363 |
+
s, axes = _cook_nd_args(a, s, axes, invreal=1)
|
| 1364 |
+
for ii in range(len(axes)-1):
|
| 1365 |
+
a = ifft(a, s[ii], axes[ii], norm)
|
| 1366 |
+
a = irfft(a, s[-1], axes[-1], norm)
|
| 1367 |
+
return a
|
| 1368 |
+
|
| 1369 |
+
|
| 1370 |
+
@array_function_dispatch(_fftn_dispatcher)
|
| 1371 |
+
def irfft2(a, s=None, axes=(-2, -1), norm=None):
|
| 1372 |
+
"""
|
| 1373 |
+
Computes the inverse of `rfft2`.
|
| 1374 |
+
|
| 1375 |
+
Parameters
|
| 1376 |
+
----------
|
| 1377 |
+
a : array_like
|
| 1378 |
+
The input array
|
| 1379 |
+
s : sequence of ints, optional
|
| 1380 |
+
Shape of the real output to the inverse FFT.
|
| 1381 |
+
axes : sequence of ints, optional
|
| 1382 |
+
The axes over which to compute the inverse fft.
|
| 1383 |
+
Default is the last two axes.
|
| 1384 |
+
norm : {"backward", "ortho", "forward"}, optional
|
| 1385 |
+
.. versionadded:: 1.10.0
|
| 1386 |
+
|
| 1387 |
+
Normalization mode (see `numpy.fft`). Default is "backward".
|
| 1388 |
+
Indicates which direction of the forward/backward pair of transforms
|
| 1389 |
+
is scaled and with what normalization factor.
|
| 1390 |
+
|
| 1391 |
+
.. versionadded:: 1.20.0
|
| 1392 |
+
|
| 1393 |
+
The "backward", "forward" values were added.
|
| 1394 |
+
|
| 1395 |
+
Returns
|
| 1396 |
+
-------
|
| 1397 |
+
out : ndarray
|
| 1398 |
+
The result of the inverse real 2-D FFT.
|
| 1399 |
+
|
| 1400 |
+
See Also
|
| 1401 |
+
--------
|
| 1402 |
+
rfft2 : The forward two-dimensional FFT of real input,
|
| 1403 |
+
of which `irfft2` is the inverse.
|
| 1404 |
+
rfft : The one-dimensional FFT for real input.
|
| 1405 |
+
irfft : The inverse of the one-dimensional FFT of real input.
|
| 1406 |
+
irfftn : Compute the inverse of the N-dimensional FFT of real input.
|
| 1407 |
+
|
| 1408 |
+
Notes
|
| 1409 |
+
-----
|
| 1410 |
+
This is really `irfftn` with different defaults.
|
| 1411 |
+
For more details see `irfftn`.
|
| 1412 |
+
|
| 1413 |
+
Examples
|
| 1414 |
+
--------
|
| 1415 |
+
>>> a = np.mgrid[:5, :5][0]
|
| 1416 |
+
>>> A = np.fft.rfft2(a)
|
| 1417 |
+
>>> np.fft.irfft2(A, s=a.shape)
|
| 1418 |
+
array([[0., 0., 0., 0., 0.],
|
| 1419 |
+
[1., 1., 1., 1., 1.],
|
| 1420 |
+
[2., 2., 2., 2., 2.],
|
| 1421 |
+
[3., 3., 3., 3., 3.],
|
| 1422 |
+
[4., 4., 4., 4., 4.]])
|
| 1423 |
+
"""
|
| 1424 |
+
return irfftn(a, s, axes, norm)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/fft/_pocketfft_internal.cpython-312-x86_64-linux-gnu.so
ADDED
|
Binary file (97 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/fft/helper.pyi
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, TypeVar, overload
|
| 2 |
+
|
| 3 |
+
from numpy import generic, integer, floating, complexfloating
|
| 4 |
+
from numpy._typing import (
|
| 5 |
+
NDArray,
|
| 6 |
+
ArrayLike,
|
| 7 |
+
_ShapeLike,
|
| 8 |
+
_ArrayLike,
|
| 9 |
+
_ArrayLikeFloat_co,
|
| 10 |
+
_ArrayLikeComplex_co,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
_SCT = TypeVar("_SCT", bound=generic)
|
| 14 |
+
|
| 15 |
+
__all__: list[str]
|
| 16 |
+
|
| 17 |
+
@overload
|
| 18 |
+
def fftshift(x: _ArrayLike[_SCT], axes: None | _ShapeLike = ...) -> NDArray[_SCT]: ...
|
| 19 |
+
@overload
|
| 20 |
+
def fftshift(x: ArrayLike, axes: None | _ShapeLike = ...) -> NDArray[Any]: ...
|
| 21 |
+
|
| 22 |
+
@overload
|
| 23 |
+
def ifftshift(x: _ArrayLike[_SCT], axes: None | _ShapeLike = ...) -> NDArray[_SCT]: ...
|
| 24 |
+
@overload
|
| 25 |
+
def ifftshift(x: ArrayLike, axes: None | _ShapeLike = ...) -> NDArray[Any]: ...
|
| 26 |
+
|
| 27 |
+
@overload
|
| 28 |
+
def fftfreq(
|
| 29 |
+
n: int | integer[Any],
|
| 30 |
+
d: _ArrayLikeFloat_co = ...,
|
| 31 |
+
) -> NDArray[floating[Any]]: ...
|
| 32 |
+
@overload
|
| 33 |
+
def fftfreq(
|
| 34 |
+
n: int | integer[Any],
|
| 35 |
+
d: _ArrayLikeComplex_co = ...,
|
| 36 |
+
) -> NDArray[complexfloating[Any, Any]]: ...
|
| 37 |
+
|
| 38 |
+
@overload
|
| 39 |
+
def rfftfreq(
|
| 40 |
+
n: int | integer[Any],
|
| 41 |
+
d: _ArrayLikeFloat_co = ...,
|
| 42 |
+
) -> NDArray[floating[Any]]: ...
|
| 43 |
+
@overload
|
| 44 |
+
def rfftfreq(
|
| 45 |
+
n: int | integer[Any],
|
| 46 |
+
d: _ArrayLikeComplex_co = ...,
|
| 47 |
+
) -> NDArray[complexfloating[Any, Any]]: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/typing/tests/data/pass/__pycache__/array_like.cpython-312.pyc
ADDED
|
Binary file (2.28 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/numpy/typing/tests/data/pass/__pycache__/simple.cpython-312.pyc
ADDED
|
Binary file (4.59 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_acc/__init__.pyi
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from torch import Tensor
|
| 2 |
+
from torch.types import _dtype, _int, Device
|
| 3 |
+
|
| 4 |
+
# Defined in torch/csrc/acc/Module.cpp
|
| 5 |
+
class PrivateUse1Hooks:
|
| 6 |
+
def has_primary_context(self, device_index: _int) -> bool: ...
|
| 7 |
+
def is_built(self) -> bool: ...
|
| 8 |
+
def is_avaible(self) -> bool: ...
|
| 9 |
+
|
| 10 |
+
class DeviceGuard:
|
| 11 |
+
def type_(self) -> Device: ...
|
| 12 |
+
|
| 13 |
+
def register_python_privateuseone_device_guard(guard: DeviceGuard) -> bool: ...
|
| 14 |
+
def register_python_privateuseone_hook(hook: PrivateUse1Hooks) -> bool: ...
|
| 15 |
+
def create_empty_tensor(shape: tuple[_int, ...], dtype: _dtype) -> Tensor: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_dynamo/__init__.pyi
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import compiled_autograd, eval_frame, guards # noqa: F401
|
| 2 |
+
|
| 3 |
+
def strip_function_call(name: str) -> str: ...
|
| 4 |
+
def is_valid_var_name(name: str) -> bool | int: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_dynamo/compiled_autograd.pyi
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Callable
|
| 2 |
+
|
| 3 |
+
from torch import Tensor
|
| 4 |
+
from torch._dynamo.compiled_autograd import AutogradCompilerInstance
|
| 5 |
+
|
| 6 |
+
def set_autograd_compiler(
|
| 7 |
+
autograd_compiler: Callable[[], AutogradCompilerInstance] | None,
|
| 8 |
+
dynamic: bool,
|
| 9 |
+
) -> tuple[Callable[[], AutogradCompilerInstance] | None, bool]: ...
|
| 10 |
+
def clear_cache() -> None: ...
|
| 11 |
+
def is_cache_empty() -> bool: ...
|
| 12 |
+
def set_verbose_logger(fn: Callable[[str], None] | None) -> bool: ...
|
| 13 |
+
def call_cpp_tensor_pre_hooks(idx: int, grad: Tensor) -> Tensor: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_dynamo/eval_frame.pyi
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import enum
|
| 2 |
+
import types
|
| 3 |
+
from collections.abc import Callable
|
| 4 |
+
from typing import Optional, overload
|
| 5 |
+
|
| 6 |
+
from torch._dynamo.guards import GuardManagerWrapper
|
| 7 |
+
from torch._dynamo.types import DynamoCallback, DynamoGuardCompleteHook, DynamoGuardHook
|
| 8 |
+
from torch._guards import CompileId
|
| 9 |
+
|
| 10 |
+
def set_eval_frame(callback: DynamoCallback) -> DynamoCallback: ...
|
| 11 |
+
def set_skip_guard_eval_unsafe(value: bool) -> bool: ...
|
| 12 |
+
def get_eval_frame_callback() -> DynamoCallback: ...
|
| 13 |
+
def reset_code(code: types.CodeType) -> None: ...
|
| 14 |
+
def unsupported(obj1: object, obj2: object) -> object: ...
|
| 15 |
+
def set_code_exec_strategy(
|
| 16 |
+
code: types.CodeType, strategy: _FrameExecStrategy
|
| 17 |
+
) -> None: ...
|
| 18 |
+
def set_guard_error_hook(hook: DynamoGuardHook) -> None: ...
|
| 19 |
+
def set_guard_complete_hook(
|
| 20 |
+
hook: Optional[DynamoGuardCompleteHook],
|
| 21 |
+
) -> Optional[DynamoGuardCompleteHook]: ...
|
| 22 |
+
def raise_sigtrap() -> None: ...
|
| 23 |
+
def set_c_recursion_limit(limit: int) -> None: ...
|
| 24 |
+
def get_c_recursion_limit() -> int: ...
|
| 25 |
+
|
| 26 |
+
class _CacheEntry:
|
| 27 |
+
def check_fn(self, *args: object, **kwargs: object) -> bool: ...
|
| 28 |
+
def update_diff_guard_root_manager(self) -> None: ...
|
| 29 |
+
code: types.CodeType
|
| 30 |
+
compile_id: CompileId
|
| 31 |
+
# If we run into circular issues, just use object
|
| 32 |
+
guard_manager: GuardManagerWrapper
|
| 33 |
+
backend: Callable
|
| 34 |
+
next: _CacheEntry | None
|
| 35 |
+
|
| 36 |
+
class _PrecompileEntry:
|
| 37 |
+
guard_manager: GuardManagerWrapper
|
| 38 |
+
|
| 39 |
+
class _ExtraState:
|
| 40 |
+
def invalidate(
|
| 41 |
+
self, cache_entry: _CacheEntry, guard_manager: GuardManagerWrapper
|
| 42 |
+
) -> None: ...
|
| 43 |
+
|
| 44 |
+
class _FrameAction(enum.IntEnum):
|
| 45 |
+
DEFAULT = 0
|
| 46 |
+
SKIP = 1
|
| 47 |
+
RUN_ONLY = 2
|
| 48 |
+
|
| 49 |
+
class _FrameExecStrategy:
|
| 50 |
+
cur_action: _FrameAction
|
| 51 |
+
recursive_action: _FrameAction
|
| 52 |
+
|
| 53 |
+
@overload
|
| 54 |
+
def __init__(self) -> None: ...
|
| 55 |
+
@overload
|
| 56 |
+
def __init__(
|
| 57 |
+
self, cur_action: _FrameAction, recursive_action: _FrameAction
|
| 58 |
+
) -> None: ...
|
| 59 |
+
|
| 60 |
+
# This is an object that encapsulates the Python FrameType, and exposes
|
| 61 |
+
# properties Dynamo cares about for a frame.
|
| 62 |
+
class _PyInterpreterFrame:
|
| 63 |
+
f_code: types.CodeType
|
| 64 |
+
f_locals: dict[str, object]
|
| 65 |
+
f_globals: dict[str, object]
|
| 66 |
+
f_builtins: dict[str, object]
|
| 67 |
+
f_lasti: int
|
| 68 |
+
f_lineno: int
|
| 69 |
+
f_back: types.FrameType
|
| 70 |
+
# A tuple containing cell objects captured by this frame.
|
| 71 |
+
closure: tuple[types.CellType]
|
| 72 |
+
|
| 73 |
+
def _debug_get_cache_entry_list(code: types.CodeType) -> list[_CacheEntry]: ...
|
| 74 |
+
|
| 75 |
+
py_opcode_caches: list[int]
|
| 76 |
+
|
| 77 |
+
def code_framelocals_names(code: types.CodeType) -> tuple[str, ...]: ...
|
| 78 |
+
def _load_precompile_entry(
|
| 79 |
+
code: types.CodeType,
|
| 80 |
+
guard_manager: GuardManagerWrapper,
|
| 81 |
+
dynamo_code: types.CodeType,
|
| 82 |
+
) -> None: ...
|
| 83 |
+
def _reset_precompile_entries(code: types.CodeType) -> None: ...
|
| 84 |
+
def _debug_get_precompile_entries(code: types.CodeType) -> list[_PrecompileEntry]: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_dynamo/guards.pyi
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import enum
|
| 2 |
+
from collections.abc import Callable
|
| 3 |
+
from typing import Any, Optional, TypeAlias
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
# TODO: We should move the `GuardManagerType`
|
| 8 |
+
# defined in `guards.py` here and update other
|
| 9 |
+
# imports
|
| 10 |
+
GuardManagerType: TypeAlias = enum.Enum
|
| 11 |
+
|
| 12 |
+
class GlobalStateGuard:
|
| 13 |
+
def check(self) -> bool: ...
|
| 14 |
+
def reason(self) -> str: ...
|
| 15 |
+
|
| 16 |
+
class LeafGuard:
|
| 17 |
+
def verbose_code_parts(self) -> list[str]: ...
|
| 18 |
+
|
| 19 |
+
class RelationalGuard: ...
|
| 20 |
+
|
| 21 |
+
class GuardDebugInfo:
|
| 22 |
+
verbose_code_parts: list[str]
|
| 23 |
+
result: bool
|
| 24 |
+
num_guards_executed: int
|
| 25 |
+
|
| 26 |
+
class GuardManager:
|
| 27 |
+
def check(self, value: Any) -> bool: ...
|
| 28 |
+
def check_verbose(self, value: Any) -> GuardDebugInfo: ...
|
| 29 |
+
|
| 30 |
+
# Accessors
|
| 31 |
+
def globals_dict_manager(
|
| 32 |
+
self,
|
| 33 |
+
f_globals: dict[str, Any],
|
| 34 |
+
source: str,
|
| 35 |
+
example_value: Any,
|
| 36 |
+
guard_manager_enum: GuardManagerType,
|
| 37 |
+
) -> GuardManager: ...
|
| 38 |
+
def framelocals_manager(
|
| 39 |
+
self,
|
| 40 |
+
key: tuple[str, int],
|
| 41 |
+
source: str,
|
| 42 |
+
example_value: Any,
|
| 43 |
+
guard_manager_enum: GuardManagerType,
|
| 44 |
+
) -> GuardManager: ...
|
| 45 |
+
def dict_getitem_manager(
|
| 46 |
+
self,
|
| 47 |
+
key: Any,
|
| 48 |
+
source: str,
|
| 49 |
+
example_value: Any,
|
| 50 |
+
guard_manager_enum: GuardManagerType,
|
| 51 |
+
) -> GuardManager: ...
|
| 52 |
+
def grad_manager(
|
| 53 |
+
self,
|
| 54 |
+
source: str,
|
| 55 |
+
example_value: Any,
|
| 56 |
+
guard_manager_enum: GuardManagerType,
|
| 57 |
+
) -> GuardManager: ...
|
| 58 |
+
def generic_getattr_manager(
|
| 59 |
+
self,
|
| 60 |
+
attr: str,
|
| 61 |
+
source: str,
|
| 62 |
+
example_value: Any,
|
| 63 |
+
guard_manager_enum: GuardManagerType,
|
| 64 |
+
) -> GuardManager: ...
|
| 65 |
+
def getitem_manager(
|
| 66 |
+
self,
|
| 67 |
+
key: Any,
|
| 68 |
+
source: str,
|
| 69 |
+
example_value: Any,
|
| 70 |
+
guard_manager_enum: GuardManagerType,
|
| 71 |
+
) -> GuardManager: ...
|
| 72 |
+
def get_generic_dict_manager(
|
| 73 |
+
self,
|
| 74 |
+
source: str,
|
| 75 |
+
example_value: Any,
|
| 76 |
+
guard_manager_enum: GuardManagerType,
|
| 77 |
+
) -> GuardManager: ...
|
| 78 |
+
def list_getitem_manager(
|
| 79 |
+
self,
|
| 80 |
+
key: Any,
|
| 81 |
+
source: str,
|
| 82 |
+
example_value: Any,
|
| 83 |
+
guard_manager_enum: GuardManagerType,
|
| 84 |
+
) -> GuardManager: ...
|
| 85 |
+
def tuple_getitem_manager(
|
| 86 |
+
self,
|
| 87 |
+
key: Any,
|
| 88 |
+
source: str,
|
| 89 |
+
example_value: Any,
|
| 90 |
+
guard_manager_enum: GuardManagerType,
|
| 91 |
+
) -> GuardManager: ...
|
| 92 |
+
def set_getitem_manager(
|
| 93 |
+
self,
|
| 94 |
+
index: Any,
|
| 95 |
+
source: str,
|
| 96 |
+
example_value: Any,
|
| 97 |
+
guard_manager_enum: GuardManagerType,
|
| 98 |
+
) -> GuardManager: ...
|
| 99 |
+
def func_defaults_manager(
|
| 100 |
+
self,
|
| 101 |
+
source: str,
|
| 102 |
+
example_value: Any,
|
| 103 |
+
guard_manager_enum: GuardManagerType,
|
| 104 |
+
) -> GuardManager: ...
|
| 105 |
+
def func_kwdefaults_manager(
|
| 106 |
+
self,
|
| 107 |
+
source: str,
|
| 108 |
+
example_value: Any,
|
| 109 |
+
guard_manager_enum: GuardManagerType,
|
| 110 |
+
) -> GuardManager: ...
|
| 111 |
+
def tuple_iterator_getitem_manager(
|
| 112 |
+
self,
|
| 113 |
+
index: Any,
|
| 114 |
+
source: str,
|
| 115 |
+
example_value: Any,
|
| 116 |
+
guard_manager_enum: GuardManagerType,
|
| 117 |
+
) -> GuardManager: ...
|
| 118 |
+
def weakref_call_manager(
|
| 119 |
+
self,
|
| 120 |
+
source: str,
|
| 121 |
+
example_value: Any,
|
| 122 |
+
guard_manager_enum: GuardManagerType,
|
| 123 |
+
) -> GuardManager: ...
|
| 124 |
+
def call_function_no_args_manager(
|
| 125 |
+
self,
|
| 126 |
+
source: str,
|
| 127 |
+
example_value: Any,
|
| 128 |
+
guard_manager_enum: GuardManagerType,
|
| 129 |
+
) -> GuardManager: ...
|
| 130 |
+
def global_weakref_manager(
|
| 131 |
+
self,
|
| 132 |
+
global_name: str,
|
| 133 |
+
source: str,
|
| 134 |
+
example_value: Any,
|
| 135 |
+
guard_manager_enum: GuardManagerType,
|
| 136 |
+
) -> GuardManager: ...
|
| 137 |
+
def type_manager(
|
| 138 |
+
self,
|
| 139 |
+
source: str,
|
| 140 |
+
example_value: Any,
|
| 141 |
+
guard_manager_enum: GuardManagerType,
|
| 142 |
+
) -> GuardManager: ...
|
| 143 |
+
def getattr_manager(
|
| 144 |
+
self,
|
| 145 |
+
attr: str,
|
| 146 |
+
source: str,
|
| 147 |
+
example_value: Any,
|
| 148 |
+
guard_manager_enum: GuardManagerType,
|
| 149 |
+
) -> GuardManager: ...
|
| 150 |
+
def tensor_property_size_manager(
|
| 151 |
+
self,
|
| 152 |
+
idx: int,
|
| 153 |
+
source: str,
|
| 154 |
+
example_value: Any,
|
| 155 |
+
guard_manager_enum: GuardManagerType,
|
| 156 |
+
) -> GuardManager: ...
|
| 157 |
+
def tensor_property_shape_manager(
|
| 158 |
+
self,
|
| 159 |
+
idx: int,
|
| 160 |
+
source: str,
|
| 161 |
+
example_value: Any,
|
| 162 |
+
guard_manager_enum: GuardManagerType,
|
| 163 |
+
) -> GuardManager: ...
|
| 164 |
+
def tensor_property_storage_offset_manager(
|
| 165 |
+
self,
|
| 166 |
+
idx: int,
|
| 167 |
+
source: str,
|
| 168 |
+
example_value: Any,
|
| 169 |
+
guard_manager_enum: GuardManagerType,
|
| 170 |
+
) -> GuardManager: ...
|
| 171 |
+
def indexed_manager(
|
| 172 |
+
self,
|
| 173 |
+
idx: int,
|
| 174 |
+
source: str,
|
| 175 |
+
example_value: Any,
|
| 176 |
+
guard_manager_enum: GuardManagerType,
|
| 177 |
+
) -> GuardManager: ...
|
| 178 |
+
def lambda_manager(
|
| 179 |
+
self,
|
| 180 |
+
python_lambda: Callable[..., Any],
|
| 181 |
+
source: str,
|
| 182 |
+
example_value: Any,
|
| 183 |
+
guard_manager_enum: GuardManagerType,
|
| 184 |
+
) -> GuardManager: ...
|
| 185 |
+
def get_root(self) -> RootGuardManager: ...
|
| 186 |
+
def get_source(self) -> str: ...
|
| 187 |
+
def fail_count(self) -> int: ...
|
| 188 |
+
def get_child_managers(self) -> list[GuardManager]: ...
|
| 189 |
+
def repr(self) -> str: ...
|
| 190 |
+
def type_of_guarded_value(self) -> str: ...
|
| 191 |
+
def get_leaf_guards(self) -> list[LeafGuard]: ...
|
| 192 |
+
def get_accessors(self) -> list[GuardManager]: ...
|
| 193 |
+
def is_guarded_value_immutable(self) -> bool: ...
|
| 194 |
+
def is_tag_safe(self) -> bool: ...
|
| 195 |
+
def is_tag_safe_root(self) -> bool: ...
|
| 196 |
+
def has_no_accessors(self) -> bool: ...
|
| 197 |
+
def has_object_aliasing_guard(self) -> bool: ...
|
| 198 |
+
def get_type_of_guarded_value(self) -> type: ...
|
| 199 |
+
def type_dict_manager(
|
| 200 |
+
self,
|
| 201 |
+
source: str,
|
| 202 |
+
example_value: Any,
|
| 203 |
+
guard_manager_enum: GuardManagerType,
|
| 204 |
+
) -> GuardManager: ...
|
| 205 |
+
def type_mro_manager(
|
| 206 |
+
self,
|
| 207 |
+
source: str,
|
| 208 |
+
example_value: Any,
|
| 209 |
+
guard_manager_enum: GuardManagerType,
|
| 210 |
+
) -> GuardManager: ...
|
| 211 |
+
def code_manager(
|
| 212 |
+
self,
|
| 213 |
+
source: str,
|
| 214 |
+
example_value: Any,
|
| 215 |
+
guard_manager_enum: GuardManagerType,
|
| 216 |
+
) -> GuardManager: ...
|
| 217 |
+
def closure_manager(
|
| 218 |
+
self,
|
| 219 |
+
source: str,
|
| 220 |
+
example_value: Any,
|
| 221 |
+
guard_manager_enum: GuardManagerType,
|
| 222 |
+
) -> GuardManager: ...
|
| 223 |
+
# Leaf guards
|
| 224 |
+
def add_lambda_guard(
|
| 225 |
+
self, user_lambda: Callable[..., Any], verbose_code_parts: list[str]
|
| 226 |
+
) -> None: ...
|
| 227 |
+
def add_id_match_guard(
|
| 228 |
+
self, id_val: int, verbose_code_parts: list[str]
|
| 229 |
+
) -> None: ...
|
| 230 |
+
def add_equals_match_guard(
|
| 231 |
+
self,
|
| 232 |
+
equals_val: Any,
|
| 233 |
+
verbose_code_parts: list[str],
|
| 234 |
+
) -> None: ...
|
| 235 |
+
def add_global_state_guard(
|
| 236 |
+
self, initial_state: Any, verbose_code_parts: list[str]
|
| 237 |
+
) -> None: ...
|
| 238 |
+
def add_torch_function_mode_stack_guard(
|
| 239 |
+
self, initial_stack: list[Any], verbose_code_parts: list[str]
|
| 240 |
+
) -> None: ...
|
| 241 |
+
def add_mapping_keys_guard(
|
| 242 |
+
self, value: Any, verbose_code_parts: list[str]
|
| 243 |
+
) -> None: ...
|
| 244 |
+
def add_dict_length_check_guard(
|
| 245 |
+
self, value: int, verbose_code_parts: list[str]
|
| 246 |
+
) -> None: ...
|
| 247 |
+
def add_length_check_guard(
|
| 248 |
+
self, value: int, verbose_code_parts: list[str]
|
| 249 |
+
) -> None: ...
|
| 250 |
+
def add_true_match_guard(
|
| 251 |
+
self,
|
| 252 |
+
verbose_code_parts: list[str],
|
| 253 |
+
) -> None: ...
|
| 254 |
+
def add_false_match_guard(
|
| 255 |
+
self,
|
| 256 |
+
verbose_code_parts: list[str],
|
| 257 |
+
) -> None: ...
|
| 258 |
+
def add_none_match_guard(
|
| 259 |
+
self,
|
| 260 |
+
verbose_code_parts: list[str],
|
| 261 |
+
) -> None: ...
|
| 262 |
+
def add_not_none_guard(
|
| 263 |
+
self,
|
| 264 |
+
verbose_code_parts: list[str],
|
| 265 |
+
) -> None: ...
|
| 266 |
+
def add_dispatch_key_set_guard(
|
| 267 |
+
self,
|
| 268 |
+
dispatch_key: Any,
|
| 269 |
+
verbose_code_parts: list[str],
|
| 270 |
+
) -> None: ...
|
| 271 |
+
def add_tensor_match_guard(
|
| 272 |
+
self,
|
| 273 |
+
value: Any,
|
| 274 |
+
sizes: list[int],
|
| 275 |
+
strides: list[int],
|
| 276 |
+
tensor_name: str,
|
| 277 |
+
verbose_code_parts: list[str],
|
| 278 |
+
ptype: Any,
|
| 279 |
+
dispatch_keys: Any,
|
| 280 |
+
) -> None: ...
|
| 281 |
+
def add_dynamic_indices_guard(
|
| 282 |
+
self,
|
| 283 |
+
value: set[Any],
|
| 284 |
+
verbose_code_parts: list[str],
|
| 285 |
+
) -> None: ...
|
| 286 |
+
def add_no_hasattr_guard(
|
| 287 |
+
self,
|
| 288 |
+
attr_name: str,
|
| 289 |
+
verbose_code_parts: list[str],
|
| 290 |
+
) -> None: ...
|
| 291 |
+
def add_dict_contains_guard(
|
| 292 |
+
self,
|
| 293 |
+
contains: bool,
|
| 294 |
+
key: Any,
|
| 295 |
+
verbose_code_parts: list[str],
|
| 296 |
+
) -> None: ...
|
| 297 |
+
def add_type_match_guard(
|
| 298 |
+
self,
|
| 299 |
+
value: int,
|
| 300 |
+
verbose_code_parts: list[str],
|
| 301 |
+
) -> None: ...
|
| 302 |
+
def add_dict_version_guard(
|
| 303 |
+
self,
|
| 304 |
+
value: Any,
|
| 305 |
+
verbose_code_parts: list[str],
|
| 306 |
+
) -> None: ...
|
| 307 |
+
def add_set_contains_guard(
|
| 308 |
+
self,
|
| 309 |
+
contains: bool,
|
| 310 |
+
item: Any,
|
| 311 |
+
verbose_code_parts: list[str],
|
| 312 |
+
) -> None: ...
|
| 313 |
+
def add_dual_level_match_guard(
|
| 314 |
+
self,
|
| 315 |
+
level: int,
|
| 316 |
+
verbose_code_parts: list[str],
|
| 317 |
+
) -> None: ...
|
| 318 |
+
def add_float_is_nan_guard(
|
| 319 |
+
self,
|
| 320 |
+
verbose_code_parts: list[str],
|
| 321 |
+
) -> None: ...
|
| 322 |
+
def add_complex_is_nan_guard(
|
| 323 |
+
self,
|
| 324 |
+
verbose_code_parts: list[str],
|
| 325 |
+
) -> None: ...
|
| 326 |
+
def add_tuple_iterator_length_guard(
|
| 327 |
+
self,
|
| 328 |
+
length: int,
|
| 329 |
+
type_id: int,
|
| 330 |
+
verbose_code_parts: list[str],
|
| 331 |
+
) -> None: ...
|
| 332 |
+
def add_range_iterator_match_guard(
|
| 333 |
+
self,
|
| 334 |
+
start: int,
|
| 335 |
+
stop: int,
|
| 336 |
+
step: int,
|
| 337 |
+
type_id: int,
|
| 338 |
+
verbose_code_parts: list[str],
|
| 339 |
+
) -> None: ...
|
| 340 |
+
def add_default_device_guard(
|
| 341 |
+
self,
|
| 342 |
+
verbose_code_parts: list[str],
|
| 343 |
+
) -> None: ...
|
| 344 |
+
def mark_tag_safe(self) -> None: ...
|
| 345 |
+
def mark_tag_safe_root(self) -> None: ...
|
| 346 |
+
|
| 347 |
+
class RootGuardManager(GuardManager):
|
| 348 |
+
def get_epilogue_lambda_guards(self) -> list[LeafGuard]: ...
|
| 349 |
+
def add_epilogue_lambda_guard(
|
| 350 |
+
self,
|
| 351 |
+
guard: LeafGuard,
|
| 352 |
+
verbose_code_parts: list[str],
|
| 353 |
+
) -> None: ...
|
| 354 |
+
def clone_manager(
|
| 355 |
+
self, clone_filter_fn: Callable[[GuardManager], bool]
|
| 356 |
+
) -> RootGuardManager: ...
|
| 357 |
+
def attach_compile_id(self, compile_id: str) -> None: ...
|
| 358 |
+
|
| 359 |
+
class DictGuardManager(GuardManager):
|
| 360 |
+
def get_key_manager(
|
| 361 |
+
self,
|
| 362 |
+
index: int,
|
| 363 |
+
source: str,
|
| 364 |
+
example_value: Any,
|
| 365 |
+
guard_manager_enum: GuardManagerType,
|
| 366 |
+
) -> GuardManager: ...
|
| 367 |
+
def get_value_manager(
|
| 368 |
+
self,
|
| 369 |
+
index: int,
|
| 370 |
+
source: str,
|
| 371 |
+
example_value: Any,
|
| 372 |
+
guard_manager_enum: GuardManagerType,
|
| 373 |
+
) -> GuardManager: ...
|
| 374 |
+
def get_key_value_managers(
|
| 375 |
+
self,
|
| 376 |
+
) -> dict[int, tuple[GuardManager, GuardManager]]: ...
|
| 377 |
+
|
| 378 |
+
# Guard accessor stubs
|
| 379 |
+
class GuardAccessor: ...
|
| 380 |
+
class DictGetItemGuardAccessor(GuardAccessor): ...
|
| 381 |
+
class GetGenericDictGuardAccessor(GuardAccessor): ...
|
| 382 |
+
class TypeDictGuardAccessor(GuardAccessor): ...
|
| 383 |
+
class TypeMROGuardAccessor(GuardAccessor): ...
|
| 384 |
+
class ClosureGuardAccessor(GuardAccessor): ...
|
| 385 |
+
class TupleGetItemGuardAccessor(GuardAccessor): ...
|
| 386 |
+
class TypeGuardAccessor(GuardAccessor): ...
|
| 387 |
+
class CodeGuardAccessor(GuardAccessor): ...
|
| 388 |
+
class FuncDefaultsGuardAccessor(GuardAccessor): ...
|
| 389 |
+
class FuncKwDefaultsGuardAccessor(GuardAccessor): ...
|
| 390 |
+
|
| 391 |
+
class GetAttrGuardAccessor(GuardAccessor):
|
| 392 |
+
def get_attr_name(self) -> str: ...
|
| 393 |
+
|
| 394 |
+
def install_object_aliasing_guard(
|
| 395 |
+
x: GuardManager,
|
| 396 |
+
y: GuardManager,
|
| 397 |
+
verbose_code_parts: list[str],
|
| 398 |
+
) -> None: ...
|
| 399 |
+
def install_no_tensor_aliasing_guard(
|
| 400 |
+
guard_managers: list[GuardManager],
|
| 401 |
+
tensor_names: list[str],
|
| 402 |
+
verbose_code_parts: list[str],
|
| 403 |
+
) -> None: ...
|
| 404 |
+
def install_storage_overlapping_guard(
|
| 405 |
+
overlapping_guard_managers: list[GuardManager],
|
| 406 |
+
non_overlapping_guard_managers: list[GuardManager],
|
| 407 |
+
verbose_code_parts: list[str],
|
| 408 |
+
) -> None: ...
|
| 409 |
+
def install_symbolic_shape_guard(
|
| 410 |
+
guard_managers: list[GuardManager],
|
| 411 |
+
nargs_int: int,
|
| 412 |
+
nargs_float: int,
|
| 413 |
+
py_addr: int,
|
| 414 |
+
py_addr_keep_alive: Any,
|
| 415 |
+
verbose_code_parts: list[str],
|
| 416 |
+
) -> None: ...
|
| 417 |
+
def profile_guard_manager(
|
| 418 |
+
guard_manager: GuardManager,
|
| 419 |
+
f_locals: dict[str, Any],
|
| 420 |
+
n_iters: int,
|
| 421 |
+
) -> float: ...
|
| 422 |
+
|
| 423 |
+
class TensorGuards:
|
| 424 |
+
def __init__(
|
| 425 |
+
self,
|
| 426 |
+
*,
|
| 427 |
+
dynamic_dims_sizes: list[torch.SymInt | None] | None = None,
|
| 428 |
+
dynamic_dims_strides: list[torch.SymInt | None] | None = None,
|
| 429 |
+
) -> None: ...
|
| 430 |
+
def check(self, *args: Any) -> bool: ...
|
| 431 |
+
def check_verbose(
|
| 432 |
+
self, *args: Any, tensor_check_names: Optional[list[str]] = None
|
| 433 |
+
) -> bool | str: ...
|
| 434 |
+
|
| 435 |
+
def assert_size_stride(
|
| 436 |
+
item: torch.Tensor,
|
| 437 |
+
size: torch.types._size,
|
| 438 |
+
stride: torch.types._size,
|
| 439 |
+
op_name: str | None = None,
|
| 440 |
+
) -> None: ...
|
| 441 |
+
def assert_alignment(
|
| 442 |
+
item: torch.Tensor,
|
| 443 |
+
alignment: int,
|
| 444 |
+
op_name: str | None = None,
|
| 445 |
+
) -> None: ...
|
| 446 |
+
def check_obj_id(obj: object, expected: int) -> bool: ...
|
| 447 |
+
def check_type_id(obj: object, expected: int) -> bool: ...
|
| 448 |
+
def dict_version(d: dict[Any, Any]) -> int: ...
|
| 449 |
+
def compute_overlapping_tensors(
|
| 450 |
+
tensors: list[torch.Tensor], symbolic: bool = True
|
| 451 |
+
) -> set[int]: ...
|
| 452 |
+
def set_is_in_mode_without_ignore_compile_internals(value: bool) -> None: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_export/__init__.pyi
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Defined in torch/csrc/export/pybind.cpp
|
| 2 |
+
class CppExportedProgram: ...
|
| 3 |
+
|
| 4 |
+
def deserialize_exported_program(
|
| 5 |
+
serialized_program: str,
|
| 6 |
+
) -> CppExportedProgram: ...
|
| 7 |
+
def serialize_exported_program(
|
| 8 |
+
cpp_exported_program: CppExportedProgram,
|
| 9 |
+
) -> str: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_C/_export/pt2_archive_constants.pyi
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Defined in torch/csrc/export/pt2_archive_constants.h
|
| 2 |
+
|
| 3 |
+
ARCHIVE_ROOT_NAME: str = ...
|
| 4 |
+
ARCHIVE_FORMAT_PATH: str = ...
|
| 5 |
+
ARCHIVE_FORMAT_VALUE: str = ...
|
| 6 |
+
ARCHIVE_VERSION_PATH: str = ...
|
| 7 |
+
ARCHIVE_VERSION_VALUE: str = ...
|
| 8 |
+
MODELS_DIR: str = ...
|
| 9 |
+
MODELS_FILENAME_FORMAT: str = ...
|
| 10 |
+
AOTINDUCTOR_DIR: str = ...
|
| 11 |
+
MTIA_DIR: str = ...
|
| 12 |
+
WEIGHTS_DIR: str = ...
|
| 13 |
+
WEIGHTS_CONFIG_FILENAME_FORMAT: str = ...
|
| 14 |
+
WEIGHT_FILENAME_PREFIX: str = ...
|
| 15 |
+
CONSTANTS_DIR: str = ...
|
| 16 |
+
CONSTANTS_CONFIG_FILENAME_FORMAT: str = ...
|
| 17 |
+
TENSOR_CONSTANT_FILENAME_PREFIX: str = ...
|
| 18 |
+
CUSTOM_OBJ_FILENAME_PREFIX: str = ...
|
| 19 |
+
SAMPLE_INPUTS_DIR: str = ...
|
| 20 |
+
SAMPLE_INPUTS_FILENAME_FORMAT: str = ...
|
| 21 |
+
EXECUTORCH_DIR: str = ...
|
| 22 |
+
EXTRA_DIR: str = ...
|
| 23 |
+
MODULE_INFO_PATH: str = ...
|
| 24 |
+
XL_MODEL_WEIGHTS_DIR: str = ...
|
| 25 |
+
XL_MODEL_WEIGHTS_PARAM_CONFIG_PATH: str = ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_custom_op/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (222 Bytes). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_custom_op/__pycache__/autograd.cpython-312.pyc
ADDED
|
Binary file (13.6 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/_custom_op/__pycache__/impl.cpython-312.pyc
ADDED
|
Binary file (32.4 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/amp/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (445 Bytes). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/amp/__pycache__/autocast_mode.cpython-312.pyc
ADDED
|
Binary file (24.1 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/amp/__pycache__/grad_scaler.cpython-312.pyc
ADDED
|
Binary file (32.3 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/contrib/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (219 Bytes). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/contrib/__pycache__/_tensorboard_vis.cpython-312.pyc
ADDED
|
Binary file (8.37 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/amp/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (472 Bytes). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/amp/__pycache__/autocast_mode.cpython-312.pyc
ADDED
|
Binary file (4.9 kB). View file
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/torch/cuda/amp/__pycache__/common.cpython-312.pyc
ADDED
|
Binary file (594 Bytes). View file
|
|
|