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,798 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: BSD-2-Clause
3
+
4
+ import collections
5
+ import ctypes
6
+ import re
7
+ import numpy as np
8
+
9
+ from numba.cuda import types
10
+ from numba.cuda.core import errors
11
+ from numba.cuda.typing.templates import signature
12
+ from numba.cuda.np import npdatetime_helpers
13
+ from numba.cuda.core.errors import TypingError
14
+
15
+ # re-export
16
+ from numba.cuda.cgutils import is_nonelike # noqa: F401
17
+
18
+ numpy_version = tuple(map(int, np.__version__.split(".")[:2]))
19
+
20
+ FROM_DTYPE = {
21
+ np.dtype("bool"): types.boolean,
22
+ np.dtype("int8"): types.int8,
23
+ np.dtype("int16"): types.int16,
24
+ np.dtype("int32"): types.int32,
25
+ np.dtype("int64"): types.int64,
26
+ np.dtype("uint8"): types.uint8,
27
+ np.dtype("uint16"): types.uint16,
28
+ np.dtype("uint32"): types.uint32,
29
+ np.dtype("uint64"): types.uint64,
30
+ np.dtype("float32"): types.float32,
31
+ np.dtype("float64"): types.float64,
32
+ np.dtype("float16"): types.float16,
33
+ np.dtype("complex64"): types.complex64,
34
+ np.dtype("complex128"): types.complex128,
35
+ np.dtype(object): types.pyobject,
36
+ }
37
+
38
+ re_typestr = re.compile(r"[<>=\|]([a-z])(\d+)?$", re.I)
39
+ re_datetimestr = re.compile(r"[<>=\|]([mM])8?(\[([a-z]+)\])?$", re.I)
40
+
41
+ sizeof_unicode_char = np.dtype("U1").itemsize
42
+
43
+
44
+ def _from_str_dtype(dtype):
45
+ m = re_typestr.match(dtype.str)
46
+ if not m:
47
+ raise errors.NumbaNotImplementedError(dtype)
48
+ groups = m.groups()
49
+ typecode = groups[0]
50
+ if typecode == "U":
51
+ # unicode
52
+ if dtype.byteorder not in "=|":
53
+ raise errors.NumbaNotImplementedError(
54
+ "Does not support non-native byteorder"
55
+ )
56
+ count = dtype.itemsize // sizeof_unicode_char
57
+ assert count == int(groups[1]), "Unicode char size mismatch"
58
+ return types.UnicodeCharSeq(count)
59
+
60
+ elif typecode == "S":
61
+ # char
62
+ count = dtype.itemsize
63
+ assert count == int(groups[1]), "Char size mismatch"
64
+ return types.CharSeq(count)
65
+
66
+ else:
67
+ raise errors.NumbaNotImplementedError(dtype)
68
+
69
+
70
+ def _from_datetime_dtype(dtype):
71
+ m = re_datetimestr.match(dtype.str)
72
+ if not m:
73
+ raise errors.NumbaNotImplementedError(dtype)
74
+ groups = m.groups()
75
+ typecode = groups[0]
76
+ unit = groups[2] or ""
77
+ if typecode == "m":
78
+ return types.NPTimedelta(unit)
79
+ elif typecode == "M":
80
+ return types.NPDatetime(unit)
81
+ else:
82
+ raise errors.NumbaNotImplementedError(dtype)
83
+
84
+
85
+ def from_dtype(dtype):
86
+ """
87
+ Return a Numba Type instance corresponding to the given Numpy *dtype*.
88
+ NumbaNotImplementedError is raised on unsupported Numpy dtypes.
89
+ """
90
+ if type(dtype) is type and issubclass(dtype, np.generic):
91
+ dtype = np.dtype(dtype)
92
+ elif getattr(dtype, "fields", None) is not None:
93
+ return from_struct_dtype(dtype)
94
+
95
+ try:
96
+ return FROM_DTYPE[dtype]
97
+ except KeyError:
98
+ pass
99
+
100
+ try:
101
+ char = dtype.char
102
+ except AttributeError:
103
+ pass
104
+ else:
105
+ if char in "SU":
106
+ return _from_str_dtype(dtype)
107
+ if char in "mM":
108
+ return _from_datetime_dtype(dtype)
109
+ if char in "V" and dtype.subdtype is not None:
110
+ subtype = from_dtype(dtype.subdtype[0])
111
+ return types.NestedArray(subtype, dtype.shape)
112
+
113
+ raise errors.NumbaNotImplementedError(dtype)
114
+
115
+
116
+ _as_dtype_letters = {
117
+ types.NPDatetime: "M8",
118
+ types.NPTimedelta: "m8",
119
+ types.CharSeq: "S",
120
+ types.UnicodeCharSeq: "U",
121
+ }
122
+
123
+
124
+ def as_dtype(nbtype):
125
+ """
126
+ Return a numpy dtype instance corresponding to the given Numba type.
127
+ NotImplementedError is if no correspondence is known.
128
+ """
129
+ nbtype = types.unliteral(nbtype)
130
+ if isinstance(nbtype, (types.Complex, types.Integer, types.Float)):
131
+ return np.dtype(str(nbtype))
132
+ if isinstance(nbtype, (types.Boolean)):
133
+ return np.dtype("?")
134
+ if isinstance(nbtype, (types.NPDatetime, types.NPTimedelta)):
135
+ letter = _as_dtype_letters[type(nbtype)]
136
+ if nbtype.unit:
137
+ return np.dtype("%s[%s]" % (letter, nbtype.unit))
138
+ else:
139
+ return np.dtype(letter)
140
+ if isinstance(nbtype, (types.CharSeq, types.UnicodeCharSeq)):
141
+ letter = _as_dtype_letters[type(nbtype)]
142
+ return np.dtype("%s%d" % (letter, nbtype.count))
143
+ if isinstance(nbtype, types.Record):
144
+ return as_struct_dtype(nbtype)
145
+ if isinstance(nbtype, types.EnumMember):
146
+ return as_dtype(nbtype.dtype)
147
+ if isinstance(nbtype, types.npytypes.DType):
148
+ return as_dtype(nbtype.dtype)
149
+ if isinstance(nbtype, types.NumberClass):
150
+ return as_dtype(nbtype.dtype)
151
+ if isinstance(nbtype, types.NestedArray):
152
+ spec = (as_dtype(nbtype.dtype), tuple(nbtype.shape))
153
+ return np.dtype(spec)
154
+ if isinstance(nbtype, types.PyObject):
155
+ return np.dtype(object)
156
+
157
+ msg = f"{nbtype} cannot be represented as a NumPy dtype"
158
+ raise errors.NumbaNotImplementedError(msg)
159
+
160
+
161
+ def as_struct_dtype(rec):
162
+ """Convert Numba Record type to NumPy structured dtype"""
163
+ assert isinstance(rec, types.Record)
164
+ names = []
165
+ formats = []
166
+ offsets = []
167
+ titles = []
168
+ # Fill the fields if they are not a title.
169
+ for k, t in rec.members:
170
+ if not rec.is_title(k):
171
+ names.append(k)
172
+ formats.append(as_dtype(t))
173
+ offsets.append(rec.offset(k))
174
+ titles.append(rec.fields[k].title)
175
+
176
+ fields = {
177
+ "names": names,
178
+ "formats": formats,
179
+ "offsets": offsets,
180
+ "itemsize": rec.size,
181
+ "titles": titles,
182
+ }
183
+ _check_struct_alignment(rec, fields)
184
+ return np.dtype(fields, align=rec.aligned)
185
+
186
+
187
+ def _check_struct_alignment(rec, fields):
188
+ """Check alignment compatibility with Numpy"""
189
+ if rec.aligned:
190
+ for k, dt in zip(fields["names"], fields["formats"]):
191
+ llvm_align = rec.alignof(k)
192
+ npy_align = dt.alignment
193
+ if llvm_align is not None and npy_align != llvm_align:
194
+ msg = (
195
+ "NumPy is using a different alignment ({}) "
196
+ "than Numba/LLVM ({}) for {}. "
197
+ "This is likely a NumPy bug."
198
+ )
199
+ raise ValueError(msg.format(npy_align, llvm_align, dt))
200
+
201
+
202
+ def map_arrayscalar_type(val):
203
+ if isinstance(val, np.generic):
204
+ # We can't blindly call np.dtype() as it loses information
205
+ # on some types, e.g. datetime64 and timedelta64.
206
+ dtype = val.dtype
207
+ else:
208
+ try:
209
+ dtype = np.dtype(type(val))
210
+ except TypeError:
211
+ raise errors.NumbaNotImplementedError(
212
+ "no corresponding numpy dtype for %r" % type(val)
213
+ )
214
+ return from_dtype(dtype)
215
+
216
+
217
+ def is_array(val):
218
+ return isinstance(val, np.ndarray)
219
+
220
+
221
+ def map_layout(val):
222
+ if val.flags["C_CONTIGUOUS"]:
223
+ layout = "C"
224
+ elif val.flags["F_CONTIGUOUS"]:
225
+ layout = "F"
226
+ else:
227
+ layout = "A"
228
+ return layout
229
+
230
+
231
+ def select_array_wrapper(inputs):
232
+ """
233
+ Given the array-compatible input types to an operation (e.g. ufunc),
234
+ select the appropriate input for wrapping the operation output,
235
+ according to each input's __array_priority__.
236
+
237
+ An index into *inputs* is returned.
238
+ """
239
+ max_prio = float("-inf")
240
+ selected_index = None
241
+ for index, ty in enumerate(inputs):
242
+ # Ties are broken by choosing the first winner, as in Numpy
243
+ if (
244
+ isinstance(ty, types.ArrayCompatible)
245
+ and ty.array_priority > max_prio
246
+ ):
247
+ selected_index = index
248
+ max_prio = ty.array_priority
249
+
250
+ assert selected_index is not None
251
+ return selected_index
252
+
253
+
254
+ def resolve_output_type(context, inputs, formal_output):
255
+ """
256
+ Given the array-compatible input types to an operation (e.g. ufunc),
257
+ and the operation's formal output type (a types.Array instance),
258
+ resolve the actual output type using the typing *context*.
259
+
260
+ This uses a mechanism compatible with Numpy's __array_priority__ /
261
+ __array_wrap__.
262
+ """
263
+ selected_input = inputs[select_array_wrapper(inputs)]
264
+ args = selected_input, formal_output
265
+ sig = context.resolve_function_type("__array_wrap__", args, {})
266
+ if sig is None:
267
+ if selected_input.array_priority == types.Array.array_priority:
268
+ # If it's the same priority as a regular array, assume we
269
+ # should return the output unchanged.
270
+ # (we can't define __array_wrap__ explicitly for types.Buffer,
271
+ # as that would be inherited by most array-compatible objects)
272
+ return formal_output
273
+ raise errors.TypingError("__array_wrap__ failed for %s" % (args,))
274
+ return sig.return_type
275
+
276
+
277
+ def supported_ufunc_loop(ufunc, loop):
278
+ """Return whether the *loop* for the *ufunc* is supported -in nopython-.
279
+
280
+ *loop* should be a UFuncLoopSpec instance, and *ufunc* a numpy ufunc.
281
+
282
+ For ufuncs implemented using the ufunc_db, it is supported if the ufunc_db
283
+ contains a lowering definition for 'loop' in the 'ufunc' entry.
284
+
285
+ For other ufuncs, it is type based. The loop will be considered valid if it
286
+ only contains the following letter types: '?bBhHiIlLqQfd'. Note this is
287
+ legacy and when implementing new ufuncs the ufunc_db should be preferred,
288
+ as it allows for a more fine-grained incremental support.
289
+ """
290
+ # NOTE: Assuming ufunc for the CPUContext
291
+ from numba.cuda.np import ufunc_db
292
+
293
+ loop_sig = loop.ufunc_sig
294
+ try:
295
+ # check if the loop has a codegen description in the
296
+ # ufunc_db. If so, we can proceed.
297
+
298
+ # note that as of now not all ufuncs have an entry in the
299
+ # ufunc_db
300
+ supported_loop = loop_sig in ufunc_db.get_ufunc_info(ufunc)
301
+ except KeyError:
302
+ # for ufuncs not in ufunc_db, base the decision of whether the
303
+ # loop is supported on its types
304
+ loop_types = [x.char for x in loop.numpy_inputs + loop.numpy_outputs]
305
+ supported_types = "?bBhHiIlLqQfd"
306
+ # check if all the types involved in the ufunc loop are
307
+ # supported in this mode
308
+ supported_loop = all(t in supported_types for t in loop_types)
309
+
310
+ return supported_loop
311
+
312
+
313
+ class UFuncLoopSpec(
314
+ collections.namedtuple("_UFuncLoopSpec", ("inputs", "outputs", "ufunc_sig"))
315
+ ):
316
+ """
317
+ An object describing a ufunc loop's inner types. Properties:
318
+ - inputs: the inputs' Numba types
319
+ - outputs: the outputs' Numba types
320
+ - ufunc_sig: the string representing the ufunc's type signature, in
321
+ Numpy format (e.g. "ii->i")
322
+ """
323
+
324
+ __slots__ = ()
325
+
326
+ @property
327
+ def numpy_inputs(self):
328
+ return [as_dtype(x) for x in self.inputs]
329
+
330
+ @property
331
+ def numpy_outputs(self):
332
+ return [as_dtype(x) for x in self.outputs]
333
+
334
+
335
+ def _ufunc_loop_sig(out_tys, in_tys):
336
+ if len(out_tys) == 1:
337
+ return signature(out_tys[0], *in_tys)
338
+ else:
339
+ return signature(types.Tuple(out_tys), *in_tys)
340
+
341
+
342
+ def ufunc_can_cast(from_, to, has_mixed_inputs, casting="safe"):
343
+ """
344
+ A variant of np.can_cast() that can allow casting any integer to
345
+ any real or complex type, in case the operation has mixed-kind
346
+ inputs.
347
+
348
+ For example we want `np.power(float32, int32)` to be computed using
349
+ SP arithmetic and return `float32`.
350
+ However, `np.sqrt(int32)` should use DP arithmetic and return `float64`.
351
+ """
352
+ from_ = np.dtype(from_)
353
+ to = np.dtype(to)
354
+ if has_mixed_inputs and from_.kind in "iu" and to.kind in "cf":
355
+ # Decide that all integers can cast to any real or complex type.
356
+ return True
357
+ return np.can_cast(from_, to, casting)
358
+
359
+
360
+ def ufunc_find_matching_loop(ufunc, arg_types):
361
+ """Find the appropriate loop to be used for a ufunc based on the types
362
+ of the operands
363
+
364
+ ufunc - The ufunc we want to check
365
+ arg_types - The tuple of arguments to the ufunc, including any
366
+ explicit output(s).
367
+ return value - A UFuncLoopSpec identifying the loop, or None
368
+ if no matching loop is found.
369
+ """
370
+
371
+ # Separate logical input from explicit output arguments
372
+ input_types = arg_types[: ufunc.nin]
373
+ output_types = arg_types[ufunc.nin :]
374
+ assert len(input_types) == ufunc.nin
375
+
376
+ try:
377
+ np_input_types = [as_dtype(x) for x in input_types]
378
+ except errors.NumbaNotImplementedError:
379
+ return None
380
+ try:
381
+ np_output_types = [as_dtype(x) for x in output_types]
382
+ except errors.NumbaNotImplementedError:
383
+ return None
384
+
385
+ # Whether the inputs are mixed integer / floating-point
386
+ has_mixed_inputs = any(dt.kind in "iu" for dt in np_input_types) and any(
387
+ dt.kind in "cf" for dt in np_input_types
388
+ )
389
+
390
+ def choose_types(numba_types, ufunc_letters):
391
+ """
392
+ Return a list of Numba types representing *ufunc_letters*,
393
+ except when the letter designates a datetime64 or timedelta64,
394
+ in which case the type is taken from *numba_types*.
395
+ """
396
+ assert len(ufunc_letters) >= len(numba_types)
397
+ types = [
398
+ tp if letter in "mM" else from_dtype(np.dtype(letter))
399
+ for tp, letter in zip(numba_types, ufunc_letters)
400
+ ]
401
+ # Add missing types (presumably implicit outputs)
402
+ types += [
403
+ from_dtype(np.dtype(letter))
404
+ for letter in ufunc_letters[len(numba_types) :]
405
+ ]
406
+ return types
407
+
408
+ def set_output_dt_units(inputs, outputs, ufunc_inputs, ufunc_name):
409
+ """
410
+ Sets the output unit of a datetime type based on the input units
411
+
412
+ Timedelta is a special dtype that requires the time unit to be
413
+ specified (day, month, etc). Not every operation with timedelta inputs
414
+ leads to an output of timedelta output. However, for those that do,
415
+ the unit of output must be inferred based on the units of the inputs.
416
+
417
+ At the moment this function takes care of two cases:
418
+ a) where all inputs are timedelta with the same unit (mm), and
419
+ therefore the output has the same unit.
420
+ This case is used for arr.sum, and for arr1+arr2 where all arrays
421
+ are timedeltas.
422
+ If in the future this needs to be extended to a case with mixed units,
423
+ the rules should be implemented in `npdatetime_helpers` and called
424
+ from this function to set the correct output unit.
425
+ b) where left operand is a timedelta, i.e. the "m?" case. This case
426
+ is used for division, eg timedelta / int.
427
+
428
+ At the time of writing, Numba does not support addition of timedelta
429
+ and other types, so this function does not consider the case "?m",
430
+ i.e. where timedelta is the right operand to a non-timedelta left
431
+ operand. To extend it in the future, just add another elif clause.
432
+ """
433
+
434
+ def make_specific(outputs, unit):
435
+ new_outputs = []
436
+ for out in outputs:
437
+ if isinstance(out, types.NPTimedelta) and out.unit == "":
438
+ new_outputs.append(types.NPTimedelta(unit))
439
+ else:
440
+ new_outputs.append(out)
441
+ return new_outputs
442
+
443
+ def make_datetime_specific(outputs, dt_unit, td_unit):
444
+ new_outputs = []
445
+ for out in outputs:
446
+ if isinstance(out, types.NPDatetime) and out.unit == "":
447
+ unit = npdatetime_helpers.combine_datetime_timedelta_units(
448
+ dt_unit, td_unit
449
+ )
450
+ if unit is None:
451
+ raise TypingError(
452
+ f"ufunc '{ufunc_name}' is not "
453
+ + "supported between "
454
+ + f"datetime64[{dt_unit}] "
455
+ + f"and timedelta64[{td_unit}]"
456
+ )
457
+ new_outputs.append(types.NPDatetime(unit))
458
+ else:
459
+ new_outputs.append(out)
460
+ return new_outputs
461
+
462
+ if ufunc_inputs == "mm":
463
+ if all(inp.unit == inputs[0].unit for inp in inputs):
464
+ # Case with operation on same units. Operations on different
465
+ # units not adjusted for now but might need to be
466
+ # added in the future
467
+ unit = inputs[0].unit
468
+ new_outputs = make_specific(outputs, unit)
469
+ else:
470
+ return outputs
471
+ return new_outputs
472
+ elif ufunc_inputs == "mM":
473
+ # case where the left operand has timedelta type
474
+ # and the right operand has datetime
475
+ td_unit = inputs[0].unit
476
+ dt_unit = inputs[1].unit
477
+ return make_datetime_specific(outputs, dt_unit, td_unit)
478
+
479
+ elif ufunc_inputs == "Mm":
480
+ # case where the right operand has timedelta type
481
+ # and the left operand has datetime
482
+ dt_unit = inputs[0].unit
483
+ td_unit = inputs[1].unit
484
+ return make_datetime_specific(outputs, dt_unit, td_unit)
485
+
486
+ elif ufunc_inputs[0] == "m":
487
+ # case where the left operand has timedelta type
488
+ unit = inputs[0].unit
489
+ new_outputs = make_specific(outputs, unit)
490
+ return new_outputs
491
+
492
+ # In NumPy, the loops are evaluated from first to last. The first one
493
+ # that is viable is the one used. One loop is viable if it is possible
494
+ # to cast every input operand to the one expected by the ufunc.
495
+ # Also under NumPy 1.10+ the output must be able to be cast back
496
+ # to a close enough type ("same_kind").
497
+
498
+ for candidate in ufunc.types:
499
+ ufunc_inputs = candidate[: ufunc.nin]
500
+ ufunc_outputs = candidate[-ufunc.nout :] if ufunc.nout else []
501
+
502
+ if "e" in ufunc_inputs:
503
+ # Skip float16 arrays since we don't have implementation for them
504
+ continue
505
+ if "O" in ufunc_inputs:
506
+ # Skip object arrays
507
+ continue
508
+ found = True
509
+ # Skip if any input or output argument is mismatching
510
+ for outer, inner in zip(np_input_types, ufunc_inputs):
511
+ # (outer is a dtype instance, inner is a type char)
512
+ if outer.char in "mM" or inner in "mM":
513
+ # For datetime64 and timedelta64, we want to retain
514
+ # precise typing (i.e. the units); therefore we look for
515
+ # an exact match.
516
+ if outer.char != inner:
517
+ found = False
518
+ break
519
+ elif not ufunc_can_cast(
520
+ outer.char, inner, has_mixed_inputs, "safe"
521
+ ):
522
+ found = False
523
+ break
524
+ if found:
525
+ # Can we cast the inner result to the outer result type?
526
+ for outer, inner in zip(np_output_types, ufunc_outputs):
527
+ if outer.char not in "mM" and not ufunc_can_cast(
528
+ inner, outer.char, has_mixed_inputs, "same_kind"
529
+ ):
530
+ found = False
531
+ break
532
+ if found:
533
+ # Found: determine the Numba types for the loop's inputs and
534
+ # outputs.
535
+ try:
536
+ inputs = choose_types(input_types, ufunc_inputs)
537
+ outputs = choose_types(output_types, ufunc_outputs)
538
+ # if the left operand or both are timedeltas, or the first
539
+ # argument is datetime and the second argument is timedelta,
540
+ # then the output units need to be determined.
541
+ if ufunc_inputs[0] == "m" or ufunc_inputs == "Mm":
542
+ outputs = set_output_dt_units(
543
+ inputs, outputs, ufunc_inputs, ufunc.__name__
544
+ )
545
+
546
+ except errors.NumbaNotImplementedError:
547
+ # One of the selected dtypes isn't supported by Numba
548
+ # (e.g. float16), try other candidates
549
+ continue
550
+ else:
551
+ return UFuncLoopSpec(inputs, outputs, candidate)
552
+
553
+ return None
554
+
555
+
556
+ def _is_aligned_struct(struct):
557
+ return struct.isalignedstruct
558
+
559
+
560
+ def from_struct_dtype(dtype):
561
+ """Convert a NumPy structured dtype to Numba Record type"""
562
+ if dtype.hasobject:
563
+ msg = "dtypes that contain object are not supported."
564
+ raise errors.NumbaNotImplementedError(msg)
565
+
566
+ fields = []
567
+ for name, info in dtype.fields.items():
568
+ # *info* may have 3 element
569
+ [elemdtype, offset] = info[:2]
570
+ title = info[2] if len(info) == 3 else None
571
+
572
+ ty = from_dtype(elemdtype)
573
+ infos = {
574
+ "type": ty,
575
+ "offset": offset,
576
+ "title": title,
577
+ }
578
+ fields.append((name, infos))
579
+
580
+ # Note: dtype.alignment is not consistent.
581
+ # It is different after passing into a recarray.
582
+ # recarray(N, dtype=mydtype).dtype.alignment != mydtype.alignment
583
+ size = dtype.itemsize
584
+ aligned = _is_aligned_struct(dtype)
585
+
586
+ return types.Record(fields, size, aligned)
587
+
588
+
589
+ def _get_bytes_buffer(ptr, nbytes):
590
+ """
591
+ Get a ctypes array of *nbytes* starting at *ptr*.
592
+ """
593
+ if isinstance(ptr, ctypes.c_void_p):
594
+ ptr = ptr.value
595
+ arrty = ctypes.c_byte * nbytes
596
+ return arrty.from_address(ptr)
597
+
598
+
599
+ def _get_array_from_ptr(ptr, nbytes, dtype):
600
+ return np.frombuffer(_get_bytes_buffer(ptr, nbytes), dtype)
601
+
602
+
603
+ def carray(ptr, shape, dtype=None):
604
+ """
605
+ Return a Numpy array view over the data pointed to by *ptr* with the
606
+ given *shape*, in C order. If *dtype* is given, it is used as the
607
+ array's dtype, otherwise the array's dtype is inferred from *ptr*'s type.
608
+ """
609
+ from numba.cuda.typing.ctypes_utils import from_ctypes
610
+
611
+ try:
612
+ # Use ctypes parameter protocol if available
613
+ ptr = ptr._as_parameter_
614
+ except AttributeError:
615
+ pass
616
+
617
+ # Normalize dtype, to accept e.g. "int64" or np.int64
618
+ if dtype is not None:
619
+ dtype = np.dtype(dtype)
620
+
621
+ if isinstance(ptr, ctypes.c_void_p):
622
+ if dtype is None:
623
+ raise TypeError("explicit dtype required for void* argument")
624
+ p = ptr
625
+ elif isinstance(ptr, ctypes._Pointer):
626
+ ptrty = from_ctypes(ptr.__class__)
627
+ assert isinstance(ptrty, types.CPointer)
628
+ ptr_dtype = as_dtype(ptrty.dtype)
629
+ if dtype is not None and dtype != ptr_dtype:
630
+ raise TypeError(
631
+ "mismatching dtype '%s' for pointer %s" % (dtype, ptr)
632
+ )
633
+ dtype = ptr_dtype
634
+ p = ctypes.cast(ptr, ctypes.c_void_p)
635
+ else:
636
+ raise TypeError("expected a ctypes pointer, got %r" % (ptr,))
637
+
638
+ nbytes = dtype.itemsize * np.prod(shape, dtype=np.intp)
639
+ return _get_array_from_ptr(p, nbytes, dtype).reshape(shape)
640
+
641
+
642
+ def farray(ptr, shape, dtype=None):
643
+ """
644
+ Return a Numpy array view over the data pointed to by *ptr* with the
645
+ given *shape*, in Fortran order. If *dtype* is given, it is used as the
646
+ array's dtype, otherwise the array's dtype is inferred from *ptr*'s type.
647
+ """
648
+ if not isinstance(shape, int):
649
+ shape = shape[::-1]
650
+ return carray(ptr, shape, dtype).T
651
+
652
+
653
+ def is_contiguous(dims, strides, itemsize):
654
+ """Is the given shape, strides, and itemsize of C layout?
655
+
656
+ Note: The code is usable as a numba-compiled function
657
+ """
658
+ nd = len(dims)
659
+ # Check and skip 1s or 0s in inner dims
660
+ innerax = nd - 1
661
+ while innerax > -1 and dims[innerax] <= 1:
662
+ innerax -= 1
663
+
664
+ # Early exit if all axis are 1s or 0s
665
+ if innerax < 0:
666
+ return True
667
+
668
+ # Check itemsize matches innermost stride
669
+ if itemsize != strides[innerax]:
670
+ return False
671
+
672
+ # Check and skip 1s or 0s in outer dims
673
+ outerax = 0
674
+ while outerax < innerax and dims[outerax] <= 1:
675
+ outerax += 1
676
+
677
+ # Check remaining strides to be contiguous
678
+ ax = innerax
679
+ while ax > outerax:
680
+ if strides[ax] * dims[ax] != strides[ax - 1]:
681
+ return False
682
+ ax -= 1
683
+ return True
684
+
685
+
686
+ def is_fortran(dims, strides, itemsize):
687
+ """Is the given shape, strides, and itemsize of F layout?
688
+
689
+ Note: The code is usable as a numba-compiled function
690
+ """
691
+ nd = len(dims)
692
+ # Check and skip 1s or 0s in inner dims
693
+ firstax = 0
694
+ while firstax < nd and dims[firstax] <= 1:
695
+ firstax += 1
696
+
697
+ # Early exit if all axis are 1s or 0s
698
+ if firstax >= nd:
699
+ return True
700
+
701
+ # Check itemsize matches innermost stride
702
+ if itemsize != strides[firstax]:
703
+ return False
704
+
705
+ # Check and skip 1s or 0s in outer dims
706
+ lastax = nd - 1
707
+ while lastax > firstax and dims[lastax] <= 1:
708
+ lastax -= 1
709
+
710
+ # Check remaining strides to be contiguous
711
+ ax = firstax
712
+ while ax < lastax:
713
+ if strides[ax] * dims[ax] != strides[ax + 1]:
714
+ return False
715
+ ax += 1
716
+ return True
717
+
718
+
719
+ def type_can_asarray(arr):
720
+ """Returns True if the type of 'arr' is supported by the Numba `np.asarray`
721
+ implementation, False otherwise.
722
+ """
723
+
724
+ ok = (
725
+ types.Array,
726
+ types.Sequence,
727
+ types.Tuple,
728
+ types.StringLiteral,
729
+ types.Number,
730
+ types.Boolean,
731
+ types.containers.ListType,
732
+ )
733
+
734
+ return isinstance(arr, ok)
735
+
736
+
737
+ def type_is_scalar(typ):
738
+ """Returns True if the type of 'typ' is a scalar type, according to
739
+ NumPy rules. False otherwise.
740
+ https://numpy.org/doc/stable/reference/arrays.scalars.html#built-in-scalar-types
741
+ """
742
+
743
+ ok = (
744
+ types.Boolean,
745
+ types.Number,
746
+ types.UnicodeType,
747
+ types.StringLiteral,
748
+ types.NPTimedelta,
749
+ types.NPDatetime,
750
+ )
751
+ return isinstance(typ, ok)
752
+
753
+
754
+ def check_is_integer(v, name):
755
+ """Raises TypingError if the value is not an integer."""
756
+ if not isinstance(v, (int, types.Integer)):
757
+ raise TypingError("{} must be an integer".format(name))
758
+
759
+
760
+ def lt_floats(a, b):
761
+ # Adapted from NumPy commit 717c7acf which introduced the behavior of
762
+ # putting NaNs at the end.
763
+ # The code is later moved to numpy/core/src/npysort/npysort_common.h
764
+ # This info is gathered as of NumPy commit d8c09c50
765
+ return a < b or (np.isnan(b) and not np.isnan(a))
766
+
767
+
768
+ def lt_complex(a, b):
769
+ if np.isnan(a.real):
770
+ if np.isnan(b.real):
771
+ if np.isnan(a.imag):
772
+ return False
773
+ else:
774
+ if np.isnan(b.imag):
775
+ return True
776
+ else:
777
+ return a.imag < b.imag
778
+ else:
779
+ return False
780
+
781
+ else:
782
+ if np.isnan(b.real):
783
+ return True
784
+ else:
785
+ if np.isnan(a.imag):
786
+ if np.isnan(b.imag):
787
+ return a.real < b.real
788
+ else:
789
+ return False
790
+ else:
791
+ if np.isnan(b.imag):
792
+ return True
793
+ else:
794
+ if a.real < b.real:
795
+ return True
796
+ elif a.real == b.real:
797
+ return a.imag < b.imag
798
+ return False