numba-cuda 0.19.0__py3-none-any.whl → 0.20.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of numba-cuda might be problematic. Click here for more details.
- _numba_cuda_redirector.pth +3 -0
- _numba_cuda_redirector.py +3 -0
- numba_cuda/VERSION +1 -1
- numba_cuda/__init__.py +2 -1
- numba_cuda/_version.py +2 -13
- numba_cuda/numba/cuda/__init__.py +4 -1
- numba_cuda/numba/cuda/_internal/cuda_bf16.py +12708 -1469
- numba_cuda/numba/cuda/_internal/cuda_fp16.py +2656 -8769
- numba_cuda/numba/cuda/api.py +9 -1
- numba_cuda/numba/cuda/api_util.py +3 -0
- numba_cuda/numba/cuda/args.py +3 -0
- numba_cuda/numba/cuda/bf16.py +288 -2
- numba_cuda/numba/cuda/cg.py +3 -0
- numba_cuda/numba/cuda/cgutils.py +5 -2
- 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 +4 -1
- numba_cuda/numba/cuda/compiler.py +376 -30
- numba_cuda/numba/cuda/core/analysis.py +319 -0
- numba_cuda/numba/cuda/core/annotations/__init__.py +0 -0
- numba_cuda/numba/cuda/core/annotations/type_annotations.py +304 -0
- numba_cuda/numba/cuda/core/base.py +1289 -0
- numba_cuda/numba/cuda/core/bytecode.py +727 -0
- numba_cuda/numba/cuda/core/caching.py +5 -2
- numba_cuda/numba/cuda/core/callconv.py +3 -0
- numba_cuda/numba/cuda/core/codegen.py +3 -0
- numba_cuda/numba/cuda/core/compiler.py +9 -14
- numba_cuda/numba/cuda/core/compiler_machinery.py +497 -0
- numba_cuda/numba/cuda/core/config.py +747 -0
- numba_cuda/numba/cuda/core/consts.py +124 -0
- numba_cuda/numba/cuda/core/cpu.py +370 -0
- numba_cuda/numba/cuda/core/environment.py +68 -0
- numba_cuda/numba/cuda/core/event.py +511 -0
- numba_cuda/numba/cuda/core/funcdesc.py +330 -0
- numba_cuda/numba/cuda/core/inline_closurecall.py +1889 -0
- numba_cuda/numba/cuda/core/interpreter.py +52 -27
- numba_cuda/numba/cuda/core/ir_utils.py +17 -29
- 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 +1868 -0
- numba_cuda/numba/cuda/core/rewrites/__init__.py +26 -0
- numba_cuda/numba/cuda/core/rewrites/ir_print.py +90 -0
- numba_cuda/numba/cuda/core/rewrites/registry.py +104 -0
- numba_cuda/numba/cuda/core/rewrites/static_binop.py +40 -0
- numba_cuda/numba/cuda/core/rewrites/static_getitem.py +187 -0
- numba_cuda/numba/cuda/core/rewrites/static_raise.py +98 -0
- numba_cuda/numba/cuda/core/sigutils.py +3 -0
- numba_cuda/numba/cuda/core/ssa.py +496 -0
- numba_cuda/numba/cuda/core/targetconfig.py +329 -0
- numba_cuda/numba/cuda/core/tracing.py +231 -0
- numba_cuda/numba/cuda/core/transforms.py +952 -0
- numba_cuda/numba/cuda/core/typed_passes.py +741 -7
- numba_cuda/numba/cuda/core/typeinfer.py +1948 -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 +66 -0
- numba_cuda/numba/cuda/core/unsafe/refcount.py +98 -0
- numba_cuda/numba/cuda/core/untyped_passes.py +1983 -0
- numba_cuda/numba/cuda/cpython/cmathimpl.py +560 -0
- numba_cuda/numba/cuda/cpython/mathimpl.py +499 -0
- numba_cuda/numba/cuda/cpython/numbers.py +1474 -0
- numba_cuda/numba/cuda/cuda_paths.py +425 -246
- numba_cuda/numba/cuda/cudadecl.py +4 -1
- numba_cuda/numba/cuda/cudadrv/__init__.py +4 -1
- numba_cuda/numba/cuda/cudadrv/devicearray.py +5 -1
- numba_cuda/numba/cuda/cudadrv/devices.py +3 -0
- numba_cuda/numba/cuda/cudadrv/driver.py +14 -140
- numba_cuda/numba/cuda/cudadrv/drvapi.py +3 -0
- numba_cuda/numba/cuda/cudadrv/dummyarray.py +114 -24
- numba_cuda/numba/cuda/cudadrv/enums.py +3 -0
- numba_cuda/numba/cuda/cudadrv/error.py +4 -0
- numba_cuda/numba/cuda/cudadrv/libs.py +8 -5
- numba_cuda/numba/cuda/cudadrv/linkable_code.py +3 -0
- numba_cuda/numba/cuda/cudadrv/mappings.py +4 -1
- numba_cuda/numba/cuda/cudadrv/ndarray.py +3 -0
- numba_cuda/numba/cuda/cudadrv/nvrtc.py +22 -8
- numba_cuda/numba/cuda/cudadrv/nvvm.py +4 -4
- numba_cuda/numba/cuda/cudadrv/rtapi.py +3 -0
- numba_cuda/numba/cuda/cudadrv/runtime.py +4 -1
- numba_cuda/numba/cuda/cudaimpl.py +8 -1
- numba_cuda/numba/cuda/cudamath.py +3 -0
- numba_cuda/numba/cuda/debuginfo.py +88 -2
- numba_cuda/numba/cuda/decorators.py +6 -3
- numba_cuda/numba/cuda/descriptor.py +6 -4
- numba_cuda/numba/cuda/device_init.py +3 -0
- numba_cuda/numba/cuda/deviceufunc.py +69 -2
- numba_cuda/numba/cuda/dispatcher.py +21 -39
- numba_cuda/numba/cuda/errors.py +10 -0
- numba_cuda/numba/cuda/extending.py +3 -0
- numba_cuda/numba/cuda/flags.py +143 -1
- numba_cuda/numba/cuda/fp16.py +3 -2
- 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 +4 -0
- numba_cuda/numba/cuda/intrinsic_wrapper.py +3 -0
- numba_cuda/numba/cuda/intrinsics.py +3 -0
- numba_cuda/numba/cuda/itanium_mangler.py +3 -0
- numba_cuda/numba/cuda/kernels/__init__.py +2 -0
- numba_cuda/numba/cuda/kernels/reduction.py +3 -0
- numba_cuda/numba/cuda/kernels/transpose.py +3 -0
- numba_cuda/numba/cuda/libdevice.py +4 -0
- numba_cuda/numba/cuda/libdevicedecl.py +3 -0
- numba_cuda/numba/cuda/libdevicefuncs.py +3 -0
- numba_cuda/numba/cuda/libdeviceimpl.py +3 -0
- numba_cuda/numba/cuda/locks.py +3 -0
- numba_cuda/numba/cuda/lowering.py +59 -159
- numba_cuda/numba/cuda/mathimpl.py +5 -1
- numba_cuda/numba/cuda/memory_management/__init__.py +3 -0
- numba_cuda/numba/cuda/memory_management/memsys.cu +5 -0
- numba_cuda/numba/cuda/memory_management/memsys.cuh +5 -0
- numba_cuda/numba/cuda/memory_management/nrt.cu +5 -0
- numba_cuda/numba/cuda/memory_management/nrt.cuh +5 -0
- numba_cuda/numba/cuda/memory_management/nrt.py +48 -18
- numba_cuda/numba/cuda/misc/findlib.py +75 -0
- numba_cuda/numba/cuda/models.py +12 -1
- numba_cuda/numba/cuda/np/npdatetime_helpers.py +217 -0
- numba_cuda/numba/cuda/np/npyfuncs.py +1807 -0
- numba_cuda/numba/cuda/np/numpy_support.py +553 -0
- numba_cuda/numba/cuda/np/ufunc/ufuncbuilder.py +59 -0
- numba_cuda/numba/cuda/nvvmutils.py +4 -1
- numba_cuda/numba/cuda/printimpl.py +15 -1
- numba_cuda/numba/cuda/random.py +4 -1
- numba_cuda/numba/cuda/reshape_funcs.cu +5 -0
- numba_cuda/numba/cuda/serialize.py +4 -1
- numba_cuda/numba/cuda/simulator/__init__.py +4 -1
- numba_cuda/numba/cuda/simulator/_internal/__init__.py +3 -0
- numba_cuda/numba/cuda/simulator/_internal/cuda_bf16.py +2 -0
- numba_cuda/numba/cuda/simulator/api.py +4 -1
- numba_cuda/numba/cuda/simulator/bf16.py +3 -0
- numba_cuda/numba/cuda/simulator/compiler.py +7 -0
- numba_cuda/numba/cuda/simulator/cudadrv/__init__.py +3 -0
- numba_cuda/numba/cuda/simulator/cudadrv/devicearray.py +4 -1
- numba_cuda/numba/cuda/simulator/cudadrv/devices.py +3 -0
- numba_cuda/numba/cuda/simulator/cudadrv/driver.py +3 -0
- numba_cuda/numba/cuda/simulator/cudadrv/drvapi.py +3 -0
- numba_cuda/numba/cuda/simulator/cudadrv/dummyarray.py +3 -0
- numba_cuda/numba/cuda/simulator/cudadrv/error.py +4 -0
- numba_cuda/numba/cuda/simulator/cudadrv/libs.py +4 -0
- numba_cuda/numba/cuda/simulator/cudadrv/linkable_code.py +4 -0
- numba_cuda/numba/cuda/simulator/cudadrv/nvrtc.py +3 -0
- numba_cuda/numba/cuda/simulator/cudadrv/nvvm.py +3 -0
- numba_cuda/numba/cuda/simulator/cudadrv/runtime.py +3 -0
- numba_cuda/numba/cuda/simulator/dispatcher.py +4 -0
- numba_cuda/numba/cuda/simulator/kernel.py +3 -0
- numba_cuda/numba/cuda/simulator/kernelapi.py +4 -1
- numba_cuda/numba/cuda/simulator/memory_management/__init__.py +3 -0
- numba_cuda/numba/cuda/simulator/memory_management/nrt.py +17 -2
- numba_cuda/numba/cuda/simulator/reduction.py +3 -0
- numba_cuda/numba/cuda/simulator/vector_types.py +3 -0
- numba_cuda/numba/cuda/simulator_init.py +3 -0
- numba_cuda/numba/cuda/stubs.py +3 -0
- numba_cuda/numba/cuda/target.py +38 -17
- numba_cuda/numba/cuda/testing.py +7 -19
- numba_cuda/numba/cuda/tests/__init__.py +4 -1
- numba_cuda/numba/cuda/tests/cloudpickle_main_class.py +9 -0
- numba_cuda/numba/cuda/tests/complex_usecases.py +3 -0
- numba_cuda/numba/cuda/tests/core/serialize_usecases.py +3 -0
- numba_cuda/numba/cuda/tests/core/test_itanium_mangler.py +3 -0
- numba_cuda/numba/cuda/tests/core/test_serialize.py +7 -4
- numba_cuda/numba/cuda/tests/cudadrv/__init__.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_array_attr.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_context_stack.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_array_slicing.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_auto_context.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_devicerecord.py +4 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_driver.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_libraries.py +4 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_memory.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_deallocations.py +4 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_detect.py +9 -3
- numba_cuda/numba/cuda/tests/cudadrv/test_emm_plugins.py +4 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_events.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_host_alloc.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_init.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_inline_ptx.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_is_fp16.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_linker.py +21 -2
- numba_cuda/numba/cuda/tests/cudadrv/test_managed_alloc.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_module_callbacks.py +5 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_nvjitlink.py +4 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_nvrtc.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_nvvm_driver.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_pinned.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_profiler.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_ptds.py +4 -1
- numba_cuda/numba/cuda/tests/cudadrv/test_reset_device.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_runtime.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_select_device.py +3 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_streams.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/__init__.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/cache_usecases.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/cache_with_cpu_usecases.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/cg_cache_usecases.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/extensions_usecases.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/recursion_usecases.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_alignment.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array.py +5 -1
- numba_cuda/numba/cuda/tests/cudapy/test_array_alignment.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array_args.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_array_methods.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_atomics.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_bfloat16.py +542 -2
- numba_cuda/numba/cuda/tests/cudapy/test_bfloat16_bindings.py +84 -1
- numba_cuda/numba/cuda/tests/cudapy/test_blackscholes.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_boolean.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_caching.py +4 -3
- numba_cuda/numba/cuda/tests/cudapy/test_casting.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cffi.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_compiler.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_complex.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_complex_kernel.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_const_string.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_constmem.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_cooperative_groups.py +5 -3
- numba_cuda/numba/cuda/tests/cudapy/test_copy_propagate.py +130 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cuda_array_interface.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_cuda_jit_no_types.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_datetime.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_debug.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py +314 -3
- numba_cuda/numba/cuda/tests/cudapy/test_debuginfo_types.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_device_func.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_dispatcher.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_enums.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_errors.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_exception.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_extending.py +5 -1
- numba_cuda/numba/cuda/tests/cudapy/test_fastmath.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_forall.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_freevar.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_frexp_ldexp.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_globals.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_gufunc.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scalar.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scheduling.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_idiv.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_inline.py +21 -8
- numba_cuda/numba/cuda/tests/cudapy/test_inspect.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_intrinsics.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ipc.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ir_utils.py +13 -37
- numba_cuda/numba/cuda/tests/cudapy/test_iterators.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_lang.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_laplace.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_libdevice.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_lineinfo.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_localmem.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_mandel.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_math.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_matmul.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_minmax.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_montecarlo.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_multigpu.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_multiprocessing.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_multithreads.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_nondet.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_operator.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_optimization.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_overload.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_powi.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_print.py +23 -0
- numba_cuda/numba/cuda/tests/cudapy/test_py2_div_issue.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_random.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_record_dtype.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_recursion.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_reduction.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_serialize.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_slicing.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_sm.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_sm_creation.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ssa.py +453 -0
- numba_cuda/numba/cuda/tests/cudapy/test_stream_api.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_sync.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_transpose.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_typeinfer.py +538 -0
- numba_cuda/numba/cuda/tests/cudapy/test_ufuncs.py +266 -2
- numba_cuda/numba/cuda/tests/cudapy/test_userexc.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_vector_type.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_complex.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_decor.py +115 -6
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_device.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py +3 -0
- numba_cuda/numba/cuda/tests/cudapy/test_warning.py +4 -1
- numba_cuda/numba/cuda/tests/cudapy/test_warp_ops.py +4 -1
- numba_cuda/numba/cuda/tests/cudasim/__init__.py +3 -0
- numba_cuda/numba/cuda/tests/cudasim/support.py +3 -0
- numba_cuda/numba/cuda/tests/cudasim/test_cudasim_issues.py +3 -0
- numba_cuda/numba/cuda/tests/data/__init__.py +2 -0
- numba_cuda/numba/cuda/tests/data/cta_barrier.cu +5 -0
- numba_cuda/numba/cuda/tests/data/cuda_include.cu +5 -0
- numba_cuda/numba/cuda/tests/data/error.cu +5 -0
- numba_cuda/numba/cuda/tests/data/include/add.cuh +5 -0
- numba_cuda/numba/cuda/tests/data/jitlink.cu +5 -0
- numba_cuda/numba/cuda/tests/data/warn.cu +5 -0
- numba_cuda/numba/cuda/tests/doc_examples/__init__.py +3 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/__init__.py +2 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/functions.cu +5 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/include/mul.cuh +5 -0
- numba_cuda/numba/cuda/tests/doc_examples/ffi/saxpy.cu +5 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_cg.py +3 -2
- numba_cuda/numba/cuda/tests/doc_examples/test_cpointer.py +3 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_cpu_gpu_compat.py +3 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_ffi.py +6 -2
- numba_cuda/numba/cuda/tests/doc_examples/test_laplace.py +3 -2
- numba_cuda/numba/cuda/tests/doc_examples/test_matmul.py +3 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_montecarlo.py +3 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_random.py +3 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_reduction.py +3 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_sessionize.py +3 -2
- numba_cuda/numba/cuda/tests/doc_examples/test_ufunc.py +3 -0
- numba_cuda/numba/cuda/tests/doc_examples/test_vecadd.py +3 -0
- numba_cuda/numba/cuda/tests/enum_usecases.py +3 -0
- numba_cuda/numba/cuda/tests/nocuda/__init__.py +3 -0
- numba_cuda/numba/cuda/tests/nocuda/test_dummyarray.py +3 -0
- numba_cuda/numba/cuda/tests/nocuda/test_function_resolution.py +3 -0
- numba_cuda/numba/cuda/tests/nocuda/test_import.py +6 -1
- numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py +27 -12
- numba_cuda/numba/cuda/tests/nocuda/test_nvvm.py +3 -0
- numba_cuda/numba/cuda/tests/nrt/__init__.py +3 -0
- numba_cuda/numba/cuda/tests/nrt/test_nrt.py +5 -1
- numba_cuda/numba/cuda/tests/nrt/test_nrt_refct.py +3 -0
- numba_cuda/numba/cuda/tests/support.py +58 -15
- numba_cuda/numba/cuda/tests/test_binary_generation/Makefile +3 -0
- numba_cuda/numba/cuda/tests/test_binary_generation/generate_raw_ltoir.py +2 -1
- numba_cuda/numba/cuda/tests/test_binary_generation/nrt_extern.cu +5 -0
- numba_cuda/numba/cuda/tests/test_binary_generation/test_device_functions.cu +5 -0
- numba_cuda/numba/cuda/tests/test_binary_generation/undefined_extern.cu +5 -0
- numba_cuda/numba/cuda/tests/test_tracing.py +200 -0
- numba_cuda/numba/cuda/types.py +59 -0
- numba_cuda/numba/cuda/typing/__init__.py +12 -1
- numba_cuda/numba/cuda/typing/cffi_utils.py +55 -0
- numba_cuda/numba/cuda/typing/context.py +751 -0
- numba_cuda/numba/cuda/typing/enumdecl.py +74 -0
- numba_cuda/numba/cuda/typing/npydecl.py +658 -0
- numba_cuda/numba/cuda/typing/templates.py +10 -14
- numba_cuda/numba/cuda/ufuncs.py +6 -3
- numba_cuda/numba/cuda/utils.py +9 -112
- numba_cuda/numba/cuda/vector_types.py +3 -0
- numba_cuda/numba/cuda/vectorizers.py +3 -0
- {numba_cuda-0.19.0.dist-info → numba_cuda-0.20.0.dist-info}/METADATA +6 -2
- numba_cuda-0.20.0.dist-info/RECORD +357 -0
- {numba_cuda-0.19.0.dist-info → numba_cuda-0.20.0.dist-info}/licenses/LICENSE +1 -0
- numba_cuda-0.20.0.dist-info/licenses/LICENSE.numba +24 -0
- numba_cuda/numba/cuda/tests/cudadrv/test_mvc.py +0 -57
- numba_cuda-0.19.0.dist-info/RECORD +0 -301
- {numba_cuda-0.19.0.dist-info → numba_cuda-0.20.0.dist-info}/WHEEL +0 -0
- {numba_cuda-0.19.0.dist-info → numba_cuda-0.20.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,658 @@
|
|
|
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
|
+
|
|
7
|
+
from numba.cuda.typing.templates import AbstractTemplate, Registry, signature
|
|
8
|
+
from numba.core import types
|
|
9
|
+
from numba.cuda import utils
|
|
10
|
+
from numba.core.errors import TypingError, NumbaTypeError
|
|
11
|
+
from numba.cuda.np.numpy_support import (
|
|
12
|
+
ufunc_find_matching_loop,
|
|
13
|
+
supported_ufunc_loop,
|
|
14
|
+
from_dtype,
|
|
15
|
+
as_dtype,
|
|
16
|
+
resolve_output_type,
|
|
17
|
+
_ufunc_loop_sig,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
registry = Registry()
|
|
21
|
+
infer = registry.register
|
|
22
|
+
infer_global = registry.register_global
|
|
23
|
+
infer_getattr = registry.register_attr
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Numpy_rules_ufunc(AbstractTemplate):
|
|
27
|
+
@classmethod
|
|
28
|
+
def _handle_inputs(cls, ufunc, args, kws):
|
|
29
|
+
"""
|
|
30
|
+
Process argument types to a given *ufunc*.
|
|
31
|
+
Returns a (base types, explicit outputs, ndims, layout) tuple where:
|
|
32
|
+
- `base types` is a tuple of scalar types for each input
|
|
33
|
+
- `explicit outputs` is a tuple of explicit output types (arrays)
|
|
34
|
+
- `ndims` is the number of dimensions of the loop and also of
|
|
35
|
+
any outputs, explicit or implicit
|
|
36
|
+
- `layout` is the layout for any implicit output to be allocated
|
|
37
|
+
"""
|
|
38
|
+
nin = ufunc.nin
|
|
39
|
+
nout = ufunc.nout
|
|
40
|
+
nargs = ufunc.nargs
|
|
41
|
+
|
|
42
|
+
# preconditions
|
|
43
|
+
assert nargs == nin + nout
|
|
44
|
+
|
|
45
|
+
if len(args) < nin:
|
|
46
|
+
msg = "ufunc '{0}': not enough arguments ({1} found, {2} required)"
|
|
47
|
+
raise TypingError(msg=msg.format(ufunc.__name__, len(args), nin))
|
|
48
|
+
|
|
49
|
+
if len(args) > nargs:
|
|
50
|
+
msg = "ufunc '{0}': too many arguments ({1} found, {2} maximum)"
|
|
51
|
+
raise TypingError(msg=msg.format(ufunc.__name__, len(args), nargs))
|
|
52
|
+
|
|
53
|
+
args = [
|
|
54
|
+
a.as_array if isinstance(a, types.ArrayCompatible) else a
|
|
55
|
+
for a in args
|
|
56
|
+
]
|
|
57
|
+
arg_ndims = [
|
|
58
|
+
a.ndim if isinstance(a, types.ArrayCompatible) else 0 for a in args
|
|
59
|
+
]
|
|
60
|
+
ndims = max(arg_ndims)
|
|
61
|
+
|
|
62
|
+
# explicit outputs must be arrays (no explicit scalar return values supported)
|
|
63
|
+
explicit_outputs = args[nin:]
|
|
64
|
+
|
|
65
|
+
if not all(
|
|
66
|
+
isinstance(output, types.ArrayCompatible)
|
|
67
|
+
for output in explicit_outputs
|
|
68
|
+
):
|
|
69
|
+
msg = "ufunc '{0}' called with an explicit output that is not an array"
|
|
70
|
+
raise TypingError(msg=msg.format(ufunc.__name__))
|
|
71
|
+
|
|
72
|
+
if not all(output.mutable for output in explicit_outputs):
|
|
73
|
+
msg = "ufunc '{0}' called with an explicit output that is read-only"
|
|
74
|
+
raise TypingError(msg=msg.format(ufunc.__name__))
|
|
75
|
+
|
|
76
|
+
# find the kernel to use, based only in the input types (as does NumPy)
|
|
77
|
+
base_types = [
|
|
78
|
+
x.dtype if isinstance(x, types.ArrayCompatible) else x for x in args
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
# Figure out the output array layout, if needed.
|
|
82
|
+
layout = None
|
|
83
|
+
if ndims > 0 and (len(explicit_outputs) < ufunc.nout):
|
|
84
|
+
layout = "C"
|
|
85
|
+
layouts = [
|
|
86
|
+
x.layout if isinstance(x, types.ArrayCompatible) else ""
|
|
87
|
+
for x in args
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
# Prefer C contig if any array is C contig.
|
|
91
|
+
# Next, prefer F contig.
|
|
92
|
+
# Defaults to C contig if not layouts are C/F.
|
|
93
|
+
if "C" not in layouts and "F" in layouts:
|
|
94
|
+
layout = "F"
|
|
95
|
+
|
|
96
|
+
return base_types, explicit_outputs, ndims, layout
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def ufunc(self):
|
|
100
|
+
return self.key
|
|
101
|
+
|
|
102
|
+
def generic(self, args, kws):
|
|
103
|
+
# First, strip optional types, ufunc loops are typed on concrete types
|
|
104
|
+
args = [x.type if isinstance(x, types.Optional) else x for x in args]
|
|
105
|
+
|
|
106
|
+
ufunc = self.ufunc
|
|
107
|
+
base_types, explicit_outputs, ndims, layout = self._handle_inputs(
|
|
108
|
+
ufunc, args, kws
|
|
109
|
+
)
|
|
110
|
+
ufunc_loop = ufunc_find_matching_loop(ufunc, base_types)
|
|
111
|
+
if ufunc_loop is None:
|
|
112
|
+
raise TypingError(
|
|
113
|
+
"can't resolve ufunc {0} for types {1}".format(
|
|
114
|
+
ufunc.__name__, args
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# check if all the types involved in the ufunc loop are supported in this mode
|
|
119
|
+
if not supported_ufunc_loop(ufunc, ufunc_loop):
|
|
120
|
+
msg = "ufunc '{0}' using the loop '{1}' not supported in this mode"
|
|
121
|
+
raise TypingError(
|
|
122
|
+
msg=msg.format(ufunc.__name__, ufunc_loop.ufunc_sig)
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
# if there is any explicit output type, check that it is valid
|
|
126
|
+
explicit_outputs_np = [as_dtype(tp.dtype) for tp in explicit_outputs]
|
|
127
|
+
|
|
128
|
+
# Numpy will happily use unsafe conversions (although it will actually warn)
|
|
129
|
+
if not all(
|
|
130
|
+
np.can_cast(fromty, toty, "unsafe")
|
|
131
|
+
for (fromty, toty) in zip(
|
|
132
|
+
ufunc_loop.numpy_outputs, explicit_outputs_np
|
|
133
|
+
)
|
|
134
|
+
):
|
|
135
|
+
msg = "ufunc '{0}' can't cast result to explicit result type"
|
|
136
|
+
raise TypingError(msg=msg.format(ufunc.__name__))
|
|
137
|
+
|
|
138
|
+
# A valid loop was found that is compatible. The result of type inference should
|
|
139
|
+
# be based on the explicit output types, and when not available with the type given
|
|
140
|
+
# by the selected NumPy loop
|
|
141
|
+
out = list(explicit_outputs)
|
|
142
|
+
implicit_output_count = ufunc.nout - len(explicit_outputs)
|
|
143
|
+
if implicit_output_count > 0:
|
|
144
|
+
# XXX this is sometimes wrong for datetime64 and timedelta64,
|
|
145
|
+
# as ufunc_find_matching_loop() doesn't do any type inference
|
|
146
|
+
ret_tys = ufunc_loop.outputs[-implicit_output_count:]
|
|
147
|
+
if ndims > 0:
|
|
148
|
+
assert layout is not None
|
|
149
|
+
# If either of the types involved in the ufunc operation have a
|
|
150
|
+
# __array_ufunc__ method then invoke the first such one to
|
|
151
|
+
# determine the output type of the ufunc.
|
|
152
|
+
array_ufunc_type = None
|
|
153
|
+
for a in args:
|
|
154
|
+
if hasattr(a, "__array_ufunc__"):
|
|
155
|
+
array_ufunc_type = a
|
|
156
|
+
break
|
|
157
|
+
output_type = types.Array
|
|
158
|
+
if array_ufunc_type is not None:
|
|
159
|
+
output_type = array_ufunc_type.__array_ufunc__(
|
|
160
|
+
ufunc, "__call__", *args, **kws
|
|
161
|
+
)
|
|
162
|
+
if output_type is NotImplemented:
|
|
163
|
+
msg = (
|
|
164
|
+
f"unsupported use of ufunc {ufunc} on "
|
|
165
|
+
f"{array_ufunc_type}"
|
|
166
|
+
)
|
|
167
|
+
# raise TypeError here because
|
|
168
|
+
# NumpyRulesArrayOperator.generic is capturing
|
|
169
|
+
# TypingError
|
|
170
|
+
raise NumbaTypeError(msg)
|
|
171
|
+
elif not issubclass(output_type, types.Array):
|
|
172
|
+
msg = (
|
|
173
|
+
f"ufunc {ufunc} on {array_ufunc_type}"
|
|
174
|
+
f"cannot return non-array {output_type}"
|
|
175
|
+
)
|
|
176
|
+
# raise TypeError here because
|
|
177
|
+
# NumpyRulesArrayOperator.generic is capturing
|
|
178
|
+
# TypingError
|
|
179
|
+
raise NumbaTypeError(msg)
|
|
180
|
+
|
|
181
|
+
ret_tys = [
|
|
182
|
+
output_type(dtype=ret_ty, ndim=ndims, layout=layout)
|
|
183
|
+
for ret_ty in ret_tys
|
|
184
|
+
]
|
|
185
|
+
ret_tys = [
|
|
186
|
+
resolve_output_type(self.context, args, ret_ty)
|
|
187
|
+
for ret_ty in ret_tys
|
|
188
|
+
]
|
|
189
|
+
out.extend(ret_tys)
|
|
190
|
+
|
|
191
|
+
return _ufunc_loop_sig(out, args)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
class NumpyRulesArrayOperator(Numpy_rules_ufunc):
|
|
195
|
+
_op_map = {
|
|
196
|
+
operator.add: "add",
|
|
197
|
+
operator.sub: "subtract",
|
|
198
|
+
operator.mul: "multiply",
|
|
199
|
+
operator.truediv: "true_divide",
|
|
200
|
+
operator.floordiv: "floor_divide",
|
|
201
|
+
operator.mod: "remainder",
|
|
202
|
+
operator.pow: "power",
|
|
203
|
+
operator.lshift: "left_shift",
|
|
204
|
+
operator.rshift: "right_shift",
|
|
205
|
+
operator.and_: "bitwise_and",
|
|
206
|
+
operator.or_: "bitwise_or",
|
|
207
|
+
operator.xor: "bitwise_xor",
|
|
208
|
+
operator.eq: "equal",
|
|
209
|
+
operator.gt: "greater",
|
|
210
|
+
operator.ge: "greater_equal",
|
|
211
|
+
operator.lt: "less",
|
|
212
|
+
operator.le: "less_equal",
|
|
213
|
+
operator.ne: "not_equal",
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
@property
|
|
217
|
+
def ufunc(self):
|
|
218
|
+
return getattr(np, self._op_map[self.key])
|
|
219
|
+
|
|
220
|
+
@classmethod
|
|
221
|
+
def install_operations(cls):
|
|
222
|
+
for op, ufunc_name in cls._op_map.items():
|
|
223
|
+
infer_global(op)(
|
|
224
|
+
type(
|
|
225
|
+
"NumpyRulesArrayOperator_" + ufunc_name,
|
|
226
|
+
(cls,),
|
|
227
|
+
dict(key=op),
|
|
228
|
+
)
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
def generic(self, args, kws):
|
|
232
|
+
"""Overloads and calls base class generic() method, returning
|
|
233
|
+
None if a TypingError occurred.
|
|
234
|
+
|
|
235
|
+
Returning None for operators is important since operators are
|
|
236
|
+
heavily overloaded, and by suppressing type errors, we allow
|
|
237
|
+
type inference to check other possibilities before giving up
|
|
238
|
+
(particularly user-defined operators).
|
|
239
|
+
"""
|
|
240
|
+
try:
|
|
241
|
+
sig = super(NumpyRulesArrayOperator, self).generic(args, kws)
|
|
242
|
+
except TypingError:
|
|
243
|
+
return None
|
|
244
|
+
if sig is None:
|
|
245
|
+
return None
|
|
246
|
+
args = sig.args
|
|
247
|
+
# Only accept at least one array argument, otherwise the operator
|
|
248
|
+
# doesn't involve Numpy's ufunc machinery.
|
|
249
|
+
if not any(isinstance(arg, types.ArrayCompatible) for arg in args):
|
|
250
|
+
return None
|
|
251
|
+
return sig
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
_binop_map = NumpyRulesArrayOperator._op_map
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
class NumpyRulesInplaceArrayOperator(NumpyRulesArrayOperator):
|
|
258
|
+
_op_map = {
|
|
259
|
+
operator.iadd: "add",
|
|
260
|
+
operator.isub: "subtract",
|
|
261
|
+
operator.imul: "multiply",
|
|
262
|
+
operator.itruediv: "true_divide",
|
|
263
|
+
operator.ifloordiv: "floor_divide",
|
|
264
|
+
operator.imod: "remainder",
|
|
265
|
+
operator.ipow: "power",
|
|
266
|
+
operator.ilshift: "left_shift",
|
|
267
|
+
operator.irshift: "right_shift",
|
|
268
|
+
operator.iand: "bitwise_and",
|
|
269
|
+
operator.ior: "bitwise_or",
|
|
270
|
+
operator.ixor: "bitwise_xor",
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
def generic(self, args, kws):
|
|
274
|
+
# Type the inplace operator as if an explicit output was passed,
|
|
275
|
+
# to handle type resolution correctly.
|
|
276
|
+
# (for example int8[:] += int16[:] should use an int8[:] output,
|
|
277
|
+
# not int16[:])
|
|
278
|
+
lhs, rhs = args
|
|
279
|
+
if not isinstance(lhs, types.ArrayCompatible):
|
|
280
|
+
return
|
|
281
|
+
args = args + (lhs,)
|
|
282
|
+
sig = super(NumpyRulesInplaceArrayOperator, self).generic(args, kws)
|
|
283
|
+
# Strip off the fake explicit output
|
|
284
|
+
assert len(sig.args) == 3
|
|
285
|
+
real_sig = signature(sig.return_type, *sig.args[:2])
|
|
286
|
+
return real_sig
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
class NumpyRulesUnaryArrayOperator(NumpyRulesArrayOperator):
|
|
290
|
+
_op_map = {
|
|
291
|
+
operator.pos: "positive",
|
|
292
|
+
operator.neg: "negative",
|
|
293
|
+
operator.invert: "invert",
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
def generic(self, args, kws):
|
|
297
|
+
assert not kws
|
|
298
|
+
if len(args) == 1 and isinstance(args[0], types.ArrayCompatible):
|
|
299
|
+
return super(NumpyRulesUnaryArrayOperator, self).generic(args, kws)
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
# list of unary ufuncs to register
|
|
303
|
+
|
|
304
|
+
math_operations = [
|
|
305
|
+
"add",
|
|
306
|
+
"subtract",
|
|
307
|
+
"multiply",
|
|
308
|
+
"logaddexp",
|
|
309
|
+
"logaddexp2",
|
|
310
|
+
"true_divide",
|
|
311
|
+
"floor_divide",
|
|
312
|
+
"negative",
|
|
313
|
+
"positive",
|
|
314
|
+
"power",
|
|
315
|
+
"float_power",
|
|
316
|
+
"remainder",
|
|
317
|
+
"fmod",
|
|
318
|
+
"absolute",
|
|
319
|
+
"rint",
|
|
320
|
+
"sign",
|
|
321
|
+
"conjugate",
|
|
322
|
+
"exp",
|
|
323
|
+
"exp2",
|
|
324
|
+
"log",
|
|
325
|
+
"log2",
|
|
326
|
+
"log10",
|
|
327
|
+
"expm1",
|
|
328
|
+
"log1p",
|
|
329
|
+
"sqrt",
|
|
330
|
+
"square",
|
|
331
|
+
"cbrt",
|
|
332
|
+
"reciprocal",
|
|
333
|
+
"divide",
|
|
334
|
+
"mod",
|
|
335
|
+
"divmod",
|
|
336
|
+
"abs",
|
|
337
|
+
"fabs",
|
|
338
|
+
"gcd",
|
|
339
|
+
"lcm",
|
|
340
|
+
]
|
|
341
|
+
|
|
342
|
+
trigonometric_functions = [
|
|
343
|
+
"sin",
|
|
344
|
+
"cos",
|
|
345
|
+
"tan",
|
|
346
|
+
"arcsin",
|
|
347
|
+
"arccos",
|
|
348
|
+
"arctan",
|
|
349
|
+
"arctan2",
|
|
350
|
+
"hypot",
|
|
351
|
+
"sinh",
|
|
352
|
+
"cosh",
|
|
353
|
+
"tanh",
|
|
354
|
+
"arcsinh",
|
|
355
|
+
"arccosh",
|
|
356
|
+
"arctanh",
|
|
357
|
+
"deg2rad",
|
|
358
|
+
"rad2deg",
|
|
359
|
+
"degrees",
|
|
360
|
+
"radians",
|
|
361
|
+
]
|
|
362
|
+
|
|
363
|
+
bit_twiddling_functions = [
|
|
364
|
+
"bitwise_and",
|
|
365
|
+
"bitwise_or",
|
|
366
|
+
"bitwise_xor",
|
|
367
|
+
"invert",
|
|
368
|
+
"left_shift",
|
|
369
|
+
"right_shift",
|
|
370
|
+
"bitwise_not",
|
|
371
|
+
]
|
|
372
|
+
|
|
373
|
+
comparison_functions = [
|
|
374
|
+
"greater",
|
|
375
|
+
"greater_equal",
|
|
376
|
+
"less",
|
|
377
|
+
"less_equal",
|
|
378
|
+
"not_equal",
|
|
379
|
+
"equal",
|
|
380
|
+
"logical_and",
|
|
381
|
+
"logical_or",
|
|
382
|
+
"logical_xor",
|
|
383
|
+
"logical_not",
|
|
384
|
+
"maximum",
|
|
385
|
+
"minimum",
|
|
386
|
+
"fmax",
|
|
387
|
+
"fmin",
|
|
388
|
+
]
|
|
389
|
+
|
|
390
|
+
floating_functions = [
|
|
391
|
+
"isfinite",
|
|
392
|
+
"isinf",
|
|
393
|
+
"isnan",
|
|
394
|
+
"signbit",
|
|
395
|
+
"copysign",
|
|
396
|
+
"nextafter",
|
|
397
|
+
"modf",
|
|
398
|
+
"ldexp",
|
|
399
|
+
"frexp",
|
|
400
|
+
"floor",
|
|
401
|
+
"ceil",
|
|
402
|
+
"trunc",
|
|
403
|
+
"spacing",
|
|
404
|
+
]
|
|
405
|
+
|
|
406
|
+
logic_functions = ["isnat"]
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
# This is a set of the ufuncs that are not yet supported by Lowering. In order
|
|
410
|
+
# to trigger no-python mode we must not register them until their Lowering is
|
|
411
|
+
# implemented.
|
|
412
|
+
#
|
|
413
|
+
# It also works as a nice TODO list for ufunc support :)
|
|
414
|
+
_unsupported = set(
|
|
415
|
+
[
|
|
416
|
+
"frexp",
|
|
417
|
+
"modf",
|
|
418
|
+
]
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def register_numpy_ufunc(name, register_global=infer_global):
|
|
423
|
+
func = getattr(np, name)
|
|
424
|
+
|
|
425
|
+
class typing_class(Numpy_rules_ufunc):
|
|
426
|
+
key = func
|
|
427
|
+
|
|
428
|
+
typing_class.__name__ = "resolve_{0}".format(name)
|
|
429
|
+
|
|
430
|
+
# A list of ufuncs that are in fact aliases of other ufuncs. They need to
|
|
431
|
+
# insert the resolve method, but not register the ufunc itself
|
|
432
|
+
aliases = ("abs", "bitwise_not", "divide", "abs")
|
|
433
|
+
|
|
434
|
+
if name not in aliases:
|
|
435
|
+
register_global(func, types.Function(typing_class))
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
all_ufuncs = sum(
|
|
439
|
+
[
|
|
440
|
+
math_operations,
|
|
441
|
+
trigonometric_functions,
|
|
442
|
+
bit_twiddling_functions,
|
|
443
|
+
comparison_functions,
|
|
444
|
+
floating_functions,
|
|
445
|
+
logic_functions,
|
|
446
|
+
],
|
|
447
|
+
[],
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
supported_ufuncs = [x for x in all_ufuncs if x not in _unsupported]
|
|
451
|
+
|
|
452
|
+
for func in supported_ufuncs:
|
|
453
|
+
register_numpy_ufunc(func)
|
|
454
|
+
|
|
455
|
+
all_ufuncs = [getattr(np, name) for name in all_ufuncs]
|
|
456
|
+
supported_ufuncs = [getattr(np, name) for name in supported_ufuncs]
|
|
457
|
+
|
|
458
|
+
NumpyRulesUnaryArrayOperator.install_operations()
|
|
459
|
+
NumpyRulesArrayOperator.install_operations()
|
|
460
|
+
NumpyRulesInplaceArrayOperator.install_operations()
|
|
461
|
+
|
|
462
|
+
supported_array_operators = (
|
|
463
|
+
set(NumpyRulesUnaryArrayOperator._op_map.keys())
|
|
464
|
+
.union(NumpyRulesArrayOperator._op_map.keys())
|
|
465
|
+
.union(NumpyRulesInplaceArrayOperator._op_map.keys())
|
|
466
|
+
)
|
|
467
|
+
|
|
468
|
+
del _unsupported
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
# -----------------------------------------------------------------------------
|
|
472
|
+
# Install global helpers for array methods.
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
class Numpy_method_redirection(AbstractTemplate):
|
|
476
|
+
"""
|
|
477
|
+
A template redirecting a Numpy global function (e.g. np.sum) to an
|
|
478
|
+
array method of the same name (e.g. ndarray.sum).
|
|
479
|
+
"""
|
|
480
|
+
|
|
481
|
+
# Arguments like *axis* can specialize on literals but also support
|
|
482
|
+
# non-literals
|
|
483
|
+
prefer_literal = True
|
|
484
|
+
|
|
485
|
+
def generic(self, args, kws):
|
|
486
|
+
pysig = None
|
|
487
|
+
if kws:
|
|
488
|
+
if self.method_name == "sum":
|
|
489
|
+
if "axis" in kws and "dtype" not in kws:
|
|
490
|
+
|
|
491
|
+
def sum_stub(arr, axis):
|
|
492
|
+
pass
|
|
493
|
+
|
|
494
|
+
pysig = utils.pysignature(sum_stub)
|
|
495
|
+
elif "dtype" in kws and "axis" not in kws:
|
|
496
|
+
|
|
497
|
+
def sum_stub(arr, dtype):
|
|
498
|
+
pass
|
|
499
|
+
|
|
500
|
+
pysig = utils.pysignature(sum_stub)
|
|
501
|
+
elif "dtype" in kws and "axis" in kws:
|
|
502
|
+
|
|
503
|
+
def sum_stub(arr, axis, dtype):
|
|
504
|
+
pass
|
|
505
|
+
|
|
506
|
+
pysig = utils.pysignature(sum_stub)
|
|
507
|
+
elif self.method_name == "argsort":
|
|
508
|
+
|
|
509
|
+
def argsort_stub(arr, kind="quicksort"):
|
|
510
|
+
pass
|
|
511
|
+
|
|
512
|
+
pysig = utils.pysignature(argsort_stub)
|
|
513
|
+
else:
|
|
514
|
+
fmt = "numba doesn't support kwarg for {}"
|
|
515
|
+
raise TypingError(fmt.format(self.method_name))
|
|
516
|
+
|
|
517
|
+
arr = args[0]
|
|
518
|
+
# This will return a BoundFunction
|
|
519
|
+
meth_ty = self.context.resolve_getattr(arr, self.method_name)
|
|
520
|
+
# Resolve arguments on the bound function
|
|
521
|
+
meth_sig = self.context.resolve_function_type(meth_ty, args[1:], kws)
|
|
522
|
+
if meth_sig is not None:
|
|
523
|
+
return meth_sig.as_function().replace(pysig=pysig)
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
# Function to glue attributes onto the numpy-esque object
|
|
527
|
+
def _numpy_redirect(fname):
|
|
528
|
+
numpy_function = getattr(np, fname)
|
|
529
|
+
cls = type(
|
|
530
|
+
"Numpy_redirect_{0}".format(fname),
|
|
531
|
+
(Numpy_method_redirection,),
|
|
532
|
+
dict(key=numpy_function, method_name=fname),
|
|
533
|
+
)
|
|
534
|
+
infer_global(numpy_function, types.Function(cls))
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
for func in ["sum", "argsort", "nonzero", "ravel"]:
|
|
538
|
+
_numpy_redirect(func)
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
# -----------------------------------------------------------------------------
|
|
542
|
+
# Numpy scalar constructors
|
|
543
|
+
|
|
544
|
+
# Register np.int8, etc. as converters to the equivalent Numba types
|
|
545
|
+
np_types = set(getattr(np, str(nb_type)) for nb_type in types.number_domain)
|
|
546
|
+
np_types.add(np.bool_)
|
|
547
|
+
# Those may or may not be aliases (depending on the Numpy build / version)
|
|
548
|
+
np_types.add(np.intc)
|
|
549
|
+
np_types.add(np.intp)
|
|
550
|
+
np_types.add(np.uintc)
|
|
551
|
+
np_types.add(np.uintp)
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
def register_number_classes(register_global):
|
|
555
|
+
for np_type in np_types:
|
|
556
|
+
nb_type = getattr(types, np_type.__name__)
|
|
557
|
+
|
|
558
|
+
register_global(np_type, types.NumberClass(nb_type))
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
register_number_classes(infer_global)
|
|
562
|
+
|
|
563
|
+
# -----------------------------------------------------------------------------
|
|
564
|
+
# Numpy array constructors
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def parse_shape(shape):
|
|
568
|
+
"""
|
|
569
|
+
Given a shape, return the number of dimensions.
|
|
570
|
+
"""
|
|
571
|
+
ndim = None
|
|
572
|
+
if isinstance(shape, types.Integer):
|
|
573
|
+
ndim = 1
|
|
574
|
+
elif isinstance(shape, (types.Tuple, types.UniTuple)):
|
|
575
|
+
int_tys = (types.Integer, types.IntEnumMember)
|
|
576
|
+
if all(isinstance(s, int_tys) for s in shape):
|
|
577
|
+
ndim = len(shape)
|
|
578
|
+
return ndim
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
def parse_dtype(dtype):
|
|
582
|
+
"""
|
|
583
|
+
Return the dtype of a type, if it is either a DtypeSpec (used for most
|
|
584
|
+
dtypes) or a TypeRef (used for record types).
|
|
585
|
+
"""
|
|
586
|
+
if isinstance(dtype, types.DTypeSpec):
|
|
587
|
+
return dtype.dtype
|
|
588
|
+
elif isinstance(dtype, types.TypeRef):
|
|
589
|
+
return dtype.instance_type
|
|
590
|
+
elif isinstance(dtype, types.StringLiteral):
|
|
591
|
+
dtstr = dtype.literal_value
|
|
592
|
+
try:
|
|
593
|
+
dt = np.dtype(dtstr)
|
|
594
|
+
except TypeError:
|
|
595
|
+
msg = f"Invalid NumPy dtype specified: '{dtstr}'"
|
|
596
|
+
raise TypingError(msg)
|
|
597
|
+
return from_dtype(dt)
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
# -----------------------------------------------------------------------------
|
|
601
|
+
# Miscellaneous functions
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
@infer_global(np.ndenumerate)
|
|
605
|
+
class NdEnumerate(AbstractTemplate):
|
|
606
|
+
def generic(self, args, kws):
|
|
607
|
+
assert not kws
|
|
608
|
+
(arr,) = args
|
|
609
|
+
|
|
610
|
+
if isinstance(arr, types.Array):
|
|
611
|
+
enumerate_type = types.NumpyNdEnumerateType(arr)
|
|
612
|
+
return signature(enumerate_type, *args)
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
@infer_global(np.nditer)
|
|
616
|
+
class NdIter(AbstractTemplate):
|
|
617
|
+
def generic(self, args, kws):
|
|
618
|
+
assert not kws
|
|
619
|
+
if len(args) != 1:
|
|
620
|
+
return
|
|
621
|
+
(arrays,) = args
|
|
622
|
+
|
|
623
|
+
if isinstance(arrays, types.BaseTuple):
|
|
624
|
+
if not arrays:
|
|
625
|
+
return
|
|
626
|
+
arrays = list(arrays)
|
|
627
|
+
else:
|
|
628
|
+
arrays = [arrays]
|
|
629
|
+
nditerty = types.NumpyNdIterType(arrays)
|
|
630
|
+
return signature(nditerty, *args)
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
@infer_global(np.ndindex)
|
|
634
|
+
class NdIndex(AbstractTemplate):
|
|
635
|
+
def generic(self, args, kws):
|
|
636
|
+
assert not kws
|
|
637
|
+
|
|
638
|
+
# Either ndindex(shape) or ndindex(*shape)
|
|
639
|
+
if len(args) == 1 and isinstance(args[0], types.BaseTuple):
|
|
640
|
+
tup = args[0]
|
|
641
|
+
if tup.count > 0 and not isinstance(tup, types.UniTuple):
|
|
642
|
+
# Heterogeneous tuple
|
|
643
|
+
return
|
|
644
|
+
shape = list(tup)
|
|
645
|
+
else:
|
|
646
|
+
shape = args
|
|
647
|
+
|
|
648
|
+
if all(isinstance(x, types.Integer) for x in shape):
|
|
649
|
+
iterator_type = types.NumpyNdIndexType(len(shape))
|
|
650
|
+
return signature(iterator_type, *args)
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
@infer_global(operator.eq)
|
|
654
|
+
class DtypeEq(AbstractTemplate):
|
|
655
|
+
def generic(self, args, kws):
|
|
656
|
+
[lhs, rhs] = args
|
|
657
|
+
if isinstance(lhs, types.DType) and isinstance(rhs, types.DType):
|
|
658
|
+
return signature(types.boolean, lhs, rhs)
|