Skip to content
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

cythonize does not trigger a recompile when .pxd dependency has changed #3208

Open
synapticarbors opened this issue Oct 25, 2019 · 0 comments

Comments

@synapticarbors
Copy link

@synapticarbors synapticarbors commented Oct 25, 2019

If I have a setup.py that looks like:

from distutils.core import setup
from distutils.extension import Extension

from Cython.Build import cythonize

import numpy

extensions = [
    Extension('mod1.ftest', ['mod1/ftest.pyx'],
              depends=['mod1/ftypes.pxd'],
              include_dirs=[numpy.get_include()])
]

setup(name='', ext_modules=cythonize(extensions, language_level='3'))

where mod1/ftest.pyx looks like:

from . ftypes cimport a_type


cpdef double test_func(a_type[::1] x):
    cdef:
        int i
        double res

    res = 0.0

    for i in range(x.shape[0]):
        res += x[i].a1 * x[i].a3

    return res

and mod1/ftypes.pxd looks like:

import numpy as np
cimport numpy as np

cdef packed struct a_type:
    np.float64 ax
    np.int32_t a1
    np.int16_t a2
    np.int32_t a3

when I modify the contents of mod1/ftypes.pxd, the cythonize call in setup.py does not trigger a compilation of ftest.pyx. If that change involved uncommenting the first line in the struct a_type definition, this gives an error like:

ValueError: Buffer dtype mismatch, expected 'int32_t' but got 'double' in 'a_type.a1'

when passing in a numpy recarray that assumes that the ax field is now defined.

This might be related to #1428. As mod1/ftypes.pxd is a dependency of mod1/ftest.pyx, it seems like perhaps the dependency tree is not complete in terms of the recompilation decision process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.