diezguerra / pycon-spain-swd-talk Goto Github PK
View Code? Open in Web Editor NEWSlides and code for the 2014 PyCon Spain Speed without Drag talk
Slides and code for the 2014 PyCon Spain Speed without Drag talk
I've tracked down the problem with the numba version, that causes the fallback to nopython mode "ruining" performance.
In the test slide you run it feeding the list of tuples. In order to perform better you have to feed the numpy array version (a list will force "object mode", while the numpy array is supported in "no python" mode -the fast backend).
A slight modification in the code is also required, as right now numba doesn't support partial indexing (indexation returning an array) in no-python mode. So changing the "numba" cell to:
import numba as nb
@nb.jit
def area_nb(points):
acc = 0
for i in xrange(len(points) - 1):
acc += points[i, 0] * points[i + 1, 1] - points[i + 1, 0] * points[i, 1]
return abs(acc) / 2
area_np_nb = nb.jit(area_np)
and using the numpy version of polygons:
print " Python Area:".ljust(21),
%timeit area(polygon)
print "Python Area Numba:".ljust(20),
%timeit area_nb(polygon_np)
print "Python NumPy:".ljust(20),
%timeit area_np(polygon_np)
print "Python NumPy Numba:".ljust(20),
%timeit area_np_nb(polygon_np)
yields a result more in line with expectations. In my dev machine:
Python Area: 1 loops, best of 3: 281 ms per loop
Python Area Numba: 1000 loops, best of 3: 1.31 ms per loop
Python NumPy: 100 loops, best of 3: 4.76 ms per loop
Python NumPy Numba: 1 loops, best of 3: 4.77 ms per loop
Note that the NumPy Numba version could be tweaked to work, but it will require external
allocation of some temporal arrays and won't be worth the effort, IMO.
Note that in order to make sure that a given function is compiled in no-python mode in the current numba version (0.15.1) you can use the njit decorator (or pass a nopython=True keyword argument to jit). In that case, if it fails to compile in the fast mode an exception will be raised pointing at the root cause of the failure (in a rather cryptic way, but this should improve in incoming versions).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.