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

Bug pure-Python mode and fused types? #3142

Open
paugier opened this issue Sep 12, 2019 · 1 comment

Comments

@paugier
Copy link

commented Sep 12, 2019

This .pyx file can be compiled:

import cython

import numpy as np
cimport numpy as np

ctypedef fused A:
    np.int_t[:]
    np.float_t[:]

cpdef func(A arg):
    cdef A arr = np.empty_like(arg)
    return arr

but this doesn't work whereas it seems to me that it should mean the same thing in pure-Python mode (Is it true?):

bug.py:

import numpy as np

def func(arg):
    arr = np.empty_like(arg)
    return arr

bug.pxd:

import cython

import numpy as np
cimport numpy as np

ctypedef fused A:
    np.int_t[:]
    np.float_t[:]

@cython.locals(arr=A)
cpdef func(A arg)

The error log:

Compiling bug.py because it changed.
[1/1] Cythonizing bug.py

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
    arr = np.empty_like(arg)
                      ^
------------------------------------------------------------

bug.py:4:23: Cannot coerce to a type that is not specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
    arr = np.empty_like(arg)
    return arr
          ^
------------------------------------------------------------

bug.py:5:11: Type is not specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
    arr = np.empty_like(arg)
                      ^
------------------------------------------------------------

bug.py:4:23: Cannot coerce to a type that is not specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
    arr = np.empty_like(arg)
    return arr
          ^
------------------------------------------------------------

bug.py:5:11: Type is not specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
    arr = np.empty_like(arg)
   ^
------------------------------------------------------------

bug.py:4:4: Invalid use of fused types, type cannot be specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
    arr = np.empty_like(arg)
   ^
------------------------------------------------------------

bug.py:4:4: Invalid use of fused types, type cannot be specialized
Traceback (most recent call last):
  File "/home/users/augier3pi/.pyenv/versions/3.7.3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/users/augier3pi/.pyenv/versions/3.7.3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/users/augier3pi/Dev/transonic/transonic_cl/cythonize.py", line 11, in <module>
    ext_modules=cythonize(path, language_level=3), include_dirs=[np.get_include()]
  File "/home/users/augier3pi/.pyenv/versions/3.7.3/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 1096, in cythonize
    cythonize_one(*args)
  File "/home/users/augier3pi/.pyenv/versions/3.7.3/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 1219, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: bug.py
@scoder

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2019

The code looks reasonable to me, so I consider it a bug that it doesn't work. My guess is that the directive_locals handling in the AnalyseDeclarationsTransform does not take (enough?) care about fused types.

Further investigation and PR welcome.

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