repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
numpy
numpy/f2py/tests/test_isoc.py
.py
import pytest import numpy as np from numpy.testing import assert_allclose from . import util @pytest.mark.slow class TestISOC(util.F2PyTest): sources = [ util.getpath("tests", "src", "isocintrin", "isoCtests.f90"), ] @pytest.mark.parametrize("dtype", [np.complex64, np.complex128, np.clongdoubl...
76
2,300
numpy
numpy/f2py/tests/__init__.py
.py
import pytest from numpy.testing import IS_EDITABLE, IS_IOS, IS_WASM if IS_WASM or IS_IOS: pytest.skip( "Platform does not use or support Fortran", allow_module_level=True ) if IS_EDITABLE: pytest.skip( "Editable install doesn't support tests with a compile step", allow_m...
17
343
numpy
numpy/f2py/tests/test_regression.py
.py
import os import platform import sys from pathlib import Path import pytest import numpy as np import numpy.testing as npt from numpy.f2py._backends._meson import MesonTemplate from . import util @pytest.mark.slow class TestIntentInOut(util.F2PyTest): # Check that intent(in out) translates as intent(inout) ...
320
11,182
numpy
numpy/f2py/tests/test_usercode.py
.py
from . import util class TestUserCode(util.F2PyTest): suffix = ".pyf" module_name = "user_code_success" # The failure path in this code isn't expected to happen (and would be # untestable if it did, because it would happen in the test setup). # However, it does need to compile correctly. code...
27
773
numpy
numpy/f2py/tests/test_capi_maps.py
.py
from numpy.f2py import capi_maps def test_complex_long_double_capi_map(): assert capi_maps.c2capi_map["complex_long_double"] == "NPY_CLONGDOUBLE" def test_complex_long_double_is_distinct(): assert capi_maps.c2pycode_map["complex_long_double"] != capi_maps.c2pycode_map["complex_double"] assert capi_maps....
11
396
numpy
numpy/f2py/tests/test_pyf_src.py
.py
# This test is ported from numpy.distutils from numpy.f2py._src_pyf import process_str from numpy.testing import assert_equal pyf_src = """ python module foo <_rd=real,double precision> interface subroutine <s,d>foosub(tol) <_rd>, intent(in,out) :: tol end subroutine <s,d>foosub ...
44
1,134
numpy
numpy/f2py/tests/test_mixed.py
.py
import textwrap import pytest from . import util @pytest.mark.slow class TestMixed(util.F2PyTest): sources = [ util.getpath("tests", "src", "mixed", "foo.f"), util.getpath("tests", "src", "mixed", "foo_fixed.f90"), util.getpath("tests", "src", "mixed", "foo_free.f90"), ] def tes...
32
713
numpy
numpy/f2py/tests/test_return_complex.py
.py
import pytest from numpy import array from . import util @pytest.mark.slow class TestReturnComplex(util.F2PyTest): def check_function(self, t, tname): if tname in ["t0", "t8", "s0", "s8"]: err = 1e-5 else: err = 0.0 assert abs(t(234j) - 234.0j) <= err asse...
68
2,440
numpy
numpy/f2py/tests/test_callback.py
.py
import math import platform import sys import textwrap import threading import time import traceback import pytest import numpy as np from . import util @pytest.mark.slow class TestF77Callback(util.F2PyTest): sources = [util.getpath("tests", "src", "callback", "foo.f")] @pytest.mark.parametrize("name", ["...
263
6,979
numpy
numpy/f2py/tests/test_return_real.py
.py
import platform import pytest from numpy import array from numpy.testing import IS_64BIT from . import util @pytest.mark.slow class TestReturnReal(util.F2PyTest): def check_function(self, t, tname): if tname in ["t0", "t4", "s0", "s4"]: err = 1e-5 else: err = 0.0 ...
110
3,273
numpy
numpy/f2py/tests/test_assumed_shape.py
.py
import os import tempfile import pytest from . import util # Note: do not mark as slow! This is one of a small set of f2py compile tests retained # in the default suite invocation for compile-path coverage. class TestAssumedShapeSumExample(util.F2PyTest): sources = [ util.getpath("tests", "src", "assume...
53
1,611
numpy
numpy/f2py/tests/test_parameter.py
.py
import pytest import numpy as np from . import util @pytest.mark.slow class TestParameters(util.F2PyTest): # Check that intent(in out) translates as intent(inout) sources = [ util.getpath("tests", "src", "parameter", "constant_real.f90"), util.getpath("tests", "src", "parameter", "constant_i...
122
4,454
numpy
numpy/f2py/tests/test_array_from_pyobj.py
.py
import copy import platform import sys from pathlib import Path import pytest import numpy as np from numpy._core._type_aliases import c_names_dict as _c_names_dict from . import util pytestmark = pytest.mark.slow wrap = None # Extend core typeinfo with CHARACTER to test dtype('c') c_names_dict = dict( CHARAC...
733
26,404
numpy
numpy/f2py/tests/test_size.py
.py
import numpy as np from . import util # Note: do not mark as slow! This is one of a small set of f2py compile tests retained # in the default suite invocation for compile-path coverage. class TestSizeSumExample(util.F2PyTest): sources = [util.getpath("tests", "src", "size", "foo.f90")] def test_all(self): ...
43
1,222
numpy
numpy/f2py/tests/test_value_attrspec.py
.py
import pytest from . import util @pytest.mark.slow class TestValueAttr(util.F2PyTest): sources = [util.getpath("tests", "src", "value_attrspec", "gh21665.f90")] # gh-21665 def test_gh21665(self): inp = 2 out = self.module.fortfuncs.square(inp) exp_out = 4 assert out == ex...
16
326
numpy
numpy/f2py/tests/test_kind.py
.py
import platform import sys import pytest from numpy.f2py.crackfortran import ( _selected_int_kind_func as selected_int_kind, _selected_real_kind_func as selected_real_kind, ) from . import util IS_PPC_OR_AIX = platform.machine().lower().startswith("ppc") or platform.system() == 'AIX' @pytest.mark.slow clas...
54
1,863
numpy
numpy/f2py/tests/test_docs.py
.py
from pathlib import Path import pytest import numpy as np from numpy.testing import assert_array_equal, assert_equal from . import util def get_docdir(): parents = Path(__file__).resolve().parents try: # Assumes that spin is used to run tests nproot = parents[8] except IndexError: ...
67
1,930
numpy
numpy/f2py/tests/test_abstract_interface.py
.py
import pytest from numpy.f2py import crackfortran from numpy.testing import HAS_SUBPROCESSES from . import util @pytest.mark.skipif(not HAS_SUBPROCESSES, reason="platform cannot start subprocesses") @pytest.mark.slow class TestAbstractInterface(util.F2PyTest): sources = [util.getpath("tests", "src", "abstract_i...
27
844
numpy
numpy/f2py/tests/test_data.py
.py
import pytest import numpy as np from numpy.f2py.crackfortran import crackfortran from . import util @pytest.mark.slow class TestData(util.F2PyTest): sources = [util.getpath("tests", "src", "crackfortran", "data_stmts.f90")] # For gh-23276 def test_data_stmts(self): assert self.module.cmplxdat....
75
2,945
numpy
numpy/f2py/tests/test_f2cmap.py
.py
import pytest import numpy as np from . import util @pytest.mark.slow class TestF2Cmap(util.F2PyTest): sources = [ util.getpath("tests", "src", "f2cmap", "isoFortranEnvMap.f90"), util.getpath("tests", "src", "f2cmap", ".f2py_f2cmap") ] # gh-15095 def test_gh15095(self): inp ...
21
420
numpy
numpy/f2py/tests/test_common.py
.py
import pytest import numpy as np from . import util @pytest.mark.slow class TestCommonBlock(util.F2PyTest): sources = [util.getpath("tests", "src", "common", "block.f")] def test_common_block(self): self.module.initcb() assert self.module.block.long_bn == np.array(1.0, dtype=np.float64) ...
25
662
numpy
numpy/f2py/tests/test_inplace.py
.py
import pytest import numpy as np from numpy.f2py.tests import util from numpy.testing import assert_array_equal @pytest.mark.slow class TestInplace(util.F2PyTest): sources = [util.getpath("tests", "src", "inplace", "foo.f")] @pytest.mark.parametrize("func", ["inplace", "inplace_out"]) @pytest.mark.para...
50
1,676
numpy
numpy/f2py/tests/test_isof.py
.py
import pytest import numpy as np from numpy.testing import assert_allclose from . import util @pytest.mark.slow class TestIOSF(util.F2PyTest): sources = [ util.getpath('tests', 'src', 'isofenv', 'isoftests.f90'), ] def test_f_real64(self): out = self.module.foddity.f_add(1.0, 2.0) ...
55
1,552
numpy
numpy/f2py/tests/test_block_docstring.py
.py
import sys import pytest from . import util @pytest.mark.slow class TestBlockDocString(util.F2PyTest): sources = [util.getpath("tests", "src", "block_docstring", "foo.f")] @pytest.mark.skipif(sys.platform == "win32", reason="Fails with MinGW64 Gfortran (Issue #9673)") def test_b...
17
439
numpy
numpy/f2py/tests/test_crackfortran.py
.py
import contextlib import importlib import io import textwrap import time import pytest import numpy as np from numpy.f2py import crackfortran from numpy.f2py.crackfortran import markinnerspaces, nameargspattern from . import util @pytest.mark.slow class TestNoSpace(util.F2PyTest): # issue gh-15035: add handlin...
464
18,091
numpy
numpy/f2py/tests/test_quoted_character.py
.py
"""See https://github.com/numpy/numpy/pull/10676. """ import sys import pytest from . import util # Note: do not mark as slow! This is one of a small set of f2py compile tests retained # in the default suite invocation for compile-path coverage. class TestQuotedCharacter(util.F2PyTest): sources = [util.getpath...
20
603
numpy
numpy/f2py/_backends/_meson.py
.py
import errno import os import re import shutil import subprocess import sys from itertools import chain from pathlib import Path from string import Template from ._backend import Backend def _meson_identifier(prefix: str, value: str, index: int) -> str: safe_value = re.sub(r"[^a-zA-Z0-9_]", "_", value) if no...
257
8,984
numpy
numpy/f2py/_backends/__init__.py
.py
def f2py_build_generator(name): if name == "meson": from ._meson import MesonBackend return MesonBackend else: raise ValueError(f"Unknown backend: {name}")
7
188
numpy
numpy/f2py/_backends/_backend.py
.py
from abc import ABC, abstractmethod class Backend(ABC): def __init__( self, modulename, sources, extra_objects, build_dir, include_dirs, library_dirs, libraries, define_macros, undef_macros, f2py_flags, sysinfo_flags, ...
45
1,151
numpy
numpy/lib/_type_check_impl.py
.py
"""Automatically adapted for numpy Sep 19, 2005 by convertcode.py """ import functools import warnings __all__ = ['iscomplexobj', 'isrealobj', 'imag', 'iscomplex', 'isreal', 'nan_to_num', 'real', 'real_if_close', 'typename', 'mintypecode', 'common_type'] import numpy._core.numeric as...
722
20,402
numpy
numpy/lib/_twodim_base_impl.py
.py
""" Basic functions for manipulating 2d arrays """ import functools import operator import os import warnings from numpy._core import iinfo, overrides from numpy._core._multiarray_umath import _array_converter from numpy._core.numeric import ( arange, asanyarray, asarray, diagonal, empty, grea...
1,243
35,250
numpy
numpy/lib/scimath.py
.py
from ._scimath_impl import ( # noqa: F401 __all__, __doc__, arccos, arcsin, arctanh, log, log2, log10, logn, power, sqrt, )
14
169
numpy
numpy/lib/introspect.py
.py
""" Introspection helper functions. """ __all__ = ['opt_func_info'] def opt_func_info(func_name=None, signature=None): """ Returns a dictionary containing the currently supported CPU dispatched features for all optimized functions. Parameters ---------- func_name : str (optional) Reg...
95
2,749
numpy
numpy/lib/_polynomial_impl.py
.py
""" Functions to operate on polynomials. """ __all__ = ['poly', 'roots', 'polyint', 'polyder', 'polyadd', 'polysub', 'polymul', 'polydiv', 'polyval', 'poly1d', 'polyfit'] import functools import re import warnings import numpy._core.numeric as NX from numpy._core import ( abs, array, ...
1,468
44,222
numpy
numpy/lib/_array_utils_impl.py
.py
""" Miscellaneous utils. """ from numpy._core import asarray from numpy._core.numeric import normalize_axis_index, normalize_axis_tuple from numpy._utils import set_module __all__ = ["byte_bounds", "normalize_axis_tuple", "normalize_axis_index"] @set_module("numpy.lib.array_utils") def byte_bounds(a): """ Re...
63
1,704
numpy
numpy/lib/recfunctions.py
.py
""" Collection of utilities to manipulate structured arrays. Most of these functions were initially implemented by John Hunter for matplotlib. They have been rewritten and extended for convenience. """ import itertools import numpy as np import numpy.ma as ma import numpy.ma.mrecords as mrec from numpy._core.overri...
1,682
59,524
numpy
numpy/lib/format.py
.py
from ._format_impl import ( # noqa: F401 ARRAY_ALIGN, BUFFER_SIZE, EXPECTED_KEYS, GROWTH_AXIS_MAX_DIGITS, MAGIC_LEN, MAGIC_PREFIX, __all__, __doc__, descr_to_dtype, drop_metadata, dtype_to_descr, header_data_from_array_1_0, isfileobj, magic, open_memmap, ...
25
477
numpy
numpy/lib/array_utils.py
.py
from ._array_utils_impl import ( # noqa: F401 __all__, __doc__, byte_bounds, normalize_axis_index, normalize_axis_tuple, )
8
144
numpy
numpy/lib/_ufunclike_impl.py
.py
""" Module of functions that are like ufuncs in acting on arrays and optionally storing results in an output array. """ __all__ = ['fix', 'isneginf', 'isposinf'] import warnings import numpy._core.numeric as nx from numpy._core.overrides import array_function_dispatch def _dispatcher(x, out=None): return (x, o...
213
6,419
numpy
numpy/lib/_user_array_impl.py
.py
""" Container class for backward compatibility with NumArray. The user_array.container class exists for backward compatibility with NumArray and is not meant to be used in new code. If you need to create an array container class, we recommend either creating a class that wraps an ndarray or subclasses ndarray. """ fr...
311
8,026
numpy
numpy/lib/_arraypad_impl.py
.py
""" The arraypad module contains a group of functions to pad values onto the edges of an n-dimensional array. """ import typing import numpy as np from numpy._core.overrides import array_function_dispatch from numpy.lib._index_tricks_impl import ndindex __all__ = ['pad'] ###########################################...
965
34,716
numpy
numpy/lib/_version.py
.py
"""Utility to compare (NumPy) version strings. The NumpyVersion class allows properly comparing numpy version strings. The LooseVersion and StrictVersion classes that distutils provides don't work; they don't recognize anything like alpha/beta/rc/dev versions. """ import re __all__ = ['NumpyVersion'] class NumpyVe...
154
4,783
numpy
numpy/lib/_datasource.py
.py
"""A file interface for handling local and remote data files. The goal of datasource is to abstract some of the file system operations when dealing with data files so the researcher doesn't have to know all the low-level details. Through datasource, a researcher can obtain and use a file with one function call, regar...
709
22,908
numpy
numpy/lib/_shape_base_impl.py
.py
import functools import numpy as np import numpy._core.numeric as _nx from numpy._core import atleast_3d, overrides from numpy._core._multiarray_umath import _array_converter from numpy._core.fromnumeric import reshape, transpose from numpy._core.multiarray import normalize_axis_index from numpy._core.numeric import (...
1,248
37,860
numpy
numpy/lib/__init__.py
.py
""" ``numpy.lib`` is mostly a space for implementing functions that don't belong in core or in another NumPy submodule with a clear purpose (e.g. ``random``, ``fft``, ``linalg``, ``ma``). ``numpy.lib``'s private submodules contain basic functions that are used by other public modules and are useful to have in the main...
91
2,694
numpy
numpy/lib/_scimath_impl.py
.py
""" Wrapper functions to more user-friendly calling of certain math functions whose output data-type is different than the input data-type in certain domains of the input. For example, for functions like `log` with branch cuts, the versions in this module provide the mathematically valid answers in the complex plane::...
643
15,684
numpy
numpy/lib/_format_impl.py
.py
""" Binary serialization NPY format ========== A simple format for saving numpy arrays to disk with the full information about them. The ``.npy`` format is the standard binary file format in NumPy for persisting a *single* arbitrary NumPy array on disk. The format stores all of the shape and dtype information necess...
1,045
37,233
numpy
numpy/lib/_npyio_impl.py
.py
""" IO related functions. """ import contextlib import functools import itertools import operator import os import pickle import re import warnings import weakref from collections.abc import Mapping from operator import itemgetter import numpy as np from numpy._core import overrides from numpy._core._multiarray_umath ...
2,492
96,284
numpy
numpy/lib/_index_tricks_impl.py
.py
import functools import math import sys from itertools import product import numpy as np import numpy._core.numeric as _nx import numpy.matrixlib as matrixlib from numpy._core import linspace, overrides from numpy._core.multiarray import ravel_multi_index, unravel_index from numpy._core.numeric import ScalarType, arra...
1,049
31,527
numpy
numpy/lib/_histograms_impl.py
.py
""" Histogram-related functions """ import contextlib import functools import operator import warnings import numpy as np from numpy._core import overrides __all__ = ['histogram', 'histogramdd', 'histogram_bin_edges'] array_function_dispatch = functools.partial( overrides.array_function_dispatch, module='numpy')...
1,086
38,438
numpy
numpy/lib/_function_base_impl.py
.py
import builtins import collections.abc import functools import operator import re import warnings import numpy as np import numpy._core.numeric as _nx from numpy._core import overrides, transpose from numpy._core._multiarray_umath import _array_converter from numpy._core.fromnumeric import any, mean, nonzero, partitio...
5,810
195,826
numpy
numpy/lib/_arrayterator_impl.py
.py
""" A buffered iterator for big arrays. This module solves the problem of iterating over a big file-based array without having to read it into memory. The `Arrayterator` class wraps an array object, and when iterated it will return sub-arrays with at most a user-specified number of elements. """ from functools import...
225
7,218
numpy
numpy/lib/_utils_impl.py
.py
import os import platform import sys import types import numpy as np from numpy._core import ndarray from numpy._utils import set_module __all__ = [ 'get_include', 'info', 'show_runtime' ] @set_module('numpy') def show_runtime(): """ Print information about various resources in the system including ...
542
16,851
numpy
numpy/lib/mixins.py
.py
""" Mixin classes for custom array types that don't inherit from ndarray. """ from numpy._core import umath as um __all__ = ['NDArrayOperatorsMixin'] def _disables_array_ufunc(obj): """True when __array_ufunc__ is set to None.""" try: return obj.__array_ufunc__ is None except AttributeError: ...
181
7,195
numpy
numpy/lib/_iotools.py
.py
"""A collection of functions designed to help I/O with ascii files. """ __docformat__ = "restructuredtext en" import itertools import numpy as np import numpy._core.numeric as nx from numpy._utils import asbytes, asunicode def _decode_line(line, encoding=None): """Decode bytes from binary input streams. D...
901
30,889
numpy
numpy/lib/_arraysetops_impl.py
.py
""" Set operations for arrays based on sorting. Notes ----- For floating point arrays, inaccurate results may appear due to usual round-off and floating point comparison issues. Speed could be gained in some operations by an implementation of `numpy.sort`, that can provide directly the permutation vectors, thus avoi...
1,159
37,341
numpy
numpy/lib/_stride_tricks_impl.py
.py
""" Utilities that manipulate strides to achieve desirable effects. An explanation of strides can be found in the :ref:`arrays.ndarray`. """ import numpy as np from numpy._core.numeric import normalize_axis_tuple from numpy._core.overrides import array_function_dispatch, set_module from numpy.lib._array_utils_impl im...
657
21,372
numpy
numpy/lib/_nanfunctions_impl.py
.py
""" Functions that ignore NaN. Functions --------- - `nanmin` -- minimum non-NaN value - `nanmax` -- maximum non-NaN value - `nanargmin` -- index of minimum non-NaN value - `nanargmax` -- index of maximum non-NaN value - `nansum` -- sum of non-NaN values - `nanprod` -- product of non-NaN values - `nancumsum` -- cumul...
2,004
71,253
numpy
numpy/lib/tests/test_format.py
.py
# doctest r''' Test the .npy file format. Set up: >>> import sys >>> from io import BytesIO >>> from numpy.lib import format >>> >>> scalars = [ ... np.uint8, ... np.int8, ... np.uint16, ... np.int16, ... np.uint32, ... np.int32, ... np.uint6...
1,044
41,392
numpy
numpy/lib/tests/test_arraysetops.py
.py
"""Test functions for 1D array set operations. """ import pytest import numpy as np from numpy import ediff1d, intersect1d, isin, setdiff1d, setxor1d, union1d, unique from numpy.dtypes import StringDType from numpy.exceptions import AxisError from numpy.testing import ( assert_array_equal, assert_equal, a...
1,305
47,837
numpy
numpy/lib/tests/test_arrayterator.py
.py
from functools import reduce from operator import mul import numpy as np from numpy.lib import Arrayterator from numpy.random import randint from numpy.testing import assert_ def test(): np.random.seed(np.arange(10)) # Create a random array ndims = randint(5) + 1 shape = tuple(randint(10) + 1 for di...
46
1,296
numpy
numpy/lib/tests/test__version.py
.py
"""Tests for the NumpyVersion class. """ from numpy.lib import NumpyVersion from numpy.testing import assert_, assert_raises def test_main_versions(): assert_(NumpyVersion('1.8.0') == '1.8.0') for ver in ['1.9.0', '2.0.0', '1.8.1', '10.0.1']: assert_(NumpyVersion('1.8.0') < ver) for ver in ['1.7...
65
1,999
numpy
numpy/lib/tests/test_shape_base.py
.py
import functools import sys import pytest import numpy as np from numpy import ( apply_along_axis, apply_over_axes, array_split, column_stack, dsplit, dstack, expand_dims, hsplit, kron, put_along_axis, split, take_along_axis, tile, vsplit, ) from numpy.exception...
814
27,406
numpy
numpy/lib/tests/test_twodim_base.py
.py
"""Test functions for matrix module """ import pytest import numpy as np from numpy import ( add, arange, array, diag, eye, fliplr, flipud, histogram2d, mask_indices, ones, tri, tril_indices, tril_indices_from, triu_indices, triu_indices_from, vander, ...
565
19,179
numpy
numpy/lib/tests/test_recfunctions.py
.py
import pytest import numpy as np import numpy.ma as ma from numpy.lib.recfunctions import ( append_fields, apply_along_fields, assign_fields_by_name, drop_fields, find_duplicates, get_fieldstructure, join_by, merge_arrays, recursive_fill_fields, rename_fields, repack_fields,...
1,043
43,973
numpy
numpy/lib/tests/test_histograms.py
.py
import warnings import pytest import numpy as np from numpy import histogram, histogram_bin_edges, histogramdd from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_array_max_ulp, assert_equal, assert_raises, ...
856
33,981
numpy
numpy/lib/tests/test_regression.py
.py
import numpy as np from numpy.testing import ( _assert_valid_refcount, assert_, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises, ) class TestRegression: def test_poly1d(self): # Ticket #28 assert_equal(np.poly1d([1]) - np.poly1d([1, 0]), ...
215
7,294
numpy
numpy/lib/tests/test_loadtxt.py
.py
""" Tests specific to `np.loadtxt` added during the move of loadtxt to be backed by C code. These tests complement those found in `test_io.py`. """ import os import sys from io import StringIO from tempfile import NamedTemporaryFile, mkstemp import pytest import numpy as np from numpy.ma.testutils import assert_equa...
1,078
38,972
numpy
numpy/lib/tests/test_index_tricks.py
.py
import pytest import numpy as np from numpy.lib._index_tricks_impl import ( c_, diag_indices, diag_indices_from, fill_diagonal, index_exp, ix_, mgrid, ndenumerate, ndindex, ogrid, r_, s_, ) from numpy.testing import ( assert_, assert_almost_equal, assert_arra...
704
24,688
numpy
numpy/lib/tests/test_io.py
.py
import gzip import locale import os import re import sys import threading import time import warnings import zipfile from ctypes import c_bool from datetime import datetime from io import BytesIO, StringIO from multiprocessing import Value, get_context from pathlib import Path from tempfile import NamedTemporaryFile i...
2,734
106,044
numpy
numpy/lib/tests/test_function_base.py
.py
import decimal import math import operator import sys import warnings from fractions import Fraction from functools import partial import pytest import numpy as np import numpy.lib._function_base_impl as nfb from numpy import ( angle, average, bartlett, blackman, corrcoef, cov, delete, ...
5,085
193,578
numpy
numpy/lib/tests/test_mixins.py
.py
import numbers import operator import numpy as np from numpy.testing import assert_, assert_equal, assert_raises # NOTE: This class should be kept as an exact copy of the example from the # docstring for NDArrayOperatorsMixin. class ArrayLike(np.lib.mixins.NDArrayOperatorsMixin): def __init__(self, value): ...
216
7,009
numpy
numpy/lib/tests/test_stride_tricks.py
.py
import pytest import numpy as np from numpy._core._rational_tests import rational, rational2 from numpy.lib._stride_tricks_impl import ( _broadcast_shape, as_strided, broadcast_arrays, broadcast_shapes, broadcast_to, sliding_window_view, ) from numpy.testing import ( assert_, assert_arr...
891
29,979
numpy
numpy/lib/tests/test_nanfunctions.py
.py
import inspect import warnings from functools import partial import pytest import numpy as np from numpy._core.numeric import normalize_axis_tuple from numpy.exceptions import AxisError, ComplexWarning from numpy.lib._nanfunctions_impl import _nan_mask, _replace_nan from numpy.testing import ( assert_, assert...
1,450
54,757
numpy
numpy/lib/tests/test_ufunclike.py
.py
import pytest import numpy as np from numpy import fix, isneginf, isposinf from numpy.testing import assert_, assert_array_equal, assert_equal, assert_raises class TestUfunclike: def test_isposinf(self): a = np.array([np.inf, -np.inf, np.nan, 0.0, 3.0, -3.0]) out = np.zeros(a.shape, bool) ...
122
3,959
numpy
numpy/lib/tests/test_array_utils.py
.py
import numpy as np from numpy.lib import array_utils from numpy.testing import assert_equal class TestByteBounds: def test_byte_bounds(self): # pointer difference matches size * itemsize # due to contiguity a = np.arange(12).reshape(3, 4) low, high = array_utils.byte_bounds(a) ...
33
1,118
numpy
numpy/lib/tests/test_polynomial.py
.py
import pytest import numpy as np import numpy.polynomial.polynomial as poly from numpy.testing import ( assert_, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_equal, assert_raises, ) # `poly1d` has some support for `np.bool` and `np.timedelta64...
334
12,723
numpy
numpy/lib/tests/test__iotools.py
.py
import time from datetime import date import pytest import numpy as np from numpy.lib._iotools import ( LineSplitter, NameValidator, StringConverter, easy_dtype, flatten_dtype, has_nested_fields, ) from numpy.testing import assert_, assert_allclose, assert_equal, assert_raises class TestLine...
359
13,830
numpy
numpy/lib/tests/test__datasource.py
.py
import os import urllib.request as urllib_request from pathlib import Path from shutil import rmtree from tempfile import NamedTemporaryFile, mkdtemp, mkstemp from urllib.error import URLError from urllib.parse import urlparse import pytest import numpy.lib._datasource as datasource from numpy.testing import assert_,...
376
12,273
numpy
numpy/lib/tests/test_type_check.py
.py
import pytest import numpy as np from numpy import ( common_type, iscomplex, iscomplexobj, isneginf, isposinf, isreal, isrealobj, mintypecode, nan_to_num, real_if_close, ) from numpy.testing import assert_, assert_array_equal, assert_equal def assert_all(x): assert_(np.all...
484
15,234
numpy
numpy/lib/tests/test_utils.py
.py
from io import StringIO import pytest import numpy as np import numpy.lib._utils_impl as _utils_impl from numpy.testing import assert_raises_regex def test_assert_raises_regex_context_manager(): with assert_raises_regex(ValueError, 'no deprecation warning'): raise ValueError('no deprecation warning') ...
81
2,374
numpy
numpy/lib/tests/test_arraypad.py
.py
"""Tests for the array padding functions. """ import pytest import numpy as np from numpy.lib._arraypad_impl import _as_pairs from numpy.testing import assert_allclose, assert_array_equal, assert_equal _numeric_dtypes = ( np._core.sctypes["uint"] + np._core.sctypes["int"] + np._core.sctypes["float"] ...
1,492
59,463
numpy
numpy/lib/tests/test_packbits.py
.py
import pytest import numpy as np from numpy.testing import assert_array_equal, assert_equal, assert_raises def test_packbits(): # Copied from the docstring. a = [[[1, 0, 1], [0, 1, 0]], [[1, 1, 0], [0, 0, 1]]] for dt in '?bBhHiIlLqQ': arr = np.array(a, dtype=dt) b = np.packbits(a...
375
17,508
numpy
numpy/_typing/__init__.py
.py
"""Private counterpart of ``numpy.typing``.""" from ._array_like import ( ArrayLike as ArrayLike, NDArray as NDArray, _ArrayLike as _ArrayLike, _ArrayLikeAnyString_co as _ArrayLikeAnyString_co, _ArrayLikeBool_co as _ArrayLikeBool_co, _ArrayLikeBytes_co as _ArrayLikeBytes_co, _ArrayLikeCompl...
139
4,348
numpy
numpy/_typing/_add_docstring.py
.py
"""A module for creating docstrings for sphinx ``data`` domains.""" import re import textwrap from ._array_like import NDArray _docstrings_list = [] def add_newdoc(name: str, value: str, doc: str) -> None: """Append ``_docstrings_list`` with a docstring for `name`. Parameters ---------- name : str...
154
3,902
numpy
numpy/_typing/_char_codes.py
.py
from typing import Literal type _BoolCodes = Literal["bool", "bool_", "?", "b1", "|b1", "=b1", "<b1", ">b1"] type _Int8Codes = Literal["int8", "byte", "b", "i1", "|i1", "=i1", "<i1", ">i1"] type _Int16Codes = Literal["int16", "short", "h", "i2", "|i2", "=i2", "<i2", ">i2"] type _Int32Codes = Literal["int32", "i4", "|...
157
6,562
numpy
numpy/_typing/_array_like.py
.py
from collections.abc import Buffer, Callable, Collection from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable import numpy as np if TYPE_CHECKING: from numpy.dtypes import StringDType else: from numpy._core.multiarray import StringDType from ._nbit_base import _32Bit, _64Bit from ._nested_seque...
93
3,391
numpy
numpy/_typing/_dtype_like.py
.py
from collections.abc import Sequence from typing import Any, NotRequired, Protocol, TypedDict, runtime_checkable import numpy as np from ._char_codes import ( _BoolCodes, _BytesCodes, _ComplexFloatingCodes, _DT64Codes, _FloatingCodes, _NumberCodes, _ObjectCodes, _SignedIntegerCodes, ...
109
3,706
numpy
numpy/_typing/_nbit_base.py
.py
"""A module with the precisions of generic `~numpy.number` types.""" from typing import final from numpy._utils import set_module @final # Disallow the creation of arbitrary `NBitBase` subclasses @set_module("numpy.typing") class NBitBase: """ A type representing `numpy.number` precision during static type ...
94
3,014
numpy
numpy/_typing/_shape.py
.py
from collections.abc import Sequence from typing import Any, SupportsIndex type _Shape = tuple[int, ...] type _AnyShape = tuple[Any, ...] # Anything that can be coerced to a shape tuple type _ShapeLike = SupportsIndex | Sequence[SupportsIndex]
9
246
numpy
numpy/_typing/_nbit.py
.py
"""A module with the precisions of platform-specific `~numpy.number`s.""" from ._nbit_base import _8Bit, _16Bit, _32Bit, _64Bit, _96Bit, _128Bit type _NBitByte = _8Bit type _NBitShort = _16Bit type _NBitIntC = _32Bit type _NBitIntP = _32Bit | _64Bit type _NBitInt = _NBitIntP type _NBitLong = _32Bit | _64Bit type _NBi...
17
465
numpy
numpy/_typing/_scalars.py
.py
from typing import Any import numpy as np # NOTE: `_StrLike_co` and `_BytesLike_co` are pointless, as `np.str_` and # `np.bytes_` are already subclasses of their builtin counterpart type _CharLike_co = str | bytes # The `<X>Like_co` type-aliases below represent all scalars that can be # coerced into `<X>` (with the ...
21
873
numpy
numpy/_typing/_nested_sequence.py
.py
"""A module containing the `_NestedSequence` protocol.""" from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable if TYPE_CHECKING: from collections.abc import Iterator from typing_extensions import TypeVar _T_co = TypeVar("_T_co", covariant=True, default=Any) else: from typing import Type...
86
2,640
numpy
numpy/core/getlimits.py
.py
def __getattr__(attr_name): from numpy._core import getlimits from ._utils import _raise_warning ret = getattr(getlimits, attr_name, None) if ret is None: raise AttributeError( f"module 'numpy.core.getlimits' has no attribute {attr_name}") _raise_warning(attr_name, "getlimits") ...
11
335
numpy
numpy/core/_utils.py
.py
import warnings def _raise_warning(attr: str, submodule: str | None = None) -> None: new_module = "numpy._core" old_module = "numpy.core" if submodule is not None: new_module = f"{new_module}.{submodule}" old_module = f"{old_module}.{submodule}" warnings.warn( f"{old_module} is...
22
923
numpy
numpy/core/function_base.py
.py
def __getattr__(attr_name): from numpy._core import function_base from ._utils import _raise_warning ret = getattr(function_base, attr_name, None) if ret is None: raise AttributeError( f"module 'numpy.core.function_base' has no attribute {attr_name}") _raise_warning(attr_name, "...
11
351
numpy
numpy/core/einsumfunc.py
.py
def __getattr__(attr_name): from numpy._core import einsumfunc from ._utils import _raise_warning ret = getattr(einsumfunc, attr_name, None) if ret is None: raise AttributeError( f"module 'numpy.core.einsumfunc' has no attribute {attr_name}") _raise_warning(attr_name, "einsumfun...
11
339
numpy
numpy/core/numeric.py
.py
def __getattr__(attr_name): from numpy._core import numeric from ._utils import _raise_warning sentinel = object() ret = getattr(numeric, attr_name, sentinel) if ret is sentinel: raise AttributeError( f"module 'numpy.core.numeric' has no attribute {attr_name}") _raise_warni...
13
360
numpy
numpy/core/records.py
.py
def __getattr__(attr_name): from numpy._core import records from ._utils import _raise_warning ret = getattr(records, attr_name, None) if ret is None: raise AttributeError( f"module 'numpy.core.records' has no attribute {attr_name}") _raise_warning(attr_name, "records") retu...
11
327
numpy
numpy/core/defchararray.py
.py
def __getattr__(attr_name): from numpy._core import defchararray from ._utils import _raise_warning ret = getattr(defchararray, attr_name, None) if ret is None: raise AttributeError( f"module 'numpy.core.defchararray' has no attribute {attr_name}") _raise_warning(attr_name, "def...
11
347