Skip to content

ENH: Add binding for random pyx files #21975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2023
Merged

Conversation

bashtage
Copy link
Contributor

Add binding so that inspect will work correctly

closes #21908

@bashtage
Copy link
Contributor Author

No idea if this is side effect free, but should fix the issue.

@bashtage
Copy link
Contributor Author

Failing because binging=True leads to some unused variables being produced by Cython.

@bashtage
Copy link
Contributor Author

Does fix the inspect issue.

In [1]: import numpy as np

In [2]: import inspect

In [3]: inspect.signature(np.random.bytes)
Out[3]: <Signature (length)>

In [4]: sig = inspect.signature(np.random.bytes)

In [5]: sig.parameters
Out[5]: mappingproxy({'length': <Parameter "length">})

In [6]: gen = np.random.default_rng(0)

In [7]: inspect.signature(gen.integers)
Out[7]: <Signature (low, high, size, dtype, endpoint)>

@bashtage
Copy link
Contributor Author

Not sure why Cython is introducing so many unused variables. Only happens in generator not mtrand.

    INFO: building 'numpy.random._generator' extension
    INFO: compiling C sources
    INFO: C compiler: gcc -pthread -B /home/kevin/anaconda/envs/throw-away/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -Wall -fPIC -O2 -isystem /home/kevin/anaconda/envs/throw-away/include -I/home/kevin/anaconda/envs/throw-away/include -fPIC -O2 -isystem /home/kevin/anaconda/envs/throw-away/include -fPIC

    INFO: compile options: '-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNPY_NO_DEPRECATED_API=0 -Inumpy/random -Inumpy/random/src -Inumpy/core/include -Inumpy/core/include/numpy -Ibuild/src.linux-x86_64-3.9/numpy/distutils/include -Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/src/_simd -I/home/kevin/anaconda/envs/throw-away/include/python3.9 -Inumpy/core/src/common -Inumpy/core/src/npymath -I/home/kevin/anaconda/envs/throw-away/include/python3.9 -c'
    extra options: '-U__GNUC_GNU_INLINE__ -msse -msse2 -msse3'
    INFO: gcc: numpy/random/_generator.c
    numpy/random/_generator.c:37271:20: warning: ‘__pyx_mdef___pyx_memoryviewslice_3__setstate_cython__’ defined but not used [-Wunused-variable]
    37271 | static PyMethodDef __pyx_mdef___pyx_memoryviewslice_3__setstate_cython__ = {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_3__setstate_cython__, METH_O, 0};
          |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    numpy/random/_generator.c:37213:20: warning: ‘__pyx_mdef___pyx_memoryviewslice_1__reduce_cython__’ defined but not used [-Wunused-variable]
    37213 | static PyMethodDef __pyx_mdef___pyx_memoryviewslice_1__reduce_cython__ = {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_1__reduce_cython__, METH_NOARGS, 0};
          |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    numpy/random/_generator.c:34368:20: warning: ‘__pyx_mdef___pyx_memoryview_3__setstate_cython__’ defined but not used [-Wunused-variable]
    34368 | static PyMethodDef __pyx_mdef___pyx_memoryview_3__setstate_cython__ = {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_3__setstate_cython__, METH_O, 0};
          |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    numpy/random/_generator.c:34310:20: warning: ‘__pyx_mdef___pyx_memoryview_1__reduce_cython__’ defined but not used [-Wunused-variable]
    34310 | static PyMethodDef __pyx_mdef___pyx_memoryview_1__reduce_cython__ = {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_1__reduce_cython__, METH_NOARGS, 0};
          |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    numpy/random/_generator.c:34216:20: warning: ‘__pyx_mdef_15View_dot_MemoryView_10memoryview_23copy_fortran’ defined but not used [-Wunused-variable]
    34216 | static PyMethodDef __pyx_mdef_15View_dot_MemoryView_10memoryview_23copy_fortran = {"copy_fortran", (PyCFunction)__pyx_memoryview_copy_fortran, METH_NOARGS, 0};
          |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    numpy/random/_generator.c:34121:20: warning: ‘__pyx_mdef_15View_dot_MemoryView_10memoryview_21copy’ defined but not used [-Wunused-variable]
    34121 | static PyMethodDef __pyx_mdef_15View_dot_MemoryView_10memoryview_21copy = {"copy", (PyCFunction)__pyx_memoryview_copy, METH_NOARGS, 0};
          |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    numpy/random/_generator.c:34044:20: warning: ‘__pyx_mdef_15View_dot_MemoryView_10memoryview_19is_f_contig’ defined but not used [-Wunused-variable]
    34044 | static PyMethodDef __pyx_mdef_15View_dot_MemoryView_10memoryview_19is_f_contig = {"is_f_contig", (PyCFunction)__pyx_memoryview_is_f_contig, METH_NOARGS, 0};
          |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    numpy/random/_generator.c:33967:20: warning: ‘__pyx_mdef_15View_dot_MemoryView_10memoryview_17is_c_contig’ defined but not used [-Wunused-variable]
    33967 | static PyMethodDef __pyx_mdef_15View_dot_MemoryView_10memoryview_17is_c_contig = {"is_c_contig", (PyCFunction)__pyx_memoryview_is_c_contig, METH_NOARGS, 0};
          |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    numpy/random/_generator.c:30094:20: warning: ‘__pyx_mdef___pyx_MemviewEnum_3__setstate_cython__’ defined but not used [-Wunused-variable]
    30094 | static PyMethodDef __pyx_mdef___pyx_MemviewEnum_3__setstate_cython__ = {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_3__setstate_cython__, METH_O, 0};
          |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    numpy/random/_generator.c:29858:20: warning: ‘__pyx_mdef___pyx_MemviewEnum_1__reduce_cython__’ defined but not used [-Wunused-variable]
    29858 | static PyMethodDef __pyx_mdef___pyx_MemviewEnum_1__reduce_cython__ = {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_1__reduce_cython__, METH_NOARGS, 0};
          |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    numpy/random/_generator.c:29480:20: warning: ‘__pyx_mdef___pyx_array_3__setstate_cython__’ defined but not used [-Wunused-variable]
    29480 | static PyMethodDef __pyx_mdef___pyx_array_3__setstate_cython__ = {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_array_3__setstate_cython__, METH_O, 0};
          |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    numpy/random/_generator.c:29422:20: warning: ‘__pyx_mdef___pyx_array_1__reduce_cython__’ defined but not used [-Wunused-variable]
    29422 | static PyMethodDef __pyx_mdef___pyx_array_1__reduce_cython__ = {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_array_1__reduce_cython__, METH_NOARGS, 0};
          |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    INFO: gcc -pthread -B /home/kevin/anaconda/envs/throw-away/compiler_compat -shared -Wl,-rpath,/home/kevin/anaconda/envs/throw-away/lib -Wl,-rpath-link,/home/kevin/anaconda/envs/throw-away/lib -L/home/kevin/anaconda/envs/throw-away/lib -L/home/kevin/anaconda/envs/throw-away/lib -Wl,-rpath,/home/kevin/anaconda/envs/throw-away/lib -Wl,-rpath-link,/home/kevin/anaconda/envs/throw-away/lib -L/home/kevin/anaconda/envs/throw-away/lib build/temp.linux-x86_64-3.9/numpy/random/_generator.o -Lbuild/temp.linux-x86_64-3.9 -lnpyrandom -lm -lnpymath -o numpy/random/_generator.cpython-39-x86_64-linux-gnu.so

@WarrenWeckesser
Copy link
Member

Quick link for anyone looking for information about binding: Source Files and Compilation / Compiler directives / binding.

@rgommers
Copy link
Member

It may make sense to suppress the warnings by injecting -Wno-unused-variable in the build to get this merged. In parallel, getting the issue fixed in Cython would be nice. But that shouldn't be a blocker here.

@seberg
Copy link
Member

seberg commented Jan 19, 2023

Just stumbled on this, there is already a cython issue here: cython/cython#1575 and compiler warnings in cython don't really matter to us anyway, I think.

Otherwise, this seems like a safe no-brainer to me, so it would be nice to just get it in. (I have to admit, I am not sure what the best way to do this is, so that it only affects random!)

@bashtage
Copy link
Contributor Author

Just rebased to see if time fixed this.

Add binding so that inspect will work correctly

closes numpy#21908
@seberg
Copy link
Member

seberg commented Jul 24, 2023

Let's try close/reopen again, I somewhat doubt things changed, but it seems like the easiest thing to see whether cython 3 shipped a fix.

@bashtage
Copy link
Contributor Author

I might need to rebase/merge to get the latest requirements and CI configs.

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks like tests are passing, so I think we are fine, and I don't think we added a global warning ignore for this (or I hope so :)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Functions in numpy.random have no signature (in the sense of inspect.signature)
4 participants