Book description
Build software that combines Python’s expressivity with the performance and control of C (and C++). It’s possible with Cython, the compiler and hybrid programming language used by foundational packages such as NumPy, and prominent in projects including Pandas, h5py, and scikits-learn. In this practical guide, you’ll learn how to use Cython to improve Python’s performance—up to 3000x— and to wrap C and C++ libraries in Python with ease.
Author Kurt Smith takes you through Cython’s capabilities, with sample code and in-depth practice exercises. If you’re just starting with Cython, or want to go deeper, you’ll learn how this language is an essential part of any performance-oriented Python programmer’s arsenal.
- Use Cython’s static typing to speed up Python code
- Gain hands-on experience using Cython features to boost your numeric-heavy Python
- Create new types with Cython—and see how fast object-oriented programming in Python can be
- Effectively organize Cython code into separate modules and packages without sacrificing performance
- Use Cython to give Pythonic interfaces to C and C++ libraries
- Optimize code with Cython’s runtime and compile-time profiling tools
- Use Cython’s prange function to parallelize loops transparently with OpenMP
Publisher resources
Table of contents
- Dedication
- Preface
- 1. Cython Essentials
- 2. Compiling and Running Cython Code
-
3. Cython in Depth
- Interpreted Versus Compiled Execution
- Dynamic Versus Static Typing
- Static Type Declaration with cdef
- Cython’s Three Kinds of Functions
- Type Coercion and Casting
- Declaring and Using structs, unions, and enums
- Type Aliasing with ctypedef
- Cython for Loops and while Loops
- The Cython Preprocessor
- Bridging the Python 2 and Python 3 Divide
- Summary
- 4. Cython in Practice: N-Body Simulation
- 5. Cython and Extension Types
- 6. Organizing Cython Code
-
7. Wrapping C Libraries with Cython
- Declaring External C Code in Cython
- Declaring External C Functions and typedefs
- Declaring and Wrapping C structs, unions, and enums
- Wrapping C Functions
- Wrapping C structs with Extension Types
- Constants, Other Modifiers, and Controlling What Cython Generates
- Error Checking and Raising Exceptions
- Callbacks
- Summary
- 8. Wrapping C++ Libraries with Cython
- 9. Cython Profiling Tools
- 10. Cython, NumPy, and Typed Memoryviews
- 11. Cython in Practice: Spectral Norm
- 12. Parallel Programming with Cython
- 13. Cython in Context
- Index
- Colophon
- Copyright
Product information
- Title: Cython
- Author(s):
- Release date: January 2015
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491901755
You might also like
video
Learning Cython
In this Learning Cython training course, expert author Caleb Hattingh will teach you how to create …
book
Fast Python
Master Python techniques and libraries to reduce run times, efficiently handle huge datasets, and optimize execution …
book
Python One-Liners
Python One-Liners will teach you how to read and write “one-liners”: concise statements of useful functionality …
book
Python in a Nutshell
Ask any Python aficionado and you'll hear that Python programmers have it all: an elegant language …