golden hour
/opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/core
⬆️ Go Up
Upload
File/Folder
Size
Actions
__init__.py
5.64 KB
Del
OK
__init__.pyi
126 B
Del
OK
__pycache__
-
Del
OK
_add_newdocs.py
204.07 KB
Del
OK
_add_newdocs_scalars.py
11.82 KB
Del
OK
_asarray.py
3.79 KB
Del
OK
_asarray.pyi
1.06 KB
Del
OK
_dtype.py
10.36 KB
Del
OK
_dtype_ctypes.py
3.59 KB
Del
OK
_exceptions.py
5.25 KB
Del
OK
_internal.py
27.68 KB
Del
OK
_internal.pyi
1.01 KB
Del
OK
_machar.py
11.29 KB
Del
OK
_methods.py
8.41 KB
Del
OK
_multiarray_tests.cpython-311-x86_64-linux-gnu.so
171.79 KB
Del
OK
_multiarray_umath.cpython-311-x86_64-linux-gnu.so
6.66 MB
Del
OK
_operand_flag_tests.cpython-311-x86_64-linux-gnu.so
16.67 KB
Del
OK
_rational_tests.cpython-311-x86_64-linux-gnu.so
58.41 KB
Del
OK
_simd.cpython-311-x86_64-linux-gnu.so
2.47 MB
Del
OK
_string_helpers.py
2.79 KB
Del
OK
_struct_ufunc_tests.cpython-311-x86_64-linux-gnu.so
16.77 KB
Del
OK
_type_aliases.py
7.36 KB
Del
OK
_type_aliases.pyi
404 B
Del
OK
_ufunc_config.py
13.62 KB
Del
OK
_ufunc_config.pyi
1.04 KB
Del
OK
_umath_tests.cpython-311-x86_64-linux-gnu.so
41.32 KB
Del
OK
arrayprint.py
62.12 KB
Del
OK
arrayprint.pyi
4.32 KB
Del
OK
cversions.py
347 B
Del
OK
defchararray.py
71.89 KB
Del
OK
defchararray.pyi
9 KB
Del
OK
einsumfunc.py
50.65 KB
Del
OK
einsumfunc.pyi
4.75 KB
Del
OK
fromnumeric.py
125.8 KB
Del
OK
fromnumeric.pyi
22.96 KB
Del
OK
function_base.py
19.37 KB
Del
OK
function_base.pyi
4.61 KB
Del
OK
generate_numpy_api.py
7.47 KB
Del
OK
getlimits.py
25.26 KB
Del
OK
getlimits.pyi
82 B
Del
OK
include
-
Del
OK
lib
-
Del
OK
memmap.py
11.5 KB
Del
OK
memmap.pyi
55 B
Del
OK
multiarray.py
54.78 KB
Del
OK
multiarray.pyi
24.19 KB
Del
OK
numeric.py
75.21 KB
Del
OK
numeric.pyi
13.9 KB
Del
OK
numerictypes.py
17.67 KB
Del
OK
numerictypes.pyi
3.19 KB
Del
OK
overrides.py
6.93 KB
Del
OK
records.py
36.65 KB
Del
OK
records.pyi
5.56 KB
Del
OK
setup.py
47.05 KB
Del
OK
setup_common.py
16.68 KB
Del
OK
shape_base.py
29.05 KB
Del
OK
shape_base.pyi
2.71 KB
Del
OK
tests
-
Del
OK
umath.py
1.99 KB
Del
OK
umath_tests.py
389 B
Del
OK
Edit: _methods.py
""" Array methods which are called by both the C-code for the method and the Python code for the NumPy-namespace function """ import warnings from contextlib import nullcontext from numpy.core import multiarray as mu from numpy.core import umath as um from numpy.core.multiarray import asanyarray from numpy.core import numerictypes as nt from numpy.core import _exceptions from numpy.core._ufunc_config import _no_nep50_warning from numpy._globals import _NoValue from numpy.compat import pickle, os_fspath # save those O(100) nanoseconds! umr_maximum = um.maximum.reduce umr_minimum = um.minimum.reduce umr_sum = um.add.reduce umr_prod = um.multiply.reduce umr_any = um.logical_or.reduce umr_all = um.logical_and.reduce # Complex types to -> (2,)float view for fast-path computation in _var() _complex_to_float = { nt.dtype(nt.csingle) : nt.dtype(nt.single), nt.dtype(nt.cdouble) : nt.dtype(nt.double), } # Special case for windows: ensure double takes precedence if nt.dtype(nt.longdouble) != nt.dtype(nt.double): _complex_to_float.update({ nt.dtype(nt.clongdouble) : nt.dtype(nt.longdouble), }) # avoid keyword arguments to speed up parsing, saves about 15%-20% for very # small reductions def _amax(a, axis=None, out=None, keepdims=False, initial=_NoValue, where=True): return umr_maximum(a, axis, None, out, keepdims, initial, where) def _amin(a, axis=None, out=None, keepdims=False, initial=_NoValue, where=True): return umr_minimum(a, axis, None, out, keepdims, initial, where) def _sum(a, axis=None, dtype=None, out=None, keepdims=False, initial=_NoValue, where=True): return umr_sum(a, axis, dtype, out, keepdims, initial, where) def _prod(a, axis=None, dtype=None, out=None, keepdims=False, initial=_NoValue, where=True): return umr_prod(a, axis, dtype, out, keepdims, initial, where) def _any(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True): # Parsing keyword arguments is currently fairly slow, so avoid it for now if where is True: return umr_any(a, axis, dtype, out, keepdims) return umr_any(a, axis, dtype, out, keepdims, where=where) def _all(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True): # Parsing keyword arguments is currently fairly slow, so avoid it for now if where is True: return umr_all(a, axis, dtype, out, keepdims) return umr_all(a, axis, dtype, out, keepdims, where=where) def _count_reduce_items(arr, axis, keepdims=False, where=True): # fast-path for the default case if where is True: # no boolean mask given, calculate items according to axis if axis is None: axis = tuple(range(arr.ndim)) elif not isinstance(axis, tuple): axis = (axis,) items = 1 for ax in axis: items *= arr.shape[mu.normalize_axis_index(ax, arr.ndim)] items = nt.intp(items) else: # TODO: Optimize case when `where` is broadcast along a non-reduction # axis and full sum is more excessive than needed. # guarded to protect circular imports from numpy.lib.stride_tricks import broadcast_to # count True values in (potentially broadcasted) boolean mask items = umr_sum(broadcast_to(where, arr.shape), axis, nt.intp, None, keepdims) return items def _clip(a, min=None, max=None, out=None, **kwargs): if min is None and max is None: raise ValueError("One of max or min must be given") if min is None: return um.minimum(a, max, out=out, **kwargs) elif max is None: return um.maximum(a, min, out=out, **kwargs) else: return um.clip(a, min, max, out=out, **kwargs) def _mean(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True): arr = asanyarray(a) is_float16_result = False rcount = _count_reduce_items(arr, axis, keepdims=keepdims, where=where) if rcount == 0 if where is True else umr_any(rcount == 0, axis=None): warnings.warn("Mean of empty slice.", RuntimeWarning, stacklevel=2) # Cast bool, unsigned int, and int to float64 by default if dtype is None: if issubclass(arr.dtype.type, (nt.integer, nt.bool_)): dtype = mu.dtype('f8') elif issubclass(arr.dtype.type, nt.float16): dtype = mu.dtype('f4') is_float16_result = True ret = umr_sum(arr, axis, dtype, out, keepdims, where=where) if isinstance(ret, mu.ndarray): with _no_nep50_warning(): ret = um.true_divide( ret, rcount, out=ret, casting='unsafe', subok=False) if is_float16_result and out is None: ret = arr.dtype.type(ret) elif hasattr(ret, 'dtype'): if is_float16_result: ret = arr.dtype.type(ret / rcount) else: ret = ret.dtype.type(ret / rcount) else: ret = ret / rcount return ret def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True): arr = asanyarray(a) rcount = _count_reduce_items(arr, axis, keepdims=keepdims, where=where) # Make this warning show up on top. if ddof >= rcount if where is True else umr_any(ddof >= rcount, axis=None): warnings.warn("Degrees of freedom <= 0 for slice", RuntimeWarning, stacklevel=2) # Cast bool, unsigned int, and int to float64 by default if dtype is None and issubclass(arr.dtype.type, (nt.integer, nt.bool_)): dtype = mu.dtype('f8') # Compute the mean. # Note that if dtype is not of inexact type then arraymean will # not be either. arrmean = umr_sum(arr, axis, dtype, keepdims=True, where=where) # The shape of rcount has to match arrmean to not change the shape of out # in broadcasting. Otherwise, it cannot be stored back to arrmean. if rcount.ndim == 0: # fast-path for default case when where is True div = rcount else: # matching rcount to arrmean when where is specified as array div = rcount.reshape(arrmean.shape) if isinstance(arrmean, mu.ndarray): with _no_nep50_warning(): arrmean = um.true_divide(arrmean, div, out=arrmean, casting='unsafe', subok=False) elif hasattr(arrmean, "dtype"): arrmean = arrmean.dtype.type(arrmean / rcount) else: arrmean = arrmean / rcount # Compute sum of squared deviations from mean # Note that x may not be inexact and that we need it to be an array, # not a scalar. x = asanyarray(arr - arrmean) if issubclass(arr.dtype.type, (nt.floating, nt.integer)): x = um.multiply(x, x, out=x) # Fast-paths for built-in complex types elif x.dtype in _complex_to_float: xv = x.view(dtype=(_complex_to_float[x.dtype], (2,))) um.multiply(xv, xv, out=xv) x = um.add(xv[..., 0], xv[..., 1], out=x.real).real # Most general case; includes handling object arrays containing imaginary # numbers and complex types with non-native byteorder else: x = um.multiply(x, um.conjugate(x), out=x).real ret = umr_sum(x, axis, dtype, out, keepdims=keepdims, where=where) # Compute degrees of freedom and make sure it is not negative. rcount = um.maximum(rcount - ddof, 0) # divide by degrees of freedom if isinstance(ret, mu.ndarray): with _no_nep50_warning(): ret = um.true_divide( ret, rcount, out=ret, casting='unsafe', subok=False) elif hasattr(ret, 'dtype'): ret = ret.dtype.type(ret / rcount) else: ret = ret / rcount return ret def _std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True): ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof, keepdims=keepdims, where=where) if isinstance(ret, mu.ndarray): ret = um.sqrt(ret, out=ret) elif hasattr(ret, 'dtype'): ret = ret.dtype.type(um.sqrt(ret)) else: ret = um.sqrt(ret) return ret def _ptp(a, axis=None, out=None, keepdims=False): return um.subtract( umr_maximum(a, axis, None, out, keepdims), umr_minimum(a, axis, None, None, keepdims), out ) def _dump(self, file, protocol=2): if hasattr(file, 'write'): ctx = nullcontext(file) else: ctx = open(os_fspath(file), "wb") with ctx as f: pickle.dump(self, f, protocol=protocol) def _dumps(self, protocol=2): return pickle.dumps(self, protocol=protocol)
Save