numexpr

Fast numerical array expression evaluator for Python, NumPy, Pandas, PyTables and more

https://github.com/pydata/numexpr

Science Score: 59.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    4 of 77 committers (5.2%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.2%) to scientific vocabulary

Keywords from Contributors

closember alignment flexible gtk qt tk wx tensors compression ipython
Last synced: 6 months ago · JSON representation

Repository

Fast numerical array expression evaluator for Python, NumPy, Pandas, PyTables and more

Basic Info
Statistics
  • Stars: 2,350
  • Watchers: 59
  • Forks: 215
  • Open Issues: 5
  • Releases: 15
Created over 12 years ago · Last pushed 6 months ago
Metadata Files
Readme Funding License Authors

README.rst

======================================================
NumExpr: Fast numerical expression evaluator for NumPy
======================================================

:Author: David M. Cooke, Francesc Alted, and others.
:Maintainer: Francesc Alted
:Contact: faltet@gmail.com
:URL: https://github.com/pydata/numexpr
:Documentation: http://numexpr.readthedocs.io/en/latest/
:GitHub Actions: |actions|
:PyPi: |version|
:DOI: |doi|
:readthedocs: |docs|

.. |actions| image:: https://github.com/pydata/numexpr/workflows/Build/badge.svg
        :target: https://github.com/pydata/numexpr/actions
.. |travis| image:: https://travis-ci.org/pydata/numexpr.png?branch=master
        :target: https://travis-ci.org/pydata/numexpr
.. |docs| image:: https://readthedocs.org/projects/numexpr/badge/?version=latest
        :target: http://numexpr.readthedocs.io/en/latest
.. |doi| image:: https://zenodo.org/badge/doi/10.5281/zenodo.2483274.svg
        :target:  https://doi.org/10.5281/zenodo.2483274
.. |version| image:: https://img.shields.io/pypi/v/numexpr
        :target: https://pypi.python.org/pypi/numexpr


What is NumExpr?
----------------

NumExpr is a fast numerical expression evaluator for NumPy.  With it,
expressions that operate on arrays (like :code:`'3*a+4*b'`) are accelerated
and use less memory than doing the same calculation in Python.

In addition, its multi-threaded capabilities can make use of all your
cores -- which generally results in substantial performance scaling compared
to NumPy.

Last but not least, numexpr can make use of Intel's VML (Vector Math
Library, normally integrated in its Math Kernel Library, or MKL).
This allows further acceleration of transcendent expressions.


How NumExpr achieves high performance
-------------------------------------

The main reason why NumExpr achieves better performance than NumPy is
that it avoids allocating memory for intermediate results. This
results in better cache utilization and reduces memory access in
general. Due to this, NumExpr works best with large arrays.

NumExpr parses expressions into its own op-codes that are then used by
an integrated computing virtual machine. The array operands are split
into small chunks that easily fit in the cache of the CPU and passed
to the virtual machine. The virtual machine then applies the
operations on each chunk. It's worth noting that all temporaries and
constants in the expression are also chunked. Chunks are distributed among
the available cores of the CPU, resulting in highly parallelized code
execution.

The result is that NumExpr can get the most of your machine computing
capabilities for array-wise computations. Common speed-ups with regard
to NumPy are usually between 0.95x (for very simple expressions like
:code:`'a + 1'`) and 4x (for relatively complex ones like :code:`'a*b-4.1*a > 2.5*b'`),
although much higher speed-ups can be achieved for some functions  and complex
math operations (up to 15x in some cases).

NumExpr performs best on matrices that are too large to fit in L1 CPU cache.
In order to get a better idea on the different speed-ups that can be achieved
on your platform, run the provided benchmarks.

Installation
------------

From wheels
^^^^^^^^^^^

NumExpr is available for install via `pip` for a wide range of platforms and
Python versions (which may be browsed at: https://pypi.org/project/numexpr/#files).
Installation can be performed as::

    pip install numexpr

If you are using the Anaconda or Miniconda distribution of Python you may prefer
to use the `conda` package manager in this case::

    conda install numexpr

From Source
^^^^^^^^^^^

On most \*nix systems your compilers will already be present. However if you
are using a virtual environment with a substantially newer version of Python than
your system Python you may be prompted to install a new version of `gcc` or `clang`.

For Windows, you will need to install the Microsoft Visual C++ Build Tools
(which are free) first. The version depends on which version of Python you have
installed:

https://wiki.python.org/moin/WindowsCompilers

For Python 3.6+ simply installing the latest version of MSVC build tools should
be sufficient. Note that wheels found via pip do not include MKL support. Wheels
available via `conda` will have MKL, if the MKL backend is used for NumPy.

See `requirements.txt` for the required version of NumPy.

NumExpr is built in the standard Python way::

  python setup.py build install

You can test `numexpr` with::

  python -c "import numexpr; numexpr.test()"

Do not test NumExpr in the source directory or you will generate import errors.

Enable Intel® MKL support
^^^^^^^^^^^^^^^^^^^^^^^^^

NumExpr includes support for Intel's MKL library. This may provide better
performance on Intel architectures, mainly when evaluating transcendental
functions (trigonometrical, exponential, ...).

If you have Intel's MKL, copy the `site.cfg.example` that comes with the
distribution to `site.cfg` and edit the latter file to provide correct paths to
the MKL libraries in your system.  After doing this, you can proceed with the
usual building instructions listed above.

Pay attention to the messages during the building process in order to know
whether MKL has been detected or not.  Finally, you can check the speed-ups on
your machine by running the `bench/vml_timing.py` script (you can play with
different parameters to the `set_vml_accuracy_mode()` and `set_vml_num_threads()`
functions in the script so as to see how it would affect performance).

Usage
-----

::

  >>> import numpy as np
  >>> import numexpr as ne

  >>> a = np.arange(1e6)   # Choose large arrays for better speedups
  >>> b = np.arange(1e6)

  >>> ne.evaluate("a + 1")   # a simple expression
  array([  1.00000000e+00,   2.00000000e+00,   3.00000000e+00, ...,
           9.99998000e+05,   9.99999000e+05,   1.00000000e+06])

  >>> ne.evaluate("a * b - 4.1 * a > 2.5 * b")   # a more complex one
  array([False, False, False, ...,  True,  True,  True], dtype=bool)

  >>> ne.evaluate("sin(a) + arcsinh(a/b)")   # you can also use functions
  array([        NaN,  1.72284457,  1.79067101, ...,  1.09567006,
          0.17523598, -0.09597844])

  >>> s = np.array([b'abba', b'abbb', b'abbcdef'])
  >>> ne.evaluate("b'abba' == s")   # string arrays are supported too
  array([ True, False, False], dtype=bool)


Free-threading support
----------------------
Starting on CPython 3.13 onwards there is a new distribution that disables the
Global Interpreter Lock (GIL) altogether, thus increasing the performance yields
under multi-threaded conditions on a single interpreter, as opposed to having to use
multiprocessing.

Whilst numexpr has been demonstrated to work under free-threaded
CPython, considerations need to be taken when using numexpr native parallel
implementation vs using Python threads directly in order to prevent oversubscription,
we recommend either using the main CPython interpreter thread to spawn multiple C threads
using the parallel numexpr API, or spawning multiple CPython threads that do not use
the parallel API.

For more information about free-threaded CPython, we recommend visiting the following
`community Wiki `


Documentation
-------------

Please see the official documentation at `numexpr.readthedocs.io `_.
Included is a user guide, benchmark results, and the reference API.


Authors
-------

Please see `AUTHORS.txt `_.


License
-------

NumExpr is distributed under the `MIT `_ license.


.. Local Variables:
.. mode: text
.. coding: utf-8
.. fill-column: 70
.. End:

Owner

  • Name: Python for Data
  • Login: pydata
  • Kind: organization

GitHub Events

Total
  • Create event: 2
  • Release event: 2
  • Issues event: 20
  • Watch event: 131
  • Delete event: 2
  • Issue comment event: 79
  • Push event: 37
  • Pull request review event: 11
  • Pull request review comment event: 10
  • Pull request event: 22
  • Fork event: 8
Last Year
  • Create event: 2
  • Release event: 2
  • Issues event: 20
  • Watch event: 131
  • Delete event: 2
  • Issue comment event: 79
  • Push event: 37
  • Pull request review event: 11
  • Pull request review comment event: 10
  • Pull request event: 22
  • Fork event: 8

Committers

Last synced: 8 months ago

All Time
  • Total Commits: 825
  • Total Committers: 77
  • Avg Commits per committer: 10.714
  • Development Distribution Score (DDS): 0.644
Past Year
  • Commits: 58
  • Committers: 5
  • Avg Commits per committer: 11.6
  • Development Distribution Score (DDS): 0.466
Top Committers
Name Email Commits
Francesc Alted f****t@g****m 294
Robert McLeod r****d@g****m 170
Francesc Alted f****c@c****o 74
Antonio Valentino a****o@t****t 34
david.m.cooke d****l@l****t 23
Gaetan de Menten g****n@g****m 22
Edgar Andrés Margffoy Tuay a****y@g****m 18
Mark Wiebe m****e@g****m 16
Marcin Krol m****2@k****t 13
Francesc Alted f****t@p****m 10
Matt Einhorn m****t@e****v 10
Teng Liu 2****t@g****m 8
Christoph Gohlke c****e@g****m 7
Andrea Bedini a****a@a****m 6
Fernando Seiti Furusato f****i@l****m 6
Emma Ai e****i@g****u 5
Francesc Alted f****m 4
Alexandr Shadchin a****n@g****m 4
Aleks B g****b@c****m 4
Kirill Kouzoubov k****8@g****m 4
Patrick Hoefler 6****l 4
Stephan Erb s****b@b****m 4
anatoly techtonik t****k@g****m 4
mamrehn m****n 4
pre-commit-ci[bot] 6****] 3
Tom Kooij t****j@t****l 3
Oleksandr Pavlyk o****k@i****m 3
Mark Harfouche m****e@g****m 3
Mahdi Ben Jelloul m****l@g****m 3
Lehman Garrison l****n@c****u 3
and 47 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 164
  • Total pull requests: 77
  • Average time to close issues: almost 3 years
  • Average time to close pull requests: about 1 month
  • Total issue authors: 118
  • Total pull request authors: 37
  • Average comments per issue: 4.62
  • Average comments per pull request: 2.3
  • Merged pull requests: 63
  • Bot issues: 0
  • Bot pull requests: 3
Past Year
  • Issues: 13
  • Pull requests: 17
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 16 days
  • Issue authors: 12
  • Pull request authors: 7
  • Average comments per issue: 2.31
  • Average comments per pull request: 2.24
  • Merged pull requests: 14
  • Bot issues: 0
  • Bot pull requests: 3
Top Authors
Issue Authors
  • FrancescAlted (18)
  • robbmcleod (13)
  • mgorny (5)
  • seberg (4)
  • 27rabbitlt (3)
  • befeleme (3)
  • duongkstn (2)
  • jorisvandenbossche (2)
  • joycebrum (2)
  • kif (2)
  • ssomnath (2)
  • beojan (2)
  • tspiteri (1)
  • antoinecarme (1)
  • bfeeny (1)
Pull Request Authors
  • 27rabbitlt (10)
  • avalentino (8)
  • neutrinoceros (5)
  • andfoy (5)
  • tacaswell (3)
  • pre-commit-ci[bot] (3)
  • FrancescAlted (3)
  • matham (2)
  • pinotree (2)
  • Jamim (2)
  • phofl (2)
  • hroncok (2)
  • robbmcleod (2)
  • seberg (2)
  • befeleme (2)
Top Labels
Issue Labels
Stale (66) imported (18) Priority-Medium (18) bug (14) enhancement (7) wontfix (1)
Pull Request Labels
Stale (2)

Packages

  • Total packages: 6
  • Total downloads:
    • pypi 8,039,835 last-month
  • Total docker downloads: 391,449,235
  • Total dependent packages: 458
    (may contain duplicates)
  • Total dependent repositories: 15,072
    (may contain duplicates)
  • Total versions: 140
  • Total maintainers: 5
  • Total advisories: 1
pypi.org: numexpr

Fast numerical expression evaluator for NumPy

  • Versions: 56
  • Dependent Packages: 378
  • Dependent Repositories: 13,496
  • Downloads: 8,039,810 Last month
  • Docker Downloads: 391,449,235
Rankings
Dependent repos count: 0.1%
Dependent packages count: 0.1%
Downloads: 0.1%
Docker downloads count: 0.3%
Average: 1.0%
Stargazers count: 1.6%
Forks count: 3.7%
Last synced: 6 months ago
spack.io: py-numexpr

Fast numerical expression evaluator for NumPy

  • Versions: 13
  • Dependent Packages: 8
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Average: 4.8%
Stargazers count: 5.3%
Dependent packages count: 6.7%
Forks count: 7.1%
Maintainers (1)
Last synced: 6 months ago
proxy.golang.org: github.com/pydata/numexpr
  • Versions: 37
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 1.5%
Forks count: 1.9%
Average: 5.9%
Dependent packages count: 9.6%
Dependent repos count: 10.8%
Last synced: 6 months ago
conda-forge.org: numexpr

Numexpr is a fast numerical expression evaluator for NumPy. With it, expressions that operate on arrays (like "3*a+4*b") are accelerated and use less memory than doing the same calculation in Python.

  • Versions: 13
  • Dependent Packages: 61
  • Dependent Repositories: 786
Rankings
Dependent repos count: 0.9%
Dependent packages count: 1.2%
Average: 6.0%
Stargazers count: 9.1%
Forks count: 12.9%
Last synced: 6 months ago
pypi.org: numexpr3

Fast numerical expression evaluator for NumPy

  • Versions: 4
  • Dependent Packages: 1
  • Dependent Repositories: 4
  • Downloads: 25 Last month
Rankings
Stargazers count: 1.6%
Forks count: 3.7%
Dependent packages count: 4.8%
Dependent repos count: 7.5%
Average: 8.1%
Downloads: 23.1%
Maintainers (1)
Last synced: 6 months ago
anaconda.org: numexpr

Numexpr is a fast numerical expression evaluator for NumPy. With it, expressions that operate on arrays (like "3*a+4*b") are accelerated and use less memory than doing the same calculation in Python.

  • Versions: 17
  • Dependent Packages: 10
  • Dependent Repositories: 786
Rankings
Dependent packages count: 4.9%
Dependent repos count: 5.3%
Average: 12.9%
Stargazers count: 18.0%
Forks count: 23.5%
Last synced: 6 months ago

Dependencies

.github/workflows/build.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
  • actions/upload-artifact v2 composite
  • docker/setup-qemu-action v1 composite
  • softprops/action-gh-release v0.1.14 composite
doc/requirements.txt pypi
  • numpy >=1.7
  • numpydoc *
requirements.txt pypi
  • numpy >=1.13.3