The Joy of SciPy David Kammeyer PUB February 14, 2013
Brief History Person Package Year Matrix Object Jim Fulton 1994 in Python Jim Hugunin Numeric 1995 Perry Greenﬁeld, Rick White, Todd Miller Numarray 2001 Travis Oliphant NumPy 2005
SciPy 2001 Travis Oliphant optimize sparse interpolate integrate special signal stats Founded in 2001 with Travis Vaught fftpack misc Eric Jones weave clusterPearu Peterson GA* linalg interpolate f2py
Community effort• Chuck Harris• Pauli Virtanen• David Cournapeau• Stefan van der Walt• Dag Sverre Seljebotn• Robert Kern• Warren Weckesser• Ralf Gommers• Mark Wiebe• Nathaniel Smith
Why Python for Technical Computing• Syntax (it gets out of your way)• Over-loadable operators• Complex numbers built-in early• Just enough language support for arrays• “Occasional” programmers can grok it• Supports multiple programming styles• Expert programmers can also use it effectively• Has a simple, extensible implementation• General-purpose language --- can build a system• Critical mass
Putting Science back in Comp Sci • Much of the software stack is for systems programming --- C++, Java, .NET, ObjC, web - Complex numbers? - Vectorized primitives? • Array-oriented programming has been supplanted by Object-oriented programming • Software stack for scientists is not as helpful as it should be • Fortran is still where many scientists end up
NumPy: an Array-Oriented Extension• Data: the array object – slicing and shaping – data-type map to Bytes• Fast Math: – vectorization – broadcasting – aggregations
Zen of NumPy• strided is better than scattered• contiguous is better than strided• descriptive is better than imperative• array-oriented is better than object-oriented• broadcasting is a great idea• vectorized is better than an explicit loop• unless it’s too complicated --- then use Cython/Numba• think in higher dimensions
Beneﬁts of Array-oriented• Many technical problems are naturally array- oriented (easy to vectorize)• Algorithms can be expressed at a high-level• These algorithms can be parallelized more simply (quite often much information is lost in the translation to typical “compiled” languages)• Array-oriented algorithms map to modern hard-ware caches and pipelines.
We need more focus oncomplied array-orientedlanguages with fast compilers!
What is good about NumPy?• Array-oriented• Extensive Dtype System (including structures)• C-API• Simple to understand data-structure• Memory mapping• Syntax support from Python• Large community of users• Broadcasting• Easy to interface C/C++/Fortran code
New Project NumPy Blaze Next Generation NumPy Out-of-core Distributed Tables
NumPy Users • Want to be able to write Python to get fast code that works on arrays and scalars • Need access to a boat-load of C-extensions (NumPy is just the beginning) PyPy doesn’t cut it for us!
Ufuncs Generalized UFuncs Python Function Window Kernel Funcs Function- based Indexing Memory Dynamic compilation Filters Dynamic CompilationNumPy Runtime I/O Filters Reduction Filters Computed Columns function pointer
SciPy needs a Python compiler optimize integrate special ode writing more of SciPy at high-level
Numba -- a Python compiler • Replays byte-code on a stack with simple type- inference • Translates to LLVM (using LLVM-py) • Uses LLVM for code-gen • Resulting C-level function-pointer can be inserted into NumPy run-time • Understands NumPy arrays • Is NumPy / SciPy aware
NumPy + Mamba = Numba Python Function Machine Code LLVM-PY LLVM 3.1 ISPC OpenCL OpenMP CUDA CLANG Intel AMD Nvidia Apple
NumFOCUSNum(Py) Foundation for Open Code for Usable Science
NumFOCUS• Mission • To initiate and support educational programs furthering the use of open source software in science. • To promote the use of high-level languages and open source in science, engineering, and math research • To encourage reproducible scientific research • To provide infrastructure and support for open source projects for technical computing
NumFOCUSCore Projects NumPy SciPy IPython MatplotlibOther Projects (seeking more --- need representatives) Scikits Image
• Large-scale data analysis products• Anaconda, SciPy in a Box• Wakari.io -- Cloud Hosted SciPy• Python training (data analysis and development)• NumPy support and consulting• Blaze, Numba, and More Development