X7ROOT File Manager
Current Path:
/opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/core/tests
opt
/
cloudlinux
/
venv
/
lib
/
python3.11
/
site-packages
/
numpy
/
core
/
tests
/
📁
..
📄
__init__.py
(0 B)
📁
__pycache__
📄
_locales.py
(2.15 KB)
📁
data
📁
examples
📄
test__exceptions.py
(2.78 KB)
📄
test_abc.py
(2.17 KB)
📄
test_api.py
(22.46 KB)
📄
test_argparse.py
(1.92 KB)
📄
test_array_coercion.py
(33.57 KB)
📄
test_array_interface.py
(7.42 KB)
📄
test_arraymethod.py
(3.17 KB)
📄
test_arrayprint.py
(39.51 KB)
📄
test_casting_floatingpoint_errors.py
(4.94 KB)
📄
test_casting_unittests.py
(33.49 KB)
📄
test_conversion_utils.py
(6.41 KB)
📄
test_cpu_dispatcher.py
(1.49 KB)
📄
test_cpu_features.py
(14.51 KB)
📄
test_custom_dtypes.py
(9.18 KB)
📄
test_cython.py
(3.54 KB)
📄
test_datetime.py
(113.49 KB)
📄
test_defchararray.py
(24.41 KB)
📄
test_deprecations.py
(30.35 KB)
📄
test_dlpack.py
(3.44 KB)
📄
test_dtype.py
(73.52 KB)
📄
test_einsum.py
(51.72 KB)
📄
test_errstate.py
(2.17 KB)
📄
test_extint128.py
(5.51 KB)
📄
test_function_base.py
(15.23 KB)
📄
test_getlimits.py
(6.56 KB)
📄
test_half.py
(23.66 KB)
📄
test_hashtable.py
(1011 B)
📄
test_indexerrors.py
(5.01 KB)
📄
test_indexing.py
(53.04 KB)
📄
test_item_selection.py
(6.31 KB)
📄
test_limited_api.py
(1.14 KB)
📄
test_longdouble.py
(13.58 KB)
📄
test_machar.py
(1.04 KB)
📄
test_mem_overlap.py
(28.4 KB)
📄
test_mem_policy.py
(15.63 KB)
📄
test_memmap.py
(7.3 KB)
📄
test_multiarray.py
(370.43 KB)
📄
test_nditer.py
(127.75 KB)
📄
test_nep50_promotions.py
(8.63 KB)
📄
test_numeric.py
(133.34 KB)
📄
test_numerictypes.py
(21.18 KB)
📄
test_overrides.py
(25.47 KB)
📄
test_print.py
(6.68 KB)
📄
test_protocols.py
(1.14 KB)
📄
test_records.py
(19.79 KB)
📄
test_regression.py
(89.3 KB)
📄
test_scalar_ctors.py
(5.97 KB)
📄
test_scalar_methods.py
(7.36 KB)
📄
test_scalarbuffer.py
(5.45 KB)
📄
test_scalarinherit.py
(2.31 KB)
📄
test_scalarmath.py
(41.88 KB)
📄
test_scalarprint.py
(18.33 KB)
📄
test_shape_base.py
(29.03 KB)
📄
test_simd.py
(47.55 KB)
📄
test_simd_module.py
(3.72 KB)
📄
test_strings.py
(3.75 KB)
📄
test_ufunc.py
(121.24 KB)
📄
test_umath.py
(180.79 KB)
📄
test_umath_accuracy.py
(3.81 KB)
📄
test_umath_complex.py
(22.7 KB)
📄
test_unicode.py
(12.48 KB)
Editing: test_umath_accuracy.py
import numpy as np import os from os import path import sys import pytest from ctypes import c_longlong, c_double, c_float, c_int, cast, pointer, POINTER from numpy.testing import assert_array_max_ulp from numpy.testing._private.utils import _glibc_older_than from numpy.core._multiarray_umath import __cpu_features__ UNARY_UFUNCS = [obj for obj in np.core.umath.__dict__.values() if isinstance(obj, np.ufunc)] UNARY_OBJECT_UFUNCS = [uf for uf in UNARY_UFUNCS if "O->O" in uf.types] UNARY_OBJECT_UFUNCS.remove(getattr(np, 'invert')) IS_AVX = __cpu_features__.get('AVX512F', False) or \ (__cpu_features__.get('FMA3', False) and __cpu_features__.get('AVX2', False)) # only run on linux with AVX, also avoid old glibc (numpy/numpy#20448). runtest = (sys.platform.startswith('linux') and IS_AVX and not _glibc_older_than("2.17")) platform_skip = pytest.mark.skipif(not runtest, reason="avoid testing inconsistent platform " "library implementations") # convert string to hex function taken from: # https://stackoverflow.com/questions/1592158/convert-hex-to-float # def convert(s, datatype="np.float32"): i = int(s, 16) # convert from hex to a Python int if (datatype == "np.float64"): cp = pointer(c_longlong(i)) # make this into a c long long integer fp = cast(cp, POINTER(c_double)) # cast the int pointer to a double pointer else: cp = pointer(c_int(i)) # make this into a c integer fp = cast(cp, POINTER(c_float)) # cast the int pointer to a float pointer return fp.contents.value # dereference the pointer, get the float str_to_float = np.vectorize(convert) class TestAccuracy: @platform_skip def test_validate_transcendentals(self): with np.errstate(all='ignore'): data_dir = path.join(path.dirname(__file__), 'data') files = os.listdir(data_dir) files = list(filter(lambda f: f.endswith('.csv'), files)) for filename in files: filepath = path.join(data_dir, filename) with open(filepath) as fid: file_without_comments = (r for r in fid if not r[0] in ('$', '#')) data = np.genfromtxt(file_without_comments, dtype=('|S39','|S39','|S39',int), names=('type','input','output','ulperr'), delimiter=',', skip_header=1) npname = path.splitext(filename)[0].split('-')[3] npfunc = getattr(np, npname) for datatype in np.unique(data['type']): data_subset = data[data['type'] == datatype] inval = np.array(str_to_float(data_subset['input'].astype(str), data_subset['type'].astype(str)), dtype=eval(datatype)) outval = np.array(str_to_float(data_subset['output'].astype(str), data_subset['type'].astype(str)), dtype=eval(datatype)) perm = np.random.permutation(len(inval)) inval = inval[perm] outval = outval[perm] maxulperr = data_subset['ulperr'].max() assert_array_max_ulp(npfunc(inval), outval, maxulperr) @pytest.mark.parametrize("ufunc", UNARY_OBJECT_UFUNCS) def test_validate_fp16_transcendentals(self, ufunc): with np.errstate(all='ignore'): arr = np.arange(65536, dtype=np.int16) datafp16 = np.frombuffer(arr.tobytes(), dtype=np.float16) datafp32 = datafp16.astype(np.float32) assert_array_max_ulp(ufunc(datafp16), ufunc(datafp32), maxulp=1, dtype=np.float16)
Upload File
Create Folder