Skip to content

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

License

Notifications You must be signed in to change notification settings

MrCheatak/numexpr_mod

 
 

Repository files navigation

NumExpr_mod: Fast numerical expression evaluator for NumPy with cache

Author: Alexander K.
URL:https://github.com/MrCheatak/numexpr_mod

What is NumExpr?

Please refer to the original Numexpr repo.

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_mod

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_mod with:

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

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

Usage

This modification of the Numexpr package enables storage of the previously compiled expressions. Stored expressions can be then called by their assigned name.

Note that precompiled expressions accept only the same variable names with the same types. Although, both arrays and single values can be used for the same expression variable.

Output destination, order and casting can be preset at compilation time or be specified at expression call.

>>> import numexpr_mod as ne
>>> import numpy as np

>>> a = np.array([1,2,3,4,5])
>>> b = np.array([6,7,8,9,0])

>>> ne.cache_expression('a + b', 'sum_ab')
{'ex': <numexpr_mod.NumExpr object at 0x1090e36b0>, 'argnames': ['a', 'b'], 'kwargs': {'out': None, 'order': 'K', 'casting': 'safe', 'ex_uses_vml': False}}
>>> ne.re_evaluate('sum_ab')
array([ 7,  9, 11, 13,  5], dtype=int64)
>>> ne.evaluate('a + b')
array([ 7,  9, 11, 13,  5], dtype=int64)

Additionally, cached expresion names can be retrieved:

>>>ne.get_expression_names()
['sum_ab']

License

NumExpr is distributed under the MIT license.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 48.6%
  • C++ 45.2%
  • C 6.2%