Cython: Compiled Code Meets Dynamic Python

Cython: Compiled Code Meets Dynamic Python

Cython: Compiled Code meets Dynamic Python Robert Bradshaw Google, Inc., Seattle Lisandro Dalcin Centro Int. de M´etodos Computacionales en Ingenier´ıa,Argentina () Cython SIAM CSE 2011 1 / 21 interactive portable easy to learn, read, and write general purpose free and open source and has large, friendly communities of scientific and non-scientific developers and users. ...so what's the catch? Python Python is high-level () Cython SIAM CSE 2011 2 / 21 portable easy to learn, read, and write general purpose free and open source and has large, friendly communities of scientific and non-scientific developers and users. ...so what's the catch? Python Python is high-level interactive () Cython SIAM CSE 2011 2 / 21 easy to learn, read, and write general purpose free and open source and has large, friendly communities of scientific and non-scientific developers and users. ...so what's the catch? Python Python is high-level interactive portable () Cython SIAM CSE 2011 2 / 21 general purpose free and open source and has large, friendly communities of scientific and non-scientific developers and users. ...so what's the catch? Python Python is high-level interactive portable easy to learn, read, and write () Cython SIAM CSE 2011 2 / 21 free and open source and has large, friendly communities of scientific and non-scientific developers and users. ...so what's the catch? Python Python is high-level interactive portable easy to learn, read, and write general purpose () Cython SIAM CSE 2011 2 / 21 and has large, friendly communities of scientific and non-scientific developers and users. ...so what's the catch? Python Python is high-level interactive portable easy to learn, read, and write general purpose free and open source () Cython SIAM CSE 2011 2 / 21 ...so what's the catch? Python Python is high-level interactive portable easy to learn, read, and write general purpose free and open source and has large, friendly communities of scientific and non-scientific developers and users. () Cython SIAM CSE 2011 2 / 21 Python Python is high-level interactive portable easy to learn, read, and write general purpose free and open source and has large, friendly communities of scientific and non-scientific developers and users. ...so what's the catch? () Cython SIAM CSE 2011 2 / 21 Python For some usecases, Python, by itself, is too slow. () Cython SIAM CSE 2011 3 / 21 Where to draw the line? (see above) Span multiple languages, extra wrapper code. Does your entire project merit the tedious write/compile/debug cycle? \Premature optimization is the root of all evil." Use a low-level language with wrappers. Performance What some the options? Use a low-level language for the entire application/stack. () Cython SIAM CSE 2011 4 / 21 Where to draw the line? (see above) Span multiple languages, extra wrapper code. Use a low-level language with wrappers. Performance What some the options? Use a low-level language for the entire application/stack. Does your entire project merit the tedious write/compile/debug cycle? \Premature optimization is the root of all evil." () Cython SIAM CSE 2011 4 / 21 Where to draw the line? (see above) Span multiple languages, extra wrapper code. Performance What some the options? Use a low-level language for the entire application/stack. Does your entire project merit the tedious write/compile/debug cycle? \Premature optimization is the root of all evil." Use a low-level language with wrappers. () Cython SIAM CSE 2011 4 / 21 Performance What some the options? Use a low-level language for the entire application/stack. Does your entire project merit the tedious write/compile/debug cycle? \Premature optimization is the root of all evil." Use a low-level language with wrappers. Where to draw the line? (see above) Span multiple languages, extra wrapper code. () Cython SIAM CSE 2011 4 / 21 Spans high and low-level paradigms. Complements existing libraries such as NumPy. NumPy, SciPy, etc. Heavy lifting done by same BLAS, C, FORTRAN, backends/algorithms as low-level language. Not all algorithms are easily expressed in terms of vectorized rectangular array operations. Use Cython. Performance What are some options? Use existing, optimized Python libraries. () Cython SIAM CSE 2011 5 / 21 Spans high and low-level paradigms. Complements existing libraries such as NumPy. Use Cython. Performance What are some options? Use existing, optimized Python libraries. NumPy, SciPy, etc. Heavy lifting done by same BLAS, C, FORTRAN, backends/algorithms as low-level language. Not all algorithms are easily expressed in terms of vectorized rectangular array operations. () Cython SIAM CSE 2011 5 / 21 Spans high and low-level paradigms. Complements existing libraries such as NumPy. Performance What are some options? Use existing, optimized Python libraries. NumPy, SciPy, etc. Heavy lifting done by same BLAS, C, FORTRAN, backends/algorithms as low-level language. Not all algorithms are easily expressed in terms of vectorized rectangular array operations. Use Cython. () Cython SIAM CSE 2011 5 / 21 Performance What are some options? Use existing, optimized Python libraries. NumPy, SciPy, etc. Heavy lifting done by same BLAS, C, FORTRAN, backends/algorithms as low-level language. Not all algorithms are easily expressed in terms of vectorized rectangular array operations. Use Cython. Spans high and low-level paradigms. Complements existing libraries such as NumPy. () Cython SIAM CSE 2011 5 / 21 Language extensions for statically declaring types Potentially massive speedups Integration with external libraries Python memory management and Python object $ c data type conversions done automatically. removes almost all the headaches of writing C extensions malloc, realloc, free still used for C memory management (could be imporved) What is Cython? Python to C compiler (almost) () Cython SIAM CSE 2011 6 / 21 Python memory management and Python object $ c data type conversions done automatically. removes almost all the headaches of writing C extensions malloc, realloc, free still used for C memory management (could be imporved) What is Cython? Python to C compiler (almost) Language extensions for statically declaring types Potentially massive speedups Integration with external libraries () Cython SIAM CSE 2011 6 / 21 What is Cython? Python to C compiler (almost) Language extensions for statically declaring types Potentially massive speedups Integration with external libraries Python memory management and Python object $ c data type conversions done automatically. removes almost all the headaches of writing C extensions malloc, realloc, free still used for C memory management (could be imporved) () Cython SIAM CSE 2011 6 / 21 What is Cython? Cython is the missing link between the simplicity of Python and the speed of C / C++ / Fortran. Python y t i c i l p m i S C C++ Fortran Performance () Cython SIAM CSE 2011 7 / 21 What is Cython? Cython is the missing link between the simplicity of Python and the speed of C / C++ / Fortran. Python y t i c i l Cython p m i S C C++ Fortran Performance () Cython SIAM CSE 2011 7 / 21 Code and developers Piece by piece Directly call C, C++, and Fortran code Use anything from the Python ecosystem as well Most time spent in a small amount of code Maintain a consistent codebase Easy migration Leverage existing libraries Why Cython? Optimize only what you need () Cython SIAM CSE 2011 8 / 21 Code and developers Piece by piece Directly call C, C++, and Fortran code Use anything from the Python ecosystem as well Maintain a consistent codebase Easy migration Leverage existing libraries Why Cython? Optimize only what you need Most time spent in a small amount of code () Cython SIAM CSE 2011 8 / 21 Code and developers Piece by piece Directly call C, C++, and Fortran code Use anything from the Python ecosystem as well Easy migration Leverage existing libraries Why Cython? Optimize only what you need Most time spent in a small amount of code Maintain a consistent codebase () Cython SIAM CSE 2011 8 / 21 Directly call C, C++, and Fortran code Use anything from the Python ecosystem as well Code and developers Piece by piece Leverage existing libraries Why Cython? Optimize only what you need Most time spent in a small amount of code Maintain a consistent codebase Easy migration () Cython SIAM CSE 2011 8 / 21 Directly call C, C++, and Fortran code Use anything from the Python ecosystem as well Piece by piece Leverage existing libraries Why Cython? Optimize only what you need Most time spent in a small amount of code Maintain a consistent codebase Easy migration Code and developers () Cython SIAM CSE 2011 8 / 21 Directly call C, C++, and Fortran code Use anything from the Python ecosystem as well Leverage existing libraries Why Cython? Optimize only what you need Most time spent in a small amount of code Maintain a consistent codebase Easy migration Code and developers Piece by piece () Cython SIAM CSE 2011 8 / 21 Directly call C, C++, and Fortran code Use anything from the Python ecosystem as well Why Cython? Optimize only what you need Most time spent in a small amount of code Maintain a consistent codebase Easy migration Code and developers Piece by piece Leverage existing libraries () Cython SIAM CSE 2011 8 / 21 Use anything from the Python ecosystem as well Why Cython? Optimize only what you need Most time spent in a small amount of code Maintain a consistent codebase Easy migration Code and developers Piece by piece Leverage existing libraries Directly call C, C++, and Fortran code () Cython SIAM CSE 2011 8 / 21 Why Cython? Optimize only what you need Most time spent in a small amount of code Maintain a consistent codebase Easy migration Code and developers Piece by piece Leverage existing libraries Directly call C, C++, and Fortran code Use anything from the Python ecosystem as well () Cython SIAM CSE 2011 8 / 21 Cython has cdef attributes Cython has cdef functions Cython has cdef values and types Cython is compiled dictionary lookups complicated calling conventions object-oriented primatives How? Python is slow because of..

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    55 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us