Add to Watchlist

Get native with Cython


Citation of segment
Embed Code
Purchasing a DVD Cite video

Formal Metadata

Title Get native with Cython
Title of Series EuroPython 2015
Part Number 89
Number of Parts 173
Author Behnel, Stefan
License CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
DOI 10.5446/20206
Publisher EuroPython
Release Date 2015
Language English
Production Place Bilbao, Euskadi, Spain

Content Metadata

Subject Area Computer Science
Abstract Stefan Behnel - Get native with Cython [Cython] is not only an excellent and widely used tool to speed up computational Python code, it's also a very comfortable way to talk to native code and libraries. The Cython compiler translates Python code to C or C++ code, and supports static type annotations to allow direct use of C/C++ data types and functions. The tight integration of all three languages makes it possible to freely mix Python features like generators and comprehensions with C/C++ features like native data types, pointer arithmetic or manually tuned memory management in the same code. This talk by a core developer introduces the Cython compiler by interactive code examples and presents recent enhancements in the language that continue to make Cython the best choice for the development of fast and portable Python extensions.
Keywords EuroPython Conference
EP 2015
EuroPython 2015

Related Material

hi how things so that most of the time and as you have to have something to do with the service for coming up so the current words about myself from as you know
present government on advocates and so the relative thousands working for school on which is so book subscription service so that it among new unlimited release but went on and said that consultants and trainers so 2nd training schools and most of them and working memory central for open source projects on which know only of the most well known to remain in the original moment inside a number of other users finally OK so site as this use a lot in in and the data applications and so I would like to go on to give you a bit of
a background votes what we're doing is the on so as a set of
new subscription service which is very logical lots of those 130 thousand publisher titles and actual publisher titles of itself publishing something and that's also the available to everyone members subscriber anywhere anytime just sit and look real and and want to have a camera of that size becomes kind of kind of treaty 0 . inevitable as it becomes difficult for people to find the books of and they want to read and so that's a problem where which states with the question is how the at work so there's lots of stuff in rural and recommendations of tolerate recommendations but you can vary scale on to you know what you believe that person recommendations to control cells that and certainly you're trying to automate a lot of stuff on you use and notice the show to users between books of data mining and so so that's 1 major thing only there are currently working on and so you can play connected you can actually help us made up of levels have been because the hiring in the with that pitch and jump come join us and importantly and you work and so for the
racial tolerance charge so some insight on which is well what
if tents cattle things 1st of all of it's so it's not sort
project the other components of a lot of us haven't compiler almost pattern compiler of certain States taken into the closely at articles introduced the state court optimization it's actually more than that and that it's been extended pattern language which allows it to write a 1st extension modules for Python our resorting down to the writing CDI calls itself and a very nice way for interfacing Python really seems to most of my rights and over the years so the 2nd section of the of relative all project was need for it from power from Pyrex Williams pirates technical people working and so fired project that was and my own migrating somewhere around 10 to thousands and so in 2007 the robot shown 4 pirates which is kind of contour so installed time on from the 2nd project and since then we that minus success in which rising our user base and that over time it will become a major killer Python ecosystem especially the scientific program the system but it's more general that so the by now that have tons of also and code of there and it certainly is the a kind of technology members of the Program Manager really helps people to get their jobs so how do you sign the this sorry this constant particles someone who spends a general introduction around but runs from the surroundings and stuff and how they work with words from the surface that notion of examples of words so don't use cycle of what you do is right present on certain quotas and expand their arms set and then translate this into C code seniors compiler that was shared library half officer the pattern and then you can just imported work with and there so long as you can see this the best uh certain additional hurdles compared to relate to ratify the putting it back and know the compiler builds up between so let's something just a stupid little example we have x last year new methods some some of the doing that as the best that is but it has a sense of him and inequalities and never hear the number of the bacteria infection fasteners because methods to make the French and political science and the really difficult but establishment had code and when you run is used by the time it will spread out of final societal about 3 thousand 300 lines of code that silence is originally present in and in this so long to get their is critical remember groups nicely interface that combines my the in places in place I a that was my and work a file a patent strips and consisting of translated from transferred to see and then it will build your attention for and then in the 2nd quarter of work so I steps along each on In these 3 thousand lines of code of then will learn lots of probabilities signs so was not until if these a Python version of the compiling against the states then optimize something of a different race for different super conversions of very often it's the case for present 3 important to differences but also for new features that came in your supply convergence so on the collection adapted to seek help from Virginia currently of building it against and so if it's no surprise version which has certain future it's going use that otherwise it just fall back to some extent public implementation might the sort of thing but it's about work again and the next thing we do is we call the all original source code logistical comments as the initial especially when you read this is file of alienation find the entire source code management for the user to figure out what's happening in which the source code like contributed to what we nutrients that goes on and so that in any case this step the at that is lot of code that is really don't wanna right itself and for which you want to use this code generator so rewrite C so you don't have to on because the whole thing already showed this slide has script which relies on some but it's kind of the thing you use for local development and when he went this route across uh you use this to tools and it's but this this mutual spilled the extension model for Europe so that users you want to install a package of the problems involved in building a locally and you know the author and we also have the help of maps so and the what you do is really important segments functions and after which the union says proposed models and then we just say 5 minus source files and all extension so the the metadata exchange metadata for Europe and the compiler for can 21 both cases we want to build a dense and libraries for example if you need set up and maintenance have and stuff like that but you can also use this this standard distutils 1 way of setting up the HIT build metadata after the extension class from configurations in this development assistance granted on continued cells and then constant getting a 2nd chemistry going to right and so I already mentioned that the cold 2nd generates very portable actually so long it generates a code that compiles with only major apostle compilers on all major platforms Linux Mac Windows and some others are more less of authenticity general works and so and and also have versions onto the 6 the truly free that's fine which is currently not released but it's it's ongoing models and pipeline supervised support for the you see you can find and models of for special cases in these second-generation decoder which say is comparative apart by then the this other ways to something else which help in a and pipeline and sometimes negative less than you so the language and exercise on falls Python troupe 7 with a lot of the future but current work but for whatever comes in from pattern 3 which is adopted as long as it doesn't conflict with any present and future and if you want to have an
acupuncturist and that's actually you can use the usual of the future imports and future imported absolute imports of print function in and stuff or you can just say and you can compare the directives at the top of this also something which and then you have the semantics for of language features of surprise something which features 1 of the tests on in our continues integration testing is no surprise on regression tested of Python this this 705 and so where abouts 98 % success so it's pretty close to full full present coverage on all of that and then there's everything that you would normally all classes control structures and as groups try finally so exception handling the comprehension means so we have support for its in the weights of which will be new entitlement 305 started in something so this this extended sample in which you have to define that so they're all being in the next 7 release which is currently better results on current published about the release this so 1st part of thinking written 23 of certain and support for profiling tracing and coverage and there's lots of of tools developed Europe understand analyze coordinated the chemical cultivations we don't have friends instead of functions of original frames it definitely a cement minority on so genetic in touch with friends but then this 1 you working on we you will notice of friends and color of faces and that's on the trees this presentation will frames always important OK so we'll get most back from certain code of Devon exception being raised that's all supported on a and then obviously no boxes from every piece of software and you can find them but as speech of so site and annotation very efficiently cold and that means that it's an optimistic optimizations that applies to the code of arms and it generates optimized code for this kind of tiresome for many buildings that reviews and has that type inference with wasn't functions so on kind of thing can decide what to do when don't understand the code of that so it has that standard knowledge about a interpret what I mean 1 way remember those leaders with Python interested so there's a bunch of software packages that were assembled on to measure the speed of the performance of preference programs that assure you were coordinated and stuff like general wasn't intended engines of only what else is in there some depth you some kind of cult of competition a little benchmarks on with very different different so so lots of lots of different stuff going on in that case you can run to see faster interpreters on a more on the inside and and the problem that is that the unification of evidence of their there but altered opinion when working for he has 6 area only in the that means they don't use many of you to any of the more recent patent features on so then it's nice benchmark but it's had it's not very telling for any reason education but you're and so in that that means my students only about swipe with 3 2 3 times on benchmark of fossil and presence of 5 all and tension in those benchmarks a little evidence to make certain general but the cost of them this sentiment 4 times 250 times and how do you do that holds that type declarations of commands acutely aware rich that's part of that it supports optional static typing in addition to the impact on and and so a new codes so and you can see it in its yeah variables for example having a certain type and this extended syntax which those suggest some type of access for Rome will vary with acceleration of with extensions of a marriage which there are only understood and with certain what they do well on sentences these declarations it can drop your cold from of all object operations and things equal because many of them birds that variable has a procedure to type for example you can say that adding value to the variable can redundancy density running objects of responses the nice thing is that the optimal time considered can only employed in this this this concentration exactly where performance matters and that's the way we may be used in these benchmarks of faster than what you'd get from simply compiled code and session from computational loops of university that you get somewhere between 100 thousand times became the actual topic of today's talk this time talking to me difficult so I don't talk much about speed up so I will talk more about how do you connect at some level is holding talks how do you see and so of a person's technical translates to city code talking to native code in the external proton code since of a that completely natural and so called straightforward and so that makes some form function the face but that the quality of the can think of it as taking was data types and the nice thing is that the comparative series that these types are converted back and forth from Python objects automatic to 40 the 2nd stanza pretty much all the data types and most of symbols passed on that of the 2 types of matrices from change point of structure for relief and so on and suppose those classes templates of operator overloading of and so on and so forth OK and that's the end of the 1st part of this demo and 1st of all usages and who does not know the output amount of Jupiter and OK everyone does that cool I'm so it is there someone here was working on its own was being being country the venture everyone's integrates was wonderful and and his 2nd wife so all you really have to do this and you open up the price the book and then say it will take some from which enables the 2nd support and current incidence is when you have a figure of
phrase and so they're all pretty little once it is released on and so you example and this is what's as that says will look like but so is main so here we don't send sentence which tells you to become aware that his title and so and this compiled phoneme sounds and run it on and 2nd components and just works and what this year is defined 1 little pattern function I define a pattern function of a tight arguments so the arguments has been accepted must be season's was rejected by then have 1 function here which is this is just a function which translates into plane is different from and then the last thing I have here is this pdf function which is kind of society with a Python wrapper there was some pattern representation generated and I came from a peasant function just what I want become called the types Python functions on which does the same thing as with difference that if I pass in something else that comes out in and you see for example then don't than and again an entry so it's going to be checked for me on when confronted with on the other hand and tried close the functional so you have many merits of using function doesn't actually up here at the model the face of the city from entrepreneurs or Python from what's what can call it implicitly function which the internal calls this functions and that that's as set of well known as different from the reparandum so the wrapper becomes visible to have other function to compiling declaration both sides and compiler so this is not same themselves himself and you can put aside from model and decorate function the present fungal decorated and then around that and when you call function it executes the the results on their own it executes the compile function for instance you have the because of the content of the pattern function of runtime compiled such that's taken during the runtime combinations of from within Python OK ontology functions on the set it's entirely natural for 4 7 talk to the libraries and when this works of what we have some of the health standards declarations that we ship that includes a large forests that's the that's supposed something he from CHI of the functions that are consistently important use that and so the words American psychoanalysis saved from the ceiling from this library that's model and they're called mass so the mass mass the own from that's the simple math and then you have a sense of the of the scene of functions and you can say it must sign of piety but from that and it will be the 1 but when I think this year evident just say % and the site on the site Wednesday arms and minds a 0 means and what state what we get out of it as an entity it's a single version of my source code on and development to see what cycle made of my source code can't because now you can see that entire exactly the source code of the but when on the on class in front it was shown me this is called gender generate for and so I considered C and so what does here is how it does the computation implied by 2 articles of the sine function on and then called CHI function on its own which concerned the converts the doubles double results to float objects and then called helper function which prints the result because that's what was that the prince of the result of science OK and the reason why it's the general compared lines that the various interaction with high on on so there's a show I object operations under the consumer results is calculated on the web and afterwards I created a python object from its and call the print function and that's the reason that the adds help but to the to the users documents of the yellow line so it's the . meaning of cracks terms of having operation look and memory allocations and things we have the center of the originally except for thickness from use and it's important you and then you can't control merit of have to check the result of this the difference among there now raise memory error if it is in other words investors we just you can work it on what you should do especially for for a little amount of the of memory that you need that is used this is tight the memory management on because that's critical memories so it doesn't matter what the operating system faster for a small memory errors and so what I'm doing here as replaced on a lot of time and metal sending to the results and this year and assigning some values to the memory buffer of located and then to the consternation print the results and free memory can importance try finally this even if something goes wrong here I want to be sure that the free memory of executed because it's 1 so it's adding up to 1 3 can but it's on 1 I sufficient and all 22 I think from the last release that somebody on is automatic retinal C functions so here and on the importance of the methods that has its own models from scene and take the assignment I function sexual C functions and sigh Python variable which makes some and the kinetochore that and can look at what it does so here are some additional a help function that is generated from you with this the sign function and rats so that's in Python call and and then it just adds to to the global model dictionary becomes
available to present code and I can just call it something I simple principle sign of half probably the best and a candidate to i function present by spring and that's what and concessional symbols that OK except viruses but more often Holst example because what sort of talking to live see but it doesn't usually get you very far Johnson balance of helper functions and that's the other but what you normally do so if you want to talk to your own court cases sensical line around external that you want to rapidly model made available for Python users from the patent holder and so on this is how this works so I chosen and because of course that was written in a way a wrapper for Python which come an and so I have a little bits and call for methods for this presentation a service or header file and a couple things and declarations from its this is the status of quality of the runtime state of the neuron time like introduce new rule runtime 104 clause in the runtimes of the out and I can modes according to the runtime instituted and then some respect machines have some function Interior to operate with the 2nd call function and stuff like that some of the declarations and its output and this year is having difficulties so you ahead of getting way larger than what property and that's all can that's all certainly and once and that's the attention this and so it is a function of random well pattern function In the past some some you are caught in there and then the 1st thing I do I compare metrics it's about strings were converted to fade in the code creating new a runtime reasoning about the sales note the court into run a reduced syntax error of that failed because that's extremely low the and then the result from maps call it's executes the workload if that fails just with runtime of saying you know you could programs for them I and then we very simple uh the return value conversion so I'm expecting the lung number that reason exception happens to be a lot of number of words which is converted so there's a whole function for converting them a number of edits the number and then return of OK so that's all I need to execute lower court and profound important insights and this this method available so for for calls from Python again try finally so there's a bit of cleanup after creating the runtime and will run time to make sure that I probably cleanup afterwards regardless of what happens exceptions should be no memory because sensors in the runtime and memory to so just clean evident afterward and then and again and so wasn't during their knowledge take some some were caught up and pattern function and and the and industry this is just the training function will function and call it and the engine return the result of texture that it can accept that that the and that gives me the attempt to be natural number currently instruments present version of and 2nd benchmark that's that's going to mean about 5 ms and this thing I didn't mention that is why this is this issue were placed 1 using records but a lot thinking and insidious answer on wednesday in about years when this compiles in this field of and and pretty much library for Python please here to find the header file use this library something against because some specifying the direction model and now only at the end we will fight the 1 and only refer replace that but rejects would also installed on order have to do is replace the include directory so self-refinement discriminative the readiness source code it could also be that and method applies file but since I'm having that have worked and just going to say that intelligent but on the code and same result should but fast and that that's is what was found OK just replacing the references whatever OK what else do we have a little of my syntax and serious so series lecture quite clumsy on C because there is just point and sometimes the most meaningful but doesn't care about them so the 2nd most length of the series and has better ways to deal with them and so on and doing nearest and create into a series of of integers elements can a and B and the minus sign in about slice something the title has high variance in right environment partial size through all of the array a series of 10 1 as features that can be assigned the value to system of support right when you sign the radius and other relevant or Variable adjustments and kind what's actually going to be in error and so you can find remains so sigh and those that require inferences hospitals the kinetochore and then you just assigned to the other half of array called more numbers but I can just iterate over the years misplacing had occurred rhetorical array registering for the year and just interested in the 1st 3 numbers to during all those happened in those of us 1 this case and then returned in the so what see here so I created function for the case of the solid you and and this is the iteration of actually uses a single over the rate of then we have here the assignments which is consistent property of Christoffel code from this is the standard partial sentence here translates to temporary and then properly on so there's also a 7 thousand the back images of the right and particle my function and the situation was for the adrenal 1st values and then when I return the array that automatically translates of the next item objects as well as returns on and can that and there's going to show you a bit of arms to justice because at the you may
not like suppose doesn't know lots of people don't like it was just but it's actually a really nice when used from Sec and and that's on your out everything that
can so I think you will exercise on the same side numbers using
and now have receptors cell cycle members disposed to the environment uh compiled into Brussels malt which enables also possible sausages meaning operator overloading meaning of a class of for each of the 10
plates and uh and set worship iterations with site and that influence the people's plus on the including for example and this year the Vector class so I can just say from which city and this is the vector the input vector class and so here define pattern
functions respect allocated it's cytosol vector objects and then a consistent and so the value with pushed back method rather and that means uh unicyclists Vector class and then return but it seemed that returns something sixfold on there look because it is that of those the tendency but as so for mapping from the business sector to present whenever you come in make from converge at the book was victorious it was just lists for you any any container most just can't converted to list for you or to so suppose mapped to present its I considered all representation and I thought of as it falls within OK the another little example effects so and the nice thing here is that 7 does the automatic economic management for instance allocate its instances vector-mediated goes out of scope I again all and you can do the same thing with an extension types of this way of life on the defense extension has anyone into middle and extension type CHI a couple of people with the wizard hears 10 insisting extension type copy over all that happens is that different models also definitions and stuff and then adapted for needs because it's never going to infer the value of the way words from the documentation documentation pages could over time insight and you don't need to do that is to say the last class and on the government's engine type the here and having made of fields of attributes to the extension types of the object in this case I do which is a simple so that term and that makes that ties the memory management for the civil society to the lifetime of the Python objects the objects created creates suppose so that the 4 years and when object of of and so this madness just called push back and representation and so the next advance and then our own the represents you just implement as wrapper all values of the of the official structure and when execute on that is a sincere presentations of the class becomes list because that's the representation of the use force vector converted to present and just proper list and OK on OK just the that's and FIL continue that's what we have to be going on 2nd tool for translating patent codes to efficiency and answer for a user to interface with XML native code as a senior just the records that just works and is it the speed up is the sum of models and the concentrate on the optimization rather than a complete rewrite it you have to do it right and see avoid pregnancy just getting started allows us to write C extensions for the program in natural patterns and that's been losing pattern semantics is inferred from the language features and this allows you to write code without that you writing any single at all and use it to to wrap syphilis feels libraries have been problems and just you know even objects were from it doesn't matter if it's kind to suppress the logic and that's all center thank you
you you for the distance and then we have to have someone listen to implement such questions and then the question is gonna up all those wondering if anyone Coleen's using this this code from sites on some what is voltage of support for the new standard Sophia-antipolis plus for what would be the same as the synthesis of responses and I want to add Cantonese busses compiler those 7 really care the communication of of the government use because mention your model there is some justified entities but like that the sort of person was generated the constables was going to change the generates the quantum of formal almost everything except when you interact and refused to vote for the object and which case through to the source code for OK so it knows what operators for example and operate a possible transition that we wanted to but also called for every minutes in possible usage in called the thank you thank you thank
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation


  527 ms - page object


AV-Portal 3.8.0 (dec2fe8b0ce2e718d55d6f23ab68f0b2424a1f3f)