Cython. April 2008 Brian Blais

Size: px
Start display at page:

Download "Cython. April 2008 Brian Blais"

Transcription

1 Cython O p t i m i z a t i o n i n P y t h o n April 2008 Brian Blais

2 Rule #1 of Optimization Premature optimization is the root of all evil - Donald Knuth

3 What is Cython/Pyrex? Python to C/Python-API Converter Extension modules to optimize code

4 Example.pyx import numpy def this(): print "hello world" a=5 b=numpy.abs(a)

5 Example.C static char pyx_k_2[] = "hello world"; pyx_v_a = Py_None; Py_INCREF(Py_None); pyx_v_b = Py_None; Py_INCREF(Py_None); /* print "hello world" */ if ( Pyx_PrintItem( pyx_k_2p) < 0) { pyx_filename = pyx_f[0]; pyx_lineno = 5; goto pyx_l1;} if ( Pyx_PrintNewline() < 0) { pyx_filename = pyx _f[0]; pyx_lineno = 5; goto pyx_l1;}

6 Example.C static PyObject * pyx_num_5; Py_INCREF( pyx_num_5); Py_DECREF( pyx_v_a); pyx_v_a = pyx_num_5;

7 Example.C pyx_1 = Pyx_GetName( pyx_m, pyx_n_numpy); if (unlikely(! pyx_1)) { pyx_filename = pyx_f [0]; pyx_lineno = 9; goto pyx_l1;} pyx_2 = PyObject_GetAttr( pyx_1, pyx_n_abs); if (unlikely(! pyx_2)) { pyx_filename = pyx_f[0]; pyx_lineno = 9; goto pyx_l1;} Py_DECREF( pyx_1); pyx_1 = 0; pyx_1 = PyTuple_New(1); if (unlikely(! pyx_1)) { pyx_filename = pyx_f[0]; pyx_lineno = 9; goto pyx_l1;} Py_INCREF( pyx_v_a); PyTuple_SET_ITEM( pyx_1, 0, pyx_v_a); pyx_3 = PyObject_Call( pyx_2, pyx_1, NULL); if (unlikely(! pyx_3)) { pyx_filename = pyx_f [0]; pyx_lineno = 9; goto pyx_l1;} Py_DECREF( pyx_2); pyx_2 = 0; Py_DECREF( pyx_1); pyx_1 = 0; Py_DECREF( pyx_v_b);

8 Cython vs Pyrex Cython is a recent branch off of Pyrex, related to the Sage project list comprehensions inplace operators boolean int type etc... Basically the same...will use Cython here

9 requirements/ Suggestions Python C compiler Cython - ipython, numpy, scipy, matplotlib

10 Windows Setup Run the MinGW Installer: extract to folder c:\mingw Copy the distutils.cfg to C:\Python25\Lib\distutils Right-click My Computer/Properties/Advanced/ Environment Variables add c:\python25;c:\mingw\bin to the path %SystemRoot%\system32;%SystemRoot%;%SystemRoot% \System32\Wbem;c:\mingw\bin;c:\python25

11 sum_python.py def my_sum(n): s=0 for k in range(n): s+=k return s

12 sum_python.py def my_sum(n): s=0 for k in range(n): s+=k return s In [2] :from sum_python import my_sum as python In [3]:python(100000) Out[3]: L In [4]:timeit python(100000) 100 loops, best of 3: 16.7 ms per loop

13 sum_cython1.pyx def my_sum(long long N): cdef long long k,s=0 for k in range(n): s+=k return s

14 sum_cython1.pyx In [1]:from cython_compile import * In [2]:compile('sum_cython1.pyx') running build_ext cythoning sum_cython1.pyx to sum_cython1.c building 'sum_cython1' extension creating build creating build/temp.macosx-10.3-fat-2.5 gcc -arch ppc -arch i o sum_cython1.so

15 sum_cython1.pyx def my_sum(long long N): cdef long long k,s=0 for k in range(n): s+=k return s In [3]:from sum_cython1 import my_sum as cython1 In [4]:cython1(100000) Out[4]: L In [5]:timeit cython1(100000) 100 loops, best of 3: 3.76 ms per loop

16 sum_python.py def my_sum(n): s=0 for k in range(n): s+=k return s In [2] :from sum_python import my_sum as python In [3]:python(100000) Out[3]: L In [4]:timeit python(100000) 100 loops, best of 3: 16.7 ms per loop

17 sum_cython2.pyx def my_sum(long long N): cdef long long k,s=0 for k from 0<=k<N: s+=k return s

18 sum_cython2.pyx def my_sum(long long N): cdef long long k,s=0 for k from 0<=k<N: s+=k return s In [12]:timeit python(100000) 100 loops, best of 3: 16.6 ms per loop In [13]:timeit cython1(100000) 100 loops, best of 3: 3.74 ms per loop In [14]:timeit cython2(100000) 1000 loops, best of 3: 314 µs per loop

19 dot.pyx cimport c_python cimport c_numpy c_numpy.import_array() # Numpy must be initialized def dotty(c_numpy.ndarray A1,c_numpy.ndarray A2): cdef int length=a1.dimensions[0] cdef int k cdef double s=0.0 cdef double *a1=<double *>A1.data cdef double *a2=<double *>A2.data for k from 0<=k<length: s+=a1[k]*a2[k] return s

20 dot.pyx In In In In [0]:from dot import * [1]:from numpy import * [2]:r=random.rand(10000) [3]:r2=list(r2) In [4]:timeit sum([a*b for a,b in zip(r2,r2)]) 100 loops, best of 3: 9.74 ms per loop In [5]:timeit dotty(r,r) loops, best of 3: 12.9 µs per loop In [6]:timeit dot(r,r) loops, best of 3: 14 µs per loop In [9]:timeit sum(r*r) loops, best of 3: 175 µs per loop

21 Gotchas! Forgetting a cdef Wrong type (float vs double) For-loop mistake Too much python

22 Appendix

23 Distutils.cfg [build] compiler=mingw32

24 Setup.py from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext import numpy incdirs=[numpy.get_include()] setup( name = 'Demos', ext_modules=[ Extension("sum_cython2",["sum_cython2.pyx"], include_dirs = incdirs) ], cmdclass = {'build_ext': build_ext} )

Python is awesome. awesomeness C/gcc C++/gcc Java 6 Go/6g Haskell/GHC Scala Lisp SBCL C#/Mono OCaml Python

Python is awesome. awesomeness C/gcc C++/gcc Java 6 Go/6g Haskell/GHC Scala Lisp SBCL C#/Mono OCaml Python Python is awesome 30 28.07 awesomeness 22.5 15 7.5 0 2.95 3.35 2.16 2.22 2.67 1.55 2.01 1.07 1.19 C/gcc C++/gcc Java 6 Go/6g Haskell/GHC Scala Lisp SBCL C#/Mono OCaml Python A benchmark http://geetduggal.wordpress.com/2010/11/25/speed-up-your-python-unladen-vs-shedskin-vs-pypy-vs-c/

More information

Running Cython. overview hello world with Cython. experimental setup adding type declarations cdef functions & calling external functions

Running Cython. overview hello world with Cython. experimental setup adding type declarations cdef functions & calling external functions Running Cython 1 Getting Started with Cython overview hello world with Cython 2 Numerical Integration experimental setup adding type declarations cdef functions & calling external functions 3 Using Cython

More information

Mixed Python/C programming with Cython September /14. Mixed Python/C programming with Cython Ben Dudson, 22nd September 2017

Mixed Python/C programming with Cython September /14. Mixed Python/C programming with Cython Ben Dudson, 22nd September 2017 Mixed Python/C programming with Cython September 2017 1/14 Mixed Python/C programming with Cython Ben Dudson, 22nd September 2017 Mixed Python/C programming with Cython September 2017 2/14 Cython http://cython.org/

More information

Robot Vision Systems Lecture 8: Python wrappers in OpenCV

Robot Vision Systems Lecture 8: Python wrappers in OpenCV Robot Vision Systems Lecture 8: Python wrappers in OpenCV Michael Felsberg michael.felsberg@liu.se Why Python Wrappers Assume a small library based on OpenCV Python interface for Testing Distribution Prototyping

More information

Cython: Stop writing native Python extensions in C

Cython: Stop writing native Python extensions in C Python extensions March 29, 2016 cython.org programming language similar to Python static typing from C/C++ compiler from Cython language to C/C++ to Python extension module or to standalone apps* feels

More information

Running Cython and Vectorization

Running Cython and Vectorization Running Cython and Vectorization 1 Getting Started with Cython overview hello world with Cython 2 Numerical Integration experimental setup adding type declarations cdef functions & calling external functions

More information

Running Cython and Vectorization

Running Cython and Vectorization Running Cython and Vectorization 1 Getting Started with Cython overview hello world with Cython 2 Numerical Integration experimental setup adding type declarations cdef functions & calling external functions

More information

LECTURE 20. Optimizing Python

LECTURE 20. Optimizing Python LECTURE 20 Optimizing Python THE NEED FOR SPEED By now, hopefully I ve shown that Python is an extremely versatile language that supports quick and easy development. However, a lot of the nice features

More information

Speeding up Python using Cython

Speeding up Python using Cython Speeding up Python using Cython Rolf Boomgaarden Thiemo Gries Florian Letsch Universität Hamburg November 28th, 2013 What is Cython? Compiler, compiles Python-like code to C-code Code is still executed

More information

Interfacing With Other Programming Languages Using Cython

Interfacing With Other Programming Languages Using Cython Lab 19 Interfacing With Other Programming Languages Using Cython Lab Objective: Learn to interface with object files using Cython. This lab should be worked through on a machine that has already been configured

More information

Advanced and Parallel Python

Advanced and Parallel Python Advanced and Parallel Python December 1st, 2016 http://tinyurl.com/cq-advanced-python-20161201 By: Bart Oldeman and Pier-Luc St-Onge 1 Financial Partners 2 Setup for the workshop 1. Get a user ID and password

More information

http://tinyurl.com/cq-advanced-python-20151029 1 2 ##: ********** ## csuser## @[S## ********** guillimin.hpc.mcgill.ca class## ********** qsub interactive.pbs 3 cp -a /software/workshop/cq-formation-advanced-python

More information

Performance Python 7 Strategies for Optimizing Your Numerical Code

Performance Python 7 Strategies for Optimizing Your Numerical Code Performance Python 7 Strategies for Optimizing Your Numerical Code Jake VanderPlas @jakevdp PyCon 2018 Python is Fast. Dynamic, interpreted, & flexible: fast Development Python is Slow. CPython has constant

More information

Interfacing With Other Programming Languages Using Cython

Interfacing With Other Programming Languages Using Cython Lab 1 Interfacing With Other Programming Languages Using Cython Lab Objective: Learn to interface with object files using Cython. This lab should be worked through on a machine that has already been configured

More information

An introduction to scientific programming with. Session 5: Extreme Python

An introduction to scientific programming with. Session 5: Extreme Python An introduction to scientific programming with Session 5: Extreme Python PyTables For creating, storing and analysing datasets from simple, small tables to complex, huge datasets standard HDF5 file format

More information

Python Optimization and Integration

Python Optimization and Integration [Software Development] Python Optimization and Integration Davide Balzarotti Eurecom Sophia Antipolis, France 1 When Python is not Enough Python is great for rapid application development Many famous examples...

More information

PyTest Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : May, More documents are freely available at PythonDSP

PyTest Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : May, More documents are freely available at PythonDSP PyTest Guide Meher Krishna Patel Created on : Octorber, 2017 Last updated : May, 2018 More documents are freely available at PythonDSP Table of contents Table of contents i 1 PyTest Guide 2 1.1 Code to

More information

C - extensions. only a small part of application benefits from compiled code

C - extensions. only a small part of application benefits from compiled code C - EXTENSIONS C - extensions Some times there are time critical parts of code which would benefit from compiled language 90/10 rule: 90 % of time is spent in 10 % of code only a small part of application

More information

FPLLL. fpylll. Martin R. Albrecht 2017/07/06

FPLLL. fpylll. Martin R. Albrecht 2017/07/06 FPLLL fpylll Martin R. Albrecht 2017/07/06 Outline How Implementation What Contributing FPYLLL fpylll is a Python (2 and 3) library for performing lattice reduction on lattices over the Integers It is

More information

Scientific Computing with Python and CUDA

Scientific Computing with Python and CUDA Scientific Computing with Python and CUDA Stefan Reiterer High Performance Computing Seminar, January 17 2011 Stefan Reiterer () Scientific Computing with Python and CUDA HPC Seminar 1 / 55 Inhalt 1 A

More information

ARTIFICIAL INTELLIGENCE AND PYTHON

ARTIFICIAL INTELLIGENCE AND PYTHON ARTIFICIAL INTELLIGENCE AND PYTHON DAY 1 STANLEY LIANG, LASSONDE SCHOOL OF ENGINEERING, YORK UNIVERSITY WHAT IS PYTHON An interpreted high-level programming language for general-purpose programming. Python

More information

CNRS ANF PYTHON Packaging & Life Cycle

CNRS ANF PYTHON Packaging & Life Cycle CNRS ANF PYTHON Packaging & Life Cycle Marc Poinot Numerical Simulation Dept. Outline Package management with Python Concepts Software life cycle Package services Pragmatic approach Practical works Source

More information

Need for Speed Python meets C/C++

Need for Speed Python meets C/C++ Need for Speed Python meets C/C++ Scientific Programming with Python Christian Elsasser Based partially on a talk by Stéfan van der Walt This work is licensed under the Creative Commons Attribution-ShareAlike

More information

High Performance Computing with Python

High Performance Computing with Python High Performance Computing with Python Pawel Pomorski SHARCNET University of Waterloo ppomorsk@sharcnet.ca April 29,2015 Outline Speeding up Python code with NumPy Speeding up Python code with Cython Using

More information

Cython documentation»

Cython documentation» Cython 0.19.1 documentation» next Welcome to Cython s Documentation Getting Started Cython - an overview Installing Cython Building Cython code Faster code via static typing Tutorials Calling C functions

More information

Speeding up Python. Antonio Gómez-Iglesias April 17th, 2015

Speeding up Python. Antonio Gómez-Iglesias April 17th, 2015 Speeding up Python Antonio Gómez-Iglesias agomez@tacc.utexas.edu April 17th, 2015 Why Python is nice, easy, development is fast However, Python is slow The bottlenecks can be rewritten: SWIG Boost.Python

More information

An introduction to scientific programming with. Session 5: Extreme Python

An introduction to scientific programming with. Session 5: Extreme Python An introduction to scientific programming with Session 5: Extreme Python Managing your environment Efficiently handling large datasets Optimising your code Squeezing out extra speed Writing robust code

More information

Cython Reference Guide

Cython Reference Guide Cython Reference Guide Release 0.28a0 Stefan Behnel, Robert Bradshaw, William Stein Gary Furnish, Dag Seljebotn, Greg Ewing Gabriel Gellner, editor January 26, 2018 Contents 1 Compilation 3 1.1 Compiling

More information

Need for Speed Python meets C/C++

Need for Speed Python meets C/C++ Need for Speed Python meets C/C++ Scientific Programming with Python Christian Elsasser Based partially on a talk by Stéfan van der Walt This work is licensed under the Creative Commons Attribution-ShareAlike

More information

Pythran: Crossing the Python Frontier

Pythran: Crossing the Python Frontier DEPARTMENT: Scientific Programming Pythran: Crossing the Python Frontier Serge Guelton Institut Mines-Télécom Bretagne Editors: Konrad Hinsen, konrad.hinsen@cnrs.fr; Matthew Turk, matthewturk@gmail.com

More information

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15 1 LECTURE 1: INTRO Introduction to Scientific Python, CME 193 Jan. 9, 2014 web.stanford.edu/~ermartin/teaching/cme193-winter15 Eileen Martin Some slides are from Sven Schmit s Fall 14 slides 2 Course Details

More information

Mixed language programming with NumPy arrays

Mixed language programming with NumPy arrays Mixed language programming with NumPy arrays Simon Funke 1,2 Ola Skavhaug 3 Joakim Sundnes 1,2 Hans Petter Langtangen 1,2 Center for Biomedical Computing, Simula Research Laboratory 1 Dept. of Informatics,

More information

Type Conversion. and. Statements

Type Conversion. and. Statements and Statements Type conversion changing a value from one type to another Void Integral Floating Point Derived Boolean Character Integer Real Imaginary Complex no fractional part fractional part 2 tj Suppose

More information

Introduction to Python. Didzis Gosko

Introduction to Python. Didzis Gosko Introduction to Python Didzis Gosko Scripting language From Wikipedia: A scripting language or script language is a programming language that supports scripts, programs written for a special run-time environment

More information

2 Getting Started with Numerical Computations in Python

2 Getting Started with Numerical Computations in Python 1 Documentation and Resources * Download: o Requirements: Python, IPython, Numpy, Scipy, Matplotlib o Windows: google "windows download (Python,IPython,Numpy,Scipy,Matplotlib" o Debian based: sudo apt-get

More information

High Performance Computing with Python

High Performance Computing with Python High Performance Computing with Python Pawel Pomorski SHARCNET University of Waterloo ppomorsk@sharcnet.ca March 15,2017 Outline Speeding up Python code with NumPy Speeding up Python code with Cython Speeding

More information

Introduction to Python

Introduction to Python Introduction to Python Part 3: Advanced Topics Michael Kraus (michael.kraus@ipp.mpg.de) Max-Planck-Institut für Plasmaphysik, Garching 1. December 2011 Advanced Topics calling and embedding C and Fortran

More information

$ easy_install scikit-learn from scikits.learn import svm. Shouyuan Chen

$ easy_install scikit-learn from scikits.learn import svm. Shouyuan Chen $ easy_install scikit-learn from scikits.learn import svm Shouyuan Chen scikits.learn Advantages Many useful model Unified API for various ML algorithms Very clean source code Features Supervised learning

More information

Cython Tutorial. Release 0.21dev. Stefan Behnel, Robert Bradshaw, William Stein Gary Furnish, Dag Seljebotn, Greg Ewing Gabriel Gellner, editor

Cython Tutorial. Release 0.21dev. Stefan Behnel, Robert Bradshaw, William Stein Gary Furnish, Dag Seljebotn, Greg Ewing Gabriel Gellner, editor Cython Tutorial Release 0.21dev Stefan Behnel, Robert Bradshaw, William Stein Gary Furnish, Dag Seljebotn, Greg Ewing Gabriel Gellner, editor May 10, 2014 CONTENTS 1 Basic Tutorial 1 1.1 The Basics of

More information

Numerical Computing in Python

Numerical Computing in Python Numerical Computing in Python A Guide for Matlab Users B. Blais Department of Science and Technology Bryant University Faculty Development Seminar - Spring 2007 Abstract Matlab is a commercial program

More information

ctypes extending python was never easier! Anant Narayanan Malaviya National Institute of Technology

ctypes extending python was never easier! Anant Narayanan Malaviya National Institute of Technology C! ctypes extending python was never easier! Anant Narayanan Malaviya National Institute of Technology So what is python? Dynamically typed, interpreted language Allows for fast prototyping, thanks to

More information

PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital

PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital PYTHON FOR MEDICAL PHYSICISTS Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital TUTORIAL 1: INTRODUCTION Thursday 1 st October, 2015 AGENDA 1. Reference list 2.

More information

Introductory Scientific Computing with Python

Introductory Scientific Computing with Python Introductory Scientific Computing with Python More plotting, lists and FOSSEE Department of Aerospace Engineering IIT Bombay SciPy India, 2015 December, 2015 FOSSEE (FOSSEE IITB) Interactive Plotting 1

More information

PYTHON IS SLOW. Make it faster with C. Ben Shaw

PYTHON IS SLOW. Make it faster with C. Ben Shaw PYTHON IS SLOW Make it faster with C Ben Shaw It s OK that Python isn t fast, you can write your slow functions in C! Everyone TABLE OF CONTENTS C Module vs C Types TABLE OF CONTENTS C Module vs C Types

More information

Python where we can, C ++ where we must

Python where we can, C ++ where we must Python where we can, C ++ where we must Source: http://xkcd.com/353/ Guy K. Kloss Python where we can,c++ where we must 1/28 Python where we can, C ++ where we must Guy K. Kloss BarCamp Auckland 2007 15

More information

Extending and Embedding Python

Extending and Embedding Python Extending and Embedding Python Release 3.4.3 Guido van Rossum and the Python development team February 25, 2015 Python Software Foundation Email: docs@python.org CONTENTS 1 Recommended third party tools

More information

Mixed language programming

Mixed language programming Mixed language programming Simon Funke 1,2 Ola Skavhaug 3 Joakim Sundnes 1,2 Hans Petter Langtangen 1,2 Center for Biomedical Computing, Simula Research Laboratory 1 Dept. of Informatics, University of

More information

Scientific Computing Using. Atriya Sen

Scientific Computing Using. Atriya Sen Scientific Computing Using Atriya Sen Broad Outline Part I, in which I discuss several aspects of the Python programming language Part II, in which I talk about some Python modules for scientific computing

More information

Diffusion processes in complex networks

Diffusion processes in complex networks Diffusion processes in complex networks Digression - parallel computing in Python Janusz Szwabiński Outlook: Multiprocessing Parallel computing in IPython MPI for Python Cython and OpenMP Python and OpenCL

More information

An introduction to scientific programming with. Session 5: Extreme Python

An introduction to scientific programming with. Session 5: Extreme Python An introduction to scientific programming with Session 5: Extreme Python Outline Managing your environment Efficiently handling large datasets Optimising your code Squeezing out extra speed Writing neat

More information

Extensions in C and Fortran

Extensions in C and Fortran Extensions in C and Fortran Why? C and Fortran are compiled languages Source code is translated to machine instructons by the compiler before you run. Ex: gfortran -o mycode mycode.f90 gcc -o mycode mycode.c

More information

phcpy: an API for PHCpack

phcpy: an API for PHCpack phcpy: an API for PHCpack Jan Verschelde University of Illinois at Chicago Department of Mathematics, Statistics, and Computer Science http://www.math.uic.edu/ jan jan@math.uic.edu Graduate Computational

More information

Embedding Python in Your C Programs

Embedding Python in Your C Programs 1 of 7 6/18/2006 9:05 PM Embedding Python in Your C Programs William Nagel Abstract C, meet Python. Python, this is C. With surprisingly little effort, the Python interpreter can be integrated into your

More information

The Python interpreter

The Python interpreter The Python interpreter Daniel Winklehner, Remi Lehe US Particle Accelerator School (USPAS) Summer Session Self-Consistent Simulations of Beam and Plasma Systems S. M. Lund, J.-L. Vay, D. Bruhwiler, R.

More information

Course May 18, Advanced Computational Physics. Course Hartmut Ruhl, LMU, Munich. People involved. SP in Python: 3 basic points

Course May 18, Advanced Computational Physics. Course Hartmut Ruhl, LMU, Munich. People involved. SP in Python: 3 basic points May 18, 2017 3 I/O 3 I/O 3 I/O 3 ASC, room A 238, phone 089-21804210, email hartmut.ruhl@lmu.de Patrick Böhl, ASC, room A205, phone 089-21804640, email patrick.boehl@physik.uni-muenchen.de. I/O Scientific

More information

Extending and Embedding Python

Extending and Embedding Python Extending and Embedding Python Release 2.7.6 Guido van Rossum Fred L. Drake, Jr., editor November 10, 2013 Python Software Foundation Email: docs@python.org CONTENTS 1 Extending Python with C or C++ 3

More information

Fast numerics in Python - NumPy and PyPy

Fast numerics in Python - NumPy and PyPy Fast numerics in Python - NumPy and Maciej Fijałkowski SEA, NCAR 22 February 2012 What is this talk about? What is and why? Numeric landscape in Python What we achieved in Where we re going? What is? An

More information

Week Two. Arrays, packages, and writing programs

Week Two. Arrays, packages, and writing programs Week Two Arrays, packages, and writing programs Review UNIX is the OS/environment in which we work We store files in directories, and we can use commands in the terminal to navigate around, make and delete

More information

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc. CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:

More information

Astronomical Data Analysis with Python

Astronomical Data Analysis with Python Astronomical Data Analysis with Python Lecture 8 Yogesh Wadadekar NCRA-TIFR July August 2010 Yogesh Wadadekar (NCRA-TIFR) Topical course 1 / 27 Slides available at: http://www.ncra.tifr.res.in/ yogesh/python_course_2010/

More information

OpenPIV Documentation

OpenPIV Documentation OpenPIV Documentation Release 0.0.1 OpenPIV group Jun 20, 2018 Contents 1 Contents: 3 1.1 Installation instruction.......................................... 3 1.2 Information for developers and contributors...............................

More information

debugging, hexadecimals, tuples

debugging, hexadecimals, tuples debugging, hexadecimals, tuples Matt Valeriote 28 January 2019 Searching for/asking for help Searching for help Google (or your search engine of choice) be as specific as possible Asking for help reproducible/minimal

More information

Intermediate/Advanced Python. Michael Weinstein (Day 2)

Intermediate/Advanced Python. Michael Weinstein (Day 2) Intermediate/Advanced Python Michael Weinstein (Day 2) Topics Review of basic data structures Accessing and working with objects in python Numpy How python actually stores data in memory Why numpy can

More information

ICA - Independent Component Analysis

ICA - Independent Component Analysis ICA - Independent Component Analysis The PLI guys Carlos Gonzalez, Felix Matuschke, Sebastian Starke, Andreas Herten, Nicole Schubert Problem to Solve Noise reduction of measured data using ICA One human

More information

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017 CS 133 - Introduction to Computational and Data Science Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017 Previous class We have learned the path and file system.

More information

CME 193: Introduction to Scientific Python Lecture 1: Introduction

CME 193: Introduction to Scientific Python Lecture 1: Introduction CME 193: Introduction to Scientific Python Lecture 1: Introduction Nolan Skochdopole stanford.edu/class/cme193 1: Introduction 1-1 Contents Administration Introduction Basics Variables Control statements

More information

Interactive Mode Python Pylab

Interactive Mode Python Pylab Short Python Intro Gerald Schuller, Nov. 2016 Python can be very similar to Matlab, very easy to learn if you already know Matlab, it is Open Source (unlike Matlab), it is easy to install, and unlike Matlab

More information

An Implementation of Python for Racket. Pedro Palma Ramos António Menezes Leitão

An Implementation of Python for Racket. Pedro Palma Ramos António Menezes Leitão An Implementation of Python for Racket Pedro Palma Ramos António Menezes Leitão Contents Motivation Goals Related Work Solution Performance Benchmarks Future Work 2 Racket + DrRacket 3 Racket + DrRacket

More information

Sage Reference Manual: Python technicalities

Sage Reference Manual: Python technicalities Sage Reference Manual: Python technicalities Release 8.1 The Sage Development Team Dec 09, 2017 CONTENTS 1 Various functions to debug Python internals 3 2 Variants of getattr() 5 3 Metaclasses for Cython

More information

Python: Swiss-Army Glue. Josh Karpel Graduate Student, Yavuz Group UW-Madison Physics Department

Python: Swiss-Army Glue. Josh Karpel Graduate Student, Yavuz Group UW-Madison Physics Department 1 Python: Swiss-Army Glue Josh Karpel Graduate Student, Yavuz Group UW-Madison Physics Department My Research: Matrix Multiplication 2 My Research: Computational Quantum Mechanics 3 Why

More information

Extending and Embedding the Python Interpreter

Extending and Embedding the Python Interpreter Extending and Embedding the Python Interpreter Release 2.5.2 Guido van Rossum Fred L. Drake, Jr., editor 21st February, 2008 Python Software Foundation Email: docs@python.org Copyright c 2001-2008 Python

More information

The Compilation Process

The Compilation Process Crash Course in C Lecture 2 Moving from Python to C: The compilation process Differences between Python and C Variable declaration and strong typing The memory model: data vs. address The Compilation Process

More information

Manual_implementation_of_the_Mersenne_twister_PseudoRandom_N

Manual_implementation_of_the_Mersenne_twister_PseudoRandom_N Manual_implementation_of_the_Mersenne_twister_PseudoRandom_N May 4, 2017 1 Table of Contents 1 Manual implementation of the Mersenne twister PseudoRandom Number Generator (PRNG) 1.1 Common API for the

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Graphical User Interfaces Robert Rand University of Pennsylvania December 03, 2015 Robert Rand (University of Pennsylvania) CIS 192 December 03, 2015 1 / 21 Outline 1 Performance

More information

[301] JSON. Tyler Caraza-Harter

[301] JSON. Tyler Caraza-Harter [301] JSON Tyler Caraza-Harter Learning Objectives Today JSON differences with Python syntax creating JSON files reading JSON files Read: Sweigart Ch 14 https://automatetheboringstuff.com/chapter14/ JSON

More information

Key Differences Between Python and Java

Key Differences Between Python and Java Python Python supports many (but not all) aspects of object-oriented programming; but it is possible to write a Python program without making any use of OO concepts. Python is designed to be used interpretively.

More information

Cython: A Guide For Python Programmers By Kurt W. Smith

Cython: A Guide For Python Programmers By Kurt W. Smith Cython: A Guide For Python Programmers By Kurt W. Smith Cython A Guide for Python Programmers. ebook Details: Paperback: 254 pages; Publisher: WOW! ebook; 1st edition (January 31, 2015) Book cover of High

More information

Function call overhead benchmarks with MATLAB, Octave, Python, Cython and C

Function call overhead benchmarks with MATLAB, Octave, Python, Cython and C Function call overhead benchmarks with MATLAB, Octave, Python, Cython and C André Gaul September 23, 2018 arxiv:1202.2736v1 [cs.pl] 13 Feb 2012 1 Background In many applications a function has to be called

More information

SciPy. scipy [www.scipy.org and links on course web page] scipy arrays

SciPy. scipy [www.scipy.org and links on course web page] scipy arrays SciPy scipy [www.scipy.org and links on course web page] - scipy is a collection of many useful numerical algorithms (numpy is the array core) - Python wrappers around compiled libraries and subroutines

More information

python 01 September 16, 2016

python 01 September 16, 2016 python 01 September 16, 2016 1 Introduction to Python adapted from Steve Phelps lectures - (http://sphelps.net) 2 Python is interpreted Python is an interpreted language (Java and C are not). In [1]: 7

More information

Python With Data Science

Python With Data Science Course Overview This course covers theoretical and technical aspects of using Python in Applied Data Science projects and Data Logistics use cases. Who Should Attend Data Scientists, Software Developers,

More information

Introduction to Python for Scientific Computing

Introduction to Python for Scientific Computing 1 Introduction to Python for Scientific Computing http://tinyurl.com/cq-intro-python-20151022 By: Bart Oldeman, Calcul Québec McGill HPC Bart.Oldeman@calculquebec.ca, Bart.Oldeman@mcgill.ca Partners and

More information

BMEGUI Installation Manual BMEGUI2.1.1 Update 1 (Last Edited on: 2009/02/25)

BMEGUI Installation Manual BMEGUI2.1.1 Update 1 (Last Edited on: 2009/02/25) BMEGUI 2.1.1 Installation Manual BMEGUI2.1.1 Update 1 (Last Edited on: 2009/02/25) Table of content Step 1: Download and unzip various libraries Step 2: Install the libraries Step 3: Download and unzip

More information

Pointers (continued), arrays and strings

Pointers (continued), arrays and strings Pointers (continued), arrays and strings 1 Last week We have seen pointers, e.g. of type char *p with the operators * and & These are tricky to understand, unless you draw pictures 2 Pointer arithmetic

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information

Principles of Software Construction: Objects, Design, and Concurrency

Principles of Software Construction: Objects, Design, and Concurrency Principles of Software Construction: Objects, Design, and Concurrency Part 3: Design case studies Performance Charlie Garrod Michael Hilton School of Computer Science 1 Administriva Homework 4b due Thursday,

More information

CFFI Documentation. Release Armin Rigo, Maciej Fijalkowski

CFFI Documentation. Release Armin Rigo, Maciej Fijalkowski CFFI Documentation Release 1.8.3 Armin Rigo, Maciej Fijalkowski September 17, 2016 Contents 1 What s New 3 1.1 v1.8.3................................................... 3 1.2 v1.8.2...................................................

More information

Lecture 12. Lists (& Sequences)

Lecture 12. Lists (& Sequences) Lecture Lists (& Sequences) Announcements for Today Reading Read 0.0-0., 0.4-0.6 Read all of Chapter 8 for Tue Prelim, Oct th 7:30-9:30 Material up to October 3rd Study guide net week Conflict with Prelim

More information

Coventry University

Coventry University 122OM: oventry University david.croft@coventry.ac.uk 2017 Overview 1 2 3 4 5 6 7 Expectations You have all attempted the green odio exercises for this week. Mark % 100 80 60 40 20 122OM results 2016-17

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

More information

Cython Reference Guide

Cython Reference Guide Cython Reference Guide Release 0.15pre Stefan Behnel, Robert Bradshaw, William Stein Gary Furnish, Dag Seljebotn, Greg Ewing Gabriel Gellner, editor June 06, 2016 Contents 1 Compilation 3 1.1 From the

More information

NumPy User Guide. Release Written by the NumPy community

NumPy User Guide. Release Written by the NumPy community NumPy User Guide Release 1.8.1 Written by the NumPy community May 07, 2015 Contents 1 Introduction 3 1.1 What is NumPy?............................................. 3 1.2 Building and installing NumPy.....................................

More information

Python Tutorial for CSE 446

Python Tutorial for CSE 446 Python Tutorial for CSE 446 Kaiyu Zheng, David Wadden Department of Computer Science & Engineering University of Washington January 2017 Goal Know some basics about how to use Python. See how you may use

More information

Python for Earth Scientists

Python for Earth Scientists Python for Earth Scientists Andrew Walker andrew.walker@bris.ac.uk Python is: A dynamic, interpreted programming language. Python is: A dynamic, interpreted programming language. Data Source code Object

More information

Pointers (continued), arrays and strings

Pointers (continued), arrays and strings Pointers (continued), arrays and strings 1 Last week We have seen pointers, e.g. of type char *p with the operators * and & These are tricky to understand, unless you draw pictures 2 Pointer arithmetic

More information

Hmax Documentation Documentation

Hmax Documentation Documentation Hmax Documentation Documentation Release 0.01 Youssef Barhomi January 22, 2014 Contents 1 OS and Hardware Prerequisites: 1 2 Installation: 3 3 Run the model on Caltech 101: 5 4 Directory structure: 7

More information

Scientific Python. 1 of 10 23/11/ :00

Scientific Python.   1 of 10 23/11/ :00 Scientific Python Neelofer Banglawala Kevin Stratford nbanglaw@epcc.ed.ac.uk kevin@epcc.ed.ac.uk Original course authors: Andy Turner Arno Proeme 1 of 10 23/11/2015 00:00 www.archer.ac.uk support@archer.ac.uk

More information

Python, C, C++, and Fortran Relationship Status: It s Not That Complicated. Philip Semanchuk

Python, C, C++, and Fortran Relationship Status: It s Not That Complicated. Philip Semanchuk Python, C, C++, and Fortran Relationship Status: It s Not That Complicated Philip Semanchuk (philip@pyspoken.com) This presentation is part of a talk I gave at PyData Carolinas 2016. This presentation

More information

Introduction to Python

Introduction to Python May 25, 2010 Basic Operators Logicals Types Tuples, Lists, & Dictionaries and or Building Functions Labs From a non-lab computer visit: http://www.csuglab.cornell.edu/userinfo Running your own python setup,

More information

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

Python review. 1 Python basics. References. CS 234 Naomi Nishimura Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not

More information