Cython

Cython
Not to be confused with CPython.
Cython-logo.svg
Developer(s) Robert Bradshaw, Stefan Behnel, et al.
Initial release 28 July 2007 (2007-07-28)[1]
Stable release

0.15.1  (September 20, 2011; 2 months ago (2011-09-20) [2])

[+/−]
Operating system Cross-platform
Type Programming language
License Apache License
Website cython.org

Cython is a programming language to simplify writing C and C++ extension modules for the CPython Python runtime. Strictly speaking, Cython syntax is a superset of Python syntax additionally supporting:

  • Direct calling of C functions, or C++ functions/methods, from Cython code.
  • Strong typing of Cython variables, classes, and class attributes as C types.

Cython compiles to C or C++ code rather than Python, and the result is used as a Python Extension Module or as a stand-alone application embedding the CPython runtime.

Contents

History

Cython is a derivative of the Pyrex language, and supports more features and optimizations than Pyrex.[3][4]

Cython was forked from Pyrex in 2007 by developers of the Sage computer algebra package, because they were unhappy with Pyrex's limitations and could not get patches accepted by Pyrex's maintainer Greg Ewing, who envisioned a much smaller scope for his tool than the Sage developers had in mind. They then forked Pyrex as SageX. When they found people were downloading Sage just to get SageX, and developers of other packages (including Stefan Behnel, who maintains LXML) were also maintaining forks of Pyrex, SageX was split off the Sage project and merged with cython-lxml to become Cython.[5]

Advantages

The special advantage of this seamless Python/C intermix approach is that existing Python code can be tuned to almost the speed of C by just adding a few static type declarations and by making some adaptations in critical loops - without requiring complicated interface code. The coding speed and the readability of the code remains very Pythonic.[6] Due to reduced overhead in control structures (especially loops), optimistic optimisations and (limited) type inference, Cython compiled Python code usually executes faster than in the CPython 2.6.x interpreter, although the absolute improvements largely depend on the code. With type declarations, the typical speed-up for numerical/array computations is about 100x-1000x.[7][8][9] In comparison, the typical speed-up with Psyco (Python JIT compiler) is about 4x-100x.[10]

Cython has been optimised for low call overhead, so a Python call into external C/C++ code through a Cython wrapper is usually faster than with most other wrapping solutions.[11][12]

Compatibility

Cython is written in Python and works on Windows, Linux, and Mac OS X.

Uses

Cython is particularly popular among scientific users of Python ,[8][13][14] where it has "the perfect audience" according to Python developer Guido van Rossum.[15] Of particular note:

  • The free software Sage computer algebra system depends on Cython, both for performance and to interface with other libraries.[16]
  • Significant parts of the scientific and numerical computing libraries SciPy and NumPy are written in Cython.[17][18]

Cython's domain is not limited to just numerical computing. For example, the lxml XML toolkit is written mostly in Cython, and Cython is used to provide Pythonic bindings for many C and C++ libraries ranging from from the graphics library OpenGL[19] to the messaging library ZeroMQ.[20]

See also

  • Unladen Swallow, optimised CPython runtime based on LLVM
  • PyPy, JIT compiler framework and runtime environment for Python
  • Psyco, JIT specialising code optimiser for the CPython runtime
  • Shedskin, static Python-like language that compiles to C++

References

  1. ^ 28th July 2007: official Cython launch, The Cython Compiler for C-Extensions in Python, Dr. Stefan Behnel, EuroPython 2008, Vilnius/Lietuva
  2. ^ http://cython.org/#download
  3. ^ Differences between Cython and Pyrex
  4. ^ Greg Ewing, Re: VM and Language summit info for those not at Pycon (and those that are!). Message to the electronic mailing-list python-dev, 21 March 2011. Retrieved 5 May 2011.
  5. ^ Says Sage and Cython developer Robert Bradshaw at the Sage Days 29 conference. Cython: Past, Present and Future, youtube.com, 22 March 2011. Retrieved 5 May 2011.
  6. ^ Stefan Behnel, Robert Bradshaw, Craig Citro, Lisandro Dalcin, Dag Sverre Seljebotn, Kurt Smith (2011). "Cython: The Best of Both Worlds". Computing in Science and Engineering 13 (2): 31–39. doi:10.1109/MCSE.2010.118. http://research.google.com/pubs/pub36727.html. 
  7. ^ gmane.comp.python.cython.devel - Passing a pointer from Python
  8. ^ a b Dag Sverre Seljebot (2009). "Fast numerical computations with Cython". Proceedings of the 8 th Python in Science Conference (SciPy 2009): 15–22. http://conference.scipy.org/proceedings/SciPy2009/paper_2. 
  9. ^ I. Wilbers; H. P. Langtangen; Å. Ødegård (2009). B. Skallerud; H. I. Andersson. ed. "Using Cython to Speed up Numerical Python Programs" (pdf). Proceedings of MekIT'09: 495–512. http://simula.no/research/sc/publications/Simula.SC.578/simula_pdf_file. Retrieved June 14, 2011. 
  10. ^ Psyco - Introduction
  11. ^ wrapper benchmarks for several Python wrapper generators (except Cython)
  12. ^ wrapper benchmarks for Cython, Boost.Python and PyBindGen
  13. ^ inSCIght: The Scientific Computing Podcast, Episode 6
  14. ^ Jarrod Millman and Michael Aivazis (2011). "Python for Scientists and Engineers". Computing in Science and Engineering 13 (2): 9–12. doi:10.1109/MCSE.2011.36. 
  15. ^ Who also criticizes Cython: Re: VM and Language summit info for those not at Pycon (and those that are!). Message to the electronic mailing-list python-dev, 21 March 2011. Retrieved 5 May 2011.
  16. ^ Burcin Erocal and William Stein (2010). "The Sage Project: Unifying Free Mathematical Software to Create a Viable Alternative to Magma, Maple, Mathematica and MATLAB". Mathematical Software‚ ICMS 2010 (Springer Berlin / Heidelberg) 6327: 12–27. doi:10.1007/978-3-642-15582-6_4. http://wstein.org/papers/icms/icms_2010.pdf. 
  17. ^ SciPy 0.7.2 release notes
  18. ^ NumPy ticket talking about moving from Pyrex to Cython
  19. ^ PyOpenGL: The Python OpenGL Binding
  20. ^ http://www.zeromq.org/bindings:python

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Cython — Paradigmen: multiparadigmatisch Erscheinungsjahr: 2007 Entwickler: Robert Bradshaw, Stefan Behnel, et al. Aktuelle Version: 0.15.1  (19. September 2011) …   Deutsch Wikipedia

  • Cython — Автор(ы): Robert Bradshaw, Stefan Behnel и др. Релиз: 0.17.1 (26 сентября 2012 года) Испытал влияние: Pyrex Лицензия Apache License Сайт …   Википедия

  • Cython — est un langage de programmation qui simplifie l écriture d extension en langage C pour Python. La syntaxe du langage est très similaire à Python mais il supporte l appel à des fonctions en C et la déclaration d attributs de classes de type C. Il… …   Wikipédia en Français

  • Python (programming language) — infobox programming language name = Python paradigm = multi paradigm: object oriented, imperative, functional year = 1991 designer = Guido van Rossum developer = Python Software Foundation latest release version = 2.6 latest release date =… …   Wikipedia

  • Python — У этого термина существуют и другие значения, см. Python (значения). Python Класс языка: му …   Википедия

  • Пайтон — Python Класс языка: функциональный, объектно ориентированный, императивный, аспектно ориентированный Тип исполнения: интерпретация байт кода, компиляция в MSIL, компиляция в байт код Java Появился в: 1990 г …   Википедия

  • Pyrex (programming language) — Infobox Software name = Pyrex caption = developer = Greg Ewing latest release version = 0.9.8.4 latest release date = June 6, 2008 operating system = Cross platform genre = Programming language website = [http://www.cosc.canterbury.ac.nz/… …   Wikipedia

  • Comparison of programming languages — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • Sage (scientific computing software) — infobox software name = Sage caption = Sage animated .gif, y=x2 (red) vs. y=x3(blue) released = 24 February 2005 latest release version = 3.1.2 latest release date = 19 September 2008 programming language = Python, Cython operating system = Cross …   Wikipedia

  • Python (Programmiersprache) — Python Basisdaten Paradigmen: multiparadigmatisch Erscheinungsjahr: 1991 …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”