1 /*
2  * General object operations and protocol implementations,
3  * including their specialisations for certain builtins.
4  *
5  * Optional optimisations for builtins are in Optimize.c.
6  *
7  * Required replacements of builtins are in Builtins.c.
8  */
9 
10 /////////////// RaiseNoneIterError.proto ///////////////
11 
12 static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);
13 
14 /////////////// RaiseNoneIterError ///////////////
15 
__Pyx_RaiseNoneNotIterableError(void)16 static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
17     PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
18 }
19 
20 /////////////// RaiseTooManyValuesToUnpack.proto ///////////////
21 
22 static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
23 
24 /////////////// RaiseTooManyValuesToUnpack ///////////////
25 
__Pyx_RaiseTooManyValuesError(Py_ssize_t expected)26 static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
27     PyErr_Format(PyExc_ValueError,
28                  "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
29 }
30 
31 /////////////// RaiseNeedMoreValuesToUnpack.proto ///////////////
32 
33 static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
34 
35 /////////////// RaiseNeedMoreValuesToUnpack ///////////////
36 
__Pyx_RaiseNeedMoreValuesError(Py_ssize_t index)37 static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
38     PyErr_Format(PyExc_ValueError,
39                  "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
40                  index, (index == 1) ? "" : "s");
41 }
42 
43 /////////////// UnpackTupleError.proto ///////////////
44 
45 static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); /*proto*/
46 
47 /////////////// UnpackTupleError ///////////////
48 //@requires: RaiseNoneIterError
49 //@requires: RaiseNeedMoreValuesToUnpack
50 //@requires: RaiseTooManyValuesToUnpack
51 
__Pyx_UnpackTupleError(PyObject * t,Py_ssize_t index)52 static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
53     if (t == Py_None) {
54       __Pyx_RaiseNoneNotIterableError();
55     } else if (PyTuple_GET_SIZE(t) < index) {
56       __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
57     } else {
58       __Pyx_RaiseTooManyValuesError(index);
59     }
60 }
61 
62 /////////////// UnpackItemEndCheck.proto ///////////////
63 
64 static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/
65 
66 /////////////// UnpackItemEndCheck ///////////////
67 //@requires: RaiseTooManyValuesToUnpack
68 //@requires: IterFinish
69 
__Pyx_IternextUnpackEndCheck(PyObject * retval,Py_ssize_t expected)70 static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
71     if (unlikely(retval)) {
72         Py_DECREF(retval);
73         __Pyx_RaiseTooManyValuesError(expected);
74         return -1;
75     } else {
76         return __Pyx_IterFinish();
77     }
78     return 0;
79 }
80 
81 /////////////// UnpackTuple2.proto ///////////////
82 
83 #define __Pyx_unpack_tuple2(tuple, value1, value2, is_tuple, has_known_size, decref_tuple) \
84     (likely(is_tuple || PyTuple_Check(tuple)) ? \
85         (likely(has_known_size || PyTuple_GET_SIZE(tuple) == 2) ? \
86             __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple) : \
87             (__Pyx_UnpackTupleError(tuple, 2), -1)) : \
88         __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple))
89 
90 static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
91     PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple);
92 static int __Pyx_unpack_tuple2_generic(
93     PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple);
94 
95 /////////////// UnpackTuple2 ///////////////
96 //@requires: UnpackItemEndCheck
97 //@requires: UnpackTupleError
98 //@requires: RaiseNeedMoreValuesToUnpack
99 
__Pyx_unpack_tuple2_exact(PyObject * tuple,PyObject ** pvalue1,PyObject ** pvalue2,int decref_tuple)100 static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
101         PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) {
102     PyObject *value1 = NULL, *value2 = NULL;
103 #if CYTHON_COMPILING_IN_PYPY
104     value1 = PySequence_ITEM(tuple, 0);  if (unlikely(!value1)) goto bad;
105     value2 = PySequence_ITEM(tuple, 1);  if (unlikely(!value2)) goto bad;
106 #else
107     value1 = PyTuple_GET_ITEM(tuple, 0);  Py_INCREF(value1);
108     value2 = PyTuple_GET_ITEM(tuple, 1);  Py_INCREF(value2);
109 #endif
110     if (decref_tuple) {
111         Py_DECREF(tuple);
112     }
113 
114     *pvalue1 = value1;
115     *pvalue2 = value2;
116     return 0;
117 #if CYTHON_COMPILING_IN_PYPY
118 bad:
119     Py_XDECREF(value1);
120     Py_XDECREF(value2);
121     if (decref_tuple) { Py_XDECREF(tuple); }
122     return -1;
123 #endif
124 }
125 
__Pyx_unpack_tuple2_generic(PyObject * tuple,PyObject ** pvalue1,PyObject ** pvalue2,int has_known_size,int decref_tuple)126 static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2,
127                                        int has_known_size, int decref_tuple) {
128     Py_ssize_t index;
129     PyObject *value1 = NULL, *value2 = NULL, *iter = NULL;
130     iternextfunc iternext;
131 
132     iter = PyObject_GetIter(tuple);
133     if (unlikely(!iter)) goto bad;
134     if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; }
135 
136     iternext = Py_TYPE(iter)->tp_iternext;
137     value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; }
138     value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; }
139     if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad;
140 
141     Py_DECREF(iter);
142     *pvalue1 = value1;
143     *pvalue2 = value2;
144     return 0;
145 
146 unpacking_failed:
147     if (!has_known_size && __Pyx_IterFinish() == 0)
148         __Pyx_RaiseNeedMoreValuesError(index);
149 bad:
150     Py_XDECREF(iter);
151     Py_XDECREF(value1);
152     Py_XDECREF(value2);
153     if (decref_tuple) { Py_XDECREF(tuple); }
154     return -1;
155 }
156 
157 
158 /////////////// IterNext.proto ///////////////
159 
160 #define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL)
161 static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject *, PyObject *); /*proto*/
162 
163 /////////////// IterNext ///////////////
164 //@requires: Exceptions.c::PyThreadStateGet
165 //@requires: Exceptions.c::PyErrFetchRestore
166 
__Pyx_PyIter_Next2Default(PyObject * defval)167 static PyObject *__Pyx_PyIter_Next2Default(PyObject* defval) {
168     PyObject* exc_type;
169     __Pyx_PyThreadState_declare
170     __Pyx_PyThreadState_assign
171     exc_type = __Pyx_PyErr_Occurred();
172     if (unlikely(exc_type)) {
173         if (!defval || unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))
174             return NULL;
175         __Pyx_PyErr_Clear();
176         Py_INCREF(defval);
177         return defval;
178     }
179     if (defval) {
180         Py_INCREF(defval);
181         return defval;
182     }
183     __Pyx_PyErr_SetNone(PyExc_StopIteration);
184     return NULL;
185 }
186 
__Pyx_PyIter_Next_ErrorNoIterator(PyObject * iterator)187 static void __Pyx_PyIter_Next_ErrorNoIterator(PyObject *iterator) {
188     PyErr_Format(PyExc_TypeError,
189         "%.200s object is not an iterator", Py_TYPE(iterator)->tp_name);
190 }
191 
192 // originally copied from Py3's builtin_next()
__Pyx_PyIter_Next2(PyObject * iterator,PyObject * defval)193 static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject* defval) {
194     PyObject* next;
195     // We always do a quick slot check because calling PyIter_Check() is so wasteful.
196     iternextfunc iternext = Py_TYPE(iterator)->tp_iternext;
197     if (likely(iternext)) {
198 #if CYTHON_USE_TYPE_SLOTS
199         next = iternext(iterator);
200         if (likely(next))
201             return next;
202         #if PY_VERSION_HEX >= 0x02070000
203         if (unlikely(iternext == &_PyObject_NextNotImplemented))
204             return NULL;
205         #endif
206 #else
207         // Since the slot was set, assume that PyIter_Next() will likely succeed, and properly fail otherwise.
208         // Note: PyIter_Next() crashes in CPython if "tp_iternext" is NULL.
209         next = PyIter_Next(iterator);
210         if (likely(next))
211             return next;
212 #endif
213     } else if (CYTHON_USE_TYPE_SLOTS || unlikely(!PyIter_Check(iterator))) {
214         // If CYTHON_USE_TYPE_SLOTS, then the slot was not set and we don't have an iterable.
215         // Otherwise, don't trust "tp_iternext" and rely on PyIter_Check().
216         __Pyx_PyIter_Next_ErrorNoIterator(iterator);
217         return NULL;
218     }
219 #if !CYTHON_USE_TYPE_SLOTS
220     else {
221         // We have an iterator with an empty "tp_iternext", but didn't call next() on it yet.
222         next = PyIter_Next(iterator);
223         if (likely(next))
224             return next;
225     }
226 #endif
227     return __Pyx_PyIter_Next2Default(defval);
228 }
229 
230 /////////////// IterFinish.proto ///////////////
231 
232 static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/
233 
234 /////////////// IterFinish ///////////////
235 
236 // When PyIter_Next(iter) has returned NULL in order to signal termination,
237 // this function does the right cleanup and returns 0 on success.  If it
238 // detects an error that occurred in the iterator, it returns -1.
239 
__Pyx_IterFinish(void)240 static CYTHON_INLINE int __Pyx_IterFinish(void) {
241 #if CYTHON_FAST_THREAD_STATE
242     PyThreadState *tstate = __Pyx_PyThreadState_Current;
243     PyObject* exc_type = tstate->curexc_type;
244     if (unlikely(exc_type)) {
245         if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) {
246             PyObject *exc_value, *exc_tb;
247             exc_value = tstate->curexc_value;
248             exc_tb = tstate->curexc_traceback;
249             tstate->curexc_type = 0;
250             tstate->curexc_value = 0;
251             tstate->curexc_traceback = 0;
252             Py_DECREF(exc_type);
253             Py_XDECREF(exc_value);
254             Py_XDECREF(exc_tb);
255             return 0;
256         } else {
257             return -1;
258         }
259     }
260     return 0;
261 #else
262     if (unlikely(PyErr_Occurred())) {
263         if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
264             PyErr_Clear();
265             return 0;
266         } else {
267             return -1;
268         }
269     }
270     return 0;
271 #endif
272 }
273 
274 
275 /////////////// ObjectGetItem.proto ///////////////
276 
277 #if CYTHON_USE_TYPE_SLOTS
278 static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key);/*proto*/
279 #else
280 #define __Pyx_PyObject_GetItem(obj, key)  PyObject_GetItem(obj, key)
281 #endif
282 
283 /////////////// ObjectGetItem ///////////////
284 // //@requires: GetItemInt - added in IndexNode as it uses templating.
285 
286 #if CYTHON_USE_TYPE_SLOTS
__Pyx_PyObject_GetIndex(PyObject * obj,PyObject * index)287 static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) {
288     PyObject *runerr;
289     Py_ssize_t key_value;
290     PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence;
291     if (unlikely(!(m && m->sq_item))) {
292         PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name);
293         return NULL;
294     }
295 
296     key_value = __Pyx_PyIndex_AsSsize_t(index);
297     if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
298         return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
299     }
300 
301     // Error handling code -- only manage OverflowError differently.
302     if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
303         PyErr_Clear();
304         PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name);
305     }
306     return NULL;
307 }
308 
__Pyx_PyObject_GetItem(PyObject * obj,PyObject * key)309 static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) {
310     PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping;
311     if (likely(m && m->mp_subscript)) {
312         return m->mp_subscript(obj, key);
313     }
314     return __Pyx_PyObject_GetIndex(obj, key);
315 }
316 #endif
317 
318 
319 /////////////// DictGetItem.proto ///////////////
320 
321 #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
322 static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key);/*proto*/
323 
324 #define __Pyx_PyObject_Dict_GetItem(obj, name) \
325     (likely(PyDict_CheckExact(obj)) ? \
326      __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name))
327 
328 #else
329 #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
330 #define __Pyx_PyObject_Dict_GetItem(obj, name)  PyObject_GetItem(obj, name)
331 #endif
332 
333 /////////////// DictGetItem ///////////////
334 
335 #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
__Pyx_PyDict_GetItem(PyObject * d,PyObject * key)336 static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
337     PyObject *value;
338     value = PyDict_GetItemWithError(d, key);
339     if (unlikely(!value)) {
340         if (!PyErr_Occurred()) {
341             if (unlikely(PyTuple_Check(key))) {
342                 // CPython interprets tuples as separate arguments => must wrap them in another tuple.
343                 PyObject* args = PyTuple_Pack(1, key);
344                 if (likely(args)) {
345                     PyErr_SetObject(PyExc_KeyError, args);
346                     Py_DECREF(args);
347                 }
348             } else {
349                 // Avoid tuple packing if possible.
350                 PyErr_SetObject(PyExc_KeyError, key);
351             }
352         }
353         return NULL;
354     }
355     Py_INCREF(value);
356     return value;
357 }
358 #endif
359 
360 /////////////// GetItemInt.proto ///////////////
361 
362 #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
363     (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
364     __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) : \
365     (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) : \
366                __Pyx_GetItemInt_Generic(o, to_py_func(i))))
367 
368 {{for type in ['List', 'Tuple']}}
369 #define __Pyx_GetItemInt_{{type}}(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
370     (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
371     __Pyx_GetItemInt_{{type}}_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
372     (PyErr_SetString(PyExc_IndexError, "{{ type.lower() }} index out of range"), (PyObject*)NULL))
373 
374 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_{{type}}_Fast(PyObject *o, Py_ssize_t i,
375                                                               int wraparound, int boundscheck);
376 {{endfor}}
377 
378 static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
379 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
380                                                      int is_list, int wraparound, int boundscheck);
381 
382 /////////////// GetItemInt ///////////////
383 
384 static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
385     PyObject *r;
386     if (!j) return NULL;
387     r = PyObject_GetItem(o, j);
388     Py_DECREF(j);
389     return r;
390 }
391 
392 {{for type in ['List', 'Tuple']}}
393 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_{{type}}_Fast(PyObject *o, Py_ssize_t i,
394                                                               CYTHON_NCP_UNUSED int wraparound,
395                                                               CYTHON_NCP_UNUSED int boundscheck) {
396 #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
397     Py_ssize_t wrapped_i = i;
398     if (wraparound & unlikely(i < 0)) {
399         wrapped_i += Py{{type}}_GET_SIZE(o);
400     }
401     if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, Py{{type}}_GET_SIZE(o)))) {
402         PyObject *r = Py{{type}}_GET_ITEM(o, wrapped_i);
403         Py_INCREF(r);
404         return r;
405     }
406     return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
407 #else
408     return PySequence_GetItem(o, i);
409 #endif
410 }
411 {{endfor}}
412 
413 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
414                                                      CYTHON_NCP_UNUSED int wraparound,
415                                                      CYTHON_NCP_UNUSED int boundscheck) {
416 #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
417     if (is_list || PyList_CheckExact(o)) {
418         Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
419         if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
420             PyObject *r = PyList_GET_ITEM(o, n);
421             Py_INCREF(r);
422             return r;
423         }
424     }
425     else if (PyTuple_CheckExact(o)) {
426         Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
427         if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
428             PyObject *r = PyTuple_GET_ITEM(o, n);
429             Py_INCREF(r);
430             return r;
431         }
432     } else {
433         // inlined PySequence_GetItem() + special cased length overflow
434         PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
435         if (likely(m && m->sq_item)) {
436             if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
437                 Py_ssize_t l = m->sq_length(o);
438                 if (likely(l >= 0)) {
439                     i += l;
440                 } else {
441                     // if length > max(Py_ssize_t), maybe the object can wrap around itself?
442                     if (!PyErr_ExceptionMatches(PyExc_OverflowError))
443                         return NULL;
444                     PyErr_Clear();
445                 }
446             }
447             return m->sq_item(o, i);
448         }
449     }
450 #else
451     if (is_list || PySequence_Check(o)) {
452         return PySequence_GetItem(o, i);
453     }
454 #endif
455     return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
456 }
457 
458 /////////////// SetItemInt.proto ///////////////
459 
460 #define __Pyx_SetItemInt(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
461     (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
462     __Pyx_SetItemInt_Fast(o, (Py_ssize_t)i, v, is_list, wraparound, boundscheck) : \
463     (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) : \
464                __Pyx_SetItemInt_Generic(o, to_py_func(i), v)))
465 
466 static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v);
467 static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v,
468                                                int is_list, int wraparound, int boundscheck);
469 
470 /////////////// SetItemInt ///////////////
471 
472 static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
473     int r;
474     if (!j) return -1;
475     r = PyObject_SetItem(o, j, v);
476     Py_DECREF(j);
477     return r;
478 }
479 
480 static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list,
481                                                CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) {
482 #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
483     if (is_list || PyList_CheckExact(o)) {
484         Py_ssize_t n = (!wraparound) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o));
485         if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o)))) {
486             PyObject* old = PyList_GET_ITEM(o, n);
487             Py_INCREF(v);
488             PyList_SET_ITEM(o, n, v);
489             Py_DECREF(old);
490             return 1;
491         }
492     } else {
493         // inlined PySequence_SetItem() + special cased length overflow
494         PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
495         if (likely(m && m->sq_ass_item)) {
496             if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
497                 Py_ssize_t l = m->sq_length(o);
498                 if (likely(l >= 0)) {
499                     i += l;
500                 } else {
501                     // if length > max(Py_ssize_t), maybe the object can wrap around itself?
502                     if (!PyErr_ExceptionMatches(PyExc_OverflowError))
503                         return -1;
504                     PyErr_Clear();
505                 }
506             }
507             return m->sq_ass_item(o, i, v);
508         }
509     }
510 #else
511 #if CYTHON_COMPILING_IN_PYPY
512     if (is_list || (PySequence_Check(o) && !PyDict_Check(o)))
513 #else
514     if (is_list || PySequence_Check(o))
515 #endif
516     {
517         return PySequence_SetItem(o, i, v);
518     }
519 #endif
520     return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v);
521 }
522 
523 
524 /////////////// DelItemInt.proto ///////////////
525 
526 #define __Pyx_DelItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
527     (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
528     __Pyx_DelItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound) : \
529     (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) : \
530                __Pyx_DelItem_Generic(o, to_py_func(i))))
531 
532 static int __Pyx_DelItem_Generic(PyObject *o, PyObject *j);
533 static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
534                                                int is_list, int wraparound);
535 
536 /////////////// DelItemInt ///////////////
537 
538 static int __Pyx_DelItem_Generic(PyObject *o, PyObject *j) {
539     int r;
540     if (!j) return -1;
541     r = PyObject_DelItem(o, j);
542     Py_DECREF(j);
543     return r;
544 }
545 
546 static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
547                                                CYTHON_UNUSED int is_list, CYTHON_NCP_UNUSED int wraparound) {
548 #if !CYTHON_USE_TYPE_SLOTS
549     if (is_list || PySequence_Check(o)) {
550         return PySequence_DelItem(o, i);
551     }
552 #else
553     // inlined PySequence_DelItem() + special cased length overflow
554     PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
555     if (likely(m && m->sq_ass_item)) {
556         if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
557             Py_ssize_t l = m->sq_length(o);
558             if (likely(l >= 0)) {
559                 i += l;
560             } else {
561                 // if length > max(Py_ssize_t), maybe the object can wrap around itself?
562                 if (!PyErr_ExceptionMatches(PyExc_OverflowError))
563                     return -1;
564                 PyErr_Clear();
565             }
566         }
567         return m->sq_ass_item(o, i, (PyObject *)NULL);
568     }
569 #endif
570     return __Pyx_DelItem_Generic(o, PyInt_FromSsize_t(i));
571 }
572 
573 
574 /////////////// SliceObject.proto ///////////////
575 
576 // we pass pointer addresses to show the C compiler what is NULL and what isn't
577 {{if access == 'Get'}}
578 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
579         PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
580         PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
581         int has_cstart, int has_cstop, int wraparound);
582 {{else}}
583 #define __Pyx_PyObject_DelSlice(obj, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound) \
584     __Pyx_PyObject_SetSlice(obj, (PyObject*)NULL, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound)
585 
586 // we pass pointer addresses to show the C compiler what is NULL and what isn't
587 static CYTHON_INLINE int __Pyx_PyObject_SetSlice(
588         PyObject* obj, PyObject* value, Py_ssize_t cstart, Py_ssize_t cstop,
589         PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
590         int has_cstart, int has_cstop, int wraparound);
591 {{endif}}
592 
593 /////////////// SliceObject ///////////////
594 
595 {{if access == 'Get'}}
596 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
597 {{else}}
598 static CYTHON_INLINE int __Pyx_PyObject_SetSlice(PyObject* obj, PyObject* value,
599 {{endif}}
600         Py_ssize_t cstart, Py_ssize_t cstop,
601         PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
602         int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
603 #if CYTHON_USE_TYPE_SLOTS
604     PyMappingMethods* mp;
605 #if PY_MAJOR_VERSION < 3
606     PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
607     if (likely(ms && ms->sq_{{if access == 'Set'}}ass_{{endif}}slice)) {
608         if (!has_cstart) {
609             if (_py_start && (*_py_start != Py_None)) {
610                 cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
611                 if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
612             } else
613                 cstart = 0;
614         }
615         if (!has_cstop) {
616             if (_py_stop && (*_py_stop != Py_None)) {
617                 cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
618                 if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
619             } else
620                 cstop = PY_SSIZE_T_MAX;
621         }
622         if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
623             Py_ssize_t l = ms->sq_length(obj);
624             if (likely(l >= 0)) {
625                 if (cstop < 0) {
626                     cstop += l;
627                     if (cstop < 0) cstop = 0;
628                 }
629                 if (cstart < 0) {
630                     cstart += l;
631                     if (cstart < 0) cstart = 0;
632                 }
633             } else {
634                 // if length > max(Py_ssize_t), maybe the object can wrap around itself?
635                 if (!PyErr_ExceptionMatches(PyExc_OverflowError))
636                     goto bad;
637                 PyErr_Clear();
638             }
639         }
640 {{if access == 'Get'}}
641         return ms->sq_slice(obj, cstart, cstop);
642 {{else}}
643         return ms->sq_ass_slice(obj, cstart, cstop, value);
644 {{endif}}
645     }
646 #endif
647 
648     mp = Py_TYPE(obj)->tp_as_mapping;
649 {{if access == 'Get'}}
650     if (likely(mp && mp->mp_subscript))
651 {{else}}
652     if (likely(mp && mp->mp_ass_subscript))
653 {{endif}}
654 #endif
655     {
656         {{if access == 'Get'}}PyObject*{{else}}int{{endif}} result;
657         PyObject *py_slice, *py_start, *py_stop;
658         if (_py_slice) {
659             py_slice = *_py_slice;
660         } else {
661             PyObject* owned_start = NULL;
662             PyObject* owned_stop = NULL;
663             if (_py_start) {
664                 py_start = *_py_start;
665             } else {
666                 if (has_cstart) {
667                     owned_start = py_start = PyInt_FromSsize_t(cstart);
668                     if (unlikely(!py_start)) goto bad;
669                 } else
670                     py_start = Py_None;
671             }
672             if (_py_stop) {
673                 py_stop = *_py_stop;
674             } else {
675                 if (has_cstop) {
676                     owned_stop = py_stop = PyInt_FromSsize_t(cstop);
677                     if (unlikely(!py_stop)) {
678                         Py_XDECREF(owned_start);
679                         goto bad;
680                     }
681                 } else
682                     py_stop = Py_None;
683             }
684             py_slice = PySlice_New(py_start, py_stop, Py_None);
685             Py_XDECREF(owned_start);
686             Py_XDECREF(owned_stop);
687             if (unlikely(!py_slice)) goto bad;
688         }
689 #if CYTHON_USE_TYPE_SLOTS
690 {{if access == 'Get'}}
691         result = mp->mp_subscript(obj, py_slice);
692 #else
693         result = PyObject_GetItem(obj, py_slice);
694 {{else}}
695         result = mp->mp_ass_subscript(obj, py_slice, value);
696 #else
697         result = value ? PyObject_SetItem(obj, py_slice, value) : PyObject_DelItem(obj, py_slice);
698 {{endif}}
699 #endif
700         if (!_py_slice) {
701             Py_DECREF(py_slice);
702         }
703         return result;
704     }
705     PyErr_Format(PyExc_TypeError,
706 {{if access == 'Get'}}
707         "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
708 {{else}}
709         "'%.200s' object does not support slice %.10s",
710         Py_TYPE(obj)->tp_name, value ? "assignment" : "deletion");
711 {{endif}}
712 
713 bad:
714     return {{if access == 'Get'}}NULL{{else}}-1{{endif}};
715 }
716 
717 
718 /////////////// SliceTupleAndList.proto ///////////////
719 
720 #if CYTHON_COMPILING_IN_CPYTHON
721 static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
722 static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
723 #else
724 #define __Pyx_PyList_GetSlice(seq, start, stop)   PySequence_GetSlice(seq, start, stop)
725 #define __Pyx_PyTuple_GetSlice(seq, start, stop)  PySequence_GetSlice(seq, start, stop)
726 #endif
727 
728 /////////////// SliceTupleAndList ///////////////
729 
730 #if CYTHON_COMPILING_IN_CPYTHON
731 static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop, Py_ssize_t* _length) {
732     Py_ssize_t start = *_start, stop = *_stop, length = *_length;
733     if (start < 0) {
734         start += length;
735         if (start < 0)
736             start = 0;
737     }
738 
739     if (stop < 0)
740         stop += length;
741     else if (stop > length)
742         stop = length;
743 
744     *_length = stop - start;
745     *_start = start;
746     *_stop = stop;
747 }
748 
749 static CYTHON_INLINE void __Pyx_copy_object_array(PyObject** CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) {
750     PyObject *v;
751     Py_ssize_t i;
752     for (i = 0; i < length; i++) {
753         v = dest[i] = src[i];
754         Py_INCREF(v);
755     }
756 }
757 
758 {{for type in ['List', 'Tuple']}}
759 static CYTHON_INLINE PyObject* __Pyx_Py{{type}}_GetSlice(
760             PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
761     PyObject* dest;
762     Py_ssize_t length = Py{{type}}_GET_SIZE(src);
763     __Pyx_crop_slice(&start, &stop, &length);
764     if (unlikely(length <= 0))
765         return Py{{type}}_New(0);
766 
767     dest = Py{{type}}_New(length);
768     if (unlikely(!dest))
769         return NULL;
770     __Pyx_copy_object_array(
771         ((Py{{type}}Object*)src)->ob_item + start,
772         ((Py{{type}}Object*)dest)->ob_item,
773         length);
774     return dest;
775 }
776 {{endfor}}
777 #endif
778 
779 
780 /////////////// CalculateMetaclass.proto ///////////////
781 
782 static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases);
783 
784 /////////////// CalculateMetaclass ///////////////
785 
786 static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) {
787     Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases);
788     for (i=0; i < nbases; i++) {
789         PyTypeObject *tmptype;
790         PyObject *tmp = PyTuple_GET_ITEM(bases, i);
791         tmptype = Py_TYPE(tmp);
792 #if PY_MAJOR_VERSION < 3
793         if (tmptype == &PyClass_Type)
794             continue;
795 #endif
796         if (!metaclass) {
797             metaclass = tmptype;
798             continue;
799         }
800         if (PyType_IsSubtype(metaclass, tmptype))
801             continue;
802         if (PyType_IsSubtype(tmptype, metaclass)) {
803             metaclass = tmptype;
804             continue;
805         }
806         // else:
807         PyErr_SetString(PyExc_TypeError,
808                         "metaclass conflict: "
809                         "the metaclass of a derived class "
810                         "must be a (non-strict) subclass "
811                         "of the metaclasses of all its bases");
812         return NULL;
813     }
814     if (!metaclass) {
815 #if PY_MAJOR_VERSION < 3
816         metaclass = &PyClass_Type;
817 #else
818         metaclass = &PyType_Type;
819 #endif
820     }
821     // make owned reference
822     Py_INCREF((PyObject*) metaclass);
823     return (PyObject*) metaclass;
824 }
825 
826 
827 /////////////// FindInheritedMetaclass.proto ///////////////
828 
829 static PyObject *__Pyx_FindInheritedMetaclass(PyObject *bases); /*proto*/
830 
831 /////////////// FindInheritedMetaclass ///////////////
832 //@requires: PyObjectGetAttrStr
833 //@requires: CalculateMetaclass
834 
835 static PyObject *__Pyx_FindInheritedMetaclass(PyObject *bases) {
836     PyObject *metaclass;
837     if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
838         PyTypeObject *metatype;
839 #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
840         PyObject *base = PyTuple_GET_ITEM(bases, 0);
841 #else
842         PyObject *base = PySequence_ITEM(bases, 0);
843 #endif
844 #if PY_MAJOR_VERSION < 3
845         PyObject* basetype = __Pyx_PyObject_GetAttrStr(base, PYIDENT("__class__"));
846         if (basetype) {
847             metatype = (PyType_Check(basetype)) ? ((PyTypeObject*) basetype) : NULL;
848         } else {
849             PyErr_Clear();
850             metatype = Py_TYPE(base);
851             basetype = (PyObject*) metatype;
852             Py_INCREF(basetype);
853         }
854 #else
855         metatype = Py_TYPE(base);
856 #endif
857         metaclass = __Pyx_CalculateMetaclass(metatype, bases);
858 #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS)
859         Py_DECREF(base);
860 #endif
861 #if PY_MAJOR_VERSION < 3
862         Py_DECREF(basetype);
863 #endif
864     } else {
865         // no bases => use default metaclass
866 #if PY_MAJOR_VERSION < 3
867         metaclass = (PyObject *) &PyClass_Type;
868 #else
869         metaclass = (PyObject *) &PyType_Type;
870 #endif
871         Py_INCREF(metaclass);
872     }
873     return metaclass;
874 }
875 
876 /////////////// Py3MetaclassGet.proto ///////////////
877 
878 static PyObject *__Pyx_Py3MetaclassGet(PyObject *bases, PyObject *mkw); /*proto*/
879 
880 /////////////// Py3MetaclassGet ///////////////
881 //@requires: FindInheritedMetaclass
882 //@requires: CalculateMetaclass
883 
884 static PyObject *__Pyx_Py3MetaclassGet(PyObject *bases, PyObject *mkw) {
885     PyObject *metaclass = mkw ? __Pyx_PyDict_GetItemStr(mkw, PYIDENT("metaclass")) : NULL;
886     if (metaclass) {
887         Py_INCREF(metaclass);
888         if (PyDict_DelItem(mkw, PYIDENT("metaclass")) < 0) {
889             Py_DECREF(metaclass);
890             return NULL;
891         }
892         if (PyType_Check(metaclass)) {
893             PyObject* orig = metaclass;
894             metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
895             Py_DECREF(orig);
896         }
897         return metaclass;
898     }
899     return __Pyx_FindInheritedMetaclass(bases);
900 }
901 
902 /////////////// CreateClass.proto ///////////////
903 
904 static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
905                                    PyObject *qualname, PyObject *modname); /*proto*/
906 
907 /////////////// CreateClass ///////////////
908 //@requires: FindInheritedMetaclass
909 //@requires: CalculateMetaclass
910 
911 static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
912                                    PyObject *qualname, PyObject *modname) {
913     PyObject *result;
914     PyObject *metaclass;
915 
916     if (PyDict_SetItem(dict, PYIDENT("__module__"), modname) < 0)
917         return NULL;
918     if (PyDict_SetItem(dict, PYIDENT("__qualname__"), qualname) < 0)
919         return NULL;
920 
921     /* Python2 __metaclass__ */
922     metaclass = __Pyx_PyDict_GetItemStr(dict, PYIDENT("__metaclass__"));
923     if (metaclass) {
924         Py_INCREF(metaclass);
925         if (PyType_Check(metaclass)) {
926             PyObject* orig = metaclass;
927             metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
928             Py_DECREF(orig);
929         }
930     } else {
931         metaclass = __Pyx_FindInheritedMetaclass(bases);
932     }
933     if (unlikely(!metaclass))
934         return NULL;
935     result = PyObject_CallFunctionObjArgs(metaclass, name, bases, dict, NULL);
936     Py_DECREF(metaclass);
937     return result;
938 }
939 
940 /////////////// Py3ClassCreate.proto ///////////////
941 
942 static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname,
943                                            PyObject *mkw, PyObject *modname, PyObject *doc); /*proto*/
944 static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict,
945                                       PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass); /*proto*/
946 
947 /////////////// Py3ClassCreate ///////////////
948 //@requires: PyObjectGetAttrStr
949 //@requires: CalculateMetaclass
950 
951 static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name,
952                                            PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) {
953     PyObject *ns;
954     if (metaclass) {
955         PyObject *prep = __Pyx_PyObject_GetAttrStr(metaclass, PYIDENT("__prepare__"));
956         if (prep) {
957             PyObject *pargs = PyTuple_Pack(2, name, bases);
958             if (unlikely(!pargs)) {
959                 Py_DECREF(prep);
960                 return NULL;
961             }
962             ns = PyObject_Call(prep, pargs, mkw);
963             Py_DECREF(prep);
964             Py_DECREF(pargs);
965         } else {
966             if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError)))
967                 return NULL;
968             PyErr_Clear();
969             ns = PyDict_New();
970         }
971     } else {
972         ns = PyDict_New();
973     }
974 
975     if (unlikely(!ns))
976         return NULL;
977 
978     /* Required here to emulate assignment order */
979     if (unlikely(PyObject_SetItem(ns, PYIDENT("__module__"), modname) < 0)) goto bad;
980     if (unlikely(PyObject_SetItem(ns, PYIDENT("__qualname__"), qualname) < 0)) goto bad;
981     if (unlikely(doc && PyObject_SetItem(ns, PYIDENT("__doc__"), doc) < 0)) goto bad;
982     return ns;
983 bad:
984     Py_DECREF(ns);
985     return NULL;
986 }
987 
988 static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases,
989                                       PyObject *dict, PyObject *mkw,
990                                       int calculate_metaclass, int allow_py2_metaclass) {
991     PyObject *result, *margs;
992     PyObject *owned_metaclass = NULL;
993     if (allow_py2_metaclass) {
994         /* honour Python2 __metaclass__ for backward compatibility */
995         owned_metaclass = PyObject_GetItem(dict, PYIDENT("__metaclass__"));
996         if (owned_metaclass) {
997             metaclass = owned_metaclass;
998         } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
999             PyErr_Clear();
1000         } else {
1001             return NULL;
1002         }
1003     }
1004     if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) {
1005         metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
1006         Py_XDECREF(owned_metaclass);
1007         if (unlikely(!metaclass))
1008             return NULL;
1009         owned_metaclass = metaclass;
1010     }
1011     margs = PyTuple_Pack(3, name, bases, dict);
1012     if (unlikely(!margs)) {
1013         result = NULL;
1014     } else {
1015         result = PyObject_Call(metaclass, margs, mkw);
1016         Py_DECREF(margs);
1017     }
1018     Py_XDECREF(owned_metaclass);
1019     return result;
1020 }
1021 
1022 /////////////// ExtTypeTest.proto ///////////////
1023 
1024 static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
1025 
1026 /////////////// ExtTypeTest ///////////////
1027 
1028 static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
1029     if (unlikely(!type)) {
1030         PyErr_SetString(PyExc_SystemError, "Missing type object");
1031         return 0;
1032     }
1033     if (likely(__Pyx_TypeCheck(obj, type)))
1034         return 1;
1035     PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
1036                  Py_TYPE(obj)->tp_name, type->tp_name);
1037     return 0;
1038 }
1039 
1040 /////////////// CallableCheck.proto ///////////////
1041 
1042 #if CYTHON_USE_TYPE_SLOTS && PY_MAJOR_VERSION >= 3
1043 #define __Pyx_PyCallable_Check(obj)   (Py_TYPE(obj)->tp_call != NULL)
1044 #else
1045 #define __Pyx_PyCallable_Check(obj)   PyCallable_Check(obj)
1046 #endif
1047 
1048 /////////////// PyDictContains.proto ///////////////
1049 
1050 static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) {
1051     int result = PyDict_Contains(dict, item);
1052     return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
1053 }
1054 
1055 /////////////// PySetContains.proto ///////////////
1056 
1057 static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq); /* proto */
1058 
1059 /////////////// PySetContains ///////////////
1060 //@requires: Builtins.c::pyfrozenset_new
1061 
1062 static int __Pyx_PySet_ContainsUnhashable(PyObject *set, PyObject *key) {
1063     int result = -1;
1064     if (PySet_Check(key) && PyErr_ExceptionMatches(PyExc_TypeError)) {
1065         /* Convert key to frozenset */
1066         PyObject *tmpkey;
1067         PyErr_Clear();
1068         tmpkey = __Pyx_PyFrozenSet_New(key);
1069         if (tmpkey != NULL) {
1070             result = PySet_Contains(set, tmpkey);
1071             Py_DECREF(tmpkey);
1072         }
1073     }
1074     return result;
1075 }
1076 
1077 static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq) {
1078     int result = PySet_Contains(set, key);
1079 
1080     if (unlikely(result < 0)) {
1081         result = __Pyx_PySet_ContainsUnhashable(set, key);
1082     }
1083     return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
1084 }
1085 
1086 /////////////// PySequenceContains.proto ///////////////
1087 
1088 static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) {
1089     int result = PySequence_Contains(seq, item);
1090     return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
1091 }
1092 
1093 /////////////// PyBoolOrNullFromLong.proto ///////////////
1094 
1095 static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
1096     return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b);
1097 }
1098 
1099 /////////////// GetBuiltinName.proto ///////////////
1100 
1101 static PyObject *__Pyx_GetBuiltinName(PyObject *name); /*proto*/
1102 
1103 /////////////// GetBuiltinName ///////////////
1104 //@requires: PyObjectGetAttrStr
1105 //@substitute: naming
1106 
1107 static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
1108     PyObject* result = __Pyx_PyObject_GetAttrStr($builtins_cname, name);
1109     if (unlikely(!result)) {
1110         PyErr_Format(PyExc_NameError,
1111 #if PY_MAJOR_VERSION >= 3
1112             "name '%U' is not defined", name);
1113 #else
1114             "name '%.200s' is not defined", PyString_AS_STRING(name));
1115 #endif
1116     }
1117     return result;
1118 }
1119 
1120 /////////////// GetNameInClass.proto ///////////////
1121 
1122 #define __Pyx_GetNameInClass(var, nmspace, name)  (var) = __Pyx__GetNameInClass(nmspace, name)
1123 static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name); /*proto*/
1124 
1125 /////////////// GetNameInClass ///////////////
1126 //@requires: PyObjectGetAttrStr
1127 //@requires: GetModuleGlobalName
1128 //@requires: Exceptions.c::PyThreadStateGet
1129 //@requires: Exceptions.c::PyErrFetchRestore
1130 //@requires: Exceptions.c::PyErrExceptionMatches
1131 
1132 static PyObject *__Pyx_GetGlobalNameAfterAttributeLookup(PyObject *name) {
1133     PyObject *result;
1134     __Pyx_PyThreadState_declare
1135     __Pyx_PyThreadState_assign
1136     if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
1137         return NULL;
1138     __Pyx_PyErr_Clear();
1139     __Pyx_GetModuleGlobalNameUncached(result, name);
1140     return result;
1141 }
1142 
1143 static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name) {
1144     PyObject *result;
1145     result = __Pyx_PyObject_GetAttrStr(nmspace, name);
1146     if (!result) {
1147         result = __Pyx_GetGlobalNameAfterAttributeLookup(name);
1148     }
1149     return result;
1150 }
1151 
1152 
1153 /////////////// SetNameInClass.proto ///////////////
1154 
1155 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
1156 // Identifier names are always interned and have a pre-calculated hash value.
1157 #define __Pyx_SetNameInClass(ns, name, value) \
1158     (likely(PyDict_CheckExact(ns)) ? _PyDict_SetItem_KnownHash(ns, name, value, ((PyASCIIObject *) name)->hash) : PyObject_SetItem(ns, name, value))
1159 #elif CYTHON_COMPILING_IN_CPYTHON
1160 #define __Pyx_SetNameInClass(ns, name, value) \
1161     (likely(PyDict_CheckExact(ns)) ? PyDict_SetItem(ns, name, value) : PyObject_SetItem(ns, name, value))
1162 #else
1163 #define __Pyx_SetNameInClass(ns, name, value)  PyObject_SetItem(ns, name, value)
1164 #endif
1165 
1166 
1167 /////////////// GetModuleGlobalName.proto ///////////////
1168 //@requires: PyDictVersioning
1169 //@substitute: naming
1170 
1171 #if CYTHON_USE_DICT_VERSIONS
1172 #define __Pyx_GetModuleGlobalName(var, name)  { \
1173     static PY_UINT64_T __pyx_dict_version = 0; \
1174     static PyObject *__pyx_dict_cached_value = NULL; \
1175     (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION($moddict_cname))) ? \
1176         (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) : \
1177         __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value); \
1178 }
1179 #define __Pyx_GetModuleGlobalNameUncached(var, name)  { \
1180     PY_UINT64_T __pyx_dict_version; \
1181     PyObject *__pyx_dict_cached_value; \
1182     (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value); \
1183 }
1184 static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); /*proto*/
1185 #else
1186 #define __Pyx_GetModuleGlobalName(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
1187 #define __Pyx_GetModuleGlobalNameUncached(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
1188 static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); /*proto*/
1189 #endif
1190 
1191 
1192 /////////////// GetModuleGlobalName ///////////////
1193 //@requires: GetBuiltinName
1194 //@substitute: naming
1195 
1196 #if CYTHON_USE_DICT_VERSIONS
1197 static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
1198 #else
1199 static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
1200 #endif
1201 {
1202     PyObject *result;
1203 #if !CYTHON_AVOID_BORROWED_REFS
1204 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
1205     // Identifier names are always interned and have a pre-calculated hash value.
1206     result = _PyDict_GetItem_KnownHash($moddict_cname, name, ((PyASCIIObject *) name)->hash);
1207     __PYX_UPDATE_DICT_CACHE($moddict_cname, result, *dict_cached_value, *dict_version)
1208     if (likely(result)) {
1209         return __Pyx_NewRef(result);
1210     } else if (unlikely(PyErr_Occurred())) {
1211         return NULL;
1212     }
1213 #else
1214     result = PyDict_GetItem($moddict_cname, name);
1215     __PYX_UPDATE_DICT_CACHE($moddict_cname, result, *dict_cached_value, *dict_version)
1216     if (likely(result)) {
1217         return __Pyx_NewRef(result);
1218     }
1219 #endif
1220 #else
1221     result = PyObject_GetItem($moddict_cname, name);
1222     __PYX_UPDATE_DICT_CACHE($moddict_cname, result, *dict_cached_value, *dict_version)
1223     if (likely(result)) {
1224         return __Pyx_NewRef(result);
1225     }
1226     PyErr_Clear();
1227 #endif
1228     return __Pyx_GetBuiltinName(name);
1229 }
1230 
1231 //////////////////// GetAttr.proto ////////////////////
1232 
1233 static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); /*proto*/
1234 
1235 //////////////////// GetAttr ////////////////////
1236 //@requires: PyObjectGetAttrStr
1237 
1238 static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
1239 #if CYTHON_USE_TYPE_SLOTS
1240 #if PY_MAJOR_VERSION >= 3
1241     if (likely(PyUnicode_Check(n)))
1242 #else
1243     if (likely(PyString_Check(n)))
1244 #endif
1245         return __Pyx_PyObject_GetAttrStr(o, n);
1246 #endif
1247     return PyObject_GetAttr(o, n);
1248 }
1249 
1250 /////////////// PyObjectLookupSpecial.proto ///////////////
1251 //@requires: PyObjectGetAttrStr
1252 
1253 #if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
1254 static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name) {
1255     PyObject *res;
1256     PyTypeObject *tp = Py_TYPE(obj);
1257 #if PY_MAJOR_VERSION < 3
1258     if (unlikely(PyInstance_Check(obj)))
1259         return __Pyx_PyObject_GetAttrStr(obj, attr_name);
1260 #endif
1261     // adapted from CPython's special_lookup() in ceval.c
1262     res = _PyType_Lookup(tp, attr_name);
1263     if (likely(res)) {
1264         descrgetfunc f = Py_TYPE(res)->tp_descr_get;
1265         if (!f) {
1266             Py_INCREF(res);
1267         } else {
1268             res = f(res, obj, (PyObject *)tp);
1269         }
1270     } else {
1271         PyErr_SetObject(PyExc_AttributeError, attr_name);
1272     }
1273     return res;
1274 }
1275 #else
1276 #define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n)
1277 #endif
1278 
1279 
1280 /////////////// PyObject_GenericGetAttrNoDict.proto ///////////////
1281 
1282 // Setting "tp_getattro" to anything but "PyObject_GenericGetAttr" disables fast method calls in Py3.7.
1283 #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
1284 static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name);
1285 #else
1286 // No-args macro to allow function pointer assignment.
1287 #define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr
1288 #endif
1289 
1290 /////////////// PyObject_GenericGetAttrNoDict ///////////////
1291 
1292 #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
1293 
1294 static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) {
1295     PyErr_Format(PyExc_AttributeError,
1296 #if PY_MAJOR_VERSION >= 3
1297                  "'%.50s' object has no attribute '%U'",
1298                  tp->tp_name, attr_name);
1299 #else
1300                  "'%.50s' object has no attribute '%.400s'",
1301                  tp->tp_name, PyString_AS_STRING(attr_name));
1302 #endif
1303     return NULL;
1304 }
1305 
1306 static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
1307     // Copied and adapted from _PyObject_GenericGetAttrWithDict() in CPython 2.6/3.7.
1308     // To be used in the "tp_getattro" slot of extension types that have no instance dict and cannot be subclassed.
1309     PyObject *descr;
1310     PyTypeObject *tp = Py_TYPE(obj);
1311 
1312     if (unlikely(!PyString_Check(attr_name))) {
1313         return PyObject_GenericGetAttr(obj, attr_name);
1314     }
1315 
1316     assert(!tp->tp_dictoffset);
1317     descr = _PyType_Lookup(tp, attr_name);
1318     if (unlikely(!descr)) {
1319         return __Pyx_RaiseGenericGetAttributeError(tp, attr_name);
1320     }
1321 
1322     Py_INCREF(descr);
1323 
1324     #if PY_MAJOR_VERSION < 3
1325     if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
1326     #endif
1327     {
1328         descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
1329         // Optimise for the non-descriptor case because it is faster.
1330         if (unlikely(f)) {
1331             PyObject *res = f(descr, obj, (PyObject *)tp);
1332             Py_DECREF(descr);
1333             return res;
1334         }
1335     }
1336     return descr;
1337 }
1338 #endif
1339 
1340 
1341 /////////////// PyObject_GenericGetAttr.proto ///////////////
1342 
1343 // Setting "tp_getattro" to anything but "PyObject_GenericGetAttr" disables fast method calls in Py3.7.
1344 #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
1345 static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name);
1346 #else
1347 // No-args macro to allow function pointer assignment.
1348 #define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr
1349 #endif
1350 
1351 /////////////// PyObject_GenericGetAttr ///////////////
1352 //@requires: PyObject_GenericGetAttrNoDict
1353 
1354 #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
1355 static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) {
1356     if (unlikely(Py_TYPE(obj)->tp_dictoffset)) {
1357         return PyObject_GenericGetAttr(obj, attr_name);
1358     }
1359     return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name);
1360 }
1361 #endif
1362 
1363 
1364 /////////////// PyObjectGetAttrStrNoError.proto ///////////////
1365 
1366 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name);/*proto*/
1367 
1368 /////////////// PyObjectGetAttrStrNoError ///////////////
1369 //@requires: PyObjectGetAttrStr
1370 //@requires: Exceptions.c::PyThreadStateGet
1371 //@requires: Exceptions.c::PyErrFetchRestore
1372 //@requires: Exceptions.c::PyErrExceptionMatches
1373 
1374 static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) {
1375     __Pyx_PyThreadState_declare
1376     __Pyx_PyThreadState_assign
1377     if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
1378         __Pyx_PyErr_Clear();
1379 }
1380 
1381 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) {
1382     PyObject *result;
1383 #if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1
1384     // _PyObject_GenericGetAttrWithDict() in CPython 3.7+ can avoid raising the AttributeError.
1385     // See https://bugs.python.org/issue32544
1386     PyTypeObject* tp = Py_TYPE(obj);
1387     if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) {
1388         return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1);
1389     }
1390 #endif
1391     result = __Pyx_PyObject_GetAttrStr(obj, attr_name);
1392     if (unlikely(!result)) {
1393         __Pyx_PyObject_GetAttrStr_ClearAttributeError();
1394     }
1395     return result;
1396 }
1397 
1398 
1399 /////////////// PyObjectGetAttrStr.proto ///////////////
1400 
1401 #if CYTHON_USE_TYPE_SLOTS
1402 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);/*proto*/
1403 #else
1404 #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
1405 #endif
1406 
1407 /////////////// PyObjectGetAttrStr ///////////////
1408 
1409 #if CYTHON_USE_TYPE_SLOTS
1410 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
1411     PyTypeObject* tp = Py_TYPE(obj);
1412     if (likely(tp->tp_getattro))
1413         return tp->tp_getattro(obj, attr_name);
1414 #if PY_MAJOR_VERSION < 3
1415     if (likely(tp->tp_getattr))
1416         return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
1417 #endif
1418     return PyObject_GetAttr(obj, attr_name);
1419 }
1420 #endif
1421 
1422 
1423 /////////////// PyObjectSetAttrStr.proto ///////////////
1424 
1425 #if CYTHON_USE_TYPE_SLOTS
1426 #define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL)
1427 static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value);/*proto*/
1428 #else
1429 #define __Pyx_PyObject_DelAttrStr(o,n)   PyObject_DelAttr(o,n)
1430 #define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
1431 #endif
1432 
1433 /////////////// PyObjectSetAttrStr ///////////////
1434 
1435 #if CYTHON_USE_TYPE_SLOTS
1436 static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
1437     PyTypeObject* tp = Py_TYPE(obj);
1438     if (likely(tp->tp_setattro))
1439         return tp->tp_setattro(obj, attr_name, value);
1440 #if PY_MAJOR_VERSION < 3
1441     if (likely(tp->tp_setattr))
1442         return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
1443 #endif
1444     return PyObject_SetAttr(obj, attr_name, value);
1445 }
1446 #endif
1447 
1448 
1449 /////////////// PyObjectGetMethod.proto ///////////////
1450 
1451 static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);/*proto*/
1452 
1453 /////////////// PyObjectGetMethod ///////////////
1454 //@requires: PyObjectGetAttrStr
1455 
1456 static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) {
1457     PyObject *attr;
1458 #if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP
1459     // Copied from _PyObject_GetMethod() in CPython 3.7
1460     PyTypeObject *tp = Py_TYPE(obj);
1461     PyObject *descr;
1462     descrgetfunc f = NULL;
1463     PyObject **dictptr, *dict;
1464     int meth_found = 0;
1465 
1466     assert (*method == NULL);
1467 
1468     if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) {
1469         attr = __Pyx_PyObject_GetAttrStr(obj, name);
1470         goto try_unpack;
1471     }
1472     if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) {
1473         return 0;
1474     }
1475 
1476     descr = _PyType_Lookup(tp, name);
1477     if (likely(descr != NULL)) {
1478         Py_INCREF(descr);
1479         // Repeating the condition below accommodates for MSVC's inability to test macros inside of macro expansions.
1480 #if PY_MAJOR_VERSION >= 3
1481         #ifdef __Pyx_CyFunction_USED
1482         if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr)))
1483         #else
1484         if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type)))
1485         #endif
1486 #else
1487         // "PyMethodDescr_Type" is not part of the C-API in Py2.
1488         #ifdef __Pyx_CyFunction_USED
1489         if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr)))
1490         #else
1491         if (likely(PyFunction_Check(descr)))
1492         #endif
1493 #endif
1494         {
1495             meth_found = 1;
1496         } else {
1497             f = Py_TYPE(descr)->tp_descr_get;
1498             if (f != NULL && PyDescr_IsData(descr)) {
1499                 attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
1500                 Py_DECREF(descr);
1501                 goto try_unpack;
1502             }
1503         }
1504     }
1505 
1506     dictptr = _PyObject_GetDictPtr(obj);
1507     if (dictptr != NULL && (dict = *dictptr) != NULL) {
1508         Py_INCREF(dict);
1509         attr = __Pyx_PyDict_GetItemStr(dict, name);
1510         if (attr != NULL) {
1511             Py_INCREF(attr);
1512             Py_DECREF(dict);
1513             Py_XDECREF(descr);
1514             goto try_unpack;
1515         }
1516         Py_DECREF(dict);
1517     }
1518 
1519     if (meth_found) {
1520         *method = descr;
1521         return 1;
1522     }
1523 
1524     if (f != NULL) {
1525         attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
1526         Py_DECREF(descr);
1527         goto try_unpack;
1528     }
1529 
1530     if (descr != NULL) {
1531         *method = descr;
1532         return 0;
1533     }
1534 
1535     PyErr_Format(PyExc_AttributeError,
1536 #if PY_MAJOR_VERSION >= 3
1537                  "'%.50s' object has no attribute '%U'",
1538                  tp->tp_name, name);
1539 #else
1540                  "'%.50s' object has no attribute '%.400s'",
1541                  tp->tp_name, PyString_AS_STRING(name));
1542 #endif
1543     return 0;
1544 
1545 // Generic fallback implementation using normal attribute lookup.
1546 #else
1547     attr = __Pyx_PyObject_GetAttrStr(obj, name);
1548     goto try_unpack;
1549 #endif
1550 
1551 try_unpack:
1552 #if CYTHON_UNPACK_METHODS
1553     // Even if we failed to avoid creating a bound method object, it's still worth unpacking it now, if possible.
1554     if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) {
1555         PyObject *function = PyMethod_GET_FUNCTION(attr);
1556         Py_INCREF(function);
1557         Py_DECREF(attr);
1558         *method = function;
1559         return 1;
1560     }
1561 #endif
1562     *method = attr;
1563     return 0;
1564 }
1565 
1566 
1567 /////////////// UnpackUnboundCMethod.proto ///////////////
1568 
1569 typedef struct {
1570     PyObject *type;
1571     PyObject **method_name;
1572     // "func" is set on first access (direct C function pointer)
1573     PyCFunction func;
1574     // "method" is set on first access (fallback)
1575     PyObject *method;
1576     int flag;
1577 } __Pyx_CachedCFunction;
1578 
1579 /////////////// UnpackUnboundCMethod ///////////////
1580 //@requires: PyObjectGetAttrStr
1581 
1582 static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
1583     PyObject *method;
1584     method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
1585     if (unlikely(!method))
1586         return -1;
1587     target->method = method;
1588 #if CYTHON_COMPILING_IN_CPYTHON
1589     #if PY_MAJOR_VERSION >= 3
1590     // method dscriptor type isn't exported in Py2.x, cannot easily check the type there
1591     if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type)))
1592     #endif
1593     {
1594         PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
1595         target->func = descr->d_method->ml_meth;
1596         target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
1597     }
1598 #endif
1599     return 0;
1600 }
1601 
1602 
1603 /////////////// CallUnboundCMethod0.proto ///////////////
1604 //@substitute: naming
1605 
1606 static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self); /*proto*/
1607 #if CYTHON_COMPILING_IN_CPYTHON
1608 // FASTCALL methods receive "&empty_tuple" as simple "PyObject[0]*"
1609 #define __Pyx_CallUnboundCMethod0(cfunc, self)  \
1610     (likely((cfunc)->func) ? \
1611         (likely((cfunc)->flag == METH_NOARGS) ?  (*((cfunc)->func))(self, NULL) : \
1612          (PY_VERSION_HEX >= 0x030600B1 && likely((cfunc)->flag == METH_FASTCALL) ? \
1613             (PY_VERSION_HEX >= 0x030700A0 ? \
1614                 (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)(cfunc)->func)(self, &$empty_tuple, 0) : \
1615                 (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &$empty_tuple, 0, NULL)) : \
1616           (PY_VERSION_HEX >= 0x030700A0 && (cfunc)->flag == (METH_FASTCALL | METH_KEYWORDS) ? \
1617             (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &$empty_tuple, 0, NULL) : \
1618             (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ?  ((*(PyCFunctionWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, $empty_tuple, NULL)) : \
1619                ((cfunc)->flag == METH_VARARGS ?  (*((cfunc)->func))(self, $empty_tuple) : \
1620                __Pyx__CallUnboundCMethod0(cfunc, self)))))) : \
1621         __Pyx__CallUnboundCMethod0(cfunc, self))
1622 #else
1623 #define __Pyx_CallUnboundCMethod0(cfunc, self)  __Pyx__CallUnboundCMethod0(cfunc, self)
1624 #endif
1625 
1626 /////////////// CallUnboundCMethod0 ///////////////
1627 //@requires: UnpackUnboundCMethod
1628 //@requires: PyObjectCall
1629 
1630 static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
1631     PyObject *args, *result = NULL;
1632     if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
1633 #if CYTHON_ASSUME_SAFE_MACROS
1634     args = PyTuple_New(1);
1635     if (unlikely(!args)) goto bad;
1636     Py_INCREF(self);
1637     PyTuple_SET_ITEM(args, 0, self);
1638 #else
1639     args = PyTuple_Pack(1, self);
1640     if (unlikely(!args)) goto bad;
1641 #endif
1642     result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
1643     Py_DECREF(args);
1644 bad:
1645     return result;
1646 }
1647 
1648 
1649 /////////////// CallUnboundCMethod1.proto ///////////////
1650 
1651 static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);/*proto*/
1652 
1653 #if CYTHON_COMPILING_IN_CPYTHON
1654 static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);/*proto*/
1655 #else
1656 #define __Pyx_CallUnboundCMethod1(cfunc, self, arg)  __Pyx__CallUnboundCMethod1(cfunc, self, arg)
1657 #endif
1658 
1659 /////////////// CallUnboundCMethod1 ///////////////
1660 //@requires: UnpackUnboundCMethod
1661 //@requires: PyObjectCall
1662 
1663 #if CYTHON_COMPILING_IN_CPYTHON
1664 static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) {
1665     if (likely(cfunc->func)) {
1666         int flag = cfunc->flag;
1667         // Not using #ifdefs for PY_VERSION_HEX to avoid C compiler warnings about unused functions.
1668         if (flag == METH_O) {
1669             return (*(cfunc->func))(self, arg);
1670         } else if (PY_VERSION_HEX >= 0x030600B1 && flag == METH_FASTCALL) {
1671             if (PY_VERSION_HEX >= 0x030700A0) {
1672                 return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, &arg, 1);
1673             } else {
1674                 return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
1675             }
1676         } else if (PY_VERSION_HEX >= 0x030700A0 && flag == (METH_FASTCALL | METH_KEYWORDS)) {
1677             return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
1678         }
1679     }
1680     return __Pyx__CallUnboundCMethod1(cfunc, self, arg);
1681 }
1682 #endif
1683 
1684 static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){
1685     PyObject *args, *result = NULL;
1686     if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
1687 #if CYTHON_COMPILING_IN_CPYTHON
1688     if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
1689         args = PyTuple_New(1);
1690         if (unlikely(!args)) goto bad;
1691         Py_INCREF(arg);
1692         PyTuple_SET_ITEM(args, 0, arg);
1693         if (cfunc->flag & METH_KEYWORDS)
1694             result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
1695         else
1696             result = (*cfunc->func)(self, args);
1697     } else {
1698         args = PyTuple_New(2);
1699         if (unlikely(!args)) goto bad;
1700         Py_INCREF(self);
1701         PyTuple_SET_ITEM(args, 0, self);
1702         Py_INCREF(arg);
1703         PyTuple_SET_ITEM(args, 1, arg);
1704         result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
1705     }
1706 #else
1707     args = PyTuple_Pack(2, self, arg);
1708     if (unlikely(!args)) goto bad;
1709     result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
1710 #endif
1711 bad:
1712     Py_XDECREF(args);
1713     return result;
1714 }
1715 
1716 
1717 /////////////// CallUnboundCMethod2.proto ///////////////
1718 
1719 static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2); /*proto*/
1720 
1721 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
1722 static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2); /*proto*/
1723 #else
1724 #define __Pyx_CallUnboundCMethod2(cfunc, self, arg1, arg2)  __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2)
1725 #endif
1726 
1727 /////////////// CallUnboundCMethod2 ///////////////
1728 //@requires: UnpackUnboundCMethod
1729 //@requires: PyObjectCall
1730 
1731 #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
1732 static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2) {
1733     if (likely(cfunc->func)) {
1734         PyObject *args[2] = {arg1, arg2};
1735         if (cfunc->flag == METH_FASTCALL) {
1736             #if PY_VERSION_HEX >= 0x030700A0
1737             return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, args, 2);
1738             #else
1739             return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
1740             #endif
1741         }
1742         #if PY_VERSION_HEX >= 0x030700A0
1743         if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS))
1744             return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
1745         #endif
1746     }
1747     return __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2);
1748 }
1749 #endif
1750 
1751 static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2){
1752     PyObject *args, *result = NULL;
1753     if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
1754 #if CYTHON_COMPILING_IN_CPYTHON
1755     if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
1756         args = PyTuple_New(2);
1757         if (unlikely(!args)) goto bad;
1758         Py_INCREF(arg1);
1759         PyTuple_SET_ITEM(args, 0, arg1);
1760         Py_INCREF(arg2);
1761         PyTuple_SET_ITEM(args, 1, arg2);
1762         if (cfunc->flag & METH_KEYWORDS)
1763             result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
1764         else
1765             result = (*cfunc->func)(self, args);
1766     } else {
1767         args = PyTuple_New(3);
1768         if (unlikely(!args)) goto bad;
1769         Py_INCREF(self);
1770         PyTuple_SET_ITEM(args, 0, self);
1771         Py_INCREF(arg1);
1772         PyTuple_SET_ITEM(args, 1, arg1);
1773         Py_INCREF(arg2);
1774         PyTuple_SET_ITEM(args, 2, arg2);
1775         result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
1776     }
1777 #else
1778     args = PyTuple_Pack(3, self, arg1, arg2);
1779     if (unlikely(!args)) goto bad;
1780     result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
1781 #endif
1782 bad:
1783     Py_XDECREF(args);
1784     return result;
1785 }
1786 
1787 
1788 /////////////// PyObjectCallMethod0.proto ///////////////
1789 
1790 static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); /*proto*/
1791 
1792 /////////////// PyObjectCallMethod0 ///////////////
1793 //@requires: PyObjectGetMethod
1794 //@requires: PyObjectCallOneArg
1795 //@requires: PyObjectCallNoArg
1796 
1797 static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
1798     PyObject *method = NULL, *result = NULL;
1799     int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
1800     if (likely(is_method)) {
1801         result = __Pyx_PyObject_CallOneArg(method, obj);
1802         Py_DECREF(method);
1803         return result;
1804     }
1805     if (unlikely(!method)) goto bad;
1806     result = __Pyx_PyObject_CallNoArg(method);
1807     Py_DECREF(method);
1808 bad:
1809     return result;
1810 }
1811 
1812 
1813 /////////////// PyObjectCallMethod1.proto ///////////////
1814 
1815 static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); /*proto*/
1816 
1817 /////////////// PyObjectCallMethod1 ///////////////
1818 //@requires: PyObjectGetMethod
1819 //@requires: PyObjectCallOneArg
1820 //@requires: PyObjectCall2Args
1821 
1822 static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) {
1823     // Separate function to avoid excessive inlining.
1824     PyObject *result = __Pyx_PyObject_CallOneArg(method, arg);
1825     Py_DECREF(method);
1826     return result;
1827 }
1828 
1829 static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
1830     PyObject *method = NULL, *result;
1831     int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
1832     if (likely(is_method)) {
1833         result = __Pyx_PyObject_Call2Args(method, obj, arg);
1834         Py_DECREF(method);
1835         return result;
1836     }
1837     if (unlikely(!method)) return NULL;
1838     return __Pyx__PyObject_CallMethod1(method, arg);
1839 }
1840 
1841 
1842 /////////////// PyObjectCallMethod2.proto ///////////////
1843 
1844 static PyObject* __Pyx_PyObject_CallMethod2(PyObject* obj, PyObject* method_name, PyObject* arg1, PyObject* arg2); /*proto*/
1845 
1846 /////////////// PyObjectCallMethod2 ///////////////
1847 //@requires: PyObjectCall
1848 //@requires: PyFunctionFastCall
1849 //@requires: PyCFunctionFastCall
1850 //@requires: PyObjectCall2Args
1851 
1852 static PyObject* __Pyx_PyObject_Call3Args(PyObject* function, PyObject* arg1, PyObject* arg2, PyObject* arg3) {
1853     #if CYTHON_FAST_PYCALL
1854     if (PyFunction_Check(function)) {
1855         PyObject *args[3] = {arg1, arg2, arg3};
1856         return __Pyx_PyFunction_FastCall(function, args, 3);
1857     }
1858     #endif
1859     #if CYTHON_FAST_PYCCALL
1860     if (__Pyx_PyFastCFunction_Check(function)) {
1861         PyObject *args[3] = {arg1, arg2, arg3};
1862         return __Pyx_PyFunction_FastCall(function, args, 3);
1863     }
1864     #endif
1865 
1866     args = PyTuple_New(3);
1867     if (unlikely(!args)) goto done;
1868     Py_INCREF(arg1);
1869     PyTuple_SET_ITEM(args, 0, arg1);
1870     Py_INCREF(arg2);
1871     PyTuple_SET_ITEM(args, 1, arg2);
1872     Py_INCREF(arg3);
1873     PyTuple_SET_ITEM(args, 2, arg3);
1874 
1875     result = __Pyx_PyObject_Call(function, args, NULL);
1876     Py_DECREF(args);
1877     return result;
1878 }
1879 
1880 static PyObject* __Pyx_PyObject_CallMethod2(PyObject* obj, PyObject* method_name, PyObject* arg1, PyObject* arg2) {
1881     PyObject *args, *method = NULL, *result = NULL;
1882     int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
1883     if (likely(is_method)) {
1884         result = __Pyx_PyObject_Call3Args(method, obj, arg1, arg2);
1885         Py_DECREF(method);
1886         return result;
1887     }
1888     if (unlikely(!method)) return NULL;
1889     result = __Pyx_PyObject_Call2Args(method, arg1, arg2);
1890     Py_DECREF(method);
1891     return result;
1892 }
1893 
1894 
1895 /////////////// tp_new.proto ///////////////
1896 
1897 #define __Pyx_tp_new(type_obj, args) __Pyx_tp_new_kwargs(type_obj, args, NULL)
1898 static CYTHON_INLINE PyObject* __Pyx_tp_new_kwargs(PyObject* type_obj, PyObject* args, PyObject* kwargs) {
1899     return (PyObject*) (((PyTypeObject*)type_obj)->tp_new((PyTypeObject*)type_obj, args, kwargs));
1900 }
1901 
1902 
1903 /////////////// PyObjectCall.proto ///////////////
1904 
1905 #if CYTHON_COMPILING_IN_CPYTHON
1906 static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); /*proto*/
1907 #else
1908 #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
1909 #endif
1910 
1911 /////////////// PyObjectCall ///////////////
1912 
1913 #if CYTHON_COMPILING_IN_CPYTHON
1914 static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
1915     PyObject *result;
1916     ternaryfunc call = Py_TYPE(func)->tp_call;
1917 
1918     if (unlikely(!call))
1919         return PyObject_Call(func, arg, kw);
1920     if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
1921         return NULL;
1922     result = (*call)(func, arg, kw);
1923     Py_LeaveRecursiveCall();
1924     if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
1925         PyErr_SetString(
1926             PyExc_SystemError,
1927             "NULL result without error in PyObject_Call");
1928     }
1929     return result;
1930 }
1931 #endif
1932 
1933 
1934 /////////////// PyObjectCallMethO.proto ///////////////
1935 
1936 #if CYTHON_COMPILING_IN_CPYTHON
1937 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); /*proto*/
1938 #endif
1939 
1940 /////////////// PyObjectCallMethO ///////////////
1941 
1942 #if CYTHON_COMPILING_IN_CPYTHON
1943 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
1944     PyObject *self, *result;
1945     PyCFunction cfunc;
1946     cfunc = PyCFunction_GET_FUNCTION(func);
1947     self = PyCFunction_GET_SELF(func);
1948 
1949     if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
1950         return NULL;
1951     result = cfunc(self, arg);
1952     Py_LeaveRecursiveCall();
1953     if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
1954         PyErr_SetString(
1955             PyExc_SystemError,
1956             "NULL result without error in PyObject_Call");
1957     }
1958     return result;
1959 }
1960 #endif
1961 
1962 
1963 /////////////// PyFunctionFastCall.proto ///////////////
1964 
1965 #if CYTHON_FAST_PYCALL
1966 #define __Pyx_PyFunction_FastCall(func, args, nargs) \
1967     __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
1968 
1969 // let's assume that the non-public C-API function might still change during the 3.6 beta phase
1970 #if 1 || PY_VERSION_HEX < 0x030600B1
1971 static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs);
1972 #else
1973 #define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
1974 #endif
1975 
1976 // Backport from Python 3
1977 // Assert a build-time dependency, as an expression.
1978 //   Your compile will fail if the condition isn't true, or can't be evaluated
1979 //   by the compiler. This can be used in an expression: its value is 0.
1980 // Example:
1981 //   #define foo_to_char(foo)  \
1982 //       ((char *)(foo)        \
1983 //        + Py_BUILD_ASSERT_EXPR(offsetof(struct foo, string) == 0))
1984 //
1985 //   Written by Rusty Russell, public domain, http://ccodearchive.net/
1986 #define __Pyx_BUILD_ASSERT_EXPR(cond) \
1987     (sizeof(char [1 - 2*!(cond)]) - 1)
1988 
1989 #ifndef Py_MEMBER_SIZE
1990 // Get the size of a structure member in bytes
1991 #define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
1992 #endif
1993 
1994   // Initialised by module init code.
1995   static size_t __pyx_pyframe_localsplus_offset = 0;
1996 
1997   #include "frameobject.h"
1998   // This is the long runtime version of
1999   //     #define __Pyx_PyFrame_GetLocalsplus(frame)  ((frame)->f_localsplus)
2000   // offsetof(PyFrameObject, f_localsplus) differs between regular C-Python and Stackless Python.
2001   // Therefore the offset is computed at run time from PyFrame_type.tp_basicsize. That is feasible,
2002   // because f_localsplus is the last field of PyFrameObject (checked by Py_BUILD_ASSERT_EXPR below).
2003   #define __Pxy_PyFrame_Initialize_Offsets()  \
2004     ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)), \
2005      (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
2006   #define __Pyx_PyFrame_GetLocalsplus(frame)  \
2007     (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
2008 #endif
2009 
2010 
2011 /////////////// PyFunctionFastCall ///////////////
2012 // copied from CPython 3.6 ceval.c
2013 
2014 #if CYTHON_FAST_PYCALL
2015 
2016 static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
2017                                                PyObject *globals) {
2018     PyFrameObject *f;
2019     PyThreadState *tstate = __Pyx_PyThreadState_Current;
2020     PyObject **fastlocals;
2021     Py_ssize_t i;
2022     PyObject *result;
2023 
2024     assert(globals != NULL);
2025     /* XXX Perhaps we should create a specialized
2026        PyFrame_New() that doesn't take locals, but does
2027        take builtins without sanity checking them.
2028        */
2029     assert(tstate != NULL);
2030     f = PyFrame_New(tstate, co, globals, NULL);
2031     if (f == NULL) {
2032         return NULL;
2033     }
2034 
2035     fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
2036 
2037     for (i = 0; i < na; i++) {
2038         Py_INCREF(*args);
2039         fastlocals[i] = *args++;
2040     }
2041     result = PyEval_EvalFrameEx(f,0);
2042 
2043     ++tstate->recursion_depth;
2044     Py_DECREF(f);
2045     --tstate->recursion_depth;
2046 
2047     return result;
2048 }
2049 
2050 
2051 #if 1 || PY_VERSION_HEX < 0x030600B1
2052 static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) {
2053     PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
2054     PyObject *globals = PyFunction_GET_GLOBALS(func);
2055     PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
2056     PyObject *closure;
2057 #if PY_MAJOR_VERSION >= 3
2058     PyObject *kwdefs;
2059     //#if PY_VERSION_HEX >= 0x03050000
2060     //PyObject *name, *qualname;
2061     //#endif
2062 #endif
2063     PyObject *kwtuple, **k;
2064     PyObject **d;
2065     Py_ssize_t nd;
2066     Py_ssize_t nk;
2067     PyObject *result;
2068 
2069     assert(kwargs == NULL || PyDict_Check(kwargs));
2070     nk = kwargs ? PyDict_Size(kwargs) : 0;
2071 
2072     if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
2073         return NULL;
2074     }
2075 
2076     if (
2077 #if PY_MAJOR_VERSION >= 3
2078             co->co_kwonlyargcount == 0 &&
2079 #endif
2080             likely(kwargs == NULL || nk == 0) &&
2081             co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
2082         /* Fast paths */
2083         if (argdefs == NULL && co->co_argcount == nargs) {
2084             result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
2085             goto done;
2086         }
2087         else if (nargs == 0 && argdefs != NULL
2088                  && co->co_argcount == Py_SIZE(argdefs)) {
2089             /* function called with no arguments, but all parameters have
2090                a default value: use default values as arguments .*/
2091             args = &PyTuple_GET_ITEM(argdefs, 0);
2092             result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
2093             goto done;
2094         }
2095     }
2096 
2097     if (kwargs != NULL) {
2098         Py_ssize_t pos, i;
2099         kwtuple = PyTuple_New(2 * nk);
2100         if (kwtuple == NULL) {
2101             result = NULL;
2102             goto done;
2103         }
2104 
2105         k = &PyTuple_GET_ITEM(kwtuple, 0);
2106         pos = i = 0;
2107         while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
2108             Py_INCREF(k[i]);
2109             Py_INCREF(k[i+1]);
2110             i += 2;
2111         }
2112         nk = i / 2;
2113     }
2114     else {
2115         kwtuple = NULL;
2116         k = NULL;
2117     }
2118 
2119     closure = PyFunction_GET_CLOSURE(func);
2120 #if PY_MAJOR_VERSION >= 3
2121     kwdefs = PyFunction_GET_KW_DEFAULTS(func);
2122     //#if PY_VERSION_HEX >= 0x03050000
2123     //name = ((PyFunctionObject *)func) -> func_name;
2124     //qualname = ((PyFunctionObject *)func) -> func_qualname;
2125     //#endif
2126 #endif
2127 
2128     if (argdefs != NULL) {
2129         d = &PyTuple_GET_ITEM(argdefs, 0);
2130         nd = Py_SIZE(argdefs);
2131     }
2132     else {
2133         d = NULL;
2134         nd = 0;
2135     }
2136 
2137     //#if PY_VERSION_HEX >= 0x03050000
2138     //return _PyEval_EvalCodeWithName((PyObject*)co, globals, (PyObject *)NULL,
2139     //                                args, nargs,
2140     //                                NULL, 0,
2141     //                                d, nd, kwdefs,
2142     //                                closure, name, qualname);
2143     //#elif PY_MAJOR_VERSION >= 3
2144 #if PY_MAJOR_VERSION >= 3
2145     result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
2146                                args, (int)nargs,
2147                                k, (int)nk,
2148                                d, (int)nd, kwdefs, closure);
2149 #else
2150     result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
2151                                args, (int)nargs,
2152                                k, (int)nk,
2153                                d, (int)nd, closure);
2154 #endif
2155     Py_XDECREF(kwtuple);
2156 
2157 done:
2158     Py_LeaveRecursiveCall();
2159     return result;
2160 }
2161 #endif  /* CPython < 3.6 */
2162 #endif  /* CYTHON_FAST_PYCALL */
2163 
2164 
2165 /////////////// PyCFunctionFastCall.proto ///////////////
2166 
2167 #if CYTHON_FAST_PYCCALL
2168 static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
2169 #else
2170 #define __Pyx_PyCFunction_FastCall(func, args, nargs)  (assert(0), NULL)
2171 #endif
2172 
2173 /////////////// PyCFunctionFastCall ///////////////
2174 
2175 #if CYTHON_FAST_PYCCALL
2176 static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
2177     PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
2178     PyCFunction meth = PyCFunction_GET_FUNCTION(func);
2179     PyObject *self = PyCFunction_GET_SELF(func);
2180     int flags = PyCFunction_GET_FLAGS(func);
2181 
2182     assert(PyCFunction_Check(func));
2183     assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)));
2184     assert(nargs >= 0);
2185     assert(nargs == 0 || args != NULL);
2186 
2187     /* _PyCFunction_FastCallDict() must not be called with an exception set,
2188        because it may clear it (directly or indirectly) and so the
2189        caller loses its exception */
2190     assert(!PyErr_Occurred());
2191 
2192     if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
2193         return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL);
2194     } else {
2195         return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs);
2196     }
2197 }
2198 #endif  /* CYTHON_FAST_PYCCALL */
2199 
2200 
2201 /////////////// PyObjectCall2Args.proto ///////////////
2202 
2203 static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); /*proto*/
2204 
2205 /////////////// PyObjectCall2Args ///////////////
2206 //@requires: PyObjectCall
2207 //@requires: PyFunctionFastCall
2208 //@requires: PyCFunctionFastCall
2209 
2210 static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
2211     PyObject *args, *result = NULL;
2212     #if CYTHON_FAST_PYCALL
2213     if (PyFunction_Check(function)) {
2214         PyObject *args[2] = {arg1, arg2};
2215         return __Pyx_PyFunction_FastCall(function, args, 2);
2216     }
2217     #endif
2218     #if CYTHON_FAST_PYCCALL
2219     if (__Pyx_PyFastCFunction_Check(function)) {
2220         PyObject *args[2] = {arg1, arg2};
2221         return __Pyx_PyCFunction_FastCall(function, args, 2);
2222     }
2223     #endif
2224 
2225     args = PyTuple_New(2);
2226     if (unlikely(!args)) goto done;
2227     Py_INCREF(arg1);
2228     PyTuple_SET_ITEM(args, 0, arg1);
2229     Py_INCREF(arg2);
2230     PyTuple_SET_ITEM(args, 1, arg2);
2231 
2232     Py_INCREF(function);
2233     result = __Pyx_PyObject_Call(function, args, NULL);
2234     Py_DECREF(args);
2235     Py_DECREF(function);
2236 done:
2237     return result;
2238 }
2239 
2240 
2241 /////////////// PyObjectCallOneArg.proto ///////////////
2242 
2243 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); /*proto*/
2244 
2245 /////////////// PyObjectCallOneArg ///////////////
2246 //@requires: PyObjectCallMethO
2247 //@requires: PyObjectCall
2248 //@requires: PyFunctionFastCall
2249 //@requires: PyCFunctionFastCall
2250 
2251 #if CYTHON_COMPILING_IN_CPYTHON
2252 static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
2253     PyObject *result;
2254     PyObject *args = PyTuple_New(1);
2255     if (unlikely(!args)) return NULL;
2256     Py_INCREF(arg);
2257     PyTuple_SET_ITEM(args, 0, arg);
2258     result = __Pyx_PyObject_Call(func, args, NULL);
2259     Py_DECREF(args);
2260     return result;
2261 }
2262 
2263 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
2264 #if CYTHON_FAST_PYCALL
2265     if (PyFunction_Check(func)) {
2266         return __Pyx_PyFunction_FastCall(func, &arg, 1);
2267     }
2268 #endif
2269     if (likely(PyCFunction_Check(func))) {
2270         if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
2271             // fast and simple case that we are optimising for
2272             return __Pyx_PyObject_CallMethO(func, arg);
2273 #if CYTHON_FAST_PYCCALL
2274         } else if (__Pyx_PyFastCFunction_Check(func)) {
2275             return __Pyx_PyCFunction_FastCall(func, &arg, 1);
2276 #endif
2277         }
2278     }
2279     return __Pyx__PyObject_CallOneArg(func, arg);
2280 }
2281 #else
2282 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
2283     PyObject *result;
2284     PyObject *args = PyTuple_Pack(1, arg);
2285     if (unlikely(!args)) return NULL;
2286     result = __Pyx_PyObject_Call(func, args, NULL);
2287     Py_DECREF(args);
2288     return result;
2289 }
2290 #endif
2291 
2292 
2293 /////////////// PyObjectCallNoArg.proto ///////////////
2294 //@requires: PyObjectCall
2295 //@substitute: naming
2296 
2297 #if CYTHON_COMPILING_IN_CPYTHON
2298 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); /*proto*/
2299 #else
2300 #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, $empty_tuple, NULL)
2301 #endif
2302 
2303 /////////////// PyObjectCallNoArg ///////////////
2304 //@requires: PyObjectCallMethO
2305 //@requires: PyObjectCall
2306 //@requires: PyFunctionFastCall
2307 //@substitute: naming
2308 
2309 #if CYTHON_COMPILING_IN_CPYTHON
2310 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
2311 #if CYTHON_FAST_PYCALL
2312     if (PyFunction_Check(func)) {
2313         return __Pyx_PyFunction_FastCall(func, NULL, 0);
2314     }
2315 #endif
2316 #ifdef __Pyx_CyFunction_USED
2317     if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func)))
2318 #else
2319     if (likely(PyCFunction_Check(func)))
2320 #endif
2321     {
2322         if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
2323             // fast and simple case that we are optimising for
2324             return __Pyx_PyObject_CallMethO(func, NULL);
2325         }
2326     }
2327     return __Pyx_PyObject_Call(func, $empty_tuple, NULL);
2328 }
2329 #endif
2330 
2331 
2332 /////////////// MatrixMultiply.proto ///////////////
2333 
2334 #if PY_VERSION_HEX >= 0x03050000
2335   #define __Pyx_PyNumber_MatrixMultiply(x,y)         PyNumber_MatrixMultiply(x,y)
2336   #define __Pyx_PyNumber_InPlaceMatrixMultiply(x,y)  PyNumber_InPlaceMatrixMultiply(x,y)
2337 #else
2338 #define __Pyx_PyNumber_MatrixMultiply(x,y)         __Pyx__PyNumber_MatrixMultiply(x, y, "@")
2339 static PyObject* __Pyx__PyNumber_MatrixMultiply(PyObject* x, PyObject* y, const char* op_name);
2340 static PyObject* __Pyx_PyNumber_InPlaceMatrixMultiply(PyObject* x, PyObject* y);
2341 #endif
2342 
2343 /////////////// MatrixMultiply ///////////////
2344 //@requires: PyObjectGetAttrStr
2345 //@requires: PyObjectCallOneArg
2346 //@requires: PyFunctionFastCall
2347 //@requires: PyCFunctionFastCall
2348 
2349 #if PY_VERSION_HEX < 0x03050000
2350 static PyObject* __Pyx_PyObject_CallMatrixMethod(PyObject* method, PyObject* arg) {
2351     // NOTE: eats the method reference
2352     PyObject *result = NULL;
2353 #if CYTHON_UNPACK_METHODS
2354     if (likely(PyMethod_Check(method))) {
2355         PyObject *self = PyMethod_GET_SELF(method);
2356         if (likely(self)) {
2357             PyObject *args;
2358             PyObject *function = PyMethod_GET_FUNCTION(method);
2359             #if CYTHON_FAST_PYCALL
2360             if (PyFunction_Check(function)) {
2361                 PyObject *args[2] = {self, arg};
2362                 result = __Pyx_PyFunction_FastCall(function, args, 2);
2363                 goto done;
2364             }
2365             #endif
2366             #if CYTHON_FAST_PYCCALL
2367             if (__Pyx_PyFastCFunction_Check(function)) {
2368                 PyObject *args[2] = {self, arg};
2369                 result = __Pyx_PyCFunction_FastCall(function, args, 2);
2370                 goto done;
2371             }
2372             #endif
2373             args = PyTuple_New(2);
2374             if (unlikely(!args)) goto done;
2375             Py_INCREF(self);
2376             PyTuple_SET_ITEM(args, 0, self);
2377             Py_INCREF(arg);
2378             PyTuple_SET_ITEM(args, 1, arg);
2379             Py_INCREF(function);
2380             Py_DECREF(method); method = NULL;
2381             result = __Pyx_PyObject_Call(function, args, NULL);
2382             Py_DECREF(args);
2383             Py_DECREF(function);
2384             return result;
2385         }
2386     }
2387 #endif
2388     result = __Pyx_PyObject_CallOneArg(method, arg);
2389 done:
2390     Py_DECREF(method);
2391     return result;
2392 }
2393 
2394 #define __Pyx_TryMatrixMethod(x, y, py_method_name) {                   \
2395     PyObject *func = __Pyx_PyObject_GetAttrStr(x, py_method_name);      \
2396     if (func) {                                                         \
2397         PyObject *result = __Pyx_PyObject_CallMatrixMethod(func, y);    \
2398         if (result != Py_NotImplemented)                                \
2399             return result;                                              \
2400         Py_DECREF(result);                                              \
2401     } else {                                                            \
2402         if (!PyErr_ExceptionMatches(PyExc_AttributeError))              \
2403             return NULL;                                                \
2404         PyErr_Clear();                                                  \
2405     }                                                                   \
2406 }
2407 
2408 static PyObject* __Pyx__PyNumber_MatrixMultiply(PyObject* x, PyObject* y, const char* op_name) {
2409     int right_is_subtype = PyObject_IsSubclass((PyObject*)Py_TYPE(y), (PyObject*)Py_TYPE(x));
2410     if (unlikely(right_is_subtype == -1))
2411         return NULL;
2412     if (right_is_subtype) {
2413         // to allow subtypes to override parent behaviour, try reversed operation first
2414         // see note at https://docs.python.org/3/reference/datamodel.html#emulating-numeric-types
2415         __Pyx_TryMatrixMethod(y, x, PYIDENT("__rmatmul__"))
2416     }
2417     __Pyx_TryMatrixMethod(x, y, PYIDENT("__matmul__"))
2418     if (!right_is_subtype) {
2419         __Pyx_TryMatrixMethod(y, x, PYIDENT("__rmatmul__"))
2420     }
2421     PyErr_Format(PyExc_TypeError,
2422                  "unsupported operand type(s) for %.2s: '%.100s' and '%.100s'",
2423                  op_name,
2424                  Py_TYPE(x)->tp_name,
2425                  Py_TYPE(y)->tp_name);
2426     return NULL;
2427 }
2428 
2429 static PyObject* __Pyx_PyNumber_InPlaceMatrixMultiply(PyObject* x, PyObject* y) {
2430     __Pyx_TryMatrixMethod(x, y, PYIDENT("__imatmul__"))
2431     return __Pyx__PyNumber_MatrixMultiply(x, y, "@=");
2432 }
2433 
2434 #undef __Pyx_TryMatrixMethod
2435 #endif
2436 
2437 
2438 /////////////// PyDictVersioning.proto ///////////////
2439 
2440 #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
2441 #define __PYX_DICT_VERSION_INIT  ((PY_UINT64_T) -1)
2442 #define __PYX_GET_DICT_VERSION(dict)  (((PyDictObject*)(dict))->ma_version_tag)
2443 #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) \
2444     (version_var) = __PYX_GET_DICT_VERSION(dict); \
2445     (cache_var) = (value);
2446 
2447 #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) { \
2448     static PY_UINT64_T __pyx_dict_version = 0; \
2449     static PyObject *__pyx_dict_cached_value = NULL; \
2450     if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) { \
2451         (VAR) = __pyx_dict_cached_value; \
2452     } else { \
2453         (VAR) = __pyx_dict_cached_value = (LOOKUP); \
2454         __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT); \
2455     } \
2456 }
2457 
2458 static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); /*proto*/
2459 static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); /*proto*/
2460 static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); /*proto*/
2461 
2462 #else
2463 #define __PYX_GET_DICT_VERSION(dict)  (0)
2464 #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
2465 #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP)  (VAR) = (LOOKUP);
2466 #endif
2467 
2468 /////////////// PyDictVersioning ///////////////
2469 
2470 #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
2471 static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
2472     PyObject *dict = Py_TYPE(obj)->tp_dict;
2473     return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
2474 }
2475 
2476 static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
2477     PyObject **dictptr = NULL;
2478     Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
2479     if (offset) {
2480 #if CYTHON_COMPILING_IN_CPYTHON
2481         dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
2482 #else
2483         dictptr = _PyObject_GetDictPtr(obj);
2484 #endif
2485     }
2486     return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
2487 }
2488 
2489 static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
2490     PyObject *dict = Py_TYPE(obj)->tp_dict;
2491     if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
2492         return 0;
2493     return obj_dict_version == __Pyx_get_object_dict_version(obj);
2494 }
2495 #endif
2496