├── .coveragerc ├── .flake8 ├── .gitattributes ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── Bug_report.md │ ├── Feature_request.md │ ├── config.yml │ ├── first_rc_checklist.md │ └── sub_rc_checklist.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── numba_linux-64_conda_builder.yml │ ├── numba_linux-64_wheel_builder.yml │ ├── numba_linux-arm64_conda_builder.yml │ ├── numba_linux-arm64_wheel_builder.yml │ ├── numba_osx-64_conda_builder.yml │ ├── numba_osx-64_wheel_builder.yml │ ├── numba_osx-arm64_conda_builder.yml │ ├── numba_osx-arm64_wheel_builder.yml │ ├── numba_win-64_builder.yml │ ├── numba_win-64_whl_builder.yml │ ├── stale.yml │ ├── towncrier.yml │ └── workflow_matrix.json ├── .gitignore ├── .pre-commit-config.yaml ├── .readthedocs.yml ├── CHANGE_LOG ├── CONTRIBUTING.md ├── LICENSE ├── LICENSES.third-party ├── MANIFEST.in ├── README.rst ├── azure-pipelines.yml ├── bin └── numba ├── buildscripts ├── azure │ ├── azure-linux-macos.yml │ └── azure-windows.yml ├── condarecipe.local │ ├── bld.bat │ ├── build.sh │ ├── conda_build_config.yaml │ ├── license.txt │ ├── meta.yaml │ ├── run_test.bat │ └── run_test.sh ├── github │ ├── MacOSX10.10.sdk.checksum │ ├── build_wheel_linux.sh │ ├── patch_wheel_dylib.py │ ├── repair_wheel_linux.sh │ └── setup_platform.sh ├── gpuci │ ├── axis.yaml │ └── build.sh └── incremental │ ├── MacOSX10.10.sdk.checksum │ ├── after_success.sh │ ├── build.cmd │ ├── build.sh │ ├── install_miniconda.sh │ ├── setup_conda_environment.cmd │ ├── setup_conda_environment.sh │ └── test.sh ├── codecov.yml ├── contrib └── valgrind-numba.supp ├── docs ├── Makefile ├── _static │ ├── js │ │ └── modernizr.min.js │ ├── numba-blue-icon-rgb.svg │ ├── numba-white-icon-rgb.svg │ └── rtd-overrides.css ├── _templates │ └── EMPTY ├── dagmap │ ├── README.md │ ├── dagmap.yaml │ ├── jquery.graphviz.svg.js │ ├── render.py │ └── template.html ├── environment.yml ├── make.bat ├── source │ ├── _ext │ │ └── ghfiles.py │ ├── conf.py │ ├── cuda-reference │ │ ├── host.rst │ │ ├── index.rst │ │ ├── kernel.rst │ │ ├── libdevice.rst │ │ ├── memory.rst │ │ └── types.rst │ ├── cuda │ │ ├── bindings.rst │ │ ├── caching.rst │ │ ├── cooperative_groups.rst │ │ ├── cuda_array_interface.rst │ │ ├── cuda_compilation.rst │ │ ├── cuda_ffi.rst │ │ ├── cudapysupported.rst │ │ ├── device-functions.rst │ │ ├── device-management.rst │ │ ├── examples.rst │ │ ├── external-memory.rst │ │ ├── faq.rst │ │ ├── fastmath.rst │ │ ├── index.rst │ │ ├── intrinsics.rst │ │ ├── ipc.rst │ │ ├── kernels.rst │ │ ├── laplace_final.svg │ │ ├── laplace_initial.svg │ │ ├── memory.rst │ │ ├── minor_version_compatibility.rst │ │ ├── overview.rst │ │ ├── random.rst │ │ ├── reduction.rst │ │ ├── simulator.rst │ │ └── ufunc.rst │ ├── developer │ │ ├── architecture.rst │ │ ├── bytecode.rst │ │ ├── caching.rst │ │ ├── compiler_pass_example.py │ │ ├── contributing.rst │ │ ├── custom_pipeline.rst │ │ ├── debugging.rst │ │ ├── dispatching.rst │ │ ├── environment.rst │ │ ├── event_api.rst │ │ ├── generators.rst │ │ ├── hashing.rst │ │ ├── index.rst │ │ ├── inline_example.py │ │ ├── inline_overload_example.py │ │ ├── inlining.rst │ │ ├── listings.rst │ │ ├── literal.rst │ │ ├── live_variable_analysis.rst │ │ ├── llvm_timings.rst │ │ ├── mission.rst │ │ ├── numba-runtime.rst │ │ ├── release.rst │ │ ├── repomap.rst │ │ ├── rewrites.rst │ │ ├── stencil.rst │ │ ├── sys_monitoring.rst │ │ ├── target_extension.rst │ │ └── threading_implementation.rst │ ├── extending │ │ ├── entrypoints.rst │ │ ├── high-level.rst │ │ ├── index.rst │ │ ├── interval-example.rst │ │ ├── low-level.rst │ │ ├── mynorm.py │ │ ├── overloading-guide.rst │ │ └── template.py │ ├── glossary.rst │ ├── index.rst │ ├── proposals │ │ ├── cfunc.rst │ │ ├── extension-points.rst │ │ ├── external-memory-management.rst │ │ ├── index.rst │ │ ├── integer-typing.rst │ │ ├── jit-classes.rst │ │ ├── np-where-override.py │ │ ├── recursion_callstack.svg │ │ ├── type-inference.rst │ │ └── typing_recursion.rst │ ├── reference │ │ ├── aot-compilation.rst │ │ ├── deprecation.rst │ │ ├── envvars.rst │ │ ├── fpsemantics.rst │ │ ├── index.rst │ │ ├── jit-compilation.rst │ │ ├── numpysupported.rst │ │ ├── pysemantics.rst │ │ ├── pysupported.rst │ │ ├── types.rst │ │ └── utils.rst │ ├── release-notes-overview.rst │ ├── release-notes.rst │ ├── release │ │ ├── 0.58.0-notes.rst │ │ ├── 0.58.1-notes.rst │ │ ├── 0.59.0-notes.rst │ │ ├── 0.59.1-notes.rst │ │ ├── 0.60.0-notes.rst │ │ ├── 0.61.0-notes.rst │ │ ├── 0.61.1-notes.rst │ │ └── 0.61.2-notes.rst │ └── user │ │ ├── 5minguide.rst │ │ ├── cfunc.rst │ │ ├── cli.rst │ │ ├── code_coverage.rst │ │ ├── examples.rst │ │ ├── faq.rst │ │ ├── index.rst │ │ ├── installing.rst │ │ ├── jit-module.rst │ │ ├── jit.rst │ │ ├── jitclass.rst │ │ ├── overview.rst │ │ ├── parallel.rst │ │ ├── performance-tips.rst │ │ ├── pycc.rst │ │ ├── stencil.rst │ │ ├── talks.rst │ │ ├── threading-layer.rst │ │ ├── troubleshoot.rst │ │ ├── vectorize.rst │ │ └── withobjmode.rst └── upcoming_changes │ ├── 10035.improvement.rst │ ├── 10047.bug_fix.rst │ ├── 10052.bug_fix.rst │ ├── 10079.improvement.rst │ ├── 9390.np_support.rst │ ├── 9676.improvement.rst │ ├── 9861.improvement.rst │ ├── 9888.bug_fix.rst │ ├── 9892.improvement.rst │ ├── 9893.bug_fix.rst │ ├── 9916.improvement.rst │ ├── 9973.bug_fix.rst │ ├── README.rst │ └── template.rst ├── maint ├── git-copy.py ├── github_weekly_meeting.py ├── gitlog2changelog.py ├── towncrier_checker.py └── towncrier_rst_validator.py ├── mypy.ini ├── numba ├── __init__.py ├── __main__.py ├── _arraystruct.h ├── _devicearray.cpp ├── _devicearray.h ├── _dispatcher.cpp ├── _dynfunc.c ├── _dynfuncmod.c ├── _hashtable.cpp ├── _hashtable.h ├── _helperlib.c ├── _helperlib.pyi ├── _helpermod.c ├── _lapack.c ├── _numba_common.h ├── _pymodule.h ├── _random.c ├── _typeof.cpp ├── _typeof.h ├── _unicodetype_db.h ├── _version.py ├── capsulethunk.h ├── cext │ ├── __init__.py │ ├── cext.h │ ├── dictobject.c │ ├── dictobject.h │ ├── listobject.c │ ├── listobject.h │ └── utils.c ├── cloudpickle │ ├── __init__.py │ ├── cloudpickle.py │ └── cloudpickle_fast.py ├── core │ ├── __init__.py │ ├── analysis.py │ ├── annotations │ │ ├── __init__.py │ │ ├── pretty_annotate.py │ │ ├── template.html │ │ └── type_annotations.py │ ├── base.py │ ├── boxing.py │ ├── bytecode.py │ ├── byteflow.py │ ├── caching.py │ ├── callconv.py │ ├── callwrapper.py │ ├── ccallback.py │ ├── cgutils.py │ ├── codegen.py │ ├── compiler.py │ ├── compiler_lock.py │ ├── compiler_machinery.py │ ├── config.py │ ├── consts.py │ ├── controlflow.py │ ├── cpu.py │ ├── cpu_options.py │ ├── datamodel │ │ ├── __init__.py │ │ ├── manager.py │ │ ├── models.py │ │ ├── new_models.py │ │ ├── old_models.py │ │ ├── packer.py │ │ ├── registry.py │ │ └── testing.py │ ├── debuginfo.py │ ├── decorators.py │ ├── descriptors.py │ ├── dispatcher.py │ ├── entrypoints.py │ ├── environment.py │ ├── errors.py │ ├── event.py │ ├── extending.py │ ├── extending.pyi │ ├── externals.py │ ├── fastmathpass.py │ ├── funcdesc.py │ ├── generators.py │ ├── imputils.py │ ├── inline_closurecall.py │ ├── interpreter.py │ ├── intrinsics.py │ ├── ir.py │ ├── ir_utils.py │ ├── itanium_mangler.py │ ├── llvm_bindings.py │ ├── lowering.py │ ├── new_boxing.py │ ├── object_mode_passes.py │ ├── old_boxing.py │ ├── optional.py │ ├── options.py │ ├── postproc.py │ ├── pylowering.py │ ├── pythonapi.py │ ├── registry.py │ ├── removerefctpass.py │ ├── rewrites │ │ ├── __init__.py │ │ ├── ir_print.py │ │ ├── registry.py │ │ ├── static_binop.py │ │ ├── static_getitem.py │ │ └── static_raise.py │ ├── runtime │ │ ├── __init__.py │ │ ├── _nrt_python.c │ │ ├── _nrt_pythonmod.c │ │ ├── context.py │ │ ├── nrt.cpp │ │ ├── nrt.h │ │ ├── nrt.py │ │ ├── nrt_external.h │ │ ├── nrtdynmod.py │ │ └── nrtopt.py │ ├── serialize.py │ ├── sigutils.py │ ├── ssa.py │ ├── target_extension.py │ ├── targetconfig.py │ ├── tracing.py │ ├── transforms.py │ ├── typeconv │ │ ├── __init__.py │ │ ├── _typeconv.cpp │ │ ├── castgraph.py │ │ ├── rules.py │ │ ├── test.cpp │ │ ├── typeconv.cpp │ │ ├── typeconv.hpp │ │ └── typeconv.py │ ├── typed_passes.py │ ├── typeinfer.py │ ├── types │ │ ├── __init__.py │ │ ├── __init__.pyi │ │ ├── abstract.py │ │ ├── common.py │ │ ├── containers.py │ │ ├── function_type.py │ │ ├── functions.py │ │ ├── iterators.py │ │ ├── misc.py │ │ ├── new_scalars │ │ │ ├── __init__.py │ │ │ ├── machine_types.py │ │ │ ├── numpy_types.py │ │ │ ├── python_types.py │ │ │ └── scalars.py │ │ ├── npytypes.py │ │ ├── old_scalars.py │ │ └── scalars.py │ ├── typing │ │ ├── __init__.py │ │ ├── arraydecl.py │ │ ├── asnumbatype.py │ │ ├── bufproto.py │ │ ├── builtins.py │ │ ├── cffi_utils.py │ │ ├── cmathdecl.py │ │ ├── collections.py │ │ ├── context.py │ │ ├── ctypes_utils.py │ │ ├── dictdecl.py │ │ ├── enumdecl.py │ │ ├── listdecl.py │ │ ├── mathdecl.py │ │ ├── new_builtins.py │ │ ├── new_cmathdecl.py │ │ ├── new_mathdecl.py │ │ ├── npdatetime.py │ │ ├── npydecl.py │ │ ├── old_builtins.py │ │ ├── old_cmathdecl.py │ │ ├── old_mathdecl.py │ │ ├── setdecl.py │ │ ├── templates.py │ │ └── typeof.py │ ├── unsafe │ │ ├── __init__.py │ │ ├── bytes.py │ │ ├── eh.py │ │ ├── nrt.py │ │ └── refcount.py │ ├── untyped_passes.py │ ├── utils.py │ └── withcontexts.py ├── cpython │ ├── __init__.py │ ├── builtins.py │ ├── charseq.py │ ├── cmathimpl.py │ ├── enumimpl.py │ ├── hashing.py │ ├── heapq.py │ ├── iterators.py │ ├── listobj.py │ ├── mathimpl.py │ ├── new_builtins.py │ ├── new_hashing.py │ ├── new_mathimpl.py │ ├── new_numbers.py │ ├── new_tupleobj.py │ ├── numbers.py │ ├── old_builtins.py │ ├── old_hashing.py │ ├── old_mathimpl.py │ ├── old_numbers.py │ ├── old_tupleobj.py │ ├── printimpl.py │ ├── randomimpl.py │ ├── rangeobj.py │ ├── setobj.py │ ├── slicing.py │ ├── tupleobj.py │ ├── unicode.py │ ├── unicode_support.py │ └── unsafe │ │ ├── __init__.py │ │ ├── numbers.py │ │ └── tuple.py ├── cuda │ ├── __init__.py │ ├── api.py │ ├── api_util.py │ ├── args.py │ ├── cg.py │ ├── codegen.py │ ├── compiler.py │ ├── cpp_function_wrappers.cu │ ├── cuda_fp16.h │ ├── cuda_fp16.hpp │ ├── cuda_paths.py │ ├── cudadecl.py │ ├── cudadrv │ │ ├── __init__.py │ │ ├── _extras.c │ │ ├── devicearray.py │ │ ├── devices.py │ │ ├── driver.py │ │ ├── drvapi.py │ │ ├── dummyarray.py │ │ ├── enums.py │ │ ├── error.py │ │ ├── libs.py │ │ ├── ndarray.py │ │ ├── nvrtc.py │ │ ├── nvvm.py │ │ ├── rtapi.py │ │ └── runtime.py │ ├── cudaimpl.py │ ├── cudamath.py │ ├── decorators.py │ ├── descriptor.py │ ├── device_init.py │ ├── deviceufunc.py │ ├── dispatcher.py │ ├── errors.py │ ├── extending.py │ ├── initialize.py │ ├── intrinsic_wrapper.py │ ├── intrinsics.py │ ├── kernels │ │ ├── __init__.py │ │ ├── reduction.py │ │ └── transpose.py │ ├── libdevice.py │ ├── libdevicedecl.py │ ├── libdevicefuncs.py │ ├── libdeviceimpl.py │ ├── mathimpl.py │ ├── models.py │ ├── nvvmutils.py │ ├── printimpl.py │ ├── random.py │ ├── simulator │ │ ├── __init__.py │ │ ├── api.py │ │ ├── compiler.py │ │ ├── cudadrv │ │ │ ├── __init__.py │ │ │ ├── devicearray.py │ │ │ ├── devices.py │ │ │ ├── driver.py │ │ │ ├── drvapi.py │ │ │ ├── dummyarray.py │ │ │ ├── error.py │ │ │ ├── libs.py │ │ │ ├── nvvm.py │ │ │ └── runtime.py │ │ ├── kernel.py │ │ ├── kernelapi.py │ │ ├── reduction.py │ │ └── vector_types.py │ ├── simulator_init.py │ ├── stubs.py │ ├── target.py │ ├── testing.py │ ├── tests │ │ ├── __init__.py │ │ ├── cudadrv │ │ │ ├── __init__.py │ │ │ ├── test_array_attr.py │ │ │ ├── test_context_stack.py │ │ │ ├── test_cuda_array_slicing.py │ │ │ ├── test_cuda_auto_context.py │ │ │ ├── test_cuda_devicerecord.py │ │ │ ├── test_cuda_driver.py │ │ │ ├── test_cuda_libraries.py │ │ │ ├── test_cuda_memory.py │ │ │ ├── test_cuda_ndarray.py │ │ │ ├── test_deallocations.py │ │ │ ├── test_detect.py │ │ │ ├── test_emm_plugins.py │ │ │ ├── test_events.py │ │ │ ├── test_host_alloc.py │ │ │ ├── test_init.py │ │ │ ├── test_inline_ptx.py │ │ │ ├── test_is_fp16.py │ │ │ ├── test_linker.py │ │ │ ├── test_managed_alloc.py │ │ │ ├── test_mvc.py │ │ │ ├── test_nvvm_driver.py │ │ │ ├── test_pinned.py │ │ │ ├── test_profiler.py │ │ │ ├── test_ptds.py │ │ │ ├── test_reset_device.py │ │ │ ├── test_runtime.py │ │ │ ├── test_select_device.py │ │ │ └── test_streams.py │ │ ├── cudapy │ │ │ ├── __init__.py │ │ │ ├── cache_usecases.py │ │ │ ├── cache_with_cpu_usecases.py │ │ │ ├── extensions_usecases.py │ │ │ ├── jitlink.ptx │ │ │ ├── recursion_usecases.py │ │ │ ├── test_alignment.py │ │ │ ├── test_array.py │ │ │ ├── test_array_args.py │ │ │ ├── test_array_methods.py │ │ │ ├── test_atomics.py │ │ │ ├── test_blackscholes.py │ │ │ ├── test_boolean.py │ │ │ ├── test_caching.py │ │ │ ├── test_casting.py │ │ │ ├── test_cffi.py │ │ │ ├── test_compiler.py │ │ │ ├── test_complex.py │ │ │ ├── test_complex_kernel.py │ │ │ ├── test_const_string.py │ │ │ ├── test_constmem.py │ │ │ ├── test_cooperative_groups.py │ │ │ ├── test_cuda_array_interface.py │ │ │ ├── test_cuda_jit_no_types.py │ │ │ ├── test_datetime.py │ │ │ ├── test_debug.py │ │ │ ├── test_debuginfo.py │ │ │ ├── test_device_func.py │ │ │ ├── test_dispatcher.py │ │ │ ├── test_enums.py │ │ │ ├── test_errors.py │ │ │ ├── test_exception.py │ │ │ ├── test_extending.py │ │ │ ├── test_fastmath.py │ │ │ ├── test_forall.py │ │ │ ├── test_freevar.py │ │ │ ├── test_frexp_ldexp.py │ │ │ ├── test_globals.py │ │ │ ├── test_gufunc.py │ │ │ ├── test_gufunc_scalar.py │ │ │ ├── test_gufunc_scheduling.py │ │ │ ├── test_idiv.py │ │ │ ├── test_inspect.py │ │ │ ├── test_intrinsics.py │ │ │ ├── test_ipc.py │ │ │ ├── test_iterators.py │ │ │ ├── test_lang.py │ │ │ ├── test_laplace.py │ │ │ ├── test_libdevice.py │ │ │ ├── test_lineinfo.py │ │ │ ├── test_localmem.py │ │ │ ├── test_mandel.py │ │ │ ├── test_math.py │ │ │ ├── test_matmul.py │ │ │ ├── test_minmax.py │ │ │ ├── test_montecarlo.py │ │ │ ├── test_multigpu.py │ │ │ ├── test_multiprocessing.py │ │ │ ├── test_multithreads.py │ │ │ ├── test_nondet.py │ │ │ ├── test_operator.py │ │ │ ├── test_optimization.py │ │ │ ├── test_overload.py │ │ │ ├── test_powi.py │ │ │ ├── test_print.py │ │ │ ├── test_py2_div_issue.py │ │ │ ├── test_random.py │ │ │ ├── test_record_dtype.py │ │ │ ├── test_recursion.py │ │ │ ├── test_reduction.py │ │ │ ├── test_retrieve_autoconverted_arrays.py │ │ │ ├── test_serialize.py │ │ │ ├── test_slicing.py │ │ │ ├── test_sm.py │ │ │ ├── test_sm_creation.py │ │ │ ├── test_sync.py │ │ │ ├── test_transpose.py │ │ │ ├── test_ufuncs.py │ │ │ ├── test_userexc.py │ │ │ ├── test_vector_type.py │ │ │ ├── test_vectorize.py │ │ │ ├── test_vectorize_complex.py │ │ │ ├── test_vectorize_decor.py │ │ │ ├── test_vectorize_device.py │ │ │ ├── test_vectorize_scalar_arg.py │ │ │ ├── test_warning.py │ │ │ └── test_warp_ops.py │ │ ├── cudasim │ │ │ ├── __init__.py │ │ │ ├── support.py │ │ │ └── test_cudasim_issues.py │ │ ├── data │ │ │ ├── __init__.py │ │ │ ├── cuda_include.cu │ │ │ ├── error.cu │ │ │ ├── jitlink.cu │ │ │ ├── jitlink.ptx │ │ │ └── warn.cu │ │ ├── doc_examples │ │ │ ├── __init__.py │ │ │ ├── ffi │ │ │ │ ├── __init__.py │ │ │ │ └── functions.cu │ │ │ ├── test_cg.py │ │ │ ├── test_cpu_gpu_compat.py │ │ │ ├── test_ffi.py │ │ │ ├── test_laplace.py │ │ │ ├── test_matmul.py │ │ │ ├── test_montecarlo.py │ │ │ ├── test_random.py │ │ │ ├── test_reduction.py │ │ │ ├── test_sessionize.py │ │ │ ├── test_ufunc.py │ │ │ └── test_vecadd.py │ │ └── nocuda │ │ │ ├── __init__.py │ │ │ ├── test_dummyarray.py │ │ │ ├── test_function_resolution.py │ │ │ ├── test_import.py │ │ │ ├── test_library_lookup.py │ │ │ └── test_nvvm.py │ ├── types.py │ ├── ufuncs.py │ ├── vector_types.py │ └── vectorizers.py ├── experimental │ ├── __init__.py │ ├── function_type.py │ ├── jitclass │ │ ├── __init__.py │ │ ├── _box.c │ │ ├── base.py │ │ ├── boxing.py │ │ ├── decorators.py │ │ └── overloads.py │ └── structref.py ├── extending.py ├── mathnames.h ├── misc │ ├── POST.py │ ├── __init__.py │ ├── appdirs.py │ ├── cffiimpl.py │ ├── cmdlang.gdb │ ├── coverage_support.py │ ├── dump_style.py │ ├── findlib.py │ ├── firstlinefinder.py │ ├── gdb_hook.py │ ├── gdb_print_extension.py │ ├── help │ │ ├── __init__.py │ │ └── inspector.py │ ├── init_utils.py │ ├── inspection.py │ ├── literal.py │ ├── llvm_pass_timings.py │ ├── mergesort.py │ ├── numba_entry.py │ ├── numba_gdbinfo.py │ ├── numba_sysinfo.py │ ├── quicksort.py │ ├── special.py │ └── timsort.py ├── mviewbuf.c ├── np │ ├── __init__.py │ ├── arraymath.py │ ├── arrayobj.py │ ├── extensions.py │ ├── linalg.py │ ├── math │ │ ├── __init__.py │ │ ├── cmathimpl.py │ │ ├── mathimpl.py │ │ └── numbers.py │ ├── new_arraymath.py │ ├── npdatetime.py │ ├── npdatetime_helpers.py │ ├── npyfuncs.py │ ├── npyimpl.py │ ├── numpy_support.py │ ├── old_arraymath.py │ ├── polynomial │ │ ├── __init__.py │ │ ├── polynomial_core.py │ │ └── polynomial_functions.py │ ├── random │ │ ├── __init__.py │ │ ├── _constants.py │ │ ├── distributions.py │ │ ├── generator_core.py │ │ ├── generator_methods.py │ │ ├── new_distributions.py │ │ ├── new_random_methods.py │ │ ├── old_distributions.py │ │ ├── old_random_methods.py │ │ └── random_methods.py │ ├── ufunc │ │ ├── __init__.py │ │ ├── _internal.c │ │ ├── _internal.h │ │ ├── _num_threads.c │ │ ├── _ufunc.c │ │ ├── array_exprs.py │ │ ├── decorators.py │ │ ├── dufunc.py │ │ ├── gufunc.py │ │ ├── gufunc_scheduler.cpp │ │ ├── gufunc_scheduler.h │ │ ├── omppool.cpp │ │ ├── parallel.py │ │ ├── sigparse.py │ │ ├── tbbpool.cpp │ │ ├── ufunc_base.py │ │ ├── ufuncbuilder.py │ │ ├── workqueue.c │ │ ├── workqueue.h │ │ └── wrappers.py │ ├── ufunc_db.py │ └── unsafe │ │ ├── __init__.py │ │ └── ndarray.py ├── parfors │ ├── __init__.py │ ├── array_analysis.py │ ├── parfor.py │ ├── parfor_lowering.py │ └── parfor_lowering_utils.py ├── pycc │ ├── __init__.py │ ├── cc.py │ ├── compiler.py │ ├── decorators.py │ ├── llvm_types.py │ ├── modulemixin.c │ └── platform.py ├── pythoncapi_compat.h ├── runtests.py ├── scripts │ ├── __init__.py │ └── generate_lower_listing.py ├── stencils │ ├── __init__.py │ ├── stencil.py │ └── stencilparfor.py ├── testing │ ├── __init__.py │ ├── __main__.py │ ├── _runtests.py │ ├── loader.py │ ├── main.py │ └── notebook.py ├── tests │ ├── __init__.py │ ├── annotation_usecases.py │ ├── cache_usecases.py │ ├── cffi_usecases.py │ ├── cfunc_cache_usecases.py │ ├── chained_assign_usecases.py │ ├── cloudpickle_main_class.py │ ├── compile_with_pycc.py │ ├── complex_usecases.py │ ├── ctypes_usecases.py │ ├── doc_examples │ │ ├── __init__.py │ │ ├── test_examples.py │ │ ├── test_interval_example.py │ │ ├── test_jitclass.py │ │ ├── test_literal_container_usage.py │ │ ├── test_literally_usage.py │ │ ├── test_llvm_pass_timings.py │ │ ├── test_numpy_generators.py │ │ ├── test_parallel_chunksize.py │ │ ├── test_rec_array.py │ │ ├── test_structref_usage.py │ │ ├── test_typed_dict_usage.py │ │ └── test_typed_list_usage.py │ ├── doctest_usecase.py │ ├── dummy_module.py │ ├── enum_usecases.py │ ├── error_usecases.py │ ├── errorhandling_usecases.py │ ├── gdb │ │ ├── __init__.py │ │ ├── test_array_arg.py │ │ ├── test_basic.py │ │ ├── test_break_on_symbol.py │ │ ├── test_break_on_symbol_version.py │ │ ├── test_conditional_breakpoint.py │ │ └── test_pretty_print.py │ ├── gdb_support.py │ ├── inlining_usecases.py │ ├── matmul_usecase.py │ ├── npyufunc │ │ ├── __init__.py │ │ ├── cache_usecases.py │ │ ├── test_caching.py │ │ ├── test_dufunc.py │ │ ├── test_errors.py │ │ ├── test_gufunc.py │ │ ├── test_parallel_env_variable.py │ │ ├── test_parallel_low_work.py │ │ ├── test_parallel_ufunc_issues.py │ │ ├── test_ufunc.py │ │ ├── test_ufuncbuilding.py │ │ ├── test_update_inplace.py │ │ ├── test_vectorize_decor.py │ │ └── ufuncbuilding_usecases.py │ ├── orphaned_semaphore_usecase.py │ ├── overload_usecases.py │ ├── parfor_iss9490_usecase.py │ ├── parfors_cache_usecases.py │ ├── pdlike_usecase.py │ ├── pycc_distutils_usecase │ │ ├── __init__.py │ │ ├── nested │ │ │ ├── __init__.py │ │ │ └── source_module.py │ │ ├── setup_distutils.py │ │ ├── setup_distutils_nested.py │ │ ├── setup_setuptools.py │ │ ├── setup_setuptools_nested.py │ │ └── source_module.py │ ├── recursion_usecases.py │ ├── serialize_usecases.py │ ├── support.py │ ├── test_alignment.py │ ├── test_analysis.py │ ├── test_annotations.py │ ├── test_api.py │ ├── test_array_analysis.py │ ├── test_array_attr.py │ ├── test_array_constants.py │ ├── test_array_exprs.py │ ├── test_array_iterators.py │ ├── test_array_manipulation.py │ ├── test_array_methods.py │ ├── test_array_reductions.py │ ├── test_array_return.py │ ├── test_asnumbatype.py │ ├── test_auto_constants.py │ ├── test_blackscholes.py │ ├── test_boundscheck.py │ ├── test_buffer_protocol.py │ ├── test_builtins.py │ ├── test_byteflow.py │ ├── test_caching.py │ ├── test_casting.py │ ├── test_cffi.py │ ├── test_cfunc.py │ ├── test_cgutils.py │ ├── test_chained_assign.py │ ├── test_chrome_trace.py │ ├── test_cli.py │ ├── test_closure.py │ ├── test_codegen.py │ ├── test_compile_cache.py │ ├── test_compiler_flags.py │ ├── test_compiler_lock.py │ ├── test_complex.py │ ├── test_comprehension.py │ ├── test_conditions_as_predicates.py │ ├── test_config.py │ ├── test_conversion.py │ ├── test_copy_propagate.py │ ├── test_ctypes.py │ ├── test_dataflow.py │ ├── test_datamodel.py │ ├── test_debug.py │ ├── test_debuginfo.py │ ├── test_deprecations.py │ ├── test_dictimpl.py │ ├── test_dictobject.py │ ├── test_dicts.py │ ├── test_dispatcher.py │ ├── test_doctest.py │ ├── test_dyn_array.py │ ├── test_dyn_func.py │ ├── test_entrypoints.py │ ├── test_enums.py │ ├── test_errorhandling.py │ ├── test_errormodels.py │ ├── test_event.py │ ├── test_exceptions.py │ ├── test_extended_arg.py │ ├── test_extending.py │ ├── test_extending_types.py │ ├── test_fancy_indexing.py │ ├── test_fastmath.py │ ├── test_findlib.py │ ├── test_firstlinefinder.py │ ├── test_flow_control.py │ ├── test_func_interface.py │ ├── test_func_lifetime.py │ ├── test_funcdesc.py │ ├── test_function_type.py │ ├── test_gdb_bindings.py │ ├── test_gdb_dwarf.py │ ├── test_generators.py │ ├── test_getitem_on_types.py │ ├── test_gil.py │ ├── test_globals.py │ ├── test_hashing.py │ ├── test_heapq.py │ ├── test_help.py │ ├── test_import.py │ ├── test_indexing.py │ ├── test_init_utils.py │ ├── test_inlining.py │ ├── test_interpreter.py │ ├── test_interproc.py │ ├── test_intwidth.py │ ├── test_ir.py │ ├── test_ir_inlining.py │ ├── test_ir_utils.py │ ├── test_itanium_mangler.py │ ├── test_iteration.py │ ├── test_jit_module.py │ ├── test_jitclasses.py │ ├── test_jitmethod.py │ ├── test_linalg.py │ ├── test_listimpl.py │ ├── test_listobject.py │ ├── test_lists.py │ ├── test_literal_dispatch.py │ ├── test_llvm_pass_timings.py │ ├── test_llvm_version_check.py │ ├── test_locals.py │ ├── test_looplifting.py │ ├── test_make_function_to_jit_function.py │ ├── test_mandelbrot.py │ ├── test_mangling.py │ ├── test_map_filter_reduce.py │ ├── test_mathlib.py │ ├── test_maxmin.py │ ├── test_misc_coverage_support.py │ ├── test_mixed_tuple_unroller.py │ ├── test_moved_modules.py │ ├── test_multi3.py │ ├── test_nan.py │ ├── test_ndarray_subclasses.py │ ├── test_nested_calls.py │ ├── test_new_type_system.py │ ├── test_np_functions.py │ ├── test_np_randomgen.py │ ├── test_npdatetime.py │ ├── test_nrt.py │ ├── test_nrt_refct.py │ ├── test_num_threads.py │ ├── test_numberctor.py │ ├── test_numbers.py │ ├── test_numconv.py │ ├── test_numpy_support.py │ ├── test_numpyadapt.py │ ├── test_obj_lifetime.py │ ├── test_object_mode.py │ ├── test_objects.py │ ├── test_operators.py │ ├── test_optimisation_pipelines.py │ ├── test_optional.py │ ├── test_overlap.py │ ├── test_parallel_backend.py │ ├── test_parfors.py │ ├── test_parfors_caching.py │ ├── test_parfors_passes.py │ ├── test_pipeline.py │ ├── test_polynomial.py │ ├── test_practical_lowering_issues.py │ ├── test_print.py │ ├── test_profiler.py │ ├── test_pycc.py │ ├── test_python_int.py │ ├── test_pythonapi.py │ ├── test_random.py │ ├── test_range.py │ ├── test_recarray_usecases.py │ ├── test_record_dtype.py │ ├── test_recursion.py │ ├── test_refop_pruning.py │ ├── test_remove_dead.py │ ├── test_repr.py │ ├── test_return_values.py │ ├── test_runtests.py │ ├── test_serialize.py │ ├── test_sets.py │ ├── test_slices.py │ ├── test_sort.py │ ├── test_ssa.py │ ├── test_stencils.py │ ├── test_storeslice.py │ ├── test_struct_ref.py │ ├── test_support.py │ ├── test_svml.py │ ├── test_sys_monitoring.py │ ├── test_sys_stdin_assignment.py │ ├── test_sysinfo.py │ ├── test_target_extension.py │ ├── test_target_overloadselector.py │ ├── test_threadsafety.py │ ├── test_tracing.py │ ├── test_try_except.py │ ├── test_tuples.py │ ├── test_typeconv.py │ ├── test_typedlist.py │ ├── test_typedobjectutils.py │ ├── test_typeguard.py │ ├── test_typeinfer.py │ ├── test_typenames.py │ ├── test_typeof.py │ ├── test_types.py │ ├── test_typingerror.py │ ├── test_ufuncs.py │ ├── test_unicode.py │ ├── test_unicode_array.py │ ├── test_unicode_names.py │ ├── test_unpack_sequence.py │ ├── test_unpickle_without_module.py │ ├── test_unsafe_intrinsics.py │ ├── test_usecases.py │ ├── test_vectorization.py │ ├── test_vectorization_type_inference.py │ ├── test_warnings.py │ ├── test_withlifting.py │ ├── threading_backend_usecases.py │ ├── typedlist_usecases.py │ └── usecases.py ├── typed │ ├── __init__.py │ ├── dictimpl.py │ ├── dictobject.py │ ├── listobject.py │ ├── py.typed │ ├── typeddict.py │ ├── typedlist.py │ └── typedobjectutils.py └── types │ └── __init__.py ├── requirements.txt ├── runtests.py ├── setup.cfg ├── setup.py ├── towncrier.toml └── versioneer.py /.coveragerc: -------------------------------------------------------------------------------- 1 | # configuration file used by run_coverage.py 2 | [run] 3 | branch = True 4 | source = numba 5 | concurrency = multiprocessing 6 | parallel = True 7 | 8 | [report] 9 | 10 | omit = 11 | */__main__.py 12 | # Vendored packages 13 | numba/misc/appdirs.py 14 | numba/cloudpickle/__init__.py 15 | numba/cloudpickle/cloudpickle.py 16 | numba/cloudpickle/cloudpickle_fast.py 17 | numba/cloudpickle/compat.py 18 | numba/_version.py 19 | 20 | exclude_lines = 21 | pragma: no cover 22 | if __name__ == .__main__.: 23 | 24 | [html] 25 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | numba/_version.py export-subst 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Report a bug. Not for asking general questions - see below. 4 | 5 | --- 6 | 7 | 15 | 16 | ## Reporting a bug 17 | 18 | 23 | 24 | - [ ] I have tried using the latest released version of Numba (most recent is 25 | visible in the release notes 26 | (https://numba.readthedocs.io/en/stable/release-notes-overview.html). 27 | - [ ] I have included a self contained code sample to reproduce the problem. 28 | i.e. it's possible to run as 'python bug.py'. 29 | 30 | 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Tell us about something in the Python language/NumPy you'd like Numba to support. Not for asking general questions - see below. 4 | 5 | --- 6 | 7 | 15 | 16 | ## Feature request 17 | 18 | 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: General Question 4 | url: https://numba.discourse.group/c/numba/community-support/ 5 | about: "If you have a general question (not a bug report or feature request) then please ask on Numba's discourse instance." 6 | - name: Quick Question/Just want to say Hi! 7 | url: https://gitter.im/numba/numba 8 | about: "If you have a quick question or want chat to users/developers in real time then please use gitter.im/numba/numba" 9 | - name: Discuss an involved feature 10 | url: https://numba.discourse.group/c/numba/development/ 11 | about: "If you would like to suggest a more involved feature like *Can a new compiler pass be added to do X* then please start a discussion on Numba's discourse instance." 12 | - name: CUDA 13 | url: https://github.com/NVIDIA/numba-cuda 14 | about: "Any items related to the CUDA target should be reported in the numba-cuda repo" 15 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: 'Mark stale issues' 2 | on: 3 | schedule: 4 | - cron: '30 1 * * *' 5 | 6 | permissions: 7 | contents: read 8 | 9 | jobs: 10 | stale: 11 | permissions: 12 | issues: write # for actions/stale to close stale issues 13 | pull-requests: write # for actions/stale to close stale PRs 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/stale@v9 17 | with: 18 | # issues 19 | stale-issue-message: > 20 | This issue is marked as stale as it has had no activity in the past 21 | 30 days. Please close this issue if no further response or action is 22 | needed. Otherwise, please respond with any updates and confirm that 23 | this issue still needs to be addressed. 24 | stale-issue-label: 'stale' 25 | any-of-issue-labels: 'question,needtriage,more info needed' 26 | days-before-issue-stale: 30 27 | days-before-issue-close: 7 28 | # pull requests 29 | stale-pr-message: > 30 | This pull request is marked as stale as it has had no activity in 31 | the past 3 months. Please respond to this comment if you're still 32 | interested in working on this. Many thanks! 33 | days-before-pr-stale: 90 # 3 months 34 | days-before-pr-close: 7 35 | any-of-pr-labels: '2 - In progress,4 - Waiting on author' 36 | stale-pr-label: 'stale' 37 | close-pr-label: 'abandoned - stale' 38 | -------------------------------------------------------------------------------- /.github/workflows/towncrier.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Check Release Notes 3 | on: 4 | pull_request: 5 | types: [labeled, unlabeled, opened, reopened, synchronize] 6 | 7 | env: 8 | GITHUB_PR_NUMBER: ${{github.event.pull_request.number}} 9 | 10 | jobs: 11 | check: 12 | name: Check release notes 13 | if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip_release_notes') }} 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | with: 18 | fetch-depth: 0 19 | - name: Set up Python 3.10 20 | uses: actions/setup-python@v5 21 | with: 22 | python-version: '3.10' 23 | - name: Install towncrier 24 | run: | 25 | python3 -m pip install towncrier==23.6 "importlib_resources<6" rstcheck 26 | - name: Run towncrier 27 | run: | 28 | git fetch --no-tags origin +refs/heads/${BASE_BRANCH}:refs/remotes/origin/${BASE_BRANCH} 29 | towncrier check --compare-with remotes/origin/${BASE_BRANCH} 30 | python maint/towncrier_rst_validator.py --pull_request_id $GITHUB_PR_NUMBER 31 | env: 32 | BASE_BRANCH: ${{ github.base_ref }} 33 | -------------------------------------------------------------------------------- /.github/workflows/workflow_matrix.json: -------------------------------------------------------------------------------- 1 | { 2 | "conda_build_matrix": [ 3 | { "python-version": "3.10", "numpy_build": "2.0" }, 4 | { "python-version": "3.11", "numpy_build": "2.0" }, 5 | { "python-version": "3.12", "numpy_build": "2.0" }, 6 | { "python-version": "3.13", "numpy_build": "2.1" } 7 | ], 8 | "conda_test_matrix": [ 9 | { "python-version": "3.10", "numpy_test": "1.24" }, 10 | { "python-version": "3.10", "numpy_test": "1.25" }, 11 | { "python-version": "3.11", "numpy_test": "1.26" }, 12 | { "python-version": "3.11", "numpy_test": "2.0" }, 13 | { "python-version": "3.11", "numpy_test": "2.2" }, 14 | { "python-version": "3.12", "numpy_test": "1.26" }, 15 | { "python-version": "3.12", "numpy_test": "2.0" }, 16 | { "python-version": "3.12", "numpy_test": "2.2" }, 17 | { "python-version": "3.13", "numpy_test": "2.2" } 18 | ], 19 | "wheel_matrix": [ 20 | { "python-version": "3.10", "numpy_build": "2.0.2", "python_tag": "cp310" }, 21 | { "python-version": "3.11", "numpy_build": "2.0.2", "python_tag": "cp311" }, 22 | { "python-version": "3.12", "numpy_build": "2.0.2", "python_tag": "cp312" }, 23 | { "python-version": "3.13", "numpy_build": "2.1.3", "python_tag": "cp313" } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.o 3 | *.so 4 | *.dylib 5 | *.pyd 6 | *.pdb 7 | *.egg-info 8 | *.sw[po] 9 | *.out 10 | *.ll 11 | .coverage 12 | .nfs* 13 | tags 14 | MANIFEST 15 | 16 | build/ 17 | docs/_build/ 18 | docs/gh-pages/ 19 | dist/ 20 | htmlcov/ 21 | .idea/ 22 | .vscode/ 23 | .ycm_extra_conf.py 24 | .mypy_cache/ 25 | .ipynb_checkpoints/ 26 | __pycache__/ 27 | 28 | docs/source/developer/autogen* 29 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/PyCQA/flake8 3 | rev: 7.1.1 4 | hooks: 5 | - id: flake8 6 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | build: 3 | os: ubuntu-20.04 4 | tools: 5 | python: miniconda3-3.12-24.1 6 | sphinx: 7 | configuration: docs/source/conf.py 8 | python: 9 | install: 10 | - method: setuptools 11 | path: . 12 | conda: 13 | environment: docs/environment.yml 14 | formats: 15 | - pdf 16 | -------------------------------------------------------------------------------- /CHANGE_LOG: -------------------------------------------------------------------------------- 1 | The contents of this file has been removed. The change log can now be found at: 2 | 3 | docs/source/release/* 4 | 5 | and: 6 | 7 | docs/source/release-notes.rst 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Anaconda, Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include MANIFEST.in 2 | include README.rst setup.py runtests.py versioneer.py CHANGE_LOG LICENSE 3 | 4 | recursive-include numba *.c *.cpp *.h *.hpp *.inc 5 | recursive-include docs *.ipynb *.txt *.py Makefile *.rst 6 | recursive-include examples *.py 7 | 8 | prune docs/_build 9 | include numba/_version.py 10 | -------------------------------------------------------------------------------- /bin/numba: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: UTF-8 -*- 3 | from __future__ import print_function, division, absolute_import 4 | 5 | from numba.misc.numba_entry import main 6 | 7 | if __name__ == "__main__": 8 | main() 9 | -------------------------------------------------------------------------------- /buildscripts/condarecipe.local/bld.bat: -------------------------------------------------------------------------------- 1 | %PYTHON% setup.py build install --single-version-externally-managed --record=record.txt 2 | 3 | exit /b %errorlevel% 4 | -------------------------------------------------------------------------------- /buildscripts/condarecipe.local/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ "$(uname -s)" == *"Linux"* ]] && [[ "$(uname -p)" == *"86"* ]]; then 4 | EXTRA_BUILD_EXT_FLAGS="--werror --wall" 5 | else 6 | EXTRA_BUILD_EXT_FLAGS="" 7 | fi 8 | 9 | if [[ "$(uname -s)" == *"Linux"* ]] && [[ "$(uname -p)" == *"ppc64le"* ]]; then 10 | # To workaround https://github.com/numba/numba/issues/7302 11 | # because of a python build problem that the -pthread could be stripped. 12 | export CC="$CC -pthread" 13 | export CXX="$CXX -pthread" 14 | fi 15 | 16 | MACOSX_DEPLOYMENT_TARGET=10.10 $PYTHON setup.py build_ext $EXTRA_BUILD_EXT_FLAGS build install --single-version-externally-managed --record=record.txt 17 | -------------------------------------------------------------------------------- /buildscripts/condarecipe.local/conda_build_config.yaml: -------------------------------------------------------------------------------- 1 | # Numba/llvmlite stack needs an older compiler for backwards compatibility. 2 | c_compiler_version: # [linux] 3 | - 7 # [linux and (x86_64 or ppc64le)] 4 | - 11 # [linux and aarch64] 5 | 6 | cxx_compiler_version: # [linux] 7 | - 7 # [linux and (x86_64 or ppc64le)] 8 | - 11 # [linux and aarch64] 9 | 10 | fortran_compiler_version: # [linux] 11 | - 7 # [linux and (x86_64 or ppc64le)] 12 | - 11 # [linux and aarch64] 13 | -------------------------------------------------------------------------------- /buildscripts/condarecipe.local/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Anaconda, Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /buildscripts/condarecipe.local/run_test.bat: -------------------------------------------------------------------------------- 1 | set NUMBA_DEVELOPER_MODE=1 2 | set NUMBA_DISABLE_ERROR_MESSAGE_HIGHLIGHTING=1 3 | set PYTHONFAULTHANDLER=1 4 | 5 | @rem Check Numba executable is there 6 | numba -h 7 | 8 | @rem Run system info tool 9 | numba -s 10 | 11 | @rem Check test discovery works 12 | python -m numba.tests.test_runtests 13 | 14 | @rem Run the whole test suite 15 | python -m numba.runtests -b -m -- %TESTS_TO_RUN% 16 | 17 | if errorlevel 1 exit 1 18 | -------------------------------------------------------------------------------- /buildscripts/github/MacOSX10.10.sdk.checksum: -------------------------------------------------------------------------------- 1 | 3839b875df1f2bc98893b8502da456cc0b022c4666bc6b7eb5764a5f915a9b00 MacOSX10.10.sdk.tar.xz 2 | -------------------------------------------------------------------------------- /buildscripts/github/patch_wheel_dylib.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import re 3 | import os 4 | import subprocess as subp 5 | 6 | 7 | known_rpaths = { 8 | '@rpath/libc++.1.dylib': "/usr/lib/libc++.1.dylib", 9 | } 10 | 11 | 12 | def run_shell(cmd): 13 | out = subp.check_output(cmd, shell=True) 14 | return out 15 | 16 | 17 | def main(whl): 18 | # Find shared libraries 19 | run_shell('wheel unpack {}'.format(whl)) 20 | thedir = '-'.join(whl.split('-')[:2]) 21 | 22 | sharedlibs = run_shell('find {} -name "*.so"'.format(thedir)).decode().splitlines() 23 | # Scan paths 24 | regex_rpath = re.compile(r'@rpath\/[^ ]+') 25 | updated_files = set() 26 | for path in sharedlibs: 27 | # Check rpaths 28 | otool_out = run_shell('otool -L {}'.format(path)).decode() 29 | rpaths = set(regex_rpath.findall(otool_out)) 30 | unknown = rpaths - set(known_rpaths.keys()) 31 | if unknown: 32 | #raise AssertionError('unknown rpath {}'.format(unknown)) 33 | print('unknown', unknown) 34 | # Patch 35 | for rpath in rpaths & set(known_rpaths.keys()): 36 | print('patch', rpath, 'in', path) 37 | run_shell('install_name_tool -change {} {} {}'.format( 38 | rpath, known_rpaths[rpath], path)) 39 | updated_files.add(path) 40 | print('updated_files', updated_files) 41 | # Update whl 42 | if updated_files: 43 | run_shell('wheel pack {}'.format(thedir)) 44 | else: 45 | print('nothing to do') 46 | 47 | 48 | if __name__ == '__main__': 49 | main(*sys.argv[1:]) 50 | -------------------------------------------------------------------------------- /buildscripts/github/setup_platform.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | PLATFORM=$1 6 | 7 | echo "Setting up platform-specific requirements for ${PLATFORM}" 8 | 9 | case "${PLATFORM}" in 10 | "osx-64") 11 | echo "Setting up macOS SDK for osx-64 build" 12 | sdk_dir="buildscripts/github" 13 | mkdir -p "${sdk_dir}" 14 | 15 | # Download SDK 16 | echo "Downloading MacOSX10.10.sdk.tar.xz" 17 | wget -q https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX10.10.sdk.tar.xz 18 | 19 | # Verify checksum 20 | echo "Verifying SDK checksum" 21 | shasum -c "${sdk_dir}/MacOSX10.10.sdk.checksum" || exit 1 22 | 23 | # Extract SDK to /opt 24 | echo "Extracting SDK to /opt" 25 | sudo mkdir -p /opt 26 | sudo tar -xf MacOSX10.10.sdk.tar.xz -C /opt 27 | echo "macOS SDK setup complete" 28 | ;; 29 | *) 30 | echo "No specific setup required for platform: ${PLATFORM}" 31 | ;; 32 | esac 33 | 34 | echo "Platform setup complete for ${PLATFORM}" 35 | -------------------------------------------------------------------------------- /buildscripts/gpuci/axis.yaml: -------------------------------------------------------------------------------- 1 | PYTHON_VER: 2 | - "3.8" 3 | 4 | CUDA_VER: 5 | - "11.2" 6 | 7 | CUDA_TOOLKIT_VER: 8 | - "11.2" 9 | - "11.3" 10 | - "11.5" 11 | - "11.8" 12 | 13 | LINUX_VER: 14 | - ubuntu18.04 15 | 16 | RAPIDS_VER: 17 | - "21.12" 18 | 19 | excludes: 20 | -------------------------------------------------------------------------------- /buildscripts/incremental/MacOSX10.10.sdk.checksum: -------------------------------------------------------------------------------- 1 | ea40a3b9dc48cd3593628490f2738b89282f00ab ./MacOSX10.10.sdk.tar.xz 2 | -------------------------------------------------------------------------------- /buildscripts/incremental/after_success.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source activate $CONDA_ENV 4 | 5 | # Make sure any error below is reported as such 6 | set -v -e 7 | 8 | if [ "$RUN_COVERAGE" == "yes" ]; then 9 | coverage combine 10 | codecov 11 | fi 12 | -------------------------------------------------------------------------------- /buildscripts/incremental/build.cmd: -------------------------------------------------------------------------------- 1 | 2 | call activate %CONDA_ENV% 3 | 4 | @rem Build numba extensions without silencing compile errors 5 | python setup.py build_ext -q --inplace 6 | 7 | @rem Install numba locally for use in `numba -s` sys info tool at test time 8 | python -m pip install -e . 9 | 10 | if %errorlevel% neq 0 exit /b %errorlevel% 11 | -------------------------------------------------------------------------------- /buildscripts/incremental/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source activate 4 | conda activate $CONDA_ENV 5 | 6 | # Make sure any error below is reported as such 7 | set -v -e 8 | 9 | # Build numba extensions without silencing compile errors 10 | if [[ "$(uname -s)" == *"Linux"* ]] && [[ "$(uname -p)" == *"86"* ]]; then 11 | EXTRA_BUILD_EXT_FLAGS="--werror --wall" 12 | else 13 | EXTRA_BUILD_EXT_FLAGS="" 14 | fi 15 | 16 | if [[ $(uname) == "Darwin" ]]; then 17 | # The following is suggested in https://docs.conda.io/projects/conda-build/en/latest/resources/compiler-tools.html?highlight=SDK#macos-sdk 18 | wget -q https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX10.10.sdk.tar.xz 19 | shasum -c ./buildscripts/incremental/MacOSX10.10.sdk.checksum 20 | tar -xf ./MacOSX10.10.sdk.tar.xz 21 | export SDKROOT=`pwd`/MacOSX10.10.sdk 22 | fi 23 | python setup.py build_ext -q --inplace --debug $EXTRA_BUILD_EXT_FLAGS --verbose 24 | # (note we don't install to avoid problems with extra long Windows paths 25 | # during distutils-dependent tests -- e.g. test_pycc) 26 | 27 | # Install numba locally for use in `numba -s` sys info tool at test time 28 | python -m pip install --no-deps -e . 29 | -------------------------------------------------------------------------------- /buildscripts/incremental/install_miniconda.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -v -e 4 | 5 | # Install Miniconda 6 | unamestr=`uname` 7 | if [[ "$unamestr" == 'Linux' ]]; then 8 | wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh 9 | elif [[ "$unamestr" == 'Darwin' ]]; then 10 | wget https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O miniconda.sh 11 | else 12 | echo Error 13 | fi 14 | chmod +x miniconda.sh 15 | bash ./miniconda.sh -b 16 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | # Configuration for codecov.io 2 | # When editing this file, please validate its contents using: 3 | # curl -X POST --data-binary @- https://codecov.io/validate < codecov.yml 4 | 5 | comment: 6 | layout: "header, diff, changes, uncovered" 7 | 8 | coverage: 9 | ignore: 10 | - "numba/cuda/.*" 11 | - "numba/hsa/.*" 12 | 13 | status: 14 | project: 15 | default: 16 | # The build fails if total project coverage drops by more than 3% 17 | target: auto 18 | threshold: "3%" 19 | # These checks can mark a build failed if too much new code 20 | # is not covered (which happens often with JITted functions). 21 | changes: false 22 | patch: false 23 | -------------------------------------------------------------------------------- /contrib/valgrind-numba.supp: -------------------------------------------------------------------------------- 1 | { 2 | 3 | Memcheck:Cond 4 | fun:_ZN4llvm3sys14getHostCPUNameEv 5 | fun:LLVMPY_GetHostCPUName 6 | } 7 | 8 | { 9 | 10 | Memcheck:Value8 11 | fun:_ZN4llvm3sys14getHostCPUNameEv 12 | fun:LLVMPY_GetHostCPUName 13 | } 14 | 15 | { 16 | 17 | Memcheck:Cond 18 | fun:__intel_sse2_strrchr 19 | fun:_ZN67_INTERNAL_45_______src_thirdparty_tbb_omp_dynamic_link_cpp_c306cade5__kmp12init_dl_dataEv 20 | fun:__sti__$E 21 | } 22 | -------------------------------------------------------------------------------- /docs/_static/js/modernizr.min.js: -------------------------------------------------------------------------------- 1 | /* modernizr.min.js is unused but causes a reflow on load. In firefox, this 2 | * manifests as the Numba logo flashing up across the whole browser window for a 3 | * split second every time the page is loaded or a documentation link is 4 | * clicked. This empty file overrides the version included by the theme. 5 | * 6 | * Reference: https://github.com/readthedocs/sphinx_rtd_theme/issues/724 7 | */ 8 | -------------------------------------------------------------------------------- /docs/_static/rtd-overrides.css: -------------------------------------------------------------------------------- 1 | .wy-nav-content { 2 | max-width: 1200px 3 | } 4 | -------------------------------------------------------------------------------- /docs/_templates/EMPTY: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/docs/_templates/EMPTY -------------------------------------------------------------------------------- /docs/environment.yml: -------------------------------------------------------------------------------- 1 | # This environment is used by the RTD config for PR builds. RTD uses this as the 2 | # base environment and then adds in the sphinx etc tools on top. 3 | # See: https://docs.readthedocs.io/en/stable/guides/conda.html 4 | name: rtd 5 | channels: 6 | - numba/label/dev 7 | dependencies: 8 | - python=3.10 9 | - llvmlite=0.45 10 | - numpy 11 | - numpydoc 12 | - setuptools 13 | # https://stackoverflow.com/questions/67542699/readthedocs-sphinx-not-rendering-bullet-list-from-rst-fileA 14 | - docutils==0.16 15 | # The following is needed to fix RTD. 16 | - conda 17 | - gxx_linux-64 18 | -------------------------------------------------------------------------------- /docs/source/cuda-reference/index.rst: -------------------------------------------------------------------------------- 1 | CUDA Python Reference 2 | ===================== 3 | 4 | .. cuda-deprecated:: 5 | 6 | .. toctree:: 7 | 8 | host.rst 9 | kernel.rst 10 | types.rst 11 | memory.rst 12 | libdevice.rst 13 | -------------------------------------------------------------------------------- /docs/source/cuda-reference/libdevice.rst: -------------------------------------------------------------------------------- 1 | Libdevice functions 2 | =================== 3 | 4 | .. cuda-deprecated:: 5 | 6 | All wrapped libdevice functions are listed in this section. All functions in 7 | libdevice are wrapped, with the exception of ``__nv_nan`` and ``__nv_nanf``. 8 | These functions return a representation of a quiet NaN, but the argument they 9 | take (a pointer to an object specifying the representation) is undocumented, and 10 | follows an unusual form compared to the rest of libdevice - it is not an output 11 | like every other pointer argument. If a NaN is required, one can be obtained in 12 | CUDA Python by other means, e.g. ``math.nan``. 13 | 14 | Wrapped functions 15 | ----------------- 16 | 17 | .. automodule:: numba.cuda.libdevice 18 | :members: 19 | -------------------------------------------------------------------------------- /docs/source/cuda-reference/memory.rst: -------------------------------------------------------------------------------- 1 | Memory Management 2 | ================= 3 | 4 | .. cuda-deprecated:: 5 | 6 | .. autofunction:: numba.cuda.to_device 7 | .. autofunction:: numba.cuda.device_array 8 | .. autofunction:: numba.cuda.device_array_like 9 | .. autofunction:: numba.cuda.pinned_array 10 | .. autofunction:: numba.cuda.pinned_array_like 11 | .. autofunction:: numba.cuda.mapped_array 12 | .. autofunction:: numba.cuda.mapped_array_like 13 | .. autofunction:: numba.cuda.managed_array 14 | .. autofunction:: numba.cuda.pinned 15 | .. autofunction:: numba.cuda.mapped 16 | 17 | Device Objects 18 | -------------- 19 | 20 | .. autoclass:: numba.cuda.cudadrv.devicearray.DeviceNDArray 21 | :members: copy_to_device, copy_to_host, is_c_contiguous, is_f_contiguous, 22 | ravel, reshape, split 23 | .. autoclass:: numba.cuda.cudadrv.devicearray.DeviceRecord 24 | :members: copy_to_device, copy_to_host 25 | .. autoclass:: numba.cuda.cudadrv.devicearray.MappedNDArray 26 | :members: copy_to_device, copy_to_host, split 27 | -------------------------------------------------------------------------------- /docs/source/cuda/device-functions.rst: -------------------------------------------------------------------------------- 1 | 2 | Writing Device Functions 3 | ======================== 4 | 5 | .. cuda-deprecated:: 6 | 7 | CUDA device functions can only be invoked from within the device (by a kernel 8 | or another device function). To define a device function:: 9 | 10 | from numba import cuda 11 | 12 | @cuda.jit(device=True) 13 | def a_device_function(a, b): 14 | return a + b 15 | 16 | Unlike a kernel function, a device function can return a value like normal 17 | functions. 18 | -------------------------------------------------------------------------------- /docs/source/cuda/faq.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _cudafaq: 3 | 4 | ================================================= 5 | CUDA Frequently Asked Questions 6 | ================================================= 7 | 8 | .. cuda-deprecated:: 9 | 10 | nvprof reports "No kernels were profiled" 11 | ----------------------------------------- 12 | 13 | When using the ``nvprof`` tool to profile Numba jitted code for the CUDA 14 | target, the output contains ``No kernels were profiled`` but there are clearly 15 | running kernels present, what is going on? 16 | 17 | This is quite likely due to the profiling data not being flushed on program 18 | exit, see the `NVIDIA CUDA documentation 19 | `_ for 20 | details. To fix this simply add a call to ``numba.cuda.profile_stop()`` prior 21 | to the exit point in your program (or wherever you want to stop profiling). 22 | For more on CUDA profiling support in Numba, see :ref:`cuda-profiling`. 23 | -------------------------------------------------------------------------------- /docs/source/cuda/index.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _cuda-index: 3 | 4 | Numba for CUDA GPUs 5 | =================== 6 | 7 | .. cuda-deprecated:: 8 | 9 | .. toctree:: 10 | 11 | overview.rst 12 | kernels.rst 13 | memory.rst 14 | device-functions.rst 15 | cudapysupported.rst 16 | fastmath.rst 17 | intrinsics.rst 18 | cooperative_groups.rst 19 | random.rst 20 | device-management.rst 21 | examples.rst 22 | simulator.rst 23 | reduction.rst 24 | ufunc.rst 25 | ipc.rst 26 | cuda_array_interface.rst 27 | external-memory.rst 28 | bindings.rst 29 | cuda_ffi.rst 30 | cuda_compilation.rst 31 | caching.rst 32 | minor_version_compatibility.rst 33 | faq.rst 34 | -------------------------------------------------------------------------------- /docs/source/cuda/ipc.rst: -------------------------------------------------------------------------------- 1 | =================== 2 | Sharing CUDA Memory 3 | =================== 4 | 5 | .. cuda-deprecated:: 6 | 7 | .. _cuda-ipc-memory: 8 | 9 | Sharing between process 10 | ======================= 11 | 12 | Sharing between processes is implemented using the Legacy CUDA IPC API 13 | (functions whose names begin with ``cuIpc``), and is supported only on Linux. 14 | 15 | 16 | Export device array to another process 17 | -------------------------------------- 18 | 19 | A device array can be shared with another process in the same machine using 20 | the CUDA IPC API. To do so, use the ``.get_ipc_handle()`` method on the device 21 | array to get a ``IpcArrayHandle`` object, which can be transferred to another 22 | process. 23 | 24 | 25 | .. automethod:: numba.cuda.cudadrv.devicearray.DeviceNDArray.get_ipc_handle 26 | :noindex: 27 | 28 | .. autoclass:: numba.cuda.cudadrv.devicearray.IpcArrayHandle 29 | :members: open, close 30 | 31 | 32 | Import IPC memory from another process 33 | -------------------------------------- 34 | 35 | The following function is used to open IPC handle from another process 36 | as a device array. 37 | 38 | .. automethod:: numba.cuda.open_ipc_array 39 | -------------------------------------------------------------------------------- /docs/source/cuda/reduction.rst: -------------------------------------------------------------------------------- 1 | GPU Reduction 2 | ============== 3 | 4 | .. cuda-deprecated:: 5 | 6 | Writing a reduction algorithm for CUDA GPU can be tricky. Numba provides a 7 | ``@reduce`` decorator for converting a simple binary operation into a reduction 8 | kernel. An example follows:: 9 | 10 | import numpy 11 | from numba import cuda 12 | 13 | @cuda.reduce 14 | def sum_reduce(a, b): 15 | return a + b 16 | 17 | A = (numpy.arange(1234, dtype=numpy.float64)) + 1 18 | expect = A.sum() # NumPy sum reduction 19 | got = sum_reduce(A) # cuda sum reduction 20 | assert expect == got 21 | 22 | Lambda functions can also be used here:: 23 | 24 | sum_reduce = cuda.reduce(lambda a, b: a + b) 25 | 26 | The Reduce class 27 | ---------------- 28 | 29 | The ``reduce`` decorator creates an instance of the ``Reduce`` class. 30 | Currently, ``reduce`` is an alias to ``Reduce``, but this behavior is not 31 | guaranteed. 32 | 33 | .. autoclass:: numba.cuda.Reduce 34 | :members: __init__, __call__ 35 | :member-order: bysource 36 | -------------------------------------------------------------------------------- /docs/source/developer/event_api.rst: -------------------------------------------------------------------------------- 1 | Event API 2 | ========= 3 | 4 | .. automodule:: numba.core.event 5 | :members: -------------------------------------------------------------------------------- /docs/source/developer/index.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _developer-manual: 3 | 4 | Developer Manual 5 | ================ 6 | 7 | .. toctree:: 8 | :maxdepth: 2 9 | 10 | contributing.rst 11 | release.rst 12 | repomap.rst 13 | architecture.rst 14 | dispatching.rst 15 | generators.rst 16 | numba-runtime.rst 17 | rewrites.rst 18 | live_variable_analysis.rst 19 | listings.rst 20 | stencil.rst 21 | custom_pipeline.rst 22 | inlining.rst 23 | environment.rst 24 | hashing.rst 25 | sys_monitoring.rst 26 | caching.rst 27 | threading_implementation.rst 28 | literal.rst 29 | llvm_timings.rst 30 | debugging.rst 31 | event_api.rst 32 | target_extension.rst 33 | bytecode.rst 34 | mission.rst 35 | -------------------------------------------------------------------------------- /docs/source/developer/listings.rst: -------------------------------------------------------------------------------- 1 | Listings 2 | ======== 3 | 4 | This shows listings from compiler internal registries (e.g. lowering 5 | definitions). The information is provided as developer reference. 6 | When possible, links to source code are provided via github links. 7 | 8 | New style listings 9 | ------------------ 10 | 11 | The following listings are generated from ``numba.help.inspector.write_listings()``. Users can run ``python -m numba.help.inspector --format=rst `` to recreate the the documentation. 12 | 13 | .. toctree:: 14 | :maxdepth: 2 15 | 16 | autogen_builtins_listing.rst 17 | autogen_math_listing.rst 18 | autogen_cmath_listing.rst 19 | autogen_numpy_listing.rst 20 | 21 | 22 | Old style listings 23 | ------------------ 24 | 25 | .. toctree:: 26 | :maxdepth: 2 27 | 28 | autogen_lower_listing.rst 29 | 30 | -------------------------------------------------------------------------------- /docs/source/extending/index.rst: -------------------------------------------------------------------------------- 1 | 2 | Extending Numba 3 | =============== 4 | 5 | .. module:: numba.extending 6 | 7 | This chapter describes how to extend Numba to make it recognize and support 8 | additional operations, functions or types. Numba provides two categories 9 | of APIs to this end: 10 | 11 | * The high-level APIs provide abstracted entry points which are sufficient 12 | for simple uses. They require little knowledge of Numba's internal 13 | compilation chain. 14 | 15 | * The low-level APIs reflect Numba's internal compilation chain and allow 16 | flexible interaction with its various layers, but require more effort 17 | and experience with Numba internals. 18 | 19 | It may be helpful for readers of this chapter to also read some of the 20 | documents in the :doc:`developer manual <../developer/index>`, especially 21 | the :doc:`architecture document <../developer/architecture>`. 22 | 23 | 24 | .. toctree:: 25 | high-level.rst 26 | low-level.rst 27 | interval-example.rst 28 | overloading-guide.rst 29 | entrypoints.rst 30 | 31 | -------------------------------------------------------------------------------- /docs/source/extending/template.py: -------------------------------------------------------------------------------- 1 | # Declare that function `myfunc` is going to be overloaded (have a 2 | # substitutable Numba implementation) 3 | @overload(myfunc) 4 | # Define the overload function with formal arguments 5 | # these arguments must be matched in the inner function implementation 6 | def jit_myfunc(arg0, arg1, arg2, ...): 7 | # This scope is for typing, access is available to the *type* of all 8 | # arguments. This information can be used to change the behaviour of the 9 | # implementing function and check that the types are actually supported 10 | # by the implementation. 11 | 12 | print(arg0) # this will show the Numba type of arg0 13 | 14 | # This is the definition of the function that implements the `myfunc` work. 15 | # It does whatever algorithm is needed to implement myfunc. 16 | def myfunc_impl(arg0, arg1, arg2, ...): # match arguments to jit_myfunc 17 | # < Implementation goes here > 18 | return # whatever needs to be returned by the algorithm 19 | 20 | # return the implementation 21 | return myfunc_impl 22 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. Numba documentation master file, created by 2 | sphinx-quickstart on Tue Dec 30 11:55:40 2014. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Numba documentation 7 | =================== 8 | 9 | This is the Numba documentation. Unless you are already acquainted 10 | with Numba, we suggest you start with the :doc:`User manual `. 11 | 12 | 13 | .. toctree:: 14 | :caption: For all users 15 | :maxdepth: 2 16 | 17 | user/index.rst 18 | reference/index.rst 19 | 20 | 21 | .. toctree:: 22 | :caption: For CUDA users 23 | :maxdepth: 2 24 | 25 | cuda/index.rst 26 | cuda-reference/index.rst 27 | 28 | 29 | .. toctree:: 30 | :caption: For advanced users & developers 31 | :maxdepth: 2 32 | 33 | extending/index.rst 34 | developer/index.rst 35 | proposals/index.rst 36 | glossary.rst 37 | release-notes-overview.rst 38 | -------------------------------------------------------------------------------- /docs/source/proposals/index.rst: -------------------------------------------------------------------------------- 1 | =========================== 2 | Numba Enhancement Proposals 3 | =========================== 4 | 5 | Numba Enhancement Proposals (not really abbreviated "NEPs", since "NEP" 6 | is already taken by the Numpy project) describe proposed changes to Numba. 7 | They are modeled on Python Enhancement Proposals (PEPs) and Numpy Enhancement 8 | Proposals, and are typically written up when important changes 9 | (behavioural changes, feature additions...) to Numba are proposed. 10 | 11 | This page provides an overview of all proposals, making only a distinction 12 | between the ones that have been implemented and those that have not been 13 | implemented. 14 | 15 | Implemented proposals 16 | --------------------- 17 | 18 | .. toctree:: 19 | :maxdepth: 1 20 | 21 | integer-typing.rst 22 | external-memory-management.rst 23 | 24 | Other proposals 25 | --------------- 26 | 27 | .. toctree:: 28 | :maxdepth: 1 29 | 30 | extension-points.rst 31 | jit-classes.rst 32 | cfunc.rst 33 | type-inference.rst 34 | typing_recursion.rst 35 | 36 | -------------------------------------------------------------------------------- /docs/source/reference/index.rst: -------------------------------------------------------------------------------- 1 | 2 | Reference Manual 3 | ================ 4 | 5 | .. toctree:: 6 | 7 | types.rst 8 | jit-compilation.rst 9 | aot-compilation.rst 10 | utils.rst 11 | envvars.rst 12 | pysupported.rst 13 | numpysupported.rst 14 | pysemantics.rst 15 | fpsemantics.rst 16 | deprecation.rst 17 | -------------------------------------------------------------------------------- /docs/source/reference/utils.rst: -------------------------------------------------------------------------------- 1 | 2 | ========= 3 | Utilities 4 | ========= 5 | 6 | Dealing with pointers 7 | ===================== 8 | 9 | These functions can be called from pure Python as well as in 10 | :term:`nopython mode`. 11 | 12 | 13 | .. function:: numba.carray(ptr, shape, dtype=None) 14 | 15 | Return a Numpy array view over the data pointed to by *ptr* with the 16 | given *shape*, in C order. If *dtype* is given, it is used as the array's 17 | dtype, otherwise the array's dtype is inferred from *ptr*'s type. 18 | As the returned array is a view, not a copy, writing to it will modify 19 | the original data. 20 | 21 | *ptr* should be a ctypes pointer object (either a typed pointer 22 | as created using :func:`~ctypes.POINTER`, or a :class:`~ctypes.c_void_p`). 23 | 24 | *shape* should be an integer or a tuple of integers. 25 | 26 | *dtype* should be a Numpy dtype or scalar class (i.e. both 27 | ``np.dtype('int8')`` and ``np.int8`` are accepted). 28 | 29 | 30 | .. function:: numba.farray(ptr, shape, dtype=None) 31 | 32 | Same as :func:`~numba.carray`, but the data is assumed to be laid out 33 | in Fortran order, and the array view is constructed accordingly. 34 | 35 | -------------------------------------------------------------------------------- /docs/source/release-notes-overview.rst: -------------------------------------------------------------------------------- 1 | ====================== 2 | Release Notes 3 | ====================== 4 | 5 | Towncrier generated notes: 6 | -------------------------- 7 | 8 | .. toctree:: 9 | :maxdepth: 1 10 | :glob: 11 | :reversed: 12 | 13 | release/* 14 | 15 | Non-Towncrier generated notes: 16 | ------------------------------ 17 | 18 | .. toctree:: 19 | :maxdepth: 1 20 | 21 | release-notes.rst 22 | -------------------------------------------------------------------------------- /docs/source/release/0.58.1-notes.rst: -------------------------------------------------------------------------------- 1 | 2 | Version 0.58.1 (17 October 2023) 3 | ================================ 4 | 5 | This is a maintenance release that adds support for NumPy 1.26 and fixes a bug. 6 | 7 | NumPy Support 8 | ~~~~~~~~~~~~~ 9 | 10 | Support NumPy 1.26 11 | ------------------ 12 | 13 | Support for NumPy 1.26 is added. 14 | 15 | (`PR-#9227 `__) 16 | 17 | 18 | Bug Fixes 19 | ~~~~~~~~~ 20 | 21 | Fixed handling of float default arguments in inline closures 22 | ------------------------------------------------------------ 23 | 24 | Float default arguments in inline closures would produce incorrect results since 25 | updates for Python 3.11 - these are now handled correctly again. 26 | 27 | (`PR-#9222 `__) 28 | 29 | Pull-Requests 30 | ~~~~~~~~~~~~~ 31 | 32 | * PR `#9220 `_: Support passing arbitrary flags to NVVM (`gmarkall `_) 33 | * PR `#9227 `_: Support NumPy 1.26 (PR aimed at review / merge) (`Tialo `_ `gmarkall `_) 34 | * PR `#9228 `_: Fix #9222 - Don't replace `.` with `_` in func arg names in inline closures (`gmarkall `_) 35 | 36 | Authors 37 | ~~~~~~~ 38 | 39 | * `gmarkall `_ 40 | * `Tialo `_ 41 | -------------------------------------------------------------------------------- /docs/source/release/0.61.1-notes.rst: -------------------------------------------------------------------------------- 1 | 2 | Version 0.61.1 (NO RELEASE) 3 | =========================== 4 | 5 | The release was skipped due to issues during the release process. 6 | -------------------------------------------------------------------------------- /docs/source/user/code_coverage.rst: -------------------------------------------------------------------------------- 1 | =============================== 2 | Code Coverage for Compiled Code 3 | =============================== 4 | 5 | Numba, a just-in-time compiler for Python, transforms Python code into machine 6 | code for optimized execution. This process, however, poses a challenge for 7 | traditional code coverage tools, as they typically operate within the Python 8 | interpreter and thus miss the lines of code compiled by Numba. To address this 9 | issue, Numba opts for a compile-time notification to coverage tools, rather than 10 | during execution, to minimize performance penalties. This approach helps prevent 11 | significant coverage gaps in projects utilizing Numba, without incurring 12 | substantial performance costs. 13 | 14 | No additional effort is required to generate compile-time coverage data. By 15 | running a Numba application under the ``coverage`` tool 16 | (e.g. ``coverage run ...``), the compiler automatically 17 | detects the active coverage session and emits data accordingly. This mechanism 18 | ensures that coverage data is generated seamlessly, without the need for manual 19 | intervention. 20 | 21 | The coverage data is emitted during the lowering phase, which involves the 22 | generation of LLVM-IR. This phase inherently excludes lines of code that are 23 | statically identified as dead code, ensuring that the coverage data accurately 24 | reflects the executable code paths. 25 | -------------------------------------------------------------------------------- /docs/source/user/index.rst: -------------------------------------------------------------------------------- 1 | 2 | User Manual 3 | =========== 4 | 5 | .. toctree:: 6 | 7 | 5minguide.rst 8 | overview.rst 9 | installing.rst 10 | jit.rst 11 | vectorize.rst 12 | jitclass.rst 13 | cfunc.rst 14 | pycc.rst 15 | parallel.rst 16 | stencil.rst 17 | withobjmode.rst 18 | jit-module.rst 19 | performance-tips.rst 20 | threading-layer.rst 21 | cli.rst 22 | code_coverage.rst 23 | troubleshoot.rst 24 | faq.rst 25 | examples.rst 26 | talks.rst 27 | -------------------------------------------------------------------------------- /docs/source/user/overview.rst: -------------------------------------------------------------------------------- 1 | 2 | Overview 3 | ======== 4 | 5 | Numba is a compiler for Python array and numerical functions that gives 6 | you the power to speed up your applications with high performance 7 | functions written directly in Python. 8 | 9 | Numba generates optimized machine code from pure Python code using 10 | the `LLVM compiler infrastructure `_. With a few simple 11 | annotations, array-oriented and math-heavy Python code can be 12 | just-in-time optimized to performance similar as C, C++ and Fortran, without 13 | having to switch languages or Python interpreters. 14 | 15 | Numba's main features are: 16 | 17 | * :ref:`on-the-fly code generation ` (at import time or runtime, at the 18 | user's preference) 19 | * native code generation for the CPU (default) and 20 | :doc:`GPU hardware <../cuda/index>` 21 | * integration with the Python scientific software stack (thanks to Numpy) 22 | 23 | Here is how a Numba-optimized function, taking a Numpy array as argument, 24 | might look like:: 25 | 26 | @numba.jit 27 | def sum2d(arr): 28 | M, N = arr.shape 29 | result = 0.0 30 | for i in range(M): 31 | for j in range(N): 32 | result += arr[i,j] 33 | return result 34 | 35 | -------------------------------------------------------------------------------- /docs/source/user/withobjmode.rst: -------------------------------------------------------------------------------- 1 | ============================================================ 2 | Callback into the Python Interpreter from within JIT'ed code 3 | ============================================================ 4 | 5 | There are rare but real cases when a nopython-mode function needs to callback 6 | into the Python interpreter to invoke code that cannot be compiled by Numba. 7 | Such cases include: 8 | 9 | - logging progress for long running JIT'ed functions; 10 | - use data structures that are not currently supported by Numba; 11 | - debugging inside JIT'ed code using the Python debugger. 12 | 13 | When Numba callbacks into the Python interpreter, the following has to happen: 14 | 15 | - acquire the GIL; 16 | - convert values in native representation back into Python objects; 17 | - call-back into the Python interpreter; 18 | - convert returned values from the Python-code into native representation; 19 | - release the GIL. 20 | 21 | These steps can be expensive. Users **should not** rely on the feature 22 | described here on performance-critical paths. 23 | 24 | 25 | .. _with_objmode: 26 | 27 | The ``objmode`` context-manager 28 | =============================== 29 | 30 | .. warning:: This feature can be easily mis-used. Users should first consider 31 | alternative approaches to achieve their intended goal before using 32 | this feature. 33 | 34 | .. autofunction:: numba.objmode 35 | -------------------------------------------------------------------------------- /docs/upcoming_changes/10035.improvement.rst: -------------------------------------------------------------------------------- 1 | Improve Environment Object Support in PYCC 2 | ------------------------------------------ 3 | 4 | Added support for Environment objects referenced indirectly by entry points in 5 | PYCC-compiled code. Previously, PYCC was unable to handle these indirect 6 | Environment object references, which limited certain compilation scenarios. 7 | -------------------------------------------------------------------------------- /docs/upcoming_changes/10047.bug_fix.rst: -------------------------------------------------------------------------------- 1 | Fix ``IntEnumMember.can_convert_to()`` when no conversions found 2 | ---------------------------------------------------------------- 3 | 4 | A spurious ``TypeError`` that was raised when no conversion from an 5 | ``IntEnumMember`` was possible has now been fixed. 6 | -------------------------------------------------------------------------------- /docs/upcoming_changes/10052.bug_fix.rst: -------------------------------------------------------------------------------- 1 | Fix ``np.searchsorted`` with ``float32`` NaN values 2 | --------------------------------------------------- 3 | 4 | Fixes a bug in ``np.searchsorted`` where passing a ``float32`` array containing 5 | NaN values produces incorrect results. This issue occurs due to the use of an 6 | incorrect comparison function. 7 | -------------------------------------------------------------------------------- /docs/upcoming_changes/10079.improvement.rst: -------------------------------------------------------------------------------- 1 | Improve loop-lifting to support zip and enumerate 2 | ------------------------------------------------- 3 | 4 | Added support for ``zip()`` and ``enumerate()`` for loop-lifting. 5 | -------------------------------------------------------------------------------- /docs/upcoming_changes/9390.np_support.rst: -------------------------------------------------------------------------------- 1 | Added support for ``np.ndarray.tobytes`` method. 2 | ================================================ 3 | 4 | Support is added for the ``np.ndarray.tobytes`` method. -------------------------------------------------------------------------------- /docs/upcoming_changes/9676.improvement.rst: -------------------------------------------------------------------------------- 1 | Use the New Pass Manager 2 | ------------------------ 3 | 4 | LLVM's New Pass Manager is used for the optimization pipelines. The use of the 5 | Legacy Pass Manager, which is removed in later LLVM versions, is accessed by a 6 | configuration variable, `USE_LLVM_LEGACY_PASS_MANAGER`. 7 | -------------------------------------------------------------------------------- /docs/upcoming_changes/9861.improvement.rst: -------------------------------------------------------------------------------- 1 | Fall back to ``inspect.getsourcelines()`` in first line finder 2 | -------------------------------------------------------------- 3 | 4 | If the first line finder can't locate source code on disk, it now tries using 5 | ``inspect.getsourcelines()`` to get the source. This enables it to locate 6 | source for cells in Jupyter notebooks, so that line info for them can be 7 | generated for profiling tools. 8 | -------------------------------------------------------------------------------- /docs/upcoming_changes/9888.bug_fix.rst: -------------------------------------------------------------------------------- 1 | Avoid declaring ``if`` operation bools in debug info 2 | ---------------------------------------------------- 3 | 4 | Internal bool variables that hold the result of conditional tests in ``if`` 5 | operations are no longer declared, and therefore can't show up in the 6 | ``locals`` in GDB. 7 | -------------------------------------------------------------------------------- /docs/upcoming_changes/9892.improvement.rst: -------------------------------------------------------------------------------- 1 | [UX] TypedDict: better error message for KeyError #9892 2 | ------------------------------------------------------- 3 | 4 | The ``KeyError`` raised from ``__getitem__`` for the ``numba.typed.Dict`` in 5 | case of an non-existing key now reports the value of the key. This behaviour is 6 | in-line with the regular ``dict`` via CPython. 7 | 8 | -------------------------------------------------------------------------------- /docs/upcoming_changes/9893.bug_fix.rst: -------------------------------------------------------------------------------- 1 | [DUX] fix use of rstcheck in towncrier check script 2 | --------------------------------------------------- 3 | 4 | The script ``maint/towncrier_rst_validator.py`` now correctly reports any RST 5 | issues encountered when calling ``rstcheck`` via ``subprocess.chck_output``. 6 | This helps to improve the developer experience as any issues are reported 7 | directly and the developers no longer need to be confused and/or run a 8 | secondary tools 9 | -------------------------------------------------------------------------------- /docs/upcoming_changes/9916.improvement.rst: -------------------------------------------------------------------------------- 1 | Improve compilation time by more lazy strings. 2 | ---------------------------------------------- 3 | 4 | Make additional large strings be generated lazily so that you don't 5 | pay the cost unless you actually use them. 6 | -------------------------------------------------------------------------------- /docs/upcoming_changes/9973.bug_fix.rst: -------------------------------------------------------------------------------- 1 | Prevent unsafe type conversion in arguments to ``range``. 2 | --------------------------------------------------------- 3 | 4 | Types that require an unsafe type conversion to ``integer`` (such as ``float``) 5 | are now not permitted as arguments to ``range``. 6 | -------------------------------------------------------------------------------- /docs/upcoming_changes/template.rst: -------------------------------------------------------------------------------- 1 | {% set title = "Version {} (Release Date)".format(versiondata.version) %} 2 | 3 | {{ title }} 4 | {{ "=" * title|length }} 5 | 6 | {% for section, _ in sections.items() %} 7 | {% if section %}{{ section }} 8 | {{ "~" * section|length }} 9 | 10 | {% endif %} 11 | {% if sections[section] %} 12 | {% for category, val in definitions.items() if category in sections[section] %} 13 | 14 | {{ definitions[category]['name'] }} 15 | {{ "~" * definitions[category]['name']|length }} 16 | 17 | {% if definitions[category]['showcontent'] %} 18 | {% for text, values in sections[section][category].items() %} 19 | {{ text }} 20 | 21 | {{ get_indent(text) }}({{values|join(', ') }}) 22 | 23 | {% endfor %} 24 | {% else %} 25 | - {{ sections[section][category]['']|join(', ') }} 26 | 27 | {% endif %} 28 | {% if sections[section][category]|length == 0 %} 29 | No significant changes. 30 | 31 | {% else %} 32 | {% endif %} 33 | {% endfor %} 34 | {% else %} 35 | No significant changes. 36 | 37 | 38 | {% endif %} 39 | {% endfor %} -------------------------------------------------------------------------------- /numba/__main__.py: -------------------------------------------------------------------------------- 1 | """Expose Numba command via ``python -m numba``.""" 2 | import sys 3 | from numba.misc.numba_entry import main 4 | 5 | if __name__ == '__main__': 6 | sys.exit(main()) 7 | -------------------------------------------------------------------------------- /numba/_arraystruct.h: -------------------------------------------------------------------------------- 1 | #ifndef NUMBA_ARYSTRUCT_H_ 2 | #define NUMBA_ARYSTRUCT_H_ 3 | /* 4 | * Fill in the *arystruct* with information from the Numpy array *obj*. 5 | * *arystruct*'s layout is defined in numba.targets.arrayobj (look 6 | * for the ArrayTemplate class). 7 | */ 8 | 9 | typedef struct { 10 | void *meminfo; /* see _nrt_python.c and nrt.h in numba/core/runtime */ 11 | PyObject *parent; 12 | npy_intp nitems; 13 | npy_intp itemsize; 14 | void *data; 15 | 16 | npy_intp shape_and_strides[]; 17 | } arystruct_t; 18 | 19 | 20 | #endif /* NUMBA_ARYSTRUCT_H_ */ 21 | 22 | -------------------------------------------------------------------------------- /numba/_devicearray.h: -------------------------------------------------------------------------------- 1 | #ifndef NUMBA_DEVICEARRAY_H_ 2 | #define NUMBA_DEVICEARRAY_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* These definitions should only be used by consumers of the Device Array API. 9 | * Consumers access the API through the opaque pointer stored in 10 | * _devicearray._DEVICEARRAY_API. We don't want these definitions in 11 | * _devicearray.cpp itself because they would conflict with the actual 12 | * implementations there. 13 | */ 14 | #ifndef NUMBA_IN_DEVICEARRAY_CPP_ 15 | 16 | extern void **DeviceArray_API; 17 | #define DeviceArrayType (*(PyTypeObject*)DeviceArray_API[0]) 18 | 19 | #endif /* ndef NUMBA_IN_DEVICEARRAY_CPP */ 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif /* NUMBA_DEVICEARRAY_H_ */ 26 | -------------------------------------------------------------------------------- /numba/_helperlib.pyi: -------------------------------------------------------------------------------- 1 | def _import_cython_function(module_name: str, function_name: str): 2 | ... 3 | -------------------------------------------------------------------------------- /numba/_pymodule.h: -------------------------------------------------------------------------------- 1 | #ifndef NUMBA_PY_MODULE_H_ 2 | #define NUMBA_PY_MODULE_H_ 3 | 4 | #define PY_SSIZE_T_CLEAN 5 | 6 | #include "Python.h" 7 | #include "structmember.h" 8 | #include "frameobject.h" 9 | 10 | #define MOD_ERROR_VAL NULL 11 | #define MOD_SUCCESS_VAL(val) val 12 | #define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) 13 | #define MOD_DEF(ob, name, doc, methods) { \ 14 | static struct PyModuleDef moduledef = { \ 15 | PyModuleDef_HEAD_INIT, name, doc, -1, methods, NULL, NULL, NULL, NULL }; \ 16 | ob = PyModule_Create(&moduledef); } 17 | #define MOD_INIT_EXEC(name) PyInit_##name(); 18 | 19 | #define PyString_AsString PyUnicode_AsUTF8 20 | #define PyString_Check PyUnicode_Check 21 | #define PyString_FromFormat PyUnicode_FromFormat 22 | #define PyString_FromString PyUnicode_FromString 23 | #define PyString_InternFromString PyUnicode_InternFromString 24 | #define PyInt_Type PyLong_Type 25 | #define PyInt_Check PyLong_Check 26 | #define PyInt_CheckExact PyLong_CheckExact 27 | #define SetAttrStringFromVoidPointer(m, name) do { \ 28 | PyObject *tmp = PyLong_FromVoidPtr((void *) &name); \ 29 | PyObject_SetAttrString(m, #name, tmp); \ 30 | Py_DECREF(tmp); } while (0) 31 | 32 | 33 | #define NB_SUPPORTED_PYTHON_MINOR ((PY_MINOR_VERSION == 10) || (PY_MINOR_VERSION == 11) || (PY_MINOR_VERSION == 12) || (PY_MINOR_VERSION == 13)) 34 | 35 | #endif /* NUMBA_PY_MODULE_H_ */ 36 | -------------------------------------------------------------------------------- /numba/_typeof.h: -------------------------------------------------------------------------------- 1 | #ifndef NUMBA_TYPEOF_H_ 2 | #define NUMBA_TYPEOF_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern PyObject *typeof_init(PyObject *self, PyObject *args); 9 | extern int typeof_typecode(PyObject *dispatcher, PyObject *val); 10 | extern PyObject *typeof_compute_fingerprint(PyObject *val); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif /* NUMBA_TYPEOF_H_ */ 17 | -------------------------------------------------------------------------------- /numba/cext/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utilities for getting information about Numba C extensions 3 | """ 4 | 5 | import os 6 | 7 | 8 | def get_extension_libs(): 9 | """Return the .c files in the `numba.cext` directory. 10 | """ 11 | libs = [] 12 | base = get_path() 13 | for fn in os.listdir(base): 14 | if fn.endswith('.c'): 15 | fn = os.path.join(base, fn) 16 | libs.append(fn) 17 | return libs 18 | 19 | 20 | def get_path(): 21 | """Returns the path to the directory for `numba.cext`. 22 | """ 23 | return os.path.abspath(os.path.join(os.path.dirname(__file__))) 24 | -------------------------------------------------------------------------------- /numba/cext/cext.h: -------------------------------------------------------------------------------- 1 | #ifndef NUMBA_EXTENSION_HELPER_H_ 2 | #define NUMBA_EXTENSION_HELPER_H_ 3 | 4 | #include "Python.h" 5 | #include "../_numba_common.h" 6 | 7 | /* Define all runtime-required symbols in this C module, but do not 8 | export them outside the shared library if possible. */ 9 | #define NUMBA_EXPORT_FUNC(_rettype) VISIBILITY_HIDDEN _rettype 10 | #define NUMBA_EXPORT_DATA(_vartype) VISIBILITY_HIDDEN _vartype 11 | 12 | /* Use to declare a symbol as exported (global). */ 13 | #define NUMBA_GLOBAL_FUNC(_rettype) VISIBILITY_GLOBAL _rettype 14 | 15 | NUMBA_EXPORT_FUNC(Py_ssize_t) 16 | aligned_size(Py_ssize_t sz); 17 | 18 | #include "dictobject.h" 19 | #include "listobject.h" 20 | 21 | #endif // end NUMBA_EXTENSION_HELPER_H_ 22 | -------------------------------------------------------------------------------- /numba/cext/utils.c: -------------------------------------------------------------------------------- 1 | #include "cext.h" 2 | 3 | /* Align size *sz* to pointer width */ 4 | Py_ssize_t 5 | aligned_size(Py_ssize_t sz) { 6 | Py_ssize_t alignment = sizeof(void*); 7 | return sz + (alignment - sz % alignment) % alignment; 8 | } 9 | -------------------------------------------------------------------------------- /numba/cloudpickle/__init__.py: -------------------------------------------------------------------------------- 1 | from . import cloudpickle 2 | from .cloudpickle import * # noqa 3 | 4 | __doc__ = cloudpickle.__doc__ 5 | 6 | __version__ = "3.0.0" 7 | 8 | __all__ = [ # noqa 9 | "__version__", 10 | "Pickler", 11 | "CloudPickler", 12 | "dumps", 13 | "loads", 14 | "dump", 15 | "load", 16 | "register_pickle_by_value", 17 | "unregister_pickle_by_value", 18 | ] 19 | -------------------------------------------------------------------------------- /numba/cloudpickle/cloudpickle_fast.py: -------------------------------------------------------------------------------- 1 | """Compatibility module. 2 | 3 | It can be necessary to load files generated by previous versions of cloudpickle 4 | that rely on symbols being defined under the `cloudpickle.cloudpickle_fast` 5 | namespace. 6 | 7 | See: tests/test_backward_compat.py 8 | """ 9 | from . import cloudpickle 10 | 11 | 12 | def __getattr__(name): 13 | return getattr(cloudpickle, name) 14 | -------------------------------------------------------------------------------- /numba/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/core/__init__.py -------------------------------------------------------------------------------- /numba/core/annotations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/core/annotations/__init__.py -------------------------------------------------------------------------------- /numba/core/boxing.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: 6 | sys.modules[__name__] = _RedirectSubpackage(locals(), 7 | "numba.core.old_boxing") 8 | else: 9 | sys.modules[__name__] = _RedirectSubpackage(locals(), 10 | "numba.core.new_boxing") 11 | -------------------------------------------------------------------------------- /numba/core/datamodel/__init__.py: -------------------------------------------------------------------------------- 1 | from .manager import DataModelManager 2 | from .packer import ArgPacker, DataPacker 3 | from .registry import register_default, default_manager, register 4 | from .models import PrimitiveModel, CompositeModel, StructModel # type: ignore 5 | -------------------------------------------------------------------------------- /numba/core/datamodel/models.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: # type: ignore 6 | sys.modules[__name__] = _RedirectSubpackage( 7 | locals(), "numba.core.datamodel.old_models" 8 | ) 9 | else: 10 | sys.modules[__name__] = _RedirectSubpackage( 11 | locals(), "numba.core.datamodel.new_models" 12 | ) 13 | -------------------------------------------------------------------------------- /numba/core/datamodel/registry.py: -------------------------------------------------------------------------------- 1 | import functools 2 | from .manager import DataModelManager 3 | 4 | 5 | def register(dmm, typecls): 6 | """Used as decorator to simplify datamodel registration. 7 | Returns the object being decorated so that chaining is possible. 8 | """ 9 | def wraps(fn): 10 | dmm.register(typecls, fn) 11 | return fn 12 | 13 | return wraps 14 | 15 | 16 | default_manager = DataModelManager() 17 | 18 | register_default = functools.partial(register, default_manager) 19 | -------------------------------------------------------------------------------- /numba/core/descriptors.py: -------------------------------------------------------------------------------- 1 | """ 2 | Target Descriptors 3 | """ 4 | 5 | from abc import ABCMeta, abstractmethod 6 | 7 | 8 | class TargetDescriptor(metaclass=ABCMeta): 9 | 10 | def __init__(self, target_name): 11 | self._target_name = target_name 12 | 13 | @property 14 | @abstractmethod 15 | def typing_context(self): 16 | ... 17 | 18 | @property 19 | @abstractmethod 20 | def target_context(self): 21 | ... 22 | -------------------------------------------------------------------------------- /numba/core/fastmathpass.py: -------------------------------------------------------------------------------- 1 | from llvmlite import ir 2 | from llvmlite.ir.transforms import Visitor, CallVisitor 3 | 4 | 5 | class FastFloatBinOpVisitor(Visitor): 6 | """ 7 | A pass to add fastmath flag to float-binop instruction if they don't have 8 | any flags. 9 | """ 10 | float_binops = frozenset(['fadd', 'fsub', 'fmul', 'fdiv', 'frem', 'fcmp']) 11 | 12 | def __init__(self, flags): 13 | self.flags = flags 14 | 15 | def visit_Instruction(self, instr): 16 | if instr.opname in self.float_binops: 17 | if not instr.flags: 18 | for flag in self.flags: 19 | instr.flags.append(flag) 20 | 21 | 22 | class FastFloatCallVisitor(CallVisitor): 23 | """ 24 | A pass to change all float function calls to use fastmath. 25 | """ 26 | 27 | def __init__(self, flags): 28 | self.flags = flags 29 | 30 | def visit_Call(self, instr): 31 | # Add to any call that has float/double return type 32 | if instr.type in (ir.FloatType(), ir.DoubleType()): 33 | for flag in self.flags: 34 | instr.fastmath.add(flag) 35 | 36 | 37 | def rewrite_module(mod, options): 38 | """ 39 | Rewrite the given LLVM module to use fastmath everywhere. 40 | """ 41 | flags = options.flags 42 | FastFloatBinOpVisitor(flags).visit(mod) 43 | FastFloatCallVisitor(flags).visit(mod) 44 | 45 | -------------------------------------------------------------------------------- /numba/core/rewrites/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | A subpackage hosting Numba IR rewrite passes. 3 | """ 4 | 5 | from .registry import register_rewrite, rewrite_registry, Rewrite 6 | # Register various built-in rewrite passes 7 | from numba.core.rewrites import (static_getitem, static_raise, static_binop, 8 | ir_print) 9 | -------------------------------------------------------------------------------- /numba/core/rewrites/static_binop.py: -------------------------------------------------------------------------------- 1 | from numba.core import errors, ir 2 | from numba.core.rewrites import register_rewrite, Rewrite 3 | 4 | 5 | @register_rewrite('before-inference') 6 | class DetectStaticBinops(Rewrite): 7 | """ 8 | Detect constant arguments to select binops. 9 | """ 10 | 11 | # Those operators can benefit from a constant-inferred argument 12 | rhs_operators = {'**'} 13 | 14 | def match(self, func_ir, block, typemap, calltypes): 15 | self.static_lhs = {} 16 | self.static_rhs = {} 17 | self.block = block 18 | # Find binop expressions with a constant lhs or rhs 19 | for expr in block.find_exprs(op='binop'): 20 | try: 21 | if (expr.fn in self.rhs_operators 22 | and expr.static_rhs is ir.UNDEFINED): 23 | self.static_rhs[expr] = func_ir.infer_constant(expr.rhs) 24 | except errors.ConstantInferenceError: 25 | continue 26 | 27 | return len(self.static_lhs) > 0 or len(self.static_rhs) > 0 28 | 29 | def apply(self): 30 | """ 31 | Store constant arguments that were detected in match(). 32 | """ 33 | for expr, rhs in self.static_rhs.items(): 34 | expr.static_rhs = rhs 35 | return self.block 36 | -------------------------------------------------------------------------------- /numba/core/runtime/__init__.py: -------------------------------------------------------------------------------- 1 | from .nrt import rtsys 2 | -------------------------------------------------------------------------------- /numba/core/typeconv/__init__.py: -------------------------------------------------------------------------------- 1 | from .castgraph import Conversion 2 | -------------------------------------------------------------------------------- /numba/core/typeconv/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "typeconv.hpp" 3 | 4 | using std::cout; 5 | const char EOL = '\n'; 6 | 7 | int main() { 8 | TypeManager tm; 9 | Type t_int32 = tm.get("int32"); 10 | Type t_float = tm.get("float"); 11 | Type t_int64 = tm.get("int64"); 12 | 13 | tm.addConversion(t_int32, t_float); 14 | tm.addConversion(t_float, t_int32); 15 | tm.addConversion(t_float, t_int64); 16 | tm.addPromotion(t_int32, t_int64); 17 | 18 | cout << "int32 -> float " 19 | << TCCString(tm.isCompatible(tm.get("int32"), tm.get("float"))) 20 | << EOL; 21 | cout << "int32 -> int64 " 22 | << TCCString(tm.isCompatible(tm.get("int32"), tm.get("int64"))) 23 | << EOL; 24 | 25 | Type sig[] = {t_int32, t_float}; 26 | Type ovsigs[] = { 27 | t_float, t_float, 28 | t_int64, t_int64, 29 | t_int32, t_float, 30 | }; 31 | 32 | int sel = tm.selectOverload(sig, ovsigs, 2, 3); 33 | 34 | cout << "Selected " << sel << '\n'; 35 | 36 | 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /numba/core/types/new_scalars/__init__.py: -------------------------------------------------------------------------------- 1 | from numba.core.types.new_scalars.scalars import ( 2 | Integer, IntegerLiteral, Boolean, BooleanLiteral, Float, Complex, 3 | parse_integer_bitwidth, parse_integer_signed, 4 | _NPDatetimeBase, NPTimedelta, NPDatetime, EnumClass, IntEnumClass, 5 | EnumMember, IntEnumMember 6 | ) 7 | from numba.core.types.new_scalars.python_types import ( 8 | PythonBoolean, PythonInteger, PythonFloat, PythonComplex, 9 | PythonBooleanLiteral, PythonIntegerLiteral 10 | ) 11 | from numba.core.types.new_scalars.machine_types import ( 12 | MachineBoolean, MachineInteger, MachineFloat, MachineComplex, 13 | MachineBooleanLiteral, MachineIntegerLiteral 14 | ) 15 | from numba.core.types.new_scalars.numpy_types import ( 16 | NumPyBoolean, NumPyInteger, NumPyFloat, NumPyComplex, 17 | NumPyBooleanLiteral, NumPyIntegerLiteral 18 | ) 19 | -------------------------------------------------------------------------------- /numba/core/types/scalars.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: # type: ignore 6 | sys.modules[__name__] = _RedirectSubpackage( 7 | locals(), "numba.core.types.old_scalars" 8 | ) 9 | else: 10 | sys.modules[__name__] = _RedirectSubpackage( 11 | locals(), "numba.core.types.new_scalars" 12 | ) 13 | -------------------------------------------------------------------------------- /numba/core/typing/__init__.py: -------------------------------------------------------------------------------- 1 | from .context import BaseContext, Context 2 | from .templates import (signature, make_concrete_template, Signature, 3 | fold_arguments) 4 | -------------------------------------------------------------------------------- /numba/core/typing/builtins.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: 6 | sys.modules[__name__] = _RedirectSubpackage( 7 | locals(), 8 | "numba.core.typing.old_builtins" 9 | ) 10 | else: 11 | sys.modules[__name__] = _RedirectSubpackage( 12 | locals(), 13 | "numba.core.typing.new_builtins" 14 | ) 15 | -------------------------------------------------------------------------------- /numba/core/typing/cmathdecl.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: 6 | sys.modules[__name__] = _RedirectSubpackage( 7 | locals(), 8 | "numba.core.typing.old_cmathdecl" 9 | ) 10 | else: 11 | sys.modules[__name__] = _RedirectSubpackage( 12 | locals(), 13 | "numba.core.typing.new_cmathdecl" 14 | ) 15 | -------------------------------------------------------------------------------- /numba/core/typing/mathdecl.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: 6 | sys.modules[__name__] = _RedirectSubpackage( 7 | locals(), 8 | "numba.core.typing.old_mathdecl" 9 | ) 10 | else: 11 | sys.modules[__name__] = _RedirectSubpackage( 12 | locals(), 13 | "numba.core.typing.new_mathdecl" 14 | ) 15 | -------------------------------------------------------------------------------- /numba/core/typing/new_cmathdecl.py: -------------------------------------------------------------------------------- 1 | import cmath 2 | 3 | from numba.core import types, utils 4 | from numba.core.typing.templates import (AbstractTemplate, ConcreteTemplate, 5 | signature, Registry) 6 | 7 | registry = Registry() 8 | infer_global = registry.register_global 9 | 10 | # TODO: support non-complex arguments (floats and ints) 11 | 12 | # TODO: New Type System 13 | # These functions are part of the Python standard library 14 | # and (without checking) probably accept anything which 15 | # is "number"-like i.e. has a __float__, __int__, or 16 | # __index__ 17 | # This needs fixing in the new type system 18 | 19 | 20 | @infer_global(cmath.acos) 21 | @infer_global(cmath.asin) 22 | @infer_global(cmath.asinh) 23 | @infer_global(cmath.atan) 24 | @infer_global(cmath.atanh) 25 | @infer_global(cmath.cos) 26 | @infer_global(cmath.exp) 27 | @infer_global(cmath.sin) 28 | @infer_global(cmath.sqrt) 29 | @infer_global(cmath.tan) 30 | class CMath_unary(ConcreteTemplate): 31 | cases = [] 32 | 33 | 34 | @infer_global(cmath.isinf) 35 | @infer_global(cmath.isnan) 36 | class CMath_predicate(ConcreteTemplate): 37 | cases = [] 38 | 39 | 40 | @infer_global(cmath.isfinite) 41 | class CMath_isfinite(CMath_predicate): 42 | pass 43 | 44 | 45 | @infer_global(cmath.log) 46 | class Cmath_log(ConcreteTemplate): 47 | # unary cmath.log() 48 | cases = [] 49 | # binary cmath.log() 50 | cases += [] 51 | -------------------------------------------------------------------------------- /numba/core/typing/old_cmathdecl.py: -------------------------------------------------------------------------------- 1 | import cmath 2 | 3 | from numba.core import types, utils 4 | from numba.core.typing.templates import (AbstractTemplate, ConcreteTemplate, 5 | signature, Registry) 6 | 7 | registry = Registry() 8 | infer_global = registry.register_global 9 | 10 | # TODO: support non-complex arguments (floats and ints) 11 | 12 | 13 | @infer_global(cmath.acos) 14 | @infer_global(cmath.asin) 15 | @infer_global(cmath.asinh) 16 | @infer_global(cmath.atan) 17 | @infer_global(cmath.atanh) 18 | @infer_global(cmath.cos) 19 | @infer_global(cmath.exp) 20 | @infer_global(cmath.sin) 21 | @infer_global(cmath.sqrt) 22 | @infer_global(cmath.tan) 23 | class CMath_unary(ConcreteTemplate): 24 | cases = [signature(tp, tp) for tp in sorted(types.complex_domain)] 25 | 26 | 27 | @infer_global(cmath.isinf) 28 | @infer_global(cmath.isnan) 29 | class CMath_predicate(ConcreteTemplate): 30 | cases = [signature(types.boolean, tp) for tp in 31 | sorted(types.complex_domain)] 32 | 33 | 34 | @infer_global(cmath.isfinite) 35 | class CMath_isfinite(CMath_predicate): 36 | pass 37 | 38 | 39 | @infer_global(cmath.log) 40 | class Cmath_log(ConcreteTemplate): 41 | # unary cmath.log() 42 | cases = [signature(tp, tp) for tp in sorted(types.complex_domain)] 43 | # binary cmath.log() 44 | cases += [signature(tp, tp, tp) for tp in sorted(types.complex_domain)] 45 | -------------------------------------------------------------------------------- /numba/core/unsafe/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/core/unsafe/__init__.py -------------------------------------------------------------------------------- /numba/core/unsafe/nrt.py: -------------------------------------------------------------------------------- 1 | """ 2 | Contains unsafe intrinsic that calls NRT C API 3 | """ 4 | 5 | from numba.core import types 6 | from numba.core.typing import signature 7 | from numba.core.extending import intrinsic 8 | 9 | 10 | @intrinsic 11 | def NRT_get_api(tyctx): 12 | """NRT_get_api() 13 | 14 | Calls NRT_get_api() from the NRT C API 15 | Returns LLVM Type i8* (void pointer) 16 | """ 17 | def codegen(cgctx, builder, sig, args): 18 | return cgctx.nrt.get_nrt_api(builder) 19 | sig = signature(types.voidptr) 20 | return sig, codegen 21 | -------------------------------------------------------------------------------- /numba/cpython/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/cpython/__init__.py -------------------------------------------------------------------------------- /numba/cpython/builtins.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: 6 | sys.modules[__name__] = _RedirectSubpackage(locals(), 7 | "numba.cpython.old_builtins") 8 | else: 9 | sys.modules[__name__] = _RedirectSubpackage(locals(), 10 | "numba.cpython.new_builtins") 11 | -------------------------------------------------------------------------------- /numba/cpython/hashing.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: 6 | sys.modules[__name__] = _RedirectSubpackage(locals(), 7 | "numba.cpython.old_hashing") 8 | else: 9 | sys.modules[__name__] = _RedirectSubpackage(locals(), 10 | "numba.cpython.new_hashing") 11 | -------------------------------------------------------------------------------- /numba/cpython/mathimpl.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: 6 | sys.modules[__name__] = _RedirectSubpackage(locals(), 7 | "numba.cpython.old_mathimpl") 8 | else: 9 | sys.modules[__name__] = _RedirectSubpackage(locals(), 10 | "numba.cpython.new_mathimpl") 11 | -------------------------------------------------------------------------------- /numba/cpython/numbers.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: 6 | sys.modules[__name__] = _RedirectSubpackage(locals(), 7 | "numba.cpython.old_numbers") 8 | else: 9 | sys.modules[__name__] = _RedirectSubpackage(locals(), 10 | "numba.cpython.new_numbers") 11 | -------------------------------------------------------------------------------- /numba/cpython/tupleobj.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: 6 | sys.modules[__name__] = _RedirectSubpackage(locals(), 7 | "numba.cpython.old_tupleobj") 8 | else: 9 | sys.modules[__name__] = _RedirectSubpackage(locals(), 10 | "numba.cpython.new_tupleobj") 11 | -------------------------------------------------------------------------------- /numba/cpython/unsafe/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/cpython/unsafe/__init__.py -------------------------------------------------------------------------------- /numba/cuda/__init__.py: -------------------------------------------------------------------------------- 1 | from numba import runtests 2 | from numba.core import config 3 | 4 | if config.ENABLE_CUDASIM: 5 | from .simulator_init import * 6 | else: 7 | from .device_init import * 8 | from .device_init import _auto_device 9 | 10 | from numba.cuda.compiler import (compile, compile_for_current_device, 11 | compile_ptx, compile_ptx_for_current_device) 12 | 13 | # Are we the numba.cuda built in to upstream Numba, or the out-of-tree 14 | # NVIDIA-maintained target? 15 | implementation = "Built-in" 16 | 17 | 18 | def test(*args, **kwargs): 19 | if not is_available(): 20 | raise cuda_error() 21 | 22 | return runtests.main("numba.cuda.tests", *args, **kwargs) 23 | -------------------------------------------------------------------------------- /numba/cuda/api_util.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | 4 | def prepare_shape_strides_dtype(shape, strides, dtype, order): 5 | dtype = np.dtype(dtype) 6 | if isinstance(shape, int): 7 | shape = (shape,) 8 | if isinstance(strides, int): 9 | strides = (strides,) 10 | else: 11 | strides = strides or _fill_stride_by_order(shape, dtype, order) 12 | return shape, strides, dtype 13 | 14 | 15 | def _fill_stride_by_order(shape, dtype, order): 16 | nd = len(shape) 17 | if nd == 0: 18 | return () 19 | strides = [0] * nd 20 | if order == 'C': 21 | strides[-1] = dtype.itemsize 22 | for d in reversed(range(nd - 1)): 23 | strides[d] = strides[d + 1] * shape[d + 1] 24 | elif order == 'F': 25 | strides[0] = dtype.itemsize 26 | for d in range(1, nd): 27 | strides[d] = strides[d - 1] * shape[d - 1] 28 | else: 29 | raise ValueError('must be either C/F order') 30 | return tuple(strides) 31 | -------------------------------------------------------------------------------- /numba/cuda/cpp_function_wrappers.cu: -------------------------------------------------------------------------------- 1 | #include "cuda_fp16.h" 2 | 3 | #define FNDEF(fname) __numba_wrapper_ ## fname 4 | 5 | #define UNARY_FUNCTION(fname) extern "C" __device__ int\ 6 | FNDEF(fname)( \ 7 | short* return_value,\ 8 | short x\ 9 | )\ 10 | {\ 11 | __half retval = fname(__short_as_half (x));\ 12 | \ 13 | *return_value = __half_as_short (retval);\ 14 | /* Signal that no Python exception occurred */ \ 15 | return 0;\ 16 | }\ 17 | 18 | extern "C" __device__ int 19 | FNDEF(hdiv)( 20 | short* return_value, 21 | short x, 22 | short y 23 | ) 24 | { 25 | __half retval = __hdiv(__short_as_half (x), __short_as_half (y)); 26 | 27 | *return_value = __half_as_short (retval); 28 | // Signal that no Python exception occurred 29 | return 0; 30 | } 31 | 32 | UNARY_FUNCTION(hsin) 33 | UNARY_FUNCTION(hcos) 34 | UNARY_FUNCTION(hlog) 35 | UNARY_FUNCTION(hlog10) 36 | UNARY_FUNCTION(hlog2) 37 | UNARY_FUNCTION(hexp) 38 | UNARY_FUNCTION(hexp10) 39 | UNARY_FUNCTION(hexp2) 40 | UNARY_FUNCTION(hsqrt) 41 | UNARY_FUNCTION(hrsqrt) 42 | UNARY_FUNCTION(hfloor) 43 | UNARY_FUNCTION(hceil) 44 | UNARY_FUNCTION(hrcp) 45 | UNARY_FUNCTION(hrint) 46 | UNARY_FUNCTION(htrunc) 47 | 48 | -------------------------------------------------------------------------------- /numba/cuda/cudadrv/__init__.py: -------------------------------------------------------------------------------- 1 | """CUDA Driver 2 | 3 | - Driver API binding 4 | - NVVM API binding 5 | - Device array implementation 6 | 7 | """ 8 | from numba.core import config 9 | assert not config.ENABLE_CUDASIM, 'Cannot use real driver API with simulator' 10 | -------------------------------------------------------------------------------- /numba/cuda/cudadrv/_extras.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Helper binding to call some CUDA Runtime API that cannot be directly 3 | * encoded using ctypes. 4 | */ 5 | 6 | #include "_pymodule.h" 7 | 8 | 9 | #define CUDA_IPC_HANDLE_SIZE 64 10 | 11 | typedef int CUresult; 12 | typedef void* CUdeviceptr; 13 | 14 | typedef struct CUipcMemHandle_st{ 15 | char reserved[CUDA_IPC_HANDLE_SIZE]; 16 | } CUipcMemHandle; 17 | 18 | typedef CUresult (*cuIpcOpenMemHandle_t)(CUdeviceptr* pdptr, CUipcMemHandle handle, unsigned int flags ); 19 | 20 | static 21 | cuIpcOpenMemHandle_t cuIpcOpenMemHandle = 0; 22 | 23 | static 24 | void set_cuIpcOpenMemHandle(void* fnptr) 25 | { 26 | cuIpcOpenMemHandle = (cuIpcOpenMemHandle_t)fnptr; 27 | } 28 | 29 | static 30 | CUresult call_cuIpcOpenMemHandle(CUdeviceptr* pdptr, CUipcMemHandle* handle, unsigned int flags) 31 | { 32 | return cuIpcOpenMemHandle(pdptr, *handle, flags); 33 | } 34 | 35 | 36 | MOD_INIT(_extras) { 37 | PyObject *m; 38 | MOD_DEF(m, "_extras", "No docs", NULL) 39 | if (m == NULL) 40 | return MOD_ERROR_VAL; 41 | PyModule_AddObject(m, "set_cuIpcOpenMemHandle", PyLong_FromVoidPtr(&set_cuIpcOpenMemHandle)); 42 | PyModule_AddObject(m, "call_cuIpcOpenMemHandle", PyLong_FromVoidPtr(&call_cuIpcOpenMemHandle)); 43 | PyModule_AddIntConstant(m, "CUDA_IPC_HANDLE_SIZE", CUDA_IPC_HANDLE_SIZE); 44 | return MOD_SUCCESS_VAL(m); 45 | } 46 | -------------------------------------------------------------------------------- /numba/cuda/cudadrv/error.py: -------------------------------------------------------------------------------- 1 | class CudaDriverError(Exception): 2 | pass 3 | 4 | 5 | class CudaRuntimeError(Exception): 6 | pass 7 | 8 | 9 | class CudaSupportError(ImportError): 10 | pass 11 | 12 | 13 | class NvvmError(Exception): 14 | def __str__(self): 15 | return '\n'.join(map(str, self.args)) 16 | 17 | 18 | class NvvmSupportError(ImportError): 19 | pass 20 | 21 | 22 | class NvvmWarning(Warning): 23 | pass 24 | 25 | 26 | class NvrtcError(Exception): 27 | def __str__(self): 28 | return '\n'.join(map(str, self.args)) 29 | 30 | 31 | class NvrtcCompilationError(NvrtcError): 32 | pass 33 | 34 | 35 | class NvrtcSupportError(ImportError): 36 | pass 37 | -------------------------------------------------------------------------------- /numba/cuda/cudadrv/ndarray.py: -------------------------------------------------------------------------------- 1 | from numba.cuda.cudadrv import devices, driver 2 | from numba.core.registry import cpu_target 3 | 4 | 5 | def _calc_array_sizeof(ndim): 6 | """ 7 | Use the ABI size in the CPU target 8 | """ 9 | ctx = cpu_target.target_context 10 | return ctx.calc_array_sizeof(ndim) 11 | 12 | 13 | def ndarray_device_allocate_data(ary): 14 | """ 15 | Allocate gpu data buffer 16 | """ 17 | datasize = driver.host_memory_size(ary) 18 | # allocate 19 | gpu_data = devices.get_context().memalloc(datasize) 20 | return gpu_data 21 | -------------------------------------------------------------------------------- /numba/cuda/cudadrv/rtapi.py: -------------------------------------------------------------------------------- 1 | """ 2 | Declarations of the Runtime API functions. 3 | """ 4 | 5 | from ctypes import c_int, POINTER 6 | 7 | API_PROTOTYPES = { 8 | # cudaError_t cudaRuntimeGetVersion ( int* runtimeVersion ) 9 | 'cudaRuntimeGetVersion': (c_int, POINTER(c_int)), 10 | } 11 | -------------------------------------------------------------------------------- /numba/cuda/descriptor.py: -------------------------------------------------------------------------------- 1 | from numba.core.descriptors import TargetDescriptor 2 | from numba.core.options import TargetOptions 3 | from .target import CUDATargetContext, CUDATypingContext 4 | 5 | 6 | class CUDATargetOptions(TargetOptions): 7 | pass 8 | 9 | 10 | class CUDATarget(TargetDescriptor): 11 | def __init__(self, name): 12 | self.options = CUDATargetOptions 13 | # The typing and target contexts are initialized only when needed - 14 | # this prevents an attempt to load CUDA libraries at import time on 15 | # systems that might not have them present. 16 | self._typingctx = None 17 | self._targetctx = None 18 | super().__init__(name) 19 | 20 | @property 21 | def typing_context(self): 22 | if self._typingctx is None: 23 | self._typingctx = CUDATypingContext() 24 | return self._typingctx 25 | 26 | @property 27 | def target_context(self): 28 | if self._targetctx is None: 29 | self._targetctx = CUDATargetContext(self._typingctx) 30 | return self._targetctx 31 | 32 | 33 | cuda_target = CUDATarget('cuda') 34 | -------------------------------------------------------------------------------- /numba/cuda/extending.py: -------------------------------------------------------------------------------- 1 | """ 2 | Added for symmetry with the core API 3 | """ 4 | 5 | from numba.core.extending import intrinsic as _intrinsic 6 | 7 | intrinsic = _intrinsic(target='cuda') 8 | -------------------------------------------------------------------------------- /numba/cuda/initialize.py: -------------------------------------------------------------------------------- 1 | def initialize_all(): 2 | # Import models to register them with the data model manager 3 | import numba.cuda.models # noqa: F401 4 | 5 | from numba.cuda.decorators import jit 6 | from numba.cuda.dispatcher import CUDADispatcher 7 | from numba.core.target_extension import (target_registry, 8 | dispatcher_registry, 9 | jit_registry) 10 | 11 | cuda_target = target_registry["cuda"] 12 | jit_registry[cuda_target] = jit 13 | dispatcher_registry[cuda_target] = CUDADispatcher 14 | -------------------------------------------------------------------------------- /numba/cuda/kernels/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/cuda/kernels/__init__.py -------------------------------------------------------------------------------- /numba/cuda/libdevicedecl.py: -------------------------------------------------------------------------------- 1 | from numba.cuda import libdevice, libdevicefuncs 2 | from numba.core.typing.templates import ConcreteTemplate, Registry 3 | 4 | registry = Registry() 5 | register_global = registry.register_global 6 | 7 | 8 | def libdevice_declare(func, retty, args): 9 | class Libdevice_function(ConcreteTemplate): 10 | cases = [libdevicefuncs.create_signature(retty, args)] 11 | 12 | pyfunc = getattr(libdevice, func[5:]) 13 | register_global(pyfunc)(Libdevice_function) 14 | 15 | 16 | for func, (retty, args) in libdevicefuncs.functions.items(): 17 | libdevice_declare(func, retty, args) 18 | -------------------------------------------------------------------------------- /numba/cuda/models.py: -------------------------------------------------------------------------------- 1 | import functools 2 | 3 | from llvmlite import ir 4 | 5 | from numba.core.datamodel.registry import DataModelManager, register 6 | from numba.core.extending import models 7 | from numba.core import types 8 | from numba.cuda.types import Dim3, GridGroup, CUDADispatcher 9 | 10 | 11 | cuda_data_manager = DataModelManager() 12 | 13 | register_model = functools.partial(register, cuda_data_manager) 14 | 15 | 16 | @register_model(Dim3) 17 | class Dim3Model(models.StructModel): 18 | def __init__(self, dmm, fe_type): 19 | members = [ 20 | ('x', types.int32), 21 | ('y', types.int32), 22 | ('z', types.int32) 23 | ] 24 | super().__init__(dmm, fe_type, members) 25 | 26 | 27 | @register_model(GridGroup) 28 | class GridGroupModel(models.PrimitiveModel): 29 | def __init__(self, dmm, fe_type): 30 | be_type = ir.IntType(64) 31 | super().__init__(dmm, fe_type, be_type) 32 | 33 | 34 | @register_model(types.Float) 35 | class FloatModel(models.PrimitiveModel): 36 | def __init__(self, dmm, fe_type): 37 | if fe_type == types.float16: 38 | be_type = ir.IntType(16) 39 | elif fe_type == types.float32: 40 | be_type = ir.FloatType() 41 | elif fe_type == types.float64: 42 | be_type = ir.DoubleType() 43 | else: 44 | raise NotImplementedError(fe_type) 45 | super(FloatModel, self).__init__(dmm, fe_type, be_type) 46 | 47 | 48 | register_model(CUDADispatcher)(models.OpaqueModel) 49 | -------------------------------------------------------------------------------- /numba/cuda/simulator/compiler.py: -------------------------------------------------------------------------------- 1 | ''' 2 | The compiler is not implemented in the simulator. This module provides a stub 3 | to allow tests to import successfully. 4 | ''' 5 | 6 | compile = None 7 | compile_for_current_device = None 8 | compile_ptx = None 9 | compile_ptx_for_current_device = None 10 | -------------------------------------------------------------------------------- /numba/cuda/simulator/cudadrv/__init__.py: -------------------------------------------------------------------------------- 1 | from numba.cuda.simulator.cudadrv import (devicearray, devices, driver, drvapi, 2 | error, nvvm) 3 | -------------------------------------------------------------------------------- /numba/cuda/simulator/cudadrv/driver.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Most of the driver API is unsupported in the simulator, but some stubs are 3 | provided to allow tests to import correctly. 4 | ''' 5 | 6 | 7 | def device_memset(dst, val, size, stream=0): 8 | dst.view('u1')[:size].fill(bytes([val])[0]) 9 | 10 | 11 | def host_to_device(dst, src, size, stream=0): 12 | dst.view('u1')[:size] = src.view('u1')[:size] 13 | 14 | 15 | def device_to_host(dst, src, size, stream=0): 16 | host_to_device(dst, src, size) 17 | 18 | 19 | def device_memory_size(obj): 20 | return obj.itemsize * obj.size 21 | 22 | 23 | def device_to_device(dst, src, size, stream=0): 24 | host_to_device(dst, src, size) 25 | 26 | 27 | class FakeDriver(object): 28 | def get_device_count(self): 29 | return 1 30 | 31 | 32 | driver = FakeDriver() 33 | 34 | 35 | class Linker: 36 | @classmethod 37 | def new(cls, max_registers=0, lineinfo=False, cc=None): 38 | return Linker() 39 | 40 | @property 41 | def lto(self): 42 | return False 43 | 44 | 45 | class LinkerError(RuntimeError): 46 | pass 47 | 48 | 49 | class NvrtcError(RuntimeError): 50 | pass 51 | 52 | 53 | class CudaAPIError(RuntimeError): 54 | pass 55 | 56 | 57 | def launch_kernel(*args, **kwargs): 58 | msg = 'Launching kernels directly is not supported in the simulator' 59 | raise RuntimeError(msg) 60 | 61 | 62 | USE_NV_BINDING = False 63 | -------------------------------------------------------------------------------- /numba/cuda/simulator/cudadrv/drvapi.py: -------------------------------------------------------------------------------- 1 | ''' 2 | drvapi is not implemented in the simulator, but this module exists to allow 3 | tests to import correctly. 4 | ''' 5 | -------------------------------------------------------------------------------- /numba/cuda/simulator/cudadrv/dummyarray.py: -------------------------------------------------------------------------------- 1 | # Dummy arrays are not implemented in the simulator. This file allows the dummy 2 | # array tests to be imported, but they are skipped on the simulator. 3 | 4 | Array = None 5 | -------------------------------------------------------------------------------- /numba/cuda/simulator/cudadrv/error.py: -------------------------------------------------------------------------------- 1 | class CudaSupportError(RuntimeError): 2 | pass 3 | 4 | 5 | class NvrtcError(Exception): 6 | pass 7 | -------------------------------------------------------------------------------- /numba/cuda/simulator/cudadrv/libs.py: -------------------------------------------------------------------------------- 1 | def check_static_lib(lib): 2 | raise FileNotFoundError('Linking libraries not supported by cudasim') 3 | -------------------------------------------------------------------------------- /numba/cuda/simulator/cudadrv/nvvm.py: -------------------------------------------------------------------------------- 1 | ''' 2 | NVVM is not supported in the simulator, but stubs are provided to allow tests 3 | to import correctly. 4 | ''' 5 | 6 | 7 | class NvvmSupportError(ImportError): 8 | pass 9 | 10 | 11 | class NVVM(object): 12 | def __init__(self): 13 | raise NvvmSupportError('NVVM not supported in the simulator') 14 | 15 | 16 | CompilationUnit = None 17 | compile_ir = None 18 | set_cuda_kernel = None 19 | get_arch_option = None 20 | LibDevice = None 21 | NvvmError = None 22 | 23 | 24 | def is_available(): 25 | return False 26 | 27 | 28 | def get_supported_ccs(): 29 | return () 30 | -------------------------------------------------------------------------------- /numba/cuda/simulator/cudadrv/runtime.py: -------------------------------------------------------------------------------- 1 | ''' 2 | The runtime API is unsupported in the simulator, but some stubs are 3 | provided to allow tests to import correctly. 4 | ''' 5 | 6 | 7 | class FakeRuntime(object): 8 | def get_version(self): 9 | return (-1, -1) 10 | 11 | def is_supported_version(self): 12 | return True 13 | 14 | @property 15 | def supported_versions(self): 16 | return (-1, -1), 17 | 18 | 19 | runtime = FakeRuntime() 20 | -------------------------------------------------------------------------------- /numba/cuda/simulator/reduction.py: -------------------------------------------------------------------------------- 1 | from functools import reduce as pyreduce 2 | 3 | 4 | def Reduce(func): 5 | def reduce_wrapper(seq, res=None, init=0): 6 | r = pyreduce(func, seq, init) 7 | if res is not None: 8 | res[0] = r 9 | return None 10 | else: 11 | return r 12 | return reduce_wrapper 13 | 14 | 15 | reduce = Reduce 16 | -------------------------------------------------------------------------------- /numba/cuda/simulator_init.py: -------------------------------------------------------------------------------- 1 | # We import * from simulator here because * is imported from simulator_init by 2 | # numba.cuda.__init__. 3 | from .simulator import * # noqa: F403, F401 4 | 5 | 6 | def is_available(): 7 | """Returns a boolean to indicate the availability of a CUDA GPU. 8 | """ 9 | # Simulator is always available 10 | return True 11 | 12 | 13 | def cuda_error(): 14 | """Returns None or an exception if the CUDA driver fails to initialize. 15 | """ 16 | # Simulator never fails to initialize 17 | return None 18 | -------------------------------------------------------------------------------- /numba/cuda/tests/__init__.py: -------------------------------------------------------------------------------- 1 | from numba.cuda.testing import ensure_supported_ccs_initialized 2 | from numba.testing import unittest 3 | from numba.testing import load_testsuite 4 | from numba import cuda 5 | from os.path import dirname, join 6 | 7 | 8 | def load_tests(loader, tests, pattern): 9 | suite = unittest.TestSuite() 10 | this_dir = dirname(__file__) 11 | ensure_supported_ccs_initialized() 12 | suite.addTests(load_testsuite(loader, join(this_dir, 'nocuda'))) 13 | if cuda.is_available(): 14 | suite.addTests(load_testsuite(loader, join(this_dir, 'cudasim'))) 15 | gpus = cuda.list_devices() 16 | if gpus and gpus[0].compute_capability >= (2, 0): 17 | suite.addTests(load_testsuite(loader, join(this_dir, 'cudadrv'))) 18 | suite.addTests(load_testsuite(loader, join(this_dir, 'cudapy'))) 19 | suite.addTests(load_testsuite(loader, join(this_dir, 'doc_examples'))) 20 | else: 21 | print("skipped CUDA tests because GPU CC < 2.0") 22 | else: 23 | print("skipped CUDA tests") 24 | return suite 25 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudadrv/__init__.py: -------------------------------------------------------------------------------- 1 | from numba.cuda.testing import ensure_supported_ccs_initialized 2 | from numba.testing import load_testsuite 3 | import os 4 | 5 | 6 | def load_tests(loader, tests, pattern): 7 | ensure_supported_ccs_initialized() 8 | return load_testsuite(loader, os.path.dirname(__file__)) 9 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudadrv/test_cuda_auto_context.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numba import cuda 3 | from numba.cuda.testing import unittest, CUDATestCase 4 | 5 | 6 | class TestCudaAutoContext(CUDATestCase): 7 | def test_auto_context(self): 8 | """A problem was revealed by a customer that the use cuda.to_device 9 | does not create a CUDA context. 10 | This tests the problem 11 | """ 12 | A = np.arange(10, dtype=np.float32) 13 | newA = np.empty_like(A) 14 | dA = cuda.to_device(A) 15 | 16 | dA.copy_to_host(newA) 17 | self.assertTrue(np.allclose(A, newA)) 18 | 19 | 20 | if __name__ == '__main__': 21 | unittest.main() 22 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudadrv/test_cuda_libraries.py: -------------------------------------------------------------------------------- 1 | from numba.cuda.testing import unittest 2 | from numba.cuda.testing import skip_on_cudasim, skip_unless_conda_cudatoolkit 3 | from numba.misc.findlib import find_lib 4 | 5 | 6 | @skip_on_cudasim('Library detection unsupported in the simulator') 7 | @skip_unless_conda_cudatoolkit 8 | class TestLibraryDetection(unittest.TestCase): 9 | def test_detect(self): 10 | """ 11 | This test is solely present to ensure that shipped cudatoolkits have 12 | additional core libraries in locations that Numba scans by default. 13 | PyCulib (and potentially others) rely on Numba's library finding 14 | capacity to find and subsequently load these libraries. 15 | """ 16 | core_libs = ['nvvm'] 17 | for l in core_libs: 18 | self.assertNotEqual(find_lib(l), []) 19 | 20 | 21 | if __name__ == '__main__': 22 | unittest.main() 23 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudadrv/test_events.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numba import cuda 3 | from numba.cuda.testing import unittest, CUDATestCase 4 | 5 | 6 | class TestCudaEvent(CUDATestCase): 7 | def test_event_elapsed(self): 8 | N = 32 9 | dary = cuda.device_array(N, dtype=np.double) 10 | evtstart = cuda.event() 11 | evtend = cuda.event() 12 | 13 | evtstart.record() 14 | cuda.to_device(np.arange(N, dtype=np.double), to=dary) 15 | evtend.record() 16 | evtend.wait() 17 | evtend.synchronize() 18 | # Exercise the code path 19 | evtstart.elapsed_time(evtend) 20 | 21 | def test_event_elapsed_stream(self): 22 | N = 32 23 | stream = cuda.stream() 24 | dary = cuda.device_array(N, dtype=np.double) 25 | evtstart = cuda.event() 26 | evtend = cuda.event() 27 | 28 | evtstart.record(stream=stream) 29 | cuda.to_device(np.arange(N, dtype=np.double), to=dary, stream=stream) 30 | evtend.record(stream=stream) 31 | evtend.wait(stream=stream) 32 | evtend.synchronize() 33 | # Exercise the code path 34 | evtstart.elapsed_time(evtend) 35 | 36 | 37 | if __name__ == '__main__': 38 | unittest.main() 39 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudadrv/test_inline_ptx.py: -------------------------------------------------------------------------------- 1 | from llvmlite import ir 2 | 3 | from numba.cuda.cudadrv import nvvm 4 | from numba.cuda.testing import unittest, ContextResettingTestCase 5 | from numba.cuda.testing import skip_on_cudasim 6 | 7 | 8 | @skip_on_cudasim('Inline PTX cannot be used in the simulator') 9 | class TestCudaInlineAsm(ContextResettingTestCase): 10 | def test_inline_rsqrt(self): 11 | mod = ir.Module(__name__) 12 | mod.triple = 'nvptx64-nvidia-cuda' 13 | nvvm.add_ir_version(mod) 14 | fnty = ir.FunctionType(ir.VoidType(), [ir.PointerType(ir.FloatType())]) 15 | fn = ir.Function(mod, fnty, 'cu_rsqrt') 16 | bldr = ir.IRBuilder(fn.append_basic_block('entry')) 17 | 18 | rsqrt_approx_fnty = ir.FunctionType(ir.FloatType(), [ir.FloatType()]) 19 | inlineasm = ir.InlineAsm(rsqrt_approx_fnty, 20 | 'rsqrt.approx.f32 $0, $1;', 21 | '=f,f', side_effect=True) 22 | val = bldr.load(fn.args[0]) 23 | res = bldr.call(inlineasm, [val]) 24 | 25 | bldr.store(res, fn.args[0]) 26 | bldr.ret_void() 27 | 28 | # generate ptx 29 | mod.data_layout = nvvm.NVVM().data_layout 30 | nvvm.set_cuda_kernel(fn) 31 | nvvmir = str(mod) 32 | ptx = nvvm.compile_ir(nvvmir) 33 | self.assertTrue('rsqrt.approx.f32' in str(ptx)) 34 | 35 | 36 | if __name__ == '__main__': 37 | unittest.main() 38 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudadrv/test_is_fp16.py: -------------------------------------------------------------------------------- 1 | from numba import cuda 2 | from numba.cuda.testing import CUDATestCase, skip_on_cudasim, skip_unless_cc_53 3 | 4 | 5 | class TestIsFP16Supported(CUDATestCase): 6 | def test_is_fp16_supported(self): 7 | self.assertTrue(cuda.is_float16_supported()) 8 | 9 | @skip_on_cudasim 10 | @skip_unless_cc_53 11 | def test_device_supports_float16(self): 12 | self.assertTrue(cuda.get_current_device().supports_float16) 13 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudadrv/test_pinned.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import platform 3 | 4 | from numba import cuda 5 | from numba.cuda.testing import unittest, ContextResettingTestCase 6 | 7 | 8 | class TestPinned(ContextResettingTestCase): 9 | 10 | def _run_copies(self, A): 11 | A0 = np.copy(A) 12 | 13 | stream = cuda.stream() 14 | ptr = cuda.to_device(A, copy=False, stream=stream) 15 | ptr.copy_to_device(A, stream=stream) 16 | ptr.copy_to_host(A, stream=stream) 17 | stream.synchronize() 18 | 19 | self.assertTrue(np.allclose(A, A0)) 20 | 21 | def test_pinned(self): 22 | machine = platform.machine() 23 | if machine.startswith('arm') or machine.startswith('aarch64'): 24 | count = 262144 # 2MB 25 | else: 26 | count = 2097152 # 16MB 27 | A = np.arange(count) 28 | with cuda.pinned(A): 29 | self._run_copies(A) 30 | 31 | def test_unpinned(self): 32 | A = np.arange(2 * 1024 * 1024) # 16 MB 33 | self._run_copies(A) 34 | 35 | 36 | if __name__ == '__main__': 37 | unittest.main() 38 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudadrv/test_profiler.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from numba.cuda.testing import ContextResettingTestCase 3 | from numba import cuda 4 | from numba.cuda.testing import skip_on_cudasim 5 | 6 | 7 | @skip_on_cudasim('CUDA Profiler unsupported in the simulator') 8 | class TestProfiler(ContextResettingTestCase): 9 | def test_profiling(self): 10 | with cuda.profiling(): 11 | a = cuda.device_array(10) 12 | del a 13 | 14 | with cuda.profiling(): 15 | a = cuda.device_array(100) 16 | del a 17 | 18 | 19 | if __name__ == '__main__': 20 | unittest.main() 21 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudadrv/test_reset_device.py: -------------------------------------------------------------------------------- 1 | import threading 2 | from numba import cuda 3 | from numba.cuda.cudadrv.driver import driver 4 | from numba.cuda.testing import unittest, ContextResettingTestCase 5 | from queue import Queue 6 | 7 | 8 | class TestResetDevice(ContextResettingTestCase): 9 | def test_reset_device(self): 10 | 11 | def newthread(exception_queue): 12 | try: 13 | devices = range(driver.get_device_count()) 14 | for _ in range(2): 15 | for d in devices: 16 | cuda.select_device(d) 17 | cuda.close() 18 | except Exception as e: 19 | exception_queue.put(e) 20 | 21 | # Do test on a separate thread so that we don't affect 22 | # the current context in the main thread. 23 | 24 | exception_queue = Queue() 25 | t = threading.Thread(target=newthread, args=(exception_queue,)) 26 | t.start() 27 | t.join() 28 | 29 | exceptions = [] 30 | while not exception_queue.empty(): 31 | exceptions.append(exception_queue.get()) 32 | self.assertEqual(exceptions, []) 33 | 34 | 35 | if __name__ == '__main__': 36 | unittest.main() 37 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudadrv/test_select_device.py: -------------------------------------------------------------------------------- 1 | # 2 | # Test does not work on some cards. 3 | # 4 | import threading 5 | from queue import Queue 6 | 7 | import numpy as np 8 | from numba import cuda 9 | from numba.cuda.testing import unittest, ContextResettingTestCase 10 | 11 | 12 | def newthread(exception_queue): 13 | try: 14 | cuda.select_device(0) 15 | stream = cuda.stream() 16 | A = np.arange(100) 17 | dA = cuda.to_device(A, stream=stream) 18 | stream.synchronize() 19 | del dA 20 | del stream 21 | cuda.close() 22 | except Exception as e: 23 | exception_queue.put(e) 24 | 25 | 26 | class TestSelectDevice(ContextResettingTestCase): 27 | def test_select_device(self): 28 | exception_queue = Queue() 29 | for i in range(10): 30 | t = threading.Thread(target=newthread, args=(exception_queue,)) 31 | t.start() 32 | t.join() 33 | 34 | exceptions = [] 35 | while not exception_queue.empty(): 36 | exceptions.append(exception_queue.get()) 37 | self.assertEqual(exceptions, []) 38 | 39 | 40 | if __name__ == '__main__': 41 | unittest.main() 42 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/__init__.py: -------------------------------------------------------------------------------- 1 | from numba.cuda.testing import ensure_supported_ccs_initialized 2 | from numba.testing import load_testsuite 3 | import os 4 | 5 | 6 | def load_tests(loader, tests, pattern): 7 | ensure_supported_ccs_initialized() 8 | return load_testsuite(loader, os.path.dirname(__file__)) 9 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/cache_with_cpu_usecases.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from numba import cuda, njit 4 | from numba.cuda.testing import CUDATestCase 5 | from numba.cuda.tests.cudapy.cache_usecases import CUDAUseCase, UseCase 6 | 7 | 8 | class CPUUseCase(UseCase): 9 | def _call(self, ret, *args): 10 | self._func(ret, *args) 11 | 12 | 13 | # Using the same function as a cached CPU and CUDA-jitted function 14 | 15 | def target_shared_assign(r, x): 16 | r[()] = x[()] 17 | 18 | 19 | assign_cuda_kernel = cuda.jit(cache=True)(target_shared_assign) 20 | assign_cuda = CUDAUseCase(assign_cuda_kernel) 21 | assign_cpu_jitted = njit(cache=True)(target_shared_assign) 22 | assign_cpu = CPUUseCase(assign_cpu_jitted) 23 | 24 | 25 | class _TestModule(CUDATestCase): 26 | """ 27 | Tests for functionality of this module's functions. 28 | Note this does not define any "test_*" method, instead check_module() 29 | should be called by hand. 30 | """ 31 | 32 | def check_module(self, mod): 33 | self.assertPreciseEqual(mod.assign_cpu(5), 5) 34 | self.assertPreciseEqual(mod.assign_cpu(5.5), 5.5) 35 | self.assertPreciseEqual(mod.assign_cuda(5), 5) 36 | self.assertPreciseEqual(mod.assign_cuda(5.5), 5.5) 37 | 38 | 39 | def self_test(): 40 | mod = sys.modules[__name__] 41 | _TestModule().check_module(mod) 42 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/jitlink.ptx: -------------------------------------------------------------------------------- 1 | // 2 | // Generated by NVIDIA NVVM Compiler 3 | // Compiler built on Tue Apr 1 03:34:02 2014 (1396341242) 4 | // Cuda compilation tools, release 6.0, V6.0.1 5 | // 6 | 7 | .version 4.0 8 | .target sm_20 9 | .address_size 64 10 | 11 | 12 | .visible .func (.param .b32 func_retval0) bar( 13 | .param .b64 bar_param_0, 14 | .param .b32 bar_param_1 15 | ) 16 | { 17 | .reg .s32 %r<4>; 18 | .reg .s64 %rd<2>; 19 | 20 | 21 | ld.param.u64 %rd1, [bar_param_0]; 22 | ld.param.u32 %r1, [bar_param_1]; 23 | shl.b32 %r2, %r1, 1; 24 | st.u32 [%rd1], %r2; 25 | mov.u32 %r3, 0; 26 | st.param.b32 [func_retval0+0], %r3; 27 | ret; 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_alignment.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numba import from_dtype, cuda 3 | from numba.cuda.testing import skip_on_cudasim, CUDATestCase 4 | import unittest 5 | 6 | 7 | class TestAlignment(CUDATestCase): 8 | def test_record_alignment(self): 9 | rec_dtype = np.dtype([('a', 'int32'), ('b', 'float64')], align=True) 10 | rec = from_dtype(rec_dtype) 11 | 12 | @cuda.jit((rec[:],)) 13 | def foo(a): 14 | i = cuda.grid(1) 15 | a[i].a = a[i].b 16 | 17 | a_recarray = np.recarray(3, dtype=rec_dtype) 18 | for i in range(a_recarray.size): 19 | a_rec = a_recarray[i] 20 | a_rec.a = 0 21 | a_rec.b = (i + 1) * 123 22 | 23 | foo[1, 3](a_recarray) 24 | 25 | self.assertTrue(np.all(a_recarray.a == a_recarray.b)) 26 | 27 | @skip_on_cudasim('Simulator does not check alignment') 28 | def test_record_alignment_error(self): 29 | rec_dtype = np.dtype([('a', 'int32'), ('b', 'float64')]) 30 | rec = from_dtype(rec_dtype) 31 | 32 | with self.assertRaises(Exception) as raises: 33 | @cuda.jit((rec[:],)) 34 | def foo(a): 35 | i = cuda.grid(1) 36 | a[i].a = a[i].b 37 | 38 | self.assertTrue('type float64 is not aligned' in str(raises.exception)) 39 | 40 | 41 | if __name__ == '__main__': 42 | unittest.main() 43 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_array_methods.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numba import cuda 3 | from numba.cuda.testing import CUDATestCase 4 | import unittest 5 | 6 | 7 | def reinterpret_array_type(byte_arr, start, stop, output): 8 | # Tested with just one thread 9 | val = byte_arr[start:stop].view(np.int32)[0] 10 | output[0] = val 11 | 12 | 13 | class TestCudaArrayMethods(CUDATestCase): 14 | def test_reinterpret_array_type(self): 15 | """ 16 | Reinterpret byte array as int32 in the GPU. 17 | """ 18 | pyfunc = reinterpret_array_type 19 | kernel = cuda.jit(pyfunc) 20 | 21 | byte_arr = np.arange(256, dtype=np.uint8) 22 | itemsize = np.dtype(np.int32).itemsize 23 | for start in range(0, 256, itemsize): 24 | stop = start + itemsize 25 | expect = byte_arr[start:stop].view(np.int32)[0] 26 | 27 | output = np.zeros(1, dtype=np.int32) 28 | kernel[1, 1](byte_arr, start, stop, output) 29 | 30 | got = output[0] 31 | self.assertEqual(expect, got) 32 | 33 | 34 | if __name__ == '__main__': 35 | unittest.main() 36 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_boolean.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numba.cuda.testing import unittest, CUDATestCase 3 | from numba import cuda 4 | 5 | 6 | def boolean_func(A, vertial): 7 | if vertial: 8 | A[0] = 123 9 | else: 10 | A[0] = 321 11 | 12 | 13 | class TestCudaBoolean(CUDATestCase): 14 | def test_boolean(self): 15 | func = cuda.jit('void(float64[:], bool_)')(boolean_func) 16 | A = np.array([0], dtype='float64') 17 | func[1, 1](A, True) 18 | self.assertTrue(A[0] == 123) 19 | func[1, 1](A, False) 20 | self.assertTrue(A[0] == 321) 21 | 22 | 23 | if __name__ == '__main__': 24 | unittest.main() 25 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_cffi.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from numba import cuda, types 4 | from numba.cuda.testing import (skip_on_cudasim, test_data_dir, unittest, 5 | CUDATestCase) 6 | from numba.tests.support import skip_unless_cffi 7 | 8 | 9 | @skip_unless_cffi 10 | @skip_on_cudasim('Simulator does not support linking') 11 | class TestCFFI(CUDATestCase): 12 | def test_from_buffer(self): 13 | import cffi 14 | ffi = cffi.FFI() 15 | 16 | link = str(test_data_dir / 'jitlink.ptx') 17 | sig = types.void(types.CPointer(types.int32)) 18 | array_mutator = cuda.declare_device('array_mutator', sig) 19 | 20 | @cuda.jit(link=[link]) 21 | def mutate_array(x): 22 | x_ptr = ffi.from_buffer(x) 23 | array_mutator(x_ptr) 24 | 25 | x = np.arange(2).astype(np.int32) 26 | mutate_array[1, 1](x) 27 | 28 | # The foreign function should have copied element 1 to element 0 29 | self.assertEqual(x[0], x[1]) 30 | 31 | 32 | if __name__ == '__main__': 33 | unittest.main() 34 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_complex_kernel.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numba import cuda 3 | from numba.cuda.testing import unittest, CUDATestCase 4 | 5 | 6 | class TestCudaComplex(CUDATestCase): 7 | def test_cuda_complex_arg(self): 8 | @cuda.jit('void(complex128[:], complex128)') 9 | def foo(a, b): 10 | i = cuda.grid(1) 11 | a[i] += b 12 | 13 | a = np.arange(5, dtype=np.complex128) 14 | a0 = a.copy() 15 | foo[1, a.shape](a, 2j) 16 | self.assertTrue(np.allclose(a, a0 + 2j)) 17 | 18 | 19 | if __name__ == '__main__': 20 | unittest.main() 21 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_freevar.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from numba import cuda 4 | from numba.cuda.testing import unittest, CUDATestCase 5 | 6 | 7 | class TestFreeVar(CUDATestCase): 8 | def test_freevar(self): 9 | """Make sure we can compile the following kernel with freevar reference 10 | in arguments to shared.array 11 | """ 12 | from numba import float32 13 | 14 | size = 1024 15 | nbtype = float32 16 | 17 | @cuda.jit("(float32[::1], intp)") 18 | def foo(A, i): 19 | "Dummy function" 20 | sdata = cuda.shared.array(size, # size is freevar 21 | dtype=nbtype) # nbtype is freevar 22 | A[i] = sdata[i] 23 | 24 | A = np.arange(2, dtype="float32") 25 | foo[1, 1](A, 0) 26 | 27 | 28 | if __name__ == '__main__': 29 | unittest.main() 30 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_idiv.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numba import cuda, float32, float64, int32, void 3 | from numba.cuda.testing import unittest, CUDATestCase 4 | 5 | 6 | class TestCudaIDiv(CUDATestCase): 7 | def test_inplace_div(self): 8 | 9 | @cuda.jit(void(float32[:, :], int32, int32)) 10 | def div(grid, l_x, l_y): 11 | for x in range(l_x): 12 | for y in range(l_y): 13 | grid[x, y] /= 2.0 14 | 15 | x = np.ones((2, 2), dtype=np.float32) 16 | grid = cuda.to_device(x) 17 | div[1, 1](grid, 2, 2) 18 | y = grid.copy_to_host() 19 | self.assertTrue(np.all(y == 0.5)) 20 | 21 | def test_inplace_div_double(self): 22 | 23 | @cuda.jit(void(float64[:, :], int32, int32)) 24 | def div_double(grid, l_x, l_y): 25 | for x in range(l_x): 26 | for y in range(l_y): 27 | grid[x, y] /= 2.0 28 | 29 | x = np.ones((2, 2), dtype=np.float64) 30 | grid = cuda.to_device(x) 31 | div_double[1, 1](grid, 2, 2) 32 | y = grid.copy_to_host() 33 | self.assertTrue(np.all(y == 0.5)) 34 | 35 | 36 | if __name__ == '__main__': 37 | unittest.main() 38 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_mandel.py: -------------------------------------------------------------------------------- 1 | from numba import float64, uint32 2 | from numba.cuda.compiler import compile_ptx 3 | from numba.cuda.testing import skip_on_cudasim, unittest 4 | 5 | 6 | @skip_on_cudasim('Compilation unsupported in the simulator') 7 | class TestCudaMandel(unittest.TestCase): 8 | def test_mandel(self): 9 | """Just make sure we can compile this 10 | """ 11 | 12 | def mandel(tid, min_x, max_x, min_y, max_y, width, height, iters): 13 | pixel_size_x = (max_x - min_x) / width 14 | pixel_size_y = (max_y - min_y) / height 15 | 16 | x = tid % width 17 | y = tid / width 18 | 19 | real = min_x + x * pixel_size_x 20 | imag = min_y + y * pixel_size_y 21 | 22 | c = complex(real, imag) 23 | z = 0.0j 24 | 25 | for i in range(iters): 26 | z = z * z + c 27 | if (z.real * z.real + z.imag * z.imag) >= 4: 28 | return i 29 | return iters 30 | 31 | args = (uint32, float64, float64, float64, float64, 32 | uint32, uint32, uint32) 33 | compile_ptx(mandel, args, device=True) 34 | 35 | 36 | if __name__ == '__main__': 37 | unittest.main() 38 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_montecarlo.py: -------------------------------------------------------------------------------- 1 | import math 2 | from numba import cuda 3 | from numba.cuda.testing import unittest, CUDATestCase 4 | 5 | 6 | class TestCudaMonteCarlo(CUDATestCase): 7 | def test_montecarlo(self): 8 | """Just make sure we can compile this 9 | """ 10 | 11 | @cuda.jit( 12 | 'void(double[:], double[:], double, double, double, double[:])') 13 | def step(last, paths, dt, c0, c1, normdist): 14 | i = cuda.grid(1) 15 | if i >= paths.shape[0]: 16 | return 17 | noise = normdist[i] 18 | paths[i] = last[i] * math.exp(c0 * dt + c1 * noise) 19 | 20 | 21 | if __name__ == '__main__': 22 | unittest.main() 23 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_multiprocessing.py: -------------------------------------------------------------------------------- 1 | import os 2 | import multiprocessing as mp 3 | 4 | import numpy as np 5 | 6 | from numba import cuda 7 | from numba.cuda.testing import skip_on_cudasim, CUDATestCase 8 | import unittest 9 | 10 | has_mp_get_context = hasattr(mp, 'get_context') 11 | is_unix = os.name == 'posix' 12 | 13 | 14 | def fork_test(q): 15 | from numba.cuda.cudadrv.error import CudaDriverError 16 | try: 17 | cuda.to_device(np.arange(1)) 18 | except CudaDriverError as e: 19 | q.put(e) 20 | else: 21 | q.put(None) 22 | 23 | 24 | @skip_on_cudasim('disabled for cudasim') 25 | class TestMultiprocessing(CUDATestCase): 26 | @unittest.skipUnless(has_mp_get_context, 'requires mp.get_context') 27 | @unittest.skipUnless(is_unix, 'requires Unix') 28 | def test_fork(self): 29 | """ 30 | Test fork detection. 31 | """ 32 | cuda.current_context() # force cuda initialize 33 | # fork in process that also uses CUDA 34 | ctx = mp.get_context('fork') 35 | q = ctx.Queue() 36 | proc = ctx.Process(target=fork_test, args=[q]) 37 | proc.start() 38 | exc = q.get() 39 | proc.join() 40 | # there should be an exception raised in the child process 41 | self.assertIsNotNone(exc) 42 | self.assertIn('CUDA initialized before forking', str(exc)) 43 | 44 | 45 | if __name__ == '__main__': 46 | unittest.main() 47 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_nondet.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numba import cuda, float32, void 3 | from numba.cuda.testing import unittest, CUDATestCase 4 | 5 | 6 | def generate_input(n): 7 | A = np.array(np.arange(n * n).reshape(n, n), dtype=np.float32) 8 | B = np.array(np.arange(n) + 0, dtype=A.dtype) 9 | return A, B 10 | 11 | 12 | class TestCudaNonDet(CUDATestCase): 13 | def test_for_pre(self): 14 | """Test issue with loop not running due to bad sign-extension at the for 15 | loop precondition. 16 | """ 17 | 18 | @cuda.jit(void(float32[:, :], float32[:, :], float32[:])) 19 | def diagproduct(c, a, b): 20 | startX, startY = cuda.grid(2) 21 | gridX = cuda.gridDim.x * cuda.blockDim.x 22 | gridY = cuda.gridDim.y * cuda.blockDim.y 23 | height = c.shape[0] 24 | width = c.shape[1] 25 | 26 | for x in range(startX, width, (gridX)): 27 | for y in range(startY, height, (gridY)): 28 | c[y, x] = a[y, x] * b[x] 29 | 30 | N = 8 31 | 32 | A, B = generate_input(N) 33 | 34 | F = np.empty(A.shape, dtype=A.dtype) 35 | 36 | blockdim = (32, 8) 37 | griddim = (1, 1) 38 | 39 | dA = cuda.to_device(A) 40 | dB = cuda.to_device(B) 41 | dF = cuda.to_device(F, copy=False) 42 | diagproduct[griddim, blockdim](dF, dA, dB) 43 | 44 | E = np.dot(A, np.diag(B)) 45 | np.testing.assert_array_almost_equal(dF.copy_to_host(), E) 46 | 47 | 48 | if __name__ == '__main__': 49 | unittest.main() 50 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_py2_div_issue.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numba import cuda, float32, int32, void 3 | from numba.cuda.testing import unittest, CUDATestCase 4 | 5 | 6 | class TestCudaPy2Div(CUDATestCase): 7 | def test_py2_div_issue(self): 8 | @cuda.jit(void(float32[:], float32[:], float32[:], int32)) 9 | def preCalc(y, yA, yB, numDataPoints): 10 | i = cuda.grid(1) 11 | # k is unused, but may be part of the trigger for the bug this 12 | # tests for. 13 | k = i % numDataPoints # noqa: F841 14 | 15 | ans = float32(1.001 * float32(i)) 16 | 17 | y[i] = ans 18 | yA[i] = ans * 1.0 19 | yB[i] = ans / 1.0 20 | 21 | numDataPoints = 15 22 | 23 | y = np.zeros(numDataPoints, dtype=np.float32) 24 | yA = np.zeros(numDataPoints, dtype=np.float32) 25 | yB = np.zeros(numDataPoints, dtype=np.float32) 26 | preCalc[1, 15](y, yA, yB, numDataPoints) 27 | 28 | self.assertTrue(np.all(y == yA)) 29 | self.assertTrue(np.all(y == yB)) 30 | 31 | 32 | if __name__ == '__main__': 33 | unittest.main() 34 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_vectorize_complex.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numba import vectorize 3 | from numba.cuda.testing import skip_on_cudasim, CUDATestCase 4 | import unittest 5 | 6 | 7 | @skip_on_cudasim('ufunc API unsupported in the simulator') 8 | class TestVectorizeComplex(CUDATestCase): 9 | def test_vectorize_complex(self): 10 | @vectorize(['complex128(complex128)'], target='cuda') 11 | def vcomp(a): 12 | return a * a + 1. 13 | 14 | A = np.arange(5, dtype=np.complex128) 15 | B = vcomp(A) 16 | self.assertTrue(np.allclose(A * A + 1., B)) 17 | 18 | 19 | if __name__ == '__main__': 20 | unittest.main() 21 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_vectorize_device.py: -------------------------------------------------------------------------------- 1 | from numba import vectorize 2 | from numba import cuda, float32 3 | import numpy as np 4 | from numba.cuda.testing import skip_on_cudasim, CUDATestCase 5 | import unittest 6 | 7 | 8 | @skip_on_cudasim('ufunc API unsupported in the simulator') 9 | class TestCudaVectorizeDeviceCall(CUDATestCase): 10 | def test_cuda_vectorize_device_call(self): 11 | 12 | @cuda.jit(float32(float32, float32, float32), device=True) 13 | def cu_device_fn(x, y, z): 14 | return x ** y / z 15 | 16 | def cu_ufunc(x, y, z): 17 | return cu_device_fn(x, y, z) 18 | 19 | ufunc = vectorize([float32(float32, float32, float32)], target='cuda')( 20 | cu_ufunc) 21 | 22 | N = 100 23 | 24 | X = np.array(np.random.sample(N), dtype=np.float32) 25 | Y = np.array(np.random.sample(N), dtype=np.float32) 26 | Z = np.array(np.random.sample(N), dtype=np.float32) + 0.1 27 | 28 | out = ufunc(X, Y, Z) 29 | 30 | gold = (X ** Y) / Z 31 | 32 | self.assertTrue(np.allclose(out, gold)) 33 | 34 | 35 | if __name__ == '__main__': 36 | unittest.main() 37 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numba import vectorize 3 | from numba import cuda, float64 4 | from numba.cuda.testing import skip_on_cudasim, CUDATestCase 5 | import unittest 6 | 7 | sig = [float64(float64, float64)] 8 | 9 | 10 | @skip_on_cudasim('ufunc API unsupported in the simulator') 11 | class TestCUDAVectorizeScalarArg(CUDATestCase): 12 | 13 | def test_vectorize_scalar_arg(self): 14 | @vectorize(sig, target='cuda') 15 | def vector_add(a, b): 16 | return a + b 17 | 18 | A = np.arange(10, dtype=np.float64) 19 | dA = cuda.to_device(A) 20 | v = vector_add(1.0, dA) 21 | 22 | np.testing.assert_array_almost_equal( 23 | v.copy_to_host(), 24 | np.arange(1, 11, dtype=np.float64)) 25 | 26 | def test_vectorize_all_scalars(self): 27 | @vectorize(sig, target='cuda') 28 | def vector_add(a, b): 29 | return a + b 30 | 31 | v = vector_add(1.0, 1.0) 32 | 33 | np.testing.assert_almost_equal(2.0, v) 34 | 35 | 36 | if __name__ == '__main__': 37 | unittest.main() 38 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudasim/__init__.py: -------------------------------------------------------------------------------- 1 | from numba.testing import load_testsuite 2 | import os 3 | 4 | 5 | def load_tests(loader, tests, pattern): 6 | return load_testsuite(loader, os.path.dirname(__file__)) 7 | -------------------------------------------------------------------------------- /numba/cuda/tests/cudasim/support.py: -------------------------------------------------------------------------------- 1 | from numba import cuda 2 | 3 | 4 | @cuda.jit(device=True) 5 | def cuda_module_in_device_function(): 6 | return cuda.threadIdx.x 7 | -------------------------------------------------------------------------------- /numba/cuda/tests/data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/cuda/tests/data/__init__.py -------------------------------------------------------------------------------- /numba/cuda/tests/data/cuda_include.cu: -------------------------------------------------------------------------------- 1 | // Not all CUDA includes are safe to include in device code compiled by NVRTC, 2 | // because it does not have paths to all system include directories. Headers 3 | // such as cuda_device_runtime_api.h are safe to use in NVRTC without adding 4 | // additional includes. 5 | #include 6 | -------------------------------------------------------------------------------- /numba/cuda/tests/data/error.cu: -------------------------------------------------------------------------------- 1 | extern "C" __device__ 2 | int bar(int* out, int a) { 3 | // Explicitly placed to generate an error 4 | SYNTAX ERROR 5 | *out = a * 2; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /numba/cuda/tests/data/jitlink.cu: -------------------------------------------------------------------------------- 1 | // Compile with: 2 | // 3 | // nvcc -gencode arch=compute_50,code=compute_50 -rdc true -ptx jitlink.cu 4 | // 5 | // using the oldest supported toolkit version (10.2 at the time of writing). 6 | 7 | extern "C" __device__ 8 | int bar(int *out, int a) 9 | { 10 | *out = a * 2; 11 | return 0; 12 | } 13 | 14 | 15 | // The out argument is necessary due to Numba's CUDA calling convention, which 16 | // always reserves the first parameter for a pointer to a returned value, even 17 | // if there is no return value. 18 | extern "C" __device__ 19 | int array_mutator(void *out, int *a) 20 | { 21 | a[0] = a[1]; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /numba/cuda/tests/data/jitlink.ptx: -------------------------------------------------------------------------------- 1 | // 2 | // Generated by NVIDIA NVVM Compiler 3 | // 4 | // Compiler Build ID: CL-27506705 5 | // Cuda compilation tools, release 10.2, V10.2.89 6 | // Based on LLVM 3.4svn 7 | // 8 | 9 | .version 6.5 10 | .target sm_50 11 | .address_size 64 12 | 13 | // .globl bar 14 | 15 | .visible .func (.param .b32 func_retval0) bar( 16 | .param .b64 bar_param_0, 17 | .param .b32 bar_param_1 18 | ) 19 | { 20 | .reg .b32 %r<4>; 21 | .reg .b64 %rd<2>; 22 | 23 | 24 | ld.param.u64 %rd1, [bar_param_0]; 25 | ld.param.u32 %r1, [bar_param_1]; 26 | shl.b32 %r2, %r1, 1; 27 | st.u32 [%rd1], %r2; 28 | mov.u32 %r3, 0; 29 | st.param.b32 [func_retval0+0], %r3; 30 | ret; 31 | } 32 | 33 | // .globl array_mutator 34 | .visible .func (.param .b32 func_retval0) array_mutator( 35 | .param .b64 array_mutator_param_0, 36 | .param .b64 array_mutator_param_1 37 | ) 38 | { 39 | .reg .b32 %r<3>; 40 | .reg .b64 %rd<2>; 41 | 42 | 43 | ld.param.u64 %rd1, [array_mutator_param_1]; 44 | ld.u32 %r1, [%rd1+4]; 45 | st.u32 [%rd1], %r1; 46 | mov.u32 %r2, 0; 47 | st.param.b32 [func_retval0+0], %r2; 48 | ret; 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /numba/cuda/tests/data/warn.cu: -------------------------------------------------------------------------------- 1 | extern "C" __device__ 2 | int bar(int* out, int a) { 3 | // Explicitly placed to generate a warning for testing the NVRTC program log 4 | int unused; 5 | *out = a * 2; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /numba/cuda/tests/doc_examples/__init__.py: -------------------------------------------------------------------------------- 1 | from numba.testing import load_testsuite 2 | import os 3 | 4 | 5 | def load_tests(loader, tests, pattern): 6 | return load_testsuite(loader, os.path.dirname(__file__)) 7 | -------------------------------------------------------------------------------- /numba/cuda/tests/doc_examples/ffi/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/cuda/tests/doc_examples/ffi/__init__.py -------------------------------------------------------------------------------- /numba/cuda/tests/doc_examples/ffi/functions.cu: -------------------------------------------------------------------------------- 1 | // magictoken.ex_mul_f32_f32.begin 2 | // Foreign function example: multiplication of a pair of floats 3 | 4 | extern "C" __device__ int 5 | mul_f32_f32( 6 | float* return_value, 7 | float x, 8 | float y) 9 | { 10 | // Compute result and store in caller-provided slot 11 | *return_value = x * y; 12 | 13 | // Signal that no Python exception occurred 14 | return 0; 15 | } 16 | // magictoken.ex_mul_f32_f32.end 17 | 18 | 19 | // magictoken.ex_sum_reduce_proto.begin 20 | extern "C" 21 | __device__ int 22 | sum_reduce( 23 | float* return_value, 24 | float* array, 25 | int n 26 | ); 27 | // magictoken.ex_sum_reduce_proto.end 28 | 29 | 30 | // Performs a simple reduction on an array passed by pointer using the 31 | // ffi.from_buffer() method. Implements the prototype above. 32 | extern "C" 33 | __device__ int 34 | sum_reduce( 35 | float* return_value, 36 | float* array, 37 | int n 38 | ) 39 | { 40 | double sum = 0.0; 41 | 42 | for (size_t i = 0; i < n; ++i) { 43 | sum += array[i]; 44 | } 45 | 46 | *return_value = (float)sum; 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /numba/cuda/tests/nocuda/__init__.py: -------------------------------------------------------------------------------- 1 | from numba.cuda.testing import ensure_supported_ccs_initialized 2 | from numba.testing import load_testsuite 3 | import os 4 | 5 | 6 | def load_tests(loader, tests, pattern): 7 | ensure_supported_ccs_initialized() 8 | return load_testsuite(loader, os.path.dirname(__file__)) 9 | -------------------------------------------------------------------------------- /numba/cuda/tests/nocuda/test_function_resolution.py: -------------------------------------------------------------------------------- 1 | from numba.cuda.testing import unittest, skip_on_cudasim 2 | import operator 3 | from numba.core import types, typing 4 | from numba.cuda.cudadrv import nvvm 5 | 6 | 7 | @unittest.skipIf(not nvvm.is_available(), "No libNVVM") 8 | @skip_on_cudasim("Skip on simulator due to use of cuda_target") 9 | class TestFunctionResolution(unittest.TestCase): 10 | def test_fp16_binary_operators(self): 11 | from numba.cuda.descriptor import cuda_target 12 | ops = (operator.add, operator.iadd, operator.sub, operator.isub, 13 | operator.mul, operator.imul) 14 | for op in ops: 15 | fp16 = types.float16 16 | typingctx = cuda_target.typing_context 17 | typingctx.refresh() 18 | fnty = typingctx.resolve_value_type(op) 19 | out = typingctx.resolve_function_type(fnty, (fp16, fp16), {}) 20 | self.assertEqual(out, typing.signature(fp16, fp16, fp16), 21 | msg=str(out)) 22 | 23 | def test_fp16_unary_operators(self): 24 | from numba.cuda.descriptor import cuda_target 25 | ops = (operator.neg, abs) 26 | for op in ops: 27 | fp16 = types.float16 28 | typingctx = cuda_target.typing_context 29 | typingctx.refresh() 30 | fnty = typingctx.resolve_value_type(op) 31 | out = typingctx.resolve_function_type(fnty, (fp16,), {}) 32 | self.assertEqual(out, typing.signature(fp16, fp16), msg=str(out)) 33 | 34 | 35 | if __name__ == '__main__': 36 | unittest.main() 37 | -------------------------------------------------------------------------------- /numba/cuda/types.py: -------------------------------------------------------------------------------- 1 | from numba.core import types 2 | 3 | 4 | class Dim3(types.Type): 5 | """ 6 | A 3-tuple (x, y, z) representing the position of a block or thread. 7 | """ 8 | def __init__(self): 9 | super().__init__(name='Dim3') 10 | 11 | 12 | class GridGroup(types.Type): 13 | """ 14 | The grid of all threads in a cooperative kernel launch. 15 | """ 16 | def __init__(self): 17 | super().__init__(name='GridGroup') 18 | 19 | 20 | dim3 = Dim3() 21 | grid_group = GridGroup() 22 | 23 | 24 | class CUDADispatcher(types.Dispatcher): 25 | """The type of CUDA dispatchers""" 26 | # This type exists (instead of using types.Dispatcher as the type of CUDA 27 | # dispatchers) so that we can have an alternative lowering for them to the 28 | # lowering of CPU dispatchers - the CPU target lowers all dispatchers as a 29 | # constant address, but we need to lower to a dummy value because it's not 30 | # generally valid to use the address of CUDA kernels and functions. 31 | # 32 | # Notes: it may be a bug in the CPU target that it lowers all dispatchers to 33 | # a constant address - it should perhaps only lower dispatchers acting as 34 | # first-class functions to a constant address. Even if that bug is fixed, it 35 | # is still probably a good idea to have a separate type for CUDA 36 | # dispatchers, and this type might get other differentiation from the CPU 37 | # dispatcher type in future. 38 | -------------------------------------------------------------------------------- /numba/experimental/__init__.py: -------------------------------------------------------------------------------- 1 | from .jitclass import jitclass -------------------------------------------------------------------------------- /numba/experimental/jitclass/__init__.py: -------------------------------------------------------------------------------- 1 | from numba.experimental.jitclass.decorators import jitclass 2 | from numba.experimental.jitclass import boxing # Has import-time side effect 3 | from numba.experimental.jitclass import overloads # Has import-time side effect 4 | -------------------------------------------------------------------------------- /numba/extending.py: -------------------------------------------------------------------------------- 1 | # Re-export symbols 2 | from numba.core.extending import * # noqa: F403, F401 3 | from numba.core.extending import _Intrinsic # noqa: F401 4 | -------------------------------------------------------------------------------- /numba/misc/POST.py: -------------------------------------------------------------------------------- 1 | """ Numba's POWER ON SELF TEST script. Used by CI to check: 2 | 0. That Numba imports ok! 3 | 1. That Numba can find an appropriate number of its own tests to run. 4 | 2. That Numba can manage to correctly compile and execute at least one thing. 5 | """ 6 | from numba.tests import test_runtests 7 | from numba import njit 8 | 9 | 10 | def _check_runtests(): 11 | test_inst = test_runtests.TestCase() 12 | test_inst.test_default() # will raise an exception if there is a problem 13 | 14 | 15 | def _check_cpu_compilation(): 16 | @njit 17 | def foo(x): 18 | return x + 1 19 | 20 | result = foo(1) 21 | 22 | if result != 2: 23 | msg = ("Unexpected result from trial compilation. " 24 | f"Expected: 2, Got: {result}.") 25 | raise AssertionError(msg) 26 | 27 | 28 | def check(): 29 | _check_runtests() 30 | _check_cpu_compilation() 31 | 32 | 33 | if __name__ == "__main__": 34 | check() 35 | -------------------------------------------------------------------------------- /numba/misc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/misc/__init__.py -------------------------------------------------------------------------------- /numba/misc/cffiimpl.py: -------------------------------------------------------------------------------- 1 | """ 2 | Implementation of some CFFI functions 3 | """ 4 | 5 | 6 | from numba.core.imputils import Registry 7 | from numba.core import types 8 | from numba.np import arrayobj 9 | 10 | registry = Registry('cffiimpl') 11 | 12 | @registry.lower('ffi.from_buffer', types.Buffer) 13 | def from_buffer(context, builder, sig, args): 14 | assert len(sig.args) == 1 15 | assert len(args) == 1 16 | [fromty] = sig.args 17 | [val] = args 18 | # Type inference should have prevented passing a buffer from an 19 | # array to a pointer of the wrong type 20 | assert fromty.dtype == sig.return_type.dtype 21 | ary = arrayobj.make_array(fromty)(context, builder, val) 22 | return ary.data 23 | -------------------------------------------------------------------------------- /numba/misc/cmdlang.gdb: -------------------------------------------------------------------------------- 1 | # this file is used with the numba.gdb* functionality 2 | break numba_gdb_breakpoint 3 | commands 4 | return 5 | end 6 | -------------------------------------------------------------------------------- /numba/misc/help/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/misc/help/__init__.py -------------------------------------------------------------------------------- /numba/misc/init_utils.py: -------------------------------------------------------------------------------- 1 | """Collection of miscellaneous initialization utilities.""" 2 | 3 | from collections import namedtuple 4 | 5 | version_info = namedtuple('version_info', 6 | ('major minor patch short full ' 7 | 'string tuple git_revision')) 8 | 9 | 10 | def generate_version_info(version): 11 | """Process a version string into a structured version_info object. 12 | 13 | Parameters 14 | ---------- 15 | version: str 16 | a string describing the current version 17 | 18 | Returns 19 | ------- 20 | version_info: tuple 21 | structured version information 22 | 23 | See also 24 | -------- 25 | Look at the definition of 'version_info' in this module for details. 26 | 27 | """ 28 | parts = version.split('.') 29 | 30 | def try_int(x): 31 | try: 32 | return int(x) 33 | except ValueError: 34 | return None 35 | major = try_int(parts[0]) if len(parts) >= 1 else None 36 | minor = try_int(parts[1]) if len(parts) >= 2 else None 37 | patch = try_int(parts[2]) if len(parts) >= 3 else None 38 | short = (major, minor) 39 | full = (major, minor, patch) 40 | string = version 41 | tup = tuple(parts) 42 | git_revision = tup[3] if len(tup) >= 4 else None 43 | return version_info(major, minor, patch, short, full, string, tup, 44 | git_revision) 45 | -------------------------------------------------------------------------------- /numba/misc/literal.py: -------------------------------------------------------------------------------- 1 | from numba.core.extending import overload 2 | from numba.core import types 3 | from numba.misc.special import literally, literal_unroll 4 | from numba.core.errors import TypingError 5 | 6 | 7 | @overload(literally) 8 | def _ov_literally(obj): 9 | if isinstance(obj, (types.Literal, types.InitialValue)): 10 | return lambda obj: obj 11 | else: 12 | m = "Invalid use of non-Literal type in literally({})".format(obj) 13 | raise TypingError(m) 14 | 15 | 16 | @overload(literal_unroll) 17 | def literal_unroll_impl(container): 18 | if isinstance(container, types.Poison): 19 | m = f"Invalid use of non-Literal type in literal_unroll({container})" 20 | raise TypingError(m) 21 | 22 | def impl(container): 23 | return container 24 | return impl 25 | -------------------------------------------------------------------------------- /numba/np/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/np/__init__.py -------------------------------------------------------------------------------- /numba/np/arraymath.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: 6 | sys.modules[__name__] = _RedirectSubpackage(locals(), 7 | "numba.np.old_arraymath") 8 | else: 9 | sys.modules[__name__] = _RedirectSubpackage(locals(), 10 | "numba.np.new_arraymath") 11 | -------------------------------------------------------------------------------- /numba/np/extensions.py: -------------------------------------------------------------------------------- 1 | """ 2 | NumPy extensions. 3 | """ 4 | 5 | from numba.np.arraymath import cross2d 6 | 7 | 8 | __all__ = [ 9 | 'cross2d' 10 | ] 11 | -------------------------------------------------------------------------------- /numba/np/math/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/np/math/__init__.py -------------------------------------------------------------------------------- /numba/np/polynomial/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/np/polynomial/__init__.py -------------------------------------------------------------------------------- /numba/np/random/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/np/random/__init__.py -------------------------------------------------------------------------------- /numba/np/random/distributions.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: 6 | sys.modules[__name__] = \ 7 | _RedirectSubpackage(locals(), 8 | "numba.np.random.old_distributions") 9 | else: 10 | sys.modules[__name__] = \ 11 | _RedirectSubpackage(locals(), 12 | "numba.np.random.new_distributions") 13 | -------------------------------------------------------------------------------- /numba/np/random/random_methods.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | from numba.core import config 4 | 5 | if config.USE_LEGACY_TYPE_SYSTEM: 6 | sys.modules[__name__] = \ 7 | _RedirectSubpackage(locals(), 8 | "numba.np.random.old_random_methods") 9 | else: 10 | sys.modules[__name__] = \ 11 | _RedirectSubpackage(locals(), 12 | "numba.np.random.new_random_methods") 13 | -------------------------------------------------------------------------------- /numba/np/ufunc/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize 4 | from numba.np.ufunc._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One 5 | from numba.np.ufunc import _internal, array_exprs 6 | from numba.np.ufunc.parallel import (threading_layer, get_num_threads, 7 | set_num_threads, get_thread_id, 8 | set_parallel_chunksize, 9 | get_parallel_chunksize) 10 | 11 | 12 | if hasattr(_internal, 'PyUFunc_ReorderableNone'): 13 | PyUFunc_ReorderableNone = _internal.PyUFunc_ReorderableNone 14 | del _internal, array_exprs 15 | 16 | 17 | def _init(): 18 | 19 | def init_cuda_vectorize(): 20 | from numba.cuda.vectorizers import CUDAVectorize 21 | return CUDAVectorize 22 | 23 | def init_cuda_guvectorize(): 24 | from numba.cuda.vectorizers import CUDAGUFuncVectorize 25 | return CUDAGUFuncVectorize 26 | 27 | Vectorize.target_registry.ondemand['cuda'] = init_cuda_vectorize 28 | GUVectorize.target_registry.ondemand['cuda'] = init_cuda_guvectorize 29 | 30 | 31 | _init() 32 | del _init 33 | -------------------------------------------------------------------------------- /numba/np/ufunc/_internal.h: -------------------------------------------------------------------------------- 1 | /* Python include */ 2 | 3 | #ifndef NUMBA_UFUNC_INTERNAL_H_ 4 | #define NUMBA_UFUNC_INTERNAL_H_ 5 | 6 | #include "../../_pymodule.h" 7 | #include 8 | 9 | #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 10 | #include "numpy/ndarrayobject.h" 11 | #include "numpy/ufuncobject.h" 12 | 13 | extern PyObject *ufunc_fromfunc(PyObject *NPY_UNUSED(dummy), PyObject *args); 14 | 15 | int PyUFunc_GeneralizedFunction(PyUFuncObject *ufunc, 16 | PyObject *args, PyObject *kwds, 17 | PyArrayObject **op); 18 | 19 | #define APPEND_(X, Y) X #Y 20 | #define APPEND(X, Y) APPEND_(X, Y) 21 | #define SENTRY_VALID_LONG(X) if( (X) == -1 ){ \ 22 | PyErr_SetString(PyExc_RuntimeError, \ 23 | APPEND("PyLong_AsLong overflow at ", __LINE__)); \ 24 | return NULL; \ 25 | } 26 | 27 | #endif /* NUMBA_UFUNC_INTERNAL_H_ */ -------------------------------------------------------------------------------- /numba/np/ufunc/_num_threads.c: -------------------------------------------------------------------------------- 1 | // Thread local num_threads variable for masking out the total number of 2 | // launched threads. 3 | 4 | #include "../../_pymodule.h" 5 | 6 | #ifdef _MSC_VER 7 | #define THREAD_LOCAL(ty) __declspec(thread) ty 8 | #else 9 | /* Non-standard C99 extension that's understood by gcc and clang */ 10 | #define THREAD_LOCAL(ty) __thread ty 11 | #endif 12 | 13 | static THREAD_LOCAL(int) num_threads = 0; 14 | 15 | static void set_num_threads(int count) 16 | { 17 | num_threads = count; 18 | } 19 | 20 | static int get_num_threads(void) 21 | { 22 | return num_threads; 23 | } 24 | 25 | MOD_INIT(_num_threads) 26 | { 27 | PyObject *m; 28 | MOD_DEF(m, "_num_threads", "No docs", NULL) 29 | if (m == NULL) 30 | return MOD_ERROR_VAL; 31 | 32 | SetAttrStringFromVoidPointer(m, set_num_threads); 33 | SetAttrStringFromVoidPointer(m, get_num_threads); 34 | 35 | return MOD_SUCCESS_VAL(m); 36 | } 37 | -------------------------------------------------------------------------------- /numba/np/ufunc/gufunc_scheduler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Intel Corporation 3 | * SPDX-License-Identifier: BSD-2-Clause 4 | */ 5 | 6 | #ifndef GUFUNC_SCHEDULER 7 | #define GUFUNC_SCHEDULER 8 | 9 | /* define int64_t and uint64_t for Visual Studio, where stdint only available > VS2008 */ 10 | #ifdef _MSC_VER 11 | #define int64_t signed __int64 12 | #define uint64_t unsigned __int64 13 | #else 14 | #include 15 | #endif 16 | 17 | #ifndef __SIZEOF_POINTER__ 18 | /* MSVC doesn't define __SIZEOF_POINTER__ */ 19 | #if defined(_WIN64) 20 | #define intp int64_t 21 | #define uintp uint64_t 22 | #elif defined(_WIN32) 23 | #define intp int 24 | #define uintp unsigned 25 | #else 26 | #error "cannot determine size of intp" 27 | #endif 28 | #elif __SIZEOF_POINTER__ == 8 29 | #define intp int64_t 30 | #define uintp uint64_t 31 | #else 32 | #define intp int 33 | #define uintp unsigned 34 | #endif 35 | 36 | #ifdef __cplusplus 37 | extern "C" 38 | { 39 | #endif 40 | 41 | void do_scheduling_signed(uintp num_dim, intp *starts, intp *ends, uintp num_threads, intp *sched, intp debug); 42 | void do_scheduling_unsigned(uintp num_dim, intp *starts, intp *ends, uintp num_threads, uintp *sched, intp debug); 43 | uintp set_parallel_chunksize(uintp); 44 | uintp get_parallel_chunksize(void); 45 | uintp get_sched_size(uintp num_threads, uintp num_dim, intp *starts, intp *ends); 46 | intp * allocate_sched(uintp sched_size); 47 | void deallocate_sched(intp * sched); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /numba/np/unsafe/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/np/unsafe/__init__.py -------------------------------------------------------------------------------- /numba/parfors/__init__.py: -------------------------------------------------------------------------------- 1 | from numba.parfors import parfor_lowering 2 | -------------------------------------------------------------------------------- /numba/pycc/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import warnings 4 | from numba.core.errors import NumbaPendingDeprecationWarning 5 | # The pycc module requires setuptools. 6 | try: 7 | import setuptools 8 | except ImportError: 9 | msg = "The 'setuptools' package is required at runtime for pycc support." 10 | raise ImportError(msg) 11 | 12 | # Public API 13 | from .cc import CC 14 | from .decorators import export, exportmany 15 | 16 | # If use of anything is attempted through the `pycc` import path this warning 17 | # will be shown. 18 | __pycc_deprecation_doc_url = ("https://numba.readthedocs.io/en/stable/" 19 | "reference/deprecation.html" 20 | "#deprecation-of-the-numba-pycc-module") 21 | __pycc_pending_deprecation_message = ("The 'pycc' module is pending " 22 | "deprecation. Replacement technology is " 23 | "being developed.\n\n" 24 | "Pending Deprecation in Numba 0.57.0. " 25 | "For more information please see: " 26 | f"{__pycc_deprecation_doc_url}") 27 | 28 | _pend_dep = NumbaPendingDeprecationWarning(__pycc_pending_deprecation_message) 29 | warnings.warn(_pend_dep, stacklevel=2) 30 | -------------------------------------------------------------------------------- /numba/pycc/llvm_types.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import ctypes 3 | import struct as struct_ 4 | import llvmlite.ir 5 | from llvmlite.ir import Constant 6 | 7 | _trace_refs_ = hasattr(sys, 'getobjects') 8 | _plat_bits = struct_.calcsize('@P') * 8 9 | 10 | _int8 = llvmlite.ir.IntType(8) 11 | _int32 = llvmlite.ir.IntType(32) 12 | 13 | _void_star = llvmlite.ir.PointerType(_int8) 14 | 15 | _int8_star = _void_star 16 | 17 | _sizeof_py_ssize_t = ctypes.sizeof(getattr(ctypes, 'c_size_t')) 18 | _llvm_py_ssize_t = llvmlite.ir.IntType(_sizeof_py_ssize_t * 8) 19 | 20 | if _trace_refs_: 21 | _pyobject_head = llvmlite.ir.LiteralStructType([_void_star, _void_star, 22 | _llvm_py_ssize_t, _void_star]) 23 | _pyobject_head_init = Constant.literal_struct([ 24 | Constant(_void_star, None), # _ob_next 25 | Constant(_void_star, None), # _ob_prev 26 | Constant(_llvm_py_ssize_t, 1), # ob_refcnt 27 | Constant(_void_star, None), # ob_type 28 | ]) 29 | 30 | else: 31 | _pyobject_head = llvmlite.ir.LiteralStructType([_llvm_py_ssize_t, _void_star]) 32 | _pyobject_head_init = Constant.literal_struct([ 33 | Constant(_llvm_py_ssize_t, 1), # ob_refcnt 34 | Constant(_void_star, None), # ob_type 35 | ]) 36 | 37 | _pyobject_head_p = llvmlite.ir.PointerType(_pyobject_head) 38 | -------------------------------------------------------------------------------- /numba/runtests.py: -------------------------------------------------------------------------------- 1 | from numba.testing._runtests import _main 2 | 3 | 4 | if __name__ == '__main__': 5 | import sys 6 | # For parallel testing under Windows 7 | from multiprocessing import freeze_support 8 | freeze_support() 9 | sys.exit(0 if _main(sys.argv) else 1) 10 | -------------------------------------------------------------------------------- /numba/scripts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/scripts/__init__.py -------------------------------------------------------------------------------- /numba/stencils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/stencils/__init__.py -------------------------------------------------------------------------------- /numba/testing/__main__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.testing import run_tests 3 | 4 | sys.exit(0 if run_tests(sys.argv).wasSuccessful() else 1) 5 | -------------------------------------------------------------------------------- /numba/testing/loader.py: -------------------------------------------------------------------------------- 1 | from unittest import loader, case 2 | from os.path import isdir, isfile, join, dirname, basename 3 | 4 | 5 | class TestLoader(loader.TestLoader): 6 | 7 | def __init__(self, topleveldir=None): 8 | super(TestLoader, self).__init__() 9 | self._top_level_dir = topleveldir or dirname(dirname(dirname(__file__))) 10 | 11 | def _find_tests(self, start_dir, pattern, namespace=False): 12 | # Upstream doesn't look for 'load_tests' in start_dir. 13 | 14 | if isdir(start_dir) and not namespace and isfile(join(start_dir, '__init__.py')): 15 | name = self._get_name_from_path(start_dir) 16 | package = self._get_module_from_name(name) 17 | load_tests = getattr(package, 'load_tests', None) 18 | tests = self.loadTestsFromModule(package) 19 | if load_tests is not None: 20 | try: 21 | yield load_tests(self, tests, pattern) 22 | except Exception as e: 23 | yield loader._make_failed_load_tests(package.__name__, e, self.suiteClass) 24 | else: 25 | for t in super(TestLoader, self)._find_tests(start_dir, pattern): 26 | yield t 27 | -------------------------------------------------------------------------------- /numba/tests/__init__.py: -------------------------------------------------------------------------------- 1 | import gc 2 | from os.path import dirname, join 3 | import multiprocessing 4 | import sys 5 | import time 6 | import unittest 7 | import warnings 8 | 9 | from unittest.suite import TestSuite 10 | from numba.testing import load_testsuite 11 | 12 | 13 | try: 14 | import faulthandler 15 | except ImportError: 16 | faulthandler = None 17 | else: 18 | try: 19 | # May fail in IPython Notebook with UnsupportedOperation 20 | faulthandler.enable() 21 | except Exception as e: 22 | msg = "Failed to enable faulthandler due to:\n{err}" 23 | warnings.warn(msg.format(err=e)) 24 | 25 | def load_tests(loader, tests, pattern): 26 | suite = TestSuite() 27 | suite.addTests(load_testsuite(loader, dirname(__file__))) 28 | # Numba CUDA tests are located in a separate directory: 29 | cuda_dir = join(dirname(dirname(__file__)), 'cuda/tests') 30 | suite.addTests(loader.discover(cuda_dir)) 31 | 32 | return suite 33 | 34 | -------------------------------------------------------------------------------- /numba/tests/annotation_usecases.py: -------------------------------------------------------------------------------- 1 | """ 2 | Usecases with Python 3 function annotations. This is a separate module 3 | in order to avoid syntax errors with Python 2. 4 | """ 5 | 6 | 7 | class AnnotatedClass: 8 | """ 9 | A class with annotated methods. 10 | """ 11 | 12 | def __init__(self, v: int): 13 | self.x = v 14 | 15 | def add(self, v: int) -> int: 16 | return self.x + v 17 | -------------------------------------------------------------------------------- /numba/tests/chained_assign_usecases.py: -------------------------------------------------------------------------------- 1 | from numba import jit 2 | import numpy as np 3 | 4 | 5 | @jit 6 | def inc(a): 7 | for i in range(len(a)): 8 | a[i] += 1 9 | return a 10 | 11 | 12 | @jit 13 | def inc1(a): 14 | a[0] += 1 15 | return a[0] 16 | 17 | 18 | @jit 19 | def inc2(a): 20 | a[0] += 1 21 | return a[0], a[0] + 1 22 | 23 | 24 | def chain1(a): 25 | x = y = z = inc(a) 26 | return x + y + z 27 | 28 | 29 | def chain2(v): 30 | a = np.zeros(2) 31 | a[0] = x = a[1] = v 32 | return a[0] + a[1] + (x / 2) 33 | 34 | 35 | def unpack1(x, y): 36 | a, b = x, y 37 | return a + b / 2 38 | 39 | 40 | def unpack2(x, y): 41 | a, b = c, d = inc1(x), inc1(y) 42 | return a + c / 2, b + d / 2 43 | 44 | 45 | def chain3(x, y): 46 | a = (b, c) = (inc1(x), inc1(y)) 47 | (d, e) = f = (inc1(x), inc1(y)) 48 | return (a[0] + b / 2 + d + f[0]), (a[1] + c + e / 2 + f[1]) 49 | 50 | 51 | def unpack3(x): 52 | a, b = inc2(x) 53 | return a + b / 2 54 | 55 | 56 | def unpack4(x): 57 | a, b = c, d = inc2(x) 58 | return a + c / 2, b + d / 2 59 | 60 | 61 | def unpack5(x): 62 | a = b, c = inc2(x) 63 | d, e = f = inc2(x) 64 | return (a[0] + b / 2 + d + f[0]), (a[1] + c + e / 2 + f[1]) 65 | 66 | 67 | def unpack6(x, y): 68 | (a, b), (c, d) = (x, y), (y + 1, x + 1) 69 | return a + c / 2, b / 2 + d 70 | -------------------------------------------------------------------------------- /numba/tests/cloudpickle_main_class.py: -------------------------------------------------------------------------------- 1 | # Expected to run this module as __main__ 2 | 3 | 4 | # Cloudpickle will think this is a dynamic class when this module is __main__ 5 | class Klass: 6 | classvar = None 7 | -------------------------------------------------------------------------------- /numba/tests/doc_examples/__init__.py: -------------------------------------------------------------------------------- 1 | from os.path import dirname 2 | import unittest 3 | from unittest.suite import TestSuite 4 | 5 | from numba.testing import load_testsuite 6 | 7 | def load_tests(loader, tests, pattern): 8 | suite = TestSuite() 9 | suite.addTests(load_testsuite(loader, dirname(__file__))) 10 | return suite 11 | -------------------------------------------------------------------------------- /numba/tests/doc_examples/test_llvm_pass_timings.py: -------------------------------------------------------------------------------- 1 | # "magictoken" is used for markers as beginning and ending of example text. 2 | 3 | import unittest 4 | from numba.tests.support import captured_stdout, override_config 5 | 6 | 7 | class DocsLLVMPassTimings(unittest.TestCase): 8 | 9 | def test_pass_timings(self): 10 | with override_config('LLVM_PASS_TIMINGS', True): 11 | with captured_stdout() as stdout: 12 | # magictoken.ex_llvm_pass_timings.begin 13 | import numba 14 | 15 | @numba.njit 16 | def foo(n): 17 | c = 0 18 | for i in range(n): 19 | for j in range(i): 20 | c += j 21 | return c 22 | 23 | foo(10) 24 | md = foo.get_metadata(foo.signatures[0]) 25 | print(md['llvm_pass_timings']) 26 | # magictoken.ex_llvm_pass_timings.end 27 | self.assertIn("Finalize object", stdout.getvalue()) 28 | 29 | 30 | if __name__ == '__main__': 31 | unittest.main() 32 | -------------------------------------------------------------------------------- /numba/tests/doc_examples/test_numpy_generators.py: -------------------------------------------------------------------------------- 1 | # "magictoken" is used for markers as beginning and ending of example text. 2 | 3 | import unittest 4 | import numpy as np 5 | import numba 6 | 7 | 8 | class NumpyGeneratorUsageTest(unittest.TestCase): 9 | 10 | def test_numpy_gen_usage(self): 11 | # magictoken.npgen_usage.begin 12 | x = np.random.default_rng(1) 13 | y = np.random.default_rng(1) 14 | 15 | size = 10 16 | 17 | @numba.njit 18 | def do_stuff(gen): 19 | return gen.random(size=int(size / 2)) 20 | 21 | original = x.random(size=size) 22 | # [0.51182162 0.9504637 0.14415961 0.94864945 0.31183145 23 | # 0.42332645 0.82770259 0.40919914 0.54959369 0.02755911] 24 | 25 | numba_func_res = do_stuff(y) 26 | # [0.51182162 0.9504637 0.14415961 0.94864945 0.31183145] 27 | 28 | after_numba = y.random(size=int(size / 2)) 29 | # [0.42332645 0.82770259 0.40919914 0.54959369 0.02755911] 30 | 31 | # magictoken.npgen_usage.end 32 | numba_res = np.concatenate((numba_func_res, after_numba)) 33 | for _np_res, _nb_res in zip(original, numba_res): 34 | self.assertEqual(_np_res, _nb_res) 35 | 36 | 37 | if __name__ == '__main__': 38 | unittest.main() 39 | -------------------------------------------------------------------------------- /numba/tests/doc_examples/test_rec_array.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestExample(unittest.TestCase): 5 | 6 | def test_documentation_example1(self): 7 | # magictoken.ex_rec_arr_const_index.begin 8 | import numpy as np 9 | from numba import njit 10 | 11 | arr = np.array([(1, 2)], dtype=[('a1', 'f8'), ('a2', 'f8')]) 12 | fields_gl = ('a1', 'a2') 13 | 14 | @njit 15 | def get_field_sum(rec): 16 | fields_lc = ('a1', 'a2') 17 | field_name1 = fields_lc[0] 18 | field_name2 = fields_gl[1] 19 | return rec[field_name1] + rec[field_name2] 20 | 21 | get_field_sum(arr[0]) # returns 3 22 | # magictoken.ex_rec_arr_const_index.end 23 | self.assertEqual(get_field_sum(arr[0]), 3) 24 | 25 | def test_documentation_example2(self): 26 | # magictoken.ex_rec_arr_lit_unroll_index.begin 27 | import numpy as np 28 | from numba import njit, literal_unroll 29 | 30 | arr = np.array([(1, 2)], dtype=[('a1', 'f8'), ('a2', 'f8')]) 31 | fields_gl = ('a1', 'a2') 32 | 33 | @njit 34 | def get_field_sum(rec): 35 | out = 0 36 | for f in literal_unroll(fields_gl): 37 | out += rec[f] 38 | return out 39 | 40 | get_field_sum(arr[0]) # returns 3 41 | # magictoken.ex_rec_arr_lit_unroll_index.end 42 | self.assertEqual(get_field_sum(arr[0]), 3) 43 | 44 | 45 | if __name__ == '__main__': 46 | unittest.main() 47 | -------------------------------------------------------------------------------- /numba/tests/doctest_usecase.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test that all docstrings are the same: 3 | 4 | >>> len({f.__doc__ for f in (a, b, c, d)}) 5 | 1 6 | """ 7 | from numba import guvectorize, int64, njit, vectorize 8 | 9 | 10 | def a(): 11 | """>>> x = 1""" 12 | return 1 13 | 14 | 15 | @njit 16 | def b(): 17 | """>>> x = 1""" 18 | return 1 19 | 20 | 21 | @guvectorize([(int64[:], int64, int64[:])], "(n),()->(n)") 22 | def c(x, y, res): 23 | """>>> x = 1""" 24 | for i in range(x.shape[0]): 25 | res[i] = x[i] + y 26 | 27 | 28 | @vectorize([int64(int64, int64)]) 29 | def d(x, y): 30 | """>>> x = 1""" 31 | return x + y 32 | -------------------------------------------------------------------------------- /numba/tests/dummy_module.py: -------------------------------------------------------------------------------- 1 | '''Dummy module''' 2 | 3 | def function(): 4 | '''Do nothing''' 5 | -------------------------------------------------------------------------------- /numba/tests/enum_usecases.py: -------------------------------------------------------------------------------- 1 | from enum import Enum, IntEnum 2 | 3 | 4 | class Color(Enum): 5 | red = 1 6 | green = 2 7 | blue = 3 8 | 9 | 10 | class Shake(Enum): 11 | vanilla = 7 12 | chocolate = 4 13 | cookies = 9 14 | # Same as Color.blue 15 | mint = 3 16 | 17 | 18 | class Planet(Enum): 19 | MERCURY = (3.303e+23, 2.4397e6) 20 | VENUS = (4.869e+24, 6.0518e6) 21 | EARTH = (5.976e+24, 6.37814e6) 22 | MARS = (6.421e+23, 3.3972e6) 23 | JUPITER = (1.9e+27, 7.1492e7) 24 | SATURN = (5.688e+26, 6.0268e7) 25 | URANUS = (8.686e+25, 2.5559e7) 26 | NEPTUNE = (1.024e+26, 2.4746e7) 27 | 28 | 29 | class HeterogeneousEnum(Enum): 30 | red = 1.0 31 | green = 2.0 32 | blue = 3j 33 | 34 | 35 | class Shape(IntEnum): 36 | # Same as Color.green 37 | circle = 2 38 | # Same as RequestError.internal_error 39 | square = 500 40 | 41 | 42 | class RequestError(IntEnum): 43 | dummy = 2 44 | not_found = 404 45 | internal_error = 500 46 | 47 | class IntEnumWithNegatives(IntEnum): 48 | # Used for testing of hash, need to make sure -1 -> -2 to comply with CPy 49 | one = 1 50 | two = 2 51 | too = 2 52 | three = 3 53 | negone = -1 54 | negtwo = -2 55 | negthree = -3 56 | -------------------------------------------------------------------------------- /numba/tests/error_usecases.py: -------------------------------------------------------------------------------- 1 | import numba as nb 2 | 3 | 4 | @nb.jit(nopython=True, parallel=True) 5 | def foo(): 6 | pass 7 | -------------------------------------------------------------------------------- /numba/tests/errorhandling_usecases.py: -------------------------------------------------------------------------------- 1 | from numba import typed, int64 2 | 3 | # used in TestMiscErrorHandling::test_handling_of_write_to_*_global 4 | _global_list = [1, 2, 3, 4] 5 | 6 | _global_dict = typed.Dict.empty(int64, int64) 7 | 8 | 9 | def global_reflected_write(): 10 | _global_list[0] = 10 11 | 12 | 13 | def global_dict_write(): 14 | _global_dict[0] = 10 15 | -------------------------------------------------------------------------------- /numba/tests/gdb/__init__.py: -------------------------------------------------------------------------------- 1 | from os.path import dirname 2 | import unittest 3 | from unittest.suite import TestSuite 4 | 5 | from numba.testing import load_testsuite 6 | 7 | def load_tests(loader, tests, pattern): 8 | suite = TestSuite() 9 | suite.addTests(load_testsuite(loader, dirname(__file__))) 10 | return suite 11 | -------------------------------------------------------------------------------- /numba/tests/gdb/test_basic.py: -------------------------------------------------------------------------------- 1 | # NOTE: This test is sensitive to line numbers as it checks breakpoints 2 | from numba import njit, types 3 | from numba.tests.gdb_support import GdbMIDriver 4 | from numba.tests.support import TestCase, needs_subprocess 5 | import unittest 6 | 7 | 8 | @needs_subprocess 9 | class Test(TestCase): 10 | 11 | def test(self): 12 | @njit(debug=True) 13 | def foo(x): 14 | z = 7 + x # break here 15 | return x, z 16 | 17 | foo(120) 18 | 19 | sz = types.intp.bitwidth 20 | driver = GdbMIDriver(__file__) 21 | driver.set_breakpoint(line=14) 22 | driver.run() 23 | driver.check_hit_breakpoint(1) 24 | driver.stack_list_arguments(2) 25 | expect = ('[frame={level="0",args=[{name="x",type="int%s",' 26 | 'value="120"}]}]' % sz) 27 | driver.assert_output(expect) 28 | driver.stack_list_variables(1) 29 | expect = '[{name="x",arg="1",value="120"},{name="z",value="0"}]' 30 | driver.assert_output(expect) 31 | driver.next() 32 | driver.stack_list_variables(1) 33 | expect = '[{name="x",arg="1",value="120"},{name="z",value="127"}]' 34 | driver.assert_output(expect) 35 | driver.quit() 36 | 37 | 38 | if __name__ == '__main__': 39 | unittest.main() 40 | -------------------------------------------------------------------------------- /numba/tests/gdb/test_break_on_symbol.py: -------------------------------------------------------------------------------- 1 | # NOTE: This test is sensitive to line numbers as it checks breakpoints 2 | from numba import njit, types 3 | from numba.tests.gdb_support import GdbMIDriver 4 | from numba.tests.support import TestCase, needs_subprocess 5 | import unittest 6 | 7 | 8 | @njit(debug=True) 9 | def foo(x): 10 | z = 7 + x 11 | return x, z 12 | 13 | 14 | @needs_subprocess 15 | class Test(TestCase): 16 | 17 | def test(self): 18 | foo(120) 19 | sz = types.intp.bitwidth 20 | driver = GdbMIDriver(__file__) 21 | driver.set_breakpoint(symbol="__main__::foo") 22 | driver.run() # will hit cpython symbol match 23 | driver.check_hit_breakpoint(number=1) 24 | driver.cont() # will hit njit symbol match 25 | driver.check_hit_breakpoint(number=1, line=10) # Ensure line number 26 | driver.stack_list_arguments(2) 27 | expect = ('[frame={level="0",args=[{name="x",type="int%s",' 28 | 'value="120"}]}]' % sz) 29 | driver.assert_output(expect) 30 | driver.quit() 31 | 32 | 33 | if __name__ == '__main__': 34 | unittest.main() 35 | -------------------------------------------------------------------------------- /numba/tests/gdb/test_conditional_breakpoint.py: -------------------------------------------------------------------------------- 1 | # NOTE: This test is sensitive to line numbers as it checks breakpoints 2 | from numba import njit 3 | from numba.tests.gdb_support import GdbMIDriver 4 | from numba.tests.support import TestCase, needs_subprocess 5 | import unittest 6 | 7 | 8 | @needs_subprocess 9 | class Test(TestCase): 10 | 11 | def test(self): 12 | 13 | @njit(debug=True) 14 | def foo(x, y): 15 | c = x + y # break-here 16 | return c 17 | 18 | @njit(debug=True) 19 | def call_foo(a): 20 | acc = 0 21 | for i in range(10): 22 | acc += foo(i, a) 23 | return acc 24 | 25 | call_foo(10) 26 | 27 | driver = GdbMIDriver(__file__) 28 | driver.set_breakpoint(line=15, condition='x == 4') 29 | driver.run() 30 | driver.check_hit_breakpoint(1) 31 | driver.stack_list_arguments(1) 32 | expect = ('[frame={level="0",args=[{name="x",value="4"},' 33 | '{name="y",value="10"}]}]') 34 | driver.assert_output(expect) 35 | driver.set_breakpoint(line=22, condition='i == 8') 36 | driver.cont() 37 | driver.check_hit_breakpoint(2) 38 | driver.stack_list_variables(1) 39 | # i should be 8 40 | driver.assert_output('{name="i",value="8"}') 41 | driver.quit() 42 | 43 | 44 | if __name__ == '__main__': 45 | unittest.main() 46 | -------------------------------------------------------------------------------- /numba/tests/inlining_usecases.py: -------------------------------------------------------------------------------- 1 | """ Test cases for inlining IR from another module """ 2 | from numba import jit, njit 3 | from numba.core import types 4 | from numba.core.extending import overload 5 | 6 | _GLOBAL1 = 100 7 | 8 | 9 | @njit(inline='always') 10 | def bar(): 11 | return _GLOBAL1 + 10 12 | 13 | 14 | def baz_factory(a): 15 | b = 17 + a 16 | 17 | @njit(inline='always') 18 | def baz(): 19 | return _GLOBAL1 + a - b 20 | return baz 21 | 22 | 23 | def baz(): 24 | return _GLOBAL1 + 10 25 | 26 | 27 | @overload(baz, inline='always') 28 | def baz_ol(): 29 | def impl(): 30 | return _GLOBAL1 + 10 31 | return impl 32 | 33 | 34 | def bop_factory(a): 35 | b = 17 + a 36 | 37 | def bop(): 38 | return _GLOBAL1 + a - b 39 | 40 | @overload(bop, inline='always') 41 | def baz(): 42 | def impl(): 43 | return _GLOBAL1 + a - b 44 | return impl 45 | 46 | return bop 47 | 48 | 49 | @jit((types.int32,), nopython=True) 50 | def inner(a): 51 | return a + 1 52 | 53 | 54 | @jit((types.int32,), nopython=True) 55 | def more(a): 56 | return inner(inner(a)) 57 | 58 | 59 | def outer_simple(a): 60 | return inner(a) * 2 61 | 62 | 63 | def outer_multiple(a): 64 | return inner(a) * more(a) 65 | 66 | 67 | @njit 68 | def __dummy__(): 69 | return 70 | -------------------------------------------------------------------------------- /numba/tests/matmul_usecase.py: -------------------------------------------------------------------------------- 1 | """Use cases for testing matmul (@) 2 | """ 3 | def matmul_usecase(x, y): 4 | return x @ y 5 | 6 | def imatmul_usecase(x, y): 7 | x @= y 8 | return x 9 | 10 | class DumbMatrix(object): 11 | 12 | def __init__(self, value): 13 | self.value = value 14 | 15 | def __matmul__(self, other): 16 | if isinstance(other, DumbMatrix): 17 | return DumbMatrix(self.value * other.value) 18 | return NotImplemented 19 | 20 | def __imatmul__(self, other): 21 | if isinstance(other, DumbMatrix): 22 | self.value *= other.value 23 | return self 24 | return NotImplemented 25 | -------------------------------------------------------------------------------- /numba/tests/npyufunc/__init__.py: -------------------------------------------------------------------------------- 1 | from os.path import dirname 2 | import unittest 3 | from unittest.suite import TestSuite 4 | 5 | from numba.testing import load_testsuite 6 | 7 | def load_tests(loader, tests, pattern): 8 | suite = TestSuite() 9 | suite.addTests(load_testsuite(loader, dirname(__file__))) 10 | return suite 11 | -------------------------------------------------------------------------------- /numba/tests/npyufunc/test_parallel_env_variable.py: -------------------------------------------------------------------------------- 1 | from numba.np.ufunc.parallel import get_thread_count 2 | from os import environ as env 3 | from numba.core import config 4 | import unittest 5 | 6 | 7 | class TestParallelEnvVariable(unittest.TestCase): 8 | """ 9 | Tests environment variables related to the underlying "parallel" 10 | functions for npyufuncs. 11 | """ 12 | 13 | _numba_parallel_test_ = False 14 | 15 | def test_num_threads_variable(self): 16 | """ 17 | Tests the NUMBA_NUM_THREADS env variable behaves as expected. 18 | """ 19 | key = 'NUMBA_NUM_THREADS' 20 | current = str(getattr(env, key, config.NUMBA_NUM_THREADS)) 21 | threads = "3154" 22 | env[key] = threads 23 | try: 24 | config.reload_config() 25 | except RuntimeError as e: 26 | # This test should fail if threads have already been launched 27 | self.assertIn("Cannot set NUMBA_NUM_THREADS", e.args[0]) 28 | else: 29 | self.assertEqual(threads, str(get_thread_count())) 30 | self.assertEqual(threads, str(config.NUMBA_NUM_THREADS)) 31 | finally: 32 | # reset the env variable/set to default. Should not fail even if 33 | # threads are launched because the value is the same. 34 | env[key] = current 35 | config.reload_config() 36 | 37 | if __name__ == '__main__': 38 | unittest.main() 39 | -------------------------------------------------------------------------------- /numba/tests/npyufunc/test_parallel_low_work.py: -------------------------------------------------------------------------------- 1 | """ 2 | There was a deadlock problem when work count is smaller than number of threads. 3 | """ 4 | 5 | import numpy as np 6 | 7 | from numba import float32, float64, int32, uint32 8 | from numba.np.ufunc import Vectorize 9 | import unittest 10 | 11 | 12 | def vector_add(a, b): 13 | return a + b 14 | 15 | 16 | class TestParallelLowWorkCount(unittest.TestCase): 17 | 18 | _numba_parallel_test_ = False 19 | 20 | def test_low_workcount(self): 21 | # build parallel native code ufunc 22 | pv = Vectorize(vector_add, target='parallel') 23 | for ty in (int32, uint32, float32, float64): 24 | pv.add(ty(ty, ty)) 25 | para_ufunc = pv.build_ufunc() 26 | 27 | # build python ufunc 28 | np_ufunc = np.vectorize(vector_add) 29 | 30 | # test it out 31 | def test(ty): 32 | data = np.arange(1).astype(ty) # just one item 33 | result = para_ufunc(data, data) 34 | gold = np_ufunc(data, data) 35 | np.testing.assert_allclose(gold, result) 36 | 37 | test(np.double) 38 | test(np.float32) 39 | test(np.int32) 40 | test(np.uint32) 41 | 42 | 43 | if __name__ == '__main__': 44 | unittest.main() 45 | -------------------------------------------------------------------------------- /numba/tests/npyufunc/ufuncbuilding_usecases.py: -------------------------------------------------------------------------------- 1 | from numba import vectorize 2 | 3 | 4 | def add(a, b): 5 | """An addition""" 6 | return a + b 7 | 8 | 9 | def equals(a, b): 10 | return a == b 11 | 12 | 13 | def mul(a, b): 14 | """A multiplication""" 15 | return a * b 16 | 17 | 18 | def guadd(a, b, c): 19 | """A generalized addition""" 20 | x, y = c.shape 21 | for i in range(x): 22 | for j in range(y): 23 | c[i, j] = a[i, j] + b[i, j] 24 | 25 | 26 | @vectorize(nopython=True) 27 | def inner(a, b): 28 | return a + b 29 | 30 | 31 | @vectorize(["int64(int64, int64)"], nopython=True) 32 | def inner_explicit(a, b): 33 | return a + b 34 | 35 | 36 | def outer(a, b): 37 | return inner(a, b) 38 | 39 | 40 | def outer_explicit(a, b): 41 | return inner_explicit(a, b) 42 | 43 | 44 | class Dummy: 45 | pass 46 | 47 | 48 | def guadd_obj(a, b, c): 49 | Dummy() # to force object mode 50 | x, y = c.shape 51 | for i in range(x): 52 | for j in range(y): 53 | c[i, j] = a[i, j] + b[i, j] 54 | 55 | 56 | def guadd_scalar_obj(a, b, c): 57 | Dummy() # to force object mode 58 | x, y = c.shape 59 | for i in range(x): 60 | for j in range(y): 61 | c[i, j] = a[i, j] + b 62 | 63 | 64 | class MyException(Exception): 65 | pass 66 | 67 | 68 | def guerror(a, b, c): 69 | raise MyException 70 | -------------------------------------------------------------------------------- /numba/tests/orphaned_semaphore_usecase.py: -------------------------------------------------------------------------------- 1 | # See issue: https://github.com/numba/numba/issues/4348 2 | # this file must be run in isolation to replicate, test: 3 | # numba.tests.test_parallel_backend.TestInitSafetyIssues.test_orphaned_semaphore 4 | # does this to check semaphores are not leaking. 5 | 6 | import multiprocessing as mp 7 | 8 | import numba # noqa, deliberately unused, here to test import is safe 9 | 10 | 11 | def w(): 12 | pass 13 | 14 | 15 | def main(): 16 | ps = [mp.Process(target=w) for _ in range(4)] 17 | [p.start() for p in ps] 18 | [p.join() for p in ps] 19 | 20 | 21 | if __name__ == '__main__': 22 | p = mp.get_context('spawn').Process(target=main) 23 | p.start() 24 | p.join() 25 | -------------------------------------------------------------------------------- /numba/tests/overload_usecases.py: -------------------------------------------------------------------------------- 1 | # Python 3 syntax only use cases, used in test_extending.py 2 | 3 | # arg name is different, and there's no arg name to match before *args 4 | 5 | 6 | def impl4(z, *args, kw=None): 7 | if z > 10: 8 | return 1 9 | else: 10 | return -1 11 | 12 | # arg name is different but at a detectable location, with *args 13 | 14 | 15 | def impl5(z, b, *args, kw=None): 16 | if z > 10: 17 | return 1 18 | else: 19 | return -1 20 | 21 | 22 | def var_positional_impl(a, *star_args_token, kw=None, kw1=12): 23 | def impl(a, b, f, kw=None, kw1=12): 24 | if a > 10: 25 | return 1 26 | else: 27 | return -1 28 | return impl 29 | -------------------------------------------------------------------------------- /numba/tests/pycc_distutils_usecase/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/tests/pycc_distutils_usecase/__init__.py -------------------------------------------------------------------------------- /numba/tests/pycc_distutils_usecase/nested/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/tests/pycc_distutils_usecase/nested/__init__.py -------------------------------------------------------------------------------- /numba/tests/pycc_distutils_usecase/nested/source_module.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from numba.pycc import CC 4 | 5 | 6 | cc = CC('pycc_compiled_module') 7 | 8 | _const = 42 9 | 10 | 11 | # This ones references a global variable at compile time 12 | @cc.export('get_const', 'i8()') 13 | def get_const(): 14 | return _const 15 | 16 | 17 | # This one needs NRT and an environment 18 | @cc.export('ones', 'f8[:](i4)') 19 | def ones(n): 20 | return np.ones(n) 21 | -------------------------------------------------------------------------------- /numba/tests/pycc_distutils_usecase/setup_distutils.py: -------------------------------------------------------------------------------- 1 | from setuptools import distutils 2 | from source_module import cc 3 | 4 | 5 | setup = distutils.core.setup 6 | 7 | 8 | def run_setup(): 9 | setup(ext_modules=[cc.distutils_extension()]) 10 | 11 | 12 | if __name__ == '__main__': 13 | run_setup() 14 | -------------------------------------------------------------------------------- /numba/tests/pycc_distutils_usecase/setup_distutils_nested.py: -------------------------------------------------------------------------------- 1 | from setuptools import distutils 2 | 3 | from nested.source_module import cc 4 | 5 | 6 | setup = distutils.core.setup 7 | 8 | 9 | def run_setup(): 10 | setup(ext_modules=[cc.distutils_extension()]) 11 | 12 | 13 | if __name__ == '__main__': 14 | run_setup() 15 | -------------------------------------------------------------------------------- /numba/tests/pycc_distutils_usecase/setup_setuptools.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | from source_module import cc 4 | 5 | 6 | def run_setup(): 7 | setup(ext_modules=[cc.distutils_extension()]) 8 | 9 | 10 | if __name__ == '__main__': 11 | run_setup() 12 | -------------------------------------------------------------------------------- /numba/tests/pycc_distutils_usecase/setup_setuptools_nested.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | from nested.source_module import cc 4 | 5 | 6 | def run_setup(): 7 | setup(ext_modules=[cc.distutils_extension()]) 8 | 9 | 10 | if __name__ == '__main__': 11 | run_setup() 12 | -------------------------------------------------------------------------------- /numba/tests/pycc_distutils_usecase/source_module.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from numba.pycc import CC 4 | 5 | 6 | cc = CC('pycc_compiled_module') 7 | 8 | _const = 42 9 | 10 | # This ones references a global variable at compile time 11 | @cc.export('get_const', 'i8()') 12 | def get_const(): 13 | return _const 14 | 15 | # This one needs NRT and an environment 16 | @cc.export('ones', 'f8[:](i4)') 17 | def ones(n): 18 | return np.ones(n) 19 | -------------------------------------------------------------------------------- /numba/tests/test_alignment.py: -------------------------------------------------------------------------------- 1 | # See also numba.cuda.tests.test_alignment 2 | 3 | import numpy as np 4 | from numba import from_dtype, njit, void 5 | from numba.tests.support import TestCase 6 | 7 | 8 | class TestAlignment(TestCase): 9 | 10 | def test_record_alignment(self): 11 | rec_dtype = np.dtype([('a', 'int32'), ('b', 'float64')], align=True) 12 | rec = from_dtype(rec_dtype) 13 | 14 | @njit((rec[:],)) 15 | def foo(a): 16 | for i in range(a.size): 17 | a[i].a = a[i].b 18 | 19 | a_recarray = np.recarray(3, dtype=rec_dtype) 20 | for i in range(a_recarray.size): 21 | a_rec = a_recarray[i] 22 | a_rec.a = 0 23 | a_rec.b = (i + 1) * 123 24 | 25 | foo(a_recarray) 26 | np.testing.assert_equal(a_recarray.a, a_recarray.b) 27 | 28 | def test_record_misaligned(self): 29 | rec_dtype = np.dtype([('a', 'int32'), ('b', 'float64')]) 30 | rec = from_dtype(rec_dtype) 31 | 32 | # Unlike the CUDA target, this will not generate an error 33 | @njit((rec[:],)) 34 | def foo(a): 35 | for i in range(a.size): 36 | a[i].a = a[i].b 37 | 38 | 39 | if __name__ == '__main__': 40 | unittest.main() 41 | -------------------------------------------------------------------------------- /numba/tests/test_array_return.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from numba import typeof, njit 4 | from numba.tests.support import MemoryLeakMixin 5 | import unittest 6 | 7 | 8 | def array_return(a, i): 9 | a[i] = 123 10 | return a 11 | 12 | 13 | def array_return_start_with_loop(a): 14 | for i in range(a.size): 15 | a[i] += 1 16 | return a 17 | 18 | 19 | class TestArrayReturn(MemoryLeakMixin, unittest.TestCase): 20 | def test_array_return(self): 21 | a = np.arange(10) 22 | i = 2 23 | at, it = typeof(a), typeof(i) 24 | cfunc = njit((at, it))(array_return) 25 | self.assertIs(a, cfunc(a, i)) 26 | 27 | def test_array_return_start_with_loop(self): 28 | """ 29 | A bug breaks array return if the function starts with a loop 30 | """ 31 | a = np.arange(10) 32 | at = typeof(a) 33 | cfunc = njit((at,))(array_return_start_with_loop) 34 | self.assertIs(a, cfunc(a)) 35 | 36 | 37 | if __name__ == '__main__': 38 | unittest.main() 39 | -------------------------------------------------------------------------------- /numba/tests/test_auto_constants.py: -------------------------------------------------------------------------------- 1 | import math 2 | import sys 3 | 4 | import numpy as np 5 | 6 | from numba import njit 7 | import numba.tests.usecases as uc 8 | import unittest 9 | 10 | 11 | class TestAutoConstants(unittest.TestCase): 12 | def test_numpy_nan(self): 13 | 14 | @njit 15 | def f(): 16 | return np.nan 17 | 18 | self.assertTrue(math.isnan(f())) 19 | self.assertTrue(math.isnan(f.py_func())) 20 | 21 | def test_sys_constant(self): 22 | 23 | @njit 24 | def f(): 25 | return sys.hexversion 26 | 27 | self.assertEqual(f(), f.py_func()) 28 | 29 | def test_module_string_constant(self): 30 | 31 | @njit 32 | def f(): 33 | return uc._GLOBAL_STR 34 | self.assertEqual(f(), f.py_func()) 35 | 36 | 37 | if __name__ == '__main__': 38 | unittest.main() 39 | -------------------------------------------------------------------------------- /numba/tests/test_compiler_lock.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from numba.core.compiler_lock import ( 3 | global_compiler_lock, 4 | require_global_compiler_lock, 5 | ) 6 | from numba.tests.support import TestCase 7 | 8 | 9 | class TestCompilerLock(TestCase): 10 | def test_gcl_as_context_manager(self): 11 | with global_compiler_lock: 12 | require_global_compiler_lock() 13 | 14 | def test_gcl_as_decorator(self): 15 | @global_compiler_lock 16 | def func(): 17 | require_global_compiler_lock() 18 | 19 | func() 20 | 21 | 22 | if __name__ == '__main__': 23 | unittest.main() 24 | -------------------------------------------------------------------------------- /numba/tests/test_doctest.py: -------------------------------------------------------------------------------- 1 | import doctest 2 | import unittest 3 | from numba.tests.support import TestCase 4 | 5 | 6 | class TestDocTest(TestCase): 7 | def test_basic_decorators(self): 8 | from . import doctest_usecase 9 | 10 | # Make sure the finder see all the doctest 11 | finder = doctest.DocTestFinder() 12 | tests = finder.find(doctest_usecase) 13 | testnames = {x.name for x in tests} 14 | expected = { 15 | 'numba.tests.doctest_usecase', 16 | 'numba.tests.doctest_usecase.a', 17 | 'numba.tests.doctest_usecase.b', 18 | 'numba.tests.doctest_usecase.c', 19 | 'numba.tests.doctest_usecase.d', 20 | } 21 | self.assertEqual(testnames, expected) 22 | 23 | # Execute the doctest in the module 24 | doctest.testmod(doctest_usecase) 25 | 26 | 27 | if __name__ == "__main__": 28 | unittest.main() 29 | -------------------------------------------------------------------------------- /numba/tests/test_dyn_func.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | import numba 4 | from numba.tests.support import TestCase 5 | 6 | 7 | class Issue455(object): 8 | """ 9 | Test code from issue 455. 10 | """ 11 | 12 | def __init__(self): 13 | self.f = [] 14 | 15 | def create_f(self): 16 | code = """ 17 | def f(x): 18 | n = x.shape[0] 19 | for i in range(n): 20 | x[i] = 1. 21 | """ 22 | d = {} 23 | exec(code.strip(), d) 24 | self.f.append(numba.jit("void(f8[:])", nopython=True)(d['f'])) 25 | 26 | def call_f(self): 27 | a = np.zeros(10) 28 | for f in self.f: 29 | f(a) 30 | return a 31 | 32 | 33 | class TestDynFunc(TestCase): 34 | 35 | def test_issue_455(self): 36 | inst = Issue455() 37 | inst.create_f() 38 | a = inst.call_f() 39 | self.assertPreciseEqual(a, np.ones_like(a)) 40 | 41 | 42 | if __name__ == '__main__': 43 | unittest.main() 44 | -------------------------------------------------------------------------------- /numba/tests/test_errormodels.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test setting/overriding error models 3 | """ 4 | 5 | from numba import jit 6 | import unittest 7 | 8 | 9 | class TestErrorModel(unittest.TestCase): 10 | 11 | def test_div_by_zero_python(self): 12 | @jit # python model is the default 13 | def model_python(val): 14 | return 1 / val 15 | 16 | with self.assertRaises(ZeroDivisionError): 17 | model_python(0) 18 | 19 | def test_div_by_zero_numpy(self): 20 | @jit(error_model='numpy') 21 | def model_numpy(val): 22 | return 1 / val 23 | 24 | self.assertEqual(model_numpy(0), float('inf')) 25 | 26 | 27 | if __name__ == '__main__': 28 | unittest.main() 29 | -------------------------------------------------------------------------------- /numba/tests/test_findlib.py: -------------------------------------------------------------------------------- 1 | from numba.tests.support import TestCase, unittest 2 | from numba.misc import findlib 3 | 4 | 5 | class TestFindlib(TestCase): 6 | def test_find_file_nonexistent_path(self): 7 | candidates = findlib.find_file('libirrelevant.so', 'NONEXISTENT') 8 | self.assertEqual(candidates, []) 9 | 10 | 11 | if __name__ == '__main__': 12 | unittest.main() 13 | -------------------------------------------------------------------------------- /numba/tests/test_func_interface.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from numba import jit 3 | 4 | 5 | class TestFuncInterface(unittest.TestCase): 6 | def test_jit_function_docstring(self): 7 | 8 | def add(x, y): 9 | '''Return sum of two numbers''' 10 | return x + y 11 | 12 | c_add = jit(add) 13 | self.assertEqual(c_add.__doc__, 'Return sum of two numbers') 14 | 15 | def test_jit_function_name(self): 16 | 17 | def add(x, y): 18 | return x + y 19 | 20 | c_add = jit(add) 21 | self.assertEqual(c_add.__name__, 'add') 22 | 23 | def test_jit_function_module(self): 24 | 25 | def add(x, y): 26 | return x + y 27 | 28 | c_add = jit(add) 29 | # Expected answer depends on how you run this test. 30 | # Compare to python function instead. 31 | self.assertEqual(c_add.__module__, add.__module__) 32 | 33 | def test_jit_function_code_object(self): 34 | def add(x, y): 35 | return x + y 36 | 37 | c_add = jit(add) 38 | self.assertEqual(c_add.__code__, add.__code__) 39 | self.assertEqual(c_add.func_code, add.__code__) 40 | 41 | 42 | if __name__ == '__main__': 43 | unittest.main() 44 | -------------------------------------------------------------------------------- /numba/tests/test_interproc.py: -------------------------------------------------------------------------------- 1 | import gc 2 | 3 | from numba import jit, int32 4 | import unittest 5 | 6 | 7 | def foo(a, b): 8 | return a + b 9 | 10 | 11 | def bar(a, b): 12 | return cfoo(a, b) + b 13 | 14 | @jit 15 | def inner(x, y): 16 | return x + y 17 | 18 | @jit(nopython=True) 19 | def outer(x, y): 20 | return inner(x, y) 21 | 22 | 23 | class TestInterProc(unittest.TestCase): 24 | 25 | def test_bar_call_foo(self): 26 | global cfoo 27 | cfoo = jit((int32, int32), nopython=True)(foo) 28 | cbar = jit((int32, int32), nopython=True)(bar) 29 | self.assertEqual(cbar(1, 2), 1 + 2 + 2) 30 | 31 | def test_bar_call_foo_compiled_twice(self): 32 | # When a function is compiled twice, then called from another 33 | # compiled function, check that the right target is called. 34 | # (otherwise, LLVM would assert out or crash) 35 | global cfoo 36 | for i in range(2): 37 | cfoo = jit((int32, int32), nopython=True)(foo) 38 | gc.collect() 39 | cbar = jit((int32, int32), nopython=True)(bar) 40 | self.assertEqual(cbar(1, 2), 1 + 2 + 2) 41 | 42 | def test_callsite_compilation(self): 43 | self.assertEqual(outer(1, 2), 1 + 2) 44 | 45 | 46 | if __name__ == '__main__': 47 | unittest.main() 48 | -------------------------------------------------------------------------------- /numba/tests/test_llvm_version_check.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | import sys 3 | 4 | import unittest 5 | 6 | 7 | class TestLlvmVersion(unittest.TestCase): 8 | 9 | def test_llvmlite_version(self): 10 | # test the system it's running on 11 | import llvmlite 12 | import numba 13 | self.assertTrue(numba.__version__) 14 | 15 | llvmlite_version = llvmlite.__version__ 16 | def cleanup(): 17 | llvmlite.__version__ = llvmlite_version 18 | self.addCleanup(cleanup) 19 | 20 | # explicitly test all 3 cases of version string 21 | ver = numba._min_llvmlite_version 22 | version_pass = '%d.%d.%d' % ver 23 | git_version_pass = '%d.%d.%d-10-g92584ed' % ver 24 | rc_version_pass = '%d.%d.%drc1' % (ver[0], ver[1], ver[2] + 1) 25 | version_fail = '%d.%d.0' % (ver[0], ver[1] - 1) 26 | git_version_fail = '%d.%d.9-10-g92584ed' % (ver[0], ver[1] - 1) 27 | 28 | ver_pass = (version_pass, git_version_pass, rc_version_pass) 29 | ver_fail = (version_fail, git_version_fail) 30 | for v in ver_pass: 31 | llvmlite.__version__ = v 32 | importlib.reload(numba) 33 | self.assertTrue(numba.__version__) 34 | 35 | for v in ver_fail: 36 | with self.assertRaises(ImportError): 37 | llvmlite.__version__ = v 38 | importlib.reload(numba) 39 | 40 | 41 | if __name__ == '__main__': 42 | unittest.main() 43 | -------------------------------------------------------------------------------- /numba/tests/test_locals.py: -------------------------------------------------------------------------------- 1 | from numba import float32, njit 2 | import unittest 3 | 4 | 5 | def foo(): 6 | x = 123 7 | return x 8 | 9 | 10 | class TestLocals(unittest.TestCase): 11 | 12 | def test_seed_types(self): 13 | cfunc = njit((), locals={'x': float32})(foo) 14 | self.assertEqual(cfunc.nopython_signatures[0].return_type, float32) 15 | 16 | 17 | if __name__ == '__main__': 18 | unittest.main() 19 | -------------------------------------------------------------------------------- /numba/tests/test_mandelbrot.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from numba import njit 3 | from numba.core import types 4 | 5 | 6 | def is_in_mandelbrot(c): 7 | i = 0 8 | z = 0.0j 9 | for i in range(100): 10 | z = z ** 2 + c 11 | if (z.real * z.real + z.imag * z.imag) >= 4: 12 | return False 13 | return True 14 | 15 | 16 | class TestMandelbrot(unittest.TestCase): 17 | 18 | def test_mandelbrot(self): 19 | pyfunc = is_in_mandelbrot 20 | cfunc = njit((types.complex64,))(pyfunc) 21 | 22 | points = [0+0j, 1+0j, 0+1j, 1+1j, 0.1+0.1j] 23 | for p in points: 24 | self.assertEqual(cfunc(p), pyfunc(p)) 25 | 26 | 27 | if __name__ == '__main__': 28 | unittest.main() 29 | -------------------------------------------------------------------------------- /numba/tests/test_mangling.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Test function name mangling. 4 | The mangling affects the ABI of numba compiled binaries. 5 | """ 6 | from numba.core import types 7 | from numba.core.funcdesc import default_mangler 8 | from numba.tests.support import unittest, TestCase 9 | 10 | 11 | class TestMangling(TestCase): 12 | def test_one_args(self): 13 | fname = 'foo' 14 | argtypes = types.int32, 15 | name = default_mangler(fname, argtypes) 16 | self.assertEqual(name, '_Z3fooi') 17 | 18 | def test_two_args(self): 19 | fname = 'foo' 20 | argtypes = types.int32, types.float32 21 | name = default_mangler(fname, argtypes) 22 | self.assertEqual(name, '_Z3fooif') 23 | 24 | def test_unicode_fname(self): 25 | fname = u'foಠ' 26 | argtypes = types.int32, types.float32 27 | name = default_mangler(fname, argtypes) 28 | self.assertIsInstance(name, str) 29 | # manually encode it 30 | unichar = fname[2] 31 | enc = ''.join('_{:02x}'.format(c) 32 | for c in unichar.encode('utf8')) 33 | text = 'fo' + enc 34 | expect = '_Z{}{}if'.format(len(text), text) 35 | self.assertEqual(name, expect) 36 | # ensure result chars are in the right charset 37 | self.assertRegex(name, r'^_Z[a-zA-Z0-9_\$]+$') 38 | 39 | 40 | if __name__ == '__main__': 41 | unittest.main() 42 | -------------------------------------------------------------------------------- /numba/tests/test_maxmin.py: -------------------------------------------------------------------------------- 1 | from numba import njit 2 | from numba.core import types 3 | import unittest 4 | 5 | 6 | def domax3(a, b, c): 7 | return max(a, b, c) 8 | 9 | 10 | def domin3(a, b, c): 11 | return min(a, b, c) 12 | 13 | 14 | class TestMaxMin(unittest.TestCase): 15 | def test_max3(self): 16 | pyfunc = domax3 17 | argtys = (types.int32, types.float32, types.double) 18 | cfunc = njit(argtys)(pyfunc) 19 | 20 | a = 1 21 | b = 2 22 | c = 3 23 | 24 | self.assertEqual(pyfunc(a, b, c), cfunc(a, b, c)) 25 | 26 | def test_min3(self): 27 | pyfunc = domin3 28 | argtys = (types.int32, types.float32, types.double) 29 | cfunc = njit(argtys)(pyfunc) 30 | 31 | a = 1 32 | b = 2 33 | c = 3 34 | 35 | self.assertEqual(pyfunc(a, b, c), cfunc(a, b, c)) 36 | 37 | 38 | if __name__ == '__main__': 39 | unittest.main() 40 | -------------------------------------------------------------------------------- /numba/tests/test_moved_modules.py: -------------------------------------------------------------------------------- 1 | """Tests for moved modules and their redirection from old path 2 | """ 3 | from numba.tests.support import TestCase 4 | 5 | 6 | class TestMovedModule(TestCase): 7 | """Testing moved modules in Q1 2020 but were decided to kept as public API 8 | """ 9 | def tests_numba_types(self): 10 | import numba.types 11 | import numba.core.types as types 12 | # The old module IS NOT the new module 13 | self.assertIsNot(numba.types, types) 14 | # Attribute access are there 15 | self.assertIs(numba.types.intp, types.intp) 16 | self.assertIs(numba.types.float64, types.float64) 17 | self.assertIs(numba.types.Array, types.Array) 18 | # Submodule access through old import path is possible 19 | import numba.types.misc 20 | self.assertIs(types.misc, numba.types.misc) 21 | self.assertIs(types.misc.Optional, numba.types.misc.Optional) 22 | # Import time code could be executed twice and causes the following to 23 | # fail. 24 | self.assertIs(types.StringLiteral, numba.types.misc.StringLiteral) 25 | # Check numba.types.container 26 | from numba.types import containers 27 | self.assertIs(types.containers, containers) 28 | self.assertIs(types.containers.Sequence, containers.Sequence) 29 | from numba.types.containers import Sequence 30 | self.assertIs(Sequence, containers.Sequence) 31 | -------------------------------------------------------------------------------- /numba/tests/test_multi3.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | import numpy as np 4 | 5 | from numba import njit 6 | from numba.core import types 7 | import unittest 8 | 9 | class TestMulti3(unittest.TestCase): 10 | """ 11 | This test is only relevant for 32-bit architectures. 12 | 13 | Test __multi3 implementation in _helperlib.c. 14 | The symbol defines a i128 multiplication. 15 | It is necessary for working around an issue in LLVM (see issue #969). 16 | The symbol does not exist in 32-bit platform, and should not be used by 17 | LLVM. However, optimization passes will create i65 multiplication that 18 | is then lowered to __multi3. 19 | """ 20 | def test_multi3(self): 21 | @njit("(int64,)") 22 | def func(x): 23 | res = 0 24 | for i in range(x): 25 | res += i 26 | return res 27 | 28 | x_cases = [-1, 0, 1, 3, 4, 8, 29 | 0xffffffff - 1, 0xffffffff, 0xffffffff + 1, 30 | 0x123456789abcdef, -0x123456789abcdef] 31 | for _ in range(500): 32 | x_cases.append(random.randint(0, 0xffffffff)) 33 | 34 | def expected(x): 35 | if x <= 0: return 0 36 | return ((x * (x - 1)) // 2) & (2**64 - 1) 37 | 38 | for x in x_cases: 39 | self.assertEqual(expected(x), func(x)) 40 | 41 | 42 | if __name__ == '__main__': 43 | unittest.main() 44 | -------------------------------------------------------------------------------- /numba/tests/test_nan.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from numba import jit 3 | from numba.core import types 4 | 5 | enable_pyobj_flags = {'forceobj': True} 6 | no_pyobj_flags = {'nopython': True} 7 | 8 | 9 | def isnan(x): 10 | return x != x 11 | 12 | 13 | def isequal(x): 14 | return x == x 15 | 16 | 17 | class TestNaN(unittest.TestCase): 18 | 19 | def test_nans(self, flags=enable_pyobj_flags): 20 | pyfunc = isnan 21 | cfunc = jit((types.float64,), **flags)(pyfunc) 22 | 23 | self.assertTrue(cfunc(float('nan'))) 24 | self.assertFalse(cfunc(1.0)) 25 | 26 | pyfunc = isequal 27 | cfunc = jit((types.float64,), **flags)(pyfunc) 28 | 29 | self.assertFalse(cfunc(float('nan'))) 30 | self.assertTrue(cfunc(1.0)) 31 | 32 | def test_nans_npm(self): 33 | self.test_nans(flags=no_pyobj_flags) 34 | 35 | 36 | if __name__ == '__main__': 37 | unittest.main() 38 | -------------------------------------------------------------------------------- /numba/tests/test_new_type_system.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from numba import njit, config 4 | from numba.tests.support import TestCase 5 | 6 | 7 | class TestTypes(TestCase): 8 | 9 | def setUp(self) -> None: 10 | if config.USE_LEGACY_TYPE_SYSTEM: 11 | self.skipTest("This test is only for the new type system") 12 | return super().setUp() 13 | 14 | def test_return_types(self): 15 | @njit 16 | def foo(x): 17 | return x 18 | 19 | cases = [ 20 | # Python types 21 | 1, 22 | 1.2, 23 | (1 + 2j), 24 | True, 25 | # NumPy types 26 | np.int32(1), 27 | np.float64(1.2), 28 | np.complex64(1 + 2j), 29 | np.complex128(1 + 2j), 30 | np.bool_(True), 31 | np.datetime64('2020-01-01'), 32 | np.timedelta64(1, 'D'), 33 | ] 34 | 35 | for case in cases: 36 | self.assertEqual(foo(case), case) 37 | self.assertEqual(type(foo(case)), type(case)) 38 | -------------------------------------------------------------------------------- /numba/tests/test_numconv.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | import unittest 3 | from numba import njit 4 | from numba.core import types 5 | 6 | 7 | def template(fromty, toty): 8 | def closure(self): 9 | def cast(x): 10 | y = x 11 | return y 12 | 13 | cfunc = njit(toty(fromty))(cast) 14 | self.assertAlmostEqual(cfunc(1), 1) 15 | 16 | return closure 17 | 18 | 19 | class TestNumberConversion(unittest.TestCase): 20 | """ 21 | Test all int/float numeric conversion to ensure we have all the external 22 | dependencies to perform these conversions. 23 | """ 24 | # NOTE: more implicit tests are in test_numberctor 25 | 26 | @classmethod 27 | def automatic_populate(cls): 28 | tys = types.integer_domain | types.real_domain 29 | for fromty, toty in itertools.permutations(tys, r=2): 30 | test_name = "test_{fromty}_to_{toty}".format(fromty=fromty, 31 | toty=toty) 32 | setattr(cls, test_name, template(fromty, toty)) 33 | 34 | 35 | TestNumberConversion.automatic_populate() 36 | 37 | if __name__ == '__main__': 38 | unittest.main() 39 | -------------------------------------------------------------------------------- /numba/tests/test_numpyadapt.py: -------------------------------------------------------------------------------- 1 | from ctypes import * 2 | 3 | import numpy as np 4 | 5 | import unittest 6 | from numba import _helperlib 7 | 8 | 9 | class ArrayStruct3D(Structure): 10 | # Mimic the structure defined in numba.targets.arrayobj's make_array() 11 | _fields_ = [ 12 | ("meminfo", c_void_p), 13 | ("parent", c_void_p), 14 | ("nitems", c_ssize_t), 15 | ("itemsize", c_ssize_t), 16 | ("data", c_void_p), 17 | ("shape", (c_ssize_t * 3)), 18 | ("strides", (c_ssize_t * 3)), 19 | ] 20 | 21 | 22 | class TestArrayAdaptor(unittest.TestCase): 23 | def test_array_adaptor(self): 24 | arystruct = ArrayStruct3D() 25 | 26 | adaptorptr = _helperlib.c_helpers['adapt_ndarray'] 27 | adaptor = PYFUNCTYPE(c_int, py_object, c_void_p)(adaptorptr) 28 | 29 | ary = np.arange(60).reshape(2, 3, 10) 30 | status = adaptor(ary, byref(arystruct)) 31 | self.assertEqual(status, 0) 32 | self.assertEqual(arystruct.data, ary.ctypes.data) 33 | self.assertNotEqual(arystruct.meminfo, 0) 34 | self.assertEqual(arystruct.parent, id(ary)) 35 | self.assertEqual(arystruct.nitems, 60) 36 | self.assertEqual(arystruct.itemsize, ary.itemsize) 37 | for i in range(3): 38 | self.assertEqual(arystruct.shape[i], ary.ctypes.shape[i]) 39 | self.assertEqual(arystruct.strides[i], ary.ctypes.strides[i]) 40 | 41 | 42 | if __name__ == '__main__': 43 | unittest.main() 44 | -------------------------------------------------------------------------------- /numba/tests/test_objects.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test generic manipulation of objects. 3 | """ 4 | 5 | 6 | import unittest 7 | from numba import jit 8 | from numba.core import types 9 | from numba.tests.support import TestCase 10 | 11 | 12 | class C(object): 13 | pass 14 | 15 | 16 | def setattr_usecase(o, v): 17 | o.x = v 18 | 19 | 20 | def delattr_usecase(o): 21 | del o.x 22 | 23 | 24 | class TestAttributes(TestCase): 25 | def test_setattr(self): 26 | pyfunc = setattr_usecase 27 | cfunc = jit((types.pyobject, types.int32), forceobj=True)(pyfunc) 28 | c = C() 29 | cfunc(c, 123) 30 | self.assertEqual(c.x, 123) 31 | 32 | def test_setattr_attribute_error(self): 33 | pyfunc = setattr_usecase 34 | cfunc = jit((types.pyobject, types.int32), forceobj=True)(pyfunc) 35 | # Can't set undeclared slot 36 | with self.assertRaises(AttributeError): 37 | cfunc(object(), 123) 38 | 39 | def test_delattr(self): 40 | pyfunc = delattr_usecase 41 | cfunc = jit((types.pyobject,), forceobj=True)(pyfunc) 42 | c = C() 43 | c.x = 123 44 | cfunc(c) 45 | with self.assertRaises(AttributeError): 46 | c.x 47 | 48 | def test_delattr_attribute_error(self): 49 | pyfunc = delattr_usecase 50 | cfunc = jit((types.pyobject,), forceobj=True)(pyfunc) 51 | # Can't delete non-existing attribute 52 | with self.assertRaises(AttributeError): 53 | cfunc(C()) 54 | 55 | 56 | if __name__ == '__main__': 57 | unittest.main() 58 | -------------------------------------------------------------------------------- /numba/tests/test_typeguard.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests to ensure that typeguard is working as expected. 3 | This mostly contains negative tests as proof that typeguard can catch errors. 4 | """ 5 | import unittest 6 | from numba.tests.support import TestCase, skip_unless_typeguard 7 | 8 | 9 | def guard_args(val: int): 10 | return 11 | 12 | 13 | def guard_ret(val) -> int: 14 | return val 15 | 16 | 17 | @skip_unless_typeguard 18 | class TestTypeGuard(TestCase): 19 | 20 | def setUp(self): 21 | super().setUp() 22 | import typeguard 23 | # This is a test class invariant but the Numba multiprocesses test 24 | # runner doesn't respect `setUpClass` so just use `setUp`. 25 | # typeguard 3+ uses typeguard.TypeCheckError, 2.x uses TypeError 26 | self._exception_type = getattr(typeguard, 'TypeCheckError', TypeError) 27 | 28 | def test_check_args(self): 29 | with self.assertRaises(self._exception_type): 30 | guard_args(float(1.2)) 31 | 32 | def test_check_ret(self): 33 | with self.assertRaises(self._exception_type): 34 | guard_ret(float(1.2)) 35 | 36 | def test_check_does_not_work_with_inner_func(self): 37 | def guard(val: int) -> int: 38 | return 39 | 40 | guard(float(1.2)) 41 | 42 | 43 | if __name__ == '__main__': 44 | unittest.main() 45 | -------------------------------------------------------------------------------- /numba/tests/test_typenames.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from numba.core import types 4 | import unittest 5 | 6 | 7 | class TestTypeNames(unittest.TestCase): 8 | def test_numpy_integers(self): 9 | expect = getattr(types, "int%d" % (np.dtype("int").itemsize * 8)) 10 | self.assertEqual(types.int_, expect) 11 | 12 | expect = getattr(types, "uint%d" % (np.dtype("uint").itemsize * 8)) 13 | self.assertEqual(types.uint, expect) 14 | 15 | 16 | if __name__ == '__main__': 17 | unittest.main() 18 | -------------------------------------------------------------------------------- /numba/tests/test_vectorization_type_inference.py: -------------------------------------------------------------------------------- 1 | from numba import vectorize, jit, bool_, double, int_, float32, typeof, int8 2 | import unittest 3 | import numpy as np 4 | 5 | 6 | def add(a, b): 7 | return a + b 8 | 9 | 10 | def func(dtypeA, dtypeB): 11 | A = np.arange(10, dtype=dtypeA) 12 | B = np.arange(10, dtype=dtypeB) 13 | return typeof(vector_add(A, B)) 14 | 15 | 16 | class TestVectTypeInfer(unittest.TestCase): 17 | 18 | def test_type_inference(self): 19 | """This is testing numpy ufunc dispatch machinery 20 | """ 21 | global vector_add 22 | vector_add = vectorize([ 23 | bool_(double, int_), 24 | double(double, double), 25 | float32(double, float32), 26 | ])(add) 27 | 28 | def numba_type_equal(a, b): 29 | self.assertEqual(a.dtype, b.dtype) 30 | self.assertEqual(a.ndim, b.ndim) 31 | 32 | numba_type_equal(func(np.dtype(np.float64), np.dtype('i')), bool_[:]) 33 | numba_type_equal(func(np.dtype(np.float64), np.dtype(np.float64)), 34 | double[:]) 35 | # This is because the double(double, double) matches first 36 | numba_type_equal(func(np.dtype(np.float64), np.dtype(np.float32)), 37 | double[:]) 38 | 39 | 40 | if __name__ == '__main__': 41 | unittest.main() 42 | -------------------------------------------------------------------------------- /numba/tests/threading_backend_usecases.py: -------------------------------------------------------------------------------- 1 | import signal 2 | import sys 3 | from numba import njit 4 | import numpy as np 5 | 6 | 7 | def sigterm_handler(signum, frame): 8 | raise RuntimeError("Caught SIGTERM") 9 | 10 | 11 | @njit(parallel=True) 12 | def busy_func_inner(a, b): 13 | c = a + b * np.sqrt(a) + np.sqrt(b) 14 | d = np.sqrt(a + b * np.sqrt(a) + np.sqrt(b)) 15 | return c + d 16 | 17 | 18 | def busy_func(a, b, q=None): 19 | sys.stdout.flush() 20 | sys.stderr.flush() 21 | signal.signal(signal.SIGTERM, sigterm_handler) 22 | try: 23 | z = busy_func_inner(a, b) 24 | sys.stdout.flush() 25 | sys.stderr.flush() 26 | return z 27 | except Exception as e: 28 | if q is not None: 29 | q.put(e) 30 | -------------------------------------------------------------------------------- /numba/tests/typedlist_usecases.py: -------------------------------------------------------------------------------- 1 | from numba import int32 2 | from numba.typed import List 3 | 4 | 5 | # global typed-list for testing purposes 6 | global_typed_list = List.empty_list(int32) 7 | for i in (1, 2, 3): 8 | global_typed_list.append(int32(i)) 9 | 10 | 11 | def catch_global(): 12 | x = List() 13 | for i in global_typed_list: 14 | x.append(i) 15 | -------------------------------------------------------------------------------- /numba/typed/__init__.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | 3 | 4 | _delayed_symbols = { 5 | "Dict": ".typeddict", 6 | "List": ".typedlist", 7 | } 8 | 9 | 10 | def __getattr__(name): 11 | # Uses PEP-562 but requires python>3.6 12 | if name in _delayed_symbols: 13 | modpath = _delayed_symbols[name] 14 | mod = importlib.import_module(modpath, __name__) 15 | return getattr(mod, name) 16 | else: 17 | try: 18 | return importlib.import_module(f".{name}", __name__) 19 | except ModuleNotFoundError: 20 | raise AttributeError 21 | -------------------------------------------------------------------------------- /numba/typed/dictimpl.py: -------------------------------------------------------------------------------- 1 | """ 2 | This file implements the lowering for `dict()` 3 | """ 4 | from numba.core import types 5 | from numba.core.imputils import lower_builtin 6 | 7 | 8 | _message_dict_support = """ 9 | Unsupported use of `dict()` with keyword argument(s). \ 10 | The only supported uses are `dict()` or `dict(*iterable)`. 11 | """.strip() 12 | 13 | 14 | @lower_builtin(dict, types.IterableType) 15 | def dict_constructor(context, builder, sig, args): 16 | from numba.typed import Dict 17 | 18 | dicttype = sig.return_type 19 | kt, vt = dicttype.key_type, dicttype.value_type 20 | 21 | def dict_impl(iterable): 22 | res = Dict.empty(kt, vt) 23 | for k, v in iterable: 24 | res[k] = v 25 | return res 26 | 27 | return context.compile_internal(builder, dict_impl, sig, args) 28 | 29 | 30 | @lower_builtin(dict) 31 | def impl_dict(context, builder, sig, args): 32 | """ 33 | The `dict()` implementation simply forwards the work to `Dict.empty()`. 34 | """ 35 | from numba.typed import Dict 36 | 37 | dicttype = sig.return_type 38 | kt, vt = dicttype.key_type, dicttype.value_type 39 | 40 | def call_ctor(): 41 | return Dict.empty(kt, vt) 42 | 43 | return context.compile_internal(builder, call_ctor, sig, args) 44 | -------------------------------------------------------------------------------- /numba/typed/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/numba/numba/6cc96d049d9a486fb03eef1f2479a792596eb4e6/numba/typed/py.typed -------------------------------------------------------------------------------- /numba/types/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from numba.core.utils import _RedirectSubpackage 3 | sys.modules[__name__] = _RedirectSubpackage(locals(), "numba.core.types") 4 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | -e . 2 | -------------------------------------------------------------------------------- /runtests.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import runpy 3 | import os 4 | 5 | if bool(os.environ.get('NUMBA_USE_TYPEGUARD')): 6 | # The typeguard import hook must be installed prior to importing numba. 7 | # Therefore, this cannot be part of the numba package. 8 | try: 9 | # version 3+ exports this at the top level 10 | from typeguard import install_import_hook 11 | except ImportError: 12 | # try location for version 2.x 13 | from typeguard.importhook import install_import_hook 14 | 15 | install_import_hook(packages=['numba']) 16 | 17 | # ensure full tracebacks are available and no help messages appear in test mode 18 | os.environ['NUMBA_DEVELOPER_MODE'] = '1' 19 | 20 | 21 | if __name__ == "__main__": 22 | runpy.run_module('numba.runtests', run_name='__main__') 23 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | 2 | # See the docstring in versioneer.py for instructions. Note that you must 3 | # re-run 'versioneer.py setup' after changing this section, and commit the 4 | # resulting files. 5 | 6 | [versioneer] 7 | VCS = git 8 | style = pep440 9 | versionfile_source = numba/_version.py 10 | versionfile_build = numba/_version.py 11 | tag_prefix = 12 | parentdir_prefix = numba- 13 | 14 | --------------------------------------------------------------------------------