1 /* Generated by Cython 0.29.23 */
2
3 /* BEGIN: Cython Metadata
4 {
5 "distutils": {
6 "depends": [],
7 "extra_compile_args": [
8 "-w",
9 "-O3",
10 "-funroll-loops"
11 ],
12 "include_dirs": [
13 "/tmp/build-env-hoit1hud/lib/python3.6/site-packages/numpy/core/include"
14 ],
15 "language": "c++",
16 "name": "qutip.cy.math",
17 "sources": [
18 "qutip/cy/math.pyx"
19 ]
20 },
21 "module_name": "qutip.cy.math"
22 }
23 END: Cython Metadata */
24
25 #ifndef PY_SSIZE_T_CLEAN
26 #define PY_SSIZE_T_CLEAN
27 #endif /* PY_SSIZE_T_CLEAN */
28 #include "Python.h"
29 #ifndef Py_PYTHON_H
30 #error Python headers needed to compile C extensions, please install development version of Python.
31 #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
32 #error Cython requires Python 2.6+ or Python 3.3+.
33 #else
34 #define CYTHON_ABI "0_29_23"
35 #define CYTHON_HEX_VERSION 0x001D17F0
36 #define CYTHON_FUTURE_DIVISION 1
37 #include <stddef.h>
38 #ifndef offsetof
39 #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
40 #endif
41 #if !defined(WIN32) && !defined(MS_WINDOWS)
42 #ifndef __stdcall
43 #define __stdcall
44 #endif
45 #ifndef __cdecl
46 #define __cdecl
47 #endif
48 #ifndef __fastcall
49 #define __fastcall
50 #endif
51 #endif
52 #ifndef DL_IMPORT
53 #define DL_IMPORT(t) t
54 #endif
55 #ifndef DL_EXPORT
56 #define DL_EXPORT(t) t
57 #endif
58 #define __PYX_COMMA ,
59 #ifndef HAVE_LONG_LONG
60 #if PY_VERSION_HEX >= 0x02070000
61 #define HAVE_LONG_LONG
62 #endif
63 #endif
64 #ifndef PY_LONG_LONG
65 #define PY_LONG_LONG LONG_LONG
66 #endif
67 #ifndef Py_HUGE_VAL
68 #define Py_HUGE_VAL HUGE_VAL
69 #endif
70 #ifdef PYPY_VERSION
71 #define CYTHON_COMPILING_IN_PYPY 1
72 #define CYTHON_COMPILING_IN_PYSTON 0
73 #define CYTHON_COMPILING_IN_CPYTHON 0
74 #undef CYTHON_USE_TYPE_SLOTS
75 #define CYTHON_USE_TYPE_SLOTS 0
76 #undef CYTHON_USE_PYTYPE_LOOKUP
77 #define CYTHON_USE_PYTYPE_LOOKUP 0
78 #if PY_VERSION_HEX < 0x03050000
79 #undef CYTHON_USE_ASYNC_SLOTS
80 #define CYTHON_USE_ASYNC_SLOTS 0
81 #elif !defined(CYTHON_USE_ASYNC_SLOTS)
82 #define CYTHON_USE_ASYNC_SLOTS 1
83 #endif
84 #undef CYTHON_USE_PYLIST_INTERNALS
85 #define CYTHON_USE_PYLIST_INTERNALS 0
86 #undef CYTHON_USE_UNICODE_INTERNALS
87 #define CYTHON_USE_UNICODE_INTERNALS 0
88 #undef CYTHON_USE_UNICODE_WRITER
89 #define CYTHON_USE_UNICODE_WRITER 0
90 #undef CYTHON_USE_PYLONG_INTERNALS
91 #define CYTHON_USE_PYLONG_INTERNALS 0
92 #undef CYTHON_AVOID_BORROWED_REFS
93 #define CYTHON_AVOID_BORROWED_REFS 1
94 #undef CYTHON_ASSUME_SAFE_MACROS
95 #define CYTHON_ASSUME_SAFE_MACROS 0
96 #undef CYTHON_UNPACK_METHODS
97 #define CYTHON_UNPACK_METHODS 0
98 #undef CYTHON_FAST_THREAD_STATE
99 #define CYTHON_FAST_THREAD_STATE 0
100 #undef CYTHON_FAST_PYCALL
101 #define CYTHON_FAST_PYCALL 0
102 #undef CYTHON_PEP489_MULTI_PHASE_INIT
103 #define CYTHON_PEP489_MULTI_PHASE_INIT 0
104 #undef CYTHON_USE_TP_FINALIZE
105 #define CYTHON_USE_TP_FINALIZE 0
106 #undef CYTHON_USE_DICT_VERSIONS
107 #define CYTHON_USE_DICT_VERSIONS 0
108 #undef CYTHON_USE_EXC_INFO_STACK
109 #define CYTHON_USE_EXC_INFO_STACK 0
110 #elif defined(PYSTON_VERSION)
111 #define CYTHON_COMPILING_IN_PYPY 0
112 #define CYTHON_COMPILING_IN_PYSTON 1
113 #define CYTHON_COMPILING_IN_CPYTHON 0
114 #ifndef CYTHON_USE_TYPE_SLOTS
115 #define CYTHON_USE_TYPE_SLOTS 1
116 #endif
117 #undef CYTHON_USE_PYTYPE_LOOKUP
118 #define CYTHON_USE_PYTYPE_LOOKUP 0
119 #undef CYTHON_USE_ASYNC_SLOTS
120 #define CYTHON_USE_ASYNC_SLOTS 0
121 #undef CYTHON_USE_PYLIST_INTERNALS
122 #define CYTHON_USE_PYLIST_INTERNALS 0
123 #ifndef CYTHON_USE_UNICODE_INTERNALS
124 #define CYTHON_USE_UNICODE_INTERNALS 1
125 #endif
126 #undef CYTHON_USE_UNICODE_WRITER
127 #define CYTHON_USE_UNICODE_WRITER 0
128 #undef CYTHON_USE_PYLONG_INTERNALS
129 #define CYTHON_USE_PYLONG_INTERNALS 0
130 #ifndef CYTHON_AVOID_BORROWED_REFS
131 #define CYTHON_AVOID_BORROWED_REFS 0
132 #endif
133 #ifndef CYTHON_ASSUME_SAFE_MACROS
134 #define CYTHON_ASSUME_SAFE_MACROS 1
135 #endif
136 #ifndef CYTHON_UNPACK_METHODS
137 #define CYTHON_UNPACK_METHODS 1
138 #endif
139 #undef CYTHON_FAST_THREAD_STATE
140 #define CYTHON_FAST_THREAD_STATE 0
141 #undef CYTHON_FAST_PYCALL
142 #define CYTHON_FAST_PYCALL 0
143 #undef CYTHON_PEP489_MULTI_PHASE_INIT
144 #define CYTHON_PEP489_MULTI_PHASE_INIT 0
145 #undef CYTHON_USE_TP_FINALIZE
146 #define CYTHON_USE_TP_FINALIZE 0
147 #undef CYTHON_USE_DICT_VERSIONS
148 #define CYTHON_USE_DICT_VERSIONS 0
149 #undef CYTHON_USE_EXC_INFO_STACK
150 #define CYTHON_USE_EXC_INFO_STACK 0
151 #else
152 #define CYTHON_COMPILING_IN_PYPY 0
153 #define CYTHON_COMPILING_IN_PYSTON 0
154 #define CYTHON_COMPILING_IN_CPYTHON 1
155 #ifndef CYTHON_USE_TYPE_SLOTS
156 #define CYTHON_USE_TYPE_SLOTS 1
157 #endif
158 #if PY_VERSION_HEX < 0x02070000
159 #undef CYTHON_USE_PYTYPE_LOOKUP
160 #define CYTHON_USE_PYTYPE_LOOKUP 0
161 #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
162 #define CYTHON_USE_PYTYPE_LOOKUP 1
163 #endif
164 #if PY_MAJOR_VERSION < 3
165 #undef CYTHON_USE_ASYNC_SLOTS
166 #define CYTHON_USE_ASYNC_SLOTS 0
167 #elif !defined(CYTHON_USE_ASYNC_SLOTS)
168 #define CYTHON_USE_ASYNC_SLOTS 1
169 #endif
170 #if PY_VERSION_HEX < 0x02070000
171 #undef CYTHON_USE_PYLONG_INTERNALS
172 #define CYTHON_USE_PYLONG_INTERNALS 0
173 #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
174 #define CYTHON_USE_PYLONG_INTERNALS 1
175 #endif
176 #ifndef CYTHON_USE_PYLIST_INTERNALS
177 #define CYTHON_USE_PYLIST_INTERNALS 1
178 #endif
179 #ifndef CYTHON_USE_UNICODE_INTERNALS
180 #define CYTHON_USE_UNICODE_INTERNALS 1
181 #endif
182 #if PY_VERSION_HEX < 0x030300F0
183 #undef CYTHON_USE_UNICODE_WRITER
184 #define CYTHON_USE_UNICODE_WRITER 0
185 #elif !defined(CYTHON_USE_UNICODE_WRITER)
186 #define CYTHON_USE_UNICODE_WRITER 1
187 #endif
188 #ifndef CYTHON_AVOID_BORROWED_REFS
189 #define CYTHON_AVOID_BORROWED_REFS 0
190 #endif
191 #ifndef CYTHON_ASSUME_SAFE_MACROS
192 #define CYTHON_ASSUME_SAFE_MACROS 1
193 #endif
194 #ifndef CYTHON_UNPACK_METHODS
195 #define CYTHON_UNPACK_METHODS 1
196 #endif
197 #ifndef CYTHON_FAST_THREAD_STATE
198 #define CYTHON_FAST_THREAD_STATE 1
199 #endif
200 #ifndef CYTHON_FAST_PYCALL
201 #define CYTHON_FAST_PYCALL 1
202 #endif
203 #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
204 #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
205 #endif
206 #ifndef CYTHON_USE_TP_FINALIZE
207 #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
208 #endif
209 #ifndef CYTHON_USE_DICT_VERSIONS
210 #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1)
211 #endif
212 #ifndef CYTHON_USE_EXC_INFO_STACK
213 #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
214 #endif
215 #endif
216 #if !defined(CYTHON_FAST_PYCCALL)
217 #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
218 #endif
219 #if CYTHON_USE_PYLONG_INTERNALS
220 #include "longintrepr.h"
221 #undef SHIFT
222 #undef BASE
223 #undef MASK
224 #ifdef SIZEOF_VOID_P
225 enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
226 #endif
227 #endif
228 #ifndef __has_attribute
229 #define __has_attribute(x) 0
230 #endif
231 #ifndef __has_cpp_attribute
232 #define __has_cpp_attribute(x) 0
233 #endif
234 #ifndef CYTHON_RESTRICT
235 #if defined(__GNUC__)
236 #define CYTHON_RESTRICT __restrict__
237 #elif defined(_MSC_VER) && _MSC_VER >= 1400
238 #define CYTHON_RESTRICT __restrict
239 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
240 #define CYTHON_RESTRICT restrict
241 #else
242 #define CYTHON_RESTRICT
243 #endif
244 #endif
245 #ifndef CYTHON_UNUSED
246 # if defined(__GNUC__)
247 # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
248 # define CYTHON_UNUSED __attribute__ ((__unused__))
249 # else
250 # define CYTHON_UNUSED
251 # endif
252 # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
253 # define CYTHON_UNUSED __attribute__ ((__unused__))
254 # else
255 # define CYTHON_UNUSED
256 # endif
257 #endif
258 #ifndef CYTHON_MAYBE_UNUSED_VAR
259 # if defined(__cplusplus)
CYTHON_MAYBE_UNUSED_VAR(const T &)260 template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
261 # else
262 # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
263 # endif
264 #endif
265 #ifndef CYTHON_NCP_UNUSED
266 # if CYTHON_COMPILING_IN_CPYTHON
267 # define CYTHON_NCP_UNUSED
268 # else
269 # define CYTHON_NCP_UNUSED CYTHON_UNUSED
270 # endif
271 #endif
272 #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
273 #ifdef _MSC_VER
274 #ifndef _MSC_STDINT_H_
275 #if _MSC_VER < 1300
276 typedef unsigned char uint8_t;
277 typedef unsigned int uint32_t;
278 #else
279 typedef unsigned __int8 uint8_t;
280 typedef unsigned __int32 uint32_t;
281 #endif
282 #endif
283 #else
284 #include <stdint.h>
285 #endif
286 #ifndef CYTHON_FALLTHROUGH
287 #if defined(__cplusplus) && __cplusplus >= 201103L
288 #if __has_cpp_attribute(fallthrough)
289 #define CYTHON_FALLTHROUGH [[fallthrough]]
290 #elif __has_cpp_attribute(clang::fallthrough)
291 #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
292 #elif __has_cpp_attribute(gnu::fallthrough)
293 #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
294 #endif
295 #endif
296 #ifndef CYTHON_FALLTHROUGH
297 #if __has_attribute(fallthrough)
298 #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
299 #else
300 #define CYTHON_FALLTHROUGH
301 #endif
302 #endif
303 #if defined(__clang__ ) && defined(__apple_build_version__)
304 #if __apple_build_version__ < 7000000
305 #undef CYTHON_FALLTHROUGH
306 #define CYTHON_FALLTHROUGH
307 #endif
308 #endif
309 #endif
310
311 #ifndef __cplusplus
312 #error "Cython files generated with the C++ option must be compiled with a C++ compiler."
313 #endif
314 #ifndef CYTHON_INLINE
315 #if defined(__clang__)
316 #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
317 #else
318 #define CYTHON_INLINE inline
319 #endif
320 #endif
321 template<typename T>
__Pyx_call_destructor(T & x)322 void __Pyx_call_destructor(T& x) {
323 x.~T();
324 }
325 template<typename T>
326 class __Pyx_FakeReference {
327 public:
__Pyx_FakeReference()328 __Pyx_FakeReference() : ptr(NULL) { }
__Pyx_FakeReference(const T & ref)329 __Pyx_FakeReference(const T& ref) : ptr(const_cast<T*>(&ref)) { }
operator ->()330 T *operator->() { return ptr; }
operator &()331 T *operator&() { return ptr; }
operator T&()332 operator T&() { return *ptr; }
operator ==(U other)333 template<typename U> bool operator ==(U other) { return *ptr == other; }
operator !=(U other)334 template<typename U> bool operator !=(U other) { return *ptr != other; }
335 private:
336 T *ptr;
337 };
338
339 #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
340 #define Py_OptimizeFlag 0
341 #endif
342 #define __PYX_BUILD_PY_SSIZE_T "n"
343 #define CYTHON_FORMAT_SSIZE_T "z"
344 #if PY_MAJOR_VERSION < 3
345 #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
346 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
347 PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
348 #define __Pyx_DefaultClassType PyClass_Type
349 #else
350 #define __Pyx_BUILTIN_MODULE_NAME "builtins"
351 #if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2
352 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
353 PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
354 #else
355 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
356 PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
357 #endif
358 #define __Pyx_DefaultClassType PyType_Type
359 #endif
360 #ifndef Py_TPFLAGS_CHECKTYPES
361 #define Py_TPFLAGS_CHECKTYPES 0
362 #endif
363 #ifndef Py_TPFLAGS_HAVE_INDEX
364 #define Py_TPFLAGS_HAVE_INDEX 0
365 #endif
366 #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
367 #define Py_TPFLAGS_HAVE_NEWBUFFER 0
368 #endif
369 #ifndef Py_TPFLAGS_HAVE_FINALIZE
370 #define Py_TPFLAGS_HAVE_FINALIZE 0
371 #endif
372 #ifndef METH_STACKLESS
373 #define METH_STACKLESS 0
374 #endif
375 #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
376 #ifndef METH_FASTCALL
377 #define METH_FASTCALL 0x80
378 #endif
379 typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
380 typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
381 Py_ssize_t nargs, PyObject *kwnames);
382 #else
383 #define __Pyx_PyCFunctionFast _PyCFunctionFast
384 #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
385 #endif
386 #if CYTHON_FAST_PYCCALL
387 #define __Pyx_PyFastCFunction_Check(func)\
388 ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)))))
389 #else
390 #define __Pyx_PyFastCFunction_Check(func) 0
391 #endif
392 #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
393 #define PyObject_Malloc(s) PyMem_Malloc(s)
394 #define PyObject_Free(p) PyMem_Free(p)
395 #define PyObject_Realloc(p) PyMem_Realloc(p)
396 #endif
397 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
398 #define PyMem_RawMalloc(n) PyMem_Malloc(n)
399 #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n)
400 #define PyMem_RawFree(p) PyMem_Free(p)
401 #endif
402 #if CYTHON_COMPILING_IN_PYSTON
403 #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)
404 #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
405 #else
406 #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0)
407 #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
408 #endif
409 #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
410 #define __Pyx_PyThreadState_Current PyThreadState_GET()
411 #elif PY_VERSION_HEX >= 0x03060000
412 #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
413 #elif PY_VERSION_HEX >= 0x03000000
414 #define __Pyx_PyThreadState_Current PyThreadState_GET()
415 #else
416 #define __Pyx_PyThreadState_Current _PyThreadState_Current
417 #endif
418 #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
419 #include "pythread.h"
420 #define Py_tss_NEEDS_INIT 0
421 typedef int Py_tss_t;
PyThread_tss_create(Py_tss_t * key)422 static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
423 *key = PyThread_create_key();
424 return 0;
425 }
PyThread_tss_alloc(void)426 static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
427 Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
428 *key = Py_tss_NEEDS_INIT;
429 return key;
430 }
PyThread_tss_free(Py_tss_t * key)431 static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
432 PyObject_Free(key);
433 }
PyThread_tss_is_created(Py_tss_t * key)434 static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
435 return *key != Py_tss_NEEDS_INIT;
436 }
PyThread_tss_delete(Py_tss_t * key)437 static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
438 PyThread_delete_key(*key);
439 *key = Py_tss_NEEDS_INIT;
440 }
PyThread_tss_set(Py_tss_t * key,void * value)441 static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
442 return PyThread_set_key_value(*key, value);
443 }
PyThread_tss_get(Py_tss_t * key)444 static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
445 return PyThread_get_key_value(*key);
446 }
447 #endif
448 #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
449 #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
450 #else
451 #define __Pyx_PyDict_NewPresized(n) PyDict_New()
452 #endif
453 #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
454 #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
455 #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
456 #else
457 #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
458 #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
459 #endif
460 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
461 #define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
462 #else
463 #define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name)
464 #endif
465 #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
466 #define CYTHON_PEP393_ENABLED 1
467 #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\
468 0 : _PyUnicode_Ready((PyObject *)(op)))
469 #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
470 #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
471 #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u)
472 #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
473 #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
474 #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
475 #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch)
476 #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
477 #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
478 #else
479 #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u))
480 #endif
481 #else
482 #define CYTHON_PEP393_ENABLED 0
483 #define PyUnicode_1BYTE_KIND 1
484 #define PyUnicode_2BYTE_KIND 2
485 #define PyUnicode_4BYTE_KIND 4
486 #define __Pyx_PyUnicode_READY(op) (0)
487 #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
488 #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
489 #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
490 #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE))
491 #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
492 #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
493 #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
494 #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u))
495 #endif
496 #if CYTHON_COMPILING_IN_PYPY
497 #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b)
498 #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b)
499 #else
500 #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b)
501 #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
502 PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
503 #endif
504 #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
505 #define PyUnicode_Contains(u, s) PySequence_Contains(u, s)
506 #endif
507 #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
508 #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type)
509 #endif
510 #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
511 #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
512 #endif
513 #define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
514 #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
515 #if PY_MAJOR_VERSION >= 3
516 #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b)
517 #else
518 #define __Pyx_PyString_Format(a, b) PyString_Format(a, b)
519 #endif
520 #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
521 #define PyObject_ASCII(o) PyObject_Repr(o)
522 #endif
523 #if PY_MAJOR_VERSION >= 3
524 #define PyBaseString_Type PyUnicode_Type
525 #define PyStringObject PyUnicodeObject
526 #define PyString_Type PyUnicode_Type
527 #define PyString_Check PyUnicode_Check
528 #define PyString_CheckExact PyUnicode_CheckExact
529 #ifndef PyObject_Unicode
530 #define PyObject_Unicode PyObject_Str
531 #endif
532 #endif
533 #if PY_MAJOR_VERSION >= 3
534 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
535 #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
536 #else
537 #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
538 #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
539 #endif
540 #ifndef PySet_CheckExact
541 #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
542 #endif
543 #if PY_VERSION_HEX >= 0x030900A4
544 #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
545 #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
546 #else
547 #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
548 #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
549 #endif
550 #if CYTHON_ASSUME_SAFE_MACROS
551 #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq)
552 #else
553 #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq)
554 #endif
555 #if PY_MAJOR_VERSION >= 3
556 #define PyIntObject PyLongObject
557 #define PyInt_Type PyLong_Type
558 #define PyInt_Check(op) PyLong_Check(op)
559 #define PyInt_CheckExact(op) PyLong_CheckExact(op)
560 #define PyInt_FromString PyLong_FromString
561 #define PyInt_FromUnicode PyLong_FromUnicode
562 #define PyInt_FromLong PyLong_FromLong
563 #define PyInt_FromSize_t PyLong_FromSize_t
564 #define PyInt_FromSsize_t PyLong_FromSsize_t
565 #define PyInt_AsLong PyLong_AsLong
566 #define PyInt_AS_LONG PyLong_AS_LONG
567 #define PyInt_AsSsize_t PyLong_AsSsize_t
568 #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
569 #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
570 #define PyNumber_Int PyNumber_Long
571 #endif
572 #if PY_MAJOR_VERSION >= 3
573 #define PyBoolObject PyLongObject
574 #endif
575 #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
576 #ifndef PyUnicode_InternFromString
577 #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
578 #endif
579 #endif
580 #if PY_VERSION_HEX < 0x030200A4
581 typedef long Py_hash_t;
582 #define __Pyx_PyInt_FromHash_t PyInt_FromLong
583 #define __Pyx_PyInt_AsHash_t PyInt_AsLong
584 #else
585 #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
586 #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
587 #endif
588 #if PY_MAJOR_VERSION >= 3
589 #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
590 #else
591 #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
592 #endif
593 #if CYTHON_USE_ASYNC_SLOTS
594 #if PY_VERSION_HEX >= 0x030500B1
595 #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
596 #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
597 #else
598 #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
599 #endif
600 #else
601 #define __Pyx_PyType_AsAsync(obj) NULL
602 #endif
603 #ifndef __Pyx_PyAsyncMethodsStruct
604 typedef struct {
605 unaryfunc am_await;
606 unaryfunc am_aiter;
607 unaryfunc am_anext;
608 } __Pyx_PyAsyncMethodsStruct;
609 #endif
610
611 #if defined(WIN32) || defined(MS_WINDOWS)
612 #define _USE_MATH_DEFINES
613 #endif
614 #include <math.h>
615 #ifdef NAN
616 #define __PYX_NAN() ((float) NAN)
617 #else
__PYX_NAN()618 static CYTHON_INLINE float __PYX_NAN() {
619 float value;
620 memset(&value, 0xFF, sizeof(value));
621 return value;
622 }
623 #endif
624 #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
625 #define __Pyx_truncl trunc
626 #else
627 #define __Pyx_truncl truncl
628 #endif
629
630 #define __PYX_MARK_ERR_POS(f_index, lineno) \
631 { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
632 #define __PYX_ERR(f_index, lineno, Ln_error) \
633 { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }
634
635 #ifndef __PYX_EXTERN_C
636 #ifdef __cplusplus
637 #define __PYX_EXTERN_C extern "C"
638 #else
639 #define __PYX_EXTERN_C extern
640 #endif
641 #endif
642
643 #define __PYX_HAVE__qutip__cy__math
644 #define __PYX_HAVE_API__qutip__cy__math
645 /* Early includes */
646 #include <math.h>
647 #include <complex>
648 #ifdef _OPENMP
649 #include <omp.h>
650 #endif /* _OPENMP */
651
652 #if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
653 #define CYTHON_WITHOUT_ASSERTIONS
654 #endif
655
656 typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
657 const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
658
659 #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
660 #define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0
661 #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
662 #define __PYX_DEFAULT_STRING_ENCODING ""
663 #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
664 #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
665 #define __Pyx_uchar_cast(c) ((unsigned char)c)
666 #define __Pyx_long_cast(x) ((long)x)
667 #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\
668 (sizeof(type) < sizeof(Py_ssize_t)) ||\
669 (sizeof(type) > sizeof(Py_ssize_t) &&\
670 likely(v < (type)PY_SSIZE_T_MAX ||\
671 v == (type)PY_SSIZE_T_MAX) &&\
672 (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
673 v == (type)PY_SSIZE_T_MIN))) ||\
674 (sizeof(type) == sizeof(Py_ssize_t) &&\
675 (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
676 v == (type)PY_SSIZE_T_MAX))) )
__Pyx_is_valid_index(Py_ssize_t i,Py_ssize_t limit)677 static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
678 return (size_t) i < (size_t) limit;
679 }
680 #if defined (__cplusplus) && __cplusplus >= 201103L
681 #include <cstdlib>
682 #define __Pyx_sst_abs(value) std::abs(value)
683 #elif SIZEOF_INT >= SIZEOF_SIZE_T
684 #define __Pyx_sst_abs(value) abs(value)
685 #elif SIZEOF_LONG >= SIZEOF_SIZE_T
686 #define __Pyx_sst_abs(value) labs(value)
687 #elif defined (_MSC_VER)
688 #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
689 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
690 #define __Pyx_sst_abs(value) llabs(value)
691 #elif defined (__GNUC__)
692 #define __Pyx_sst_abs(value) __builtin_llabs(value)
693 #else
694 #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
695 #endif
696 static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
697 static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
698 #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
699 #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
700 #define __Pyx_PyBytes_FromString PyBytes_FromString
701 #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
702 static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
703 #if PY_MAJOR_VERSION < 3
704 #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString
705 #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
706 #else
707 #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString
708 #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
709 #endif
710 #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s))
711 #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s))
712 #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s))
713 #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s))
714 #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s))
715 #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s))
716 #define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s))
717 #define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s))
718 #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s))
719 #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s))
720 #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s))
721 #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
722 #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
723 #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
724 #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s)
725 #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
__Pyx_Py_UNICODE_strlen(const Py_UNICODE * u)726 static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
727 const Py_UNICODE *u_end = u;
728 while (*u_end++) ;
729 return (size_t)(u_end - u - 1);
730 }
731 #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
732 #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
733 #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
734 #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
735 #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
736 static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
737 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
738 static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
739 static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
740 #define __Pyx_PySequence_Tuple(obj)\
741 (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
742 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
743 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
744 #if CYTHON_ASSUME_SAFE_MACROS
745 #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
746 #else
747 #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
748 #endif
749 #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
750 #if PY_MAJOR_VERSION >= 3
751 #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
752 #else
753 #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
754 #endif
755 #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
756 #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
757 static int __Pyx_sys_getdefaultencoding_not_ascii;
__Pyx_init_sys_getdefaultencoding_params(void)758 static int __Pyx_init_sys_getdefaultencoding_params(void) {
759 PyObject* sys;
760 PyObject* default_encoding = NULL;
761 PyObject* ascii_chars_u = NULL;
762 PyObject* ascii_chars_b = NULL;
763 const char* default_encoding_c;
764 sys = PyImport_ImportModule("sys");
765 if (!sys) goto bad;
766 default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
767 Py_DECREF(sys);
768 if (!default_encoding) goto bad;
769 default_encoding_c = PyBytes_AsString(default_encoding);
770 if (!default_encoding_c) goto bad;
771 if (strcmp(default_encoding_c, "ascii") == 0) {
772 __Pyx_sys_getdefaultencoding_not_ascii = 0;
773 } else {
774 char ascii_chars[128];
775 int c;
776 for (c = 0; c < 128; c++) {
777 ascii_chars[c] = c;
778 }
779 __Pyx_sys_getdefaultencoding_not_ascii = 1;
780 ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
781 if (!ascii_chars_u) goto bad;
782 ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
783 if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
784 PyErr_Format(
785 PyExc_ValueError,
786 "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
787 default_encoding_c);
788 goto bad;
789 }
790 Py_DECREF(ascii_chars_u);
791 Py_DECREF(ascii_chars_b);
792 }
793 Py_DECREF(default_encoding);
794 return 0;
795 bad:
796 Py_XDECREF(default_encoding);
797 Py_XDECREF(ascii_chars_u);
798 Py_XDECREF(ascii_chars_b);
799 return -1;
800 }
801 #endif
802 #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
803 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
804 #else
805 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
806 #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
807 static char* __PYX_DEFAULT_STRING_ENCODING;
__Pyx_init_sys_getdefaultencoding_params(void)808 static int __Pyx_init_sys_getdefaultencoding_params(void) {
809 PyObject* sys;
810 PyObject* default_encoding = NULL;
811 char* default_encoding_c;
812 sys = PyImport_ImportModule("sys");
813 if (!sys) goto bad;
814 default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
815 Py_DECREF(sys);
816 if (!default_encoding) goto bad;
817 default_encoding_c = PyBytes_AsString(default_encoding);
818 if (!default_encoding_c) goto bad;
819 __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
820 if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
821 strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
822 Py_DECREF(default_encoding);
823 return 0;
824 bad:
825 Py_XDECREF(default_encoding);
826 return -1;
827 }
828 #endif
829 #endif
830
831
832 /* Test for GCC > 2.95 */
833 #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
834 #define likely(x) __builtin_expect(!!(x), 1)
835 #define unlikely(x) __builtin_expect(!!(x), 0)
836 #else /* !__GNUC__ or GCC < 2.95 */
837 #define likely(x) (x)
838 #define unlikely(x) (x)
839 #endif /* __GNUC__ */
__Pyx_pretend_to_initialize(void * ptr)840 static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
841
842 static PyObject *__pyx_m = NULL;
843 static PyObject *__pyx_d;
844 static PyObject *__pyx_b;
845 static PyObject *__pyx_cython_runtime = NULL;
846 static PyObject *__pyx_empty_tuple;
847 static PyObject *__pyx_empty_bytes;
848 static PyObject *__pyx_empty_unicode;
849 static int __pyx_lineno;
850 static int __pyx_clineno = 0;
851 static const char * __pyx_cfilenm= __FILE__;
852 static const char *__pyx_filename;
853
854 /* Header.proto */
855 #if !defined(CYTHON_CCOMPLEX)
856 #if defined(__cplusplus)
857 #define CYTHON_CCOMPLEX 1
858 #elif defined(_Complex_I)
859 #define CYTHON_CCOMPLEX 1
860 #else
861 #define CYTHON_CCOMPLEX 0
862 #endif
863 #endif
864 #if CYTHON_CCOMPLEX
865 #ifdef __cplusplus
866 #include <complex>
867 #else
868 #include <complex.h>
869 #endif
870 #endif
871 #if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__)
872 #undef _Complex_I
873 #define _Complex_I 1.0fj
874 #endif
875
876
877 static const char *__pyx_f[] = {
878 "qutip/cy/math.pyx",
879 };
880 /* Declarations.proto */
881 #if CYTHON_CCOMPLEX
882 #ifdef __cplusplus
883 typedef ::std::complex< double > __pyx_t_double_complex;
884 #else
885 typedef double _Complex __pyx_t_double_complex;
886 #endif
887 #else
888 typedef struct { double real, imag; } __pyx_t_double_complex;
889 #endif
890 static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double);
891
892
893 /*--- Type declarations ---*/
894
895 /* --- Runtime support code (head) --- */
896 /* Refnanny.proto */
897 #ifndef CYTHON_REFNANNY
898 #define CYTHON_REFNANNY 0
899 #endif
900 #if CYTHON_REFNANNY
901 typedef struct {
902 void (*INCREF)(void*, PyObject*, int);
903 void (*DECREF)(void*, PyObject*, int);
904 void (*GOTREF)(void*, PyObject*, int);
905 void (*GIVEREF)(void*, PyObject*, int);
906 void* (*SetupContext)(const char*, int, const char*);
907 void (*FinishContext)(void**);
908 } __Pyx_RefNannyAPIStruct;
909 static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
910 static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
911 #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
912 #ifdef WITH_THREAD
913 #define __Pyx_RefNannySetupContext(name, acquire_gil)\
914 if (acquire_gil) {\
915 PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
916 __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
917 PyGILState_Release(__pyx_gilstate_save);\
918 } else {\
919 __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
920 }
921 #else
922 #define __Pyx_RefNannySetupContext(name, acquire_gil)\
923 __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
924 #endif
925 #define __Pyx_RefNannyFinishContext()\
926 __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
927 #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
928 #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
929 #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
930 #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
931 #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
932 #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
933 #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
934 #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
935 #else
936 #define __Pyx_RefNannyDeclarations
937 #define __Pyx_RefNannySetupContext(name, acquire_gil)
938 #define __Pyx_RefNannyFinishContext()
939 #define __Pyx_INCREF(r) Py_INCREF(r)
940 #define __Pyx_DECREF(r) Py_DECREF(r)
941 #define __Pyx_GOTREF(r)
942 #define __Pyx_GIVEREF(r)
943 #define __Pyx_XINCREF(r) Py_XINCREF(r)
944 #define __Pyx_XDECREF(r) Py_XDECREF(r)
945 #define __Pyx_XGOTREF(r)
946 #define __Pyx_XGIVEREF(r)
947 #endif
948 #define __Pyx_XDECREF_SET(r, v) do {\
949 PyObject *tmp = (PyObject *) r;\
950 r = v; __Pyx_XDECREF(tmp);\
951 } while (0)
952 #define __Pyx_DECREF_SET(r, v) do {\
953 PyObject *tmp = (PyObject *) r;\
954 r = v; __Pyx_DECREF(tmp);\
955 } while (0)
956 #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
957 #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
958
959 /* PyObjectGetAttrStr.proto */
960 #if CYTHON_USE_TYPE_SLOTS
961 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
962 #else
963 #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
964 #endif
965
966 /* GetBuiltinName.proto */
967 static PyObject *__Pyx_GetBuiltinName(PyObject *name);
968
969 /* IncludeStringH.proto */
970 #include <string.h>
971
972 /* PyDictVersioning.proto */
973 #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
974 #define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1)
975 #define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag)
976 #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
977 (version_var) = __PYX_GET_DICT_VERSION(dict);\
978 (cache_var) = (value);
979 #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
980 static PY_UINT64_T __pyx_dict_version = 0;\
981 static PyObject *__pyx_dict_cached_value = NULL;\
982 if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
983 (VAR) = __pyx_dict_cached_value;\
984 } else {\
985 (VAR) = __pyx_dict_cached_value = (LOOKUP);\
986 __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
987 }\
988 }
989 static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj);
990 static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj);
991 static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version);
992 #else
993 #define __PYX_GET_DICT_VERSION(dict) (0)
994 #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
995 #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP);
996 #endif
997
998 /* PyThreadStateGet.proto */
999 #if CYTHON_FAST_THREAD_STATE
1000 #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate;
1001 #define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current;
1002 #define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type
1003 #else
1004 #define __Pyx_PyThreadState_declare
1005 #define __Pyx_PyThreadState_assign
1006 #define __Pyx_PyErr_Occurred() PyErr_Occurred()
1007 #endif
1008
1009 /* PyErrFetchRestore.proto */
1010 #if CYTHON_FAST_THREAD_STATE
1011 #define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
1012 #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
1013 #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
1014 #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
1015 #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
1016 static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
1017 static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
1018 #if CYTHON_COMPILING_IN_CPYTHON
1019 #define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
1020 #else
1021 #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
1022 #endif
1023 #else
1024 #define __Pyx_PyErr_Clear() PyErr_Clear()
1025 #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
1026 #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
1027 #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
1028 #define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb)
1029 #define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb)
1030 #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
1031 #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb)
1032 #endif
1033
1034 /* CLineInTraceback.proto */
1035 #ifdef CYTHON_CLINE_IN_TRACEBACK
1036 #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
1037 #else
1038 static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
1039 #endif
1040
1041 /* CodeObjectCache.proto */
1042 typedef struct {
1043 PyCodeObject* code_object;
1044 int code_line;
1045 } __Pyx_CodeObjectCacheEntry;
1046 struct __Pyx_CodeObjectCache {
1047 int count;
1048 int max_count;
1049 __Pyx_CodeObjectCacheEntry* entries;
1050 };
1051 static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
1052 static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
1053 static PyCodeObject *__pyx_find_code_object(int code_line);
1054 static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
1055
1056 /* AddTraceback.proto */
1057 static void __Pyx_AddTraceback(const char *funcname, int c_line,
1058 int py_line, const char *filename);
1059
1060 /* RealImag.proto */
1061 #if CYTHON_CCOMPLEX
1062 #ifdef __cplusplus
1063 #define __Pyx_CREAL(z) ((z).real())
1064 #define __Pyx_CIMAG(z) ((z).imag())
1065 #else
1066 #define __Pyx_CREAL(z) (__real__(z))
1067 #define __Pyx_CIMAG(z) (__imag__(z))
1068 #endif
1069 #else
1070 #define __Pyx_CREAL(z) ((z).real)
1071 #define __Pyx_CIMAG(z) ((z).imag)
1072 #endif
1073 #if defined(__cplusplus) && CYTHON_CCOMPLEX\
1074 && (defined(_WIN32) || defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 5 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4 )) || __cplusplus >= 201103)
1075 #define __Pyx_SET_CREAL(z,x) ((z).real(x))
1076 #define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
1077 #else
1078 #define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
1079 #define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
1080 #endif
1081
1082 /* Arithmetic.proto */
1083 #if CYTHON_CCOMPLEX
1084 #define __Pyx_c_eq_double(a, b) ((a)==(b))
1085 #define __Pyx_c_sum_double(a, b) ((a)+(b))
1086 #define __Pyx_c_diff_double(a, b) ((a)-(b))
1087 #define __Pyx_c_prod_double(a, b) ((a)*(b))
1088 #define __Pyx_c_quot_double(a, b) ((a)/(b))
1089 #define __Pyx_c_neg_double(a) (-(a))
1090 #ifdef __cplusplus
1091 #define __Pyx_c_is_zero_double(z) ((z)==(double)0)
1092 #define __Pyx_c_conj_double(z) (::std::conj(z))
1093 #if 1
1094 #define __Pyx_c_abs_double(z) (::std::abs(z))
1095 #define __Pyx_c_pow_double(a, b) (::std::pow(a, b))
1096 #endif
1097 #else
1098 #define __Pyx_c_is_zero_double(z) ((z)==0)
1099 #define __Pyx_c_conj_double(z) (conj(z))
1100 #if 1
1101 #define __Pyx_c_abs_double(z) (cabs(z))
1102 #define __Pyx_c_pow_double(a, b) (cpow(a, b))
1103 #endif
1104 #endif
1105 #else
1106 static CYTHON_INLINE int __Pyx_c_eq_double(__pyx_t_double_complex, __pyx_t_double_complex);
1107 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum_double(__pyx_t_double_complex, __pyx_t_double_complex);
1108 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff_double(__pyx_t_double_complex, __pyx_t_double_complex);
1109 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod_double(__pyx_t_double_complex, __pyx_t_double_complex);
1110 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex, __pyx_t_double_complex);
1111 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg_double(__pyx_t_double_complex);
1112 static CYTHON_INLINE int __Pyx_c_is_zero_double(__pyx_t_double_complex);
1113 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj_double(__pyx_t_double_complex);
1114 #if 1
1115 static CYTHON_INLINE double __Pyx_c_abs_double(__pyx_t_double_complex);
1116 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow_double(__pyx_t_double_complex, __pyx_t_double_complex);
1117 #endif
1118 #endif
1119
1120 /* GCCDiagnostics.proto */
1121 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
1122 #define __Pyx_HAS_GCC_DIAGNOSTIC
1123 #endif
1124
1125 /* CIntFromPy.proto */
1126 static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *);
1127
1128 /* CIntToPy.proto */
1129 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
1130
1131 /* CIntFromPy.proto */
1132 static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
1133
1134 /* CIntFromPy.proto */
1135 static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
1136
1137 /* FastTypeChecks.proto */
1138 #if CYTHON_COMPILING_IN_CPYTHON
1139 #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
1140 static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
1141 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
1142 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
1143 #else
1144 #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
1145 #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
1146 #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
1147 #endif
1148 #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
1149
1150 /* CheckBinaryVersion.proto */
1151 static int __Pyx_check_binary_version(void);
1152
1153 /* FunctionExport.proto */
1154 static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig);
1155
1156 /* InitStrings.proto */
1157 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
1158
1159
1160 /* Module declarations from 'cython' */
1161
1162 /* Module declarations from 'libc.math' */
1163
1164 /* Module declarations from 'qutip.cy.math' */
1165 #define __Pyx_MODULE_NAME "qutip.cy.math"
1166 extern int __pyx_module_is_main_qutip__cy__math;
1167 int __pyx_module_is_main_qutip__cy__math = 0;
1168
1169 /* Implementation of 'qutip.cy.math' */
1170 static PyObject *__pyx_builtin_range;
1171 static const char __pyx_k_main[] = "__main__";
1172 static const char __pyx_k_name[] = "__name__";
1173 static const char __pyx_k_test[] = "__test__";
1174 static const char __pyx_k_range[] = "range";
1175 static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
1176 static PyObject *__pyx_n_s_cline_in_traceback;
1177 static PyObject *__pyx_n_s_main;
1178 static PyObject *__pyx_n_s_name;
1179 static PyObject *__pyx_n_s_range;
1180 static PyObject *__pyx_n_s_test;
1181 /* Late includes */
1182
1183 /* "qutip/cy/math.pyx":43
1184 * @cython.boundscheck(False)
1185 * @cython.cdivision(True)
1186 * cdef double erf(double x): # <<<<<<<<<<<<<<
1187 * """
1188 * A Cython version of the erf function from the cdflib in SciPy.
1189 */
1190
__pyx_f_5qutip_2cy_4math_erf(double __pyx_v_x)1191 static double __pyx_f_5qutip_2cy_4math_erf(double __pyx_v_x) {
1192 double __pyx_v_c;
1193 double __pyx_v_a[5];
1194 double __pyx_v_b[3];
1195 double __pyx_v_p[8];
1196 double __pyx_v_q[8];
1197 double __pyx_v_r[5];
1198 double __pyx_v_s[4];
1199 double __pyx_v_ax;
1200 double __pyx_v_t;
1201 double __pyx_v_x2;
1202 double __pyx_v_top;
1203 double __pyx_v_bot;
1204 double __pyx_v_erf;
1205 double __pyx_r;
1206 __Pyx_RefNannyDeclarations
1207 double __pyx_t_1[5];
1208 double __pyx_t_2[3];
1209 double __pyx_t_3[8];
1210 double __pyx_t_4[8];
1211 double __pyx_t_5[5];
1212 double __pyx_t_6[4];
1213 int __pyx_t_7;
1214 __Pyx_RefNannySetupContext("erf", 0);
1215
1216 /* "qutip/cy/math.pyx":47
1217 * A Cython version of the erf function from the cdflib in SciPy.
1218 * """
1219 * cdef double c = 0.564189583547756 # <<<<<<<<<<<<<<
1220 *
1221 * cdef double a[5]
1222 */
1223 __pyx_v_c = 0.564189583547756;
1224
1225 /* "qutip/cy/math.pyx":50
1226 *
1227 * cdef double a[5]
1228 * a[:] = [0.771058495001320e-4, -0.133733772997339e-2, 0.323076579225834e-1, # <<<<<<<<<<<<<<
1229 * 0.479137145607681e-1, 0.128379167095513]
1230 *
1231 */
1232 __pyx_t_1[0] = 0.771058495001320e-4;
1233 __pyx_t_1[1] = -0.133733772997339e-2;
1234 __pyx_t_1[2] = 0.323076579225834e-1;
1235 __pyx_t_1[3] = 0.479137145607681e-1;
1236 __pyx_t_1[4] = 0.128379167095513;
1237 memcpy(&(__pyx_v_a[0]), __pyx_t_1, sizeof(__pyx_v_a[0]) * (5));
1238
1239 /* "qutip/cy/math.pyx":54
1240 *
1241 * cdef double b[3]
1242 * b[:] = [0.301048631703895e-2, 0.538971687740286e-1, .375795757275549] # <<<<<<<<<<<<<<
1243 *
1244 * cdef double p[8]
1245 */
1246 __pyx_t_2[0] = 0.301048631703895e-2;
1247 __pyx_t_2[1] = 0.538971687740286e-1;
1248 __pyx_t_2[2] = .375795757275549;
1249 memcpy(&(__pyx_v_b[0]), __pyx_t_2, sizeof(__pyx_v_b[0]) * (3));
1250
1251 /* "qutip/cy/math.pyx":57
1252 *
1253 * cdef double p[8]
1254 * p[:] = [-1.36864857382717e-7, 5.64195517478974e-1, 7.21175825088309, # <<<<<<<<<<<<<<
1255 * 4.31622272220567e1, 1.52989285046940e2, 3.39320816734344e2,
1256 * 4.51918953711873e2, 3.00459261020162e2]
1257 */
1258 __pyx_t_3[0] = -1.36864857382717e-7;
1259 __pyx_t_3[1] = 5.64195517478974e-1;
1260 __pyx_t_3[2] = 7.21175825088309;
1261 __pyx_t_3[3] = 4.31622272220567e1;
1262 __pyx_t_3[4] = 1.52989285046940e2;
1263 __pyx_t_3[5] = 3.39320816734344e2;
1264 __pyx_t_3[6] = 4.51918953711873e2;
1265 __pyx_t_3[7] = 3.00459261020162e2;
1266 memcpy(&(__pyx_v_p[0]), __pyx_t_3, sizeof(__pyx_v_p[0]) * (8));
1267
1268 /* "qutip/cy/math.pyx":62
1269 *
1270 * cdef double q[8]
1271 * q[:]= [1.0, 1.27827273196294e1, 7.70001529352295e1, 2.77585444743988e2, # <<<<<<<<<<<<<<
1272 * 6.38980264465631e2, 9.31354094850610e2, 7.90950925327898e2,
1273 * 3.00459260956983e2]
1274 */
1275 __pyx_t_4[0] = 1.0;
1276 __pyx_t_4[1] = 1.27827273196294e1;
1277 __pyx_t_4[2] = 7.70001529352295e1;
1278 __pyx_t_4[3] = 2.77585444743988e2;
1279 __pyx_t_4[4] = 6.38980264465631e2;
1280 __pyx_t_4[5] = 9.31354094850610e2;
1281 __pyx_t_4[6] = 7.90950925327898e2;
1282 __pyx_t_4[7] = 3.00459260956983e2;
1283 memcpy(&(__pyx_v_q[0]), __pyx_t_4, sizeof(__pyx_v_q[0]) * (8));
1284
1285 /* "qutip/cy/math.pyx":67
1286 *
1287 * cdef double r[5]
1288 * r[:] = [2.10144126479064, 2.62370141675169e1, 2.13688200555087e1, # <<<<<<<<<<<<<<
1289 * 4.65807828718470, 2.82094791773523e-1]
1290 *
1291 */
1292 __pyx_t_5[0] = 2.10144126479064;
1293 __pyx_t_5[1] = 2.62370141675169e1;
1294 __pyx_t_5[2] = 2.13688200555087e1;
1295 __pyx_t_5[3] = 4.65807828718470;
1296 __pyx_t_5[4] = 2.82094791773523e-1;
1297 memcpy(&(__pyx_v_r[0]), __pyx_t_5, sizeof(__pyx_v_r[0]) * (5));
1298
1299 /* "qutip/cy/math.pyx":71
1300 *
1301 * cdef double s[4]
1302 * s[:] = [9.41537750555460e1, 1.87114811799590e2, 9.90191814623914e1, # <<<<<<<<<<<<<<
1303 * 1.80124575948747e1]
1304 *
1305 */
1306 __pyx_t_6[0] = 9.41537750555460e1;
1307 __pyx_t_6[1] = 1.87114811799590e2;
1308 __pyx_t_6[2] = 9.90191814623914e1;
1309 __pyx_t_6[3] = 1.80124575948747e1;
1310 memcpy(&(__pyx_v_s[0]), __pyx_t_6, sizeof(__pyx_v_s[0]) * (4));
1311
1312 /* "qutip/cy/math.pyx":74
1313 * 1.80124575948747e1]
1314 *
1315 * cdef double ax = fabs(x) # <<<<<<<<<<<<<<
1316 * cdef double t, x2, top, bot, erf
1317 *
1318 */
1319 __pyx_v_ax = fabs(__pyx_v_x);
1320
1321 /* "qutip/cy/math.pyx":77
1322 * cdef double t, x2, top, bot, erf
1323 *
1324 * if ax <= 0.5: # <<<<<<<<<<<<<<
1325 * t = x*x
1326 * top = ((((a[0]*t+a[1])*t+a[2])*t+a[3])*t+a[4]) + 1.0
1327 */
1328 __pyx_t_7 = ((__pyx_v_ax <= 0.5) != 0);
1329 if (__pyx_t_7) {
1330
1331 /* "qutip/cy/math.pyx":78
1332 *
1333 * if ax <= 0.5:
1334 * t = x*x # <<<<<<<<<<<<<<
1335 * top = ((((a[0]*t+a[1])*t+a[2])*t+a[3])*t+a[4]) + 1.0
1336 * bot = ((b[0]*t+b[1])*t+b[2])*t + 1.0
1337 */
1338 __pyx_v_t = (__pyx_v_x * __pyx_v_x);
1339
1340 /* "qutip/cy/math.pyx":79
1341 * if ax <= 0.5:
1342 * t = x*x
1343 * top = ((((a[0]*t+a[1])*t+a[2])*t+a[3])*t+a[4]) + 1.0 # <<<<<<<<<<<<<<
1344 * bot = ((b[0]*t+b[1])*t+b[2])*t + 1.0
1345 * erf = x * (top/bot)
1346 */
1347 __pyx_v_top = ((((((((((__pyx_v_a[0]) * __pyx_v_t) + (__pyx_v_a[1])) * __pyx_v_t) + (__pyx_v_a[2])) * __pyx_v_t) + (__pyx_v_a[3])) * __pyx_v_t) + (__pyx_v_a[4])) + 1.0);
1348
1349 /* "qutip/cy/math.pyx":80
1350 * t = x*x
1351 * top = ((((a[0]*t+a[1])*t+a[2])*t+a[3])*t+a[4]) + 1.0
1352 * bot = ((b[0]*t+b[1])*t+b[2])*t + 1.0 # <<<<<<<<<<<<<<
1353 * erf = x * (top/bot)
1354 * return erf
1355 */
1356 __pyx_v_bot = (((((((__pyx_v_b[0]) * __pyx_v_t) + (__pyx_v_b[1])) * __pyx_v_t) + (__pyx_v_b[2])) * __pyx_v_t) + 1.0);
1357
1358 /* "qutip/cy/math.pyx":81
1359 * top = ((((a[0]*t+a[1])*t+a[2])*t+a[3])*t+a[4]) + 1.0
1360 * bot = ((b[0]*t+b[1])*t+b[2])*t + 1.0
1361 * erf = x * (top/bot) # <<<<<<<<<<<<<<
1362 * return erf
1363 * elif ax <= 4.0:
1364 */
1365 __pyx_v_erf = (__pyx_v_x * (__pyx_v_top / __pyx_v_bot));
1366
1367 /* "qutip/cy/math.pyx":82
1368 * bot = ((b[0]*t+b[1])*t+b[2])*t + 1.0
1369 * erf = x * (top/bot)
1370 * return erf # <<<<<<<<<<<<<<
1371 * elif ax <= 4.0:
1372 * x2 = x*x
1373 */
1374 __pyx_r = __pyx_v_erf;
1375 goto __pyx_L0;
1376
1377 /* "qutip/cy/math.pyx":77
1378 * cdef double t, x2, top, bot, erf
1379 *
1380 * if ax <= 0.5: # <<<<<<<<<<<<<<
1381 * t = x*x
1382 * top = ((((a[0]*t+a[1])*t+a[2])*t+a[3])*t+a[4]) + 1.0
1383 */
1384 }
1385
1386 /* "qutip/cy/math.pyx":83
1387 * erf = x * (top/bot)
1388 * return erf
1389 * elif ax <= 4.0: # <<<<<<<<<<<<<<
1390 * x2 = x*x
1391 * top = ((((((p[0]*ax+p[1])*ax+p[2])*ax+p[3])*ax+p[4])*ax+p[5])*ax+p[6])*ax + p[7]
1392 */
1393 __pyx_t_7 = ((__pyx_v_ax <= 4.0) != 0);
1394 if (__pyx_t_7) {
1395
1396 /* "qutip/cy/math.pyx":84
1397 * return erf
1398 * elif ax <= 4.0:
1399 * x2 = x*x # <<<<<<<<<<<<<<
1400 * top = ((((((p[0]*ax+p[1])*ax+p[2])*ax+p[3])*ax+p[4])*ax+p[5])*ax+p[6])*ax + p[7]
1401 * bot = ((((((q[0]*ax+q[1])*ax+q[2])*ax+q[3])*ax+q[4])*ax+q[5])*ax+q[6])*ax + q[7]
1402 */
1403 __pyx_v_x2 = (__pyx_v_x * __pyx_v_x);
1404
1405 /* "qutip/cy/math.pyx":85
1406 * elif ax <= 4.0:
1407 * x2 = x*x
1408 * top = ((((((p[0]*ax+p[1])*ax+p[2])*ax+p[3])*ax+p[4])*ax+p[5])*ax+p[6])*ax + p[7] # <<<<<<<<<<<<<<
1409 * bot = ((((((q[0]*ax+q[1])*ax+q[2])*ax+q[3])*ax+q[4])*ax+q[5])*ax+q[6])*ax + q[7]
1410 * erf = 0.5 + (0.5-exp(-x2)*top/bot)
1411 */
1412 __pyx_v_top = (((((((((((((((__pyx_v_p[0]) * __pyx_v_ax) + (__pyx_v_p[1])) * __pyx_v_ax) + (__pyx_v_p[2])) * __pyx_v_ax) + (__pyx_v_p[3])) * __pyx_v_ax) + (__pyx_v_p[4])) * __pyx_v_ax) + (__pyx_v_p[5])) * __pyx_v_ax) + (__pyx_v_p[6])) * __pyx_v_ax) + (__pyx_v_p[7]));
1413
1414 /* "qutip/cy/math.pyx":86
1415 * x2 = x*x
1416 * top = ((((((p[0]*ax+p[1])*ax+p[2])*ax+p[3])*ax+p[4])*ax+p[5])*ax+p[6])*ax + p[7]
1417 * bot = ((((((q[0]*ax+q[1])*ax+q[2])*ax+q[3])*ax+q[4])*ax+q[5])*ax+q[6])*ax + q[7] # <<<<<<<<<<<<<<
1418 * erf = 0.5 + (0.5-exp(-x2)*top/bot)
1419 * if x < 0.0:
1420 */
1421 __pyx_v_bot = (((((((((((((((__pyx_v_q[0]) * __pyx_v_ax) + (__pyx_v_q[1])) * __pyx_v_ax) + (__pyx_v_q[2])) * __pyx_v_ax) + (__pyx_v_q[3])) * __pyx_v_ax) + (__pyx_v_q[4])) * __pyx_v_ax) + (__pyx_v_q[5])) * __pyx_v_ax) + (__pyx_v_q[6])) * __pyx_v_ax) + (__pyx_v_q[7]));
1422
1423 /* "qutip/cy/math.pyx":87
1424 * top = ((((((p[0]*ax+p[1])*ax+p[2])*ax+p[3])*ax+p[4])*ax+p[5])*ax+p[6])*ax + p[7]
1425 * bot = ((((((q[0]*ax+q[1])*ax+q[2])*ax+q[3])*ax+q[4])*ax+q[5])*ax+q[6])*ax + q[7]
1426 * erf = 0.5 + (0.5-exp(-x2)*top/bot) # <<<<<<<<<<<<<<
1427 * if x < 0.0:
1428 * erf = -erf
1429 */
1430 __pyx_v_erf = (0.5 + (0.5 - ((exp((-__pyx_v_x2)) * __pyx_v_top) / __pyx_v_bot)));
1431
1432 /* "qutip/cy/math.pyx":88
1433 * bot = ((((((q[0]*ax+q[1])*ax+q[2])*ax+q[3])*ax+q[4])*ax+q[5])*ax+q[6])*ax + q[7]
1434 * erf = 0.5 + (0.5-exp(-x2)*top/bot)
1435 * if x < 0.0: # <<<<<<<<<<<<<<
1436 * erf = -erf
1437 * return erf
1438 */
1439 __pyx_t_7 = ((__pyx_v_x < 0.0) != 0);
1440 if (__pyx_t_7) {
1441
1442 /* "qutip/cy/math.pyx":89
1443 * erf = 0.5 + (0.5-exp(-x2)*top/bot)
1444 * if x < 0.0:
1445 * erf = -erf # <<<<<<<<<<<<<<
1446 * return erf
1447 * elif ax < 5.8:
1448 */
1449 __pyx_v_erf = (-__pyx_v_erf);
1450
1451 /* "qutip/cy/math.pyx":88
1452 * bot = ((((((q[0]*ax+q[1])*ax+q[2])*ax+q[3])*ax+q[4])*ax+q[5])*ax+q[6])*ax + q[7]
1453 * erf = 0.5 + (0.5-exp(-x2)*top/bot)
1454 * if x < 0.0: # <<<<<<<<<<<<<<
1455 * erf = -erf
1456 * return erf
1457 */
1458 }
1459
1460 /* "qutip/cy/math.pyx":90
1461 * if x < 0.0:
1462 * erf = -erf
1463 * return erf # <<<<<<<<<<<<<<
1464 * elif ax < 5.8:
1465 * x2 = x*x
1466 */
1467 __pyx_r = __pyx_v_erf;
1468 goto __pyx_L0;
1469
1470 /* "qutip/cy/math.pyx":83
1471 * erf = x * (top/bot)
1472 * return erf
1473 * elif ax <= 4.0: # <<<<<<<<<<<<<<
1474 * x2 = x*x
1475 * top = ((((((p[0]*ax+p[1])*ax+p[2])*ax+p[3])*ax+p[4])*ax+p[5])*ax+p[6])*ax + p[7]
1476 */
1477 }
1478
1479 /* "qutip/cy/math.pyx":91
1480 * erf = -erf
1481 * return erf
1482 * elif ax < 5.8: # <<<<<<<<<<<<<<
1483 * x2 = x*x
1484 * t = 1.0/x2
1485 */
1486 __pyx_t_7 = ((__pyx_v_ax < 5.8) != 0);
1487 if (__pyx_t_7) {
1488
1489 /* "qutip/cy/math.pyx":92
1490 * return erf
1491 * elif ax < 5.8:
1492 * x2 = x*x # <<<<<<<<<<<<<<
1493 * t = 1.0/x2
1494 * top = (((r[0]*t+r[1])*t+r[2])*t+r[3])*t + r[4]
1495 */
1496 __pyx_v_x2 = (__pyx_v_x * __pyx_v_x);
1497
1498 /* "qutip/cy/math.pyx":93
1499 * elif ax < 5.8:
1500 * x2 = x*x
1501 * t = 1.0/x2 # <<<<<<<<<<<<<<
1502 * top = (((r[0]*t+r[1])*t+r[2])*t+r[3])*t + r[4]
1503 * bot = (((s[0]*t+s[1])*t+s[2])*t+s[3])*t + 1.0
1504 */
1505 __pyx_v_t = (1.0 / __pyx_v_x2);
1506
1507 /* "qutip/cy/math.pyx":94
1508 * x2 = x*x
1509 * t = 1.0/x2
1510 * top = (((r[0]*t+r[1])*t+r[2])*t+r[3])*t + r[4] # <<<<<<<<<<<<<<
1511 * bot = (((s[0]*t+s[1])*t+s[2])*t+s[3])*t + 1.0
1512 * erf = (c-top/(x2*bot))/ax
1513 */
1514 __pyx_v_top = (((((((((__pyx_v_r[0]) * __pyx_v_t) + (__pyx_v_r[1])) * __pyx_v_t) + (__pyx_v_r[2])) * __pyx_v_t) + (__pyx_v_r[3])) * __pyx_v_t) + (__pyx_v_r[4]));
1515
1516 /* "qutip/cy/math.pyx":95
1517 * t = 1.0/x2
1518 * top = (((r[0]*t+r[1])*t+r[2])*t+r[3])*t + r[4]
1519 * bot = (((s[0]*t+s[1])*t+s[2])*t+s[3])*t + 1.0 # <<<<<<<<<<<<<<
1520 * erf = (c-top/(x2*bot))/ax
1521 * erf = 0.5 + (0.5-exp(-x2)*erf)
1522 */
1523 __pyx_v_bot = (((((((((__pyx_v_s[0]) * __pyx_v_t) + (__pyx_v_s[1])) * __pyx_v_t) + (__pyx_v_s[2])) * __pyx_v_t) + (__pyx_v_s[3])) * __pyx_v_t) + 1.0);
1524
1525 /* "qutip/cy/math.pyx":96
1526 * top = (((r[0]*t+r[1])*t+r[2])*t+r[3])*t + r[4]
1527 * bot = (((s[0]*t+s[1])*t+s[2])*t+s[3])*t + 1.0
1528 * erf = (c-top/(x2*bot))/ax # <<<<<<<<<<<<<<
1529 * erf = 0.5 + (0.5-exp(-x2)*erf)
1530 * if x < 0.0:
1531 */
1532 __pyx_v_erf = ((__pyx_v_c - (__pyx_v_top / (__pyx_v_x2 * __pyx_v_bot))) / __pyx_v_ax);
1533
1534 /* "qutip/cy/math.pyx":97
1535 * bot = (((s[0]*t+s[1])*t+s[2])*t+s[3])*t + 1.0
1536 * erf = (c-top/(x2*bot))/ax
1537 * erf = 0.5 + (0.5-exp(-x2)*erf) # <<<<<<<<<<<<<<
1538 * if x < 0.0:
1539 * erf = -erf
1540 */
1541 __pyx_v_erf = (0.5 + (0.5 - (exp((-__pyx_v_x2)) * __pyx_v_erf)));
1542
1543 /* "qutip/cy/math.pyx":98
1544 * erf = (c-top/(x2*bot))/ax
1545 * erf = 0.5 + (0.5-exp(-x2)*erf)
1546 * if x < 0.0: # <<<<<<<<<<<<<<
1547 * erf = -erf
1548 * return erf
1549 */
1550 __pyx_t_7 = ((__pyx_v_x < 0.0) != 0);
1551 if (__pyx_t_7) {
1552
1553 /* "qutip/cy/math.pyx":99
1554 * erf = 0.5 + (0.5-exp(-x2)*erf)
1555 * if x < 0.0:
1556 * erf = -erf # <<<<<<<<<<<<<<
1557 * return erf
1558 * else:
1559 */
1560 __pyx_v_erf = (-__pyx_v_erf);
1561
1562 /* "qutip/cy/math.pyx":98
1563 * erf = (c-top/(x2*bot))/ax
1564 * erf = 0.5 + (0.5-exp(-x2)*erf)
1565 * if x < 0.0: # <<<<<<<<<<<<<<
1566 * erf = -erf
1567 * return erf
1568 */
1569 }
1570
1571 /* "qutip/cy/math.pyx":100
1572 * if x < 0.0:
1573 * erf = -erf
1574 * return erf # <<<<<<<<<<<<<<
1575 * else:
1576 * erf = copysign(1.0, x)
1577 */
1578 __pyx_r = __pyx_v_erf;
1579 goto __pyx_L0;
1580
1581 /* "qutip/cy/math.pyx":91
1582 * erf = -erf
1583 * return erf
1584 * elif ax < 5.8: # <<<<<<<<<<<<<<
1585 * x2 = x*x
1586 * t = 1.0/x2
1587 */
1588 }
1589
1590 /* "qutip/cy/math.pyx":102
1591 * return erf
1592 * else:
1593 * erf = copysign(1.0, x) # <<<<<<<<<<<<<<
1594 * return erf
1595 *
1596 */
1597 /*else*/ {
1598 __pyx_v_erf = copysign(1.0, __pyx_v_x);
1599
1600 /* "qutip/cy/math.pyx":103
1601 * else:
1602 * erf = copysign(1.0, x)
1603 * return erf # <<<<<<<<<<<<<<
1604 *
1605 *
1606 */
1607 __pyx_r = __pyx_v_erf;
1608 goto __pyx_L0;
1609 }
1610
1611 /* "qutip/cy/math.pyx":43
1612 * @cython.boundscheck(False)
1613 * @cython.cdivision(True)
1614 * cdef double erf(double x): # <<<<<<<<<<<<<<
1615 * """
1616 * A Cython version of the erf function from the cdflib in SciPy.
1617 */
1618
1619 /* function exit code */
1620 __pyx_L0:;
1621 __Pyx_RefNannyFinishContext();
1622 return __pyx_r;
1623 }
1624
1625 /* "qutip/cy/math.pyx":115
1626 * @cython.cdivision(True)
1627 * @cython.boundscheck(False)
1628 * cdef double complex zerf(double complex Z): # <<<<<<<<<<<<<<
1629 * """
1630 * Parameters
1631 */
1632
__pyx_f_5qutip_2cy_4math_zerf(__pyx_t_double_complex __pyx_v_Z)1633 static __pyx_t_double_complex __pyx_f_5qutip_2cy_4math_zerf(__pyx_t_double_complex __pyx_v_Z) {
1634 double __pyx_v_EPS;
1635 double __pyx_v_X;
1636 double __pyx_v_Y;
1637 double __pyx_v_X2;
1638 double __pyx_v_ER;
1639 double __pyx_v_R;
1640 double __pyx_v_W;
1641 double __pyx_v_C0;
1642 double __pyx_v_ER0;
1643 double __pyx_v_ERR;
1644 double __pyx_v_ERI;
1645 double __pyx_v_CS;
1646 double __pyx_v_SS;
1647 double __pyx_v_ER1;
1648 double __pyx_v_EI1;
1649 double __pyx_v_ER2;
1650 double __pyx_v_W1;
1651 size_t __pyx_v_K;
1652 size_t __pyx_v_N;
1653 double __pyx_v_EI2;
1654 double __pyx_v_W2;
1655 __pyx_t_double_complex __pyx_r;
1656 __Pyx_RefNannyDeclarations
1657 int __pyx_t_1;
1658 size_t __pyx_t_2;
1659 __Pyx_RefNannySetupContext("zerf", 0);
1660
1661 /* "qutip/cy/math.pyx":131
1662 * """
1663 *
1664 * cdef double EPS = 1e-12 # <<<<<<<<<<<<<<
1665 * cdef double X = real(Z)
1666 * cdef double Y = imag(Z)
1667 */
1668 __pyx_v_EPS = 1e-12;
1669
1670 /* "qutip/cy/math.pyx":132
1671 *
1672 * cdef double EPS = 1e-12
1673 * cdef double X = real(Z) # <<<<<<<<<<<<<<
1674 * cdef double Y = imag(Z)
1675 * cdef double X2 = X * X
1676 */
1677 __pyx_v_X = std::real(__pyx_v_Z);
1678
1679 /* "qutip/cy/math.pyx":133
1680 * cdef double EPS = 1e-12
1681 * cdef double X = real(Z)
1682 * cdef double Y = imag(Z) # <<<<<<<<<<<<<<
1683 * cdef double X2 = X * X
1684 *
1685 */
1686 __pyx_v_Y = std::imag(__pyx_v_Z);
1687
1688 /* "qutip/cy/math.pyx":134
1689 * cdef double X = real(Z)
1690 * cdef double Y = imag(Z)
1691 * cdef double X2 = X * X # <<<<<<<<<<<<<<
1692 *
1693 * cdef double ER, R, W, C0, ER0, ERR, ERI, CS, SS, ER1, EI1, ER2, W1
1694 */
1695 __pyx_v_X2 = (__pyx_v_X * __pyx_v_X);
1696
1697 /* "qutip/cy/math.pyx":140
1698 * cdef size_t K, N
1699 *
1700 * if X < 3.5: # <<<<<<<<<<<<<<
1701 * ER = 1.0
1702 * R = 1.0
1703 */
1704 __pyx_t_1 = ((__pyx_v_X < 3.5) != 0);
1705 if (__pyx_t_1) {
1706
1707 /* "qutip/cy/math.pyx":141
1708 *
1709 * if X < 3.5:
1710 * ER = 1.0 # <<<<<<<<<<<<<<
1711 * R = 1.0
1712 * W = 0.0
1713 */
1714 __pyx_v_ER = 1.0;
1715
1716 /* "qutip/cy/math.pyx":142
1717 * if X < 3.5:
1718 * ER = 1.0
1719 * R = 1.0 # <<<<<<<<<<<<<<
1720 * W = 0.0
1721 * for K in range(1, 100):
1722 */
1723 __pyx_v_R = 1.0;
1724
1725 /* "qutip/cy/math.pyx":143
1726 * ER = 1.0
1727 * R = 1.0
1728 * W = 0.0 # <<<<<<<<<<<<<<
1729 * for K in range(1, 100):
1730 * R = R*X2/(K+0.5)
1731 */
1732 __pyx_v_W = 0.0;
1733
1734 /* "qutip/cy/math.pyx":144
1735 * R = 1.0
1736 * W = 0.0
1737 * for K in range(1, 100): # <<<<<<<<<<<<<<
1738 * R = R*X2/(K+0.5)
1739 * ER = ER+R
1740 */
1741 for (__pyx_t_2 = 1; __pyx_t_2 < 0x64; __pyx_t_2+=1) {
1742 __pyx_v_K = __pyx_t_2;
1743
1744 /* "qutip/cy/math.pyx":145
1745 * W = 0.0
1746 * for K in range(1, 100):
1747 * R = R*X2/(K+0.5) # <<<<<<<<<<<<<<
1748 * ER = ER+R
1749 * if (fabs(ER-W) < EPS*fabs(ER)):
1750 */
1751 __pyx_v_R = ((__pyx_v_R * __pyx_v_X2) / (__pyx_v_K + 0.5));
1752
1753 /* "qutip/cy/math.pyx":146
1754 * for K in range(1, 100):
1755 * R = R*X2/(K+0.5)
1756 * ER = ER+R # <<<<<<<<<<<<<<
1757 * if (fabs(ER-W) < EPS*fabs(ER)):
1758 * break
1759 */
1760 __pyx_v_ER = (__pyx_v_ER + __pyx_v_R);
1761
1762 /* "qutip/cy/math.pyx":147
1763 * R = R*X2/(K+0.5)
1764 * ER = ER+R
1765 * if (fabs(ER-W) < EPS*fabs(ER)): # <<<<<<<<<<<<<<
1766 * break
1767 * W = ER
1768 */
1769 __pyx_t_1 = ((fabs((__pyx_v_ER - __pyx_v_W)) < (__pyx_v_EPS * fabs(__pyx_v_ER))) != 0);
1770 if (__pyx_t_1) {
1771
1772 /* "qutip/cy/math.pyx":148
1773 * ER = ER+R
1774 * if (fabs(ER-W) < EPS*fabs(ER)):
1775 * break # <<<<<<<<<<<<<<
1776 * W = ER
1777 * C0 = 2.0/sqrt(pi)*X*exp(-X2)
1778 */
1779 goto __pyx_L5_break;
1780
1781 /* "qutip/cy/math.pyx":147
1782 * R = R*X2/(K+0.5)
1783 * ER = ER+R
1784 * if (fabs(ER-W) < EPS*fabs(ER)): # <<<<<<<<<<<<<<
1785 * break
1786 * W = ER
1787 */
1788 }
1789
1790 /* "qutip/cy/math.pyx":149
1791 * if (fabs(ER-W) < EPS*fabs(ER)):
1792 * break
1793 * W = ER # <<<<<<<<<<<<<<
1794 * C0 = 2.0/sqrt(pi)*X*exp(-X2)
1795 * ER0 = C0*ER
1796 */
1797 __pyx_v_W = __pyx_v_ER;
1798 }
1799 __pyx_L5_break:;
1800
1801 /* "qutip/cy/math.pyx":150
1802 * break
1803 * W = ER
1804 * C0 = 2.0/sqrt(pi)*X*exp(-X2) # <<<<<<<<<<<<<<
1805 * ER0 = C0*ER
1806 * else:
1807 */
1808 __pyx_v_C0 = (((2.0 / sqrt(M_PI)) * __pyx_v_X) * exp((-__pyx_v_X2)));
1809
1810 /* "qutip/cy/math.pyx":151
1811 * W = ER
1812 * C0 = 2.0/sqrt(pi)*X*exp(-X2)
1813 * ER0 = C0*ER # <<<<<<<<<<<<<<
1814 * else:
1815 * ER = 1.0
1816 */
1817 __pyx_v_ER0 = (__pyx_v_C0 * __pyx_v_ER);
1818
1819 /* "qutip/cy/math.pyx":140
1820 * cdef size_t K, N
1821 *
1822 * if X < 3.5: # <<<<<<<<<<<<<<
1823 * ER = 1.0
1824 * R = 1.0
1825 */
1826 goto __pyx_L3;
1827 }
1828
1829 /* "qutip/cy/math.pyx":153
1830 * ER0 = C0*ER
1831 * else:
1832 * ER = 1.0 # <<<<<<<<<<<<<<
1833 * R=1.0
1834 * for K in range(1, 12):
1835 */
1836 /*else*/ {
1837 __pyx_v_ER = 1.0;
1838
1839 /* "qutip/cy/math.pyx":154
1840 * else:
1841 * ER = 1.0
1842 * R=1.0 # <<<<<<<<<<<<<<
1843 * for K in range(1, 12):
1844 * R = -R*(K-0.5)/X2
1845 */
1846 __pyx_v_R = 1.0;
1847
1848 /* "qutip/cy/math.pyx":155
1849 * ER = 1.0
1850 * R=1.0
1851 * for K in range(1, 12): # <<<<<<<<<<<<<<
1852 * R = -R*(K-0.5)/X2
1853 * ER = ER+R
1854 */
1855 for (__pyx_t_2 = 1; __pyx_t_2 < 12; __pyx_t_2+=1) {
1856 __pyx_v_K = __pyx_t_2;
1857
1858 /* "qutip/cy/math.pyx":156
1859 * R=1.0
1860 * for K in range(1, 12):
1861 * R = -R*(K-0.5)/X2 # <<<<<<<<<<<<<<
1862 * ER = ER+R
1863 * C0 = exp(-X2)/(X*sqrt(pi))
1864 */
1865 __pyx_v_R = (((-__pyx_v_R) * (__pyx_v_K - 0.5)) / __pyx_v_X2);
1866
1867 /* "qutip/cy/math.pyx":157
1868 * for K in range(1, 12):
1869 * R = -R*(K-0.5)/X2
1870 * ER = ER+R # <<<<<<<<<<<<<<
1871 * C0 = exp(-X2)/(X*sqrt(pi))
1872 * ER0 = 1.0-C0*ER
1873 */
1874 __pyx_v_ER = (__pyx_v_ER + __pyx_v_R);
1875 }
1876
1877 /* "qutip/cy/math.pyx":158
1878 * R = -R*(K-0.5)/X2
1879 * ER = ER+R
1880 * C0 = exp(-X2)/(X*sqrt(pi)) # <<<<<<<<<<<<<<
1881 * ER0 = 1.0-C0*ER
1882 *
1883 */
1884 __pyx_v_C0 = (exp((-__pyx_v_X2)) / (__pyx_v_X * sqrt(M_PI)));
1885
1886 /* "qutip/cy/math.pyx":159
1887 * ER = ER+R
1888 * C0 = exp(-X2)/(X*sqrt(pi))
1889 * ER0 = 1.0-C0*ER # <<<<<<<<<<<<<<
1890 *
1891 * if Y == 0.0:
1892 */
1893 __pyx_v_ER0 = (1.0 - (__pyx_v_C0 * __pyx_v_ER));
1894 }
1895 __pyx_L3:;
1896
1897 /* "qutip/cy/math.pyx":161
1898 * ER0 = 1.0-C0*ER
1899 *
1900 * if Y == 0.0: # <<<<<<<<<<<<<<
1901 * ERR = ER0
1902 * ERI = 0.0
1903 */
1904 __pyx_t_1 = ((__pyx_v_Y == 0.0) != 0);
1905 if (__pyx_t_1) {
1906
1907 /* "qutip/cy/math.pyx":162
1908 *
1909 * if Y == 0.0:
1910 * ERR = ER0 # <<<<<<<<<<<<<<
1911 * ERI = 0.0
1912 * else:
1913 */
1914 __pyx_v_ERR = __pyx_v_ER0;
1915
1916 /* "qutip/cy/math.pyx":163
1917 * if Y == 0.0:
1918 * ERR = ER0
1919 * ERI = 0.0 # <<<<<<<<<<<<<<
1920 * else:
1921 * CS = cos(2.0*X*Y)
1922 */
1923 __pyx_v_ERI = 0.0;
1924
1925 /* "qutip/cy/math.pyx":161
1926 * ER0 = 1.0-C0*ER
1927 *
1928 * if Y == 0.0: # <<<<<<<<<<<<<<
1929 * ERR = ER0
1930 * ERI = 0.0
1931 */
1932 goto __pyx_L9;
1933 }
1934
1935 /* "qutip/cy/math.pyx":165
1936 * ERI = 0.0
1937 * else:
1938 * CS = cos(2.0*X*Y) # <<<<<<<<<<<<<<
1939 * SS = sin(2.0*X*Y)
1940 * ER1 = exp(-X2)*(1.0-CS)/(2.0*pi*X)
1941 */
1942 /*else*/ {
1943 __pyx_v_CS = cos(((2.0 * __pyx_v_X) * __pyx_v_Y));
1944
1945 /* "qutip/cy/math.pyx":166
1946 * else:
1947 * CS = cos(2.0*X*Y)
1948 * SS = sin(2.0*X*Y) # <<<<<<<<<<<<<<
1949 * ER1 = exp(-X2)*(1.0-CS)/(2.0*pi*X)
1950 * EI1 = exp(-X2)*SS/(2.0*pi*X)
1951 */
1952 __pyx_v_SS = sin(((2.0 * __pyx_v_X) * __pyx_v_Y));
1953
1954 /* "qutip/cy/math.pyx":167
1955 * CS = cos(2.0*X*Y)
1956 * SS = sin(2.0*X*Y)
1957 * ER1 = exp(-X2)*(1.0-CS)/(2.0*pi*X) # <<<<<<<<<<<<<<
1958 * EI1 = exp(-X2)*SS/(2.0*pi*X)
1959 * ER2 = 0.0
1960 */
1961 __pyx_v_ER1 = ((exp((-__pyx_v_X2)) * (1.0 - __pyx_v_CS)) / ((2.0 * M_PI) * __pyx_v_X));
1962
1963 /* "qutip/cy/math.pyx":168
1964 * SS = sin(2.0*X*Y)
1965 * ER1 = exp(-X2)*(1.0-CS)/(2.0*pi*X)
1966 * EI1 = exp(-X2)*SS/(2.0*pi*X) # <<<<<<<<<<<<<<
1967 * ER2 = 0.0
1968 * W1 = 0.0
1969 */
1970 __pyx_v_EI1 = ((exp((-__pyx_v_X2)) * __pyx_v_SS) / ((2.0 * M_PI) * __pyx_v_X));
1971
1972 /* "qutip/cy/math.pyx":169
1973 * ER1 = exp(-X2)*(1.0-CS)/(2.0*pi*X)
1974 * EI1 = exp(-X2)*SS/(2.0*pi*X)
1975 * ER2 = 0.0 # <<<<<<<<<<<<<<
1976 * W1 = 0.0
1977 *
1978 */
1979 __pyx_v_ER2 = 0.0;
1980
1981 /* "qutip/cy/math.pyx":170
1982 * EI1 = exp(-X2)*SS/(2.0*pi*X)
1983 * ER2 = 0.0
1984 * W1 = 0.0 # <<<<<<<<<<<<<<
1985 *
1986 * for N in range(1,100):
1987 */
1988 __pyx_v_W1 = 0.0;
1989
1990 /* "qutip/cy/math.pyx":172
1991 * W1 = 0.0
1992 *
1993 * for N in range(1,100): # <<<<<<<<<<<<<<
1994 * ER2 = ER2+exp(-.25*N*N)/(N*N+4.0*X2)*(2.0*X-2.0*X*cosh(N*Y)*CS+N*sinh(N*Y)*SS)
1995 * if (fabs((ER2-W1)/ER2) < EPS):
1996 */
1997 for (__pyx_t_2 = 1; __pyx_t_2 < 0x64; __pyx_t_2+=1) {
1998 __pyx_v_N = __pyx_t_2;
1999
2000 /* "qutip/cy/math.pyx":173
2001 *
2002 * for N in range(1,100):
2003 * ER2 = ER2+exp(-.25*N*N)/(N*N+4.0*X2)*(2.0*X-2.0*X*cosh(N*Y)*CS+N*sinh(N*Y)*SS) # <<<<<<<<<<<<<<
2004 * if (fabs((ER2-W1)/ER2) < EPS):
2005 * break
2006 */
2007 __pyx_v_ER2 = (__pyx_v_ER2 + ((exp(((-.25 * __pyx_v_N) * __pyx_v_N)) / ((__pyx_v_N * __pyx_v_N) + (4.0 * __pyx_v_X2))) * (((2.0 * __pyx_v_X) - (((2.0 * __pyx_v_X) * cosh((__pyx_v_N * __pyx_v_Y))) * __pyx_v_CS)) + ((__pyx_v_N * sinh((__pyx_v_N * __pyx_v_Y))) * __pyx_v_SS))));
2008
2009 /* "qutip/cy/math.pyx":174
2010 * for N in range(1,100):
2011 * ER2 = ER2+exp(-.25*N*N)/(N*N+4.0*X2)*(2.0*X-2.0*X*cosh(N*Y)*CS+N*sinh(N*Y)*SS)
2012 * if (fabs((ER2-W1)/ER2) < EPS): # <<<<<<<<<<<<<<
2013 * break
2014 * W1 = ER2
2015 */
2016 __pyx_t_1 = ((fabs(((__pyx_v_ER2 - __pyx_v_W1) / __pyx_v_ER2)) < __pyx_v_EPS) != 0);
2017 if (__pyx_t_1) {
2018
2019 /* "qutip/cy/math.pyx":175
2020 * ER2 = ER2+exp(-.25*N*N)/(N*N+4.0*X2)*(2.0*X-2.0*X*cosh(N*Y)*CS+N*sinh(N*Y)*SS)
2021 * if (fabs((ER2-W1)/ER2) < EPS):
2022 * break # <<<<<<<<<<<<<<
2023 * W1 = ER2
2024 *
2025 */
2026 goto __pyx_L11_break;
2027
2028 /* "qutip/cy/math.pyx":174
2029 * for N in range(1,100):
2030 * ER2 = ER2+exp(-.25*N*N)/(N*N+4.0*X2)*(2.0*X-2.0*X*cosh(N*Y)*CS+N*sinh(N*Y)*SS)
2031 * if (fabs((ER2-W1)/ER2) < EPS): # <<<<<<<<<<<<<<
2032 * break
2033 * W1 = ER2
2034 */
2035 }
2036
2037 /* "qutip/cy/math.pyx":176
2038 * if (fabs((ER2-W1)/ER2) < EPS):
2039 * break
2040 * W1 = ER2 # <<<<<<<<<<<<<<
2041 *
2042 * C0 = 2.0*exp(-X2)/pi
2043 */
2044 __pyx_v_W1 = __pyx_v_ER2;
2045 }
2046 __pyx_L11_break:;
2047
2048 /* "qutip/cy/math.pyx":178
2049 * W1 = ER2
2050 *
2051 * C0 = 2.0*exp(-X2)/pi # <<<<<<<<<<<<<<
2052 * ERR = ER0+ER1+C0*ER2
2053 * EI2 = 0.0
2054 */
2055 __pyx_v_C0 = ((2.0 * exp((-__pyx_v_X2))) / ((double)M_PI));
2056
2057 /* "qutip/cy/math.pyx":179
2058 *
2059 * C0 = 2.0*exp(-X2)/pi
2060 * ERR = ER0+ER1+C0*ER2 # <<<<<<<<<<<<<<
2061 * EI2 = 0.0
2062 * W2 = 0.0
2063 */
2064 __pyx_v_ERR = ((__pyx_v_ER0 + __pyx_v_ER1) + (__pyx_v_C0 * __pyx_v_ER2));
2065
2066 /* "qutip/cy/math.pyx":180
2067 * C0 = 2.0*exp(-X2)/pi
2068 * ERR = ER0+ER1+C0*ER2
2069 * EI2 = 0.0 # <<<<<<<<<<<<<<
2070 * W2 = 0.0
2071 *
2072 */
2073 __pyx_v_EI2 = 0.0;
2074
2075 /* "qutip/cy/math.pyx":181
2076 * ERR = ER0+ER1+C0*ER2
2077 * EI2 = 0.0
2078 * W2 = 0.0 # <<<<<<<<<<<<<<
2079 *
2080 * for N in range(1,100):
2081 */
2082 __pyx_v_W2 = 0.0;
2083
2084 /* "qutip/cy/math.pyx":183
2085 * W2 = 0.0
2086 *
2087 * for N in range(1,100): # <<<<<<<<<<<<<<
2088 * EI2 = EI2+exp(-.25*N*N)/(N*N+4.0*X2)*(2.0*X*cosh(N*Y)*SS+N*sinh(N*Y)*CS)
2089 * if (fabs((EI2-W2)/EI2) < EPS):
2090 */
2091 for (__pyx_t_2 = 1; __pyx_t_2 < 0x64; __pyx_t_2+=1) {
2092 __pyx_v_N = __pyx_t_2;
2093
2094 /* "qutip/cy/math.pyx":184
2095 *
2096 * for N in range(1,100):
2097 * EI2 = EI2+exp(-.25*N*N)/(N*N+4.0*X2)*(2.0*X*cosh(N*Y)*SS+N*sinh(N*Y)*CS) # <<<<<<<<<<<<<<
2098 * if (fabs((EI2-W2)/EI2) < EPS):
2099 * break
2100 */
2101 __pyx_v_EI2 = (__pyx_v_EI2 + ((exp(((-.25 * __pyx_v_N) * __pyx_v_N)) / ((__pyx_v_N * __pyx_v_N) + (4.0 * __pyx_v_X2))) * ((((2.0 * __pyx_v_X) * cosh((__pyx_v_N * __pyx_v_Y))) * __pyx_v_SS) + ((__pyx_v_N * sinh((__pyx_v_N * __pyx_v_Y))) * __pyx_v_CS))));
2102
2103 /* "qutip/cy/math.pyx":185
2104 * for N in range(1,100):
2105 * EI2 = EI2+exp(-.25*N*N)/(N*N+4.0*X2)*(2.0*X*cosh(N*Y)*SS+N*sinh(N*Y)*CS)
2106 * if (fabs((EI2-W2)/EI2) < EPS): # <<<<<<<<<<<<<<
2107 * break
2108 * W2 = EI2
2109 */
2110 __pyx_t_1 = ((fabs(((__pyx_v_EI2 - __pyx_v_W2) / __pyx_v_EI2)) < __pyx_v_EPS) != 0);
2111 if (__pyx_t_1) {
2112
2113 /* "qutip/cy/math.pyx":186
2114 * EI2 = EI2+exp(-.25*N*N)/(N*N+4.0*X2)*(2.0*X*cosh(N*Y)*SS+N*sinh(N*Y)*CS)
2115 * if (fabs((EI2-W2)/EI2) < EPS):
2116 * break # <<<<<<<<<<<<<<
2117 * W2 = EI2
2118 * ERI = EI1+C0*EI2
2119 */
2120 goto __pyx_L14_break;
2121
2122 /* "qutip/cy/math.pyx":185
2123 * for N in range(1,100):
2124 * EI2 = EI2+exp(-.25*N*N)/(N*N+4.0*X2)*(2.0*X*cosh(N*Y)*SS+N*sinh(N*Y)*CS)
2125 * if (fabs((EI2-W2)/EI2) < EPS): # <<<<<<<<<<<<<<
2126 * break
2127 * W2 = EI2
2128 */
2129 }
2130
2131 /* "qutip/cy/math.pyx":187
2132 * if (fabs((EI2-W2)/EI2) < EPS):
2133 * break
2134 * W2 = EI2 # <<<<<<<<<<<<<<
2135 * ERI = EI1+C0*EI2
2136 *
2137 */
2138 __pyx_v_W2 = __pyx_v_EI2;
2139 }
2140 __pyx_L14_break:;
2141
2142 /* "qutip/cy/math.pyx":188
2143 * break
2144 * W2 = EI2
2145 * ERI = EI1+C0*EI2 # <<<<<<<<<<<<<<
2146 *
2147 * return ERR + 1j*ERI
2148 */
2149 __pyx_v_ERI = (__pyx_v_EI1 + (__pyx_v_C0 * __pyx_v_EI2));
2150 }
2151 __pyx_L9:;
2152
2153 /* "qutip/cy/math.pyx":190
2154 * ERI = EI1+C0*EI2
2155 *
2156 * return ERR + 1j*ERI # <<<<<<<<<<<<<<
2157 */
2158 __pyx_r = __Pyx_c_sum_double(__pyx_t_double_complex_from_parts(__pyx_v_ERR, 0), __Pyx_c_prod_double(__pyx_t_double_complex_from_parts(0, 1.0), __pyx_t_double_complex_from_parts(__pyx_v_ERI, 0)));
2159 goto __pyx_L0;
2160
2161 /* "qutip/cy/math.pyx":115
2162 * @cython.cdivision(True)
2163 * @cython.boundscheck(False)
2164 * cdef double complex zerf(double complex Z): # <<<<<<<<<<<<<<
2165 * """
2166 * Parameters
2167 */
2168
2169 /* function exit code */
2170 __pyx_L0:;
2171 __Pyx_RefNannyFinishContext();
2172 return __pyx_r;
2173 }
2174
2175 static PyMethodDef __pyx_methods[] = {
2176 {0, 0, 0, 0}
2177 };
2178
2179 #if PY_MAJOR_VERSION >= 3
2180 #if CYTHON_PEP489_MULTI_PHASE_INIT
2181 static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
2182 static int __pyx_pymod_exec_math(PyObject* module); /*proto*/
2183 static PyModuleDef_Slot __pyx_moduledef_slots[] = {
2184 {Py_mod_create, (void*)__pyx_pymod_create},
2185 {Py_mod_exec, (void*)__pyx_pymod_exec_math},
2186 {0, NULL}
2187 };
2188 #endif
2189
2190 static struct PyModuleDef __pyx_moduledef = {
2191 PyModuleDef_HEAD_INIT,
2192 "math",
2193 0, /* m_doc */
2194 #if CYTHON_PEP489_MULTI_PHASE_INIT
2195 0, /* m_size */
2196 #else
2197 -1, /* m_size */
2198 #endif
2199 __pyx_methods /* m_methods */,
2200 #if CYTHON_PEP489_MULTI_PHASE_INIT
2201 __pyx_moduledef_slots, /* m_slots */
2202 #else
2203 NULL, /* m_reload */
2204 #endif
2205 NULL, /* m_traverse */
2206 NULL, /* m_clear */
2207 NULL /* m_free */
2208 };
2209 #endif
2210 #ifndef CYTHON_SMALL_CODE
2211 #if defined(__clang__)
2212 #define CYTHON_SMALL_CODE
2213 #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
2214 #define CYTHON_SMALL_CODE __attribute__((cold))
2215 #else
2216 #define CYTHON_SMALL_CODE
2217 #endif
2218 #endif
2219
2220 static __Pyx_StringTabEntry __pyx_string_tab[] = {
2221 {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
2222 {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
2223 {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
2224 {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
2225 {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
2226 {0, 0, 0, 0, 0, 0, 0}
2227 };
__Pyx_InitCachedBuiltins(void)2228 static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
2229 __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 144, __pyx_L1_error)
2230 return 0;
2231 __pyx_L1_error:;
2232 return -1;
2233 }
2234
__Pyx_InitCachedConstants(void)2235 static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
2236 __Pyx_RefNannyDeclarations
2237 __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
2238 __Pyx_RefNannyFinishContext();
2239 return 0;
2240 }
2241
__Pyx_InitGlobals(void)2242 static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
2243 if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
2244 return 0;
2245 __pyx_L1_error:;
2246 return -1;
2247 }
2248
2249 static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
2250 static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
2251 static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
2252 static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
2253 static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
2254 static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
2255 static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/
2256
__Pyx_modinit_global_init_code(void)2257 static int __Pyx_modinit_global_init_code(void) {
2258 __Pyx_RefNannyDeclarations
2259 __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
2260 /*--- Global init code ---*/
2261 __Pyx_RefNannyFinishContext();
2262 return 0;
2263 }
2264
__Pyx_modinit_variable_export_code(void)2265 static int __Pyx_modinit_variable_export_code(void) {
2266 __Pyx_RefNannyDeclarations
2267 __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
2268 /*--- Variable export code ---*/
2269 __Pyx_RefNannyFinishContext();
2270 return 0;
2271 }
2272
__Pyx_modinit_function_export_code(void)2273 static int __Pyx_modinit_function_export_code(void) {
2274 __Pyx_RefNannyDeclarations
2275 int __pyx_lineno = 0;
2276 const char *__pyx_filename = NULL;
2277 int __pyx_clineno = 0;
2278 __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
2279 /*--- Function export code ---*/
2280 if (__Pyx_ExportFunction("erf", (void (*)(void))__pyx_f_5qutip_2cy_4math_erf, "double (double)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2281 if (__Pyx_ExportFunction("zerf", (void (*)(void))__pyx_f_5qutip_2cy_4math_zerf, "__pyx_t_double_complex (__pyx_t_double_complex)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2282 __Pyx_RefNannyFinishContext();
2283 return 0;
2284 __pyx_L1_error:;
2285 __Pyx_RefNannyFinishContext();
2286 return -1;
2287 }
2288
__Pyx_modinit_type_init_code(void)2289 static int __Pyx_modinit_type_init_code(void) {
2290 __Pyx_RefNannyDeclarations
2291 __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
2292 /*--- Type init code ---*/
2293 __Pyx_RefNannyFinishContext();
2294 return 0;
2295 }
2296
__Pyx_modinit_type_import_code(void)2297 static int __Pyx_modinit_type_import_code(void) {
2298 __Pyx_RefNannyDeclarations
2299 __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
2300 /*--- Type import code ---*/
2301 __Pyx_RefNannyFinishContext();
2302 return 0;
2303 }
2304
__Pyx_modinit_variable_import_code(void)2305 static int __Pyx_modinit_variable_import_code(void) {
2306 __Pyx_RefNannyDeclarations
2307 __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
2308 /*--- Variable import code ---*/
2309 __Pyx_RefNannyFinishContext();
2310 return 0;
2311 }
2312
__Pyx_modinit_function_import_code(void)2313 static int __Pyx_modinit_function_import_code(void) {
2314 __Pyx_RefNannyDeclarations
2315 __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
2316 /*--- Function import code ---*/
2317 __Pyx_RefNannyFinishContext();
2318 return 0;
2319 }
2320
2321
2322 #ifndef CYTHON_NO_PYINIT_EXPORT
2323 #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
2324 #elif PY_MAJOR_VERSION < 3
2325 #ifdef __cplusplus
2326 #define __Pyx_PyMODINIT_FUNC extern "C" void
2327 #else
2328 #define __Pyx_PyMODINIT_FUNC void
2329 #endif
2330 #else
2331 #ifdef __cplusplus
2332 #define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
2333 #else
2334 #define __Pyx_PyMODINIT_FUNC PyObject *
2335 #endif
2336 #endif
2337
2338
2339 #if PY_MAJOR_VERSION < 3
2340 __Pyx_PyMODINIT_FUNC initmath(void) CYTHON_SMALL_CODE; /*proto*/
initmath(void)2341 __Pyx_PyMODINIT_FUNC initmath(void)
2342 #else
2343 __Pyx_PyMODINIT_FUNC PyInit_math(void) CYTHON_SMALL_CODE; /*proto*/
2344 __Pyx_PyMODINIT_FUNC PyInit_math(void)
2345 #if CYTHON_PEP489_MULTI_PHASE_INIT
2346 {
2347 return PyModuleDef_Init(&__pyx_moduledef);
2348 }
2349 static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
2350 #if PY_VERSION_HEX >= 0x030700A1
2351 static PY_INT64_T main_interpreter_id = -1;
2352 PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
2353 if (main_interpreter_id == -1) {
2354 main_interpreter_id = current_id;
2355 return (unlikely(current_id == -1)) ? -1 : 0;
2356 } else if (unlikely(main_interpreter_id != current_id))
2357 #else
2358 static PyInterpreterState *main_interpreter = NULL;
2359 PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
2360 if (!main_interpreter) {
2361 main_interpreter = current_interpreter;
2362 } else if (unlikely(main_interpreter != current_interpreter))
2363 #endif
2364 {
2365 PyErr_SetString(
2366 PyExc_ImportError,
2367 "Interpreter change detected - this module can only be loaded into one interpreter per process.");
2368 return -1;
2369 }
2370 return 0;
2371 }
2372 static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) {
2373 PyObject *value = PyObject_GetAttrString(spec, from_name);
2374 int result = 0;
2375 if (likely(value)) {
2376 if (allow_none || value != Py_None) {
2377 result = PyDict_SetItemString(moddict, to_name, value);
2378 }
2379 Py_DECREF(value);
2380 } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
2381 PyErr_Clear();
2382 } else {
2383 result = -1;
2384 }
2385 return result;
2386 }
2387 static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
2388 PyObject *module = NULL, *moddict, *modname;
2389 if (__Pyx_check_single_interpreter())
2390 return NULL;
2391 if (__pyx_m)
2392 return __Pyx_NewRef(__pyx_m);
2393 modname = PyObject_GetAttrString(spec, "name");
2394 if (unlikely(!modname)) goto bad;
2395 module = PyModule_NewObject(modname);
2396 Py_DECREF(modname);
2397 if (unlikely(!module)) goto bad;
2398 moddict = PyModule_GetDict(module);
2399 if (unlikely(!moddict)) goto bad;
2400 if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
2401 if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
2402 if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
2403 if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
2404 return module;
2405 bad:
2406 Py_XDECREF(module);
2407 return NULL;
2408 }
2409
2410
2411 static CYTHON_SMALL_CODE int __pyx_pymod_exec_math(PyObject *__pyx_pyinit_module)
2412 #endif
2413 #endif
2414 {
2415 PyObject *__pyx_t_1 = NULL;
2416 int __pyx_lineno = 0;
2417 const char *__pyx_filename = NULL;
2418 int __pyx_clineno = 0;
2419 __Pyx_RefNannyDeclarations
2420 #if CYTHON_PEP489_MULTI_PHASE_INIT
2421 if (__pyx_m) {
2422 if (__pyx_m == __pyx_pyinit_module) return 0;
2423 PyErr_SetString(PyExc_RuntimeError, "Module 'math' has already been imported. Re-initialisation is not supported.");
2424 return -1;
2425 }
2426 #elif PY_MAJOR_VERSION >= 3
2427 if (__pyx_m) return __Pyx_NewRef(__pyx_m);
2428 #endif
2429 #if CYTHON_REFNANNY
2430 __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
2431 if (!__Pyx_RefNanny) {
2432 PyErr_Clear();
2433 __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
2434 if (!__Pyx_RefNanny)
2435 Py_FatalError("failed to import 'refnanny' module");
2436 }
2437 #endif
2438 __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_math(void)", 0);
2439 if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2440 #ifdef __Pxy_PyFrame_Initialize_Offsets
2441 __Pxy_PyFrame_Initialize_Offsets();
2442 #endif
2443 __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
2444 __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
2445 __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
2446 #ifdef __Pyx_CyFunction_USED
2447 if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2448 #endif
2449 #ifdef __Pyx_FusedFunction_USED
2450 if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2451 #endif
2452 #ifdef __Pyx_Coroutine_USED
2453 if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2454 #endif
2455 #ifdef __Pyx_Generator_USED
2456 if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2457 #endif
2458 #ifdef __Pyx_AsyncGen_USED
2459 if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2460 #endif
2461 #ifdef __Pyx_StopAsyncIteration_USED
2462 if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2463 #endif
2464 /*--- Library function declarations ---*/
2465 /*--- Threads initialization code ---*/
2466 #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
2467 #ifdef WITH_THREAD /* Python build with threading support? */
2468 PyEval_InitThreads();
2469 #endif
2470 #endif
2471 /*--- Module creation code ---*/
2472 #if CYTHON_PEP489_MULTI_PHASE_INIT
2473 __pyx_m = __pyx_pyinit_module;
2474 Py_INCREF(__pyx_m);
2475 #else
2476 #if PY_MAJOR_VERSION < 3
2477 __pyx_m = Py_InitModule4("math", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
2478 #else
2479 __pyx_m = PyModule_Create(&__pyx_moduledef);
2480 #endif
2481 if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
2482 #endif
2483 __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
2484 Py_INCREF(__pyx_d);
2485 __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
2486 Py_INCREF(__pyx_b);
2487 __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
2488 Py_INCREF(__pyx_cython_runtime);
2489 if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
2490 /*--- Initialize various global constants etc. ---*/
2491 if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2492 #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
2493 if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2494 #endif
2495 if (__pyx_module_is_main_qutip__cy__math) {
2496 if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2497 }
2498 #if PY_MAJOR_VERSION >= 3
2499 {
2500 PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
2501 if (!PyDict_GetItemString(modules, "qutip.cy.math")) {
2502 if (unlikely(PyDict_SetItemString(modules, "qutip.cy.math", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
2503 }
2504 }
2505 #endif
2506 /*--- Builtin init code ---*/
2507 if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2508 /*--- Constants init code ---*/
2509 if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2510 /*--- Global type/function init code ---*/
2511 (void)__Pyx_modinit_global_init_code();
2512 (void)__Pyx_modinit_variable_export_code();
2513 if (unlikely(__Pyx_modinit_function_export_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
2514 (void)__Pyx_modinit_type_init_code();
2515 (void)__Pyx_modinit_type_import_code();
2516 (void)__Pyx_modinit_variable_import_code();
2517 (void)__Pyx_modinit_function_import_code();
2518 /*--- Execution code ---*/
2519 #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
2520 if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2521 #endif
2522
2523 /* "qutip/cy/math.pyx":1
2524 * #cython: language_level=3 # <<<<<<<<<<<<<<
2525 * # This file is part of QuTiP: Quantum Toolbox in Python.
2526 * #
2527 */
2528 __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
2529 __Pyx_GOTREF(__pyx_t_1);
2530 if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2531 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2532
2533 /*--- Wrapped vars code ---*/
2534
2535 goto __pyx_L0;
2536 __pyx_L1_error:;
2537 __Pyx_XDECREF(__pyx_t_1);
2538 if (__pyx_m) {
2539 if (__pyx_d) {
2540 __Pyx_AddTraceback("init qutip.cy.math", __pyx_clineno, __pyx_lineno, __pyx_filename);
2541 }
2542 Py_CLEAR(__pyx_m);
2543 } else if (!PyErr_Occurred()) {
2544 PyErr_SetString(PyExc_ImportError, "init qutip.cy.math");
2545 }
2546 __pyx_L0:;
2547 __Pyx_RefNannyFinishContext();
2548 #if CYTHON_PEP489_MULTI_PHASE_INIT
2549 return (__pyx_m != NULL) ? 0 : -1;
2550 #elif PY_MAJOR_VERSION >= 3
2551 return __pyx_m;
2552 #else
2553 return;
2554 #endif
2555 }
2556
2557 /* --- Runtime support code --- */
2558 /* Refnanny */
2559 #if CYTHON_REFNANNY
__Pyx_RefNannyImportAPI(const char * modname)2560 static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
2561 PyObject *m = NULL, *p = NULL;
2562 void *r = NULL;
2563 m = PyImport_ImportModule(modname);
2564 if (!m) goto end;
2565 p = PyObject_GetAttrString(m, "RefNannyAPI");
2566 if (!p) goto end;
2567 r = PyLong_AsVoidPtr(p);
2568 end:
2569 Py_XDECREF(p);
2570 Py_XDECREF(m);
2571 return (__Pyx_RefNannyAPIStruct *)r;
2572 }
2573 #endif
2574
2575 /* PyObjectGetAttrStr */
2576 #if CYTHON_USE_TYPE_SLOTS
__Pyx_PyObject_GetAttrStr(PyObject * obj,PyObject * attr_name)2577 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
2578 PyTypeObject* tp = Py_TYPE(obj);
2579 if (likely(tp->tp_getattro))
2580 return tp->tp_getattro(obj, attr_name);
2581 #if PY_MAJOR_VERSION < 3
2582 if (likely(tp->tp_getattr))
2583 return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
2584 #endif
2585 return PyObject_GetAttr(obj, attr_name);
2586 }
2587 #endif
2588
2589 /* GetBuiltinName */
__Pyx_GetBuiltinName(PyObject * name)2590 static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
2591 PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
2592 if (unlikely(!result)) {
2593 PyErr_Format(PyExc_NameError,
2594 #if PY_MAJOR_VERSION >= 3
2595 "name '%U' is not defined", name);
2596 #else
2597 "name '%.200s' is not defined", PyString_AS_STRING(name));
2598 #endif
2599 }
2600 return result;
2601 }
2602
2603 /* PyDictVersioning */
2604 #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
__Pyx_get_tp_dict_version(PyObject * obj)2605 static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
2606 PyObject *dict = Py_TYPE(obj)->tp_dict;
2607 return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
2608 }
__Pyx_get_object_dict_version(PyObject * obj)2609 static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
2610 PyObject **dictptr = NULL;
2611 Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
2612 if (offset) {
2613 #if CYTHON_COMPILING_IN_CPYTHON
2614 dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
2615 #else
2616 dictptr = _PyObject_GetDictPtr(obj);
2617 #endif
2618 }
2619 return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
2620 }
__Pyx_object_dict_version_matches(PyObject * obj,PY_UINT64_T tp_dict_version,PY_UINT64_T obj_dict_version)2621 static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
2622 PyObject *dict = Py_TYPE(obj)->tp_dict;
2623 if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
2624 return 0;
2625 return obj_dict_version == __Pyx_get_object_dict_version(obj);
2626 }
2627 #endif
2628
2629 /* PyErrFetchRestore */
2630 #if CYTHON_FAST_THREAD_STATE
__Pyx_ErrRestoreInState(PyThreadState * tstate,PyObject * type,PyObject * value,PyObject * tb)2631 static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
2632 PyObject *tmp_type, *tmp_value, *tmp_tb;
2633 tmp_type = tstate->curexc_type;
2634 tmp_value = tstate->curexc_value;
2635 tmp_tb = tstate->curexc_traceback;
2636 tstate->curexc_type = type;
2637 tstate->curexc_value = value;
2638 tstate->curexc_traceback = tb;
2639 Py_XDECREF(tmp_type);
2640 Py_XDECREF(tmp_value);
2641 Py_XDECREF(tmp_tb);
2642 }
__Pyx_ErrFetchInState(PyThreadState * tstate,PyObject ** type,PyObject ** value,PyObject ** tb)2643 static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
2644 *type = tstate->curexc_type;
2645 *value = tstate->curexc_value;
2646 *tb = tstate->curexc_traceback;
2647 tstate->curexc_type = 0;
2648 tstate->curexc_value = 0;
2649 tstate->curexc_traceback = 0;
2650 }
2651 #endif
2652
2653 /* CLineInTraceback */
2654 #ifndef CYTHON_CLINE_IN_TRACEBACK
__Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState * tstate,int c_line)2655 static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) {
2656 PyObject *use_cline;
2657 PyObject *ptype, *pvalue, *ptraceback;
2658 #if CYTHON_COMPILING_IN_CPYTHON
2659 PyObject **cython_runtime_dict;
2660 #endif
2661 if (unlikely(!__pyx_cython_runtime)) {
2662 return c_line;
2663 }
2664 __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
2665 #if CYTHON_COMPILING_IN_CPYTHON
2666 cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
2667 if (likely(cython_runtime_dict)) {
2668 __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
2669 use_cline, *cython_runtime_dict,
2670 __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
2671 } else
2672 #endif
2673 {
2674 PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
2675 if (use_cline_obj) {
2676 use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
2677 Py_DECREF(use_cline_obj);
2678 } else {
2679 PyErr_Clear();
2680 use_cline = NULL;
2681 }
2682 }
2683 if (!use_cline) {
2684 c_line = 0;
2685 PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
2686 }
2687 else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
2688 c_line = 0;
2689 }
2690 __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
2691 return c_line;
2692 }
2693 #endif
2694
2695 /* CodeObjectCache */
__pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry * entries,int count,int code_line)2696 static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
2697 int start = 0, mid = 0, end = count - 1;
2698 if (end >= 0 && code_line > entries[end].code_line) {
2699 return count;
2700 }
2701 while (start < end) {
2702 mid = start + (end - start) / 2;
2703 if (code_line < entries[mid].code_line) {
2704 end = mid;
2705 } else if (code_line > entries[mid].code_line) {
2706 start = mid + 1;
2707 } else {
2708 return mid;
2709 }
2710 }
2711 if (code_line <= entries[mid].code_line) {
2712 return mid;
2713 } else {
2714 return mid + 1;
2715 }
2716 }
__pyx_find_code_object(int code_line)2717 static PyCodeObject *__pyx_find_code_object(int code_line) {
2718 PyCodeObject* code_object;
2719 int pos;
2720 if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
2721 return NULL;
2722 }
2723 pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
2724 if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
2725 return NULL;
2726 }
2727 code_object = __pyx_code_cache.entries[pos].code_object;
2728 Py_INCREF(code_object);
2729 return code_object;
2730 }
__pyx_insert_code_object(int code_line,PyCodeObject * code_object)2731 static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
2732 int pos, i;
2733 __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
2734 if (unlikely(!code_line)) {
2735 return;
2736 }
2737 if (unlikely(!entries)) {
2738 entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
2739 if (likely(entries)) {
2740 __pyx_code_cache.entries = entries;
2741 __pyx_code_cache.max_count = 64;
2742 __pyx_code_cache.count = 1;
2743 entries[0].code_line = code_line;
2744 entries[0].code_object = code_object;
2745 Py_INCREF(code_object);
2746 }
2747 return;
2748 }
2749 pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
2750 if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
2751 PyCodeObject* tmp = entries[pos].code_object;
2752 entries[pos].code_object = code_object;
2753 Py_DECREF(tmp);
2754 return;
2755 }
2756 if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
2757 int new_max = __pyx_code_cache.max_count + 64;
2758 entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
2759 __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry));
2760 if (unlikely(!entries)) {
2761 return;
2762 }
2763 __pyx_code_cache.entries = entries;
2764 __pyx_code_cache.max_count = new_max;
2765 }
2766 for (i=__pyx_code_cache.count; i>pos; i--) {
2767 entries[i] = entries[i-1];
2768 }
2769 entries[pos].code_line = code_line;
2770 entries[pos].code_object = code_object;
2771 __pyx_code_cache.count++;
2772 Py_INCREF(code_object);
2773 }
2774
2775 /* AddTraceback */
2776 #include "compile.h"
2777 #include "frameobject.h"
2778 #include "traceback.h"
__Pyx_CreateCodeObjectForTraceback(const char * funcname,int c_line,int py_line,const char * filename)2779 static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
2780 const char *funcname, int c_line,
2781 int py_line, const char *filename) {
2782 PyCodeObject *py_code = 0;
2783 PyObject *py_srcfile = 0;
2784 PyObject *py_funcname = 0;
2785 #if PY_MAJOR_VERSION < 3
2786 py_srcfile = PyString_FromString(filename);
2787 #else
2788 py_srcfile = PyUnicode_FromString(filename);
2789 #endif
2790 if (!py_srcfile) goto bad;
2791 if (c_line) {
2792 #if PY_MAJOR_VERSION < 3
2793 py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
2794 #else
2795 py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
2796 #endif
2797 }
2798 else {
2799 #if PY_MAJOR_VERSION < 3
2800 py_funcname = PyString_FromString(funcname);
2801 #else
2802 py_funcname = PyUnicode_FromString(funcname);
2803 #endif
2804 }
2805 if (!py_funcname) goto bad;
2806 py_code = __Pyx_PyCode_New(
2807 0,
2808 0,
2809 0,
2810 0,
2811 0,
2812 __pyx_empty_bytes, /*PyObject *code,*/
2813 __pyx_empty_tuple, /*PyObject *consts,*/
2814 __pyx_empty_tuple, /*PyObject *names,*/
2815 __pyx_empty_tuple, /*PyObject *varnames,*/
2816 __pyx_empty_tuple, /*PyObject *freevars,*/
2817 __pyx_empty_tuple, /*PyObject *cellvars,*/
2818 py_srcfile, /*PyObject *filename,*/
2819 py_funcname, /*PyObject *name,*/
2820 py_line,
2821 __pyx_empty_bytes /*PyObject *lnotab*/
2822 );
2823 Py_DECREF(py_srcfile);
2824 Py_DECREF(py_funcname);
2825 return py_code;
2826 bad:
2827 Py_XDECREF(py_srcfile);
2828 Py_XDECREF(py_funcname);
2829 return NULL;
2830 }
__Pyx_AddTraceback(const char * funcname,int c_line,int py_line,const char * filename)2831 static void __Pyx_AddTraceback(const char *funcname, int c_line,
2832 int py_line, const char *filename) {
2833 PyCodeObject *py_code = 0;
2834 PyFrameObject *py_frame = 0;
2835 PyThreadState *tstate = __Pyx_PyThreadState_Current;
2836 if (c_line) {
2837 c_line = __Pyx_CLineForTraceback(tstate, c_line);
2838 }
2839 py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
2840 if (!py_code) {
2841 py_code = __Pyx_CreateCodeObjectForTraceback(
2842 funcname, c_line, py_line, filename);
2843 if (!py_code) goto bad;
2844 __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
2845 }
2846 py_frame = PyFrame_New(
2847 tstate, /*PyThreadState *tstate,*/
2848 py_code, /*PyCodeObject *code,*/
2849 __pyx_d, /*PyObject *globals,*/
2850 0 /*PyObject *locals*/
2851 );
2852 if (!py_frame) goto bad;
2853 __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
2854 PyTraceBack_Here(py_frame);
2855 bad:
2856 Py_XDECREF(py_code);
2857 Py_XDECREF(py_frame);
2858 }
2859
2860 /* Declarations */
2861 #if CYTHON_CCOMPLEX
2862 #ifdef __cplusplus
__pyx_t_double_complex_from_parts(double x,double y)2863 static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
2864 return ::std::complex< double >(x, y);
2865 }
2866 #else
__pyx_t_double_complex_from_parts(double x,double y)2867 static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
2868 return x + y*(__pyx_t_double_complex)_Complex_I;
2869 }
2870 #endif
2871 #else
__pyx_t_double_complex_from_parts(double x,double y)2872 static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
2873 __pyx_t_double_complex z;
2874 z.real = x;
2875 z.imag = y;
2876 return z;
2877 }
2878 #endif
2879
2880 /* Arithmetic */
2881 #if CYTHON_CCOMPLEX
2882 #else
__Pyx_c_eq_double(__pyx_t_double_complex a,__pyx_t_double_complex b)2883 static CYTHON_INLINE int __Pyx_c_eq_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
2884 return (a.real == b.real) && (a.imag == b.imag);
2885 }
__Pyx_c_sum_double(__pyx_t_double_complex a,__pyx_t_double_complex b)2886 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
2887 __pyx_t_double_complex z;
2888 z.real = a.real + b.real;
2889 z.imag = a.imag + b.imag;
2890 return z;
2891 }
__Pyx_c_diff_double(__pyx_t_double_complex a,__pyx_t_double_complex b)2892 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
2893 __pyx_t_double_complex z;
2894 z.real = a.real - b.real;
2895 z.imag = a.imag - b.imag;
2896 return z;
2897 }
__Pyx_c_prod_double(__pyx_t_double_complex a,__pyx_t_double_complex b)2898 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
2899 __pyx_t_double_complex z;
2900 z.real = a.real * b.real - a.imag * b.imag;
2901 z.imag = a.real * b.imag + a.imag * b.real;
2902 return z;
2903 }
2904 #if 1
__Pyx_c_quot_double(__pyx_t_double_complex a,__pyx_t_double_complex b)2905 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
2906 if (b.imag == 0) {
2907 return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.real);
2908 } else if (fabs(b.real) >= fabs(b.imag)) {
2909 if (b.real == 0 && b.imag == 0) {
2910 return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.imag);
2911 } else {
2912 double r = b.imag / b.real;
2913 double s = (double)(1.0) / (b.real + b.imag * r);
2914 return __pyx_t_double_complex_from_parts(
2915 (a.real + a.imag * r) * s, (a.imag - a.real * r) * s);
2916 }
2917 } else {
2918 double r = b.real / b.imag;
2919 double s = (double)(1.0) / (b.imag + b.real * r);
2920 return __pyx_t_double_complex_from_parts(
2921 (a.real * r + a.imag) * s, (a.imag * r - a.real) * s);
2922 }
2923 }
2924 #else
__Pyx_c_quot_double(__pyx_t_double_complex a,__pyx_t_double_complex b)2925 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
2926 if (b.imag == 0) {
2927 return __pyx_t_double_complex_from_parts(a.real / b.real, a.imag / b.real);
2928 } else {
2929 double denom = b.real * b.real + b.imag * b.imag;
2930 return __pyx_t_double_complex_from_parts(
2931 (a.real * b.real + a.imag * b.imag) / denom,
2932 (a.imag * b.real - a.real * b.imag) / denom);
2933 }
2934 }
2935 #endif
__Pyx_c_neg_double(__pyx_t_double_complex a)2936 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg_double(__pyx_t_double_complex a) {
2937 __pyx_t_double_complex z;
2938 z.real = -a.real;
2939 z.imag = -a.imag;
2940 return z;
2941 }
__Pyx_c_is_zero_double(__pyx_t_double_complex a)2942 static CYTHON_INLINE int __Pyx_c_is_zero_double(__pyx_t_double_complex a) {
2943 return (a.real == 0) && (a.imag == 0);
2944 }
__Pyx_c_conj_double(__pyx_t_double_complex a)2945 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj_double(__pyx_t_double_complex a) {
2946 __pyx_t_double_complex z;
2947 z.real = a.real;
2948 z.imag = -a.imag;
2949 return z;
2950 }
2951 #if 1
__Pyx_c_abs_double(__pyx_t_double_complex z)2952 static CYTHON_INLINE double __Pyx_c_abs_double(__pyx_t_double_complex z) {
2953 #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
2954 return sqrt(z.real*z.real + z.imag*z.imag);
2955 #else
2956 return hypot(z.real, z.imag);
2957 #endif
2958 }
__Pyx_c_pow_double(__pyx_t_double_complex a,__pyx_t_double_complex b)2959 static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow_double(__pyx_t_double_complex a, __pyx_t_double_complex b) {
2960 __pyx_t_double_complex z;
2961 double r, lnr, theta, z_r, z_theta;
2962 if (b.imag == 0 && b.real == (int)b.real) {
2963 if (b.real < 0) {
2964 double denom = a.real * a.real + a.imag * a.imag;
2965 a.real = a.real / denom;
2966 a.imag = -a.imag / denom;
2967 b.real = -b.real;
2968 }
2969 switch ((int)b.real) {
2970 case 0:
2971 z.real = 1;
2972 z.imag = 0;
2973 return z;
2974 case 1:
2975 return a;
2976 case 2:
2977 return __Pyx_c_prod_double(a, a);
2978 case 3:
2979 z = __Pyx_c_prod_double(a, a);
2980 return __Pyx_c_prod_double(z, a);
2981 case 4:
2982 z = __Pyx_c_prod_double(a, a);
2983 return __Pyx_c_prod_double(z, z);
2984 }
2985 }
2986 if (a.imag == 0) {
2987 if (a.real == 0) {
2988 return a;
2989 } else if (b.imag == 0) {
2990 z.real = pow(a.real, b.real);
2991 z.imag = 0;
2992 return z;
2993 } else if (a.real > 0) {
2994 r = a.real;
2995 theta = 0;
2996 } else {
2997 r = -a.real;
2998 theta = atan2(0.0, -1.0);
2999 }
3000 } else {
3001 r = __Pyx_c_abs_double(a);
3002 theta = atan2(a.imag, a.real);
3003 }
3004 lnr = log(r);
3005 z_r = exp(lnr * b.real - theta * b.imag);
3006 z_theta = theta * b.real + lnr * b.imag;
3007 z.real = z_r * cos(z_theta);
3008 z.imag = z_r * sin(z_theta);
3009 return z;
3010 }
3011 #endif
3012 #endif
3013
3014 /* CIntFromPyVerify */
3015 #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
3016 __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
3017 #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
3018 __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
3019 #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
3020 {\
3021 func_type value = func_value;\
3022 if (sizeof(target_type) < sizeof(func_type)) {\
3023 if (unlikely(value != (func_type) (target_type) value)) {\
3024 func_type zero = 0;\
3025 if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
3026 return (target_type) -1;\
3027 if (is_unsigned && unlikely(value < zero))\
3028 goto raise_neg_overflow;\
3029 else\
3030 goto raise_overflow;\
3031 }\
3032 }\
3033 return (target_type) value;\
3034 }
3035
3036 /* CIntFromPy */
__Pyx_PyInt_As_size_t(PyObject * x)3037 static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) {
3038 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
3039 #pragma GCC diagnostic push
3040 #pragma GCC diagnostic ignored "-Wconversion"
3041 #endif
3042 const size_t neg_one = (size_t) -1, const_zero = (size_t) 0;
3043 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
3044 #pragma GCC diagnostic pop
3045 #endif
3046 const int is_unsigned = neg_one > const_zero;
3047 #if PY_MAJOR_VERSION < 3
3048 if (likely(PyInt_Check(x))) {
3049 if (sizeof(size_t) < sizeof(long)) {
3050 __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG(x))
3051 } else {
3052 long val = PyInt_AS_LONG(x);
3053 if (is_unsigned && unlikely(val < 0)) {
3054 goto raise_neg_overflow;
3055 }
3056 return (size_t) val;
3057 }
3058 } else
3059 #endif
3060 if (likely(PyLong_Check(x))) {
3061 if (is_unsigned) {
3062 #if CYTHON_USE_PYLONG_INTERNALS
3063 const digit* digits = ((PyLongObject*)x)->ob_digit;
3064 switch (Py_SIZE(x)) {
3065 case 0: return (size_t) 0;
3066 case 1: __PYX_VERIFY_RETURN_INT(size_t, digit, digits[0])
3067 case 2:
3068 if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
3069 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3070 __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3071 } else if (8 * sizeof(size_t) >= 2 * PyLong_SHIFT) {
3072 return (size_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
3073 }
3074 }
3075 break;
3076 case 3:
3077 if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
3078 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3079 __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3080 } else if (8 * sizeof(size_t) >= 3 * PyLong_SHIFT) {
3081 return (size_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
3082 }
3083 }
3084 break;
3085 case 4:
3086 if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
3087 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3088 __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3089 } else if (8 * sizeof(size_t) >= 4 * PyLong_SHIFT) {
3090 return (size_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
3091 }
3092 }
3093 break;
3094 }
3095 #endif
3096 #if CYTHON_COMPILING_IN_CPYTHON
3097 if (unlikely(Py_SIZE(x) < 0)) {
3098 goto raise_neg_overflow;
3099 }
3100 #else
3101 {
3102 int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
3103 if (unlikely(result < 0))
3104 return (size_t) -1;
3105 if (unlikely(result == 1))
3106 goto raise_neg_overflow;
3107 }
3108 #endif
3109 if (sizeof(size_t) <= sizeof(unsigned long)) {
3110 __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned long, PyLong_AsUnsignedLong(x))
3111 #ifdef HAVE_LONG_LONG
3112 } else if (sizeof(size_t) <= sizeof(unsigned PY_LONG_LONG)) {
3113 __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
3114 #endif
3115 }
3116 } else {
3117 #if CYTHON_USE_PYLONG_INTERNALS
3118 const digit* digits = ((PyLongObject*)x)->ob_digit;
3119 switch (Py_SIZE(x)) {
3120 case 0: return (size_t) 0;
3121 case -1: __PYX_VERIFY_RETURN_INT(size_t, sdigit, (sdigit) (-(sdigit)digits[0]))
3122 case 1: __PYX_VERIFY_RETURN_INT(size_t, digit, +digits[0])
3123 case -2:
3124 if (8 * sizeof(size_t) - 1 > 1 * PyLong_SHIFT) {
3125 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3126 __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3127 } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
3128 return (size_t) (((size_t)-1)*(((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
3129 }
3130 }
3131 break;
3132 case 2:
3133 if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
3134 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3135 __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3136 } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
3137 return (size_t) ((((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
3138 }
3139 }
3140 break;
3141 case -3:
3142 if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
3143 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3144 __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3145 } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
3146 return (size_t) (((size_t)-1)*(((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
3147 }
3148 }
3149 break;
3150 case 3:
3151 if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
3152 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3153 __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3154 } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
3155 return (size_t) ((((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
3156 }
3157 }
3158 break;
3159 case -4:
3160 if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
3161 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3162 __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3163 } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) {
3164 return (size_t) (((size_t)-1)*(((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
3165 }
3166 }
3167 break;
3168 case 4:
3169 if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
3170 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3171 __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3172 } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) {
3173 return (size_t) ((((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
3174 }
3175 }
3176 break;
3177 }
3178 #endif
3179 if (sizeof(size_t) <= sizeof(long)) {
3180 __PYX_VERIFY_RETURN_INT_EXC(size_t, long, PyLong_AsLong(x))
3181 #ifdef HAVE_LONG_LONG
3182 } else if (sizeof(size_t) <= sizeof(PY_LONG_LONG)) {
3183 __PYX_VERIFY_RETURN_INT_EXC(size_t, PY_LONG_LONG, PyLong_AsLongLong(x))
3184 #endif
3185 }
3186 }
3187 {
3188 #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
3189 PyErr_SetString(PyExc_RuntimeError,
3190 "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
3191 #else
3192 size_t val;
3193 PyObject *v = __Pyx_PyNumber_IntOrLong(x);
3194 #if PY_MAJOR_VERSION < 3
3195 if (likely(v) && !PyLong_Check(v)) {
3196 PyObject *tmp = v;
3197 v = PyNumber_Long(tmp);
3198 Py_DECREF(tmp);
3199 }
3200 #endif
3201 if (likely(v)) {
3202 int one = 1; int is_little = (int)*(unsigned char *)&one;
3203 unsigned char *bytes = (unsigned char *)&val;
3204 int ret = _PyLong_AsByteArray((PyLongObject *)v,
3205 bytes, sizeof(val),
3206 is_little, !is_unsigned);
3207 Py_DECREF(v);
3208 if (likely(!ret))
3209 return val;
3210 }
3211 #endif
3212 return (size_t) -1;
3213 }
3214 } else {
3215 size_t val;
3216 PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
3217 if (!tmp) return (size_t) -1;
3218 val = __Pyx_PyInt_As_size_t(tmp);
3219 Py_DECREF(tmp);
3220 return val;
3221 }
3222 raise_overflow:
3223 PyErr_SetString(PyExc_OverflowError,
3224 "value too large to convert to size_t");
3225 return (size_t) -1;
3226 raise_neg_overflow:
3227 PyErr_SetString(PyExc_OverflowError,
3228 "can't convert negative value to size_t");
3229 return (size_t) -1;
3230 }
3231
3232 /* CIntToPy */
__Pyx_PyInt_From_long(long value)3233 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
3234 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
3235 #pragma GCC diagnostic push
3236 #pragma GCC diagnostic ignored "-Wconversion"
3237 #endif
3238 const long neg_one = (long) -1, const_zero = (long) 0;
3239 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
3240 #pragma GCC diagnostic pop
3241 #endif
3242 const int is_unsigned = neg_one > const_zero;
3243 if (is_unsigned) {
3244 if (sizeof(long) < sizeof(long)) {
3245 return PyInt_FromLong((long) value);
3246 } else if (sizeof(long) <= sizeof(unsigned long)) {
3247 return PyLong_FromUnsignedLong((unsigned long) value);
3248 #ifdef HAVE_LONG_LONG
3249 } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
3250 return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
3251 #endif
3252 }
3253 } else {
3254 if (sizeof(long) <= sizeof(long)) {
3255 return PyInt_FromLong((long) value);
3256 #ifdef HAVE_LONG_LONG
3257 } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
3258 return PyLong_FromLongLong((PY_LONG_LONG) value);
3259 #endif
3260 }
3261 }
3262 {
3263 int one = 1; int little = (int)*(unsigned char *)&one;
3264 unsigned char *bytes = (unsigned char *)&value;
3265 return _PyLong_FromByteArray(bytes, sizeof(long),
3266 little, !is_unsigned);
3267 }
3268 }
3269
3270 /* CIntFromPy */
__Pyx_PyInt_As_long(PyObject * x)3271 static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
3272 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
3273 #pragma GCC diagnostic push
3274 #pragma GCC diagnostic ignored "-Wconversion"
3275 #endif
3276 const long neg_one = (long) -1, const_zero = (long) 0;
3277 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
3278 #pragma GCC diagnostic pop
3279 #endif
3280 const int is_unsigned = neg_one > const_zero;
3281 #if PY_MAJOR_VERSION < 3
3282 if (likely(PyInt_Check(x))) {
3283 if (sizeof(long) < sizeof(long)) {
3284 __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
3285 } else {
3286 long val = PyInt_AS_LONG(x);
3287 if (is_unsigned && unlikely(val < 0)) {
3288 goto raise_neg_overflow;
3289 }
3290 return (long) val;
3291 }
3292 } else
3293 #endif
3294 if (likely(PyLong_Check(x))) {
3295 if (is_unsigned) {
3296 #if CYTHON_USE_PYLONG_INTERNALS
3297 const digit* digits = ((PyLongObject*)x)->ob_digit;
3298 switch (Py_SIZE(x)) {
3299 case 0: return (long) 0;
3300 case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
3301 case 2:
3302 if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
3303 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3304 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3305 } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
3306 return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
3307 }
3308 }
3309 break;
3310 case 3:
3311 if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
3312 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3313 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3314 } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
3315 return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
3316 }
3317 }
3318 break;
3319 case 4:
3320 if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
3321 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3322 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3323 } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
3324 return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
3325 }
3326 }
3327 break;
3328 }
3329 #endif
3330 #if CYTHON_COMPILING_IN_CPYTHON
3331 if (unlikely(Py_SIZE(x) < 0)) {
3332 goto raise_neg_overflow;
3333 }
3334 #else
3335 {
3336 int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
3337 if (unlikely(result < 0))
3338 return (long) -1;
3339 if (unlikely(result == 1))
3340 goto raise_neg_overflow;
3341 }
3342 #endif
3343 if (sizeof(long) <= sizeof(unsigned long)) {
3344 __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
3345 #ifdef HAVE_LONG_LONG
3346 } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
3347 __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
3348 #endif
3349 }
3350 } else {
3351 #if CYTHON_USE_PYLONG_INTERNALS
3352 const digit* digits = ((PyLongObject*)x)->ob_digit;
3353 switch (Py_SIZE(x)) {
3354 case 0: return (long) 0;
3355 case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
3356 case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0])
3357 case -2:
3358 if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
3359 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3360 __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3361 } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
3362 return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
3363 }
3364 }
3365 break;
3366 case 2:
3367 if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
3368 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3369 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3370 } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
3371 return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
3372 }
3373 }
3374 break;
3375 case -3:
3376 if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
3377 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3378 __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3379 } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
3380 return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
3381 }
3382 }
3383 break;
3384 case 3:
3385 if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
3386 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3387 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3388 } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
3389 return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
3390 }
3391 }
3392 break;
3393 case -4:
3394 if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
3395 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3396 __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3397 } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
3398 return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
3399 }
3400 }
3401 break;
3402 case 4:
3403 if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
3404 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3405 __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3406 } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
3407 return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
3408 }
3409 }
3410 break;
3411 }
3412 #endif
3413 if (sizeof(long) <= sizeof(long)) {
3414 __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
3415 #ifdef HAVE_LONG_LONG
3416 } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
3417 __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
3418 #endif
3419 }
3420 }
3421 {
3422 #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
3423 PyErr_SetString(PyExc_RuntimeError,
3424 "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
3425 #else
3426 long val;
3427 PyObject *v = __Pyx_PyNumber_IntOrLong(x);
3428 #if PY_MAJOR_VERSION < 3
3429 if (likely(v) && !PyLong_Check(v)) {
3430 PyObject *tmp = v;
3431 v = PyNumber_Long(tmp);
3432 Py_DECREF(tmp);
3433 }
3434 #endif
3435 if (likely(v)) {
3436 int one = 1; int is_little = (int)*(unsigned char *)&one;
3437 unsigned char *bytes = (unsigned char *)&val;
3438 int ret = _PyLong_AsByteArray((PyLongObject *)v,
3439 bytes, sizeof(val),
3440 is_little, !is_unsigned);
3441 Py_DECREF(v);
3442 if (likely(!ret))
3443 return val;
3444 }
3445 #endif
3446 return (long) -1;
3447 }
3448 } else {
3449 long val;
3450 PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
3451 if (!tmp) return (long) -1;
3452 val = __Pyx_PyInt_As_long(tmp);
3453 Py_DECREF(tmp);
3454 return val;
3455 }
3456 raise_overflow:
3457 PyErr_SetString(PyExc_OverflowError,
3458 "value too large to convert to long");
3459 return (long) -1;
3460 raise_neg_overflow:
3461 PyErr_SetString(PyExc_OverflowError,
3462 "can't convert negative value to long");
3463 return (long) -1;
3464 }
3465
3466 /* CIntFromPy */
__Pyx_PyInt_As_int(PyObject * x)3467 static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
3468 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
3469 #pragma GCC diagnostic push
3470 #pragma GCC diagnostic ignored "-Wconversion"
3471 #endif
3472 const int neg_one = (int) -1, const_zero = (int) 0;
3473 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
3474 #pragma GCC diagnostic pop
3475 #endif
3476 const int is_unsigned = neg_one > const_zero;
3477 #if PY_MAJOR_VERSION < 3
3478 if (likely(PyInt_Check(x))) {
3479 if (sizeof(int) < sizeof(long)) {
3480 __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
3481 } else {
3482 long val = PyInt_AS_LONG(x);
3483 if (is_unsigned && unlikely(val < 0)) {
3484 goto raise_neg_overflow;
3485 }
3486 return (int) val;
3487 }
3488 } else
3489 #endif
3490 if (likely(PyLong_Check(x))) {
3491 if (is_unsigned) {
3492 #if CYTHON_USE_PYLONG_INTERNALS
3493 const digit* digits = ((PyLongObject*)x)->ob_digit;
3494 switch (Py_SIZE(x)) {
3495 case 0: return (int) 0;
3496 case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
3497 case 2:
3498 if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
3499 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3500 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3501 } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
3502 return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
3503 }
3504 }
3505 break;
3506 case 3:
3507 if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
3508 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3509 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3510 } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
3511 return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
3512 }
3513 }
3514 break;
3515 case 4:
3516 if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
3517 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3518 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3519 } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
3520 return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
3521 }
3522 }
3523 break;
3524 }
3525 #endif
3526 #if CYTHON_COMPILING_IN_CPYTHON
3527 if (unlikely(Py_SIZE(x) < 0)) {
3528 goto raise_neg_overflow;
3529 }
3530 #else
3531 {
3532 int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
3533 if (unlikely(result < 0))
3534 return (int) -1;
3535 if (unlikely(result == 1))
3536 goto raise_neg_overflow;
3537 }
3538 #endif
3539 if (sizeof(int) <= sizeof(unsigned long)) {
3540 __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
3541 #ifdef HAVE_LONG_LONG
3542 } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
3543 __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
3544 #endif
3545 }
3546 } else {
3547 #if CYTHON_USE_PYLONG_INTERNALS
3548 const digit* digits = ((PyLongObject*)x)->ob_digit;
3549 switch (Py_SIZE(x)) {
3550 case 0: return (int) 0;
3551 case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
3552 case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0])
3553 case -2:
3554 if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
3555 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3556 __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3557 } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
3558 return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
3559 }
3560 }
3561 break;
3562 case 2:
3563 if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
3564 if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
3565 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3566 } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
3567 return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
3568 }
3569 }
3570 break;
3571 case -3:
3572 if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
3573 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3574 __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3575 } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
3576 return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
3577 }
3578 }
3579 break;
3580 case 3:
3581 if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
3582 if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
3583 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3584 } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
3585 return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
3586 }
3587 }
3588 break;
3589 case -4:
3590 if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
3591 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3592 __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3593 } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
3594 return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
3595 }
3596 }
3597 break;
3598 case 4:
3599 if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
3600 if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
3601 __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
3602 } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
3603 return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
3604 }
3605 }
3606 break;
3607 }
3608 #endif
3609 if (sizeof(int) <= sizeof(long)) {
3610 __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
3611 #ifdef HAVE_LONG_LONG
3612 } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
3613 __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
3614 #endif
3615 }
3616 }
3617 {
3618 #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
3619 PyErr_SetString(PyExc_RuntimeError,
3620 "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
3621 #else
3622 int val;
3623 PyObject *v = __Pyx_PyNumber_IntOrLong(x);
3624 #if PY_MAJOR_VERSION < 3
3625 if (likely(v) && !PyLong_Check(v)) {
3626 PyObject *tmp = v;
3627 v = PyNumber_Long(tmp);
3628 Py_DECREF(tmp);
3629 }
3630 #endif
3631 if (likely(v)) {
3632 int one = 1; int is_little = (int)*(unsigned char *)&one;
3633 unsigned char *bytes = (unsigned char *)&val;
3634 int ret = _PyLong_AsByteArray((PyLongObject *)v,
3635 bytes, sizeof(val),
3636 is_little, !is_unsigned);
3637 Py_DECREF(v);
3638 if (likely(!ret))
3639 return val;
3640 }
3641 #endif
3642 return (int) -1;
3643 }
3644 } else {
3645 int val;
3646 PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
3647 if (!tmp) return (int) -1;
3648 val = __Pyx_PyInt_As_int(tmp);
3649 Py_DECREF(tmp);
3650 return val;
3651 }
3652 raise_overflow:
3653 PyErr_SetString(PyExc_OverflowError,
3654 "value too large to convert to int");
3655 return (int) -1;
3656 raise_neg_overflow:
3657 PyErr_SetString(PyExc_OverflowError,
3658 "can't convert negative value to int");
3659 return (int) -1;
3660 }
3661
3662 /* FastTypeChecks */
3663 #if CYTHON_COMPILING_IN_CPYTHON
__Pyx_InBases(PyTypeObject * a,PyTypeObject * b)3664 static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
3665 while (a) {
3666 a = a->tp_base;
3667 if (a == b)
3668 return 1;
3669 }
3670 return b == &PyBaseObject_Type;
3671 }
__Pyx_IsSubtype(PyTypeObject * a,PyTypeObject * b)3672 static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
3673 PyObject *mro;
3674 if (a == b) return 1;
3675 mro = a->tp_mro;
3676 if (likely(mro)) {
3677 Py_ssize_t i, n;
3678 n = PyTuple_GET_SIZE(mro);
3679 for (i = 0; i < n; i++) {
3680 if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
3681 return 1;
3682 }
3683 return 0;
3684 }
3685 return __Pyx_InBases(a, b);
3686 }
3687 #if PY_MAJOR_VERSION == 2
__Pyx_inner_PyErr_GivenExceptionMatches2(PyObject * err,PyObject * exc_type1,PyObject * exc_type2)3688 static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
3689 PyObject *exception, *value, *tb;
3690 int res;
3691 __Pyx_PyThreadState_declare
3692 __Pyx_PyThreadState_assign
3693 __Pyx_ErrFetch(&exception, &value, &tb);
3694 res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
3695 if (unlikely(res == -1)) {
3696 PyErr_WriteUnraisable(err);
3697 res = 0;
3698 }
3699 if (!res) {
3700 res = PyObject_IsSubclass(err, exc_type2);
3701 if (unlikely(res == -1)) {
3702 PyErr_WriteUnraisable(err);
3703 res = 0;
3704 }
3705 }
3706 __Pyx_ErrRestore(exception, value, tb);
3707 return res;
3708 }
3709 #else
__Pyx_inner_PyErr_GivenExceptionMatches2(PyObject * err,PyObject * exc_type1,PyObject * exc_type2)3710 static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
3711 int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
3712 if (!res) {
3713 res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
3714 }
3715 return res;
3716 }
3717 #endif
__Pyx_PyErr_GivenExceptionMatchesTuple(PyObject * exc_type,PyObject * tuple)3718 static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
3719 Py_ssize_t i, n;
3720 assert(PyExceptionClass_Check(exc_type));
3721 n = PyTuple_GET_SIZE(tuple);
3722 #if PY_MAJOR_VERSION >= 3
3723 for (i=0; i<n; i++) {
3724 if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
3725 }
3726 #endif
3727 for (i=0; i<n; i++) {
3728 PyObject *t = PyTuple_GET_ITEM(tuple, i);
3729 #if PY_MAJOR_VERSION < 3
3730 if (likely(exc_type == t)) return 1;
3731 #endif
3732 if (likely(PyExceptionClass_Check(t))) {
3733 if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
3734 } else {
3735 }
3736 }
3737 return 0;
3738 }
__Pyx_PyErr_GivenExceptionMatches(PyObject * err,PyObject * exc_type)3739 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
3740 if (likely(err == exc_type)) return 1;
3741 if (likely(PyExceptionClass_Check(err))) {
3742 if (likely(PyExceptionClass_Check(exc_type))) {
3743 return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
3744 } else if (likely(PyTuple_Check(exc_type))) {
3745 return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
3746 } else {
3747 }
3748 }
3749 return PyErr_GivenExceptionMatches(err, exc_type);
3750 }
__Pyx_PyErr_GivenExceptionMatches2(PyObject * err,PyObject * exc_type1,PyObject * exc_type2)3751 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
3752 assert(PyExceptionClass_Check(exc_type1));
3753 assert(PyExceptionClass_Check(exc_type2));
3754 if (likely(err == exc_type1 || err == exc_type2)) return 1;
3755 if (likely(PyExceptionClass_Check(err))) {
3756 return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
3757 }
3758 return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
3759 }
3760 #endif
3761
3762 /* CheckBinaryVersion */
__Pyx_check_binary_version(void)3763 static int __Pyx_check_binary_version(void) {
3764 char ctversion[4], rtversion[4];
3765 PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
3766 PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
3767 if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
3768 char message[200];
3769 PyOS_snprintf(message, sizeof(message),
3770 "compiletime version %s of module '%.100s' "
3771 "does not match runtime version %s",
3772 ctversion, __Pyx_MODULE_NAME, rtversion);
3773 return PyErr_WarnEx(NULL, message, 1);
3774 }
3775 return 0;
3776 }
3777
3778 /* FunctionExport */
__Pyx_ExportFunction(const char * name,void (* f)(void),const char * sig)3779 static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
3780 PyObject *d = 0;
3781 PyObject *cobj = 0;
3782 union {
3783 void (*fp)(void);
3784 void *p;
3785 } tmp;
3786 d = PyObject_GetAttrString(__pyx_m, (char *)"__pyx_capi__");
3787 if (!d) {
3788 PyErr_Clear();
3789 d = PyDict_New();
3790 if (!d)
3791 goto bad;
3792 Py_INCREF(d);
3793 if (PyModule_AddObject(__pyx_m, (char *)"__pyx_capi__", d) < 0)
3794 goto bad;
3795 }
3796 tmp.fp = f;
3797 #if PY_VERSION_HEX >= 0x02070000
3798 cobj = PyCapsule_New(tmp.p, sig, 0);
3799 #else
3800 cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
3801 #endif
3802 if (!cobj)
3803 goto bad;
3804 if (PyDict_SetItemString(d, name, cobj) < 0)
3805 goto bad;
3806 Py_DECREF(cobj);
3807 Py_DECREF(d);
3808 return 0;
3809 bad:
3810 Py_XDECREF(cobj);
3811 Py_XDECREF(d);
3812 return -1;
3813 }
3814
3815 /* InitStrings */
__Pyx_InitStrings(__Pyx_StringTabEntry * t)3816 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
3817 while (t->p) {
3818 #if PY_MAJOR_VERSION < 3
3819 if (t->is_unicode) {
3820 *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
3821 } else if (t->intern) {
3822 *t->p = PyString_InternFromString(t->s);
3823 } else {
3824 *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
3825 }
3826 #else
3827 if (t->is_unicode | t->is_str) {
3828 if (t->intern) {
3829 *t->p = PyUnicode_InternFromString(t->s);
3830 } else if (t->encoding) {
3831 *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
3832 } else {
3833 *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
3834 }
3835 } else {
3836 *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
3837 }
3838 #endif
3839 if (!*t->p)
3840 return -1;
3841 if (PyObject_Hash(*t->p) == -1)
3842 return -1;
3843 ++t;
3844 }
3845 return 0;
3846 }
3847
__Pyx_PyUnicode_FromString(const char * c_str)3848 static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
3849 return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
3850 }
__Pyx_PyObject_AsString(PyObject * o)3851 static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
3852 Py_ssize_t ignore;
3853 return __Pyx_PyObject_AsStringAndSize(o, &ignore);
3854 }
3855 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
3856 #if !CYTHON_PEP393_ENABLED
__Pyx_PyUnicode_AsStringAndSize(PyObject * o,Py_ssize_t * length)3857 static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
3858 char* defenc_c;
3859 PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
3860 if (!defenc) return NULL;
3861 defenc_c = PyBytes_AS_STRING(defenc);
3862 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
3863 {
3864 char* end = defenc_c + PyBytes_GET_SIZE(defenc);
3865 char* c;
3866 for (c = defenc_c; c < end; c++) {
3867 if ((unsigned char) (*c) >= 128) {
3868 PyUnicode_AsASCIIString(o);
3869 return NULL;
3870 }
3871 }
3872 }
3873 #endif
3874 *length = PyBytes_GET_SIZE(defenc);
3875 return defenc_c;
3876 }
3877 #else
__Pyx_PyUnicode_AsStringAndSize(PyObject * o,Py_ssize_t * length)3878 static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
3879 if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
3880 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
3881 if (likely(PyUnicode_IS_ASCII(o))) {
3882 *length = PyUnicode_GET_LENGTH(o);
3883 return PyUnicode_AsUTF8(o);
3884 } else {
3885 PyUnicode_AsASCIIString(o);
3886 return NULL;
3887 }
3888 #else
3889 return PyUnicode_AsUTF8AndSize(o, length);
3890 #endif
3891 }
3892 #endif
3893 #endif
__Pyx_PyObject_AsStringAndSize(PyObject * o,Py_ssize_t * length)3894 static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
3895 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
3896 if (
3897 #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
3898 __Pyx_sys_getdefaultencoding_not_ascii &&
3899 #endif
3900 PyUnicode_Check(o)) {
3901 return __Pyx_PyUnicode_AsStringAndSize(o, length);
3902 } else
3903 #endif
3904 #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
3905 if (PyByteArray_Check(o)) {
3906 *length = PyByteArray_GET_SIZE(o);
3907 return PyByteArray_AS_STRING(o);
3908 } else
3909 #endif
3910 {
3911 char* result;
3912 int r = PyBytes_AsStringAndSize(o, &result, length);
3913 if (unlikely(r < 0)) {
3914 return NULL;
3915 } else {
3916 return result;
3917 }
3918 }
3919 }
__Pyx_PyObject_IsTrue(PyObject * x)3920 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
3921 int is_true = x == Py_True;
3922 if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
3923 else return PyObject_IsTrue(x);
3924 }
__Pyx_PyObject_IsTrueAndDecref(PyObject * x)3925 static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
3926 int retval;
3927 if (unlikely(!x)) return -1;
3928 retval = __Pyx_PyObject_IsTrue(x);
3929 Py_DECREF(x);
3930 return retval;
3931 }
__Pyx_PyNumber_IntOrLongWrongResultType(PyObject * result,const char * type_name)3932 static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
3933 #if PY_MAJOR_VERSION >= 3
3934 if (PyLong_Check(result)) {
3935 if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
3936 "__int__ returned non-int (type %.200s). "
3937 "The ability to return an instance of a strict subclass of int "
3938 "is deprecated, and may be removed in a future version of Python.",
3939 Py_TYPE(result)->tp_name)) {
3940 Py_DECREF(result);
3941 return NULL;
3942 }
3943 return result;
3944 }
3945 #endif
3946 PyErr_Format(PyExc_TypeError,
3947 "__%.4s__ returned non-%.4s (type %.200s)",
3948 type_name, type_name, Py_TYPE(result)->tp_name);
3949 Py_DECREF(result);
3950 return NULL;
3951 }
__Pyx_PyNumber_IntOrLong(PyObject * x)3952 static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
3953 #if CYTHON_USE_TYPE_SLOTS
3954 PyNumberMethods *m;
3955 #endif
3956 const char *name = NULL;
3957 PyObject *res = NULL;
3958 #if PY_MAJOR_VERSION < 3
3959 if (likely(PyInt_Check(x) || PyLong_Check(x)))
3960 #else
3961 if (likely(PyLong_Check(x)))
3962 #endif
3963 return __Pyx_NewRef(x);
3964 #if CYTHON_USE_TYPE_SLOTS
3965 m = Py_TYPE(x)->tp_as_number;
3966 #if PY_MAJOR_VERSION < 3
3967 if (m && m->nb_int) {
3968 name = "int";
3969 res = m->nb_int(x);
3970 }
3971 else if (m && m->nb_long) {
3972 name = "long";
3973 res = m->nb_long(x);
3974 }
3975 #else
3976 if (likely(m && m->nb_int)) {
3977 name = "int";
3978 res = m->nb_int(x);
3979 }
3980 #endif
3981 #else
3982 if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
3983 res = PyNumber_Int(x);
3984 }
3985 #endif
3986 if (likely(res)) {
3987 #if PY_MAJOR_VERSION < 3
3988 if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
3989 #else
3990 if (unlikely(!PyLong_CheckExact(res))) {
3991 #endif
3992 return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
3993 }
3994 }
3995 else if (!PyErr_Occurred()) {
3996 PyErr_SetString(PyExc_TypeError,
3997 "an integer is required");
3998 }
3999 return res;
4000 }
4001 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
4002 Py_ssize_t ival;
4003 PyObject *x;
4004 #if PY_MAJOR_VERSION < 3
4005 if (likely(PyInt_CheckExact(b))) {
4006 if (sizeof(Py_ssize_t) >= sizeof(long))
4007 return PyInt_AS_LONG(b);
4008 else
4009 return PyInt_AsSsize_t(b);
4010 }
4011 #endif
4012 if (likely(PyLong_CheckExact(b))) {
4013 #if CYTHON_USE_PYLONG_INTERNALS
4014 const digit* digits = ((PyLongObject*)b)->ob_digit;
4015 const Py_ssize_t size = Py_SIZE(b);
4016 if (likely(__Pyx_sst_abs(size) <= 1)) {
4017 ival = likely(size) ? digits[0] : 0;
4018 if (size == -1) ival = -ival;
4019 return ival;
4020 } else {
4021 switch (size) {
4022 case 2:
4023 if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
4024 return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4025 }
4026 break;
4027 case -2:
4028 if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
4029 return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4030 }
4031 break;
4032 case 3:
4033 if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
4034 return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4035 }
4036 break;
4037 case -3:
4038 if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
4039 return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4040 }
4041 break;
4042 case 4:
4043 if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
4044 return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4045 }
4046 break;
4047 case -4:
4048 if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
4049 return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4050 }
4051 break;
4052 }
4053 }
4054 #endif
4055 return PyLong_AsSsize_t(b);
4056 }
4057 x = PyNumber_Index(b);
4058 if (!x) return -1;
4059 ival = PyInt_AsSsize_t(x);
4060 Py_DECREF(x);
4061 return ival;
4062 }
4063 static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
4064 return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
4065 }
4066 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
4067 return PyInt_FromSize_t(ival);
4068 }
4069
4070
4071 #endif /* Py_PYTHON_H */
4072