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

Open
h5rdly opened this Issue Dec 27, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@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

This comment has been minimized.

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

h5rdly commented Dec 30, 2018

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

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