1 /* Generated by Cython 0.29.23 */
2 
3 #ifndef PY_SSIZE_T_CLEAN
4 #define PY_SSIZE_T_CLEAN
5 #endif /* PY_SSIZE_T_CLEAN */
6 #include "Python.h"
7 #ifndef Py_PYTHON_H
8     #error Python headers needed to compile C extensions, please install development version of Python.
9 #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
10     #error Cython requires Python 2.6+ or Python 3.3+.
11 #else
12 #define CYTHON_ABI "0_29_23"
13 #define CYTHON_HEX_VERSION 0x001D17F0
14 #define CYTHON_FUTURE_DIVISION 1
15 #include <stddef.h>
16 #ifndef offsetof
17   #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
18 #endif
19 #if !defined(WIN32) && !defined(MS_WINDOWS)
20   #ifndef __stdcall
21     #define __stdcall
22   #endif
23   #ifndef __cdecl
24     #define __cdecl
25   #endif
26   #ifndef __fastcall
27     #define __fastcall
28   #endif
29 #endif
30 #ifndef DL_IMPORT
31   #define DL_IMPORT(t) t
32 #endif
33 #ifndef DL_EXPORT
34   #define DL_EXPORT(t) t
35 #endif
36 #define __PYX_COMMA ,
37 #ifndef HAVE_LONG_LONG
38   #if PY_VERSION_HEX >= 0x02070000
39     #define HAVE_LONG_LONG
40   #endif
41 #endif
42 #ifndef PY_LONG_LONG
43   #define PY_LONG_LONG LONG_LONG
44 #endif
45 #ifndef Py_HUGE_VAL
46   #define Py_HUGE_VAL HUGE_VAL
47 #endif
48 #ifdef PYPY_VERSION
49   #define CYTHON_COMPILING_IN_PYPY 1
50   #define CYTHON_COMPILING_IN_PYSTON 0
51   #define CYTHON_COMPILING_IN_CPYTHON 0
52   #undef CYTHON_USE_TYPE_SLOTS
53   #define CYTHON_USE_TYPE_SLOTS 0
54   #undef CYTHON_USE_PYTYPE_LOOKUP
55   #define CYTHON_USE_PYTYPE_LOOKUP 0
56   #if PY_VERSION_HEX < 0x03050000
57     #undef CYTHON_USE_ASYNC_SLOTS
58     #define CYTHON_USE_ASYNC_SLOTS 0
59   #elif !defined(CYTHON_USE_ASYNC_SLOTS)
60     #define CYTHON_USE_ASYNC_SLOTS 1
61   #endif
62   #undef CYTHON_USE_PYLIST_INTERNALS
63   #define CYTHON_USE_PYLIST_INTERNALS 0
64   #undef CYTHON_USE_UNICODE_INTERNALS
65   #define CYTHON_USE_UNICODE_INTERNALS 0
66   #undef CYTHON_USE_UNICODE_WRITER
67   #define CYTHON_USE_UNICODE_WRITER 0
68   #undef CYTHON_USE_PYLONG_INTERNALS
69   #define CYTHON_USE_PYLONG_INTERNALS 0
70   #undef CYTHON_AVOID_BORROWED_REFS
71   #define CYTHON_AVOID_BORROWED_REFS 1
72   #undef CYTHON_ASSUME_SAFE_MACROS
73   #define CYTHON_ASSUME_SAFE_MACROS 0
74   #undef CYTHON_UNPACK_METHODS
75   #define CYTHON_UNPACK_METHODS 0
76   #undef CYTHON_FAST_THREAD_STATE
77   #define CYTHON_FAST_THREAD_STATE 0
78   #undef CYTHON_FAST_PYCALL
79   #define CYTHON_FAST_PYCALL 0
80   #undef CYTHON_PEP489_MULTI_PHASE_INIT
81   #define CYTHON_PEP489_MULTI_PHASE_INIT 0
82   #undef CYTHON_USE_TP_FINALIZE
83   #define CYTHON_USE_TP_FINALIZE 0
84   #undef CYTHON_USE_DICT_VERSIONS
85   #define CYTHON_USE_DICT_VERSIONS 0
86   #undef CYTHON_USE_EXC_INFO_STACK
87   #define CYTHON_USE_EXC_INFO_STACK 0
88 #elif defined(PYSTON_VERSION)
89   #define CYTHON_COMPILING_IN_PYPY 0
90   #define CYTHON_COMPILING_IN_PYSTON 1
91   #define CYTHON_COMPILING_IN_CPYTHON 0
92   #ifndef CYTHON_USE_TYPE_SLOTS
93     #define CYTHON_USE_TYPE_SLOTS 1
94   #endif
95   #undef CYTHON_USE_PYTYPE_LOOKUP
96   #define CYTHON_USE_PYTYPE_LOOKUP 0
97   #undef CYTHON_USE_ASYNC_SLOTS
98   #define CYTHON_USE_ASYNC_SLOTS 0
99   #undef CYTHON_USE_PYLIST_INTERNALS
100   #define CYTHON_USE_PYLIST_INTERNALS 0
101   #ifndef CYTHON_USE_UNICODE_INTERNALS
102     #define CYTHON_USE_UNICODE_INTERNALS 1
103   #endif
104   #undef CYTHON_USE_UNICODE_WRITER
105   #define CYTHON_USE_UNICODE_WRITER 0
106   #undef CYTHON_USE_PYLONG_INTERNALS
107   #define CYTHON_USE_PYLONG_INTERNALS 0
108   #ifndef CYTHON_AVOID_BORROWED_REFS
109     #define CYTHON_AVOID_BORROWED_REFS 0
110   #endif
111   #ifndef CYTHON_ASSUME_SAFE_MACROS
112     #define CYTHON_ASSUME_SAFE_MACROS 1
113   #endif
114   #ifndef CYTHON_UNPACK_METHODS
115     #define CYTHON_UNPACK_METHODS 1
116   #endif
117   #undef CYTHON_FAST_THREAD_STATE
118   #define CYTHON_FAST_THREAD_STATE 0
119   #undef CYTHON_FAST_PYCALL
120   #define CYTHON_FAST_PYCALL 0
121   #undef CYTHON_PEP489_MULTI_PHASE_INIT
122   #define CYTHON_PEP489_MULTI_PHASE_INIT 0
123   #undef CYTHON_USE_TP_FINALIZE
124   #define CYTHON_USE_TP_FINALIZE 0
125   #undef CYTHON_USE_DICT_VERSIONS
126   #define CYTHON_USE_DICT_VERSIONS 0
127   #undef CYTHON_USE_EXC_INFO_STACK
128   #define CYTHON_USE_EXC_INFO_STACK 0
129 #else
130   #define CYTHON_COMPILING_IN_PYPY 0
131   #define CYTHON_COMPILING_IN_PYSTON 0
132   #define CYTHON_COMPILING_IN_CPYTHON 1
133   #ifndef CYTHON_USE_TYPE_SLOTS
134     #define CYTHON_USE_TYPE_SLOTS 1
135   #endif
136   #if PY_VERSION_HEX < 0x02070000
137     #undef CYTHON_USE_PYTYPE_LOOKUP
138     #define CYTHON_USE_PYTYPE_LOOKUP 0
139   #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
140     #define CYTHON_USE_PYTYPE_LOOKUP 1
141   #endif
142   #if PY_MAJOR_VERSION < 3
143     #undef CYTHON_USE_ASYNC_SLOTS
144     #define CYTHON_USE_ASYNC_SLOTS 0
145   #elif !defined(CYTHON_USE_ASYNC_SLOTS)
146     #define CYTHON_USE_ASYNC_SLOTS 1
147   #endif
148   #if PY_VERSION_HEX < 0x02070000
149     #undef CYTHON_USE_PYLONG_INTERNALS
150     #define CYTHON_USE_PYLONG_INTERNALS 0
151   #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
152     #define CYTHON_USE_PYLONG_INTERNALS 1
153   #endif
154   #ifndef CYTHON_USE_PYLIST_INTERNALS
155     #define CYTHON_USE_PYLIST_INTERNALS 1
156   #endif
157   #ifndef CYTHON_USE_UNICODE_INTERNALS
158     #define CYTHON_USE_UNICODE_INTERNALS 1
159   #endif
160   #if PY_VERSION_HEX < 0x030300F0
161     #undef CYTHON_USE_UNICODE_WRITER
162     #define CYTHON_USE_UNICODE_WRITER 0
163   #elif !defined(CYTHON_USE_UNICODE_WRITER)
164     #define CYTHON_USE_UNICODE_WRITER 1
165   #endif
166   #ifndef CYTHON_AVOID_BORROWED_REFS
167     #define CYTHON_AVOID_BORROWED_REFS 0
168   #endif
169   #ifndef CYTHON_ASSUME_SAFE_MACROS
170     #define CYTHON_ASSUME_SAFE_MACROS 1
171   #endif
172   #ifndef CYTHON_UNPACK_METHODS
173     #define CYTHON_UNPACK_METHODS 1
174   #endif
175   #ifndef CYTHON_FAST_THREAD_STATE
176     #define CYTHON_FAST_THREAD_STATE 1
177   #endif
178   #ifndef CYTHON_FAST_PYCALL
179     #define CYTHON_FAST_PYCALL 1
180   #endif
181   #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
182     #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
183   #endif
184   #ifndef CYTHON_USE_TP_FINALIZE
185     #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
186   #endif
187   #ifndef CYTHON_USE_DICT_VERSIONS
188     #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1)
189   #endif
190   #ifndef CYTHON_USE_EXC_INFO_STACK
191     #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
192   #endif
193 #endif
194 #if !defined(CYTHON_FAST_PYCCALL)
195 #define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
196 #endif
197 #if CYTHON_USE_PYLONG_INTERNALS
198   #include "longintrepr.h"
199   #undef SHIFT
200   #undef BASE
201   #undef MASK
202   #ifdef SIZEOF_VOID_P
203     enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
204   #endif
205 #endif
206 #ifndef __has_attribute
207   #define __has_attribute(x) 0
208 #endif
209 #ifndef __has_cpp_attribute
210   #define __has_cpp_attribute(x) 0
211 #endif
212 #ifndef CYTHON_RESTRICT
213   #if defined(__GNUC__)
214     #define CYTHON_RESTRICT __restrict__
215   #elif defined(_MSC_VER) && _MSC_VER >= 1400
216     #define CYTHON_RESTRICT __restrict
217   #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
218     #define CYTHON_RESTRICT restrict
219   #else
220     #define CYTHON_RESTRICT
221   #endif
222 #endif
223 #ifndef CYTHON_UNUSED
224 # if defined(__GNUC__)
225 #   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
226 #     define CYTHON_UNUSED __attribute__ ((__unused__))
227 #   else
228 #     define CYTHON_UNUSED
229 #   endif
230 # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
231 #   define CYTHON_UNUSED __attribute__ ((__unused__))
232 # else
233 #   define CYTHON_UNUSED
234 # endif
235 #endif
236 #ifndef CYTHON_MAYBE_UNUSED_VAR
237 #  if defined(__cplusplus)
CYTHON_MAYBE_UNUSED_VAR(const T &)238      template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
239 #  else
240 #    define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
241 #  endif
242 #endif
243 #ifndef CYTHON_NCP_UNUSED
244 # if CYTHON_COMPILING_IN_CPYTHON
245 #  define CYTHON_NCP_UNUSED
246 # else
247 #  define CYTHON_NCP_UNUSED CYTHON_UNUSED
248 # endif
249 #endif
250 #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
251 #ifdef _MSC_VER
252     #ifndef _MSC_STDINT_H_
253         #if _MSC_VER < 1300
254            typedef unsigned char     uint8_t;
255            typedef unsigned int      uint32_t;
256         #else
257            typedef unsigned __int8   uint8_t;
258            typedef unsigned __int32  uint32_t;
259         #endif
260     #endif
261 #else
262    #include <stdint.h>
263 #endif
264 #ifndef CYTHON_FALLTHROUGH
265   #if defined(__cplusplus) && __cplusplus >= 201103L
266     #if __has_cpp_attribute(fallthrough)
267       #define CYTHON_FALLTHROUGH [[fallthrough]]
268     #elif __has_cpp_attribute(clang::fallthrough)
269       #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
270     #elif __has_cpp_attribute(gnu::fallthrough)
271       #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
272     #endif
273   #endif
274   #ifndef CYTHON_FALLTHROUGH
275     #if __has_attribute(fallthrough)
276       #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
277     #else
278       #define CYTHON_FALLTHROUGH
279     #endif
280   #endif
281   #if defined(__clang__ ) && defined(__apple_build_version__)
282     #if __apple_build_version__ < 7000000
283       #undef  CYTHON_FALLTHROUGH
284       #define CYTHON_FALLTHROUGH
285     #endif
286   #endif
287 #endif
288 
289 #ifndef CYTHON_INLINE
290   #if defined(__clang__)
291     #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
292   #elif defined(__GNUC__)
293     #define CYTHON_INLINE __inline__
294   #elif defined(_MSC_VER)
295     #define CYTHON_INLINE __inline
296   #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
297     #define CYTHON_INLINE inline
298   #else
299     #define CYTHON_INLINE
300   #endif
301 #endif
302 
303 #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
304   #define Py_OptimizeFlag 0
305 #endif
306 #define __PYX_BUILD_PY_SSIZE_T "n"
307 #define CYTHON_FORMAT_SSIZE_T "z"
308 #if PY_MAJOR_VERSION < 3
309   #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
310   #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
311           PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
312   #define __Pyx_DefaultClassType PyClass_Type
313 #else
314   #define __Pyx_BUILTIN_MODULE_NAME "builtins"
315 #if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2
316   #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
317           PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
318 #else
319   #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
320           PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
321 #endif
322   #define __Pyx_DefaultClassType PyType_Type
323 #endif
324 #ifndef Py_TPFLAGS_CHECKTYPES
325   #define Py_TPFLAGS_CHECKTYPES 0
326 #endif
327 #ifndef Py_TPFLAGS_HAVE_INDEX
328   #define Py_TPFLAGS_HAVE_INDEX 0
329 #endif
330 #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
331   #define Py_TPFLAGS_HAVE_NEWBUFFER 0
332 #endif
333 #ifndef Py_TPFLAGS_HAVE_FINALIZE
334   #define Py_TPFLAGS_HAVE_FINALIZE 0
335 #endif
336 #ifndef METH_STACKLESS
337   #define METH_STACKLESS 0
338 #endif
339 #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
340   #ifndef METH_FASTCALL
341      #define METH_FASTCALL 0x80
342   #endif
343   typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
344   typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
345                                                           Py_ssize_t nargs, PyObject *kwnames);
346 #else
347   #define __Pyx_PyCFunctionFast _PyCFunctionFast
348   #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
349 #endif
350 #if CYTHON_FAST_PYCCALL
351 #define __Pyx_PyFastCFunction_Check(func)\
352     ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)))))
353 #else
354 #define __Pyx_PyFastCFunction_Check(func) 0
355 #endif
356 #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
357   #define PyObject_Malloc(s)   PyMem_Malloc(s)
358   #define PyObject_Free(p)     PyMem_Free(p)
359   #define PyObject_Realloc(p)  PyMem_Realloc(p)
360 #endif
361 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
362   #define PyMem_RawMalloc(n)           PyMem_Malloc(n)
363   #define PyMem_RawRealloc(p, n)       PyMem_Realloc(p, n)
364   #define PyMem_RawFree(p)             PyMem_Free(p)
365 #endif
366 #if CYTHON_COMPILING_IN_PYSTON
367   #define __Pyx_PyCode_HasFreeVars(co)  PyCode_HasFreeVars(co)
368   #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
369 #else
370   #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
371   #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
372 #endif
373 #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
374   #define __Pyx_PyThreadState_Current PyThreadState_GET()
375 #elif PY_VERSION_HEX >= 0x03060000
376   #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
377 #elif PY_VERSION_HEX >= 0x03000000
378   #define __Pyx_PyThreadState_Current PyThreadState_GET()
379 #else
380   #define __Pyx_PyThreadState_Current _PyThreadState_Current
381 #endif
382 #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
383 #include "pythread.h"
384 #define Py_tss_NEEDS_INIT 0
385 typedef int Py_tss_t;
PyThread_tss_create(Py_tss_t * key)386 static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
387   *key = PyThread_create_key();
388   return 0;
389 }
PyThread_tss_alloc(void)390 static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
391   Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
392   *key = Py_tss_NEEDS_INIT;
393   return key;
394 }
PyThread_tss_free(Py_tss_t * key)395 static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
396   PyObject_Free(key);
397 }
PyThread_tss_is_created(Py_tss_t * key)398 static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
399   return *key != Py_tss_NEEDS_INIT;
400 }
PyThread_tss_delete(Py_tss_t * key)401 static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
402   PyThread_delete_key(*key);
403   *key = Py_tss_NEEDS_INIT;
404 }
PyThread_tss_set(Py_tss_t * key,void * value)405 static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
406   return PyThread_set_key_value(*key, value);
407 }
PyThread_tss_get(Py_tss_t * key)408 static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
409   return PyThread_get_key_value(*key);
410 }
411 #endif
412 #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
413 #define __Pyx_PyDict_NewPresized(n)  ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
414 #else
415 #define __Pyx_PyDict_NewPresized(n)  PyDict_New()
416 #endif
417 #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
418   #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
419   #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
420 #else
421   #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
422   #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
423 #endif
424 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
425 #define __Pyx_PyDict_GetItemStr(dict, name)  _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
426 #else
427 #define __Pyx_PyDict_GetItemStr(dict, name)  PyDict_GetItem(dict, name)
428 #endif
429 #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
430   #define CYTHON_PEP393_ENABLED 1
431   #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
432                                               0 : _PyUnicode_Ready((PyObject *)(op)))
433   #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
434   #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
435   #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
436   #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
437   #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
438   #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
439   #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
440   #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
441   #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
442   #else
443   #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_LENGTH(u))
444   #endif
445 #else
446   #define CYTHON_PEP393_ENABLED 0
447   #define PyUnicode_1BYTE_KIND  1
448   #define PyUnicode_2BYTE_KIND  2
449   #define PyUnicode_4BYTE_KIND  4
450   #define __Pyx_PyUnicode_READY(op)       (0)
451   #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
452   #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
453   #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
454   #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
455   #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
456   #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
457   #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
458   #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
459 #endif
460 #if CYTHON_COMPILING_IN_PYPY
461   #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
462   #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
463 #else
464   #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
465   #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
466       PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
467 #endif
468 #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
469   #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
470 #endif
471 #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
472   #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
473 #endif
474 #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
475   #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
476 #endif
477 #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))
478 #define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
479 #if PY_MAJOR_VERSION >= 3
480   #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
481 #else
482   #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
483 #endif
484 #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
485   #define PyObject_ASCII(o)            PyObject_Repr(o)
486 #endif
487 #if PY_MAJOR_VERSION >= 3
488   #define PyBaseString_Type            PyUnicode_Type
489   #define PyStringObject               PyUnicodeObject
490   #define PyString_Type                PyUnicode_Type
491   #define PyString_Check               PyUnicode_Check
492   #define PyString_CheckExact          PyUnicode_CheckExact
493 #ifndef PyObject_Unicode
494   #define PyObject_Unicode             PyObject_Str
495 #endif
496 #endif
497 #if PY_MAJOR_VERSION >= 3
498   #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
499   #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
500 #else
501   #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
502   #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
503 #endif
504 #ifndef PySet_CheckExact
505   #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
506 #endif
507 #if PY_VERSION_HEX >= 0x030900A4
508   #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
509   #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
510 #else
511   #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
512   #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
513 #endif
514 #if CYTHON_ASSUME_SAFE_MACROS
515   #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
516 #else
517   #define __Pyx_PySequence_SIZE(seq)  PySequence_Size(seq)
518 #endif
519 #if PY_MAJOR_VERSION >= 3
520   #define PyIntObject                  PyLongObject
521   #define PyInt_Type                   PyLong_Type
522   #define PyInt_Check(op)              PyLong_Check(op)
523   #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
524   #define PyInt_FromString             PyLong_FromString
525   #define PyInt_FromUnicode            PyLong_FromUnicode
526   #define PyInt_FromLong               PyLong_FromLong
527   #define PyInt_FromSize_t             PyLong_FromSize_t
528   #define PyInt_FromSsize_t            PyLong_FromSsize_t
529   #define PyInt_AsLong                 PyLong_AsLong
530   #define PyInt_AS_LONG                PyLong_AS_LONG
531   #define PyInt_AsSsize_t              PyLong_AsSsize_t
532   #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
533   #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
534   #define PyNumber_Int                 PyNumber_Long
535 #endif
536 #if PY_MAJOR_VERSION >= 3
537   #define PyBoolObject                 PyLongObject
538 #endif
539 #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
540   #ifndef PyUnicode_InternFromString
541     #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
542   #endif
543 #endif
544 #if PY_VERSION_HEX < 0x030200A4
545   typedef long Py_hash_t;
546   #define __Pyx_PyInt_FromHash_t PyInt_FromLong
547   #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
548 #else
549   #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
550   #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
551 #endif
552 #if PY_MAJOR_VERSION >= 3
553   #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
554 #else
555   #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
556 #endif
557 #if CYTHON_USE_ASYNC_SLOTS
558   #if PY_VERSION_HEX >= 0x030500B1
559     #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
560     #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
561   #else
562     #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
563   #endif
564 #else
565   #define __Pyx_PyType_AsAsync(obj) NULL
566 #endif
567 #ifndef __Pyx_PyAsyncMethodsStruct
568     typedef struct {
569         unaryfunc am_await;
570         unaryfunc am_aiter;
571         unaryfunc am_anext;
572     } __Pyx_PyAsyncMethodsStruct;
573 #endif
574 
575 #if defined(WIN32) || defined(MS_WINDOWS)
576   #define _USE_MATH_DEFINES
577 #endif
578 #include <math.h>
579 #ifdef NAN
580 #define __PYX_NAN() ((float) NAN)
581 #else
__PYX_NAN()582 static CYTHON_INLINE float __PYX_NAN() {
583   float value;
584   memset(&value, 0xFF, sizeof(value));
585   return value;
586 }
587 #endif
588 #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
589 #define __Pyx_truncl trunc
590 #else
591 #define __Pyx_truncl truncl
592 #endif
593 
594 #define __PYX_MARK_ERR_POS(f_index, lineno) \
595     { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
596 #define __PYX_ERR(f_index, lineno, Ln_error) \
597     { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }
598 
599 #ifndef __PYX_EXTERN_C
600   #ifdef __cplusplus
601     #define __PYX_EXTERN_C extern "C"
602   #else
603     #define __PYX_EXTERN_C extern
604   #endif
605 #endif
606 
607 #define __PYX_HAVE__dipy__utils__omp
608 #define __PYX_HAVE_API__dipy__utils__omp
609 /* Early includes */
610 #include "conditional_omp.h"
611 #ifdef _OPENMP
612 #include <omp.h>
613 #endif /* _OPENMP */
614 
615 #if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
616 #define CYTHON_WITHOUT_ASSERTIONS
617 #endif
618 
619 typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
620                 const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
621 
622 #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
623 #define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0
624 #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
625 #define __PYX_DEFAULT_STRING_ENCODING ""
626 #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
627 #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
628 #define __Pyx_uchar_cast(c) ((unsigned char)c)
629 #define __Pyx_long_cast(x) ((long)x)
630 #define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
631     (sizeof(type) < sizeof(Py_ssize_t))  ||\
632     (sizeof(type) > sizeof(Py_ssize_t) &&\
633           likely(v < (type)PY_SSIZE_T_MAX ||\
634                  v == (type)PY_SSIZE_T_MAX)  &&\
635           (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
636                                 v == (type)PY_SSIZE_T_MIN)))  ||\
637     (sizeof(type) == sizeof(Py_ssize_t) &&\
638           (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
639                                v == (type)PY_SSIZE_T_MAX)))  )
__Pyx_is_valid_index(Py_ssize_t i,Py_ssize_t limit)640 static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
641     return (size_t) i < (size_t) limit;
642 }
643 #if defined (__cplusplus) && __cplusplus >= 201103L
644     #include <cstdlib>
645     #define __Pyx_sst_abs(value) std::abs(value)
646 #elif SIZEOF_INT >= SIZEOF_SIZE_T
647     #define __Pyx_sst_abs(value) abs(value)
648 #elif SIZEOF_LONG >= SIZEOF_SIZE_T
649     #define __Pyx_sst_abs(value) labs(value)
650 #elif defined (_MSC_VER)
651     #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
652 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
653     #define __Pyx_sst_abs(value) llabs(value)
654 #elif defined (__GNUC__)
655     #define __Pyx_sst_abs(value) __builtin_llabs(value)
656 #else
657     #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
658 #endif
659 static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
660 static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
661 #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
662 #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
663 #define __Pyx_PyBytes_FromString        PyBytes_FromString
664 #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
665 static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
666 #if PY_MAJOR_VERSION < 3
667     #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
668     #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
669 #else
670     #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
671     #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
672 #endif
673 #define __Pyx_PyBytes_AsWritableString(s)     ((char*) PyBytes_AS_STRING(s))
674 #define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AS_STRING(s))
675 #define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AS_STRING(s))
676 #define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AS_STRING(s))
677 #define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AS_STRING(s))
678 #define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AS_STRING(s))
679 #define __Pyx_PyObject_AsWritableString(s)    ((char*) __Pyx_PyObject_AsString(s))
680 #define __Pyx_PyObject_AsWritableSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
681 #define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
682 #define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
683 #define __Pyx_PyObject_AsUString(s)    ((const unsigned char*) __Pyx_PyObject_AsString(s))
684 #define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
685 #define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
686 #define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
687 #define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
688 #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
__Pyx_Py_UNICODE_strlen(const Py_UNICODE * u)689 static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
690     const Py_UNICODE *u_end = u;
691     while (*u_end++) ;
692     return (size_t)(u_end - u - 1);
693 }
694 #define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
695 #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
696 #define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
697 #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
698 #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
699 static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
700 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
701 static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
702 static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
703 #define __Pyx_PySequence_Tuple(obj)\
704     (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
705 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
706 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
707 #if CYTHON_ASSUME_SAFE_MACROS
708 #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
709 #else
710 #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
711 #endif
712 #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
713 #if PY_MAJOR_VERSION >= 3
714 #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
715 #else
716 #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
717 #endif
718 #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
719 #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
720 static int __Pyx_sys_getdefaultencoding_not_ascii;
__Pyx_init_sys_getdefaultencoding_params(void)721 static int __Pyx_init_sys_getdefaultencoding_params(void) {
722     PyObject* sys;
723     PyObject* default_encoding = NULL;
724     PyObject* ascii_chars_u = NULL;
725     PyObject* ascii_chars_b = NULL;
726     const char* default_encoding_c;
727     sys = PyImport_ImportModule("sys");
728     if (!sys) goto bad;
729     default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
730     Py_DECREF(sys);
731     if (!default_encoding) goto bad;
732     default_encoding_c = PyBytes_AsString(default_encoding);
733     if (!default_encoding_c) goto bad;
734     if (strcmp(default_encoding_c, "ascii") == 0) {
735         __Pyx_sys_getdefaultencoding_not_ascii = 0;
736     } else {
737         char ascii_chars[128];
738         int c;
739         for (c = 0; c < 128; c++) {
740             ascii_chars[c] = c;
741         }
742         __Pyx_sys_getdefaultencoding_not_ascii = 1;
743         ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
744         if (!ascii_chars_u) goto bad;
745         ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
746         if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
747             PyErr_Format(
748                 PyExc_ValueError,
749                 "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
750                 default_encoding_c);
751             goto bad;
752         }
753         Py_DECREF(ascii_chars_u);
754         Py_DECREF(ascii_chars_b);
755     }
756     Py_DECREF(default_encoding);
757     return 0;
758 bad:
759     Py_XDECREF(default_encoding);
760     Py_XDECREF(ascii_chars_u);
761     Py_XDECREF(ascii_chars_b);
762     return -1;
763 }
764 #endif
765 #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
766 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
767 #else
768 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
769 #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
770 static char* __PYX_DEFAULT_STRING_ENCODING;
__Pyx_init_sys_getdefaultencoding_params(void)771 static int __Pyx_init_sys_getdefaultencoding_params(void) {
772     PyObject* sys;
773     PyObject* default_encoding = NULL;
774     char* default_encoding_c;
775     sys = PyImport_ImportModule("sys");
776     if (!sys) goto bad;
777     default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
778     Py_DECREF(sys);
779     if (!default_encoding) goto bad;
780     default_encoding_c = PyBytes_AsString(default_encoding);
781     if (!default_encoding_c) goto bad;
782     __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
783     if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
784     strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
785     Py_DECREF(default_encoding);
786     return 0;
787 bad:
788     Py_XDECREF(default_encoding);
789     return -1;
790 }
791 #endif
792 #endif
793 
794 
795 /* Test for GCC > 2.95 */
796 #if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
797   #define likely(x)   __builtin_expect(!!(x), 1)
798   #define unlikely(x) __builtin_expect(!!(x), 0)
799 #else /* !__GNUC__ or GCC < 2.95 */
800   #define likely(x)   (x)
801   #define unlikely(x) (x)
802 #endif /* __GNUC__ */
__Pyx_pretend_to_initialize(void * ptr)803 static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
804 
805 static PyObject *__pyx_m = NULL;
806 static PyObject *__pyx_d;
807 static PyObject *__pyx_b;
808 static PyObject *__pyx_cython_runtime = NULL;
809 static PyObject *__pyx_empty_tuple;
810 static PyObject *__pyx_empty_bytes;
811 static PyObject *__pyx_empty_unicode;
812 static int __pyx_lineno;
813 static int __pyx_clineno = 0;
814 static const char * __pyx_cfilenm= __FILE__;
815 static const char *__pyx_filename;
816 
817 
818 static const char *__pyx_f[] = {
819   "dipy/utils/omp.pyx",
820 };
821 
822 /*--- Type declarations ---*/
823 
824 /* --- Runtime support code (head) --- */
825 /* Refnanny.proto */
826 #ifndef CYTHON_REFNANNY
827   #define CYTHON_REFNANNY 0
828 #endif
829 #if CYTHON_REFNANNY
830   typedef struct {
831     void (*INCREF)(void*, PyObject*, int);
832     void (*DECREF)(void*, PyObject*, int);
833     void (*GOTREF)(void*, PyObject*, int);
834     void (*GIVEREF)(void*, PyObject*, int);
835     void* (*SetupContext)(const char*, int, const char*);
836     void (*FinishContext)(void**);
837   } __Pyx_RefNannyAPIStruct;
838   static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
839   static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
840   #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
841 #ifdef WITH_THREAD
842   #define __Pyx_RefNannySetupContext(name, acquire_gil)\
843           if (acquire_gil) {\
844               PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
845               __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
846               PyGILState_Release(__pyx_gilstate_save);\
847           } else {\
848               __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
849           }
850 #else
851   #define __Pyx_RefNannySetupContext(name, acquire_gil)\
852           __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
853 #endif
854   #define __Pyx_RefNannyFinishContext()\
855           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
856   #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
857   #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
858   #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
859   #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
860   #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
861   #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
862   #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
863   #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
864 #else
865   #define __Pyx_RefNannyDeclarations
866   #define __Pyx_RefNannySetupContext(name, acquire_gil)
867   #define __Pyx_RefNannyFinishContext()
868   #define __Pyx_INCREF(r) Py_INCREF(r)
869   #define __Pyx_DECREF(r) Py_DECREF(r)
870   #define __Pyx_GOTREF(r)
871   #define __Pyx_GIVEREF(r)
872   #define __Pyx_XINCREF(r) Py_XINCREF(r)
873   #define __Pyx_XDECREF(r) Py_XDECREF(r)
874   #define __Pyx_XGOTREF(r)
875   #define __Pyx_XGIVEREF(r)
876 #endif
877 #define __Pyx_XDECREF_SET(r, v) do {\
878         PyObject *tmp = (PyObject *) r;\
879         r = v; __Pyx_XDECREF(tmp);\
880     } while (0)
881 #define __Pyx_DECREF_SET(r, v) do {\
882         PyObject *tmp = (PyObject *) r;\
883         r = v; __Pyx_DECREF(tmp);\
884     } while (0)
885 #define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
886 #define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
887 
888 /* PyObjectGetAttrStr.proto */
889 #if CYTHON_USE_TYPE_SLOTS
890 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
891 #else
892 #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
893 #endif
894 
895 /* GetBuiltinName.proto */
896 static PyObject *__Pyx_GetBuiltinName(PyObject *name);
897 
898 /* PyDictVersioning.proto */
899 #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
900 #define __PYX_DICT_VERSION_INIT  ((PY_UINT64_T) -1)
901 #define __PYX_GET_DICT_VERSION(dict)  (((PyDictObject*)(dict))->ma_version_tag)
902 #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
903     (version_var) = __PYX_GET_DICT_VERSION(dict);\
904     (cache_var) = (value);
905 #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
906     static PY_UINT64_T __pyx_dict_version = 0;\
907     static PyObject *__pyx_dict_cached_value = NULL;\
908     if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
909         (VAR) = __pyx_dict_cached_value;\
910     } else {\
911         (VAR) = __pyx_dict_cached_value = (LOOKUP);\
912         __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
913     }\
914 }
915 static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj);
916 static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj);
917 static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version);
918 #else
919 #define __PYX_GET_DICT_VERSION(dict)  (0)
920 #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
921 #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP)  (VAR) = (LOOKUP);
922 #endif
923 
924 /* GetModuleGlobalName.proto */
925 #if CYTHON_USE_DICT_VERSIONS
926 #define __Pyx_GetModuleGlobalName(var, name)  {\
927     static PY_UINT64_T __pyx_dict_version = 0;\
928     static PyObject *__pyx_dict_cached_value = NULL;\
929     (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\
930         (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\
931         __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
932 }
933 #define __Pyx_GetModuleGlobalNameUncached(var, name)  {\
934     PY_UINT64_T __pyx_dict_version;\
935     PyObject *__pyx_dict_cached_value;\
936     (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
937 }
938 static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value);
939 #else
940 #define __Pyx_GetModuleGlobalName(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
941 #define __Pyx_GetModuleGlobalNameUncached(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
942 static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name);
943 #endif
944 
945 /* PyObjectCall.proto */
946 #if CYTHON_COMPILING_IN_CPYTHON
947 static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
948 #else
949 #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
950 #endif
951 
952 /* PyThreadStateGet.proto */
953 #if CYTHON_FAST_THREAD_STATE
954 #define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
955 #define __Pyx_PyThreadState_assign  __pyx_tstate = __Pyx_PyThreadState_Current;
956 #define __Pyx_PyErr_Occurred()  __pyx_tstate->curexc_type
957 #else
958 #define __Pyx_PyThreadState_declare
959 #define __Pyx_PyThreadState_assign
960 #define __Pyx_PyErr_Occurred()  PyErr_Occurred()
961 #endif
962 
963 /* PyErrFetchRestore.proto */
964 #if CYTHON_FAST_THREAD_STATE
965 #define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
966 #define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
967 #define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
968 #define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
969 #define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
970 static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
971 static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
972 #if CYTHON_COMPILING_IN_CPYTHON
973 #define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
974 #else
975 #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
976 #endif
977 #else
978 #define __Pyx_PyErr_Clear() PyErr_Clear()
979 #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
980 #define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
981 #define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
982 #define __Pyx_ErrRestoreInState(tstate, type, value, tb)  PyErr_Restore(type, value, tb)
983 #define __Pyx_ErrFetchInState(tstate, type, value, tb)  PyErr_Fetch(type, value, tb)
984 #define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
985 #define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
986 #endif
987 
988 /* RaiseException.proto */
989 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
990 
991 /* GetTopmostException.proto */
992 #if CYTHON_USE_EXC_INFO_STACK
993 static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate);
994 #endif
995 
996 /* SaveResetException.proto */
997 #if CYTHON_FAST_THREAD_STATE
998 #define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
999 static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
1000 #define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
1001 static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
1002 #else
1003 #define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
1004 #define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
1005 #endif
1006 
1007 /* PyErrExceptionMatches.proto */
1008 #if CYTHON_FAST_THREAD_STATE
1009 #define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
1010 static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
1011 #else
1012 #define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
1013 #endif
1014 
1015 /* GetException.proto */
1016 #if CYTHON_FAST_THREAD_STATE
1017 #define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
1018 static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
1019 #else
1020 static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
1021 #endif
1022 
1023 /* PyIntCompare.proto */
1024 static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, long inplace);
1025 
1026 /* PyIntBinop.proto */
1027 #if !CYTHON_COMPILING_IN_PYPY
1028 static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
1029 #else
1030 #define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\
1031     (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
1032 #endif
1033 
1034 /* PyFunctionFastCall.proto */
1035 #if CYTHON_FAST_PYCALL
1036 #define __Pyx_PyFunction_FastCall(func, args, nargs)\
1037     __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
1038 #if 1 || PY_VERSION_HEX < 0x030600B1
1039 static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs);
1040 #else
1041 #define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
1042 #endif
1043 #define __Pyx_BUILD_ASSERT_EXPR(cond)\
1044     (sizeof(char [1 - 2*!(cond)]) - 1)
1045 #ifndef Py_MEMBER_SIZE
1046 #define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
1047 #endif
1048   static size_t __pyx_pyframe_localsplus_offset = 0;
1049   #include "frameobject.h"
1050   #define __Pxy_PyFrame_Initialize_Offsets()\
1051     ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\
1052      (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
1053   #define __Pyx_PyFrame_GetLocalsplus(frame)\
1054     (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
1055 #endif
1056 
1057 /* PyObjectCallMethO.proto */
1058 #if CYTHON_COMPILING_IN_CPYTHON
1059 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
1060 #endif
1061 
1062 /* PyObjectCallNoArg.proto */
1063 #if CYTHON_COMPILING_IN_CPYTHON
1064 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
1065 #else
1066 #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
1067 #endif
1068 
1069 /* PyCFunctionFastCall.proto */
1070 #if CYTHON_FAST_PYCCALL
1071 static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
1072 #else
1073 #define __Pyx_PyCFunction_FastCall(func, args, nargs)  (assert(0), NULL)
1074 #endif
1075 
1076 /* PyObjectCallOneArg.proto */
1077 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
1078 
1079 /* WriteUnraisableException.proto */
1080 static void __Pyx_WriteUnraisable(const char *name, int clineno,
1081                                   int lineno, const char *filename,
1082                                   int full_traceback, int nogil);
1083 
1084 /* Import.proto */
1085 static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);
1086 
1087 /* CLineInTraceback.proto */
1088 #ifdef CYTHON_CLINE_IN_TRACEBACK
1089 #define __Pyx_CLineForTraceback(tstate, c_line)  (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
1090 #else
1091 static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
1092 #endif
1093 
1094 /* CodeObjectCache.proto */
1095 typedef struct {
1096     PyCodeObject* code_object;
1097     int code_line;
1098 } __Pyx_CodeObjectCacheEntry;
1099 struct __Pyx_CodeObjectCache {
1100     int count;
1101     int max_count;
1102     __Pyx_CodeObjectCacheEntry* entries;
1103 };
1104 static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
1105 static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
1106 static PyCodeObject *__pyx_find_code_object(int code_line);
1107 static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
1108 
1109 /* AddTraceback.proto */
1110 static void __Pyx_AddTraceback(const char *funcname, int c_line,
1111                                int py_line, const char *filename);
1112 
1113 /* GCCDiagnostics.proto */
1114 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
1115 #define __Pyx_HAS_GCC_DIAGNOSTIC
1116 #endif
1117 
1118 /* CIntToPy.proto */
1119 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);
1120 
1121 /* CIntToPy.proto */
1122 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
1123 
1124 /* CIntFromPy.proto */
1125 static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
1126 
1127 /* CIntFromPy.proto */
1128 static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
1129 
1130 /* FastTypeChecks.proto */
1131 #if CYTHON_COMPILING_IN_CPYTHON
1132 #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
1133 static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
1134 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
1135 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
1136 #else
1137 #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
1138 #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
1139 #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
1140 #endif
1141 #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
1142 
1143 /* CheckBinaryVersion.proto */
1144 static int __Pyx_check_binary_version(void);
1145 
1146 /* FunctionExport.proto */
1147 static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig);
1148 
1149 /* InitStrings.proto */
1150 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
1151 
1152 
1153 /* Module declarations from 'cython' */
1154 
1155 /* Module declarations from 'safe_openmp' */
1156 
1157 /* Module declarations from 'dipy.utils.omp' */
1158 static void __pyx_f_4dipy_5utils_3omp_set_num_threads(PyObject *); /*proto*/
1159 static void __pyx_f_4dipy_5utils_3omp_restore_default_num_threads(void); /*proto*/
1160 #define __Pyx_MODULE_NAME "dipy.utils.omp"
1161 extern int __pyx_module_is_main_dipy__utils__omp;
1162 int __pyx_module_is_main_dipy__utils__omp = 0;
1163 
1164 /* Implementation of 'dipy.utils.omp' */
1165 static PyObject *__pyx_builtin_ValueError;
1166 static PyObject *__pyx_builtin_TypeError;
1167 static const char __pyx_k_os[] = "os";
1168 static const char __pyx_k_all[] = "__all__";
1169 static const char __pyx_k_get[] = "get";
1170 static const char __pyx_k_main[] = "__main__";
1171 static const char __pyx_k_name[] = "__name__";
1172 static const char __pyx_k_test[] = "__test__";
1173 static const char __pyx_k_import[] = "__import__";
1174 static const char __pyx_k_environ[] = "environ";
1175 static const char __pyx_k_TypeError[] = "TypeError";
1176 static const char __pyx_k_cpu_count[] = "cpu_count";
1177 static const char __pyx_k_ValueError[] = "ValueError";
1178 static const char __pyx_k_have_openmp[] = "have_openmp";
1179 static const char __pyx_k_num_threads[] = "num_threads";
1180 static const char __pyx_k_thread_count[] = "thread_count";
1181 static const char __pyx_k_dipy_utils_omp[] = "dipy.utils.omp";
1182 static const char __pyx_k_OMP_NUM_THREADS[] = "OMP_NUM_THREADS";
1183 static const char __pyx_k_default_threads[] = "default_threads";
1184 static const char __pyx_k_set_omp_threads[] = "_set_omp_threads";
1185 static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
1186 static const char __pyx_k_dipy_utils_omp_pyx[] = "dipy/utils/omp.pyx";
1187 static const char __pyx_k_get_default_threads[] = "_get_default_threads";
1188 static const char __pyx_k_restore_omp_threads[] = "_restore_omp_threads";
1189 static const char __pyx_k_determine_num_threads[] = "determine_num_threads";
1190 static const char __pyx_k_num_threads_cannot_be_0[] = "num_threads cannot be 0";
1191 static const char __pyx_k_invalid_number_of_threads[] = "invalid number of threads";
1192 static const char __pyx_k_num_threads_must_be_an_int_or_No[] = "num_threads must be an int or None";
1193 static PyObject *__pyx_n_u_OMP_NUM_THREADS;
1194 static PyObject *__pyx_n_s_TypeError;
1195 static PyObject *__pyx_n_s_ValueError;
1196 static PyObject *__pyx_n_s_all;
1197 static PyObject *__pyx_n_s_cline_in_traceback;
1198 static PyObject *__pyx_n_s_cpu_count;
1199 static PyObject *__pyx_n_u_cpu_count;
1200 static PyObject *__pyx_n_s_default_threads;
1201 static PyObject *__pyx_n_u_default_threads;
1202 static PyObject *__pyx_n_s_determine_num_threads;
1203 static PyObject *__pyx_n_s_dipy_utils_omp;
1204 static PyObject *__pyx_kp_s_dipy_utils_omp_pyx;
1205 static PyObject *__pyx_n_s_environ;
1206 static PyObject *__pyx_n_s_get;
1207 static PyObject *__pyx_n_s_get_default_threads;
1208 static PyObject *__pyx_n_s_have_openmp;
1209 static PyObject *__pyx_n_u_have_openmp;
1210 static PyObject *__pyx_n_s_import;
1211 static PyObject *__pyx_kp_u_invalid_number_of_threads;
1212 static PyObject *__pyx_n_s_main;
1213 static PyObject *__pyx_n_s_name;
1214 static PyObject *__pyx_n_s_num_threads;
1215 static PyObject *__pyx_kp_u_num_threads_cannot_be_0;
1216 static PyObject *__pyx_kp_u_num_threads_must_be_an_int_or_No;
1217 static PyObject *__pyx_n_s_os;
1218 static PyObject *__pyx_n_s_restore_omp_threads;
1219 static PyObject *__pyx_n_s_set_omp_threads;
1220 static PyObject *__pyx_n_s_test;
1221 static PyObject *__pyx_n_s_thread_count;
1222 static PyObject *__pyx_n_u_thread_count;
1223 static PyObject *__pyx_pf_4dipy_5utils_3omp_cpu_count(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
1224 static PyObject *__pyx_pf_4dipy_5utils_3omp_2thread_count(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
1225 static PyObject *__pyx_pf_4dipy_5utils_3omp_4_get_default_threads(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
1226 static PyObject *__pyx_pf_4dipy_5utils_3omp_6determine_num_threads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_num_threads); /* proto */
1227 static PyObject *__pyx_pf_4dipy_5utils_3omp_8_set_omp_threads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_num_threads); /* proto */
1228 static PyObject *__pyx_pf_4dipy_5utils_3omp_10_restore_omp_threads(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
1229 static PyObject *__pyx_int_0;
1230 static PyObject *__pyx_int_1;
1231 static PyObject *__pyx_tuple_;
1232 static PyObject *__pyx_tuple__2;
1233 static PyObject *__pyx_tuple__3;
1234 static PyObject *__pyx_tuple__4;
1235 static PyObject *__pyx_tuple__7;
1236 static PyObject *__pyx_tuple__9;
1237 static PyObject *__pyx_tuple__11;
1238 static PyObject *__pyx_codeobj__5;
1239 static PyObject *__pyx_codeobj__6;
1240 static PyObject *__pyx_codeobj__8;
1241 static PyObject *__pyx_codeobj__10;
1242 static PyObject *__pyx_codeobj__12;
1243 static PyObject *__pyx_codeobj__13;
1244 /* Late includes */
1245 
1246 /* "dipy/utils/omp.pyx":11
1247  *
1248  *
1249  * def cpu_count():             # <<<<<<<<<<<<<<
1250  *     """Return number of cpus as determined by omp_get_num_procs."""
1251  *     if have_openmp:
1252  */
1253 
1254 /* Python wrapper */
1255 static PyObject *__pyx_pw_4dipy_5utils_3omp_1cpu_count(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
1256 static char __pyx_doc_4dipy_5utils_3omp_cpu_count[] = "Return number of cpus as determined by omp_get_num_procs.";
1257 static PyMethodDef __pyx_mdef_4dipy_5utils_3omp_1cpu_count = {"cpu_count", (PyCFunction)__pyx_pw_4dipy_5utils_3omp_1cpu_count, METH_NOARGS, __pyx_doc_4dipy_5utils_3omp_cpu_count};
__pyx_pw_4dipy_5utils_3omp_1cpu_count(PyObject * __pyx_self,CYTHON_UNUSED PyObject * unused)1258 static PyObject *__pyx_pw_4dipy_5utils_3omp_1cpu_count(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
1259   PyObject *__pyx_r = 0;
1260   __Pyx_RefNannyDeclarations
1261   __Pyx_RefNannySetupContext("cpu_count (wrapper)", 0);
1262   __pyx_r = __pyx_pf_4dipy_5utils_3omp_cpu_count(__pyx_self);
1263 
1264   /* function exit code */
1265   __Pyx_RefNannyFinishContext();
1266   return __pyx_r;
1267 }
1268 
__pyx_pf_4dipy_5utils_3omp_cpu_count(CYTHON_UNUSED PyObject * __pyx_self)1269 static PyObject *__pyx_pf_4dipy_5utils_3omp_cpu_count(CYTHON_UNUSED PyObject *__pyx_self) {
1270   PyObject *__pyx_r = NULL;
1271   __Pyx_RefNannyDeclarations
1272   PyObject *__pyx_t_1 = NULL;
1273   int __pyx_t_2;
1274   int __pyx_lineno = 0;
1275   const char *__pyx_filename = NULL;
1276   int __pyx_clineno = 0;
1277   __Pyx_RefNannySetupContext("cpu_count", 0);
1278 
1279   /* "dipy/utils/omp.pyx":13
1280  * def cpu_count():
1281  *     """Return number of cpus as determined by omp_get_num_procs."""
1282  *     if have_openmp:             # <<<<<<<<<<<<<<
1283  *         return openmp.omp_get_num_procs()
1284  *     else:
1285  */
1286   __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_have_openmp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error)
1287   __Pyx_GOTREF(__pyx_t_1);
1288   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 13, __pyx_L1_error)
1289   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1290   if (__pyx_t_2) {
1291 
1292     /* "dipy/utils/omp.pyx":14
1293  *     """Return number of cpus as determined by omp_get_num_procs."""
1294  *     if have_openmp:
1295  *         return openmp.omp_get_num_procs()             # <<<<<<<<<<<<<<
1296  *     else:
1297  *         return 1
1298  */
1299     __Pyx_XDECREF(__pyx_r);
1300     __pyx_t_1 = __Pyx_PyInt_From_int(omp_get_num_procs()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error)
1301     __Pyx_GOTREF(__pyx_t_1);
1302     __pyx_r = __pyx_t_1;
1303     __pyx_t_1 = 0;
1304     goto __pyx_L0;
1305 
1306     /* "dipy/utils/omp.pyx":13
1307  * def cpu_count():
1308  *     """Return number of cpus as determined by omp_get_num_procs."""
1309  *     if have_openmp:             # <<<<<<<<<<<<<<
1310  *         return openmp.omp_get_num_procs()
1311  *     else:
1312  */
1313   }
1314 
1315   /* "dipy/utils/omp.pyx":16
1316  *         return openmp.omp_get_num_procs()
1317  *     else:
1318  *         return 1             # <<<<<<<<<<<<<<
1319  *
1320  *
1321  */
1322   /*else*/ {
1323     __Pyx_XDECREF(__pyx_r);
1324     __Pyx_INCREF(__pyx_int_1);
1325     __pyx_r = __pyx_int_1;
1326     goto __pyx_L0;
1327   }
1328 
1329   /* "dipy/utils/omp.pyx":11
1330  *
1331  *
1332  * def cpu_count():             # <<<<<<<<<<<<<<
1333  *     """Return number of cpus as determined by omp_get_num_procs."""
1334  *     if have_openmp:
1335  */
1336 
1337   /* function exit code */
1338   __pyx_L1_error:;
1339   __Pyx_XDECREF(__pyx_t_1);
1340   __Pyx_AddTraceback("dipy.utils.omp.cpu_count", __pyx_clineno, __pyx_lineno, __pyx_filename);
1341   __pyx_r = NULL;
1342   __pyx_L0:;
1343   __Pyx_XGIVEREF(__pyx_r);
1344   __Pyx_RefNannyFinishContext();
1345   return __pyx_r;
1346 }
1347 
1348 /* "dipy/utils/omp.pyx":19
1349  *
1350  *
1351  * def thread_count():             # <<<<<<<<<<<<<<
1352  *     """Return number of threads as determined by omp_get_max_threads."""
1353  *     if have_openmp:
1354  */
1355 
1356 /* Python wrapper */
1357 static PyObject *__pyx_pw_4dipy_5utils_3omp_3thread_count(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
1358 static char __pyx_doc_4dipy_5utils_3omp_2thread_count[] = "Return number of threads as determined by omp_get_max_threads.";
1359 static PyMethodDef __pyx_mdef_4dipy_5utils_3omp_3thread_count = {"thread_count", (PyCFunction)__pyx_pw_4dipy_5utils_3omp_3thread_count, METH_NOARGS, __pyx_doc_4dipy_5utils_3omp_2thread_count};
__pyx_pw_4dipy_5utils_3omp_3thread_count(PyObject * __pyx_self,CYTHON_UNUSED PyObject * unused)1360 static PyObject *__pyx_pw_4dipy_5utils_3omp_3thread_count(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
1361   PyObject *__pyx_r = 0;
1362   __Pyx_RefNannyDeclarations
1363   __Pyx_RefNannySetupContext("thread_count (wrapper)", 0);
1364   __pyx_r = __pyx_pf_4dipy_5utils_3omp_2thread_count(__pyx_self);
1365 
1366   /* function exit code */
1367   __Pyx_RefNannyFinishContext();
1368   return __pyx_r;
1369 }
1370 
__pyx_pf_4dipy_5utils_3omp_2thread_count(CYTHON_UNUSED PyObject * __pyx_self)1371 static PyObject *__pyx_pf_4dipy_5utils_3omp_2thread_count(CYTHON_UNUSED PyObject *__pyx_self) {
1372   PyObject *__pyx_r = NULL;
1373   __Pyx_RefNannyDeclarations
1374   PyObject *__pyx_t_1 = NULL;
1375   int __pyx_t_2;
1376   int __pyx_lineno = 0;
1377   const char *__pyx_filename = NULL;
1378   int __pyx_clineno = 0;
1379   __Pyx_RefNannySetupContext("thread_count", 0);
1380 
1381   /* "dipy/utils/omp.pyx":21
1382  * def thread_count():
1383  *     """Return number of threads as determined by omp_get_max_threads."""
1384  *     if have_openmp:             # <<<<<<<<<<<<<<
1385  *         return openmp.omp_get_max_threads()
1386  *     else:
1387  */
1388   __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_have_openmp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error)
1389   __Pyx_GOTREF(__pyx_t_1);
1390   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 21, __pyx_L1_error)
1391   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1392   if (__pyx_t_2) {
1393 
1394     /* "dipy/utils/omp.pyx":22
1395  *     """Return number of threads as determined by omp_get_max_threads."""
1396  *     if have_openmp:
1397  *         return openmp.omp_get_max_threads()             # <<<<<<<<<<<<<<
1398  *     else:
1399  *         return 1
1400  */
1401     __Pyx_XDECREF(__pyx_r);
1402     __pyx_t_1 = __Pyx_PyInt_From_int(omp_get_max_threads()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error)
1403     __Pyx_GOTREF(__pyx_t_1);
1404     __pyx_r = __pyx_t_1;
1405     __pyx_t_1 = 0;
1406     goto __pyx_L0;
1407 
1408     /* "dipy/utils/omp.pyx":21
1409  * def thread_count():
1410  *     """Return number of threads as determined by omp_get_max_threads."""
1411  *     if have_openmp:             # <<<<<<<<<<<<<<
1412  *         return openmp.omp_get_max_threads()
1413  *     else:
1414  */
1415   }
1416 
1417   /* "dipy/utils/omp.pyx":24
1418  *         return openmp.omp_get_max_threads()
1419  *     else:
1420  *         return 1             # <<<<<<<<<<<<<<
1421  *
1422  *
1423  */
1424   /*else*/ {
1425     __Pyx_XDECREF(__pyx_r);
1426     __Pyx_INCREF(__pyx_int_1);
1427     __pyx_r = __pyx_int_1;
1428     goto __pyx_L0;
1429   }
1430 
1431   /* "dipy/utils/omp.pyx":19
1432  *
1433  *
1434  * def thread_count():             # <<<<<<<<<<<<<<
1435  *     """Return number of threads as determined by omp_get_max_threads."""
1436  *     if have_openmp:
1437  */
1438 
1439   /* function exit code */
1440   __pyx_L1_error:;
1441   __Pyx_XDECREF(__pyx_t_1);
1442   __Pyx_AddTraceback("dipy.utils.omp.thread_count", __pyx_clineno, __pyx_lineno, __pyx_filename);
1443   __pyx_r = NULL;
1444   __pyx_L0:;
1445   __Pyx_XGIVEREF(__pyx_r);
1446   __Pyx_RefNannyFinishContext();
1447   return __pyx_r;
1448 }
1449 
1450 /* "dipy/utils/omp.pyx":27
1451  *
1452  *
1453  * def _get_default_threads():             # <<<<<<<<<<<<<<
1454  *     """Default number of threads for OpenMP.
1455  *
1456  */
1457 
1458 /* Python wrapper */
1459 static PyObject *__pyx_pw_4dipy_5utils_3omp_5_get_default_threads(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
1460 static char __pyx_doc_4dipy_5utils_3omp_4_get_default_threads[] = "Default number of threads for OpenMP.\n\n    This function prioritizes the OMP_NUM_THREADS environment variable.\n    ";
1461 static PyMethodDef __pyx_mdef_4dipy_5utils_3omp_5_get_default_threads = {"_get_default_threads", (PyCFunction)__pyx_pw_4dipy_5utils_3omp_5_get_default_threads, METH_NOARGS, __pyx_doc_4dipy_5utils_3omp_4_get_default_threads};
__pyx_pw_4dipy_5utils_3omp_5_get_default_threads(PyObject * __pyx_self,CYTHON_UNUSED PyObject * unused)1462 static PyObject *__pyx_pw_4dipy_5utils_3omp_5_get_default_threads(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
1463   PyObject *__pyx_r = 0;
1464   __Pyx_RefNannyDeclarations
1465   __Pyx_RefNannySetupContext("_get_default_threads (wrapper)", 0);
1466   __pyx_r = __pyx_pf_4dipy_5utils_3omp_4_get_default_threads(__pyx_self);
1467 
1468   /* function exit code */
1469   __Pyx_RefNannyFinishContext();
1470   return __pyx_r;
1471 }
1472 
__pyx_pf_4dipy_5utils_3omp_4_get_default_threads(CYTHON_UNUSED PyObject * __pyx_self)1473 static PyObject *__pyx_pf_4dipy_5utils_3omp_4_get_default_threads(CYTHON_UNUSED PyObject *__pyx_self) {
1474   PyObject *__pyx_v_default_threads = NULL;
1475   PyObject *__pyx_r = NULL;
1476   __Pyx_RefNannyDeclarations
1477   PyObject *__pyx_t_1 = NULL;
1478   int __pyx_t_2;
1479   PyObject *__pyx_t_3 = NULL;
1480   PyObject *__pyx_t_4 = NULL;
1481   PyObject *__pyx_t_5 = NULL;
1482   PyObject *__pyx_t_6 = NULL;
1483   int __pyx_t_7;
1484   PyObject *__pyx_t_8 = NULL;
1485   PyObject *__pyx_t_9 = NULL;
1486   int __pyx_lineno = 0;
1487   const char *__pyx_filename = NULL;
1488   int __pyx_clineno = 0;
1489   __Pyx_RefNannySetupContext("_get_default_threads", 0);
1490 
1491   /* "dipy/utils/omp.pyx":32
1492  *     This function prioritizes the OMP_NUM_THREADS environment variable.
1493  *     """
1494  *     if have_openmp:             # <<<<<<<<<<<<<<
1495  *         try:
1496  *             default_threads = int(os.environ.get('OMP_NUM_THREADS', None))
1497  */
1498   __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_have_openmp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error)
1499   __Pyx_GOTREF(__pyx_t_1);
1500   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 32, __pyx_L1_error)
1501   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1502   if (__pyx_t_2) {
1503 
1504     /* "dipy/utils/omp.pyx":33
1505  *     """
1506  *     if have_openmp:
1507  *         try:             # <<<<<<<<<<<<<<
1508  *             default_threads = int(os.environ.get('OMP_NUM_THREADS', None))
1509  *             if default_threads < 1:
1510  */
1511     {
1512       __Pyx_PyThreadState_declare
1513       __Pyx_PyThreadState_assign
1514       __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
1515       __Pyx_XGOTREF(__pyx_t_3);
1516       __Pyx_XGOTREF(__pyx_t_4);
1517       __Pyx_XGOTREF(__pyx_t_5);
1518       /*try:*/ {
1519 
1520         /* "dipy/utils/omp.pyx":34
1521  *     if have_openmp:
1522  *         try:
1523  *             default_threads = int(os.environ.get('OMP_NUM_THREADS', None))             # <<<<<<<<<<<<<<
1524  *             if default_threads < 1:
1525  *                 raise ValueError("invalid number of threads")
1526  */
1527         __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 34, __pyx_L4_error)
1528         __Pyx_GOTREF(__pyx_t_1);
1529         __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_environ); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 34, __pyx_L4_error)
1530         __Pyx_GOTREF(__pyx_t_6);
1531         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1532         __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_get); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 34, __pyx_L4_error)
1533         __Pyx_GOTREF(__pyx_t_1);
1534         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
1535         __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 34, __pyx_L4_error)
1536         __Pyx_GOTREF(__pyx_t_6);
1537         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1538         __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 34, __pyx_L4_error)
1539         __Pyx_GOTREF(__pyx_t_1);
1540         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
1541         __pyx_v_default_threads = __pyx_t_1;
1542         __pyx_t_1 = 0;
1543 
1544         /* "dipy/utils/omp.pyx":35
1545  *         try:
1546  *             default_threads = int(os.environ.get('OMP_NUM_THREADS', None))
1547  *             if default_threads < 1:             # <<<<<<<<<<<<<<
1548  *                 raise ValueError("invalid number of threads")
1549  *         except (ValueError, TypeError):
1550  */
1551         __pyx_t_1 = PyObject_RichCompare(__pyx_v_default_threads, __pyx_int_1, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 35, __pyx_L4_error)
1552         __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 35, __pyx_L4_error)
1553         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1554         if (unlikely(__pyx_t_2)) {
1555 
1556           /* "dipy/utils/omp.pyx":36
1557  *             default_threads = int(os.environ.get('OMP_NUM_THREADS', None))
1558  *             if default_threads < 1:
1559  *                 raise ValueError("invalid number of threads")             # <<<<<<<<<<<<<<
1560  *         except (ValueError, TypeError):
1561  *             default_threads = openmp.omp_get_num_procs()
1562  */
1563           __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 36, __pyx_L4_error)
1564           __Pyx_GOTREF(__pyx_t_1);
1565           __Pyx_Raise(__pyx_t_1, 0, 0, 0);
1566           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1567           __PYX_ERR(0, 36, __pyx_L4_error)
1568 
1569           /* "dipy/utils/omp.pyx":35
1570  *         try:
1571  *             default_threads = int(os.environ.get('OMP_NUM_THREADS', None))
1572  *             if default_threads < 1:             # <<<<<<<<<<<<<<
1573  *                 raise ValueError("invalid number of threads")
1574  *         except (ValueError, TypeError):
1575  */
1576         }
1577 
1578         /* "dipy/utils/omp.pyx":33
1579  *     """
1580  *     if have_openmp:
1581  *         try:             # <<<<<<<<<<<<<<
1582  *             default_threads = int(os.environ.get('OMP_NUM_THREADS', None))
1583  *             if default_threads < 1:
1584  */
1585       }
1586       __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
1587       __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
1588       __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
1589       goto __pyx_L9_try_end;
1590       __pyx_L4_error:;
1591       __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
1592       __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
1593 
1594       /* "dipy/utils/omp.pyx":37
1595  *             if default_threads < 1:
1596  *                 raise ValueError("invalid number of threads")
1597  *         except (ValueError, TypeError):             # <<<<<<<<<<<<<<
1598  *             default_threads = openmp.omp_get_num_procs()
1599  *         return default_threads
1600  */
1601       __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError) || __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError);
1602       if (__pyx_t_7) {
1603         __Pyx_AddTraceback("dipy.utils.omp._get_default_threads", __pyx_clineno, __pyx_lineno, __pyx_filename);
1604         if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_6, &__pyx_t_8) < 0) __PYX_ERR(0, 37, __pyx_L6_except_error)
1605         __Pyx_GOTREF(__pyx_t_1);
1606         __Pyx_GOTREF(__pyx_t_6);
1607         __Pyx_GOTREF(__pyx_t_8);
1608 
1609         /* "dipy/utils/omp.pyx":38
1610  *                 raise ValueError("invalid number of threads")
1611  *         except (ValueError, TypeError):
1612  *             default_threads = openmp.omp_get_num_procs()             # <<<<<<<<<<<<<<
1613  *         return default_threads
1614  *     else:
1615  */
1616         __pyx_t_9 = __Pyx_PyInt_From_int(omp_get_num_procs()); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 38, __pyx_L6_except_error)
1617         __Pyx_GOTREF(__pyx_t_9);
1618         __Pyx_XDECREF_SET(__pyx_v_default_threads, __pyx_t_9);
1619         __pyx_t_9 = 0;
1620         __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
1621         __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
1622         __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
1623         goto __pyx_L5_exception_handled;
1624       }
1625       goto __pyx_L6_except_error;
1626       __pyx_L6_except_error:;
1627 
1628       /* "dipy/utils/omp.pyx":33
1629  *     """
1630  *     if have_openmp:
1631  *         try:             # <<<<<<<<<<<<<<
1632  *             default_threads = int(os.environ.get('OMP_NUM_THREADS', None))
1633  *             if default_threads < 1:
1634  */
1635       __Pyx_XGIVEREF(__pyx_t_3);
1636       __Pyx_XGIVEREF(__pyx_t_4);
1637       __Pyx_XGIVEREF(__pyx_t_5);
1638       __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
1639       goto __pyx_L1_error;
1640       __pyx_L5_exception_handled:;
1641       __Pyx_XGIVEREF(__pyx_t_3);
1642       __Pyx_XGIVEREF(__pyx_t_4);
1643       __Pyx_XGIVEREF(__pyx_t_5);
1644       __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
1645       __pyx_L9_try_end:;
1646     }
1647 
1648     /* "dipy/utils/omp.pyx":39
1649  *         except (ValueError, TypeError):
1650  *             default_threads = openmp.omp_get_num_procs()
1651  *         return default_threads             # <<<<<<<<<<<<<<
1652  *     else:
1653  *         return 1
1654  */
1655     __Pyx_XDECREF(__pyx_r);
1656     __Pyx_INCREF(__pyx_v_default_threads);
1657     __pyx_r = __pyx_v_default_threads;
1658     goto __pyx_L0;
1659 
1660     /* "dipy/utils/omp.pyx":32
1661  *     This function prioritizes the OMP_NUM_THREADS environment variable.
1662  *     """
1663  *     if have_openmp:             # <<<<<<<<<<<<<<
1664  *         try:
1665  *             default_threads = int(os.environ.get('OMP_NUM_THREADS', None))
1666  */
1667   }
1668 
1669   /* "dipy/utils/omp.pyx":41
1670  *         return default_threads
1671  *     else:
1672  *         return 1             # <<<<<<<<<<<<<<
1673  * default_threads = _get_default_threads()
1674  *
1675  */
1676   /*else*/ {
1677     __Pyx_XDECREF(__pyx_r);
1678     __Pyx_INCREF(__pyx_int_1);
1679     __pyx_r = __pyx_int_1;
1680     goto __pyx_L0;
1681   }
1682 
1683   /* "dipy/utils/omp.pyx":27
1684  *
1685  *
1686  * def _get_default_threads():             # <<<<<<<<<<<<<<
1687  *     """Default number of threads for OpenMP.
1688  *
1689  */
1690 
1691   /* function exit code */
1692   __pyx_L1_error:;
1693   __Pyx_XDECREF(__pyx_t_1);
1694   __Pyx_XDECREF(__pyx_t_6);
1695   __Pyx_XDECREF(__pyx_t_8);
1696   __Pyx_XDECREF(__pyx_t_9);
1697   __Pyx_AddTraceback("dipy.utils.omp._get_default_threads", __pyx_clineno, __pyx_lineno, __pyx_filename);
1698   __pyx_r = NULL;
1699   __pyx_L0:;
1700   __Pyx_XDECREF(__pyx_v_default_threads);
1701   __Pyx_XGIVEREF(__pyx_r);
1702   __Pyx_RefNannyFinishContext();
1703   return __pyx_r;
1704 }
1705 
1706 /* "dipy/utils/omp.pyx":45
1707  *
1708  *
1709  * def determine_num_threads(num_threads):             # <<<<<<<<<<<<<<
1710  *     """Determine the effective number of threads to be used for OpenMP calls
1711  *
1712  */
1713 
1714 /* Python wrapper */
1715 static PyObject *__pyx_pw_4dipy_5utils_3omp_7determine_num_threads(PyObject *__pyx_self, PyObject *__pyx_v_num_threads); /*proto*/
1716 static char __pyx_doc_4dipy_5utils_3omp_6determine_num_threads[] = "Determine the effective number of threads to be used for OpenMP calls\n\n    - For ``num_threads = None``,\n      - if the ``OMP_NUM_THREADS`` environment variable is set, return that\n      value\n      - otherwise, return the maximum number of cores retrieved by\n      ``openmp.opm_get_num_procs()``.\n\n    - For ``num_threads > 0``, return this value.\n\n    - For ``num_threads < 0``, return the maximal number of threads minus\n      ``|num_threads + 1|``. In particular ``num_threads = -1`` will use as\n      many threads as there are available cores on the machine.\n\n    - For ``num_threads = 0`` a ValueError is raised.\n\n    Parameters\n    ----------\n    num_threads : int or None\n        Desired number of threads to be used.\n    ";
1717 static PyMethodDef __pyx_mdef_4dipy_5utils_3omp_7determine_num_threads = {"determine_num_threads", (PyCFunction)__pyx_pw_4dipy_5utils_3omp_7determine_num_threads, METH_O, __pyx_doc_4dipy_5utils_3omp_6determine_num_threads};
__pyx_pw_4dipy_5utils_3omp_7determine_num_threads(PyObject * __pyx_self,PyObject * __pyx_v_num_threads)1718 static PyObject *__pyx_pw_4dipy_5utils_3omp_7determine_num_threads(PyObject *__pyx_self, PyObject *__pyx_v_num_threads) {
1719   PyObject *__pyx_r = 0;
1720   __Pyx_RefNannyDeclarations
1721   __Pyx_RefNannySetupContext("determine_num_threads (wrapper)", 0);
1722   __pyx_r = __pyx_pf_4dipy_5utils_3omp_6determine_num_threads(__pyx_self, ((PyObject *)__pyx_v_num_threads));
1723 
1724   /* function exit code */
1725   __Pyx_RefNannyFinishContext();
1726   return __pyx_r;
1727 }
1728 
__pyx_pf_4dipy_5utils_3omp_6determine_num_threads(CYTHON_UNUSED PyObject * __pyx_self,PyObject * __pyx_v_num_threads)1729 static PyObject *__pyx_pf_4dipy_5utils_3omp_6determine_num_threads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_num_threads) {
1730   PyObject *__pyx_r = NULL;
1731   __Pyx_RefNannyDeclarations
1732   int __pyx_t_1;
1733   int __pyx_t_2;
1734   int __pyx_t_3;
1735   PyObject *__pyx_t_4 = NULL;
1736   PyObject *__pyx_t_5 = NULL;
1737   PyObject *__pyx_t_6 = NULL;
1738   long __pyx_t_7;
1739   PyObject *__pyx_t_8 = NULL;
1740   int __pyx_lineno = 0;
1741   const char *__pyx_filename = NULL;
1742   int __pyx_clineno = 0;
1743   __Pyx_RefNannySetupContext("determine_num_threads", 0);
1744 
1745   /* "dipy/utils/omp.pyx":67
1746  *         Desired number of threads to be used.
1747  *     """
1748  *     if not isinstance(num_threads, int) and num_threads is not None:             # <<<<<<<<<<<<<<
1749  *         raise TypeError("num_threads must be an int or None")
1750  *
1751  */
1752   __pyx_t_2 = PyInt_Check(__pyx_v_num_threads);
1753   __pyx_t_3 = ((!(__pyx_t_2 != 0)) != 0);
1754   if (__pyx_t_3) {
1755   } else {
1756     __pyx_t_1 = __pyx_t_3;
1757     goto __pyx_L4_bool_binop_done;
1758   }
1759   __pyx_t_3 = (__pyx_v_num_threads != Py_None);
1760   __pyx_t_2 = (__pyx_t_3 != 0);
1761   __pyx_t_1 = __pyx_t_2;
1762   __pyx_L4_bool_binop_done:;
1763   if (unlikely(__pyx_t_1)) {
1764 
1765     /* "dipy/utils/omp.pyx":68
1766  *     """
1767  *     if not isinstance(num_threads, int) and num_threads is not None:
1768  *         raise TypeError("num_threads must be an int or None")             # <<<<<<<<<<<<<<
1769  *
1770  *     if num_threads == 0:
1771  */
1772     __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 68, __pyx_L1_error)
1773     __Pyx_GOTREF(__pyx_t_4);
1774     __Pyx_Raise(__pyx_t_4, 0, 0, 0);
1775     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1776     __PYX_ERR(0, 68, __pyx_L1_error)
1777 
1778     /* "dipy/utils/omp.pyx":67
1779  *         Desired number of threads to be used.
1780  *     """
1781  *     if not isinstance(num_threads, int) and num_threads is not None:             # <<<<<<<<<<<<<<
1782  *         raise TypeError("num_threads must be an int or None")
1783  *
1784  */
1785   }
1786 
1787   /* "dipy/utils/omp.pyx":70
1788  *         raise TypeError("num_threads must be an int or None")
1789  *
1790  *     if num_threads == 0:             # <<<<<<<<<<<<<<
1791  *         raise ValueError("num_threads cannot be 0")
1792  *
1793  */
1794   __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_v_num_threads, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 70, __pyx_L1_error)
1795   __Pyx_GOTREF(__pyx_t_4);
1796   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 70, __pyx_L1_error)
1797   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1798   if (unlikely(__pyx_t_1)) {
1799 
1800     /* "dipy/utils/omp.pyx":71
1801  *
1802  *     if num_threads == 0:
1803  *         raise ValueError("num_threads cannot be 0")             # <<<<<<<<<<<<<<
1804  *
1805  *     if num_threads is None:
1806  */
1807     __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 71, __pyx_L1_error)
1808     __Pyx_GOTREF(__pyx_t_4);
1809     __Pyx_Raise(__pyx_t_4, 0, 0, 0);
1810     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1811     __PYX_ERR(0, 71, __pyx_L1_error)
1812 
1813     /* "dipy/utils/omp.pyx":70
1814  *         raise TypeError("num_threads must be an int or None")
1815  *
1816  *     if num_threads == 0:             # <<<<<<<<<<<<<<
1817  *         raise ValueError("num_threads cannot be 0")
1818  *
1819  */
1820   }
1821 
1822   /* "dipy/utils/omp.pyx":73
1823  *         raise ValueError("num_threads cannot be 0")
1824  *
1825  *     if num_threads is None:             # <<<<<<<<<<<<<<
1826  *         return default_threads
1827  *
1828  */
1829   __pyx_t_1 = (__pyx_v_num_threads == Py_None);
1830   __pyx_t_2 = (__pyx_t_1 != 0);
1831   if (__pyx_t_2) {
1832 
1833     /* "dipy/utils/omp.pyx":74
1834  *
1835  *     if num_threads is None:
1836  *         return default_threads             # <<<<<<<<<<<<<<
1837  *
1838  *     if num_threads < 0:
1839  */
1840     __Pyx_XDECREF(__pyx_r);
1841     __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_default_threads); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 74, __pyx_L1_error)
1842     __Pyx_GOTREF(__pyx_t_4);
1843     __pyx_r = __pyx_t_4;
1844     __pyx_t_4 = 0;
1845     goto __pyx_L0;
1846 
1847     /* "dipy/utils/omp.pyx":73
1848  *         raise ValueError("num_threads cannot be 0")
1849  *
1850  *     if num_threads is None:             # <<<<<<<<<<<<<<
1851  *         return default_threads
1852  *
1853  */
1854   }
1855 
1856   /* "dipy/utils/omp.pyx":76
1857  *         return default_threads
1858  *
1859  *     if num_threads < 0:             # <<<<<<<<<<<<<<
1860  *         return max(1, cpu_count() + num_threads + 1)
1861  *
1862  */
1863   __pyx_t_4 = PyObject_RichCompare(__pyx_v_num_threads, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __pyx_L1_error)
1864   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 76, __pyx_L1_error)
1865   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1866   if (__pyx_t_2) {
1867 
1868     /* "dipy/utils/omp.pyx":77
1869  *
1870  *     if num_threads < 0:
1871  *         return max(1, cpu_count() + num_threads + 1)             # <<<<<<<<<<<<<<
1872  *
1873  *     return num_threads
1874  */
1875     __Pyx_XDECREF(__pyx_r);
1876     __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_cpu_count); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 77, __pyx_L1_error)
1877     __Pyx_GOTREF(__pyx_t_5);
1878     __pyx_t_6 = NULL;
1879     if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
1880       __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
1881       if (likely(__pyx_t_6)) {
1882         PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
1883         __Pyx_INCREF(__pyx_t_6);
1884         __Pyx_INCREF(function);
1885         __Pyx_DECREF_SET(__pyx_t_5, function);
1886       }
1887     }
1888     __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
1889     __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
1890     if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 77, __pyx_L1_error)
1891     __Pyx_GOTREF(__pyx_t_4);
1892     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
1893     __pyx_t_5 = PyNumber_Add(__pyx_t_4, __pyx_v_num_threads); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 77, __pyx_L1_error)
1894     __Pyx_GOTREF(__pyx_t_5);
1895     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1896     __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_5, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 77, __pyx_L1_error)
1897     __Pyx_GOTREF(__pyx_t_4);
1898     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
1899     __pyx_t_7 = 1;
1900     __pyx_t_6 = __Pyx_PyInt_From_long(__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 77, __pyx_L1_error)
1901     __Pyx_GOTREF(__pyx_t_6);
1902     __pyx_t_8 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_GT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 77, __pyx_L1_error)
1903     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
1904     __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 77, __pyx_L1_error)
1905     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
1906     if (__pyx_t_2) {
1907       __Pyx_INCREF(__pyx_t_4);
1908       __pyx_t_5 = __pyx_t_4;
1909     } else {
1910       __pyx_t_8 = __Pyx_PyInt_From_long(__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 77, __pyx_L1_error)
1911       __Pyx_GOTREF(__pyx_t_8);
1912       __pyx_t_5 = __pyx_t_8;
1913       __pyx_t_8 = 0;
1914     }
1915     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1916     __Pyx_INCREF(__pyx_t_5);
1917     __pyx_r = __pyx_t_5;
1918     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
1919     goto __pyx_L0;
1920 
1921     /* "dipy/utils/omp.pyx":76
1922  *         return default_threads
1923  *
1924  *     if num_threads < 0:             # <<<<<<<<<<<<<<
1925  *         return max(1, cpu_count() + num_threads + 1)
1926  *
1927  */
1928   }
1929 
1930   /* "dipy/utils/omp.pyx":79
1931  *         return max(1, cpu_count() + num_threads + 1)
1932  *
1933  *     return num_threads             # <<<<<<<<<<<<<<
1934  *
1935  *
1936  */
1937   __Pyx_XDECREF(__pyx_r);
1938   __Pyx_INCREF(__pyx_v_num_threads);
1939   __pyx_r = __pyx_v_num_threads;
1940   goto __pyx_L0;
1941 
1942   /* "dipy/utils/omp.pyx":45
1943  *
1944  *
1945  * def determine_num_threads(num_threads):             # <<<<<<<<<<<<<<
1946  *     """Determine the effective number of threads to be used for OpenMP calls
1947  *
1948  */
1949 
1950   /* function exit code */
1951   __pyx_L1_error:;
1952   __Pyx_XDECREF(__pyx_t_4);
1953   __Pyx_XDECREF(__pyx_t_5);
1954   __Pyx_XDECREF(__pyx_t_6);
1955   __Pyx_XDECREF(__pyx_t_8);
1956   __Pyx_AddTraceback("dipy.utils.omp.determine_num_threads", __pyx_clineno, __pyx_lineno, __pyx_filename);
1957   __pyx_r = NULL;
1958   __pyx_L0:;
1959   __Pyx_XGIVEREF(__pyx_r);
1960   __Pyx_RefNannyFinishContext();
1961   return __pyx_r;
1962 }
1963 
1964 /* "dipy/utils/omp.pyx":82
1965  *
1966  *
1967  * cdef void set_num_threads(num_threads):             # <<<<<<<<<<<<<<
1968  *     """Set the number of threads to be used by OpenMP
1969  *
1970  */
1971 
__pyx_f_4dipy_5utils_3omp_set_num_threads(PyObject * __pyx_v_num_threads)1972 static void __pyx_f_4dipy_5utils_3omp_set_num_threads(PyObject *__pyx_v_num_threads) {
1973   __Pyx_RefNannyDeclarations
1974   int __pyx_t_1;
1975   int __pyx_t_2;
1976   int __pyx_lineno = 0;
1977   const char *__pyx_filename = NULL;
1978   int __pyx_clineno = 0;
1979   __Pyx_RefNannySetupContext("set_num_threads", 0);
1980 
1981   /* "dipy/utils/omp.pyx":92
1982  *         Effective number of threads for OpenMP accelerated code.
1983  *     """
1984  *     if openmp.have_openmp:             # <<<<<<<<<<<<<<
1985  *         openmp.omp_set_dynamic(0)
1986  *         openmp.omp_set_num_threads(num_threads)
1987  */
1988   __pyx_t_1 = (have_openmp != 0);
1989   if (__pyx_t_1) {
1990 
1991     /* "dipy/utils/omp.pyx":93
1992  *     """
1993  *     if openmp.have_openmp:
1994  *         openmp.omp_set_dynamic(0)             # <<<<<<<<<<<<<<
1995  *         openmp.omp_set_num_threads(num_threads)
1996  *
1997  */
1998     omp_set_dynamic(0);
1999 
2000     /* "dipy/utils/omp.pyx":94
2001  *     if openmp.have_openmp:
2002  *         openmp.omp_set_dynamic(0)
2003  *         openmp.omp_set_num_threads(num_threads)             # <<<<<<<<<<<<<<
2004  *
2005  *
2006  */
2007     __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_v_num_threads); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 94, __pyx_L1_error)
2008     omp_set_num_threads(__pyx_t_2);
2009 
2010     /* "dipy/utils/omp.pyx":92
2011  *         Effective number of threads for OpenMP accelerated code.
2012  *     """
2013  *     if openmp.have_openmp:             # <<<<<<<<<<<<<<
2014  *         openmp.omp_set_dynamic(0)
2015  *         openmp.omp_set_num_threads(num_threads)
2016  */
2017   }
2018 
2019   /* "dipy/utils/omp.pyx":82
2020  *
2021  *
2022  * cdef void set_num_threads(num_threads):             # <<<<<<<<<<<<<<
2023  *     """Set the number of threads to be used by OpenMP
2024  *
2025  */
2026 
2027   /* function exit code */
2028   goto __pyx_L0;
2029   __pyx_L1_error:;
2030   __Pyx_WriteUnraisable("dipy.utils.omp.set_num_threads", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
2031   __pyx_L0:;
2032   __Pyx_RefNannyFinishContext();
2033 }
2034 
2035 /* "dipy/utils/omp.pyx":97
2036  *
2037  *
2038  * cdef void restore_default_num_threads():             # <<<<<<<<<<<<<<
2039  *     """Restore OpenMP to using the default number of threads.
2040  *
2041  */
2042 
__pyx_f_4dipy_5utils_3omp_restore_default_num_threads(void)2043 static void __pyx_f_4dipy_5utils_3omp_restore_default_num_threads(void) {
2044   __Pyx_RefNannyDeclarations
2045   int __pyx_t_1;
2046   PyObject *__pyx_t_2 = NULL;
2047   int __pyx_t_3;
2048   int __pyx_lineno = 0;
2049   const char *__pyx_filename = NULL;
2050   int __pyx_clineno = 0;
2051   __Pyx_RefNannySetupContext("restore_default_num_threads", 0);
2052 
2053   /* "dipy/utils/omp.pyx":102
2054  *     This function does nothing if OpenMP is not available
2055  *     """
2056  *     if openmp.have_openmp:             # <<<<<<<<<<<<<<
2057  *         openmp.omp_set_num_threads(<int> default_threads)
2058  *
2059  */
2060   __pyx_t_1 = (have_openmp != 0);
2061   if (__pyx_t_1) {
2062 
2063     /* "dipy/utils/omp.pyx":103
2064  *     """
2065  *     if openmp.have_openmp:
2066  *         openmp.omp_set_num_threads(<int> default_threads)             # <<<<<<<<<<<<<<
2067  *
2068  *
2069  */
2070     __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_default_threads); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 103, __pyx_L1_error)
2071     __Pyx_GOTREF(__pyx_t_2);
2072     __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 103, __pyx_L1_error)
2073     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2074     omp_set_num_threads(((int)__pyx_t_3));
2075 
2076     /* "dipy/utils/omp.pyx":102
2077  *     This function does nothing if OpenMP is not available
2078  *     """
2079  *     if openmp.have_openmp:             # <<<<<<<<<<<<<<
2080  *         openmp.omp_set_num_threads(<int> default_threads)
2081  *
2082  */
2083   }
2084 
2085   /* "dipy/utils/omp.pyx":97
2086  *
2087  *
2088  * cdef void restore_default_num_threads():             # <<<<<<<<<<<<<<
2089  *     """Restore OpenMP to using the default number of threads.
2090  *
2091  */
2092 
2093   /* function exit code */
2094   goto __pyx_L0;
2095   __pyx_L1_error:;
2096   __Pyx_XDECREF(__pyx_t_2);
2097   __Pyx_WriteUnraisable("dipy.utils.omp.restore_default_num_threads", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
2098   __pyx_L0:;
2099   __Pyx_RefNannyFinishContext();
2100 }
2101 
2102 /* "dipy/utils/omp.pyx":106
2103  *
2104  *
2105  * def _set_omp_threads(num_threads):             # <<<<<<<<<<<<<<
2106  *     """Function for testing set_num_threads."""
2107  *     set_num_threads(num_threads)
2108  */
2109 
2110 /* Python wrapper */
2111 static PyObject *__pyx_pw_4dipy_5utils_3omp_9_set_omp_threads(PyObject *__pyx_self, PyObject *__pyx_v_num_threads); /*proto*/
2112 static char __pyx_doc_4dipy_5utils_3omp_8_set_omp_threads[] = "Function for testing set_num_threads.";
2113 static PyMethodDef __pyx_mdef_4dipy_5utils_3omp_9_set_omp_threads = {"_set_omp_threads", (PyCFunction)__pyx_pw_4dipy_5utils_3omp_9_set_omp_threads, METH_O, __pyx_doc_4dipy_5utils_3omp_8_set_omp_threads};
__pyx_pw_4dipy_5utils_3omp_9_set_omp_threads(PyObject * __pyx_self,PyObject * __pyx_v_num_threads)2114 static PyObject *__pyx_pw_4dipy_5utils_3omp_9_set_omp_threads(PyObject *__pyx_self, PyObject *__pyx_v_num_threads) {
2115   PyObject *__pyx_r = 0;
2116   __Pyx_RefNannyDeclarations
2117   __Pyx_RefNannySetupContext("_set_omp_threads (wrapper)", 0);
2118   __pyx_r = __pyx_pf_4dipy_5utils_3omp_8_set_omp_threads(__pyx_self, ((PyObject *)__pyx_v_num_threads));
2119 
2120   /* function exit code */
2121   __Pyx_RefNannyFinishContext();
2122   return __pyx_r;
2123 }
2124 
__pyx_pf_4dipy_5utils_3omp_8_set_omp_threads(CYTHON_UNUSED PyObject * __pyx_self,PyObject * __pyx_v_num_threads)2125 static PyObject *__pyx_pf_4dipy_5utils_3omp_8_set_omp_threads(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_num_threads) {
2126   PyObject *__pyx_r = NULL;
2127   __Pyx_RefNannyDeclarations
2128   __Pyx_RefNannySetupContext("_set_omp_threads", 0);
2129 
2130   /* "dipy/utils/omp.pyx":108
2131  * def _set_omp_threads(num_threads):
2132  *     """Function for testing set_num_threads."""
2133  *     set_num_threads(num_threads)             # <<<<<<<<<<<<<<
2134  *
2135  *
2136  */
2137   __pyx_f_4dipy_5utils_3omp_set_num_threads(__pyx_v_num_threads);
2138 
2139   /* "dipy/utils/omp.pyx":106
2140  *
2141  *
2142  * def _set_omp_threads(num_threads):             # <<<<<<<<<<<<<<
2143  *     """Function for testing set_num_threads."""
2144  *     set_num_threads(num_threads)
2145  */
2146 
2147   /* function exit code */
2148   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
2149   __Pyx_XGIVEREF(__pyx_r);
2150   __Pyx_RefNannyFinishContext();
2151   return __pyx_r;
2152 }
2153 
2154 /* "dipy/utils/omp.pyx":111
2155  *
2156  *
2157  * def _restore_omp_threads():             # <<<<<<<<<<<<<<
2158  *     """Function for testing restore_default_num_threads."""
2159  *     restore_default_num_threads()
2160  */
2161 
2162 /* Python wrapper */
2163 static PyObject *__pyx_pw_4dipy_5utils_3omp_11_restore_omp_threads(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
2164 static char __pyx_doc_4dipy_5utils_3omp_10_restore_omp_threads[] = "Function for testing restore_default_num_threads.";
2165 static PyMethodDef __pyx_mdef_4dipy_5utils_3omp_11_restore_omp_threads = {"_restore_omp_threads", (PyCFunction)__pyx_pw_4dipy_5utils_3omp_11_restore_omp_threads, METH_NOARGS, __pyx_doc_4dipy_5utils_3omp_10_restore_omp_threads};
__pyx_pw_4dipy_5utils_3omp_11_restore_omp_threads(PyObject * __pyx_self,CYTHON_UNUSED PyObject * unused)2166 static PyObject *__pyx_pw_4dipy_5utils_3omp_11_restore_omp_threads(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
2167   PyObject *__pyx_r = 0;
2168   __Pyx_RefNannyDeclarations
2169   __Pyx_RefNannySetupContext("_restore_omp_threads (wrapper)", 0);
2170   __pyx_r = __pyx_pf_4dipy_5utils_3omp_10_restore_omp_threads(__pyx_self);
2171 
2172   /* function exit code */
2173   __Pyx_RefNannyFinishContext();
2174   return __pyx_r;
2175 }
2176 
__pyx_pf_4dipy_5utils_3omp_10_restore_omp_threads(CYTHON_UNUSED PyObject * __pyx_self)2177 static PyObject *__pyx_pf_4dipy_5utils_3omp_10_restore_omp_threads(CYTHON_UNUSED PyObject *__pyx_self) {
2178   PyObject *__pyx_r = NULL;
2179   __Pyx_RefNannyDeclarations
2180   __Pyx_RefNannySetupContext("_restore_omp_threads", 0);
2181 
2182   /* "dipy/utils/omp.pyx":113
2183  * def _restore_omp_threads():
2184  *     """Function for testing restore_default_num_threads."""
2185  *     restore_default_num_threads()             # <<<<<<<<<<<<<<
2186  */
2187   __pyx_f_4dipy_5utils_3omp_restore_default_num_threads();
2188 
2189   /* "dipy/utils/omp.pyx":111
2190  *
2191  *
2192  * def _restore_omp_threads():             # <<<<<<<<<<<<<<
2193  *     """Function for testing restore_default_num_threads."""
2194  *     restore_default_num_threads()
2195  */
2196 
2197   /* function exit code */
2198   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
2199   __Pyx_XGIVEREF(__pyx_r);
2200   __Pyx_RefNannyFinishContext();
2201   return __pyx_r;
2202 }
2203 
2204 static PyMethodDef __pyx_methods[] = {
2205   {0, 0, 0, 0}
2206 };
2207 
2208 #if PY_MAJOR_VERSION >= 3
2209 #if CYTHON_PEP489_MULTI_PHASE_INIT
2210 static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
2211 static int __pyx_pymod_exec_omp(PyObject* module); /*proto*/
2212 static PyModuleDef_Slot __pyx_moduledef_slots[] = {
2213   {Py_mod_create, (void*)__pyx_pymod_create},
2214   {Py_mod_exec, (void*)__pyx_pymod_exec_omp},
2215   {0, NULL}
2216 };
2217 #endif
2218 
2219 static struct PyModuleDef __pyx_moduledef = {
2220     PyModuleDef_HEAD_INIT,
2221     "omp",
2222     0, /* m_doc */
2223   #if CYTHON_PEP489_MULTI_PHASE_INIT
2224     0, /* m_size */
2225   #else
2226     -1, /* m_size */
2227   #endif
2228     __pyx_methods /* m_methods */,
2229   #if CYTHON_PEP489_MULTI_PHASE_INIT
2230     __pyx_moduledef_slots, /* m_slots */
2231   #else
2232     NULL, /* m_reload */
2233   #endif
2234     NULL, /* m_traverse */
2235     NULL, /* m_clear */
2236     NULL /* m_free */
2237 };
2238 #endif
2239 #ifndef CYTHON_SMALL_CODE
2240 #if defined(__clang__)
2241     #define CYTHON_SMALL_CODE
2242 #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
2243     #define CYTHON_SMALL_CODE __attribute__((cold))
2244 #else
2245     #define CYTHON_SMALL_CODE
2246 #endif
2247 #endif
2248 
2249 static __Pyx_StringTabEntry __pyx_string_tab[] = {
2250   {&__pyx_n_u_OMP_NUM_THREADS, __pyx_k_OMP_NUM_THREADS, sizeof(__pyx_k_OMP_NUM_THREADS), 0, 1, 0, 1},
2251   {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
2252   {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
2253   {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1},
2254   {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
2255   {&__pyx_n_s_cpu_count, __pyx_k_cpu_count, sizeof(__pyx_k_cpu_count), 0, 0, 1, 1},
2256   {&__pyx_n_u_cpu_count, __pyx_k_cpu_count, sizeof(__pyx_k_cpu_count), 0, 1, 0, 1},
2257   {&__pyx_n_s_default_threads, __pyx_k_default_threads, sizeof(__pyx_k_default_threads), 0, 0, 1, 1},
2258   {&__pyx_n_u_default_threads, __pyx_k_default_threads, sizeof(__pyx_k_default_threads), 0, 1, 0, 1},
2259   {&__pyx_n_s_determine_num_threads, __pyx_k_determine_num_threads, sizeof(__pyx_k_determine_num_threads), 0, 0, 1, 1},
2260   {&__pyx_n_s_dipy_utils_omp, __pyx_k_dipy_utils_omp, sizeof(__pyx_k_dipy_utils_omp), 0, 0, 1, 1},
2261   {&__pyx_kp_s_dipy_utils_omp_pyx, __pyx_k_dipy_utils_omp_pyx, sizeof(__pyx_k_dipy_utils_omp_pyx), 0, 0, 1, 0},
2262   {&__pyx_n_s_environ, __pyx_k_environ, sizeof(__pyx_k_environ), 0, 0, 1, 1},
2263   {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1},
2264   {&__pyx_n_s_get_default_threads, __pyx_k_get_default_threads, sizeof(__pyx_k_get_default_threads), 0, 0, 1, 1},
2265   {&__pyx_n_s_have_openmp, __pyx_k_have_openmp, sizeof(__pyx_k_have_openmp), 0, 0, 1, 1},
2266   {&__pyx_n_u_have_openmp, __pyx_k_have_openmp, sizeof(__pyx_k_have_openmp), 0, 1, 0, 1},
2267   {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
2268   {&__pyx_kp_u_invalid_number_of_threads, __pyx_k_invalid_number_of_threads, sizeof(__pyx_k_invalid_number_of_threads), 0, 1, 0, 0},
2269   {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
2270   {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
2271   {&__pyx_n_s_num_threads, __pyx_k_num_threads, sizeof(__pyx_k_num_threads), 0, 0, 1, 1},
2272   {&__pyx_kp_u_num_threads_cannot_be_0, __pyx_k_num_threads_cannot_be_0, sizeof(__pyx_k_num_threads_cannot_be_0), 0, 1, 0, 0},
2273   {&__pyx_kp_u_num_threads_must_be_an_int_or_No, __pyx_k_num_threads_must_be_an_int_or_No, sizeof(__pyx_k_num_threads_must_be_an_int_or_No), 0, 1, 0, 0},
2274   {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1},
2275   {&__pyx_n_s_restore_omp_threads, __pyx_k_restore_omp_threads, sizeof(__pyx_k_restore_omp_threads), 0, 0, 1, 1},
2276   {&__pyx_n_s_set_omp_threads, __pyx_k_set_omp_threads, sizeof(__pyx_k_set_omp_threads), 0, 0, 1, 1},
2277   {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
2278   {&__pyx_n_s_thread_count, __pyx_k_thread_count, sizeof(__pyx_k_thread_count), 0, 0, 1, 1},
2279   {&__pyx_n_u_thread_count, __pyx_k_thread_count, sizeof(__pyx_k_thread_count), 0, 1, 0, 1},
2280   {0, 0, 0, 0, 0, 0, 0}
2281 };
__Pyx_InitCachedBuiltins(void)2282 static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
2283   __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 36, __pyx_L1_error)
2284   __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 37, __pyx_L1_error)
2285   return 0;
2286   __pyx_L1_error:;
2287   return -1;
2288 }
2289 
__Pyx_InitCachedConstants(void)2290 static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
2291   __Pyx_RefNannyDeclarations
2292   __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
2293 
2294   /* "dipy/utils/omp.pyx":34
2295  *     if have_openmp:
2296  *         try:
2297  *             default_threads = int(os.environ.get('OMP_NUM_THREADS', None))             # <<<<<<<<<<<<<<
2298  *             if default_threads < 1:
2299  *                 raise ValueError("invalid number of threads")
2300  */
2301   __pyx_tuple_ = PyTuple_Pack(2, __pyx_n_u_OMP_NUM_THREADS, Py_None); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 34, __pyx_L1_error)
2302   __Pyx_GOTREF(__pyx_tuple_);
2303   __Pyx_GIVEREF(__pyx_tuple_);
2304 
2305   /* "dipy/utils/omp.pyx":36
2306  *             default_threads = int(os.environ.get('OMP_NUM_THREADS', None))
2307  *             if default_threads < 1:
2308  *                 raise ValueError("invalid number of threads")             # <<<<<<<<<<<<<<
2309  *         except (ValueError, TypeError):
2310  *             default_threads = openmp.omp_get_num_procs()
2311  */
2312   __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_u_invalid_number_of_threads); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 36, __pyx_L1_error)
2313   __Pyx_GOTREF(__pyx_tuple__2);
2314   __Pyx_GIVEREF(__pyx_tuple__2);
2315 
2316   /* "dipy/utils/omp.pyx":68
2317  *     """
2318  *     if not isinstance(num_threads, int) and num_threads is not None:
2319  *         raise TypeError("num_threads must be an int or None")             # <<<<<<<<<<<<<<
2320  *
2321  *     if num_threads == 0:
2322  */
2323   __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_u_num_threads_must_be_an_int_or_No); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 68, __pyx_L1_error)
2324   __Pyx_GOTREF(__pyx_tuple__3);
2325   __Pyx_GIVEREF(__pyx_tuple__3);
2326 
2327   /* "dipy/utils/omp.pyx":71
2328  *
2329  *     if num_threads == 0:
2330  *         raise ValueError("num_threads cannot be 0")             # <<<<<<<<<<<<<<
2331  *
2332  *     if num_threads is None:
2333  */
2334   __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_u_num_threads_cannot_be_0); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 71, __pyx_L1_error)
2335   __Pyx_GOTREF(__pyx_tuple__4);
2336   __Pyx_GIVEREF(__pyx_tuple__4);
2337 
2338   /* "dipy/utils/omp.pyx":11
2339  *
2340  *
2341  * def cpu_count():             # <<<<<<<<<<<<<<
2342  *     """Return number of cpus as determined by omp_get_num_procs."""
2343  *     if have_openmp:
2344  */
2345   __pyx_codeobj__5 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_dipy_utils_omp_pyx, __pyx_n_s_cpu_count, 11, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__5)) __PYX_ERR(0, 11, __pyx_L1_error)
2346 
2347   /* "dipy/utils/omp.pyx":19
2348  *
2349  *
2350  * def thread_count():             # <<<<<<<<<<<<<<
2351  *     """Return number of threads as determined by omp_get_max_threads."""
2352  *     if have_openmp:
2353  */
2354   __pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_dipy_utils_omp_pyx, __pyx_n_s_thread_count, 19, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 19, __pyx_L1_error)
2355 
2356   /* "dipy/utils/omp.pyx":27
2357  *
2358  *
2359  * def _get_default_threads():             # <<<<<<<<<<<<<<
2360  *     """Default number of threads for OpenMP.
2361  *
2362  */
2363   __pyx_tuple__7 = PyTuple_Pack(1, __pyx_n_s_default_threads); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 27, __pyx_L1_error)
2364   __Pyx_GOTREF(__pyx_tuple__7);
2365   __Pyx_GIVEREF(__pyx_tuple__7);
2366   __pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_dipy_utils_omp_pyx, __pyx_n_s_get_default_threads, 27, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) __PYX_ERR(0, 27, __pyx_L1_error)
2367 
2368   /* "dipy/utils/omp.pyx":45
2369  *
2370  *
2371  * def determine_num_threads(num_threads):             # <<<<<<<<<<<<<<
2372  *     """Determine the effective number of threads to be used for OpenMP calls
2373  *
2374  */
2375   __pyx_tuple__9 = PyTuple_Pack(1, __pyx_n_s_num_threads); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 45, __pyx_L1_error)
2376   __Pyx_GOTREF(__pyx_tuple__9);
2377   __Pyx_GIVEREF(__pyx_tuple__9);
2378   __pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__9, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_dipy_utils_omp_pyx, __pyx_n_s_determine_num_threads, 45, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) __PYX_ERR(0, 45, __pyx_L1_error)
2379 
2380   /* "dipy/utils/omp.pyx":106
2381  *
2382  *
2383  * def _set_omp_threads(num_threads):             # <<<<<<<<<<<<<<
2384  *     """Function for testing set_num_threads."""
2385  *     set_num_threads(num_threads)
2386  */
2387   __pyx_tuple__11 = PyTuple_Pack(1, __pyx_n_s_num_threads); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 106, __pyx_L1_error)
2388   __Pyx_GOTREF(__pyx_tuple__11);
2389   __Pyx_GIVEREF(__pyx_tuple__11);
2390   __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_dipy_utils_omp_pyx, __pyx_n_s_set_omp_threads, 106, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 106, __pyx_L1_error)
2391 
2392   /* "dipy/utils/omp.pyx":111
2393  *
2394  *
2395  * def _restore_omp_threads():             # <<<<<<<<<<<<<<
2396  *     """Function for testing restore_default_num_threads."""
2397  *     restore_default_num_threads()
2398  */
2399   __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_dipy_utils_omp_pyx, __pyx_n_s_restore_omp_threads, 111, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 111, __pyx_L1_error)
2400   __Pyx_RefNannyFinishContext();
2401   return 0;
2402   __pyx_L1_error:;
2403   __Pyx_RefNannyFinishContext();
2404   return -1;
2405 }
2406 
__Pyx_InitGlobals(void)2407 static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
2408   if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
2409   __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
2410   __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
2411   return 0;
2412   __pyx_L1_error:;
2413   return -1;
2414 }
2415 
2416 static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
2417 static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
2418 static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
2419 static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
2420 static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
2421 static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
2422 static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/
2423 
__Pyx_modinit_global_init_code(void)2424 static int __Pyx_modinit_global_init_code(void) {
2425   __Pyx_RefNannyDeclarations
2426   __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
2427   /*--- Global init code ---*/
2428   __Pyx_RefNannyFinishContext();
2429   return 0;
2430 }
2431 
__Pyx_modinit_variable_export_code(void)2432 static int __Pyx_modinit_variable_export_code(void) {
2433   __Pyx_RefNannyDeclarations
2434   __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
2435   /*--- Variable export code ---*/
2436   __Pyx_RefNannyFinishContext();
2437   return 0;
2438 }
2439 
__Pyx_modinit_function_export_code(void)2440 static int __Pyx_modinit_function_export_code(void) {
2441   __Pyx_RefNannyDeclarations
2442   int __pyx_lineno = 0;
2443   const char *__pyx_filename = NULL;
2444   int __pyx_clineno = 0;
2445   __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
2446   /*--- Function export code ---*/
2447   if (__Pyx_ExportFunction("set_num_threads", (void (*)(void))__pyx_f_4dipy_5utils_3omp_set_num_threads, "void (PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2448   if (__Pyx_ExportFunction("restore_default_num_threads", (void (*)(void))__pyx_f_4dipy_5utils_3omp_restore_default_num_threads, "void (void)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2449   __Pyx_RefNannyFinishContext();
2450   return 0;
2451   __pyx_L1_error:;
2452   __Pyx_RefNannyFinishContext();
2453   return -1;
2454 }
2455 
__Pyx_modinit_type_init_code(void)2456 static int __Pyx_modinit_type_init_code(void) {
2457   __Pyx_RefNannyDeclarations
2458   __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
2459   /*--- Type init code ---*/
2460   __Pyx_RefNannyFinishContext();
2461   return 0;
2462 }
2463 
__Pyx_modinit_type_import_code(void)2464 static int __Pyx_modinit_type_import_code(void) {
2465   __Pyx_RefNannyDeclarations
2466   __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
2467   /*--- Type import code ---*/
2468   __Pyx_RefNannyFinishContext();
2469   return 0;
2470 }
2471 
__Pyx_modinit_variable_import_code(void)2472 static int __Pyx_modinit_variable_import_code(void) {
2473   __Pyx_RefNannyDeclarations
2474   __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
2475   /*--- Variable import code ---*/
2476   __Pyx_RefNannyFinishContext();
2477   return 0;
2478 }
2479 
__Pyx_modinit_function_import_code(void)2480 static int __Pyx_modinit_function_import_code(void) {
2481   __Pyx_RefNannyDeclarations
2482   __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
2483   /*--- Function import code ---*/
2484   __Pyx_RefNannyFinishContext();
2485   return 0;
2486 }
2487 
2488 
2489 #ifndef CYTHON_NO_PYINIT_EXPORT
2490 #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
2491 #elif PY_MAJOR_VERSION < 3
2492 #ifdef __cplusplus
2493 #define __Pyx_PyMODINIT_FUNC extern "C" void
2494 #else
2495 #define __Pyx_PyMODINIT_FUNC void
2496 #endif
2497 #else
2498 #ifdef __cplusplus
2499 #define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
2500 #else
2501 #define __Pyx_PyMODINIT_FUNC PyObject *
2502 #endif
2503 #endif
2504 
2505 
2506 #if PY_MAJOR_VERSION < 3
2507 __Pyx_PyMODINIT_FUNC initomp(void) CYTHON_SMALL_CODE; /*proto*/
initomp(void)2508 __Pyx_PyMODINIT_FUNC initomp(void)
2509 #else
2510 __Pyx_PyMODINIT_FUNC PyInit_omp(void) CYTHON_SMALL_CODE; /*proto*/
2511 __Pyx_PyMODINIT_FUNC PyInit_omp(void)
2512 #if CYTHON_PEP489_MULTI_PHASE_INIT
2513 {
2514   return PyModuleDef_Init(&__pyx_moduledef);
2515 }
2516 static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
2517     #if PY_VERSION_HEX >= 0x030700A1
2518     static PY_INT64_T main_interpreter_id = -1;
2519     PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
2520     if (main_interpreter_id == -1) {
2521         main_interpreter_id = current_id;
2522         return (unlikely(current_id == -1)) ? -1 : 0;
2523     } else if (unlikely(main_interpreter_id != current_id))
2524     #else
2525     static PyInterpreterState *main_interpreter = NULL;
2526     PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
2527     if (!main_interpreter) {
2528         main_interpreter = current_interpreter;
2529     } else if (unlikely(main_interpreter != current_interpreter))
2530     #endif
2531     {
2532         PyErr_SetString(
2533             PyExc_ImportError,
2534             "Interpreter change detected - this module can only be loaded into one interpreter per process.");
2535         return -1;
2536     }
2537     return 0;
2538 }
2539 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) {
2540     PyObject *value = PyObject_GetAttrString(spec, from_name);
2541     int result = 0;
2542     if (likely(value)) {
2543         if (allow_none || value != Py_None) {
2544             result = PyDict_SetItemString(moddict, to_name, value);
2545         }
2546         Py_DECREF(value);
2547     } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
2548         PyErr_Clear();
2549     } else {
2550         result = -1;
2551     }
2552     return result;
2553 }
2554 static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
2555     PyObject *module = NULL, *moddict, *modname;
2556     if (__Pyx_check_single_interpreter())
2557         return NULL;
2558     if (__pyx_m)
2559         return __Pyx_NewRef(__pyx_m);
2560     modname = PyObject_GetAttrString(spec, "name");
2561     if (unlikely(!modname)) goto bad;
2562     module = PyModule_NewObject(modname);
2563     Py_DECREF(modname);
2564     if (unlikely(!module)) goto bad;
2565     moddict = PyModule_GetDict(module);
2566     if (unlikely(!moddict)) goto bad;
2567     if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
2568     if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
2569     if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
2570     if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
2571     return module;
2572 bad:
2573     Py_XDECREF(module);
2574     return NULL;
2575 }
2576 
2577 
2578 static CYTHON_SMALL_CODE int __pyx_pymod_exec_omp(PyObject *__pyx_pyinit_module)
2579 #endif
2580 #endif
2581 {
2582   PyObject *__pyx_t_1 = NULL;
2583   PyObject *__pyx_t_2 = NULL;
2584   int __pyx_lineno = 0;
2585   const char *__pyx_filename = NULL;
2586   int __pyx_clineno = 0;
2587   __Pyx_RefNannyDeclarations
2588   #if CYTHON_PEP489_MULTI_PHASE_INIT
2589   if (__pyx_m) {
2590     if (__pyx_m == __pyx_pyinit_module) return 0;
2591     PyErr_SetString(PyExc_RuntimeError, "Module 'omp' has already been imported. Re-initialisation is not supported.");
2592     return -1;
2593   }
2594   #elif PY_MAJOR_VERSION >= 3
2595   if (__pyx_m) return __Pyx_NewRef(__pyx_m);
2596   #endif
2597   #if CYTHON_REFNANNY
2598 __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
2599 if (!__Pyx_RefNanny) {
2600   PyErr_Clear();
2601   __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
2602   if (!__Pyx_RefNanny)
2603       Py_FatalError("failed to import 'refnanny' module");
2604 }
2605 #endif
2606   __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_omp(void)", 0);
2607   if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2608   #ifdef __Pxy_PyFrame_Initialize_Offsets
2609   __Pxy_PyFrame_Initialize_Offsets();
2610   #endif
2611   __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
2612   __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
2613   __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
2614   #ifdef __Pyx_CyFunction_USED
2615   if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2616   #endif
2617   #ifdef __Pyx_FusedFunction_USED
2618   if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2619   #endif
2620   #ifdef __Pyx_Coroutine_USED
2621   if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2622   #endif
2623   #ifdef __Pyx_Generator_USED
2624   if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2625   #endif
2626   #ifdef __Pyx_AsyncGen_USED
2627   if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2628   #endif
2629   #ifdef __Pyx_StopAsyncIteration_USED
2630   if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2631   #endif
2632   /*--- Library function declarations ---*/
2633   /*--- Threads initialization code ---*/
2634   #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
2635   #ifdef WITH_THREAD /* Python build with threading support? */
2636   PyEval_InitThreads();
2637   #endif
2638   #endif
2639   /*--- Module creation code ---*/
2640   #if CYTHON_PEP489_MULTI_PHASE_INIT
2641   __pyx_m = __pyx_pyinit_module;
2642   Py_INCREF(__pyx_m);
2643   #else
2644   #if PY_MAJOR_VERSION < 3
2645   __pyx_m = Py_InitModule4("omp", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
2646   #else
2647   __pyx_m = PyModule_Create(&__pyx_moduledef);
2648   #endif
2649   if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
2650   #endif
2651   __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
2652   Py_INCREF(__pyx_d);
2653   __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
2654   Py_INCREF(__pyx_b);
2655   __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
2656   Py_INCREF(__pyx_cython_runtime);
2657   if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
2658   /*--- Initialize various global constants etc. ---*/
2659   if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2660   #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
2661   if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2662   #endif
2663   if (__pyx_module_is_main_dipy__utils__omp) {
2664     if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2665   }
2666   #if PY_MAJOR_VERSION >= 3
2667   {
2668     PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
2669     if (!PyDict_GetItemString(modules, "dipy.utils.omp")) {
2670       if (unlikely(PyDict_SetItemString(modules, "dipy.utils.omp", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
2671     }
2672   }
2673   #endif
2674   /*--- Builtin init code ---*/
2675   if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2676   /*--- Constants init code ---*/
2677   if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2678   /*--- Global type/function init code ---*/
2679   (void)__Pyx_modinit_global_init_code();
2680   (void)__Pyx_modinit_variable_export_code();
2681   if (unlikely(__Pyx_modinit_function_export_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
2682   (void)__Pyx_modinit_type_init_code();
2683   (void)__Pyx_modinit_type_import_code();
2684   (void)__Pyx_modinit_variable_import_code();
2685   (void)__Pyx_modinit_function_import_code();
2686   /*--- Execution code ---*/
2687   #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
2688   if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2689   #endif
2690 
2691   /* "dipy/utils/omp.pyx":3
2692  * #!python
2693  *
2694  * import os             # <<<<<<<<<<<<<<
2695  * cimport cython
2696  * cimport safe_openmp as openmp
2697  */
2698   __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error)
2699   __Pyx_GOTREF(__pyx_t_1);
2700   if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error)
2701   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2702 
2703   /* "dipy/utils/omp.pyx":6
2704  * cimport cython
2705  * cimport safe_openmp as openmp
2706  * have_openmp = <int> openmp.have_openmp             # <<<<<<<<<<<<<<
2707  *
2708  * __all__ = ['have_openmp', 'default_threads', 'cpu_count', 'thread_count']
2709  */
2710   __pyx_t_1 = __Pyx_PyInt_From_int(((int)have_openmp)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error)
2711   __Pyx_GOTREF(__pyx_t_1);
2712   if (PyDict_SetItem(__pyx_d, __pyx_n_s_have_openmp, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error)
2713   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2714 
2715   /* "dipy/utils/omp.pyx":8
2716  * have_openmp = <int> openmp.have_openmp
2717  *
2718  * __all__ = ['have_openmp', 'default_threads', 'cpu_count', 'thread_count']             # <<<<<<<<<<<<<<
2719  *
2720  *
2721  */
2722   __pyx_t_1 = PyList_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
2723   __Pyx_GOTREF(__pyx_t_1);
2724   __Pyx_INCREF(__pyx_n_u_have_openmp);
2725   __Pyx_GIVEREF(__pyx_n_u_have_openmp);
2726   PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_u_have_openmp);
2727   __Pyx_INCREF(__pyx_n_u_default_threads);
2728   __Pyx_GIVEREF(__pyx_n_u_default_threads);
2729   PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_u_default_threads);
2730   __Pyx_INCREF(__pyx_n_u_cpu_count);
2731   __Pyx_GIVEREF(__pyx_n_u_cpu_count);
2732   PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_u_cpu_count);
2733   __Pyx_INCREF(__pyx_n_u_thread_count);
2734   __Pyx_GIVEREF(__pyx_n_u_thread_count);
2735   PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_u_thread_count);
2736   if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
2737   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2738 
2739   /* "dipy/utils/omp.pyx":11
2740  *
2741  *
2742  * def cpu_count():             # <<<<<<<<<<<<<<
2743  *     """Return number of cpus as determined by omp_get_num_procs."""
2744  *     if have_openmp:
2745  */
2746   __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_5utils_3omp_1cpu_count, NULL, __pyx_n_s_dipy_utils_omp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error)
2747   __Pyx_GOTREF(__pyx_t_1);
2748   if (PyDict_SetItem(__pyx_d, __pyx_n_s_cpu_count, __pyx_t_1) < 0) __PYX_ERR(0, 11, __pyx_L1_error)
2749   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2750 
2751   /* "dipy/utils/omp.pyx":19
2752  *
2753  *
2754  * def thread_count():             # <<<<<<<<<<<<<<
2755  *     """Return number of threads as determined by omp_get_max_threads."""
2756  *     if have_openmp:
2757  */
2758   __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_5utils_3omp_3thread_count, NULL, __pyx_n_s_dipy_utils_omp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 19, __pyx_L1_error)
2759   __Pyx_GOTREF(__pyx_t_1);
2760   if (PyDict_SetItem(__pyx_d, __pyx_n_s_thread_count, __pyx_t_1) < 0) __PYX_ERR(0, 19, __pyx_L1_error)
2761   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2762 
2763   /* "dipy/utils/omp.pyx":27
2764  *
2765  *
2766  * def _get_default_threads():             # <<<<<<<<<<<<<<
2767  *     """Default number of threads for OpenMP.
2768  *
2769  */
2770   __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_5utils_3omp_5_get_default_threads, NULL, __pyx_n_s_dipy_utils_omp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error)
2771   __Pyx_GOTREF(__pyx_t_1);
2772   if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_default_threads, __pyx_t_1) < 0) __PYX_ERR(0, 27, __pyx_L1_error)
2773   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2774 
2775   /* "dipy/utils/omp.pyx":42
2776  *     else:
2777  *         return 1
2778  * default_threads = _get_default_threads()             # <<<<<<<<<<<<<<
2779  *
2780  *
2781  */
2782   __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_get_default_threads); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 42, __pyx_L1_error)
2783   __Pyx_GOTREF(__pyx_t_1);
2784   __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error)
2785   __Pyx_GOTREF(__pyx_t_2);
2786   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2787   if (PyDict_SetItem(__pyx_d, __pyx_n_s_default_threads, __pyx_t_2) < 0) __PYX_ERR(0, 42, __pyx_L1_error)
2788   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2789 
2790   /* "dipy/utils/omp.pyx":45
2791  *
2792  *
2793  * def determine_num_threads(num_threads):             # <<<<<<<<<<<<<<
2794  *     """Determine the effective number of threads to be used for OpenMP calls
2795  *
2796  */
2797   __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_4dipy_5utils_3omp_7determine_num_threads, NULL, __pyx_n_s_dipy_utils_omp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __pyx_L1_error)
2798   __Pyx_GOTREF(__pyx_t_2);
2799   if (PyDict_SetItem(__pyx_d, __pyx_n_s_determine_num_threads, __pyx_t_2) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
2800   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2801 
2802   /* "dipy/utils/omp.pyx":106
2803  *
2804  *
2805  * def _set_omp_threads(num_threads):             # <<<<<<<<<<<<<<
2806  *     """Function for testing set_num_threads."""
2807  *     set_num_threads(num_threads)
2808  */
2809   __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_4dipy_5utils_3omp_9_set_omp_threads, NULL, __pyx_n_s_dipy_utils_omp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 106, __pyx_L1_error)
2810   __Pyx_GOTREF(__pyx_t_2);
2811   if (PyDict_SetItem(__pyx_d, __pyx_n_s_set_omp_threads, __pyx_t_2) < 0) __PYX_ERR(0, 106, __pyx_L1_error)
2812   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2813 
2814   /* "dipy/utils/omp.pyx":111
2815  *
2816  *
2817  * def _restore_omp_threads():             # <<<<<<<<<<<<<<
2818  *     """Function for testing restore_default_num_threads."""
2819  *     restore_default_num_threads()
2820  */
2821   __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_4dipy_5utils_3omp_11_restore_omp_threads, NULL, __pyx_n_s_dipy_utils_omp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 111, __pyx_L1_error)
2822   __Pyx_GOTREF(__pyx_t_2);
2823   if (PyDict_SetItem(__pyx_d, __pyx_n_s_restore_omp_threads, __pyx_t_2) < 0) __PYX_ERR(0, 111, __pyx_L1_error)
2824   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2825 
2826   /* "dipy/utils/omp.pyx":1
2827  * #!python             # <<<<<<<<<<<<<<
2828  *
2829  * import os
2830  */
2831   __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
2832   __Pyx_GOTREF(__pyx_t_2);
2833   if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
2834   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2835 
2836   /*--- Wrapped vars code ---*/
2837 
2838   goto __pyx_L0;
2839   __pyx_L1_error:;
2840   __Pyx_XDECREF(__pyx_t_1);
2841   __Pyx_XDECREF(__pyx_t_2);
2842   if (__pyx_m) {
2843     if (__pyx_d) {
2844       __Pyx_AddTraceback("init dipy.utils.omp", __pyx_clineno, __pyx_lineno, __pyx_filename);
2845     }
2846     Py_CLEAR(__pyx_m);
2847   } else if (!PyErr_Occurred()) {
2848     PyErr_SetString(PyExc_ImportError, "init dipy.utils.omp");
2849   }
2850   __pyx_L0:;
2851   __Pyx_RefNannyFinishContext();
2852   #if CYTHON_PEP489_MULTI_PHASE_INIT
2853   return (__pyx_m != NULL) ? 0 : -1;
2854   #elif PY_MAJOR_VERSION >= 3
2855   return __pyx_m;
2856   #else
2857   return;
2858   #endif
2859 }
2860 
2861 /* --- Runtime support code --- */
2862 /* Refnanny */
2863 #if CYTHON_REFNANNY
__Pyx_RefNannyImportAPI(const char * modname)2864 static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
2865     PyObject *m = NULL, *p = NULL;
2866     void *r = NULL;
2867     m = PyImport_ImportModule(modname);
2868     if (!m) goto end;
2869     p = PyObject_GetAttrString(m, "RefNannyAPI");
2870     if (!p) goto end;
2871     r = PyLong_AsVoidPtr(p);
2872 end:
2873     Py_XDECREF(p);
2874     Py_XDECREF(m);
2875     return (__Pyx_RefNannyAPIStruct *)r;
2876 }
2877 #endif
2878 
2879 /* PyObjectGetAttrStr */
2880 #if CYTHON_USE_TYPE_SLOTS
__Pyx_PyObject_GetAttrStr(PyObject * obj,PyObject * attr_name)2881 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
2882     PyTypeObject* tp = Py_TYPE(obj);
2883     if (likely(tp->tp_getattro))
2884         return tp->tp_getattro(obj, attr_name);
2885 #if PY_MAJOR_VERSION < 3
2886     if (likely(tp->tp_getattr))
2887         return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
2888 #endif
2889     return PyObject_GetAttr(obj, attr_name);
2890 }
2891 #endif
2892 
2893 /* GetBuiltinName */
__Pyx_GetBuiltinName(PyObject * name)2894 static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
2895     PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
2896     if (unlikely(!result)) {
2897         PyErr_Format(PyExc_NameError,
2898 #if PY_MAJOR_VERSION >= 3
2899             "name '%U' is not defined", name);
2900 #else
2901             "name '%.200s' is not defined", PyString_AS_STRING(name));
2902 #endif
2903     }
2904     return result;
2905 }
2906 
2907 /* PyDictVersioning */
2908 #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
__Pyx_get_tp_dict_version(PyObject * obj)2909 static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
2910     PyObject *dict = Py_TYPE(obj)->tp_dict;
2911     return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
2912 }
__Pyx_get_object_dict_version(PyObject * obj)2913 static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
2914     PyObject **dictptr = NULL;
2915     Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
2916     if (offset) {
2917 #if CYTHON_COMPILING_IN_CPYTHON
2918         dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
2919 #else
2920         dictptr = _PyObject_GetDictPtr(obj);
2921 #endif
2922     }
2923     return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
2924 }
__Pyx_object_dict_version_matches(PyObject * obj,PY_UINT64_T tp_dict_version,PY_UINT64_T obj_dict_version)2925 static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
2926     PyObject *dict = Py_TYPE(obj)->tp_dict;
2927     if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
2928         return 0;
2929     return obj_dict_version == __Pyx_get_object_dict_version(obj);
2930 }
2931 #endif
2932 
2933 /* GetModuleGlobalName */
2934 #if CYTHON_USE_DICT_VERSIONS
__Pyx__GetModuleGlobalName(PyObject * name,PY_UINT64_T * dict_version,PyObject ** dict_cached_value)2935 static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
2936 #else
2937 static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
2938 #endif
2939 {
2940     PyObject *result;
2941 #if !CYTHON_AVOID_BORROWED_REFS
2942 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
2943     result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
2944     __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
2945     if (likely(result)) {
2946         return __Pyx_NewRef(result);
2947     } else if (unlikely(PyErr_Occurred())) {
2948         return NULL;
2949     }
2950 #else
2951     result = PyDict_GetItem(__pyx_d, name);
2952     __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
2953     if (likely(result)) {
2954         return __Pyx_NewRef(result);
2955     }
2956 #endif
2957 #else
2958     result = PyObject_GetItem(__pyx_d, name);
2959     __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
2960     if (likely(result)) {
2961         return __Pyx_NewRef(result);
2962     }
2963     PyErr_Clear();
2964 #endif
2965     return __Pyx_GetBuiltinName(name);
2966 }
2967 
2968 /* PyObjectCall */
2969 #if CYTHON_COMPILING_IN_CPYTHON
__Pyx_PyObject_Call(PyObject * func,PyObject * arg,PyObject * kw)2970 static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
2971     PyObject *result;
2972     ternaryfunc call = func->ob_type->tp_call;
2973     if (unlikely(!call))
2974         return PyObject_Call(func, arg, kw);
2975     if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
2976         return NULL;
2977     result = (*call)(func, arg, kw);
2978     Py_LeaveRecursiveCall();
2979     if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
2980         PyErr_SetString(
2981             PyExc_SystemError,
2982             "NULL result without error in PyObject_Call");
2983     }
2984     return result;
2985 }
2986 #endif
2987 
2988 /* PyErrFetchRestore */
2989 #if CYTHON_FAST_THREAD_STATE
__Pyx_ErrRestoreInState(PyThreadState * tstate,PyObject * type,PyObject * value,PyObject * tb)2990 static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
2991     PyObject *tmp_type, *tmp_value, *tmp_tb;
2992     tmp_type = tstate->curexc_type;
2993     tmp_value = tstate->curexc_value;
2994     tmp_tb = tstate->curexc_traceback;
2995     tstate->curexc_type = type;
2996     tstate->curexc_value = value;
2997     tstate->curexc_traceback = tb;
2998     Py_XDECREF(tmp_type);
2999     Py_XDECREF(tmp_value);
3000     Py_XDECREF(tmp_tb);
3001 }
__Pyx_ErrFetchInState(PyThreadState * tstate,PyObject ** type,PyObject ** value,PyObject ** tb)3002 static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
3003     *type = tstate->curexc_type;
3004     *value = tstate->curexc_value;
3005     *tb = tstate->curexc_traceback;
3006     tstate->curexc_type = 0;
3007     tstate->curexc_value = 0;
3008     tstate->curexc_traceback = 0;
3009 }
3010 #endif
3011 
3012 /* RaiseException */
3013 #if PY_MAJOR_VERSION < 3
__Pyx_Raise(PyObject * type,PyObject * value,PyObject * tb,CYTHON_UNUSED PyObject * cause)3014 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
3015                         CYTHON_UNUSED PyObject *cause) {
3016     __Pyx_PyThreadState_declare
3017     Py_XINCREF(type);
3018     if (!value || value == Py_None)
3019         value = NULL;
3020     else
3021         Py_INCREF(value);
3022     if (!tb || tb == Py_None)
3023         tb = NULL;
3024     else {
3025         Py_INCREF(tb);
3026         if (!PyTraceBack_Check(tb)) {
3027             PyErr_SetString(PyExc_TypeError,
3028                 "raise: arg 3 must be a traceback or None");
3029             goto raise_error;
3030         }
3031     }
3032     if (PyType_Check(type)) {
3033 #if CYTHON_COMPILING_IN_PYPY
3034         if (!value) {
3035             Py_INCREF(Py_None);
3036             value = Py_None;
3037         }
3038 #endif
3039         PyErr_NormalizeException(&type, &value, &tb);
3040     } else {
3041         if (value) {
3042             PyErr_SetString(PyExc_TypeError,
3043                 "instance exception may not have a separate value");
3044             goto raise_error;
3045         }
3046         value = type;
3047         type = (PyObject*) Py_TYPE(type);
3048         Py_INCREF(type);
3049         if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
3050             PyErr_SetString(PyExc_TypeError,
3051                 "raise: exception class must be a subclass of BaseException");
3052             goto raise_error;
3053         }
3054     }
3055     __Pyx_PyThreadState_assign
3056     __Pyx_ErrRestore(type, value, tb);
3057     return;
3058 raise_error:
3059     Py_XDECREF(value);
3060     Py_XDECREF(type);
3061     Py_XDECREF(tb);
3062     return;
3063 }
3064 #else
__Pyx_Raise(PyObject * type,PyObject * value,PyObject * tb,PyObject * cause)3065 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
3066     PyObject* owned_instance = NULL;
3067     if (tb == Py_None) {
3068         tb = 0;
3069     } else if (tb && !PyTraceBack_Check(tb)) {
3070         PyErr_SetString(PyExc_TypeError,
3071             "raise: arg 3 must be a traceback or None");
3072         goto bad;
3073     }
3074     if (value == Py_None)
3075         value = 0;
3076     if (PyExceptionInstance_Check(type)) {
3077         if (value) {
3078             PyErr_SetString(PyExc_TypeError,
3079                 "instance exception may not have a separate value");
3080             goto bad;
3081         }
3082         value = type;
3083         type = (PyObject*) Py_TYPE(value);
3084     } else if (PyExceptionClass_Check(type)) {
3085         PyObject *instance_class = NULL;
3086         if (value && PyExceptionInstance_Check(value)) {
3087             instance_class = (PyObject*) Py_TYPE(value);
3088             if (instance_class != type) {
3089                 int is_subclass = PyObject_IsSubclass(instance_class, type);
3090                 if (!is_subclass) {
3091                     instance_class = NULL;
3092                 } else if (unlikely(is_subclass == -1)) {
3093                     goto bad;
3094                 } else {
3095                     type = instance_class;
3096                 }
3097             }
3098         }
3099         if (!instance_class) {
3100             PyObject *args;
3101             if (!value)
3102                 args = PyTuple_New(0);
3103             else if (PyTuple_Check(value)) {
3104                 Py_INCREF(value);
3105                 args = value;
3106             } else
3107                 args = PyTuple_Pack(1, value);
3108             if (!args)
3109                 goto bad;
3110             owned_instance = PyObject_Call(type, args, NULL);
3111             Py_DECREF(args);
3112             if (!owned_instance)
3113                 goto bad;
3114             value = owned_instance;
3115             if (!PyExceptionInstance_Check(value)) {
3116                 PyErr_Format(PyExc_TypeError,
3117                              "calling %R should have returned an instance of "
3118                              "BaseException, not %R",
3119                              type, Py_TYPE(value));
3120                 goto bad;
3121             }
3122         }
3123     } else {
3124         PyErr_SetString(PyExc_TypeError,
3125             "raise: exception class must be a subclass of BaseException");
3126         goto bad;
3127     }
3128     if (cause) {
3129         PyObject *fixed_cause;
3130         if (cause == Py_None) {
3131             fixed_cause = NULL;
3132         } else if (PyExceptionClass_Check(cause)) {
3133             fixed_cause = PyObject_CallObject(cause, NULL);
3134             if (fixed_cause == NULL)
3135                 goto bad;
3136         } else if (PyExceptionInstance_Check(cause)) {
3137             fixed_cause = cause;
3138             Py_INCREF(fixed_cause);
3139         } else {
3140             PyErr_SetString(PyExc_TypeError,
3141                             "exception causes must derive from "
3142                             "BaseException");
3143             goto bad;
3144         }
3145         PyException_SetCause(value, fixed_cause);
3146     }
3147     PyErr_SetObject(type, value);
3148     if (tb) {
3149 #if CYTHON_COMPILING_IN_PYPY
3150         PyObject *tmp_type, *tmp_value, *tmp_tb;
3151         PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
3152         Py_INCREF(tb);
3153         PyErr_Restore(tmp_type, tmp_value, tb);
3154         Py_XDECREF(tmp_tb);
3155 #else
3156         PyThreadState *tstate = __Pyx_PyThreadState_Current;
3157         PyObject* tmp_tb = tstate->curexc_traceback;
3158         if (tb != tmp_tb) {
3159             Py_INCREF(tb);
3160             tstate->curexc_traceback = tb;
3161             Py_XDECREF(tmp_tb);
3162         }
3163 #endif
3164     }
3165 bad:
3166     Py_XDECREF(owned_instance);
3167     return;
3168 }
3169 #endif
3170 
3171 /* GetTopmostException */
3172 #if CYTHON_USE_EXC_INFO_STACK
3173 static _PyErr_StackItem *
__Pyx_PyErr_GetTopmostException(PyThreadState * tstate)3174 __Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
3175 {
3176     _PyErr_StackItem *exc_info = tstate->exc_info;
3177     while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
3178            exc_info->previous_item != NULL)
3179     {
3180         exc_info = exc_info->previous_item;
3181     }
3182     return exc_info;
3183 }
3184 #endif
3185 
3186 /* SaveResetException */
3187 #if CYTHON_FAST_THREAD_STATE
__Pyx__ExceptionSave(PyThreadState * tstate,PyObject ** type,PyObject ** value,PyObject ** tb)3188 static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
3189     #if CYTHON_USE_EXC_INFO_STACK
3190     _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
3191     *type = exc_info->exc_type;
3192     *value = exc_info->exc_value;
3193     *tb = exc_info->exc_traceback;
3194     #else
3195     *type = tstate->exc_type;
3196     *value = tstate->exc_value;
3197     *tb = tstate->exc_traceback;
3198     #endif
3199     Py_XINCREF(*type);
3200     Py_XINCREF(*value);
3201     Py_XINCREF(*tb);
3202 }
__Pyx__ExceptionReset(PyThreadState * tstate,PyObject * type,PyObject * value,PyObject * tb)3203 static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
3204     PyObject *tmp_type, *tmp_value, *tmp_tb;
3205     #if CYTHON_USE_EXC_INFO_STACK
3206     _PyErr_StackItem *exc_info = tstate->exc_info;
3207     tmp_type = exc_info->exc_type;
3208     tmp_value = exc_info->exc_value;
3209     tmp_tb = exc_info->exc_traceback;
3210     exc_info->exc_type = type;
3211     exc_info->exc_value = value;
3212     exc_info->exc_traceback = tb;
3213     #else
3214     tmp_type = tstate->exc_type;
3215     tmp_value = tstate->exc_value;
3216     tmp_tb = tstate->exc_traceback;
3217     tstate->exc_type = type;
3218     tstate->exc_value = value;
3219     tstate->exc_traceback = tb;
3220     #endif
3221     Py_XDECREF(tmp_type);
3222     Py_XDECREF(tmp_value);
3223     Py_XDECREF(tmp_tb);
3224 }
3225 #endif
3226 
3227 /* PyErrExceptionMatches */
3228 #if CYTHON_FAST_THREAD_STATE
__Pyx_PyErr_ExceptionMatchesTuple(PyObject * exc_type,PyObject * tuple)3229 static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
3230     Py_ssize_t i, n;
3231     n = PyTuple_GET_SIZE(tuple);
3232 #if PY_MAJOR_VERSION >= 3
3233     for (i=0; i<n; i++) {
3234         if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
3235     }
3236 #endif
3237     for (i=0; i<n; i++) {
3238         if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
3239     }
3240     return 0;
3241 }
__Pyx_PyErr_ExceptionMatchesInState(PyThreadState * tstate,PyObject * err)3242 static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
3243     PyObject *exc_type = tstate->curexc_type;
3244     if (exc_type == err) return 1;
3245     if (unlikely(!exc_type)) return 0;
3246     if (unlikely(PyTuple_Check(err)))
3247         return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
3248     return __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
3249 }
3250 #endif
3251 
3252 /* GetException */
3253 #if CYTHON_FAST_THREAD_STATE
__Pyx__GetException(PyThreadState * tstate,PyObject ** type,PyObject ** value,PyObject ** tb)3254 static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb)
3255 #else
3256 static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
3257 #endif
3258 {
3259     PyObject *local_type, *local_value, *local_tb;
3260 #if CYTHON_FAST_THREAD_STATE
3261     PyObject *tmp_type, *tmp_value, *tmp_tb;
3262     local_type = tstate->curexc_type;
3263     local_value = tstate->curexc_value;
3264     local_tb = tstate->curexc_traceback;
3265     tstate->curexc_type = 0;
3266     tstate->curexc_value = 0;
3267     tstate->curexc_traceback = 0;
3268 #else
3269     PyErr_Fetch(&local_type, &local_value, &local_tb);
3270 #endif
3271     PyErr_NormalizeException(&local_type, &local_value, &local_tb);
3272 #if CYTHON_FAST_THREAD_STATE
3273     if (unlikely(tstate->curexc_type))
3274 #else
3275     if (unlikely(PyErr_Occurred()))
3276 #endif
3277         goto bad;
3278     #if PY_MAJOR_VERSION >= 3
3279     if (local_tb) {
3280         if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
3281             goto bad;
3282     }
3283     #endif
3284     Py_XINCREF(local_tb);
3285     Py_XINCREF(local_type);
3286     Py_XINCREF(local_value);
3287     *type = local_type;
3288     *value = local_value;
3289     *tb = local_tb;
3290 #if CYTHON_FAST_THREAD_STATE
3291     #if CYTHON_USE_EXC_INFO_STACK
3292     {
3293         _PyErr_StackItem *exc_info = tstate->exc_info;
3294         tmp_type = exc_info->exc_type;
3295         tmp_value = exc_info->exc_value;
3296         tmp_tb = exc_info->exc_traceback;
3297         exc_info->exc_type = local_type;
3298         exc_info->exc_value = local_value;
3299         exc_info->exc_traceback = local_tb;
3300     }
3301     #else
3302     tmp_type = tstate->exc_type;
3303     tmp_value = tstate->exc_value;
3304     tmp_tb = tstate->exc_traceback;
3305     tstate->exc_type = local_type;
3306     tstate->exc_value = local_value;
3307     tstate->exc_traceback = local_tb;
3308     #endif
3309     Py_XDECREF(tmp_type);
3310     Py_XDECREF(tmp_value);
3311     Py_XDECREF(tmp_tb);
3312 #else
3313     PyErr_SetExcInfo(local_type, local_value, local_tb);
3314 #endif
3315     return 0;
3316 bad:
3317     *type = 0;
3318     *value = 0;
3319     *tb = 0;
3320     Py_XDECREF(local_type);
3321     Py_XDECREF(local_value);
3322     Py_XDECREF(local_tb);
3323     return -1;
3324 }
3325 
3326 /* PyIntCompare */
__Pyx_PyInt_EqObjC(PyObject * op1,PyObject * op2,CYTHON_UNUSED long intval,CYTHON_UNUSED long inplace)3327 static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) {
3328     if (op1 == op2) {
3329         Py_RETURN_TRUE;
3330     }
3331     #if PY_MAJOR_VERSION < 3
3332     if (likely(PyInt_CheckExact(op1))) {
3333         const long b = intval;
3334         long a = PyInt_AS_LONG(op1);
3335         if (a == b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
3336     }
3337     #endif
3338     #if CYTHON_USE_PYLONG_INTERNALS
3339     if (likely(PyLong_CheckExact(op1))) {
3340         int unequal;
3341         unsigned long uintval;
3342         Py_ssize_t size = Py_SIZE(op1);
3343         const digit* digits = ((PyLongObject*)op1)->ob_digit;
3344         if (intval == 0) {
3345             if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
3346         } else if (intval < 0) {
3347             if (size >= 0)
3348                 Py_RETURN_FALSE;
3349             intval = -intval;
3350             size = -size;
3351         } else {
3352             if (size <= 0)
3353                 Py_RETURN_FALSE;
3354         }
3355         uintval = (unsigned long) intval;
3356 #if PyLong_SHIFT * 4 < SIZEOF_LONG*8
3357         if (uintval >> (PyLong_SHIFT * 4)) {
3358             unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
3359                  | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
3360         } else
3361 #endif
3362 #if PyLong_SHIFT * 3 < SIZEOF_LONG*8
3363         if (uintval >> (PyLong_SHIFT * 3)) {
3364             unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
3365                  | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
3366         } else
3367 #endif
3368 #if PyLong_SHIFT * 2 < SIZEOF_LONG*8
3369         if (uintval >> (PyLong_SHIFT * 2)) {
3370             unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
3371                  | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
3372         } else
3373 #endif
3374 #if PyLong_SHIFT * 1 < SIZEOF_LONG*8
3375         if (uintval >> (PyLong_SHIFT * 1)) {
3376             unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
3377                  | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
3378         } else
3379 #endif
3380             unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
3381         if (unequal == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
3382     }
3383     #endif
3384     if (PyFloat_CheckExact(op1)) {
3385         const long b = intval;
3386         double a = PyFloat_AS_DOUBLE(op1);
3387         if ((double)a == (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
3388     }
3389     return (
3390         PyObject_RichCompare(op1, op2, Py_EQ));
3391 }
3392 
3393 /* PyIntBinop */
3394 #if !CYTHON_COMPILING_IN_PYPY
__Pyx_PyInt_AddObjC(PyObject * op1,PyObject * op2,CYTHON_UNUSED long intval,int inplace,int zerodivision_check)3395 static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
3396     (void)inplace;
3397     (void)zerodivision_check;
3398     #if PY_MAJOR_VERSION < 3
3399     if (likely(PyInt_CheckExact(op1))) {
3400         const long b = intval;
3401         long x;
3402         long a = PyInt_AS_LONG(op1);
3403             x = (long)((unsigned long)a + b);
3404             if (likely((x^a) >= 0 || (x^b) >= 0))
3405                 return PyInt_FromLong(x);
3406             return PyLong_Type.tp_as_number->nb_add(op1, op2);
3407     }
3408     #endif
3409     #if CYTHON_USE_PYLONG_INTERNALS
3410     if (likely(PyLong_CheckExact(op1))) {
3411         const long b = intval;
3412         long a, x;
3413 #ifdef HAVE_LONG_LONG
3414         const PY_LONG_LONG llb = intval;
3415         PY_LONG_LONG lla, llx;
3416 #endif
3417         const digit* digits = ((PyLongObject*)op1)->ob_digit;
3418         const Py_ssize_t size = Py_SIZE(op1);
3419         if (likely(__Pyx_sst_abs(size) <= 1)) {
3420             a = likely(size) ? digits[0] : 0;
3421             if (size == -1) a = -a;
3422         } else {
3423             switch (size) {
3424                 case -2:
3425                     if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
3426                         a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
3427                         break;
3428 #ifdef HAVE_LONG_LONG
3429                     } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
3430                         lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
3431                         goto long_long;
3432 #endif
3433                     }
3434                     CYTHON_FALLTHROUGH;
3435                 case 2:
3436                     if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
3437                         a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
3438                         break;
3439 #ifdef HAVE_LONG_LONG
3440                     } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
3441                         lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
3442                         goto long_long;
3443 #endif
3444                     }
3445                     CYTHON_FALLTHROUGH;
3446                 case -3:
3447                     if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
3448                         a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
3449                         break;
3450 #ifdef HAVE_LONG_LONG
3451                     } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
3452                         lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
3453                         goto long_long;
3454 #endif
3455                     }
3456                     CYTHON_FALLTHROUGH;
3457                 case 3:
3458                     if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
3459                         a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
3460                         break;
3461 #ifdef HAVE_LONG_LONG
3462                     } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
3463                         lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
3464                         goto long_long;
3465 #endif
3466                     }
3467                     CYTHON_FALLTHROUGH;
3468                 case -4:
3469                     if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
3470                         a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
3471                         break;
3472 #ifdef HAVE_LONG_LONG
3473                     } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
3474                         lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
3475                         goto long_long;
3476 #endif
3477                     }
3478                     CYTHON_FALLTHROUGH;
3479                 case 4:
3480                     if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
3481                         a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
3482                         break;
3483 #ifdef HAVE_LONG_LONG
3484                     } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
3485                         lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
3486                         goto long_long;
3487 #endif
3488                     }
3489                     CYTHON_FALLTHROUGH;
3490                 default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
3491             }
3492         }
3493                 x = a + b;
3494             return PyLong_FromLong(x);
3495 #ifdef HAVE_LONG_LONG
3496         long_long:
3497                 llx = lla + llb;
3498             return PyLong_FromLongLong(llx);
3499 #endif
3500 
3501 
3502     }
3503     #endif
3504     if (PyFloat_CheckExact(op1)) {
3505         const long b = intval;
3506         double a = PyFloat_AS_DOUBLE(op1);
3507             double result;
3508             PyFPE_START_PROTECT("add", return NULL)
3509             result = ((double)a) + (double)b;
3510             PyFPE_END_PROTECT(result)
3511             return PyFloat_FromDouble(result);
3512     }
3513     return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
3514 }
3515 #endif
3516 
3517 /* PyFunctionFastCall */
3518 #if CYTHON_FAST_PYCALL
__Pyx_PyFunction_FastCallNoKw(PyCodeObject * co,PyObject ** args,Py_ssize_t na,PyObject * globals)3519 static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
3520                                                PyObject *globals) {
3521     PyFrameObject *f;
3522     PyThreadState *tstate = __Pyx_PyThreadState_Current;
3523     PyObject **fastlocals;
3524     Py_ssize_t i;
3525     PyObject *result;
3526     assert(globals != NULL);
3527     /* XXX Perhaps we should create a specialized
3528        PyFrame_New() that doesn't take locals, but does
3529        take builtins without sanity checking them.
3530        */
3531     assert(tstate != NULL);
3532     f = PyFrame_New(tstate, co, globals, NULL);
3533     if (f == NULL) {
3534         return NULL;
3535     }
3536     fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
3537     for (i = 0; i < na; i++) {
3538         Py_INCREF(*args);
3539         fastlocals[i] = *args++;
3540     }
3541     result = PyEval_EvalFrameEx(f,0);
3542     ++tstate->recursion_depth;
3543     Py_DECREF(f);
3544     --tstate->recursion_depth;
3545     return result;
3546 }
3547 #if 1 || PY_VERSION_HEX < 0x030600B1
__Pyx_PyFunction_FastCallDict(PyObject * func,PyObject ** args,Py_ssize_t nargs,PyObject * kwargs)3548 static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) {
3549     PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
3550     PyObject *globals = PyFunction_GET_GLOBALS(func);
3551     PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
3552     PyObject *closure;
3553 #if PY_MAJOR_VERSION >= 3
3554     PyObject *kwdefs;
3555 #endif
3556     PyObject *kwtuple, **k;
3557     PyObject **d;
3558     Py_ssize_t nd;
3559     Py_ssize_t nk;
3560     PyObject *result;
3561     assert(kwargs == NULL || PyDict_Check(kwargs));
3562     nk = kwargs ? PyDict_Size(kwargs) : 0;
3563     if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
3564         return NULL;
3565     }
3566     if (
3567 #if PY_MAJOR_VERSION >= 3
3568             co->co_kwonlyargcount == 0 &&
3569 #endif
3570             likely(kwargs == NULL || nk == 0) &&
3571             co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
3572         if (argdefs == NULL && co->co_argcount == nargs) {
3573             result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
3574             goto done;
3575         }
3576         else if (nargs == 0 && argdefs != NULL
3577                  && co->co_argcount == Py_SIZE(argdefs)) {
3578             /* function called with no arguments, but all parameters have
3579                a default value: use default values as arguments .*/
3580             args = &PyTuple_GET_ITEM(argdefs, 0);
3581             result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
3582             goto done;
3583         }
3584     }
3585     if (kwargs != NULL) {
3586         Py_ssize_t pos, i;
3587         kwtuple = PyTuple_New(2 * nk);
3588         if (kwtuple == NULL) {
3589             result = NULL;
3590             goto done;
3591         }
3592         k = &PyTuple_GET_ITEM(kwtuple, 0);
3593         pos = i = 0;
3594         while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
3595             Py_INCREF(k[i]);
3596             Py_INCREF(k[i+1]);
3597             i += 2;
3598         }
3599         nk = i / 2;
3600     }
3601     else {
3602         kwtuple = NULL;
3603         k = NULL;
3604     }
3605     closure = PyFunction_GET_CLOSURE(func);
3606 #if PY_MAJOR_VERSION >= 3
3607     kwdefs = PyFunction_GET_KW_DEFAULTS(func);
3608 #endif
3609     if (argdefs != NULL) {
3610         d = &PyTuple_GET_ITEM(argdefs, 0);
3611         nd = Py_SIZE(argdefs);
3612     }
3613     else {
3614         d = NULL;
3615         nd = 0;
3616     }
3617 #if PY_MAJOR_VERSION >= 3
3618     result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
3619                                args, (int)nargs,
3620                                k, (int)nk,
3621                                d, (int)nd, kwdefs, closure);
3622 #else
3623     result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
3624                                args, (int)nargs,
3625                                k, (int)nk,
3626                                d, (int)nd, closure);
3627 #endif
3628     Py_XDECREF(kwtuple);
3629 done:
3630     Py_LeaveRecursiveCall();
3631     return result;
3632 }
3633 #endif
3634 #endif
3635 
3636 /* PyObjectCallMethO */
3637 #if CYTHON_COMPILING_IN_CPYTHON
__Pyx_PyObject_CallMethO(PyObject * func,PyObject * arg)3638 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
3639     PyObject *self, *result;
3640     PyCFunction cfunc;
3641     cfunc = PyCFunction_GET_FUNCTION(func);
3642     self = PyCFunction_GET_SELF(func);
3643     if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
3644         return NULL;
3645     result = cfunc(self, arg);
3646     Py_LeaveRecursiveCall();
3647     if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
3648         PyErr_SetString(
3649             PyExc_SystemError,
3650             "NULL result without error in PyObject_Call");
3651     }
3652     return result;
3653 }
3654 #endif
3655 
3656 /* PyObjectCallNoArg */
3657 #if CYTHON_COMPILING_IN_CPYTHON
__Pyx_PyObject_CallNoArg(PyObject * func)3658 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
3659 #if CYTHON_FAST_PYCALL
3660     if (PyFunction_Check(func)) {
3661         return __Pyx_PyFunction_FastCall(func, NULL, 0);
3662     }
3663 #endif
3664 #ifdef __Pyx_CyFunction_USED
3665     if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func)))
3666 #else
3667     if (likely(PyCFunction_Check(func)))
3668 #endif
3669     {
3670         if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
3671             return __Pyx_PyObject_CallMethO(func, NULL);
3672         }
3673     }
3674     return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
3675 }
3676 #endif
3677 
3678 /* PyCFunctionFastCall */
3679 #if CYTHON_FAST_PYCCALL
__Pyx_PyCFunction_FastCall(PyObject * func_obj,PyObject ** args,Py_ssize_t nargs)3680 static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
3681     PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
3682     PyCFunction meth = PyCFunction_GET_FUNCTION(func);
3683     PyObject *self = PyCFunction_GET_SELF(func);
3684     int flags = PyCFunction_GET_FLAGS(func);
3685     assert(PyCFunction_Check(func));
3686     assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)));
3687     assert(nargs >= 0);
3688     assert(nargs == 0 || args != NULL);
3689     /* _PyCFunction_FastCallDict() must not be called with an exception set,
3690        because it may clear it (directly or indirectly) and so the
3691        caller loses its exception */
3692     assert(!PyErr_Occurred());
3693     if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
3694         return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL);
3695     } else {
3696         return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs);
3697     }
3698 }
3699 #endif
3700 
3701 /* PyObjectCallOneArg */
3702 #if CYTHON_COMPILING_IN_CPYTHON
__Pyx__PyObject_CallOneArg(PyObject * func,PyObject * arg)3703 static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
3704     PyObject *result;
3705     PyObject *args = PyTuple_New(1);
3706     if (unlikely(!args)) return NULL;
3707     Py_INCREF(arg);
3708     PyTuple_SET_ITEM(args, 0, arg);
3709     result = __Pyx_PyObject_Call(func, args, NULL);
3710     Py_DECREF(args);
3711     return result;
3712 }
__Pyx_PyObject_CallOneArg(PyObject * func,PyObject * arg)3713 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
3714 #if CYTHON_FAST_PYCALL
3715     if (PyFunction_Check(func)) {
3716         return __Pyx_PyFunction_FastCall(func, &arg, 1);
3717     }
3718 #endif
3719     if (likely(PyCFunction_Check(func))) {
3720         if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
3721             return __Pyx_PyObject_CallMethO(func, arg);
3722 #if CYTHON_FAST_PYCCALL
3723         } else if (__Pyx_PyFastCFunction_Check(func)) {
3724             return __Pyx_PyCFunction_FastCall(func, &arg, 1);
3725 #endif
3726         }
3727     }
3728     return __Pyx__PyObject_CallOneArg(func, arg);
3729 }
3730 #else
__Pyx_PyObject_CallOneArg(PyObject * func,PyObject * arg)3731 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
3732     PyObject *result;
3733     PyObject *args = PyTuple_Pack(1, arg);
3734     if (unlikely(!args)) return NULL;
3735     result = __Pyx_PyObject_Call(func, args, NULL);
3736     Py_DECREF(args);
3737     return result;
3738 }
3739 #endif
3740 
3741 /* WriteUnraisableException */
__Pyx_WriteUnraisable(const char * name,CYTHON_UNUSED int clineno,CYTHON_UNUSED int lineno,CYTHON_UNUSED const char * filename,int full_traceback,CYTHON_UNUSED int nogil)3742 static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
3743                                   CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
3744                                   int full_traceback, CYTHON_UNUSED int nogil) {
3745     PyObject *old_exc, *old_val, *old_tb;
3746     PyObject *ctx;
3747     __Pyx_PyThreadState_declare
3748 #ifdef WITH_THREAD
3749     PyGILState_STATE state;
3750     if (nogil)
3751         state = PyGILState_Ensure();
3752 #ifdef _MSC_VER
3753     else state = (PyGILState_STATE)-1;
3754 #endif
3755 #endif
3756     __Pyx_PyThreadState_assign
3757     __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
3758     if (full_traceback) {
3759         Py_XINCREF(old_exc);
3760         Py_XINCREF(old_val);
3761         Py_XINCREF(old_tb);
3762         __Pyx_ErrRestore(old_exc, old_val, old_tb);
3763         PyErr_PrintEx(1);
3764     }
3765     #if PY_MAJOR_VERSION < 3
3766     ctx = PyString_FromString(name);
3767     #else
3768     ctx = PyUnicode_FromString(name);
3769     #endif
3770     __Pyx_ErrRestore(old_exc, old_val, old_tb);
3771     if (!ctx) {
3772         PyErr_WriteUnraisable(Py_None);
3773     } else {
3774         PyErr_WriteUnraisable(ctx);
3775         Py_DECREF(ctx);
3776     }
3777 #ifdef WITH_THREAD
3778     if (nogil)
3779         PyGILState_Release(state);
3780 #endif
3781 }
3782 
3783 /* Import */
__Pyx_Import(PyObject * name,PyObject * from_list,int level)3784 static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
3785     PyObject *empty_list = 0;
3786     PyObject *module = 0;
3787     PyObject *global_dict = 0;
3788     PyObject *empty_dict = 0;
3789     PyObject *list;
3790     #if PY_MAJOR_VERSION < 3
3791     PyObject *py_import;
3792     py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
3793     if (!py_import)
3794         goto bad;
3795     #endif
3796     if (from_list)
3797         list = from_list;
3798     else {
3799         empty_list = PyList_New(0);
3800         if (!empty_list)
3801             goto bad;
3802         list = empty_list;
3803     }
3804     global_dict = PyModule_GetDict(__pyx_m);
3805     if (!global_dict)
3806         goto bad;
3807     empty_dict = PyDict_New();
3808     if (!empty_dict)
3809         goto bad;
3810     {
3811         #if PY_MAJOR_VERSION >= 3
3812         if (level == -1) {
3813             if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) {
3814                 module = PyImport_ImportModuleLevelObject(
3815                     name, global_dict, empty_dict, list, 1);
3816                 if (!module) {
3817                     if (!PyErr_ExceptionMatches(PyExc_ImportError))
3818                         goto bad;
3819                     PyErr_Clear();
3820                 }
3821             }
3822             level = 0;
3823         }
3824         #endif
3825         if (!module) {
3826             #if PY_MAJOR_VERSION < 3
3827             PyObject *py_level = PyInt_FromLong(level);
3828             if (!py_level)
3829                 goto bad;
3830             module = PyObject_CallFunctionObjArgs(py_import,
3831                 name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
3832             Py_DECREF(py_level);
3833             #else
3834             module = PyImport_ImportModuleLevelObject(
3835                 name, global_dict, empty_dict, list, level);
3836             #endif
3837         }
3838     }
3839 bad:
3840     #if PY_MAJOR_VERSION < 3
3841     Py_XDECREF(py_import);
3842     #endif
3843     Py_XDECREF(empty_list);
3844     Py_XDECREF(empty_dict);
3845     return module;
3846 }
3847 
3848 /* CLineInTraceback */
3849 #ifndef CYTHON_CLINE_IN_TRACEBACK
__Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState * tstate,int c_line)3850 static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) {
3851     PyObject *use_cline;
3852     PyObject *ptype, *pvalue, *ptraceback;
3853 #if CYTHON_COMPILING_IN_CPYTHON
3854     PyObject **cython_runtime_dict;
3855 #endif
3856     if (unlikely(!__pyx_cython_runtime)) {
3857         return c_line;
3858     }
3859     __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
3860 #if CYTHON_COMPILING_IN_CPYTHON
3861     cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
3862     if (likely(cython_runtime_dict)) {
3863         __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
3864             use_cline, *cython_runtime_dict,
3865             __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
3866     } else
3867 #endif
3868     {
3869       PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
3870       if (use_cline_obj) {
3871         use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
3872         Py_DECREF(use_cline_obj);
3873       } else {
3874         PyErr_Clear();
3875         use_cline = NULL;
3876       }
3877     }
3878     if (!use_cline) {
3879         c_line = 0;
3880         PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
3881     }
3882     else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
3883         c_line = 0;
3884     }
3885     __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
3886     return c_line;
3887 }
3888 #endif
3889 
3890 /* CodeObjectCache */
__pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry * entries,int count,int code_line)3891 static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
3892     int start = 0, mid = 0, end = count - 1;
3893     if (end >= 0 && code_line > entries[end].code_line) {
3894         return count;
3895     }
3896     while (start < end) {
3897         mid = start + (end - start) / 2;
3898         if (code_line < entries[mid].code_line) {
3899             end = mid;
3900         } else if (code_line > entries[mid].code_line) {
3901              start = mid + 1;
3902         } else {
3903             return mid;
3904         }
3905     }
3906     if (code_line <= entries[mid].code_line) {
3907         return mid;
3908     } else {
3909         return mid + 1;
3910     }
3911 }
__pyx_find_code_object(int code_line)3912 static PyCodeObject *__pyx_find_code_object(int code_line) {
3913     PyCodeObject* code_object;
3914     int pos;
3915     if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
3916         return NULL;
3917     }
3918     pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
3919     if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
3920         return NULL;
3921     }
3922     code_object = __pyx_code_cache.entries[pos].code_object;
3923     Py_INCREF(code_object);
3924     return code_object;
3925 }
__pyx_insert_code_object(int code_line,PyCodeObject * code_object)3926 static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
3927     int pos, i;
3928     __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
3929     if (unlikely(!code_line)) {
3930         return;
3931     }
3932     if (unlikely(!entries)) {
3933         entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
3934         if (likely(entries)) {
3935             __pyx_code_cache.entries = entries;
3936             __pyx_code_cache.max_count = 64;
3937             __pyx_code_cache.count = 1;
3938             entries[0].code_line = code_line;
3939             entries[0].code_object = code_object;
3940             Py_INCREF(code_object);
3941         }
3942         return;
3943     }
3944     pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
3945     if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
3946         PyCodeObject* tmp = entries[pos].code_object;
3947         entries[pos].code_object = code_object;
3948         Py_DECREF(tmp);
3949         return;
3950     }
3951     if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
3952         int new_max = __pyx_code_cache.max_count + 64;
3953         entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
3954             __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry));
3955         if (unlikely(!entries)) {
3956             return;
3957         }
3958         __pyx_code_cache.entries = entries;
3959         __pyx_code_cache.max_count = new_max;
3960     }
3961     for (i=__pyx_code_cache.count; i>pos; i--) {
3962         entries[i] = entries[i-1];
3963     }
3964     entries[pos].code_line = code_line;
3965     entries[pos].code_object = code_object;
3966     __pyx_code_cache.count++;
3967     Py_INCREF(code_object);
3968 }
3969 
3970 /* AddTraceback */
3971 #include "compile.h"
3972 #include "frameobject.h"
3973 #include "traceback.h"
__Pyx_CreateCodeObjectForTraceback(const char * funcname,int c_line,int py_line,const char * filename)3974 static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
3975             const char *funcname, int c_line,
3976             int py_line, const char *filename) {
3977     PyCodeObject *py_code = 0;
3978     PyObject *py_srcfile = 0;
3979     PyObject *py_funcname = 0;
3980     #if PY_MAJOR_VERSION < 3
3981     py_srcfile = PyString_FromString(filename);
3982     #else
3983     py_srcfile = PyUnicode_FromString(filename);
3984     #endif
3985     if (!py_srcfile) goto bad;
3986     if (c_line) {
3987         #if PY_MAJOR_VERSION < 3
3988         py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
3989         #else
3990         py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
3991         #endif
3992     }
3993     else {
3994         #if PY_MAJOR_VERSION < 3
3995         py_funcname = PyString_FromString(funcname);
3996         #else
3997         py_funcname = PyUnicode_FromString(funcname);
3998         #endif
3999     }
4000     if (!py_funcname) goto bad;
4001     py_code = __Pyx_PyCode_New(
4002         0,
4003         0,
4004         0,
4005         0,
4006         0,
4007         __pyx_empty_bytes, /*PyObject *code,*/
4008         __pyx_empty_tuple, /*PyObject *consts,*/
4009         __pyx_empty_tuple, /*PyObject *names,*/
4010         __pyx_empty_tuple, /*PyObject *varnames,*/
4011         __pyx_empty_tuple, /*PyObject *freevars,*/
4012         __pyx_empty_tuple, /*PyObject *cellvars,*/
4013         py_srcfile,   /*PyObject *filename,*/
4014         py_funcname,  /*PyObject *name,*/
4015         py_line,
4016         __pyx_empty_bytes  /*PyObject *lnotab*/
4017     );
4018     Py_DECREF(py_srcfile);
4019     Py_DECREF(py_funcname);
4020     return py_code;
4021 bad:
4022     Py_XDECREF(py_srcfile);
4023     Py_XDECREF(py_funcname);
4024     return NULL;
4025 }
__Pyx_AddTraceback(const char * funcname,int c_line,int py_line,const char * filename)4026 static void __Pyx_AddTraceback(const char *funcname, int c_line,
4027                                int py_line, const char *filename) {
4028     PyCodeObject *py_code = 0;
4029     PyFrameObject *py_frame = 0;
4030     PyThreadState *tstate = __Pyx_PyThreadState_Current;
4031     if (c_line) {
4032         c_line = __Pyx_CLineForTraceback(tstate, c_line);
4033     }
4034     py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
4035     if (!py_code) {
4036         py_code = __Pyx_CreateCodeObjectForTraceback(
4037             funcname, c_line, py_line, filename);
4038         if (!py_code) goto bad;
4039         __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
4040     }
4041     py_frame = PyFrame_New(
4042         tstate,            /*PyThreadState *tstate,*/
4043         py_code,           /*PyCodeObject *code,*/
4044         __pyx_d,    /*PyObject *globals,*/
4045         0                  /*PyObject *locals*/
4046     );
4047     if (!py_frame) goto bad;
4048     __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
4049     PyTraceBack_Here(py_frame);
4050 bad:
4051     Py_XDECREF(py_code);
4052     Py_XDECREF(py_frame);
4053 }
4054 
4055 /* CIntFromPyVerify */
4056 #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
4057     __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
4058 #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
4059     __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
4060 #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
4061     {\
4062         func_type value = func_value;\
4063         if (sizeof(target_type) < sizeof(func_type)) {\
4064             if (unlikely(value != (func_type) (target_type) value)) {\
4065                 func_type zero = 0;\
4066                 if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
4067                     return (target_type) -1;\
4068                 if (is_unsigned && unlikely(value < zero))\
4069                     goto raise_neg_overflow;\
4070                 else\
4071                     goto raise_overflow;\
4072             }\
4073         }\
4074         return (target_type) value;\
4075     }
4076 
4077 /* CIntToPy */
__Pyx_PyInt_From_int(int value)4078 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
4079 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
4080 #pragma GCC diagnostic push
4081 #pragma GCC diagnostic ignored "-Wconversion"
4082 #endif
4083     const int neg_one = (int) -1, const_zero = (int) 0;
4084 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
4085 #pragma GCC diagnostic pop
4086 #endif
4087     const int is_unsigned = neg_one > const_zero;
4088     if (is_unsigned) {
4089         if (sizeof(int) < sizeof(long)) {
4090             return PyInt_FromLong((long) value);
4091         } else if (sizeof(int) <= sizeof(unsigned long)) {
4092             return PyLong_FromUnsignedLong((unsigned long) value);
4093 #ifdef HAVE_LONG_LONG
4094         } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
4095             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
4096 #endif
4097         }
4098     } else {
4099         if (sizeof(int) <= sizeof(long)) {
4100             return PyInt_FromLong((long) value);
4101 #ifdef HAVE_LONG_LONG
4102         } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
4103             return PyLong_FromLongLong((PY_LONG_LONG) value);
4104 #endif
4105         }
4106     }
4107     {
4108         int one = 1; int little = (int)*(unsigned char *)&one;
4109         unsigned char *bytes = (unsigned char *)&value;
4110         return _PyLong_FromByteArray(bytes, sizeof(int),
4111                                      little, !is_unsigned);
4112     }
4113 }
4114 
4115 /* CIntToPy */
__Pyx_PyInt_From_long(long value)4116 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
4117 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
4118 #pragma GCC diagnostic push
4119 #pragma GCC diagnostic ignored "-Wconversion"
4120 #endif
4121     const long neg_one = (long) -1, const_zero = (long) 0;
4122 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
4123 #pragma GCC diagnostic pop
4124 #endif
4125     const int is_unsigned = neg_one > const_zero;
4126     if (is_unsigned) {
4127         if (sizeof(long) < sizeof(long)) {
4128             return PyInt_FromLong((long) value);
4129         } else if (sizeof(long) <= sizeof(unsigned long)) {
4130             return PyLong_FromUnsignedLong((unsigned long) value);
4131 #ifdef HAVE_LONG_LONG
4132         } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
4133             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
4134 #endif
4135         }
4136     } else {
4137         if (sizeof(long) <= sizeof(long)) {
4138             return PyInt_FromLong((long) value);
4139 #ifdef HAVE_LONG_LONG
4140         } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
4141             return PyLong_FromLongLong((PY_LONG_LONG) value);
4142 #endif
4143         }
4144     }
4145     {
4146         int one = 1; int little = (int)*(unsigned char *)&one;
4147         unsigned char *bytes = (unsigned char *)&value;
4148         return _PyLong_FromByteArray(bytes, sizeof(long),
4149                                      little, !is_unsigned);
4150     }
4151 }
4152 
4153 /* CIntFromPy */
__Pyx_PyInt_As_int(PyObject * x)4154 static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
4155 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
4156 #pragma GCC diagnostic push
4157 #pragma GCC diagnostic ignored "-Wconversion"
4158 #endif
4159     const int neg_one = (int) -1, const_zero = (int) 0;
4160 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
4161 #pragma GCC diagnostic pop
4162 #endif
4163     const int is_unsigned = neg_one > const_zero;
4164 #if PY_MAJOR_VERSION < 3
4165     if (likely(PyInt_Check(x))) {
4166         if (sizeof(int) < sizeof(long)) {
4167             __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
4168         } else {
4169             long val = PyInt_AS_LONG(x);
4170             if (is_unsigned && unlikely(val < 0)) {
4171                 goto raise_neg_overflow;
4172             }
4173             return (int) val;
4174         }
4175     } else
4176 #endif
4177     if (likely(PyLong_Check(x))) {
4178         if (is_unsigned) {
4179 #if CYTHON_USE_PYLONG_INTERNALS
4180             const digit* digits = ((PyLongObject*)x)->ob_digit;
4181             switch (Py_SIZE(x)) {
4182                 case  0: return (int) 0;
4183                 case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
4184                 case 2:
4185                     if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
4186                         if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
4187                             __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4188                         } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
4189                             return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
4190                         }
4191                     }
4192                     break;
4193                 case 3:
4194                     if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
4195                         if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
4196                             __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4197                         } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
4198                             return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
4199                         }
4200                     }
4201                     break;
4202                 case 4:
4203                     if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
4204                         if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
4205                             __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])))
4206                         } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
4207                             return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
4208                         }
4209                     }
4210                     break;
4211             }
4212 #endif
4213 #if CYTHON_COMPILING_IN_CPYTHON
4214             if (unlikely(Py_SIZE(x) < 0)) {
4215                 goto raise_neg_overflow;
4216             }
4217 #else
4218             {
4219                 int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
4220                 if (unlikely(result < 0))
4221                     return (int) -1;
4222                 if (unlikely(result == 1))
4223                     goto raise_neg_overflow;
4224             }
4225 #endif
4226             if (sizeof(int) <= sizeof(unsigned long)) {
4227                 __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
4228 #ifdef HAVE_LONG_LONG
4229             } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
4230                 __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
4231 #endif
4232             }
4233         } else {
4234 #if CYTHON_USE_PYLONG_INTERNALS
4235             const digit* digits = ((PyLongObject*)x)->ob_digit;
4236             switch (Py_SIZE(x)) {
4237                 case  0: return (int) 0;
4238                 case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
4239                 case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
4240                 case -2:
4241                     if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
4242                         if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
4243                             __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4244                         } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
4245                             return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
4246                         }
4247                     }
4248                     break;
4249                 case 2:
4250                     if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
4251                         if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
4252                             __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4253                         } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
4254                             return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
4255                         }
4256                     }
4257                     break;
4258                 case -3:
4259                     if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
4260                         if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
4261                             __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4262                         } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
4263                             return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
4264                         }
4265                     }
4266                     break;
4267                 case 3:
4268                     if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
4269                         if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
4270                             __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4271                         } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
4272                             return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
4273                         }
4274                     }
4275                     break;
4276                 case -4:
4277                     if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
4278                         if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
4279                             __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])))
4280                         } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
4281                             return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
4282                         }
4283                     }
4284                     break;
4285                 case 4:
4286                     if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
4287                         if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
4288                             __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])))
4289                         } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
4290                             return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
4291                         }
4292                     }
4293                     break;
4294             }
4295 #endif
4296             if (sizeof(int) <= sizeof(long)) {
4297                 __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
4298 #ifdef HAVE_LONG_LONG
4299             } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
4300                 __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
4301 #endif
4302             }
4303         }
4304         {
4305 #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
4306             PyErr_SetString(PyExc_RuntimeError,
4307                             "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
4308 #else
4309             int val;
4310             PyObject *v = __Pyx_PyNumber_IntOrLong(x);
4311  #if PY_MAJOR_VERSION < 3
4312             if (likely(v) && !PyLong_Check(v)) {
4313                 PyObject *tmp = v;
4314                 v = PyNumber_Long(tmp);
4315                 Py_DECREF(tmp);
4316             }
4317  #endif
4318             if (likely(v)) {
4319                 int one = 1; int is_little = (int)*(unsigned char *)&one;
4320                 unsigned char *bytes = (unsigned char *)&val;
4321                 int ret = _PyLong_AsByteArray((PyLongObject *)v,
4322                                               bytes, sizeof(val),
4323                                               is_little, !is_unsigned);
4324                 Py_DECREF(v);
4325                 if (likely(!ret))
4326                     return val;
4327             }
4328 #endif
4329             return (int) -1;
4330         }
4331     } else {
4332         int val;
4333         PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
4334         if (!tmp) return (int) -1;
4335         val = __Pyx_PyInt_As_int(tmp);
4336         Py_DECREF(tmp);
4337         return val;
4338     }
4339 raise_overflow:
4340     PyErr_SetString(PyExc_OverflowError,
4341         "value too large to convert to int");
4342     return (int) -1;
4343 raise_neg_overflow:
4344     PyErr_SetString(PyExc_OverflowError,
4345         "can't convert negative value to int");
4346     return (int) -1;
4347 }
4348 
4349 /* CIntFromPy */
__Pyx_PyInt_As_long(PyObject * x)4350 static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
4351 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
4352 #pragma GCC diagnostic push
4353 #pragma GCC diagnostic ignored "-Wconversion"
4354 #endif
4355     const long neg_one = (long) -1, const_zero = (long) 0;
4356 #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
4357 #pragma GCC diagnostic pop
4358 #endif
4359     const int is_unsigned = neg_one > const_zero;
4360 #if PY_MAJOR_VERSION < 3
4361     if (likely(PyInt_Check(x))) {
4362         if (sizeof(long) < sizeof(long)) {
4363             __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
4364         } else {
4365             long val = PyInt_AS_LONG(x);
4366             if (is_unsigned && unlikely(val < 0)) {
4367                 goto raise_neg_overflow;
4368             }
4369             return (long) val;
4370         }
4371     } else
4372 #endif
4373     if (likely(PyLong_Check(x))) {
4374         if (is_unsigned) {
4375 #if CYTHON_USE_PYLONG_INTERNALS
4376             const digit* digits = ((PyLongObject*)x)->ob_digit;
4377             switch (Py_SIZE(x)) {
4378                 case  0: return (long) 0;
4379                 case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
4380                 case 2:
4381                     if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
4382                         if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
4383                             __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4384                         } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
4385                             return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
4386                         }
4387                     }
4388                     break;
4389                 case 3:
4390                     if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
4391                         if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
4392                             __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4393                         } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
4394                             return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
4395                         }
4396                     }
4397                     break;
4398                 case 4:
4399                     if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
4400                         if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
4401                             __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])))
4402                         } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
4403                             return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
4404                         }
4405                     }
4406                     break;
4407             }
4408 #endif
4409 #if CYTHON_COMPILING_IN_CPYTHON
4410             if (unlikely(Py_SIZE(x) < 0)) {
4411                 goto raise_neg_overflow;
4412             }
4413 #else
4414             {
4415                 int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
4416                 if (unlikely(result < 0))
4417                     return (long) -1;
4418                 if (unlikely(result == 1))
4419                     goto raise_neg_overflow;
4420             }
4421 #endif
4422             if (sizeof(long) <= sizeof(unsigned long)) {
4423                 __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
4424 #ifdef HAVE_LONG_LONG
4425             } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
4426                 __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
4427 #endif
4428             }
4429         } else {
4430 #if CYTHON_USE_PYLONG_INTERNALS
4431             const digit* digits = ((PyLongObject*)x)->ob_digit;
4432             switch (Py_SIZE(x)) {
4433                 case  0: return (long) 0;
4434                 case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
4435                 case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
4436                 case -2:
4437                     if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
4438                         if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
4439                             __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4440                         } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
4441                             return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
4442                         }
4443                     }
4444                     break;
4445                 case 2:
4446                     if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
4447                         if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
4448                             __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4449                         } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
4450                             return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
4451                         }
4452                     }
4453                     break;
4454                 case -3:
4455                     if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
4456                         if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
4457                             __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4458                         } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
4459                             return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
4460                         }
4461                     }
4462                     break;
4463                 case 3:
4464                     if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
4465                         if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
4466                             __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
4467                         } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
4468                             return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
4469                         }
4470                     }
4471                     break;
4472                 case -4:
4473                     if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
4474                         if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
4475                             __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])))
4476                         } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
4477                             return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
4478                         }
4479                     }
4480                     break;
4481                 case 4:
4482                     if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
4483                         if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
4484                             __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])))
4485                         } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
4486                             return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
4487                         }
4488                     }
4489                     break;
4490             }
4491 #endif
4492             if (sizeof(long) <= sizeof(long)) {
4493                 __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
4494 #ifdef HAVE_LONG_LONG
4495             } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
4496                 __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
4497 #endif
4498             }
4499         }
4500         {
4501 #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
4502             PyErr_SetString(PyExc_RuntimeError,
4503                             "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
4504 #else
4505             long val;
4506             PyObject *v = __Pyx_PyNumber_IntOrLong(x);
4507  #if PY_MAJOR_VERSION < 3
4508             if (likely(v) && !PyLong_Check(v)) {
4509                 PyObject *tmp = v;
4510                 v = PyNumber_Long(tmp);
4511                 Py_DECREF(tmp);
4512             }
4513  #endif
4514             if (likely(v)) {
4515                 int one = 1; int is_little = (int)*(unsigned char *)&one;
4516                 unsigned char *bytes = (unsigned char *)&val;
4517                 int ret = _PyLong_AsByteArray((PyLongObject *)v,
4518                                               bytes, sizeof(val),
4519                                               is_little, !is_unsigned);
4520                 Py_DECREF(v);
4521                 if (likely(!ret))
4522                     return val;
4523             }
4524 #endif
4525             return (long) -1;
4526         }
4527     } else {
4528         long val;
4529         PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
4530         if (!tmp) return (long) -1;
4531         val = __Pyx_PyInt_As_long(tmp);
4532         Py_DECREF(tmp);
4533         return val;
4534     }
4535 raise_overflow:
4536     PyErr_SetString(PyExc_OverflowError,
4537         "value too large to convert to long");
4538     return (long) -1;
4539 raise_neg_overflow:
4540     PyErr_SetString(PyExc_OverflowError,
4541         "can't convert negative value to long");
4542     return (long) -1;
4543 }
4544 
4545 /* FastTypeChecks */
4546 #if CYTHON_COMPILING_IN_CPYTHON
__Pyx_InBases(PyTypeObject * a,PyTypeObject * b)4547 static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
4548     while (a) {
4549         a = a->tp_base;
4550         if (a == b)
4551             return 1;
4552     }
4553     return b == &PyBaseObject_Type;
4554 }
__Pyx_IsSubtype(PyTypeObject * a,PyTypeObject * b)4555 static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
4556     PyObject *mro;
4557     if (a == b) return 1;
4558     mro = a->tp_mro;
4559     if (likely(mro)) {
4560         Py_ssize_t i, n;
4561         n = PyTuple_GET_SIZE(mro);
4562         for (i = 0; i < n; i++) {
4563             if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
4564                 return 1;
4565         }
4566         return 0;
4567     }
4568     return __Pyx_InBases(a, b);
4569 }
4570 #if PY_MAJOR_VERSION == 2
__Pyx_inner_PyErr_GivenExceptionMatches2(PyObject * err,PyObject * exc_type1,PyObject * exc_type2)4571 static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
4572     PyObject *exception, *value, *tb;
4573     int res;
4574     __Pyx_PyThreadState_declare
4575     __Pyx_PyThreadState_assign
4576     __Pyx_ErrFetch(&exception, &value, &tb);
4577     res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
4578     if (unlikely(res == -1)) {
4579         PyErr_WriteUnraisable(err);
4580         res = 0;
4581     }
4582     if (!res) {
4583         res = PyObject_IsSubclass(err, exc_type2);
4584         if (unlikely(res == -1)) {
4585             PyErr_WriteUnraisable(err);
4586             res = 0;
4587         }
4588     }
4589     __Pyx_ErrRestore(exception, value, tb);
4590     return res;
4591 }
4592 #else
__Pyx_inner_PyErr_GivenExceptionMatches2(PyObject * err,PyObject * exc_type1,PyObject * exc_type2)4593 static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
4594     int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
4595     if (!res) {
4596         res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
4597     }
4598     return res;
4599 }
4600 #endif
__Pyx_PyErr_GivenExceptionMatchesTuple(PyObject * exc_type,PyObject * tuple)4601 static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
4602     Py_ssize_t i, n;
4603     assert(PyExceptionClass_Check(exc_type));
4604     n = PyTuple_GET_SIZE(tuple);
4605 #if PY_MAJOR_VERSION >= 3
4606     for (i=0; i<n; i++) {
4607         if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
4608     }
4609 #endif
4610     for (i=0; i<n; i++) {
4611         PyObject *t = PyTuple_GET_ITEM(tuple, i);
4612         #if PY_MAJOR_VERSION < 3
4613         if (likely(exc_type == t)) return 1;
4614         #endif
4615         if (likely(PyExceptionClass_Check(t))) {
4616             if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
4617         } else {
4618         }
4619     }
4620     return 0;
4621 }
__Pyx_PyErr_GivenExceptionMatches(PyObject * err,PyObject * exc_type)4622 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
4623     if (likely(err == exc_type)) return 1;
4624     if (likely(PyExceptionClass_Check(err))) {
4625         if (likely(PyExceptionClass_Check(exc_type))) {
4626             return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
4627         } else if (likely(PyTuple_Check(exc_type))) {
4628             return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
4629         } else {
4630         }
4631     }
4632     return PyErr_GivenExceptionMatches(err, exc_type);
4633 }
__Pyx_PyErr_GivenExceptionMatches2(PyObject * err,PyObject * exc_type1,PyObject * exc_type2)4634 static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
4635     assert(PyExceptionClass_Check(exc_type1));
4636     assert(PyExceptionClass_Check(exc_type2));
4637     if (likely(err == exc_type1 || err == exc_type2)) return 1;
4638     if (likely(PyExceptionClass_Check(err))) {
4639         return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
4640     }
4641     return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
4642 }
4643 #endif
4644 
4645 /* CheckBinaryVersion */
__Pyx_check_binary_version(void)4646 static int __Pyx_check_binary_version(void) {
4647     char ctversion[4], rtversion[4];
4648     PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
4649     PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
4650     if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
4651         char message[200];
4652         PyOS_snprintf(message, sizeof(message),
4653                       "compiletime version %s of module '%.100s' "
4654                       "does not match runtime version %s",
4655                       ctversion, __Pyx_MODULE_NAME, rtversion);
4656         return PyErr_WarnEx(NULL, message, 1);
4657     }
4658     return 0;
4659 }
4660 
4661 /* FunctionExport */
__Pyx_ExportFunction(const char * name,void (* f)(void),const char * sig)4662 static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
4663     PyObject *d = 0;
4664     PyObject *cobj = 0;
4665     union {
4666         void (*fp)(void);
4667         void *p;
4668     } tmp;
4669     d = PyObject_GetAttrString(__pyx_m, (char *)"__pyx_capi__");
4670     if (!d) {
4671         PyErr_Clear();
4672         d = PyDict_New();
4673         if (!d)
4674             goto bad;
4675         Py_INCREF(d);
4676         if (PyModule_AddObject(__pyx_m, (char *)"__pyx_capi__", d) < 0)
4677             goto bad;
4678     }
4679     tmp.fp = f;
4680 #if PY_VERSION_HEX >= 0x02070000
4681     cobj = PyCapsule_New(tmp.p, sig, 0);
4682 #else
4683     cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
4684 #endif
4685     if (!cobj)
4686         goto bad;
4687     if (PyDict_SetItemString(d, name, cobj) < 0)
4688         goto bad;
4689     Py_DECREF(cobj);
4690     Py_DECREF(d);
4691     return 0;
4692 bad:
4693     Py_XDECREF(cobj);
4694     Py_XDECREF(d);
4695     return -1;
4696 }
4697 
4698 /* InitStrings */
__Pyx_InitStrings(__Pyx_StringTabEntry * t)4699 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
4700     while (t->p) {
4701         #if PY_MAJOR_VERSION < 3
4702         if (t->is_unicode) {
4703             *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
4704         } else if (t->intern) {
4705             *t->p = PyString_InternFromString(t->s);
4706         } else {
4707             *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
4708         }
4709         #else
4710         if (t->is_unicode | t->is_str) {
4711             if (t->intern) {
4712                 *t->p = PyUnicode_InternFromString(t->s);
4713             } else if (t->encoding) {
4714                 *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
4715             } else {
4716                 *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
4717             }
4718         } else {
4719             *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
4720         }
4721         #endif
4722         if (!*t->p)
4723             return -1;
4724         if (PyObject_Hash(*t->p) == -1)
4725             return -1;
4726         ++t;
4727     }
4728     return 0;
4729 }
4730 
__Pyx_PyUnicode_FromString(const char * c_str)4731 static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
4732     return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
4733 }
__Pyx_PyObject_AsString(PyObject * o)4734 static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
4735     Py_ssize_t ignore;
4736     return __Pyx_PyObject_AsStringAndSize(o, &ignore);
4737 }
4738 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
4739 #if !CYTHON_PEP393_ENABLED
__Pyx_PyUnicode_AsStringAndSize(PyObject * o,Py_ssize_t * length)4740 static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
4741     char* defenc_c;
4742     PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
4743     if (!defenc) return NULL;
4744     defenc_c = PyBytes_AS_STRING(defenc);
4745 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
4746     {
4747         char* end = defenc_c + PyBytes_GET_SIZE(defenc);
4748         char* c;
4749         for (c = defenc_c; c < end; c++) {
4750             if ((unsigned char) (*c) >= 128) {
4751                 PyUnicode_AsASCIIString(o);
4752                 return NULL;
4753             }
4754         }
4755     }
4756 #endif
4757     *length = PyBytes_GET_SIZE(defenc);
4758     return defenc_c;
4759 }
4760 #else
__Pyx_PyUnicode_AsStringAndSize(PyObject * o,Py_ssize_t * length)4761 static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
4762     if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
4763 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
4764     if (likely(PyUnicode_IS_ASCII(o))) {
4765         *length = PyUnicode_GET_LENGTH(o);
4766         return PyUnicode_AsUTF8(o);
4767     } else {
4768         PyUnicode_AsASCIIString(o);
4769         return NULL;
4770     }
4771 #else
4772     return PyUnicode_AsUTF8AndSize(o, length);
4773 #endif
4774 }
4775 #endif
4776 #endif
__Pyx_PyObject_AsStringAndSize(PyObject * o,Py_ssize_t * length)4777 static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
4778 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
4779     if (
4780 #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
4781             __Pyx_sys_getdefaultencoding_not_ascii &&
4782 #endif
4783             PyUnicode_Check(o)) {
4784         return __Pyx_PyUnicode_AsStringAndSize(o, length);
4785     } else
4786 #endif
4787 #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
4788     if (PyByteArray_Check(o)) {
4789         *length = PyByteArray_GET_SIZE(o);
4790         return PyByteArray_AS_STRING(o);
4791     } else
4792 #endif
4793     {
4794         char* result;
4795         int r = PyBytes_AsStringAndSize(o, &result, length);
4796         if (unlikely(r < 0)) {
4797             return NULL;
4798         } else {
4799             return result;
4800         }
4801     }
4802 }
__Pyx_PyObject_IsTrue(PyObject * x)4803 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
4804    int is_true = x == Py_True;
4805    if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
4806    else return PyObject_IsTrue(x);
4807 }
__Pyx_PyObject_IsTrueAndDecref(PyObject * x)4808 static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
4809     int retval;
4810     if (unlikely(!x)) return -1;
4811     retval = __Pyx_PyObject_IsTrue(x);
4812     Py_DECREF(x);
4813     return retval;
4814 }
__Pyx_PyNumber_IntOrLongWrongResultType(PyObject * result,const char * type_name)4815 static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
4816 #if PY_MAJOR_VERSION >= 3
4817     if (PyLong_Check(result)) {
4818         if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
4819                 "__int__ returned non-int (type %.200s).  "
4820                 "The ability to return an instance of a strict subclass of int "
4821                 "is deprecated, and may be removed in a future version of Python.",
4822                 Py_TYPE(result)->tp_name)) {
4823             Py_DECREF(result);
4824             return NULL;
4825         }
4826         return result;
4827     }
4828 #endif
4829     PyErr_Format(PyExc_TypeError,
4830                  "__%.4s__ returned non-%.4s (type %.200s)",
4831                  type_name, type_name, Py_TYPE(result)->tp_name);
4832     Py_DECREF(result);
4833     return NULL;
4834 }
__Pyx_PyNumber_IntOrLong(PyObject * x)4835 static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
4836 #if CYTHON_USE_TYPE_SLOTS
4837   PyNumberMethods *m;
4838 #endif
4839   const char *name = NULL;
4840   PyObject *res = NULL;
4841 #if PY_MAJOR_VERSION < 3
4842   if (likely(PyInt_Check(x) || PyLong_Check(x)))
4843 #else
4844   if (likely(PyLong_Check(x)))
4845 #endif
4846     return __Pyx_NewRef(x);
4847 #if CYTHON_USE_TYPE_SLOTS
4848   m = Py_TYPE(x)->tp_as_number;
4849   #if PY_MAJOR_VERSION < 3
4850   if (m && m->nb_int) {
4851     name = "int";
4852     res = m->nb_int(x);
4853   }
4854   else if (m && m->nb_long) {
4855     name = "long";
4856     res = m->nb_long(x);
4857   }
4858   #else
4859   if (likely(m && m->nb_int)) {
4860     name = "int";
4861     res = m->nb_int(x);
4862   }
4863   #endif
4864 #else
4865   if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
4866     res = PyNumber_Int(x);
4867   }
4868 #endif
4869   if (likely(res)) {
4870 #if PY_MAJOR_VERSION < 3
4871     if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
4872 #else
4873     if (unlikely(!PyLong_CheckExact(res))) {
4874 #endif
4875         return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
4876     }
4877   }
4878   else if (!PyErr_Occurred()) {
4879     PyErr_SetString(PyExc_TypeError,
4880                     "an integer is required");
4881   }
4882   return res;
4883 }
4884 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
4885   Py_ssize_t ival;
4886   PyObject *x;
4887 #if PY_MAJOR_VERSION < 3
4888   if (likely(PyInt_CheckExact(b))) {
4889     if (sizeof(Py_ssize_t) >= sizeof(long))
4890         return PyInt_AS_LONG(b);
4891     else
4892         return PyInt_AsSsize_t(b);
4893   }
4894 #endif
4895   if (likely(PyLong_CheckExact(b))) {
4896     #if CYTHON_USE_PYLONG_INTERNALS
4897     const digit* digits = ((PyLongObject*)b)->ob_digit;
4898     const Py_ssize_t size = Py_SIZE(b);
4899     if (likely(__Pyx_sst_abs(size) <= 1)) {
4900         ival = likely(size) ? digits[0] : 0;
4901         if (size == -1) ival = -ival;
4902         return ival;
4903     } else {
4904       switch (size) {
4905          case 2:
4906            if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
4907              return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4908            }
4909            break;
4910          case -2:
4911            if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
4912              return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4913            }
4914            break;
4915          case 3:
4916            if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
4917              return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4918            }
4919            break;
4920          case -3:
4921            if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
4922              return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
4923            }
4924            break;
4925          case 4:
4926            if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
4927              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]));
4928            }
4929            break;
4930          case -4:
4931            if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
4932              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]));
4933            }
4934            break;
4935       }
4936     }
4937     #endif
4938     return PyLong_AsSsize_t(b);
4939   }
4940   x = PyNumber_Index(b);
4941   if (!x) return -1;
4942   ival = PyInt_AsSsize_t(x);
4943   Py_DECREF(x);
4944   return ival;
4945 }
4946 static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
4947   return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
4948 }
4949 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
4950     return PyInt_FromSize_t(ival);
4951 }
4952 
4953 
4954 #endif /* Py_PYTHON_H */
4955