Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python Scientific and Numerical Computing (fast...

Python Scientific and Numerical Computing (fast with pypy?)

Five minute lightning talk given at the pymntos (www.pymntos.org) monthly meeting. This talk reviews: if pypy is useful for numerical and scientific computing.

Avatar for Christopher Felton

Christopher Felton

July 11, 2013
Tweet

Other Decks in Technology

Transcript

  1. Context • Hardware design • HDL development and simulation •

    synthesizable descriptions and verification environments • Signal / data analysis (lab data, field data) • Before Python • HDL (Verilog/SV and VHDL), Matlab, and C/C++ • Ad hoc growth into a Python user
  2. pypy • All the rave - PyCon 2012 • JIT

    compiler for Python • impressive results (benchmarks) • www.pypy.org
  3. cpython gfortran romberg-integration* 25x faster 2x faster akima-interpolation* 20x faster

    5x slower float 7x faster meteor-contest 2x faster chaos 25x faster ai 4x faster lfsr** 19.5x faster randgen** 12.3x faster longdiv** 10.9x faster findmax** 7.8x faster image processing simulation 2x faster -- FFT 8.6x faster -- above all pure python implementations (except the referenced fortran) pypy compared to cpython and fortran * pypy mailing-list ** HDL (hardware description language) simulation Because pypy is fast (simple fast)
  4. Nfft, Nloops 4096, 1024 262144, 256 avg increase cpython pypy

    numpy* 1.000 1.000 0.126 0.136 7.7x 0.003 0.003 259.2x FFT Comparison ... wait there is more Not really a fair comparison ... let’s look a little closer ... the FFT available with the numpy package much faster def _fftr(x): n = len(x) if (n == 1): return x # even and odd parts X,Y = (x[::2], x[1::2],) Xr,Yr = (_fftr(X), _fftr(Y),) w = [(cos(2*pi*k/float(n)) + 1.j*sin(2*pi*k/float(n))) for k in range(n)] m = n/2; b = [Xr[(k%m)]+w[k]*Yr[(k%m)] for k in range(n)] return b Simple recursive FFT (python only) * The numpy FFT, optimized FFTW code @ http://www.dsprelated.com/showcode/16.php or www.bitbucket.org/cfelton/examples/src/tip/rfft
  5. FFT Comparison ... wait there is more The FFT is

    used in a simulation but more than just the FFT in the simulation. What is the overall performance? This simulation uses the FFT but the FFT speed up alone was not enough to affect the overall performance! Nfft, Nloops 4096, 1024 4096, 256 avg increase cpython pypy numpy 1.000 1.000 0.010 0.073 13.8x 1.005 0.987 1.0x 0 0.275 0.550 0.825 1.100 4096,1024 4096,256 4069,32 4096,8 128,128 Simulation 1 cpython pypy numpy
  6. it is great for hardware development (EDA) See MyHDL digital

    circuit simulations: www.myhdl.org/performance
  7. Filling the Library Gap • rewrite of sci/num libraries in

    Python (golden models) • new C and fortran interfaces to existing packages (cffi and ???) • key portions written in rpython (this is what the pypy team is currently doing with numpypy)
  8. Transmitting Mixed Signals • pypy current state • No -

    analysis, classical signals and systems, etc • Yes - simulation: HDL simulation and Simulink like simulations • projects of interest (where applicable) • gnuradio for fpga (krypton) • large correlators for radio astronomy