numba-cuda 0.21.1__cp313-cp313-win_amd64.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.
- _numba_cuda_redirector.pth +4 -0
- _numba_cuda_redirector.py +89 -0
- numba_cuda/VERSION +1 -0
- numba_cuda/__init__.py +6 -0
- numba_cuda/_version.py +11 -0
- numba_cuda/numba/cuda/__init__.py +70 -0
- numba_cuda/numba/cuda/_internal/cuda_bf16.py +16394 -0
- numba_cuda/numba/cuda/_internal/cuda_fp16.py +8112 -0
- numba_cuda/numba/cuda/api.py +577 -0
- numba_cuda/numba/cuda/api_util.py +76 -0
- numba_cuda/numba/cuda/args.py +72 -0
- numba_cuda/numba/cuda/bf16.py +397 -0
- numba_cuda/numba/cuda/cache_hints.py +287 -0
- numba_cuda/numba/cuda/cext/__init__.py +2 -0
- numba_cuda/numba/cuda/cext/_devicearray.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/_devicearray.cpp +159 -0
- numba_cuda/numba/cuda/cext/_devicearray.h +29 -0
- numba_cuda/numba/cuda/cext/_dispatcher.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/_dispatcher.cpp +1098 -0
- numba_cuda/numba/cuda/cext/_hashtable.cpp +532 -0
- numba_cuda/numba/cuda/cext/_hashtable.h +135 -0
- numba_cuda/numba/cuda/cext/_helperlib.c +71 -0
- numba_cuda/numba/cuda/cext/_helperlib.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/_helpermod.c +82 -0
- numba_cuda/numba/cuda/cext/_pymodule.h +38 -0
- numba_cuda/numba/cuda/cext/_typeconv.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/_typeconv.cpp +206 -0
- numba_cuda/numba/cuda/cext/_typeof.cpp +1159 -0
- numba_cuda/numba/cuda/cext/_typeof.h +19 -0
- numba_cuda/numba/cuda/cext/capsulethunk.h +111 -0
- numba_cuda/numba/cuda/cext/mviewbuf.c +385 -0
- numba_cuda/numba/cuda/cext/mviewbuf.cp313-win_amd64.pyd +0 -0
- numba_cuda/numba/cuda/cext/typeconv.cpp +212 -0
- numba_cuda/numba/cuda/cext/typeconv.hpp +101 -0
- numba_cuda/numba/cuda/cg.py +67 -0
- numba_cuda/numba/cuda/cgutils.py +1294 -0
- numba_cuda/numba/cuda/cloudpickle/__init__.py +21 -0
- numba_cuda/numba/cuda/cloudpickle/cloudpickle.py +1598 -0
- numba_cuda/numba/cuda/cloudpickle/cloudpickle_fast.py +17 -0
- numba_cuda/numba/cuda/codegen.py +541 -0
- numba_cuda/numba/cuda/compiler.py +1396 -0
- numba_cuda/numba/cuda/core/analysis.py +758 -0
- numba_cuda/numba/cuda/core/annotations/__init__.py +0 -0
- numba_cuda/numba/cuda/core/annotations/pretty_annotate.py +288 -0
- numba_cuda/numba/cuda/core/annotations/type_annotations.py +305 -0
- numba_cuda/numba/cuda/core/base.py +1332 -0
- numba_cuda/numba/cuda/core/boxing.py +1411 -0
- numba_cuda/numba/cuda/core/bytecode.py +728 -0
- numba_cuda/numba/cuda/core/byteflow.py +2346 -0
- numba_cuda/numba/cuda/core/caching.py +744 -0
- numba_cuda/numba/cuda/core/callconv.py +392 -0
- numba_cuda/numba/cuda/core/codegen.py +171 -0
- numba_cuda/numba/cuda/core/compiler.py +199 -0
- numba_cuda/numba/cuda/core/compiler_lock.py +85 -0
- numba_cuda/numba/cuda/core/compiler_machinery.py +497 -0
- numba_cuda/numba/cuda/core/config.py +650 -0
- numba_cuda/numba/cuda/core/consts.py +124 -0
- numba_cuda/numba/cuda/core/controlflow.py +989 -0
- numba_cuda/numba/cuda/core/entrypoints.py +57 -0
- numba_cuda/numba/cuda/core/environment.py +66 -0
- numba_cuda/numba/cuda/core/errors.py +917 -0
- numba_cuda/numba/cuda/core/event.py +511 -0
- numba_cuda/numba/cuda/core/funcdesc.py +330 -0
- numba_cuda/numba/cuda/core/generators.py +387 -0
- numba_cuda/numba/cuda/core/imputils.py +509 -0
- numba_cuda/numba/cuda/core/inline_closurecall.py +1787 -0
- numba_cuda/numba/cuda/core/interpreter.py +3617 -0
- numba_cuda/numba/cuda/core/ir.py +1812 -0
- numba_cuda/numba/cuda/core/ir_utils.py +2638 -0
- numba_cuda/numba/cuda/core/optional.py +129 -0
- numba_cuda/numba/cuda/core/options.py +262 -0
- numba_cuda/numba/cuda/core/postproc.py +249 -0
- numba_cuda/numba/cuda/core/pythonapi.py +1859 -0
- numba_cuda/numba/cuda/core/registry.py +46 -0
- numba_cuda/numba/cuda/core/removerefctpass.py +123 -0
- numba_cuda/numba/cuda/core/rewrites/__init__.py +26 -0
- numba_cuda/numba/cuda/core/rewrites/ir_print.py +91 -0
- numba_cuda/numba/cuda/core/rewrites/registry.py +104 -0
- numba_cuda/numba/cuda/core/rewrites/static_binop.py +41 -0
- numba_cuda/numba/cuda/core/rewrites/static_getitem.py +189 -0
- numba_cuda/numba/cuda/core/rewrites/static_raise.py +100 -0
- numba_cuda/numba/cuda/core/sigutils.py +68 -0
- numba_cuda/numba/cuda/core/ssa.py +498 -0
- numba_cuda/numba/cuda/core/targetconfig.py +330 -0
- numba_cuda/numba/cuda/core/tracing.py +231 -0
- numba_cuda/numba/cuda/core/transforms.py +956 -0
- numba_cuda/numba/cuda/core/typed_passes.py +867 -0
- numba_cuda/numba/cuda/core/typeinfer.py +1950 -0
- numba_cuda/numba/cuda/core/unsafe/__init__.py +0 -0
- numba_cuda/numba/cuda/core/unsafe/bytes.py +67 -0
- numba_cuda/numba/cuda/core/unsafe/eh.py +67 -0
- numba_cuda/numba/cuda/core/unsafe/refcount.py +98 -0
- numba_cuda/numba/cuda/core/untyped_passes.py +1979 -0
- numba_cuda/numba/cuda/cpython/builtins.py +1153 -0
- numba_cuda/numba/cuda/cpython/charseq.py +1218 -0
- numba_cuda/numba/cuda/cpython/cmathimpl.py +560 -0
- numba_cuda/numba/cuda/cpython/enumimpl.py +103 -0
- numba_cuda/numba/cuda/cpython/iterators.py +167 -0
- numba_cuda/numba/cuda/cpython/listobj.py +1326 -0
- numba_cuda/numba/cuda/cpython/mathimpl.py +499 -0
- numba_cuda/numba/cuda/cpython/numbers.py +1475 -0
- numba_cuda/numba/cuda/cpython/rangeobj.py +289 -0
- numba_cuda/numba/cuda/cpython/slicing.py +322 -0
- numba_cuda/numba/cuda/cpython/tupleobj.py +456 -0
- numba_cuda/numba/cuda/cpython/unicode.py +2865 -0
- numba_cuda/numba/cuda/cpython/unicode_support.py +1597 -0
- numba_cuda/numba/cuda/cpython/unsafe/__init__.py +0 -0
- numba_cuda/numba/cuda/cpython/unsafe/numbers.py +64 -0
- numba_cuda/numba/cuda/cpython/unsafe/tuple.py +92 -0
- numba_cuda/numba/cuda/cuda_paths.py +691 -0
- numba_cuda/numba/cuda/cudadecl.py +556 -0
- numba_cuda/numba/cuda/cudadrv/__init__.py +14 -0
- numba_cuda/numba/cuda/cudadrv/devicearray.py +951 -0
- numba_cuda/numba/cuda/cudadrv/devices.py +249 -0
- numba_cuda/numba/cuda/cudadrv/driver.py +3222 -0
- numba_cuda/numba/cuda/cudadrv/drvapi.py +435 -0
- numba_cuda/numba/cuda/cudadrv/dummyarray.py +558 -0
- numba_cuda/numba/cuda/cudadrv/enums.py +613 -0
- numba_cuda/numba/cuda/cudadrv/error.py +48 -0
- numba_cuda/numba/cuda/cudadrv/libs.py +220 -0
- numba_cuda/numba/cuda/cudadrv/linkable_code.py +184 -0
- numba_cuda/numba/cuda/cudadrv/mappings.py +14 -0
- numba_cuda/numba/cuda/cudadrv/ndarray.py +26 -0
- numba_cuda/numba/cuda/cudadrv/nvrtc.py +193 -0
- numba_cuda/numba/cuda/cudadrv/nvvm.py +756 -0
- numba_cuda/numba/cuda/cudadrv/rtapi.py +13 -0
- numba_cuda/numba/cuda/cudadrv/runtime.py +34 -0
- numba_cuda/numba/cuda/cudaimpl.py +995 -0
- numba_cuda/numba/cuda/cudamath.py +149 -0
- numba_cuda/numba/cuda/datamodel/__init__.py +7 -0
- numba_cuda/numba/cuda/datamodel/cuda_manager.py +66 -0
- numba_cuda/numba/cuda/datamodel/cuda_models.py +1446 -0
- numba_cuda/numba/cuda/datamodel/cuda_packer.py +224 -0
- numba_cuda/numba/cuda/datamodel/cuda_registry.py +22 -0
- numba_cuda/numba/cuda/datamodel/cuda_testing.py +153 -0
- numba_cuda/numba/cuda/datamodel/manager.py +11 -0
- numba_cuda/numba/cuda/datamodel/models.py +9 -0
- numba_cuda/numba/cuda/datamodel/packer.py +9 -0
- numba_cuda/numba/cuda/datamodel/registry.py +11 -0
- numba_cuda/numba/cuda/datamodel/testing.py +11 -0
- numba_cuda/numba/cuda/debuginfo.py +903 -0
- numba_cuda/numba/cuda/decorators.py +294 -0
- numba_cuda/numba/cuda/descriptor.py +35 -0
- numba_cuda/numba/cuda/device_init.py +158 -0
- numba_cuda/numba/cuda/deviceufunc.py +1021 -0
- numba_cuda/numba/cuda/dispatcher.py +2463 -0
- numba_cuda/numba/cuda/errors.py +72 -0
- numba_cuda/numba/cuda/extending.py +697 -0
- numba_cuda/numba/cuda/flags.py +178 -0
- numba_cuda/numba/cuda/fp16.py +357 -0
- numba_cuda/numba/cuda/include/12/cuda_bf16.h +5118 -0
- numba_cuda/numba/cuda/include/12/cuda_bf16.hpp +3865 -0
- numba_cuda/numba/cuda/include/12/cuda_fp16.h +5363 -0
- numba_cuda/numba/cuda/include/12/cuda_fp16.hpp +3483 -0
- numba_cuda/numba/cuda/include/13/cuda_bf16.h +5118 -0
- numba_cuda/numba/cuda/include/13/cuda_bf16.hpp +3865 -0
- numba_cuda/numba/cuda/include/13/cuda_fp16.h +5363 -0
- numba_cuda/numba/cuda/include/13/cuda_fp16.hpp +3483 -0
- numba_cuda/numba/cuda/initialize.py +24 -0
- numba_cuda/numba/cuda/intrinsic_wrapper.py +41 -0
- numba_cuda/numba/cuda/intrinsics.py +382 -0
- numba_cuda/numba/cuda/itanium_mangler.py +214 -0
- numba_cuda/numba/cuda/kernels/__init__.py +2 -0
- numba_cuda/numba/cuda/kernels/reduction.py +265 -0
- numba_cuda/numba/cuda/kernels/transpose.py +65 -0
- numba_cuda/numba/cuda/libdevice.py +3386 -0
- numba_cuda/numba/cuda/libdevicedecl.py +20 -0
- numba_cuda/numba/cuda/libdevicefuncs.py +1060 -0
- numba_cuda/numba/cuda/libdeviceimpl.py +88 -0
- numba_cuda/numba/cuda/locks.py +19 -0
- numba_cuda/numba/cuda/lowering.py +1951 -0
- numba_cuda/numba/cuda/mathimpl.py +374 -0
- numba_cuda/numba/cuda/memory_management/__init__.py +4 -0
- numba_cuda/numba/cuda/memory_management/memsys.cu +99 -0
- numba_cuda/numba/cuda/memory_management/memsys.cuh +22 -0
- numba_cuda/numba/cuda/memory_management/nrt.cu +212 -0
- numba_cuda/numba/cuda/memory_management/nrt.cuh +48 -0
- numba_cuda/numba/cuda/memory_management/nrt.py +390 -0
- numba_cuda/numba/cuda/memory_management/nrt_context.py +438 -0
- numba_cuda/numba/cuda/misc/appdirs.py +594 -0
- numba_cuda/numba/cuda/misc/cffiimpl.py +24 -0
- numba_cuda/numba/cuda/misc/coverage_support.py +43 -0
- numba_cuda/numba/cuda/misc/dump_style.py +41 -0
- numba_cuda/numba/cuda/misc/findlib.py +75 -0
- numba_cuda/numba/cuda/misc/firstlinefinder.py +96 -0
- numba_cuda/numba/cuda/misc/gdb_hook.py +240 -0
- numba_cuda/numba/cuda/misc/literal.py +28 -0
- numba_cuda/numba/cuda/misc/llvm_pass_timings.py +412 -0
- numba_cuda/numba/cuda/misc/special.py +94 -0
- numba_cuda/numba/cuda/models.py +56 -0
- numba_cuda/numba/cuda/np/arraymath.py +5130 -0
- numba_cuda/numba/cuda/np/arrayobj.py +7635 -0
- numba_cuda/numba/cuda/np/extensions.py +11 -0
- numba_cuda/numba/cuda/np/linalg.py +3087 -0
- numba_cuda/numba/cuda/np/math/__init__.py +0 -0
- numba_cuda/numba/cuda/np/math/cmathimpl.py +558 -0
- numba_cuda/numba/cuda/np/math/mathimpl.py +487 -0
- numba_cuda/numba/cuda/np/math/numbers.py +1461 -0
- numba_cuda/numba/cuda/np/npdatetime.py +969 -0
- numba_cuda/numba/cuda/np/npdatetime_helpers.py +217 -0
- numba_cuda/numba/cuda/np/npyfuncs.py +1808 -0
- numba_cuda/numba/cuda/np/npyimpl.py +1027 -0
- numba_cuda/numba/cuda/np/numpy_support.py +798 -0
- numba_cuda/numba/cuda/np/polynomial/__init__.py +4 -0
- numba_cuda/numba/cuda/np/polynomial/polynomial_core.py +242 -0
- numba_cuda/numba/cuda/np/polynomial/polynomial_functions.py +380 -0
- numba_cuda/numba/cuda/np/ufunc/__init__.py +4 -0
- numba_cuda/numba/cuda/np/ufunc/decorators.py +203 -0
- numba_cuda/numba/cuda/np/ufunc/sigparse.py +68 -0
- numba_cuda/numba/cuda/np/ufunc/ufuncbuilder.py +65 -0
- numba_cuda/numba/cuda/np/ufunc_db.py +1282 -0
- numba_cuda/numba/cuda/np/unsafe/__init__.py +0 -0
- numba_cuda/numba/cuda/np/unsafe/ndarray.py +84 -0
- numba_cuda/numba/cuda/nvvmutils.py +254 -0
- numba_cuda/numba/cuda/printimpl.py +126 -0
- numba_cuda/numba/cuda/random.py +308 -0
- numba_cuda/numba/cuda/reshape_funcs.cu +156 -0
- numba_cuda/numba/cuda/serialize.py +267 -0
- numba_cuda/numba/cuda/simulator/__init__.py +63 -0
- numba_cuda/numba/cuda/simulator/_internal/__init__.py +4 -0
- numba_cuda/numba/cuda/simulator/_internal/cuda_bf16.py +2 -0
- numba_cuda/numba/cuda/simulator/api.py +179 -0
- numba_cuda/numba/cuda/simulator/bf16.py +4 -0
- numba_cuda/numba/cuda/simulator/compiler.py +38 -0
- numba_cuda/numba/cuda/simulator/cudadrv/__init__.py +11 -0
- numba_cuda/numba/cuda/simulator/cudadrv/devicearray.py +462 -0
- numba_cuda/numba/cuda/simulator/cudadrv/devices.py +122 -0
- numba_cuda/numba/cuda/simulator/cudadrv/driver.py +66 -0
- numba_cuda/numba/cuda/simulator/cudadrv/drvapi.py +7 -0
- numba_cuda/numba/cuda/simulator/cudadrv/dummyarray.py +7 -0
- numba_cuda/numba/cuda/simulator/cudadrv/error.py +10 -0
- numba_cuda/numba/cuda/simulator/cudadrv/libs.py +10 -0
- numba_cuda/numba/cuda/simulator/cudadrv/linkable_code.py +61 -0
- numba_cuda/numba/cuda/simulator/cudadrv/nvrtc.py +11 -0
- numba_cuda/numba/cuda/simulator/cudadrv/nvvm.py +32 -0
- numba_cuda/numba/cuda/simulator/cudadrv/runtime.py +22 -0
- numba_cuda/numba/cuda/simulator/dispatcher.py +11 -0
- numba_cuda/numba/cuda/simulator/kernel.py +320 -0
- numba_cuda/numba/cuda/simulator/kernelapi.py +509 -0
- numba_cuda/numba/cuda/simulator/memory_management/__init__.py +4 -0
- numba_cuda/numba/cuda/simulator/memory_management/nrt.py +21 -0
- numba_cuda/numba/cuda/simulator/reduction.py +19 -0
- numba_cuda/numba/cuda/simulator/tests/support.py +4 -0
- numba_cuda/numba/cuda/simulator/vector_types.py +65 -0
- numba_cuda/numba/cuda/simulator_init.py +18 -0
- numba_cuda/numba/cuda/stubs.py +635 -0
- numba_cuda/numba/cuda/target.py +505 -0
- numba_cuda/numba/cuda/testing.py +347 -0
- numba_cuda/numba/cuda/tests/__init__.py +62 -0
- numba_cuda/numba/cuda/tests/benchmarks/__init__.py +0 -0
- numba_cuda/numba/cuda/tests/benchmarks/test_kernel_launch.py +119 -0
- numba_cuda/numba/cuda/tests/cloudpickle_main_class.py +9 -0
- numba_cuda/numba/cuda/tests/core/serialize_usecases.py +113 -0
- numba_cuda/numba/cuda/tests/core/test_itanium_mangler.py +83 -0
- numba_cuda/numba/cuda/tests/core/test_serialize.py +371 -0
- numba_cuda/numba/cuda/tests/cudadrv/__init__.py +9 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_array_attr.py +147 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_context_stack.py +161 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_array_slicing.py +397 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_auto_context.py +24 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_devicerecord.py +180 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_driver.py +313 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_memory.py +187 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +621 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_deallocations.py +247 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_detect.py +100 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_emm_plugins.py +198 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_events.py +53 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_host_alloc.py +72 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_init.py +138 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_inline_ptx.py +43 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_is_fp16.py +15 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_linkable_code.py +58 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_linker.py +348 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_managed_alloc.py +128 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_module_callbacks.py +301 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_nvjitlink.py +174 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_nvrtc.py +28 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_nvvm_driver.py +185 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_pinned.py +39 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_profiler.py +23 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_reset_device.py +38 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_runtime.py +48 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_select_device.py +44 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_streams.py +127 -0
- numba_cuda/numba/cuda/tests/cudapy/__init__.py +9 -0
- numba_cuda/numba/cuda/tests/cudapy/cache_usecases.py +231 -0
- numba_cuda/numba/cuda/tests/cudapy/cache_with_cpu_usecases.py +50 -0
- numba_cuda/numba/cuda/tests/cudapy/cg_cache_usecases.py +36 -0
- numba_cuda/numba/cuda/tests/cudapy/complex_usecases.py +116 -0
- numba_cuda/numba/cuda/tests/cudapy/enum_usecases.py +59 -0
- numba_cuda/numba/cuda/tests/cudapy/extensions_usecases.py +62 -0
- numba_cuda/numba/cuda/tests/cudapy/jitlink.ptx +28 -0
- numba_cuda/numba/cuda/tests/cudapy/overload_usecases.py +33 -0
- numba_cuda/numba/cuda/tests/cudapy/recursion_usecases.py +104 -0
- numba_cuda/numba/cuda/tests/cudapy/test_alignment.py +47 -0
- numba_cuda/numba/cuda/tests/cudapy/test_analysis.py +1122 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array.py +344 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array_alignment.py +268 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array_args.py +203 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array_methods.py +63 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array_reductions.py +360 -0
- numba_cuda/numba/cuda/tests/cudapy/test_atomics.py +1815 -0
- numba_cuda/numba/cuda/tests/cudapy/test_bfloat16.py +599 -0
- numba_cuda/numba/cuda/tests/cudapy/test_bfloat16_bindings.py +377 -0
- numba_cuda/numba/cuda/tests/cudapy/test_blackscholes.py +160 -0
- numba_cuda/numba/cuda/tests/cudapy/test_boolean.py +27 -0
- numba_cuda/numba/cuda/tests/cudapy/test_byteflow.py +98 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cache_hints.py +210 -0
- numba_cuda/numba/cuda/tests/cudapy/test_caching.py +683 -0
- numba_cuda/numba/cuda/tests/cudapy/test_casting.py +265 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cffi.py +42 -0
- numba_cuda/numba/cuda/tests/cudapy/test_compiler.py +718 -0
- numba_cuda/numba/cuda/tests/cudapy/test_complex.py +370 -0
- numba_cuda/numba/cuda/tests/cudapy/test_complex_kernel.py +23 -0
- numba_cuda/numba/cuda/tests/cudapy/test_const_string.py +142 -0
- numba_cuda/numba/cuda/tests/cudapy/test_constmem.py +178 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cooperative_groups.py +193 -0
- numba_cuda/numba/cuda/tests/cudapy/test_copy_propagate.py +131 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cuda_array_interface.py +438 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cuda_jit_no_types.py +94 -0
- numba_cuda/numba/cuda/tests/cudapy/test_datetime.py +101 -0
- numba_cuda/numba/cuda/tests/cudapy/test_debug.py +105 -0
- numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py +889 -0
- numba_cuda/numba/cuda/tests/cudapy/test_debuginfo_types.py +476 -0
- numba_cuda/numba/cuda/tests/cudapy/test_device_func.py +500 -0
- numba_cuda/numba/cuda/tests/cudapy/test_dispatcher.py +820 -0
- numba_cuda/numba/cuda/tests/cudapy/test_enums.py +152 -0
- numba_cuda/numba/cuda/tests/cudapy/test_errors.py +111 -0
- numba_cuda/numba/cuda/tests/cudapy/test_exception.py +170 -0
- numba_cuda/numba/cuda/tests/cudapy/test_extending.py +1088 -0
- numba_cuda/numba/cuda/tests/cudapy/test_extending_types.py +71 -0
- numba_cuda/numba/cuda/tests/cudapy/test_fastmath.py +265 -0
- numba_cuda/numba/cuda/tests/cudapy/test_flow_control.py +1433 -0
- numba_cuda/numba/cuda/tests/cudapy/test_forall.py +57 -0
- numba_cuda/numba/cuda/tests/cudapy/test_freevar.py +34 -0
- numba_cuda/numba/cuda/tests/cudapy/test_frexp_ldexp.py +69 -0
- numba_cuda/numba/cuda/tests/cudapy/test_globals.py +62 -0
- numba_cuda/numba/cuda/tests/cudapy/test_gufunc.py +474 -0
- numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scalar.py +167 -0
- numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scheduling.py +92 -0
- numba_cuda/numba/cuda/tests/cudapy/test_idiv.py +39 -0
- numba_cuda/numba/cuda/tests/cudapy/test_inline.py +170 -0
- numba_cuda/numba/cuda/tests/cudapy/test_inspect.py +255 -0
- numba_cuda/numba/cuda/tests/cudapy/test_intrinsics.py +1219 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ipc.py +263 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ir.py +598 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ir_utils.py +276 -0
- numba_cuda/numba/cuda/tests/cudapy/test_iterators.py +101 -0
- numba_cuda/numba/cuda/tests/cudapy/test_lang.py +68 -0
- numba_cuda/numba/cuda/tests/cudapy/test_laplace.py +123 -0
- numba_cuda/numba/cuda/tests/cudapy/test_libdevice.py +194 -0
- numba_cuda/numba/cuda/tests/cudapy/test_lineinfo.py +220 -0
- numba_cuda/numba/cuda/tests/cudapy/test_localmem.py +173 -0
- numba_cuda/numba/cuda/tests/cudapy/test_make_function_to_jit_function.py +364 -0
- numba_cuda/numba/cuda/tests/cudapy/test_mandel.py +47 -0
- numba_cuda/numba/cuda/tests/cudapy/test_math.py +842 -0
- numba_cuda/numba/cuda/tests/cudapy/test_matmul.py +76 -0
- numba_cuda/numba/cuda/tests/cudapy/test_minmax.py +78 -0
- numba_cuda/numba/cuda/tests/cudapy/test_montecarlo.py +25 -0
- numba_cuda/numba/cuda/tests/cudapy/test_multigpu.py +145 -0
- numba_cuda/numba/cuda/tests/cudapy/test_multiprocessing.py +39 -0
- numba_cuda/numba/cuda/tests/cudapy/test_multithreads.py +82 -0
- numba_cuda/numba/cuda/tests/cudapy/test_nondet.py +53 -0
- numba_cuda/numba/cuda/tests/cudapy/test_operator.py +504 -0
- numba_cuda/numba/cuda/tests/cudapy/test_optimization.py +93 -0
- numba_cuda/numba/cuda/tests/cudapy/test_overload.py +402 -0
- numba_cuda/numba/cuda/tests/cudapy/test_powi.py +128 -0
- numba_cuda/numba/cuda/tests/cudapy/test_print.py +193 -0
- numba_cuda/numba/cuda/tests/cudapy/test_py2_div_issue.py +37 -0
- numba_cuda/numba/cuda/tests/cudapy/test_random.py +117 -0
- numba_cuda/numba/cuda/tests/cudapy/test_record_dtype.py +614 -0
- numba_cuda/numba/cuda/tests/cudapy/test_recursion.py +130 -0
- numba_cuda/numba/cuda/tests/cudapy/test_reduction.py +94 -0
- numba_cuda/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py +83 -0
- numba_cuda/numba/cuda/tests/cudapy/test_serialize.py +86 -0
- numba_cuda/numba/cuda/tests/cudapy/test_slicing.py +40 -0
- numba_cuda/numba/cuda/tests/cudapy/test_sm.py +457 -0
- numba_cuda/numba/cuda/tests/cudapy/test_sm_creation.py +233 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ssa.py +454 -0
- numba_cuda/numba/cuda/tests/cudapy/test_stream_api.py +56 -0
- numba_cuda/numba/cuda/tests/cudapy/test_sync.py +277 -0
- numba_cuda/numba/cuda/tests/cudapy/test_tracing.py +200 -0
- numba_cuda/numba/cuda/tests/cudapy/test_transpose.py +90 -0
- numba_cuda/numba/cuda/tests/cudapy/test_typeconv.py +333 -0
- numba_cuda/numba/cuda/tests/cudapy/test_typeinfer.py +538 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ufuncs.py +585 -0
- numba_cuda/numba/cuda/tests/cudapy/test_userexc.py +42 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vector_type.py +485 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize.py +312 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_complex.py +23 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_decor.py +183 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_device.py +40 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py +40 -0
- numba_cuda/numba/cuda/tests/cudapy/test_warning.py +206 -0
- numba_cuda/numba/cuda/tests/cudapy/test_warp_ops.py +331 -0
- numba_cuda/numba/cuda/tests/cudasim/__init__.py +9 -0
- numba_cuda/numba/cuda/tests/cudasim/support.py +9 -0
- numba_cuda/numba/cuda/tests/cudasim/test_cudasim_issues.py +111 -0
- numba_cuda/numba/cuda/tests/data/__init__.py +2 -0
- numba_cuda/numba/cuda/tests/data/cta_barrier.cu +28 -0
- numba_cuda/numba/cuda/tests/data/cuda_include.cu +10 -0
- numba_cuda/numba/cuda/tests/data/error.cu +12 -0
- numba_cuda/numba/cuda/tests/data/include/add.cuh +8 -0
- numba_cuda/numba/cuda/tests/data/jitlink.cu +28 -0
- numba_cuda/numba/cuda/tests/data/jitlink.ptx +49 -0
- numba_cuda/numba/cuda/tests/data/warn.cu +12 -0
- numba_cuda/numba/cuda/tests/doc_examples/__init__.py +9 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/__init__.py +2 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/functions.cu +54 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/include/mul.cuh +8 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/saxpy.cu +14 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_cg.py +86 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_cpointer.py +68 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_cpu_gpu_compat.py +81 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_ffi.py +141 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_laplace.py +160 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_matmul.py +180 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_montecarlo.py +119 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_random.py +66 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_reduction.py +80 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_sessionize.py +206 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_ufunc.py +53 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_vecadd.py +76 -0
- numba_cuda/numba/cuda/tests/nocuda/__init__.py +9 -0
- numba_cuda/numba/cuda/tests/nocuda/test_dummyarray.py +391 -0
- numba_cuda/numba/cuda/tests/nocuda/test_function_resolution.py +48 -0
- numba_cuda/numba/cuda/tests/nocuda/test_import.py +63 -0
- numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py +252 -0
- numba_cuda/numba/cuda/tests/nocuda/test_nvvm.py +59 -0
- numba_cuda/numba/cuda/tests/nrt/__init__.py +9 -0
- numba_cuda/numba/cuda/tests/nrt/test_nrt.py +387 -0
- numba_cuda/numba/cuda/tests/nrt/test_nrt_refct.py +124 -0
- numba_cuda/numba/cuda/tests/support.py +900 -0
- numba_cuda/numba/cuda/typeconv/__init__.py +4 -0
- numba_cuda/numba/cuda/typeconv/castgraph.py +137 -0
- numba_cuda/numba/cuda/typeconv/rules.py +63 -0
- numba_cuda/numba/cuda/typeconv/typeconv.py +121 -0
- numba_cuda/numba/cuda/types/__init__.py +233 -0
- numba_cuda/numba/cuda/types/__init__.pyi +167 -0
- numba_cuda/numba/cuda/types/abstract.py +9 -0
- numba_cuda/numba/cuda/types/common.py +9 -0
- numba_cuda/numba/cuda/types/containers.py +9 -0
- numba_cuda/numba/cuda/types/cuda_abstract.py +533 -0
- numba_cuda/numba/cuda/types/cuda_common.py +110 -0
- numba_cuda/numba/cuda/types/cuda_containers.py +971 -0
- numba_cuda/numba/cuda/types/cuda_function_type.py +230 -0
- numba_cuda/numba/cuda/types/cuda_functions.py +798 -0
- numba_cuda/numba/cuda/types/cuda_iterators.py +120 -0
- numba_cuda/numba/cuda/types/cuda_misc.py +569 -0
- numba_cuda/numba/cuda/types/cuda_npytypes.py +690 -0
- numba_cuda/numba/cuda/types/cuda_scalars.py +280 -0
- numba_cuda/numba/cuda/types/ext_types.py +101 -0
- numba_cuda/numba/cuda/types/function_type.py +11 -0
- numba_cuda/numba/cuda/types/functions.py +9 -0
- numba_cuda/numba/cuda/types/iterators.py +9 -0
- numba_cuda/numba/cuda/types/misc.py +9 -0
- numba_cuda/numba/cuda/types/npytypes.py +9 -0
- numba_cuda/numba/cuda/types/scalars.py +9 -0
- numba_cuda/numba/cuda/typing/__init__.py +19 -0
- numba_cuda/numba/cuda/typing/arraydecl.py +939 -0
- numba_cuda/numba/cuda/typing/asnumbatype.py +130 -0
- numba_cuda/numba/cuda/typing/bufproto.py +70 -0
- numba_cuda/numba/cuda/typing/builtins.py +1209 -0
- numba_cuda/numba/cuda/typing/cffi_utils.py +219 -0
- numba_cuda/numba/cuda/typing/cmathdecl.py +47 -0
- numba_cuda/numba/cuda/typing/collections.py +138 -0
- numba_cuda/numba/cuda/typing/context.py +782 -0
- numba_cuda/numba/cuda/typing/ctypes_utils.py +125 -0
- numba_cuda/numba/cuda/typing/dictdecl.py +63 -0
- numba_cuda/numba/cuda/typing/enumdecl.py +74 -0
- numba_cuda/numba/cuda/typing/listdecl.py +147 -0
- numba_cuda/numba/cuda/typing/mathdecl.py +158 -0
- numba_cuda/numba/cuda/typing/npdatetime.py +322 -0
- numba_cuda/numba/cuda/typing/npydecl.py +749 -0
- numba_cuda/numba/cuda/typing/setdecl.py +115 -0
- numba_cuda/numba/cuda/typing/templates.py +1446 -0
- numba_cuda/numba/cuda/typing/typeof.py +301 -0
- numba_cuda/numba/cuda/ufuncs.py +746 -0
- numba_cuda/numba/cuda/utils.py +724 -0
- numba_cuda/numba/cuda/vector_types.py +214 -0
- numba_cuda/numba/cuda/vectorizers.py +260 -0
- numba_cuda-0.21.1.dist-info/METADATA +109 -0
- numba_cuda-0.21.1.dist-info/RECORD +488 -0
- numba_cuda-0.21.1.dist-info/WHEEL +5 -0
- numba_cuda-0.21.1.dist-info/licenses/LICENSE +26 -0
- numba_cuda-0.21.1.dist-info/licenses/LICENSE.numba +24 -0
- numba_cuda-0.21.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,971 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
# SPDX-License-Identifier: BSD-2-Clause
|
|
3
|
+
|
|
4
|
+
from collections.abc import Iterable
|
|
5
|
+
from collections.abc import Sequence as pySequence
|
|
6
|
+
from types import MappingProxyType
|
|
7
|
+
|
|
8
|
+
from .abstract import (
|
|
9
|
+
ConstSized,
|
|
10
|
+
Container,
|
|
11
|
+
Hashable,
|
|
12
|
+
MutableSequence,
|
|
13
|
+
Sequence,
|
|
14
|
+
Type,
|
|
15
|
+
TypeRef,
|
|
16
|
+
Literal,
|
|
17
|
+
InitialValue,
|
|
18
|
+
Poison,
|
|
19
|
+
)
|
|
20
|
+
from .common import (
|
|
21
|
+
Buffer,
|
|
22
|
+
IterableType,
|
|
23
|
+
SimpleIterableType,
|
|
24
|
+
SimpleIteratorType,
|
|
25
|
+
)
|
|
26
|
+
from .misc import Undefined, unliteral, Optional, NoneType
|
|
27
|
+
from numba.cuda.typeconv import Conversion
|
|
28
|
+
from numba.cuda.core.errors import TypingError
|
|
29
|
+
from numba.cuda import utils
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Pair(Type):
|
|
33
|
+
"""
|
|
34
|
+
A heterogeneous pair.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, first_type, second_type):
|
|
38
|
+
self.first_type = first_type
|
|
39
|
+
self.second_type = second_type
|
|
40
|
+
name = "pair<%s, %s>" % (first_type, second_type)
|
|
41
|
+
super(Pair, self).__init__(name=name)
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def key(self):
|
|
45
|
+
return self.first_type, self.second_type
|
|
46
|
+
|
|
47
|
+
def unify(self, typingctx, other):
|
|
48
|
+
if isinstance(other, Pair):
|
|
49
|
+
first = typingctx.unify_pairs(self.first_type, other.first_type)
|
|
50
|
+
second = typingctx.unify_pairs(self.second_type, other.second_type)
|
|
51
|
+
if first is not None and second is not None:
|
|
52
|
+
return Pair(first, second)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class BaseContainerIterator(SimpleIteratorType):
|
|
56
|
+
"""
|
|
57
|
+
Convenience base class for some container iterators.
|
|
58
|
+
|
|
59
|
+
Derived classes must implement the *container_class* attribute.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
def __init__(self, container):
|
|
63
|
+
assert isinstance(container, self.container_class), container
|
|
64
|
+
self.container = container
|
|
65
|
+
yield_type = container.dtype
|
|
66
|
+
name = "iter(%s)" % container
|
|
67
|
+
super(BaseContainerIterator, self).__init__(name, yield_type)
|
|
68
|
+
|
|
69
|
+
def unify(self, typingctx, other):
|
|
70
|
+
cls = type(self)
|
|
71
|
+
if isinstance(other, cls):
|
|
72
|
+
container = typingctx.unify_pairs(self.container, other.container)
|
|
73
|
+
if container is not None:
|
|
74
|
+
return cls(container)
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def key(self):
|
|
78
|
+
return self.container
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class BaseContainerPayload(Type):
|
|
82
|
+
"""
|
|
83
|
+
Convenience base class for some container payloads.
|
|
84
|
+
|
|
85
|
+
Derived classes must implement the *container_class* attribute.
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
def __init__(self, container):
|
|
89
|
+
assert isinstance(container, self.container_class)
|
|
90
|
+
self.container = container
|
|
91
|
+
name = "payload(%s)" % container
|
|
92
|
+
super(BaseContainerPayload, self).__init__(name)
|
|
93
|
+
|
|
94
|
+
@property
|
|
95
|
+
def key(self):
|
|
96
|
+
return self.container
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class Bytes(Buffer):
|
|
100
|
+
"""
|
|
101
|
+
Type class for Python 3.x bytes objects.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
mutable = False
|
|
105
|
+
# Actually true but doesn't matter since bytes is immutable
|
|
106
|
+
slice_is_copy = False
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class ByteArray(Buffer):
|
|
110
|
+
"""
|
|
111
|
+
Type class for bytearray objects.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
slice_is_copy = True
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class PyArray(Buffer):
|
|
118
|
+
"""
|
|
119
|
+
Type class for array.array objects.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
slice_is_copy = True
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class MemoryView(Buffer):
|
|
126
|
+
"""
|
|
127
|
+
Type class for memoryview objects.
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def is_homogeneous(*tys):
|
|
132
|
+
"""Are the types homogeneous?"""
|
|
133
|
+
if tys:
|
|
134
|
+
first, tys = tys[0], tys[1:]
|
|
135
|
+
return not any(t != first for t in tys)
|
|
136
|
+
else:
|
|
137
|
+
# *tys* is empty.
|
|
138
|
+
return False
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class BaseTuple(ConstSized, Hashable):
|
|
142
|
+
"""
|
|
143
|
+
The base class for all tuple types (with a known size).
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
@classmethod
|
|
147
|
+
def from_types(cls, tys, pyclass=None):
|
|
148
|
+
"""
|
|
149
|
+
Instantiate the right tuple type for the given element types.
|
|
150
|
+
"""
|
|
151
|
+
if pyclass is not None and pyclass is not tuple:
|
|
152
|
+
# A subclass => is it a namedtuple?
|
|
153
|
+
assert issubclass(pyclass, tuple)
|
|
154
|
+
if hasattr(pyclass, "_asdict"):
|
|
155
|
+
tys = tuple(map(unliteral, tys))
|
|
156
|
+
homogeneous = is_homogeneous(*tys)
|
|
157
|
+
if homogeneous:
|
|
158
|
+
return NamedUniTuple(tys[0], len(tys), pyclass)
|
|
159
|
+
else:
|
|
160
|
+
return NamedTuple(tys, pyclass)
|
|
161
|
+
else:
|
|
162
|
+
dtype = utils.unified_function_type(tys)
|
|
163
|
+
if dtype is not None:
|
|
164
|
+
return UniTuple(dtype, len(tys))
|
|
165
|
+
# non-named tuple
|
|
166
|
+
homogeneous = is_homogeneous(*tys)
|
|
167
|
+
if homogeneous:
|
|
168
|
+
return cls._make_homogeneous_tuple(tys[0], len(tys))
|
|
169
|
+
else:
|
|
170
|
+
return cls._make_heterogeneous_tuple(tys)
|
|
171
|
+
|
|
172
|
+
@classmethod
|
|
173
|
+
def _make_homogeneous_tuple(cls, dtype, count):
|
|
174
|
+
return UniTuple(dtype, count)
|
|
175
|
+
|
|
176
|
+
@classmethod
|
|
177
|
+
def _make_heterogeneous_tuple(cls, tys):
|
|
178
|
+
return Tuple(tys)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class BaseAnonymousTuple(BaseTuple):
|
|
182
|
+
"""
|
|
183
|
+
Mixin for non-named tuples.
|
|
184
|
+
"""
|
|
185
|
+
|
|
186
|
+
def can_convert_to(self, typingctx, other):
|
|
187
|
+
"""
|
|
188
|
+
Convert this tuple to another one. Note named tuples are rejected.
|
|
189
|
+
"""
|
|
190
|
+
if not isinstance(other, BaseAnonymousTuple):
|
|
191
|
+
return
|
|
192
|
+
if len(self) != len(other):
|
|
193
|
+
return
|
|
194
|
+
if len(self) == 0:
|
|
195
|
+
return Conversion.safe
|
|
196
|
+
if isinstance(other, BaseTuple):
|
|
197
|
+
kinds = [
|
|
198
|
+
typingctx.can_convert(ta, tb) for ta, tb in zip(self, other)
|
|
199
|
+
]
|
|
200
|
+
if any(kind is None for kind in kinds):
|
|
201
|
+
return
|
|
202
|
+
return max(kinds)
|
|
203
|
+
|
|
204
|
+
def __unliteral__(self):
|
|
205
|
+
return type(self).from_types([unliteral(t) for t in self])
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class _HomogeneousTuple(Sequence, BaseTuple):
|
|
209
|
+
@property
|
|
210
|
+
def iterator_type(self):
|
|
211
|
+
return UniTupleIter(self)
|
|
212
|
+
|
|
213
|
+
def __getitem__(self, i):
|
|
214
|
+
"""
|
|
215
|
+
Return element at position i
|
|
216
|
+
"""
|
|
217
|
+
return self.dtype
|
|
218
|
+
|
|
219
|
+
def __iter__(self):
|
|
220
|
+
return iter([self.dtype] * self.count)
|
|
221
|
+
|
|
222
|
+
def __len__(self):
|
|
223
|
+
return self.count
|
|
224
|
+
|
|
225
|
+
@property
|
|
226
|
+
def types(self):
|
|
227
|
+
return (self.dtype,) * self.count
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
class UniTuple(BaseAnonymousTuple, _HomogeneousTuple, Sequence):
|
|
231
|
+
"""
|
|
232
|
+
Type class for homogeneous tuples.
|
|
233
|
+
"""
|
|
234
|
+
|
|
235
|
+
def __init__(self, dtype, count):
|
|
236
|
+
self.dtype = dtype
|
|
237
|
+
self.count = count
|
|
238
|
+
name = "%s(%s x %d)" % (
|
|
239
|
+
self.__class__.__name__,
|
|
240
|
+
dtype,
|
|
241
|
+
count,
|
|
242
|
+
)
|
|
243
|
+
super(UniTuple, self).__init__(name)
|
|
244
|
+
|
|
245
|
+
@property
|
|
246
|
+
def mangling_args(self):
|
|
247
|
+
return self.__class__.__name__, (self.dtype, self.count)
|
|
248
|
+
|
|
249
|
+
@property
|
|
250
|
+
def key(self):
|
|
251
|
+
return self.dtype, self.count
|
|
252
|
+
|
|
253
|
+
def unify(self, typingctx, other):
|
|
254
|
+
"""
|
|
255
|
+
Unify UniTuples with their dtype
|
|
256
|
+
"""
|
|
257
|
+
if isinstance(other, UniTuple) and len(self) == len(other):
|
|
258
|
+
dtype = typingctx.unify_pairs(self.dtype, other.dtype)
|
|
259
|
+
if dtype is not None:
|
|
260
|
+
return UniTuple(dtype=dtype, count=self.count)
|
|
261
|
+
|
|
262
|
+
def __unliteral__(self):
|
|
263
|
+
return type(self)(dtype=unliteral(self.dtype), count=self.count)
|
|
264
|
+
|
|
265
|
+
def __repr__(self):
|
|
266
|
+
return f"UniTuple({repr(self.dtype)}, {self.count})"
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
class UniTupleIter(BaseContainerIterator):
|
|
270
|
+
"""
|
|
271
|
+
Type class for homogeneous tuple iterators.
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
container_class = _HomogeneousTuple
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
class _HeterogeneousTuple(BaseTuple):
|
|
278
|
+
def __getitem__(self, i):
|
|
279
|
+
"""
|
|
280
|
+
Return element at position i
|
|
281
|
+
"""
|
|
282
|
+
return self.types[i]
|
|
283
|
+
|
|
284
|
+
def __len__(self):
|
|
285
|
+
# Beware: this makes Tuple(()) false-ish
|
|
286
|
+
return len(self.types)
|
|
287
|
+
|
|
288
|
+
def __iter__(self):
|
|
289
|
+
return iter(self.types)
|
|
290
|
+
|
|
291
|
+
@staticmethod
|
|
292
|
+
def is_types_iterable(types):
|
|
293
|
+
# issue 4463 - check if argument 'types' is iterable
|
|
294
|
+
if not isinstance(types, Iterable):
|
|
295
|
+
raise TypingError("Argument 'types' is not iterable")
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
class UnionType(Type):
|
|
299
|
+
def __init__(self, types):
|
|
300
|
+
self.types = tuple(sorted(set(types), key=lambda x: x.name))
|
|
301
|
+
name = "Union[{}]".format(",".join(map(str, self.types)))
|
|
302
|
+
super(UnionType, self).__init__(name=name)
|
|
303
|
+
|
|
304
|
+
def get_type_tag(self, typ):
|
|
305
|
+
return self.types.index(typ)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
class Tuple(BaseAnonymousTuple, _HeterogeneousTuple):
|
|
309
|
+
def __new__(cls, types):
|
|
310
|
+
t = utils.unified_function_type(types, require_precise=True)
|
|
311
|
+
if t is not None:
|
|
312
|
+
return UniTuple(dtype=t, count=len(types))
|
|
313
|
+
|
|
314
|
+
_HeterogeneousTuple.is_types_iterable(types)
|
|
315
|
+
|
|
316
|
+
if types and all(t == types[0] for t in types[1:]):
|
|
317
|
+
return UniTuple(dtype=types[0], count=len(types))
|
|
318
|
+
else:
|
|
319
|
+
return object.__new__(Tuple)
|
|
320
|
+
|
|
321
|
+
def __init__(self, types):
|
|
322
|
+
self.types = tuple(types)
|
|
323
|
+
self.count = len(self.types)
|
|
324
|
+
self.dtype = UnionType(types)
|
|
325
|
+
name = "%s(%s)" % (
|
|
326
|
+
self.__class__.__name__,
|
|
327
|
+
", ".join(str(i) for i in self.types),
|
|
328
|
+
)
|
|
329
|
+
super(Tuple, self).__init__(name)
|
|
330
|
+
|
|
331
|
+
@property
|
|
332
|
+
def mangling_args(self):
|
|
333
|
+
return self.__class__.__name__, tuple(t for t in self.types)
|
|
334
|
+
|
|
335
|
+
@property
|
|
336
|
+
def key(self):
|
|
337
|
+
return self.types
|
|
338
|
+
|
|
339
|
+
def unify(self, typingctx, other):
|
|
340
|
+
"""
|
|
341
|
+
Unify elements of Tuples/UniTuples
|
|
342
|
+
"""
|
|
343
|
+
# Other is UniTuple or Tuple
|
|
344
|
+
if isinstance(other, BaseTuple) and len(self) == len(other):
|
|
345
|
+
unified = [
|
|
346
|
+
typingctx.unify_pairs(ta, tb) for ta, tb in zip(self, other)
|
|
347
|
+
]
|
|
348
|
+
|
|
349
|
+
if all(t is not None for t in unified):
|
|
350
|
+
return Tuple(unified)
|
|
351
|
+
|
|
352
|
+
def __repr__(self):
|
|
353
|
+
return f"Tuple({tuple(ty for ty in self.types)})"
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
class _StarArgTupleMixin:
|
|
357
|
+
@classmethod
|
|
358
|
+
def _make_homogeneous_tuple(cls, dtype, count):
|
|
359
|
+
return StarArgUniTuple(dtype, count)
|
|
360
|
+
|
|
361
|
+
@classmethod
|
|
362
|
+
def _make_heterogeneous_tuple(cls, tys):
|
|
363
|
+
return StarArgTuple(tys)
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
class StarArgTuple(_StarArgTupleMixin, Tuple):
|
|
367
|
+
"""To distinguish from Tuple() used as argument to a `*args`."""
|
|
368
|
+
|
|
369
|
+
def __new__(cls, types):
|
|
370
|
+
_HeterogeneousTuple.is_types_iterable(types)
|
|
371
|
+
|
|
372
|
+
if types and all(t == types[0] for t in types[1:]):
|
|
373
|
+
return StarArgUniTuple(dtype=types[0], count=len(types))
|
|
374
|
+
else:
|
|
375
|
+
return object.__new__(StarArgTuple)
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
class StarArgUniTuple(_StarArgTupleMixin, UniTuple):
|
|
379
|
+
"""To distinguish from UniTuple() used as argument to a `*args`."""
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
class BaseNamedTuple(BaseTuple):
|
|
383
|
+
pass
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
class NamedUniTuple(_HomogeneousTuple, BaseNamedTuple):
|
|
387
|
+
def __init__(self, dtype, count, cls):
|
|
388
|
+
self.dtype = dtype
|
|
389
|
+
self.count = count
|
|
390
|
+
self.fields = tuple(cls._fields)
|
|
391
|
+
self.instance_class = cls
|
|
392
|
+
name = "%s(%s x %d)" % (cls.__name__, dtype, count)
|
|
393
|
+
super(NamedUniTuple, self).__init__(name)
|
|
394
|
+
|
|
395
|
+
@property
|
|
396
|
+
def iterator_type(self):
|
|
397
|
+
return UniTupleIter(self)
|
|
398
|
+
|
|
399
|
+
@property
|
|
400
|
+
def key(self):
|
|
401
|
+
return self.instance_class, self.dtype, self.count
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
class NamedTuple(_HeterogeneousTuple, BaseNamedTuple):
|
|
405
|
+
def __init__(self, types, cls):
|
|
406
|
+
_HeterogeneousTuple.is_types_iterable(types)
|
|
407
|
+
|
|
408
|
+
self.types = tuple(types)
|
|
409
|
+
self.count = len(self.types)
|
|
410
|
+
self.fields = tuple(cls._fields)
|
|
411
|
+
self.instance_class = cls
|
|
412
|
+
name = "%s(%s)" % (cls.__name__, ", ".join(str(i) for i in self.types))
|
|
413
|
+
super(NamedTuple, self).__init__(name)
|
|
414
|
+
|
|
415
|
+
@property
|
|
416
|
+
def key(self):
|
|
417
|
+
return self.instance_class, self.types
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
class List(MutableSequence, InitialValue):
|
|
421
|
+
"""
|
|
422
|
+
Type class for (arbitrary-sized) homogeneous lists.
|
|
423
|
+
"""
|
|
424
|
+
|
|
425
|
+
def __init__(self, dtype, reflected=False, initial_value=None):
|
|
426
|
+
dtype = unliteral(dtype)
|
|
427
|
+
self.dtype = dtype
|
|
428
|
+
self.reflected = reflected
|
|
429
|
+
cls_name = "reflected list" if reflected else "list"
|
|
430
|
+
name = "%s(%s)<iv=%s>" % (cls_name, self.dtype, initial_value)
|
|
431
|
+
super(List, self).__init__(name=name)
|
|
432
|
+
InitialValue.__init__(self, initial_value)
|
|
433
|
+
|
|
434
|
+
def copy(self, dtype=None, reflected=None):
|
|
435
|
+
if dtype is None:
|
|
436
|
+
dtype = self.dtype
|
|
437
|
+
if reflected is None:
|
|
438
|
+
reflected = self.reflected
|
|
439
|
+
return List(dtype, reflected, self.initial_value)
|
|
440
|
+
|
|
441
|
+
def unify(self, typingctx, other):
|
|
442
|
+
if isinstance(other, List):
|
|
443
|
+
dtype = typingctx.unify_pairs(self.dtype, other.dtype)
|
|
444
|
+
reflected = self.reflected or other.reflected
|
|
445
|
+
if dtype is not None:
|
|
446
|
+
siv = self.initial_value
|
|
447
|
+
oiv = other.initial_value
|
|
448
|
+
if siv is not None and oiv is not None:
|
|
449
|
+
use = siv
|
|
450
|
+
if siv is None:
|
|
451
|
+
use = oiv
|
|
452
|
+
return List(dtype, reflected, use)
|
|
453
|
+
else:
|
|
454
|
+
return List(dtype, reflected)
|
|
455
|
+
|
|
456
|
+
@property
|
|
457
|
+
def key(self):
|
|
458
|
+
return self.dtype, self.reflected, str(self.initial_value)
|
|
459
|
+
|
|
460
|
+
@property
|
|
461
|
+
def iterator_type(self):
|
|
462
|
+
return ListIter(self)
|
|
463
|
+
|
|
464
|
+
def is_precise(self):
|
|
465
|
+
return self.dtype.is_precise()
|
|
466
|
+
|
|
467
|
+
def __getitem__(self, args):
|
|
468
|
+
"""
|
|
469
|
+
Overrides the default __getitem__ from Type.
|
|
470
|
+
"""
|
|
471
|
+
return self.dtype
|
|
472
|
+
|
|
473
|
+
def __unliteral__(self):
|
|
474
|
+
return List(self.dtype, reflected=self.reflected, initial_value=None)
|
|
475
|
+
|
|
476
|
+
def __repr__(self):
|
|
477
|
+
return f"List({self.dtype}, {self.reflected})"
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
class LiteralList(Literal, ConstSized, Hashable):
|
|
481
|
+
"""A heterogeneous immutable list (basically a tuple with list semantics)."""
|
|
482
|
+
|
|
483
|
+
mutable = False
|
|
484
|
+
|
|
485
|
+
def __init__(self, literal_value):
|
|
486
|
+
self.is_types_iterable(literal_value)
|
|
487
|
+
self._literal_init(list(literal_value))
|
|
488
|
+
self.types = tuple(literal_value)
|
|
489
|
+
self.count = len(self.types)
|
|
490
|
+
self.name = "LiteralList({})".format(literal_value)
|
|
491
|
+
|
|
492
|
+
def __getitem__(self, i):
|
|
493
|
+
"""
|
|
494
|
+
Return element at position i
|
|
495
|
+
"""
|
|
496
|
+
return self.types[i]
|
|
497
|
+
|
|
498
|
+
def __len__(self):
|
|
499
|
+
return len(self.types)
|
|
500
|
+
|
|
501
|
+
def __iter__(self):
|
|
502
|
+
return iter(self.types)
|
|
503
|
+
|
|
504
|
+
@classmethod
|
|
505
|
+
def from_types(cls, tys):
|
|
506
|
+
return LiteralList(tys)
|
|
507
|
+
|
|
508
|
+
@staticmethod
|
|
509
|
+
def is_types_iterable(types):
|
|
510
|
+
if not isinstance(types, Iterable):
|
|
511
|
+
raise TypingError("Argument 'types' is not iterable")
|
|
512
|
+
|
|
513
|
+
@property
|
|
514
|
+
def iterator_type(self):
|
|
515
|
+
return ListIter(self)
|
|
516
|
+
|
|
517
|
+
def __unliteral__(self):
|
|
518
|
+
return Poison(self)
|
|
519
|
+
|
|
520
|
+
def unify(self, typingctx, other):
|
|
521
|
+
"""
|
|
522
|
+
Unify this with the *other* one.
|
|
523
|
+
"""
|
|
524
|
+
if isinstance(other, LiteralList) and self.count == other.count:
|
|
525
|
+
tys = []
|
|
526
|
+
for i1, i2 in zip(self.types, other.types):
|
|
527
|
+
tys.append(typingctx.unify_pairs(i1, i2))
|
|
528
|
+
if all(tys):
|
|
529
|
+
return LiteralList(tys)
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
class ListIter(BaseContainerIterator):
|
|
533
|
+
"""
|
|
534
|
+
Type class for list iterators.
|
|
535
|
+
"""
|
|
536
|
+
|
|
537
|
+
container_class = List
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
class ListPayload(BaseContainerPayload):
|
|
541
|
+
"""
|
|
542
|
+
Internal type class for the dynamically-allocated payload of a list.
|
|
543
|
+
"""
|
|
544
|
+
|
|
545
|
+
container_class = List
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
class Set(Container):
|
|
549
|
+
"""
|
|
550
|
+
Type class for homogeneous sets.
|
|
551
|
+
"""
|
|
552
|
+
|
|
553
|
+
mutable = True
|
|
554
|
+
|
|
555
|
+
def __init__(self, dtype, reflected=False):
|
|
556
|
+
assert isinstance(dtype, (Hashable, Undefined))
|
|
557
|
+
self.dtype = dtype
|
|
558
|
+
self.reflected = reflected
|
|
559
|
+
cls_name = "reflected set" if reflected else "set"
|
|
560
|
+
name = "%s(%s)" % (cls_name, self.dtype)
|
|
561
|
+
super(Set, self).__init__(name=name)
|
|
562
|
+
|
|
563
|
+
@property
|
|
564
|
+
def key(self):
|
|
565
|
+
return self.dtype, self.reflected
|
|
566
|
+
|
|
567
|
+
@property
|
|
568
|
+
def iterator_type(self):
|
|
569
|
+
return SetIter(self)
|
|
570
|
+
|
|
571
|
+
def is_precise(self):
|
|
572
|
+
return self.dtype.is_precise()
|
|
573
|
+
|
|
574
|
+
def copy(self, dtype=None, reflected=None):
|
|
575
|
+
if dtype is None:
|
|
576
|
+
dtype = self.dtype
|
|
577
|
+
if reflected is None:
|
|
578
|
+
reflected = self.reflected
|
|
579
|
+
return Set(dtype, reflected)
|
|
580
|
+
|
|
581
|
+
def unify(self, typingctx, other):
|
|
582
|
+
if isinstance(other, Set):
|
|
583
|
+
dtype = typingctx.unify_pairs(self.dtype, other.dtype)
|
|
584
|
+
reflected = self.reflected or other.reflected
|
|
585
|
+
if dtype is not None:
|
|
586
|
+
return Set(dtype, reflected)
|
|
587
|
+
|
|
588
|
+
def __repr__(self):
|
|
589
|
+
return f"Set({self.dtype}, {self.reflected})"
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
class SetIter(BaseContainerIterator):
|
|
593
|
+
"""
|
|
594
|
+
Type class for set iterators.
|
|
595
|
+
"""
|
|
596
|
+
|
|
597
|
+
container_class = Set
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
class SetPayload(BaseContainerPayload):
|
|
601
|
+
"""
|
|
602
|
+
Internal type class for the dynamically-allocated payload of a set.
|
|
603
|
+
"""
|
|
604
|
+
|
|
605
|
+
container_class = Set
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
class SetEntry(Type):
|
|
609
|
+
"""
|
|
610
|
+
Internal type class for the entries of a Set's hash table.
|
|
611
|
+
"""
|
|
612
|
+
|
|
613
|
+
def __init__(self, set_type):
|
|
614
|
+
self.set_type = set_type
|
|
615
|
+
name = "entry(%s)" % set_type
|
|
616
|
+
super(SetEntry, self).__init__(name)
|
|
617
|
+
|
|
618
|
+
@property
|
|
619
|
+
def key(self):
|
|
620
|
+
return self.set_type
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
class ListType(IterableType):
|
|
624
|
+
"""List type"""
|
|
625
|
+
|
|
626
|
+
mutable = True
|
|
627
|
+
|
|
628
|
+
def __init__(self, itemty):
|
|
629
|
+
assert not isinstance(itemty, TypeRef)
|
|
630
|
+
itemty = unliteral(itemty)
|
|
631
|
+
if isinstance(itemty, Optional):
|
|
632
|
+
fmt = "List.item_type cannot be of type {}"
|
|
633
|
+
raise TypingError(fmt.format(itemty))
|
|
634
|
+
# FIXME: _sentry_forbidden_types(itemty)
|
|
635
|
+
self.item_type = itemty
|
|
636
|
+
self.dtype = itemty
|
|
637
|
+
name = "{}[{}]".format(
|
|
638
|
+
self.__class__.__name__,
|
|
639
|
+
itemty,
|
|
640
|
+
)
|
|
641
|
+
super(ListType, self).__init__(name)
|
|
642
|
+
|
|
643
|
+
@property
|
|
644
|
+
def key(self):
|
|
645
|
+
return self.item_type
|
|
646
|
+
|
|
647
|
+
def is_precise(self):
|
|
648
|
+
return not isinstance(self.item_type, Undefined)
|
|
649
|
+
|
|
650
|
+
@property
|
|
651
|
+
def iterator_type(self):
|
|
652
|
+
return ListTypeIterableType(self).iterator_type
|
|
653
|
+
|
|
654
|
+
@classmethod
|
|
655
|
+
def refine(cls, itemty):
|
|
656
|
+
"""Refine to a precise list type"""
|
|
657
|
+
res = cls(itemty)
|
|
658
|
+
assert res.is_precise()
|
|
659
|
+
return res
|
|
660
|
+
|
|
661
|
+
def unify(self, typingctx, other):
|
|
662
|
+
"""
|
|
663
|
+
Unify this with the *other* list.
|
|
664
|
+
"""
|
|
665
|
+
# If other is list
|
|
666
|
+
if isinstance(other, ListType):
|
|
667
|
+
if not other.is_precise():
|
|
668
|
+
return self
|
|
669
|
+
|
|
670
|
+
def __repr__(self):
|
|
671
|
+
return f"ListType({self.item_type})"
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
class ListTypeIterableType(SimpleIterableType):
|
|
675
|
+
"""List iterable type"""
|
|
676
|
+
|
|
677
|
+
def __init__(self, parent):
|
|
678
|
+
assert isinstance(parent, ListType)
|
|
679
|
+
self.parent = parent
|
|
680
|
+
self.yield_type = self.parent.item_type
|
|
681
|
+
name = "list[{}]".format(self.parent.name)
|
|
682
|
+
iterator_type = ListTypeIteratorType(self)
|
|
683
|
+
super(ListTypeIterableType, self).__init__(name, iterator_type)
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
class ListTypeIteratorType(SimpleIteratorType):
|
|
687
|
+
def __init__(self, iterable):
|
|
688
|
+
self.parent = iterable.parent
|
|
689
|
+
self.iterable = iterable
|
|
690
|
+
yield_type = iterable.yield_type
|
|
691
|
+
name = "iter[{}->{}]".format(iterable.parent, yield_type)
|
|
692
|
+
super(ListTypeIteratorType, self).__init__(name, yield_type)
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
def _sentry_forbidden_types(key, value):
|
|
696
|
+
# Forbids List and Set for now
|
|
697
|
+
if isinstance(key, (Set, List)):
|
|
698
|
+
raise TypingError("{} as key is forbidden".format(key))
|
|
699
|
+
if isinstance(value, (Set, List)):
|
|
700
|
+
raise TypingError("{} as value is forbidden".format(value))
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
class DictType(IterableType, InitialValue):
|
|
704
|
+
"""Dictionary type"""
|
|
705
|
+
|
|
706
|
+
def __init__(self, keyty, valty, initial_value=None):
|
|
707
|
+
assert not isinstance(keyty, TypeRef)
|
|
708
|
+
assert not isinstance(valty, TypeRef)
|
|
709
|
+
keyty = unliteral(keyty)
|
|
710
|
+
valty = unliteral(valty)
|
|
711
|
+
if isinstance(keyty, (Optional, NoneType)):
|
|
712
|
+
fmt = "Dict.key_type cannot be of type {}"
|
|
713
|
+
raise TypingError(fmt.format(keyty))
|
|
714
|
+
if isinstance(valty, (Optional, NoneType)):
|
|
715
|
+
fmt = "Dict.value_type cannot be of type {}"
|
|
716
|
+
raise TypingError(fmt.format(valty))
|
|
717
|
+
_sentry_forbidden_types(keyty, valty)
|
|
718
|
+
self.key_type = keyty
|
|
719
|
+
self.value_type = valty
|
|
720
|
+
self.keyvalue_type = Tuple([keyty, valty])
|
|
721
|
+
name = "{}[{},{}]<iv={}>".format(
|
|
722
|
+
self.__class__.__name__, keyty, valty, initial_value
|
|
723
|
+
)
|
|
724
|
+
super(DictType, self).__init__(name)
|
|
725
|
+
InitialValue.__init__(self, initial_value)
|
|
726
|
+
|
|
727
|
+
def is_precise(self):
|
|
728
|
+
return not any(
|
|
729
|
+
(
|
|
730
|
+
isinstance(self.key_type, Undefined),
|
|
731
|
+
isinstance(self.value_type, Undefined),
|
|
732
|
+
)
|
|
733
|
+
)
|
|
734
|
+
|
|
735
|
+
@property
|
|
736
|
+
def iterator_type(self):
|
|
737
|
+
return DictKeysIterableType(self).iterator_type
|
|
738
|
+
|
|
739
|
+
@classmethod
|
|
740
|
+
def refine(cls, keyty, valty):
|
|
741
|
+
"""Refine to a precise dictionary type"""
|
|
742
|
+
res = cls(keyty, valty)
|
|
743
|
+
assert res.is_precise()
|
|
744
|
+
return res
|
|
745
|
+
|
|
746
|
+
def unify(self, typingctx, other):
|
|
747
|
+
"""
|
|
748
|
+
Unify this with the *other* dictionary.
|
|
749
|
+
"""
|
|
750
|
+
# If other is dict
|
|
751
|
+
if isinstance(other, DictType):
|
|
752
|
+
if not other.is_precise():
|
|
753
|
+
return self
|
|
754
|
+
else:
|
|
755
|
+
ukey_type = self.key_type == other.key_type
|
|
756
|
+
uvalue_type = self.value_type == other.value_type
|
|
757
|
+
if ukey_type and uvalue_type:
|
|
758
|
+
siv = self.initial_value
|
|
759
|
+
oiv = other.initial_value
|
|
760
|
+
siv_none = siv is None
|
|
761
|
+
oiv_none = oiv is None
|
|
762
|
+
if not siv_none and not oiv_none:
|
|
763
|
+
if siv == oiv:
|
|
764
|
+
return DictType(
|
|
765
|
+
self.key_type, other.value_type, siv
|
|
766
|
+
)
|
|
767
|
+
return DictType(self.key_type, other.value_type)
|
|
768
|
+
|
|
769
|
+
@property
|
|
770
|
+
def key(self):
|
|
771
|
+
return self.key_type, self.value_type, str(self.initial_value)
|
|
772
|
+
|
|
773
|
+
def __unliteral__(self):
|
|
774
|
+
return DictType(self.key_type, self.value_type)
|
|
775
|
+
|
|
776
|
+
def __repr__(self):
|
|
777
|
+
return f"DictType({self.key_type}, {self.value_type})"
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
class LiteralStrKeyDict(Literal, ConstSized, Hashable):
|
|
781
|
+
"""A Dictionary of string keys to heterogeneous values (basically a
|
|
782
|
+
namedtuple with dict semantics).
|
|
783
|
+
"""
|
|
784
|
+
|
|
785
|
+
class FakeNamedTuple(pySequence):
|
|
786
|
+
# This is namedtuple-like and is a workaround for #6518 and #7416.
|
|
787
|
+
# This has the couple of namedtuple properties that are used by Numba's
|
|
788
|
+
# internals but avoids use of an actual namedtuple as it cannot have
|
|
789
|
+
# numeric field names, i.e. `namedtuple('foo', '0 1')` is invalid.
|
|
790
|
+
def __init__(self, name, keys):
|
|
791
|
+
self.__name__ = name
|
|
792
|
+
self._fields = tuple(keys)
|
|
793
|
+
super(LiteralStrKeyDict.FakeNamedTuple, self).__init__()
|
|
794
|
+
|
|
795
|
+
def __len__(self):
|
|
796
|
+
return len(self._fields)
|
|
797
|
+
|
|
798
|
+
def __getitem__(self, key):
|
|
799
|
+
return self._fields[key]
|
|
800
|
+
|
|
801
|
+
mutable = False
|
|
802
|
+
|
|
803
|
+
def __init__(self, literal_value, value_index=None):
|
|
804
|
+
self._literal_init(literal_value)
|
|
805
|
+
self.value_index = value_index
|
|
806
|
+
strkeys = [x.literal_value for x in literal_value.keys()]
|
|
807
|
+
self.tuple_ty = self.FakeNamedTuple("_ntclazz", strkeys)
|
|
808
|
+
tys = [x for x in literal_value.values()]
|
|
809
|
+
self.types = tuple(tys)
|
|
810
|
+
self.count = len(self.types)
|
|
811
|
+
self.fields = tuple(self.tuple_ty._fields)
|
|
812
|
+
self.instance_class = self.tuple_ty
|
|
813
|
+
self.name = "LiteralStrKey[Dict]({})".format(literal_value)
|
|
814
|
+
|
|
815
|
+
def __unliteral__(self):
|
|
816
|
+
return Poison(self)
|
|
817
|
+
|
|
818
|
+
def unify(self, typingctx, other):
|
|
819
|
+
"""
|
|
820
|
+
Unify this with the *other* one.
|
|
821
|
+
"""
|
|
822
|
+
if isinstance(other, LiteralStrKeyDict):
|
|
823
|
+
tys = []
|
|
824
|
+
for (k1, v1), (k2, v2) in zip(
|
|
825
|
+
self.literal_value.items(), other.literal_value.items()
|
|
826
|
+
):
|
|
827
|
+
if k1 != k2: # keys must be same
|
|
828
|
+
break
|
|
829
|
+
tys.append(typingctx.unify_pairs(v1, v2))
|
|
830
|
+
else:
|
|
831
|
+
if all(tys):
|
|
832
|
+
d = {k: v for k, v in zip(self.literal_value.keys(), tys)}
|
|
833
|
+
return LiteralStrKeyDict(d)
|
|
834
|
+
|
|
835
|
+
def __len__(self):
|
|
836
|
+
return len(self.types)
|
|
837
|
+
|
|
838
|
+
def __iter__(self):
|
|
839
|
+
return iter(self.types)
|
|
840
|
+
|
|
841
|
+
@property
|
|
842
|
+
def key(self):
|
|
843
|
+
# use the namedtuple fields not the namedtuple itself as it's created
|
|
844
|
+
# locally in the ctor and comparison would always be False.
|
|
845
|
+
return self.tuple_ty._fields, self.types, str(self.literal_value)
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
class DictItemsIterableType(SimpleIterableType):
|
|
849
|
+
"""Dictionary iterable type for .items()"""
|
|
850
|
+
|
|
851
|
+
def __init__(self, parent):
|
|
852
|
+
assert isinstance(parent, DictType)
|
|
853
|
+
self.parent = parent
|
|
854
|
+
self.yield_type = self.parent.keyvalue_type
|
|
855
|
+
name = "items[{}]".format(self.parent.name)
|
|
856
|
+
self.name = name
|
|
857
|
+
iterator_type = DictIteratorType(self)
|
|
858
|
+
super(DictItemsIterableType, self).__init__(name, iterator_type)
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
class DictKeysIterableType(SimpleIterableType):
|
|
862
|
+
"""Dictionary iterable type for .keys()"""
|
|
863
|
+
|
|
864
|
+
def __init__(self, parent):
|
|
865
|
+
assert isinstance(parent, DictType)
|
|
866
|
+
self.parent = parent
|
|
867
|
+
self.yield_type = self.parent.key_type
|
|
868
|
+
name = "keys[{}]".format(self.parent.name)
|
|
869
|
+
self.name = name
|
|
870
|
+
iterator_type = DictIteratorType(self)
|
|
871
|
+
super(DictKeysIterableType, self).__init__(name, iterator_type)
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
class DictValuesIterableType(SimpleIterableType):
|
|
875
|
+
"""Dictionary iterable type for .values()"""
|
|
876
|
+
|
|
877
|
+
def __init__(self, parent):
|
|
878
|
+
assert isinstance(parent, DictType)
|
|
879
|
+
self.parent = parent
|
|
880
|
+
self.yield_type = self.parent.value_type
|
|
881
|
+
name = "values[{}]".format(self.parent.name)
|
|
882
|
+
self.name = name
|
|
883
|
+
iterator_type = DictIteratorType(self)
|
|
884
|
+
super(DictValuesIterableType, self).__init__(name, iterator_type)
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
class DictIteratorType(SimpleIteratorType):
|
|
888
|
+
def __init__(self, iterable):
|
|
889
|
+
self.parent = iterable.parent
|
|
890
|
+
self.iterable = iterable
|
|
891
|
+
yield_type = iterable.yield_type
|
|
892
|
+
name = "iter[{}->{}],{}".format(
|
|
893
|
+
iterable.parent, yield_type, iterable.name
|
|
894
|
+
)
|
|
895
|
+
super(DictIteratorType, self).__init__(name, yield_type)
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
class StructRef(Type):
|
|
899
|
+
"""A mutable struct."""
|
|
900
|
+
|
|
901
|
+
def __init__(self, fields):
|
|
902
|
+
"""
|
|
903
|
+
Parameters
|
|
904
|
+
----------
|
|
905
|
+
fields : Sequence
|
|
906
|
+
A sequence of field descriptions, which is a 2-tuple-like object
|
|
907
|
+
containing `(name, type)`, where `name` is a `str` for the field
|
|
908
|
+
name, and `type` is a numba type for the field type.
|
|
909
|
+
"""
|
|
910
|
+
|
|
911
|
+
def check_field_pair(fieldpair):
|
|
912
|
+
name, typ = fieldpair
|
|
913
|
+
if not isinstance(name, str):
|
|
914
|
+
msg = "expecting a str for field name"
|
|
915
|
+
raise ValueError(msg)
|
|
916
|
+
if not isinstance(typ, Type):
|
|
917
|
+
msg = "expecting a Numba Type for field type"
|
|
918
|
+
raise ValueError(msg)
|
|
919
|
+
return name, typ
|
|
920
|
+
|
|
921
|
+
fields = tuple(map(check_field_pair, fields))
|
|
922
|
+
self._fields = tuple(
|
|
923
|
+
map(check_field_pair, self.preprocess_fields(fields))
|
|
924
|
+
)
|
|
925
|
+
self._typename = self.__class__.__qualname__
|
|
926
|
+
name = f"numba.{self._typename}{self._fields}"
|
|
927
|
+
super().__init__(name=name)
|
|
928
|
+
|
|
929
|
+
def preprocess_fields(self, fields):
|
|
930
|
+
"""Subclasses can override this to do additional clean up on fields.
|
|
931
|
+
|
|
932
|
+
The default is an identity function.
|
|
933
|
+
|
|
934
|
+
Parameters:
|
|
935
|
+
-----------
|
|
936
|
+
fields : Sequence[Tuple[str, Type]]
|
|
937
|
+
"""
|
|
938
|
+
return fields
|
|
939
|
+
|
|
940
|
+
@property
|
|
941
|
+
def field_dict(self):
|
|
942
|
+
"""Return an immutable mapping for the field names and their
|
|
943
|
+
corresponding types.
|
|
944
|
+
"""
|
|
945
|
+
return MappingProxyType(dict(self._fields))
|
|
946
|
+
|
|
947
|
+
def get_data_type(self):
|
|
948
|
+
"""Get the payload type for the actual underlying structure referred
|
|
949
|
+
to by this struct reference.
|
|
950
|
+
|
|
951
|
+
See also: `ClassInstanceType.get_data_type`
|
|
952
|
+
"""
|
|
953
|
+
return StructRefPayload(
|
|
954
|
+
typename=self.__class__.__name__,
|
|
955
|
+
fields=self._fields,
|
|
956
|
+
)
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
class StructRefPayload(Type):
|
|
960
|
+
"""The type of the payload of a mutable struct."""
|
|
961
|
+
|
|
962
|
+
mutable = True
|
|
963
|
+
|
|
964
|
+
def __init__(self, typename, fields):
|
|
965
|
+
self._typename = typename
|
|
966
|
+
self._fields = tuple(fields)
|
|
967
|
+
super().__init__(name=f"numba.{typename}{self._fields}.payload")
|
|
968
|
+
|
|
969
|
+
@property
|
|
970
|
+
def field_dict(self):
|
|
971
|
+
return MappingProxyType(dict(self._fields))
|