Cython 3.2.0__cp39-abi3-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Cython/Build/BuildExecutable.py +169 -0
- Cython/Build/Cache.py +199 -0
- Cython/Build/Cythonize.py +350 -0
- Cython/Build/Dependencies.py +1314 -0
- Cython/Build/Distutils.py +1 -0
- Cython/Build/Inline.py +463 -0
- Cython/Build/IpythonMagic.py +560 -0
- Cython/Build/SharedModule.py +94 -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 +11 -0
- Cython/CodeWriter.py +815 -0
- Cython/Compiler/AnalysedTreeTransforms.py +97 -0
- Cython/Compiler/Annotate.py +328 -0
- Cython/Compiler/AutoDocTransforms.py +320 -0
- Cython/Compiler/Buffer.py +680 -0
- Cython/Compiler/Builtin.py +984 -0
- Cython/Compiler/CmdLine.py +263 -0
- Cython/Compiler/Code.pxd +149 -0
- Cython/Compiler/Code.py +3746 -0
- Cython/Compiler/Code.pyd +0 -0
- Cython/Compiler/CodeGeneration.py +33 -0
- Cython/Compiler/CythonScope.py +191 -0
- Cython/Compiler/Dataclass.py +864 -0
- Cython/Compiler/DebugFlags.py +24 -0
- Cython/Compiler/Errors.py +297 -0
- Cython/Compiler/ExprNodes.py +15562 -0
- Cython/Compiler/FlowControl.pxd +97 -0
- Cython/Compiler/FlowControl.py +1451 -0
- Cython/Compiler/FlowControl.pyd +0 -0
- Cython/Compiler/FusedNode.py +971 -0
- Cython/Compiler/FusedNode.pyd +0 -0
- Cython/Compiler/Future.py +16 -0
- Cython/Compiler/Interpreter.py +57 -0
- Cython/Compiler/Lexicon.py +421 -0
- Cython/Compiler/LineTable.py +114 -0
- Cython/Compiler/LineTable.pyd +0 -0
- Cython/Compiler/Main.py +857 -0
- Cython/Compiler/MatchCaseNodes.py +259 -0
- Cython/Compiler/MemoryView.py +905 -0
- Cython/Compiler/ModuleNode.py +4235 -0
- Cython/Compiler/Naming.py +363 -0
- Cython/Compiler/Nodes.py +10831 -0
- Cython/Compiler/Optimize.py +5288 -0
- Cython/Compiler/Options.py +843 -0
- Cython/Compiler/ParseTreeTransforms.pxd +78 -0
- Cython/Compiler/ParseTreeTransforms.py +4638 -0
- Cython/Compiler/Parsing.pxd +9 -0
- Cython/Compiler/Parsing.py +4775 -0
- Cython/Compiler/Parsing.pyd +0 -0
- Cython/Compiler/Pipeline.py +439 -0
- Cython/Compiler/PyrexTypes.py +5870 -0
- Cython/Compiler/Pythran.py +232 -0
- Cython/Compiler/Scanning.pxd +48 -0
- Cython/Compiler/Scanning.py +701 -0
- Cython/Compiler/Scanning.pyd +0 -0
- Cython/Compiler/StringEncoding.py +298 -0
- Cython/Compiler/Symtab.py +3073 -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 +144 -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 +21 -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 +591 -0
- Cython/Compiler/TypeSlots.py +1174 -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/Visitor.pyd +0 -0
- Cython/Compiler/__init__.py +1 -0
- Cython/Coverage.py +448 -0
- Cython/Debugger/Cygdb.py +177 -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 +178 -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 +141 -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 +234 -0
- Cython/Includes/libc/time.pxd +52 -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/condition_variable.pxd +322 -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 +387 -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 +43 -0
- Cython/Includes/libcpp/set.pxd +228 -0
- Cython/Includes/libcpp/shared_mutex.pxd +96 -0
- Cython/Includes/libcpp/span.pxd +87 -0
- Cython/Includes/libcpp/stack.pxd +11 -0
- Cython/Includes/libcpp/stop_token.pxd +117 -0
- Cython/Includes/libcpp/string.pxd +355 -0
- Cython/Includes/libcpp/string_view.pxd +183 -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/numpy/math.pxd +150 -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/Actions.pyd +0 -0
- Cython/Plex/DFA.pxd +14 -0
- Cython/Plex/DFA.py +164 -0
- Cython/Plex/DFA.pyd +0 -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/Machines.pyd +0 -0
- Cython/Plex/Regexps.py +535 -0
- Cython/Plex/Scanners.pxd +45 -0
- Cython/Plex/Scanners.py +328 -0
- Cython/Plex/Scanners.pyd +0 -0
- Cython/Plex/Transitions.pxd +14 -0
- Cython/Plex/Transitions.py +239 -0
- Cython/Plex/Transitions.pyd +0 -0
- Cython/Plex/__init__.py +34 -0
- Cython/Runtime/__init__.py +1 -0
- Cython/Runtime/refnanny.pyd +0 -0
- Cython/Runtime/refnanny.pyx +237 -0
- Cython/Shadow.py +690 -0
- Cython/Shadow.pyi +521 -0
- Cython/StringIOTree.py +170 -0
- Cython/StringIOTree.pyd +0 -0
- Cython/Tempita/__init__.py +4 -0
- Cython/Tempita/_looper.py +154 -0
- Cython/Tempita/_tempita.py +1091 -0
- Cython/Tempita/_tempita.pyd +0 -0
- Cython/TestUtils.py +422 -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 +1031 -0
- Cython/Utility/Buffer.c +865 -0
- Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
- Cython/Utility/Builtins.c +810 -0
- Cython/Utility/CConvert.pyx +134 -0
- Cython/Utility/CMath.c +104 -0
- Cython/Utility/CommonStructures.c +226 -0
- Cython/Utility/Complex.c +378 -0
- Cython/Utility/Coroutine.c +2300 -0
- Cython/Utility/CpdefEnums.pyx +103 -0
- Cython/Utility/CppConvert.pyx +282 -0
- Cython/Utility/CppSupport.cpp +151 -0
- Cython/Utility/CythonFunction.c +1832 -0
- Cython/Utility/Dataclasses.c +101 -0
- Cython/Utility/Embed.c +121 -0
- Cython/Utility/Exceptions.c +1016 -0
- Cython/Utility/ExtensionTypes.c +996 -0
- Cython/Utility/FunctionArguments.c +1043 -0
- Cython/Utility/FusedFunction.pyx +44 -0
- Cython/Utility/ImportExport.c +907 -0
- Cython/Utility/MemoryView.pxd +188 -0
- Cython/Utility/MemoryView.pyx +1482 -0
- Cython/Utility/MemoryView_C.c +927 -0
- Cython/Utility/ModuleSetupCode.c +3203 -0
- Cython/Utility/NumpyImportArray.c +46 -0
- Cython/Utility/ObjectHandling.c +3273 -0
- Cython/Utility/Optimize.c +1603 -0
- Cython/Utility/Overflow.c +384 -0
- Cython/Utility/Printing.c +86 -0
- Cython/Utility/Profile.c +732 -0
- Cython/Utility/StringTools.c +1379 -0
- Cython/Utility/Synchronization.c +399 -0
- Cython/Utility/TString.c +356 -0
- Cython/Utility/TestCyUtilityLoader.pyx +8 -0
- Cython/Utility/TestCythonScope.pyx +75 -0
- Cython/Utility/TestUtilityLoader.c +12 -0
- Cython/Utility/TypeConversion.c +1385 -0
- Cython/Utility/UFuncs.pyx +50 -0
- Cython/Utility/UFuncs_C.c +89 -0
- Cython/Utility/__init__.py +28 -0
- Cython/Utility/arrayarray.h +167 -0
- Cython/Utils.py +687 -0
- Cython/Utils.pyd +0 -0
- Cython/__init__.py +10 -0
- Cython/__init__.pyi +7 -0
- Cython/py.typed +0 -0
- cython-3.2.0.dist-info/METADATA +85 -0
- cython-3.2.0.dist-info/RECORD +333 -0
- cython-3.2.0.dist-info/WHEEL +5 -0
- cython-3.2.0.dist-info/entry_points.txt +4 -0
- cython-3.2.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
Cython/Shadow.py
ADDED
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
# cython.* namespace for pure mode.
|
|
2
|
+
|
|
3
|
+
# Possible version formats: "3.1.0", "3.1.0a1", "3.1.0a1.dev0"
|
|
4
|
+
__version__ = "3.2.0"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# BEGIN shameless copy from Cython/minivect/minitypes.py
|
|
8
|
+
|
|
9
|
+
class _ArrayType:
|
|
10
|
+
|
|
11
|
+
is_array = True
|
|
12
|
+
subtypes = ['dtype']
|
|
13
|
+
|
|
14
|
+
def __init__(self, dtype, ndim, is_c_contig=False, is_f_contig=False,
|
|
15
|
+
inner_contig=False, broadcasting=None):
|
|
16
|
+
self.dtype = dtype
|
|
17
|
+
self.ndim = ndim
|
|
18
|
+
self.is_c_contig = is_c_contig
|
|
19
|
+
self.is_f_contig = is_f_contig
|
|
20
|
+
self.inner_contig = inner_contig or is_c_contig or is_f_contig
|
|
21
|
+
self.broadcasting = broadcasting
|
|
22
|
+
|
|
23
|
+
def __repr__(self):
|
|
24
|
+
axes = [":"] * self.ndim
|
|
25
|
+
if self.is_c_contig:
|
|
26
|
+
axes[-1] = "::1"
|
|
27
|
+
elif self.is_f_contig:
|
|
28
|
+
axes[0] = "::1"
|
|
29
|
+
|
|
30
|
+
return "%s[%s]" % (self.dtype, ", ".join(axes))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def index_type(base_type, item):
|
|
34
|
+
"""
|
|
35
|
+
Support array type creation by slicing, e.g. double[:, :] specifies
|
|
36
|
+
a 2D strided array of doubles. The syntax is the same as for
|
|
37
|
+
Cython memoryviews.
|
|
38
|
+
"""
|
|
39
|
+
class InvalidTypeSpecification(Exception):
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
def verify_slice(s):
|
|
43
|
+
if s.start or s.stop or s.step not in (None, 1):
|
|
44
|
+
raise InvalidTypeSpecification(
|
|
45
|
+
"Only a step of 1 may be provided to indicate C or "
|
|
46
|
+
"Fortran contiguity")
|
|
47
|
+
|
|
48
|
+
if isinstance(item, tuple):
|
|
49
|
+
step_idx = None
|
|
50
|
+
for idx, s in enumerate(item):
|
|
51
|
+
verify_slice(s)
|
|
52
|
+
if s.step and (step_idx or idx not in (0, len(item) - 1)):
|
|
53
|
+
raise InvalidTypeSpecification(
|
|
54
|
+
"Step may only be provided once, and only in the "
|
|
55
|
+
"first or last dimension.")
|
|
56
|
+
|
|
57
|
+
if s.step == 1:
|
|
58
|
+
step_idx = idx
|
|
59
|
+
|
|
60
|
+
return _ArrayType(base_type, len(item),
|
|
61
|
+
is_c_contig=step_idx == len(item) - 1,
|
|
62
|
+
is_f_contig=step_idx == 0)
|
|
63
|
+
elif isinstance(item, slice):
|
|
64
|
+
verify_slice(item)
|
|
65
|
+
return _ArrayType(base_type, 1, is_c_contig=bool(item.step))
|
|
66
|
+
else:
|
|
67
|
+
# int[8] etc.
|
|
68
|
+
assert int(item) == item # array size must be a plain integer
|
|
69
|
+
return array(base_type, item)
|
|
70
|
+
|
|
71
|
+
# END shameless copy
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
compiled = False
|
|
75
|
+
|
|
76
|
+
_Unspecified = object()
|
|
77
|
+
|
|
78
|
+
# Function decorators
|
|
79
|
+
|
|
80
|
+
def _empty_decorator(x):
|
|
81
|
+
return x
|
|
82
|
+
|
|
83
|
+
def locals(**arg_types):
|
|
84
|
+
return _empty_decorator
|
|
85
|
+
|
|
86
|
+
def test_assert_path_exists(*paths):
|
|
87
|
+
return _empty_decorator
|
|
88
|
+
|
|
89
|
+
def test_fail_if_path_exists(*paths):
|
|
90
|
+
return _empty_decorator
|
|
91
|
+
|
|
92
|
+
class _EmptyDecoratorAndManager:
|
|
93
|
+
def __call__(self, x):
|
|
94
|
+
return x
|
|
95
|
+
def __enter__(self):
|
|
96
|
+
pass
|
|
97
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
98
|
+
pass
|
|
99
|
+
|
|
100
|
+
class _Optimization:
|
|
101
|
+
pass
|
|
102
|
+
|
|
103
|
+
cclass = ccall = cfunc = _EmptyDecoratorAndManager()
|
|
104
|
+
|
|
105
|
+
annotation_typing = returns = wraparound = boundscheck = initializedcheck = \
|
|
106
|
+
nonecheck = embedsignature = cdivision = cdivision_warnings = \
|
|
107
|
+
always_allow_keywords = profile = linetrace = infer_types = \
|
|
108
|
+
unraisable_tracebacks = freelist = auto_pickle = cpow = trashcan = \
|
|
109
|
+
auto_cpdef = c_api_binop_methods = \
|
|
110
|
+
allow_none_for_extension_args = callspec = show_performance_hints = \
|
|
111
|
+
cpp_locals = py2_import = iterable_coroutine = remove_unreachable = \
|
|
112
|
+
overflowcheck = test_body_needs_exception_handling = \
|
|
113
|
+
lambda _: _EmptyDecoratorAndManager()
|
|
114
|
+
|
|
115
|
+
# Note that fast_getattr is untested and undocumented!
|
|
116
|
+
fast_getattr = lambda _: _EmptyDecoratorAndManager()
|
|
117
|
+
# c_compile_guard is largely for internal use
|
|
118
|
+
c_compile_guard = lambda _:_EmptyDecoratorAndManager()
|
|
119
|
+
|
|
120
|
+
exceptval = lambda _=None, check=True: _EmptyDecoratorAndManager()
|
|
121
|
+
|
|
122
|
+
optimize = _Optimization()
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
embedsignature.format = overflowcheck.fold = optimize.use_switch = \
|
|
126
|
+
optimize.unpack_method_calls = lambda arg: _EmptyDecoratorAndManager()
|
|
127
|
+
|
|
128
|
+
final = internal = type_version_tag = no_gc_clear = no_gc = total_ordering = \
|
|
129
|
+
ufunc = _empty_decorator
|
|
130
|
+
|
|
131
|
+
binding = lambda _: _empty_decorator
|
|
132
|
+
|
|
133
|
+
class warn:
|
|
134
|
+
undeclared = unreachable = maybe_uninitialized = unused = \
|
|
135
|
+
unused_arg = unused_result = \
|
|
136
|
+
lambda _: _EmptyDecoratorAndManager()
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
_cython_inline = None
|
|
140
|
+
def inline(f, *args, **kwds):
|
|
141
|
+
if isinstance(f, str):
|
|
142
|
+
global _cython_inline
|
|
143
|
+
if _cython_inline is None:
|
|
144
|
+
from Cython.Build.Inline import cython_inline as _cython_inline
|
|
145
|
+
return _cython_inline(f, *args, **kwds)
|
|
146
|
+
else:
|
|
147
|
+
assert len(args) == len(kwds) == 0
|
|
148
|
+
return f
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def compile(f):
|
|
152
|
+
from Cython.Build.Inline import RuntimeCompiledFunction
|
|
153
|
+
return RuntimeCompiledFunction(f)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
# Special functions
|
|
157
|
+
|
|
158
|
+
def cdiv(a, b):
|
|
159
|
+
if a < 0:
|
|
160
|
+
a = -a
|
|
161
|
+
b = -b
|
|
162
|
+
if b < 0:
|
|
163
|
+
return (a + b + 1) // b
|
|
164
|
+
return a // b
|
|
165
|
+
|
|
166
|
+
def cmod(a, b):
|
|
167
|
+
r = a % b
|
|
168
|
+
if (a * b) < 0 and r:
|
|
169
|
+
r -= b
|
|
170
|
+
return r
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
# Emulated language constructs
|
|
174
|
+
|
|
175
|
+
def cast(t, *args, **kwargs):
|
|
176
|
+
kwargs.pop('typecheck', None)
|
|
177
|
+
assert not kwargs
|
|
178
|
+
|
|
179
|
+
if isinstance(t, typedef):
|
|
180
|
+
return t(*args)
|
|
181
|
+
elif isinstance(t, type): # Doesn't work with old-style classes of Python 2.x
|
|
182
|
+
if len(args) != 1 or not (args[0] is None or isinstance(args[0], t)):
|
|
183
|
+
return t(*args)
|
|
184
|
+
|
|
185
|
+
return args[0]
|
|
186
|
+
|
|
187
|
+
def sizeof(arg):
|
|
188
|
+
return 1
|
|
189
|
+
|
|
190
|
+
def typeof(arg):
|
|
191
|
+
return arg.__class__.__name__
|
|
192
|
+
# return type(arg)
|
|
193
|
+
|
|
194
|
+
def address(arg):
|
|
195
|
+
return pointer(type(arg))([arg])
|
|
196
|
+
|
|
197
|
+
def _is_value_type(t):
|
|
198
|
+
if isinstance(t, typedef):
|
|
199
|
+
return _is_value_type(t._basetype)
|
|
200
|
+
|
|
201
|
+
return isinstance(t, type) and issubclass(t, (StructType, UnionType, ArrayType))
|
|
202
|
+
|
|
203
|
+
def declare(t=None, value=_Unspecified, **kwds):
|
|
204
|
+
if value is not _Unspecified:
|
|
205
|
+
return cast(t, value)
|
|
206
|
+
elif _is_value_type(t):
|
|
207
|
+
return t()
|
|
208
|
+
else:
|
|
209
|
+
return None
|
|
210
|
+
|
|
211
|
+
class _nogil:
|
|
212
|
+
"""Support for 'with nogil' statement and @nogil decorator.
|
|
213
|
+
"""
|
|
214
|
+
def __call__(self, x):
|
|
215
|
+
if callable(x):
|
|
216
|
+
# Used as function decorator => return the function unchanged.
|
|
217
|
+
return x
|
|
218
|
+
# Used as conditional context manager or to create an "@nogil(True/False)" decorator => keep going.
|
|
219
|
+
return self
|
|
220
|
+
|
|
221
|
+
def __enter__(self):
|
|
222
|
+
pass
|
|
223
|
+
def __exit__(self, exc_class, exc, tb):
|
|
224
|
+
return exc_class is None
|
|
225
|
+
|
|
226
|
+
nogil = _nogil()
|
|
227
|
+
gil = _nogil()
|
|
228
|
+
with_gil = _nogil() # Actually not a context manager, but compilation will give the right error.
|
|
229
|
+
del _nogil
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
class critical_section:
|
|
233
|
+
def __init__(self, arg0, arg1=None):
|
|
234
|
+
# It's ambiguous if this is being used as a decorator or context manager
|
|
235
|
+
# even with a callable arg.
|
|
236
|
+
self.arg0 = arg0
|
|
237
|
+
def __call__(self, *args, **kwds):
|
|
238
|
+
return self.arg0(*args, **kwds)
|
|
239
|
+
def __enter__(self):
|
|
240
|
+
pass
|
|
241
|
+
def __exit__(self, exc_class, exc, tb):
|
|
242
|
+
return False
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
# Emulated types
|
|
246
|
+
|
|
247
|
+
class CythonMetaType(type):
|
|
248
|
+
|
|
249
|
+
def __getitem__(type, ix):
|
|
250
|
+
return array(type, ix)
|
|
251
|
+
|
|
252
|
+
CythonTypeObject = CythonMetaType('CythonTypeObject', (object,), {})
|
|
253
|
+
|
|
254
|
+
class CythonType(CythonTypeObject):
|
|
255
|
+
|
|
256
|
+
def _pointer(self, n=1):
|
|
257
|
+
for i in range(n):
|
|
258
|
+
self = pointer(self)
|
|
259
|
+
return self
|
|
260
|
+
|
|
261
|
+
class PointerType(CythonType):
|
|
262
|
+
|
|
263
|
+
def __init__(self, value=None):
|
|
264
|
+
if isinstance(value, (ArrayType, PointerType)):
|
|
265
|
+
self._items = [cast(self._basetype, a) for a in value._items]
|
|
266
|
+
elif isinstance(value, list):
|
|
267
|
+
self._items = [cast(self._basetype, a) for a in value]
|
|
268
|
+
elif value is None or value == 0:
|
|
269
|
+
self._items = []
|
|
270
|
+
else:
|
|
271
|
+
raise ValueError
|
|
272
|
+
|
|
273
|
+
def __getitem__(self, ix):
|
|
274
|
+
if ix < 0:
|
|
275
|
+
raise IndexError("negative indexing not allowed in C")
|
|
276
|
+
return self._items[ix]
|
|
277
|
+
|
|
278
|
+
def __setitem__(self, ix, value):
|
|
279
|
+
if ix < 0:
|
|
280
|
+
raise IndexError("negative indexing not allowed in C")
|
|
281
|
+
self._items[ix] = cast(self._basetype, value)
|
|
282
|
+
|
|
283
|
+
def __eq__(self, value):
|
|
284
|
+
if value is None and not self._items:
|
|
285
|
+
return True
|
|
286
|
+
elif type(self) != type(value):
|
|
287
|
+
return False
|
|
288
|
+
else:
|
|
289
|
+
return not self._items and not value._items
|
|
290
|
+
|
|
291
|
+
def __repr__(self):
|
|
292
|
+
return f"{self._basetype} *"
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
class ArrayType(PointerType):
|
|
296
|
+
|
|
297
|
+
def __init__(self, value=None):
|
|
298
|
+
if value is None:
|
|
299
|
+
self._items = [None] * self._n
|
|
300
|
+
else:
|
|
301
|
+
super().__init__(value)
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
class StructType(CythonType):
|
|
305
|
+
|
|
306
|
+
def __init__(self, *posargs, **data):
|
|
307
|
+
if not (posargs or data):
|
|
308
|
+
return
|
|
309
|
+
if posargs and data:
|
|
310
|
+
raise ValueError('Cannot accept both positional and keyword arguments.')
|
|
311
|
+
|
|
312
|
+
# Allow 'cast_from' as single positional or keyword argument.
|
|
313
|
+
if data and len(data) == 1 and 'cast_from' in data:
|
|
314
|
+
cast_from = data.pop('cast_from')
|
|
315
|
+
elif len(posargs) == 1 and type(posargs[0]) is type(self):
|
|
316
|
+
cast_from, posargs = posargs[0], ()
|
|
317
|
+
elif posargs:
|
|
318
|
+
for key, arg in zip(self._members, posargs):
|
|
319
|
+
setattr(self, key, arg)
|
|
320
|
+
return
|
|
321
|
+
else:
|
|
322
|
+
for key, value in data.items():
|
|
323
|
+
if key not in self._members:
|
|
324
|
+
raise ValueError("Invalid struct attribute for %s: %s" % (
|
|
325
|
+
self.__class__.__name__, key))
|
|
326
|
+
setattr(self, key, value)
|
|
327
|
+
return
|
|
328
|
+
|
|
329
|
+
# do cast
|
|
330
|
+
if data:
|
|
331
|
+
raise ValueError('Cannot accept keyword arguments when casting.')
|
|
332
|
+
if type(cast_from) is not type(self):
|
|
333
|
+
raise ValueError('Cannot cast from %s' % cast_from)
|
|
334
|
+
for key, value in cast_from.__dict__.items():
|
|
335
|
+
setattr(self, key, value)
|
|
336
|
+
|
|
337
|
+
def __setattr__(self, key, value):
|
|
338
|
+
if key in self._members:
|
|
339
|
+
self.__dict__[key] = cast(self._members[key], value)
|
|
340
|
+
else:
|
|
341
|
+
raise AttributeError("Struct has no member '%s'" % key)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
class UnionType(CythonType):
|
|
345
|
+
|
|
346
|
+
def __init__(self, cast_from=_Unspecified, **data):
|
|
347
|
+
if cast_from is not _Unspecified:
|
|
348
|
+
# do type cast
|
|
349
|
+
if len(data) > 0:
|
|
350
|
+
raise ValueError('Cannot accept keyword arguments when casting.')
|
|
351
|
+
if isinstance(cast_from, dict):
|
|
352
|
+
datadict = cast_from
|
|
353
|
+
elif type(cast_from) is type(self):
|
|
354
|
+
datadict = cast_from.__dict__
|
|
355
|
+
else:
|
|
356
|
+
raise ValueError('Cannot cast from %s' % cast_from)
|
|
357
|
+
else:
|
|
358
|
+
datadict = data
|
|
359
|
+
if len(datadict) > 1:
|
|
360
|
+
raise AttributeError("Union can only store one field at a time.")
|
|
361
|
+
for key, value in datadict.items():
|
|
362
|
+
setattr(self, key, value)
|
|
363
|
+
|
|
364
|
+
def __setattr__(self, key, value):
|
|
365
|
+
if key == '__dict__':
|
|
366
|
+
CythonType.__setattr__(self, key, value)
|
|
367
|
+
elif key in self._members:
|
|
368
|
+
self.__dict__ = {key: cast(self._members[key], value)}
|
|
369
|
+
else:
|
|
370
|
+
raise AttributeError("Union has no member '%s'" % key)
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
class pointer(PointerType):
|
|
374
|
+
# Implemented as class to support both 'pointer(int)' and 'pointer[int]'.
|
|
375
|
+
def __new__(cls, basetype):
|
|
376
|
+
class PointerInstance(PointerType):
|
|
377
|
+
_basetype = basetype
|
|
378
|
+
return PointerInstance
|
|
379
|
+
|
|
380
|
+
def __class_getitem__(cls, basetype):
|
|
381
|
+
return cls(basetype)
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
class array(ArrayType):
|
|
385
|
+
# Implemented as class to support both 'array(int, 5)' and 'array[int, 5]'.
|
|
386
|
+
def __new__(cls, basetype, n):
|
|
387
|
+
class ArrayInstance(ArrayType):
|
|
388
|
+
_basetype = basetype
|
|
389
|
+
_n = n
|
|
390
|
+
return ArrayInstance
|
|
391
|
+
|
|
392
|
+
def __class_getitem__(cls, item):
|
|
393
|
+
basetype, n = item
|
|
394
|
+
return cls(basetype, item)
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def struct(**members):
|
|
398
|
+
class StructInstance(StructType):
|
|
399
|
+
_members = members
|
|
400
|
+
for key in members:
|
|
401
|
+
setattr(StructInstance, key, None)
|
|
402
|
+
return StructInstance
|
|
403
|
+
|
|
404
|
+
def union(**members):
|
|
405
|
+
class UnionInstance(UnionType):
|
|
406
|
+
_members = members
|
|
407
|
+
for key in members:
|
|
408
|
+
setattr(UnionInstance, key, None)
|
|
409
|
+
return UnionInstance
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
class typedef(CythonType):
|
|
413
|
+
|
|
414
|
+
def __init__(self, type, name=None):
|
|
415
|
+
self._basetype = type
|
|
416
|
+
self.name = name
|
|
417
|
+
|
|
418
|
+
def __call__(self, *arg):
|
|
419
|
+
value = cast(self._basetype, *arg)
|
|
420
|
+
return value
|
|
421
|
+
|
|
422
|
+
def __repr__(self):
|
|
423
|
+
return self.name or str(self._basetype)
|
|
424
|
+
|
|
425
|
+
__getitem__ = index_type
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
class const(typedef):
|
|
429
|
+
def __init__(self, type, name=None):
|
|
430
|
+
name = f"const {name or repr(type)}"
|
|
431
|
+
super().__init__(type, name)
|
|
432
|
+
|
|
433
|
+
def __class_getitem__(cls, base_type):
|
|
434
|
+
return const(base_type)
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
class volatile(typedef):
|
|
438
|
+
def __init__(self, type, name=None):
|
|
439
|
+
name = f"volatile {name or repr(type)}"
|
|
440
|
+
super().__init__(type, name)
|
|
441
|
+
|
|
442
|
+
def __class_getitem__(cls, base_type):
|
|
443
|
+
return volatile(base_type)
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
class _FusedType(CythonType):
|
|
447
|
+
__getitem__ = index_type
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def fused_type(*args):
|
|
451
|
+
if not args:
|
|
452
|
+
raise TypeError("Expected at least one type as argument")
|
|
453
|
+
|
|
454
|
+
# Find the numeric type with biggest rank if all types are numeric
|
|
455
|
+
rank = -1
|
|
456
|
+
for type in args:
|
|
457
|
+
if type not in (py_int, py_long, py_float, py_complex):
|
|
458
|
+
break
|
|
459
|
+
|
|
460
|
+
if type_ordering.index(type) > rank:
|
|
461
|
+
result_type = type
|
|
462
|
+
else:
|
|
463
|
+
return result_type
|
|
464
|
+
|
|
465
|
+
# Not a simple numeric type, return a fused type instance. The result
|
|
466
|
+
# isn't really meant to be used, as we can't keep track of the context in
|
|
467
|
+
# pure-mode. Casting won't do anything in this case.
|
|
468
|
+
return _FusedType()
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
def _specialized_from_args(signatures, args, kwargs):
|
|
472
|
+
"Perhaps this should be implemented in a TreeFragment in Cython code"
|
|
473
|
+
raise Exception("yet to be implemented")
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
py_int = typedef(int, "int")
|
|
477
|
+
py_long = typedef(int, "long") # for legacy Py2 code only
|
|
478
|
+
py_float = typedef(float, "float")
|
|
479
|
+
py_complex = typedef(complex, "double complex")
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
# Predefined types
|
|
483
|
+
|
|
484
|
+
int_types = [
|
|
485
|
+
'char',
|
|
486
|
+
'short',
|
|
487
|
+
'Py_UNICODE',
|
|
488
|
+
'int',
|
|
489
|
+
'Py_UCS4',
|
|
490
|
+
'long',
|
|
491
|
+
'longlong',
|
|
492
|
+
'Py_hash_t',
|
|
493
|
+
'Py_ssize_t',
|
|
494
|
+
'size_t',
|
|
495
|
+
'ssize_t',
|
|
496
|
+
'ptrdiff_t',
|
|
497
|
+
]
|
|
498
|
+
float_types = [
|
|
499
|
+
'longdouble',
|
|
500
|
+
'double',
|
|
501
|
+
'float',
|
|
502
|
+
]
|
|
503
|
+
complex_types = [
|
|
504
|
+
'longdoublecomplex',
|
|
505
|
+
'doublecomplex',
|
|
506
|
+
'floatcomplex',
|
|
507
|
+
'complex',
|
|
508
|
+
]
|
|
509
|
+
other_types = [
|
|
510
|
+
'bint',
|
|
511
|
+
'void',
|
|
512
|
+
'Py_tss_t',
|
|
513
|
+
]
|
|
514
|
+
|
|
515
|
+
to_repr = {
|
|
516
|
+
'longlong': 'long long',
|
|
517
|
+
'longdouble': 'long double',
|
|
518
|
+
'longdoublecomplex': 'long double complex',
|
|
519
|
+
'doublecomplex': 'double complex',
|
|
520
|
+
'floatcomplex': 'float complex',
|
|
521
|
+
}.get
|
|
522
|
+
|
|
523
|
+
gs = globals()
|
|
524
|
+
|
|
525
|
+
gs['unicode'] = typedef(str, 'unicode')
|
|
526
|
+
|
|
527
|
+
for name in int_types:
|
|
528
|
+
reprname = to_repr(name, name)
|
|
529
|
+
gs[name] = typedef(py_int, reprname)
|
|
530
|
+
if name not in ('Py_UNICODE', 'Py_UCS4', 'Py_hash_t', 'ptrdiff_t') and not name.endswith('size_t'):
|
|
531
|
+
gs['u'+name] = typedef(py_int, "unsigned " + reprname)
|
|
532
|
+
gs['s'+name] = typedef(py_int, "signed " + reprname)
|
|
533
|
+
|
|
534
|
+
for name in float_types:
|
|
535
|
+
gs[name] = typedef(py_float, to_repr(name, name))
|
|
536
|
+
|
|
537
|
+
for name in complex_types:
|
|
538
|
+
gs[name] = typedef(py_complex, to_repr(name, name))
|
|
539
|
+
|
|
540
|
+
del name, reprname
|
|
541
|
+
|
|
542
|
+
bint = typedef(bool, "bint")
|
|
543
|
+
void = typedef(None, "void")
|
|
544
|
+
Py_tss_t = typedef(None, "Py_tss_t")
|
|
545
|
+
|
|
546
|
+
# Generate const types.
|
|
547
|
+
for t in int_types + float_types + complex_types + other_types:
|
|
548
|
+
for t in (t, f'u{t}', f's{t}'):
|
|
549
|
+
if t in gs:
|
|
550
|
+
gs[f"const_{t}"] = const(gs[t], t)
|
|
551
|
+
|
|
552
|
+
# Generate pointer types: p_int, p_const_char, etc.
|
|
553
|
+
for i in range(1, 4):
|
|
554
|
+
for const_ in ('', 'const_'):
|
|
555
|
+
for t in int_types:
|
|
556
|
+
for t in (t, f'u{t}', f's{t}'):
|
|
557
|
+
if t in gs:
|
|
558
|
+
gs[f"{'p'*i}_{const_}{t}"] = pointer(gs[f"{'p'*(i-1)}{'_' if i > 1 else ''}{const_}{t}"])
|
|
559
|
+
|
|
560
|
+
for t in float_types + complex_types:
|
|
561
|
+
gs[f"{'p'*i}_{const_}{t}"] = pointer(gs[f"{'p'*(i-1)}{'_' if i > 1 else ''}{const_}{t}"])
|
|
562
|
+
|
|
563
|
+
gs[f"{'p'*i}_const_bint"] = pointer(gs[f"{'p'*(i-1)}{'_' if i > 1 else ''}const_bint"])
|
|
564
|
+
for t in other_types:
|
|
565
|
+
gs[f"{'p'*i}_{t}"] = pointer(gs[f"{'p'*(i-1)}{'_' if i > 1 else ''}{t}"])
|
|
566
|
+
|
|
567
|
+
del t, const_, i
|
|
568
|
+
|
|
569
|
+
NULL = gs['p_void'](0)
|
|
570
|
+
|
|
571
|
+
del gs
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
def __getattr__(name):
|
|
575
|
+
# looks like 'gs' has some users out there by now...
|
|
576
|
+
if name == 'gs':
|
|
577
|
+
import warnings
|
|
578
|
+
warnings.warn(
|
|
579
|
+
"'gs' is not a publicly exposed name in cython.*. Use vars() or globals() instead.",
|
|
580
|
+
DeprecationWarning)
|
|
581
|
+
return globals()
|
|
582
|
+
raise AttributeError(f"'cython' has no attribute {name!r}")
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
integral = floating = numeric = _FusedType()
|
|
586
|
+
|
|
587
|
+
type_ordering = [py_int, py_long, py_float, py_complex]
|
|
588
|
+
|
|
589
|
+
class CythonDotParallel:
|
|
590
|
+
"""
|
|
591
|
+
The cython.parallel module.
|
|
592
|
+
"""
|
|
593
|
+
|
|
594
|
+
__all__ = ['parallel', 'prange', 'threadid']
|
|
595
|
+
|
|
596
|
+
def parallel(self, num_threads=None):
|
|
597
|
+
return nogil
|
|
598
|
+
|
|
599
|
+
def prange(self, start=0, stop=None, step=1, nogil=False, schedule=None, chunksize=None, num_threads=None):
|
|
600
|
+
if stop is None:
|
|
601
|
+
stop = start
|
|
602
|
+
start = 0
|
|
603
|
+
return range(start, stop, step)
|
|
604
|
+
|
|
605
|
+
def threadid(self):
|
|
606
|
+
return 0
|
|
607
|
+
|
|
608
|
+
# def threadsavailable(self):
|
|
609
|
+
# return 1
|
|
610
|
+
|
|
611
|
+
class CythonDotImportedFromElsewhere:
|
|
612
|
+
"""
|
|
613
|
+
cython.dataclasses just shadows the standard library modules of the same name
|
|
614
|
+
"""
|
|
615
|
+
def __init__(self, module):
|
|
616
|
+
self.__path__ = []
|
|
617
|
+
self.__file__ = None
|
|
618
|
+
self.__name__ = module
|
|
619
|
+
self.__package__ = module
|
|
620
|
+
|
|
621
|
+
def __getattr__(self, attr):
|
|
622
|
+
# we typically only expect this to be called once
|
|
623
|
+
from importlib import import_module
|
|
624
|
+
import sys
|
|
625
|
+
try:
|
|
626
|
+
mod = import_module(self.__name__)
|
|
627
|
+
except ImportError:
|
|
628
|
+
# but if they don't exist (Python is not sufficiently up-to-date) then
|
|
629
|
+
# you can't use them
|
|
630
|
+
raise AttributeError("%s: the standard library module %s is not available" %
|
|
631
|
+
(attr, self.__name__))
|
|
632
|
+
sys.modules['cython.%s' % self.__name__] = mod
|
|
633
|
+
return getattr(mod, attr)
|
|
634
|
+
|
|
635
|
+
class CythonCImports:
|
|
636
|
+
"""
|
|
637
|
+
Simplistic module mock to make cimports sort-of work in Python code.
|
|
638
|
+
"""
|
|
639
|
+
def __init__(self, module, **attributes):
|
|
640
|
+
self.__path__ = []
|
|
641
|
+
self.__file__ = None
|
|
642
|
+
self.__name__ = module
|
|
643
|
+
self.__package__ = module
|
|
644
|
+
if attributes:
|
|
645
|
+
self.__dict__.update(attributes)
|
|
646
|
+
|
|
647
|
+
def __getattr__(self, item):
|
|
648
|
+
if item.startswith('__') and item.endswith('__'):
|
|
649
|
+
raise AttributeError(item)
|
|
650
|
+
|
|
651
|
+
package = self.__package__[len('cython.cimports.'):]
|
|
652
|
+
|
|
653
|
+
from importlib import import_module
|
|
654
|
+
try:
|
|
655
|
+
return import_module(item, package or None)
|
|
656
|
+
except ImportError:
|
|
657
|
+
ex = AttributeError(item)
|
|
658
|
+
ex.__cause__ = None
|
|
659
|
+
raise ex
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
import math, sys
|
|
663
|
+
sys.modules['cython.parallel'] = CythonDotParallel()
|
|
664
|
+
sys.modules['cython.cimports.libc.math'] = math
|
|
665
|
+
sys.modules['cython.cimports.libc'] = CythonCImports('cython.cimports.libc', math=math)
|
|
666
|
+
sys.modules['cython.cimports'] = CythonCImports('cython.cimports', libc=sys.modules['cython.cimports.libc'])
|
|
667
|
+
|
|
668
|
+
# In pure Python mode @cython.dataclasses.dataclass and dataclass field should just
|
|
669
|
+
# shadow the standard library ones (if they are available)
|
|
670
|
+
dataclasses = sys.modules['cython.dataclasses'] = CythonDotImportedFromElsewhere('dataclasses')
|
|
671
|
+
del math, sys
|
|
672
|
+
|
|
673
|
+
class pymutex:
|
|
674
|
+
def __init__(self):
|
|
675
|
+
import threading
|
|
676
|
+
self._l = threading.Lock()
|
|
677
|
+
|
|
678
|
+
def acquire(self):
|
|
679
|
+
return self._l.acquire()
|
|
680
|
+
|
|
681
|
+
def release(self):
|
|
682
|
+
return self._l.release()
|
|
683
|
+
|
|
684
|
+
def __enter__(self):
|
|
685
|
+
return self._l.__enter__()
|
|
686
|
+
|
|
687
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
688
|
+
return self._l.__exit__(exc_type, exc_value, traceback)
|
|
689
|
+
|
|
690
|
+
pythread_type_lock = pymutex
|