What it is 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.
In addition, its multi-threaded capabilities can make use of all your
cores, which may accelerate computations, most specially if they are
not memory-bounded (e.g. those using transcendental functions).
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.
Examples of use
===============
>>> import numpy as np
>>> import numexpr as ne
>>> a = np.arange(1e6) # Choose large arrays
>>> 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(['abba', 'abbb', 'abbcdef'])
>>> ne.evaluate("'abba' == s") # string arrays are supported too
array([ True, False, False], dtype=bool)
Datatypes supported internally
==============================
Numexpr operates internally only with the following types:
* 8-bit boolean (bool)
* 32-bit signed integer (int or int32)
* 64-bit signed integer (long or int64)
* 32-bit single-precision floating point number (float or float32)
* 64-bit, double-precision floating point number (double or float64)
* 2x64-bit, double-precision complex number (complex or complex128)
* Raw string of bytes (str)
If the arrays in the expression does not match any of these types,
they will be upcasted to one of the above types (following the usual
type inference rules, see below). Have this in mind when doing
estimations about the memory consumption during the computation of
your expressions.
Also, the types in Numexpr conditions are somewhat stricter than those
of Python. For instance, the only valid constants for booleans are
`True` and `False`, and they are never automatically cast to integers.
Casting rules
=============
Casting rules in Numexpr follow closely those of NumPy. However, for
implementation reasons, there are some known exceptions to this rule,
namely:
* When an array with type `int8`, `uint8`, `int16` or `uint16` is
used inside Numexpr, it is internally upcasted to an `int` (or
`int32` in NumPy notation).
* When an array with type `uint32` is used inside Numexpr, it is
internally upcasted to a `long` (or `int64` in NumPy notation).
* A floating point function (e.g. `sin`) acting on `int8` or
`int16` types returns a `float64` type, instead of the `float32`
that is returned by NumPy functions. This is mainly due to the
absence of native `int8` or `int16` types in Numexpr.
* In operations implying a scalar and an array, the normal rules
of casting are used in Numexpr, in contrast with NumPy, where
array types takes priority. For example, if 'a' is an array of
type `float32` and 'b' is an scalar of type `float64` (or Python
`float` type, which is equivalent), then 'a*b' returns a
`float64` in Numexpr, but a `float32` in NumPy (i.e. array
operands take priority in determining the result type). If you
need to keep the result a `float32`, be sure you use a `float32`
scalar too.
Supported operators
===================
Numexpr supports the set of operators listed below:
* Logical operators: &, |, ~
* Comparison operators: <, <=, ==, !=, >=, >
* Unary arithmetic operators: -
* Binary arithmetic operators: +, -, *, /, **, %
Supported functions
===================
The next are the current supported set:
* where(bool, number1, number2): number
Number1 if the bool condition is true, number2 otherwise.
* {sin,cos,tan}(float|complex): float|complex
Trigonometric sine, cosine or tangent.
* {arcsin,arccos,arctan}(float|complex): float|complex
Trigonometric inverse sine, cosine or tangent.
* arctan2(float1, float2): float
Trigonometric inverse tangent of float1/float2.
* {sinh,cosh,tanh}(float|complex): float|complex
Hyperbolic sine, cosine or tangent.
* {arcsinh,arccosh,arctanh}(float|complex): float|complex
Hyperbolic inverse sine, cosine or tangent.
* {log,log10,log1p}(float|complex): float|complex
Natural, base-10 and log(1+x) logarithms.
* {exp,expm1}(float|complex): float|complex
Exponential and exponential minus one.
* sqrt(float|complex): float|complex
Square root.
* abs(float|complex): float|complex
Absolute value.
* {real,imag}(complex): float
Real or imaginary part of complex.
* complex(float, float): complex
Complex from real and imaginary parts.
.. Notes:
+ `abs()` for complex inputs returns a ``complex`` output too. This
is a departure from NumPy where a ``float`` is returned instead.
However, Numexpr is not flexible enough yet so as to allow this to
happen. Meanwhile, if you want to mimic NumPy behaviour, you may
want to select the real part via the ``real`` function
(e.g. "real(abs(cplx))") or via the ``real`` selector
(e.g. "abs(cplx).real").
More functions can be added if you need them.
Supported reduction operations
==============================
The next are the current supported set:
* sum(number, axis=None): Sum of array elements over a given axis.
Negative axis are not supported.
* prod(number, axis=None): Product of array elements over a given
axis. Negative axis are not supported.
General routines
================
* evaluate(expression, local_dict=None, global_dict=None,
out=None, order='K', casting='safe', **kwargs):
Evaluate a simple array expression element-wise. See docstrings
for more info on parameters. Also, see examples above.
* test(): Run all the tests in the test suite.
* print_versions(): Print the versions of software that numexpr
relies on.
* set_num_threads(nthreads): Sets a number of threads to be used in
operations. Returns the previous setting for the number of
threads. During initialization time Numexpr sets this number to
the number of detected cores in the system (see
`detect_number_of_cores()`).
If you are using Intel's VML, you may want to use
`set_vml_num_threads(nthreads)` to perform the parallel job with
VML instead. However, you should get very similar performance
with VML-optimized functions, and VML's parallelizer cannot deal
with common expresions like `(x+1)*(x-2)`, while Numexpr's one
can.
* detect_number_of_cores(): Detects the number of cores in the
system.
Intel's VML specific support routines
=====================================
When compiled with Intel's VML (Vector Math Library), you will be able
to use some additional functions for controlling its use. These are:
* set_vml_accuracy_mode(mode): Set the accuracy for VML operations.
The `mode` parameter can take the values:
- 'low': Equivalent to VML_LA - low accuracy VML functions are called
- 'high': Equivalent to VML_HA - high accuracy VML functions are called
- 'fast': Equivalent to VML_EP - enhanced performance VML functions are called
It returns the previous mode.
This call is equivalent to the `vmlSetMode()` in the VML library.
See:
http://www.intel.com/software/products/mkl/docs/webhelp/vml/vml_DataTypesAccuracyModes.html
for more info on the accuracy modes.
* set_vml_num_threads(nthreads): Suggests a maximum number of
threads to be used in VML operations.
T
没有合适的资源?快使用搜索试试~ 我知道了~
快速数值数组表达式计算器Python和NumPy。.zip
共49个文件
py:18个
txt:10个
hpp:9个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 199 浏览量
2024-04-24
16:34:15
上传
评论
收藏 96KB ZIP 举报
温馨提示
快速数值数组表达式计算器Python和NumPy。
资源推荐
资源详情
资源评论
收起资源包目录
快速数值数组表达式计算器Python和NumPy。.zip (49个子文件)
123Y-2
快速数值数组表达式计算器Python和NumPy。
numexpr-2.2.2
CMakeLists.txt 3KB
numexpr
utils.py 4KB
__init__.py 2KB
interpreter.hpp 2KB
cpuinfo.py 22KB
opcodes.hpp 6KB
functions.hpp 5KB
msvc_function_stubs.hpp 3KB
numexpr_object.hpp 1KB
missing_posix_functions.hpp 2KB
module.hpp 2KB
version.py 846B
numexpr_config.hpp 2KB
interp_body.cpp 19KB
tests
__init__.py 447B
test_numexpr.py 28KB
necompiler.py 25KB
expressions.py 16KB
numexpr_object.cpp 14KB
interpreter.cpp 42KB
module.cpp 12KB
win32
pthread.h 3KB
pthread.c 7KB
complex_functions.hpp 8KB
setup.py 7KB
AUTHORS.txt 689B
LICENSE.txt 1KB
PKG-INFO 312B
site.cfg.example 2KB
RELEASE_NOTES.txt 12KB
README.txt 10KB
INSTALL.txt 2KB
numexpr.egg-info
SOURCES.txt 1KB
top_level.txt 8B
PKG-INFO 312B
not-zip-safe 1B
dependency_links.txt 1B
MANIFEST.in 184B
setup.cfg 59B
ANNOUNCE.txt 2KB
bench
issue-47.py 195B
vml_timing.py 6KB
poly.py 2KB
unaligned-simple.py 1KB
boolean_timing.py 5KB
timing.py 4KB
varying-expr.py 2KB
issue-36.py 854B
multidim.py 3KB
G2
共 49 条
- 1
资源评论
m0_74456535
- 粉丝: 89
- 资源: 704
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功