diff options
| author | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
|---|---|---|
| committer | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
| commit | 4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch) | |
| tree | ee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/numpy/core/tests/examples | |
| parent | cc961e04ba734dd72309fb548a2f97d67d578813 (diff) | |
| download | gn-ai-master.tar.gz | |
Diffstat (limited to '.venv/lib/python3.12/site-packages/numpy/core/tests/examples')
5 files changed, 135 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) +) diff --git a/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/limited_api/limited_api.c b/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/limited_api/limited_api.c new file mode 100644 index 00000000..698c54c5 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/limited_api/limited_api.c @@ -0,0 +1,17 @@ +#define Py_LIMITED_API 0x03060000 + +#include <Python.h> +#include <numpy/arrayobject.h> +#include <numpy/ufuncobject.h> + +static PyModuleDef moduledef = { + .m_base = PyModuleDef_HEAD_INIT, + .m_name = "limited_api" +}; + +PyMODINIT_FUNC PyInit_limited_api(void) +{ + import_array(); + import_umath(); + return PyModule_Create(&moduledef); +} diff --git a/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/limited_api/setup.py b/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/limited_api/setup.py new file mode 100644 index 00000000..18747dc8 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/core/tests/examples/limited_api/setup.py @@ -0,0 +1,22 @@ +""" +Build an example package using the limited Python C API. +""" + +import numpy as np +from setuptools import setup, Extension +import os + +macros = [("NPY_NO_DEPRECATED_API", 0), ("Py_LIMITED_API", "0x03060000")] + +limited_api = Extension( + "limited_api", + sources=[os.path.join('.', "limited_api.c")], + include_dirs=[np.get_include()], + define_macros=macros, +) + +extensions = [limited_api] + +setup( + ext_modules=extensions +) |
