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,939 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
# SPDX-License-Identifier: BSD-2-Clause
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import operator
|
|
6
|
+
from collections import namedtuple
|
|
7
|
+
|
|
8
|
+
from numba.cuda import types
|
|
9
|
+
from numba.cuda import utils
|
|
10
|
+
from numba.cuda.typing.templates import (
|
|
11
|
+
AttributeTemplate,
|
|
12
|
+
AbstractTemplate,
|
|
13
|
+
Registry,
|
|
14
|
+
signature,
|
|
15
|
+
bound_function,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
# import time side effect: array operations requires typing support of sequence
|
|
19
|
+
# defined in collections: e.g. array.shape[i]
|
|
20
|
+
from numba.cuda.core.errors import (
|
|
21
|
+
TypingError,
|
|
22
|
+
RequireLiteralValue,
|
|
23
|
+
NumbaTypeError,
|
|
24
|
+
NumbaAssertionError,
|
|
25
|
+
NumbaKeyError,
|
|
26
|
+
NumbaIndexError,
|
|
27
|
+
NumbaValueError,
|
|
28
|
+
)
|
|
29
|
+
from numba.cuda.cgutils import is_nonelike
|
|
30
|
+
|
|
31
|
+
numpy_version = tuple(map(int, np.__version__.split(".")[:2]))
|
|
32
|
+
|
|
33
|
+
registry = Registry()
|
|
34
|
+
infer = registry.register
|
|
35
|
+
infer_global = registry.register_global
|
|
36
|
+
infer_getattr = registry.register_attr
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
Indexing = namedtuple("Indexing", ("index", "result", "advanced"))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def get_array_index_type(ary, idx):
|
|
43
|
+
"""
|
|
44
|
+
Returns None or a tuple-3 for the types of the input array, index, and
|
|
45
|
+
resulting type of ``array[index]``.
|
|
46
|
+
|
|
47
|
+
Note: This is shared logic for ndarray getitem and setitem.
|
|
48
|
+
"""
|
|
49
|
+
if not isinstance(ary, types.Buffer):
|
|
50
|
+
return
|
|
51
|
+
|
|
52
|
+
ndim = ary.ndim
|
|
53
|
+
|
|
54
|
+
left_indices = []
|
|
55
|
+
right_indices = []
|
|
56
|
+
ellipsis_met = False
|
|
57
|
+
advanced = False
|
|
58
|
+
num_newaxis = 0
|
|
59
|
+
|
|
60
|
+
if not isinstance(idx, types.BaseTuple):
|
|
61
|
+
idx = [idx]
|
|
62
|
+
|
|
63
|
+
# Here, a subspace is considered as a contiguous group of advanced indices.
|
|
64
|
+
# num_subspaces keeps track of the number of such
|
|
65
|
+
# contiguous groups.
|
|
66
|
+
in_subspace = False
|
|
67
|
+
num_subspaces = 0
|
|
68
|
+
array_indices = 0
|
|
69
|
+
|
|
70
|
+
# Walk indices
|
|
71
|
+
for ty in idx:
|
|
72
|
+
if ty is types.ellipsis:
|
|
73
|
+
if ellipsis_met:
|
|
74
|
+
raise NumbaTypeError(
|
|
75
|
+
"Only one ellipsis allowed in array indices "
|
|
76
|
+
"(got %s)" % (idx,)
|
|
77
|
+
)
|
|
78
|
+
ellipsis_met = True
|
|
79
|
+
in_subspace = False
|
|
80
|
+
elif isinstance(ty, types.SliceType):
|
|
81
|
+
# If we encounter a non-advanced index while in a
|
|
82
|
+
# subspace then that subspace ends.
|
|
83
|
+
in_subspace = False
|
|
84
|
+
# In advanced indexing, any index broadcastable to an
|
|
85
|
+
# array is considered an advanced index. Hence all the
|
|
86
|
+
# branches below are considered as advanced indices.
|
|
87
|
+
elif isinstance(ty, types.Integer):
|
|
88
|
+
# Normalize integer index
|
|
89
|
+
ty = types.intp if ty.signed else types.uintp
|
|
90
|
+
# Integer indexing removes the given dimension
|
|
91
|
+
ndim -= 1
|
|
92
|
+
# If we're within a subspace/contiguous group of
|
|
93
|
+
# advanced indices then no action is necessary
|
|
94
|
+
# since we've already counted that subspace once.
|
|
95
|
+
if not in_subspace:
|
|
96
|
+
# If we're not within a subspace and we encounter
|
|
97
|
+
# this branch then we have a new subspace/group.
|
|
98
|
+
num_subspaces += 1
|
|
99
|
+
in_subspace = True
|
|
100
|
+
elif (
|
|
101
|
+
isinstance(ty, types.Array)
|
|
102
|
+
and ty.ndim == 0
|
|
103
|
+
and isinstance(ty.dtype, types.Integer)
|
|
104
|
+
):
|
|
105
|
+
# 0-d array used as integer index
|
|
106
|
+
ndim -= 1
|
|
107
|
+
if not in_subspace:
|
|
108
|
+
num_subspaces += 1
|
|
109
|
+
in_subspace = True
|
|
110
|
+
elif isinstance(ty, types.Array) and isinstance(
|
|
111
|
+
ty.dtype, (types.Integer, types.Boolean)
|
|
112
|
+
):
|
|
113
|
+
if ty.ndim > 1:
|
|
114
|
+
# Advanced indexing limitation # 1
|
|
115
|
+
raise NumbaTypeError(
|
|
116
|
+
"Multi-dimensional indices are not supported."
|
|
117
|
+
)
|
|
118
|
+
array_indices += 1
|
|
119
|
+
# The condition for activating advanced indexing is simply
|
|
120
|
+
# having at least one array with size > 1.
|
|
121
|
+
advanced = True
|
|
122
|
+
if not in_subspace:
|
|
123
|
+
num_subspaces += 1
|
|
124
|
+
in_subspace = True
|
|
125
|
+
elif is_nonelike(ty):
|
|
126
|
+
ndim += 1
|
|
127
|
+
num_newaxis += 1
|
|
128
|
+
else:
|
|
129
|
+
raise NumbaTypeError(
|
|
130
|
+
"Unsupported array index type %s in %s" % (ty, idx)
|
|
131
|
+
)
|
|
132
|
+
(right_indices if ellipsis_met else left_indices).append(ty)
|
|
133
|
+
|
|
134
|
+
if advanced:
|
|
135
|
+
if array_indices > 1:
|
|
136
|
+
# Advanced indexing limitation # 2
|
|
137
|
+
msg = "Using more than one non-scalar array index is unsupported."
|
|
138
|
+
raise NumbaTypeError(msg)
|
|
139
|
+
|
|
140
|
+
if num_subspaces > 1:
|
|
141
|
+
# Advanced indexing limitation # 3
|
|
142
|
+
msg = (
|
|
143
|
+
"Using more than one indexing subspace is unsupported."
|
|
144
|
+
" An indexing subspace is a group of one or more"
|
|
145
|
+
" consecutive indices comprising integer or array types."
|
|
146
|
+
)
|
|
147
|
+
raise NumbaTypeError(msg)
|
|
148
|
+
|
|
149
|
+
# Only Numpy arrays support advanced indexing
|
|
150
|
+
if advanced and not isinstance(ary, types.Array):
|
|
151
|
+
return
|
|
152
|
+
|
|
153
|
+
# Check indices and result dimensionality
|
|
154
|
+
all_indices = left_indices + right_indices
|
|
155
|
+
if ellipsis_met:
|
|
156
|
+
assert right_indices[0] is types.ellipsis
|
|
157
|
+
del right_indices[0]
|
|
158
|
+
|
|
159
|
+
n_indices = len(all_indices) - ellipsis_met - num_newaxis
|
|
160
|
+
if n_indices > ary.ndim:
|
|
161
|
+
raise NumbaTypeError(
|
|
162
|
+
"cannot index %s with %d indices: %s" % (ary, n_indices, idx)
|
|
163
|
+
)
|
|
164
|
+
if n_indices == ary.ndim and ndim == 0 and not ellipsis_met:
|
|
165
|
+
# Full integer indexing => scalar result
|
|
166
|
+
# (note if ellipsis is present, a 0-d view is returned instead)
|
|
167
|
+
res = ary.dtype
|
|
168
|
+
|
|
169
|
+
elif advanced:
|
|
170
|
+
# Result is a copy
|
|
171
|
+
res = ary.copy(ndim=ndim, layout="C", readonly=False)
|
|
172
|
+
|
|
173
|
+
else:
|
|
174
|
+
# Result is a view
|
|
175
|
+
if ary.slice_is_copy:
|
|
176
|
+
# Avoid view semantics when the original type creates a copy
|
|
177
|
+
# when slicing.
|
|
178
|
+
return
|
|
179
|
+
|
|
180
|
+
# Infer layout
|
|
181
|
+
layout = ary.layout
|
|
182
|
+
|
|
183
|
+
def keeps_contiguity(ty, is_innermost):
|
|
184
|
+
# A slice can only keep an array contiguous if it is the
|
|
185
|
+
# innermost index and it is not strided
|
|
186
|
+
return (
|
|
187
|
+
ty is types.ellipsis
|
|
188
|
+
or isinstance(ty, types.Integer)
|
|
189
|
+
or (
|
|
190
|
+
is_innermost
|
|
191
|
+
and isinstance(ty, types.SliceType)
|
|
192
|
+
and not ty.has_step
|
|
193
|
+
)
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
def check_contiguity(outer_indices):
|
|
197
|
+
"""
|
|
198
|
+
Whether indexing with the given indices (from outer to inner in
|
|
199
|
+
physical layout order) can keep an array contiguous.
|
|
200
|
+
"""
|
|
201
|
+
for ty in outer_indices[:-1]:
|
|
202
|
+
if not keeps_contiguity(ty, False):
|
|
203
|
+
return False
|
|
204
|
+
if outer_indices and not keeps_contiguity(outer_indices[-1], True):
|
|
205
|
+
return False
|
|
206
|
+
return True
|
|
207
|
+
|
|
208
|
+
if layout == "C":
|
|
209
|
+
# Integer indexing on the left keeps the array C-contiguous
|
|
210
|
+
if n_indices == ary.ndim:
|
|
211
|
+
# If all indices are there, ellipsis's place is indifferent
|
|
212
|
+
left_indices = left_indices + right_indices
|
|
213
|
+
right_indices = []
|
|
214
|
+
if right_indices:
|
|
215
|
+
layout = "A"
|
|
216
|
+
elif not check_contiguity(left_indices):
|
|
217
|
+
layout = "A"
|
|
218
|
+
elif layout == "F":
|
|
219
|
+
# Integer indexing on the right keeps the array F-contiguous
|
|
220
|
+
if n_indices == ary.ndim:
|
|
221
|
+
# If all indices are there, ellipsis's place is indifferent
|
|
222
|
+
right_indices = left_indices + right_indices
|
|
223
|
+
left_indices = []
|
|
224
|
+
if left_indices:
|
|
225
|
+
layout = "A"
|
|
226
|
+
elif not check_contiguity(right_indices[::-1]):
|
|
227
|
+
layout = "A"
|
|
228
|
+
|
|
229
|
+
if ndim == 0:
|
|
230
|
+
# Implicitly convert to a scalar if the output ndim==0
|
|
231
|
+
res = ary.dtype
|
|
232
|
+
else:
|
|
233
|
+
res = ary.copy(ndim=ndim, layout=layout)
|
|
234
|
+
|
|
235
|
+
# Re-wrap indices
|
|
236
|
+
if isinstance(idx, types.BaseTuple):
|
|
237
|
+
idx = types.BaseTuple.from_types(all_indices)
|
|
238
|
+
else:
|
|
239
|
+
(idx,) = all_indices
|
|
240
|
+
|
|
241
|
+
return Indexing(idx, res, advanced)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
@infer_global(operator.getitem)
|
|
245
|
+
class GetItemBuffer(AbstractTemplate):
|
|
246
|
+
def generic(self, args, kws):
|
|
247
|
+
assert not kws
|
|
248
|
+
[ary, idx] = args
|
|
249
|
+
out = get_array_index_type(ary, idx)
|
|
250
|
+
if out is not None:
|
|
251
|
+
return signature(out.result, ary, out.index)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@infer_global(operator.setitem)
|
|
255
|
+
class SetItemBuffer(AbstractTemplate):
|
|
256
|
+
def generic(self, args, kws):
|
|
257
|
+
assert not kws
|
|
258
|
+
ary, idx, val = args
|
|
259
|
+
if not isinstance(ary, types.Buffer):
|
|
260
|
+
return
|
|
261
|
+
if not ary.mutable:
|
|
262
|
+
msg = f"Cannot modify readonly array of type: {ary}"
|
|
263
|
+
raise NumbaTypeError(msg)
|
|
264
|
+
out = get_array_index_type(ary, idx)
|
|
265
|
+
if out is None:
|
|
266
|
+
return
|
|
267
|
+
|
|
268
|
+
idx = out.index
|
|
269
|
+
res = out.result # res is the result type of the access ary[idx]
|
|
270
|
+
if isinstance(res, types.Array):
|
|
271
|
+
# Indexing produces an array
|
|
272
|
+
if isinstance(val, types.Array):
|
|
273
|
+
if not self.context.can_convert(val.dtype, res.dtype):
|
|
274
|
+
# DType conversion not possible
|
|
275
|
+
return
|
|
276
|
+
else:
|
|
277
|
+
res = val
|
|
278
|
+
elif isinstance(val, types.Sequence):
|
|
279
|
+
if res.ndim == 1 and self.context.can_convert(
|
|
280
|
+
val.dtype, res.dtype
|
|
281
|
+
):
|
|
282
|
+
# Allow assignment of sequence to 1d array
|
|
283
|
+
res = val
|
|
284
|
+
else:
|
|
285
|
+
# NOTE: sequence-to-array broadcasting is unsupported
|
|
286
|
+
return
|
|
287
|
+
else:
|
|
288
|
+
# Allow scalar broadcasting
|
|
289
|
+
if self.context.can_convert(val, res.dtype):
|
|
290
|
+
res = res.dtype
|
|
291
|
+
else:
|
|
292
|
+
# Incompatible scalar type
|
|
293
|
+
return
|
|
294
|
+
elif not isinstance(val, types.Array):
|
|
295
|
+
# Single item assignment
|
|
296
|
+
if not self.context.can_convert(val, res):
|
|
297
|
+
# if the array dtype is not yet defined
|
|
298
|
+
if not res.is_precise():
|
|
299
|
+
# set the array type to use the dtype of value (RHS)
|
|
300
|
+
newary = ary.copy(dtype=val)
|
|
301
|
+
return signature(types.none, newary, idx, res)
|
|
302
|
+
else:
|
|
303
|
+
return
|
|
304
|
+
res = val
|
|
305
|
+
elif (
|
|
306
|
+
isinstance(val, types.Array)
|
|
307
|
+
and val.ndim == 0
|
|
308
|
+
and self.context.can_convert(val.dtype, res)
|
|
309
|
+
):
|
|
310
|
+
# val is an array(T, 0d, O), where T is the type of res, O is order
|
|
311
|
+
res = val
|
|
312
|
+
else:
|
|
313
|
+
return
|
|
314
|
+
return signature(types.none, ary, idx, res)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def normalize_shape(shape):
|
|
318
|
+
if isinstance(shape, types.UniTuple):
|
|
319
|
+
if isinstance(shape.dtype, types.Integer):
|
|
320
|
+
dimtype = types.intp if shape.dtype.signed else types.uintp
|
|
321
|
+
return types.UniTuple(dimtype, len(shape))
|
|
322
|
+
|
|
323
|
+
elif isinstance(shape, types.Tuple) and shape.count == 0:
|
|
324
|
+
# Force (0 x intp) for consistency with other shapes
|
|
325
|
+
return types.UniTuple(types.intp, 0)
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
@infer_getattr
|
|
329
|
+
class ArrayAttribute(AttributeTemplate):
|
|
330
|
+
key = types.Array
|
|
331
|
+
|
|
332
|
+
def resolve_dtype(self, ary):
|
|
333
|
+
return types.DType(ary.dtype)
|
|
334
|
+
|
|
335
|
+
def resolve_nbytes(self, ary):
|
|
336
|
+
return types.intp
|
|
337
|
+
|
|
338
|
+
def resolve_itemsize(self, ary):
|
|
339
|
+
return types.intp
|
|
340
|
+
|
|
341
|
+
def resolve_shape(self, ary):
|
|
342
|
+
return types.UniTuple(types.intp, ary.ndim)
|
|
343
|
+
|
|
344
|
+
def resolve_strides(self, ary):
|
|
345
|
+
return types.UniTuple(types.intp, ary.ndim)
|
|
346
|
+
|
|
347
|
+
def resolve_ndim(self, ary):
|
|
348
|
+
return types.intp
|
|
349
|
+
|
|
350
|
+
def resolve_size(self, ary):
|
|
351
|
+
return types.intp
|
|
352
|
+
|
|
353
|
+
def resolve_flat(self, ary):
|
|
354
|
+
return types.NumpyFlatType(ary)
|
|
355
|
+
|
|
356
|
+
def resolve_ctypes(self, ary):
|
|
357
|
+
return types.ArrayCTypes(ary)
|
|
358
|
+
|
|
359
|
+
def resolve_flags(self, ary):
|
|
360
|
+
return types.ArrayFlags(ary)
|
|
361
|
+
|
|
362
|
+
def resolve_T(self, ary):
|
|
363
|
+
if ary.ndim <= 1:
|
|
364
|
+
retty = ary
|
|
365
|
+
else:
|
|
366
|
+
layout = {"C": "F", "F": "C"}.get(ary.layout, "A")
|
|
367
|
+
retty = ary.copy(layout=layout)
|
|
368
|
+
return retty
|
|
369
|
+
|
|
370
|
+
def resolve_real(self, ary):
|
|
371
|
+
return self._resolve_real_imag(ary, attr="real")
|
|
372
|
+
|
|
373
|
+
def resolve_imag(self, ary):
|
|
374
|
+
return self._resolve_real_imag(ary, attr="imag")
|
|
375
|
+
|
|
376
|
+
def _resolve_real_imag(self, ary, attr):
|
|
377
|
+
if ary.dtype in types.complex_domain:
|
|
378
|
+
return ary.copy(dtype=ary.dtype.underlying_float, layout="A")
|
|
379
|
+
elif ary.dtype in types.number_domain:
|
|
380
|
+
res = ary.copy(dtype=ary.dtype)
|
|
381
|
+
if attr == "imag":
|
|
382
|
+
res = res.copy(readonly=True)
|
|
383
|
+
return res
|
|
384
|
+
else:
|
|
385
|
+
msg = "cannot access .{} of array of {}"
|
|
386
|
+
raise TypingError(msg.format(attr, ary.dtype))
|
|
387
|
+
|
|
388
|
+
@bound_function("array.transpose")
|
|
389
|
+
def resolve_transpose(self, ary, args, kws):
|
|
390
|
+
def sentry_shape_scalar(ty):
|
|
391
|
+
if ty in types.number_domain:
|
|
392
|
+
# Guard against non integer type
|
|
393
|
+
if not isinstance(ty, types.Integer):
|
|
394
|
+
msg = "transpose() arg cannot be {0}".format(ty)
|
|
395
|
+
raise TypingError(msg)
|
|
396
|
+
return True
|
|
397
|
+
else:
|
|
398
|
+
return False
|
|
399
|
+
|
|
400
|
+
assert not kws
|
|
401
|
+
if len(args) == 0:
|
|
402
|
+
return signature(self.resolve_T(ary))
|
|
403
|
+
|
|
404
|
+
if len(args) == 1:
|
|
405
|
+
(shape,) = args
|
|
406
|
+
|
|
407
|
+
if sentry_shape_scalar(shape):
|
|
408
|
+
assert ary.ndim == 1
|
|
409
|
+
return signature(ary, *args)
|
|
410
|
+
|
|
411
|
+
if isinstance(shape, types.NoneType):
|
|
412
|
+
return signature(self.resolve_T(ary))
|
|
413
|
+
|
|
414
|
+
shape = normalize_shape(shape)
|
|
415
|
+
if shape is None:
|
|
416
|
+
return
|
|
417
|
+
|
|
418
|
+
assert ary.ndim == shape.count
|
|
419
|
+
return signature(self.resolve_T(ary).copy(layout="A"), shape)
|
|
420
|
+
|
|
421
|
+
else:
|
|
422
|
+
if any(not sentry_shape_scalar(a) for a in args):
|
|
423
|
+
msg = "transpose({0}) is not supported".format(", ".join(args))
|
|
424
|
+
raise TypingError(msg)
|
|
425
|
+
assert ary.ndim == len(args)
|
|
426
|
+
return signature(self.resolve_T(ary).copy(layout="A"), *args)
|
|
427
|
+
|
|
428
|
+
@bound_function("array.copy")
|
|
429
|
+
def resolve_copy(self, ary, args, kws):
|
|
430
|
+
assert not args
|
|
431
|
+
assert not kws
|
|
432
|
+
retty = ary.copy(layout="C", readonly=False)
|
|
433
|
+
return signature(retty)
|
|
434
|
+
|
|
435
|
+
@bound_function("array.item")
|
|
436
|
+
def resolve_item(self, ary, args, kws):
|
|
437
|
+
assert not kws
|
|
438
|
+
# We don't support explicit arguments as that's exactly equivalent
|
|
439
|
+
# to regular indexing. The no-argument form is interesting to
|
|
440
|
+
# allow some degree of genericity when writing functions.
|
|
441
|
+
if not args:
|
|
442
|
+
return signature(ary.dtype)
|
|
443
|
+
|
|
444
|
+
if numpy_version < (2, 0):
|
|
445
|
+
|
|
446
|
+
@bound_function("array.itemset")
|
|
447
|
+
def resolve_itemset(self, ary, args, kws):
|
|
448
|
+
assert not kws
|
|
449
|
+
# We don't support explicit arguments as that's exactly equivalent
|
|
450
|
+
# to regular indexing. The no-argument form is interesting to
|
|
451
|
+
# allow some degree of genericity when writing functions.
|
|
452
|
+
if len(args) == 1:
|
|
453
|
+
return signature(types.none, ary.dtype)
|
|
454
|
+
|
|
455
|
+
@bound_function("array.nonzero")
|
|
456
|
+
def resolve_nonzero(self, ary, args, kws):
|
|
457
|
+
assert not args
|
|
458
|
+
assert not kws
|
|
459
|
+
if ary.ndim == 0 and numpy_version >= (2, 1):
|
|
460
|
+
raise NumbaValueError(
|
|
461
|
+
"Calling nonzero on 0d arrays is not allowed."
|
|
462
|
+
" Use np.atleast_1d(scalar).nonzero() instead."
|
|
463
|
+
)
|
|
464
|
+
# 0-dim arrays return one result array
|
|
465
|
+
ndim = max(ary.ndim, 1)
|
|
466
|
+
retty = types.UniTuple(types.Array(types.intp, 1, "C"), ndim)
|
|
467
|
+
return signature(retty)
|
|
468
|
+
|
|
469
|
+
@bound_function("array.reshape")
|
|
470
|
+
def resolve_reshape(self, ary, args, kws):
|
|
471
|
+
def sentry_shape_scalar(ty):
|
|
472
|
+
if ty in types.number_domain:
|
|
473
|
+
# Guard against non integer type
|
|
474
|
+
if not isinstance(ty, types.Integer):
|
|
475
|
+
raise TypingError("reshape() arg cannot be {0}".format(ty))
|
|
476
|
+
return True
|
|
477
|
+
else:
|
|
478
|
+
return False
|
|
479
|
+
|
|
480
|
+
assert not kws
|
|
481
|
+
if ary.layout not in "CF":
|
|
482
|
+
# only work for contiguous array
|
|
483
|
+
raise TypingError("reshape() supports contiguous array only")
|
|
484
|
+
|
|
485
|
+
if len(args) == 1:
|
|
486
|
+
# single arg
|
|
487
|
+
(shape,) = args
|
|
488
|
+
|
|
489
|
+
if sentry_shape_scalar(shape):
|
|
490
|
+
ndim = 1
|
|
491
|
+
else:
|
|
492
|
+
shape = normalize_shape(shape)
|
|
493
|
+
if shape is None:
|
|
494
|
+
return
|
|
495
|
+
ndim = shape.count
|
|
496
|
+
retty = ary.copy(ndim=ndim)
|
|
497
|
+
return signature(retty, shape)
|
|
498
|
+
|
|
499
|
+
elif len(args) == 0:
|
|
500
|
+
# no arg
|
|
501
|
+
raise TypingError("reshape() take at least one arg")
|
|
502
|
+
|
|
503
|
+
else:
|
|
504
|
+
# vararg case
|
|
505
|
+
if any(not sentry_shape_scalar(a) for a in args):
|
|
506
|
+
raise TypingError(
|
|
507
|
+
"reshape({0}) is not supported".format(
|
|
508
|
+
", ".join(map(str, args))
|
|
509
|
+
)
|
|
510
|
+
)
|
|
511
|
+
|
|
512
|
+
retty = ary.copy(ndim=len(args))
|
|
513
|
+
return signature(retty, *args)
|
|
514
|
+
|
|
515
|
+
@bound_function("array.sort")
|
|
516
|
+
def resolve_sort(self, ary, args, kws):
|
|
517
|
+
assert not args
|
|
518
|
+
assert not kws
|
|
519
|
+
return signature(types.none)
|
|
520
|
+
|
|
521
|
+
@bound_function("array.view")
|
|
522
|
+
def resolve_view(self, ary, args, kws):
|
|
523
|
+
from .npydecl import parse_dtype
|
|
524
|
+
|
|
525
|
+
assert not kws
|
|
526
|
+
(dtype,) = args
|
|
527
|
+
dtype = parse_dtype(dtype)
|
|
528
|
+
if dtype is None:
|
|
529
|
+
return
|
|
530
|
+
retty = ary.copy(dtype=dtype)
|
|
531
|
+
return signature(retty, *args)
|
|
532
|
+
|
|
533
|
+
@bound_function("array.astype")
|
|
534
|
+
def resolve_astype(self, ary, args, kws):
|
|
535
|
+
from .npydecl import parse_dtype
|
|
536
|
+
|
|
537
|
+
assert not kws
|
|
538
|
+
(dtype,) = args
|
|
539
|
+
if isinstance(dtype, types.UnicodeType):
|
|
540
|
+
raise RequireLiteralValue(
|
|
541
|
+
("array.astype if dtype is a string it must be constant")
|
|
542
|
+
)
|
|
543
|
+
dtype = parse_dtype(dtype)
|
|
544
|
+
if dtype is None:
|
|
545
|
+
return
|
|
546
|
+
if not self.context.can_convert(ary.dtype, dtype):
|
|
547
|
+
raise TypingError(
|
|
548
|
+
"astype(%s) not supported on %s: "
|
|
549
|
+
"cannot convert from %s to %s" % (dtype, ary, ary.dtype, dtype)
|
|
550
|
+
)
|
|
551
|
+
layout = ary.layout if ary.layout in "CF" else "C"
|
|
552
|
+
# reset the write bit irrespective of whether the cast type is the same
|
|
553
|
+
# as the current dtype, this replicates numpy
|
|
554
|
+
retty = ary.copy(dtype=dtype, layout=layout, readonly=False)
|
|
555
|
+
return signature(retty, *args)
|
|
556
|
+
|
|
557
|
+
@bound_function("array.ravel")
|
|
558
|
+
def resolve_ravel(self, ary, args, kws):
|
|
559
|
+
# Only support no argument version (default order='C')
|
|
560
|
+
assert not kws
|
|
561
|
+
assert not args
|
|
562
|
+
copy_will_be_made = ary.layout != "C"
|
|
563
|
+
readonly = not (copy_will_be_made or ary.mutable)
|
|
564
|
+
return signature(ary.copy(ndim=1, layout="C", readonly=readonly))
|
|
565
|
+
|
|
566
|
+
@bound_function("array.flatten")
|
|
567
|
+
def resolve_flatten(self, ary, args, kws):
|
|
568
|
+
# Only support no argument version (default order='C')
|
|
569
|
+
assert not kws
|
|
570
|
+
assert not args
|
|
571
|
+
# To ensure that Numba behaves exactly like NumPy,
|
|
572
|
+
# we also clear the read-only flag when doing a "flatten"
|
|
573
|
+
# Why? Two reasons:
|
|
574
|
+
# Because flatten always returns a copy. (see NumPy docs for "flatten")
|
|
575
|
+
# And because a copy always returns a writeable array.
|
|
576
|
+
# ref: https://numpy.org/doc/stable/reference/generated/numpy.copy.html
|
|
577
|
+
return signature(ary.copy(ndim=1, layout="C", readonly=False))
|
|
578
|
+
|
|
579
|
+
def generic_resolve(self, ary, attr):
|
|
580
|
+
# Resolution of other attributes, for record arrays
|
|
581
|
+
if isinstance(ary.dtype, types.Record):
|
|
582
|
+
if attr in ary.dtype.fields:
|
|
583
|
+
attr_dtype = ary.dtype.typeof(attr)
|
|
584
|
+
if isinstance(attr_dtype, types.NestedArray):
|
|
585
|
+
return ary.copy(
|
|
586
|
+
dtype=attr_dtype.dtype,
|
|
587
|
+
ndim=ary.ndim + attr_dtype.ndim,
|
|
588
|
+
layout="A",
|
|
589
|
+
)
|
|
590
|
+
else:
|
|
591
|
+
return ary.copy(dtype=attr_dtype, layout="A")
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
@infer_getattr
|
|
595
|
+
class DTypeAttr(AttributeTemplate):
|
|
596
|
+
key = types.DType
|
|
597
|
+
|
|
598
|
+
def resolve_type(self, ary):
|
|
599
|
+
# Wrap the numeric type in NumberClass
|
|
600
|
+
return types.NumberClass(ary.dtype)
|
|
601
|
+
|
|
602
|
+
def resolve_kind(self, ary):
|
|
603
|
+
if isinstance(ary.key, types.scalars.Float):
|
|
604
|
+
val = "f"
|
|
605
|
+
elif isinstance(ary.key, types.scalars.Integer):
|
|
606
|
+
val = "i"
|
|
607
|
+
else:
|
|
608
|
+
return None # other types not supported yet
|
|
609
|
+
return types.StringLiteral(val)
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
@infer
|
|
613
|
+
class StaticGetItemArray(AbstractTemplate):
|
|
614
|
+
key = "static_getitem"
|
|
615
|
+
|
|
616
|
+
def generic(self, args, kws):
|
|
617
|
+
# Resolution of members for record and structured arrays
|
|
618
|
+
ary, idx = args
|
|
619
|
+
if (
|
|
620
|
+
isinstance(ary, types.Array)
|
|
621
|
+
and isinstance(idx, str)
|
|
622
|
+
and isinstance(ary.dtype, types.Record)
|
|
623
|
+
):
|
|
624
|
+
if idx in ary.dtype.fields:
|
|
625
|
+
attr_dtype = ary.dtype.typeof(idx)
|
|
626
|
+
if isinstance(attr_dtype, types.NestedArray):
|
|
627
|
+
ret = ary.copy(
|
|
628
|
+
dtype=attr_dtype.dtype,
|
|
629
|
+
ndim=ary.ndim + attr_dtype.ndim,
|
|
630
|
+
layout="A",
|
|
631
|
+
)
|
|
632
|
+
return signature(ret, *args)
|
|
633
|
+
else:
|
|
634
|
+
ret = ary.copy(dtype=attr_dtype, layout="A")
|
|
635
|
+
return signature(ret, *args)
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
@infer_getattr
|
|
639
|
+
class RecordAttribute(AttributeTemplate):
|
|
640
|
+
key = types.Record
|
|
641
|
+
|
|
642
|
+
def generic_resolve(self, record, attr):
|
|
643
|
+
ret = record.typeof(attr)
|
|
644
|
+
assert ret
|
|
645
|
+
return ret
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
@infer
|
|
649
|
+
class StaticGetItemRecord(AbstractTemplate):
|
|
650
|
+
key = "static_getitem"
|
|
651
|
+
|
|
652
|
+
def generic(self, args, kws):
|
|
653
|
+
# Resolution of members for records
|
|
654
|
+
record, idx = args
|
|
655
|
+
if isinstance(record, types.Record) and isinstance(idx, str):
|
|
656
|
+
if idx not in record.fields:
|
|
657
|
+
raise NumbaKeyError(
|
|
658
|
+
f"Field '{idx}' was not found in record "
|
|
659
|
+
"with fields "
|
|
660
|
+
f"{tuple(record.fields.keys())}"
|
|
661
|
+
)
|
|
662
|
+
ret = record.typeof(idx)
|
|
663
|
+
assert ret
|
|
664
|
+
return signature(ret, *args)
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
@infer_global(operator.getitem)
|
|
668
|
+
class StaticGetItemLiteralRecord(AbstractTemplate):
|
|
669
|
+
def generic(self, args, kws):
|
|
670
|
+
# Resolution of members for records
|
|
671
|
+
record, idx = args
|
|
672
|
+
if isinstance(record, types.Record):
|
|
673
|
+
if isinstance(idx, types.StringLiteral):
|
|
674
|
+
if idx.literal_value not in record.fields:
|
|
675
|
+
msg = (
|
|
676
|
+
f"Field '{idx.literal_value}' was not found in "
|
|
677
|
+
f"record with fields {tuple(record.fields.keys())}"
|
|
678
|
+
)
|
|
679
|
+
raise NumbaKeyError(msg)
|
|
680
|
+
ret = record.typeof(idx.literal_value)
|
|
681
|
+
assert ret
|
|
682
|
+
return signature(ret, *args)
|
|
683
|
+
elif isinstance(idx, types.IntegerLiteral):
|
|
684
|
+
if idx.literal_value >= len(record.fields):
|
|
685
|
+
msg = f"Requested index {idx.literal_value} is out of range"
|
|
686
|
+
raise NumbaIndexError(msg)
|
|
687
|
+
field_names = list(record.fields)
|
|
688
|
+
ret = record.typeof(field_names[idx.literal_value])
|
|
689
|
+
assert ret
|
|
690
|
+
return signature(ret, *args)
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
@infer
|
|
694
|
+
class StaticSetItemRecord(AbstractTemplate):
|
|
695
|
+
key = "static_setitem"
|
|
696
|
+
|
|
697
|
+
def generic(self, args, kws):
|
|
698
|
+
# Resolution of members for record and structured arrays
|
|
699
|
+
record, idx, value = args
|
|
700
|
+
if isinstance(record, types.Record):
|
|
701
|
+
if isinstance(idx, str):
|
|
702
|
+
expectedty = record.typeof(idx)
|
|
703
|
+
if self.context.can_convert(value, expectedty) is not None:
|
|
704
|
+
return signature(
|
|
705
|
+
types.void, record, types.literal(idx), value
|
|
706
|
+
)
|
|
707
|
+
elif isinstance(idx, int):
|
|
708
|
+
if idx >= len(record.fields):
|
|
709
|
+
msg = f"Requested index {idx} is out of range"
|
|
710
|
+
raise NumbaIndexError(msg)
|
|
711
|
+
str_field = list(record.fields)[idx]
|
|
712
|
+
expectedty = record.typeof(str_field)
|
|
713
|
+
if self.context.can_convert(value, expectedty) is not None:
|
|
714
|
+
return signature(
|
|
715
|
+
types.void, record, types.literal(idx), value
|
|
716
|
+
)
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
@infer_global(operator.setitem)
|
|
720
|
+
class StaticSetItemLiteralRecord(AbstractTemplate):
|
|
721
|
+
def generic(self, args, kws):
|
|
722
|
+
# Resolution of members for records
|
|
723
|
+
target, idx, value = args
|
|
724
|
+
if isinstance(target, types.Record) and isinstance(
|
|
725
|
+
idx, types.StringLiteral
|
|
726
|
+
):
|
|
727
|
+
if idx.literal_value not in target.fields:
|
|
728
|
+
msg = (
|
|
729
|
+
f"Field '{idx.literal_value}' was not found in record "
|
|
730
|
+
f"with fields {tuple(target.fields.keys())}"
|
|
731
|
+
)
|
|
732
|
+
raise NumbaKeyError(msg)
|
|
733
|
+
expectedty = target.typeof(idx.literal_value)
|
|
734
|
+
if self.context.can_convert(value, expectedty) is not None:
|
|
735
|
+
return signature(types.void, target, idx, value)
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
@infer_getattr
|
|
739
|
+
class ArrayCTypesAttribute(AttributeTemplate):
|
|
740
|
+
key = types.ArrayCTypes
|
|
741
|
+
|
|
742
|
+
def resolve_data(self, ctinfo):
|
|
743
|
+
return types.uintp
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
@infer_getattr
|
|
747
|
+
class ArrayFlagsAttribute(AttributeTemplate):
|
|
748
|
+
key = types.ArrayFlags
|
|
749
|
+
|
|
750
|
+
def resolve_contiguous(self, ctflags):
|
|
751
|
+
return types.boolean
|
|
752
|
+
|
|
753
|
+
def resolve_c_contiguous(self, ctflags):
|
|
754
|
+
return types.boolean
|
|
755
|
+
|
|
756
|
+
def resolve_f_contiguous(self, ctflags):
|
|
757
|
+
return types.boolean
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
@infer_getattr
|
|
761
|
+
class NestedArrayAttribute(ArrayAttribute):
|
|
762
|
+
key = types.NestedArray
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
def _expand_integer(ty):
|
|
766
|
+
"""
|
|
767
|
+
If *ty* is an integer, expand it to a machine int (like Numpy).
|
|
768
|
+
"""
|
|
769
|
+
if isinstance(ty, types.Integer):
|
|
770
|
+
if ty.signed:
|
|
771
|
+
return max(types.intp, ty)
|
|
772
|
+
else:
|
|
773
|
+
return max(types.uintp, ty)
|
|
774
|
+
elif isinstance(ty, types.Boolean):
|
|
775
|
+
return types.intp
|
|
776
|
+
else:
|
|
777
|
+
return ty
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
def generic_homog(self, args, kws):
|
|
781
|
+
if args:
|
|
782
|
+
raise NumbaAssertionError("args not supported")
|
|
783
|
+
if kws:
|
|
784
|
+
raise NumbaAssertionError("kws not supported")
|
|
785
|
+
|
|
786
|
+
return signature(self.this.dtype, recvr=self.this)
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
def generic_expand(self, args, kws):
|
|
790
|
+
assert not args
|
|
791
|
+
assert not kws
|
|
792
|
+
return signature(_expand_integer(self.this.dtype), recvr=self.this)
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
def sum_expand(self, args, kws):
|
|
796
|
+
"""
|
|
797
|
+
sum can be called with or without an axis parameter, and with or without
|
|
798
|
+
a dtype parameter
|
|
799
|
+
"""
|
|
800
|
+
pysig = None
|
|
801
|
+
if "axis" in kws and "dtype" not in kws:
|
|
802
|
+
|
|
803
|
+
def sum_stub(axis):
|
|
804
|
+
pass
|
|
805
|
+
|
|
806
|
+
pysig = utils.pysignature(sum_stub)
|
|
807
|
+
# rewrite args
|
|
808
|
+
args = list(args) + [kws["axis"]]
|
|
809
|
+
elif "dtype" in kws and "axis" not in kws:
|
|
810
|
+
|
|
811
|
+
def sum_stub(dtype):
|
|
812
|
+
pass
|
|
813
|
+
|
|
814
|
+
pysig = utils.pysignature(sum_stub)
|
|
815
|
+
# rewrite args
|
|
816
|
+
args = list(args) + [kws["dtype"]]
|
|
817
|
+
elif "dtype" in kws and "axis" in kws:
|
|
818
|
+
|
|
819
|
+
def sum_stub(axis, dtype):
|
|
820
|
+
pass
|
|
821
|
+
|
|
822
|
+
pysig = utils.pysignature(sum_stub)
|
|
823
|
+
# rewrite args
|
|
824
|
+
args = list(args) + [kws["axis"], kws["dtype"]]
|
|
825
|
+
|
|
826
|
+
args_len = len(args)
|
|
827
|
+
assert args_len <= 2
|
|
828
|
+
if args_len == 0:
|
|
829
|
+
# No axis or dtype parameter so the return type of the summation is a scalar
|
|
830
|
+
# of the type of the array.
|
|
831
|
+
out = signature(
|
|
832
|
+
_expand_integer(self.this.dtype), *args, recvr=self.this
|
|
833
|
+
)
|
|
834
|
+
elif args_len == 1 and "dtype" not in kws:
|
|
835
|
+
# There is an axis parameter, either arg or kwarg
|
|
836
|
+
if self.this.ndim == 1:
|
|
837
|
+
# 1d reduces to a scalar
|
|
838
|
+
return_type = _expand_integer(self.this.dtype)
|
|
839
|
+
else:
|
|
840
|
+
# the return type of this summation is an array of dimension one
|
|
841
|
+
# less than the input array.
|
|
842
|
+
return_type = types.Array(
|
|
843
|
+
dtype=_expand_integer(self.this.dtype),
|
|
844
|
+
ndim=self.this.ndim - 1,
|
|
845
|
+
layout="C",
|
|
846
|
+
)
|
|
847
|
+
out = signature(return_type, *args, recvr=self.this)
|
|
848
|
+
|
|
849
|
+
elif args_len == 1 and "dtype" in kws:
|
|
850
|
+
# No axis parameter so the return type of the summation is a scalar
|
|
851
|
+
# of the dtype parameter.
|
|
852
|
+
from .npydecl import parse_dtype
|
|
853
|
+
|
|
854
|
+
(dtype,) = args
|
|
855
|
+
dtype = parse_dtype(dtype)
|
|
856
|
+
out = signature(dtype, *args, recvr=self.this)
|
|
857
|
+
|
|
858
|
+
elif args_len == 2:
|
|
859
|
+
# There is an axis and dtype parameter, either arg or kwarg
|
|
860
|
+
from .npydecl import parse_dtype
|
|
861
|
+
|
|
862
|
+
dtype = parse_dtype(args[1])
|
|
863
|
+
return_type = dtype
|
|
864
|
+
if self.this.ndim != 1:
|
|
865
|
+
# 1d reduces to a scalar, 2d and above reduce dim by 1
|
|
866
|
+
# the return type of this summation is an array of dimension one
|
|
867
|
+
# less than the input array.
|
|
868
|
+
return_type = types.Array(
|
|
869
|
+
dtype=return_type, ndim=self.this.ndim - 1, layout="C"
|
|
870
|
+
)
|
|
871
|
+
out = signature(return_type, *args, recvr=self.this)
|
|
872
|
+
else:
|
|
873
|
+
pass
|
|
874
|
+
return out.replace(pysig=pysig)
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
def generic_expand_cumulative(self, args, kws):
|
|
878
|
+
if args:
|
|
879
|
+
raise NumbaAssertionError("args unsupported")
|
|
880
|
+
if kws:
|
|
881
|
+
raise NumbaAssertionError("kwargs unsupported")
|
|
882
|
+
assert isinstance(self.this, types.Array)
|
|
883
|
+
return_type = types.Array(
|
|
884
|
+
dtype=_expand_integer(self.this.dtype), ndim=1, layout="C"
|
|
885
|
+
)
|
|
886
|
+
return signature(return_type, recvr=self.this)
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
def generic_hetero_real(self, args, kws):
|
|
890
|
+
assert not args
|
|
891
|
+
assert not kws
|
|
892
|
+
if isinstance(self.this.dtype, (types.Integer, types.Boolean)):
|
|
893
|
+
return signature(types.float64, recvr=self.this)
|
|
894
|
+
return signature(self.this.dtype, recvr=self.this)
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
def generic_hetero_always_real(self, args, kws):
|
|
898
|
+
assert not args
|
|
899
|
+
assert not kws
|
|
900
|
+
if isinstance(self.this.dtype, (types.Integer, types.Boolean)):
|
|
901
|
+
return signature(types.float64, recvr=self.this)
|
|
902
|
+
if isinstance(self.this.dtype, types.Complex):
|
|
903
|
+
return signature(self.this.dtype.underlying_float, recvr=self.this)
|
|
904
|
+
return signature(self.this.dtype, recvr=self.this)
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
def generic_index(self, args, kws):
|
|
908
|
+
assert not args
|
|
909
|
+
assert not kws
|
|
910
|
+
return signature(types.intp, recvr=self.this)
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
def install_array_method(name, generic, prefer_literal=True):
|
|
914
|
+
my_attr = {
|
|
915
|
+
"key": "array." + name,
|
|
916
|
+
"generic": generic,
|
|
917
|
+
"prefer_literal": prefer_literal,
|
|
918
|
+
}
|
|
919
|
+
temp_class = type("Array_" + name, (AbstractTemplate,), my_attr)
|
|
920
|
+
|
|
921
|
+
def array_attribute_attachment(self, ary):
|
|
922
|
+
return types.BoundFunction(temp_class, ary)
|
|
923
|
+
|
|
924
|
+
setattr(ArrayAttribute, "resolve_" + name, array_attribute_attachment)
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
# Functions that return a machine-width type, to avoid overflows
|
|
928
|
+
install_array_method("sum", sum_expand, prefer_literal=True)
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
@infer_global(operator.eq)
|
|
932
|
+
class CmpOpEqArray(AbstractTemplate):
|
|
933
|
+
# key = operator.eq
|
|
934
|
+
|
|
935
|
+
def generic(self, args, kws):
|
|
936
|
+
assert not kws
|
|
937
|
+
[va, vb] = args
|
|
938
|
+
if isinstance(va, types.Array) and va == vb:
|
|
939
|
+
return signature(va.copy(dtype=types.boolean), va, vb)
|