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