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

Document @cython.compile #2770

Closed
h5rdly opened this issue Dec 27, 2018 · 4 comments · Fixed by #4551
Closed

Document @cython.compile #2770

h5rdly opened this issue Dec 27, 2018 · 4 comments · Fixed by #4551
Milestone

Comments

@h5rdly
Copy link

h5rdly commented Dec 27, 2018

Hi,

I was wondering whethter there is a way, or it is possible to add a way, to do something like:

from cython import cythonize, other, cython, magics

@cythonize  # Decorator of interest
@other 
@cython
@magics
def slow_function_at_work():
      # omg so slow

# slow function is fast at this point

I dug a bit inside some cython files, and saw there's a pyx_to_dll function, and a cython_inline function.

Is it perhaps possible to -

  • Make pyx_to_dll read StringIO objects (probably not since I saw that path is formed into a command string)
  • Somehow work with cython_inline(inspect.getsource(slow_function))
  • Use some other method

So that one can @cythonize his functions in pure mode?

I think this is the epitome of pure mode - the ability to decorate and move along, and let cython hook in the sped up code.

Thanks,
Eli

@scoder scoder changed the title Function compilation decorator for pure mode Document @cython.compile Dec 27, 2018
@scoder
Copy link
Contributor

scoder commented Dec 27, 2018

Looks like @cython.compile is undocumented, that's what you want. It should be mentioned here, preferably somewhere close to @cython.inline.

@h5rdly
Copy link
Author

h5rdly commented Dec 27, 2018

Sweet, thanks!

It looks like RuntimeCompiledFunction in fact uses cython_inline.
Are you aware of -
https://github.com/AlanCristhian/statically

This package also seems to use a similar technique, but has more meat to it -
https://github.com/AlanCristhian/statically/blob/master/statically.py

Edit:
Does @cython.compile take into account the other magics, eg locals, returns, cfunc, nogil etc?

@scoder
Copy link
Contributor

scoder commented Dec 29, 2018

Does @cython.compile take into account the other magics, eg locals, returns, cfunc, nogil etc?

I would hope so, but since it's undocumented, you'd better try it out. If it does not, then that's probably just an easy to fix bug.

@h5rdly
Copy link
Author

h5rdly commented Dec 30, 2018

Sorry if it's silly, but how can I see in runtime what @compile generated?

scoder pushed a commit that referenced this issue Jan 2, 2022
@scoder scoder added this to the 3.0 milestone Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants