I need more perfomance running my neural network, so I thinked that building it with cython will be good idea. I am building my code like this:
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("my_code.pyx")
)
But will it build external python files that I use? Like pybrain, skimage and PIL in my case. If not, how to force cython to build them.
No, external python files will not be cythonized and compiled unless you specifically add them to your setup.py as an extension. As far as I know there is no trivial way to do this.
This means that all calls to the external files will be handled in 'Python-space' and hence can not use the full potential of Cython. For example all calls to an external file will be type checked, which wastes a lot of time. You can see this if you cythonize a file using cython -a yourfile.pyx and take a look at the created C code. The more yellow there is the more pythony your code is.
You have the following options:
I personally would go with option three, as options one and two both might require a lot of work on your side with questionable outcome.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With