numexpr 2.14.2__cp313-cp313-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- numexpr/__init__.py +66 -0
- numexpr/bespoke_functions.hpp +339 -0
- numexpr/complex_functions.hpp +498 -0
- numexpr/cpuinfo.py +861 -0
- numexpr/expressions.py +546 -0
- numexpr/functions.hpp +235 -0
- numexpr/interp_body.cpp +602 -0
- numexpr/interpreter.cp313-win_arm64.pyd +0 -0
- numexpr/interpreter.cpp +1585 -0
- numexpr/interpreter.hpp +137 -0
- numexpr/missing_posix_functions.hpp +102 -0
- numexpr/module.cpp +552 -0
- numexpr/module.hpp +60 -0
- numexpr/msvc_function_stubs.hpp +231 -0
- numexpr/necompiler.py +1074 -0
- numexpr/numexpr_config.hpp +71 -0
- numexpr/numexpr_object.cpp +408 -0
- numexpr/numexpr_object.hpp +34 -0
- numexpr/opcodes.hpp +214 -0
- numexpr/str-two-way.hpp +435 -0
- numexpr/tests/__init__.py +14 -0
- numexpr/tests/conftest.py +21 -0
- numexpr/tests/test_numexpr.py +1603 -0
- numexpr/utils.py +311 -0
- numexpr/version.py +5 -0
- numexpr/win32/pthread.c +218 -0
- numexpr/win32/pthread.h +119 -0
- numexpr/win32/stdint.h +235 -0
- numexpr-2.14.2.dist-info/METADATA +233 -0
- numexpr-2.14.2.dist-info/RECORD +34 -0
- numexpr-2.14.2.dist-info/WHEEL +5 -0
- numexpr-2.14.2.dist-info/licenses/LICENSE.txt +21 -0
- numexpr-2.14.2.dist-info/licenses/LICENSES/cpuinfo.txt +31 -0
- numexpr-2.14.2.dist-info/top_level.txt +1 -0
numexpr/__init__.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
###################################################################
|
|
2
|
+
# Numexpr - Fast numerical array expression evaluator for NumPy.
|
|
3
|
+
#
|
|
4
|
+
# License: MIT
|
|
5
|
+
# Author: See AUTHORS.txt
|
|
6
|
+
#
|
|
7
|
+
# See LICENSE.txt and LICENSES/*.txt for details about copyright and
|
|
8
|
+
# rights to use.
|
|
9
|
+
####################################################################
|
|
10
|
+
|
|
11
|
+
"""
|
|
12
|
+
Numexpr is a fast numerical expression evaluator for NumPy. With it,
|
|
13
|
+
expressions that operate on arrays (like "3*a+4*b") are accelerated
|
|
14
|
+
and use less memory than doing the same calculation in Python.
|
|
15
|
+
|
|
16
|
+
See:
|
|
17
|
+
|
|
18
|
+
https://github.com/pydata/numexpr
|
|
19
|
+
|
|
20
|
+
for more info about it.
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from numexpr.interpreter import __BLOCK_SIZE1__, MAX_THREADS, use_vml
|
|
25
|
+
|
|
26
|
+
is_cpu_amd_intel = False # DEPRECATION WARNING: WILL BE REMOVED IN FUTURE RELEASE
|
|
27
|
+
|
|
28
|
+
# cpuinfo imports were moved into the test submodule function that calls them
|
|
29
|
+
# to improve import times.
|
|
30
|
+
|
|
31
|
+
from numexpr.expressions import E
|
|
32
|
+
from numexpr.necompiler import (NumExpr, disassemble, evaluate, re_evaluate,
|
|
33
|
+
validate)
|
|
34
|
+
from numexpr.utils import (_init_num_threads, detect_number_of_cores,
|
|
35
|
+
detect_number_of_threads, get_num_threads,
|
|
36
|
+
get_vml_version, set_num_threads,
|
|
37
|
+
set_vml_accuracy_mode, set_vml_num_threads)
|
|
38
|
+
|
|
39
|
+
# Detect the number of cores
|
|
40
|
+
ncores = detect_number_of_cores()
|
|
41
|
+
# Initialize the number of threads to be used
|
|
42
|
+
nthreads = _init_num_threads()
|
|
43
|
+
# The default for VML is 1 thread (see #39)
|
|
44
|
+
# set_vml_num_threads(1)
|
|
45
|
+
|
|
46
|
+
from . import version
|
|
47
|
+
|
|
48
|
+
__version__ = version.version
|
|
49
|
+
|
|
50
|
+
def print_versions():
|
|
51
|
+
"""Print the versions of software that numexpr relies on."""
|
|
52
|
+
try:
|
|
53
|
+
import numexpr.tests
|
|
54
|
+
return numexpr.tests.print_versions()
|
|
55
|
+
except ImportError:
|
|
56
|
+
# To maintain Python 2.6 compatibility we have simple error handling
|
|
57
|
+
raise ImportError('`numexpr.tests` could not be imported, likely it was excluded from the distribution.')
|
|
58
|
+
|
|
59
|
+
def test(verbosity=1):
|
|
60
|
+
"""Run all the tests in the test suite."""
|
|
61
|
+
try:
|
|
62
|
+
import numexpr.tests
|
|
63
|
+
return numexpr.tests.test(verbosity=verbosity)
|
|
64
|
+
except ImportError:
|
|
65
|
+
# To maintain Python 2.6 compatibility we have simple error handling
|
|
66
|
+
raise ImportError('`numexpr.tests` could not be imported, likely it was excluded from the distribution.')
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
#include <numpy/npy_cpu.h>
|
|
2
|
+
#include <math.h>
|
|
3
|
+
#include <string.h>
|
|
4
|
+
#include <assert.h>
|
|
5
|
+
#include <vector>
|
|
6
|
+
#include "numexpr_config.hpp" // isnan definitions
|
|
7
|
+
|
|
8
|
+
// Generic sign function
|
|
9
|
+
inline int signi(int x) {return (0 < x) - (x < 0);}
|
|
10
|
+
inline long signl(long x) {return (0 < x) - (x < 0);}
|
|
11
|
+
inline double sign(double x){
|
|
12
|
+
// Floats: -1.0, 0.0, +1.0, NaN stays NaN
|
|
13
|
+
if (isnand(x)) {return NAN;}
|
|
14
|
+
if (x > 0) {return 1;}
|
|
15
|
+
if (x < 0) {return -1;}
|
|
16
|
+
return 0; // handles +0.0 and -0.0
|
|
17
|
+
}
|
|
18
|
+
inline float signf(float x){
|
|
19
|
+
// Floats: -1.0, 0.0, +1.0, NaN stays NaN
|
|
20
|
+
if (isnanf_(x)) {return NAN;}
|
|
21
|
+
if (x > 0) {return 1;}
|
|
22
|
+
if (x < 0) {return -1;}
|
|
23
|
+
return 0; // handles +0.0 and -0.0
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// round function for ints
|
|
27
|
+
inline int rinti(int x) {return x;}
|
|
28
|
+
inline long rintl(long x) {return x;}
|
|
29
|
+
// abs function for ints
|
|
30
|
+
inline int fabsi(int x) {return x<0 ? -x: x;}
|
|
31
|
+
inline long fabsl(long x) {return x<0 ? -x: x;}
|
|
32
|
+
// fmod function for ints
|
|
33
|
+
// TODO: Have to add FUNC_III, FUNC_LLL signatures to functions.hpp to enable these
|
|
34
|
+
// inline int fmodi(int x, int y) {return (int)fmodf((float)x, (float)y);}
|
|
35
|
+
// inline long fmodl(long x, long y) {return (long)fmodf((long)x, (long)y);}
|
|
36
|
+
|
|
37
|
+
#ifdef USE_VML
|
|
38
|
+
// To match Numpy behaviour for NaNs
|
|
39
|
+
static void vsFmax_(MKL_INT n, const float* x1, const float* x2, float* dest)
|
|
40
|
+
{
|
|
41
|
+
vsFmax(n, x1, x2, dest);
|
|
42
|
+
MKL_INT j;
|
|
43
|
+
for (j=0; j<n; j++) {
|
|
44
|
+
if (isnanf_(x1[j]) | isnanf_(x2[j])){
|
|
45
|
+
dest[j] = NAN;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
static void vsFmin_(MKL_INT n, const float* x1, const float* x2, float* dest)
|
|
51
|
+
{
|
|
52
|
+
vsFmin(n, x1, x2, dest);
|
|
53
|
+
MKL_INT j;
|
|
54
|
+
for (j=0; j<n; j++) {
|
|
55
|
+
if (isnanf_(x1[j]) | isnanf_(x2[j])){
|
|
56
|
+
dest[j] = NAN;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
// To match Numpy behaviour for NaNs
|
|
61
|
+
static void vdFmax_(MKL_INT n, const double* x1, const double* x2, double* dest)
|
|
62
|
+
{
|
|
63
|
+
vdFmax(n, x1, x2, dest);
|
|
64
|
+
MKL_INT j;
|
|
65
|
+
for (j=0; j<n; j++) {
|
|
66
|
+
if (isnand(x1[j]) | isnand(x2[j])){
|
|
67
|
+
dest[j] = NAN;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
static void vdFmin_(MKL_INT n, const double* x1, const double* x2, double* dest)
|
|
73
|
+
{
|
|
74
|
+
vdFmin(n, x1, x2, dest);
|
|
75
|
+
MKL_INT j;
|
|
76
|
+
for (j=0; j<n; j++) {
|
|
77
|
+
if (isnand(x1[j]) | isnand(x2[j])){
|
|
78
|
+
dest[j] = NAN;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
static void viRint(MKL_INT n, const int* x, int* dest)
|
|
84
|
+
{
|
|
85
|
+
memcpy(dest, x, n * sizeof(int)); // just copy x1 which is already int
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
static void vlRint(MKL_INT n, const long* x, long* dest)
|
|
89
|
+
{
|
|
90
|
+
memcpy(dest, x, n * sizeof(long)); // just copy x1 which is already int
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
static void viFabs(MKL_INT n, const int* x, int* dest)
|
|
94
|
+
{
|
|
95
|
+
MKL_INT j;
|
|
96
|
+
for (j=0; j<n; j++) {
|
|
97
|
+
dest[j] = x[j] < 0 ? -x[j]: x[j];
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
static void vlFabs(MKL_INT n, const long* x, long* dest)
|
|
102
|
+
{
|
|
103
|
+
MKL_INT j;
|
|
104
|
+
for (j=0; j<n; j++) {
|
|
105
|
+
dest[j] = x[j] < 0 ? -x[j]: x[j];
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/* Fake vsConj function just for casting purposes inside numexpr */
|
|
110
|
+
static void vsConj(MKL_INT n, const float* x1, float* dest)
|
|
111
|
+
{
|
|
112
|
+
MKL_INT j;
|
|
113
|
+
for (j=0; j<n; j++) {
|
|
114
|
+
dest[j] = x1[j];
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/* fmod not available in VML */
|
|
119
|
+
static void vsfmod(MKL_INT n, const float* x1, const float* x2, float* dest)
|
|
120
|
+
{
|
|
121
|
+
MKL_INT j;
|
|
122
|
+
for(j=0; j < n; j++) {
|
|
123
|
+
dest[j] = fmodf(x1[j], x2[j]);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
static void vdfmod(MKL_INT n, const double* x1, const double* x2, double* dest)
|
|
127
|
+
{
|
|
128
|
+
MKL_INT j;
|
|
129
|
+
for(j=0; j < n; j++) {
|
|
130
|
+
dest[j] = fmod(x1[j], x2[j]);
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
// TODO: Have to add FUNC_III, FUNC_LLL signatures to functions.hpp
|
|
134
|
+
// static void vifmod(MKL_INT n, const int* x1, const int* x2, int* dest)
|
|
135
|
+
// {
|
|
136
|
+
// MKL_INT j;
|
|
137
|
+
// for(j=0; j < n; j++) {
|
|
138
|
+
// dest[j] = fmodi(x1[j], x2[j]);
|
|
139
|
+
// };
|
|
140
|
+
// };
|
|
141
|
+
// static void vlfmod(MKL_INT n, const long* x1, const long* x2, long* dest)
|
|
142
|
+
// {
|
|
143
|
+
// MKL_INT j;
|
|
144
|
+
// for(j=0; j < n; j++) {
|
|
145
|
+
// dest[j] = fmodl(x1[j], x2[j]);
|
|
146
|
+
// };
|
|
147
|
+
// };
|
|
148
|
+
|
|
149
|
+
/* no isnan, isfinite, isinf or signbit in VML */
|
|
150
|
+
static void vsIsfinite(MKL_INT n, const float* x1, bool* dest)
|
|
151
|
+
{
|
|
152
|
+
MKL_INT j;
|
|
153
|
+
for (j=0; j<n; j++) {
|
|
154
|
+
dest[j] = isfinitef_(x1[j]);
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
static void vsIsinf(MKL_INT n, const float* x1, bool* dest)
|
|
158
|
+
{
|
|
159
|
+
MKL_INT j;
|
|
160
|
+
for (j=0; j<n; j++) {
|
|
161
|
+
dest[j] = isinff_(x1[j]);
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
static void vsIsnan(MKL_INT n, const float* x1, bool* dest)
|
|
165
|
+
{
|
|
166
|
+
MKL_INT j;
|
|
167
|
+
for (j=0; j<n; j++) {
|
|
168
|
+
dest[j] = isnanf_(x1[j]);
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
static void vsSignBit(MKL_INT n, const float* x1, bool* dest)
|
|
172
|
+
{
|
|
173
|
+
MKL_INT j;
|
|
174
|
+
for (j=0; j<n; j++) {
|
|
175
|
+
dest[j] = signbitf(x1[j]);
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/* no isnan, isfinite, isinf, signbit in VML */
|
|
180
|
+
static void vdIsfinite(MKL_INT n, const double* x1, bool* dest)
|
|
181
|
+
{
|
|
182
|
+
MKL_INT j;
|
|
183
|
+
for (j=0; j<n; j++) {
|
|
184
|
+
dest[j] = isfinited(x1[j]);
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
static void vdIsinf(MKL_INT n, const double* x1, bool* dest)
|
|
188
|
+
{
|
|
189
|
+
MKL_INT j;
|
|
190
|
+
for (j=0; j<n; j++) {
|
|
191
|
+
dest[j] = isinfd(x1[j]);
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
static void vdIsnan(MKL_INT n, const double* x1, bool* dest)
|
|
195
|
+
{
|
|
196
|
+
MKL_INT j;
|
|
197
|
+
for (j=0; j<n; j++) {
|
|
198
|
+
dest[j] = isnand(x1[j]);
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
static void vdSignBit(MKL_INT n, const double* x1, bool* dest)
|
|
202
|
+
{
|
|
203
|
+
MKL_INT j;
|
|
204
|
+
for (j=0; j<n; j++) {
|
|
205
|
+
dest[j] = signbit(x1[j]);
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/* no isnan, isfinite or isinf in VML */
|
|
210
|
+
static void vzIsfinite(MKL_INT n, const MKL_Complex16* x1, bool* dest)
|
|
211
|
+
{
|
|
212
|
+
MKL_INT j;
|
|
213
|
+
for (j=0; j<n; j++) {
|
|
214
|
+
dest[j] = isfinited(x1[j].real) && isfinited(x1[j].imag);
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
static void vzIsinf(MKL_INT n, const MKL_Complex16* x1, bool* dest)
|
|
218
|
+
{
|
|
219
|
+
MKL_INT j;
|
|
220
|
+
for (j=0; j<n; j++) {
|
|
221
|
+
dest[j] = isinfd(x1[j].real) || isinfd(x1[j].imag);
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
static void vzIsnan(MKL_INT n, const MKL_Complex16* x1, bool* dest)
|
|
225
|
+
{
|
|
226
|
+
MKL_INT j;
|
|
227
|
+
for (j=0; j<n; j++) {
|
|
228
|
+
dest[j] = isnand(x1[j].real) || isnand(x1[j].imag);
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
/* Fake vdConj function just for casting purposes inside numexpr */
|
|
233
|
+
static void vdConj(MKL_INT n, const double* x1, double* dest)
|
|
234
|
+
{
|
|
235
|
+
MKL_INT j;
|
|
236
|
+
for (j=0; j<n; j++) {
|
|
237
|
+
dest[j] = x1[j];
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/* various functions not available in VML */
|
|
242
|
+
static void vzExpm1(MKL_INT n, const MKL_Complex16* x1, MKL_Complex16* dest)
|
|
243
|
+
{
|
|
244
|
+
MKL_INT j;
|
|
245
|
+
vzExp(n, x1, dest);
|
|
246
|
+
for (j=0; j<n; j++) {
|
|
247
|
+
dest[j].real -= 1.0;
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
static void vzLog1p(MKL_INT n, const MKL_Complex16* x1, MKL_Complex16* dest)
|
|
252
|
+
{
|
|
253
|
+
MKL_INT j;
|
|
254
|
+
for (j=0; j<n; j++) {
|
|
255
|
+
dest[j].real = x1[j].real + 1;
|
|
256
|
+
dest[j].imag = x1[j].imag;
|
|
257
|
+
};
|
|
258
|
+
vzLn(n, dest, dest);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
static void vzLog2(MKL_INT n, const MKL_Complex16* x1, MKL_Complex16* dest)
|
|
262
|
+
{
|
|
263
|
+
MKL_INT j;
|
|
264
|
+
vzLn(n, x1, dest);
|
|
265
|
+
for (j=0; j<n; j++) {
|
|
266
|
+
dest[j].real = dest[j].real * M_LOG2_E;
|
|
267
|
+
dest[j].imag = dest[j].imag * M_LOG2_E;
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
static void vzRint(MKL_INT n, const MKL_Complex16* x1, MKL_Complex16* dest)
|
|
272
|
+
{
|
|
273
|
+
MKL_INT j;
|
|
274
|
+
for (j=0; j<n; j++) {
|
|
275
|
+
dest[j].real = rint(x1[j].real);
|
|
276
|
+
dest[j].imag = rint(x1[j].imag);
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/* Use this instead of native vzAbs in VML as it seems to work badly */
|
|
281
|
+
static void vzAbs_(MKL_INT n, const MKL_Complex16* x1, MKL_Complex16* dest)
|
|
282
|
+
{
|
|
283
|
+
MKL_INT j;
|
|
284
|
+
for (j=0; j<n; j++) {
|
|
285
|
+
dest[j].real = sqrt(x1[j].real*x1[j].real + x1[j].imag*x1[j].imag);
|
|
286
|
+
dest[j].imag = 0;
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/*sign functions*/
|
|
291
|
+
static void vsSign(MKL_INT n, const float* x1, float* dest)
|
|
292
|
+
{
|
|
293
|
+
MKL_INT j;
|
|
294
|
+
for(j=0; j < n; j++) {
|
|
295
|
+
dest[j] = signf(x1[j]);
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
static void vdSign(MKL_INT n, const double* x1, double* dest)
|
|
299
|
+
{
|
|
300
|
+
MKL_INT j;
|
|
301
|
+
for(j=0; j < n; j++) {
|
|
302
|
+
dest[j] = sign(x1[j]);
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
static void viSign(MKL_INT n, const int* x1, int* dest)
|
|
306
|
+
{
|
|
307
|
+
MKL_INT j;
|
|
308
|
+
for(j=0; j < n; j++) {
|
|
309
|
+
dest[j] = signi(x1[j]);
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
static void vlSign(MKL_INT n, const long* x1, long* dest)
|
|
313
|
+
{
|
|
314
|
+
MKL_INT j;
|
|
315
|
+
for(j=0; j < n; j++) {
|
|
316
|
+
dest[j] = signl(x1[j]);
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
static void vzSign(MKL_INT n, const MKL_Complex16* x1, MKL_Complex16* dest)
|
|
320
|
+
{
|
|
321
|
+
MKL_INT j;
|
|
322
|
+
double mag;
|
|
323
|
+
for(j=0; j < n; j++) {
|
|
324
|
+
mag = sqrt(x1[j].real*x1[j].real + x1[j].imag*x1[j].imag);
|
|
325
|
+
if (isnand(mag)) {
|
|
326
|
+
dest[j].real = NAN;
|
|
327
|
+
dest[j].imag = NAN;
|
|
328
|
+
}
|
|
329
|
+
else if (mag == 0) {
|
|
330
|
+
dest[j].real = 0;
|
|
331
|
+
dest[j].imag = 0;
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
dest[j].real = x1[j].real / mag;
|
|
335
|
+
dest[j].imag = x1[j].imag / mag;
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
#endif
|