numba-cuda 0.22.0__cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.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 +580 -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.cpp +159 -0
- numba_cuda/numba/cuda/cext/_devicearray.cpython-313-aarch64-linux-gnu.so +0 -0
- numba_cuda/numba/cuda/cext/_devicearray.h +29 -0
- numba_cuda/numba/cuda/cext/_dispatcher.cpp +1098 -0
- numba_cuda/numba/cuda/cext/_dispatcher.cpython-313-aarch64-linux-gnu.so +0 -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.cpython-313-aarch64-linux-gnu.so +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.cpp +206 -0
- numba_cuda/numba/cuda/cext/_typeconv.cpython-313-aarch64-linux-gnu.so +0 -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.cpython-313-aarch64-linux-gnu.so +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 +543 -0
- numba_cuda/numba/cuda/cudadrv/__init__.py +14 -0
- numba_cuda/numba/cuda/cudadrv/devicearray.py +954 -0
- numba_cuda/numba/cuda/cudadrv/devices.py +249 -0
- numba_cuda/numba/cuda/cudadrv/driver.py +3238 -0
- numba_cuda/numba/cuda/cudadrv/drvapi.py +435 -0
- numba_cuda/numba/cuda/cudadrv/dummyarray.py +562 -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 +983 -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 +997 -0
- numba_cuda/numba/cuda/decorators.py +294 -0
- numba_cuda/numba/cuda/descriptor.py +35 -0
- numba_cuda/numba/cuda/device_init.py +155 -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/intrinsics.py +531 -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 +1980 -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 +624 -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 +191 -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 +200 -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 +978 -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 +446 -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 +452 -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.22.0.dist-info/METADATA +109 -0
- numba_cuda-0.22.0.dist-info/RECORD +487 -0
- numba_cuda-0.22.0.dist-info/WHEEL +6 -0
- numba_cuda-0.22.0.dist-info/licenses/LICENSE +26 -0
- numba_cuda-0.22.0.dist-info/licenses/LICENSE.numba +24 -0
- numba_cuda-0.22.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
# SPDX-License-Identifier: BSD-2-Clause
|
|
3
|
+
|
|
4
|
+
from collections import namedtuple
|
|
5
|
+
import itertools
|
|
6
|
+
import functools
|
|
7
|
+
import operator
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Extent = namedtuple("Extent", ["begin", "end"])
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def attempt_nocopy_reshape(
|
|
15
|
+
nd, dims, strides, newnd, newdims, newstrides, itemsize, is_f_order
|
|
16
|
+
):
|
|
17
|
+
"""
|
|
18
|
+
Attempt to reshape an array without copying data.
|
|
19
|
+
|
|
20
|
+
This function should correctly handle all reshapes, including
|
|
21
|
+
axes of length 1. Zero strides should work but are untested.
|
|
22
|
+
|
|
23
|
+
If a copy is needed, returns 0
|
|
24
|
+
If no copy is needed, returns 1 and fills `newstrides`
|
|
25
|
+
with appropriate strides
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
olddims = []
|
|
29
|
+
oldstrides = []
|
|
30
|
+
oldnd = 0
|
|
31
|
+
|
|
32
|
+
# Remove axes with dimension 1 from the old array. They have no effect
|
|
33
|
+
# but would need special cases since their strides do not matter.
|
|
34
|
+
for oi in range(nd):
|
|
35
|
+
if dims[oi] != 1:
|
|
36
|
+
olddims.append(dims[oi])
|
|
37
|
+
oldstrides.append(strides[oi])
|
|
38
|
+
oldnd += 1
|
|
39
|
+
|
|
40
|
+
# Calculate total sizes
|
|
41
|
+
np_total = 1
|
|
42
|
+
for ni in range(newnd):
|
|
43
|
+
np_total *= newdims[ni]
|
|
44
|
+
|
|
45
|
+
op_total = 1
|
|
46
|
+
for oi in range(oldnd):
|
|
47
|
+
op_total *= olddims[oi]
|
|
48
|
+
|
|
49
|
+
if np_total != op_total:
|
|
50
|
+
# Different total sizes; no hope
|
|
51
|
+
return 0
|
|
52
|
+
|
|
53
|
+
if np_total == 0:
|
|
54
|
+
# Handle zero-sized arrays
|
|
55
|
+
# Just make the strides vaguely reasonable
|
|
56
|
+
# (they can have any value in theory).
|
|
57
|
+
for i in range(newnd):
|
|
58
|
+
newstrides[i] = itemsize
|
|
59
|
+
return 1
|
|
60
|
+
|
|
61
|
+
# oi to oj and ni to nj give the axis ranges currently worked with
|
|
62
|
+
oi = 0
|
|
63
|
+
oj = 1
|
|
64
|
+
ni = 0
|
|
65
|
+
nj = 1
|
|
66
|
+
|
|
67
|
+
while ni < newnd and oi < oldnd:
|
|
68
|
+
np = newdims[ni]
|
|
69
|
+
op = olddims[oi]
|
|
70
|
+
|
|
71
|
+
while np != op:
|
|
72
|
+
if np < op:
|
|
73
|
+
# Misses trailing 1s, these are handled later
|
|
74
|
+
np *= newdims[nj]
|
|
75
|
+
nj += 1
|
|
76
|
+
else:
|
|
77
|
+
op *= olddims[oj]
|
|
78
|
+
oj += 1
|
|
79
|
+
|
|
80
|
+
# Check whether the original axes can be combined
|
|
81
|
+
for ok in range(oi, oj - 1):
|
|
82
|
+
if is_f_order:
|
|
83
|
+
if oldstrides[ok + 1] != olddims[ok] * oldstrides[ok]:
|
|
84
|
+
# not contiguous enough
|
|
85
|
+
return 0
|
|
86
|
+
else:
|
|
87
|
+
# C order
|
|
88
|
+
if oldstrides[ok] != olddims[ok + 1] * oldstrides[ok + 1]:
|
|
89
|
+
# not contiguous enough
|
|
90
|
+
return 0
|
|
91
|
+
|
|
92
|
+
# Calculate new strides for all axes currently worked with
|
|
93
|
+
if is_f_order:
|
|
94
|
+
newstrides[ni] = oldstrides[oi]
|
|
95
|
+
for nk in range(ni + 1, nj):
|
|
96
|
+
newstrides[nk] = newstrides[nk - 1] * newdims[nk - 1]
|
|
97
|
+
else:
|
|
98
|
+
# C order
|
|
99
|
+
newstrides[nj - 1] = oldstrides[oj - 1]
|
|
100
|
+
for nk in range(nj - 1, ni, -1):
|
|
101
|
+
newstrides[nk - 1] = newstrides[nk] * newdims[nk]
|
|
102
|
+
|
|
103
|
+
ni = nj
|
|
104
|
+
nj += 1
|
|
105
|
+
oi = oj
|
|
106
|
+
oj += 1
|
|
107
|
+
|
|
108
|
+
# Set strides corresponding to trailing 1s of the new shape
|
|
109
|
+
if ni >= 1:
|
|
110
|
+
last_stride = newstrides[ni - 1]
|
|
111
|
+
else:
|
|
112
|
+
last_stride = itemsize
|
|
113
|
+
|
|
114
|
+
if is_f_order:
|
|
115
|
+
last_stride *= newdims[ni - 1]
|
|
116
|
+
|
|
117
|
+
for nk in range(ni, newnd):
|
|
118
|
+
newstrides[nk] = last_stride
|
|
119
|
+
|
|
120
|
+
return 1
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class Dim(object):
|
|
124
|
+
"""A single dimension of the array
|
|
125
|
+
|
|
126
|
+
Attributes
|
|
127
|
+
----------
|
|
128
|
+
start:
|
|
129
|
+
start offset
|
|
130
|
+
stop:
|
|
131
|
+
stop offset
|
|
132
|
+
size:
|
|
133
|
+
number of items
|
|
134
|
+
stride:
|
|
135
|
+
item stride
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
__slots__ = "start", "stop", "size", "stride", "single"
|
|
139
|
+
|
|
140
|
+
def __init__(self, start, stop, size, stride, single):
|
|
141
|
+
self.start = start
|
|
142
|
+
self.stop = stop
|
|
143
|
+
self.size = size
|
|
144
|
+
self.stride = stride
|
|
145
|
+
self.single = single
|
|
146
|
+
assert not single or size == 1
|
|
147
|
+
|
|
148
|
+
def __getitem__(self, item):
|
|
149
|
+
if isinstance(item, slice):
|
|
150
|
+
start, stop, step = item.indices(self.size)
|
|
151
|
+
stride = step * self.stride
|
|
152
|
+
start = self.start + start * abs(self.stride)
|
|
153
|
+
stop = self.start + stop * abs(self.stride)
|
|
154
|
+
if stride == 0:
|
|
155
|
+
size = 1
|
|
156
|
+
else:
|
|
157
|
+
size = _compute_size(start, stop, stride)
|
|
158
|
+
ret = Dim(
|
|
159
|
+
start=start, stop=stop, size=size, stride=stride, single=False
|
|
160
|
+
)
|
|
161
|
+
return ret
|
|
162
|
+
else:
|
|
163
|
+
sliced = self[item : item + 1] if item != -1 else self[-1:]
|
|
164
|
+
if sliced.size != 1:
|
|
165
|
+
raise IndexError
|
|
166
|
+
return Dim(
|
|
167
|
+
start=sliced.start,
|
|
168
|
+
stop=sliced.stop,
|
|
169
|
+
size=sliced.size,
|
|
170
|
+
stride=sliced.stride,
|
|
171
|
+
single=True,
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
def get_offset(self, idx):
|
|
175
|
+
return self.start + idx * self.stride
|
|
176
|
+
|
|
177
|
+
def __repr__(self):
|
|
178
|
+
strfmt = "Dim(start=%s, stop=%s, size=%s, stride=%s)"
|
|
179
|
+
return strfmt % (self.start, self.stop, self.size, self.stride)
|
|
180
|
+
|
|
181
|
+
def normalize(self, base):
|
|
182
|
+
return Dim(
|
|
183
|
+
start=self.start - base,
|
|
184
|
+
stop=self.stop - base,
|
|
185
|
+
size=self.size,
|
|
186
|
+
stride=self.stride,
|
|
187
|
+
single=self.single,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
def copy(self, start=None, stop=None, size=None, stride=None, single=None):
|
|
191
|
+
if start is None:
|
|
192
|
+
start = self.start
|
|
193
|
+
if stop is None:
|
|
194
|
+
stop = self.stop
|
|
195
|
+
if size is None:
|
|
196
|
+
size = self.size
|
|
197
|
+
if stride is None:
|
|
198
|
+
stride = self.stride
|
|
199
|
+
if single is None:
|
|
200
|
+
single = self.single
|
|
201
|
+
return Dim(start, stop, size, stride, single)
|
|
202
|
+
|
|
203
|
+
def is_contiguous(self, itemsize):
|
|
204
|
+
return self.stride == itemsize
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def compute_index(indices, dims):
|
|
208
|
+
return sum(d.get_offset(i) for i, d in zip(indices, dims))
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
class Element(object):
|
|
212
|
+
is_array = False
|
|
213
|
+
|
|
214
|
+
def __init__(self, extent):
|
|
215
|
+
self.extent = extent
|
|
216
|
+
|
|
217
|
+
def iter_contiguous_extent(self):
|
|
218
|
+
yield self.extent
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
class Array(object):
|
|
222
|
+
"""A dummy numpy array-like object. Consider it an array without the
|
|
223
|
+
actual data, but offset from the base data pointer.
|
|
224
|
+
|
|
225
|
+
Attributes
|
|
226
|
+
----------
|
|
227
|
+
dims: tuple of Dim
|
|
228
|
+
describing each dimension of the array
|
|
229
|
+
|
|
230
|
+
ndim: int
|
|
231
|
+
number of dimension
|
|
232
|
+
|
|
233
|
+
shape: tuple of int
|
|
234
|
+
size of each dimension
|
|
235
|
+
|
|
236
|
+
strides: tuple of int
|
|
237
|
+
stride of each dimension
|
|
238
|
+
|
|
239
|
+
itemsize: int
|
|
240
|
+
itemsize
|
|
241
|
+
|
|
242
|
+
extent: (start, end)
|
|
243
|
+
start and end offset containing the memory region
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
is_array = True
|
|
247
|
+
|
|
248
|
+
@classmethod
|
|
249
|
+
@functools.cache
|
|
250
|
+
def from_desc(cls, offset, shape, strides, itemsize):
|
|
251
|
+
dims = []
|
|
252
|
+
for ashape, astride in zip(shape, strides):
|
|
253
|
+
if not isinstance(ashape, (int, np.integer)):
|
|
254
|
+
raise TypeError("all elements of shape must be ints")
|
|
255
|
+
dim = Dim(
|
|
256
|
+
offset, offset + ashape * astride, ashape, astride, single=False
|
|
257
|
+
)
|
|
258
|
+
dims.append(dim)
|
|
259
|
+
offset = 0 # offset only applies to first dimension
|
|
260
|
+
return cls(dims, itemsize)
|
|
261
|
+
|
|
262
|
+
def __init__(self, dims, itemsize):
|
|
263
|
+
self.dims = tuple(dims)
|
|
264
|
+
self.ndim = len(self.dims)
|
|
265
|
+
self.shape = tuple(dim.size for dim in self.dims)
|
|
266
|
+
self.strides = tuple(dim.stride for dim in self.dims)
|
|
267
|
+
self.itemsize = itemsize
|
|
268
|
+
self.size = functools.reduce(operator.mul, self.shape, 1)
|
|
269
|
+
self.extent = self._compute_extent()
|
|
270
|
+
self.flags = self._compute_layout()
|
|
271
|
+
|
|
272
|
+
def _compute_layout(self):
|
|
273
|
+
# The logic here is based on that in _UpdateContiguousFlags from
|
|
274
|
+
# numpy/core/src/multiarray/flagsobject.c in NumPy v1.19.1 (commit
|
|
275
|
+
# 13661ac70).
|
|
276
|
+
# https://github.com/numpy/numpy/blob/maintenance/1.19.x/numpy/core/src/multiarray/flagsobject.c#L123-L191
|
|
277
|
+
|
|
278
|
+
# Records have no dims, and we can treat them as contiguous
|
|
279
|
+
if not self.dims:
|
|
280
|
+
return {"C_CONTIGUOUS": True, "F_CONTIGUOUS": True}
|
|
281
|
+
|
|
282
|
+
# All 0-size arrays are considered contiguous, even if they are multidimensional
|
|
283
|
+
if self.size == 0:
|
|
284
|
+
return {"C_CONTIGUOUS": True, "F_CONTIGUOUS": True}
|
|
285
|
+
|
|
286
|
+
# If this is a broadcast array then it is not contiguous
|
|
287
|
+
if any([dim.stride == 0 for dim in self.dims]):
|
|
288
|
+
return {"C_CONTIGUOUS": False, "F_CONTIGUOUS": False}
|
|
289
|
+
|
|
290
|
+
flags = {"C_CONTIGUOUS": True, "F_CONTIGUOUS": True}
|
|
291
|
+
|
|
292
|
+
# Check C contiguity
|
|
293
|
+
sd = self.itemsize
|
|
294
|
+
for dim in reversed(self.dims):
|
|
295
|
+
if dim.size == 0:
|
|
296
|
+
# Contiguous by definition
|
|
297
|
+
return {"C_CONTIGUOUS": True, "F_CONTIGUOUS": True}
|
|
298
|
+
if dim.size != 1:
|
|
299
|
+
if dim.stride != sd:
|
|
300
|
+
flags["C_CONTIGUOUS"] = False
|
|
301
|
+
sd *= dim.size
|
|
302
|
+
|
|
303
|
+
# Check F contiguity
|
|
304
|
+
sd = self.itemsize
|
|
305
|
+
for dim in self.dims:
|
|
306
|
+
if dim.size != 1:
|
|
307
|
+
if dim.stride != sd:
|
|
308
|
+
flags["F_CONTIGUOUS"] = False
|
|
309
|
+
return flags
|
|
310
|
+
sd *= dim.size
|
|
311
|
+
|
|
312
|
+
return flags
|
|
313
|
+
|
|
314
|
+
def _compute_extent(self):
|
|
315
|
+
firstidx = [0] * self.ndim
|
|
316
|
+
lastidx = [s - 1 for s in self.shape]
|
|
317
|
+
start = compute_index(firstidx, self.dims)
|
|
318
|
+
stop = compute_index(lastidx, self.dims) + self.itemsize
|
|
319
|
+
stop = max(stop, start) # ensure positive extent
|
|
320
|
+
return Extent(start, stop)
|
|
321
|
+
|
|
322
|
+
def __repr__(self):
|
|
323
|
+
return "<Array dims=%s itemsize=%s>" % (self.dims, self.itemsize)
|
|
324
|
+
|
|
325
|
+
def __getitem__(self, item):
|
|
326
|
+
if not isinstance(item, tuple):
|
|
327
|
+
item = [item]
|
|
328
|
+
else:
|
|
329
|
+
item = list(item)
|
|
330
|
+
|
|
331
|
+
nitem = len(item)
|
|
332
|
+
ndim = len(self.dims)
|
|
333
|
+
if nitem > ndim:
|
|
334
|
+
raise IndexError("%d extra indices given" % (nitem - ndim,))
|
|
335
|
+
|
|
336
|
+
# Add empty slices for missing indices
|
|
337
|
+
while len(item) < ndim:
|
|
338
|
+
item.append(slice(None, None))
|
|
339
|
+
|
|
340
|
+
dims = [dim.__getitem__(it) for dim, it in zip(self.dims, item)]
|
|
341
|
+
newshape = [d.size for d in dims if not d.single]
|
|
342
|
+
|
|
343
|
+
arr = Array(dims, self.itemsize)
|
|
344
|
+
if newshape:
|
|
345
|
+
return arr.reshape(*newshape)[0]
|
|
346
|
+
else:
|
|
347
|
+
return Element(arr.extent)
|
|
348
|
+
|
|
349
|
+
@property
|
|
350
|
+
def is_c_contig(self):
|
|
351
|
+
return self.flags["C_CONTIGUOUS"]
|
|
352
|
+
|
|
353
|
+
@property
|
|
354
|
+
def is_f_contig(self):
|
|
355
|
+
return self.flags["F_CONTIGUOUS"]
|
|
356
|
+
|
|
357
|
+
def iter_contiguous_extent(self):
|
|
358
|
+
"""Generates extents"""
|
|
359
|
+
if self.is_c_contig or self.is_f_contig:
|
|
360
|
+
yield self.extent
|
|
361
|
+
else:
|
|
362
|
+
if self.dims[0].stride < self.dims[-1].stride:
|
|
363
|
+
innerdim = self.dims[0]
|
|
364
|
+
outerdims = self.dims[1:]
|
|
365
|
+
outershape = self.shape[1:]
|
|
366
|
+
else:
|
|
367
|
+
innerdim = self.dims[-1]
|
|
368
|
+
outerdims = self.dims[:-1]
|
|
369
|
+
outershape = self.shape[:-1]
|
|
370
|
+
|
|
371
|
+
if innerdim.is_contiguous(self.itemsize):
|
|
372
|
+
oslen = [range(s) for s in outershape]
|
|
373
|
+
for indices in itertools.product(*oslen):
|
|
374
|
+
base = compute_index(indices, outerdims)
|
|
375
|
+
yield base + innerdim.start, base + innerdim.stop
|
|
376
|
+
else:
|
|
377
|
+
oslen = [range(s) for s in self.shape]
|
|
378
|
+
for indices in itertools.product(*oslen):
|
|
379
|
+
offset = compute_index(indices, self.dims)
|
|
380
|
+
yield offset, offset + self.itemsize
|
|
381
|
+
|
|
382
|
+
def reshape(self, *newdims, **kws):
|
|
383
|
+
oldnd = self.ndim
|
|
384
|
+
newnd = len(newdims)
|
|
385
|
+
|
|
386
|
+
if newdims == self.shape:
|
|
387
|
+
return self, None
|
|
388
|
+
|
|
389
|
+
order = kws.pop("order", "C")
|
|
390
|
+
if kws:
|
|
391
|
+
raise TypeError("unknown keyword arguments %s" % kws.keys())
|
|
392
|
+
if order not in "CFA":
|
|
393
|
+
raise ValueError("order not C|F|A")
|
|
394
|
+
|
|
395
|
+
# check for exactly one instance of -1 in newdims
|
|
396
|
+
# https://github.com/numpy/numpy/blob/623bc1fae1d47df24e7f1e29321d0c0ba2771ce0/numpy/core/src/multiarray/shape.c#L470-L515 # noqa: E501
|
|
397
|
+
unknownidx = -1
|
|
398
|
+
knownsize = 1
|
|
399
|
+
for i, dim in enumerate(newdims):
|
|
400
|
+
if dim < 0:
|
|
401
|
+
if unknownidx == -1:
|
|
402
|
+
unknownidx = i
|
|
403
|
+
else:
|
|
404
|
+
raise ValueError("can only specify one unknown dimension")
|
|
405
|
+
else:
|
|
406
|
+
knownsize *= dim
|
|
407
|
+
|
|
408
|
+
# compute the missing dimension
|
|
409
|
+
if unknownidx >= 0:
|
|
410
|
+
if knownsize == 0 or self.size % knownsize != 0:
|
|
411
|
+
raise ValueError(
|
|
412
|
+
"cannot infer valid shape for unknown dimension"
|
|
413
|
+
)
|
|
414
|
+
else:
|
|
415
|
+
newdims = (
|
|
416
|
+
newdims[0:unknownidx]
|
|
417
|
+
+ (self.size // knownsize,)
|
|
418
|
+
+ newdims[unknownidx + 1 :]
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
newsize = functools.reduce(operator.mul, newdims, 1)
|
|
422
|
+
|
|
423
|
+
if order == "A":
|
|
424
|
+
order = "F" if self.is_f_contig else "C"
|
|
425
|
+
|
|
426
|
+
if newsize != self.size:
|
|
427
|
+
raise ValueError("reshape changes the size of the array")
|
|
428
|
+
|
|
429
|
+
if self.is_c_contig or self.is_f_contig:
|
|
430
|
+
if order == "C":
|
|
431
|
+
newstrides = list(iter_strides_c_contig(self, newdims))
|
|
432
|
+
elif order == "F":
|
|
433
|
+
newstrides = list(iter_strides_f_contig(self, newdims))
|
|
434
|
+
else:
|
|
435
|
+
raise AssertionError("unreachable")
|
|
436
|
+
else:
|
|
437
|
+
newstrides = [0] * newnd
|
|
438
|
+
|
|
439
|
+
if not attempt_nocopy_reshape(
|
|
440
|
+
oldnd,
|
|
441
|
+
self.shape,
|
|
442
|
+
self.strides,
|
|
443
|
+
newnd,
|
|
444
|
+
newdims,
|
|
445
|
+
newstrides,
|
|
446
|
+
self.itemsize,
|
|
447
|
+
order == "F",
|
|
448
|
+
):
|
|
449
|
+
raise NotImplementedError("reshape would require copy")
|
|
450
|
+
|
|
451
|
+
ret = self.from_desc(
|
|
452
|
+
self.extent.begin,
|
|
453
|
+
shape=tuple(newdims),
|
|
454
|
+
strides=tuple(newstrides),
|
|
455
|
+
itemsize=self.itemsize,
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
return ret, list(self.iter_contiguous_extent())
|
|
459
|
+
|
|
460
|
+
def squeeze(self, axis=None):
|
|
461
|
+
newshape, newstrides = [], []
|
|
462
|
+
if axis is None:
|
|
463
|
+
for length, stride in zip(self.shape, self.strides):
|
|
464
|
+
if length != 1:
|
|
465
|
+
newshape.append(length)
|
|
466
|
+
newstrides.append(stride)
|
|
467
|
+
else:
|
|
468
|
+
if not isinstance(axis, tuple):
|
|
469
|
+
axis = (axis,)
|
|
470
|
+
for ax in axis:
|
|
471
|
+
if self.shape[ax] != 1:
|
|
472
|
+
raise ValueError(
|
|
473
|
+
"cannot select an axis to squeeze out which has size "
|
|
474
|
+
"not equal to one"
|
|
475
|
+
)
|
|
476
|
+
for i, (length, stride) in enumerate(zip(self.shape, self.strides)):
|
|
477
|
+
if i not in axis:
|
|
478
|
+
newshape.append(length)
|
|
479
|
+
newstrides.append(stride)
|
|
480
|
+
newarr = self.from_desc(
|
|
481
|
+
self.extent.begin,
|
|
482
|
+
shape=tuple(newshape),
|
|
483
|
+
strides=tuple(newstrides),
|
|
484
|
+
itemsize=self.itemsize,
|
|
485
|
+
)
|
|
486
|
+
return newarr, list(self.iter_contiguous_extent())
|
|
487
|
+
|
|
488
|
+
def ravel(self, order="C"):
|
|
489
|
+
if order not in "CFA":
|
|
490
|
+
raise ValueError("order not C|F|A")
|
|
491
|
+
|
|
492
|
+
if (
|
|
493
|
+
order in "CA"
|
|
494
|
+
and self.is_c_contig
|
|
495
|
+
or order in "FA"
|
|
496
|
+
and self.is_f_contig
|
|
497
|
+
):
|
|
498
|
+
newshape = (self.size,)
|
|
499
|
+
newstrides = (self.itemsize,)
|
|
500
|
+
arr = self.from_desc(
|
|
501
|
+
self.extent.begin, newshape, newstrides, self.itemsize
|
|
502
|
+
)
|
|
503
|
+
return arr, list(self.iter_contiguous_extent())
|
|
504
|
+
|
|
505
|
+
else:
|
|
506
|
+
raise NotImplementedError("ravel on non-contiguous array")
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
def iter_strides_f_contig(arr, shape=None):
|
|
510
|
+
"""yields the f-contiguous strides"""
|
|
511
|
+
shape = arr.shape if shape is None else shape
|
|
512
|
+
itemsize = arr.itemsize
|
|
513
|
+
yield itemsize
|
|
514
|
+
sum = 1
|
|
515
|
+
for s in shape[:-1]:
|
|
516
|
+
sum *= s
|
|
517
|
+
yield sum * itemsize
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
def iter_strides_c_contig(arr, shape=None):
|
|
521
|
+
"""yields the c-contiguous strides"""
|
|
522
|
+
shape = arr.shape if shape is None else shape
|
|
523
|
+
itemsize = arr.itemsize
|
|
524
|
+
|
|
525
|
+
def gen():
|
|
526
|
+
yield itemsize
|
|
527
|
+
sum = 1
|
|
528
|
+
for s in reversed(shape[1:]):
|
|
529
|
+
sum *= s
|
|
530
|
+
yield sum * itemsize
|
|
531
|
+
|
|
532
|
+
for i in reversed(list(gen())):
|
|
533
|
+
yield i
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
def is_element_indexing(item, ndim):
|
|
537
|
+
if isinstance(item, slice):
|
|
538
|
+
return False
|
|
539
|
+
|
|
540
|
+
elif isinstance(item, tuple):
|
|
541
|
+
if len(item) == ndim:
|
|
542
|
+
if not any(isinstance(it, slice) for it in item):
|
|
543
|
+
return True
|
|
544
|
+
|
|
545
|
+
else:
|
|
546
|
+
return True
|
|
547
|
+
|
|
548
|
+
return False
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
def _compute_size(start, stop, step):
|
|
552
|
+
"""Algorithm adapted from cpython rangeobject.c"""
|
|
553
|
+
if step > 0:
|
|
554
|
+
lo = start
|
|
555
|
+
hi = stop
|
|
556
|
+
else:
|
|
557
|
+
lo = stop
|
|
558
|
+
hi = start
|
|
559
|
+
step = -step
|
|
560
|
+
if lo >= hi:
|
|
561
|
+
return 0
|
|
562
|
+
return (hi - lo - 1) // step + 1
|