Cython 3.2.0__cp39-abi3-win32.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 (333) hide show
  1. Cython/Build/BuildExecutable.py +169 -0
  2. Cython/Build/Cache.py +199 -0
  3. Cython/Build/Cythonize.py +350 -0
  4. Cython/Build/Dependencies.py +1314 -0
  5. Cython/Build/Distutils.py +1 -0
  6. Cython/Build/Inline.py +463 -0
  7. Cython/Build/IpythonMagic.py +560 -0
  8. Cython/Build/SharedModule.py +94 -0
  9. Cython/Build/Tests/TestCyCache.py +194 -0
  10. Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
  11. Cython/Build/Tests/TestDependencies.py +133 -0
  12. Cython/Build/Tests/TestInline.py +177 -0
  13. Cython/Build/Tests/TestIpythonMagic.py +287 -0
  14. Cython/Build/Tests/TestRecythonize.py +212 -0
  15. Cython/Build/Tests/TestStripLiterals.py +155 -0
  16. Cython/Build/Tests/__init__.py +1 -0
  17. Cython/Build/__init__.py +11 -0
  18. Cython/CodeWriter.py +815 -0
  19. Cython/Compiler/AnalysedTreeTransforms.py +97 -0
  20. Cython/Compiler/Annotate.py +328 -0
  21. Cython/Compiler/AutoDocTransforms.py +320 -0
  22. Cython/Compiler/Buffer.py +680 -0
  23. Cython/Compiler/Builtin.py +984 -0
  24. Cython/Compiler/CmdLine.py +263 -0
  25. Cython/Compiler/Code.pxd +149 -0
  26. Cython/Compiler/Code.py +3746 -0
  27. Cython/Compiler/Code.pyd +0 -0
  28. Cython/Compiler/CodeGeneration.py +33 -0
  29. Cython/Compiler/CythonScope.py +191 -0
  30. Cython/Compiler/Dataclass.py +864 -0
  31. Cython/Compiler/DebugFlags.py +24 -0
  32. Cython/Compiler/Errors.py +297 -0
  33. Cython/Compiler/ExprNodes.py +15562 -0
  34. Cython/Compiler/FlowControl.pxd +97 -0
  35. Cython/Compiler/FlowControl.py +1451 -0
  36. Cython/Compiler/FlowControl.pyd +0 -0
  37. Cython/Compiler/FusedNode.py +971 -0
  38. Cython/Compiler/FusedNode.pyd +0 -0
  39. Cython/Compiler/Future.py +16 -0
  40. Cython/Compiler/Interpreter.py +57 -0
  41. Cython/Compiler/Lexicon.py +421 -0
  42. Cython/Compiler/LineTable.py +114 -0
  43. Cython/Compiler/LineTable.pyd +0 -0
  44. Cython/Compiler/Main.py +857 -0
  45. Cython/Compiler/MatchCaseNodes.py +259 -0
  46. Cython/Compiler/MemoryView.py +905 -0
  47. Cython/Compiler/ModuleNode.py +4235 -0
  48. Cython/Compiler/Naming.py +363 -0
  49. Cython/Compiler/Nodes.py +10831 -0
  50. Cython/Compiler/Optimize.py +5288 -0
  51. Cython/Compiler/Options.py +843 -0
  52. Cython/Compiler/ParseTreeTransforms.pxd +78 -0
  53. Cython/Compiler/ParseTreeTransforms.py +4638 -0
  54. Cython/Compiler/Parsing.pxd +9 -0
  55. Cython/Compiler/Parsing.py +4775 -0
  56. Cython/Compiler/Parsing.pyd +0 -0
  57. Cython/Compiler/Pipeline.py +439 -0
  58. Cython/Compiler/PyrexTypes.py +5870 -0
  59. Cython/Compiler/Pythran.py +232 -0
  60. Cython/Compiler/Scanning.pxd +48 -0
  61. Cython/Compiler/Scanning.py +701 -0
  62. Cython/Compiler/Scanning.pyd +0 -0
  63. Cython/Compiler/StringEncoding.py +298 -0
  64. Cython/Compiler/Symtab.py +3073 -0
  65. Cython/Compiler/Tests/TestBuffer.py +105 -0
  66. Cython/Compiler/Tests/TestBuiltin.py +72 -0
  67. Cython/Compiler/Tests/TestCmdLine.py +586 -0
  68. Cython/Compiler/Tests/TestCode.py +144 -0
  69. Cython/Compiler/Tests/TestFlowControl.py +65 -0
  70. Cython/Compiler/Tests/TestGrammar.py +202 -0
  71. Cython/Compiler/Tests/TestMemView.py +71 -0
  72. Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
  73. Cython/Compiler/Tests/TestScanning.py +134 -0
  74. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  75. Cython/Compiler/Tests/TestStringEncoding.py +21 -0
  76. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  77. Cython/Compiler/Tests/TestTreePath.py +103 -0
  78. Cython/Compiler/Tests/TestTypes.py +75 -0
  79. Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
  80. Cython/Compiler/Tests/TestVisitor.py +61 -0
  81. Cython/Compiler/Tests/Utils.py +36 -0
  82. Cython/Compiler/Tests/__init__.py +1 -0
  83. Cython/Compiler/TreeFragment.py +278 -0
  84. Cython/Compiler/TreePath.py +303 -0
  85. Cython/Compiler/TypeInference.py +591 -0
  86. Cython/Compiler/TypeSlots.py +1174 -0
  87. Cython/Compiler/UFuncs.py +311 -0
  88. Cython/Compiler/UtilNodes.py +389 -0
  89. Cython/Compiler/UtilityCode.py +344 -0
  90. Cython/Compiler/Version.py +8 -0
  91. Cython/Compiler/Visitor.pxd +53 -0
  92. Cython/Compiler/Visitor.py +861 -0
  93. Cython/Compiler/Visitor.pyd +0 -0
  94. Cython/Compiler/__init__.py +1 -0
  95. Cython/Coverage.py +448 -0
  96. Cython/Debugger/Cygdb.py +177 -0
  97. Cython/Debugger/DebugWriter.py +82 -0
  98. Cython/Debugger/Tests/TestLibCython.py +275 -0
  99. Cython/Debugger/Tests/__init__.py +1 -0
  100. Cython/Debugger/Tests/cfuncs.c +8 -0
  101. Cython/Debugger/Tests/codefile +49 -0
  102. Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
  103. Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
  104. Cython/Debugger/__init__.py +1 -0
  105. Cython/Debugger/libcython.py +1548 -0
  106. Cython/Debugger/libpython.py +2821 -0
  107. Cython/Debugging.py +20 -0
  108. Cython/Distutils/__init__.py +2 -0
  109. Cython/Distutils/build_ext.py +139 -0
  110. Cython/Distutils/extension.py +96 -0
  111. Cython/Distutils/old_build_ext.py +351 -0
  112. Cython/Includes/cpython/__init__.pxd +173 -0
  113. Cython/Includes/cpython/array.pxd +178 -0
  114. Cython/Includes/cpython/bool.pxd +37 -0
  115. Cython/Includes/cpython/buffer.pxd +112 -0
  116. Cython/Includes/cpython/bytearray.pxd +33 -0
  117. Cython/Includes/cpython/bytes.pxd +200 -0
  118. Cython/Includes/cpython/cellobject.pxd +35 -0
  119. Cython/Includes/cpython/ceval.pxd +8 -0
  120. Cython/Includes/cpython/codecs.pxd +121 -0
  121. Cython/Includes/cpython/complex.pxd +60 -0
  122. Cython/Includes/cpython/contextvars.pxd +145 -0
  123. Cython/Includes/cpython/conversion.pxd +36 -0
  124. Cython/Includes/cpython/datetime.pxd +395 -0
  125. Cython/Includes/cpython/descr.pxd +26 -0
  126. Cython/Includes/cpython/dict.pxd +187 -0
  127. Cython/Includes/cpython/exc.pxd +263 -0
  128. Cython/Includes/cpython/fileobject.pxd +57 -0
  129. Cython/Includes/cpython/float.pxd +47 -0
  130. Cython/Includes/cpython/function.pxd +65 -0
  131. Cython/Includes/cpython/genobject.pxd +25 -0
  132. Cython/Includes/cpython/getargs.pxd +12 -0
  133. Cython/Includes/cpython/instance.pxd +25 -0
  134. Cython/Includes/cpython/iterator.pxd +36 -0
  135. Cython/Includes/cpython/iterobject.pxd +24 -0
  136. Cython/Includes/cpython/list.pxd +92 -0
  137. Cython/Includes/cpython/long.pxd +149 -0
  138. Cython/Includes/cpython/longintrepr.pxd +14 -0
  139. Cython/Includes/cpython/mapping.pxd +63 -0
  140. Cython/Includes/cpython/marshal.pxd +66 -0
  141. Cython/Includes/cpython/mem.pxd +120 -0
  142. Cython/Includes/cpython/memoryview.pxd +50 -0
  143. Cython/Includes/cpython/method.pxd +49 -0
  144. Cython/Includes/cpython/module.pxd +208 -0
  145. Cython/Includes/cpython/number.pxd +258 -0
  146. Cython/Includes/cpython/object.pxd +433 -0
  147. Cython/Includes/cpython/pycapsule.pxd +143 -0
  148. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  149. Cython/Includes/cpython/pyport.pxd +8 -0
  150. Cython/Includes/cpython/pystate.pxd +95 -0
  151. Cython/Includes/cpython/pythread.pxd +53 -0
  152. Cython/Includes/cpython/ref.pxd +141 -0
  153. Cython/Includes/cpython/sequence.pxd +134 -0
  154. Cython/Includes/cpython/set.pxd +119 -0
  155. Cython/Includes/cpython/slice.pxd +70 -0
  156. Cython/Includes/cpython/time.pxd +129 -0
  157. Cython/Includes/cpython/tuple.pxd +72 -0
  158. Cython/Includes/cpython/type.pxd +53 -0
  159. Cython/Includes/cpython/unicode.pxd +639 -0
  160. Cython/Includes/cpython/version.pxd +32 -0
  161. Cython/Includes/cpython/weakref.pxd +78 -0
  162. Cython/Includes/libc/__init__.pxd +1 -0
  163. Cython/Includes/libc/complex.pxd +35 -0
  164. Cython/Includes/libc/errno.pxd +127 -0
  165. Cython/Includes/libc/float.pxd +43 -0
  166. Cython/Includes/libc/limits.pxd +28 -0
  167. Cython/Includes/libc/locale.pxd +46 -0
  168. Cython/Includes/libc/math.pxd +209 -0
  169. Cython/Includes/libc/setjmp.pxd +10 -0
  170. Cython/Includes/libc/signal.pxd +64 -0
  171. Cython/Includes/libc/stddef.pxd +9 -0
  172. Cython/Includes/libc/stdint.pxd +105 -0
  173. Cython/Includes/libc/stdio.pxd +80 -0
  174. Cython/Includes/libc/stdlib.pxd +72 -0
  175. Cython/Includes/libc/string.pxd +50 -0
  176. Cython/Includes/libc/threads.pxd +234 -0
  177. Cython/Includes/libc/time.pxd +52 -0
  178. Cython/Includes/libcpp/__init__.pxd +4 -0
  179. Cython/Includes/libcpp/algorithm.pxd +320 -0
  180. Cython/Includes/libcpp/any.pxd +16 -0
  181. Cython/Includes/libcpp/atomic.pxd +59 -0
  182. Cython/Includes/libcpp/barrier.pxd +22 -0
  183. Cython/Includes/libcpp/bit.pxd +29 -0
  184. Cython/Includes/libcpp/cast.pxd +12 -0
  185. Cython/Includes/libcpp/cmath.pxd +518 -0
  186. Cython/Includes/libcpp/complex.pxd +106 -0
  187. Cython/Includes/libcpp/condition_variable.pxd +322 -0
  188. Cython/Includes/libcpp/deque.pxd +165 -0
  189. Cython/Includes/libcpp/exception.pxd +86 -0
  190. Cython/Includes/libcpp/execution.pxd +15 -0
  191. Cython/Includes/libcpp/forward_list.pxd +63 -0
  192. Cython/Includes/libcpp/functional.pxd +26 -0
  193. Cython/Includes/libcpp/future.pxd +103 -0
  194. Cython/Includes/libcpp/iterator.pxd +34 -0
  195. Cython/Includes/libcpp/latch.pxd +17 -0
  196. Cython/Includes/libcpp/limits.pxd +61 -0
  197. Cython/Includes/libcpp/list.pxd +117 -0
  198. Cython/Includes/libcpp/map.pxd +252 -0
  199. Cython/Includes/libcpp/memory.pxd +115 -0
  200. Cython/Includes/libcpp/mutex.pxd +387 -0
  201. Cython/Includes/libcpp/numbers.pxd +15 -0
  202. Cython/Includes/libcpp/numeric.pxd +131 -0
  203. Cython/Includes/libcpp/optional.pxd +34 -0
  204. Cython/Includes/libcpp/pair.pxd +1 -0
  205. Cython/Includes/libcpp/queue.pxd +25 -0
  206. Cython/Includes/libcpp/random.pxd +166 -0
  207. Cython/Includes/libcpp/semaphore.pxd +43 -0
  208. Cython/Includes/libcpp/set.pxd +228 -0
  209. Cython/Includes/libcpp/shared_mutex.pxd +96 -0
  210. Cython/Includes/libcpp/span.pxd +87 -0
  211. Cython/Includes/libcpp/stack.pxd +11 -0
  212. Cython/Includes/libcpp/stop_token.pxd +117 -0
  213. Cython/Includes/libcpp/string.pxd +355 -0
  214. Cython/Includes/libcpp/string_view.pxd +183 -0
  215. Cython/Includes/libcpp/typeindex.pxd +15 -0
  216. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  217. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  218. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  219. Cython/Includes/libcpp/utility.pxd +30 -0
  220. Cython/Includes/libcpp/vector.pxd +186 -0
  221. Cython/Includes/numpy/math.pxd +150 -0
  222. Cython/Includes/openmp.pxd +50 -0
  223. Cython/Includes/posix/__init__.pxd +1 -0
  224. Cython/Includes/posix/dlfcn.pxd +14 -0
  225. Cython/Includes/posix/fcntl.pxd +86 -0
  226. Cython/Includes/posix/ioctl.pxd +4 -0
  227. Cython/Includes/posix/mman.pxd +101 -0
  228. Cython/Includes/posix/resource.pxd +57 -0
  229. Cython/Includes/posix/select.pxd +21 -0
  230. Cython/Includes/posix/signal.pxd +73 -0
  231. Cython/Includes/posix/stat.pxd +98 -0
  232. Cython/Includes/posix/stdio.pxd +37 -0
  233. Cython/Includes/posix/stdlib.pxd +29 -0
  234. Cython/Includes/posix/strings.pxd +9 -0
  235. Cython/Includes/posix/time.pxd +71 -0
  236. Cython/Includes/posix/types.pxd +30 -0
  237. Cython/Includes/posix/uio.pxd +26 -0
  238. Cython/Includes/posix/unistd.pxd +271 -0
  239. Cython/Includes/posix/wait.pxd +38 -0
  240. Cython/Plex/Actions.pxd +24 -0
  241. Cython/Plex/Actions.py +119 -0
  242. Cython/Plex/Actions.pyd +0 -0
  243. Cython/Plex/DFA.pxd +14 -0
  244. Cython/Plex/DFA.py +164 -0
  245. Cython/Plex/DFA.pyd +0 -0
  246. Cython/Plex/Errors.py +48 -0
  247. Cython/Plex/Lexicons.py +178 -0
  248. Cython/Plex/Machines.pxd +36 -0
  249. Cython/Plex/Machines.py +238 -0
  250. Cython/Plex/Machines.pyd +0 -0
  251. Cython/Plex/Regexps.py +535 -0
  252. Cython/Plex/Scanners.pxd +45 -0
  253. Cython/Plex/Scanners.py +328 -0
  254. Cython/Plex/Scanners.pyd +0 -0
  255. Cython/Plex/Transitions.pxd +14 -0
  256. Cython/Plex/Transitions.py +239 -0
  257. Cython/Plex/Transitions.pyd +0 -0
  258. Cython/Plex/__init__.py +34 -0
  259. Cython/Runtime/__init__.py +1 -0
  260. Cython/Runtime/refnanny.pyd +0 -0
  261. Cython/Runtime/refnanny.pyx +237 -0
  262. Cython/Shadow.py +690 -0
  263. Cython/Shadow.pyi +521 -0
  264. Cython/StringIOTree.py +170 -0
  265. Cython/StringIOTree.pyd +0 -0
  266. Cython/Tempita/__init__.py +4 -0
  267. Cython/Tempita/_looper.py +154 -0
  268. Cython/Tempita/_tempita.py +1091 -0
  269. Cython/Tempita/_tempita.pyd +0 -0
  270. Cython/TestUtils.py +422 -0
  271. Cython/Tests/TestCodeWriter.py +128 -0
  272. Cython/Tests/TestCythonUtils.py +202 -0
  273. Cython/Tests/TestJediTyper.py +223 -0
  274. Cython/Tests/TestShadow.py +114 -0
  275. Cython/Tests/TestStringIOTree.py +67 -0
  276. Cython/Tests/TestTestUtils.py +90 -0
  277. Cython/Tests/__init__.py +1 -0
  278. Cython/Tests/xmlrunner.py +390 -0
  279. Cython/Utility/AsyncGen.c +1031 -0
  280. Cython/Utility/Buffer.c +865 -0
  281. Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
  282. Cython/Utility/Builtins.c +810 -0
  283. Cython/Utility/CConvert.pyx +134 -0
  284. Cython/Utility/CMath.c +104 -0
  285. Cython/Utility/CommonStructures.c +226 -0
  286. Cython/Utility/Complex.c +378 -0
  287. Cython/Utility/Coroutine.c +2300 -0
  288. Cython/Utility/CpdefEnums.pyx +103 -0
  289. Cython/Utility/CppConvert.pyx +282 -0
  290. Cython/Utility/CppSupport.cpp +151 -0
  291. Cython/Utility/CythonFunction.c +1832 -0
  292. Cython/Utility/Dataclasses.c +101 -0
  293. Cython/Utility/Embed.c +121 -0
  294. Cython/Utility/Exceptions.c +1016 -0
  295. Cython/Utility/ExtensionTypes.c +996 -0
  296. Cython/Utility/FunctionArguments.c +1043 -0
  297. Cython/Utility/FusedFunction.pyx +44 -0
  298. Cython/Utility/ImportExport.c +907 -0
  299. Cython/Utility/MemoryView.pxd +188 -0
  300. Cython/Utility/MemoryView.pyx +1482 -0
  301. Cython/Utility/MemoryView_C.c +927 -0
  302. Cython/Utility/ModuleSetupCode.c +3203 -0
  303. Cython/Utility/NumpyImportArray.c +46 -0
  304. Cython/Utility/ObjectHandling.c +3273 -0
  305. Cython/Utility/Optimize.c +1603 -0
  306. Cython/Utility/Overflow.c +384 -0
  307. Cython/Utility/Printing.c +86 -0
  308. Cython/Utility/Profile.c +732 -0
  309. Cython/Utility/StringTools.c +1379 -0
  310. Cython/Utility/Synchronization.c +399 -0
  311. Cython/Utility/TString.c +356 -0
  312. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  313. Cython/Utility/TestCythonScope.pyx +75 -0
  314. Cython/Utility/TestUtilityLoader.c +12 -0
  315. Cython/Utility/TypeConversion.c +1385 -0
  316. Cython/Utility/UFuncs.pyx +50 -0
  317. Cython/Utility/UFuncs_C.c +89 -0
  318. Cython/Utility/__init__.py +28 -0
  319. Cython/Utility/arrayarray.h +167 -0
  320. Cython/Utils.py +687 -0
  321. Cython/Utils.pyd +0 -0
  322. Cython/__init__.py +10 -0
  323. Cython/__init__.pyi +7 -0
  324. Cython/py.typed +0 -0
  325. cython-3.2.0.dist-info/METADATA +85 -0
  326. cython-3.2.0.dist-info/RECORD +333 -0
  327. cython-3.2.0.dist-info/WHEEL +5 -0
  328. cython-3.2.0.dist-info/entry_points.txt +4 -0
  329. cython-3.2.0.dist-info/top_level.txt +3 -0
  330. cython.py +29 -0
  331. pyximport/__init__.py +4 -0
  332. pyximport/pyxbuild.py +160 -0
  333. pyximport/pyximport.py +482 -0
@@ -0,0 +1,927 @@
1
+ ////////// MemviewSliceStruct.proto //////////
2
+ //@proto_block: utility_code_proto_before_types
3
+ //@substitute: naming
4
+ //@requires: Synchronization.c::Atomics
5
+
6
+ /* memoryview slice struct */
7
+ struct $memview_objstruct_cname;
8
+
9
+ typedef struct {
10
+ struct $memview_objstruct_cname *memview;
11
+ char *data;
12
+ Py_ssize_t shape[{{max_dims}}];
13
+ Py_ssize_t strides[{{max_dims}}];
14
+ Py_ssize_t suboffsets[{{max_dims}}];
15
+ } $memviewslice_cname;
16
+
17
+ // used for "len(memviewslice)"
18
+ #define __Pyx_MemoryView_Len(m) (m.shape[0])
19
+
20
+ // Metadata flags for slice creation and validation.
21
+ #define __Pyx_MEMVIEW_DIRECT 1
22
+ #define __Pyx_MEMVIEW_PTR 2
23
+ #define __Pyx_MEMVIEW_FULL 4
24
+ #define __Pyx_MEMVIEW_CONTIG 8
25
+ #define __Pyx_MEMVIEW_STRIDED 16
26
+ #define __Pyx_MEMVIEW_FOLLOW 32
27
+
28
+ #define __Pyx_IS_C_CONTIG 1
29
+ #define __Pyx_IS_F_CONTIG 2
30
+
31
+ #if CYTHON_ATOMICS
32
+ #define __pyx_add_acquisition_count(memview) \
33
+ __pyx_atomic_incr_relaxed(__pyx_get_slice_count_pointer(memview))
34
+ #define __pyx_sub_acquisition_count(memview) \
35
+ __pyx_atomic_decr_acq_rel(__pyx_get_slice_count_pointer(memview))
36
+ #else
37
+ #define __pyx_add_acquisition_count(memview) \
38
+ __pyx_add_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
39
+ #define __pyx_sub_acquisition_count(memview) \
40
+ __pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
41
+ #endif
42
+
43
+ /////////////// ObjectToMemviewSlice.proto ///////////////
44
+ //@substitute: naming
45
+
46
+ static CYTHON_INLINE $memviewslice_cname {{funcname}}(PyObject *, int writable_flag);
47
+
48
+
49
+ /////////////// ObjectToMemviewSlice ///////////////
50
+ //@requires: Buffer.c::BufferFormatStructs
51
+ //@requires: MemviewSliceValidateAndInit
52
+ //@substitute: naming
53
+
54
+ static CYTHON_INLINE $memviewslice_cname {{funcname}}(PyObject *obj, int writable_flag) {
55
+ $memviewslice_cname result = {{memslice_init}};
56
+ __Pyx_BufFmt_StackElem stack[{{struct_nesting_depth}}];
57
+ int axes_specs[] = { {{axes_specs}} };
58
+ int retcode;
59
+
60
+ if (obj == Py_None) {
61
+ /* We don't bother to refcount None */
62
+ result.memview = (struct $memview_objstruct_cname *) Py_None;
63
+ return result;
64
+ }
65
+
66
+ retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, {{c_or_f_flag}},
67
+ {{buf_flag}} | writable_flag, {{ndim}},
68
+ &{{dtype_typeinfo}}, stack,
69
+ &result, obj);
70
+
71
+ if (unlikely(retcode == -1))
72
+ goto __pyx_fail;
73
+
74
+ return result;
75
+ __pyx_fail:
76
+ result.memview = NULL;
77
+ result.data = NULL;
78
+ return result;
79
+ }
80
+
81
+
82
+ /////////////// MemviewSliceValidateAndInit.export ///////////////
83
+ //@requires: Buffer.c::BufferFormatStructs
84
+ //@substitute: naming
85
+
86
+ static int __Pyx_ValidateAndInit_memviewslice(
87
+ int *axes_specs,
88
+ int c_or_f_flag,
89
+ int buf_flags,
90
+ int ndim,
91
+ const __Pyx_TypeInfo *dtype,
92
+ __Pyx_BufFmt_StackElem stack[],
93
+ $memviewslice_cname *memviewslice,
94
+ PyObject *original_obj);
95
+
96
+
97
+ /////////////// MemviewSliceValidateAndInit ///////////////
98
+ //@requires: Buffer.c::TypeInfoCompare
99
+ //@requires: Buffer.c::BufferFormatStructs
100
+ //@requires: Buffer.c::BufferFormatCheck
101
+ //@requires: MemviewSliceInit
102
+ //@substitute: naming
103
+
104
+ static int
105
+ __pyx_check_strides(Py_buffer *buf, int dim, int ndim, int spec)
106
+ {
107
+ if (buf->shape[dim] <= 1)
108
+ return 1;
109
+
110
+ if (buf->strides) {
111
+ if (spec & __Pyx_MEMVIEW_CONTIG) {
112
+ if (spec & (__Pyx_MEMVIEW_PTR|__Pyx_MEMVIEW_FULL)) {
113
+ if (unlikely(buf->strides[dim] != sizeof(void *))) {
114
+ PyErr_Format(PyExc_ValueError,
115
+ "Buffer is not indirectly contiguous "
116
+ "in dimension %d.", dim);
117
+ goto fail;
118
+ }
119
+ } else if (unlikely(buf->strides[dim] != buf->itemsize)) {
120
+ PyErr_SetString(PyExc_ValueError,
121
+ "Buffer and memoryview are not contiguous "
122
+ "in the same dimension.");
123
+ goto fail;
124
+ }
125
+ }
126
+
127
+ if (spec & __Pyx_MEMVIEW_FOLLOW) {
128
+ Py_ssize_t stride = buf->strides[dim];
129
+ if (stride < 0)
130
+ stride = -stride;
131
+ if (unlikely(stride < buf->itemsize)) {
132
+ PyErr_SetString(PyExc_ValueError,
133
+ "Buffer and memoryview are not contiguous "
134
+ "in the same dimension.");
135
+ goto fail;
136
+ }
137
+ }
138
+ } else {
139
+ if (unlikely(spec & __Pyx_MEMVIEW_CONTIG && dim != ndim - 1)) {
140
+ PyErr_Format(PyExc_ValueError,
141
+ "C-contiguous buffer is not contiguous in "
142
+ "dimension %d", dim);
143
+ goto fail;
144
+ } else if (unlikely(spec & (__Pyx_MEMVIEW_PTR))) {
145
+ PyErr_Format(PyExc_ValueError,
146
+ "C-contiguous buffer is not indirect in "
147
+ "dimension %d", dim);
148
+ goto fail;
149
+ } else if (unlikely(buf->suboffsets)) {
150
+ PyErr_SetString(PyExc_ValueError,
151
+ "Buffer exposes suboffsets but no strides");
152
+ goto fail;
153
+ }
154
+ }
155
+
156
+ return 1;
157
+ fail:
158
+ return 0;
159
+ }
160
+
161
+ static int
162
+ __pyx_check_suboffsets(Py_buffer *buf, int dim, int ndim, int spec)
163
+ {
164
+ CYTHON_UNUSED_VAR(ndim);
165
+ // Todo: without PyBUF_INDIRECT we may not have suboffset information, i.e., the
166
+ // ptr may not be set to NULL but may be uninitialized?
167
+ if (spec & __Pyx_MEMVIEW_DIRECT) {
168
+ if (unlikely(buf->suboffsets && buf->suboffsets[dim] >= 0)) {
169
+ PyErr_Format(PyExc_ValueError,
170
+ "Buffer not compatible with direct access "
171
+ "in dimension %d.", dim);
172
+ goto fail;
173
+ }
174
+ }
175
+
176
+ if (spec & __Pyx_MEMVIEW_PTR) {
177
+ if (unlikely(!buf->suboffsets || (buf->suboffsets[dim] < 0))) {
178
+ PyErr_Format(PyExc_ValueError,
179
+ "Buffer is not indirectly accessible "
180
+ "in dimension %d.", dim);
181
+ goto fail;
182
+ }
183
+ }
184
+
185
+ return 1;
186
+ fail:
187
+ return 0;
188
+ }
189
+
190
+ static int
191
+ __pyx_verify_contig(Py_buffer *buf, int ndim, int c_or_f_flag)
192
+ {
193
+ int i;
194
+
195
+ if (c_or_f_flag & __Pyx_IS_F_CONTIG) {
196
+ Py_ssize_t stride = 1;
197
+ for (i = 0; i < ndim; i++) {
198
+ if (unlikely(stride * buf->itemsize != buf->strides[i] && buf->shape[i] > 1)) {
199
+ PyErr_SetString(PyExc_ValueError,
200
+ "Buffer not fortran contiguous.");
201
+ goto fail;
202
+ }
203
+ stride = stride * buf->shape[i];
204
+ }
205
+ } else if (c_or_f_flag & __Pyx_IS_C_CONTIG) {
206
+ Py_ssize_t stride = 1;
207
+ for (i = ndim - 1; i >- 1; i--) {
208
+ if (unlikely(stride * buf->itemsize != buf->strides[i] && buf->shape[i] > 1)) {
209
+ PyErr_SetString(PyExc_ValueError,
210
+ "Buffer not C contiguous.");
211
+ goto fail;
212
+ }
213
+ stride = stride * buf->shape[i];
214
+ }
215
+ }
216
+
217
+ return 1;
218
+ fail:
219
+ return 0;
220
+ }
221
+
222
+ static int __Pyx_ValidateAndInit_memviewslice(
223
+ int *axes_specs,
224
+ int c_or_f_flag,
225
+ int buf_flags,
226
+ int ndim,
227
+ const __Pyx_TypeInfo *dtype,
228
+ __Pyx_BufFmt_StackElem stack[],
229
+ $memviewslice_cname *memviewslice,
230
+ PyObject *original_obj)
231
+ {
232
+ struct $memview_objstruct_cname *memview, *new_memview;
233
+ __Pyx_RefNannyDeclarations
234
+ Py_buffer *buf;
235
+ int i, spec = 0, retval = -1;
236
+ __Pyx_BufFmt_Context ctx;
237
+ int from_memoryview = __pyx_memoryview_check(original_obj);
238
+
239
+ __Pyx_RefNannySetupContext("ValidateAndInit_memviewslice", 0);
240
+
241
+ if (from_memoryview && __pyx_typeinfo_cmp(dtype, ((struct $memview_objstruct_cname *)
242
+ original_obj)->typeinfo)) {
243
+ /* We have a matching dtype, skip format parsing */
244
+ memview = (struct $memview_objstruct_cname *) original_obj;
245
+ new_memview = NULL;
246
+ } else {
247
+ memview = (struct $memview_objstruct_cname *) __pyx_memoryview_new(
248
+ original_obj, buf_flags, 0, dtype);
249
+ new_memview = memview;
250
+ if (unlikely(!memview))
251
+ goto fail;
252
+ }
253
+
254
+ buf = &memview->view;
255
+ if (unlikely(buf->ndim != ndim)) {
256
+ PyErr_Format(PyExc_ValueError,
257
+ "Buffer has wrong number of dimensions (expected %d, got %d)",
258
+ ndim, buf->ndim);
259
+ goto fail;
260
+ }
261
+
262
+ if (new_memview) {
263
+ __Pyx_BufFmt_Init(&ctx, stack, dtype);
264
+ if (unlikely(!__Pyx_BufFmt_CheckString(&ctx, buf->format))) goto fail;
265
+ }
266
+
267
+ if (unlikely((unsigned) buf->itemsize != dtype->size)) {
268
+ PyErr_Format(PyExc_ValueError,
269
+ "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "u byte%s) "
270
+ "does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "u byte%s)",
271
+ buf->itemsize,
272
+ (buf->itemsize > 1) ? "s" : "",
273
+ dtype->name,
274
+ dtype->size,
275
+ (dtype->size > 1) ? "s" : "");
276
+ goto fail;
277
+ }
278
+
279
+ /* Check axes */
280
+ if (buf->len > 0) {
281
+ // 0-sized arrays do not undergo these checks since their strides are
282
+ // irrelevant and they are always both C- and F-contiguous.
283
+ for (i = 0; i < ndim; i++) {
284
+ spec = axes_specs[i];
285
+ if (unlikely(!__pyx_check_strides(buf, i, ndim, spec)))
286
+ goto fail;
287
+ if (unlikely(!__pyx_check_suboffsets(buf, i, ndim, spec)))
288
+ goto fail;
289
+ }
290
+
291
+ /* Check contiguity */
292
+ if (unlikely(buf->strides && !__pyx_verify_contig(buf, ndim, c_or_f_flag)))
293
+ goto fail;
294
+ }
295
+
296
+ /* Initialize */
297
+ if (unlikely(__Pyx_init_memviewslice(memview, ndim, memviewslice,
298
+ new_memview != NULL) == -1)) {
299
+ goto fail;
300
+ }
301
+
302
+ retval = 0;
303
+ goto no_fail;
304
+
305
+ fail:
306
+ Py_XDECREF((PyObject*)new_memview);
307
+ retval = -1;
308
+
309
+ no_fail:
310
+ __Pyx_RefNannyFinishContext();
311
+ return retval;
312
+ }
313
+
314
+
315
+ ////////// MemviewSliceInit.proto //////////
316
+ //@substitute: naming
317
+
318
+ static int __Pyx_init_memviewslice(
319
+ struct $memview_objstruct_cname *memview,
320
+ int ndim,
321
+ $memviewslice_cname *memviewslice,
322
+ int memview_is_new_reference);
323
+
324
+
325
+ ////////// MemviewSliceInit //////////
326
+ //@substitute: naming
327
+
328
+ static int
329
+ __Pyx_init_memviewslice(struct $memview_objstruct_cname *memview,
330
+ int ndim,
331
+ $memviewslice_cname *memviewslice,
332
+ int memview_is_new_reference)
333
+ {
334
+ __Pyx_RefNannyDeclarations
335
+ int i, retval=-1;
336
+ Py_buffer *buf = &memview->view;
337
+ __Pyx_RefNannySetupContext("init_memviewslice", 0);
338
+
339
+ if (unlikely(memviewslice->memview || memviewslice->data)) {
340
+ PyErr_SetString(PyExc_ValueError,
341
+ "memviewslice is already initialized!");
342
+ goto fail;
343
+ }
344
+
345
+ if (buf->strides) {
346
+ for (i = 0; i < ndim; i++) {
347
+ memviewslice->strides[i] = buf->strides[i];
348
+ }
349
+ } else {
350
+ Py_ssize_t stride = buf->itemsize;
351
+ for (i = ndim - 1; i >= 0; i--) {
352
+ memviewslice->strides[i] = stride;
353
+ stride *= buf->shape[i];
354
+ }
355
+ }
356
+
357
+ for (i = 0; i < ndim; i++) {
358
+ memviewslice->shape[i] = buf->shape[i];
359
+ if (buf->suboffsets) {
360
+ memviewslice->suboffsets[i] = buf->suboffsets[i];
361
+ } else {
362
+ memviewslice->suboffsets[i] = -1;
363
+ }
364
+ }
365
+
366
+ memviewslice->memview = memview;
367
+ memviewslice->data = (char *)buf->buf;
368
+ if (__pyx_add_acquisition_count(memview) == 0 && !memview_is_new_reference) {
369
+ Py_INCREF((PyObject*)memview);
370
+ }
371
+ retval = 0;
372
+ goto no_fail;
373
+
374
+ fail:
375
+ /* Don't decref, the memoryview may be borrowed. Let the caller do the cleanup */
376
+ /* __Pyx_XDECREF(memviewslice->memview); */
377
+ memviewslice->memview = 0;
378
+ memviewslice->data = 0;
379
+ retval = -1;
380
+ no_fail:
381
+ __Pyx_RefNannyFinishContext();
382
+ return retval;
383
+ }
384
+
385
+
386
+ ////////// MemviewRefcount.proto //////////
387
+ //@substitute: naming
388
+
389
+ static CYTHON_INLINE int __pyx_add_acquisition_count_locked(
390
+ __pyx_atomic_int_type *acquisition_count, PyThread_type_lock lock);
391
+ static CYTHON_INLINE int __pyx_sub_acquisition_count_locked(
392
+ __pyx_atomic_int_type *acquisition_count, PyThread_type_lock lock);
393
+
394
+ #define __pyx_get_slice_count_pointer(memview) (&memview->acquisition_count)
395
+ #define __PYX_INC_MEMVIEW(slice, have_gil) __Pyx_INC_MEMVIEW(slice, have_gil, __LINE__)
396
+ #define __PYX_XCLEAR_MEMVIEW(slice, have_gil) __Pyx_XCLEAR_MEMVIEW(slice, have_gil, __LINE__)
397
+ static CYTHON_INLINE void __Pyx_INC_MEMVIEW($memviewslice_cname *, int, int);
398
+ static CYTHON_INLINE void __Pyx_XCLEAR_MEMVIEW($memviewslice_cname *, int, int);
399
+
400
+
401
+ ////////// MemviewRefcount //////////
402
+ //@substitute: naming
403
+
404
+ // vsnprintf
405
+ #include <stdio.h>
406
+
407
+ #ifndef _Py_NO_RETURN
408
+ // It's non-public and just a hint, so allow it to be missing.
409
+ #define _Py_NO_RETURN
410
+ #endif
411
+
412
+ _Py_NO_RETURN
413
+ static void __pyx_fatalerror(const char *fmt, ...) {
414
+ va_list vargs;
415
+ char msg[200];
416
+
417
+ #if PY_VERSION_HEX >= 0x030A0000 || defined(HAVE_STDARG_PROTOTYPES)
418
+ va_start(vargs, fmt);
419
+ #else
420
+ va_start(vargs);
421
+ #endif
422
+ vsnprintf(msg, 200, fmt, vargs);
423
+ va_end(vargs);
424
+
425
+ Py_FatalError(msg);
426
+ }
427
+
428
+ static CYTHON_INLINE int
429
+ __pyx_add_acquisition_count_locked(__pyx_atomic_int_type *acquisition_count,
430
+ PyThread_type_lock lock)
431
+ {
432
+ int result;
433
+ PyThread_acquire_lock(lock, 1);
434
+ result = (*acquisition_count)++;
435
+ PyThread_release_lock(lock);
436
+ return result;
437
+ }
438
+
439
+ static CYTHON_INLINE int
440
+ __pyx_sub_acquisition_count_locked(__pyx_atomic_int_type *acquisition_count,
441
+ PyThread_type_lock lock)
442
+ {
443
+ int result;
444
+ PyThread_acquire_lock(lock, 1);
445
+ result = (*acquisition_count)--;
446
+ PyThread_release_lock(lock);
447
+ return result;
448
+ }
449
+
450
+
451
+ static CYTHON_INLINE void
452
+ __Pyx_INC_MEMVIEW($memviewslice_cname *memslice, int have_gil, int lineno)
453
+ {
454
+ __pyx_nonatomic_int_type old_acquisition_count;
455
+ struct $memview_objstruct_cname *memview = memslice->memview;
456
+ if (unlikely(!memview || (PyObject *) memview == Py_None)) {
457
+ // Allow uninitialized memoryview assignment and do not ref-count None.
458
+ return;
459
+ }
460
+
461
+ old_acquisition_count = __pyx_add_acquisition_count(memview);
462
+ if (unlikely(old_acquisition_count <= 0)) {
463
+ if (likely(old_acquisition_count == 0)) {
464
+ // First acquisition => keep the memoryview object alive.
465
+ if (have_gil) {
466
+ Py_INCREF((PyObject *) memview);
467
+ } else {
468
+ PyGILState_STATE _gilstate = PyGILState_Ensure();
469
+ Py_INCREF((PyObject *) memview);
470
+ PyGILState_Release(_gilstate);
471
+ }
472
+ } else {
473
+ __pyx_fatalerror("Acquisition count is %d (line %d)",
474
+ old_acquisition_count+1, lineno);
475
+ }
476
+ }
477
+ }
478
+
479
+ static CYTHON_INLINE void __Pyx_XCLEAR_MEMVIEW($memviewslice_cname *memslice,
480
+ int have_gil, int lineno) {
481
+ __pyx_nonatomic_int_type old_acquisition_count;
482
+ struct $memview_objstruct_cname *memview = memslice->memview;
483
+
484
+ if (unlikely(!memview || (PyObject *) memview == Py_None)) {
485
+ // Do not ref-count None.
486
+ memslice->memview = NULL;
487
+ return;
488
+ }
489
+
490
+ old_acquisition_count = __pyx_sub_acquisition_count(memview);
491
+ memslice->data = NULL;
492
+ if (likely(old_acquisition_count > 1)) {
493
+ // Still other slices out there => we do not own the reference.
494
+ memslice->memview = NULL;
495
+ } else if (likely(old_acquisition_count == 1)) {
496
+ // Last slice => discard owned Python reference to memoryview object.
497
+ if (have_gil) {
498
+ Py_CLEAR(memslice->memview);
499
+ } else {
500
+ PyGILState_STATE _gilstate = PyGILState_Ensure();
501
+ Py_CLEAR(memslice->memview);
502
+ PyGILState_Release(_gilstate);
503
+ }
504
+ } else {
505
+ __pyx_fatalerror("Acquisition count is %d (line %d)",
506
+ old_acquisition_count-1, lineno);
507
+ }
508
+ }
509
+
510
+
511
+ ////////// MemviewSliceCopyTemplate.proto //////////
512
+ //@substitute: naming
513
+
514
+ static $memviewslice_cname
515
+ __pyx_memoryview_copy_new_contig(const $memviewslice_cname *from_mvs,
516
+ const char *mode, int ndim,
517
+ size_t sizeof_dtype, int contig_flag,
518
+ int dtype_is_object);
519
+
520
+
521
+ ////////// MemviewSliceCopyTemplate //////////
522
+ //@requires: MemviewSliceInit
523
+ //@substitute: naming
524
+
525
+ static $memviewslice_cname
526
+ __pyx_memoryview_copy_new_contig(const $memviewslice_cname *from_mvs,
527
+ const char *mode, int ndim,
528
+ size_t sizeof_dtype, int contig_flag,
529
+ int dtype_is_object)
530
+ {
531
+ __Pyx_RefNannyDeclarations
532
+ int i;
533
+ $memviewslice_cname new_mvs = {{memslice_init}};
534
+ struct $memview_objstruct_cname *from_memview = from_mvs->memview;
535
+ Py_buffer *buf = &from_memview->view;
536
+ PyObject *shape_tuple = NULL;
537
+ PyObject *temp_int = NULL;
538
+ struct __pyx_array_obj *array_obj = NULL;
539
+ struct $memview_objstruct_cname *memview_obj = NULL;
540
+
541
+ __Pyx_RefNannySetupContext("__pyx_memoryview_copy_new_contig", 0);
542
+
543
+ for (i = 0; i < ndim; i++) {
544
+ if (unlikely(from_mvs->suboffsets[i] >= 0)) {
545
+ PyErr_Format(PyExc_ValueError, "Cannot copy memoryview slice with "
546
+ "indirect dimensions (axis %d)", i);
547
+ goto fail;
548
+ }
549
+ }
550
+
551
+ shape_tuple = PyTuple_New(ndim);
552
+ if (unlikely(!shape_tuple)) {
553
+ goto fail;
554
+ }
555
+ __Pyx_GOTREF(shape_tuple);
556
+
557
+
558
+ for(i = 0; i < ndim; i++) {
559
+ temp_int = PyLong_FromSsize_t(from_mvs->shape[i]);
560
+ if(unlikely(!temp_int)) {
561
+ goto fail;
562
+ } else {
563
+ #if CYTHON_ASSUME_SAFE_MACROS
564
+ PyTuple_SET_ITEM(shape_tuple, i, temp_int);
565
+ #else
566
+ if (PyTuple_SetItem(shape_tuple, i, temp_int) < 0) {
567
+ goto fail;
568
+ }
569
+ #endif
570
+ temp_int = NULL;
571
+ }
572
+ }
573
+
574
+ array_obj = __pyx_array_new(shape_tuple, sizeof_dtype, buf->format, mode, NULL);
575
+ if (unlikely(!array_obj)) {
576
+ goto fail;
577
+ }
578
+ __Pyx_GOTREF(array_obj);
579
+
580
+ memview_obj = (struct $memview_objstruct_cname *) __pyx_memoryview_new(
581
+ (PyObject *) array_obj, contig_flag,
582
+ dtype_is_object,
583
+ from_mvs->memview->typeinfo);
584
+ if (unlikely(!memview_obj))
585
+ goto fail;
586
+
587
+ /* initialize new_mvs */
588
+ if (unlikely(__Pyx_init_memviewslice(memview_obj, ndim, &new_mvs, 1) < 0))
589
+ goto fail;
590
+
591
+ if (unlikely(__pyx_memoryview_copy_contents(*from_mvs, new_mvs, ndim, ndim,
592
+ dtype_is_object) < 0))
593
+ goto fail;
594
+
595
+ goto no_fail;
596
+
597
+ fail:
598
+ __Pyx_XDECREF((PyObject *) new_mvs.memview);
599
+ new_mvs.memview = NULL;
600
+ new_mvs.data = NULL;
601
+ no_fail:
602
+ __Pyx_XDECREF(shape_tuple);
603
+ __Pyx_XDECREF(temp_int);
604
+ __Pyx_XDECREF((PyObject *) array_obj);
605
+ __Pyx_RefNannyFinishContext();
606
+ return new_mvs;
607
+ }
608
+
609
+
610
+ ////////// CopyContentsUtility.proto /////////
611
+
612
+ #define {{func_cname}}(slice) \
613
+ __pyx_memoryview_copy_new_contig(&slice, "{{mode}}", {{ndim}}, \
614
+ sizeof({{dtype_decl}}), {{contig_flag}}, \
615
+ {{dtype_is_object}})
616
+
617
+
618
+ ////////// OverlappingSlices.proto //////////
619
+ //@substitute: naming
620
+
621
+ static int __pyx_slices_overlap($memviewslice_cname *slice1,
622
+ $memviewslice_cname *slice2,
623
+ int ndim, size_t itemsize);
624
+
625
+
626
+ ////////// OverlappingSlices //////////
627
+ //@substitute: naming
628
+
629
+ /* Based on numpy's core/src/multiarray/array_assign.c */
630
+
631
+ /* Gets a half-open range [start, end) which contains the array data */
632
+ static void
633
+ __pyx_get_array_memory_extents($memviewslice_cname *slice,
634
+ void **out_start, void **out_end,
635
+ int ndim, size_t itemsize)
636
+ {
637
+ char *start, *end;
638
+ int i;
639
+
640
+ start = end = slice->data;
641
+
642
+ for (i = 0; i < ndim; i++) {
643
+ Py_ssize_t stride = slice->strides[i];
644
+ Py_ssize_t extent = slice->shape[i];
645
+
646
+ if (extent == 0) {
647
+ *out_start = *out_end = start;
648
+ return;
649
+ } else {
650
+ if (stride > 0)
651
+ end += stride * (extent - 1);
652
+ else
653
+ start += stride * (extent - 1);
654
+ }
655
+ }
656
+
657
+ /* Return a half-open range */
658
+ *out_start = start;
659
+ *out_end = end + itemsize;
660
+ }
661
+
662
+ /* Returns 1 if the arrays have overlapping data, 0 otherwise */
663
+ static int
664
+ __pyx_slices_overlap($memviewslice_cname *slice1,
665
+ $memviewslice_cname *slice2,
666
+ int ndim, size_t itemsize)
667
+ {
668
+ void *start1, *end1, *start2, *end2;
669
+
670
+ __pyx_get_array_memory_extents(slice1, &start1, &end1, ndim, itemsize);
671
+ __pyx_get_array_memory_extents(slice2, &start2, &end2, ndim, itemsize);
672
+
673
+ return (start1 < end2) && (start2 < end1);
674
+ }
675
+
676
+
677
+ ////////// MemviewSliceCheckContig.proto //////////
678
+
679
+ #define __pyx_memviewslice_is_contig_{{contig_type}}{{ndim}}(slice) \
680
+ __pyx_memviewslice_is_contig(slice, '{{contig_type}}', {{ndim}})
681
+
682
+
683
+ ////////// MemviewSliceIsContig.proto //////////
684
+ //@substitute: naming
685
+
686
+ static int __pyx_memviewslice_is_contig(const $memviewslice_cname mvs, char order, int ndim);/*proto*/
687
+
688
+
689
+ ////////// MemviewSliceIsContig //////////
690
+ //@substitute: naming
691
+
692
+ static int
693
+ __pyx_memviewslice_is_contig(const $memviewslice_cname mvs, char order, int ndim)
694
+ {
695
+ int i, index, step, start;
696
+ Py_ssize_t itemsize = mvs.memview->view.itemsize;
697
+
698
+ if (order == 'F') {
699
+ step = 1;
700
+ start = 0;
701
+ } else {
702
+ step = -1;
703
+ start = ndim - 1;
704
+ }
705
+
706
+ for (i = 0; i < ndim; i++) {
707
+ index = start + step * i;
708
+ if (mvs.suboffsets[index] >= 0 || mvs.strides[index] != itemsize)
709
+ return 0;
710
+
711
+ itemsize *= mvs.shape[index];
712
+ }
713
+
714
+ return 1;
715
+ }
716
+
717
+
718
+ /////////////// MemviewSliceIndex.proto ///////////////
719
+
720
+ static CYTHON_INLINE char *
721
+ __pyx_memviewslice_index_full(const char *bufp, Py_ssize_t idx, Py_ssize_t stride, Py_ssize_t suboffset); /*proto*/
722
+
723
+
724
+ /////////////// MemviewSliceIndex ///////////////
725
+
726
+ static CYTHON_INLINE char *
727
+ __pyx_memviewslice_index_full(const char *bufp, Py_ssize_t idx,
728
+ Py_ssize_t stride, Py_ssize_t suboffset)
729
+ {
730
+ bufp = bufp + idx * stride;
731
+ if (suboffset >= 0) {
732
+ bufp = *((char **) bufp) + suboffset;
733
+ }
734
+ return (char *) bufp;
735
+ }
736
+
737
+
738
+ /////////////// MemviewDtypeToObject.proto ///////////////
739
+
740
+ {{if to_py_function}}
741
+ static CYTHON_INLINE PyObject *{{get_function}}(const char *itemp); /* proto */
742
+ {{endif}}
743
+
744
+ {{if from_py_function}}
745
+ static CYTHON_INLINE int {{set_function}}(char *itemp, PyObject *obj); /* proto */
746
+ {{endif}}
747
+
748
+ /////////////// MemviewDtypeToObject ///////////////
749
+
750
+ {{#__pyx_memview_<dtype_name>_to_object}}
751
+
752
+ /* Convert a dtype to or from a Python object */
753
+
754
+ {{if to_py_function}}
755
+ static CYTHON_INLINE PyObject *{{get_function}}(const char *itemp) {
756
+ return (PyObject *) {{to_py_function}}(*({{dtype}} {{'' if dtype_is_const else 'const'}} *) itemp);
757
+ }
758
+ {{endif}}
759
+
760
+ {{if from_py_function}}
761
+ static CYTHON_INLINE int {{set_function}}(char *itemp, PyObject *obj) {
762
+ {{dtype}} value = {{from_py_function}}(obj);
763
+ if (unlikely({{error_condition}}))
764
+ return 0;
765
+ *({{dtype}} *) itemp = value;
766
+ return 1;
767
+ }
768
+ {{endif}}
769
+
770
+
771
+ /////////////// MemviewObjectToObject.proto ///////////////
772
+
773
+ /* Function callbacks (for memoryview object) for dtype object */
774
+ static PyObject *{{get_function}}(const char *itemp); /* proto */
775
+ static int {{set_function}}(const char *itemp, PyObject *obj); /* proto */
776
+
777
+
778
+ /////////////// MemviewObjectToObject ///////////////
779
+
780
+ static PyObject *{{get_function}}(const char *itemp) {
781
+ PyObject *result = *(PyObject **) itemp;
782
+ Py_INCREF(result);
783
+ return result;
784
+ }
785
+
786
+ static int {{set_function}}(const char *itemp, PyObject *obj) {
787
+ Py_INCREF(obj);
788
+ Py_DECREF(*(PyObject **) itemp);
789
+ *(PyObject **) itemp = obj;
790
+ return 1;
791
+ }
792
+
793
+ /////////// ToughSlice //////////
794
+
795
+ /* Dimension is indexed with 'start:stop:step' */
796
+
797
+ if (unlikely(__pyx_memoryview_slice_memviewslice(
798
+ &{{dst}},
799
+ {{src}}.shape[{{dim}}], {{src}}.strides[{{dim}}], {{src}}.suboffsets[{{dim}}],
800
+ {{dim}},
801
+ {{new_ndim}},
802
+ &{{get_suboffset_dim()}},
803
+ {{start}},
804
+ {{stop}},
805
+ {{step}},
806
+ {{int(have_start)}},
807
+ {{int(have_stop)}},
808
+ {{int(have_step)}},
809
+ 1) < 0))
810
+ {
811
+ {{error_goto}}
812
+ }
813
+
814
+
815
+ ////////// SimpleSlice //////////
816
+
817
+ /* Dimension is indexed with ':' only */
818
+
819
+ {{dst}}.shape[{{new_ndim}}] = {{src}}.shape[{{dim}}];
820
+ {{dst}}.strides[{{new_ndim}}] = {{src}}.strides[{{dim}}];
821
+
822
+ {{if access == 'direct'}}
823
+ {{dst}}.suboffsets[{{new_ndim}}] = -1;
824
+ {{else}}
825
+ {{dst}}.suboffsets[{{new_ndim}}] = {{src}}.suboffsets[{{dim}}];
826
+ if ({{src}}.suboffsets[{{dim}}] >= 0)
827
+ {{get_suboffset_dim()}} = {{new_ndim}};
828
+ {{endif}}
829
+
830
+
831
+ ////////// SliceIndex //////////
832
+
833
+ // Dimension is indexed with an integer, we could use the ToughSlice
834
+ // approach, but this is faster
835
+
836
+ {
837
+ Py_ssize_t __pyx_tmp_idx = {{idx}};
838
+
839
+ {{if wraparound or boundscheck}}
840
+ Py_ssize_t __pyx_tmp_shape = {{src}}.shape[{{dim}}];
841
+ {{endif}}
842
+
843
+ Py_ssize_t __pyx_tmp_stride = {{src}}.strides[{{dim}}];
844
+ {{if wraparound}}
845
+ if (__pyx_tmp_idx < 0)
846
+ __pyx_tmp_idx += __pyx_tmp_shape;
847
+ {{endif}}
848
+
849
+ {{if boundscheck}}
850
+ if (unlikely(!__Pyx_is_valid_index(__pyx_tmp_idx, __pyx_tmp_shape))) {
851
+ {{if not have_gil}}
852
+ PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
853
+ {{endif}}
854
+
855
+ PyErr_SetString(PyExc_IndexError,
856
+ "Index out of bounds (axis {{dim}})");
857
+
858
+ {{if not have_gil}}
859
+ PyGILState_Release(__pyx_gilstate_save);
860
+ {{endif}}
861
+
862
+ {{error_goto}}
863
+ }
864
+ {{endif}}
865
+
866
+ {{if all_dimensions_direct}}
867
+ {{dst}}.data += __pyx_tmp_idx * __pyx_tmp_stride;
868
+ {{else}}
869
+ if ({{get_suboffset_dim()}} < 0) {
870
+ {{dst}}.data += __pyx_tmp_idx * __pyx_tmp_stride;
871
+
872
+ /* This dimension is the first dimension, or is preceded by */
873
+ /* direct or indirect dimensions that are indexed away. */
874
+ /* Hence suboffset_dim must be less than zero, and we can have */
875
+ /* our data pointer refer to another block by dereferencing. */
876
+ /* slice.data -> B -> C becomes slice.data -> C */
877
+
878
+ {{if indirect}}
879
+ {
880
+ Py_ssize_t __pyx_tmp_suboffset = {{src}}.suboffsets[{{dim}}];
881
+
882
+ {{if generic}}
883
+ if (__pyx_tmp_suboffset >= 0)
884
+ {{endif}}
885
+
886
+ {{dst}}.data = *((char **) {{dst}}.data) + __pyx_tmp_suboffset;
887
+ }
888
+ {{endif}}
889
+
890
+ } else {
891
+ {{dst}}.suboffsets[{{get_suboffset_dim()}}] += __pyx_tmp_idx * __pyx_tmp_stride;
892
+
893
+ /* Note: dimension can not be indirect, the compiler will have */
894
+ /* issued an error */
895
+ }
896
+
897
+ {{endif}}
898
+ }
899
+
900
+
901
+ ////////// FillStrided1DScalar.proto //////////
902
+
903
+ static void
904
+ __pyx_fill_slice_{{dtype_name}}({{type_decl}} *p, Py_ssize_t extent, Py_ssize_t stride,
905
+ size_t itemsize, void *itemp);
906
+
907
+ ////////// FillStrided1DScalar //////////
908
+
909
+ /* Fill a slice with a scalar value. The dimension is direct and strided or contiguous */
910
+ /* This can be used as a callback for the memoryview object to efficiently assign a scalar */
911
+ /* Currently unused */
912
+ static void
913
+ __pyx_fill_slice_{{dtype_name}}({{type_decl}} *p, Py_ssize_t extent, Py_ssize_t stride,
914
+ size_t itemsize, void *itemp)
915
+ {
916
+ Py_ssize_t i;
917
+ {{type_decl}} item = *(({{type_decl}} *) itemp);
918
+ {{type_decl}} *endp;
919
+
920
+ stride /= sizeof({{type_decl}});
921
+ endp = p + stride * extent;
922
+
923
+ while (p < endp) {
924
+ *p = item;
925
+ p += stride;
926
+ }
927
+ }