Git Product home page Git Product logo

fastats's Introduction

fastats

codecov Codacy Badge License

A pure Python library for benchmarked, scalable numerics, built using numba.

Fastats mailing list


Latest Release: 2019.1, get it using pip install fastats

Aims/Reasoning

Current state-of-the-art in numerics / algorithmics / machine learning has many big problems, two of which are:

  1. The data is getting bigger and more complex, and code is having trouble scaling to these levels.
  2. The code is getting bigger and more complex, and developers are having trouble scaling to these levels.

To fix (1) we need better algorithms, code which vectorises to SIMD instructions, and code which parallelises across CPU cores.

To fix (2) we need to focus on simpler code which is easier to debug.

fastats (ie, fast-stats) tries to help with both of these by; using Linear Algebra for performance optimizations in common functions, using numba from Anaconda to JIT compile the optimized Python code to vectorised native code, whilst being trivial to run in pure Python mode for debugging.

Usage

Finding the roots of an equation is central to much of data science and machine learning. For monotonic functions we can use a Newton-Raphson solver to find the root:

from fastats import newton_raphson

def my_func(x):
    return x**3 - x - 1

result = newton_raphson(0.025, 1e-6, root=my_func)

This uses numba under-the-hood to JIT compile the python code to native code, and uses fastats transforms to call my_func where required.

However, we usually wish to take a fast function and apply it to a large data set, so fastats allows you to get the optimized function back as a callable:

newton_opt = newton_raphson(0.025, 1e-6, root=my_func, return_callable=True)

result = newton_opt(0.03, 1e-6)

If you profile this you will find it's extremely fast (from a 2015 Macbook Pro):

>>> %timeit newton_opt(0.03, 1e-6)
785 ns ± 8.2 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

compared with SciPy 1.0.1:

>>> import scipy
>>> scipy.__version__
>>> from scipy.optimize import newton
>>> %timeit newton(my_func, x0=0.03, tol=1e-6)
25.6 µs ± 954 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)

What does this show?

Most high-level languages like Python/Lua/Ruby have a formal C-API which allows us to 'drop' down to native code easily (such as SciPy shown above). However, not only is this time-consuming, error-prone and off-putting to many developers, but as you can see from the example above, the specialised C extensions do not automatically scale to larger data.

Through the use of numba to JIT-compile the entire function down to native code, we can quickly scale to much larger data sizes without leaving the simplicity of Python.

What does fastats actually do?

The secret is in the handling of the function arguments.

When we write C-extensions to high-level languages, we are usually trying to speed up a certain algorithm which is taking too long. This works well for specialised libraries, however in this world of big data, the next step is usually now I want to apply that function to this array of 10 million items. This is where the C-extension / native library technique falls down.

C-extensions to high-level languages are necessarily limited by the defined API - ie, you can write a C function to take 3 floats, or 3 arrays of floats, but it's very difficult to deal with arbitrary inputs.

fastats allows you to pass functions as arguments into numba, and therefore abstract away the specific looping or concurrency constructs, resulting in faster, cleaner development time, as well as faster execution time.

Requirements

This project is managed using the poetry library; all dependencies are specified in pyproject.toml.

Run pip install poetry then poetry install to get the correct development environment.

The contribution guide contains information on how to install development requirements.

Running the tests

Run poetry run pytest from the top-level of the repository.

To install poetry, you can use pip install poetry then poetry install.

Contributing

Please make sure you've read the contribution guide: CONTRIBUTING.md

In short, we use PRs for everything.

Sponsors

Pico Software

fastats's People

Contributors

aaroncritchley avatar dependabot[bot] avatar dwillmer avatar ktattan avatar pawroman avatar rjenc29 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

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.