numexpr 2.10.2__cp313-cp313-win_amd64.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/complex_functions.hpp +427 -0
- numexpr/cpuinfo.py +859 -0
- numexpr/expressions.py +523 -0
- numexpr/functions.hpp +140 -0
- numexpr/interp_body.cpp +543 -0
- numexpr/interpreter.cp313-win_amd64.pyd +0 -0
- numexpr/interpreter.cpp +1528 -0
- numexpr/interpreter.hpp +107 -0
- numexpr/missing_posix_functions.hpp +102 -0
- numexpr/module.cpp +537 -0
- numexpr/module.hpp +60 -0
- numexpr/msvc_function_stubs.hpp +150 -0
- numexpr/necompiler.py +1005 -0
- numexpr/numexpr_config.hpp +51 -0
- numexpr/numexpr_object.cpp +408 -0
- numexpr/numexpr_object.hpp +34 -0
- numexpr/opcodes.hpp +179 -0
- numexpr/str-two-way.hpp +435 -0
- numexpr/tests/__init__.py +14 -0
- numexpr/tests/test_numexpr.py +1421 -0
- numexpr/utils.py +309 -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.10.2.dist-info/AUTHORS.txt +31 -0
- numexpr-2.10.2.dist-info/LICENSE.txt +21 -0
- numexpr-2.10.2.dist-info/METADATA +214 -0
- numexpr-2.10.2.dist-info/RECORD +32 -0
- numexpr-2.10.2.dist-info/WHEEL +5 -0
- numexpr-2.10.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 MAX_THREADS, use_vml, __BLOCK_SIZE1__
|
|
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
|
+
|
|
35
|
+
from numexpr.utils import (_init_num_threads,
|
|
36
|
+
get_vml_version, set_vml_accuracy_mode, set_vml_num_threads,
|
|
37
|
+
set_num_threads, get_num_threads,
|
|
38
|
+
detect_number_of_cores, detect_number_of_threads)
|
|
39
|
+
|
|
40
|
+
# Detect the number of cores
|
|
41
|
+
ncores = detect_number_of_cores()
|
|
42
|
+
# Initialize the number of threads to be used
|
|
43
|
+
nthreads = _init_num_threads()
|
|
44
|
+
# The default for VML is 1 thread (see #39)
|
|
45
|
+
# set_vml_num_threads(1)
|
|
46
|
+
|
|
47
|
+
from . import version
|
|
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,427 @@
|
|
|
1
|
+
#ifndef NUMEXPR_COMPLEX_FUNCTIONS_HPP
|
|
2
|
+
#define NUMEXPR_COMPLEX_FUNCTIONS_HPP
|
|
3
|
+
|
|
4
|
+
/*********************************************************************
|
|
5
|
+
Numexpr - Fast numerical array expression evaluator for NumPy.
|
|
6
|
+
|
|
7
|
+
License: MIT
|
|
8
|
+
Author: See AUTHORS.txt
|
|
9
|
+
|
|
10
|
+
See LICENSE.txt for details about copyright and rights to use.
|
|
11
|
+
**********************************************************************/
|
|
12
|
+
|
|
13
|
+
// Replace npy_cdouble with std::complex<double>
|
|
14
|
+
#include <complex>
|
|
15
|
+
|
|
16
|
+
/* constants */
|
|
17
|
+
static std::complex<double> nc_1(1., 0.);
|
|
18
|
+
static std::complex<double> nc_half(0.5, 0.);
|
|
19
|
+
static std::complex<double> nc_i(0., 1.);
|
|
20
|
+
static std::complex<double> nc_i2(0., 0.5);
|
|
21
|
+
/*
|
|
22
|
+
static std::complex<double> nc_mi = {0., -1.};
|
|
23
|
+
static std::complex<double> nc_pi2 = {M_PI/2., 0.};
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/* *************************** WARNING *****************************
|
|
27
|
+
Due to the way Numexpr places the results of operations, the *x and *r
|
|
28
|
+
pointers do point to the same address (apparently this doesn't happen
|
|
29
|
+
in NumPy). So, measures should be taken so as to not to reuse *x
|
|
30
|
+
after the first *r has been overwritten.
|
|
31
|
+
*********************************************************************
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
static void
|
|
35
|
+
nc_assign(std::complex<double> *x, std::complex<double> *r)
|
|
36
|
+
{
|
|
37
|
+
r->real(x->real());
|
|
38
|
+
r->imag(x->imag());
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static void
|
|
43
|
+
nc_sum(std::complex<double> *a, std::complex<double> *b, std::complex<double> *r)
|
|
44
|
+
{
|
|
45
|
+
r->real(a->real() + b->real());
|
|
46
|
+
r->imag(a->imag() + b->imag());
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static void
|
|
51
|
+
nc_diff(std::complex<double> *a, std::complex<double> *b, std::complex<double> *r)
|
|
52
|
+
{
|
|
53
|
+
r->real(a->real() - b->real());
|
|
54
|
+
r->imag(a->imag() - b->imag());
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static void
|
|
59
|
+
nc_neg(std::complex<double> *a, std::complex<double> *r)
|
|
60
|
+
{
|
|
61
|
+
r->real(-a->real());
|
|
62
|
+
r->imag(-a->imag());
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static void
|
|
67
|
+
nc_conj(std::complex<double> *a, std::complex<double> *r)
|
|
68
|
+
{
|
|
69
|
+
r->real(a->real());
|
|
70
|
+
r->imag(-a->imag());
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Needed for allowing the internal casting in numexpr machinery for
|
|
75
|
+
// conjugate operations
|
|
76
|
+
inline float fconjf(float x)
|
|
77
|
+
{
|
|
78
|
+
return x;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Needed for allowing the internal casting in numexpr machinery for
|
|
82
|
+
// conjugate operations
|
|
83
|
+
inline double fconj(double x)
|
|
84
|
+
{
|
|
85
|
+
return x;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static void
|
|
89
|
+
nc_prod(std::complex<double> *a, std::complex<double> *b, std::complex<double> *r)
|
|
90
|
+
{
|
|
91
|
+
double ar=a->real(), br=b->real(), ai=a->imag(), bi=b->imag();
|
|
92
|
+
r->real(ar*br - ai*bi);
|
|
93
|
+
r->imag(ar*bi + ai*br);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static void
|
|
98
|
+
nc_quot(std::complex<double> *a, std::complex<double> *b, std::complex<double> *r)
|
|
99
|
+
{
|
|
100
|
+
double ar=a->real(), br=b->real(), ai=a->imag(), bi=b->imag();
|
|
101
|
+
double d = br*br + bi*bi;
|
|
102
|
+
r->real((ar*br + ai*bi)/d);
|
|
103
|
+
r->imag((ai*br - ar*bi)/d);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static void
|
|
108
|
+
nc_sqrt(std::complex<double> *x, std::complex<double> *r)
|
|
109
|
+
{
|
|
110
|
+
double s,d;
|
|
111
|
+
if (x->real() == 0. && x->imag() == 0.)
|
|
112
|
+
*r = *x;
|
|
113
|
+
else {
|
|
114
|
+
s = sqrt((fabs(x->real()) + hypot(x->real(),x->imag()))/2);
|
|
115
|
+
d = x->imag()/(2*s);
|
|
116
|
+
if (x->real() > 0.) {
|
|
117
|
+
r->real(s);
|
|
118
|
+
r->imag(d);
|
|
119
|
+
}
|
|
120
|
+
else if (x->imag() >= 0.) {
|
|
121
|
+
r->real(d);
|
|
122
|
+
r->imag(s);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
r->real(-d);
|
|
126
|
+
r->imag(-s);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static void
|
|
133
|
+
nc_log(std::complex<double> *x, std::complex<double> *r)
|
|
134
|
+
{
|
|
135
|
+
double l = hypot(x->real(),x->imag());
|
|
136
|
+
r->imag(atan2(x->imag(), x->real()));
|
|
137
|
+
r->real(log(l));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static void
|
|
142
|
+
nc_log1p(std::complex<double> *x, std::complex<double> *r)
|
|
143
|
+
{
|
|
144
|
+
double l = hypot(x->real() + 1.0,x->imag());
|
|
145
|
+
r->imag(atan2(x->imag(), x->real() + 1.0));
|
|
146
|
+
r->real(log(l));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static void
|
|
151
|
+
nc_exp(std::complex<double> *x, std::complex<double> *r)
|
|
152
|
+
{
|
|
153
|
+
double a = exp(x->real());
|
|
154
|
+
r->real(a*cos(x->imag()));
|
|
155
|
+
r->imag(a*sin(x->imag()));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static void
|
|
160
|
+
nc_expm1(std::complex<double> *x, std::complex<double> *r)
|
|
161
|
+
{
|
|
162
|
+
double a = sin(x->imag() / 2);
|
|
163
|
+
double b = exp(x->real());
|
|
164
|
+
r->real(expm1(x->real()) * cos(x->imag()) - 2 * a * a);
|
|
165
|
+
r->imag(b * sin(x->imag()));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static void
|
|
170
|
+
nc_pow(std::complex<double> *a, std::complex<double> *b, std::complex<double> *r)
|
|
171
|
+
{
|
|
172
|
+
npy_intp n;
|
|
173
|
+
double ar=a->real(), br=b->real(), ai=a->imag(), bi=b->imag();
|
|
174
|
+
|
|
175
|
+
if (br == 0. && bi == 0.) {
|
|
176
|
+
r->real(1.);
|
|
177
|
+
r->imag(0.);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (ar == 0. && ai == 0.) {
|
|
181
|
+
r->real(0.);
|
|
182
|
+
r->imag(0.);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (bi == 0 && (n=(npy_intp)br) == br) {
|
|
186
|
+
if (n > -100 && n < 100) {
|
|
187
|
+
std::complex<double> p, aa;
|
|
188
|
+
npy_intp mask = 1;
|
|
189
|
+
if (n < 0) n = -n;
|
|
190
|
+
aa = nc_1;
|
|
191
|
+
p.real(ar); p.imag(ai);
|
|
192
|
+
while (1) {
|
|
193
|
+
if (n & mask)
|
|
194
|
+
nc_prod(&aa,&p,&aa);
|
|
195
|
+
mask <<= 1;
|
|
196
|
+
if (n < mask || mask <= 0) break;
|
|
197
|
+
nc_prod(&p,&p,&p);
|
|
198
|
+
}
|
|
199
|
+
r->real(aa.real()); r->imag(aa.imag());
|
|
200
|
+
if (br < 0) nc_quot(&nc_1, r, r);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/* complexobject.c uses an inline version of this formula
|
|
205
|
+
investigate whether this had better performance or accuracy */
|
|
206
|
+
nc_log(a, r);
|
|
207
|
+
nc_prod(r, b, r);
|
|
208
|
+
nc_exp(r, r);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
static void
|
|
214
|
+
nc_prodi(std::complex<double> *x, std::complex<double> *r)
|
|
215
|
+
{
|
|
216
|
+
double xr = x->real();
|
|
217
|
+
r->real(-x->imag());
|
|
218
|
+
r->imag(xr);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
static void
|
|
224
|
+
nc_acos(std::complex<double> *x, std::complex<double> *r)
|
|
225
|
+
{
|
|
226
|
+
std::complex<double> a, *pa=&a;
|
|
227
|
+
|
|
228
|
+
nc_assign(x, pa);
|
|
229
|
+
nc_prod(x,x,r);
|
|
230
|
+
nc_diff(&nc_1, r, r);
|
|
231
|
+
nc_sqrt(r, r);
|
|
232
|
+
nc_prodi(r, r);
|
|
233
|
+
nc_sum(pa, r, r);
|
|
234
|
+
nc_log(r, r);
|
|
235
|
+
nc_prodi(r, r);
|
|
236
|
+
nc_neg(r, r);
|
|
237
|
+
return;
|
|
238
|
+
/* return nc_neg(nc_prodi(nc_log(nc_sum(x,nc_prod(nc_i,
|
|
239
|
+
nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))))));
|
|
240
|
+
*/
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
static void
|
|
244
|
+
nc_acosh(std::complex<double> *x, std::complex<double> *r)
|
|
245
|
+
{
|
|
246
|
+
std::complex<double> t, a, *pa=&a;
|
|
247
|
+
|
|
248
|
+
nc_assign(x, pa);
|
|
249
|
+
nc_sum(x, &nc_1, &t);
|
|
250
|
+
nc_sqrt(&t, &t);
|
|
251
|
+
nc_diff(x, &nc_1, r);
|
|
252
|
+
nc_sqrt(r, r);
|
|
253
|
+
nc_prod(&t, r, r);
|
|
254
|
+
nc_sum(pa, r, r);
|
|
255
|
+
nc_log(r, r);
|
|
256
|
+
return;
|
|
257
|
+
/*
|
|
258
|
+
return nc_log(nc_sum(x,
|
|
259
|
+
nc_prod(nc_sqrt(nc_sum(x,nc_1)), nc_sqrt(nc_diff(x,nc_1)))));
|
|
260
|
+
*/
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
static void
|
|
264
|
+
nc_asin(std::complex<double> *x, std::complex<double> *r)
|
|
265
|
+
{
|
|
266
|
+
std::complex<double> a, *pa=&a;
|
|
267
|
+
nc_prodi(x, pa);
|
|
268
|
+
nc_prod(x, x, r);
|
|
269
|
+
nc_diff(&nc_1, r, r);
|
|
270
|
+
nc_sqrt(r, r);
|
|
271
|
+
nc_sum(pa, r, r);
|
|
272
|
+
nc_log(r, r);
|
|
273
|
+
nc_prodi(r, r);
|
|
274
|
+
nc_neg(r, r);
|
|
275
|
+
return;
|
|
276
|
+
/*
|
|
277
|
+
return nc_neg(nc_prodi(nc_log(nc_sum(nc_prod(nc_i,x),
|
|
278
|
+
nc_sqrt(nc_diff(nc_1,nc_prod(x,x)))))));
|
|
279
|
+
*/
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
static void
|
|
284
|
+
nc_asinh(std::complex<double> *x, std::complex<double> *r)
|
|
285
|
+
{
|
|
286
|
+
std::complex<double> a, *pa=&a;
|
|
287
|
+
nc_assign(x, pa);
|
|
288
|
+
nc_prod(x, x, r);
|
|
289
|
+
nc_sum(&nc_1, r, r);
|
|
290
|
+
nc_sqrt(r, r);
|
|
291
|
+
nc_sum(r, pa, r);
|
|
292
|
+
nc_log(r, r);
|
|
293
|
+
return;
|
|
294
|
+
/*
|
|
295
|
+
return nc_log(nc_sum(nc_sqrt(nc_sum(nc_1,nc_prod(x,x))),x));
|
|
296
|
+
*/
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
static void
|
|
300
|
+
nc_atan(std::complex<double> *x, std::complex<double> *r)
|
|
301
|
+
{
|
|
302
|
+
std::complex<double> a, *pa=&a;
|
|
303
|
+
nc_diff(&nc_i, x, pa);
|
|
304
|
+
nc_sum(&nc_i, x, r);
|
|
305
|
+
nc_quot(r, pa, r);
|
|
306
|
+
nc_log(r,r);
|
|
307
|
+
nc_prod(&nc_i2, r, r);
|
|
308
|
+
return;
|
|
309
|
+
/*
|
|
310
|
+
return nc_prod(nc_i2,nc_log(nc_quot(nc_sum(nc_i,x),nc_diff(nc_i,x))));
|
|
311
|
+
*/
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
static void
|
|
315
|
+
nc_atanh(std::complex<double> *x, std::complex<double> *r)
|
|
316
|
+
{
|
|
317
|
+
std::complex<double> a, b, *pa=&a, *pb=&b;
|
|
318
|
+
nc_assign(x, pa);
|
|
319
|
+
nc_diff(&nc_1, pa, r);
|
|
320
|
+
nc_sum(&nc_1, pa, pb);
|
|
321
|
+
nc_quot(pb, r, r);
|
|
322
|
+
nc_log(r, r);
|
|
323
|
+
nc_prod(&nc_half, r, r);
|
|
324
|
+
return;
|
|
325
|
+
/*
|
|
326
|
+
return nc_prod(nc_half,nc_log(nc_quot(nc_sum(nc_1,x),nc_diff(nc_1,x))));
|
|
327
|
+
*/
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
static void
|
|
331
|
+
nc_cos(std::complex<double> *x, std::complex<double> *r)
|
|
332
|
+
{
|
|
333
|
+
double xr=x->real(), xi=x->imag();
|
|
334
|
+
r->real(cos(xr)*cosh(xi));
|
|
335
|
+
r->imag(-sin(xr)*sinh(xi));
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
static void
|
|
340
|
+
nc_cosh(std::complex<double> *x, std::complex<double> *r)
|
|
341
|
+
{
|
|
342
|
+
double xr=x->real(), xi=x->imag();
|
|
343
|
+
r->real(cos(xi)*cosh(xr));
|
|
344
|
+
r->imag(sin(xi)*sinh(xr));
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
#define M_LOG10_E 0.434294481903251827651128918916605082294397
|
|
350
|
+
|
|
351
|
+
static void
|
|
352
|
+
nc_log10(std::complex<double> *x, std::complex<double> *r)
|
|
353
|
+
{
|
|
354
|
+
nc_log(x, r);
|
|
355
|
+
r->real(r->real() * M_LOG10_E);
|
|
356
|
+
r->imag(r->imag() * M_LOG10_E);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
static void
|
|
361
|
+
nc_sin(std::complex<double> *x, std::complex<double> *r)
|
|
362
|
+
{
|
|
363
|
+
double xr=x->real(), xi=x->imag();
|
|
364
|
+
r->real(sin(xr)*cosh(xi));
|
|
365
|
+
r->imag(cos(xr)*sinh(xi));
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
static void
|
|
370
|
+
nc_sinh(std::complex<double> *x, std::complex<double> *r)
|
|
371
|
+
{
|
|
372
|
+
double xr=x->real(), xi=x->imag();
|
|
373
|
+
r->real(cos(xi)*sinh(xr));
|
|
374
|
+
r->imag(sin(xi)*cosh(xr));
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
static void
|
|
379
|
+
nc_tan(std::complex<double> *x, std::complex<double> *r)
|
|
380
|
+
{
|
|
381
|
+
double sr,cr,shi,chi;
|
|
382
|
+
double rs,is,rc,ic;
|
|
383
|
+
double d;
|
|
384
|
+
double xr=x->real(), xi=x->imag();
|
|
385
|
+
sr = sin(xr);
|
|
386
|
+
cr = cos(xr);
|
|
387
|
+
shi = sinh(xi);
|
|
388
|
+
chi = cosh(xi);
|
|
389
|
+
rs = sr*chi;
|
|
390
|
+
is = cr*shi;
|
|
391
|
+
rc = cr*chi;
|
|
392
|
+
ic = -sr*shi;
|
|
393
|
+
d = rc*rc + ic*ic;
|
|
394
|
+
r->real((rs*rc+is*ic)/d);
|
|
395
|
+
r->imag((is*rc-rs*ic)/d);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
static void
|
|
400
|
+
nc_tanh(std::complex<double> *x, std::complex<double> *r)
|
|
401
|
+
{
|
|
402
|
+
double si,ci,shr,chr;
|
|
403
|
+
double rs,is,rc,ic;
|
|
404
|
+
double d;
|
|
405
|
+
double xr=x->real(), xi=x->imag();
|
|
406
|
+
si = sin(xi);
|
|
407
|
+
ci = cos(xi);
|
|
408
|
+
shr = sinh(xr);
|
|
409
|
+
chr = cosh(xr);
|
|
410
|
+
rs = ci*shr;
|
|
411
|
+
is = si*chr;
|
|
412
|
+
rc = ci*chr;
|
|
413
|
+
ic = si*shr;
|
|
414
|
+
d = rc*rc + ic*ic;
|
|
415
|
+
r->real((rs*rc+is*ic)/d);
|
|
416
|
+
r->imag((is*rc-rs*ic)/d);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
static void
|
|
421
|
+
nc_abs(std::complex<double> *x, std::complex<double> *r)
|
|
422
|
+
{
|
|
423
|
+
r->real(sqrt(x->real()*x->real() + x->imag()*x->imag()));
|
|
424
|
+
r->imag(0);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
#endif // NUMEXPR_COMPLEX_FUNCTIONS_HPP
|