Cython 3.1.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. Cython/Build/BuildExecutable.py +169 -0
  2. Cython/Build/Cache.py +199 -0
  3. Cython/Build/Cythonize.py +250 -0
  4. Cython/Build/Dependencies.py +1275 -0
  5. Cython/Build/Distutils.py +1 -0
  6. Cython/Build/Inline.py +342 -0
  7. Cython/Build/IpythonMagic.py +560 -0
  8. Cython/Build/Tests/TestCyCache.py +119 -0
  9. Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
  10. Cython/Build/Tests/TestDependencies.py +133 -0
  11. Cython/Build/Tests/TestInline.py +112 -0
  12. Cython/Build/Tests/TestIpythonMagic.py +287 -0
  13. Cython/Build/Tests/TestRecythonize.py +212 -0
  14. Cython/Build/Tests/TestStripLiterals.py +155 -0
  15. Cython/Build/Tests/__init__.py +1 -0
  16. Cython/Build/__init__.py +8 -0
  17. Cython/CodeWriter.py +811 -0
  18. Cython/Compiler/AnalysedTreeTransforms.py +97 -0
  19. Cython/Compiler/Annotate.py +326 -0
  20. Cython/Compiler/AutoDocTransforms.py +314 -0
  21. Cython/Compiler/Buffer.py +680 -0
  22. Cython/Compiler/Builtin.py +862 -0
  23. Cython/Compiler/CmdLine.py +243 -0
  24. Cython/Compiler/Code.pxd +145 -0
  25. Cython/Compiler/Code.py +3328 -0
  26. Cython/Compiler/CodeGeneration.py +33 -0
  27. Cython/Compiler/CythonScope.py +179 -0
  28. Cython/Compiler/Dataclass.py +868 -0
  29. Cython/Compiler/DebugFlags.py +21 -0
  30. Cython/Compiler/Errors.py +295 -0
  31. Cython/Compiler/ExprNodes.py +15051 -0
  32. Cython/Compiler/FlowControl.pxd +97 -0
  33. Cython/Compiler/FlowControl.py +1438 -0
  34. Cython/Compiler/FusedNode.py +998 -0
  35. Cython/Compiler/Future.py +16 -0
  36. Cython/Compiler/Interpreter.py +57 -0
  37. Cython/Compiler/Lexicon.py +340 -0
  38. Cython/Compiler/LineTable.py +114 -0
  39. Cython/Compiler/Main.py +779 -0
  40. Cython/Compiler/MatchCaseNodes.py +259 -0
  41. Cython/Compiler/MemoryView.py +860 -0
  42. Cython/Compiler/ModuleNode.py +4065 -0
  43. Cython/Compiler/Naming.py +369 -0
  44. Cython/Compiler/Nodes.py +10557 -0
  45. Cython/Compiler/Optimize.py +5269 -0
  46. Cython/Compiler/Options.py +828 -0
  47. Cython/Compiler/ParseTreeTransforms.pxd +78 -0
  48. Cython/Compiler/ParseTreeTransforms.py +4441 -0
  49. Cython/Compiler/Parsing.pxd +9 -0
  50. Cython/Compiler/Parsing.py +4797 -0
  51. Cython/Compiler/Pipeline.py +425 -0
  52. Cython/Compiler/PyrexTypes.py +5572 -0
  53. Cython/Compiler/Pythran.py +223 -0
  54. Cython/Compiler/Scanning.pxd +40 -0
  55. Cython/Compiler/Scanning.py +574 -0
  56. Cython/Compiler/StringEncoding.py +347 -0
  57. Cython/Compiler/Symtab.py +2998 -0
  58. Cython/Compiler/Tests/TestBuffer.py +105 -0
  59. Cython/Compiler/Tests/TestBuiltin.py +72 -0
  60. Cython/Compiler/Tests/TestCmdLine.py +573 -0
  61. Cython/Compiler/Tests/TestCode.py +86 -0
  62. Cython/Compiler/Tests/TestFlowControl.py +65 -0
  63. Cython/Compiler/Tests/TestGrammar.py +202 -0
  64. Cython/Compiler/Tests/TestMemView.py +71 -0
  65. Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
  66. Cython/Compiler/Tests/TestScanning.py +134 -0
  67. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  68. Cython/Compiler/Tests/TestStringEncoding.py +33 -0
  69. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  70. Cython/Compiler/Tests/TestTreePath.py +93 -0
  71. Cython/Compiler/Tests/TestTypes.py +75 -0
  72. Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
  73. Cython/Compiler/Tests/TestVisitor.py +61 -0
  74. Cython/Compiler/Tests/Utils.py +36 -0
  75. Cython/Compiler/Tests/__init__.py +1 -0
  76. Cython/Compiler/TreeFragment.py +278 -0
  77. Cython/Compiler/TreePath.py +290 -0
  78. Cython/Compiler/TypeInference.py +584 -0
  79. Cython/Compiler/TypeSlots.py +1181 -0
  80. Cython/Compiler/UFuncs.py +311 -0
  81. Cython/Compiler/UtilNodes.py +387 -0
  82. Cython/Compiler/UtilityCode.py +274 -0
  83. Cython/Compiler/Version.py +8 -0
  84. Cython/Compiler/Visitor.pxd +53 -0
  85. Cython/Compiler/Visitor.py +861 -0
  86. Cython/Compiler/__init__.py +1 -0
  87. Cython/Coverage.py +443 -0
  88. Cython/Debugger/Cygdb.py +179 -0
  89. Cython/Debugger/DebugWriter.py +82 -0
  90. Cython/Debugger/Tests/TestLibCython.py +275 -0
  91. Cython/Debugger/Tests/__init__.py +1 -0
  92. Cython/Debugger/Tests/cfuncs.c +8 -0
  93. Cython/Debugger/Tests/codefile +49 -0
  94. Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
  95. Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
  96. Cython/Debugger/__init__.py +1 -0
  97. Cython/Debugger/libcython.py +1549 -0
  98. Cython/Debugger/libpython.py +2821 -0
  99. Cython/Debugging.py +20 -0
  100. Cython/Distutils/__init__.py +2 -0
  101. Cython/Distutils/build_ext.py +137 -0
  102. Cython/Distutils/extension.py +96 -0
  103. Cython/Distutils/old_build_ext.py +351 -0
  104. Cython/Includes/cpython/__init__.pxd +173 -0
  105. Cython/Includes/cpython/array.pxd +174 -0
  106. Cython/Includes/cpython/bool.pxd +37 -0
  107. Cython/Includes/cpython/buffer.pxd +112 -0
  108. Cython/Includes/cpython/bytearray.pxd +33 -0
  109. Cython/Includes/cpython/bytes.pxd +200 -0
  110. Cython/Includes/cpython/cellobject.pxd +35 -0
  111. Cython/Includes/cpython/ceval.pxd +8 -0
  112. Cython/Includes/cpython/codecs.pxd +121 -0
  113. Cython/Includes/cpython/complex.pxd +55 -0
  114. Cython/Includes/cpython/contextvars.pxd +141 -0
  115. Cython/Includes/cpython/conversion.pxd +36 -0
  116. Cython/Includes/cpython/datetime.pxd +384 -0
  117. Cython/Includes/cpython/descr.pxd +26 -0
  118. Cython/Includes/cpython/dict.pxd +187 -0
  119. Cython/Includes/cpython/exc.pxd +263 -0
  120. Cython/Includes/cpython/fileobject.pxd +57 -0
  121. Cython/Includes/cpython/float.pxd +47 -0
  122. Cython/Includes/cpython/function.pxd +65 -0
  123. Cython/Includes/cpython/genobject.pxd +25 -0
  124. Cython/Includes/cpython/getargs.pxd +12 -0
  125. Cython/Includes/cpython/instance.pxd +25 -0
  126. Cython/Includes/cpython/iterator.pxd +36 -0
  127. Cython/Includes/cpython/iterobject.pxd +24 -0
  128. Cython/Includes/cpython/list.pxd +92 -0
  129. Cython/Includes/cpython/long.pxd +149 -0
  130. Cython/Includes/cpython/longintrepr.pxd +19 -0
  131. Cython/Includes/cpython/mapping.pxd +63 -0
  132. Cython/Includes/cpython/marshal.pxd +66 -0
  133. Cython/Includes/cpython/mem.pxd +120 -0
  134. Cython/Includes/cpython/memoryview.pxd +50 -0
  135. Cython/Includes/cpython/method.pxd +49 -0
  136. Cython/Includes/cpython/module.pxd +208 -0
  137. Cython/Includes/cpython/number.pxd +258 -0
  138. Cython/Includes/cpython/object.pxd +433 -0
  139. Cython/Includes/cpython/pycapsule.pxd +143 -0
  140. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  141. Cython/Includes/cpython/pyport.pxd +8 -0
  142. Cython/Includes/cpython/pystate.pxd +95 -0
  143. Cython/Includes/cpython/pythread.pxd +53 -0
  144. Cython/Includes/cpython/ref.pxd +67 -0
  145. Cython/Includes/cpython/sequence.pxd +134 -0
  146. Cython/Includes/cpython/set.pxd +119 -0
  147. Cython/Includes/cpython/slice.pxd +70 -0
  148. Cython/Includes/cpython/time.pxd +129 -0
  149. Cython/Includes/cpython/tuple.pxd +72 -0
  150. Cython/Includes/cpython/type.pxd +53 -0
  151. Cython/Includes/cpython/unicode.pxd +639 -0
  152. Cython/Includes/cpython/version.pxd +32 -0
  153. Cython/Includes/cpython/weakref.pxd +42 -0
  154. Cython/Includes/libc/__init__.pxd +1 -0
  155. Cython/Includes/libc/complex.pxd +35 -0
  156. Cython/Includes/libc/errno.pxd +127 -0
  157. Cython/Includes/libc/float.pxd +43 -0
  158. Cython/Includes/libc/limits.pxd +28 -0
  159. Cython/Includes/libc/locale.pxd +46 -0
  160. Cython/Includes/libc/math.pxd +209 -0
  161. Cython/Includes/libc/setjmp.pxd +10 -0
  162. Cython/Includes/libc/signal.pxd +64 -0
  163. Cython/Includes/libc/stddef.pxd +9 -0
  164. Cython/Includes/libc/stdint.pxd +105 -0
  165. Cython/Includes/libc/stdio.pxd +80 -0
  166. Cython/Includes/libc/stdlib.pxd +72 -0
  167. Cython/Includes/libc/string.pxd +50 -0
  168. Cython/Includes/libc/time.pxd +47 -0
  169. Cython/Includes/libcpp/__init__.pxd +4 -0
  170. Cython/Includes/libcpp/algorithm.pxd +320 -0
  171. Cython/Includes/libcpp/any.pxd +16 -0
  172. Cython/Includes/libcpp/atomic.pxd +59 -0
  173. Cython/Includes/libcpp/bit.pxd +29 -0
  174. Cython/Includes/libcpp/cast.pxd +12 -0
  175. Cython/Includes/libcpp/cmath.pxd +518 -0
  176. Cython/Includes/libcpp/complex.pxd +106 -0
  177. Cython/Includes/libcpp/deque.pxd +165 -0
  178. Cython/Includes/libcpp/execution.pxd +15 -0
  179. Cython/Includes/libcpp/forward_list.pxd +63 -0
  180. Cython/Includes/libcpp/functional.pxd +26 -0
  181. Cython/Includes/libcpp/iterator.pxd +34 -0
  182. Cython/Includes/libcpp/limits.pxd +61 -0
  183. Cython/Includes/libcpp/list.pxd +117 -0
  184. Cython/Includes/libcpp/map.pxd +252 -0
  185. Cython/Includes/libcpp/memory.pxd +115 -0
  186. Cython/Includes/libcpp/numbers.pxd +15 -0
  187. Cython/Includes/libcpp/numeric.pxd +131 -0
  188. Cython/Includes/libcpp/optional.pxd +34 -0
  189. Cython/Includes/libcpp/pair.pxd +1 -0
  190. Cython/Includes/libcpp/queue.pxd +25 -0
  191. Cython/Includes/libcpp/random.pxd +166 -0
  192. Cython/Includes/libcpp/set.pxd +228 -0
  193. Cython/Includes/libcpp/stack.pxd +11 -0
  194. Cython/Includes/libcpp/string.pxd +333 -0
  195. Cython/Includes/libcpp/typeindex.pxd +15 -0
  196. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  197. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  198. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  199. Cython/Includes/libcpp/utility.pxd +30 -0
  200. Cython/Includes/libcpp/vector.pxd +167 -0
  201. Cython/Includes/openmp.pxd +50 -0
  202. Cython/Includes/posix/__init__.pxd +1 -0
  203. Cython/Includes/posix/dlfcn.pxd +14 -0
  204. Cython/Includes/posix/fcntl.pxd +86 -0
  205. Cython/Includes/posix/ioctl.pxd +4 -0
  206. Cython/Includes/posix/mman.pxd +101 -0
  207. Cython/Includes/posix/resource.pxd +57 -0
  208. Cython/Includes/posix/select.pxd +21 -0
  209. Cython/Includes/posix/signal.pxd +73 -0
  210. Cython/Includes/posix/stat.pxd +98 -0
  211. Cython/Includes/posix/stdio.pxd +37 -0
  212. Cython/Includes/posix/stdlib.pxd +29 -0
  213. Cython/Includes/posix/strings.pxd +9 -0
  214. Cython/Includes/posix/time.pxd +71 -0
  215. Cython/Includes/posix/types.pxd +30 -0
  216. Cython/Includes/posix/uio.pxd +26 -0
  217. Cython/Includes/posix/unistd.pxd +271 -0
  218. Cython/Includes/posix/wait.pxd +38 -0
  219. Cython/Plex/Actions.pxd +24 -0
  220. Cython/Plex/Actions.py +119 -0
  221. Cython/Plex/DFA.pxd +14 -0
  222. Cython/Plex/DFA.py +164 -0
  223. Cython/Plex/Errors.py +48 -0
  224. Cython/Plex/Lexicons.py +178 -0
  225. Cython/Plex/Machines.pxd +36 -0
  226. Cython/Plex/Machines.py +238 -0
  227. Cython/Plex/Regexps.py +539 -0
  228. Cython/Plex/Scanners.pxd +47 -0
  229. Cython/Plex/Scanners.py +360 -0
  230. Cython/Plex/Transitions.pxd +14 -0
  231. Cython/Plex/Transitions.py +239 -0
  232. Cython/Plex/__init__.py +34 -0
  233. Cython/Runtime/__init__.py +1 -0
  234. Cython/Runtime/refnanny.pyx +261 -0
  235. Cython/Shadow.py +656 -0
  236. Cython/Shadow.pyi +521 -0
  237. Cython/StringIOTree.py +170 -0
  238. Cython/Tempita/__init__.py +4 -0
  239. Cython/Tempita/_looper.py +154 -0
  240. Cython/Tempita/_tempita.py +1091 -0
  241. Cython/TestUtils.py +417 -0
  242. Cython/Tests/TestCodeWriter.py +128 -0
  243. Cython/Tests/TestCythonUtils.py +202 -0
  244. Cython/Tests/TestJediTyper.py +223 -0
  245. Cython/Tests/TestShadow.py +114 -0
  246. Cython/Tests/TestStringIOTree.py +67 -0
  247. Cython/Tests/TestTestUtils.py +90 -0
  248. Cython/Tests/__init__.py +1 -0
  249. Cython/Tests/xmlrunner.py +390 -0
  250. Cython/Utility/AsyncGen.c +1263 -0
  251. Cython/Utility/Buffer.c +875 -0
  252. Cython/Utility/Builtins.c +660 -0
  253. Cython/Utility/CConvert.pyx +134 -0
  254. Cython/Utility/CMath.c +95 -0
  255. Cython/Utility/CommonStructures.c +139 -0
  256. Cython/Utility/Complex.c +378 -0
  257. Cython/Utility/Coroutine.c +2413 -0
  258. Cython/Utility/CpdefEnums.pyx +108 -0
  259. Cython/Utility/CppConvert.pyx +279 -0
  260. Cython/Utility/CppSupport.cpp +133 -0
  261. Cython/Utility/CythonFunction.c +1851 -0
  262. Cython/Utility/Dataclasses.c +185 -0
  263. Cython/Utility/Dataclasses.py +112 -0
  264. Cython/Utility/Embed.c +125 -0
  265. Cython/Utility/Exceptions.c +1017 -0
  266. Cython/Utility/ExtensionTypes.c +797 -0
  267. Cython/Utility/FunctionArguments.c +573 -0
  268. Cython/Utility/ImportExport.c +912 -0
  269. Cython/Utility/MemoryView.pyx +1478 -0
  270. Cython/Utility/MemoryView_C.c +992 -0
  271. Cython/Utility/ModuleSetupCode.c +2501 -0
  272. Cython/Utility/NumpyImportArray.c +46 -0
  273. Cython/Utility/ObjectHandling.c +3054 -0
  274. Cython/Utility/Optimize.c +1533 -0
  275. Cython/Utility/Overflow.c +404 -0
  276. Cython/Utility/Printing.c +86 -0
  277. Cython/Utility/Profile.c +660 -0
  278. Cython/Utility/StringTools.c +1206 -0
  279. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  280. Cython/Utility/TestCythonScope.pyx +75 -0
  281. Cython/Utility/TestUtilityLoader.c +12 -0
  282. Cython/Utility/TypeConversion.c +1329 -0
  283. Cython/Utility/UFuncs.pyx +50 -0
  284. Cython/Utility/UFuncs_C.c +89 -0
  285. Cython/Utility/__init__.py +28 -0
  286. Cython/Utility/arrayarray.h +143 -0
  287. Cython/Utils.py +687 -0
  288. Cython/__init__.py +10 -0
  289. Cython/__init__.pyi +7 -0
  290. Cython/py.typed +0 -0
  291. Cython-3.1.0a1.dist-info/COPYING.txt +19 -0
  292. Cython-3.1.0a1.dist-info/LICENSE.txt +176 -0
  293. Cython-3.1.0a1.dist-info/METADATA +67 -0
  294. Cython-3.1.0a1.dist-info/RECORD +301 -0
  295. Cython-3.1.0a1.dist-info/WHEEL +5 -0
  296. Cython-3.1.0a1.dist-info/entry_points.txt +4 -0
  297. Cython-3.1.0a1.dist-info/top_level.txt +3 -0
  298. cython.py +29 -0
  299. pyximport/__init__.py +4 -0
  300. pyximport/pyxbuild.py +160 -0
  301. pyximport/pyximport.py +482 -0
@@ -0,0 +1,1533 @@
1
+ /*
2
+ * Optional optimisations of built-in functions and methods.
3
+ *
4
+ * Required replacements of builtins are in Builtins.c.
5
+ *
6
+ * General object operations and protocols are in ObjectHandling.c.
7
+ */
8
+
9
+ /////////////// append.proto ///////////////
10
+
11
+ static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); /*proto*/
12
+
13
+ /////////////// append ///////////////
14
+ //@requires: ListAppend
15
+ //@requires: ObjectHandling.c::PyObjectCallMethod1
16
+
17
+ static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
18
+ if (likely(PyList_CheckExact(L))) {
19
+ if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
20
+ } else {
21
+ PyObject* retval = __Pyx_PyObject_CallMethod1(L, PYIDENT("append"), x);
22
+ if (unlikely(!retval))
23
+ return -1;
24
+ Py_DECREF(retval);
25
+ }
26
+ return 0;
27
+ }
28
+
29
+ /////////////// ListAppend.proto ///////////////
30
+
31
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
32
+ static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
33
+ PyListObject* L = (PyListObject*) list;
34
+ Py_ssize_t len = Py_SIZE(list);
35
+ if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
36
+ Py_INCREF(x);
37
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000
38
+ // In Py3.13a1, PyList_SET_ITEM() checks that the end index is lower than the current size.
39
+ // However, extending the size *before* setting the value would not be correct,
40
+ // so we cannot call PyList_SET_ITEM().
41
+ L->ob_item[len] = x;
42
+ #else
43
+ PyList_SET_ITEM(list, len, x);
44
+ #endif
45
+ __Pyx_SET_SIZE(list, len + 1);
46
+ return 0;
47
+ }
48
+ return PyList_Append(list, x);
49
+ }
50
+ #else
51
+ #define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
52
+ #endif
53
+
54
+ /////////////// ListCompAppend.proto ///////////////
55
+
56
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
57
+ static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
58
+ PyListObject* L = (PyListObject*) list;
59
+ Py_ssize_t len = Py_SIZE(list);
60
+ if (likely(L->allocated > len)) {
61
+ Py_INCREF(x);
62
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000
63
+ // In Py3.13a1, PyList_SET_ITEM() checks that the end index is lower than the current size.
64
+ // However, extending the size *before* setting the value would not be correct,
65
+ // so we cannot call PyList_SET_ITEM().
66
+ L->ob_item[len] = x;
67
+ #else
68
+ PyList_SET_ITEM(list, len, x);
69
+ #endif
70
+ __Pyx_SET_SIZE(list, len + 1);
71
+ return 0;
72
+ }
73
+ return PyList_Append(list, x);
74
+ }
75
+ #else
76
+ #define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
77
+ #endif
78
+
79
+ //////////////////// ListExtend.proto ////////////////////
80
+
81
+ static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) {
82
+ #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00a2
83
+ return PyList_Extend(L, v);
84
+ #elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
85
+ PyObject* none = _PyList_Extend((PyListObject*)L, v);
86
+ if (unlikely(!none))
87
+ return -1;
88
+ Py_DECREF(none);
89
+ return 0;
90
+ #else
91
+ return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v);
92
+ #endif
93
+ }
94
+
95
+ /////////////// pop.proto ///////////////
96
+
97
+ static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L); /*proto*/
98
+
99
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
100
+ static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L); /*proto*/
101
+ #define __Pyx_PyObject_Pop(L) (likely(PyList_CheckExact(L)) ? \
102
+ __Pyx_PyList_Pop(L) : __Pyx__PyObject_Pop(L))
103
+
104
+ #else
105
+ #define __Pyx_PyList_Pop(L) __Pyx__PyObject_Pop(L)
106
+ #define __Pyx_PyObject_Pop(L) __Pyx__PyObject_Pop(L)
107
+ #endif
108
+
109
+ /////////////// pop ///////////////
110
+ //@requires: ObjectHandling.c::PyObjectCallMethod0
111
+
112
+ static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) {
113
+ if (__Pyx_IS_TYPE(L, &PySet_Type)) {
114
+ return PySet_Pop(L);
115
+ }
116
+ return __Pyx_PyObject_CallMethod0(L, PYIDENT("pop"));
117
+ }
118
+
119
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
120
+ static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L) {
121
+ /* Check that both the size is positive and no reallocation shrinking needs to be done. */
122
+ if (likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) {
123
+ __Pyx_SET_SIZE(L, Py_SIZE(L) - 1);
124
+ return PyList_GET_ITEM(L, PyList_GET_SIZE(L));
125
+ }
126
+ return CALL_UNBOUND_METHOD(PyList_Type, "pop", L);
127
+ }
128
+ #endif
129
+
130
+
131
+ /////////////// pop_index.proto ///////////////
132
+
133
+ static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix); /*proto*/
134
+ static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix); /*proto*/
135
+
136
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
137
+ static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix); /*proto*/
138
+
139
+ #define __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) ( \
140
+ (likely(PyList_CheckExact(L) && __Pyx_fits_Py_ssize_t(ix, type, is_signed))) ? \
141
+ __Pyx__PyList_PopIndex(L, py_ix, ix) : ( \
142
+ (unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) : \
143
+ __Pyx__PyObject_PopIndex(L, py_ix)))
144
+
145
+ #define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) ( \
146
+ __Pyx_fits_Py_ssize_t(ix, type, is_signed) ? \
147
+ __Pyx__PyList_PopIndex(L, py_ix, ix) : ( \
148
+ (unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) : \
149
+ __Pyx__PyObject_PopIndex(L, py_ix)))
150
+
151
+ #else
152
+
153
+ #define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) \
154
+ __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func)
155
+
156
+ #define __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) ( \
157
+ (unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) : \
158
+ __Pyx__PyObject_PopIndex(L, py_ix))
159
+ #endif
160
+
161
+ /////////////// pop_index ///////////////
162
+ //@requires: ObjectHandling.c::PyObjectCallMethod1
163
+
164
+ static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix) {
165
+ PyObject *r;
166
+ if (unlikely(!py_ix)) return NULL;
167
+ r = __Pyx__PyObject_PopIndex(L, py_ix);
168
+ Py_DECREF(py_ix);
169
+ return r;
170
+ }
171
+
172
+ static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix) {
173
+ return __Pyx_PyObject_CallMethod1(L, PYIDENT("pop"), py_ix);
174
+ }
175
+
176
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
177
+ static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix) {
178
+ Py_ssize_t size = PyList_GET_SIZE(L);
179
+ if (likely(size > (((PyListObject*)L)->allocated >> 1))) {
180
+ Py_ssize_t cix = ix;
181
+ if (cix < 0) {
182
+ cix += size;
183
+ }
184
+ if (likely(__Pyx_is_valid_index(cix, size))) {
185
+ PyObject* v = PyList_GET_ITEM(L, cix);
186
+ __Pyx_SET_SIZE(L, Py_SIZE(L) - 1);
187
+ size -= 1;
188
+ memmove(&PyList_GET_ITEM(L, cix), &PyList_GET_ITEM(L, cix+1), (size_t)(size-cix)*sizeof(PyObject*));
189
+ return v;
190
+ }
191
+ }
192
+ if (py_ix == Py_None) {
193
+ return __Pyx__PyObject_PopNewIndex(L, PyLong_FromSsize_t(ix));
194
+ } else {
195
+ return __Pyx__PyObject_PopIndex(L, py_ix);
196
+ }
197
+ }
198
+ #endif
199
+
200
+
201
+ /////////////// dict_getitem_default.proto ///////////////
202
+
203
+ static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value); /*proto*/
204
+
205
+ /////////////// dict_getitem_default ///////////////
206
+
207
+ static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
208
+ PyObject* value;
209
+ #if !CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000
210
+ value = PyDict_GetItemWithError(d, key);
211
+ if (unlikely(!value)) {
212
+ if (unlikely(PyErr_Occurred()))
213
+ return NULL;
214
+ value = default_value;
215
+ }
216
+ Py_INCREF(value);
217
+ // avoid C compiler warning about unused utility functions
218
+ if ((1));
219
+ #else
220
+ if (PyBytes_CheckExact(key) || PyUnicode_CheckExact(key) || PyLong_CheckExact(key)) {
221
+ /* these presumably have safe hash functions */
222
+ value = PyDict_GetItem(d, key);
223
+ if (unlikely(!value)) {
224
+ value = default_value;
225
+ }
226
+ Py_INCREF(value);
227
+ }
228
+ #endif
229
+ else {
230
+ if (default_value == Py_None)
231
+ value = CALL_UNBOUND_METHOD(PyDict_Type, "get", d, key);
232
+ else
233
+ value = CALL_UNBOUND_METHOD(PyDict_Type, "get", d, key, default_value);
234
+ }
235
+ return value;
236
+ }
237
+
238
+
239
+ /////////////// dict_setdefault.proto ///////////////
240
+
241
+ static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value, int is_safe_type); /*proto*/
242
+
243
+ /////////////// dict_setdefault ///////////////
244
+
245
+ static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value,
246
+ int is_safe_type) {
247
+ PyObject* value;
248
+ CYTHON_MAYBE_UNUSED_VAR(is_safe_type);
249
+ value = PyDict_SetDefault(d, key, default_value);
250
+ if (unlikely(!value)) return NULL;
251
+ Py_INCREF(value);
252
+ return value;
253
+ }
254
+
255
+
256
+ /////////////// py_dict_clear.proto ///////////////
257
+
258
+ #define __Pyx_PyDict_Clear(d) (PyDict_Clear(d), 0)
259
+
260
+
261
+ /////////////// py_dict_pop.proto ///////////////
262
+
263
+ static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value); /*proto*/
264
+
265
+ /////////////// py_dict_pop ///////////////
266
+
267
+ static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value) {
268
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d00A2 || defined(PyDict_Pop)
269
+ PyObject *value;
270
+ if (PyDict_Pop(d, key, &value) == 0) {
271
+ if (default_value) {
272
+ Py_INCREF(default_value);
273
+ } else {
274
+ PyErr_SetObject(PyExc_KeyError, key);
275
+ }
276
+ value = default_value;
277
+ }
278
+ // On error, PyDict_Pop() returns -1 and sets value to NULL (our own exception return value).
279
+ return value;
280
+ #elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
281
+ return _PyDict_Pop(d, key, default_value);
282
+ #else
283
+ if (default_value) {
284
+ return CALL_UNBOUND_METHOD(PyDict_Type, "pop", d, key, default_value);
285
+ } else {
286
+ return CALL_UNBOUND_METHOD(PyDict_Type, "pop", d, key);
287
+ }
288
+ #endif
289
+ }
290
+
291
+
292
+ /////////////// py_dict_pop_ignore.proto ///////////////
293
+
294
+ static CYTHON_INLINE int __Pyx_PyDict_Pop_ignore(PyObject *d, PyObject *key, PyObject *default_value); /*proto*/
295
+
296
+ /////////////// py_dict_pop_ignore ///////////////
297
+
298
+ static CYTHON_INLINE int __Pyx_PyDict_Pop_ignore(PyObject *d, PyObject *key, PyObject *default_value) {
299
+ // We take the "default_value" as argument to avoid "unused" warnings, but we ignore it here.
300
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d00A2 || defined(PyDict_Pop)
301
+ int result = PyDict_Pop(d, key, NULL);
302
+ CYTHON_UNUSED_VAR(default_value);
303
+ return (unlikely(result == -1)) ? -1 : 0;
304
+ #else
305
+ PyObject *value;
306
+ CYTHON_UNUSED_VAR(default_value);
307
+
308
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
309
+ value = _PyDict_Pop(d, key, Py_None);
310
+ #else
311
+ value = CALL_UNBOUND_METHOD(PyDict_Type, "pop", d, key, Py_None);
312
+ #endif
313
+
314
+ if (unlikely(value == NULL))
315
+ return -1;
316
+ Py_DECREF(value);
317
+ return 0;
318
+ #endif
319
+ }
320
+
321
+
322
+ /////////////// dict_iter.proto ///////////////
323
+
324
+ static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name,
325
+ Py_ssize_t* p_orig_length, int* p_is_dict);
326
+ static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos,
327
+ PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict);
328
+
329
+ /////////////// dict_iter ///////////////
330
+ //@requires: ObjectHandling.c::UnpackTuple2
331
+ //@requires: ObjectHandling.c::IterFinish
332
+ //@requires: ObjectHandling.c::PyObjectCallMethod0
333
+
334
+ #if CYTHON_COMPILING_IN_PYPY
335
+ #include <string.h>
336
+ #endif
337
+
338
+ static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name,
339
+ Py_ssize_t* p_orig_length, int* p_source_is_dict) {
340
+ is_dict = is_dict || likely(PyDict_CheckExact(iterable));
341
+ *p_source_is_dict = is_dict;
342
+ if (is_dict) {
343
+ #if !CYTHON_COMPILING_IN_PYPY
344
+ *p_orig_length = PyDict_Size(iterable);
345
+ Py_INCREF(iterable);
346
+ return iterable;
347
+ #else
348
+ // On PyPy3, we need to translate manually a few method names.
349
+ // This logic is not needed on CPython thanks to the fast case above.
350
+ static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL;
351
+ PyObject **pp = NULL;
352
+ if (method_name) {
353
+ const char *name = PyUnicode_AsUTF8(method_name);
354
+ if (strcmp(name, "iteritems") == 0) pp = &py_items;
355
+ else if (strcmp(name, "iterkeys") == 0) pp = &py_keys;
356
+ else if (strcmp(name, "itervalues") == 0) pp = &py_values;
357
+ if (pp) {
358
+ if (!*pp) {
359
+ *pp = PyUnicode_FromString(name + 4);
360
+ if (!*pp)
361
+ return NULL;
362
+ }
363
+ method_name = *pp;
364
+ }
365
+ }
366
+ #endif
367
+ }
368
+ *p_orig_length = 0;
369
+ if (method_name) {
370
+ PyObject* iter;
371
+ iterable = __Pyx_PyObject_CallMethod0(iterable, method_name);
372
+ if (!iterable)
373
+ return NULL;
374
+ #if !CYTHON_COMPILING_IN_PYPY
375
+ if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable))
376
+ return iterable;
377
+ #endif
378
+ iter = PyObject_GetIter(iterable);
379
+ Py_DECREF(iterable);
380
+ return iter;
381
+ }
382
+ return PyObject_GetIter(iterable);
383
+ }
384
+
385
+ static CYTHON_INLINE int __Pyx_dict_iter_next(
386
+ PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos,
387
+ PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) {
388
+ PyObject* next_item;
389
+ #if !CYTHON_COMPILING_IN_PYPY
390
+ if (source_is_dict) {
391
+ PyObject *key, *value;
392
+ if (unlikely(orig_length != PyDict_Size(iter_obj))) {
393
+ PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration");
394
+ return -1;
395
+ }
396
+ if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) {
397
+ return 0;
398
+ }
399
+ if (pitem) {
400
+ PyObject* tuple = PyTuple_New(2);
401
+ if (unlikely(!tuple)) {
402
+ return -1;
403
+ }
404
+ Py_INCREF(key);
405
+ Py_INCREF(value);
406
+ #if CYTHON_ASSUME_SAFE_MACROS
407
+ PyTuple_SET_ITEM(tuple, 0, key);
408
+ PyTuple_SET_ITEM(tuple, 1, value);
409
+ #else
410
+ if (unlikely(PyTuple_SetItem(tuple, 0, key) < 0)) {
411
+ // decref value; PyTuple_SetItem decrefs key on failure
412
+ Py_DECREF(value);
413
+ Py_DECREF(tuple);
414
+ return -1;
415
+ }
416
+ if (unlikely(PyTuple_SetItem(tuple, 1, value) < 0)) {
417
+ // PyTuple_SetItem decrefs value on failure
418
+ Py_DECREF(tuple);
419
+ return -1;
420
+ }
421
+ #endif
422
+ *pitem = tuple;
423
+ } else {
424
+ if (pkey) {
425
+ Py_INCREF(key);
426
+ *pkey = key;
427
+ }
428
+ if (pvalue) {
429
+ Py_INCREF(value);
430
+ *pvalue = value;
431
+ }
432
+ }
433
+ return 1;
434
+ } else if (PyTuple_CheckExact(iter_obj)) {
435
+ Py_ssize_t pos = *ppos;
436
+ Py_ssize_t tuple_size = __Pyx_PyTuple_GET_SIZE(iter_obj);
437
+ #if !CYTHON_ASSUME_SAFE_SIZE
438
+ if (unlikely(tuple_size < 0)) return -1;
439
+ #endif
440
+ if (unlikely(pos >= tuple_size)) return 0;
441
+ *ppos = pos + 1;
442
+ #if CYTHON_ASSUME_SAFE_MACROS
443
+ next_item = PyTuple_GET_ITEM(iter_obj, pos);
444
+ #else
445
+ next_item = PyTuple_GetItem(iter_obj, pos);
446
+ if (unlikely(!next_item)) return -1;
447
+ #endif
448
+ Py_INCREF(next_item);
449
+ } else if (PyList_CheckExact(iter_obj)) {
450
+ Py_ssize_t pos = *ppos;
451
+ Py_ssize_t list_size = __Pyx_PyList_GET_SIZE(iter_obj);
452
+ #if !CYTHON_ASSUME_SAFE_SIZE
453
+ if (unlikely(list_size < 0)) return -1;
454
+ #endif
455
+ if (unlikely(pos >= list_size)) return 0;
456
+ *ppos = pos + 1;
457
+ #if CYTHON_ASSUME_SAFE_MACROS
458
+ next_item = PyList_GET_ITEM(iter_obj, pos);
459
+ #else
460
+ next_item = PyList_GetItem(iter_obj, pos);
461
+ if (unlikely(!next_item)) return -1;
462
+ #endif
463
+ Py_INCREF(next_item);
464
+ } else
465
+ #endif
466
+ {
467
+ next_item = PyIter_Next(iter_obj);
468
+ if (unlikely(!next_item)) {
469
+ return __Pyx_IterFinish();
470
+ }
471
+ }
472
+ if (pitem) {
473
+ *pitem = next_item;
474
+ } else if (pkey && pvalue) {
475
+ if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1))
476
+ return -1;
477
+ } else if (pkey) {
478
+ *pkey = next_item;
479
+ } else {
480
+ *pvalue = next_item;
481
+ }
482
+ return 1;
483
+ }
484
+
485
+
486
+ /////////////// set_iter.proto ///////////////
487
+
488
+ static CYTHON_INLINE PyObject* __Pyx_set_iterator(PyObject* iterable, int is_set,
489
+ Py_ssize_t* p_orig_length, int* p_source_is_set); /*proto*/
490
+ static CYTHON_INLINE int __Pyx_set_iter_next(
491
+ PyObject* iter_obj, Py_ssize_t orig_length,
492
+ Py_ssize_t* ppos, PyObject **value,
493
+ int source_is_set); /*proto*/
494
+
495
+ /////////////// set_iter ///////////////
496
+ //@requires: ObjectHandling.c::IterFinish
497
+
498
+ static CYTHON_INLINE PyObject* __Pyx_set_iterator(PyObject* iterable, int is_set,
499
+ Py_ssize_t* p_orig_length, int* p_source_is_set) {
500
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
501
+ is_set = is_set || likely(PySet_CheckExact(iterable) || PyFrozenSet_CheckExact(iterable));
502
+ *p_source_is_set = is_set;
503
+ if (likely(is_set)) {
504
+ *p_orig_length = PySet_Size(iterable);
505
+ Py_INCREF(iterable);
506
+ return iterable;
507
+ }
508
+ #else
509
+ CYTHON_UNUSED_VAR(is_set);
510
+ *p_source_is_set = 0;
511
+ #endif
512
+ *p_orig_length = 0;
513
+ return PyObject_GetIter(iterable);
514
+ }
515
+
516
+ static CYTHON_INLINE int __Pyx_set_iter_next(
517
+ PyObject* iter_obj, Py_ssize_t orig_length,
518
+ Py_ssize_t* ppos, PyObject **value,
519
+ int source_is_set) {
520
+ if (!CYTHON_COMPILING_IN_CPYTHON || PY_VERSION_HEX >= 0x030d0000 || unlikely(!source_is_set)) {
521
+ *value = PyIter_Next(iter_obj);
522
+ if (unlikely(!*value)) {
523
+ return __Pyx_IterFinish();
524
+ }
525
+ CYTHON_UNUSED_VAR(orig_length);
526
+ CYTHON_UNUSED_VAR(ppos);
527
+ return 1;
528
+ }
529
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
530
+ if (unlikely(PySet_GET_SIZE(iter_obj) != orig_length)) {
531
+ PyErr_SetString(
532
+ PyExc_RuntimeError,
533
+ "set changed size during iteration");
534
+ return -1;
535
+ }
536
+ {
537
+ Py_hash_t hash;
538
+ int ret = _PySet_NextEntry(iter_obj, ppos, value, &hash);
539
+ // CPython does not raise errors here, only if !isinstance(iter_obj, set/frozenset)
540
+ assert (ret != -1);
541
+ if (likely(ret)) {
542
+ Py_INCREF(*value);
543
+ return 1;
544
+ }
545
+ }
546
+ #endif
547
+ return 0;
548
+ }
549
+
550
+ /////////////// py_set_discard_unhashable ///////////////
551
+ //@requires: Builtins.c::pyfrozenset_new
552
+
553
+ static int __Pyx_PySet_DiscardUnhashable(PyObject *set, PyObject *key) {
554
+ PyObject *tmpkey;
555
+ int rv;
556
+
557
+ if (likely(!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)))
558
+ return -1;
559
+ PyErr_Clear();
560
+ tmpkey = __Pyx_PyFrozenSet_New(key);
561
+ if (tmpkey == NULL)
562
+ return -1;
563
+ rv = PySet_Discard(set, tmpkey);
564
+ Py_DECREF(tmpkey);
565
+ return rv;
566
+ }
567
+
568
+
569
+ /////////////// py_set_discard.proto ///////////////
570
+
571
+ static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key); /*proto*/
572
+
573
+ /////////////// py_set_discard ///////////////
574
+ //@requires: py_set_discard_unhashable
575
+
576
+ static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key) {
577
+ int found = PySet_Discard(set, key);
578
+ // Convert *key* to frozenset if necessary
579
+ if (unlikely(found < 0)) {
580
+ found = __Pyx_PySet_DiscardUnhashable(set, key);
581
+ }
582
+ // note: returns -1 on error, 0 (not found) or 1 (found) otherwise => error check for -1 or < 0 works
583
+ return found;
584
+ }
585
+
586
+
587
+ /////////////// py_set_remove.proto ///////////////
588
+
589
+ static CYTHON_INLINE int __Pyx_PySet_Remove(PyObject *set, PyObject *key); /*proto*/
590
+
591
+ /////////////// py_set_remove ///////////////
592
+ //@requires: py_set_discard_unhashable
593
+
594
+ static int __Pyx_PySet_RemoveNotFound(PyObject *set, PyObject *key, int found) {
595
+ // Convert *key* to frozenset if necessary
596
+ if (unlikely(found < 0)) {
597
+ found = __Pyx_PySet_DiscardUnhashable(set, key);
598
+ }
599
+ if (likely(found == 0)) {
600
+ // Not found
601
+ PyObject *tup;
602
+ tup = PyTuple_Pack(1, key);
603
+ if (!tup)
604
+ return -1;
605
+ PyErr_SetObject(PyExc_KeyError, tup);
606
+ Py_DECREF(tup);
607
+ return -1;
608
+ }
609
+ // note: returns -1 on error, 0 (not found) or 1 (found) otherwise => error check for -1 or < 0 works
610
+ return found;
611
+ }
612
+
613
+ static CYTHON_INLINE int __Pyx_PySet_Remove(PyObject *set, PyObject *key) {
614
+ int found = PySet_Discard(set, key);
615
+ if (unlikely(found != 1)) {
616
+ // note: returns -1 on error, 0 (not found) or 1 (found) otherwise => error check for -1 or < 0 works
617
+ return __Pyx_PySet_RemoveNotFound(set, key, found);
618
+ }
619
+ return 0;
620
+ }
621
+
622
+
623
+ /////////////// unicode_iter.proto ///////////////
624
+
625
+ static CYTHON_INLINE int __Pyx_init_unicode_iteration(
626
+ PyObject* ustring, Py_ssize_t *length, void** data, int *kind); /* proto */
627
+
628
+ /////////////// unicode_iter ///////////////
629
+
630
+ static CYTHON_INLINE int __Pyx_init_unicode_iteration(
631
+ PyObject* ustring, Py_ssize_t *length, void** data, int *kind) {
632
+ #if CYTHON_COMPILING_IN_LIMITED_API
633
+ // In the limited API we just point data to the unicode object
634
+ *kind = 0;
635
+ *length = PyUnicode_GetLength(ustring);
636
+ *data = (void*)ustring;
637
+ #else
638
+ if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return -1;
639
+ *kind = PyUnicode_KIND(ustring);
640
+ *length = PyUnicode_GET_LENGTH(ustring);
641
+ *data = PyUnicode_DATA(ustring);
642
+ #endif
643
+ return 0;
644
+ }
645
+
646
+ /////////////// pyobject_as_double.proto ///////////////
647
+
648
+ static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */
649
+
650
+ #if CYTHON_COMPILING_IN_PYPY
651
+ #define __Pyx_PyObject_AsDouble(obj) \
652
+ (likely(PyFloat_CheckExact(obj)) ? PyFloat_AS_DOUBLE(obj) : \
653
+ likely(PyLong_CheckExact(obj)) ? \
654
+ PyFloat_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
655
+ #else
656
+ #define __Pyx_PyObject_AsDouble(obj) \
657
+ ((likely(PyFloat_CheckExact(obj))) ? __Pyx_PyFloat_AS_DOUBLE(obj) : \
658
+ likely(PyLong_CheckExact(obj)) ? \
659
+ PyLong_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
660
+ #endif
661
+
662
+ /////////////// pyobject_as_double ///////////////
663
+ //@requires: pybytes_as_double
664
+ //@requires: pyunicode_as_double
665
+ //@requires: ObjectHandling.c::PyObjectCallOneArg
666
+
667
+ static double __Pyx__PyObject_AsDouble(PyObject* obj) {
668
+ if (PyUnicode_CheckExact(obj)) {
669
+ return __Pyx_PyUnicode_AsDouble(obj);
670
+ } else if (PyBytes_CheckExact(obj)) {
671
+ return __Pyx_PyBytes_AsDouble(obj);
672
+ } else if (PyByteArray_CheckExact(obj)) {
673
+ return __Pyx_PyByteArray_AsDouble(obj);
674
+ } else {
675
+ PyObject* float_value;
676
+ #if !CYTHON_USE_TYPE_SLOTS
677
+ float_value = PyNumber_Float(obj); if ((0)) goto bad;
678
+ // avoid "unused" warnings
679
+ (void)__Pyx_PyObject_CallOneArg;
680
+ #else
681
+ PyNumberMethods *nb = Py_TYPE(obj)->tp_as_number;
682
+ if (likely(nb) && likely(nb->nb_float)) {
683
+ float_value = nb->nb_float(obj);
684
+ if (likely(float_value) && unlikely(!PyFloat_Check(float_value))) {
685
+ __Pyx_TypeName float_value_type_name = __Pyx_PyType_GetName(Py_TYPE(float_value));
686
+ PyErr_Format(PyExc_TypeError,
687
+ "__float__ returned non-float (type " __Pyx_FMT_TYPENAME ")",
688
+ float_value_type_name);
689
+ __Pyx_DECREF_TypeName(float_value_type_name);
690
+ Py_DECREF(float_value);
691
+ goto bad;
692
+ }
693
+ } else {
694
+ float_value = __Pyx_PyObject_CallOneArg((PyObject*)&PyFloat_Type, obj);
695
+ }
696
+ #endif
697
+ if (likely(float_value)) {
698
+ double value = __Pyx_PyFloat_AS_DOUBLE(float_value);
699
+ Py_DECREF(float_value);
700
+ return value;
701
+ }
702
+ }
703
+ bad:
704
+ return (double)-1;
705
+ }
706
+
707
+
708
+ /////////////// pyunicode_as_double.proto ///////////////
709
+
710
+ static CYTHON_INLINE double __Pyx_PyUnicode_AsDouble(PyObject *obj);/*proto*/
711
+
712
+ /////////////// pyunicode_as_double.proto ///////////////
713
+ //@requires: pybytes_as_double
714
+
715
+ #if !CYTHON_COMPILING_IN_PYPY && CYTHON_ASSUME_SAFE_MACROS
716
+ static const char* __Pyx__PyUnicode_AsDouble_Copy(const void* data, const int kind, char* buffer, Py_ssize_t start, Py_ssize_t end) {
717
+ int last_was_punctuation;
718
+ Py_ssize_t i;
719
+ // number must not start with punctuation
720
+ last_was_punctuation = 1;
721
+ for (i=start; i <= end; i++) {
722
+ Py_UCS4 chr = PyUnicode_READ(kind, data, i);
723
+ int is_punctuation = (chr == '_') | (chr == '.');
724
+ *buffer = (char)chr;
725
+ // reject sequences of '_' and '.'
726
+ buffer += (chr != '_');
727
+ if (unlikely(chr > 127)) goto parse_failure;
728
+ if (unlikely(last_was_punctuation & is_punctuation)) goto parse_failure;
729
+ last_was_punctuation = is_punctuation;
730
+ }
731
+ if (unlikely(last_was_punctuation)) goto parse_failure;
732
+ *buffer = '\0';
733
+ return buffer;
734
+
735
+ parse_failure:
736
+ return NULL;
737
+ }
738
+
739
+ static double __Pyx__PyUnicode_AsDouble_inf_nan(const void* data, int kind, Py_ssize_t start, Py_ssize_t length) {
740
+ int matches = 1;
741
+ Py_UCS4 chr;
742
+ Py_UCS4 sign = PyUnicode_READ(kind, data, start);
743
+ int is_signed = (sign == '-') | (sign == '+');
744
+ start += is_signed;
745
+ length -= is_signed;
746
+
747
+ switch (PyUnicode_READ(kind, data, start)) {
748
+ #ifdef Py_NAN
749
+ case 'n':
750
+ case 'N':
751
+ if (unlikely(length != 3)) goto parse_failure;
752
+ chr = PyUnicode_READ(kind, data, start+1);
753
+ matches &= (chr == 'a') | (chr == 'A');
754
+ chr = PyUnicode_READ(kind, data, start+2);
755
+ matches &= (chr == 'n') | (chr == 'N');
756
+ if (unlikely(!matches)) goto parse_failure;
757
+ return (sign == '-') ? -Py_NAN : Py_NAN;
758
+ #endif
759
+ case 'i':
760
+ case 'I':
761
+ if (unlikely(length < 3)) goto parse_failure;
762
+ chr = PyUnicode_READ(kind, data, start+1);
763
+ matches &= (chr == 'n') | (chr == 'N');
764
+ chr = PyUnicode_READ(kind, data, start+2);
765
+ matches &= (chr == 'f') | (chr == 'F');
766
+ if (likely(length == 3 && matches))
767
+ return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL;
768
+ if (unlikely(length != 8)) goto parse_failure;
769
+ chr = PyUnicode_READ(kind, data, start+3);
770
+ matches &= (chr == 'i') | (chr == 'I');
771
+ chr = PyUnicode_READ(kind, data, start+4);
772
+ matches &= (chr == 'n') | (chr == 'N');
773
+ chr = PyUnicode_READ(kind, data, start+5);
774
+ matches &= (chr == 'i') | (chr == 'I');
775
+ chr = PyUnicode_READ(kind, data, start+6);
776
+ matches &= (chr == 't') | (chr == 'T');
777
+ chr = PyUnicode_READ(kind, data, start+7);
778
+ matches &= (chr == 'y') | (chr == 'Y');
779
+ if (unlikely(!matches)) goto parse_failure;
780
+ return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL;
781
+ case '.': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
782
+ break;
783
+ default:
784
+ goto parse_failure;
785
+ }
786
+ return 0.0;
787
+ parse_failure:
788
+ return -1.0;
789
+ }
790
+
791
+ static double __Pyx_PyUnicode_AsDouble_WithSpaces(PyObject *obj) {
792
+ double value;
793
+ const char *last;
794
+ char *end;
795
+ Py_ssize_t start, length = PyUnicode_GET_LENGTH(obj);
796
+ const int kind = PyUnicode_KIND(obj);
797
+ const void* data = PyUnicode_DATA(obj);
798
+
799
+ // strip spaces at start and end
800
+ start = 0;
801
+ while (Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, start)))
802
+ start++;
803
+ while (start < length - 1 && Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, length - 1)))
804
+ length--;
805
+ length -= start;
806
+ if (unlikely(length <= 0)) goto fallback;
807
+
808
+ // parse NaN / inf
809
+ value = __Pyx__PyUnicode_AsDouble_inf_nan(data, kind, start, length);
810
+ if (unlikely(value == -1.0)) goto fallback;
811
+ if (value != 0.0) return value;
812
+
813
+ if (length < 40) {
814
+ char number[40];
815
+ last = __Pyx__PyUnicode_AsDouble_Copy(data, kind, number, start, start + length);
816
+ if (unlikely(!last)) goto fallback;
817
+ value = PyOS_string_to_double(number, &end, NULL);
818
+ } else {
819
+ char *number = (char*) PyMem_Malloc((length + 1) * sizeof(char));
820
+ if (unlikely(!number)) goto fallback;
821
+ last = __Pyx__PyUnicode_AsDouble_Copy(data, kind, number, start, start + length);
822
+ if (unlikely(!last)) {
823
+ PyMem_Free(number);
824
+ goto fallback;
825
+ }
826
+ value = PyOS_string_to_double(number, &end, NULL);
827
+ PyMem_Free(number);
828
+ }
829
+ if (likely(end == last) || (value == (double)-1 && PyErr_Occurred())) {
830
+ return value;
831
+ }
832
+ fallback:
833
+ return __Pyx_SlowPyString_AsDouble(obj);
834
+ }
835
+ #endif
836
+
837
+ static CYTHON_INLINE double __Pyx_PyUnicode_AsDouble(PyObject *obj) {
838
+ // Currently not optimised for Py2.7.
839
+ #if !CYTHON_COMPILING_IN_PYPY && CYTHON_ASSUME_SAFE_MACROS
840
+ if (unlikely(__Pyx_PyUnicode_READY(obj) == -1))
841
+ return (double)-1;
842
+ if (likely(PyUnicode_IS_ASCII(obj))) {
843
+ const char *s;
844
+ Py_ssize_t length;
845
+ s = PyUnicode_AsUTF8AndSize(obj, &length);
846
+ return __Pyx__PyBytes_AsDouble(obj, s, length);
847
+ }
848
+ return __Pyx_PyUnicode_AsDouble_WithSpaces(obj);
849
+ #else
850
+ return __Pyx_SlowPyString_AsDouble(obj);
851
+ #endif
852
+ }
853
+
854
+
855
+ /////////////// pybytes_as_double.proto ///////////////
856
+
857
+ static double __Pyx_SlowPyString_AsDouble(PyObject *obj);/*proto*/
858
+ static double __Pyx__PyBytes_AsDouble(PyObject *obj, const char* start, Py_ssize_t length);/*proto*/
859
+
860
+ static CYTHON_INLINE double __Pyx_PyBytes_AsDouble(PyObject *obj) {
861
+ char* as_c_string;
862
+ Py_ssize_t size;
863
+ #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
864
+ as_c_string = PyBytes_AS_STRING(obj);
865
+ size = PyBytes_GET_SIZE(obj);
866
+ #else
867
+ if (PyBytes_AsStringAndSize(obj, &as_c_string, &size) < 0) {
868
+ return (double)-1;
869
+ }
870
+ #endif
871
+ return __Pyx__PyBytes_AsDouble(obj, as_c_string, size);
872
+ }
873
+ static CYTHON_INLINE double __Pyx_PyByteArray_AsDouble(PyObject *obj) {
874
+ char* as_c_string;
875
+ Py_ssize_t size;
876
+ #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
877
+ as_c_string = PyByteArray_AS_STRING(obj);
878
+ size = PyByteArray_GET_SIZE(obj);
879
+ #else
880
+ as_c_string = PyByteArray_AsString(obj);
881
+ if (as_c_string == NULL) {
882
+ return (double)-1;
883
+ }
884
+ size = PyByteArray_Size(obj);
885
+ #endif
886
+ return __Pyx__PyBytes_AsDouble(obj, as_c_string, size);
887
+ }
888
+
889
+
890
+ /////////////// pybytes_as_double ///////////////
891
+
892
+ static double __Pyx_SlowPyString_AsDouble(PyObject *obj) {
893
+ PyObject *float_value = PyFloat_FromString(obj);
894
+ if (likely(float_value)) {
895
+ double value = __Pyx_PyFloat_AS_DOUBLE(float_value);
896
+ Py_DECREF(float_value);
897
+ return value;
898
+ }
899
+ return (double)-1;
900
+ }
901
+
902
+ static const char* __Pyx__PyBytes_AsDouble_Copy(const char* start, char* buffer, Py_ssize_t length) {
903
+ // number must not start with punctuation
904
+ int last_was_punctuation = 1;
905
+ int parse_error_found = 0;
906
+ Py_ssize_t i;
907
+ for (i=0; i < length; i++) {
908
+ char chr = start[i];
909
+ int is_punctuation = (chr == '_') | (chr == '.') | (chr == 'e') | (chr == 'E');
910
+ *buffer = chr;
911
+ buffer += (chr != '_');
912
+ // reject sequences of punctuation, e.g. '_.'
913
+ parse_error_found |= last_was_punctuation & is_punctuation;
914
+ last_was_punctuation = is_punctuation;
915
+ }
916
+ // number must not end with punctuation
917
+ parse_error_found |= last_was_punctuation;
918
+ *buffer = '\0';
919
+ return unlikely(parse_error_found) ? NULL : buffer;
920
+ }
921
+
922
+ static double __Pyx__PyBytes_AsDouble_inf_nan(const char* start, Py_ssize_t length) {
923
+ int matches = 1;
924
+ char sign = start[0];
925
+ int is_signed = (sign == '+') | (sign == '-');
926
+ start += is_signed;
927
+ length -= is_signed;
928
+
929
+ switch (start[0]) {
930
+ #ifdef Py_NAN
931
+ case 'n':
932
+ case 'N':
933
+ if (unlikely(length != 3)) goto parse_failure;
934
+ matches &= (start[1] == 'a' || start[1] == 'A');
935
+ matches &= (start[2] == 'n' || start[2] == 'N');
936
+ if (unlikely(!matches)) goto parse_failure;
937
+ return (sign == '-') ? -Py_NAN : Py_NAN;
938
+ #endif
939
+ case 'i':
940
+ case 'I':
941
+ if (unlikely(length < 3)) goto parse_failure;
942
+ matches &= (start[1] == 'n' || start[1] == 'N');
943
+ matches &= (start[2] == 'f' || start[2] == 'F');
944
+ if (likely(length == 3 && matches))
945
+ return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL;
946
+ if (unlikely(length != 8)) goto parse_failure;
947
+ matches &= (start[3] == 'i' || start[3] == 'I');
948
+ matches &= (start[4] == 'n' || start[4] == 'N');
949
+ matches &= (start[5] == 'i' || start[5] == 'I');
950
+ matches &= (start[6] == 't' || start[6] == 'T');
951
+ matches &= (start[7] == 'y' || start[7] == 'Y');
952
+ if (unlikely(!matches)) goto parse_failure;
953
+ return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL;
954
+ case '.': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
955
+ break;
956
+ default:
957
+ goto parse_failure;
958
+ }
959
+ return 0.0;
960
+ parse_failure:
961
+ return -1.0;
962
+ }
963
+
964
+ static CYTHON_INLINE int __Pyx__PyBytes_AsDouble_IsSpace(char ch) {
965
+ // see Py_ISSPACE() in CPython
966
+ // https://github.com/python/cpython/blob/master/Python/pyctype.c
967
+ return (ch == 0x20) | !((ch < 0x9) | (ch > 0xd));
968
+ }
969
+
970
+ CYTHON_UNUSED static double __Pyx__PyBytes_AsDouble(PyObject *obj, const char* start, Py_ssize_t length) {
971
+ double value;
972
+ Py_ssize_t i, digits;
973
+ const char *last = start + length;
974
+ char *end;
975
+
976
+ // strip spaces at start and end
977
+ while (__Pyx__PyBytes_AsDouble_IsSpace(*start))
978
+ start++;
979
+ while (start < last - 1 && __Pyx__PyBytes_AsDouble_IsSpace(last[-1]))
980
+ last--;
981
+ length = last - start;
982
+ if (unlikely(length <= 0)) goto fallback;
983
+
984
+ // parse NaN / inf
985
+ value = __Pyx__PyBytes_AsDouble_inf_nan(start, length);
986
+ if (unlikely(value == -1.0)) goto fallback;
987
+ if (value != 0.0) return value;
988
+
989
+ // look for underscores
990
+ digits = 0;
991
+ for (i=0; i < length; digits += start[i++] != '_');
992
+
993
+ if (likely(digits == length)) {
994
+ value = PyOS_string_to_double(start, &end, NULL);
995
+ } else if (digits < 40) {
996
+ char number[40];
997
+ last = __Pyx__PyBytes_AsDouble_Copy(start, number, length);
998
+ if (unlikely(!last)) goto fallback;
999
+ value = PyOS_string_to_double(number, &end, NULL);
1000
+ } else {
1001
+ char *number = (char*) PyMem_Malloc((digits + 1) * sizeof(char));
1002
+ if (unlikely(!number)) goto fallback;
1003
+ last = __Pyx__PyBytes_AsDouble_Copy(start, number, length);
1004
+ if (unlikely(!last)) {
1005
+ PyMem_Free(number);
1006
+ goto fallback;
1007
+ }
1008
+ value = PyOS_string_to_double(number, &end, NULL);
1009
+ PyMem_Free(number);
1010
+ }
1011
+ if (likely(end == last) || (value == (double)-1 && PyErr_Occurred())) {
1012
+ return value;
1013
+ }
1014
+ fallback:
1015
+ return __Pyx_SlowPyString_AsDouble(obj);
1016
+ }
1017
+
1018
+
1019
+ /////////////// PyNumberPow2.proto ///////////////
1020
+
1021
+ #define __Pyx_PyNumber_InPlacePowerOf2(a, b, c) __Pyx__PyNumber_PowerOf2(a, b, c, 1)
1022
+ #define __Pyx_PyNumber_PowerOf2(a, b, c) __Pyx__PyNumber_PowerOf2(a, b, c, 0)
1023
+
1024
+ static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject *none, int inplace); /*proto*/
1025
+
1026
+ /////////////// PyNumberPow2 ///////////////
1027
+
1028
+ static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject *none, int inplace) {
1029
+ // in CPython, 1<<N is substantially faster than 2**N
1030
+ // see https://bugs.python.org/issue21420
1031
+ #if !CYTHON_COMPILING_IN_PYPY
1032
+ Py_ssize_t shiftby;
1033
+ if (likely(PyLong_CheckExact(exp))) {
1034
+ #if CYTHON_USE_PYLONG_INTERNALS
1035
+ if (__Pyx_PyLong_IsZero(exp)) {
1036
+ return PyLong_FromLong(1L);
1037
+ } else if (__Pyx_PyLong_IsNeg(exp)) {
1038
+ goto fallback;
1039
+ } else if (__Pyx_PyLong_IsCompact(exp)) {
1040
+ shiftby = __Pyx_PyLong_CompactValueUnsigned(exp);
1041
+ } else {
1042
+ shiftby = PyLong_AsSsize_t(exp);
1043
+ }
1044
+ #else
1045
+ shiftby = PyLong_AsSsize_t(exp);
1046
+ #endif
1047
+ } else {
1048
+ goto fallback;
1049
+ }
1050
+ if (likely(shiftby >= 0)) {
1051
+ if ((size_t)shiftby <= sizeof(long) * 8 - 2) {
1052
+ long value = 1L << shiftby;
1053
+ return PyLong_FromLong(value);
1054
+ #ifdef HAVE_LONG_LONG
1055
+ } else if ((size_t)shiftby <= sizeof(unsigned PY_LONG_LONG) * 8 - 1) {
1056
+ unsigned PY_LONG_LONG value = ((unsigned PY_LONG_LONG)1) << shiftby;
1057
+ return PyLong_FromUnsignedLongLong(value);
1058
+ #endif
1059
+ } else {
1060
+ PyObject *result, *one = PyLong_FromLong(1L);
1061
+ if (unlikely(!one)) return NULL;
1062
+ result = PyNumber_Lshift(one, exp);
1063
+ Py_DECREF(one);
1064
+ return result;
1065
+ }
1066
+ } else if (shiftby == -1 && PyErr_Occurred()) {
1067
+ PyErr_Clear();
1068
+ }
1069
+ fallback:
1070
+ #endif
1071
+ return (inplace ? PyNumber_InPlacePower : PyNumber_Power)(two, exp, none);
1072
+ }
1073
+
1074
+
1075
+ /////////////// PyLongCompare.proto ///////////////
1076
+
1077
+ {{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
1078
+ static CYTHON_INLINE {{c_ret_type}} __Pyx_PyLong_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(PyObject *op1, PyObject *op2, long intval, long inplace); /*proto*/
1079
+
1080
+ /////////////// PyLongCompare ///////////////
1081
+
1082
+ {{py: pyval, ival = ('op2', 'b') if order == 'CObj' else ('op1', 'a') }}
1083
+ {{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
1084
+ {{py: return_true = 'Py_RETURN_TRUE' if ret_type.is_pyobject else 'return 1'}}
1085
+ {{py: return_false = 'Py_RETURN_FALSE' if ret_type.is_pyobject else 'return 0'}}
1086
+ {{py: slot_name = op.lower() }}
1087
+ {{py: c_op = {'Eq': '==', 'Ne': '!='}[op] }}
1088
+ {{py:
1089
+ return_compare = (
1090
+ (lambda a,b,c_op, return_true=return_true, return_false=return_false: "if ({a} {c_op} {b}) {return_true}; else {return_false};".format(
1091
+ a=a, b=b, c_op=c_op, return_true=return_true, return_false=return_false))
1092
+ if ret_type.is_pyobject else
1093
+ (lambda a,b,c_op: "return ({a} {c_op} {b});".format(a=a, b=b, c_op=c_op))
1094
+ )
1095
+ }}
1096
+
1097
+ static CYTHON_INLINE {{c_ret_type}} __Pyx_PyLong_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(PyObject *op1, PyObject *op2, long intval, long inplace) {
1098
+ CYTHON_MAYBE_UNUSED_VAR(intval);
1099
+ CYTHON_UNUSED_VAR(inplace);
1100
+ if (op1 == op2) {
1101
+ {{return_true if op == 'Eq' else return_false}};
1102
+ }
1103
+
1104
+ #if CYTHON_USE_PYLONG_INTERNALS
1105
+ if (likely(PyLong_CheckExact({{pyval}}))) {
1106
+ int unequal;
1107
+ unsigned long uintval;
1108
+ Py_ssize_t size = __Pyx_PyLong_DigitCount({{pyval}});
1109
+ const digit* digits = __Pyx_PyLong_Digits({{pyval}});
1110
+ if (intval == 0) {
1111
+ {{return_compare('__Pyx_PyLong_IsZero(%s)' % pyval, '1', c_op)}}
1112
+ } else if (intval < 0) {
1113
+ if (__Pyx_PyLong_IsNonNeg({{pyval}}))
1114
+ {{return_false if op == 'Eq' else return_true}};
1115
+ // both are negative => can use absolute values now.
1116
+ intval = -intval;
1117
+ } else {
1118
+ // > 0 => Py_SIZE(pyval) > 0
1119
+ if (__Pyx_PyLong_IsNeg({{pyval}}))
1120
+ {{return_false if op == 'Eq' else return_true}};
1121
+ }
1122
+ // After checking that the sign is the same (and excluding 0), now compare the absolute values.
1123
+ // When inlining, the C compiler should select exactly one line from this unrolled loop.
1124
+ uintval = (unsigned long) intval;
1125
+ {{for _size in range(4, 0, -1)}}
1126
+ #if PyLong_SHIFT * {{_size}} < SIZEOF_LONG*8
1127
+ if (uintval >> (PyLong_SHIFT * {{_size}})) {
1128
+ // The C integer value is between (PyLong_BASE ** _size) and MIN(PyLong_BASE ** _size, LONG_MAX).
1129
+ unequal = (size != {{_size+1}}) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
1130
+ {{for _i in range(1, _size+1)}} | (digits[{{_i}}] != ((uintval >> ({{_i}} * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)){{endfor}};
1131
+ } else
1132
+ #endif
1133
+ {{endfor}}
1134
+ unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
1135
+
1136
+ {{return_compare('unequal', '0', c_op)}}
1137
+ }
1138
+ #endif
1139
+
1140
+ if (PyFloat_CheckExact({{pyval}})) {
1141
+ const long {{'a' if order == 'CObj' else 'b'}} = intval;
1142
+ double {{ival}} = __Pyx_PyFloat_AS_DOUBLE({{pyval}});
1143
+ {{return_compare('(double)a', '(double)b', c_op)}}
1144
+ }
1145
+
1146
+ return {{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(
1147
+ PyObject_RichCompare(op1, op2, Py_{{op.upper()}}));
1148
+ }
1149
+
1150
+
1151
+ /////////////// PyLongBinop.proto ///////////////
1152
+
1153
+ {{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
1154
+ #if !CYTHON_COMPILING_IN_PYPY
1155
+ static {{c_ret_type}} __Pyx_PyLong_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); /*proto*/
1156
+ #else
1157
+ #define __Pyx_PyLong_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(op1, op2, intval, inplace, zerodivision_check) \
1158
+ {{if op in ('Eq', 'Ne')}}{{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(PyObject_RichCompare(op1, op2, Py_{{op.upper()}}))
1159
+ {{else}}(inplace ? PyNumber_InPlace{{op}}(op1, op2) : PyNumber_{{op}}(op1, op2))
1160
+ {{endif}}
1161
+ #endif
1162
+
1163
+ /////////////// PyLongBinop ///////////////
1164
+
1165
+ #if !CYTHON_COMPILING_IN_PYPY
1166
+ {{py: from Cython.Utility import pylong_join }}
1167
+ {{py: pyval, ival = ('op2', 'b') if order == 'CObj' else ('op1', 'a') }}
1168
+ {{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
1169
+ {{py: return_true = 'Py_RETURN_TRUE' if ret_type.is_pyobject else 'return 1'}}
1170
+ {{py: return_false = 'Py_RETURN_FALSE' if ret_type.is_pyobject else 'return 0'}}
1171
+ {{py: slot_name = {'TrueDivide': 'true_divide', 'FloorDivide': 'floor_divide'}.get(op, op.lower()) }}
1172
+ {{py: cfunc_name = '__Pyx_PyLong_%s%s%s' % ('' if ret_type.is_pyobject else 'Bool', op, order)}}
1173
+ {{py:
1174
+ c_op = {
1175
+ 'Add': '+', 'Subtract': '-', 'Multiply': '*', 'Remainder': '%', 'TrueDivide': '/', 'FloorDivide': '/',
1176
+ 'Or': '|', 'Xor': '^', 'And': '&', 'Rshift': '>>', 'Lshift': '<<',
1177
+ 'Eq': '==', 'Ne': '!=',
1178
+ }[op]
1179
+ }}
1180
+ {{py:
1181
+ def zerodiv_check(operand, optype='integer', _is_mod=op == 'Remainder', _needs_check=(order == 'CObj' and c_op in '%/')):
1182
+ return (((
1183
+ 'if (unlikely(zerodivision_check && ((%s) == 0))) {'
1184
+ ' PyErr_SetString(PyExc_ZeroDivisionError, "%s division%s by zero");'
1185
+ ' return NULL;'
1186
+ '}') % (operand, optype, ' or modulo' if _is_mod else '')
1187
+ ) if _needs_check else '')
1188
+ }}
1189
+
1190
+ static {{c_ret_type}} {{cfunc_name}}(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) {
1191
+ CYTHON_MAYBE_UNUSED_VAR(intval);
1192
+ CYTHON_MAYBE_UNUSED_VAR(inplace);
1193
+ CYTHON_UNUSED_VAR(zerodivision_check);
1194
+
1195
+ {{if op in ('Eq', 'Ne')}}
1196
+ if (op1 == op2) {
1197
+ {{return_true if op == 'Eq' else return_false}};
1198
+ }
1199
+ {{endif}}
1200
+
1201
+ #if CYTHON_USE_PYLONG_INTERNALS
1202
+ if (likely(PyLong_CheckExact({{pyval}}))) {
1203
+ const long {{'a' if order == 'CObj' else 'b'}} = intval;
1204
+ long {{ival}}{{if op not in ('Eq', 'Ne')}}, x{{endif}};
1205
+ {{if op not in ('Eq', 'Ne', 'TrueDivide')}}
1206
+ #ifdef HAVE_LONG_LONG
1207
+ const PY_LONG_LONG ll{{'a' if order == 'CObj' else 'b'}} = intval;
1208
+ PY_LONG_LONG ll{{ival}}, llx;
1209
+ #endif
1210
+ {{endif}}
1211
+ // special cases for 0: + - * % / // | ^ & >> <<
1212
+ if (unlikely(__Pyx_PyLong_IsZero({{pyval}}))) {
1213
+ {{if order == 'CObj' and c_op in '%/'}}
1214
+ // division by zero!
1215
+ {{zerodiv_check('0')}}
1216
+ {{elif order == 'CObj' and c_op in '+-|^>><<'}}
1217
+ // x == x+0 == x-0 == x|0 == x^0 == x>>0 == x<<0
1218
+ return __Pyx_NewRef(op1);
1219
+ {{elif order == 'CObj' and c_op in '*&'}}
1220
+ // 0 == x*0 == x&0
1221
+ return __Pyx_NewRef(op2);
1222
+ {{elif order == 'ObjC' and c_op in '+|^'}}
1223
+ // x == 0+x == 0|x == 0^x
1224
+ return __Pyx_NewRef(op2);
1225
+ {{elif order == 'ObjC' and c_op == '-'}}
1226
+ // -x == 0-x
1227
+ return PyLong_FromLong(-intval);
1228
+ {{elif order == 'ObjC' and (c_op in '*%&>><<' or op == 'FloorDivide')}}
1229
+ // 0 == 0*x == 0%x == 0&x == 0>>x == 0<<x == 0//x
1230
+ return __Pyx_NewRef(op1);
1231
+ {{endif}}
1232
+ }
1233
+ {{if c_op == '&'}}
1234
+ // special case for &-ing arbitrarily large numbers with known single digit operands
1235
+ if ((intval & PyLong_MASK) == intval) {
1236
+ // Calling PyLong_CompactValue() requires the PyLong value to be compact, we only need the last digit.
1237
+ long last_digit = (long) __Pyx_PyLong_Digits({{pyval}})[0];
1238
+ long result = intval & (likely(__Pyx_PyLong_IsPos({{pyval}})) ? last_digit : (PyLong_MASK - last_digit + 1));
1239
+ return PyLong_FromLong(result);
1240
+ }
1241
+ {{endif}}
1242
+ // handle most common case first to avoid indirect branch and optimise branch prediction
1243
+ if (likely(__Pyx_PyLong_IsCompact({{pyval}}))) {
1244
+ {{ival}} = __Pyx_PyLong_CompactValue({{pyval}});
1245
+ } else {
1246
+ const digit* digits = __Pyx_PyLong_Digits({{pyval}});
1247
+ const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount({{pyval}});
1248
+ switch (size) {
1249
+ {{for _size in range(2, 5)}}
1250
+ {{for _case in (-_size, _size)}}
1251
+ case {{_case}}:
1252
+ if (8 * sizeof(long) - 1 > {{_size}} * PyLong_SHIFT{{if c_op == '*'}}+30{{endif}}{{if op == 'TrueDivide'}} && {{_size-1}} * PyLong_SHIFT < 53{{endif}}) {
1253
+ {{ival}} = {{'-' if _case < 0 else ''}}(long) {{pylong_join(_size, 'digits')}};
1254
+ break;
1255
+ {{if op not in ('Eq', 'Ne', 'TrueDivide')}}
1256
+ #ifdef HAVE_LONG_LONG
1257
+ } else if (8 * sizeof(PY_LONG_LONG) - 1 > {{_size}} * PyLong_SHIFT{{if c_op == '*'}}+30{{endif}}) {
1258
+ ll{{ival}} = {{'-' if _case < 0 else ''}}(PY_LONG_LONG) {{pylong_join(_size, 'digits', 'unsigned PY_LONG_LONG')}};
1259
+ goto long_long;
1260
+ #endif
1261
+ {{endif}}
1262
+ }
1263
+ // if size doesn't fit into a long or PY_LONG_LONG anymore, fall through to default
1264
+ CYTHON_FALLTHROUGH;
1265
+ {{endfor}}
1266
+ {{endfor}}
1267
+
1268
+ {{if op in ('Eq', 'Ne')}}
1269
+ #if PyLong_SHIFT < 30 && PyLong_SHIFT != 15
1270
+ // unusual setup - your fault
1271
+ default: return {{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(
1272
+ PyLong_Type.tp_richcompare({{'op1, op2' if order == 'ObjC' else 'op2, op1'}}, Py_{{op.upper()}}));
1273
+ #else
1274
+ // too large for the long values we allow => definitely not equal
1275
+ default: {{return_false if op == 'Eq' else return_true}};
1276
+ #endif
1277
+ {{else}}
1278
+ default: return PyLong_Type.tp_as_number->nb_{{slot_name}}(op1, op2);
1279
+ {{endif}}
1280
+ }
1281
+ }
1282
+ {{if op in ('Eq', 'Ne')}}
1283
+ if (a {{c_op}} b) {
1284
+ {{return_true}};
1285
+ } else {
1286
+ {{return_false}};
1287
+ }
1288
+ {{else}}
1289
+ {{if c_op == '*'}}
1290
+ CYTHON_UNUSED_VAR(a);
1291
+ CYTHON_UNUSED_VAR(b);
1292
+ #ifdef HAVE_LONG_LONG
1293
+ ll{{ival}} = {{ival}};
1294
+ goto long_long;
1295
+ #else
1296
+ return PyLong_Type.tp_as_number->nb_{{slot_name}}(op1, op2);
1297
+ #endif
1298
+ {{elif c_op == '%'}}
1299
+ // see CMath.c :: ModInt utility code
1300
+ x = a % b;
1301
+ x += ((x != 0) & ((x ^ b) < 0)) * b;
1302
+ {{elif op == 'TrueDivide'}}
1303
+ if ((8 * sizeof(long) <= 53 || likely(labs({{ival}}) <= ((PY_LONG_LONG)1 << 53)))
1304
+ || __Pyx_PyLong_DigitCount({{pyval}}) <= 52 / PyLong_SHIFT) {
1305
+ return PyFloat_FromDouble((double)a / (double)b);
1306
+ }
1307
+ return PyLong_Type.tp_as_number->nb_{{slot_name}}(op1, op2);
1308
+ {{elif op == 'FloorDivide'}}
1309
+ {
1310
+ long q, r;
1311
+ // see CMath.c :: DivInt utility code
1312
+ q = a / b;
1313
+ r = a - q*b;
1314
+ q -= ((r != 0) & ((r ^ b) < 0));
1315
+ x = q;
1316
+ }
1317
+ {{else}}
1318
+ x = a {{c_op}} b;
1319
+ {{if op == 'Lshift'}}
1320
+ #ifdef HAVE_LONG_LONG
1321
+ if (unlikely(!(b < (long) (sizeof(long)*8) && a == x >> b)) && a) {
1322
+ ll{{ival}} = {{ival}};
1323
+ goto long_long;
1324
+ }
1325
+ #else
1326
+ if (likely(b < (long) (sizeof(long)*8) && a == x >> b) || !a) /* execute return statement below */
1327
+ #endif
1328
+ {{endif}}
1329
+ {{endif}}
1330
+ return PyLong_FromLong(x);
1331
+
1332
+ {{if op != 'TrueDivide'}}
1333
+ #ifdef HAVE_LONG_LONG
1334
+ long_long:
1335
+ {{if c_op == '%'}}
1336
+ // see CMath.c :: ModInt utility code
1337
+ llx = lla % llb;
1338
+ llx += ((llx != 0) & ((llx ^ llb) < 0)) * llb;
1339
+ {{elif op == 'FloorDivide'}}
1340
+ {
1341
+ PY_LONG_LONG q, r;
1342
+ // see CMath.c :: DivInt utility code
1343
+ q = lla / llb;
1344
+ r = lla - q*llb;
1345
+ q -= ((r != 0) & ((r ^ llb) < 0));
1346
+ llx = q;
1347
+ }
1348
+ {{else}}
1349
+ llx = lla {{c_op}} llb;
1350
+ {{if op == 'Lshift'}}
1351
+ if (likely(lla == llx >> llb)) /* then execute 'return' below */
1352
+ {{endif}}
1353
+ {{endif}}
1354
+ return PyLong_FromLongLong(llx);
1355
+ #endif
1356
+ {{endif}}{{# if op != 'TrueDivide' #}}
1357
+ {{endif}}{{# if op in ('Eq', 'Ne') #}}
1358
+ }
1359
+ #endif
1360
+
1361
+ {{if c_op in '+-*' or op in ('TrueDivide', 'Eq', 'Ne')}}
1362
+ if (PyFloat_CheckExact({{pyval}})) {
1363
+ const long {{'a' if order == 'CObj' else 'b'}} = intval;
1364
+ double {{ival}} = __Pyx_PyFloat_AS_DOUBLE({{pyval}});
1365
+ {{if op in ('Eq', 'Ne')}}
1366
+ if ((double)a {{c_op}} (double)b) {
1367
+ {{return_true}};
1368
+ } else {
1369
+ {{return_false}};
1370
+ }
1371
+ {{else}}
1372
+ double result;
1373
+ {{zerodiv_check('b', 'float')}}
1374
+ result = ((double)a) {{c_op}} (double)b;
1375
+ return PyFloat_FromDouble(result);
1376
+ {{endif}}
1377
+ }
1378
+ {{endif}}
1379
+
1380
+ {{if op in ('Eq', 'Ne')}}
1381
+ return {{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(
1382
+ PyObject_RichCompare(op1, op2, Py_{{op.upper()}}));
1383
+ {{else}}
1384
+ return (inplace ? PyNumber_InPlace{{op}} : PyNumber_{{op}})(op1, op2);
1385
+ {{endif}}
1386
+ }
1387
+ #endif
1388
+
1389
+ /////////////// PyFloatBinop.proto ///////////////
1390
+
1391
+ {{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
1392
+ #if !CYTHON_COMPILING_IN_PYPY
1393
+ static {{c_ret_type}} __Pyx_PyFloat_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check); /*proto*/
1394
+ #else
1395
+ #define __Pyx_PyFloat_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(op1, op2, floatval, inplace, zerodivision_check) \
1396
+ {{if op in ('Eq', 'Ne')}}{{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(PyObject_RichCompare(op1, op2, Py_{{op.upper()}}))
1397
+ {{elif op == 'Divide'}}((inplace ? __Pyx_PyNumber_InPlaceDivide(op1, op2) : __Pyx_PyNumber_Divide(op1, op2)))
1398
+ {{else}}(inplace ? PyNumber_InPlace{{op}}(op1, op2) : PyNumber_{{op}}(op1, op2))
1399
+ {{endif}}
1400
+ #endif
1401
+
1402
+ /////////////// PyFloatBinop ///////////////
1403
+
1404
+ #if !CYTHON_COMPILING_IN_PYPY
1405
+ {{py: from Cython.Utility import pylong_join }}
1406
+ {{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
1407
+ {{py: return_true = 'Py_RETURN_TRUE' if ret_type.is_pyobject else 'return 1'}}
1408
+ {{py: return_false = 'Py_RETURN_FALSE' if ret_type.is_pyobject else 'return 0'}}
1409
+ {{py: pyval, fval = ('op2', 'b') if order == 'CObj' else ('op1', 'a') }}
1410
+ {{py: cfunc_name = '__Pyx_PyFloat_%s%s%s' % ('' if ret_type.is_pyobject else 'Bool', op, order) }}
1411
+ {{py:
1412
+ c_op = {
1413
+ 'Add': '+', 'Subtract': '-', 'TrueDivide': '/', 'Divide': '/', 'Remainder': '%',
1414
+ 'Eq': '==', 'Ne': '!=',
1415
+ }[op]
1416
+ }}
1417
+ {{py:
1418
+ def zerodiv_check(operand, _is_mod=op == 'Remainder', _needs_check=(order == 'CObj' and c_op in '%/')):
1419
+ return (((
1420
+ 'if (unlikely(zerodivision_check && ((%s) == 0.0))) {'
1421
+ ' PyErr_SetString(PyExc_ZeroDivisionError, "float division%s by zero");'
1422
+ ' return NULL;'
1423
+ '}') % (operand, ' or modulo' if _is_mod else '')
1424
+ ) if _needs_check else '')
1425
+ }}
1426
+
1427
+ static {{c_ret_type}} {{cfunc_name}}(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check) {
1428
+ const double {{'a' if order == 'CObj' else 'b'}} = floatval;
1429
+ double {{fval}}{{if op not in ('Eq', 'Ne')}}, result{{endif}};
1430
+ CYTHON_UNUSED_VAR(inplace);
1431
+ CYTHON_UNUSED_VAR(zerodivision_check);
1432
+
1433
+ {{if op in ('Eq', 'Ne')}}
1434
+ if (op1 == op2) {
1435
+ {{return_true if op == 'Eq' else return_false}};
1436
+ }
1437
+ {{endif}}
1438
+
1439
+ if (likely(PyFloat_CheckExact({{pyval}}))) {
1440
+ {{fval}} = __Pyx_PyFloat_AS_DOUBLE({{pyval}});
1441
+ {{zerodiv_check(fval)}}
1442
+ } else
1443
+
1444
+ if (likely(PyLong_CheckExact({{pyval}}))) {
1445
+ #if CYTHON_USE_PYLONG_INTERNALS
1446
+ if (__Pyx_PyLong_IsZero({{pyval}})) {
1447
+ {{fval}} = 0.0;
1448
+ {{zerodiv_check(fval)}}
1449
+ } else if (__Pyx_PyLong_IsCompact({{pyval}})) {
1450
+ {{fval}} = (double) __Pyx_PyLong_CompactValue({{pyval}});
1451
+ } else {
1452
+ const digit* digits = __Pyx_PyLong_Digits({{pyval}});
1453
+ const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount({{pyval}});
1454
+ switch (size) {
1455
+ {{for _size in (2, 3, 4)}}
1456
+ case -{{_size}}:
1457
+ case {{_size}}:
1458
+ if (8 * sizeof(unsigned long) > {{_size}} * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || ({{_size-1}} * PyLong_SHIFT < 53))) {
1459
+ {{fval}} = (double) {{pylong_join(_size, 'digits')}};
1460
+ // let CPython do its own float rounding from 2**53 on (max. consecutive integer in double float)
1461
+ if ((8 * sizeof(unsigned long) < 53) || ({{_size}} * PyLong_SHIFT < 53) || ({{fval}} < (double) ((PY_LONG_LONG)1 << 53))) {
1462
+ if (size == {{-_size}})
1463
+ {{fval}} = -{{fval}};
1464
+ break;
1465
+ }
1466
+ }
1467
+ // Fall through if size doesn't fit safely into a double anymore.
1468
+ // It may not be obvious that this is a safe fall-through given the "fval < 2**53"
1469
+ // check above. However, the number of digits that CPython uses for a given PyLong
1470
+ // value is minimal, and together with the "(size-1) * SHIFT < 53" check above,
1471
+ // this should make it safe.
1472
+ CYTHON_FALLTHROUGH;
1473
+ {{endfor}}
1474
+ default:
1475
+ #endif
1476
+ {{if op in ('Eq', 'Ne')}}
1477
+ {
1478
+ PyObject *res =
1479
+ #if CYTHON_USE_TYPE_SLOTS || __PYX_LIMITED_VERSION_HEX > 0x030A0000
1480
+ // PyType_GetSlot only works on non-heap types from Python 3.10
1481
+ __Pyx_PyType_GetSlot((&PyFloat_Type), tp_richcompare, richcmpfunc)
1482
+ #else
1483
+ PyObject_RichCompare
1484
+ #endif
1485
+ ({{'op1, op2' if order == 'CObj' else 'op2, op1'}},
1486
+ Py_{{op.upper()}});
1487
+ return {{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(
1488
+ res);
1489
+ }
1490
+ {{else}}
1491
+ {{fval}} = PyLong_AsDouble({{pyval}});
1492
+ if (unlikely({{fval}} == -1.0 && PyErr_Occurred())) return NULL;
1493
+ {{if zerodiv_check(fval)}}
1494
+ #if !CYTHON_USE_PYLONG_INTERNALS
1495
+ {{zerodiv_check(fval)}}
1496
+ #endif
1497
+ {{endif}}
1498
+ {{endif}}
1499
+ #if CYTHON_USE_PYLONG_INTERNALS
1500
+ }
1501
+ }
1502
+ #endif
1503
+ } else {
1504
+ {{if op in ('Eq', 'Ne')}}
1505
+ return {{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(
1506
+ PyObject_RichCompare(op1, op2, Py_{{op.upper()}}));
1507
+ {{elif op == 'Divide'}}
1508
+ return (inplace ? __Pyx_PyNumber_InPlaceDivide(op1, op2) : __Pyx_PyNumber_Divide(op1, op2));
1509
+ {{else}}
1510
+ return (inplace ? PyNumber_InPlace{{op}} : PyNumber_{{op}})(op1, op2);
1511
+ {{endif}}
1512
+ }
1513
+
1514
+ {{if op in ('Eq', 'Ne')}}
1515
+ if (a {{c_op}} b) {
1516
+ {{return_true}};
1517
+ } else {
1518
+ {{return_false}};
1519
+ }
1520
+ {{else}}
1521
+ {{if c_op == '%'}}
1522
+ result = fmod(a, b);
1523
+ if (result)
1524
+ result += ((result < 0) ^ (b < 0)) * b;
1525
+ else
1526
+ result = copysign(0.0, b);
1527
+ {{else}}
1528
+ result = a {{c_op}} b;
1529
+ {{endif}}
1530
+ return PyFloat_FromDouble(result);
1531
+ {{endif}}
1532
+ }
1533
+ #endif