Content deleted Content added
No edit summary Tags: Reverted Mobile edit Mobile web edit |
Ascchrvalstr (talk | contribs) m Copyedit |
||
(37 intermediate revisions by 25 users not shown) | |||
Line 5:
| name = Cython
| logo = Cython logo.svg
| developer = Robert Bradshaw, Stefan Behnel,
| released = {{Start date and age|df=yes|2007|07|28}}<ref>{{cite web |url=
| license = [[Apache License 2.0]]
| programming language = [[Python (programming language)|Python]]
| influenced_by = [[C (programming language)|C]], [[Python (programming language)|Python]]
| operating_system = [[Windows]], [[macOS]], [[Linux]]
| file_ext = .pyx, .pxd, .pxi
| website = {{official URL}}
}}
'''Cython''' ({{IPAc-en|ˈ|s|aɪ|θ|ɒ|n}}) is a [[
Cython is a [[compiled language]] that is typically used to generate [[CPython]] extension modules. Annotated Python-like code is compiled to C
Cython is written in Python and C and works on [[Microsoft Windows|Windows]], [[macOS]], and [[Linux]], producing C source files compatible with CPython 2.6, 2.7, and 3.3 and later versions. The Cython source code that Cython compiles (to C) can use both Python 2 and Python 3 syntax, defaulting to Python 2 syntax in Cython 0.x
Cython 3.0.0 was released on 17 July 2023.<ref>{{Cite web |title=Cython Changelog |url=https://cython.readthedocs.io/en/latest/src/changes.html |access-date=21 July 2023 |website=cython.org |language=en}}</ref>
Line 30:
Cython has a [[foreign function interface]] for invoking [[C (programming language)|C]]/[[C++]] [[subroutine|routines]] and the ability to declare the [[static type]] of subroutine parameters and results, local variables, and class attributes.
A Cython program that implements the same algorithm as a corresponding Python program may consume fewer computing resources such as core memory and processing cycles due to differences between the CPython and Cython execution models. A basic Python program is loaded and executed by the CPython [[virtual machine]], so both the runtime and the program itself consume computing resources. A Cython program is compiled to C code, which is further compiled to machine code, so the virtual machine is used only briefly when the program is loaded.<ref>{{cite web |last=Oliphant |first=Travis |date=20 June 2011 |url=
</ref><ref name="scipy09">{{cite
Cython employs:
Line 37:
* [[Type inference]] (optional)
* Low overhead in control structures
* Low function call overhead<ref>{{cite web |url=http://telecom.inescporto.pt/~gjc/pybindgen-benchmarks/ |title=wrapper benchmarks for several Python wrapper generators (except Cython) |access-date=28 May 2010 |archive-url=https://web.archive.org/web/20150404154630/http://telecom.inescporto.pt/~gjc/pybindgen-benchmarks/ |archive-date=4 April 2015 |url-status=dead}}</ref><ref>{{cite web |url=
Performance depends both on what C code is generated by Cython and how that code is compiled by the C compiler.<ref>{{cite web |title=Cython: C-Extensions for Python |url=http://cython.org/index.html |accessdate=22 November 2015}}</ref>
== History ==
Cython is a derivative of the [[Pyrex (programming language)|Pyrex language]],
Cython files have a <code>.pyx</code> extension. At its most basic, Cython code looks exactly like Python code. However, whereas standard Python is [[dynamic typing|dynamically typed]], in Cython, types can optionally be provided, allowing for improved performance, allowing loops to be converted into C loops where possible. For example:
Line 83:
[[File:Cython CPython Ext Module Workflow.png|thumb|Hello World in Cython]]
A sample [["Hello, World!" program|hello world]] program for Cython is more complex than in most languages because it interfaces with the Python C API and <code>setuptools</code> or other [[PEP517]]-compliant extension building facilities.{{technical inline|date=May 2024}} At least three files are required for a basic project:
* A <code>setup.py</code> file to invoke the <code>setuptools</code> build process that generates the extension module
Line 154:
== Uses ==
Cython is particularly popular among scientific users of Python,<ref name="scipy09" /><ref>{{cite web |title=inSCIght: The Scientific Computing Podcast |url=http://inscight.org/2011/03/31/episode_/ |type=Episode 6 |access-date=29 May 2011 |archive-url=https://web.archive.org/web/20141010032300/http://inscight.org/2011/03/31/episode_/ |archive-date=10 October 2014 |url-status=dead}}</ref><ref>{{cite journal |last1=Millman |first1=Jarrod |last2=Aivazis |first2=Michael |year=2011 |title=Python for Scientists and Engineers |journal=[[Computing in Science and Engineering]] |volume=13 |issue=2 |pages=9–12 |doi=10.1109/MCSE.2011.36 |bibcode=2011CSE....13b...9M |url=https://escholarship.org/uc/item/93s2v2s7}}</ref> where it has "the perfect audience" according to Python creator [[Guido van Rossum]].<ref>{{cite web |author=Guido Van Rossum |url=
* The [[free software]] [[SageMath]] computer algebra system depends on Cython, both for performance and to interface with other libraries.<ref>{{cite book |last1=Erocal |first1=Burcin |last2=Stein |first2=William |title=Mathematical Software – ICMS 2010 |chapter=The Sage Project: Unifying Free Mathematical Software to Create a Viable Alternative to Magma, Maple, Mathematica and MATLAB |year=2010
* Significant parts of the scientific computing libraries [[SciPy]], [[Pandas (software)|pandas]] and [[scikit-learn]] are written in Cython.<ref>{{cite web |url=http://docs.scipy.org/doc/scipy/reference/release.0.7.2.html |title=SciPy 0.7.2 release notes |access-date=29 May 2011 |archive-date=4 March 2016 |archive-url=https://web.archive.org/web/20160304052117/http://docs.scipy.org/doc/scipy/reference/release.0.7.2.html |url-status=dead}}</ref><ref name="jmlr">{{cite journal |last1=Pedregosa |first1=Fabian |last2=Varoquaux |first2=Gaël |last3=Gramfort |first3=Alexandre |last4=Michel |first4=Vincent |last5=Thirion |first5=Bertrand |last6=Grisel |first6=Olivier |last7=Blondel |first7=Mathieu |last8=Prettenhofer |first8=Peter |last9=Weiss |first9=Ron |last10=Dubourg |first10=Vincent |last11=Vanderplas |first11=Jake |last12=Passos |first12=Alexandre |last13=Cournapeau |first13=David |title=Scikit-learn: Machine Learning in Python |journal=[[Journal of Machine Learning Research]] |year=2011 |volume=12 |pages=2825–2830 |arxiv=1201.0490|bibcode=2011JMLR...12.2825P }}</ref>
* Some high-traffic websites such as [[Quora]] use Cython.{{better source needed|date=October 2018}}<ref>{{cite web |url=https://www.quora.com/Is-Quora-still-running-on-PyPy/answer/Alex-Yakunin |title=Is Quora still running on PyPy?}}</ref>
Cython's ___domain is not limited to just numerical computing. For example, the {{proper name|lxml}} XML toolkit is written mostly in Cython, and like its predecessor Pyrex, Cython is used to provide Python bindings for many C and C++ libraries such as the messaging library [[ZeroMQ]].<ref>{{cite web |url=
== See also ==
* [[PyPy]]
* [[Numba]]
* [[pybind]]
== References ==
|