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,992 @@
1
+ ////////// MemviewSliceStruct.proto //////////
2
+ //@proto_block: utility_code_proto_before_types
3
+
4
+ /* memoryview slice struct */
5
+ struct {{memview_struct_name}};
6
+
7
+ typedef struct {
8
+ struct {{memview_struct_name}} *memview;
9
+ char *data;
10
+ Py_ssize_t shape[{{max_dims}}];
11
+ Py_ssize_t strides[{{max_dims}}];
12
+ Py_ssize_t suboffsets[{{max_dims}}];
13
+ } {{memviewslice_name}};
14
+
15
+ // used for "len(memviewslice)"
16
+ #define __Pyx_MemoryView_Len(m) (m.shape[0])
17
+
18
+
19
+ /////////// Atomics.proto /////////////
20
+ //@proto_block: utility_code_proto_before_types
21
+
22
+ #include <pythread.h>
23
+
24
+ #ifndef CYTHON_ATOMICS
25
+ #define CYTHON_ATOMICS 1
26
+ #endif
27
+ // using CYTHON_ATOMICS as a cdef extern bint in the Cython memoryview code
28
+ // interacts badly with "import *". Therefore, define a helper function-like macro
29
+ #define __PYX_CYTHON_ATOMICS_ENABLED() CYTHON_ATOMICS
30
+
31
+ #define __pyx_atomic_int_type int
32
+ #define __pyx_nonatomic_int_type int
33
+
34
+ // For standard C/C++ atomics, get the headers first so we have ATOMIC_INT_LOCK_FREE
35
+ // defined when we decide to use them.
36
+ #if CYTHON_ATOMICS && (defined(__STDC_VERSION__) && \
37
+ (__STDC_VERSION__ >= 201112L) && \
38
+ !defined(__STDC_NO_ATOMICS__))
39
+ #include <stdatomic.h>
40
+ #elif CYTHON_ATOMICS && (defined(__cplusplus) && ( \
41
+ (__cplusplus >= 201103L) || \
42
+ (defined(_MSC_VER) && _MSC_VER >= 1700)))
43
+ #include <atomic>
44
+ #endif
45
+
46
+ #if CYTHON_ATOMICS && (defined(__STDC_VERSION__) && \
47
+ (__STDC_VERSION__ >= 201112L) && \
48
+ !defined(__STDC_NO_ATOMICS__) && \
49
+ ATOMIC_INT_LOCK_FREE == 2)
50
+ // C11 atomics are available and ATOMIC_INT_LOCK_FREE is definitely on
51
+ #undef __pyx_atomic_int_type
52
+ #define __pyx_atomic_int_type atomic_int
53
+ #define __pyx_atomic_incr_aligned(value) atomic_fetch_add_explicit(value, 1, memory_order_relaxed)
54
+ #define __pyx_atomic_decr_aligned(value) atomic_fetch_sub_explicit(value, 1, memory_order_acq_rel)
55
+ #if defined(__PYX_DEBUG_ATOMICS) && defined(_MSC_VER)
56
+ #pragma message ("Using standard C atomics")
57
+ #elif defined(__PYX_DEBUG_ATOMICS)
58
+ #warning "Using standard C atomics"
59
+ #endif
60
+ #elif CYTHON_ATOMICS && (defined(__cplusplus) && ( \
61
+ (__cplusplus >= 201103L) || \
62
+ /*_MSC_VER 1700 is Visual Studio 2012 */ \
63
+ (defined(_MSC_VER) && _MSC_VER >= 1700)) && \
64
+ ATOMIC_INT_LOCK_FREE == 2)
65
+ // C++11 atomics are available and ATOMIC_INT_LOCK_FREE is definitely on
66
+ #undef __pyx_atomic_int_type
67
+ #define __pyx_atomic_int_type std::atomic_int
68
+ #define __pyx_atomic_incr_aligned(value) std::atomic_fetch_add_explicit(value, 1, std::memory_order_relaxed)
69
+ #define __pyx_atomic_decr_aligned(value) std::atomic_fetch_sub_explicit(value, 1, std::memory_order_acq_rel)
70
+
71
+ #if defined(__PYX_DEBUG_ATOMICS) && defined(_MSC_VER)
72
+ #pragma message ("Using standard C++ atomics")
73
+ #elif defined(__PYX_DEBUG_ATOMICS)
74
+ #warning "Using standard C++ atomics"
75
+ #endif
76
+ #elif CYTHON_ATOMICS && (__GNUC__ >= 5 || (__GNUC__ == 4 && \
77
+ (__GNUC_MINOR__ > 1 || \
78
+ (__GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ >= 2))))
79
+ /* gcc >= 4.1.2 */
80
+ #define __pyx_atomic_incr_aligned(value) __sync_fetch_and_add(value, 1)
81
+ #define __pyx_atomic_decr_aligned(value) __sync_fetch_and_sub(value, 1)
82
+
83
+ #ifdef __PYX_DEBUG_ATOMICS
84
+ #warning "Using GNU atomics"
85
+ #endif
86
+ #elif CYTHON_ATOMICS && defined(_MSC_VER)
87
+ /* msvc */
88
+ #include <intrin.h>
89
+ #undef __pyx_atomic_int_type
90
+ #define __pyx_atomic_int_type long
91
+ #undef __pyx_nonatomic_int_type
92
+ #define __pyx_nonatomic_int_type long
93
+ #pragma intrinsic (_InterlockedExchangeAdd)
94
+ #define __pyx_atomic_incr_aligned(value) _InterlockedExchangeAdd(value, 1)
95
+ #define __pyx_atomic_decr_aligned(value) _InterlockedExchangeAdd(value, -1)
96
+
97
+ #ifdef __PYX_DEBUG_ATOMICS
98
+ #pragma message ("Using MSVC atomics")
99
+ #endif
100
+ #else
101
+ #undef CYTHON_ATOMICS
102
+ #define CYTHON_ATOMICS 0
103
+
104
+ #ifdef __PYX_DEBUG_ATOMICS
105
+ #warning "Not using atomics"
106
+ #endif
107
+ #endif
108
+
109
+ #if CYTHON_ATOMICS
110
+ #define __pyx_add_acquisition_count(memview) \
111
+ __pyx_atomic_incr_aligned(__pyx_get_slice_count_pointer(memview))
112
+ #define __pyx_sub_acquisition_count(memview) \
113
+ __pyx_atomic_decr_aligned(__pyx_get_slice_count_pointer(memview))
114
+ #else
115
+ #define __pyx_add_acquisition_count(memview) \
116
+ __pyx_add_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
117
+ #define __pyx_sub_acquisition_count(memview) \
118
+ __pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
119
+ #endif
120
+
121
+
122
+ /////////////// ObjectToMemviewSlice.proto ///////////////
123
+
124
+ static CYTHON_INLINE {{memviewslice_name}} {{funcname}}(PyObject *, int writable_flag);
125
+
126
+
127
+ ////////// MemviewSliceInit.proto //////////
128
+
129
+ // vsnprintf
130
+ #include <stdio.h>
131
+
132
+ #define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d
133
+
134
+ #define __Pyx_MEMVIEW_DIRECT 1
135
+ #define __Pyx_MEMVIEW_PTR 2
136
+ #define __Pyx_MEMVIEW_FULL 4
137
+ #define __Pyx_MEMVIEW_CONTIG 8
138
+ #define __Pyx_MEMVIEW_STRIDED 16
139
+ #define __Pyx_MEMVIEW_FOLLOW 32
140
+
141
+ #define __Pyx_IS_C_CONTIG 1
142
+ #define __Pyx_IS_F_CONTIG 2
143
+
144
+ static int __Pyx_init_memviewslice(
145
+ struct __pyx_memoryview_obj *memview,
146
+ int ndim,
147
+ __Pyx_memviewslice *memviewslice,
148
+ int memview_is_new_reference);
149
+
150
+ static CYTHON_INLINE int __pyx_add_acquisition_count_locked(
151
+ __pyx_atomic_int_type *acquisition_count, PyThread_type_lock lock);
152
+ static CYTHON_INLINE int __pyx_sub_acquisition_count_locked(
153
+ __pyx_atomic_int_type *acquisition_count, PyThread_type_lock lock);
154
+
155
+ #define __pyx_get_slice_count_pointer(memview) (&memview->acquisition_count)
156
+ #define __PYX_INC_MEMVIEW(slice, have_gil) __Pyx_INC_MEMVIEW(slice, have_gil, __LINE__)
157
+ #define __PYX_XCLEAR_MEMVIEW(slice, have_gil) __Pyx_XCLEAR_MEMVIEW(slice, have_gil, __LINE__)
158
+ static CYTHON_INLINE void __Pyx_INC_MEMVIEW({{memviewslice_name}} *, int, int);
159
+ static CYTHON_INLINE void __Pyx_XCLEAR_MEMVIEW({{memviewslice_name}} *, int, int);
160
+
161
+
162
+ /////////////// MemviewSliceIndex.proto ///////////////
163
+
164
+ static CYTHON_INLINE char *__pyx_memviewslice_index_full(
165
+ const char *bufp, Py_ssize_t idx, Py_ssize_t stride, Py_ssize_t suboffset);
166
+
167
+
168
+ /////////////// ObjectToMemviewSlice ///////////////
169
+ //@requires: MemviewSliceValidateAndInit
170
+
171
+ static CYTHON_INLINE {{memviewslice_name}} {{funcname}}(PyObject *obj, int writable_flag) {
172
+ {{memviewslice_name}} result = {{memslice_init}};
173
+ __Pyx_BufFmt_StackElem stack[{{struct_nesting_depth}}];
174
+ int axes_specs[] = { {{axes_specs}} };
175
+ int retcode;
176
+
177
+ if (obj == Py_None) {
178
+ /* We don't bother to refcount None */
179
+ result.memview = (struct __pyx_memoryview_obj *) Py_None;
180
+ return result;
181
+ }
182
+
183
+ retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, {{c_or_f_flag}},
184
+ {{buf_flag}} | writable_flag, {{ndim}},
185
+ &{{dtype_typeinfo}}, stack,
186
+ &result, obj);
187
+
188
+ if (unlikely(retcode == -1))
189
+ goto __pyx_fail;
190
+
191
+ return result;
192
+ __pyx_fail:
193
+ result.memview = NULL;
194
+ result.data = NULL;
195
+ return result;
196
+ }
197
+
198
+
199
+ /////////////// MemviewSliceValidateAndInit.proto ///////////////
200
+
201
+ static int __Pyx_ValidateAndInit_memviewslice(
202
+ int *axes_specs,
203
+ int c_or_f_flag,
204
+ int buf_flags,
205
+ int ndim,
206
+ __Pyx_TypeInfo *dtype,
207
+ __Pyx_BufFmt_StackElem stack[],
208
+ __Pyx_memviewslice *memviewslice,
209
+ PyObject *original_obj);
210
+
211
+ /////////////// MemviewSliceValidateAndInit ///////////////
212
+ //@requires: Buffer.c::TypeInfoCompare
213
+ //@requires: Buffer.c::BufferFormatStructs
214
+ //@requires: Buffer.c::BufferFormatCheck
215
+
216
+ static int
217
+ __pyx_check_strides(Py_buffer *buf, int dim, int ndim, int spec)
218
+ {
219
+ if (buf->shape[dim] <= 1)
220
+ return 1;
221
+
222
+ if (buf->strides) {
223
+ if (spec & __Pyx_MEMVIEW_CONTIG) {
224
+ if (spec & (__Pyx_MEMVIEW_PTR|__Pyx_MEMVIEW_FULL)) {
225
+ if (unlikely(buf->strides[dim] != sizeof(void *))) {
226
+ PyErr_Format(PyExc_ValueError,
227
+ "Buffer is not indirectly contiguous "
228
+ "in dimension %d.", dim);
229
+ goto fail;
230
+ }
231
+ } else if (unlikely(buf->strides[dim] != buf->itemsize)) {
232
+ PyErr_SetString(PyExc_ValueError,
233
+ "Buffer and memoryview are not contiguous "
234
+ "in the same dimension.");
235
+ goto fail;
236
+ }
237
+ }
238
+
239
+ if (spec & __Pyx_MEMVIEW_FOLLOW) {
240
+ Py_ssize_t stride = buf->strides[dim];
241
+ if (stride < 0)
242
+ stride = -stride;
243
+ if (unlikely(stride < buf->itemsize)) {
244
+ PyErr_SetString(PyExc_ValueError,
245
+ "Buffer and memoryview are not contiguous "
246
+ "in the same dimension.");
247
+ goto fail;
248
+ }
249
+ }
250
+ } else {
251
+ if (unlikely(spec & __Pyx_MEMVIEW_CONTIG && dim != ndim - 1)) {
252
+ PyErr_Format(PyExc_ValueError,
253
+ "C-contiguous buffer is not contiguous in "
254
+ "dimension %d", dim);
255
+ goto fail;
256
+ } else if (unlikely(spec & (__Pyx_MEMVIEW_PTR))) {
257
+ PyErr_Format(PyExc_ValueError,
258
+ "C-contiguous buffer is not indirect in "
259
+ "dimension %d", dim);
260
+ goto fail;
261
+ } else if (unlikely(buf->suboffsets)) {
262
+ PyErr_SetString(PyExc_ValueError,
263
+ "Buffer exposes suboffsets but no strides");
264
+ goto fail;
265
+ }
266
+ }
267
+
268
+ return 1;
269
+ fail:
270
+ return 0;
271
+ }
272
+
273
+ static int
274
+ __pyx_check_suboffsets(Py_buffer *buf, int dim, int ndim, int spec)
275
+ {
276
+ CYTHON_UNUSED_VAR(ndim);
277
+ // Todo: without PyBUF_INDIRECT we may not have suboffset information, i.e., the
278
+ // ptr may not be set to NULL but may be uninitialized?
279
+ if (spec & __Pyx_MEMVIEW_DIRECT) {
280
+ if (unlikely(buf->suboffsets && buf->suboffsets[dim] >= 0)) {
281
+ PyErr_Format(PyExc_ValueError,
282
+ "Buffer not compatible with direct access "
283
+ "in dimension %d.", dim);
284
+ goto fail;
285
+ }
286
+ }
287
+
288
+ if (spec & __Pyx_MEMVIEW_PTR) {
289
+ if (unlikely(!buf->suboffsets || (buf->suboffsets[dim] < 0))) {
290
+ PyErr_Format(PyExc_ValueError,
291
+ "Buffer is not indirectly accessible "
292
+ "in dimension %d.", dim);
293
+ goto fail;
294
+ }
295
+ }
296
+
297
+ return 1;
298
+ fail:
299
+ return 0;
300
+ }
301
+
302
+ static int
303
+ __pyx_verify_contig(Py_buffer *buf, int ndim, int c_or_f_flag)
304
+ {
305
+ int i;
306
+
307
+ if (c_or_f_flag & __Pyx_IS_F_CONTIG) {
308
+ Py_ssize_t stride = 1;
309
+ for (i = 0; i < ndim; i++) {
310
+ if (unlikely(stride * buf->itemsize != buf->strides[i] && buf->shape[i] > 1)) {
311
+ PyErr_SetString(PyExc_ValueError,
312
+ "Buffer not fortran contiguous.");
313
+ goto fail;
314
+ }
315
+ stride = stride * buf->shape[i];
316
+ }
317
+ } else if (c_or_f_flag & __Pyx_IS_C_CONTIG) {
318
+ Py_ssize_t stride = 1;
319
+ for (i = ndim - 1; i >- 1; i--) {
320
+ if (unlikely(stride * buf->itemsize != buf->strides[i] && buf->shape[i] > 1)) {
321
+ PyErr_SetString(PyExc_ValueError,
322
+ "Buffer not C contiguous.");
323
+ goto fail;
324
+ }
325
+ stride = stride * buf->shape[i];
326
+ }
327
+ }
328
+
329
+ return 1;
330
+ fail:
331
+ return 0;
332
+ }
333
+
334
+ static int __Pyx_ValidateAndInit_memviewslice(
335
+ int *axes_specs,
336
+ int c_or_f_flag,
337
+ int buf_flags,
338
+ int ndim,
339
+ __Pyx_TypeInfo *dtype,
340
+ __Pyx_BufFmt_StackElem stack[],
341
+ __Pyx_memviewslice *memviewslice,
342
+ PyObject *original_obj)
343
+ {
344
+ struct __pyx_memoryview_obj *memview, *new_memview;
345
+ __Pyx_RefNannyDeclarations
346
+ Py_buffer *buf;
347
+ int i, spec = 0, retval = -1;
348
+ __Pyx_BufFmt_Context ctx;
349
+ int from_memoryview = __pyx_memoryview_check(original_obj);
350
+
351
+ __Pyx_RefNannySetupContext("ValidateAndInit_memviewslice", 0);
352
+
353
+ if (from_memoryview && __pyx_typeinfo_cmp(dtype, ((struct __pyx_memoryview_obj *)
354
+ original_obj)->typeinfo)) {
355
+ /* We have a matching dtype, skip format parsing */
356
+ memview = (struct __pyx_memoryview_obj *) original_obj;
357
+ new_memview = NULL;
358
+ } else {
359
+ memview = (struct __pyx_memoryview_obj *) __pyx_memoryview_new(
360
+ original_obj, buf_flags, 0, dtype);
361
+ new_memview = memview;
362
+ if (unlikely(!memview))
363
+ goto fail;
364
+ }
365
+
366
+ buf = &memview->view;
367
+ if (unlikely(buf->ndim != ndim)) {
368
+ PyErr_Format(PyExc_ValueError,
369
+ "Buffer has wrong number of dimensions (expected %d, got %d)",
370
+ ndim, buf->ndim);
371
+ goto fail;
372
+ }
373
+
374
+ if (new_memview) {
375
+ __Pyx_BufFmt_Init(&ctx, stack, dtype);
376
+ if (unlikely(!__Pyx_BufFmt_CheckString(&ctx, buf->format))) goto fail;
377
+ }
378
+
379
+ if (unlikely((unsigned) buf->itemsize != dtype->size)) {
380
+ PyErr_Format(PyExc_ValueError,
381
+ "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "u byte%s) "
382
+ "does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "u byte%s)",
383
+ buf->itemsize,
384
+ (buf->itemsize > 1) ? "s" : "",
385
+ dtype->name,
386
+ dtype->size,
387
+ (dtype->size > 1) ? "s" : "");
388
+ goto fail;
389
+ }
390
+
391
+ /* Check axes */
392
+ if (buf->len > 0) {
393
+ // 0-sized arrays do not undergo these checks since their strides are
394
+ // irrelevant and they are always both C- and F-contiguous.
395
+ for (i = 0; i < ndim; i++) {
396
+ spec = axes_specs[i];
397
+ if (unlikely(!__pyx_check_strides(buf, i, ndim, spec)))
398
+ goto fail;
399
+ if (unlikely(!__pyx_check_suboffsets(buf, i, ndim, spec)))
400
+ goto fail;
401
+ }
402
+
403
+ /* Check contiguity */
404
+ if (unlikely(buf->strides && !__pyx_verify_contig(buf, ndim, c_or_f_flag)))
405
+ goto fail;
406
+ }
407
+
408
+ /* Initialize */
409
+ if (unlikely(__Pyx_init_memviewslice(memview, ndim, memviewslice,
410
+ new_memview != NULL) == -1)) {
411
+ goto fail;
412
+ }
413
+
414
+ retval = 0;
415
+ goto no_fail;
416
+
417
+ fail:
418
+ Py_XDECREF((PyObject*)new_memview);
419
+ retval = -1;
420
+
421
+ no_fail:
422
+ __Pyx_RefNannyFinishContext();
423
+ return retval;
424
+ }
425
+
426
+
427
+ ////////// MemviewSliceInit //////////
428
+
429
+ static int
430
+ __Pyx_init_memviewslice(struct __pyx_memoryview_obj *memview,
431
+ int ndim,
432
+ {{memviewslice_name}} *memviewslice,
433
+ int memview_is_new_reference)
434
+ {
435
+ __Pyx_RefNannyDeclarations
436
+ int i, retval=-1;
437
+ Py_buffer *buf = &memview->view;
438
+ __Pyx_RefNannySetupContext("init_memviewslice", 0);
439
+
440
+ if (unlikely(memviewslice->memview || memviewslice->data)) {
441
+ PyErr_SetString(PyExc_ValueError,
442
+ "memviewslice is already initialized!");
443
+ goto fail;
444
+ }
445
+
446
+ if (buf->strides) {
447
+ for (i = 0; i < ndim; i++) {
448
+ memviewslice->strides[i] = buf->strides[i];
449
+ }
450
+ } else {
451
+ Py_ssize_t stride = buf->itemsize;
452
+ for (i = ndim - 1; i >= 0; i--) {
453
+ memviewslice->strides[i] = stride;
454
+ stride *= buf->shape[i];
455
+ }
456
+ }
457
+
458
+ for (i = 0; i < ndim; i++) {
459
+ memviewslice->shape[i] = buf->shape[i];
460
+ if (buf->suboffsets) {
461
+ memviewslice->suboffsets[i] = buf->suboffsets[i];
462
+ } else {
463
+ memviewslice->suboffsets[i] = -1;
464
+ }
465
+ }
466
+
467
+ memviewslice->memview = memview;
468
+ memviewslice->data = (char *)buf->buf;
469
+ if (__pyx_add_acquisition_count(memview) == 0 && !memview_is_new_reference) {
470
+ Py_INCREF((PyObject*)memview);
471
+ }
472
+ retval = 0;
473
+ goto no_fail;
474
+
475
+ fail:
476
+ /* Don't decref, the memoryview may be borrowed. Let the caller do the cleanup */
477
+ /* __Pyx_XDECREF(memviewslice->memview); */
478
+ memviewslice->memview = 0;
479
+ memviewslice->data = 0;
480
+ retval = -1;
481
+ no_fail:
482
+ __Pyx_RefNannyFinishContext();
483
+ return retval;
484
+ }
485
+
486
+ #ifndef Py_NO_RETURN
487
+ // available since Py3.3
488
+ #define Py_NO_RETURN
489
+ #endif
490
+
491
+ static void __pyx_fatalerror(const char *fmt, ...) Py_NO_RETURN {
492
+ va_list vargs;
493
+ char msg[200];
494
+
495
+ #if PY_VERSION_HEX >= 0x030A0000 || defined(HAVE_STDARG_PROTOTYPES)
496
+ va_start(vargs, fmt);
497
+ #else
498
+ va_start(vargs);
499
+ #endif
500
+ vsnprintf(msg, 200, fmt, vargs);
501
+ va_end(vargs);
502
+
503
+ Py_FatalError(msg);
504
+ }
505
+
506
+ static CYTHON_INLINE int
507
+ __pyx_add_acquisition_count_locked(__pyx_atomic_int_type *acquisition_count,
508
+ PyThread_type_lock lock)
509
+ {
510
+ int result;
511
+ PyThread_acquire_lock(lock, 1);
512
+ result = (*acquisition_count)++;
513
+ PyThread_release_lock(lock);
514
+ return result;
515
+ }
516
+
517
+ static CYTHON_INLINE int
518
+ __pyx_sub_acquisition_count_locked(__pyx_atomic_int_type *acquisition_count,
519
+ PyThread_type_lock lock)
520
+ {
521
+ int result;
522
+ PyThread_acquire_lock(lock, 1);
523
+ result = (*acquisition_count)--;
524
+ PyThread_release_lock(lock);
525
+ return result;
526
+ }
527
+
528
+
529
+ static CYTHON_INLINE void
530
+ __Pyx_INC_MEMVIEW({{memviewslice_name}} *memslice, int have_gil, int lineno)
531
+ {
532
+ __pyx_nonatomic_int_type old_acquisition_count;
533
+ struct {{memview_struct_name}} *memview = memslice->memview;
534
+ if (unlikely(!memview || (PyObject *) memview == Py_None)) {
535
+ // Allow uninitialized memoryview assignment and do not ref-count None.
536
+ return;
537
+ }
538
+
539
+ old_acquisition_count = __pyx_add_acquisition_count(memview);
540
+ if (unlikely(old_acquisition_count <= 0)) {
541
+ if (likely(old_acquisition_count == 0)) {
542
+ // First acquisition => keep the memoryview object alive.
543
+ if (have_gil) {
544
+ Py_INCREF((PyObject *) memview);
545
+ } else {
546
+ PyGILState_STATE _gilstate = PyGILState_Ensure();
547
+ Py_INCREF((PyObject *) memview);
548
+ PyGILState_Release(_gilstate);
549
+ }
550
+ } else {
551
+ __pyx_fatalerror("Acquisition count is %d (line %d)",
552
+ old_acquisition_count+1, lineno);
553
+ }
554
+ }
555
+ }
556
+
557
+ static CYTHON_INLINE void __Pyx_XCLEAR_MEMVIEW({{memviewslice_name}} *memslice,
558
+ int have_gil, int lineno) {
559
+ __pyx_nonatomic_int_type old_acquisition_count;
560
+ struct {{memview_struct_name}} *memview = memslice->memview;
561
+
562
+ if (unlikely(!memview || (PyObject *) memview == Py_None)) {
563
+ // Do not ref-count None.
564
+ memslice->memview = NULL;
565
+ return;
566
+ }
567
+
568
+ old_acquisition_count = __pyx_sub_acquisition_count(memview);
569
+ memslice->data = NULL;
570
+ if (likely(old_acquisition_count > 1)) {
571
+ // Still other slices out there => we do not own the reference.
572
+ memslice->memview = NULL;
573
+ } else if (likely(old_acquisition_count == 1)) {
574
+ // Last slice => discard owned Python reference to memoryview object.
575
+ if (have_gil) {
576
+ Py_CLEAR(memslice->memview);
577
+ } else {
578
+ PyGILState_STATE _gilstate = PyGILState_Ensure();
579
+ Py_CLEAR(memslice->memview);
580
+ PyGILState_Release(_gilstate);
581
+ }
582
+ } else {
583
+ __pyx_fatalerror("Acquisition count is %d (line %d)",
584
+ old_acquisition_count-1, lineno);
585
+ }
586
+ }
587
+
588
+
589
+ ////////// MemviewSliceCopyTemplate.proto //////////
590
+
591
+ static {{memviewslice_name}}
592
+ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs,
593
+ const char *mode, int ndim,
594
+ size_t sizeof_dtype, int contig_flag,
595
+ int dtype_is_object);
596
+
597
+
598
+ ////////// MemviewSliceCopyTemplate //////////
599
+
600
+ static {{memviewslice_name}}
601
+ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs,
602
+ const char *mode, int ndim,
603
+ size_t sizeof_dtype, int contig_flag,
604
+ int dtype_is_object)
605
+ {
606
+ __Pyx_RefNannyDeclarations
607
+ int i;
608
+ __Pyx_memviewslice new_mvs = {{memslice_init}};
609
+ struct __pyx_memoryview_obj *from_memview = from_mvs->memview;
610
+ Py_buffer *buf = &from_memview->view;
611
+ PyObject *shape_tuple = NULL;
612
+ PyObject *temp_int = NULL;
613
+ struct __pyx_array_obj *array_obj = NULL;
614
+ struct __pyx_memoryview_obj *memview_obj = NULL;
615
+
616
+ __Pyx_RefNannySetupContext("__pyx_memoryview_copy_new_contig", 0);
617
+
618
+ for (i = 0; i < ndim; i++) {
619
+ if (unlikely(from_mvs->suboffsets[i] >= 0)) {
620
+ PyErr_Format(PyExc_ValueError, "Cannot copy memoryview slice with "
621
+ "indirect dimensions (axis %d)", i);
622
+ goto fail;
623
+ }
624
+ }
625
+
626
+ shape_tuple = PyTuple_New(ndim);
627
+ if (unlikely(!shape_tuple)) {
628
+ goto fail;
629
+ }
630
+ __Pyx_GOTREF(shape_tuple);
631
+
632
+
633
+ for(i = 0; i < ndim; i++) {
634
+ temp_int = PyLong_FromSsize_t(from_mvs->shape[i]);
635
+ if(unlikely(!temp_int)) {
636
+ goto fail;
637
+ } else {
638
+ #if CYTHON_ASSUME_SAFE_MACROS
639
+ PyTuple_SET_ITEM(shape_tuple, i, temp_int);
640
+ #else
641
+ if (PyTuple_SetItem(shape_tuple, i, temp_int) < 0) {
642
+ goto fail;
643
+ }
644
+ #endif
645
+ temp_int = NULL;
646
+ }
647
+ }
648
+
649
+ array_obj = __pyx_array_new(shape_tuple, sizeof_dtype, buf->format, mode, NULL);
650
+ if (unlikely(!array_obj)) {
651
+ goto fail;
652
+ }
653
+ __Pyx_GOTREF(array_obj);
654
+
655
+ memview_obj = (struct __pyx_memoryview_obj *) __pyx_memoryview_new(
656
+ (PyObject *) array_obj, contig_flag,
657
+ dtype_is_object,
658
+ from_mvs->memview->typeinfo);
659
+ if (unlikely(!memview_obj))
660
+ goto fail;
661
+
662
+ /* initialize new_mvs */
663
+ if (unlikely(__Pyx_init_memviewslice(memview_obj, ndim, &new_mvs, 1) < 0))
664
+ goto fail;
665
+
666
+ if (unlikely(__pyx_memoryview_copy_contents(*from_mvs, new_mvs, ndim, ndim,
667
+ dtype_is_object) < 0))
668
+ goto fail;
669
+
670
+ goto no_fail;
671
+
672
+ fail:
673
+ __Pyx_XDECREF((PyObject *) new_mvs.memview);
674
+ new_mvs.memview = NULL;
675
+ new_mvs.data = NULL;
676
+ no_fail:
677
+ __Pyx_XDECREF(shape_tuple);
678
+ __Pyx_XDECREF(temp_int);
679
+ __Pyx_XDECREF((PyObject *) array_obj);
680
+ __Pyx_RefNannyFinishContext();
681
+ return new_mvs;
682
+ }
683
+
684
+
685
+ ////////// CopyContentsUtility.proto /////////
686
+
687
+ #define {{func_cname}}(slice) \
688
+ __pyx_memoryview_copy_new_contig(&slice, "{{mode}}", {{ndim}}, \
689
+ sizeof({{dtype_decl}}), {{contig_flag}}, \
690
+ {{dtype_is_object}})
691
+
692
+
693
+ ////////// OverlappingSlices.proto //////////
694
+
695
+ static int __pyx_slices_overlap({{memviewslice_name}} *slice1,
696
+ {{memviewslice_name}} *slice2,
697
+ int ndim, size_t itemsize);
698
+
699
+
700
+ ////////// OverlappingSlices //////////
701
+
702
+ /* Based on numpy's core/src/multiarray/array_assign.c */
703
+
704
+ /* Gets a half-open range [start, end) which contains the array data */
705
+ static void
706
+ __pyx_get_array_memory_extents({{memviewslice_name}} *slice,
707
+ void **out_start, void **out_end,
708
+ int ndim, size_t itemsize)
709
+ {
710
+ char *start, *end;
711
+ int i;
712
+
713
+ start = end = slice->data;
714
+
715
+ for (i = 0; i < ndim; i++) {
716
+ Py_ssize_t stride = slice->strides[i];
717
+ Py_ssize_t extent = slice->shape[i];
718
+
719
+ if (extent == 0) {
720
+ *out_start = *out_end = start;
721
+ return;
722
+ } else {
723
+ if (stride > 0)
724
+ end += stride * (extent - 1);
725
+ else
726
+ start += stride * (extent - 1);
727
+ }
728
+ }
729
+
730
+ /* Return a half-open range */
731
+ *out_start = start;
732
+ *out_end = end + itemsize;
733
+ }
734
+
735
+ /* Returns 1 if the arrays have overlapping data, 0 otherwise */
736
+ static int
737
+ __pyx_slices_overlap({{memviewslice_name}} *slice1,
738
+ {{memviewslice_name}} *slice2,
739
+ int ndim, size_t itemsize)
740
+ {
741
+ void *start1, *end1, *start2, *end2;
742
+
743
+ __pyx_get_array_memory_extents(slice1, &start1, &end1, ndim, itemsize);
744
+ __pyx_get_array_memory_extents(slice2, &start2, &end2, ndim, itemsize);
745
+
746
+ return (start1 < end2) && (start2 < end1);
747
+ }
748
+
749
+
750
+ ////////// MemviewSliceCheckContig.proto //////////
751
+
752
+ #define __pyx_memviewslice_is_contig_{{contig_type}}{{ndim}}(slice) \
753
+ __pyx_memviewslice_is_contig(slice, '{{contig_type}}', {{ndim}})
754
+
755
+
756
+ ////////// MemviewSliceIsContig.proto //////////
757
+
758
+ static int __pyx_memviewslice_is_contig(const {{memviewslice_name}} mvs, char order, int ndim);/*proto*/
759
+
760
+
761
+ ////////// MemviewSliceIsContig //////////
762
+
763
+ static int
764
+ __pyx_memviewslice_is_contig(const {{memviewslice_name}} mvs, char order, int ndim)
765
+ {
766
+ int i, index, step, start;
767
+ Py_ssize_t itemsize = mvs.memview->view.itemsize;
768
+
769
+ if (order == 'F') {
770
+ step = 1;
771
+ start = 0;
772
+ } else {
773
+ step = -1;
774
+ start = ndim - 1;
775
+ }
776
+
777
+ for (i = 0; i < ndim; i++) {
778
+ index = start + step * i;
779
+ if (mvs.suboffsets[index] >= 0 || mvs.strides[index] != itemsize)
780
+ return 0;
781
+
782
+ itemsize *= mvs.shape[index];
783
+ }
784
+
785
+ return 1;
786
+ }
787
+
788
+
789
+ /////////////// MemviewSliceIndex ///////////////
790
+
791
+ static CYTHON_INLINE char *
792
+ __pyx_memviewslice_index_full(const char *bufp, Py_ssize_t idx,
793
+ Py_ssize_t stride, Py_ssize_t suboffset)
794
+ {
795
+ bufp = bufp + idx * stride;
796
+ if (suboffset >= 0) {
797
+ bufp = *((char **) bufp) + suboffset;
798
+ }
799
+ return (char *) bufp;
800
+ }
801
+
802
+
803
+ /////////////// MemviewDtypeToObject.proto ///////////////
804
+
805
+ {{if to_py_function}}
806
+ static CYTHON_INLINE PyObject *{{get_function}}(const char *itemp); /* proto */
807
+ {{endif}}
808
+
809
+ {{if from_py_function}}
810
+ static CYTHON_INLINE int {{set_function}}(const char *itemp, PyObject *obj); /* proto */
811
+ {{endif}}
812
+
813
+ /////////////// MemviewDtypeToObject ///////////////
814
+
815
+ {{#__pyx_memview_<dtype_name>_to_object}}
816
+
817
+ /* Convert a dtype to or from a Python object */
818
+
819
+ {{if to_py_function}}
820
+ static CYTHON_INLINE PyObject *{{get_function}}(const char *itemp) {
821
+ return (PyObject *) {{to_py_function}}(*({{dtype}} *) itemp);
822
+ }
823
+ {{endif}}
824
+
825
+ {{if from_py_function}}
826
+ static CYTHON_INLINE int {{set_function}}(const char *itemp, PyObject *obj) {
827
+ {{dtype}} value = {{from_py_function}}(obj);
828
+ if (unlikely({{error_condition}}))
829
+ return 0;
830
+ *({{dtype}} *) itemp = value;
831
+ return 1;
832
+ }
833
+ {{endif}}
834
+
835
+
836
+ /////////////// MemviewObjectToObject.proto ///////////////
837
+
838
+ /* Function callbacks (for memoryview object) for dtype object */
839
+ static PyObject *{{get_function}}(const char *itemp); /* proto */
840
+ static int {{set_function}}(const char *itemp, PyObject *obj); /* proto */
841
+
842
+
843
+ /////////////// MemviewObjectToObject ///////////////
844
+
845
+ static PyObject *{{get_function}}(const char *itemp) {
846
+ PyObject *result = *(PyObject **) itemp;
847
+ Py_INCREF(result);
848
+ return result;
849
+ }
850
+
851
+ static int {{set_function}}(const char *itemp, PyObject *obj) {
852
+ Py_INCREF(obj);
853
+ Py_DECREF(*(PyObject **) itemp);
854
+ *(PyObject **) itemp = obj;
855
+ return 1;
856
+ }
857
+
858
+ /////////// ToughSlice //////////
859
+
860
+ /* Dimension is indexed with 'start:stop:step' */
861
+
862
+ if (unlikely(__pyx_memoryview_slice_memviewslice(
863
+ &{{dst}},
864
+ {{src}}.shape[{{dim}}], {{src}}.strides[{{dim}}], {{src}}.suboffsets[{{dim}}],
865
+ {{dim}},
866
+ {{new_ndim}},
867
+ &{{get_suboffset_dim()}},
868
+ {{start}},
869
+ {{stop}},
870
+ {{step}},
871
+ {{int(have_start)}},
872
+ {{int(have_stop)}},
873
+ {{int(have_step)}},
874
+ 1) < 0))
875
+ {
876
+ {{error_goto}}
877
+ }
878
+
879
+
880
+ ////////// SimpleSlice //////////
881
+
882
+ /* Dimension is indexed with ':' only */
883
+
884
+ {{dst}}.shape[{{new_ndim}}] = {{src}}.shape[{{dim}}];
885
+ {{dst}}.strides[{{new_ndim}}] = {{src}}.strides[{{dim}}];
886
+
887
+ {{if access == 'direct'}}
888
+ {{dst}}.suboffsets[{{new_ndim}}] = -1;
889
+ {{else}}
890
+ {{dst}}.suboffsets[{{new_ndim}}] = {{src}}.suboffsets[{{dim}}];
891
+ if ({{src}}.suboffsets[{{dim}}] >= 0)
892
+ {{get_suboffset_dim()}} = {{new_ndim}};
893
+ {{endif}}
894
+
895
+
896
+ ////////// SliceIndex //////////
897
+
898
+ // Dimension is indexed with an integer, we could use the ToughSlice
899
+ // approach, but this is faster
900
+
901
+ {
902
+ Py_ssize_t __pyx_tmp_idx = {{idx}};
903
+
904
+ {{if wraparound or boundscheck}}
905
+ Py_ssize_t __pyx_tmp_shape = {{src}}.shape[{{dim}}];
906
+ {{endif}}
907
+
908
+ Py_ssize_t __pyx_tmp_stride = {{src}}.strides[{{dim}}];
909
+ {{if wraparound}}
910
+ if (__pyx_tmp_idx < 0)
911
+ __pyx_tmp_idx += __pyx_tmp_shape;
912
+ {{endif}}
913
+
914
+ {{if boundscheck}}
915
+ if (unlikely(!__Pyx_is_valid_index(__pyx_tmp_idx, __pyx_tmp_shape))) {
916
+ {{if not have_gil}}
917
+ PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
918
+ {{endif}}
919
+
920
+ PyErr_SetString(PyExc_IndexError,
921
+ "Index out of bounds (axis {{dim}})");
922
+
923
+ {{if not have_gil}}
924
+ PyGILState_Release(__pyx_gilstate_save);
925
+ {{endif}}
926
+
927
+ {{error_goto}}
928
+ }
929
+ {{endif}}
930
+
931
+ {{if all_dimensions_direct}}
932
+ {{dst}}.data += __pyx_tmp_idx * __pyx_tmp_stride;
933
+ {{else}}
934
+ if ({{get_suboffset_dim()}} < 0) {
935
+ {{dst}}.data += __pyx_tmp_idx * __pyx_tmp_stride;
936
+
937
+ /* This dimension is the first dimension, or is preceded by */
938
+ /* direct or indirect dimensions that are indexed away. */
939
+ /* Hence suboffset_dim must be less than zero, and we can have */
940
+ /* our data pointer refer to another block by dereferencing. */
941
+ /* slice.data -> B -> C becomes slice.data -> C */
942
+
943
+ {{if indirect}}
944
+ {
945
+ Py_ssize_t __pyx_tmp_suboffset = {{src}}.suboffsets[{{dim}}];
946
+
947
+ {{if generic}}
948
+ if (__pyx_tmp_suboffset >= 0)
949
+ {{endif}}
950
+
951
+ {{dst}}.data = *((char **) {{dst}}.data) + __pyx_tmp_suboffset;
952
+ }
953
+ {{endif}}
954
+
955
+ } else {
956
+ {{dst}}.suboffsets[{{get_suboffset_dim()}}] += __pyx_tmp_idx * __pyx_tmp_stride;
957
+
958
+ /* Note: dimension can not be indirect, the compiler will have */
959
+ /* issued an error */
960
+ }
961
+
962
+ {{endif}}
963
+ }
964
+
965
+
966
+ ////////// FillStrided1DScalar.proto //////////
967
+
968
+ static void
969
+ __pyx_fill_slice_{{dtype_name}}({{type_decl}} *p, Py_ssize_t extent, Py_ssize_t stride,
970
+ size_t itemsize, void *itemp);
971
+
972
+ ////////// FillStrided1DScalar //////////
973
+
974
+ /* Fill a slice with a scalar value. The dimension is direct and strided or contiguous */
975
+ /* This can be used as a callback for the memoryview object to efficiently assign a scalar */
976
+ /* Currently unused */
977
+ static void
978
+ __pyx_fill_slice_{{dtype_name}}({{type_decl}} *p, Py_ssize_t extent, Py_ssize_t stride,
979
+ size_t itemsize, void *itemp)
980
+ {
981
+ Py_ssize_t i;
982
+ {{type_decl}} item = *(({{type_decl}} *) itemp);
983
+ {{type_decl}} *endp;
984
+
985
+ stride /= sizeof({{type_decl}});
986
+ endp = p + stride * extent;
987
+
988
+ while (p < endp) {
989
+ *p = item;
990
+ p += stride;
991
+ }
992
+ }