numba-cuda 0.21.1__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (488) hide show
  1. _numba_cuda_redirector.pth +4 -0
  2. _numba_cuda_redirector.py +89 -0
  3. numba_cuda/VERSION +1 -0
  4. numba_cuda/__init__.py +6 -0
  5. numba_cuda/_version.py +11 -0
  6. numba_cuda/numba/cuda/__init__.py +70 -0
  7. numba_cuda/numba/cuda/_internal/cuda_bf16.py +16394 -0
  8. numba_cuda/numba/cuda/_internal/cuda_fp16.py +8112 -0
  9. numba_cuda/numba/cuda/api.py +577 -0
  10. numba_cuda/numba/cuda/api_util.py +76 -0
  11. numba_cuda/numba/cuda/args.py +72 -0
  12. numba_cuda/numba/cuda/bf16.py +397 -0
  13. numba_cuda/numba/cuda/cache_hints.py +287 -0
  14. numba_cuda/numba/cuda/cext/__init__.py +2 -0
  15. numba_cuda/numba/cuda/cext/_devicearray.cp313-win_amd64.pyd +0 -0
  16. numba_cuda/numba/cuda/cext/_devicearray.cpp +159 -0
  17. numba_cuda/numba/cuda/cext/_devicearray.h +29 -0
  18. numba_cuda/numba/cuda/cext/_dispatcher.cp313-win_amd64.pyd +0 -0
  19. numba_cuda/numba/cuda/cext/_dispatcher.cpp +1098 -0
  20. numba_cuda/numba/cuda/cext/_hashtable.cpp +532 -0
  21. numba_cuda/numba/cuda/cext/_hashtable.h +135 -0
  22. numba_cuda/numba/cuda/cext/_helperlib.c +71 -0
  23. numba_cuda/numba/cuda/cext/_helperlib.cp313-win_amd64.pyd +0 -0
  24. numba_cuda/numba/cuda/cext/_helpermod.c +82 -0
  25. numba_cuda/numba/cuda/cext/_pymodule.h +38 -0
  26. numba_cuda/numba/cuda/cext/_typeconv.cp313-win_amd64.pyd +0 -0
  27. numba_cuda/numba/cuda/cext/_typeconv.cpp +206 -0
  28. numba_cuda/numba/cuda/cext/_typeof.cpp +1159 -0
  29. numba_cuda/numba/cuda/cext/_typeof.h +19 -0
  30. numba_cuda/numba/cuda/cext/capsulethunk.h +111 -0
  31. numba_cuda/numba/cuda/cext/mviewbuf.c +385 -0
  32. numba_cuda/numba/cuda/cext/mviewbuf.cp313-win_amd64.pyd +0 -0
  33. numba_cuda/numba/cuda/cext/typeconv.cpp +212 -0
  34. numba_cuda/numba/cuda/cext/typeconv.hpp +101 -0
  35. numba_cuda/numba/cuda/cg.py +67 -0
  36. numba_cuda/numba/cuda/cgutils.py +1294 -0
  37. numba_cuda/numba/cuda/cloudpickle/__init__.py +21 -0
  38. numba_cuda/numba/cuda/cloudpickle/cloudpickle.py +1598 -0
  39. numba_cuda/numba/cuda/cloudpickle/cloudpickle_fast.py +17 -0
  40. numba_cuda/numba/cuda/codegen.py +541 -0
  41. numba_cuda/numba/cuda/compiler.py +1396 -0
  42. numba_cuda/numba/cuda/core/analysis.py +758 -0
  43. numba_cuda/numba/cuda/core/annotations/__init__.py +0 -0
  44. numba_cuda/numba/cuda/core/annotations/pretty_annotate.py +288 -0
  45. numba_cuda/numba/cuda/core/annotations/type_annotations.py +305 -0
  46. numba_cuda/numba/cuda/core/base.py +1332 -0
  47. numba_cuda/numba/cuda/core/boxing.py +1411 -0
  48. numba_cuda/numba/cuda/core/bytecode.py +728 -0
  49. numba_cuda/numba/cuda/core/byteflow.py +2346 -0
  50. numba_cuda/numba/cuda/core/caching.py +744 -0
  51. numba_cuda/numba/cuda/core/callconv.py +392 -0
  52. numba_cuda/numba/cuda/core/codegen.py +171 -0
  53. numba_cuda/numba/cuda/core/compiler.py +199 -0
  54. numba_cuda/numba/cuda/core/compiler_lock.py +85 -0
  55. numba_cuda/numba/cuda/core/compiler_machinery.py +497 -0
  56. numba_cuda/numba/cuda/core/config.py +650 -0
  57. numba_cuda/numba/cuda/core/consts.py +124 -0
  58. numba_cuda/numba/cuda/core/controlflow.py +989 -0
  59. numba_cuda/numba/cuda/core/entrypoints.py +57 -0
  60. numba_cuda/numba/cuda/core/environment.py +66 -0
  61. numba_cuda/numba/cuda/core/errors.py +917 -0
  62. numba_cuda/numba/cuda/core/event.py +511 -0
  63. numba_cuda/numba/cuda/core/funcdesc.py +330 -0
  64. numba_cuda/numba/cuda/core/generators.py +387 -0
  65. numba_cuda/numba/cuda/core/imputils.py +509 -0
  66. numba_cuda/numba/cuda/core/inline_closurecall.py +1787 -0
  67. numba_cuda/numba/cuda/core/interpreter.py +3617 -0
  68. numba_cuda/numba/cuda/core/ir.py +1812 -0
  69. numba_cuda/numba/cuda/core/ir_utils.py +2638 -0
  70. numba_cuda/numba/cuda/core/optional.py +129 -0
  71. numba_cuda/numba/cuda/core/options.py +262 -0
  72. numba_cuda/numba/cuda/core/postproc.py +249 -0
  73. numba_cuda/numba/cuda/core/pythonapi.py +1859 -0
  74. numba_cuda/numba/cuda/core/registry.py +46 -0
  75. numba_cuda/numba/cuda/core/removerefctpass.py +123 -0
  76. numba_cuda/numba/cuda/core/rewrites/__init__.py +26 -0
  77. numba_cuda/numba/cuda/core/rewrites/ir_print.py +91 -0
  78. numba_cuda/numba/cuda/core/rewrites/registry.py +104 -0
  79. numba_cuda/numba/cuda/core/rewrites/static_binop.py +41 -0
  80. numba_cuda/numba/cuda/core/rewrites/static_getitem.py +189 -0
  81. numba_cuda/numba/cuda/core/rewrites/static_raise.py +100 -0
  82. numba_cuda/numba/cuda/core/sigutils.py +68 -0
  83. numba_cuda/numba/cuda/core/ssa.py +498 -0
  84. numba_cuda/numba/cuda/core/targetconfig.py +330 -0
  85. numba_cuda/numba/cuda/core/tracing.py +231 -0
  86. numba_cuda/numba/cuda/core/transforms.py +956 -0
  87. numba_cuda/numba/cuda/core/typed_passes.py +867 -0
  88. numba_cuda/numba/cuda/core/typeinfer.py +1950 -0
  89. numba_cuda/numba/cuda/core/unsafe/__init__.py +0 -0
  90. numba_cuda/numba/cuda/core/unsafe/bytes.py +67 -0
  91. numba_cuda/numba/cuda/core/unsafe/eh.py +67 -0
  92. numba_cuda/numba/cuda/core/unsafe/refcount.py +98 -0
  93. numba_cuda/numba/cuda/core/untyped_passes.py +1979 -0
  94. numba_cuda/numba/cuda/cpython/builtins.py +1153 -0
  95. numba_cuda/numba/cuda/cpython/charseq.py +1218 -0
  96. numba_cuda/numba/cuda/cpython/cmathimpl.py +560 -0
  97. numba_cuda/numba/cuda/cpython/enumimpl.py +103 -0
  98. numba_cuda/numba/cuda/cpython/iterators.py +167 -0
  99. numba_cuda/numba/cuda/cpython/listobj.py +1326 -0
  100. numba_cuda/numba/cuda/cpython/mathimpl.py +499 -0
  101. numba_cuda/numba/cuda/cpython/numbers.py +1475 -0
  102. numba_cuda/numba/cuda/cpython/rangeobj.py +289 -0
  103. numba_cuda/numba/cuda/cpython/slicing.py +322 -0
  104. numba_cuda/numba/cuda/cpython/tupleobj.py +456 -0
  105. numba_cuda/numba/cuda/cpython/unicode.py +2865 -0
  106. numba_cuda/numba/cuda/cpython/unicode_support.py +1597 -0
  107. numba_cuda/numba/cuda/cpython/unsafe/__init__.py +0 -0
  108. numba_cuda/numba/cuda/cpython/unsafe/numbers.py +64 -0
  109. numba_cuda/numba/cuda/cpython/unsafe/tuple.py +92 -0
  110. numba_cuda/numba/cuda/cuda_paths.py +691 -0
  111. numba_cuda/numba/cuda/cudadecl.py +556 -0
  112. numba_cuda/numba/cuda/cudadrv/__init__.py +14 -0
  113. numba_cuda/numba/cuda/cudadrv/devicearray.py +951 -0
  114. numba_cuda/numba/cuda/cudadrv/devices.py +249 -0
  115. numba_cuda/numba/cuda/cudadrv/driver.py +3222 -0
  116. numba_cuda/numba/cuda/cudadrv/drvapi.py +435 -0
  117. numba_cuda/numba/cuda/cudadrv/dummyarray.py +558 -0
  118. numba_cuda/numba/cuda/cudadrv/enums.py +613 -0
  119. numba_cuda/numba/cuda/cudadrv/error.py +48 -0
  120. numba_cuda/numba/cuda/cudadrv/libs.py +220 -0
  121. numba_cuda/numba/cuda/cudadrv/linkable_code.py +184 -0
  122. numba_cuda/numba/cuda/cudadrv/mappings.py +14 -0
  123. numba_cuda/numba/cuda/cudadrv/ndarray.py +26 -0
  124. numba_cuda/numba/cuda/cudadrv/nvrtc.py +193 -0
  125. numba_cuda/numba/cuda/cudadrv/nvvm.py +756 -0
  126. numba_cuda/numba/cuda/cudadrv/rtapi.py +13 -0
  127. numba_cuda/numba/cuda/cudadrv/runtime.py +34 -0
  128. numba_cuda/numba/cuda/cudaimpl.py +995 -0
  129. numba_cuda/numba/cuda/cudamath.py +149 -0
  130. numba_cuda/numba/cuda/datamodel/__init__.py +7 -0
  131. numba_cuda/numba/cuda/datamodel/cuda_manager.py +66 -0
  132. numba_cuda/numba/cuda/datamodel/cuda_models.py +1446 -0
  133. numba_cuda/numba/cuda/datamodel/cuda_packer.py +224 -0
  134. numba_cuda/numba/cuda/datamodel/cuda_registry.py +22 -0
  135. numba_cuda/numba/cuda/datamodel/cuda_testing.py +153 -0
  136. numba_cuda/numba/cuda/datamodel/manager.py +11 -0
  137. numba_cuda/numba/cuda/datamodel/models.py +9 -0
  138. numba_cuda/numba/cuda/datamodel/packer.py +9 -0
  139. numba_cuda/numba/cuda/datamodel/registry.py +11 -0
  140. numba_cuda/numba/cuda/datamodel/testing.py +11 -0
  141. numba_cuda/numba/cuda/debuginfo.py +903 -0
  142. numba_cuda/numba/cuda/decorators.py +294 -0
  143. numba_cuda/numba/cuda/descriptor.py +35 -0
  144. numba_cuda/numba/cuda/device_init.py +158 -0
  145. numba_cuda/numba/cuda/deviceufunc.py +1021 -0
  146. numba_cuda/numba/cuda/dispatcher.py +2463 -0
  147. numba_cuda/numba/cuda/errors.py +72 -0
  148. numba_cuda/numba/cuda/extending.py +697 -0
  149. numba_cuda/numba/cuda/flags.py +178 -0
  150. numba_cuda/numba/cuda/fp16.py +357 -0
  151. numba_cuda/numba/cuda/include/12/cuda_bf16.h +5118 -0
  152. numba_cuda/numba/cuda/include/12/cuda_bf16.hpp +3865 -0
  153. numba_cuda/numba/cuda/include/12/cuda_fp16.h +5363 -0
  154. numba_cuda/numba/cuda/include/12/cuda_fp16.hpp +3483 -0
  155. numba_cuda/numba/cuda/include/13/cuda_bf16.h +5118 -0
  156. numba_cuda/numba/cuda/include/13/cuda_bf16.hpp +3865 -0
  157. numba_cuda/numba/cuda/include/13/cuda_fp16.h +5363 -0
  158. numba_cuda/numba/cuda/include/13/cuda_fp16.hpp +3483 -0
  159. numba_cuda/numba/cuda/initialize.py +24 -0
  160. numba_cuda/numba/cuda/intrinsic_wrapper.py +41 -0
  161. numba_cuda/numba/cuda/intrinsics.py +382 -0
  162. numba_cuda/numba/cuda/itanium_mangler.py +214 -0
  163. numba_cuda/numba/cuda/kernels/__init__.py +2 -0
  164. numba_cuda/numba/cuda/kernels/reduction.py +265 -0
  165. numba_cuda/numba/cuda/kernels/transpose.py +65 -0
  166. numba_cuda/numba/cuda/libdevice.py +3386 -0
  167. numba_cuda/numba/cuda/libdevicedecl.py +20 -0
  168. numba_cuda/numba/cuda/libdevicefuncs.py +1060 -0
  169. numba_cuda/numba/cuda/libdeviceimpl.py +88 -0
  170. numba_cuda/numba/cuda/locks.py +19 -0
  171. numba_cuda/numba/cuda/lowering.py +1951 -0
  172. numba_cuda/numba/cuda/mathimpl.py +374 -0
  173. numba_cuda/numba/cuda/memory_management/__init__.py +4 -0
  174. numba_cuda/numba/cuda/memory_management/memsys.cu +99 -0
  175. numba_cuda/numba/cuda/memory_management/memsys.cuh +22 -0
  176. numba_cuda/numba/cuda/memory_management/nrt.cu +212 -0
  177. numba_cuda/numba/cuda/memory_management/nrt.cuh +48 -0
  178. numba_cuda/numba/cuda/memory_management/nrt.py +390 -0
  179. numba_cuda/numba/cuda/memory_management/nrt_context.py +438 -0
  180. numba_cuda/numba/cuda/misc/appdirs.py +594 -0
  181. numba_cuda/numba/cuda/misc/cffiimpl.py +24 -0
  182. numba_cuda/numba/cuda/misc/coverage_support.py +43 -0
  183. numba_cuda/numba/cuda/misc/dump_style.py +41 -0
  184. numba_cuda/numba/cuda/misc/findlib.py +75 -0
  185. numba_cuda/numba/cuda/misc/firstlinefinder.py +96 -0
  186. numba_cuda/numba/cuda/misc/gdb_hook.py +240 -0
  187. numba_cuda/numba/cuda/misc/literal.py +28 -0
  188. numba_cuda/numba/cuda/misc/llvm_pass_timings.py +412 -0
  189. numba_cuda/numba/cuda/misc/special.py +94 -0
  190. numba_cuda/numba/cuda/models.py +56 -0
  191. numba_cuda/numba/cuda/np/arraymath.py +5130 -0
  192. numba_cuda/numba/cuda/np/arrayobj.py +7635 -0
  193. numba_cuda/numba/cuda/np/extensions.py +11 -0
  194. numba_cuda/numba/cuda/np/linalg.py +3087 -0
  195. numba_cuda/numba/cuda/np/math/__init__.py +0 -0
  196. numba_cuda/numba/cuda/np/math/cmathimpl.py +558 -0
  197. numba_cuda/numba/cuda/np/math/mathimpl.py +487 -0
  198. numba_cuda/numba/cuda/np/math/numbers.py +1461 -0
  199. numba_cuda/numba/cuda/np/npdatetime.py +969 -0
  200. numba_cuda/numba/cuda/np/npdatetime_helpers.py +217 -0
  201. numba_cuda/numba/cuda/np/npyfuncs.py +1808 -0
  202. numba_cuda/numba/cuda/np/npyimpl.py +1027 -0
  203. numba_cuda/numba/cuda/np/numpy_support.py +798 -0
  204. numba_cuda/numba/cuda/np/polynomial/__init__.py +4 -0
  205. numba_cuda/numba/cuda/np/polynomial/polynomial_core.py +242 -0
  206. numba_cuda/numba/cuda/np/polynomial/polynomial_functions.py +380 -0
  207. numba_cuda/numba/cuda/np/ufunc/__init__.py +4 -0
  208. numba_cuda/numba/cuda/np/ufunc/decorators.py +203 -0
  209. numba_cuda/numba/cuda/np/ufunc/sigparse.py +68 -0
  210. numba_cuda/numba/cuda/np/ufunc/ufuncbuilder.py +65 -0
  211. numba_cuda/numba/cuda/np/ufunc_db.py +1282 -0
  212. numba_cuda/numba/cuda/np/unsafe/__init__.py +0 -0
  213. numba_cuda/numba/cuda/np/unsafe/ndarray.py +84 -0
  214. numba_cuda/numba/cuda/nvvmutils.py +254 -0
  215. numba_cuda/numba/cuda/printimpl.py +126 -0
  216. numba_cuda/numba/cuda/random.py +308 -0
  217. numba_cuda/numba/cuda/reshape_funcs.cu +156 -0
  218. numba_cuda/numba/cuda/serialize.py +267 -0
  219. numba_cuda/numba/cuda/simulator/__init__.py +63 -0
  220. numba_cuda/numba/cuda/simulator/_internal/__init__.py +4 -0
  221. numba_cuda/numba/cuda/simulator/_internal/cuda_bf16.py +2 -0
  222. numba_cuda/numba/cuda/simulator/api.py +179 -0
  223. numba_cuda/numba/cuda/simulator/bf16.py +4 -0
  224. numba_cuda/numba/cuda/simulator/compiler.py +38 -0
  225. numba_cuda/numba/cuda/simulator/cudadrv/__init__.py +11 -0
  226. numba_cuda/numba/cuda/simulator/cudadrv/devicearray.py +462 -0
  227. numba_cuda/numba/cuda/simulator/cudadrv/devices.py +122 -0
  228. numba_cuda/numba/cuda/simulator/cudadrv/driver.py +66 -0
  229. numba_cuda/numba/cuda/simulator/cudadrv/drvapi.py +7 -0
  230. numba_cuda/numba/cuda/simulator/cudadrv/dummyarray.py +7 -0
  231. numba_cuda/numba/cuda/simulator/cudadrv/error.py +10 -0
  232. numba_cuda/numba/cuda/simulator/cudadrv/libs.py +10 -0
  233. numba_cuda/numba/cuda/simulator/cudadrv/linkable_code.py +61 -0
  234. numba_cuda/numba/cuda/simulator/cudadrv/nvrtc.py +11 -0
  235. numba_cuda/numba/cuda/simulator/cudadrv/nvvm.py +32 -0
  236. numba_cuda/numba/cuda/simulator/cudadrv/runtime.py +22 -0
  237. numba_cuda/numba/cuda/simulator/dispatcher.py +11 -0
  238. numba_cuda/numba/cuda/simulator/kernel.py +320 -0
  239. numba_cuda/numba/cuda/simulator/kernelapi.py +509 -0
  240. numba_cuda/numba/cuda/simulator/memory_management/__init__.py +4 -0
  241. numba_cuda/numba/cuda/simulator/memory_management/nrt.py +21 -0
  242. numba_cuda/numba/cuda/simulator/reduction.py +19 -0
  243. numba_cuda/numba/cuda/simulator/tests/support.py +4 -0
  244. numba_cuda/numba/cuda/simulator/vector_types.py +65 -0
  245. numba_cuda/numba/cuda/simulator_init.py +18 -0
  246. numba_cuda/numba/cuda/stubs.py +635 -0
  247. numba_cuda/numba/cuda/target.py +505 -0
  248. numba_cuda/numba/cuda/testing.py +347 -0
  249. numba_cuda/numba/cuda/tests/__init__.py +62 -0
  250. numba_cuda/numba/cuda/tests/benchmarks/__init__.py +0 -0
  251. numba_cuda/numba/cuda/tests/benchmarks/test_kernel_launch.py +119 -0
  252. numba_cuda/numba/cuda/tests/cloudpickle_main_class.py +9 -0
  253. numba_cuda/numba/cuda/tests/core/serialize_usecases.py +113 -0
  254. numba_cuda/numba/cuda/tests/core/test_itanium_mangler.py +83 -0
  255. numba_cuda/numba/cuda/tests/core/test_serialize.py +371 -0
  256. numba_cuda/numba/cuda/tests/cudadrv/__init__.py +9 -0
  257. numba_cuda/numba/cuda/tests/cudadrv/test_array_attr.py +147 -0
  258. numba_cuda/numba/cuda/tests/cudadrv/test_context_stack.py +161 -0
  259. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_array_slicing.py +397 -0
  260. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_auto_context.py +24 -0
  261. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_devicerecord.py +180 -0
  262. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_driver.py +313 -0
  263. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_memory.py +187 -0
  264. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +621 -0
  265. numba_cuda/numba/cuda/tests/cudadrv/test_deallocations.py +247 -0
  266. numba_cuda/numba/cuda/tests/cudadrv/test_detect.py +100 -0
  267. numba_cuda/numba/cuda/tests/cudadrv/test_emm_plugins.py +198 -0
  268. numba_cuda/numba/cuda/tests/cudadrv/test_events.py +53 -0
  269. numba_cuda/numba/cuda/tests/cudadrv/test_host_alloc.py +72 -0
  270. numba_cuda/numba/cuda/tests/cudadrv/test_init.py +138 -0
  271. numba_cuda/numba/cuda/tests/cudadrv/test_inline_ptx.py +43 -0
  272. numba_cuda/numba/cuda/tests/cudadrv/test_is_fp16.py +15 -0
  273. numba_cuda/numba/cuda/tests/cudadrv/test_linkable_code.py +58 -0
  274. numba_cuda/numba/cuda/tests/cudadrv/test_linker.py +348 -0
  275. numba_cuda/numba/cuda/tests/cudadrv/test_managed_alloc.py +128 -0
  276. numba_cuda/numba/cuda/tests/cudadrv/test_module_callbacks.py +301 -0
  277. numba_cuda/numba/cuda/tests/cudadrv/test_nvjitlink.py +174 -0
  278. numba_cuda/numba/cuda/tests/cudadrv/test_nvrtc.py +28 -0
  279. numba_cuda/numba/cuda/tests/cudadrv/test_nvvm_driver.py +185 -0
  280. numba_cuda/numba/cuda/tests/cudadrv/test_pinned.py +39 -0
  281. numba_cuda/numba/cuda/tests/cudadrv/test_profiler.py +23 -0
  282. numba_cuda/numba/cuda/tests/cudadrv/test_reset_device.py +38 -0
  283. numba_cuda/numba/cuda/tests/cudadrv/test_runtime.py +48 -0
  284. numba_cuda/numba/cuda/tests/cudadrv/test_select_device.py +44 -0
  285. numba_cuda/numba/cuda/tests/cudadrv/test_streams.py +127 -0
  286. numba_cuda/numba/cuda/tests/cudapy/__init__.py +9 -0
  287. numba_cuda/numba/cuda/tests/cudapy/cache_usecases.py +231 -0
  288. numba_cuda/numba/cuda/tests/cudapy/cache_with_cpu_usecases.py +50 -0
  289. numba_cuda/numba/cuda/tests/cudapy/cg_cache_usecases.py +36 -0
  290. numba_cuda/numba/cuda/tests/cudapy/complex_usecases.py +116 -0
  291. numba_cuda/numba/cuda/tests/cudapy/enum_usecases.py +59 -0
  292. numba_cuda/numba/cuda/tests/cudapy/extensions_usecases.py +62 -0
  293. numba_cuda/numba/cuda/tests/cudapy/jitlink.ptx +28 -0
  294. numba_cuda/numba/cuda/tests/cudapy/overload_usecases.py +33 -0
  295. numba_cuda/numba/cuda/tests/cudapy/recursion_usecases.py +104 -0
  296. numba_cuda/numba/cuda/tests/cudapy/test_alignment.py +47 -0
  297. numba_cuda/numba/cuda/tests/cudapy/test_analysis.py +1122 -0
  298. numba_cuda/numba/cuda/tests/cudapy/test_array.py +344 -0
  299. numba_cuda/numba/cuda/tests/cudapy/test_array_alignment.py +268 -0
  300. numba_cuda/numba/cuda/tests/cudapy/test_array_args.py +203 -0
  301. numba_cuda/numba/cuda/tests/cudapy/test_array_methods.py +63 -0
  302. numba_cuda/numba/cuda/tests/cudapy/test_array_reductions.py +360 -0
  303. numba_cuda/numba/cuda/tests/cudapy/test_atomics.py +1815 -0
  304. numba_cuda/numba/cuda/tests/cudapy/test_bfloat16.py +599 -0
  305. numba_cuda/numba/cuda/tests/cudapy/test_bfloat16_bindings.py +377 -0
  306. numba_cuda/numba/cuda/tests/cudapy/test_blackscholes.py +160 -0
  307. numba_cuda/numba/cuda/tests/cudapy/test_boolean.py +27 -0
  308. numba_cuda/numba/cuda/tests/cudapy/test_byteflow.py +98 -0
  309. numba_cuda/numba/cuda/tests/cudapy/test_cache_hints.py +210 -0
  310. numba_cuda/numba/cuda/tests/cudapy/test_caching.py +683 -0
  311. numba_cuda/numba/cuda/tests/cudapy/test_casting.py +265 -0
  312. numba_cuda/numba/cuda/tests/cudapy/test_cffi.py +42 -0
  313. numba_cuda/numba/cuda/tests/cudapy/test_compiler.py +718 -0
  314. numba_cuda/numba/cuda/tests/cudapy/test_complex.py +370 -0
  315. numba_cuda/numba/cuda/tests/cudapy/test_complex_kernel.py +23 -0
  316. numba_cuda/numba/cuda/tests/cudapy/test_const_string.py +142 -0
  317. numba_cuda/numba/cuda/tests/cudapy/test_constmem.py +178 -0
  318. numba_cuda/numba/cuda/tests/cudapy/test_cooperative_groups.py +193 -0
  319. numba_cuda/numba/cuda/tests/cudapy/test_copy_propagate.py +131 -0
  320. numba_cuda/numba/cuda/tests/cudapy/test_cuda_array_interface.py +438 -0
  321. numba_cuda/numba/cuda/tests/cudapy/test_cuda_jit_no_types.py +94 -0
  322. numba_cuda/numba/cuda/tests/cudapy/test_datetime.py +101 -0
  323. numba_cuda/numba/cuda/tests/cudapy/test_debug.py +105 -0
  324. numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py +889 -0
  325. numba_cuda/numba/cuda/tests/cudapy/test_debuginfo_types.py +476 -0
  326. numba_cuda/numba/cuda/tests/cudapy/test_device_func.py +500 -0
  327. numba_cuda/numba/cuda/tests/cudapy/test_dispatcher.py +820 -0
  328. numba_cuda/numba/cuda/tests/cudapy/test_enums.py +152 -0
  329. numba_cuda/numba/cuda/tests/cudapy/test_errors.py +111 -0
  330. numba_cuda/numba/cuda/tests/cudapy/test_exception.py +170 -0
  331. numba_cuda/numba/cuda/tests/cudapy/test_extending.py +1088 -0
  332. numba_cuda/numba/cuda/tests/cudapy/test_extending_types.py +71 -0
  333. numba_cuda/numba/cuda/tests/cudapy/test_fastmath.py +265 -0
  334. numba_cuda/numba/cuda/tests/cudapy/test_flow_control.py +1433 -0
  335. numba_cuda/numba/cuda/tests/cudapy/test_forall.py +57 -0
  336. numba_cuda/numba/cuda/tests/cudapy/test_freevar.py +34 -0
  337. numba_cuda/numba/cuda/tests/cudapy/test_frexp_ldexp.py +69 -0
  338. numba_cuda/numba/cuda/tests/cudapy/test_globals.py +62 -0
  339. numba_cuda/numba/cuda/tests/cudapy/test_gufunc.py +474 -0
  340. numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scalar.py +167 -0
  341. numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scheduling.py +92 -0
  342. numba_cuda/numba/cuda/tests/cudapy/test_idiv.py +39 -0
  343. numba_cuda/numba/cuda/tests/cudapy/test_inline.py +170 -0
  344. numba_cuda/numba/cuda/tests/cudapy/test_inspect.py +255 -0
  345. numba_cuda/numba/cuda/tests/cudapy/test_intrinsics.py +1219 -0
  346. numba_cuda/numba/cuda/tests/cudapy/test_ipc.py +263 -0
  347. numba_cuda/numba/cuda/tests/cudapy/test_ir.py +598 -0
  348. numba_cuda/numba/cuda/tests/cudapy/test_ir_utils.py +276 -0
  349. numba_cuda/numba/cuda/tests/cudapy/test_iterators.py +101 -0
  350. numba_cuda/numba/cuda/tests/cudapy/test_lang.py +68 -0
  351. numba_cuda/numba/cuda/tests/cudapy/test_laplace.py +123 -0
  352. numba_cuda/numba/cuda/tests/cudapy/test_libdevice.py +194 -0
  353. numba_cuda/numba/cuda/tests/cudapy/test_lineinfo.py +220 -0
  354. numba_cuda/numba/cuda/tests/cudapy/test_localmem.py +173 -0
  355. numba_cuda/numba/cuda/tests/cudapy/test_make_function_to_jit_function.py +364 -0
  356. numba_cuda/numba/cuda/tests/cudapy/test_mandel.py +47 -0
  357. numba_cuda/numba/cuda/tests/cudapy/test_math.py +842 -0
  358. numba_cuda/numba/cuda/tests/cudapy/test_matmul.py +76 -0
  359. numba_cuda/numba/cuda/tests/cudapy/test_minmax.py +78 -0
  360. numba_cuda/numba/cuda/tests/cudapy/test_montecarlo.py +25 -0
  361. numba_cuda/numba/cuda/tests/cudapy/test_multigpu.py +145 -0
  362. numba_cuda/numba/cuda/tests/cudapy/test_multiprocessing.py +39 -0
  363. numba_cuda/numba/cuda/tests/cudapy/test_multithreads.py +82 -0
  364. numba_cuda/numba/cuda/tests/cudapy/test_nondet.py +53 -0
  365. numba_cuda/numba/cuda/tests/cudapy/test_operator.py +504 -0
  366. numba_cuda/numba/cuda/tests/cudapy/test_optimization.py +93 -0
  367. numba_cuda/numba/cuda/tests/cudapy/test_overload.py +402 -0
  368. numba_cuda/numba/cuda/tests/cudapy/test_powi.py +128 -0
  369. numba_cuda/numba/cuda/tests/cudapy/test_print.py +193 -0
  370. numba_cuda/numba/cuda/tests/cudapy/test_py2_div_issue.py +37 -0
  371. numba_cuda/numba/cuda/tests/cudapy/test_random.py +117 -0
  372. numba_cuda/numba/cuda/tests/cudapy/test_record_dtype.py +614 -0
  373. numba_cuda/numba/cuda/tests/cudapy/test_recursion.py +130 -0
  374. numba_cuda/numba/cuda/tests/cudapy/test_reduction.py +94 -0
  375. numba_cuda/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py +83 -0
  376. numba_cuda/numba/cuda/tests/cudapy/test_serialize.py +86 -0
  377. numba_cuda/numba/cuda/tests/cudapy/test_slicing.py +40 -0
  378. numba_cuda/numba/cuda/tests/cudapy/test_sm.py +457 -0
  379. numba_cuda/numba/cuda/tests/cudapy/test_sm_creation.py +233 -0
  380. numba_cuda/numba/cuda/tests/cudapy/test_ssa.py +454 -0
  381. numba_cuda/numba/cuda/tests/cudapy/test_stream_api.py +56 -0
  382. numba_cuda/numba/cuda/tests/cudapy/test_sync.py +277 -0
  383. numba_cuda/numba/cuda/tests/cudapy/test_tracing.py +200 -0
  384. numba_cuda/numba/cuda/tests/cudapy/test_transpose.py +90 -0
  385. numba_cuda/numba/cuda/tests/cudapy/test_typeconv.py +333 -0
  386. numba_cuda/numba/cuda/tests/cudapy/test_typeinfer.py +538 -0
  387. numba_cuda/numba/cuda/tests/cudapy/test_ufuncs.py +585 -0
  388. numba_cuda/numba/cuda/tests/cudapy/test_userexc.py +42 -0
  389. numba_cuda/numba/cuda/tests/cudapy/test_vector_type.py +485 -0
  390. numba_cuda/numba/cuda/tests/cudapy/test_vectorize.py +312 -0
  391. numba_cuda/numba/cuda/tests/cudapy/test_vectorize_complex.py +23 -0
  392. numba_cuda/numba/cuda/tests/cudapy/test_vectorize_decor.py +183 -0
  393. numba_cuda/numba/cuda/tests/cudapy/test_vectorize_device.py +40 -0
  394. numba_cuda/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py +40 -0
  395. numba_cuda/numba/cuda/tests/cudapy/test_warning.py +206 -0
  396. numba_cuda/numba/cuda/tests/cudapy/test_warp_ops.py +331 -0
  397. numba_cuda/numba/cuda/tests/cudasim/__init__.py +9 -0
  398. numba_cuda/numba/cuda/tests/cudasim/support.py +9 -0
  399. numba_cuda/numba/cuda/tests/cudasim/test_cudasim_issues.py +111 -0
  400. numba_cuda/numba/cuda/tests/data/__init__.py +2 -0
  401. numba_cuda/numba/cuda/tests/data/cta_barrier.cu +28 -0
  402. numba_cuda/numba/cuda/tests/data/cuda_include.cu +10 -0
  403. numba_cuda/numba/cuda/tests/data/error.cu +12 -0
  404. numba_cuda/numba/cuda/tests/data/include/add.cuh +8 -0
  405. numba_cuda/numba/cuda/tests/data/jitlink.cu +28 -0
  406. numba_cuda/numba/cuda/tests/data/jitlink.ptx +49 -0
  407. numba_cuda/numba/cuda/tests/data/warn.cu +12 -0
  408. numba_cuda/numba/cuda/tests/doc_examples/__init__.py +9 -0
  409. numba_cuda/numba/cuda/tests/doc_examples/ffi/__init__.py +2 -0
  410. numba_cuda/numba/cuda/tests/doc_examples/ffi/functions.cu +54 -0
  411. numba_cuda/numba/cuda/tests/doc_examples/ffi/include/mul.cuh +8 -0
  412. numba_cuda/numba/cuda/tests/doc_examples/ffi/saxpy.cu +14 -0
  413. numba_cuda/numba/cuda/tests/doc_examples/test_cg.py +86 -0
  414. numba_cuda/numba/cuda/tests/doc_examples/test_cpointer.py +68 -0
  415. numba_cuda/numba/cuda/tests/doc_examples/test_cpu_gpu_compat.py +81 -0
  416. numba_cuda/numba/cuda/tests/doc_examples/test_ffi.py +141 -0
  417. numba_cuda/numba/cuda/tests/doc_examples/test_laplace.py +160 -0
  418. numba_cuda/numba/cuda/tests/doc_examples/test_matmul.py +180 -0
  419. numba_cuda/numba/cuda/tests/doc_examples/test_montecarlo.py +119 -0
  420. numba_cuda/numba/cuda/tests/doc_examples/test_random.py +66 -0
  421. numba_cuda/numba/cuda/tests/doc_examples/test_reduction.py +80 -0
  422. numba_cuda/numba/cuda/tests/doc_examples/test_sessionize.py +206 -0
  423. numba_cuda/numba/cuda/tests/doc_examples/test_ufunc.py +53 -0
  424. numba_cuda/numba/cuda/tests/doc_examples/test_vecadd.py +76 -0
  425. numba_cuda/numba/cuda/tests/nocuda/__init__.py +9 -0
  426. numba_cuda/numba/cuda/tests/nocuda/test_dummyarray.py +391 -0
  427. numba_cuda/numba/cuda/tests/nocuda/test_function_resolution.py +48 -0
  428. numba_cuda/numba/cuda/tests/nocuda/test_import.py +63 -0
  429. numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py +252 -0
  430. numba_cuda/numba/cuda/tests/nocuda/test_nvvm.py +59 -0
  431. numba_cuda/numba/cuda/tests/nrt/__init__.py +9 -0
  432. numba_cuda/numba/cuda/tests/nrt/test_nrt.py +387 -0
  433. numba_cuda/numba/cuda/tests/nrt/test_nrt_refct.py +124 -0
  434. numba_cuda/numba/cuda/tests/support.py +900 -0
  435. numba_cuda/numba/cuda/typeconv/__init__.py +4 -0
  436. numba_cuda/numba/cuda/typeconv/castgraph.py +137 -0
  437. numba_cuda/numba/cuda/typeconv/rules.py +63 -0
  438. numba_cuda/numba/cuda/typeconv/typeconv.py +121 -0
  439. numba_cuda/numba/cuda/types/__init__.py +233 -0
  440. numba_cuda/numba/cuda/types/__init__.pyi +167 -0
  441. numba_cuda/numba/cuda/types/abstract.py +9 -0
  442. numba_cuda/numba/cuda/types/common.py +9 -0
  443. numba_cuda/numba/cuda/types/containers.py +9 -0
  444. numba_cuda/numba/cuda/types/cuda_abstract.py +533 -0
  445. numba_cuda/numba/cuda/types/cuda_common.py +110 -0
  446. numba_cuda/numba/cuda/types/cuda_containers.py +971 -0
  447. numba_cuda/numba/cuda/types/cuda_function_type.py +230 -0
  448. numba_cuda/numba/cuda/types/cuda_functions.py +798 -0
  449. numba_cuda/numba/cuda/types/cuda_iterators.py +120 -0
  450. numba_cuda/numba/cuda/types/cuda_misc.py +569 -0
  451. numba_cuda/numba/cuda/types/cuda_npytypes.py +690 -0
  452. numba_cuda/numba/cuda/types/cuda_scalars.py +280 -0
  453. numba_cuda/numba/cuda/types/ext_types.py +101 -0
  454. numba_cuda/numba/cuda/types/function_type.py +11 -0
  455. numba_cuda/numba/cuda/types/functions.py +9 -0
  456. numba_cuda/numba/cuda/types/iterators.py +9 -0
  457. numba_cuda/numba/cuda/types/misc.py +9 -0
  458. numba_cuda/numba/cuda/types/npytypes.py +9 -0
  459. numba_cuda/numba/cuda/types/scalars.py +9 -0
  460. numba_cuda/numba/cuda/typing/__init__.py +19 -0
  461. numba_cuda/numba/cuda/typing/arraydecl.py +939 -0
  462. numba_cuda/numba/cuda/typing/asnumbatype.py +130 -0
  463. numba_cuda/numba/cuda/typing/bufproto.py +70 -0
  464. numba_cuda/numba/cuda/typing/builtins.py +1209 -0
  465. numba_cuda/numba/cuda/typing/cffi_utils.py +219 -0
  466. numba_cuda/numba/cuda/typing/cmathdecl.py +47 -0
  467. numba_cuda/numba/cuda/typing/collections.py +138 -0
  468. numba_cuda/numba/cuda/typing/context.py +782 -0
  469. numba_cuda/numba/cuda/typing/ctypes_utils.py +125 -0
  470. numba_cuda/numba/cuda/typing/dictdecl.py +63 -0
  471. numba_cuda/numba/cuda/typing/enumdecl.py +74 -0
  472. numba_cuda/numba/cuda/typing/listdecl.py +147 -0
  473. numba_cuda/numba/cuda/typing/mathdecl.py +158 -0
  474. numba_cuda/numba/cuda/typing/npdatetime.py +322 -0
  475. numba_cuda/numba/cuda/typing/npydecl.py +749 -0
  476. numba_cuda/numba/cuda/typing/setdecl.py +115 -0
  477. numba_cuda/numba/cuda/typing/templates.py +1446 -0
  478. numba_cuda/numba/cuda/typing/typeof.py +301 -0
  479. numba_cuda/numba/cuda/ufuncs.py +746 -0
  480. numba_cuda/numba/cuda/utils.py +724 -0
  481. numba_cuda/numba/cuda/vector_types.py +214 -0
  482. numba_cuda/numba/cuda/vectorizers.py +260 -0
  483. numba_cuda-0.21.1.dist-info/METADATA +109 -0
  484. numba_cuda-0.21.1.dist-info/RECORD +488 -0
  485. numba_cuda-0.21.1.dist-info/WHEEL +5 -0
  486. numba_cuda-0.21.1.dist-info/licenses/LICENSE +26 -0
  487. numba_cuda-0.21.1.dist-info/licenses/LICENSE.numba +24 -0
  488. numba_cuda-0.21.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1153 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: BSD-2-Clause
3
+
4
+ from collections import namedtuple
5
+ import math
6
+ from functools import reduce
7
+
8
+ import numpy as np
9
+ import operator
10
+
11
+ from llvmlite import ir
12
+
13
+ from numba.cuda.core.imputils import (
14
+ call_getiter,
15
+ call_iternext,
16
+ impl_ret_borrowed,
17
+ impl_ret_untracked,
18
+ numba_typeref_ctor,
19
+ Registry,
20
+ )
21
+ from numba.cuda import typing, types
22
+ from numba.cuda import cgutils
23
+ from numba.cuda.extending import overload, intrinsic, register_jitable
24
+ from numba.cuda.core.errors import (
25
+ TypingError,
26
+ LoweringError,
27
+ NumbaTypeError,
28
+ RequireLiteralValue,
29
+ )
30
+ from numba.cuda.typing.templates import AbstractTemplate, signature
31
+ from numba.cuda.typing.templates import infer_global
32
+ from numba.cuda.misc.special import literal_unroll
33
+ from numba.cuda.typing.asnumbatype import as_numba_type
34
+
35
+ from numba.cuda.typing.builtins import IndexValue, IndexValueType
36
+
37
+
38
+ registry = Registry("cpython.builtins")
39
+ lower = registry.lower
40
+ lower_cast = registry.lower_cast
41
+ lower_constant = registry.lower_constant
42
+ lower_getattr_generic = registry.lower_getattr_generic
43
+
44
+
45
+ @overload(operator.truth)
46
+ def ol_truth(val):
47
+ if isinstance(val, types.Boolean):
48
+
49
+ def impl(val):
50
+ return val
51
+
52
+ return impl
53
+
54
+
55
+ @lower(operator.is_not, types.Any, types.Any)
56
+ def generic_is_not(context, builder, sig, args):
57
+ """
58
+ Implement `x is not y` as `not (x is y)`.
59
+ """
60
+ is_impl = context.get_function(operator.is_, sig)
61
+ return builder.not_(is_impl(builder, args))
62
+
63
+
64
+ @lower(operator.is_, types.Any, types.Any)
65
+ def generic_is(context, builder, sig, args):
66
+ """
67
+ Default implementation for `x is y`
68
+ """
69
+ lhs_type, rhs_type = sig.args
70
+ # the lhs and rhs have the same type
71
+ if lhs_type == rhs_type:
72
+ # mutable types
73
+ if lhs_type.mutable:
74
+ msg = "no default `is` implementation"
75
+ raise LoweringError(msg)
76
+ # immutable types
77
+ else:
78
+ # fallbacks to `==`
79
+ try:
80
+ eq_impl = context.get_function(operator.eq, sig)
81
+ except NotImplementedError:
82
+ # no `==` implemented for this type
83
+ return cgutils.false_bit
84
+ else:
85
+ return eq_impl(builder, args)
86
+ else:
87
+ return cgutils.false_bit
88
+
89
+
90
+ @lower(operator.is_, types.Opaque, types.Opaque)
91
+ def opaque_is(context, builder, sig, args):
92
+ """
93
+ Implementation for `x is y` for Opaque types.
94
+ """
95
+ lhs_type, rhs_type = sig.args
96
+ # the lhs and rhs have the same type
97
+ if lhs_type == rhs_type:
98
+ lhs_ptr = builder.ptrtoint(args[0], cgutils.intp_t)
99
+ rhs_ptr = builder.ptrtoint(args[1], cgutils.intp_t)
100
+
101
+ return builder.icmp_unsigned("==", lhs_ptr, rhs_ptr)
102
+ else:
103
+ return cgutils.false_bit
104
+
105
+
106
+ @lower(operator.is_, types.Boolean, types.Boolean)
107
+ def bool_is_impl(context, builder, sig, args):
108
+ """
109
+ Implementation for `x is y` for types derived from types.Boolean
110
+ (e.g. BooleanLiteral), and cross-checks between literal and non-literal
111
+ booleans, to satisfy Python's behavior preserving identity for bools.
112
+ """
113
+ arg1, arg2 = args
114
+ arg1_type, arg2_type = sig.args
115
+ _arg1 = context.cast(builder, arg1, arg1_type, types.boolean)
116
+ _arg2 = context.cast(builder, arg2, arg2_type, types.boolean)
117
+ eq_impl = context.get_function(
118
+ operator.eq,
119
+ typing.signature(types.boolean, types.boolean, types.boolean),
120
+ )
121
+ return eq_impl(builder, (_arg1, _arg2))
122
+
123
+
124
+ # keep types.IntegerLiteral, as otherwise there's ambiguity between this and int_eq_impl
125
+ @lower(operator.eq, types.Literal, types.Literal)
126
+ @lower(operator.eq, types.IntegerLiteral, types.IntegerLiteral)
127
+ def const_eq_impl(context, builder, sig, args):
128
+ arg1, arg2 = sig.args
129
+ val = 0
130
+ if arg1.literal_value == arg2.literal_value:
131
+ val = 1
132
+ res = ir.Constant(ir.IntType(1), val)
133
+ return impl_ret_untracked(context, builder, sig.return_type, res)
134
+
135
+
136
+ # keep types.IntegerLiteral, as otherwise there's ambiguity between this and int_ne_impl
137
+ @lower(operator.ne, types.Literal, types.Literal)
138
+ @lower(operator.ne, types.IntegerLiteral, types.IntegerLiteral)
139
+ def const_ne_impl(context, builder, sig, args):
140
+ arg1, arg2 = sig.args
141
+ val = 0
142
+ if arg1.literal_value != arg2.literal_value:
143
+ val = 1
144
+ res = ir.Constant(ir.IntType(1), val)
145
+ return impl_ret_untracked(context, builder, sig.return_type, res)
146
+
147
+
148
+ def gen_non_eq(val):
149
+ def none_equality(a, b):
150
+ a_none = isinstance(a, types.NoneType)
151
+ b_none = isinstance(b, types.NoneType)
152
+ if a_none and b_none:
153
+
154
+ def impl(a, b):
155
+ return val
156
+
157
+ return impl
158
+ elif a_none ^ b_none:
159
+
160
+ def impl(a, b):
161
+ return not val
162
+
163
+ return impl
164
+
165
+ return none_equality
166
+
167
+
168
+ overload(operator.eq)(gen_non_eq(True))
169
+ overload(operator.ne)(gen_non_eq(False))
170
+
171
+ # -------------------------------------------------------------------------------
172
+
173
+
174
+ @lower_getattr_generic(types.DeferredType)
175
+ def deferred_getattr(context, builder, typ, value, attr):
176
+ """
177
+ Deferred.__getattr__ => redirect to the actual type.
178
+ """
179
+ inner_type = typ.get()
180
+ val = context.cast(builder, value, typ, inner_type)
181
+ imp = context.get_getattr(inner_type, attr)
182
+ return imp(context, builder, inner_type, val, attr)
183
+
184
+
185
+ @lower_cast(types.Any, types.DeferredType)
186
+ @lower_cast(types.Optional, types.DeferredType)
187
+ @lower_cast(types.Boolean, types.DeferredType)
188
+ def any_to_deferred(context, builder, fromty, toty, val):
189
+ actual = context.cast(builder, val, fromty, toty.get())
190
+ model = context.data_model_manager[toty]
191
+ return model.set(builder, model.make_uninitialized(), actual)
192
+
193
+
194
+ @lower_cast(types.DeferredType, types.Any)
195
+ @lower_cast(types.DeferredType, types.Boolean)
196
+ @lower_cast(types.DeferredType, types.Optional)
197
+ def deferred_to_any(context, builder, fromty, toty, val):
198
+ model = context.data_model_manager[fromty]
199
+ val = model.get(builder, val)
200
+ return context.cast(builder, val, fromty.get(), toty)
201
+
202
+
203
+ # ------------------------------------------------------------------------------
204
+
205
+
206
+ @lower(operator.getitem, types.CPointer, types.Integer)
207
+ def getitem_cpointer(context, builder, sig, args):
208
+ base_ptr, idx = args
209
+ elem_ptr = builder.gep(base_ptr, [idx])
210
+ res = builder.load(elem_ptr)
211
+ return impl_ret_borrowed(context, builder, sig.return_type, res)
212
+
213
+
214
+ @lower(operator.setitem, types.CPointer, types.Integer, types.Any)
215
+ def setitem_cpointer(context, builder, sig, args):
216
+ base_ptr, idx, val = args
217
+ elem_ptr = builder.gep(base_ptr, [idx])
218
+ builder.store(val, elem_ptr)
219
+
220
+
221
+ # -------------------------------------------------------------------------------
222
+
223
+
224
+ def do_minmax(context, builder, argtys, args, cmpop):
225
+ assert len(argtys) == len(args), (argtys, args)
226
+ assert len(args) > 0
227
+
228
+ def binary_minmax(accumulator, value):
229
+ # This is careful to reproduce Python's algorithm, e.g.
230
+ # max(1.5, nan, 2.5) should return 2.5 (not nan or 1.5)
231
+ accty, acc = accumulator
232
+ vty, v = value
233
+ ty = context.typing_context.unify_types(accty, vty)
234
+ assert ty is not None
235
+ acc = context.cast(builder, acc, accty, ty)
236
+ v = context.cast(builder, v, vty, ty)
237
+ cmpsig = typing.signature(types.boolean, ty, ty)
238
+ ge = context.get_function(cmpop, cmpsig)
239
+ pred = ge(builder, (v, acc))
240
+ res = builder.select(pred, v, acc)
241
+ return ty, res
242
+
243
+ typvals = zip(argtys, args)
244
+ resty, resval = reduce(binary_minmax, typvals)
245
+ return resval
246
+
247
+
248
+ @lower(max, types.BaseTuple)
249
+ def max_iterable(context, builder, sig, args):
250
+ argtys = list(sig.args[0])
251
+ args = cgutils.unpack_tuple(builder, args[0])
252
+ return do_minmax(context, builder, argtys, args, operator.gt)
253
+
254
+
255
+ @lower(max, types.VarArg(types.Any))
256
+ def max_vararg(context, builder, sig, args):
257
+ return do_minmax(context, builder, sig.args, args, operator.gt)
258
+
259
+
260
+ @lower(min, types.BaseTuple)
261
+ def min_iterable(context, builder, sig, args):
262
+ argtys = list(sig.args[0])
263
+ args = cgutils.unpack_tuple(builder, args[0])
264
+ return do_minmax(context, builder, argtys, args, operator.lt)
265
+
266
+
267
+ @lower(min, types.VarArg(types.Any))
268
+ def min_vararg(context, builder, sig, args):
269
+ return do_minmax(context, builder, sig.args, args, operator.lt)
270
+
271
+
272
+ def _round_intrinsic(tp):
273
+ # round() rounds half to even
274
+ return "llvm.rint.f%d" % (tp.bitwidth,)
275
+
276
+
277
+ @lower(round, types.Float)
278
+ def round_impl_unary(context, builder, sig, args):
279
+ fltty = sig.args[0]
280
+ llty = context.get_value_type(fltty)
281
+ module = builder.module
282
+ fnty = ir.FunctionType(llty, [llty])
283
+ fn = cgutils.get_or_insert_function(module, fnty, _round_intrinsic(fltty))
284
+ res = builder.call(fn, args)
285
+ # unary round() returns an int
286
+ res = builder.fptosi(res, context.get_value_type(sig.return_type))
287
+ return impl_ret_untracked(context, builder, sig.return_type, res)
288
+
289
+
290
+ @lower(round, types.Float, types.Integer)
291
+ def round_impl_binary(context, builder, sig, args):
292
+ fltty = sig.args[0]
293
+ # Allow calling the intrinsic from the Python implementation below.
294
+ # This avoids the conversion to an int in Python 3's unary round().
295
+ _round = types.ExternalFunction(
296
+ _round_intrinsic(fltty), typing.signature(fltty, fltty)
297
+ )
298
+
299
+ def round_ndigits(x, ndigits):
300
+ if math.isinf(x) or math.isnan(x):
301
+ return x
302
+
303
+ if ndigits >= 0:
304
+ if ndigits > 22:
305
+ # pow1 and pow2 are each safe from overflow, but
306
+ # pow1*pow2 ~= pow(10.0, ndigits) might overflow.
307
+ pow1 = 10.0 ** (ndigits - 22)
308
+ pow2 = 1e22
309
+ else:
310
+ pow1 = 10.0**ndigits
311
+ pow2 = 1.0
312
+ y = (x * pow1) * pow2
313
+ if math.isinf(y):
314
+ return x
315
+ return (_round(y) / pow2) / pow1
316
+
317
+ else:
318
+ pow1 = 10.0 ** (-ndigits)
319
+ y = x / pow1
320
+ return _round(y) * pow1
321
+
322
+ res = context.compile_internal(builder, round_ndigits, sig, args)
323
+ return impl_ret_untracked(context, builder, sig.return_type, res)
324
+
325
+
326
+ # -------------------------------------------------------------------------------
327
+ # Numeric constructors
328
+
329
+
330
+ @lower(int, types.Any)
331
+ @lower(float, types.Any)
332
+ def int_impl(context, builder, sig, args):
333
+ [ty] = sig.args
334
+ [val] = args
335
+ res = context.cast(builder, val, ty, sig.return_type)
336
+ return impl_ret_untracked(context, builder, sig.return_type, res)
337
+
338
+
339
+ @lower(float, types.StringLiteral)
340
+ def float_literal_impl(context, builder, sig, args):
341
+ [ty] = sig.args
342
+ res = context.get_constant(sig.return_type, float(ty.literal_value))
343
+ return impl_ret_untracked(context, builder, sig.return_type, res)
344
+
345
+
346
+ @lower(complex, types.VarArg(types.Any))
347
+ def complex_impl(context, builder, sig, args):
348
+ complex_type = sig.return_type
349
+ float_type = complex_type.underlying_float
350
+ if len(sig.args) == 1:
351
+ [argty] = sig.args
352
+ [arg] = args
353
+ if isinstance(argty, types.Complex):
354
+ # Cast Complex* to Complex*
355
+ res = context.cast(builder, arg, argty, complex_type)
356
+ return impl_ret_untracked(context, builder, sig.return_type, res)
357
+ else:
358
+ real = context.cast(builder, arg, argty, float_type)
359
+ imag = context.get_constant(float_type, 0)
360
+
361
+ elif len(sig.args) == 2:
362
+ [realty, imagty] = sig.args
363
+ [real, imag] = args
364
+ real = context.cast(builder, real, realty, float_type)
365
+ imag = context.cast(builder, imag, imagty, float_type)
366
+
367
+ cmplx = context.make_complex(builder, complex_type)
368
+ cmplx.real = real
369
+ cmplx.imag = imag
370
+ res = cmplx._getvalue()
371
+ return impl_ret_untracked(context, builder, sig.return_type, res)
372
+
373
+
374
+ @lower(types.NumberClass, types.Any)
375
+ def number_constructor(context, builder, sig, args):
376
+ """
377
+ Call a number class, e.g. np.int32(...)
378
+ """
379
+ if isinstance(sig.return_type, types.Array):
380
+ # Array constructor
381
+ dt = sig.return_type.dtype
382
+
383
+ def foo(*arg_hack):
384
+ return np.array(arg_hack, dtype=dt)
385
+
386
+ res = context.compile_internal(builder, foo, sig, args)
387
+ return impl_ret_untracked(context, builder, sig.return_type, res)
388
+ else:
389
+ # Scalar constructor
390
+ [val] = args
391
+ [valty] = sig.args
392
+ return context.cast(builder, val, valty, sig.return_type)
393
+
394
+
395
+ # -------------------------------------------------------------------------------
396
+ # Constants
397
+
398
+
399
+ @lower_constant(types.Dummy)
400
+ def constant_dummy(context, builder, ty, pyval):
401
+ # This handles None, etc.
402
+ return context.get_dummy_value()
403
+
404
+
405
+ @lower_constant(types.ExternalFunctionPointer)
406
+ def constant_function_pointer(context, builder, ty, pyval):
407
+ ptrty = context.get_function_pointer_type(ty)
408
+ ptrval = context.add_dynamic_addr(
409
+ builder, ty.get_pointer(pyval), info=str(pyval)
410
+ )
411
+ return builder.bitcast(ptrval, ptrty)
412
+
413
+
414
+ @lower_constant(types.Optional)
415
+ def constant_optional(context, builder, ty, pyval):
416
+ if pyval is None:
417
+ return context.make_optional_none(builder, ty.type)
418
+ else:
419
+ return context.make_optional_value(builder, ty.type, pyval)
420
+
421
+
422
+ # -----------------------------------------------------------------------------
423
+
424
+
425
+ @lower(type, types.Any)
426
+ def type_impl(context, builder, sig, args):
427
+ """
428
+ One-argument type() builtin.
429
+ """
430
+ return context.get_dummy_value()
431
+
432
+
433
+ @lower(iter, types.IterableType)
434
+ def iter_impl(context, builder, sig, args):
435
+ (ty,) = sig.args
436
+ (val,) = args
437
+ iterval = call_getiter(context, builder, ty, val)
438
+ return iterval
439
+
440
+
441
+ @lower(next, types.IteratorType)
442
+ def next_impl(context, builder, sig, args):
443
+ (iterty,) = sig.args
444
+ (iterval,) = args
445
+
446
+ res = call_iternext(context, builder, iterty, iterval)
447
+
448
+ with builder.if_then(builder.not_(res.is_valid()), likely=False):
449
+ context.call_conv.return_user_exc(builder, StopIteration, ())
450
+
451
+ return res.yielded_value()
452
+
453
+
454
+ # -----------------------------------------------------------------------------
455
+
456
+
457
+ @lower("not in", types.Any, types.Any)
458
+ def not_in(context, builder, sig, args):
459
+ def in_impl(a, b):
460
+ return operator.contains(b, a)
461
+
462
+ res = context.compile_internal(builder, in_impl, sig, args)
463
+ return builder.not_(res)
464
+
465
+
466
+ # -----------------------------------------------------------------------------
467
+
468
+
469
+ @lower(len, types.ConstSized)
470
+ def constsized_len(context, builder, sig, args):
471
+ [ty] = sig.args
472
+ retty = sig.return_type
473
+ res = context.get_constant(retty, len(ty.types))
474
+ return impl_ret_untracked(context, builder, sig.return_type, res)
475
+
476
+
477
+ @lower(bool, types.Sized)
478
+ def sized_bool(context, builder, sig, args):
479
+ [ty] = sig.args
480
+ if len(ty):
481
+ return cgutils.true_bit
482
+ else:
483
+ return cgutils.false_bit
484
+
485
+
486
+ @lower(tuple)
487
+ def lower_empty_tuple(context, builder, sig, args):
488
+ retty = sig.return_type
489
+ res = context.get_constant_undef(retty)
490
+ return impl_ret_untracked(context, builder, sig.return_type, res)
491
+
492
+
493
+ @lower(tuple, types.BaseTuple)
494
+ def lower_tuple(context, builder, sig, args):
495
+ (val,) = args
496
+ return impl_ret_borrowed(context, builder, sig.return_type, val)
497
+
498
+
499
+ @overload(bool)
500
+ def bool_sequence(x):
501
+ valid_types = (
502
+ types.CharSeq,
503
+ types.UnicodeCharSeq,
504
+ types.DictType,
505
+ types.ListType,
506
+ types.UnicodeType,
507
+ types.Set,
508
+ )
509
+
510
+ if isinstance(x, valid_types):
511
+
512
+ def bool_impl(x):
513
+ return len(x) > 0
514
+
515
+ return bool_impl
516
+
517
+
518
+ @overload(bool, inline="always")
519
+ def bool_none(x):
520
+ if isinstance(x, types.NoneType) or x is None:
521
+ return lambda x: False
522
+
523
+
524
+ # -----------------------------------------------------------------------------
525
+
526
+
527
+ def get_type_max_value(typ):
528
+ if isinstance(typ, types.Float):
529
+ return np.inf
530
+ if isinstance(typ, types.Integer):
531
+ return typ.maxval
532
+ raise NotImplementedError("Unsupported type")
533
+
534
+
535
+ def get_type_min_value(typ):
536
+ if isinstance(typ, types.Float):
537
+ return -np.inf
538
+ if isinstance(typ, types.Integer):
539
+ return typ.minval
540
+ raise NotImplementedError("Unsupported type")
541
+
542
+
543
+ @infer_global(get_type_min_value)
544
+ @infer_global(get_type_max_value)
545
+ class MinValInfer(AbstractTemplate):
546
+ def generic(self, args, kws):
547
+ assert not kws
548
+ assert len(args) == 1
549
+ if isinstance(args[0], (types.DType, types.NumberClass)):
550
+ return signature(args[0].dtype, *args)
551
+
552
+
553
+ @lower(get_type_min_value, types.NumberClass)
554
+ @lower(get_type_min_value, types.DType)
555
+ def lower_get_type_min_value(context, builder, sig, args):
556
+ typ = sig.args[0].dtype
557
+
558
+ if isinstance(typ, types.Integer):
559
+ bw = typ.bitwidth
560
+ lty = ir.IntType(bw)
561
+ val = typ.minval
562
+ res = ir.Constant(lty, val)
563
+ elif isinstance(typ, types.Float):
564
+ bw = typ.bitwidth
565
+ if bw == 32:
566
+ lty = ir.FloatType()
567
+ elif bw == 64:
568
+ lty = ir.DoubleType()
569
+ else:
570
+ raise NotImplementedError(
571
+ "llvmlite only supports 32 and 64 bit floats"
572
+ )
573
+ npty = getattr(np, "float{}".format(bw)) # noqa: F841
574
+ res = ir.Constant(lty, -np.inf)
575
+ elif isinstance(typ, (types.NPDatetime, types.NPTimedelta)):
576
+ bw = 64
577
+ lty = ir.IntType(bw)
578
+ val = (
579
+ types.int64.minval + 1
580
+ ) # minval is NaT, so minval + 1 is the smallest value
581
+ res = ir.Constant(lty, val)
582
+ return impl_ret_untracked(context, builder, lty, res)
583
+
584
+
585
+ @lower(get_type_max_value, types.NumberClass)
586
+ @lower(get_type_max_value, types.DType)
587
+ def lower_get_type_max_value(context, builder, sig, args):
588
+ typ = sig.args[0].dtype
589
+
590
+ if isinstance(typ, types.Integer):
591
+ bw = typ.bitwidth
592
+ lty = ir.IntType(bw)
593
+ val = typ.maxval
594
+ res = ir.Constant(lty, val)
595
+ elif isinstance(typ, types.Float):
596
+ bw = typ.bitwidth
597
+ if bw == 32:
598
+ lty = ir.FloatType()
599
+ elif bw == 64:
600
+ lty = ir.DoubleType()
601
+ else:
602
+ raise NotImplementedError(
603
+ "llvmlite only supports 32 and 64 bit floats"
604
+ )
605
+ npty = getattr(np, "float{}".format(bw)) # noqa: F841
606
+ res = ir.Constant(lty, np.inf)
607
+ elif isinstance(typ, (types.NPDatetime, types.NPTimedelta)):
608
+ bw = 64
609
+ lty = ir.IntType(bw)
610
+ val = types.int64.maxval
611
+ res = ir.Constant(lty, val)
612
+ return impl_ret_untracked(context, builder, lty, res)
613
+
614
+
615
+ # -----------------------------------------------------------------------------
616
+
617
+
618
+ @lower(IndexValue, types.intp, types.Type)
619
+ @lower(IndexValue, types.uintp, types.Type)
620
+ def impl_index_value(context, builder, sig, args):
621
+ typ = sig.return_type
622
+ index, value = args
623
+ index_value = cgutils.create_struct_proxy(typ)(context, builder)
624
+ index_value.index = index
625
+ index_value.value = value
626
+ return index_value._getvalue()
627
+
628
+
629
+ @overload(min)
630
+ def indval_min(indval1, indval2):
631
+ if isinstance(indval1, IndexValueType) and isinstance(
632
+ indval2, IndexValueType
633
+ ):
634
+
635
+ def min_impl(indval1, indval2):
636
+ if np.isnan(indval1.value):
637
+ if np.isnan(indval2.value):
638
+ # both indval1 and indval2 are nans so order by index
639
+ if indval1.index < indval2.index:
640
+ return indval1
641
+ else:
642
+ return indval2
643
+ else:
644
+ # comparing against one nan always considered less
645
+ return indval1
646
+ elif np.isnan(indval2.value):
647
+ # indval1 not a nan but indval2 is so consider indval2 less
648
+ return indval2
649
+ elif indval1.value > indval2.value:
650
+ return indval2
651
+ elif indval1.value == indval2.value:
652
+ if indval1.index < indval2.index:
653
+ return indval1
654
+ else:
655
+ return indval2
656
+ return indval1
657
+
658
+ return min_impl
659
+
660
+
661
+ @overload(min)
662
+ def boolval_min(val1, val2):
663
+ if isinstance(val1, types.Boolean) and isinstance(val2, types.Boolean):
664
+
665
+ def bool_min_impl(val1, val2):
666
+ return val1 and val2
667
+
668
+ return bool_min_impl
669
+
670
+
671
+ @overload(max)
672
+ def indval_max(indval1, indval2):
673
+ if isinstance(indval1, IndexValueType) and isinstance(
674
+ indval2, IndexValueType
675
+ ):
676
+
677
+ def max_impl(indval1, indval2):
678
+ if np.isnan(indval1.value):
679
+ if np.isnan(indval2.value):
680
+ # both indval1 and indval2 are nans so order by index
681
+ if indval1.index < indval2.index:
682
+ return indval1
683
+ else:
684
+ return indval2
685
+ else:
686
+ # comparing against one nan always considered larger
687
+ return indval1
688
+ elif np.isnan(indval2.value):
689
+ # indval1 not a nan but indval2 is so consider indval2 larger
690
+ return indval2
691
+ elif indval2.value > indval1.value:
692
+ return indval2
693
+ elif indval1.value == indval2.value:
694
+ if indval1.index < indval2.index:
695
+ return indval1
696
+ else:
697
+ return indval2
698
+ return indval1
699
+
700
+ return max_impl
701
+
702
+
703
+ @overload(max)
704
+ def boolval_max(val1, val2):
705
+ if isinstance(val1, types.Boolean) and isinstance(val2, types.Boolean):
706
+
707
+ def bool_max_impl(val1, val2):
708
+ return val1 or val2
709
+
710
+ return bool_max_impl
711
+
712
+
713
+ greater_than = register_jitable(lambda a, b: a > b)
714
+ less_than = register_jitable(lambda a, b: a < b)
715
+
716
+
717
+ @register_jitable
718
+ def min_max_impl(iterable, op):
719
+ if isinstance(iterable, types.IterableType):
720
+
721
+ def impl(iterable):
722
+ it = iter(iterable)
723
+ return_val = next(it)
724
+ for val in it:
725
+ if op(val, return_val):
726
+ return_val = val
727
+ return return_val
728
+
729
+ return impl
730
+
731
+
732
+ @overload(min)
733
+ def iterable_min(iterable):
734
+ return min_max_impl(iterable, less_than)
735
+
736
+
737
+ @overload(max)
738
+ def iterable_max(iterable):
739
+ return min_max_impl(iterable, greater_than)
740
+
741
+
742
+ @lower(types.TypeRef, types.VarArg(types.Any))
743
+ def redirect_type_ctor(context, builder, sig, args):
744
+ """Redirect constructor implementation to `numba_typeref_ctor(cls, *args)`,
745
+ which should be overloaded by the type's implementation.
746
+
747
+ For example:
748
+
749
+ d = Dict()
750
+
751
+ `d` will be typed as `TypeRef[DictType]()`. Thus, it will call into this
752
+ implementation. We need to redirect the lowering to a function
753
+ named ``numba_typeref_ctor``.
754
+ """
755
+ cls = sig.return_type
756
+
757
+ def call_ctor(cls, *args):
758
+ return numba_typeref_ctor(cls, *args)
759
+
760
+ # Pack arguments into a tuple for `*args`
761
+ ctor_args = types.Tuple.from_types(sig.args)
762
+ # Make signature T(TypeRef[T], *args) where T is cls
763
+ sig = typing.signature(cls, types.TypeRef(cls), ctor_args)
764
+ if len(ctor_args) > 0:
765
+ args = (
766
+ context.get_dummy_value(), # Type object has no runtime repr.
767
+ context.make_tuple(builder, ctor_args, args),
768
+ )
769
+ else:
770
+ args = (
771
+ context.get_dummy_value(), # Type object has no runtime repr.
772
+ context.make_tuple(builder, ctor_args, ()),
773
+ )
774
+
775
+ return context.compile_internal(builder, call_ctor, sig, args)
776
+
777
+
778
+ @overload(sum)
779
+ def ol_sum(iterable, start=0):
780
+ # Cpython explicitly rejects strings, bytes and bytearrays
781
+ # https://github.com/python/cpython/blob/3.9/Python/bltinmodule.c#L2310-L2329 # noqa: E501
782
+ error = None
783
+ if isinstance(start, types.UnicodeType):
784
+ error = ("strings", "")
785
+ elif isinstance(start, types.Bytes):
786
+ error = ("bytes", "b")
787
+ elif isinstance(start, types.ByteArray):
788
+ error = ("bytearray", "b")
789
+
790
+ if error is not None:
791
+ msg = "sum() can't sum {} [use {}''.join(seq) instead]".format(*error)
792
+ raise TypingError(msg)
793
+
794
+ # if the container is homogeneous then it's relatively easy to handle.
795
+ if isinstance(
796
+ iterable,
797
+ (
798
+ types.containers._HomogeneousTuple,
799
+ types.List,
800
+ types.ListType,
801
+ types.Array,
802
+ types.RangeType,
803
+ ),
804
+ ):
805
+ iterator = iter
806
+ elif isinstance(iterable, (types.containers._HeterogeneousTuple)):
807
+ # if container is heterogeneous then literal unroll and hope for the
808
+ # best.
809
+ iterator = literal_unroll
810
+ else:
811
+ return None
812
+
813
+ def impl(iterable, start=0):
814
+ acc = start
815
+ for x in iterator(iterable):
816
+ # This most likely widens the type, this is expected Numba behaviour
817
+ acc = acc + x
818
+ return acc
819
+
820
+ return impl
821
+
822
+
823
+ # ------------------------------------------------------------------------------
824
+ # map, filter, reduce
825
+
826
+
827
+ @overload(map)
828
+ def ol_map(func, iterable, *args):
829
+ def impl(func, iterable, *args):
830
+ for x in zip(iterable, *args):
831
+ yield func(*x)
832
+
833
+ return impl
834
+
835
+
836
+ @overload(filter)
837
+ def ol_filter(func, iterable):
838
+ if (func is None) or isinstance(func, types.NoneType):
839
+
840
+ def impl(func, iterable):
841
+ for x in iterable:
842
+ if x:
843
+ yield x
844
+ else:
845
+
846
+ def impl(func, iterable):
847
+ for x in iterable:
848
+ if func(x):
849
+ yield x
850
+
851
+ return impl
852
+
853
+
854
+ @overload(isinstance)
855
+ def ol_isinstance(var, typs):
856
+ def true_impl(var, typs):
857
+ return True
858
+
859
+ def false_impl(var, typs):
860
+ return False
861
+
862
+ var_ty = as_numba_type(var)
863
+
864
+ if isinstance(var_ty, types.Optional):
865
+ msg = f'isinstance cannot handle optional types. Found: "{var_ty}"'
866
+ raise NumbaTypeError(msg)
867
+
868
+ # NOTE: The current implementation of `isinstance` restricts the type of the
869
+ # instance variable to types that are well known and in common use. The
870
+ # danger of unrestricted type comparison is that a "default" of `False` is
871
+ # required and this means that if there is a bug in the logic of the
872
+ # comparison tree `isinstance` returns False! It's therefore safer to just
873
+ # reject the compilation as untypable!
874
+ supported_var_ty = (
875
+ types.Number,
876
+ types.Bytes,
877
+ types.RangeType,
878
+ types.DictType,
879
+ types.LiteralStrKeyDict,
880
+ types.List,
881
+ types.ListType,
882
+ types.Tuple,
883
+ types.UniTuple,
884
+ types.Set,
885
+ types.Function,
886
+ types.ClassType,
887
+ types.UnicodeType,
888
+ types.ClassInstanceType,
889
+ types.NoneType,
890
+ types.Array,
891
+ types.Boolean,
892
+ types.Float,
893
+ types.UnicodeCharSeq,
894
+ types.Complex,
895
+ types.NPDatetime,
896
+ types.NPTimedelta,
897
+ )
898
+ if not isinstance(var_ty, supported_var_ty):
899
+ msg = f'isinstance() does not support variables of type "{var_ty}".'
900
+ raise NumbaTypeError(msg)
901
+
902
+ t_typs = typs
903
+
904
+ # Check the types that the var can be an instance of, it'll be a scalar,
905
+ # a unituple or a tuple.
906
+ if isinstance(t_typs, types.UniTuple):
907
+ # corner case - all types in isinstance are the same
908
+ t_typs = t_typs.key[0]
909
+
910
+ if not isinstance(t_typs, types.Tuple):
911
+ t_typs = (t_typs,)
912
+
913
+ for typ in t_typs:
914
+ if isinstance(typ, types.Function):
915
+ key = typ.key[0] # functions like int(..), float(..), str(..)
916
+ elif isinstance(typ, types.ClassType):
917
+ key = typ # jitclasses
918
+ else:
919
+ key = typ.key
920
+
921
+ # corner cases for bytes, range, ...
922
+ # avoid registering those types on `as_numba_type`
923
+ types_not_registered = {
924
+ bytes: types.Bytes,
925
+ range: types.RangeType,
926
+ dict: (types.DictType, types.LiteralStrKeyDict),
927
+ list: types.List,
928
+ tuple: types.BaseTuple,
929
+ set: types.Set,
930
+ }
931
+ if key in types_not_registered:
932
+ if isinstance(var_ty, types_not_registered[key]):
933
+ return true_impl
934
+ continue
935
+
936
+ if isinstance(typ, types.TypeRef):
937
+ # Use of Numba type classes is in general not supported as they do
938
+ # not work when the jit is disabled.
939
+ if key not in (types.ListType, types.DictType):
940
+ msg = (
941
+ "Numba type classes (except numba.typed.* container "
942
+ "types) are not supported."
943
+ )
944
+ raise NumbaTypeError(msg)
945
+ # Case for TypeRef (i.e. isinstance(var, typed.List))
946
+ # var_ty == ListType[int64] (instance)
947
+ # typ == types.ListType (class)
948
+ return true_impl if type(var_ty) is key else false_impl
949
+ else:
950
+ numba_typ = as_numba_type(key)
951
+ if var_ty == numba_typ:
952
+ return true_impl
953
+ elif isinstance(numba_typ, (types.NPDatetime, types.NPTimedelta)):
954
+ if isinstance(var_ty, type(numba_typ)):
955
+ return true_impl
956
+ elif (
957
+ isinstance(numba_typ, types.ClassType)
958
+ and isinstance(var_ty, types.ClassInstanceType)
959
+ and var_ty.key == numba_typ.instance_type.key
960
+ ):
961
+ # check for jitclasses
962
+ return true_impl
963
+ elif (
964
+ isinstance(numba_typ, types.Container)
965
+ and numba_typ.key[0] == types.undefined
966
+ ):
967
+ # check for containers (list, tuple, set, ...)
968
+ if isinstance(var_ty, numba_typ.__class__) or (
969
+ isinstance(var_ty, types.BaseTuple)
970
+ and isinstance(numba_typ, types.BaseTuple)
971
+ ):
972
+ return true_impl
973
+
974
+ return false_impl
975
+
976
+
977
+ # -- getattr implementation
978
+
979
+
980
+ def _getattr_raise_attr_exc(obj, name):
981
+ # Dummy function for the purpose of creating an overloadable stub from
982
+ # which to raise an AttributeError as needed
983
+ pass
984
+
985
+
986
+ @overload(_getattr_raise_attr_exc)
987
+ def ol__getattr_raise_attr_exc(obj, name):
988
+ if not isinstance(name, types.StringLiteral):
989
+ raise RequireLiteralValue("argument 'name' must be a literal string")
990
+ lname = name.literal_value
991
+ message = f"'{obj}' has no attribute '{lname}'"
992
+
993
+ def impl(obj, name):
994
+ raise AttributeError(message)
995
+
996
+ return impl
997
+
998
+
999
+ @intrinsic
1000
+ def resolve_getattr(tyctx, obj, name, default):
1001
+ if not isinstance(name, types.StringLiteral):
1002
+ raise RequireLiteralValue("argument 'name' must be a literal string")
1003
+ lname = name.literal_value
1004
+ fn = tyctx.resolve_getattr(obj, lname)
1005
+ # Cannot handle things like `getattr(np, 'cos')` as the return type is
1006
+ # types.Function.
1007
+ if isinstance(fn, types.Function):
1008
+ msg = (
1009
+ "Returning function objects is not implemented. "
1010
+ f"getattr() was requested to return {fn} from attribute "
1011
+ f"'{lname}' of {obj}."
1012
+ )
1013
+ raise TypingError(msg)
1014
+
1015
+ if fn is None: # No attribute
1016
+ # if default is not _getattr_default then return the default
1017
+ if not (
1018
+ isinstance(default, types.NamedTuple)
1019
+ and default.instance_class == _getattr_default_type
1020
+ ):
1021
+ # it's not the marker default value, so return it
1022
+ sig = default(obj, name, default)
1023
+
1024
+ def impl(cgctx, builder, sig, llargs):
1025
+ tmp = llargs[-1]
1026
+ cgctx.nrt.incref(builder, default, tmp)
1027
+ return tmp
1028
+ else:
1029
+ # else wire in raising an AttributeError
1030
+ fnty = tyctx.resolve_value_type(_getattr_raise_attr_exc)
1031
+ raise_sig = fnty.get_call_type(tyctx, (obj, name), {})
1032
+ sig = types.none(obj, name, default)
1033
+
1034
+ def impl(cgctx, builder, sig, llargs):
1035
+ native_impl = cgctx.get_function(fnty, raise_sig)
1036
+ return native_impl(builder, llargs[:-1])
1037
+
1038
+ else: # Attribute present, wire in handing it back to the overload(getattr)
1039
+ sig = fn(obj, name, default)
1040
+ if isinstance(fn, types.BoundFunction):
1041
+ # It's a method on an object
1042
+ def impl(cgctx, builder, sig, ll_args):
1043
+ cast_type = fn.this
1044
+ casted = cgctx.cast(builder, ll_args[0], obj, cast_type)
1045
+ res = cgctx.get_bound_function(builder, casted, cast_type)
1046
+ cgctx.nrt.incref(builder, fn, res)
1047
+ return res
1048
+ else:
1049
+ # Else it's some other type of attribute.
1050
+ # Ensure typing calls occur at typing time, not at lowering
1051
+ attrty = tyctx.resolve_getattr(obj, lname)
1052
+
1053
+ def impl(cgctx, builder, sig, ll_args):
1054
+ attr_impl = cgctx.get_getattr(obj, lname)
1055
+ res = attr_impl(cgctx, builder, obj, ll_args[0], lname)
1056
+ casted = cgctx.cast(builder, res, attrty, fn)
1057
+ cgctx.nrt.incref(builder, fn, casted)
1058
+ return casted
1059
+
1060
+ return sig, impl
1061
+
1062
+
1063
+ # These are marker objects to indicate "no default has been provided" in a call
1064
+ _getattr_default_type = namedtuple("_getattr_default_type", "")
1065
+ _getattr_default = _getattr_default_type()
1066
+
1067
+
1068
+ # getattr with no default arg, obj is an open type and name is forced as a
1069
+ # literal string. The _getattr_default marker is used to indicate "no default
1070
+ # was provided".
1071
+ @overload(getattr, prefer_literal=True)
1072
+ def ol_getattr_2(obj, name):
1073
+ def impl(obj, name):
1074
+ return resolve_getattr(obj, name, _getattr_default)
1075
+
1076
+ return impl
1077
+
1078
+
1079
+ # getattr with default arg present, obj is an open type, name is forced as a
1080
+ # literal string, the "default" is again an open type. Note that the CPython
1081
+ # definition is: `getattr(object, name[, default]) -> value`, the `default`
1082
+ # is not a kwarg.
1083
+ @overload(getattr)
1084
+ def ol_getattr_3(obj, name, default):
1085
+ def impl(obj, name, default):
1086
+ return resolve_getattr(obj, name, default)
1087
+
1088
+ return impl
1089
+
1090
+
1091
+ @intrinsic
1092
+ def resolve_hasattr(tyctx, obj, name):
1093
+ if not isinstance(name, types.StringLiteral):
1094
+ raise RequireLiteralValue("argument 'name' must be a literal string")
1095
+ lname = name.literal_value
1096
+ fn = tyctx.resolve_getattr(obj, lname)
1097
+ # Whilst technically the return type could be a types.bool_, the literal
1098
+ # value is resolvable at typing time. Propagating this literal information
1099
+ # into the type system allows the compiler to prune branches based on a
1100
+ # hasattr predicate. As a result the signature is based on literals. This is
1101
+ # "safe" because the overload requires a literal string so each will be a
1102
+ # different variant of (obj, literal(name)) -> literal(bool).
1103
+ if fn is None:
1104
+ retty = types.literal(False)
1105
+ else:
1106
+ retty = types.literal(True)
1107
+ sig = retty(obj, name)
1108
+
1109
+ def impl(cgctx, builder, sig, ll_args):
1110
+ return cgutils.false_bit if fn is None else cgutils.true_bit
1111
+
1112
+ return sig, impl
1113
+
1114
+
1115
+ # hasattr cannot be implemented as a getattr call and then catching
1116
+ # AttributeError because Numba doesn't support catching anything other than
1117
+ # "Exception", so lacks the specificity required. Instead this implementation
1118
+ # tries to resolve the attribute via typing information and returns True/False
1119
+ # based on that.
1120
+ @overload(hasattr)
1121
+ def ol_hasattr(obj, name):
1122
+ def impl(obj, name):
1123
+ return resolve_hasattr(obj, name)
1124
+
1125
+ return impl
1126
+
1127
+
1128
+ @overload(repr)
1129
+ def ol_repr_generic(obj):
1130
+ missing_repr_format = f"<object type:{obj}>"
1131
+
1132
+ def impl(obj):
1133
+ attr = "__repr__"
1134
+ if hasattr(obj, attr):
1135
+ return getattr(obj, attr)()
1136
+ else:
1137
+ # There's no __str__ or __repr__ defined for this object, return
1138
+ # something generic
1139
+ return missing_repr_format
1140
+
1141
+ return impl
1142
+
1143
+
1144
+ @overload(str)
1145
+ def ol_str_generic(object=""):
1146
+ def impl(object=""):
1147
+ attr = "__str__"
1148
+ if hasattr(object, attr):
1149
+ return getattr(object, attr)()
1150
+ else:
1151
+ return repr(object)
1152
+
1153
+ return impl