Python High Performance Programming by Gabriele Lanaro

By Gabriele Lanaro

Determine the bottlenecks on your functions and resolve them utilizing the simplest profiling techniques
Write effective numerical code in NumPy and Cython
Adapt your courses to run on a number of processors with parallel programming

Table of Contents
Preface
Chapter 1: Benchmarking and Profiling
Chapter 2: quickly Array Operations with NumPy
Chapter three: C functionality with Cython
Chapter four: Parallel Processing
Index

Preface

Up

bankruptcy 1: Benchmarking and Profiling
Designing your application
Writing assessments and benchmarks
Timing your benchmark
discovering bottlenecks with cProfile
Profile line through line with line_profiler
Optimizing our code
The dis module
Profiling reminiscence utilization with memory_profiler
functionality tuning information for natural Python code
Summary

Up

bankruptcy 2: quickly Array Operations with NumPy
Getting began with NumPy
growing arrays
getting access to arrays
Broadcasting
Mathematical operations
Calculating the Norm
Rewriting the particle simulator in NumPy
achieving optimum functionality with numexpr
Summary

Up

bankruptcy three: C functionality with Cython
Compiling Cython extensions
including static types
Variables
Functions
Classes
Sharing declarations
operating with arrays
C arrays and pointers
NumPy arrays
Typed memoryviews
Particle simulator in Cython
Profiling Cython
Summary

Up

bankruptcy four: Parallel Processing
advent to parallel programming
The multiprocessing module
the method and Pool classes
Monte Carlo approximation of pi
Synchronization and locks
IPython parallel
Direct interface
Task-based interface
Parallel Cython with OpenMP
Summary

Show description

Read Online or Download Python High Performance Programming PDF

Similar python books

Fundamentals of Python: From First Programs through Data Structures

In basics OF PYTHON: FROM FIRST courses via info constructions, Washington and Lee college professor Kenneth A. Lambert offers the entire very important issues in CS1 and CS2 in a single quantity. This within your budget structure offers teachers with a constant method of instructing introductory programming and information buildings over a regular two-term path series.

Python for Data Analysis: Data Wrangling with Pandas, NumPy, and IPython

Python for information research is worried with the nuts and bolts of manipulating, processing, cleansing, and crunching info in Python. it's also a pragmatic, glossy advent to medical computing in Python, adapted for data-intensive functions. it is a booklet in regards to the elements of the Python language and libraries you'll have to successfully clear up a vast set of knowledge research difficulties.

Python and AWS

In the event you intend to exploit Amazon internet providers (AWS) for distant computing and garage, Python is a perfect programming language for constructing purposes and controlling your cloud-based infrastructure. This cookbook will get you began with greater than dozen recipes for utilizing Python with AWS, in line with the author’s boto library.

Artificial Intelligence with Python

Construct real-world man made Intelligence purposes with Python to intelligently have interaction with the realm round you approximately This e-book Step into the superb global of clever apps utilizing this complete advisor input the realm of man-made Intelligence, discover it, and create your personal purposes paintings via easy but insightful examples that might get you up and operating with man made Intelligence very quickly Who This booklet Is For This ebook is for Python builders who are looking to construct real-world man made Intelligence purposes.

Extra info for Python High Performance Programming

Example text

Compiling Cython extensions By design, the Cython syntax is a superset of Python. Cython can typically compile a Python module without requiring any change. pyx and they can be compiled to C using the cython command. Chapter 3 In the first two lines of the previous code, we import the setup function and the cythonize helper. The setup function contains a few key-value pairs that tell distutils the name of the application and which extensions need to be built. The cythonize helper takes either a string or a list of strings containing the Cython modules we want to compile.

To take advantage of Cython optimizations we have to declare the function using a cdef statement and an optional return type, as in the following code: cdef int max_cython(int a, int b): return a if a > b else b Functions declared in this way are translated to native C functions, which are not callable from Python. They have much less overhead compared to Python functions, and using them results in a substantial increase in performance. Their scope is restricted to the same Cython file, unless they're exposed in a definition file (refer to the Sharing Declarations section).

In the next chapter, we will see how to use numpy to dramatically speedup computations in an easy and convenient way. [ 30 ] Fast Array Operations with NumPy NumPy is the de facto standard for scientific computing in Python. It extends Python with a flexible multidimensional array that allows fast mathematical calculations. NumPy works as a framework that allows coding complex operations using a concise syntax. ndarray) is internally based on C arrays: in this way, the developer can easily interface NumPy with existing C and FORTRAN code.

Download PDF sample

Rated 4.30 of 5 – based on 29 votes