Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/python/bench/src/cython/nt.c
1067 views
1
/* Generated by Cython 0.29.32 */
2
3
/* BEGIN: Cython Metadata
4
{
5
"distutils": {
6
"name": "nt",
7
"sources": [
8
"nt.pyx"
9
]
10
},
11
"module_name": "nt"
12
}
13
END: Cython Metadata */
14
15
#ifndef PY_SSIZE_T_CLEAN
16
#define PY_SSIZE_T_CLEAN
17
#endif /* PY_SSIZE_T_CLEAN */
18
#include "Python.h"
19
#ifndef Py_PYTHON_H
20
#error Python headers needed to compile C extensions, please install development version of Python.
21
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
22
#error Cython requires Python 2.6+ or Python 3.3+.
23
#else
24
#define CYTHON_ABI "0_29_32"
25
#define CYTHON_HEX_VERSION 0x001D20F0
26
#define CYTHON_FUTURE_DIVISION 0
27
#include <stddef.h>
28
#ifndef offsetof
29
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
30
#endif
31
#if !defined(WIN32) && !defined(MS_WINDOWS)
32
#ifndef __stdcall
33
#define __stdcall
34
#endif
35
#ifndef __cdecl
36
#define __cdecl
37
#endif
38
#ifndef __fastcall
39
#define __fastcall
40
#endif
41
#endif
42
#ifndef DL_IMPORT
43
#define DL_IMPORT(t) t
44
#endif
45
#ifndef DL_EXPORT
46
#define DL_EXPORT(t) t
47
#endif
48
#define __PYX_COMMA ,
49
#ifndef HAVE_LONG_LONG
50
#if PY_VERSION_HEX >= 0x02070000
51
#define HAVE_LONG_LONG
52
#endif
53
#endif
54
#ifndef PY_LONG_LONG
55
#define PY_LONG_LONG LONG_LONG
56
#endif
57
#ifndef Py_HUGE_VAL
58
#define Py_HUGE_VAL HUGE_VAL
59
#endif
60
#ifdef PYPY_VERSION
61
#define CYTHON_COMPILING_IN_PYPY 1
62
#define CYTHON_COMPILING_IN_PYSTON 0
63
#define CYTHON_COMPILING_IN_CPYTHON 0
64
#define CYTHON_COMPILING_IN_NOGIL 0
65
#undef CYTHON_USE_TYPE_SLOTS
66
#define CYTHON_USE_TYPE_SLOTS 0
67
#undef CYTHON_USE_PYTYPE_LOOKUP
68
#define CYTHON_USE_PYTYPE_LOOKUP 0
69
#if PY_VERSION_HEX < 0x03050000
70
#undef CYTHON_USE_ASYNC_SLOTS
71
#define CYTHON_USE_ASYNC_SLOTS 0
72
#elif !defined(CYTHON_USE_ASYNC_SLOTS)
73
#define CYTHON_USE_ASYNC_SLOTS 1
74
#endif
75
#undef CYTHON_USE_PYLIST_INTERNALS
76
#define CYTHON_USE_PYLIST_INTERNALS 0
77
#undef CYTHON_USE_UNICODE_INTERNALS
78
#define CYTHON_USE_UNICODE_INTERNALS 0
79
#undef CYTHON_USE_UNICODE_WRITER
80
#define CYTHON_USE_UNICODE_WRITER 0
81
#undef CYTHON_USE_PYLONG_INTERNALS
82
#define CYTHON_USE_PYLONG_INTERNALS 0
83
#undef CYTHON_AVOID_BORROWED_REFS
84
#define CYTHON_AVOID_BORROWED_REFS 1
85
#undef CYTHON_ASSUME_SAFE_MACROS
86
#define CYTHON_ASSUME_SAFE_MACROS 0
87
#undef CYTHON_UNPACK_METHODS
88
#define CYTHON_UNPACK_METHODS 0
89
#undef CYTHON_FAST_THREAD_STATE
90
#define CYTHON_FAST_THREAD_STATE 0
91
#undef CYTHON_FAST_PYCALL
92
#define CYTHON_FAST_PYCALL 0
93
#undef CYTHON_PEP489_MULTI_PHASE_INIT
94
#define CYTHON_PEP489_MULTI_PHASE_INIT 0
95
#undef CYTHON_USE_TP_FINALIZE
96
#define CYTHON_USE_TP_FINALIZE 0
97
#undef CYTHON_USE_DICT_VERSIONS
98
#define CYTHON_USE_DICT_VERSIONS 0
99
#undef CYTHON_USE_EXC_INFO_STACK
100
#define CYTHON_USE_EXC_INFO_STACK 0
101
#ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
102
#define CYTHON_UPDATE_DESCRIPTOR_DOC (PYPY_VERSION_HEX >= 0x07030900)
103
#endif
104
#elif defined(PYSTON_VERSION)
105
#define CYTHON_COMPILING_IN_PYPY 0
106
#define CYTHON_COMPILING_IN_PYSTON 1
107
#define CYTHON_COMPILING_IN_CPYTHON 0
108
#define CYTHON_COMPILING_IN_NOGIL 0
109
#ifndef CYTHON_USE_TYPE_SLOTS
110
#define CYTHON_USE_TYPE_SLOTS 1
111
#endif
112
#undef CYTHON_USE_PYTYPE_LOOKUP
113
#define CYTHON_USE_PYTYPE_LOOKUP 0
114
#undef CYTHON_USE_ASYNC_SLOTS
115
#define CYTHON_USE_ASYNC_SLOTS 0
116
#undef CYTHON_USE_PYLIST_INTERNALS
117
#define CYTHON_USE_PYLIST_INTERNALS 0
118
#ifndef CYTHON_USE_UNICODE_INTERNALS
119
#define CYTHON_USE_UNICODE_INTERNALS 1
120
#endif
121
#undef CYTHON_USE_UNICODE_WRITER
122
#define CYTHON_USE_UNICODE_WRITER 0
123
#undef CYTHON_USE_PYLONG_INTERNALS
124
#define CYTHON_USE_PYLONG_INTERNALS 0
125
#ifndef CYTHON_AVOID_BORROWED_REFS
126
#define CYTHON_AVOID_BORROWED_REFS 0
127
#endif
128
#ifndef CYTHON_ASSUME_SAFE_MACROS
129
#define CYTHON_ASSUME_SAFE_MACROS 1
130
#endif
131
#ifndef CYTHON_UNPACK_METHODS
132
#define CYTHON_UNPACK_METHODS 1
133
#endif
134
#undef CYTHON_FAST_THREAD_STATE
135
#define CYTHON_FAST_THREAD_STATE 0
136
#undef CYTHON_FAST_PYCALL
137
#define CYTHON_FAST_PYCALL 0
138
#undef CYTHON_PEP489_MULTI_PHASE_INIT
139
#define CYTHON_PEP489_MULTI_PHASE_INIT 0
140
#undef CYTHON_USE_TP_FINALIZE
141
#define CYTHON_USE_TP_FINALIZE 0
142
#undef CYTHON_USE_DICT_VERSIONS
143
#define CYTHON_USE_DICT_VERSIONS 0
144
#undef CYTHON_USE_EXC_INFO_STACK
145
#define CYTHON_USE_EXC_INFO_STACK 0
146
#ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
147
#define CYTHON_UPDATE_DESCRIPTOR_DOC 0
148
#endif
149
#elif defined(PY_NOGIL)
150
#define CYTHON_COMPILING_IN_PYPY 0
151
#define CYTHON_COMPILING_IN_PYSTON 0
152
#define CYTHON_COMPILING_IN_CPYTHON 0
153
#define CYTHON_COMPILING_IN_NOGIL 1
154
#ifndef CYTHON_USE_TYPE_SLOTS
155
#define CYTHON_USE_TYPE_SLOTS 1
156
#endif
157
#undef CYTHON_USE_PYTYPE_LOOKUP
158
#define CYTHON_USE_PYTYPE_LOOKUP 0
159
#ifndef CYTHON_USE_ASYNC_SLOTS
160
#define CYTHON_USE_ASYNC_SLOTS 1
161
#endif
162
#undef CYTHON_USE_PYLIST_INTERNALS
163
#define CYTHON_USE_PYLIST_INTERNALS 0
164
#ifndef CYTHON_USE_UNICODE_INTERNALS
165
#define CYTHON_USE_UNICODE_INTERNALS 1
166
#endif
167
#undef CYTHON_USE_UNICODE_WRITER
168
#define CYTHON_USE_UNICODE_WRITER 0
169
#undef CYTHON_USE_PYLONG_INTERNALS
170
#define CYTHON_USE_PYLONG_INTERNALS 0
171
#ifndef CYTHON_AVOID_BORROWED_REFS
172
#define CYTHON_AVOID_BORROWED_REFS 0
173
#endif
174
#ifndef CYTHON_ASSUME_SAFE_MACROS
175
#define CYTHON_ASSUME_SAFE_MACROS 1
176
#endif
177
#ifndef CYTHON_UNPACK_METHODS
178
#define CYTHON_UNPACK_METHODS 1
179
#endif
180
#undef CYTHON_FAST_THREAD_STATE
181
#define CYTHON_FAST_THREAD_STATE 0
182
#undef CYTHON_FAST_PYCALL
183
#define CYTHON_FAST_PYCALL 0
184
#ifndef CYTHON_PEP489_MULTI_PHASE_INIT
185
#define CYTHON_PEP489_MULTI_PHASE_INIT 1
186
#endif
187
#ifndef CYTHON_USE_TP_FINALIZE
188
#define CYTHON_USE_TP_FINALIZE 1
189
#endif
190
#undef CYTHON_USE_DICT_VERSIONS
191
#define CYTHON_USE_DICT_VERSIONS 0
192
#undef CYTHON_USE_EXC_INFO_STACK
193
#define CYTHON_USE_EXC_INFO_STACK 0
194
#else
195
#define CYTHON_COMPILING_IN_PYPY 0
196
#define CYTHON_COMPILING_IN_PYSTON 0
197
#define CYTHON_COMPILING_IN_CPYTHON 1
198
#define CYTHON_COMPILING_IN_NOGIL 0
199
#ifndef CYTHON_USE_TYPE_SLOTS
200
#define CYTHON_USE_TYPE_SLOTS 1
201
#endif
202
#if PY_VERSION_HEX < 0x02070000
203
#undef CYTHON_USE_PYTYPE_LOOKUP
204
#define CYTHON_USE_PYTYPE_LOOKUP 0
205
#elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
206
#define CYTHON_USE_PYTYPE_LOOKUP 1
207
#endif
208
#if PY_MAJOR_VERSION < 3
209
#undef CYTHON_USE_ASYNC_SLOTS
210
#define CYTHON_USE_ASYNC_SLOTS 0
211
#elif !defined(CYTHON_USE_ASYNC_SLOTS)
212
#define CYTHON_USE_ASYNC_SLOTS 1
213
#endif
214
#if PY_VERSION_HEX < 0x02070000
215
#undef CYTHON_USE_PYLONG_INTERNALS
216
#define CYTHON_USE_PYLONG_INTERNALS 0
217
#elif !defined(CYTHON_USE_PYLONG_INTERNALS)
218
#define CYTHON_USE_PYLONG_INTERNALS 1
219
#endif
220
#ifndef CYTHON_USE_PYLIST_INTERNALS
221
#define CYTHON_USE_PYLIST_INTERNALS 1
222
#endif
223
#ifndef CYTHON_USE_UNICODE_INTERNALS
224
#define CYTHON_USE_UNICODE_INTERNALS 1
225
#endif
226
#if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2
227
#undef CYTHON_USE_UNICODE_WRITER
228
#define CYTHON_USE_UNICODE_WRITER 0
229
#elif !defined(CYTHON_USE_UNICODE_WRITER)
230
#define CYTHON_USE_UNICODE_WRITER 1
231
#endif
232
#ifndef CYTHON_AVOID_BORROWED_REFS
233
#define CYTHON_AVOID_BORROWED_REFS 0
234
#endif
235
#ifndef CYTHON_ASSUME_SAFE_MACROS
236
#define CYTHON_ASSUME_SAFE_MACROS 1
237
#endif
238
#ifndef CYTHON_UNPACK_METHODS
239
#define CYTHON_UNPACK_METHODS 1
240
#endif
241
#if PY_VERSION_HEX >= 0x030B00A4
242
#undef CYTHON_FAST_THREAD_STATE
243
#define CYTHON_FAST_THREAD_STATE 0
244
#elif !defined(CYTHON_FAST_THREAD_STATE)
245
#define CYTHON_FAST_THREAD_STATE 1
246
#endif
247
#ifndef CYTHON_FAST_PYCALL
248
#define CYTHON_FAST_PYCALL (PY_VERSION_HEX < 0x030A0000)
249
#endif
250
#ifndef CYTHON_PEP489_MULTI_PHASE_INIT
251
#define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
252
#endif
253
#ifndef CYTHON_USE_TP_FINALIZE
254
#define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
255
#endif
256
#ifndef CYTHON_USE_DICT_VERSIONS
257
#define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1)
258
#endif
259
#if PY_VERSION_HEX >= 0x030B00A4
260
#undef CYTHON_USE_EXC_INFO_STACK
261
#define CYTHON_USE_EXC_INFO_STACK 0
262
#elif !defined(CYTHON_USE_EXC_INFO_STACK)
263
#define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
264
#endif
265
#ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
266
#define CYTHON_UPDATE_DESCRIPTOR_DOC 1
267
#endif
268
#endif
269
#if !defined(CYTHON_FAST_PYCCALL)
270
#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
271
#endif
272
#if CYTHON_USE_PYLONG_INTERNALS
273
#if PY_MAJOR_VERSION < 3
274
#include "longintrepr.h"
275
#endif
276
#undef SHIFT
277
#undef BASE
278
#undef MASK
279
#ifdef SIZEOF_VOID_P
280
enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
281
#endif
282
#endif
283
#ifndef __has_attribute
284
#define __has_attribute(x) 0
285
#endif
286
#ifndef __has_cpp_attribute
287
#define __has_cpp_attribute(x) 0
288
#endif
289
#ifndef CYTHON_RESTRICT
290
#if defined(__GNUC__)
291
#define CYTHON_RESTRICT __restrict__
292
#elif defined(_MSC_VER) && _MSC_VER >= 1400
293
#define CYTHON_RESTRICT __restrict
294
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
295
#define CYTHON_RESTRICT restrict
296
#else
297
#define CYTHON_RESTRICT
298
#endif
299
#endif
300
#ifndef CYTHON_UNUSED
301
# if defined(__GNUC__)
302
# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
303
# define CYTHON_UNUSED __attribute__ ((__unused__))
304
# else
305
# define CYTHON_UNUSED
306
# endif
307
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
308
# define CYTHON_UNUSED __attribute__ ((__unused__))
309
# else
310
# define CYTHON_UNUSED
311
# endif
312
#endif
313
#ifndef CYTHON_MAYBE_UNUSED_VAR
314
# if defined(__cplusplus)
315
template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
316
# else
317
# define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
318
# endif
319
#endif
320
#ifndef CYTHON_NCP_UNUSED
321
# if CYTHON_COMPILING_IN_CPYTHON
322
# define CYTHON_NCP_UNUSED
323
# else
324
# define CYTHON_NCP_UNUSED CYTHON_UNUSED
325
# endif
326
#endif
327
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
328
#ifdef _MSC_VER
329
#ifndef _MSC_STDINT_H_
330
#if _MSC_VER < 1300
331
typedef unsigned char uint8_t;
332
typedef unsigned int uint32_t;
333
#else
334
typedef unsigned __int8 uint8_t;
335
typedef unsigned __int32 uint32_t;
336
#endif
337
#endif
338
#else
339
#include <stdint.h>
340
#endif
341
#ifndef CYTHON_FALLTHROUGH
342
#if defined(__cplusplus) && __cplusplus >= 201103L
343
#if __has_cpp_attribute(fallthrough)
344
#define CYTHON_FALLTHROUGH [[fallthrough]]
345
#elif __has_cpp_attribute(clang::fallthrough)
346
#define CYTHON_FALLTHROUGH [[clang::fallthrough]]
347
#elif __has_cpp_attribute(gnu::fallthrough)
348
#define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
349
#endif
350
#endif
351
#ifndef CYTHON_FALLTHROUGH
352
#if __has_attribute(fallthrough)
353
#define CYTHON_FALLTHROUGH __attribute__((fallthrough))
354
#else
355
#define CYTHON_FALLTHROUGH
356
#endif
357
#endif
358
#if defined(__clang__ ) && defined(__apple_build_version__)
359
#if __apple_build_version__ < 7000000
360
#undef CYTHON_FALLTHROUGH
361
#define CYTHON_FALLTHROUGH
362
#endif
363
#endif
364
#endif
365
366
#ifndef CYTHON_INLINE
367
#if defined(__clang__)
368
#define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
369
#elif defined(__GNUC__)
370
#define CYTHON_INLINE __inline__
371
#elif defined(_MSC_VER)
372
#define CYTHON_INLINE __inline
373
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
374
#define CYTHON_INLINE inline
375
#else
376
#define CYTHON_INLINE
377
#endif
378
#endif
379
380
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
381
#define Py_OptimizeFlag 0
382
#endif
383
#define __PYX_BUILD_PY_SSIZE_T "n"
384
#define CYTHON_FORMAT_SSIZE_T "z"
385
#if PY_MAJOR_VERSION < 3
386
#define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
387
#define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
388
PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
389
#define __Pyx_DefaultClassType PyClass_Type
390
#else
391
#define __Pyx_BUILTIN_MODULE_NAME "builtins"
392
#define __Pyx_DefaultClassType PyType_Type
393
#if PY_VERSION_HEX >= 0x030B00A1
394
static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int k, int l, int s, int f,
395
PyObject *code, PyObject *c, PyObject* n, PyObject *v,
396
PyObject *fv, PyObject *cell, PyObject* fn,
397
PyObject *name, int fline, PyObject *lnos) {
398
PyObject *kwds=NULL, *argcount=NULL, *posonlyargcount=NULL, *kwonlyargcount=NULL;
399
PyObject *nlocals=NULL, *stacksize=NULL, *flags=NULL, *replace=NULL, *call_result=NULL, *empty=NULL;
400
const char *fn_cstr=NULL;
401
const char *name_cstr=NULL;
402
PyCodeObject* co=NULL;
403
PyObject *type, *value, *traceback;
404
PyErr_Fetch(&type, &value, &traceback);
405
if (!(kwds=PyDict_New())) goto end;
406
if (!(argcount=PyLong_FromLong(a))) goto end;
407
if (PyDict_SetItemString(kwds, "co_argcount", argcount) != 0) goto end;
408
if (!(posonlyargcount=PyLong_FromLong(0))) goto end;
409
if (PyDict_SetItemString(kwds, "co_posonlyargcount", posonlyargcount) != 0) goto end;
410
if (!(kwonlyargcount=PyLong_FromLong(k))) goto end;
411
if (PyDict_SetItemString(kwds, "co_kwonlyargcount", kwonlyargcount) != 0) goto end;
412
if (!(nlocals=PyLong_FromLong(l))) goto end;
413
if (PyDict_SetItemString(kwds, "co_nlocals", nlocals) != 0) goto end;
414
if (!(stacksize=PyLong_FromLong(s))) goto end;
415
if (PyDict_SetItemString(kwds, "co_stacksize", stacksize) != 0) goto end;
416
if (!(flags=PyLong_FromLong(f))) goto end;
417
if (PyDict_SetItemString(kwds, "co_flags", flags) != 0) goto end;
418
if (PyDict_SetItemString(kwds, "co_code", code) != 0) goto end;
419
if (PyDict_SetItemString(kwds, "co_consts", c) != 0) goto end;
420
if (PyDict_SetItemString(kwds, "co_names", n) != 0) goto end;
421
if (PyDict_SetItemString(kwds, "co_varnames", v) != 0) goto end;
422
if (PyDict_SetItemString(kwds, "co_freevars", fv) != 0) goto end;
423
if (PyDict_SetItemString(kwds, "co_cellvars", cell) != 0) goto end;
424
if (PyDict_SetItemString(kwds, "co_linetable", lnos) != 0) goto end;
425
if (!(fn_cstr=PyUnicode_AsUTF8AndSize(fn, NULL))) goto end;
426
if (!(name_cstr=PyUnicode_AsUTF8AndSize(name, NULL))) goto end;
427
if (!(co = PyCode_NewEmpty(fn_cstr, name_cstr, fline))) goto end;
428
if (!(replace = PyObject_GetAttrString((PyObject*)co, "replace"))) goto cleanup_code_too;
429
if (!(empty = PyTuple_New(0))) goto cleanup_code_too; // unfortunately __pyx_empty_tuple isn't available here
430
if (!(call_result = PyObject_Call(replace, empty, kwds))) goto cleanup_code_too;
431
Py_XDECREF((PyObject*)co);
432
co = (PyCodeObject*)call_result;
433
call_result = NULL;
434
if (0) {
435
cleanup_code_too:
436
Py_XDECREF((PyObject*)co);
437
co = NULL;
438
}
439
end:
440
Py_XDECREF(kwds);
441
Py_XDECREF(argcount);
442
Py_XDECREF(posonlyargcount);
443
Py_XDECREF(kwonlyargcount);
444
Py_XDECREF(nlocals);
445
Py_XDECREF(stacksize);
446
Py_XDECREF(replace);
447
Py_XDECREF(call_result);
448
Py_XDECREF(empty);
449
if (type) {
450
PyErr_Restore(type, value, traceback);
451
}
452
return co;
453
}
454
#else
455
#define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
456
PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
457
#endif
458
#define __Pyx_DefaultClassType PyType_Type
459
#endif
460
#ifndef Py_TPFLAGS_CHECKTYPES
461
#define Py_TPFLAGS_CHECKTYPES 0
462
#endif
463
#ifndef Py_TPFLAGS_HAVE_INDEX
464
#define Py_TPFLAGS_HAVE_INDEX 0
465
#endif
466
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
467
#define Py_TPFLAGS_HAVE_NEWBUFFER 0
468
#endif
469
#ifndef Py_TPFLAGS_HAVE_FINALIZE
470
#define Py_TPFLAGS_HAVE_FINALIZE 0
471
#endif
472
#ifndef METH_STACKLESS
473
#define METH_STACKLESS 0
474
#endif
475
#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
476
#ifndef METH_FASTCALL
477
#define METH_FASTCALL 0x80
478
#endif
479
typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
480
typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
481
Py_ssize_t nargs, PyObject *kwnames);
482
#else
483
#define __Pyx_PyCFunctionFast _PyCFunctionFast
484
#define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
485
#endif
486
#if CYTHON_FAST_PYCCALL
487
#define __Pyx_PyFastCFunction_Check(func)\
488
((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)))))
489
#else
490
#define __Pyx_PyFastCFunction_Check(func) 0
491
#endif
492
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
493
#define PyObject_Malloc(s) PyMem_Malloc(s)
494
#define PyObject_Free(p) PyMem_Free(p)
495
#define PyObject_Realloc(p) PyMem_Realloc(p)
496
#endif
497
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
498
#define PyMem_RawMalloc(n) PyMem_Malloc(n)
499
#define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n)
500
#define PyMem_RawFree(p) PyMem_Free(p)
501
#endif
502
#if CYTHON_COMPILING_IN_PYSTON
503
#define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)
504
#define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
505
#else
506
#define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0)
507
#define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
508
#endif
509
#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
510
#define __Pyx_PyThreadState_Current PyThreadState_GET()
511
#elif PY_VERSION_HEX >= 0x03060000
512
#define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
513
#elif PY_VERSION_HEX >= 0x03000000
514
#define __Pyx_PyThreadState_Current PyThreadState_GET()
515
#else
516
#define __Pyx_PyThreadState_Current _PyThreadState_Current
517
#endif
518
#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
519
#include "pythread.h"
520
#define Py_tss_NEEDS_INIT 0
521
typedef int Py_tss_t;
522
static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
523
*key = PyThread_create_key();
524
return 0;
525
}
526
static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
527
Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
528
*key = Py_tss_NEEDS_INIT;
529
return key;
530
}
531
static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
532
PyObject_Free(key);
533
}
534
static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
535
return *key != Py_tss_NEEDS_INIT;
536
}
537
static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
538
PyThread_delete_key(*key);
539
*key = Py_tss_NEEDS_INIT;
540
}
541
static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
542
return PyThread_set_key_value(*key, value);
543
}
544
static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
545
return PyThread_get_key_value(*key);
546
}
547
#endif
548
#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
549
#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
550
#else
551
#define __Pyx_PyDict_NewPresized(n) PyDict_New()
552
#endif
553
#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
554
#define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
555
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
556
#else
557
#define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
558
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
559
#endif
560
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
561
#define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
562
#else
563
#define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name)
564
#endif
565
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
566
#define CYTHON_PEP393_ENABLED 1
567
#if defined(PyUnicode_IS_READY)
568
#define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\
569
0 : _PyUnicode_Ready((PyObject *)(op)))
570
#else
571
#define __Pyx_PyUnicode_READY(op) (0)
572
#endif
573
#define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
574
#define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
575
#define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u)
576
#define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
577
#define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
578
#define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
579
#define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch)
580
#if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
581
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000
582
#define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length))
583
#else
584
#define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
585
#endif
586
#else
587
#define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u))
588
#endif
589
#else
590
#define CYTHON_PEP393_ENABLED 0
591
#define PyUnicode_1BYTE_KIND 1
592
#define PyUnicode_2BYTE_KIND 2
593
#define PyUnicode_4BYTE_KIND 4
594
#define __Pyx_PyUnicode_READY(op) (0)
595
#define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
596
#define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
597
#define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
598
#define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE))
599
#define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
600
#define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
601
#define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
602
#define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u))
603
#endif
604
#if CYTHON_COMPILING_IN_PYPY
605
#define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b)
606
#define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b)
607
#else
608
#define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b)
609
#define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
610
PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
611
#endif
612
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
613
#define PyUnicode_Contains(u, s) PySequence_Contains(u, s)
614
#endif
615
#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
616
#define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type)
617
#endif
618
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
619
#define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
620
#endif
621
#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))
622
#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
623
#if PY_MAJOR_VERSION >= 3
624
#define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b)
625
#else
626
#define __Pyx_PyString_Format(a, b) PyString_Format(a, b)
627
#endif
628
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
629
#define PyObject_ASCII(o) PyObject_Repr(o)
630
#endif
631
#if PY_MAJOR_VERSION >= 3
632
#define PyBaseString_Type PyUnicode_Type
633
#define PyStringObject PyUnicodeObject
634
#define PyString_Type PyUnicode_Type
635
#define PyString_Check PyUnicode_Check
636
#define PyString_CheckExact PyUnicode_CheckExact
637
#ifndef PyObject_Unicode
638
#define PyObject_Unicode PyObject_Str
639
#endif
640
#endif
641
#if PY_MAJOR_VERSION >= 3
642
#define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
643
#define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
644
#else
645
#define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
646
#define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
647
#endif
648
#ifndef PySet_CheckExact
649
#define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
650
#endif
651
#if PY_VERSION_HEX >= 0x030900A4
652
#define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
653
#define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
654
#else
655
#define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
656
#define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
657
#endif
658
#if CYTHON_ASSUME_SAFE_MACROS
659
#define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq)
660
#else
661
#define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq)
662
#endif
663
#if PY_MAJOR_VERSION >= 3
664
#define PyIntObject PyLongObject
665
#define PyInt_Type PyLong_Type
666
#define PyInt_Check(op) PyLong_Check(op)
667
#define PyInt_CheckExact(op) PyLong_CheckExact(op)
668
#define PyInt_FromString PyLong_FromString
669
#define PyInt_FromUnicode PyLong_FromUnicode
670
#define PyInt_FromLong PyLong_FromLong
671
#define PyInt_FromSize_t PyLong_FromSize_t
672
#define PyInt_FromSsize_t PyLong_FromSsize_t
673
#define PyInt_AsLong PyLong_AsLong
674
#define PyInt_AS_LONG PyLong_AS_LONG
675
#define PyInt_AsSsize_t PyLong_AsSsize_t
676
#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
677
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
678
#define PyNumber_Int PyNumber_Long
679
#endif
680
#if PY_MAJOR_VERSION >= 3
681
#define PyBoolObject PyLongObject
682
#endif
683
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
684
#ifndef PyUnicode_InternFromString
685
#define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
686
#endif
687
#endif
688
#if PY_VERSION_HEX < 0x030200A4
689
typedef long Py_hash_t;
690
#define __Pyx_PyInt_FromHash_t PyInt_FromLong
691
#define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsHash_t
692
#else
693
#define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
694
#define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsSsize_t
695
#endif
696
#if PY_MAJOR_VERSION >= 3
697
#define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
698
#else
699
#define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
700
#endif
701
#if CYTHON_USE_ASYNC_SLOTS
702
#if PY_VERSION_HEX >= 0x030500B1
703
#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
704
#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
705
#else
706
#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
707
#endif
708
#else
709
#define __Pyx_PyType_AsAsync(obj) NULL
710
#endif
711
#ifndef __Pyx_PyAsyncMethodsStruct
712
typedef struct {
713
unaryfunc am_await;
714
unaryfunc am_aiter;
715
unaryfunc am_anext;
716
} __Pyx_PyAsyncMethodsStruct;
717
#endif
718
719
#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)
720
#if !defined(_USE_MATH_DEFINES)
721
#define _USE_MATH_DEFINES
722
#endif
723
#endif
724
#include <math.h>
725
#ifdef NAN
726
#define __PYX_NAN() ((float) NAN)
727
#else
728
static CYTHON_INLINE float __PYX_NAN() {
729
float value;
730
memset(&value, 0xFF, sizeof(value));
731
return value;
732
}
733
#endif
734
#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
735
#define __Pyx_truncl trunc
736
#else
737
#define __Pyx_truncl truncl
738
#endif
739
740
#define __PYX_MARK_ERR_POS(f_index, lineno) \
741
{ __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
742
#define __PYX_ERR(f_index, lineno, Ln_error) \
743
{ __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }
744
745
#ifndef __PYX_EXTERN_C
746
#ifdef __cplusplus
747
#define __PYX_EXTERN_C extern "C"
748
#else
749
#define __PYX_EXTERN_C extern
750
#endif
751
#endif
752
753
#define __PYX_HAVE__nt
754
#define __PYX_HAVE_API__nt
755
/* Early includes */
756
#ifdef _OPENMP
757
#include <omp.h>
758
#endif /* _OPENMP */
759
760
#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
761
#define CYTHON_WITHOUT_ASSERTIONS
762
#endif
763
764
typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
765
const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
766
767
#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
768
#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0
769
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
770
#define __PYX_DEFAULT_STRING_ENCODING ""
771
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
772
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
773
#define __Pyx_uchar_cast(c) ((unsigned char)c)
774
#define __Pyx_long_cast(x) ((long)x)
775
#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\
776
(sizeof(type) < sizeof(Py_ssize_t)) ||\
777
(sizeof(type) > sizeof(Py_ssize_t) &&\
778
likely(v < (type)PY_SSIZE_T_MAX ||\
779
v == (type)PY_SSIZE_T_MAX) &&\
780
(!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
781
v == (type)PY_SSIZE_T_MIN))) ||\
782
(sizeof(type) == sizeof(Py_ssize_t) &&\
783
(is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
784
v == (type)PY_SSIZE_T_MAX))) )
785
static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
786
return (size_t) i < (size_t) limit;
787
}
788
#if defined (__cplusplus) && __cplusplus >= 201103L
789
#include <cstdlib>
790
#define __Pyx_sst_abs(value) std::abs(value)
791
#elif SIZEOF_INT >= SIZEOF_SIZE_T
792
#define __Pyx_sst_abs(value) abs(value)
793
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
794
#define __Pyx_sst_abs(value) labs(value)
795
#elif defined (_MSC_VER)
796
#define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
797
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
798
#define __Pyx_sst_abs(value) llabs(value)
799
#elif defined (__GNUC__)
800
#define __Pyx_sst_abs(value) __builtin_llabs(value)
801
#else
802
#define __Pyx_sst_abs(value) ((value<0) ? -value : value)
803
#endif
804
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
805
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
806
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
807
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
808
#define __Pyx_PyBytes_FromString PyBytes_FromString
809
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
810
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
811
#if PY_MAJOR_VERSION < 3
812
#define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString
813
#define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
814
#else
815
#define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString
816
#define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
817
#endif
818
#define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s))
819
#define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s))
820
#define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s))
821
#define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s))
822
#define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s))
823
#define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s))
824
#define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s))
825
#define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s))
826
#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s))
827
#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s))
828
#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s))
829
#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
830
#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
831
#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
832
#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s)
833
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
834
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
835
const Py_UNICODE *u_end = u;
836
while (*u_end++) ;
837
return (size_t)(u_end - u - 1);
838
}
839
#define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
840
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
841
#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
842
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
843
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
844
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
845
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
846
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
847
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
848
#define __Pyx_PySequence_Tuple(obj)\
849
(likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
850
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
851
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
852
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*);
853
#if CYTHON_ASSUME_SAFE_MACROS
854
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
855
#else
856
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
857
#endif
858
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
859
#if PY_MAJOR_VERSION >= 3
860
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
861
#else
862
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
863
#endif
864
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
865
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
866
static int __Pyx_sys_getdefaultencoding_not_ascii;
867
static int __Pyx_init_sys_getdefaultencoding_params(void) {
868
PyObject* sys;
869
PyObject* default_encoding = NULL;
870
PyObject* ascii_chars_u = NULL;
871
PyObject* ascii_chars_b = NULL;
872
const char* default_encoding_c;
873
sys = PyImport_ImportModule("sys");
874
if (!sys) goto bad;
875
default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
876
Py_DECREF(sys);
877
if (!default_encoding) goto bad;
878
default_encoding_c = PyBytes_AsString(default_encoding);
879
if (!default_encoding_c) goto bad;
880
if (strcmp(default_encoding_c, "ascii") == 0) {
881
__Pyx_sys_getdefaultencoding_not_ascii = 0;
882
} else {
883
char ascii_chars[128];
884
int c;
885
for (c = 0; c < 128; c++) {
886
ascii_chars[c] = c;
887
}
888
__Pyx_sys_getdefaultencoding_not_ascii = 1;
889
ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
890
if (!ascii_chars_u) goto bad;
891
ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
892
if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
893
PyErr_Format(
894
PyExc_ValueError,
895
"This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
896
default_encoding_c);
897
goto bad;
898
}
899
Py_DECREF(ascii_chars_u);
900
Py_DECREF(ascii_chars_b);
901
}
902
Py_DECREF(default_encoding);
903
return 0;
904
bad:
905
Py_XDECREF(default_encoding);
906
Py_XDECREF(ascii_chars_u);
907
Py_XDECREF(ascii_chars_b);
908
return -1;
909
}
910
#endif
911
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
912
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
913
#else
914
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
915
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
916
static char* __PYX_DEFAULT_STRING_ENCODING;
917
static int __Pyx_init_sys_getdefaultencoding_params(void) {
918
PyObject* sys;
919
PyObject* default_encoding = NULL;
920
char* default_encoding_c;
921
sys = PyImport_ImportModule("sys");
922
if (!sys) goto bad;
923
default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
924
Py_DECREF(sys);
925
if (!default_encoding) goto bad;
926
default_encoding_c = PyBytes_AsString(default_encoding);
927
if (!default_encoding_c) goto bad;
928
__PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
929
if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
930
strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
931
Py_DECREF(default_encoding);
932
return 0;
933
bad:
934
Py_XDECREF(default_encoding);
935
return -1;
936
}
937
#endif
938
#endif
939
940
941
/* Test for GCC > 2.95 */
942
#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
943
#define likely(x) __builtin_expect(!!(x), 1)
944
#define unlikely(x) __builtin_expect(!!(x), 0)
945
#else /* !__GNUC__ or GCC < 2.95 */
946
#define likely(x) (x)
947
#define unlikely(x) (x)
948
#endif /* __GNUC__ */
949
static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
950
951
static PyObject *__pyx_m = NULL;
952
static PyObject *__pyx_d;
953
static PyObject *__pyx_b;
954
static PyObject *__pyx_cython_runtime = NULL;
955
static PyObject *__pyx_empty_tuple;
956
static PyObject *__pyx_empty_bytes;
957
static PyObject *__pyx_empty_unicode;
958
static int __pyx_lineno;
959
static int __pyx_clineno = 0;
960
static const char * __pyx_cfilenm= __FILE__;
961
static const char *__pyx_filename;
962
963
964
static const char *__pyx_f[] = {
965
"nt.pyx",
966
};
967
968
/*--- Type declarations ---*/
969
970
/* --- Runtime support code (head) --- */
971
/* Refnanny.proto */
972
#ifndef CYTHON_REFNANNY
973
#define CYTHON_REFNANNY 0
974
#endif
975
#if CYTHON_REFNANNY
976
typedef struct {
977
void (*INCREF)(void*, PyObject*, int);
978
void (*DECREF)(void*, PyObject*, int);
979
void (*GOTREF)(void*, PyObject*, int);
980
void (*GIVEREF)(void*, PyObject*, int);
981
void* (*SetupContext)(const char*, int, const char*);
982
void (*FinishContext)(void**);
983
} __Pyx_RefNannyAPIStruct;
984
static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
985
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
986
#define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
987
#ifdef WITH_THREAD
988
#define __Pyx_RefNannySetupContext(name, acquire_gil)\
989
if (acquire_gil) {\
990
PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
991
__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
992
PyGILState_Release(__pyx_gilstate_save);\
993
} else {\
994
__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
995
}
996
#else
997
#define __Pyx_RefNannySetupContext(name, acquire_gil)\
998
__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
999
#endif
1000
#define __Pyx_RefNannyFinishContext()\
1001
__Pyx_RefNanny->FinishContext(&__pyx_refnanny)
1002
#define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
1003
#define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
1004
#define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
1005
#define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
1006
#define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
1007
#define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
1008
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
1009
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
1010
#else
1011
#define __Pyx_RefNannyDeclarations
1012
#define __Pyx_RefNannySetupContext(name, acquire_gil)
1013
#define __Pyx_RefNannyFinishContext()
1014
#define __Pyx_INCREF(r) Py_INCREF(r)
1015
#define __Pyx_DECREF(r) Py_DECREF(r)
1016
#define __Pyx_GOTREF(r)
1017
#define __Pyx_GIVEREF(r)
1018
#define __Pyx_XINCREF(r) Py_XINCREF(r)
1019
#define __Pyx_XDECREF(r) Py_XDECREF(r)
1020
#define __Pyx_XGOTREF(r)
1021
#define __Pyx_XGIVEREF(r)
1022
#endif
1023
#define __Pyx_XDECREF_SET(r, v) do {\
1024
PyObject *tmp = (PyObject *) r;\
1025
r = v; __Pyx_XDECREF(tmp);\
1026
} while (0)
1027
#define __Pyx_DECREF_SET(r, v) do {\
1028
PyObject *tmp = (PyObject *) r;\
1029
r = v; __Pyx_DECREF(tmp);\
1030
} while (0)
1031
#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
1032
#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
1033
1034
/* PyObjectGetAttrStr.proto */
1035
#if CYTHON_USE_TYPE_SLOTS
1036
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
1037
#else
1038
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
1039
#endif
1040
1041
/* GetBuiltinName.proto */
1042
static PyObject *__Pyx_GetBuiltinName(PyObject *name);
1043
1044
/* ModInt[int].proto */
1045
static CYTHON_INLINE int __Pyx_mod_int(int, int);
1046
1047
/* PyThreadStateGet.proto */
1048
#if CYTHON_FAST_THREAD_STATE
1049
#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate;
1050
#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current;
1051
#define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type
1052
#else
1053
#define __Pyx_PyThreadState_declare
1054
#define __Pyx_PyThreadState_assign
1055
#define __Pyx_PyErr_Occurred() PyErr_Occurred()
1056
#endif
1057
1058
/* PyErrFetchRestore.proto */
1059
#if CYTHON_FAST_THREAD_STATE
1060
#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
1061
#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
1062
#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
1063
#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
1064
#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
1065
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
1066
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
1067
#if CYTHON_COMPILING_IN_CPYTHON
1068
#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
1069
#else
1070
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
1071
#endif
1072
#else
1073
#define __Pyx_PyErr_Clear() PyErr_Clear()
1074
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
1075
#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
1076
#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
1077
#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb)
1078
#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb)
1079
#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
1080
#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb)
1081
#endif
1082
1083
/* WriteUnraisableException.proto */
1084
static void __Pyx_WriteUnraisable(const char *name, int clineno,
1085
int lineno, const char *filename,
1086
int full_traceback, int nogil);
1087
1088
/* RaiseArgTupleInvalid.proto */
1089
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
1090
Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
1091
1092
/* RaiseDoubleKeywords.proto */
1093
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
1094
1095
/* ParseKeywords.proto */
1096
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
1097
PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
1098
const char* function_name);
1099
1100
/* DivInt[int].proto */
1101
static CYTHON_INLINE int __Pyx_div_int(int, int);
1102
1103
/* UnaryNegOverflows.proto */
1104
#define UNARY_NEG_WOULD_OVERFLOW(x)\
1105
(((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x)))
1106
1107
/* RaiseException.proto */
1108
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
1109
1110
/* PyIntBinop.proto */
1111
#if !CYTHON_COMPILING_IN_PYPY
1112
static PyObject* __Pyx_PyInt_RemainderObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
1113
#else
1114
#define __Pyx_PyInt_RemainderObjC(op1, op2, intval, inplace, zerodivision_check)\
1115
(inplace ? PyNumber_InPlaceRemainder(op1, op2) : PyNumber_Remainder(op1, op2))
1116
#endif
1117
1118
/* PyIntBinop.proto */
1119
#if !CYTHON_COMPILING_IN_PYPY
1120
static PyObject* __Pyx_PyInt_SubtractCObj(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
1121
#else
1122
#define __Pyx_PyInt_SubtractCObj(op1, op2, intval, inplace, zerodivision_check)\
1123
(inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
1124
#endif
1125
1126
/* PyIntCompare.proto */
1127
static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, long inplace);
1128
1129
/* PyDictVersioning.proto */
1130
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
1131
#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1)
1132
#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag)
1133
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
1134
(version_var) = __PYX_GET_DICT_VERSION(dict);\
1135
(cache_var) = (value);
1136
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
1137
static PY_UINT64_T __pyx_dict_version = 0;\
1138
static PyObject *__pyx_dict_cached_value = NULL;\
1139
if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
1140
(VAR) = __pyx_dict_cached_value;\
1141
} else {\
1142
(VAR) = __pyx_dict_cached_value = (LOOKUP);\
1143
__pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
1144
}\
1145
}
1146
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj);
1147
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj);
1148
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version);
1149
#else
1150
#define __PYX_GET_DICT_VERSION(dict) (0)
1151
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
1152
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP);
1153
#endif
1154
1155
/* GetModuleGlobalName.proto */
1156
#if CYTHON_USE_DICT_VERSIONS
1157
#define __Pyx_GetModuleGlobalName(var, name) {\
1158
static PY_UINT64_T __pyx_dict_version = 0;\
1159
static PyObject *__pyx_dict_cached_value = NULL;\
1160
(var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\
1161
(likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\
1162
__Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
1163
}
1164
#define __Pyx_GetModuleGlobalNameUncached(var, name) {\
1165
PY_UINT64_T __pyx_dict_version;\
1166
PyObject *__pyx_dict_cached_value;\
1167
(var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
1168
}
1169
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value);
1170
#else
1171
#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name)
1172
#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name)
1173
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name);
1174
#endif
1175
1176
/* PyCFunctionFastCall.proto */
1177
#if CYTHON_FAST_PYCCALL
1178
static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
1179
#else
1180
#define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL)
1181
#endif
1182
1183
/* PyFunctionFastCall.proto */
1184
#if CYTHON_FAST_PYCALL
1185
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
1186
__Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
1187
#if 1 || PY_VERSION_HEX < 0x030600B1
1188
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs);
1189
#else
1190
#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
1191
#endif
1192
#define __Pyx_BUILD_ASSERT_EXPR(cond)\
1193
(sizeof(char [1 - 2*!(cond)]) - 1)
1194
#ifndef Py_MEMBER_SIZE
1195
#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
1196
#endif
1197
#if CYTHON_FAST_PYCALL
1198
static size_t __pyx_pyframe_localsplus_offset = 0;
1199
#include "frameobject.h"
1200
#if PY_VERSION_HEX >= 0x030b00a6
1201
#ifndef Py_BUILD_CORE
1202
#define Py_BUILD_CORE 1
1203
#endif
1204
#include "internal/pycore_frame.h"
1205
#endif
1206
#define __Pxy_PyFrame_Initialize_Offsets()\
1207
((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\
1208
(void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
1209
#define __Pyx_PyFrame_GetLocalsplus(frame)\
1210
(assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
1211
#endif // CYTHON_FAST_PYCALL
1212
#endif
1213
1214
/* PyObjectCall.proto */
1215
#if CYTHON_COMPILING_IN_CPYTHON
1216
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
1217
#else
1218
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
1219
#endif
1220
1221
/* PyObjectCall2Args.proto */
1222
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2);
1223
1224
/* PyObjectCallMethO.proto */
1225
#if CYTHON_COMPILING_IN_CPYTHON
1226
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
1227
#endif
1228
1229
/* PyObjectCallOneArg.proto */
1230
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
1231
1232
/* PyIntCompare.proto */
1233
static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, long intval, long inplace);
1234
1235
/* GetItemInt.proto */
1236
#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
1237
(__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
1238
__Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
1239
(is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
1240
__Pyx_GetItemInt_Generic(o, to_py_func(i))))
1241
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
1242
(__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
1243
__Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
1244
(PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
1245
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
1246
int wraparound, int boundscheck);
1247
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
1248
(__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
1249
__Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
1250
(PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
1251
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
1252
int wraparound, int boundscheck);
1253
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
1254
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
1255
int is_list, int wraparound, int boundscheck);
1256
1257
/* ObjectGetItem.proto */
1258
#if CYTHON_USE_TYPE_SLOTS
1259
static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key);
1260
#else
1261
#define __Pyx_PyObject_GetItem(obj, key) PyObject_GetItem(obj, key)
1262
#endif
1263
1264
/* PyIntBinop.proto */
1265
#if !CYTHON_COMPILING_IN_PYPY
1266
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
1267
#else
1268
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\
1269
(inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
1270
#endif
1271
1272
/* Import.proto */
1273
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);
1274
1275
/* ImportFrom.proto */
1276
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);
1277
1278
/* CLineInTraceback.proto */
1279
#ifdef CYTHON_CLINE_IN_TRACEBACK
1280
#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
1281
#else
1282
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
1283
#endif
1284
1285
/* CodeObjectCache.proto */
1286
typedef struct {
1287
PyCodeObject* code_object;
1288
int code_line;
1289
} __Pyx_CodeObjectCacheEntry;
1290
struct __Pyx_CodeObjectCache {
1291
int count;
1292
int max_count;
1293
__Pyx_CodeObjectCacheEntry* entries;
1294
};
1295
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
1296
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
1297
static PyCodeObject *__pyx_find_code_object(int code_line);
1298
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
1299
1300
/* AddTraceback.proto */
1301
static void __Pyx_AddTraceback(const char *funcname, int c_line,
1302
int py_line, const char *filename);
1303
1304
/* GCCDiagnostics.proto */
1305
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
1306
#define __Pyx_HAS_GCC_DIAGNOSTIC
1307
#endif
1308
1309
/* CIntFromPy.proto */
1310
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
1311
1312
/* CIntToPy.proto */
1313
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);
1314
1315
/* CIntToPy.proto */
1316
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
1317
1318
/* CIntFromPy.proto */
1319
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
1320
1321
/* FastTypeChecks.proto */
1322
#if CYTHON_COMPILING_IN_CPYTHON
1323
#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
1324
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
1325
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
1326
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
1327
#else
1328
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
1329
#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
1330
#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
1331
#endif
1332
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
1333
1334
/* CheckBinaryVersion.proto */
1335
static int __Pyx_check_binary_version(void);
1336
1337
/* FunctionExport.proto */
1338
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig);
1339
1340
/* InitStrings.proto */
1341
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
1342
1343
1344
/* Module declarations from 'nt' */
1345
static int __pyx_f_2nt_gcd(int, int, int __pyx_skip_dispatch); /*proto*/
1346
static int __pyx_f_2nt_xgcd_c(int, int, int *, int *); /*proto*/
1347
static int __pyx_f_2nt_inverse_mod(int, int, int __pyx_skip_dispatch); /*proto*/
1348
#define __Pyx_MODULE_NAME "nt"
1349
extern int __pyx_module_is_main_nt;
1350
int __pyx_module_is_main_nt = 0;
1351
1352
/* Implementation of 'nt' */
1353
static PyObject *__pyx_builtin_ZeroDivisionError;
1354
static PyObject *__pyx_builtin_round;
1355
static PyObject *__pyx_builtin_range;
1356
static const char __pyx_k_N[] = "N";
1357
static const char __pyx_k_a[] = "a";
1358
static const char __pyx_k_b[] = "b";
1359
static const char __pyx_k_g[] = "g";
1360
static const char __pyx_k_i[] = "i";
1361
static const char __pyx_k_m[] = "m";
1362
static const char __pyx_k_n[] = "n";
1363
static const char __pyx_k_s[] = "s";
1364
static const char __pyx_k_cx[] = "cx";
1365
static const char __pyx_k_cy[] = "cy";
1366
static const char __pyx_k_nt[] = "nt";
1367
static const char __pyx_k_pi[] = "pi";
1368
static const char __pyx_k_dif[] = "dif";
1369
static const char __pyx_k_main[] = "__main__";
1370
static const char __pyx_k_math[] = "math";
1371
static const char __pyx_k_name[] = "__name__";
1372
static const char __pyx_k_sqrt[] = "sqrt";
1373
static const char __pyx_k_test[] = "__test__";
1374
static const char __pyx_k_xgcd[] = "xgcd";
1375
static const char __pyx_k_Tuple[] = "Tuple";
1376
static const char __pyx_k_bound[] = "bound";
1377
static const char __pyx_k_limit[] = "limit";
1378
static const char __pyx_k_range[] = "range";
1379
static const char __pyx_k_round[] = "round";
1380
static const char __pyx_k_start[] = "start";
1381
static const char __pyx_k_import[] = "__import__";
1382
static const char __pyx_k_nt_pyx[] = "nt.pyx";
1383
static const char __pyx_k_typing[] = "typing";
1384
static const char __pyx_k_is_prime[] = "is_prime";
1385
static const char __pyx_k_trial_division[] = "trial_division";
1386
static const char __pyx_k_ZeroDivisionError[] = "ZeroDivisionError";
1387
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
1388
static PyObject *__pyx_n_s_N;
1389
static PyObject *__pyx_n_s_Tuple;
1390
static PyObject *__pyx_n_s_ZeroDivisionError;
1391
static PyObject *__pyx_n_s_a;
1392
static PyObject *__pyx_n_s_b;
1393
static PyObject *__pyx_n_s_bound;
1394
static PyObject *__pyx_n_s_cline_in_traceback;
1395
static PyObject *__pyx_n_s_cx;
1396
static PyObject *__pyx_n_s_cy;
1397
static PyObject *__pyx_n_s_dif;
1398
static PyObject *__pyx_n_s_g;
1399
static PyObject *__pyx_n_s_i;
1400
static PyObject *__pyx_n_s_import;
1401
static PyObject *__pyx_n_s_is_prime;
1402
static PyObject *__pyx_n_s_limit;
1403
static PyObject *__pyx_n_s_m;
1404
static PyObject *__pyx_n_s_main;
1405
static PyObject *__pyx_n_s_math;
1406
static PyObject *__pyx_n_s_n;
1407
static PyObject *__pyx_n_s_name;
1408
static PyObject *__pyx_n_s_nt;
1409
static PyObject *__pyx_kp_s_nt_pyx;
1410
static PyObject *__pyx_n_s_pi;
1411
static PyObject *__pyx_n_s_range;
1412
static PyObject *__pyx_n_s_round;
1413
static PyObject *__pyx_n_s_s;
1414
static PyObject *__pyx_n_s_sqrt;
1415
static PyObject *__pyx_n_s_start;
1416
static PyObject *__pyx_n_s_test;
1417
static PyObject *__pyx_n_s_trial_division;
1418
static PyObject *__pyx_n_s_typing;
1419
static PyObject *__pyx_n_s_xgcd;
1420
static PyObject *__pyx_pf_2nt_gcd(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_a, int __pyx_v_b); /* proto */
1421
static PyObject *__pyx_pf_2nt_2xgcd(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_a, int __pyx_v_b); /* proto */
1422
static PyObject *__pyx_pf_2nt_4inverse_mod(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_a, int __pyx_v_N); /* proto */
1423
static PyObject *__pyx_pf_2nt_6trial_division(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_N, PyObject *__pyx_v_bound, PyObject *__pyx_v_start); /* proto */
1424
static PyObject *__pyx_pf_2nt_8is_prime(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_N); /* proto */
1425
static PyObject *__pyx_pf_2nt_10pi(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_n); /* proto */
1426
static PyObject *__pyx_int_0;
1427
static PyObject *__pyx_int_1;
1428
static PyObject *__pyx_int_2;
1429
static PyObject *__pyx_int_3;
1430
static PyObject *__pyx_int_4;
1431
static PyObject *__pyx_int_5;
1432
static PyObject *__pyx_int_6;
1433
static PyObject *__pyx_int_7;
1434
static PyObject *__pyx_int_8;
1435
static PyObject *__pyx_int_11;
1436
static PyObject *__pyx_int_13;
1437
static PyObject *__pyx_int_17;
1438
static PyObject *__pyx_int_19;
1439
static PyObject *__pyx_int_23;
1440
static PyObject *__pyx_int_29;
1441
static PyObject *__pyx_int_30;
1442
static PyObject *__pyx_int_100000;
1443
static PyObject *__pyx_tuple_;
1444
static PyObject *__pyx_tuple__3;
1445
static PyObject *__pyx_tuple__5;
1446
static PyObject *__pyx_tuple__7;
1447
static PyObject *__pyx_codeobj__2;
1448
static PyObject *__pyx_codeobj__4;
1449
static PyObject *__pyx_codeobj__6;
1450
static PyObject *__pyx_codeobj__8;
1451
/* Late includes */
1452
1453
/* "nt.pyx":9
1454
*
1455
*
1456
* cpdef int gcd(int a, int b): # <<<<<<<<<<<<<<
1457
* cdef int c
1458
* while b:
1459
*/
1460
1461
static PyObject *__pyx_pw_2nt_1gcd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1462
static int __pyx_f_2nt_gcd(int __pyx_v_a, int __pyx_v_b, CYTHON_UNUSED int __pyx_skip_dispatch) {
1463
int __pyx_v_c;
1464
int __pyx_r;
1465
__Pyx_RefNannyDeclarations
1466
int __pyx_t_1;
1467
int __pyx_lineno = 0;
1468
const char *__pyx_filename = NULL;
1469
int __pyx_clineno = 0;
1470
__Pyx_RefNannySetupContext("gcd", 0);
1471
1472
/* "nt.pyx":11
1473
* cpdef int gcd(int a, int b):
1474
* cdef int c
1475
* while b: # <<<<<<<<<<<<<<
1476
* c = a % b
1477
* a = b
1478
*/
1479
while (1) {
1480
__pyx_t_1 = (__pyx_v_b != 0);
1481
if (!__pyx_t_1) break;
1482
1483
/* "nt.pyx":12
1484
* cdef int c
1485
* while b:
1486
* c = a % b # <<<<<<<<<<<<<<
1487
* a = b
1488
* b = c
1489
*/
1490
if (unlikely(__pyx_v_b == 0)) {
1491
PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
1492
__PYX_ERR(0, 12, __pyx_L1_error)
1493
}
1494
__pyx_v_c = __Pyx_mod_int(__pyx_v_a, __pyx_v_b);
1495
1496
/* "nt.pyx":13
1497
* while b:
1498
* c = a % b
1499
* a = b # <<<<<<<<<<<<<<
1500
* b = c
1501
* return a
1502
*/
1503
__pyx_v_a = __pyx_v_b;
1504
1505
/* "nt.pyx":14
1506
* c = a % b
1507
* a = b
1508
* b = c # <<<<<<<<<<<<<<
1509
* return a
1510
*
1511
*/
1512
__pyx_v_b = __pyx_v_c;
1513
}
1514
1515
/* "nt.pyx":15
1516
* a = b
1517
* b = c
1518
* return a # <<<<<<<<<<<<<<
1519
*
1520
*
1521
*/
1522
__pyx_r = __pyx_v_a;
1523
goto __pyx_L0;
1524
1525
/* "nt.pyx":9
1526
*
1527
*
1528
* cpdef int gcd(int a, int b): # <<<<<<<<<<<<<<
1529
* cdef int c
1530
* while b:
1531
*/
1532
1533
/* function exit code */
1534
__pyx_L1_error:;
1535
__Pyx_WriteUnraisable("nt.gcd", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
1536
__pyx_r = 0;
1537
__pyx_L0:;
1538
__Pyx_RefNannyFinishContext();
1539
return __pyx_r;
1540
}
1541
1542
/* Python wrapper */
1543
static PyObject *__pyx_pw_2nt_1gcd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1544
static PyObject *__pyx_pw_2nt_1gcd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1545
int __pyx_v_a;
1546
int __pyx_v_b;
1547
int __pyx_lineno = 0;
1548
const char *__pyx_filename = NULL;
1549
int __pyx_clineno = 0;
1550
PyObject *__pyx_r = 0;
1551
__Pyx_RefNannyDeclarations
1552
__Pyx_RefNannySetupContext("gcd (wrapper)", 0);
1553
{
1554
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_a,&__pyx_n_s_b,0};
1555
PyObject* values[2] = {0,0};
1556
if (unlikely(__pyx_kwds)) {
1557
Py_ssize_t kw_args;
1558
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
1559
switch (pos_args) {
1560
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
1561
CYTHON_FALLTHROUGH;
1562
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
1563
CYTHON_FALLTHROUGH;
1564
case 0: break;
1565
default: goto __pyx_L5_argtuple_error;
1566
}
1567
kw_args = PyDict_Size(__pyx_kwds);
1568
switch (pos_args) {
1569
case 0:
1570
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_a)) != 0)) kw_args--;
1571
else goto __pyx_L5_argtuple_error;
1572
CYTHON_FALLTHROUGH;
1573
case 1:
1574
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_b)) != 0)) kw_args--;
1575
else {
1576
__Pyx_RaiseArgtupleInvalid("gcd", 1, 2, 2, 1); __PYX_ERR(0, 9, __pyx_L3_error)
1577
}
1578
}
1579
if (unlikely(kw_args > 0)) {
1580
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "gcd") < 0)) __PYX_ERR(0, 9, __pyx_L3_error)
1581
}
1582
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
1583
goto __pyx_L5_argtuple_error;
1584
} else {
1585
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
1586
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
1587
}
1588
__pyx_v_a = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_a == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 9, __pyx_L3_error)
1589
__pyx_v_b = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_b == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 9, __pyx_L3_error)
1590
}
1591
goto __pyx_L4_argument_unpacking_done;
1592
__pyx_L5_argtuple_error:;
1593
__Pyx_RaiseArgtupleInvalid("gcd", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 9, __pyx_L3_error)
1594
__pyx_L3_error:;
1595
__Pyx_AddTraceback("nt.gcd", __pyx_clineno, __pyx_lineno, __pyx_filename);
1596
__Pyx_RefNannyFinishContext();
1597
return NULL;
1598
__pyx_L4_argument_unpacking_done:;
1599
__pyx_r = __pyx_pf_2nt_gcd(__pyx_self, __pyx_v_a, __pyx_v_b);
1600
1601
/* function exit code */
1602
__Pyx_RefNannyFinishContext();
1603
return __pyx_r;
1604
}
1605
1606
static PyObject *__pyx_pf_2nt_gcd(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_a, int __pyx_v_b) {
1607
PyObject *__pyx_r = NULL;
1608
__Pyx_RefNannyDeclarations
1609
PyObject *__pyx_t_1 = NULL;
1610
int __pyx_lineno = 0;
1611
const char *__pyx_filename = NULL;
1612
int __pyx_clineno = 0;
1613
__Pyx_RefNannySetupContext("gcd", 0);
1614
__Pyx_XDECREF(__pyx_r);
1615
__pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_2nt_gcd(__pyx_v_a, __pyx_v_b, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __pyx_L1_error)
1616
__Pyx_GOTREF(__pyx_t_1);
1617
__pyx_r = __pyx_t_1;
1618
__pyx_t_1 = 0;
1619
goto __pyx_L0;
1620
1621
/* function exit code */
1622
__pyx_L1_error:;
1623
__Pyx_XDECREF(__pyx_t_1);
1624
__Pyx_AddTraceback("nt.gcd", __pyx_clineno, __pyx_lineno, __pyx_filename);
1625
__pyx_r = NULL;
1626
__pyx_L0:;
1627
__Pyx_XGIVEREF(__pyx_r);
1628
__Pyx_RefNannyFinishContext();
1629
return __pyx_r;
1630
}
1631
1632
/* "nt.pyx":18
1633
*
1634
*
1635
* cdef int xgcd_c(int a, int b, int* cx, int* cy): # <<<<<<<<<<<<<<
1636
* cdef int prevx, prevy, x, y, q, r
1637
* prevx, x = 1, 0
1638
*/
1639
1640
static int __pyx_f_2nt_xgcd_c(int __pyx_v_a, int __pyx_v_b, int *__pyx_v_cx, int *__pyx_v_cy) {
1641
int __pyx_v_prevx;
1642
int __pyx_v_prevy;
1643
int __pyx_v_x;
1644
int __pyx_v_y;
1645
int __pyx_v_q;
1646
int __pyx_v_r;
1647
int __pyx_r;
1648
__Pyx_RefNannyDeclarations
1649
int __pyx_t_1;
1650
int __pyx_t_2;
1651
int __pyx_t_3;
1652
int __pyx_lineno = 0;
1653
const char *__pyx_filename = NULL;
1654
int __pyx_clineno = 0;
1655
__Pyx_RefNannySetupContext("xgcd_c", 0);
1656
1657
/* "nt.pyx":20
1658
* cdef int xgcd_c(int a, int b, int* cx, int* cy):
1659
* cdef int prevx, prevy, x, y, q, r
1660
* prevx, x = 1, 0 # <<<<<<<<<<<<<<
1661
* prevy, y = 0, 1
1662
* while b:
1663
*/
1664
__pyx_t_1 = 1;
1665
__pyx_t_2 = 0;
1666
__pyx_v_prevx = __pyx_t_1;
1667
__pyx_v_x = __pyx_t_2;
1668
1669
/* "nt.pyx":21
1670
* cdef int prevx, prevy, x, y, q, r
1671
* prevx, x = 1, 0
1672
* prevy, y = 0, 1 # <<<<<<<<<<<<<<
1673
* while b:
1674
* q = a // b
1675
*/
1676
__pyx_t_2 = 0;
1677
__pyx_t_1 = 1;
1678
__pyx_v_prevy = __pyx_t_2;
1679
__pyx_v_y = __pyx_t_1;
1680
1681
/* "nt.pyx":22
1682
* prevx, x = 1, 0
1683
* prevy, y = 0, 1
1684
* while b: # <<<<<<<<<<<<<<
1685
* q = a // b
1686
* r = a % b
1687
*/
1688
while (1) {
1689
__pyx_t_3 = (__pyx_v_b != 0);
1690
if (!__pyx_t_3) break;
1691
1692
/* "nt.pyx":23
1693
* prevy, y = 0, 1
1694
* while b:
1695
* q = a // b # <<<<<<<<<<<<<<
1696
* r = a % b
1697
* x, prevx = prevx - q * x, x
1698
*/
1699
if (unlikely(__pyx_v_b == 0)) {
1700
PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
1701
__PYX_ERR(0, 23, __pyx_L1_error)
1702
}
1703
else if (sizeof(int) == sizeof(long) && (!(((int)-1) > 0)) && unlikely(__pyx_v_b == (int)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_a))) {
1704
PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
1705
__PYX_ERR(0, 23, __pyx_L1_error)
1706
}
1707
__pyx_v_q = __Pyx_div_int(__pyx_v_a, __pyx_v_b);
1708
1709
/* "nt.pyx":24
1710
* while b:
1711
* q = a // b
1712
* r = a % b # <<<<<<<<<<<<<<
1713
* x, prevx = prevx - q * x, x
1714
* y, prevy = prevy - q * y, y
1715
*/
1716
if (unlikely(__pyx_v_b == 0)) {
1717
PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
1718
__PYX_ERR(0, 24, __pyx_L1_error)
1719
}
1720
__pyx_v_r = __Pyx_mod_int(__pyx_v_a, __pyx_v_b);
1721
1722
/* "nt.pyx":25
1723
* q = a // b
1724
* r = a % b
1725
* x, prevx = prevx - q * x, x # <<<<<<<<<<<<<<
1726
* y, prevy = prevy - q * y, y
1727
* a, b = b, r
1728
*/
1729
__pyx_t_1 = (__pyx_v_prevx - (__pyx_v_q * __pyx_v_x));
1730
__pyx_t_2 = __pyx_v_x;
1731
__pyx_v_x = __pyx_t_1;
1732
__pyx_v_prevx = __pyx_t_2;
1733
1734
/* "nt.pyx":26
1735
* r = a % b
1736
* x, prevx = prevx - q * x, x
1737
* y, prevy = prevy - q * y, y # <<<<<<<<<<<<<<
1738
* a, b = b, r
1739
* cx[0] = prevx
1740
*/
1741
__pyx_t_2 = (__pyx_v_prevy - (__pyx_v_q * __pyx_v_y));
1742
__pyx_t_1 = __pyx_v_y;
1743
__pyx_v_y = __pyx_t_2;
1744
__pyx_v_prevy = __pyx_t_1;
1745
1746
/* "nt.pyx":27
1747
* x, prevx = prevx - q * x, x
1748
* y, prevy = prevy - q * y, y
1749
* a, b = b, r # <<<<<<<<<<<<<<
1750
* cx[0] = prevx
1751
* cy[0] = prevy
1752
*/
1753
__pyx_t_1 = __pyx_v_b;
1754
__pyx_t_2 = __pyx_v_r;
1755
__pyx_v_a = __pyx_t_1;
1756
__pyx_v_b = __pyx_t_2;
1757
}
1758
1759
/* "nt.pyx":28
1760
* y, prevy = prevy - q * y, y
1761
* a, b = b, r
1762
* cx[0] = prevx # <<<<<<<<<<<<<<
1763
* cy[0] = prevy
1764
* return a
1765
*/
1766
(__pyx_v_cx[0]) = __pyx_v_prevx;
1767
1768
/* "nt.pyx":29
1769
* a, b = b, r
1770
* cx[0] = prevx
1771
* cy[0] = prevy # <<<<<<<<<<<<<<
1772
* return a
1773
*
1774
*/
1775
(__pyx_v_cy[0]) = __pyx_v_prevy;
1776
1777
/* "nt.pyx":30
1778
* cx[0] = prevx
1779
* cy[0] = prevy
1780
* return a # <<<<<<<<<<<<<<
1781
*
1782
* def xgcd(int a, int b) -> Tuple[int, int, int]:
1783
*/
1784
__pyx_r = __pyx_v_a;
1785
goto __pyx_L0;
1786
1787
/* "nt.pyx":18
1788
*
1789
*
1790
* cdef int xgcd_c(int a, int b, int* cx, int* cy): # <<<<<<<<<<<<<<
1791
* cdef int prevx, prevy, x, y, q, r
1792
* prevx, x = 1, 0
1793
*/
1794
1795
/* function exit code */
1796
__pyx_L1_error:;
1797
__Pyx_WriteUnraisable("nt.xgcd_c", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
1798
__pyx_r = 0;
1799
__pyx_L0:;
1800
__Pyx_RefNannyFinishContext();
1801
return __pyx_r;
1802
}
1803
1804
/* "nt.pyx":32
1805
* return a
1806
*
1807
* def xgcd(int a, int b) -> Tuple[int, int, int]: # <<<<<<<<<<<<<<
1808
* cdef int cx, cy, g
1809
* g = xgcd_c(a,b,&cx,&cy)
1810
*/
1811
1812
/* Python wrapper */
1813
static PyObject *__pyx_pw_2nt_3xgcd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1814
static PyMethodDef __pyx_mdef_2nt_3xgcd = {"xgcd", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_2nt_3xgcd, METH_VARARGS|METH_KEYWORDS, 0};
1815
static PyObject *__pyx_pw_2nt_3xgcd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1816
int __pyx_v_a;
1817
int __pyx_v_b;
1818
int __pyx_lineno = 0;
1819
const char *__pyx_filename = NULL;
1820
int __pyx_clineno = 0;
1821
PyObject *__pyx_r = 0;
1822
__Pyx_RefNannyDeclarations
1823
__Pyx_RefNannySetupContext("xgcd (wrapper)", 0);
1824
{
1825
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_a,&__pyx_n_s_b,0};
1826
PyObject* values[2] = {0,0};
1827
if (unlikely(__pyx_kwds)) {
1828
Py_ssize_t kw_args;
1829
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
1830
switch (pos_args) {
1831
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
1832
CYTHON_FALLTHROUGH;
1833
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
1834
CYTHON_FALLTHROUGH;
1835
case 0: break;
1836
default: goto __pyx_L5_argtuple_error;
1837
}
1838
kw_args = PyDict_Size(__pyx_kwds);
1839
switch (pos_args) {
1840
case 0:
1841
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_a)) != 0)) kw_args--;
1842
else goto __pyx_L5_argtuple_error;
1843
CYTHON_FALLTHROUGH;
1844
case 1:
1845
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_b)) != 0)) kw_args--;
1846
else {
1847
__Pyx_RaiseArgtupleInvalid("xgcd", 1, 2, 2, 1); __PYX_ERR(0, 32, __pyx_L3_error)
1848
}
1849
}
1850
if (unlikely(kw_args > 0)) {
1851
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "xgcd") < 0)) __PYX_ERR(0, 32, __pyx_L3_error)
1852
}
1853
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
1854
goto __pyx_L5_argtuple_error;
1855
} else {
1856
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
1857
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
1858
}
1859
__pyx_v_a = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_a == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 32, __pyx_L3_error)
1860
__pyx_v_b = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_b == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 32, __pyx_L3_error)
1861
}
1862
goto __pyx_L4_argument_unpacking_done;
1863
__pyx_L5_argtuple_error:;
1864
__Pyx_RaiseArgtupleInvalid("xgcd", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 32, __pyx_L3_error)
1865
__pyx_L3_error:;
1866
__Pyx_AddTraceback("nt.xgcd", __pyx_clineno, __pyx_lineno, __pyx_filename);
1867
__Pyx_RefNannyFinishContext();
1868
return NULL;
1869
__pyx_L4_argument_unpacking_done:;
1870
__pyx_r = __pyx_pf_2nt_2xgcd(__pyx_self, __pyx_v_a, __pyx_v_b);
1871
1872
/* function exit code */
1873
__Pyx_RefNannyFinishContext();
1874
return __pyx_r;
1875
}
1876
1877
static PyObject *__pyx_pf_2nt_2xgcd(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_a, int __pyx_v_b) {
1878
int __pyx_v_cx;
1879
int __pyx_v_cy;
1880
int __pyx_v_g;
1881
PyObject *__pyx_r = NULL;
1882
__Pyx_RefNannyDeclarations
1883
PyObject *__pyx_t_1 = NULL;
1884
PyObject *__pyx_t_2 = NULL;
1885
PyObject *__pyx_t_3 = NULL;
1886
PyObject *__pyx_t_4 = NULL;
1887
int __pyx_lineno = 0;
1888
const char *__pyx_filename = NULL;
1889
int __pyx_clineno = 0;
1890
__Pyx_RefNannySetupContext("xgcd", 0);
1891
1892
/* "nt.pyx":34
1893
* def xgcd(int a, int b) -> Tuple[int, int, int]:
1894
* cdef int cx, cy, g
1895
* g = xgcd_c(a,b,&cx,&cy) # <<<<<<<<<<<<<<
1896
* return [g,cx,cy]
1897
*
1898
*/
1899
__pyx_v_g = __pyx_f_2nt_xgcd_c(__pyx_v_a, __pyx_v_b, (&__pyx_v_cx), (&__pyx_v_cy));
1900
1901
/* "nt.pyx":35
1902
* cdef int cx, cy, g
1903
* g = xgcd_c(a,b,&cx,&cy)
1904
* return [g,cx,cy] # <<<<<<<<<<<<<<
1905
*
1906
*
1907
*/
1908
__Pyx_XDECREF(__pyx_r);
1909
__pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 35, __pyx_L1_error)
1910
__Pyx_GOTREF(__pyx_t_1);
1911
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_cx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 35, __pyx_L1_error)
1912
__Pyx_GOTREF(__pyx_t_2);
1913
__pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_cy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 35, __pyx_L1_error)
1914
__Pyx_GOTREF(__pyx_t_3);
1915
__pyx_t_4 = PyList_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 35, __pyx_L1_error)
1916
__Pyx_GOTREF(__pyx_t_4);
1917
__Pyx_GIVEREF(__pyx_t_1);
1918
PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
1919
__Pyx_GIVEREF(__pyx_t_2);
1920
PyList_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
1921
__Pyx_GIVEREF(__pyx_t_3);
1922
PyList_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
1923
__pyx_t_1 = 0;
1924
__pyx_t_2 = 0;
1925
__pyx_t_3 = 0;
1926
__pyx_r = __pyx_t_4;
1927
__pyx_t_4 = 0;
1928
goto __pyx_L0;
1929
1930
/* "nt.pyx":32
1931
* return a
1932
*
1933
* def xgcd(int a, int b) -> Tuple[int, int, int]: # <<<<<<<<<<<<<<
1934
* cdef int cx, cy, g
1935
* g = xgcd_c(a,b,&cx,&cy)
1936
*/
1937
1938
/* function exit code */
1939
__pyx_L1_error:;
1940
__Pyx_XDECREF(__pyx_t_1);
1941
__Pyx_XDECREF(__pyx_t_2);
1942
__Pyx_XDECREF(__pyx_t_3);
1943
__Pyx_XDECREF(__pyx_t_4);
1944
__Pyx_AddTraceback("nt.xgcd", __pyx_clineno, __pyx_lineno, __pyx_filename);
1945
__pyx_r = NULL;
1946
__pyx_L0:;
1947
__Pyx_XGIVEREF(__pyx_r);
1948
__Pyx_RefNannyFinishContext();
1949
return __pyx_r;
1950
}
1951
1952
/* "nt.pyx":38
1953
*
1954
*
1955
* cpdef int inverse_mod(int a, int N): # <<<<<<<<<<<<<<
1956
* """
1957
* Compute multiplicative inverse of a modulo N.
1958
*/
1959
1960
static PyObject *__pyx_pw_2nt_5inverse_mod(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1961
static int __pyx_f_2nt_inverse_mod(int __pyx_v_a, int __pyx_v_N, CYTHON_UNUSED int __pyx_skip_dispatch) {
1962
int __pyx_v_g;
1963
int __pyx_v_s;
1964
int __pyx_v_cy;
1965
PyObject *__pyx_v_b = 0;
1966
int __pyx_r;
1967
__Pyx_RefNannyDeclarations
1968
int __pyx_t_1;
1969
int __pyx_t_2;
1970
PyObject *__pyx_t_3 = NULL;
1971
PyObject *__pyx_t_4 = NULL;
1972
int __pyx_t_5;
1973
int __pyx_lineno = 0;
1974
const char *__pyx_filename = NULL;
1975
int __pyx_clineno = 0;
1976
__Pyx_RefNannySetupContext("inverse_mod", 0);
1977
1978
/* "nt.pyx":42
1979
* Compute multiplicative inverse of a modulo N.
1980
* """
1981
* if a == 1 or N <= 1: # common special cases # <<<<<<<<<<<<<<
1982
* return a % N
1983
* cdef int g, s, cy
1984
*/
1985
__pyx_t_2 = ((__pyx_v_a == 1) != 0);
1986
if (!__pyx_t_2) {
1987
} else {
1988
__pyx_t_1 = __pyx_t_2;
1989
goto __pyx_L4_bool_binop_done;
1990
}
1991
__pyx_t_2 = ((__pyx_v_N <= 1) != 0);
1992
__pyx_t_1 = __pyx_t_2;
1993
__pyx_L4_bool_binop_done:;
1994
if (__pyx_t_1) {
1995
1996
/* "nt.pyx":43
1997
* """
1998
* if a == 1 or N <= 1: # common special cases
1999
* return a % N # <<<<<<<<<<<<<<
2000
* cdef int g, s, cy
2001
* g = xgcd_c(a, N, &s, &cy)
2002
*/
2003
if (unlikely(__pyx_v_N == 0)) {
2004
PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
2005
__PYX_ERR(0, 43, __pyx_L1_error)
2006
}
2007
__pyx_r = __Pyx_mod_int(__pyx_v_a, __pyx_v_N);
2008
goto __pyx_L0;
2009
2010
/* "nt.pyx":42
2011
* Compute multiplicative inverse of a modulo N.
2012
* """
2013
* if a == 1 or N <= 1: # common special cases # <<<<<<<<<<<<<<
2014
* return a % N
2015
* cdef int g, s, cy
2016
*/
2017
}
2018
2019
/* "nt.pyx":45
2020
* return a % N
2021
* cdef int g, s, cy
2022
* g = xgcd_c(a, N, &s, &cy) # <<<<<<<<<<<<<<
2023
* if g != 1:
2024
* raise ZeroDivisionError
2025
*/
2026
__pyx_v_g = __pyx_f_2nt_xgcd_c(__pyx_v_a, __pyx_v_N, (&__pyx_v_s), (&__pyx_v_cy));
2027
2028
/* "nt.pyx":46
2029
* cdef int g, s, cy
2030
* g = xgcd_c(a, N, &s, &cy)
2031
* if g != 1: # <<<<<<<<<<<<<<
2032
* raise ZeroDivisionError
2033
* cdef b = s % N
2034
*/
2035
__pyx_t_1 = ((__pyx_v_g != 1) != 0);
2036
if (unlikely(__pyx_t_1)) {
2037
2038
/* "nt.pyx":47
2039
* g = xgcd_c(a, N, &s, &cy)
2040
* if g != 1:
2041
* raise ZeroDivisionError # <<<<<<<<<<<<<<
2042
* cdef b = s % N
2043
* if b < 0:
2044
*/
2045
__Pyx_Raise(__pyx_builtin_ZeroDivisionError, 0, 0, 0);
2046
__PYX_ERR(0, 47, __pyx_L1_error)
2047
2048
/* "nt.pyx":46
2049
* cdef int g, s, cy
2050
* g = xgcd_c(a, N, &s, &cy)
2051
* if g != 1: # <<<<<<<<<<<<<<
2052
* raise ZeroDivisionError
2053
* cdef b = s % N
2054
*/
2055
}
2056
2057
/* "nt.pyx":48
2058
* if g != 1:
2059
* raise ZeroDivisionError
2060
* cdef b = s % N # <<<<<<<<<<<<<<
2061
* if b < 0:
2062
* b += N
2063
*/
2064
if (unlikely(__pyx_v_N == 0)) {
2065
PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
2066
__PYX_ERR(0, 48, __pyx_L1_error)
2067
}
2068
__pyx_t_3 = __Pyx_PyInt_From_int(__Pyx_mod_int(__pyx_v_s, __pyx_v_N)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 48, __pyx_L1_error)
2069
__Pyx_GOTREF(__pyx_t_3);
2070
__pyx_v_b = __pyx_t_3;
2071
__pyx_t_3 = 0;
2072
2073
/* "nt.pyx":49
2074
* raise ZeroDivisionError
2075
* cdef b = s % N
2076
* if b < 0: # <<<<<<<<<<<<<<
2077
* b += N
2078
* return b
2079
*/
2080
__pyx_t_3 = PyObject_RichCompare(__pyx_v_b, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 49, __pyx_L1_error)
2081
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 49, __pyx_L1_error)
2082
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2083
if (__pyx_t_1) {
2084
2085
/* "nt.pyx":50
2086
* cdef b = s % N
2087
* if b < 0:
2088
* b += N # <<<<<<<<<<<<<<
2089
* return b
2090
*
2091
*/
2092
__pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_N); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 50, __pyx_L1_error)
2093
__Pyx_GOTREF(__pyx_t_3);
2094
__pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_b, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 50, __pyx_L1_error)
2095
__Pyx_GOTREF(__pyx_t_4);
2096
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2097
__Pyx_DECREF_SET(__pyx_v_b, __pyx_t_4);
2098
__pyx_t_4 = 0;
2099
2100
/* "nt.pyx":49
2101
* raise ZeroDivisionError
2102
* cdef b = s % N
2103
* if b < 0: # <<<<<<<<<<<<<<
2104
* b += N
2105
* return b
2106
*/
2107
}
2108
2109
/* "nt.pyx":51
2110
* if b < 0:
2111
* b += N
2112
* return b # <<<<<<<<<<<<<<
2113
*
2114
*
2115
*/
2116
__pyx_t_5 = __Pyx_PyInt_As_int(__pyx_v_b); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 51, __pyx_L1_error)
2117
__pyx_r = __pyx_t_5;
2118
goto __pyx_L0;
2119
2120
/* "nt.pyx":38
2121
*
2122
*
2123
* cpdef int inverse_mod(int a, int N): # <<<<<<<<<<<<<<
2124
* """
2125
* Compute multiplicative inverse of a modulo N.
2126
*/
2127
2128
/* function exit code */
2129
__pyx_L1_error:;
2130
__Pyx_XDECREF(__pyx_t_3);
2131
__Pyx_XDECREF(__pyx_t_4);
2132
__Pyx_WriteUnraisable("nt.inverse_mod", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
2133
__pyx_r = 0;
2134
__pyx_L0:;
2135
__Pyx_XDECREF(__pyx_v_b);
2136
__Pyx_RefNannyFinishContext();
2137
return __pyx_r;
2138
}
2139
2140
/* Python wrapper */
2141
static PyObject *__pyx_pw_2nt_5inverse_mod(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
2142
static char __pyx_doc_2nt_4inverse_mod[] = "\n Compute multiplicative inverse of a modulo N.\n ";
2143
static PyObject *__pyx_pw_2nt_5inverse_mod(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
2144
int __pyx_v_a;
2145
int __pyx_v_N;
2146
int __pyx_lineno = 0;
2147
const char *__pyx_filename = NULL;
2148
int __pyx_clineno = 0;
2149
PyObject *__pyx_r = 0;
2150
__Pyx_RefNannyDeclarations
2151
__Pyx_RefNannySetupContext("inverse_mod (wrapper)", 0);
2152
{
2153
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_a,&__pyx_n_s_N,0};
2154
PyObject* values[2] = {0,0};
2155
if (unlikely(__pyx_kwds)) {
2156
Py_ssize_t kw_args;
2157
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
2158
switch (pos_args) {
2159
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
2160
CYTHON_FALLTHROUGH;
2161
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
2162
CYTHON_FALLTHROUGH;
2163
case 0: break;
2164
default: goto __pyx_L5_argtuple_error;
2165
}
2166
kw_args = PyDict_Size(__pyx_kwds);
2167
switch (pos_args) {
2168
case 0:
2169
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_a)) != 0)) kw_args--;
2170
else goto __pyx_L5_argtuple_error;
2171
CYTHON_FALLTHROUGH;
2172
case 1:
2173
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_N)) != 0)) kw_args--;
2174
else {
2175
__Pyx_RaiseArgtupleInvalid("inverse_mod", 1, 2, 2, 1); __PYX_ERR(0, 38, __pyx_L3_error)
2176
}
2177
}
2178
if (unlikely(kw_args > 0)) {
2179
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "inverse_mod") < 0)) __PYX_ERR(0, 38, __pyx_L3_error)
2180
}
2181
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
2182
goto __pyx_L5_argtuple_error;
2183
} else {
2184
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
2185
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
2186
}
2187
__pyx_v_a = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_a == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 38, __pyx_L3_error)
2188
__pyx_v_N = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_N == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 38, __pyx_L3_error)
2189
}
2190
goto __pyx_L4_argument_unpacking_done;
2191
__pyx_L5_argtuple_error:;
2192
__Pyx_RaiseArgtupleInvalid("inverse_mod", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 38, __pyx_L3_error)
2193
__pyx_L3_error:;
2194
__Pyx_AddTraceback("nt.inverse_mod", __pyx_clineno, __pyx_lineno, __pyx_filename);
2195
__Pyx_RefNannyFinishContext();
2196
return NULL;
2197
__pyx_L4_argument_unpacking_done:;
2198
__pyx_r = __pyx_pf_2nt_4inverse_mod(__pyx_self, __pyx_v_a, __pyx_v_N);
2199
2200
/* function exit code */
2201
__Pyx_RefNannyFinishContext();
2202
return __pyx_r;
2203
}
2204
2205
static PyObject *__pyx_pf_2nt_4inverse_mod(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_a, int __pyx_v_N) {
2206
PyObject *__pyx_r = NULL;
2207
__Pyx_RefNannyDeclarations
2208
PyObject *__pyx_t_1 = NULL;
2209
int __pyx_lineno = 0;
2210
const char *__pyx_filename = NULL;
2211
int __pyx_clineno = 0;
2212
__Pyx_RefNannySetupContext("inverse_mod", 0);
2213
__Pyx_XDECREF(__pyx_r);
2214
__pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_2nt_inverse_mod(__pyx_v_a, __pyx_v_N, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L1_error)
2215
__Pyx_GOTREF(__pyx_t_1);
2216
__pyx_r = __pyx_t_1;
2217
__pyx_t_1 = 0;
2218
goto __pyx_L0;
2219
2220
/* function exit code */
2221
__pyx_L1_error:;
2222
__Pyx_XDECREF(__pyx_t_1);
2223
__Pyx_AddTraceback("nt.inverse_mod", __pyx_clineno, __pyx_lineno, __pyx_filename);
2224
__pyx_r = NULL;
2225
__pyx_L0:;
2226
__Pyx_XGIVEREF(__pyx_r);
2227
__Pyx_RefNannyFinishContext();
2228
return __pyx_r;
2229
}
2230
2231
/* "nt.pyx":54
2232
*
2233
*
2234
* def trial_division(N: int, bound: int = 0, start: int = 2) -> int: # <<<<<<<<<<<<<<
2235
* if N <= 1:
2236
* return N
2237
*/
2238
2239
/* Python wrapper */
2240
static PyObject *__pyx_pw_2nt_7trial_division(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
2241
static PyMethodDef __pyx_mdef_2nt_7trial_division = {"trial_division", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_2nt_7trial_division, METH_VARARGS|METH_KEYWORDS, 0};
2242
static PyObject *__pyx_pw_2nt_7trial_division(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
2243
PyObject *__pyx_v_N = 0;
2244
PyObject *__pyx_v_bound = 0;
2245
PyObject *__pyx_v_start = 0;
2246
int __pyx_lineno = 0;
2247
const char *__pyx_filename = NULL;
2248
int __pyx_clineno = 0;
2249
PyObject *__pyx_r = 0;
2250
__Pyx_RefNannyDeclarations
2251
__Pyx_RefNannySetupContext("trial_division (wrapper)", 0);
2252
{
2253
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_N,&__pyx_n_s_bound,&__pyx_n_s_start,0};
2254
PyObject* values[3] = {0,0,0};
2255
values[1] = ((PyObject *)__pyx_int_0);
2256
values[2] = ((PyObject *)__pyx_int_2);
2257
if (unlikely(__pyx_kwds)) {
2258
Py_ssize_t kw_args;
2259
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
2260
switch (pos_args) {
2261
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
2262
CYTHON_FALLTHROUGH;
2263
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
2264
CYTHON_FALLTHROUGH;
2265
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
2266
CYTHON_FALLTHROUGH;
2267
case 0: break;
2268
default: goto __pyx_L5_argtuple_error;
2269
}
2270
kw_args = PyDict_Size(__pyx_kwds);
2271
switch (pos_args) {
2272
case 0:
2273
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_N)) != 0)) kw_args--;
2274
else goto __pyx_L5_argtuple_error;
2275
CYTHON_FALLTHROUGH;
2276
case 1:
2277
if (kw_args > 0) {
2278
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bound);
2279
if (value) { values[1] = value; kw_args--; }
2280
}
2281
CYTHON_FALLTHROUGH;
2282
case 2:
2283
if (kw_args > 0) {
2284
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start);
2285
if (value) { values[2] = value; kw_args--; }
2286
}
2287
}
2288
if (unlikely(kw_args > 0)) {
2289
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "trial_division") < 0)) __PYX_ERR(0, 54, __pyx_L3_error)
2290
}
2291
} else {
2292
switch (PyTuple_GET_SIZE(__pyx_args)) {
2293
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
2294
CYTHON_FALLTHROUGH;
2295
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
2296
CYTHON_FALLTHROUGH;
2297
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
2298
break;
2299
default: goto __pyx_L5_argtuple_error;
2300
}
2301
}
2302
__pyx_v_N = values[0];
2303
__pyx_v_bound = values[1];
2304
__pyx_v_start = values[2];
2305
}
2306
goto __pyx_L4_argument_unpacking_done;
2307
__pyx_L5_argtuple_error:;
2308
__Pyx_RaiseArgtupleInvalid("trial_division", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 54, __pyx_L3_error)
2309
__pyx_L3_error:;
2310
__Pyx_AddTraceback("nt.trial_division", __pyx_clineno, __pyx_lineno, __pyx_filename);
2311
__Pyx_RefNannyFinishContext();
2312
return NULL;
2313
__pyx_L4_argument_unpacking_done:;
2314
__pyx_r = __pyx_pf_2nt_6trial_division(__pyx_self, __pyx_v_N, __pyx_v_bound, __pyx_v_start);
2315
2316
/* function exit code */
2317
__Pyx_RefNannyFinishContext();
2318
return __pyx_r;
2319
}
2320
2321
static PyObject *__pyx_pf_2nt_6trial_division(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_N, PyObject *__pyx_v_bound, PyObject *__pyx_v_start) {
2322
PyObject *__pyx_v_m = NULL;
2323
PyObject *__pyx_v_i = NULL;
2324
PyObject *__pyx_v_dif = NULL;
2325
PyObject *__pyx_v_limit = NULL;
2326
PyObject *__pyx_r = NULL;
2327
__Pyx_RefNannyDeclarations
2328
PyObject *__pyx_t_1 = NULL;
2329
int __pyx_t_2;
2330
PyObject *__pyx_t_3 = NULL;
2331
int __pyx_t_4;
2332
PyObject *__pyx_t_5 = NULL;
2333
int __pyx_lineno = 0;
2334
const char *__pyx_filename = NULL;
2335
int __pyx_clineno = 0;
2336
__Pyx_RefNannySetupContext("trial_division", 0);
2337
2338
/* "nt.pyx":55
2339
*
2340
* def trial_division(N: int, bound: int = 0, start: int = 2) -> int:
2341
* if N <= 1: # <<<<<<<<<<<<<<
2342
* return N
2343
* m = 7
2344
*/
2345
__pyx_t_1 = PyObject_RichCompare(__pyx_v_N, __pyx_int_1, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error)
2346
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 55, __pyx_L1_error)
2347
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2348
if (__pyx_t_2) {
2349
2350
/* "nt.pyx":56
2351
* def trial_division(N: int, bound: int = 0, start: int = 2) -> int:
2352
* if N <= 1:
2353
* return N # <<<<<<<<<<<<<<
2354
* m = 7
2355
* i = 1
2356
*/
2357
__Pyx_XDECREF(__pyx_r);
2358
__Pyx_INCREF(__pyx_v_N);
2359
__pyx_r = __pyx_v_N;
2360
goto __pyx_L0;
2361
2362
/* "nt.pyx":55
2363
*
2364
* def trial_division(N: int, bound: int = 0, start: int = 2) -> int:
2365
* if N <= 1: # <<<<<<<<<<<<<<
2366
* return N
2367
* m = 7
2368
*/
2369
}
2370
2371
/* "nt.pyx":57
2372
* if N <= 1:
2373
* return N
2374
* m = 7 # <<<<<<<<<<<<<<
2375
* i = 1
2376
* dif = [6, 4, 2, 4, 2, 4, 6, 2]
2377
*/
2378
__Pyx_INCREF(__pyx_int_7);
2379
__pyx_v_m = __pyx_int_7;
2380
2381
/* "nt.pyx":58
2382
* return N
2383
* m = 7
2384
* i = 1 # <<<<<<<<<<<<<<
2385
* dif = [6, 4, 2, 4, 2, 4, 6, 2]
2386
* if start > 7:
2387
*/
2388
__Pyx_INCREF(__pyx_int_1);
2389
__pyx_v_i = __pyx_int_1;
2390
2391
/* "nt.pyx":59
2392
* m = 7
2393
* i = 1
2394
* dif = [6, 4, 2, 4, 2, 4, 6, 2] # <<<<<<<<<<<<<<
2395
* if start > 7:
2396
* m = start % 30
2397
*/
2398
__pyx_t_1 = PyList_New(8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error)
2399
__Pyx_GOTREF(__pyx_t_1);
2400
__Pyx_INCREF(__pyx_int_6);
2401
__Pyx_GIVEREF(__pyx_int_6);
2402
PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_6);
2403
__Pyx_INCREF(__pyx_int_4);
2404
__Pyx_GIVEREF(__pyx_int_4);
2405
PyList_SET_ITEM(__pyx_t_1, 1, __pyx_int_4);
2406
__Pyx_INCREF(__pyx_int_2);
2407
__Pyx_GIVEREF(__pyx_int_2);
2408
PyList_SET_ITEM(__pyx_t_1, 2, __pyx_int_2);
2409
__Pyx_INCREF(__pyx_int_4);
2410
__Pyx_GIVEREF(__pyx_int_4);
2411
PyList_SET_ITEM(__pyx_t_1, 3, __pyx_int_4);
2412
__Pyx_INCREF(__pyx_int_2);
2413
__Pyx_GIVEREF(__pyx_int_2);
2414
PyList_SET_ITEM(__pyx_t_1, 4, __pyx_int_2);
2415
__Pyx_INCREF(__pyx_int_4);
2416
__Pyx_GIVEREF(__pyx_int_4);
2417
PyList_SET_ITEM(__pyx_t_1, 5, __pyx_int_4);
2418
__Pyx_INCREF(__pyx_int_6);
2419
__Pyx_GIVEREF(__pyx_int_6);
2420
PyList_SET_ITEM(__pyx_t_1, 6, __pyx_int_6);
2421
__Pyx_INCREF(__pyx_int_2);
2422
__Pyx_GIVEREF(__pyx_int_2);
2423
PyList_SET_ITEM(__pyx_t_1, 7, __pyx_int_2);
2424
__pyx_v_dif = ((PyObject*)__pyx_t_1);
2425
__pyx_t_1 = 0;
2426
2427
/* "nt.pyx":60
2428
* i = 1
2429
* dif = [6, 4, 2, 4, 2, 4, 6, 2]
2430
* if start > 7: # <<<<<<<<<<<<<<
2431
* m = start % 30
2432
* if m <= 1:
2433
*/
2434
__pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_int_7, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error)
2435
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 60, __pyx_L1_error)
2436
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2437
if (__pyx_t_2) {
2438
2439
/* "nt.pyx":61
2440
* dif = [6, 4, 2, 4, 2, 4, 6, 2]
2441
* if start > 7:
2442
* m = start % 30 # <<<<<<<<<<<<<<
2443
* if m <= 1:
2444
* i = 0
2445
*/
2446
__pyx_t_1 = __Pyx_PyInt_RemainderObjC(__pyx_v_start, __pyx_int_30, 30, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L1_error)
2447
__Pyx_GOTREF(__pyx_t_1);
2448
__Pyx_DECREF_SET(__pyx_v_m, __pyx_t_1);
2449
__pyx_t_1 = 0;
2450
2451
/* "nt.pyx":62
2452
* if start > 7:
2453
* m = start % 30
2454
* if m <= 1: # <<<<<<<<<<<<<<
2455
* i = 0
2456
* m = start + (1 - m)
2457
*/
2458
__pyx_t_1 = PyObject_RichCompare(__pyx_v_m, __pyx_int_1, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)
2459
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 62, __pyx_L1_error)
2460
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2461
if (__pyx_t_2) {
2462
2463
/* "nt.pyx":63
2464
* m = start % 30
2465
* if m <= 1:
2466
* i = 0 # <<<<<<<<<<<<<<
2467
* m = start + (1 - m)
2468
* elif m <= 7:
2469
*/
2470
__Pyx_INCREF(__pyx_int_0);
2471
__Pyx_DECREF_SET(__pyx_v_i, __pyx_int_0);
2472
2473
/* "nt.pyx":64
2474
* if m <= 1:
2475
* i = 0
2476
* m = start + (1 - m) # <<<<<<<<<<<<<<
2477
* elif m <= 7:
2478
* i = 1
2479
*/
2480
__pyx_t_1 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_v_m, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 64, __pyx_L1_error)
2481
__Pyx_GOTREF(__pyx_t_1);
2482
__pyx_t_3 = PyNumber_Add(__pyx_v_start, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 64, __pyx_L1_error)
2483
__Pyx_GOTREF(__pyx_t_3);
2484
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2485
__Pyx_DECREF_SET(__pyx_v_m, __pyx_t_3);
2486
__pyx_t_3 = 0;
2487
2488
/* "nt.pyx":62
2489
* if start > 7:
2490
* m = start % 30
2491
* if m <= 1: # <<<<<<<<<<<<<<
2492
* i = 0
2493
* m = start + (1 - m)
2494
*/
2495
goto __pyx_L5;
2496
}
2497
2498
/* "nt.pyx":65
2499
* i = 0
2500
* m = start + (1 - m)
2501
* elif m <= 7: # <<<<<<<<<<<<<<
2502
* i = 1
2503
* m = start + (7 - m)
2504
*/
2505
__pyx_t_3 = PyObject_RichCompare(__pyx_v_m, __pyx_int_7, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 65, __pyx_L1_error)
2506
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 65, __pyx_L1_error)
2507
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2508
if (__pyx_t_2) {
2509
2510
/* "nt.pyx":66
2511
* m = start + (1 - m)
2512
* elif m <= 7:
2513
* i = 1 # <<<<<<<<<<<<<<
2514
* m = start + (7 - m)
2515
* elif m <= 11:
2516
*/
2517
__Pyx_INCREF(__pyx_int_1);
2518
__Pyx_DECREF_SET(__pyx_v_i, __pyx_int_1);
2519
2520
/* "nt.pyx":67
2521
* elif m <= 7:
2522
* i = 1
2523
* m = start + (7 - m) # <<<<<<<<<<<<<<
2524
* elif m <= 11:
2525
* i = 2
2526
*/
2527
__pyx_t_3 = __Pyx_PyInt_SubtractCObj(__pyx_int_7, __pyx_v_m, 7, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 67, __pyx_L1_error)
2528
__Pyx_GOTREF(__pyx_t_3);
2529
__pyx_t_1 = PyNumber_Add(__pyx_v_start, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L1_error)
2530
__Pyx_GOTREF(__pyx_t_1);
2531
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2532
__Pyx_DECREF_SET(__pyx_v_m, __pyx_t_1);
2533
__pyx_t_1 = 0;
2534
2535
/* "nt.pyx":65
2536
* i = 0
2537
* m = start + (1 - m)
2538
* elif m <= 7: # <<<<<<<<<<<<<<
2539
* i = 1
2540
* m = start + (7 - m)
2541
*/
2542
goto __pyx_L5;
2543
}
2544
2545
/* "nt.pyx":68
2546
* i = 1
2547
* m = start + (7 - m)
2548
* elif m <= 11: # <<<<<<<<<<<<<<
2549
* i = 2
2550
* m = start + (11 - m)
2551
*/
2552
__pyx_t_1 = PyObject_RichCompare(__pyx_v_m, __pyx_int_11, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 68, __pyx_L1_error)
2553
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 68, __pyx_L1_error)
2554
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2555
if (__pyx_t_2) {
2556
2557
/* "nt.pyx":69
2558
* m = start + (7 - m)
2559
* elif m <= 11:
2560
* i = 2 # <<<<<<<<<<<<<<
2561
* m = start + (11 - m)
2562
* elif m <= 13:
2563
*/
2564
__Pyx_INCREF(__pyx_int_2);
2565
__Pyx_DECREF_SET(__pyx_v_i, __pyx_int_2);
2566
2567
/* "nt.pyx":70
2568
* elif m <= 11:
2569
* i = 2
2570
* m = start + (11 - m) # <<<<<<<<<<<<<<
2571
* elif m <= 13:
2572
* i = 3
2573
*/
2574
__pyx_t_1 = __Pyx_PyInt_SubtractCObj(__pyx_int_11, __pyx_v_m, 11, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error)
2575
__Pyx_GOTREF(__pyx_t_1);
2576
__pyx_t_3 = PyNumber_Add(__pyx_v_start, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 70, __pyx_L1_error)
2577
__Pyx_GOTREF(__pyx_t_3);
2578
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2579
__Pyx_DECREF_SET(__pyx_v_m, __pyx_t_3);
2580
__pyx_t_3 = 0;
2581
2582
/* "nt.pyx":68
2583
* i = 1
2584
* m = start + (7 - m)
2585
* elif m <= 11: # <<<<<<<<<<<<<<
2586
* i = 2
2587
* m = start + (11 - m)
2588
*/
2589
goto __pyx_L5;
2590
}
2591
2592
/* "nt.pyx":71
2593
* i = 2
2594
* m = start + (11 - m)
2595
* elif m <= 13: # <<<<<<<<<<<<<<
2596
* i = 3
2597
* m = start + (13 - m)
2598
*/
2599
__pyx_t_3 = PyObject_RichCompare(__pyx_v_m, __pyx_int_13, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 71, __pyx_L1_error)
2600
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 71, __pyx_L1_error)
2601
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2602
if (__pyx_t_2) {
2603
2604
/* "nt.pyx":72
2605
* m = start + (11 - m)
2606
* elif m <= 13:
2607
* i = 3 # <<<<<<<<<<<<<<
2608
* m = start + (13 - m)
2609
* elif m <= 17:
2610
*/
2611
__Pyx_INCREF(__pyx_int_3);
2612
__Pyx_DECREF_SET(__pyx_v_i, __pyx_int_3);
2613
2614
/* "nt.pyx":73
2615
* elif m <= 13:
2616
* i = 3
2617
* m = start + (13 - m) # <<<<<<<<<<<<<<
2618
* elif m <= 17:
2619
* i = 4
2620
*/
2621
__pyx_t_3 = __Pyx_PyInt_SubtractCObj(__pyx_int_13, __pyx_v_m, 13, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 73, __pyx_L1_error)
2622
__Pyx_GOTREF(__pyx_t_3);
2623
__pyx_t_1 = PyNumber_Add(__pyx_v_start, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 73, __pyx_L1_error)
2624
__Pyx_GOTREF(__pyx_t_1);
2625
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2626
__Pyx_DECREF_SET(__pyx_v_m, __pyx_t_1);
2627
__pyx_t_1 = 0;
2628
2629
/* "nt.pyx":71
2630
* i = 2
2631
* m = start + (11 - m)
2632
* elif m <= 13: # <<<<<<<<<<<<<<
2633
* i = 3
2634
* m = start + (13 - m)
2635
*/
2636
goto __pyx_L5;
2637
}
2638
2639
/* "nt.pyx":74
2640
* i = 3
2641
* m = start + (13 - m)
2642
* elif m <= 17: # <<<<<<<<<<<<<<
2643
* i = 4
2644
* m = start + (17 - m)
2645
*/
2646
__pyx_t_1 = PyObject_RichCompare(__pyx_v_m, __pyx_int_17, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error)
2647
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 74, __pyx_L1_error)
2648
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2649
if (__pyx_t_2) {
2650
2651
/* "nt.pyx":75
2652
* m = start + (13 - m)
2653
* elif m <= 17:
2654
* i = 4 # <<<<<<<<<<<<<<
2655
* m = start + (17 - m)
2656
* elif m <= 19:
2657
*/
2658
__Pyx_INCREF(__pyx_int_4);
2659
__Pyx_DECREF_SET(__pyx_v_i, __pyx_int_4);
2660
2661
/* "nt.pyx":76
2662
* elif m <= 17:
2663
* i = 4
2664
* m = start + (17 - m) # <<<<<<<<<<<<<<
2665
* elif m <= 19:
2666
* i = 5
2667
*/
2668
__pyx_t_1 = __Pyx_PyInt_SubtractCObj(__pyx_int_17, __pyx_v_m, 17, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __pyx_L1_error)
2669
__Pyx_GOTREF(__pyx_t_1);
2670
__pyx_t_3 = PyNumber_Add(__pyx_v_start, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 76, __pyx_L1_error)
2671
__Pyx_GOTREF(__pyx_t_3);
2672
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2673
__Pyx_DECREF_SET(__pyx_v_m, __pyx_t_3);
2674
__pyx_t_3 = 0;
2675
2676
/* "nt.pyx":74
2677
* i = 3
2678
* m = start + (13 - m)
2679
* elif m <= 17: # <<<<<<<<<<<<<<
2680
* i = 4
2681
* m = start + (17 - m)
2682
*/
2683
goto __pyx_L5;
2684
}
2685
2686
/* "nt.pyx":77
2687
* i = 4
2688
* m = start + (17 - m)
2689
* elif m <= 19: # <<<<<<<<<<<<<<
2690
* i = 5
2691
* m = start + (19 - m)
2692
*/
2693
__pyx_t_3 = PyObject_RichCompare(__pyx_v_m, __pyx_int_19, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 77, __pyx_L1_error)
2694
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 77, __pyx_L1_error)
2695
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2696
if (__pyx_t_2) {
2697
2698
/* "nt.pyx":78
2699
* m = start + (17 - m)
2700
* elif m <= 19:
2701
* i = 5 # <<<<<<<<<<<<<<
2702
* m = start + (19 - m)
2703
* elif m <= 23:
2704
*/
2705
__Pyx_INCREF(__pyx_int_5);
2706
__Pyx_DECREF_SET(__pyx_v_i, __pyx_int_5);
2707
2708
/* "nt.pyx":79
2709
* elif m <= 19:
2710
* i = 5
2711
* m = start + (19 - m) # <<<<<<<<<<<<<<
2712
* elif m <= 23:
2713
* i = 6
2714
*/
2715
__pyx_t_3 = __Pyx_PyInt_SubtractCObj(__pyx_int_19, __pyx_v_m, 19, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 79, __pyx_L1_error)
2716
__Pyx_GOTREF(__pyx_t_3);
2717
__pyx_t_1 = PyNumber_Add(__pyx_v_start, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 79, __pyx_L1_error)
2718
__Pyx_GOTREF(__pyx_t_1);
2719
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2720
__Pyx_DECREF_SET(__pyx_v_m, __pyx_t_1);
2721
__pyx_t_1 = 0;
2722
2723
/* "nt.pyx":77
2724
* i = 4
2725
* m = start + (17 - m)
2726
* elif m <= 19: # <<<<<<<<<<<<<<
2727
* i = 5
2728
* m = start + (19 - m)
2729
*/
2730
goto __pyx_L5;
2731
}
2732
2733
/* "nt.pyx":80
2734
* i = 5
2735
* m = start + (19 - m)
2736
* elif m <= 23: # <<<<<<<<<<<<<<
2737
* i = 6
2738
* m = start + (23 - m)
2739
*/
2740
__pyx_t_1 = PyObject_RichCompare(__pyx_v_m, __pyx_int_23, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)
2741
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 80, __pyx_L1_error)
2742
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2743
if (__pyx_t_2) {
2744
2745
/* "nt.pyx":81
2746
* m = start + (19 - m)
2747
* elif m <= 23:
2748
* i = 6 # <<<<<<<<<<<<<<
2749
* m = start + (23 - m)
2750
* elif m <= 29:
2751
*/
2752
__Pyx_INCREF(__pyx_int_6);
2753
__Pyx_DECREF_SET(__pyx_v_i, __pyx_int_6);
2754
2755
/* "nt.pyx":82
2756
* elif m <= 23:
2757
* i = 6
2758
* m = start + (23 - m) # <<<<<<<<<<<<<<
2759
* elif m <= 29:
2760
* i = 7
2761
*/
2762
__pyx_t_1 = __Pyx_PyInt_SubtractCObj(__pyx_int_23, __pyx_v_m, 23, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error)
2763
__Pyx_GOTREF(__pyx_t_1);
2764
__pyx_t_3 = PyNumber_Add(__pyx_v_start, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 82, __pyx_L1_error)
2765
__Pyx_GOTREF(__pyx_t_3);
2766
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2767
__Pyx_DECREF_SET(__pyx_v_m, __pyx_t_3);
2768
__pyx_t_3 = 0;
2769
2770
/* "nt.pyx":80
2771
* i = 5
2772
* m = start + (19 - m)
2773
* elif m <= 23: # <<<<<<<<<<<<<<
2774
* i = 6
2775
* m = start + (23 - m)
2776
*/
2777
goto __pyx_L5;
2778
}
2779
2780
/* "nt.pyx":83
2781
* i = 6
2782
* m = start + (23 - m)
2783
* elif m <= 29: # <<<<<<<<<<<<<<
2784
* i = 7
2785
* m = start + (29 - m)
2786
*/
2787
__pyx_t_3 = PyObject_RichCompare(__pyx_v_m, __pyx_int_29, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 83, __pyx_L1_error)
2788
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 83, __pyx_L1_error)
2789
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2790
if (__pyx_t_2) {
2791
2792
/* "nt.pyx":84
2793
* m = start + (23 - m)
2794
* elif m <= 29:
2795
* i = 7 # <<<<<<<<<<<<<<
2796
* m = start + (29 - m)
2797
* if start <= 2 and N % 2 == 0:
2798
*/
2799
__Pyx_INCREF(__pyx_int_7);
2800
__Pyx_DECREF_SET(__pyx_v_i, __pyx_int_7);
2801
2802
/* "nt.pyx":85
2803
* elif m <= 29:
2804
* i = 7
2805
* m = start + (29 - m) # <<<<<<<<<<<<<<
2806
* if start <= 2 and N % 2 == 0:
2807
* return 2
2808
*/
2809
__pyx_t_3 = __Pyx_PyInt_SubtractCObj(__pyx_int_29, __pyx_v_m, 29, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 85, __pyx_L1_error)
2810
__Pyx_GOTREF(__pyx_t_3);
2811
__pyx_t_1 = PyNumber_Add(__pyx_v_start, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error)
2812
__Pyx_GOTREF(__pyx_t_1);
2813
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2814
__Pyx_DECREF_SET(__pyx_v_m, __pyx_t_1);
2815
__pyx_t_1 = 0;
2816
2817
/* "nt.pyx":83
2818
* i = 6
2819
* m = start + (23 - m)
2820
* elif m <= 29: # <<<<<<<<<<<<<<
2821
* i = 7
2822
* m = start + (29 - m)
2823
*/
2824
}
2825
__pyx_L5:;
2826
2827
/* "nt.pyx":60
2828
* i = 1
2829
* dif = [6, 4, 2, 4, 2, 4, 6, 2]
2830
* if start > 7: # <<<<<<<<<<<<<<
2831
* m = start % 30
2832
* if m <= 1:
2833
*/
2834
}
2835
2836
/* "nt.pyx":86
2837
* i = 7
2838
* m = start + (29 - m)
2839
* if start <= 2 and N % 2 == 0: # <<<<<<<<<<<<<<
2840
* return 2
2841
* if start <= 3 and N % 3 == 0:
2842
*/
2843
__pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_int_2, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error)
2844
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 86, __pyx_L1_error)
2845
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2846
if (__pyx_t_4) {
2847
} else {
2848
__pyx_t_2 = __pyx_t_4;
2849
goto __pyx_L7_bool_binop_done;
2850
}
2851
__pyx_t_1 = __Pyx_PyInt_RemainderObjC(__pyx_v_N, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error)
2852
__Pyx_GOTREF(__pyx_t_1);
2853
__pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 86, __pyx_L1_error)
2854
__Pyx_GOTREF(__pyx_t_3);
2855
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2856
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 86, __pyx_L1_error)
2857
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2858
__pyx_t_2 = __pyx_t_4;
2859
__pyx_L7_bool_binop_done:;
2860
if (__pyx_t_2) {
2861
2862
/* "nt.pyx":87
2863
* m = start + (29 - m)
2864
* if start <= 2 and N % 2 == 0:
2865
* return 2 # <<<<<<<<<<<<<<
2866
* if start <= 3 and N % 3 == 0:
2867
* return 3
2868
*/
2869
__Pyx_XDECREF(__pyx_r);
2870
__Pyx_INCREF(__pyx_int_2);
2871
__pyx_r = __pyx_int_2;
2872
goto __pyx_L0;
2873
2874
/* "nt.pyx":86
2875
* i = 7
2876
* m = start + (29 - m)
2877
* if start <= 2 and N % 2 == 0: # <<<<<<<<<<<<<<
2878
* return 2
2879
* if start <= 3 and N % 3 == 0:
2880
*/
2881
}
2882
2883
/* "nt.pyx":88
2884
* if start <= 2 and N % 2 == 0:
2885
* return 2
2886
* if start <= 3 and N % 3 == 0: # <<<<<<<<<<<<<<
2887
* return 3
2888
* if start <= 5 and N % 5 == 0:
2889
*/
2890
__pyx_t_3 = PyObject_RichCompare(__pyx_v_start, __pyx_int_3, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 88, __pyx_L1_error)
2891
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 88, __pyx_L1_error)
2892
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2893
if (__pyx_t_4) {
2894
} else {
2895
__pyx_t_2 = __pyx_t_4;
2896
goto __pyx_L10_bool_binop_done;
2897
}
2898
__pyx_t_3 = __Pyx_PyInt_RemainderObjC(__pyx_v_N, __pyx_int_3, 3, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 88, __pyx_L1_error)
2899
__Pyx_GOTREF(__pyx_t_3);
2900
__pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_t_3, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error)
2901
__Pyx_GOTREF(__pyx_t_1);
2902
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2903
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 88, __pyx_L1_error)
2904
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2905
__pyx_t_2 = __pyx_t_4;
2906
__pyx_L10_bool_binop_done:;
2907
if (__pyx_t_2) {
2908
2909
/* "nt.pyx":89
2910
* return 2
2911
* if start <= 3 and N % 3 == 0:
2912
* return 3 # <<<<<<<<<<<<<<
2913
* if start <= 5 and N % 5 == 0:
2914
* return 5
2915
*/
2916
__Pyx_XDECREF(__pyx_r);
2917
__Pyx_INCREF(__pyx_int_3);
2918
__pyx_r = __pyx_int_3;
2919
goto __pyx_L0;
2920
2921
/* "nt.pyx":88
2922
* if start <= 2 and N % 2 == 0:
2923
* return 2
2924
* if start <= 3 and N % 3 == 0: # <<<<<<<<<<<<<<
2925
* return 3
2926
* if start <= 5 and N % 5 == 0:
2927
*/
2928
}
2929
2930
/* "nt.pyx":90
2931
* if start <= 3 and N % 3 == 0:
2932
* return 3
2933
* if start <= 5 and N % 5 == 0: # <<<<<<<<<<<<<<
2934
* return 5
2935
* limit = round(sqrt(N))
2936
*/
2937
__pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_int_5, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error)
2938
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 90, __pyx_L1_error)
2939
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2940
if (__pyx_t_4) {
2941
} else {
2942
__pyx_t_2 = __pyx_t_4;
2943
goto __pyx_L13_bool_binop_done;
2944
}
2945
__pyx_t_1 = __Pyx_PyInt_RemainderObjC(__pyx_v_N, __pyx_int_5, 5, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error)
2946
__Pyx_GOTREF(__pyx_t_1);
2947
__pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 90, __pyx_L1_error)
2948
__Pyx_GOTREF(__pyx_t_3);
2949
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2950
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 90, __pyx_L1_error)
2951
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2952
__pyx_t_2 = __pyx_t_4;
2953
__pyx_L13_bool_binop_done:;
2954
if (__pyx_t_2) {
2955
2956
/* "nt.pyx":91
2957
* return 3
2958
* if start <= 5 and N % 5 == 0:
2959
* return 5 # <<<<<<<<<<<<<<
2960
* limit = round(sqrt(N))
2961
* if bound != 0 and bound < limit:
2962
*/
2963
__Pyx_XDECREF(__pyx_r);
2964
__Pyx_INCREF(__pyx_int_5);
2965
__pyx_r = __pyx_int_5;
2966
goto __pyx_L0;
2967
2968
/* "nt.pyx":90
2969
* if start <= 3 and N % 3 == 0:
2970
* return 3
2971
* if start <= 5 and N % 5 == 0: # <<<<<<<<<<<<<<
2972
* return 5
2973
* limit = round(sqrt(N))
2974
*/
2975
}
2976
2977
/* "nt.pyx":92
2978
* if start <= 5 and N % 5 == 0:
2979
* return 5
2980
* limit = round(sqrt(N)) # <<<<<<<<<<<<<<
2981
* if bound != 0 and bound < limit:
2982
* limit = bound
2983
*/
2984
__Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_sqrt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error)
2985
__Pyx_GOTREF(__pyx_t_1);
2986
__pyx_t_5 = NULL;
2987
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
2988
__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
2989
if (likely(__pyx_t_5)) {
2990
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
2991
__Pyx_INCREF(__pyx_t_5);
2992
__Pyx_INCREF(function);
2993
__Pyx_DECREF_SET(__pyx_t_1, function);
2994
}
2995
}
2996
__pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_5, __pyx_v_N) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_N);
2997
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
2998
if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 92, __pyx_L1_error)
2999
__Pyx_GOTREF(__pyx_t_3);
3000
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3001
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_round, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error)
3002
__Pyx_GOTREF(__pyx_t_1);
3003
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3004
__pyx_v_limit = __pyx_t_1;
3005
__pyx_t_1 = 0;
3006
3007
/* "nt.pyx":93
3008
* return 5
3009
* limit = round(sqrt(N))
3010
* if bound != 0 and bound < limit: # <<<<<<<<<<<<<<
3011
* limit = bound
3012
* while m <= limit:
3013
*/
3014
__pyx_t_1 = __Pyx_PyInt_NeObjC(__pyx_v_bound, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)
3015
__Pyx_GOTREF(__pyx_t_1);
3016
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 93, __pyx_L1_error)
3017
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3018
if (__pyx_t_4) {
3019
} else {
3020
__pyx_t_2 = __pyx_t_4;
3021
goto __pyx_L16_bool_binop_done;
3022
}
3023
__pyx_t_1 = PyObject_RichCompare(__pyx_v_bound, __pyx_v_limit, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error)
3024
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 93, __pyx_L1_error)
3025
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3026
__pyx_t_2 = __pyx_t_4;
3027
__pyx_L16_bool_binop_done:;
3028
if (__pyx_t_2) {
3029
3030
/* "nt.pyx":94
3031
* limit = round(sqrt(N))
3032
* if bound != 0 and bound < limit:
3033
* limit = bound # <<<<<<<<<<<<<<
3034
* while m <= limit:
3035
* if N % m == 0:
3036
*/
3037
__Pyx_INCREF(__pyx_v_bound);
3038
__Pyx_DECREF_SET(__pyx_v_limit, __pyx_v_bound);
3039
3040
/* "nt.pyx":93
3041
* return 5
3042
* limit = round(sqrt(N))
3043
* if bound != 0 and bound < limit: # <<<<<<<<<<<<<<
3044
* limit = bound
3045
* while m <= limit:
3046
*/
3047
}
3048
3049
/* "nt.pyx":95
3050
* if bound != 0 and bound < limit:
3051
* limit = bound
3052
* while m <= limit: # <<<<<<<<<<<<<<
3053
* if N % m == 0:
3054
* return m
3055
*/
3056
while (1) {
3057
__pyx_t_1 = PyObject_RichCompare(__pyx_v_m, __pyx_v_limit, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 95, __pyx_L1_error)
3058
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 95, __pyx_L1_error)
3059
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3060
if (!__pyx_t_2) break;
3061
3062
/* "nt.pyx":96
3063
* limit = bound
3064
* while m <= limit:
3065
* if N % m == 0: # <<<<<<<<<<<<<<
3066
* return m
3067
* m += dif[i % 8]
3068
*/
3069
__pyx_t_1 = PyNumber_Remainder(__pyx_v_N, __pyx_v_m); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error)
3070
__Pyx_GOTREF(__pyx_t_1);
3071
__pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 96, __pyx_L1_error)
3072
__Pyx_GOTREF(__pyx_t_3);
3073
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3074
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 96, __pyx_L1_error)
3075
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3076
if (__pyx_t_2) {
3077
3078
/* "nt.pyx":97
3079
* while m <= limit:
3080
* if N % m == 0:
3081
* return m # <<<<<<<<<<<<<<
3082
* m += dif[i % 8]
3083
* i += 1
3084
*/
3085
__Pyx_XDECREF(__pyx_r);
3086
__Pyx_INCREF(__pyx_v_m);
3087
__pyx_r = __pyx_v_m;
3088
goto __pyx_L0;
3089
3090
/* "nt.pyx":96
3091
* limit = bound
3092
* while m <= limit:
3093
* if N % m == 0: # <<<<<<<<<<<<<<
3094
* return m
3095
* m += dif[i % 8]
3096
*/
3097
}
3098
3099
/* "nt.pyx":98
3100
* if N % m == 0:
3101
* return m
3102
* m += dif[i % 8] # <<<<<<<<<<<<<<
3103
* i += 1
3104
*
3105
*/
3106
__pyx_t_3 = __Pyx_PyInt_RemainderObjC(__pyx_v_i, __pyx_int_8, 8, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 98, __pyx_L1_error)
3107
__Pyx_GOTREF(__pyx_t_3);
3108
__pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_dif, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 98, __pyx_L1_error)
3109
__Pyx_GOTREF(__pyx_t_1);
3110
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3111
__pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_m, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 98, __pyx_L1_error)
3112
__Pyx_GOTREF(__pyx_t_3);
3113
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3114
__Pyx_DECREF_SET(__pyx_v_m, __pyx_t_3);
3115
__pyx_t_3 = 0;
3116
3117
/* "nt.pyx":99
3118
* return m
3119
* m += dif[i % 8]
3120
* i += 1 # <<<<<<<<<<<<<<
3121
*
3122
* return N
3123
*/
3124
__pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 99, __pyx_L1_error)
3125
__Pyx_GOTREF(__pyx_t_3);
3126
__Pyx_DECREF_SET(__pyx_v_i, __pyx_t_3);
3127
__pyx_t_3 = 0;
3128
}
3129
3130
/* "nt.pyx":101
3131
* i += 1
3132
*
3133
* return N # <<<<<<<<<<<<<<
3134
*
3135
*
3136
*/
3137
__Pyx_XDECREF(__pyx_r);
3138
__Pyx_INCREF(__pyx_v_N);
3139
__pyx_r = __pyx_v_N;
3140
goto __pyx_L0;
3141
3142
/* "nt.pyx":54
3143
*
3144
*
3145
* def trial_division(N: int, bound: int = 0, start: int = 2) -> int: # <<<<<<<<<<<<<<
3146
* if N <= 1:
3147
* return N
3148
*/
3149
3150
/* function exit code */
3151
__pyx_L1_error:;
3152
__Pyx_XDECREF(__pyx_t_1);
3153
__Pyx_XDECREF(__pyx_t_3);
3154
__Pyx_XDECREF(__pyx_t_5);
3155
__Pyx_AddTraceback("nt.trial_division", __pyx_clineno, __pyx_lineno, __pyx_filename);
3156
__pyx_r = NULL;
3157
__pyx_L0:;
3158
__Pyx_XDECREF(__pyx_v_m);
3159
__Pyx_XDECREF(__pyx_v_i);
3160
__Pyx_XDECREF(__pyx_v_dif);
3161
__Pyx_XDECREF(__pyx_v_limit);
3162
__Pyx_XGIVEREF(__pyx_r);
3163
__Pyx_RefNannyFinishContext();
3164
return __pyx_r;
3165
}
3166
3167
/* "nt.pyx":104
3168
*
3169
*
3170
* def is_prime(N: int) -> bool: # <<<<<<<<<<<<<<
3171
* return N > 1 and trial_division(N) == N
3172
*
3173
*/
3174
3175
/* Python wrapper */
3176
static PyObject *__pyx_pw_2nt_9is_prime(PyObject *__pyx_self, PyObject *__pyx_v_N); /*proto*/
3177
static PyMethodDef __pyx_mdef_2nt_9is_prime = {"is_prime", (PyCFunction)__pyx_pw_2nt_9is_prime, METH_O, 0};
3178
static PyObject *__pyx_pw_2nt_9is_prime(PyObject *__pyx_self, PyObject *__pyx_v_N) {
3179
PyObject *__pyx_r = 0;
3180
__Pyx_RefNannyDeclarations
3181
__Pyx_RefNannySetupContext("is_prime (wrapper)", 0);
3182
__pyx_r = __pyx_pf_2nt_8is_prime(__pyx_self, ((PyObject *)__pyx_v_N));
3183
3184
/* function exit code */
3185
__Pyx_RefNannyFinishContext();
3186
return __pyx_r;
3187
}
3188
3189
static PyObject *__pyx_pf_2nt_8is_prime(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_N) {
3190
PyObject *__pyx_r = NULL;
3191
__Pyx_RefNannyDeclarations
3192
PyObject *__pyx_t_1 = NULL;
3193
PyObject *__pyx_t_2 = NULL;
3194
int __pyx_t_3;
3195
PyObject *__pyx_t_4 = NULL;
3196
PyObject *__pyx_t_5 = NULL;
3197
int __pyx_lineno = 0;
3198
const char *__pyx_filename = NULL;
3199
int __pyx_clineno = 0;
3200
__Pyx_RefNannySetupContext("is_prime", 0);
3201
3202
/* "nt.pyx":105
3203
*
3204
* def is_prime(N: int) -> bool:
3205
* return N > 1 and trial_division(N) == N # <<<<<<<<<<<<<<
3206
*
3207
*
3208
*/
3209
__Pyx_XDECREF(__pyx_r);
3210
__pyx_t_2 = PyObject_RichCompare(__pyx_v_N, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 105, __pyx_L1_error)
3211
__pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 105, __pyx_L1_error)
3212
if (__pyx_t_3) {
3213
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3214
} else {
3215
__Pyx_INCREF(__pyx_t_2);
3216
__pyx_t_1 = __pyx_t_2;
3217
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3218
goto __pyx_L3_bool_binop_done;
3219
}
3220
__Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_trial_division); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error)
3221
__Pyx_GOTREF(__pyx_t_4);
3222
__pyx_t_5 = NULL;
3223
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
3224
__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
3225
if (likely(__pyx_t_5)) {
3226
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
3227
__Pyx_INCREF(__pyx_t_5);
3228
__Pyx_INCREF(function);
3229
__Pyx_DECREF_SET(__pyx_t_4, function);
3230
}
3231
}
3232
__pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_v_N) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_N);
3233
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
3234
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 105, __pyx_L1_error)
3235
__Pyx_GOTREF(__pyx_t_2);
3236
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
3237
__pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_v_N, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error)
3238
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3239
__Pyx_INCREF(__pyx_t_4);
3240
__pyx_t_1 = __pyx_t_4;
3241
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
3242
__pyx_L3_bool_binop_done:;
3243
__pyx_r = __pyx_t_1;
3244
__pyx_t_1 = 0;
3245
goto __pyx_L0;
3246
3247
/* "nt.pyx":104
3248
*
3249
*
3250
* def is_prime(N: int) -> bool: # <<<<<<<<<<<<<<
3251
* return N > 1 and trial_division(N) == N
3252
*
3253
*/
3254
3255
/* function exit code */
3256
__pyx_L1_error:;
3257
__Pyx_XDECREF(__pyx_t_1);
3258
__Pyx_XDECREF(__pyx_t_2);
3259
__Pyx_XDECREF(__pyx_t_4);
3260
__Pyx_XDECREF(__pyx_t_5);
3261
__Pyx_AddTraceback("nt.is_prime", __pyx_clineno, __pyx_lineno, __pyx_filename);
3262
__pyx_r = NULL;
3263
__pyx_L0:;
3264
__Pyx_XGIVEREF(__pyx_r);
3265
__Pyx_RefNannyFinishContext();
3266
return __pyx_r;
3267
}
3268
3269
/* "nt.pyx":108
3270
*
3271
*
3272
* def pi(n: int = 100000) -> int: # <<<<<<<<<<<<<<
3273
* s = 0
3274
* for i in range(1, n + 1):
3275
*/
3276
3277
/* Python wrapper */
3278
static PyObject *__pyx_pw_2nt_11pi(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
3279
static PyMethodDef __pyx_mdef_2nt_11pi = {"pi", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_2nt_11pi, METH_VARARGS|METH_KEYWORDS, 0};
3280
static PyObject *__pyx_pw_2nt_11pi(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
3281
PyObject *__pyx_v_n = 0;
3282
int __pyx_lineno = 0;
3283
const char *__pyx_filename = NULL;
3284
int __pyx_clineno = 0;
3285
PyObject *__pyx_r = 0;
3286
__Pyx_RefNannyDeclarations
3287
__Pyx_RefNannySetupContext("pi (wrapper)", 0);
3288
{
3289
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_n,0};
3290
PyObject* values[1] = {0};
3291
values[0] = ((PyObject *)__pyx_int_100000);
3292
if (unlikely(__pyx_kwds)) {
3293
Py_ssize_t kw_args;
3294
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
3295
switch (pos_args) {
3296
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
3297
CYTHON_FALLTHROUGH;
3298
case 0: break;
3299
default: goto __pyx_L5_argtuple_error;
3300
}
3301
kw_args = PyDict_Size(__pyx_kwds);
3302
switch (pos_args) {
3303
case 0:
3304
if (kw_args > 0) {
3305
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n);
3306
if (value) { values[0] = value; kw_args--; }
3307
}
3308
}
3309
if (unlikely(kw_args > 0)) {
3310
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "pi") < 0)) __PYX_ERR(0, 108, __pyx_L3_error)
3311
}
3312
} else {
3313
switch (PyTuple_GET_SIZE(__pyx_args)) {
3314
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
3315
CYTHON_FALLTHROUGH;
3316
case 0: break;
3317
default: goto __pyx_L5_argtuple_error;
3318
}
3319
}
3320
__pyx_v_n = values[0];
3321
}
3322
goto __pyx_L4_argument_unpacking_done;
3323
__pyx_L5_argtuple_error:;
3324
__Pyx_RaiseArgtupleInvalid("pi", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 108, __pyx_L3_error)
3325
__pyx_L3_error:;
3326
__Pyx_AddTraceback("nt.pi", __pyx_clineno, __pyx_lineno, __pyx_filename);
3327
__Pyx_RefNannyFinishContext();
3328
return NULL;
3329
__pyx_L4_argument_unpacking_done:;
3330
__pyx_r = __pyx_pf_2nt_10pi(__pyx_self, __pyx_v_n);
3331
3332
/* function exit code */
3333
__Pyx_RefNannyFinishContext();
3334
return __pyx_r;
3335
}
3336
3337
static PyObject *__pyx_pf_2nt_10pi(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_n) {
3338
PyObject *__pyx_v_s = NULL;
3339
PyObject *__pyx_v_i = NULL;
3340
PyObject *__pyx_r = NULL;
3341
__Pyx_RefNannyDeclarations
3342
PyObject *__pyx_t_1 = NULL;
3343
PyObject *__pyx_t_2 = NULL;
3344
Py_ssize_t __pyx_t_3;
3345
PyObject *(*__pyx_t_4)(PyObject *);
3346
PyObject *__pyx_t_5 = NULL;
3347
PyObject *__pyx_t_6 = NULL;
3348
int __pyx_t_7;
3349
int __pyx_lineno = 0;
3350
const char *__pyx_filename = NULL;
3351
int __pyx_clineno = 0;
3352
__Pyx_RefNannySetupContext("pi", 0);
3353
3354
/* "nt.pyx":109
3355
*
3356
* def pi(n: int = 100000) -> int:
3357
* s = 0 # <<<<<<<<<<<<<<
3358
* for i in range(1, n + 1):
3359
* if is_prime(i):
3360
*/
3361
__Pyx_INCREF(__pyx_int_0);
3362
__pyx_v_s = __pyx_int_0;
3363
3364
/* "nt.pyx":110
3365
* def pi(n: int = 100000) -> int:
3366
* s = 0
3367
* for i in range(1, n + 1): # <<<<<<<<<<<<<<
3368
* if is_prime(i):
3369
* s += 1
3370
*/
3371
__pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_n, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error)
3372
__Pyx_GOTREF(__pyx_t_1);
3373
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 110, __pyx_L1_error)
3374
__Pyx_GOTREF(__pyx_t_2);
3375
__Pyx_INCREF(__pyx_int_1);
3376
__Pyx_GIVEREF(__pyx_int_1);
3377
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_1);
3378
__Pyx_GIVEREF(__pyx_t_1);
3379
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
3380
__pyx_t_1 = 0;
3381
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error)
3382
__Pyx_GOTREF(__pyx_t_1);
3383
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3384
if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
3385
__pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
3386
__pyx_t_4 = NULL;
3387
} else {
3388
__pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 110, __pyx_L1_error)
3389
__Pyx_GOTREF(__pyx_t_2);
3390
__pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 110, __pyx_L1_error)
3391
}
3392
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3393
for (;;) {
3394
if (likely(!__pyx_t_4)) {
3395
if (likely(PyList_CheckExact(__pyx_t_2))) {
3396
if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
3397
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
3398
__pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 110, __pyx_L1_error)
3399
#else
3400
__pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error)
3401
__Pyx_GOTREF(__pyx_t_1);
3402
#endif
3403
} else {
3404
if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
3405
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
3406
__pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 110, __pyx_L1_error)
3407
#else
3408
__pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error)
3409
__Pyx_GOTREF(__pyx_t_1);
3410
#endif
3411
}
3412
} else {
3413
__pyx_t_1 = __pyx_t_4(__pyx_t_2);
3414
if (unlikely(!__pyx_t_1)) {
3415
PyObject* exc_type = PyErr_Occurred();
3416
if (exc_type) {
3417
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
3418
else __PYX_ERR(0, 110, __pyx_L1_error)
3419
}
3420
break;
3421
}
3422
__Pyx_GOTREF(__pyx_t_1);
3423
}
3424
__Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1);
3425
__pyx_t_1 = 0;
3426
3427
/* "nt.pyx":111
3428
* s = 0
3429
* for i in range(1, n + 1):
3430
* if is_prime(i): # <<<<<<<<<<<<<<
3431
* s += 1
3432
* return s
3433
*/
3434
__Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_is_prime); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 111, __pyx_L1_error)
3435
__Pyx_GOTREF(__pyx_t_5);
3436
__pyx_t_6 = NULL;
3437
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
3438
__pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
3439
if (likely(__pyx_t_6)) {
3440
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
3441
__Pyx_INCREF(__pyx_t_6);
3442
__Pyx_INCREF(function);
3443
__Pyx_DECREF_SET(__pyx_t_5, function);
3444
}
3445
}
3446
__pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_v_i) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_i);
3447
__Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
3448
if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 111, __pyx_L1_error)
3449
__Pyx_GOTREF(__pyx_t_1);
3450
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
3451
__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 111, __pyx_L1_error)
3452
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3453
if (__pyx_t_7) {
3454
3455
/* "nt.pyx":112
3456
* for i in range(1, n + 1):
3457
* if is_prime(i):
3458
* s += 1 # <<<<<<<<<<<<<<
3459
* return s
3460
*/
3461
__pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_s, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 112, __pyx_L1_error)
3462
__Pyx_GOTREF(__pyx_t_1);
3463
__Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1);
3464
__pyx_t_1 = 0;
3465
3466
/* "nt.pyx":111
3467
* s = 0
3468
* for i in range(1, n + 1):
3469
* if is_prime(i): # <<<<<<<<<<<<<<
3470
* s += 1
3471
* return s
3472
*/
3473
}
3474
3475
/* "nt.pyx":110
3476
* def pi(n: int = 100000) -> int:
3477
* s = 0
3478
* for i in range(1, n + 1): # <<<<<<<<<<<<<<
3479
* if is_prime(i):
3480
* s += 1
3481
*/
3482
}
3483
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3484
3485
/* "nt.pyx":113
3486
* if is_prime(i):
3487
* s += 1
3488
* return s # <<<<<<<<<<<<<<
3489
*/
3490
__Pyx_XDECREF(__pyx_r);
3491
__Pyx_INCREF(__pyx_v_s);
3492
__pyx_r = __pyx_v_s;
3493
goto __pyx_L0;
3494
3495
/* "nt.pyx":108
3496
*
3497
*
3498
* def pi(n: int = 100000) -> int: # <<<<<<<<<<<<<<
3499
* s = 0
3500
* for i in range(1, n + 1):
3501
*/
3502
3503
/* function exit code */
3504
__pyx_L1_error:;
3505
__Pyx_XDECREF(__pyx_t_1);
3506
__Pyx_XDECREF(__pyx_t_2);
3507
__Pyx_XDECREF(__pyx_t_5);
3508
__Pyx_XDECREF(__pyx_t_6);
3509
__Pyx_AddTraceback("nt.pi", __pyx_clineno, __pyx_lineno, __pyx_filename);
3510
__pyx_r = NULL;
3511
__pyx_L0:;
3512
__Pyx_XDECREF(__pyx_v_s);
3513
__Pyx_XDECREF(__pyx_v_i);
3514
__Pyx_XGIVEREF(__pyx_r);
3515
__Pyx_RefNannyFinishContext();
3516
return __pyx_r;
3517
}
3518
3519
static PyMethodDef __pyx_methods[] = {
3520
{"gcd", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_2nt_1gcd, METH_VARARGS|METH_KEYWORDS, 0},
3521
{"inverse_mod", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_2nt_5inverse_mod, METH_VARARGS|METH_KEYWORDS, __pyx_doc_2nt_4inverse_mod},
3522
{0, 0, 0, 0}
3523
};
3524
3525
#if PY_MAJOR_VERSION >= 3
3526
#if CYTHON_PEP489_MULTI_PHASE_INIT
3527
static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
3528
static int __pyx_pymod_exec_nt(PyObject* module); /*proto*/
3529
static PyModuleDef_Slot __pyx_moduledef_slots[] = {
3530
{Py_mod_create, (void*)__pyx_pymod_create},
3531
{Py_mod_exec, (void*)__pyx_pymod_exec_nt},
3532
{0, NULL}
3533
};
3534
#endif
3535
3536
static struct PyModuleDef __pyx_moduledef = {
3537
PyModuleDef_HEAD_INIT,
3538
"nt",
3539
0, /* m_doc */
3540
#if CYTHON_PEP489_MULTI_PHASE_INIT
3541
0, /* m_size */
3542
#else
3543
-1, /* m_size */
3544
#endif
3545
__pyx_methods /* m_methods */,
3546
#if CYTHON_PEP489_MULTI_PHASE_INIT
3547
__pyx_moduledef_slots, /* m_slots */
3548
#else
3549
NULL, /* m_reload */
3550
#endif
3551
NULL, /* m_traverse */
3552
NULL, /* m_clear */
3553
NULL /* m_free */
3554
};
3555
#endif
3556
#ifndef CYTHON_SMALL_CODE
3557
#if defined(__clang__)
3558
#define CYTHON_SMALL_CODE
3559
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
3560
#define CYTHON_SMALL_CODE __attribute__((cold))
3561
#else
3562
#define CYTHON_SMALL_CODE
3563
#endif
3564
#endif
3565
3566
static __Pyx_StringTabEntry __pyx_string_tab[] = {
3567
{&__pyx_n_s_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 0, 1, 1},
3568
{&__pyx_n_s_Tuple, __pyx_k_Tuple, sizeof(__pyx_k_Tuple), 0, 0, 1, 1},
3569
{&__pyx_n_s_ZeroDivisionError, __pyx_k_ZeroDivisionError, sizeof(__pyx_k_ZeroDivisionError), 0, 0, 1, 1},
3570
{&__pyx_n_s_a, __pyx_k_a, sizeof(__pyx_k_a), 0, 0, 1, 1},
3571
{&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
3572
{&__pyx_n_s_bound, __pyx_k_bound, sizeof(__pyx_k_bound), 0, 0, 1, 1},
3573
{&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
3574
{&__pyx_n_s_cx, __pyx_k_cx, sizeof(__pyx_k_cx), 0, 0, 1, 1},
3575
{&__pyx_n_s_cy, __pyx_k_cy, sizeof(__pyx_k_cy), 0, 0, 1, 1},
3576
{&__pyx_n_s_dif, __pyx_k_dif, sizeof(__pyx_k_dif), 0, 0, 1, 1},
3577
{&__pyx_n_s_g, __pyx_k_g, sizeof(__pyx_k_g), 0, 0, 1, 1},
3578
{&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
3579
{&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
3580
{&__pyx_n_s_is_prime, __pyx_k_is_prime, sizeof(__pyx_k_is_prime), 0, 0, 1, 1},
3581
{&__pyx_n_s_limit, __pyx_k_limit, sizeof(__pyx_k_limit), 0, 0, 1, 1},
3582
{&__pyx_n_s_m, __pyx_k_m, sizeof(__pyx_k_m), 0, 0, 1, 1},
3583
{&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
3584
{&__pyx_n_s_math, __pyx_k_math, sizeof(__pyx_k_math), 0, 0, 1, 1},
3585
{&__pyx_n_s_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 0, 1, 1},
3586
{&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
3587
{&__pyx_n_s_nt, __pyx_k_nt, sizeof(__pyx_k_nt), 0, 0, 1, 1},
3588
{&__pyx_kp_s_nt_pyx, __pyx_k_nt_pyx, sizeof(__pyx_k_nt_pyx), 0, 0, 1, 0},
3589
{&__pyx_n_s_pi, __pyx_k_pi, sizeof(__pyx_k_pi), 0, 0, 1, 1},
3590
{&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
3591
{&__pyx_n_s_round, __pyx_k_round, sizeof(__pyx_k_round), 0, 0, 1, 1},
3592
{&__pyx_n_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 1},
3593
{&__pyx_n_s_sqrt, __pyx_k_sqrt, sizeof(__pyx_k_sqrt), 0, 0, 1, 1},
3594
{&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
3595
{&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
3596
{&__pyx_n_s_trial_division, __pyx_k_trial_division, sizeof(__pyx_k_trial_division), 0, 0, 1, 1},
3597
{&__pyx_n_s_typing, __pyx_k_typing, sizeof(__pyx_k_typing), 0, 0, 1, 1},
3598
{&__pyx_n_s_xgcd, __pyx_k_xgcd, sizeof(__pyx_k_xgcd), 0, 0, 1, 1},
3599
{0, 0, 0, 0, 0, 0, 0}
3600
};
3601
static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
3602
__pyx_builtin_ZeroDivisionError = __Pyx_GetBuiltinName(__pyx_n_s_ZeroDivisionError); if (!__pyx_builtin_ZeroDivisionError) __PYX_ERR(0, 47, __pyx_L1_error)
3603
__pyx_builtin_round = __Pyx_GetBuiltinName(__pyx_n_s_round); if (!__pyx_builtin_round) __PYX_ERR(0, 92, __pyx_L1_error)
3604
__pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 110, __pyx_L1_error)
3605
return 0;
3606
__pyx_L1_error:;
3607
return -1;
3608
}
3609
3610
static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
3611
__Pyx_RefNannyDeclarations
3612
__Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
3613
3614
/* "nt.pyx":32
3615
* return a
3616
*
3617
* def xgcd(int a, int b) -> Tuple[int, int, int]: # <<<<<<<<<<<<<<
3618
* cdef int cx, cy, g
3619
* g = xgcd_c(a,b,&cx,&cy)
3620
*/
3621
__pyx_tuple_ = PyTuple_Pack(5, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_cx, __pyx_n_s_cy, __pyx_n_s_g); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 32, __pyx_L1_error)
3622
__Pyx_GOTREF(__pyx_tuple_);
3623
__Pyx_GIVEREF(__pyx_tuple_);
3624
__pyx_codeobj__2 = (PyObject*)__Pyx_PyCode_New(2, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple_, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_nt_pyx, __pyx_n_s_xgcd, 32, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__2)) __PYX_ERR(0, 32, __pyx_L1_error)
3625
3626
/* "nt.pyx":54
3627
*
3628
*
3629
* def trial_division(N: int, bound: int = 0, start: int = 2) -> int: # <<<<<<<<<<<<<<
3630
* if N <= 1:
3631
* return N
3632
*/
3633
__pyx_tuple__3 = PyTuple_Pack(7, __pyx_n_s_N, __pyx_n_s_bound, __pyx_n_s_start, __pyx_n_s_m, __pyx_n_s_i, __pyx_n_s_dif, __pyx_n_s_limit); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 54, __pyx_L1_error)
3634
__Pyx_GOTREF(__pyx_tuple__3);
3635
__Pyx_GIVEREF(__pyx_tuple__3);
3636
__pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__3, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_nt_pyx, __pyx_n_s_trial_division, 54, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 54, __pyx_L1_error)
3637
3638
/* "nt.pyx":104
3639
*
3640
*
3641
* def is_prime(N: int) -> bool: # <<<<<<<<<<<<<<
3642
* return N > 1 and trial_division(N) == N
3643
*
3644
*/
3645
__pyx_tuple__5 = PyTuple_Pack(1, __pyx_n_s_N); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 104, __pyx_L1_error)
3646
__Pyx_GOTREF(__pyx_tuple__5);
3647
__Pyx_GIVEREF(__pyx_tuple__5);
3648
__pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__5, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_nt_pyx, __pyx_n_s_is_prime, 104, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 104, __pyx_L1_error)
3649
3650
/* "nt.pyx":108
3651
*
3652
*
3653
* def pi(n: int = 100000) -> int: # <<<<<<<<<<<<<<
3654
* s = 0
3655
* for i in range(1, n + 1):
3656
*/
3657
__pyx_tuple__7 = PyTuple_Pack(3, __pyx_n_s_n, __pyx_n_s_s, __pyx_n_s_i); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 108, __pyx_L1_error)
3658
__Pyx_GOTREF(__pyx_tuple__7);
3659
__Pyx_GIVEREF(__pyx_tuple__7);
3660
__pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 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_nt_pyx, __pyx_n_s_pi, 108, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) __PYX_ERR(0, 108, __pyx_L1_error)
3661
__Pyx_RefNannyFinishContext();
3662
return 0;
3663
__pyx_L1_error:;
3664
__Pyx_RefNannyFinishContext();
3665
return -1;
3666
}
3667
3668
static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
3669
if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
3670
__pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
3671
__pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
3672
__pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error)
3673
__pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error)
3674
__pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) __PYX_ERR(0, 1, __pyx_L1_error)
3675
__pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) __PYX_ERR(0, 1, __pyx_L1_error)
3676
__pyx_int_6 = PyInt_FromLong(6); if (unlikely(!__pyx_int_6)) __PYX_ERR(0, 1, __pyx_L1_error)
3677
__pyx_int_7 = PyInt_FromLong(7); if (unlikely(!__pyx_int_7)) __PYX_ERR(0, 1, __pyx_L1_error)
3678
__pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) __PYX_ERR(0, 1, __pyx_L1_error)
3679
__pyx_int_11 = PyInt_FromLong(11); if (unlikely(!__pyx_int_11)) __PYX_ERR(0, 1, __pyx_L1_error)
3680
__pyx_int_13 = PyInt_FromLong(13); if (unlikely(!__pyx_int_13)) __PYX_ERR(0, 1, __pyx_L1_error)
3681
__pyx_int_17 = PyInt_FromLong(17); if (unlikely(!__pyx_int_17)) __PYX_ERR(0, 1, __pyx_L1_error)
3682
__pyx_int_19 = PyInt_FromLong(19); if (unlikely(!__pyx_int_19)) __PYX_ERR(0, 1, __pyx_L1_error)
3683
__pyx_int_23 = PyInt_FromLong(23); if (unlikely(!__pyx_int_23)) __PYX_ERR(0, 1, __pyx_L1_error)
3684
__pyx_int_29 = PyInt_FromLong(29); if (unlikely(!__pyx_int_29)) __PYX_ERR(0, 1, __pyx_L1_error)
3685
__pyx_int_30 = PyInt_FromLong(30); if (unlikely(!__pyx_int_30)) __PYX_ERR(0, 1, __pyx_L1_error)
3686
__pyx_int_100000 = PyInt_FromLong(100000L); if (unlikely(!__pyx_int_100000)) __PYX_ERR(0, 1, __pyx_L1_error)
3687
return 0;
3688
__pyx_L1_error:;
3689
return -1;
3690
}
3691
3692
static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
3693
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
3694
static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
3695
static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
3696
static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
3697
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
3698
static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/
3699
3700
static int __Pyx_modinit_global_init_code(void) {
3701
__Pyx_RefNannyDeclarations
3702
__Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
3703
/*--- Global init code ---*/
3704
__Pyx_RefNannyFinishContext();
3705
return 0;
3706
}
3707
3708
static int __Pyx_modinit_variable_export_code(void) {
3709
__Pyx_RefNannyDeclarations
3710
__Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
3711
/*--- Variable export code ---*/
3712
__Pyx_RefNannyFinishContext();
3713
return 0;
3714
}
3715
3716
static int __Pyx_modinit_function_export_code(void) {
3717
__Pyx_RefNannyDeclarations
3718
int __pyx_lineno = 0;
3719
const char *__pyx_filename = NULL;
3720
int __pyx_clineno = 0;
3721
__Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
3722
/*--- Function export code ---*/
3723
if (__Pyx_ExportFunction("gcd", (void (*)(void))__pyx_f_2nt_gcd, "int (int, int, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3724
if (__Pyx_ExportFunction("xgcd_c", (void (*)(void))__pyx_f_2nt_xgcd_c, "int (int, int, int *, int *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3725
if (__Pyx_ExportFunction("inverse_mod", (void (*)(void))__pyx_f_2nt_inverse_mod, "int (int, int, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3726
__Pyx_RefNannyFinishContext();
3727
return 0;
3728
__pyx_L1_error:;
3729
__Pyx_RefNannyFinishContext();
3730
return -1;
3731
}
3732
3733
static int __Pyx_modinit_type_init_code(void) {
3734
__Pyx_RefNannyDeclarations
3735
__Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
3736
/*--- Type init code ---*/
3737
__Pyx_RefNannyFinishContext();
3738
return 0;
3739
}
3740
3741
static int __Pyx_modinit_type_import_code(void) {
3742
__Pyx_RefNannyDeclarations
3743
__Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
3744
/*--- Type import code ---*/
3745
__Pyx_RefNannyFinishContext();
3746
return 0;
3747
}
3748
3749
static int __Pyx_modinit_variable_import_code(void) {
3750
__Pyx_RefNannyDeclarations
3751
__Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
3752
/*--- Variable import code ---*/
3753
__Pyx_RefNannyFinishContext();
3754
return 0;
3755
}
3756
3757
static int __Pyx_modinit_function_import_code(void) {
3758
__Pyx_RefNannyDeclarations
3759
__Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
3760
/*--- Function import code ---*/
3761
__Pyx_RefNannyFinishContext();
3762
return 0;
3763
}
3764
3765
3766
#ifndef CYTHON_NO_PYINIT_EXPORT
3767
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
3768
#elif PY_MAJOR_VERSION < 3
3769
#ifdef __cplusplus
3770
#define __Pyx_PyMODINIT_FUNC extern "C" void
3771
#else
3772
#define __Pyx_PyMODINIT_FUNC void
3773
#endif
3774
#else
3775
#ifdef __cplusplus
3776
#define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
3777
#else
3778
#define __Pyx_PyMODINIT_FUNC PyObject *
3779
#endif
3780
#endif
3781
3782
3783
#if PY_MAJOR_VERSION < 3
3784
__Pyx_PyMODINIT_FUNC initnt(void) CYTHON_SMALL_CODE; /*proto*/
3785
__Pyx_PyMODINIT_FUNC initnt(void)
3786
#else
3787
__Pyx_PyMODINIT_FUNC PyInit_nt(void) CYTHON_SMALL_CODE; /*proto*/
3788
__Pyx_PyMODINIT_FUNC PyInit_nt(void)
3789
#if CYTHON_PEP489_MULTI_PHASE_INIT
3790
{
3791
return PyModuleDef_Init(&__pyx_moduledef);
3792
}
3793
static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
3794
#if PY_VERSION_HEX >= 0x030700A1
3795
static PY_INT64_T main_interpreter_id = -1;
3796
PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
3797
if (main_interpreter_id == -1) {
3798
main_interpreter_id = current_id;
3799
return (unlikely(current_id == -1)) ? -1 : 0;
3800
} else if (unlikely(main_interpreter_id != current_id))
3801
#else
3802
static PyInterpreterState *main_interpreter = NULL;
3803
PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
3804
if (!main_interpreter) {
3805
main_interpreter = current_interpreter;
3806
} else if (unlikely(main_interpreter != current_interpreter))
3807
#endif
3808
{
3809
PyErr_SetString(
3810
PyExc_ImportError,
3811
"Interpreter change detected - this module can only be loaded into one interpreter per process.");
3812
return -1;
3813
}
3814
return 0;
3815
}
3816
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) {
3817
PyObject *value = PyObject_GetAttrString(spec, from_name);
3818
int result = 0;
3819
if (likely(value)) {
3820
if (allow_none || value != Py_None) {
3821
result = PyDict_SetItemString(moddict, to_name, value);
3822
}
3823
Py_DECREF(value);
3824
} else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
3825
PyErr_Clear();
3826
} else {
3827
result = -1;
3828
}
3829
return result;
3830
}
3831
static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
3832
PyObject *module = NULL, *moddict, *modname;
3833
if (__Pyx_check_single_interpreter())
3834
return NULL;
3835
if (__pyx_m)
3836
return __Pyx_NewRef(__pyx_m);
3837
modname = PyObject_GetAttrString(spec, "name");
3838
if (unlikely(!modname)) goto bad;
3839
module = PyModule_NewObject(modname);
3840
Py_DECREF(modname);
3841
if (unlikely(!module)) goto bad;
3842
moddict = PyModule_GetDict(module);
3843
if (unlikely(!moddict)) goto bad;
3844
if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
3845
if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
3846
if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
3847
if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
3848
return module;
3849
bad:
3850
Py_XDECREF(module);
3851
return NULL;
3852
}
3853
3854
3855
static CYTHON_SMALL_CODE int __pyx_pymod_exec_nt(PyObject *__pyx_pyinit_module)
3856
#endif
3857
#endif
3858
{
3859
PyObject *__pyx_t_1 = NULL;
3860
PyObject *__pyx_t_2 = NULL;
3861
int __pyx_lineno = 0;
3862
const char *__pyx_filename = NULL;
3863
int __pyx_clineno = 0;
3864
__Pyx_RefNannyDeclarations
3865
#if CYTHON_PEP489_MULTI_PHASE_INIT
3866
if (__pyx_m) {
3867
if (__pyx_m == __pyx_pyinit_module) return 0;
3868
PyErr_SetString(PyExc_RuntimeError, "Module 'nt' has already been imported. Re-initialisation is not supported.");
3869
return -1;
3870
}
3871
#elif PY_MAJOR_VERSION >= 3
3872
if (__pyx_m) return __Pyx_NewRef(__pyx_m);
3873
#endif
3874
#if CYTHON_REFNANNY
3875
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
3876
if (!__Pyx_RefNanny) {
3877
PyErr_Clear();
3878
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
3879
if (!__Pyx_RefNanny)
3880
Py_FatalError("failed to import 'refnanny' module");
3881
}
3882
#endif
3883
__Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_nt(void)", 0);
3884
if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3885
#ifdef __Pxy_PyFrame_Initialize_Offsets
3886
__Pxy_PyFrame_Initialize_Offsets();
3887
#endif
3888
__pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
3889
__pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
3890
__pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
3891
#ifdef __Pyx_CyFunction_USED
3892
if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3893
#endif
3894
#ifdef __Pyx_FusedFunction_USED
3895
if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3896
#endif
3897
#ifdef __Pyx_Coroutine_USED
3898
if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3899
#endif
3900
#ifdef __Pyx_Generator_USED
3901
if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3902
#endif
3903
#ifdef __Pyx_AsyncGen_USED
3904
if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3905
#endif
3906
#ifdef __Pyx_StopAsyncIteration_USED
3907
if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3908
#endif
3909
/*--- Library function declarations ---*/
3910
/*--- Threads initialization code ---*/
3911
#if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
3912
PyEval_InitThreads();
3913
#endif
3914
/*--- Module creation code ---*/
3915
#if CYTHON_PEP489_MULTI_PHASE_INIT
3916
__pyx_m = __pyx_pyinit_module;
3917
Py_INCREF(__pyx_m);
3918
#else
3919
#if PY_MAJOR_VERSION < 3
3920
__pyx_m = Py_InitModule4("nt", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
3921
#else
3922
__pyx_m = PyModule_Create(&__pyx_moduledef);
3923
#endif
3924
if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
3925
#endif
3926
__pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
3927
Py_INCREF(__pyx_d);
3928
__pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
3929
Py_INCREF(__pyx_b);
3930
__pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
3931
Py_INCREF(__pyx_cython_runtime);
3932
if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
3933
/*--- Initialize various global constants etc. ---*/
3934
if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3935
#if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
3936
if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3937
#endif
3938
if (__pyx_module_is_main_nt) {
3939
if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3940
}
3941
#if PY_MAJOR_VERSION >= 3
3942
{
3943
PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
3944
if (!PyDict_GetItemString(modules, "nt")) {
3945
if (unlikely(PyDict_SetItemString(modules, "nt", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
3946
}
3947
}
3948
#endif
3949
/*--- Builtin init code ---*/
3950
if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3951
/*--- Constants init code ---*/
3952
if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3953
/*--- Global type/function init code ---*/
3954
(void)__Pyx_modinit_global_init_code();
3955
(void)__Pyx_modinit_variable_export_code();
3956
if (unlikely(__Pyx_modinit_function_export_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
3957
(void)__Pyx_modinit_type_init_code();
3958
(void)__Pyx_modinit_type_import_code();
3959
(void)__Pyx_modinit_variable_import_code();
3960
(void)__Pyx_modinit_function_import_code();
3961
/*--- Execution code ---*/
3962
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
3963
if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3964
#endif
3965
3966
/* "nt.pyx":5
3967
* # as a foundation for some microbenchmarks
3968
*
3969
* from math import sqrt # <<<<<<<<<<<<<<
3970
* from typing import Tuple
3971
*
3972
*/
3973
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error)
3974
__Pyx_GOTREF(__pyx_t_1);
3975
__Pyx_INCREF(__pyx_n_s_sqrt);
3976
__Pyx_GIVEREF(__pyx_n_s_sqrt);
3977
PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_sqrt);
3978
__pyx_t_2 = __Pyx_Import(__pyx_n_s_math, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5, __pyx_L1_error)
3979
__Pyx_GOTREF(__pyx_t_2);
3980
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3981
__pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_sqrt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error)
3982
__Pyx_GOTREF(__pyx_t_1);
3983
if (PyDict_SetItem(__pyx_d, __pyx_n_s_sqrt, __pyx_t_1) < 0) __PYX_ERR(0, 5, __pyx_L1_error)
3984
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3985
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3986
3987
/* "nt.pyx":6
3988
*
3989
* from math import sqrt
3990
* from typing import Tuple # <<<<<<<<<<<<<<
3991
*
3992
*
3993
*/
3994
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error)
3995
__Pyx_GOTREF(__pyx_t_2);
3996
__Pyx_INCREF(__pyx_n_s_Tuple);
3997
__Pyx_GIVEREF(__pyx_n_s_Tuple);
3998
PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Tuple);
3999
__pyx_t_1 = __Pyx_Import(__pyx_n_s_typing, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error)
4000
__Pyx_GOTREF(__pyx_t_1);
4001
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4002
__pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_Tuple); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error)
4003
__Pyx_GOTREF(__pyx_t_2);
4004
if (PyDict_SetItem(__pyx_d, __pyx_n_s_Tuple, __pyx_t_2) < 0) __PYX_ERR(0, 6, __pyx_L1_error)
4005
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4006
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4007
4008
/* "nt.pyx":32
4009
* return a
4010
*
4011
* def xgcd(int a, int b) -> Tuple[int, int, int]: # <<<<<<<<<<<<<<
4012
* cdef int cx, cy, g
4013
* g = xgcd_c(a,b,&cx,&cy)
4014
*/
4015
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_2nt_3xgcd, NULL, __pyx_n_s_nt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error)
4016
__Pyx_GOTREF(__pyx_t_1);
4017
if (PyDict_SetItem(__pyx_d, __pyx_n_s_xgcd, __pyx_t_1) < 0) __PYX_ERR(0, 32, __pyx_L1_error)
4018
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4019
4020
/* "nt.pyx":54
4021
*
4022
*
4023
* def trial_division(N: int, bound: int = 0, start: int = 2) -> int: # <<<<<<<<<<<<<<
4024
* if N <= 1:
4025
* return N
4026
*/
4027
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_2nt_7trial_division, NULL, __pyx_n_s_nt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error)
4028
__Pyx_GOTREF(__pyx_t_1);
4029
if (PyDict_SetItem(__pyx_d, __pyx_n_s_trial_division, __pyx_t_1) < 0) __PYX_ERR(0, 54, __pyx_L1_error)
4030
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4031
4032
/* "nt.pyx":104
4033
*
4034
*
4035
* def is_prime(N: int) -> bool: # <<<<<<<<<<<<<<
4036
* return N > 1 and trial_division(N) == N
4037
*
4038
*/
4039
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_2nt_9is_prime, NULL, __pyx_n_s_nt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error)
4040
__Pyx_GOTREF(__pyx_t_1);
4041
if (PyDict_SetItem(__pyx_d, __pyx_n_s_is_prime, __pyx_t_1) < 0) __PYX_ERR(0, 104, __pyx_L1_error)
4042
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4043
4044
/* "nt.pyx":108
4045
*
4046
*
4047
* def pi(n: int = 100000) -> int: # <<<<<<<<<<<<<<
4048
* s = 0
4049
* for i in range(1, n + 1):
4050
*/
4051
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_2nt_11pi, NULL, __pyx_n_s_nt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error)
4052
__Pyx_GOTREF(__pyx_t_1);
4053
if (PyDict_SetItem(__pyx_d, __pyx_n_s_pi, __pyx_t_1) < 0) __PYX_ERR(0, 108, __pyx_L1_error)
4054
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4055
4056
/* "nt.pyx":1
4057
* # mypy # <<<<<<<<<<<<<<
4058
* # A little pure python number theory library, which is useful
4059
* # as a foundation for some microbenchmarks
4060
*/
4061
__pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
4062
__Pyx_GOTREF(__pyx_t_1);
4063
if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4064
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4065
4066
/*--- Wrapped vars code ---*/
4067
4068
goto __pyx_L0;
4069
__pyx_L1_error:;
4070
__Pyx_XDECREF(__pyx_t_1);
4071
__Pyx_XDECREF(__pyx_t_2);
4072
if (__pyx_m) {
4073
if (__pyx_d) {
4074
__Pyx_AddTraceback("init nt", __pyx_clineno, __pyx_lineno, __pyx_filename);
4075
}
4076
Py_CLEAR(__pyx_m);
4077
} else if (!PyErr_Occurred()) {
4078
PyErr_SetString(PyExc_ImportError, "init nt");
4079
}
4080
__pyx_L0:;
4081
__Pyx_RefNannyFinishContext();
4082
#if CYTHON_PEP489_MULTI_PHASE_INIT
4083
return (__pyx_m != NULL) ? 0 : -1;
4084
#elif PY_MAJOR_VERSION >= 3
4085
return __pyx_m;
4086
#else
4087
return;
4088
#endif
4089
}
4090
4091
/* --- Runtime support code --- */
4092
/* Refnanny */
4093
#if CYTHON_REFNANNY
4094
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
4095
PyObject *m = NULL, *p = NULL;
4096
void *r = NULL;
4097
m = PyImport_ImportModule(modname);
4098
if (!m) goto end;
4099
p = PyObject_GetAttrString(m, "RefNannyAPI");
4100
if (!p) goto end;
4101
r = PyLong_AsVoidPtr(p);
4102
end:
4103
Py_XDECREF(p);
4104
Py_XDECREF(m);
4105
return (__Pyx_RefNannyAPIStruct *)r;
4106
}
4107
#endif
4108
4109
/* PyObjectGetAttrStr */
4110
#if CYTHON_USE_TYPE_SLOTS
4111
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
4112
PyTypeObject* tp = Py_TYPE(obj);
4113
if (likely(tp->tp_getattro))
4114
return tp->tp_getattro(obj, attr_name);
4115
#if PY_MAJOR_VERSION < 3
4116
if (likely(tp->tp_getattr))
4117
return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
4118
#endif
4119
return PyObject_GetAttr(obj, attr_name);
4120
}
4121
#endif
4122
4123
/* GetBuiltinName */
4124
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
4125
PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
4126
if (unlikely(!result)) {
4127
PyErr_Format(PyExc_NameError,
4128
#if PY_MAJOR_VERSION >= 3
4129
"name '%U' is not defined", name);
4130
#else
4131
"name '%.200s' is not defined", PyString_AS_STRING(name));
4132
#endif
4133
}
4134
return result;
4135
}
4136
4137
/* ModInt[int] */
4138
static CYTHON_INLINE int __Pyx_mod_int(int a, int b) {
4139
int r = a % b;
4140
r += ((r != 0) & ((r ^ b) < 0)) * b;
4141
return r;
4142
}
4143
4144
/* PyErrFetchRestore */
4145
#if CYTHON_FAST_THREAD_STATE
4146
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
4147
PyObject *tmp_type, *tmp_value, *tmp_tb;
4148
tmp_type = tstate->curexc_type;
4149
tmp_value = tstate->curexc_value;
4150
tmp_tb = tstate->curexc_traceback;
4151
tstate->curexc_type = type;
4152
tstate->curexc_value = value;
4153
tstate->curexc_traceback = tb;
4154
Py_XDECREF(tmp_type);
4155
Py_XDECREF(tmp_value);
4156
Py_XDECREF(tmp_tb);
4157
}
4158
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
4159
*type = tstate->curexc_type;
4160
*value = tstate->curexc_value;
4161
*tb = tstate->curexc_traceback;
4162
tstate->curexc_type = 0;
4163
tstate->curexc_value = 0;
4164
tstate->curexc_traceback = 0;
4165
}
4166
#endif
4167
4168
/* WriteUnraisableException */
4169
static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
4170
CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
4171
int full_traceback, CYTHON_UNUSED int nogil) {
4172
PyObject *old_exc, *old_val, *old_tb;
4173
PyObject *ctx;
4174
__Pyx_PyThreadState_declare
4175
#ifdef WITH_THREAD
4176
PyGILState_STATE state;
4177
if (nogil)
4178
state = PyGILState_Ensure();
4179
#ifdef _MSC_VER
4180
else state = (PyGILState_STATE)-1;
4181
#endif
4182
#endif
4183
__Pyx_PyThreadState_assign
4184
__Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
4185
if (full_traceback) {
4186
Py_XINCREF(old_exc);
4187
Py_XINCREF(old_val);
4188
Py_XINCREF(old_tb);
4189
__Pyx_ErrRestore(old_exc, old_val, old_tb);
4190
PyErr_PrintEx(1);
4191
}
4192
#if PY_MAJOR_VERSION < 3
4193
ctx = PyString_FromString(name);
4194
#else
4195
ctx = PyUnicode_FromString(name);
4196
#endif
4197
__Pyx_ErrRestore(old_exc, old_val, old_tb);
4198
if (!ctx) {
4199
PyErr_WriteUnraisable(Py_None);
4200
} else {
4201
PyErr_WriteUnraisable(ctx);
4202
Py_DECREF(ctx);
4203
}
4204
#ifdef WITH_THREAD
4205
if (nogil)
4206
PyGILState_Release(state);
4207
#endif
4208
}
4209
4210
/* RaiseArgTupleInvalid */
4211
static void __Pyx_RaiseArgtupleInvalid(
4212
const char* func_name,
4213
int exact,
4214
Py_ssize_t num_min,
4215
Py_ssize_t num_max,
4216
Py_ssize_t num_found)
4217
{
4218
Py_ssize_t num_expected;
4219
const char *more_or_less;
4220
if (num_found < num_min) {
4221
num_expected = num_min;
4222
more_or_less = "at least";
4223
} else {
4224
num_expected = num_max;
4225
more_or_less = "at most";
4226
}
4227
if (exact) {
4228
more_or_less = "exactly";
4229
}
4230
PyErr_Format(PyExc_TypeError,
4231
"%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
4232
func_name, more_or_less, num_expected,
4233
(num_expected == 1) ? "" : "s", num_found);
4234
}
4235
4236
/* RaiseDoubleKeywords */
4237
static void __Pyx_RaiseDoubleKeywordsError(
4238
const char* func_name,
4239
PyObject* kw_name)
4240
{
4241
PyErr_Format(PyExc_TypeError,
4242
#if PY_MAJOR_VERSION >= 3
4243
"%s() got multiple values for keyword argument '%U'", func_name, kw_name);
4244
#else
4245
"%s() got multiple values for keyword argument '%s'", func_name,
4246
PyString_AsString(kw_name));
4247
#endif
4248
}
4249
4250
/* ParseKeywords */
4251
static int __Pyx_ParseOptionalKeywords(
4252
PyObject *kwds,
4253
PyObject **argnames[],
4254
PyObject *kwds2,
4255
PyObject *values[],
4256
Py_ssize_t num_pos_args,
4257
const char* function_name)
4258
{
4259
PyObject *key = 0, *value = 0;
4260
Py_ssize_t pos = 0;
4261
PyObject*** name;
4262
PyObject*** first_kw_arg = argnames + num_pos_args;
4263
while (PyDict_Next(kwds, &pos, &key, &value)) {
4264
name = first_kw_arg;
4265
while (*name && (**name != key)) name++;
4266
if (*name) {
4267
values[name-argnames] = value;
4268
continue;
4269
}
4270
name = first_kw_arg;
4271
#if PY_MAJOR_VERSION < 3
4272
if (likely(PyString_Check(key))) {
4273
while (*name) {
4274
if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
4275
&& _PyString_Eq(**name, key)) {
4276
values[name-argnames] = value;
4277
break;
4278
}
4279
name++;
4280
}
4281
if (*name) continue;
4282
else {
4283
PyObject*** argname = argnames;
4284
while (argname != first_kw_arg) {
4285
if ((**argname == key) || (
4286
(CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
4287
&& _PyString_Eq(**argname, key))) {
4288
goto arg_passed_twice;
4289
}
4290
argname++;
4291
}
4292
}
4293
} else
4294
#endif
4295
if (likely(PyUnicode_Check(key))) {
4296
while (*name) {
4297
int cmp = (**name == key) ? 0 :
4298
#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
4299
(__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
4300
#endif
4301
PyUnicode_Compare(**name, key);
4302
if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
4303
if (cmp == 0) {
4304
values[name-argnames] = value;
4305
break;
4306
}
4307
name++;
4308
}
4309
if (*name) continue;
4310
else {
4311
PyObject*** argname = argnames;
4312
while (argname != first_kw_arg) {
4313
int cmp = (**argname == key) ? 0 :
4314
#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
4315
(__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
4316
#endif
4317
PyUnicode_Compare(**argname, key);
4318
if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
4319
if (cmp == 0) goto arg_passed_twice;
4320
argname++;
4321
}
4322
}
4323
} else
4324
goto invalid_keyword_type;
4325
if (kwds2) {
4326
if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
4327
} else {
4328
goto invalid_keyword;
4329
}
4330
}
4331
return 0;
4332
arg_passed_twice:
4333
__Pyx_RaiseDoubleKeywordsError(function_name, key);
4334
goto bad;
4335
invalid_keyword_type:
4336
PyErr_Format(PyExc_TypeError,
4337
"%.200s() keywords must be strings", function_name);
4338
goto bad;
4339
invalid_keyword:
4340
PyErr_Format(PyExc_TypeError,
4341
#if PY_MAJOR_VERSION < 3
4342
"%.200s() got an unexpected keyword argument '%.200s'",
4343
function_name, PyString_AsString(key));
4344
#else
4345
"%s() got an unexpected keyword argument '%U'",
4346
function_name, key);
4347
#endif
4348
bad:
4349
return -1;
4350
}
4351
4352
/* DivInt[int] */
4353
static CYTHON_INLINE int __Pyx_div_int(int a, int b) {
4354
int q = a / b;
4355
int r = a - q*b;
4356
q -= ((r != 0) & ((r ^ b) < 0));
4357
return q;
4358
}
4359
4360
/* RaiseException */
4361
#if PY_MAJOR_VERSION < 3
4362
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
4363
CYTHON_UNUSED PyObject *cause) {
4364
__Pyx_PyThreadState_declare
4365
Py_XINCREF(type);
4366
if (!value || value == Py_None)
4367
value = NULL;
4368
else
4369
Py_INCREF(value);
4370
if (!tb || tb == Py_None)
4371
tb = NULL;
4372
else {
4373
Py_INCREF(tb);
4374
if (!PyTraceBack_Check(tb)) {
4375
PyErr_SetString(PyExc_TypeError,
4376
"raise: arg 3 must be a traceback or None");
4377
goto raise_error;
4378
}
4379
}
4380
if (PyType_Check(type)) {
4381
#if CYTHON_COMPILING_IN_PYPY
4382
if (!value) {
4383
Py_INCREF(Py_None);
4384
value = Py_None;
4385
}
4386
#endif
4387
PyErr_NormalizeException(&type, &value, &tb);
4388
} else {
4389
if (value) {
4390
PyErr_SetString(PyExc_TypeError,
4391
"instance exception may not have a separate value");
4392
goto raise_error;
4393
}
4394
value = type;
4395
type = (PyObject*) Py_TYPE(type);
4396
Py_INCREF(type);
4397
if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
4398
PyErr_SetString(PyExc_TypeError,
4399
"raise: exception class must be a subclass of BaseException");
4400
goto raise_error;
4401
}
4402
}
4403
__Pyx_PyThreadState_assign
4404
__Pyx_ErrRestore(type, value, tb);
4405
return;
4406
raise_error:
4407
Py_XDECREF(value);
4408
Py_XDECREF(type);
4409
Py_XDECREF(tb);
4410
return;
4411
}
4412
#else
4413
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
4414
PyObject* owned_instance = NULL;
4415
if (tb == Py_None) {
4416
tb = 0;
4417
} else if (tb && !PyTraceBack_Check(tb)) {
4418
PyErr_SetString(PyExc_TypeError,
4419
"raise: arg 3 must be a traceback or None");
4420
goto bad;
4421
}
4422
if (value == Py_None)
4423
value = 0;
4424
if (PyExceptionInstance_Check(type)) {
4425
if (value) {
4426
PyErr_SetString(PyExc_TypeError,
4427
"instance exception may not have a separate value");
4428
goto bad;
4429
}
4430
value = type;
4431
type = (PyObject*) Py_TYPE(value);
4432
} else if (PyExceptionClass_Check(type)) {
4433
PyObject *instance_class = NULL;
4434
if (value && PyExceptionInstance_Check(value)) {
4435
instance_class = (PyObject*) Py_TYPE(value);
4436
if (instance_class != type) {
4437
int is_subclass = PyObject_IsSubclass(instance_class, type);
4438
if (!is_subclass) {
4439
instance_class = NULL;
4440
} else if (unlikely(is_subclass == -1)) {
4441
goto bad;
4442
} else {
4443
type = instance_class;
4444
}
4445
}
4446
}
4447
if (!instance_class) {
4448
PyObject *args;
4449
if (!value)
4450
args = PyTuple_New(0);
4451
else if (PyTuple_Check(value)) {
4452
Py_INCREF(value);
4453
args = value;
4454
} else
4455
args = PyTuple_Pack(1, value);
4456
if (!args)
4457
goto bad;
4458
owned_instance = PyObject_Call(type, args, NULL);
4459
Py_DECREF(args);
4460
if (!owned_instance)
4461
goto bad;
4462
value = owned_instance;
4463
if (!PyExceptionInstance_Check(value)) {
4464
PyErr_Format(PyExc_TypeError,
4465
"calling %R should have returned an instance of "
4466
"BaseException, not %R",
4467
type, Py_TYPE(value));
4468
goto bad;
4469
}
4470
}
4471
} else {
4472
PyErr_SetString(PyExc_TypeError,
4473
"raise: exception class must be a subclass of BaseException");
4474
goto bad;
4475
}
4476
if (cause) {
4477
PyObject *fixed_cause;
4478
if (cause == Py_None) {
4479
fixed_cause = NULL;
4480
} else if (PyExceptionClass_Check(cause)) {
4481
fixed_cause = PyObject_CallObject(cause, NULL);
4482
if (fixed_cause == NULL)
4483
goto bad;
4484
} else if (PyExceptionInstance_Check(cause)) {
4485
fixed_cause = cause;
4486
Py_INCREF(fixed_cause);
4487
} else {
4488
PyErr_SetString(PyExc_TypeError,
4489
"exception causes must derive from "
4490
"BaseException");
4491
goto bad;
4492
}
4493
PyException_SetCause(value, fixed_cause);
4494
}
4495
PyErr_SetObject(type, value);
4496
if (tb) {
4497
#if CYTHON_COMPILING_IN_PYPY
4498
PyObject *tmp_type, *tmp_value, *tmp_tb;
4499
PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
4500
Py_INCREF(tb);
4501
PyErr_Restore(tmp_type, tmp_value, tb);
4502
Py_XDECREF(tmp_tb);
4503
#else
4504
PyThreadState *tstate = __Pyx_PyThreadState_Current;
4505
PyObject* tmp_tb = tstate->curexc_traceback;
4506
if (tb != tmp_tb) {
4507
Py_INCREF(tb);
4508
tstate->curexc_traceback = tb;
4509
Py_XDECREF(tmp_tb);
4510
}
4511
#endif
4512
}
4513
bad:
4514
Py_XDECREF(owned_instance);
4515
return;
4516
}
4517
#endif
4518
4519
/* PyIntBinop */
4520
#if !CYTHON_COMPILING_IN_PYPY
4521
#if PY_MAJOR_VERSION < 3 || CYTHON_USE_PYLONG_INTERNALS
4522
#define __Pyx_PyInt_RemainderObjC_ZeroDivisionError(operand)\
4523
if (unlikely(zerodivision_check && ((operand) == 0))) {\
4524
PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");\
4525
return NULL;\
4526
}
4527
#endif
4528
static PyObject* __Pyx_PyInt_RemainderObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
4529
(void)inplace;
4530
(void)zerodivision_check;
4531
#if PY_MAJOR_VERSION < 3
4532
if (likely(PyInt_CheckExact(op1))) {
4533
const long b = intval;
4534
long x;
4535
long a = PyInt_AS_LONG(op1);
4536
__Pyx_PyInt_RemainderObjC_ZeroDivisionError(b)
4537
x = a % b;
4538
x += ((x != 0) & ((x ^ b) < 0)) * b;
4539
return PyInt_FromLong(x);
4540
}
4541
#endif
4542
#if CYTHON_USE_PYLONG_INTERNALS
4543
if (likely(PyLong_CheckExact(op1))) {
4544
const long b = intval;
4545
long a, x;
4546
#ifdef HAVE_LONG_LONG
4547
const PY_LONG_LONG llb = intval;
4548
PY_LONG_LONG lla, llx;
4549
#endif
4550
const digit* digits = ((PyLongObject*)op1)->ob_digit;
4551
const Py_ssize_t size = Py_SIZE(op1);
4552
if (likely(__Pyx_sst_abs(size) <= 1)) {
4553
a = likely(size) ? digits[0] : 0;
4554
if (size == -1) a = -a;
4555
} else {
4556
switch (size) {
4557
case -2:
4558
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
4559
a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4560
break;
4561
#ifdef HAVE_LONG_LONG
4562
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
4563
lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
4564
goto long_long;
4565
#endif
4566
}
4567
CYTHON_FALLTHROUGH;
4568
case 2:
4569
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
4570
a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4571
break;
4572
#ifdef HAVE_LONG_LONG
4573
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
4574
lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
4575
goto long_long;
4576
#endif
4577
}
4578
CYTHON_FALLTHROUGH;
4579
case -3:
4580
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
4581
a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4582
break;
4583
#ifdef HAVE_LONG_LONG
4584
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
4585
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]));
4586
goto long_long;
4587
#endif
4588
}
4589
CYTHON_FALLTHROUGH;
4590
case 3:
4591
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
4592
a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4593
break;
4594
#ifdef HAVE_LONG_LONG
4595
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
4596
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]));
4597
goto long_long;
4598
#endif
4599
}
4600
CYTHON_FALLTHROUGH;
4601
case -4:
4602
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
4603
a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4604
break;
4605
#ifdef HAVE_LONG_LONG
4606
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
4607
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]));
4608
goto long_long;
4609
#endif
4610
}
4611
CYTHON_FALLTHROUGH;
4612
case 4:
4613
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
4614
a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4615
break;
4616
#ifdef HAVE_LONG_LONG
4617
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
4618
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]));
4619
goto long_long;
4620
#endif
4621
}
4622
CYTHON_FALLTHROUGH;
4623
default: return PyLong_Type.tp_as_number->nb_remainder(op1, op2);
4624
}
4625
}
4626
__Pyx_PyInt_RemainderObjC_ZeroDivisionError(b)
4627
x = a % b;
4628
x += ((x != 0) & ((x ^ b) < 0)) * b;
4629
return PyLong_FromLong(x);
4630
#ifdef HAVE_LONG_LONG
4631
long_long:
4632
llx = lla % llb;
4633
llx += ((llx != 0) & ((llx ^ llb) < 0)) * llb;
4634
return PyLong_FromLongLong(llx);
4635
#endif
4636
4637
4638
}
4639
#endif
4640
return (inplace ? PyNumber_InPlaceRemainder : PyNumber_Remainder)(op1, op2);
4641
}
4642
#endif
4643
4644
/* PyIntBinop */
4645
#if !CYTHON_COMPILING_IN_PYPY
4646
static PyObject* __Pyx_PyInt_SubtractCObj(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
4647
(void)inplace;
4648
(void)zerodivision_check;
4649
#if PY_MAJOR_VERSION < 3
4650
if (likely(PyInt_CheckExact(op2))) {
4651
const long a = intval;
4652
long x;
4653
long b = PyInt_AS_LONG(op2);
4654
x = (long)((unsigned long)a - b);
4655
if (likely((x^a) >= 0 || (x^~b) >= 0))
4656
return PyInt_FromLong(x);
4657
return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
4658
}
4659
#endif
4660
#if CYTHON_USE_PYLONG_INTERNALS
4661
if (likely(PyLong_CheckExact(op2))) {
4662
const long a = intval;
4663
long b, x;
4664
#ifdef HAVE_LONG_LONG
4665
const PY_LONG_LONG lla = intval;
4666
PY_LONG_LONG llb, llx;
4667
#endif
4668
const digit* digits = ((PyLongObject*)op2)->ob_digit;
4669
const Py_ssize_t size = Py_SIZE(op2);
4670
if (likely(__Pyx_sst_abs(size) <= 1)) {
4671
b = likely(size) ? digits[0] : 0;
4672
if (size == -1) b = -b;
4673
} else {
4674
switch (size) {
4675
case -2:
4676
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
4677
b = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4678
break;
4679
#ifdef HAVE_LONG_LONG
4680
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
4681
llb = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
4682
goto long_long;
4683
#endif
4684
}
4685
CYTHON_FALLTHROUGH;
4686
case 2:
4687
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
4688
b = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4689
break;
4690
#ifdef HAVE_LONG_LONG
4691
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
4692
llb = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
4693
goto long_long;
4694
#endif
4695
}
4696
CYTHON_FALLTHROUGH;
4697
case -3:
4698
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
4699
b = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4700
break;
4701
#ifdef HAVE_LONG_LONG
4702
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
4703
llb = -(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]));
4704
goto long_long;
4705
#endif
4706
}
4707
CYTHON_FALLTHROUGH;
4708
case 3:
4709
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
4710
b = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4711
break;
4712
#ifdef HAVE_LONG_LONG
4713
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
4714
llb = (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]));
4715
goto long_long;
4716
#endif
4717
}
4718
CYTHON_FALLTHROUGH;
4719
case -4:
4720
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
4721
b = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4722
break;
4723
#ifdef HAVE_LONG_LONG
4724
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
4725
llb = -(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]));
4726
goto long_long;
4727
#endif
4728
}
4729
CYTHON_FALLTHROUGH;
4730
case 4:
4731
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
4732
b = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
4733
break;
4734
#ifdef HAVE_LONG_LONG
4735
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
4736
llb = (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]));
4737
goto long_long;
4738
#endif
4739
}
4740
CYTHON_FALLTHROUGH;
4741
default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
4742
}
4743
}
4744
x = a - b;
4745
return PyLong_FromLong(x);
4746
#ifdef HAVE_LONG_LONG
4747
long_long:
4748
llx = lla - llb;
4749
return PyLong_FromLongLong(llx);
4750
#endif
4751
4752
4753
}
4754
#endif
4755
if (PyFloat_CheckExact(op2)) {
4756
const long a = intval;
4757
double b = PyFloat_AS_DOUBLE(op2);
4758
double result;
4759
PyFPE_START_PROTECT("subtract", return NULL)
4760
result = ((double)a) - (double)b;
4761
PyFPE_END_PROTECT(result)
4762
return PyFloat_FromDouble(result);
4763
}
4764
return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
4765
}
4766
#endif
4767
4768
/* PyIntCompare */
4769
static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) {
4770
if (op1 == op2) {
4771
Py_RETURN_TRUE;
4772
}
4773
#if PY_MAJOR_VERSION < 3
4774
if (likely(PyInt_CheckExact(op1))) {
4775
const long b = intval;
4776
long a = PyInt_AS_LONG(op1);
4777
if (a == b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
4778
}
4779
#endif
4780
#if CYTHON_USE_PYLONG_INTERNALS
4781
if (likely(PyLong_CheckExact(op1))) {
4782
int unequal;
4783
unsigned long uintval;
4784
Py_ssize_t size = Py_SIZE(op1);
4785
const digit* digits = ((PyLongObject*)op1)->ob_digit;
4786
if (intval == 0) {
4787
if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
4788
} else if (intval < 0) {
4789
if (size >= 0)
4790
Py_RETURN_FALSE;
4791
intval = -intval;
4792
size = -size;
4793
} else {
4794
if (size <= 0)
4795
Py_RETURN_FALSE;
4796
}
4797
uintval = (unsigned long) intval;
4798
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
4799
if (uintval >> (PyLong_SHIFT * 4)) {
4800
unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
4801
| (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));
4802
} else
4803
#endif
4804
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
4805
if (uintval >> (PyLong_SHIFT * 3)) {
4806
unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
4807
| (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));
4808
} else
4809
#endif
4810
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
4811
if (uintval >> (PyLong_SHIFT * 2)) {
4812
unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
4813
| (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
4814
} else
4815
#endif
4816
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
4817
if (uintval >> (PyLong_SHIFT * 1)) {
4818
unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
4819
| (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
4820
} else
4821
#endif
4822
unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
4823
if (unequal == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
4824
}
4825
#endif
4826
if (PyFloat_CheckExact(op1)) {
4827
const long b = intval;
4828
double a = PyFloat_AS_DOUBLE(op1);
4829
if ((double)a == (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
4830
}
4831
return (
4832
PyObject_RichCompare(op1, op2, Py_EQ));
4833
}
4834
4835
/* PyDictVersioning */
4836
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
4837
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
4838
PyObject *dict = Py_TYPE(obj)->tp_dict;
4839
return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
4840
}
4841
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
4842
PyObject **dictptr = NULL;
4843
Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
4844
if (offset) {
4845
#if CYTHON_COMPILING_IN_CPYTHON
4846
dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
4847
#else
4848
dictptr = _PyObject_GetDictPtr(obj);
4849
#endif
4850
}
4851
return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
4852
}
4853
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
4854
PyObject *dict = Py_TYPE(obj)->tp_dict;
4855
if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
4856
return 0;
4857
return obj_dict_version == __Pyx_get_object_dict_version(obj);
4858
}
4859
#endif
4860
4861
/* GetModuleGlobalName */
4862
#if CYTHON_USE_DICT_VERSIONS
4863
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
4864
#else
4865
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
4866
#endif
4867
{
4868
PyObject *result;
4869
#if !CYTHON_AVOID_BORROWED_REFS
4870
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
4871
result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
4872
__PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
4873
if (likely(result)) {
4874
return __Pyx_NewRef(result);
4875
} else if (unlikely(PyErr_Occurred())) {
4876
return NULL;
4877
}
4878
#else
4879
result = PyDict_GetItem(__pyx_d, name);
4880
__PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
4881
if (likely(result)) {
4882
return __Pyx_NewRef(result);
4883
}
4884
#endif
4885
#else
4886
result = PyObject_GetItem(__pyx_d, name);
4887
__PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
4888
if (likely(result)) {
4889
return __Pyx_NewRef(result);
4890
}
4891
PyErr_Clear();
4892
#endif
4893
return __Pyx_GetBuiltinName(name);
4894
}
4895
4896
/* PyCFunctionFastCall */
4897
#if CYTHON_FAST_PYCCALL
4898
static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
4899
PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
4900
PyCFunction meth = PyCFunction_GET_FUNCTION(func);
4901
PyObject *self = PyCFunction_GET_SELF(func);
4902
int flags = PyCFunction_GET_FLAGS(func);
4903
assert(PyCFunction_Check(func));
4904
assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)));
4905
assert(nargs >= 0);
4906
assert(nargs == 0 || args != NULL);
4907
/* _PyCFunction_FastCallDict() must not be called with an exception set,
4908
because it may clear it (directly or indirectly) and so the
4909
caller loses its exception */
4910
assert(!PyErr_Occurred());
4911
if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
4912
return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL);
4913
} else {
4914
return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs);
4915
}
4916
}
4917
#endif
4918
4919
/* PyFunctionFastCall */
4920
#if CYTHON_FAST_PYCALL
4921
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
4922
PyObject *globals) {
4923
PyFrameObject *f;
4924
PyThreadState *tstate = __Pyx_PyThreadState_Current;
4925
PyObject **fastlocals;
4926
Py_ssize_t i;
4927
PyObject *result;
4928
assert(globals != NULL);
4929
/* XXX Perhaps we should create a specialized
4930
PyFrame_New() that doesn't take locals, but does
4931
take builtins without sanity checking them.
4932
*/
4933
assert(tstate != NULL);
4934
f = PyFrame_New(tstate, co, globals, NULL);
4935
if (f == NULL) {
4936
return NULL;
4937
}
4938
fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
4939
for (i = 0; i < na; i++) {
4940
Py_INCREF(*args);
4941
fastlocals[i] = *args++;
4942
}
4943
result = PyEval_EvalFrameEx(f,0);
4944
++tstate->recursion_depth;
4945
Py_DECREF(f);
4946
--tstate->recursion_depth;
4947
return result;
4948
}
4949
#if 1 || PY_VERSION_HEX < 0x030600B1
4950
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) {
4951
PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
4952
PyObject *globals = PyFunction_GET_GLOBALS(func);
4953
PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
4954
PyObject *closure;
4955
#if PY_MAJOR_VERSION >= 3
4956
PyObject *kwdefs;
4957
#endif
4958
PyObject *kwtuple, **k;
4959
PyObject **d;
4960
Py_ssize_t nd;
4961
Py_ssize_t nk;
4962
PyObject *result;
4963
assert(kwargs == NULL || PyDict_Check(kwargs));
4964
nk = kwargs ? PyDict_Size(kwargs) : 0;
4965
if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
4966
return NULL;
4967
}
4968
if (
4969
#if PY_MAJOR_VERSION >= 3
4970
co->co_kwonlyargcount == 0 &&
4971
#endif
4972
likely(kwargs == NULL || nk == 0) &&
4973
co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
4974
if (argdefs == NULL && co->co_argcount == nargs) {
4975
result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
4976
goto done;
4977
}
4978
else if (nargs == 0 && argdefs != NULL
4979
&& co->co_argcount == Py_SIZE(argdefs)) {
4980
/* function called with no arguments, but all parameters have
4981
a default value: use default values as arguments .*/
4982
args = &PyTuple_GET_ITEM(argdefs, 0);
4983
result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
4984
goto done;
4985
}
4986
}
4987
if (kwargs != NULL) {
4988
Py_ssize_t pos, i;
4989
kwtuple = PyTuple_New(2 * nk);
4990
if (kwtuple == NULL) {
4991
result = NULL;
4992
goto done;
4993
}
4994
k = &PyTuple_GET_ITEM(kwtuple, 0);
4995
pos = i = 0;
4996
while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
4997
Py_INCREF(k[i]);
4998
Py_INCREF(k[i+1]);
4999
i += 2;
5000
}
5001
nk = i / 2;
5002
}
5003
else {
5004
kwtuple = NULL;
5005
k = NULL;
5006
}
5007
closure = PyFunction_GET_CLOSURE(func);
5008
#if PY_MAJOR_VERSION >= 3
5009
kwdefs = PyFunction_GET_KW_DEFAULTS(func);
5010
#endif
5011
if (argdefs != NULL) {
5012
d = &PyTuple_GET_ITEM(argdefs, 0);
5013
nd = Py_SIZE(argdefs);
5014
}
5015
else {
5016
d = NULL;
5017
nd = 0;
5018
}
5019
#if PY_MAJOR_VERSION >= 3
5020
result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
5021
args, (int)nargs,
5022
k, (int)nk,
5023
d, (int)nd, kwdefs, closure);
5024
#else
5025
result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
5026
args, (int)nargs,
5027
k, (int)nk,
5028
d, (int)nd, closure);
5029
#endif
5030
Py_XDECREF(kwtuple);
5031
done:
5032
Py_LeaveRecursiveCall();
5033
return result;
5034
}
5035
#endif
5036
#endif
5037
5038
/* PyObjectCall */
5039
#if CYTHON_COMPILING_IN_CPYTHON
5040
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
5041
PyObject *result;
5042
ternaryfunc call = Py_TYPE(func)->tp_call;
5043
if (unlikely(!call))
5044
return PyObject_Call(func, arg, kw);
5045
if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
5046
return NULL;
5047
result = (*call)(func, arg, kw);
5048
Py_LeaveRecursiveCall();
5049
if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
5050
PyErr_SetString(
5051
PyExc_SystemError,
5052
"NULL result without error in PyObject_Call");
5053
}
5054
return result;
5055
}
5056
#endif
5057
5058
/* PyObjectCall2Args */
5059
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
5060
PyObject *args, *result = NULL;
5061
#if CYTHON_FAST_PYCALL
5062
if (PyFunction_Check(function)) {
5063
PyObject *args[2] = {arg1, arg2};
5064
return __Pyx_PyFunction_FastCall(function, args, 2);
5065
}
5066
#endif
5067
#if CYTHON_FAST_PYCCALL
5068
if (__Pyx_PyFastCFunction_Check(function)) {
5069
PyObject *args[2] = {arg1, arg2};
5070
return __Pyx_PyCFunction_FastCall(function, args, 2);
5071
}
5072
#endif
5073
args = PyTuple_New(2);
5074
if (unlikely(!args)) goto done;
5075
Py_INCREF(arg1);
5076
PyTuple_SET_ITEM(args, 0, arg1);
5077
Py_INCREF(arg2);
5078
PyTuple_SET_ITEM(args, 1, arg2);
5079
Py_INCREF(function);
5080
result = __Pyx_PyObject_Call(function, args, NULL);
5081
Py_DECREF(args);
5082
Py_DECREF(function);
5083
done:
5084
return result;
5085
}
5086
5087
/* PyObjectCallMethO */
5088
#if CYTHON_COMPILING_IN_CPYTHON
5089
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
5090
PyObject *self, *result;
5091
PyCFunction cfunc;
5092
cfunc = PyCFunction_GET_FUNCTION(func);
5093
self = PyCFunction_GET_SELF(func);
5094
if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
5095
return NULL;
5096
result = cfunc(self, arg);
5097
Py_LeaveRecursiveCall();
5098
if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
5099
PyErr_SetString(
5100
PyExc_SystemError,
5101
"NULL result without error in PyObject_Call");
5102
}
5103
return result;
5104
}
5105
#endif
5106
5107
/* PyObjectCallOneArg */
5108
#if CYTHON_COMPILING_IN_CPYTHON
5109
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
5110
PyObject *result;
5111
PyObject *args = PyTuple_New(1);
5112
if (unlikely(!args)) return NULL;
5113
Py_INCREF(arg);
5114
PyTuple_SET_ITEM(args, 0, arg);
5115
result = __Pyx_PyObject_Call(func, args, NULL);
5116
Py_DECREF(args);
5117
return result;
5118
}
5119
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
5120
#if CYTHON_FAST_PYCALL
5121
if (PyFunction_Check(func)) {
5122
return __Pyx_PyFunction_FastCall(func, &arg, 1);
5123
}
5124
#endif
5125
if (likely(PyCFunction_Check(func))) {
5126
if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
5127
return __Pyx_PyObject_CallMethO(func, arg);
5128
#if CYTHON_FAST_PYCCALL
5129
} else if (__Pyx_PyFastCFunction_Check(func)) {
5130
return __Pyx_PyCFunction_FastCall(func, &arg, 1);
5131
#endif
5132
}
5133
}
5134
return __Pyx__PyObject_CallOneArg(func, arg);
5135
}
5136
#else
5137
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
5138
PyObject *result;
5139
PyObject *args = PyTuple_Pack(1, arg);
5140
if (unlikely(!args)) return NULL;
5141
result = __Pyx_PyObject_Call(func, args, NULL);
5142
Py_DECREF(args);
5143
return result;
5144
}
5145
#endif
5146
5147
/* PyIntCompare */
5148
static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) {
5149
if (op1 == op2) {
5150
Py_RETURN_FALSE;
5151
}
5152
#if PY_MAJOR_VERSION < 3
5153
if (likely(PyInt_CheckExact(op1))) {
5154
const long b = intval;
5155
long a = PyInt_AS_LONG(op1);
5156
if (a != b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
5157
}
5158
#endif
5159
#if CYTHON_USE_PYLONG_INTERNALS
5160
if (likely(PyLong_CheckExact(op1))) {
5161
int unequal;
5162
unsigned long uintval;
5163
Py_ssize_t size = Py_SIZE(op1);
5164
const digit* digits = ((PyLongObject*)op1)->ob_digit;
5165
if (intval == 0) {
5166
if (size != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
5167
} else if (intval < 0) {
5168
if (size >= 0)
5169
Py_RETURN_TRUE;
5170
intval = -intval;
5171
size = -size;
5172
} else {
5173
if (size <= 0)
5174
Py_RETURN_TRUE;
5175
}
5176
uintval = (unsigned long) intval;
5177
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
5178
if (uintval >> (PyLong_SHIFT * 4)) {
5179
unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
5180
| (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));
5181
} else
5182
#endif
5183
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
5184
if (uintval >> (PyLong_SHIFT * 3)) {
5185
unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
5186
| (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));
5187
} else
5188
#endif
5189
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
5190
if (uintval >> (PyLong_SHIFT * 2)) {
5191
unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
5192
| (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
5193
} else
5194
#endif
5195
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
5196
if (uintval >> (PyLong_SHIFT * 1)) {
5197
unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
5198
| (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
5199
} else
5200
#endif
5201
unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
5202
if (unequal != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
5203
}
5204
#endif
5205
if (PyFloat_CheckExact(op1)) {
5206
const long b = intval;
5207
double a = PyFloat_AS_DOUBLE(op1);
5208
if ((double)a != (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
5209
}
5210
return (
5211
PyObject_RichCompare(op1, op2, Py_NE));
5212
}
5213
5214
/* GetItemInt */
5215
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
5216
PyObject *r;
5217
if (!j) return NULL;
5218
r = PyObject_GetItem(o, j);
5219
Py_DECREF(j);
5220
return r;
5221
}
5222
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
5223
CYTHON_NCP_UNUSED int wraparound,
5224
CYTHON_NCP_UNUSED int boundscheck) {
5225
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
5226
Py_ssize_t wrapped_i = i;
5227
if (wraparound & unlikely(i < 0)) {
5228
wrapped_i += PyList_GET_SIZE(o);
5229
}
5230
if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) {
5231
PyObject *r = PyList_GET_ITEM(o, wrapped_i);
5232
Py_INCREF(r);
5233
return r;
5234
}
5235
return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
5236
#else
5237
return PySequence_GetItem(o, i);
5238
#endif
5239
}
5240
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
5241
CYTHON_NCP_UNUSED int wraparound,
5242
CYTHON_NCP_UNUSED int boundscheck) {
5243
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
5244
Py_ssize_t wrapped_i = i;
5245
if (wraparound & unlikely(i < 0)) {
5246
wrapped_i += PyTuple_GET_SIZE(o);
5247
}
5248
if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) {
5249
PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
5250
Py_INCREF(r);
5251
return r;
5252
}
5253
return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
5254
#else
5255
return PySequence_GetItem(o, i);
5256
#endif
5257
}
5258
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
5259
CYTHON_NCP_UNUSED int wraparound,
5260
CYTHON_NCP_UNUSED int boundscheck) {
5261
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
5262
if (is_list || PyList_CheckExact(o)) {
5263
Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
5264
if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
5265
PyObject *r = PyList_GET_ITEM(o, n);
5266
Py_INCREF(r);
5267
return r;
5268
}
5269
}
5270
else if (PyTuple_CheckExact(o)) {
5271
Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
5272
if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
5273
PyObject *r = PyTuple_GET_ITEM(o, n);
5274
Py_INCREF(r);
5275
return r;
5276
}
5277
} else {
5278
PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
5279
if (likely(m && m->sq_item)) {
5280
if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
5281
Py_ssize_t l = m->sq_length(o);
5282
if (likely(l >= 0)) {
5283
i += l;
5284
} else {
5285
if (!PyErr_ExceptionMatches(PyExc_OverflowError))
5286
return NULL;
5287
PyErr_Clear();
5288
}
5289
}
5290
return m->sq_item(o, i);
5291
}
5292
}
5293
#else
5294
if (is_list || PySequence_Check(o)) {
5295
return PySequence_GetItem(o, i);
5296
}
5297
#endif
5298
return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
5299
}
5300
5301
/* ObjectGetItem */
5302
#if CYTHON_USE_TYPE_SLOTS
5303
static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) {
5304
PyObject *runerr;
5305
Py_ssize_t key_value;
5306
PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence;
5307
if (unlikely(!(m && m->sq_item))) {
5308
PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name);
5309
return NULL;
5310
}
5311
key_value = __Pyx_PyIndex_AsSsize_t(index);
5312
if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
5313
return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
5314
}
5315
if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
5316
PyErr_Clear();
5317
PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name);
5318
}
5319
return NULL;
5320
}
5321
static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) {
5322
PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping;
5323
if (likely(m && m->mp_subscript)) {
5324
return m->mp_subscript(obj, key);
5325
}
5326
return __Pyx_PyObject_GetIndex(obj, key);
5327
}
5328
#endif
5329
5330
/* PyIntBinop */
5331
#if !CYTHON_COMPILING_IN_PYPY
5332
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
5333
(void)inplace;
5334
(void)zerodivision_check;
5335
#if PY_MAJOR_VERSION < 3
5336
if (likely(PyInt_CheckExact(op1))) {
5337
const long b = intval;
5338
long x;
5339
long a = PyInt_AS_LONG(op1);
5340
x = (long)((unsigned long)a + b);
5341
if (likely((x^a) >= 0 || (x^b) >= 0))
5342
return PyInt_FromLong(x);
5343
return PyLong_Type.tp_as_number->nb_add(op1, op2);
5344
}
5345
#endif
5346
#if CYTHON_USE_PYLONG_INTERNALS
5347
if (likely(PyLong_CheckExact(op1))) {
5348
const long b = intval;
5349
long a, x;
5350
#ifdef HAVE_LONG_LONG
5351
const PY_LONG_LONG llb = intval;
5352
PY_LONG_LONG lla, llx;
5353
#endif
5354
const digit* digits = ((PyLongObject*)op1)->ob_digit;
5355
const Py_ssize_t size = Py_SIZE(op1);
5356
if (likely(__Pyx_sst_abs(size) <= 1)) {
5357
a = likely(size) ? digits[0] : 0;
5358
if (size == -1) a = -a;
5359
} else {
5360
switch (size) {
5361
case -2:
5362
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
5363
a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
5364
break;
5365
#ifdef HAVE_LONG_LONG
5366
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
5367
lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
5368
goto long_long;
5369
#endif
5370
}
5371
CYTHON_FALLTHROUGH;
5372
case 2:
5373
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
5374
a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
5375
break;
5376
#ifdef HAVE_LONG_LONG
5377
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
5378
lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
5379
goto long_long;
5380
#endif
5381
}
5382
CYTHON_FALLTHROUGH;
5383
case -3:
5384
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
5385
a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
5386
break;
5387
#ifdef HAVE_LONG_LONG
5388
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
5389
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]));
5390
goto long_long;
5391
#endif
5392
}
5393
CYTHON_FALLTHROUGH;
5394
case 3:
5395
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
5396
a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
5397
break;
5398
#ifdef HAVE_LONG_LONG
5399
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
5400
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]));
5401
goto long_long;
5402
#endif
5403
}
5404
CYTHON_FALLTHROUGH;
5405
case -4:
5406
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
5407
a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
5408
break;
5409
#ifdef HAVE_LONG_LONG
5410
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
5411
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]));
5412
goto long_long;
5413
#endif
5414
}
5415
CYTHON_FALLTHROUGH;
5416
case 4:
5417
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
5418
a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
5419
break;
5420
#ifdef HAVE_LONG_LONG
5421
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
5422
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]));
5423
goto long_long;
5424
#endif
5425
}
5426
CYTHON_FALLTHROUGH;
5427
default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
5428
}
5429
}
5430
x = a + b;
5431
return PyLong_FromLong(x);
5432
#ifdef HAVE_LONG_LONG
5433
long_long:
5434
llx = lla + llb;
5435
return PyLong_FromLongLong(llx);
5436
#endif
5437
5438
5439
}
5440
#endif
5441
if (PyFloat_CheckExact(op1)) {
5442
const long b = intval;
5443
double a = PyFloat_AS_DOUBLE(op1);
5444
double result;
5445
PyFPE_START_PROTECT("add", return NULL)
5446
result = ((double)a) + (double)b;
5447
PyFPE_END_PROTECT(result)
5448
return PyFloat_FromDouble(result);
5449
}
5450
return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
5451
}
5452
#endif
5453
5454
/* Import */
5455
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
5456
PyObject *empty_list = 0;
5457
PyObject *module = 0;
5458
PyObject *global_dict = 0;
5459
PyObject *empty_dict = 0;
5460
PyObject *list;
5461
#if PY_MAJOR_VERSION < 3
5462
PyObject *py_import;
5463
py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
5464
if (!py_import)
5465
goto bad;
5466
#endif
5467
if (from_list)
5468
list = from_list;
5469
else {
5470
empty_list = PyList_New(0);
5471
if (!empty_list)
5472
goto bad;
5473
list = empty_list;
5474
}
5475
global_dict = PyModule_GetDict(__pyx_m);
5476
if (!global_dict)
5477
goto bad;
5478
empty_dict = PyDict_New();
5479
if (!empty_dict)
5480
goto bad;
5481
{
5482
#if PY_MAJOR_VERSION >= 3
5483
if (level == -1) {
5484
if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) {
5485
module = PyImport_ImportModuleLevelObject(
5486
name, global_dict, empty_dict, list, 1);
5487
if (!module) {
5488
if (!PyErr_ExceptionMatches(PyExc_ImportError))
5489
goto bad;
5490
PyErr_Clear();
5491
}
5492
}
5493
level = 0;
5494
}
5495
#endif
5496
if (!module) {
5497
#if PY_MAJOR_VERSION < 3
5498
PyObject *py_level = PyInt_FromLong(level);
5499
if (!py_level)
5500
goto bad;
5501
module = PyObject_CallFunctionObjArgs(py_import,
5502
name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
5503
Py_DECREF(py_level);
5504
#else
5505
module = PyImport_ImportModuleLevelObject(
5506
name, global_dict, empty_dict, list, level);
5507
#endif
5508
}
5509
}
5510
bad:
5511
#if PY_MAJOR_VERSION < 3
5512
Py_XDECREF(py_import);
5513
#endif
5514
Py_XDECREF(empty_list);
5515
Py_XDECREF(empty_dict);
5516
return module;
5517
}
5518
5519
/* ImportFrom */
5520
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
5521
PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
5522
if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
5523
PyErr_Format(PyExc_ImportError,
5524
#if PY_MAJOR_VERSION < 3
5525
"cannot import name %.230s", PyString_AS_STRING(name));
5526
#else
5527
"cannot import name %S", name);
5528
#endif
5529
}
5530
return value;
5531
}
5532
5533
/* CLineInTraceback */
5534
#ifndef CYTHON_CLINE_IN_TRACEBACK
5535
static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) {
5536
PyObject *use_cline;
5537
PyObject *ptype, *pvalue, *ptraceback;
5538
#if CYTHON_COMPILING_IN_CPYTHON
5539
PyObject **cython_runtime_dict;
5540
#endif
5541
if (unlikely(!__pyx_cython_runtime)) {
5542
return c_line;
5543
}
5544
__Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
5545
#if CYTHON_COMPILING_IN_CPYTHON
5546
cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
5547
if (likely(cython_runtime_dict)) {
5548
__PYX_PY_DICT_LOOKUP_IF_MODIFIED(
5549
use_cline, *cython_runtime_dict,
5550
__Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
5551
} else
5552
#endif
5553
{
5554
PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
5555
if (use_cline_obj) {
5556
use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
5557
Py_DECREF(use_cline_obj);
5558
} else {
5559
PyErr_Clear();
5560
use_cline = NULL;
5561
}
5562
}
5563
if (!use_cline) {
5564
c_line = 0;
5565
(void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
5566
}
5567
else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
5568
c_line = 0;
5569
}
5570
__Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
5571
return c_line;
5572
}
5573
#endif
5574
5575
/* CodeObjectCache */
5576
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
5577
int start = 0, mid = 0, end = count - 1;
5578
if (end >= 0 && code_line > entries[end].code_line) {
5579
return count;
5580
}
5581
while (start < end) {
5582
mid = start + (end - start) / 2;
5583
if (code_line < entries[mid].code_line) {
5584
end = mid;
5585
} else if (code_line > entries[mid].code_line) {
5586
start = mid + 1;
5587
} else {
5588
return mid;
5589
}
5590
}
5591
if (code_line <= entries[mid].code_line) {
5592
return mid;
5593
} else {
5594
return mid + 1;
5595
}
5596
}
5597
static PyCodeObject *__pyx_find_code_object(int code_line) {
5598
PyCodeObject* code_object;
5599
int pos;
5600
if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
5601
return NULL;
5602
}
5603
pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
5604
if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
5605
return NULL;
5606
}
5607
code_object = __pyx_code_cache.entries[pos].code_object;
5608
Py_INCREF(code_object);
5609
return code_object;
5610
}
5611
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
5612
int pos, i;
5613
__Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
5614
if (unlikely(!code_line)) {
5615
return;
5616
}
5617
if (unlikely(!entries)) {
5618
entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
5619
if (likely(entries)) {
5620
__pyx_code_cache.entries = entries;
5621
__pyx_code_cache.max_count = 64;
5622
__pyx_code_cache.count = 1;
5623
entries[0].code_line = code_line;
5624
entries[0].code_object = code_object;
5625
Py_INCREF(code_object);
5626
}
5627
return;
5628
}
5629
pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
5630
if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
5631
PyCodeObject* tmp = entries[pos].code_object;
5632
entries[pos].code_object = code_object;
5633
Py_DECREF(tmp);
5634
return;
5635
}
5636
if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
5637
int new_max = __pyx_code_cache.max_count + 64;
5638
entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
5639
__pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry));
5640
if (unlikely(!entries)) {
5641
return;
5642
}
5643
__pyx_code_cache.entries = entries;
5644
__pyx_code_cache.max_count = new_max;
5645
}
5646
for (i=__pyx_code_cache.count; i>pos; i--) {
5647
entries[i] = entries[i-1];
5648
}
5649
entries[pos].code_line = code_line;
5650
entries[pos].code_object = code_object;
5651
__pyx_code_cache.count++;
5652
Py_INCREF(code_object);
5653
}
5654
5655
/* AddTraceback */
5656
#include "compile.h"
5657
#include "frameobject.h"
5658
#include "traceback.h"
5659
#if PY_VERSION_HEX >= 0x030b00a6
5660
#ifndef Py_BUILD_CORE
5661
#define Py_BUILD_CORE 1
5662
#endif
5663
#include "internal/pycore_frame.h"
5664
#endif
5665
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
5666
const char *funcname, int c_line,
5667
int py_line, const char *filename) {
5668
PyCodeObject *py_code = NULL;
5669
PyObject *py_funcname = NULL;
5670
#if PY_MAJOR_VERSION < 3
5671
PyObject *py_srcfile = NULL;
5672
py_srcfile = PyString_FromString(filename);
5673
if (!py_srcfile) goto bad;
5674
#endif
5675
if (c_line) {
5676
#if PY_MAJOR_VERSION < 3
5677
py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
5678
if (!py_funcname) goto bad;
5679
#else
5680
py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
5681
if (!py_funcname) goto bad;
5682
funcname = PyUnicode_AsUTF8(py_funcname);
5683
if (!funcname) goto bad;
5684
#endif
5685
}
5686
else {
5687
#if PY_MAJOR_VERSION < 3
5688
py_funcname = PyString_FromString(funcname);
5689
if (!py_funcname) goto bad;
5690
#endif
5691
}
5692
#if PY_MAJOR_VERSION < 3
5693
py_code = __Pyx_PyCode_New(
5694
0,
5695
0,
5696
0,
5697
0,
5698
0,
5699
__pyx_empty_bytes, /*PyObject *code,*/
5700
__pyx_empty_tuple, /*PyObject *consts,*/
5701
__pyx_empty_tuple, /*PyObject *names,*/
5702
__pyx_empty_tuple, /*PyObject *varnames,*/
5703
__pyx_empty_tuple, /*PyObject *freevars,*/
5704
__pyx_empty_tuple, /*PyObject *cellvars,*/
5705
py_srcfile, /*PyObject *filename,*/
5706
py_funcname, /*PyObject *name,*/
5707
py_line,
5708
__pyx_empty_bytes /*PyObject *lnotab*/
5709
);
5710
Py_DECREF(py_srcfile);
5711
#else
5712
py_code = PyCode_NewEmpty(filename, funcname, py_line);
5713
#endif
5714
Py_XDECREF(py_funcname); // XDECREF since it's only set on Py3 if cline
5715
return py_code;
5716
bad:
5717
Py_XDECREF(py_funcname);
5718
#if PY_MAJOR_VERSION < 3
5719
Py_XDECREF(py_srcfile);
5720
#endif
5721
return NULL;
5722
}
5723
static void __Pyx_AddTraceback(const char *funcname, int c_line,
5724
int py_line, const char *filename) {
5725
PyCodeObject *py_code = 0;
5726
PyFrameObject *py_frame = 0;
5727
PyThreadState *tstate = __Pyx_PyThreadState_Current;
5728
PyObject *ptype, *pvalue, *ptraceback;
5729
if (c_line) {
5730
c_line = __Pyx_CLineForTraceback(tstate, c_line);
5731
}
5732
py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
5733
if (!py_code) {
5734
__Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
5735
py_code = __Pyx_CreateCodeObjectForTraceback(
5736
funcname, c_line, py_line, filename);
5737
if (!py_code) {
5738
/* If the code object creation fails, then we should clear the
5739
fetched exception references and propagate the new exception */
5740
Py_XDECREF(ptype);
5741
Py_XDECREF(pvalue);
5742
Py_XDECREF(ptraceback);
5743
goto bad;
5744
}
5745
__Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
5746
__pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
5747
}
5748
py_frame = PyFrame_New(
5749
tstate, /*PyThreadState *tstate,*/
5750
py_code, /*PyCodeObject *code,*/
5751
__pyx_d, /*PyObject *globals,*/
5752
0 /*PyObject *locals*/
5753
);
5754
if (!py_frame) goto bad;
5755
__Pyx_PyFrame_SetLineNumber(py_frame, py_line);
5756
PyTraceBack_Here(py_frame);
5757
bad:
5758
Py_XDECREF(py_code);
5759
Py_XDECREF(py_frame);
5760
}
5761
5762
/* CIntFromPyVerify */
5763
#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
5764
__PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
5765
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
5766
__PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
5767
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
5768
{\
5769
func_type value = func_value;\
5770
if (sizeof(target_type) < sizeof(func_type)) {\
5771
if (unlikely(value != (func_type) (target_type) value)) {\
5772
func_type zero = 0;\
5773
if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
5774
return (target_type) -1;\
5775
if (is_unsigned && unlikely(value < zero))\
5776
goto raise_neg_overflow;\
5777
else\
5778
goto raise_overflow;\
5779
}\
5780
}\
5781
return (target_type) value;\
5782
}
5783
5784
/* CIntFromPy */
5785
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
5786
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
5787
#pragma GCC diagnostic push
5788
#pragma GCC diagnostic ignored "-Wconversion"
5789
#endif
5790
const int neg_one = (int) -1, const_zero = (int) 0;
5791
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
5792
#pragma GCC diagnostic pop
5793
#endif
5794
const int is_unsigned = neg_one > const_zero;
5795
#if PY_MAJOR_VERSION < 3
5796
if (likely(PyInt_Check(x))) {
5797
if (sizeof(int) < sizeof(long)) {
5798
__PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
5799
} else {
5800
long val = PyInt_AS_LONG(x);
5801
if (is_unsigned && unlikely(val < 0)) {
5802
goto raise_neg_overflow;
5803
}
5804
return (int) val;
5805
}
5806
} else
5807
#endif
5808
if (likely(PyLong_Check(x))) {
5809
if (is_unsigned) {
5810
#if CYTHON_USE_PYLONG_INTERNALS
5811
const digit* digits = ((PyLongObject*)x)->ob_digit;
5812
switch (Py_SIZE(x)) {
5813
case 0: return (int) 0;
5814
case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
5815
case 2:
5816
if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
5817
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5818
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5819
} else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
5820
return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
5821
}
5822
}
5823
break;
5824
case 3:
5825
if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
5826
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5827
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5828
} else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
5829
return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
5830
}
5831
}
5832
break;
5833
case 4:
5834
if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
5835
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5836
__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])))
5837
} else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
5838
return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
5839
}
5840
}
5841
break;
5842
}
5843
#endif
5844
#if CYTHON_COMPILING_IN_CPYTHON
5845
if (unlikely(Py_SIZE(x) < 0)) {
5846
goto raise_neg_overflow;
5847
}
5848
#else
5849
{
5850
int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
5851
if (unlikely(result < 0))
5852
return (int) -1;
5853
if (unlikely(result == 1))
5854
goto raise_neg_overflow;
5855
}
5856
#endif
5857
if (sizeof(int) <= sizeof(unsigned long)) {
5858
__PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
5859
#ifdef HAVE_LONG_LONG
5860
} else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
5861
__PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
5862
#endif
5863
}
5864
} else {
5865
#if CYTHON_USE_PYLONG_INTERNALS
5866
const digit* digits = ((PyLongObject*)x)->ob_digit;
5867
switch (Py_SIZE(x)) {
5868
case 0: return (int) 0;
5869
case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
5870
case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0])
5871
case -2:
5872
if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
5873
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5874
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5875
} else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
5876
return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5877
}
5878
}
5879
break;
5880
case 2:
5881
if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
5882
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5883
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5884
} else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
5885
return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5886
}
5887
}
5888
break;
5889
case -3:
5890
if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
5891
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5892
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5893
} else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
5894
return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5895
}
5896
}
5897
break;
5898
case 3:
5899
if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
5900
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5901
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5902
} else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
5903
return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5904
}
5905
}
5906
break;
5907
case -4:
5908
if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
5909
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5910
__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])))
5911
} else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
5912
return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5913
}
5914
}
5915
break;
5916
case 4:
5917
if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
5918
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5919
__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])))
5920
} else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
5921
return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5922
}
5923
}
5924
break;
5925
}
5926
#endif
5927
if (sizeof(int) <= sizeof(long)) {
5928
__PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
5929
#ifdef HAVE_LONG_LONG
5930
} else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
5931
__PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
5932
#endif
5933
}
5934
}
5935
{
5936
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
5937
PyErr_SetString(PyExc_RuntimeError,
5938
"_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
5939
#else
5940
int val;
5941
PyObject *v = __Pyx_PyNumber_IntOrLong(x);
5942
#if PY_MAJOR_VERSION < 3
5943
if (likely(v) && !PyLong_Check(v)) {
5944
PyObject *tmp = v;
5945
v = PyNumber_Long(tmp);
5946
Py_DECREF(tmp);
5947
}
5948
#endif
5949
if (likely(v)) {
5950
int one = 1; int is_little = (int)*(unsigned char *)&one;
5951
unsigned char *bytes = (unsigned char *)&val;
5952
int ret = _PyLong_AsByteArray((PyLongObject *)v,
5953
bytes, sizeof(val),
5954
is_little, !is_unsigned);
5955
Py_DECREF(v);
5956
if (likely(!ret))
5957
return val;
5958
}
5959
#endif
5960
return (int) -1;
5961
}
5962
} else {
5963
int val;
5964
PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
5965
if (!tmp) return (int) -1;
5966
val = __Pyx_PyInt_As_int(tmp);
5967
Py_DECREF(tmp);
5968
return val;
5969
}
5970
raise_overflow:
5971
PyErr_SetString(PyExc_OverflowError,
5972
"value too large to convert to int");
5973
return (int) -1;
5974
raise_neg_overflow:
5975
PyErr_SetString(PyExc_OverflowError,
5976
"can't convert negative value to int");
5977
return (int) -1;
5978
}
5979
5980
/* CIntToPy */
5981
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
5982
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
5983
#pragma GCC diagnostic push
5984
#pragma GCC diagnostic ignored "-Wconversion"
5985
#endif
5986
const int neg_one = (int) -1, const_zero = (int) 0;
5987
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
5988
#pragma GCC diagnostic pop
5989
#endif
5990
const int is_unsigned = neg_one > const_zero;
5991
if (is_unsigned) {
5992
if (sizeof(int) < sizeof(long)) {
5993
return PyInt_FromLong((long) value);
5994
} else if (sizeof(int) <= sizeof(unsigned long)) {
5995
return PyLong_FromUnsignedLong((unsigned long) value);
5996
#ifdef HAVE_LONG_LONG
5997
} else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
5998
return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
5999
#endif
6000
}
6001
} else {
6002
if (sizeof(int) <= sizeof(long)) {
6003
return PyInt_FromLong((long) value);
6004
#ifdef HAVE_LONG_LONG
6005
} else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
6006
return PyLong_FromLongLong((PY_LONG_LONG) value);
6007
#endif
6008
}
6009
}
6010
{
6011
int one = 1; int little = (int)*(unsigned char *)&one;
6012
unsigned char *bytes = (unsigned char *)&value;
6013
return _PyLong_FromByteArray(bytes, sizeof(int),
6014
little, !is_unsigned);
6015
}
6016
}
6017
6018
/* CIntToPy */
6019
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
6020
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
6021
#pragma GCC diagnostic push
6022
#pragma GCC diagnostic ignored "-Wconversion"
6023
#endif
6024
const long neg_one = (long) -1, const_zero = (long) 0;
6025
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
6026
#pragma GCC diagnostic pop
6027
#endif
6028
const int is_unsigned = neg_one > const_zero;
6029
if (is_unsigned) {
6030
if (sizeof(long) < sizeof(long)) {
6031
return PyInt_FromLong((long) value);
6032
} else if (sizeof(long) <= sizeof(unsigned long)) {
6033
return PyLong_FromUnsignedLong((unsigned long) value);
6034
#ifdef HAVE_LONG_LONG
6035
} else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
6036
return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
6037
#endif
6038
}
6039
} else {
6040
if (sizeof(long) <= sizeof(long)) {
6041
return PyInt_FromLong((long) value);
6042
#ifdef HAVE_LONG_LONG
6043
} else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
6044
return PyLong_FromLongLong((PY_LONG_LONG) value);
6045
#endif
6046
}
6047
}
6048
{
6049
int one = 1; int little = (int)*(unsigned char *)&one;
6050
unsigned char *bytes = (unsigned char *)&value;
6051
return _PyLong_FromByteArray(bytes, sizeof(long),
6052
little, !is_unsigned);
6053
}
6054
}
6055
6056
/* CIntFromPy */
6057
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
6058
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
6059
#pragma GCC diagnostic push
6060
#pragma GCC diagnostic ignored "-Wconversion"
6061
#endif
6062
const long neg_one = (long) -1, const_zero = (long) 0;
6063
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
6064
#pragma GCC diagnostic pop
6065
#endif
6066
const int is_unsigned = neg_one > const_zero;
6067
#if PY_MAJOR_VERSION < 3
6068
if (likely(PyInt_Check(x))) {
6069
if (sizeof(long) < sizeof(long)) {
6070
__PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
6071
} else {
6072
long val = PyInt_AS_LONG(x);
6073
if (is_unsigned && unlikely(val < 0)) {
6074
goto raise_neg_overflow;
6075
}
6076
return (long) val;
6077
}
6078
} else
6079
#endif
6080
if (likely(PyLong_Check(x))) {
6081
if (is_unsigned) {
6082
#if CYTHON_USE_PYLONG_INTERNALS
6083
const digit* digits = ((PyLongObject*)x)->ob_digit;
6084
switch (Py_SIZE(x)) {
6085
case 0: return (long) 0;
6086
case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
6087
case 2:
6088
if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
6089
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
6090
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6091
} else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
6092
return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
6093
}
6094
}
6095
break;
6096
case 3:
6097
if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
6098
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
6099
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6100
} else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
6101
return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
6102
}
6103
}
6104
break;
6105
case 4:
6106
if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
6107
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
6108
__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])))
6109
} else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
6110
return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
6111
}
6112
}
6113
break;
6114
}
6115
#endif
6116
#if CYTHON_COMPILING_IN_CPYTHON
6117
if (unlikely(Py_SIZE(x) < 0)) {
6118
goto raise_neg_overflow;
6119
}
6120
#else
6121
{
6122
int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
6123
if (unlikely(result < 0))
6124
return (long) -1;
6125
if (unlikely(result == 1))
6126
goto raise_neg_overflow;
6127
}
6128
#endif
6129
if (sizeof(long) <= sizeof(unsigned long)) {
6130
__PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
6131
#ifdef HAVE_LONG_LONG
6132
} else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
6133
__PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
6134
#endif
6135
}
6136
} else {
6137
#if CYTHON_USE_PYLONG_INTERNALS
6138
const digit* digits = ((PyLongObject*)x)->ob_digit;
6139
switch (Py_SIZE(x)) {
6140
case 0: return (long) 0;
6141
case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
6142
case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0])
6143
case -2:
6144
if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
6145
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
6146
__PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6147
} else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
6148
return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
6149
}
6150
}
6151
break;
6152
case 2:
6153
if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
6154
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
6155
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6156
} else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
6157
return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
6158
}
6159
}
6160
break;
6161
case -3:
6162
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
6163
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
6164
__PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6165
} else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
6166
return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
6167
}
6168
}
6169
break;
6170
case 3:
6171
if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
6172
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
6173
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6174
} else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
6175
return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
6176
}
6177
}
6178
break;
6179
case -4:
6180
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
6181
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
6182
__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])))
6183
} else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
6184
return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
6185
}
6186
}
6187
break;
6188
case 4:
6189
if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
6190
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
6191
__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])))
6192
} else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
6193
return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
6194
}
6195
}
6196
break;
6197
}
6198
#endif
6199
if (sizeof(long) <= sizeof(long)) {
6200
__PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
6201
#ifdef HAVE_LONG_LONG
6202
} else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
6203
__PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
6204
#endif
6205
}
6206
}
6207
{
6208
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
6209
PyErr_SetString(PyExc_RuntimeError,
6210
"_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
6211
#else
6212
long val;
6213
PyObject *v = __Pyx_PyNumber_IntOrLong(x);
6214
#if PY_MAJOR_VERSION < 3
6215
if (likely(v) && !PyLong_Check(v)) {
6216
PyObject *tmp = v;
6217
v = PyNumber_Long(tmp);
6218
Py_DECREF(tmp);
6219
}
6220
#endif
6221
if (likely(v)) {
6222
int one = 1; int is_little = (int)*(unsigned char *)&one;
6223
unsigned char *bytes = (unsigned char *)&val;
6224
int ret = _PyLong_AsByteArray((PyLongObject *)v,
6225
bytes, sizeof(val),
6226
is_little, !is_unsigned);
6227
Py_DECREF(v);
6228
if (likely(!ret))
6229
return val;
6230
}
6231
#endif
6232
return (long) -1;
6233
}
6234
} else {
6235
long val;
6236
PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
6237
if (!tmp) return (long) -1;
6238
val = __Pyx_PyInt_As_long(tmp);
6239
Py_DECREF(tmp);
6240
return val;
6241
}
6242
raise_overflow:
6243
PyErr_SetString(PyExc_OverflowError,
6244
"value too large to convert to long");
6245
return (long) -1;
6246
raise_neg_overflow:
6247
PyErr_SetString(PyExc_OverflowError,
6248
"can't convert negative value to long");
6249
return (long) -1;
6250
}
6251
6252
/* FastTypeChecks */
6253
#if CYTHON_COMPILING_IN_CPYTHON
6254
static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
6255
while (a) {
6256
a = a->tp_base;
6257
if (a == b)
6258
return 1;
6259
}
6260
return b == &PyBaseObject_Type;
6261
}
6262
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
6263
PyObject *mro;
6264
if (a == b) return 1;
6265
mro = a->tp_mro;
6266
if (likely(mro)) {
6267
Py_ssize_t i, n;
6268
n = PyTuple_GET_SIZE(mro);
6269
for (i = 0; i < n; i++) {
6270
if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
6271
return 1;
6272
}
6273
return 0;
6274
}
6275
return __Pyx_InBases(a, b);
6276
}
6277
#if PY_MAJOR_VERSION == 2
6278
static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
6279
PyObject *exception, *value, *tb;
6280
int res;
6281
__Pyx_PyThreadState_declare
6282
__Pyx_PyThreadState_assign
6283
__Pyx_ErrFetch(&exception, &value, &tb);
6284
res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
6285
if (unlikely(res == -1)) {
6286
PyErr_WriteUnraisable(err);
6287
res = 0;
6288
}
6289
if (!res) {
6290
res = PyObject_IsSubclass(err, exc_type2);
6291
if (unlikely(res == -1)) {
6292
PyErr_WriteUnraisable(err);
6293
res = 0;
6294
}
6295
}
6296
__Pyx_ErrRestore(exception, value, tb);
6297
return res;
6298
}
6299
#else
6300
static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
6301
int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
6302
if (!res) {
6303
res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
6304
}
6305
return res;
6306
}
6307
#endif
6308
static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
6309
Py_ssize_t i, n;
6310
assert(PyExceptionClass_Check(exc_type));
6311
n = PyTuple_GET_SIZE(tuple);
6312
#if PY_MAJOR_VERSION >= 3
6313
for (i=0; i<n; i++) {
6314
if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
6315
}
6316
#endif
6317
for (i=0; i<n; i++) {
6318
PyObject *t = PyTuple_GET_ITEM(tuple, i);
6319
#if PY_MAJOR_VERSION < 3
6320
if (likely(exc_type == t)) return 1;
6321
#endif
6322
if (likely(PyExceptionClass_Check(t))) {
6323
if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
6324
} else {
6325
}
6326
}
6327
return 0;
6328
}
6329
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
6330
if (likely(err == exc_type)) return 1;
6331
if (likely(PyExceptionClass_Check(err))) {
6332
if (likely(PyExceptionClass_Check(exc_type))) {
6333
return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
6334
} else if (likely(PyTuple_Check(exc_type))) {
6335
return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
6336
} else {
6337
}
6338
}
6339
return PyErr_GivenExceptionMatches(err, exc_type);
6340
}
6341
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
6342
assert(PyExceptionClass_Check(exc_type1));
6343
assert(PyExceptionClass_Check(exc_type2));
6344
if (likely(err == exc_type1 || err == exc_type2)) return 1;
6345
if (likely(PyExceptionClass_Check(err))) {
6346
return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
6347
}
6348
return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
6349
}
6350
#endif
6351
6352
/* CheckBinaryVersion */
6353
static int __Pyx_check_binary_version(void) {
6354
char ctversion[5];
6355
int same=1, i, found_dot;
6356
const char* rt_from_call = Py_GetVersion();
6357
PyOS_snprintf(ctversion, 5, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
6358
found_dot = 0;
6359
for (i = 0; i < 4; i++) {
6360
if (!ctversion[i]) {
6361
same = (rt_from_call[i] < '0' || rt_from_call[i] > '9');
6362
break;
6363
}
6364
if (rt_from_call[i] != ctversion[i]) {
6365
same = 0;
6366
break;
6367
}
6368
}
6369
if (!same) {
6370
char rtversion[5] = {'\0'};
6371
char message[200];
6372
for (i=0; i<4; ++i) {
6373
if (rt_from_call[i] == '.') {
6374
if (found_dot) break;
6375
found_dot = 1;
6376
} else if (rt_from_call[i] < '0' || rt_from_call[i] > '9') {
6377
break;
6378
}
6379
rtversion[i] = rt_from_call[i];
6380
}
6381
PyOS_snprintf(message, sizeof(message),
6382
"compiletime version %s of module '%.100s' "
6383
"does not match runtime version %s",
6384
ctversion, __Pyx_MODULE_NAME, rtversion);
6385
return PyErr_WarnEx(NULL, message, 1);
6386
}
6387
return 0;
6388
}
6389
6390
/* FunctionExport */
6391
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
6392
PyObject *d = 0;
6393
PyObject *cobj = 0;
6394
union {
6395
void (*fp)(void);
6396
void *p;
6397
} tmp;
6398
d = PyObject_GetAttrString(__pyx_m, (char *)"__pyx_capi__");
6399
if (!d) {
6400
PyErr_Clear();
6401
d = PyDict_New();
6402
if (!d)
6403
goto bad;
6404
Py_INCREF(d);
6405
if (PyModule_AddObject(__pyx_m, (char *)"__pyx_capi__", d) < 0)
6406
goto bad;
6407
}
6408
tmp.fp = f;
6409
#if PY_VERSION_HEX >= 0x02070000
6410
cobj = PyCapsule_New(tmp.p, sig, 0);
6411
#else
6412
cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
6413
#endif
6414
if (!cobj)
6415
goto bad;
6416
if (PyDict_SetItemString(d, name, cobj) < 0)
6417
goto bad;
6418
Py_DECREF(cobj);
6419
Py_DECREF(d);
6420
return 0;
6421
bad:
6422
Py_XDECREF(cobj);
6423
Py_XDECREF(d);
6424
return -1;
6425
}
6426
6427
/* InitStrings */
6428
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
6429
while (t->p) {
6430
#if PY_MAJOR_VERSION < 3
6431
if (t->is_unicode) {
6432
*t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
6433
} else if (t->intern) {
6434
*t->p = PyString_InternFromString(t->s);
6435
} else {
6436
*t->p = PyString_FromStringAndSize(t->s, t->n - 1);
6437
}
6438
#else
6439
if (t->is_unicode | t->is_str) {
6440
if (t->intern) {
6441
*t->p = PyUnicode_InternFromString(t->s);
6442
} else if (t->encoding) {
6443
*t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
6444
} else {
6445
*t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
6446
}
6447
} else {
6448
*t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
6449
}
6450
#endif
6451
if (!*t->p)
6452
return -1;
6453
if (PyObject_Hash(*t->p) == -1)
6454
return -1;
6455
++t;
6456
}
6457
return 0;
6458
}
6459
6460
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
6461
return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
6462
}
6463
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
6464
Py_ssize_t ignore;
6465
return __Pyx_PyObject_AsStringAndSize(o, &ignore);
6466
}
6467
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
6468
#if !CYTHON_PEP393_ENABLED
6469
static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
6470
char* defenc_c;
6471
PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
6472
if (!defenc) return NULL;
6473
defenc_c = PyBytes_AS_STRING(defenc);
6474
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
6475
{
6476
char* end = defenc_c + PyBytes_GET_SIZE(defenc);
6477
char* c;
6478
for (c = defenc_c; c < end; c++) {
6479
if ((unsigned char) (*c) >= 128) {
6480
PyUnicode_AsASCIIString(o);
6481
return NULL;
6482
}
6483
}
6484
}
6485
#endif
6486
*length = PyBytes_GET_SIZE(defenc);
6487
return defenc_c;
6488
}
6489
#else
6490
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
6491
if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
6492
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
6493
if (likely(PyUnicode_IS_ASCII(o))) {
6494
*length = PyUnicode_GET_LENGTH(o);
6495
return PyUnicode_AsUTF8(o);
6496
} else {
6497
PyUnicode_AsASCIIString(o);
6498
return NULL;
6499
}
6500
#else
6501
return PyUnicode_AsUTF8AndSize(o, length);
6502
#endif
6503
}
6504
#endif
6505
#endif
6506
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
6507
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
6508
if (
6509
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
6510
__Pyx_sys_getdefaultencoding_not_ascii &&
6511
#endif
6512
PyUnicode_Check(o)) {
6513
return __Pyx_PyUnicode_AsStringAndSize(o, length);
6514
} else
6515
#endif
6516
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
6517
if (PyByteArray_Check(o)) {
6518
*length = PyByteArray_GET_SIZE(o);
6519
return PyByteArray_AS_STRING(o);
6520
} else
6521
#endif
6522
{
6523
char* result;
6524
int r = PyBytes_AsStringAndSize(o, &result, length);
6525
if (unlikely(r < 0)) {
6526
return NULL;
6527
} else {
6528
return result;
6529
}
6530
}
6531
}
6532
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
6533
int is_true = x == Py_True;
6534
if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
6535
else return PyObject_IsTrue(x);
6536
}
6537
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
6538
int retval;
6539
if (unlikely(!x)) return -1;
6540
retval = __Pyx_PyObject_IsTrue(x);
6541
Py_DECREF(x);
6542
return retval;
6543
}
6544
static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
6545
#if PY_MAJOR_VERSION >= 3
6546
if (PyLong_Check(result)) {
6547
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
6548
"__int__ returned non-int (type %.200s). "
6549
"The ability to return an instance of a strict subclass of int "
6550
"is deprecated, and may be removed in a future version of Python.",
6551
Py_TYPE(result)->tp_name)) {
6552
Py_DECREF(result);
6553
return NULL;
6554
}
6555
return result;
6556
}
6557
#endif
6558
PyErr_Format(PyExc_TypeError,
6559
"__%.4s__ returned non-%.4s (type %.200s)",
6560
type_name, type_name, Py_TYPE(result)->tp_name);
6561
Py_DECREF(result);
6562
return NULL;
6563
}
6564
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
6565
#if CYTHON_USE_TYPE_SLOTS
6566
PyNumberMethods *m;
6567
#endif
6568
const char *name = NULL;
6569
PyObject *res = NULL;
6570
#if PY_MAJOR_VERSION < 3
6571
if (likely(PyInt_Check(x) || PyLong_Check(x)))
6572
#else
6573
if (likely(PyLong_Check(x)))
6574
#endif
6575
return __Pyx_NewRef(x);
6576
#if CYTHON_USE_TYPE_SLOTS
6577
m = Py_TYPE(x)->tp_as_number;
6578
#if PY_MAJOR_VERSION < 3
6579
if (m && m->nb_int) {
6580
name = "int";
6581
res = m->nb_int(x);
6582
}
6583
else if (m && m->nb_long) {
6584
name = "long";
6585
res = m->nb_long(x);
6586
}
6587
#else
6588
if (likely(m && m->nb_int)) {
6589
name = "int";
6590
res = m->nb_int(x);
6591
}
6592
#endif
6593
#else
6594
if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
6595
res = PyNumber_Int(x);
6596
}
6597
#endif
6598
if (likely(res)) {
6599
#if PY_MAJOR_VERSION < 3
6600
if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
6601
#else
6602
if (unlikely(!PyLong_CheckExact(res))) {
6603
#endif
6604
return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
6605
}
6606
}
6607
else if (!PyErr_Occurred()) {
6608
PyErr_SetString(PyExc_TypeError,
6609
"an integer is required");
6610
}
6611
return res;
6612
}
6613
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
6614
Py_ssize_t ival;
6615
PyObject *x;
6616
#if PY_MAJOR_VERSION < 3
6617
if (likely(PyInt_CheckExact(b))) {
6618
if (sizeof(Py_ssize_t) >= sizeof(long))
6619
return PyInt_AS_LONG(b);
6620
else
6621
return PyInt_AsSsize_t(b);
6622
}
6623
#endif
6624
if (likely(PyLong_CheckExact(b))) {
6625
#if CYTHON_USE_PYLONG_INTERNALS
6626
const digit* digits = ((PyLongObject*)b)->ob_digit;
6627
const Py_ssize_t size = Py_SIZE(b);
6628
if (likely(__Pyx_sst_abs(size) <= 1)) {
6629
ival = likely(size) ? digits[0] : 0;
6630
if (size == -1) ival = -ival;
6631
return ival;
6632
} else {
6633
switch (size) {
6634
case 2:
6635
if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
6636
return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6637
}
6638
break;
6639
case -2:
6640
if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
6641
return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6642
}
6643
break;
6644
case 3:
6645
if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
6646
return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6647
}
6648
break;
6649
case -3:
6650
if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
6651
return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6652
}
6653
break;
6654
case 4:
6655
if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
6656
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]));
6657
}
6658
break;
6659
case -4:
6660
if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
6661
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]));
6662
}
6663
break;
6664
}
6665
}
6666
#endif
6667
return PyLong_AsSsize_t(b);
6668
}
6669
x = PyNumber_Index(b);
6670
if (!x) return -1;
6671
ival = PyInt_AsSsize_t(x);
6672
Py_DECREF(x);
6673
return ival;
6674
}
6675
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) {
6676
if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) {
6677
return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o);
6678
#if PY_MAJOR_VERSION < 3
6679
} else if (likely(PyInt_CheckExact(o))) {
6680
return PyInt_AS_LONG(o);
6681
#endif
6682
} else {
6683
Py_ssize_t ival;
6684
PyObject *x;
6685
x = PyNumber_Index(o);
6686
if (!x) return -1;
6687
ival = PyInt_AsLong(x);
6688
Py_DECREF(x);
6689
return ival;
6690
}
6691
}
6692
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
6693
return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
6694
}
6695
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
6696
return PyInt_FromSize_t(ival);
6697
}
6698
6699
6700
#endif /* Py_PYTHON_H */
6701
6702