diff options
Diffstat (limited to '.venv/lib/python3.12/site-packages/numpy/core/tests/examples/cython')
3 files changed, 96 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/cython/checks.pyx b/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/cython/checks.pyx new file mode 100644 index 00000000..c5529ee8 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/cython/checks.pyx @@ -0,0 +1,35 @@ +#cython: language_level=3 + +""" +Functions in this module give python-space wrappers for cython functions +exposed in numpy/__init__.pxd, so they can be tested in test_cython.py +""" +cimport numpy as cnp +cnp.import_array() + + +def is_td64(obj): + return cnp.is_timedelta64_object(obj) + + +def is_dt64(obj): + return cnp.is_datetime64_object(obj) + + +def get_dt64_value(obj): + return cnp.get_datetime64_value(obj) + + +def get_td64_value(obj): + return cnp.get_timedelta64_value(obj) + + +def get_dt64_unit(obj): + return cnp.get_datetime64_unit(obj) + + +def is_integer(obj): + return isinstance(obj, (cnp.integer, int)) + +def conv_intp(cnp.intp_t val): + return val diff --git a/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/cython/meson.build b/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/cython/meson.build new file mode 100644 index 00000000..836b74ac --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/cython/meson.build @@ -0,0 +1,36 @@ +project('checks', 'c', 'cython') + +py = import('python').find_installation(pure: false) + +cc = meson.get_compiler('c') +cy = meson.get_compiler('cython') + +if not cy.version().version_compare('>=0.29.35') + error('tests requires Cython >= 0.29.35') +endif + +npy_include_path = run_command(py, [ + '-c', + 'import os; os.chdir(".."); import numpy; print(os.path.abspath(numpy.get_include()))' + ], check: true).stdout().strip() + +npy_path = run_command(py, [ + '-c', + 'import os; os.chdir(".."); import numpy; print(os.path.dirname(numpy.__file__).removesuffix("numpy"))' + ], check: true).stdout().strip() + +# TODO: This is a hack due to gh-25135, where cython may not find the right +# __init__.pyd file. +add_project_arguments('-I', npy_path, language : 'cython') + +py.extension_module( + 'checks', + 'checks.pyx', + install: false, + c_args: [ + '-DNPY_NO_DEPRECATED_API=0', # Cython still uses old NumPy C API + # Require 1.25+ to test datetime additions + '-DNPY_TARGET_VERSION=NPY_2_0_API_VERSION', + ], + include_directories: [npy_include_path], +) diff --git a/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/cython/setup.py b/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/cython/setup.py new file mode 100644 index 00000000..6e34aa77 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/cython/setup.py @@ -0,0 +1,25 @@ +""" +Provide python-space access to the functions exposed in numpy/__init__.pxd +for testing. +""" + +import numpy as np +from distutils.core import setup +from Cython.Build import cythonize +from setuptools.extension import Extension +import os + +macros = [("NPY_NO_DEPRECATED_API", 0)] + +checks = Extension( + "checks", + sources=[os.path.join('.', "checks.pyx")], + include_dirs=[np.get_include()], + define_macros=macros, +) + +extensions = [checks] + +setup( + ext_modules=cythonize(extensions) +) |
