Giter Site home page Giter Site logo

pycon-spain-swd-talk's People

Contributors

diezguerra avatar

Watchers

 avatar

pycon-spain-swd-talk's Issues

A possible fix for the numba version

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).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.