numba-cuda 0.0.1__py3-none-any.whl → 0.0.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. _numba_cuda_redirector.pth +1 -0
  2. _numba_cuda_redirector.py +74 -0
  3. numba_cuda/VERSION +1 -0
  4. numba_cuda/__init__.py +5 -0
  5. numba_cuda/_version.py +19 -0
  6. numba_cuda/numba/cuda/__init__.py +22 -0
  7. numba_cuda/numba/cuda/api.py +526 -0
  8. numba_cuda/numba/cuda/api_util.py +30 -0
  9. numba_cuda/numba/cuda/args.py +77 -0
  10. numba_cuda/numba/cuda/cg.py +62 -0
  11. numba_cuda/numba/cuda/codegen.py +378 -0
  12. numba_cuda/numba/cuda/compiler.py +422 -0
  13. numba_cuda/numba/cuda/cpp_function_wrappers.cu +47 -0
  14. numba_cuda/numba/cuda/cuda_fp16.h +3631 -0
  15. numba_cuda/numba/cuda/cuda_fp16.hpp +2465 -0
  16. numba_cuda/numba/cuda/cuda_paths.py +258 -0
  17. numba_cuda/numba/cuda/cudadecl.py +806 -0
  18. numba_cuda/numba/cuda/cudadrv/__init__.py +9 -0
  19. numba_cuda/numba/cuda/cudadrv/devicearray.py +904 -0
  20. numba_cuda/numba/cuda/cudadrv/devices.py +248 -0
  21. numba_cuda/numba/cuda/cudadrv/driver.py +3201 -0
  22. numba_cuda/numba/cuda/cudadrv/drvapi.py +398 -0
  23. numba_cuda/numba/cuda/cudadrv/dummyarray.py +452 -0
  24. numba_cuda/numba/cuda/cudadrv/enums.py +607 -0
  25. numba_cuda/numba/cuda/cudadrv/error.py +36 -0
  26. numba_cuda/numba/cuda/cudadrv/libs.py +176 -0
  27. numba_cuda/numba/cuda/cudadrv/ndarray.py +20 -0
  28. numba_cuda/numba/cuda/cudadrv/nvrtc.py +260 -0
  29. numba_cuda/numba/cuda/cudadrv/nvvm.py +707 -0
  30. numba_cuda/numba/cuda/cudadrv/rtapi.py +10 -0
  31. numba_cuda/numba/cuda/cudadrv/runtime.py +142 -0
  32. numba_cuda/numba/cuda/cudaimpl.py +1055 -0
  33. numba_cuda/numba/cuda/cudamath.py +140 -0
  34. numba_cuda/numba/cuda/decorators.py +189 -0
  35. numba_cuda/numba/cuda/descriptor.py +33 -0
  36. numba_cuda/numba/cuda/device_init.py +89 -0
  37. numba_cuda/numba/cuda/deviceufunc.py +908 -0
  38. numba_cuda/numba/cuda/dispatcher.py +1057 -0
  39. numba_cuda/numba/cuda/errors.py +59 -0
  40. numba_cuda/numba/cuda/extending.py +7 -0
  41. numba_cuda/numba/cuda/initialize.py +13 -0
  42. numba_cuda/numba/cuda/intrinsic_wrapper.py +77 -0
  43. numba_cuda/numba/cuda/intrinsics.py +198 -0
  44. numba_cuda/numba/cuda/kernels/__init__.py +0 -0
  45. numba_cuda/numba/cuda/kernels/reduction.py +262 -0
  46. numba_cuda/numba/cuda/kernels/transpose.py +65 -0
  47. numba_cuda/numba/cuda/libdevice.py +3382 -0
  48. numba_cuda/numba/cuda/libdevicedecl.py +17 -0
  49. numba_cuda/numba/cuda/libdevicefuncs.py +1057 -0
  50. numba_cuda/numba/cuda/libdeviceimpl.py +83 -0
  51. numba_cuda/numba/cuda/mathimpl.py +448 -0
  52. numba_cuda/numba/cuda/models.py +48 -0
  53. numba_cuda/numba/cuda/nvvmutils.py +235 -0
  54. numba_cuda/numba/cuda/printimpl.py +86 -0
  55. numba_cuda/numba/cuda/random.py +292 -0
  56. numba_cuda/numba/cuda/simulator/__init__.py +38 -0
  57. numba_cuda/numba/cuda/simulator/api.py +110 -0
  58. numba_cuda/numba/cuda/simulator/compiler.py +9 -0
  59. numba_cuda/numba/cuda/simulator/cudadrv/__init__.py +2 -0
  60. numba_cuda/numba/cuda/simulator/cudadrv/devicearray.py +432 -0
  61. numba_cuda/numba/cuda/simulator/cudadrv/devices.py +117 -0
  62. numba_cuda/numba/cuda/simulator/cudadrv/driver.py +62 -0
  63. numba_cuda/numba/cuda/simulator/cudadrv/drvapi.py +4 -0
  64. numba_cuda/numba/cuda/simulator/cudadrv/dummyarray.py +4 -0
  65. numba_cuda/numba/cuda/simulator/cudadrv/error.py +6 -0
  66. numba_cuda/numba/cuda/simulator/cudadrv/libs.py +2 -0
  67. numba_cuda/numba/cuda/simulator/cudadrv/nvvm.py +29 -0
  68. numba_cuda/numba/cuda/simulator/cudadrv/runtime.py +19 -0
  69. numba_cuda/numba/cuda/simulator/kernel.py +308 -0
  70. numba_cuda/numba/cuda/simulator/kernelapi.py +495 -0
  71. numba_cuda/numba/cuda/simulator/reduction.py +15 -0
  72. numba_cuda/numba/cuda/simulator/vector_types.py +58 -0
  73. numba_cuda/numba/cuda/simulator_init.py +17 -0
  74. numba_cuda/numba/cuda/stubs.py +902 -0
  75. numba_cuda/numba/cuda/target.py +440 -0
  76. numba_cuda/numba/cuda/testing.py +202 -0
  77. numba_cuda/numba/cuda/tests/__init__.py +58 -0
  78. numba_cuda/numba/cuda/tests/cudadrv/__init__.py +8 -0
  79. numba_cuda/numba/cuda/tests/cudadrv/test_array_attr.py +145 -0
  80. numba_cuda/numba/cuda/tests/cudadrv/test_context_stack.py +145 -0
  81. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_array_slicing.py +375 -0
  82. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_auto_context.py +21 -0
  83. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_devicerecord.py +179 -0
  84. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_driver.py +235 -0
  85. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_libraries.py +22 -0
  86. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_memory.py +193 -0
  87. numba_cuda/numba/cuda/tests/cudadrv/test_cuda_ndarray.py +547 -0
  88. numba_cuda/numba/cuda/tests/cudadrv/test_deallocations.py +249 -0
  89. numba_cuda/numba/cuda/tests/cudadrv/test_detect.py +81 -0
  90. numba_cuda/numba/cuda/tests/cudadrv/test_emm_plugins.py +192 -0
  91. numba_cuda/numba/cuda/tests/cudadrv/test_events.py +38 -0
  92. numba_cuda/numba/cuda/tests/cudadrv/test_host_alloc.py +65 -0
  93. numba_cuda/numba/cuda/tests/cudadrv/test_init.py +139 -0
  94. numba_cuda/numba/cuda/tests/cudadrv/test_inline_ptx.py +37 -0
  95. numba_cuda/numba/cuda/tests/cudadrv/test_is_fp16.py +12 -0
  96. numba_cuda/numba/cuda/tests/cudadrv/test_linker.py +317 -0
  97. numba_cuda/numba/cuda/tests/cudadrv/test_managed_alloc.py +127 -0
  98. numba_cuda/numba/cuda/tests/cudadrv/test_mvc.py +54 -0
  99. numba_cuda/numba/cuda/tests/cudadrv/test_nvvm_driver.py +199 -0
  100. numba_cuda/numba/cuda/tests/cudadrv/test_pinned.py +37 -0
  101. numba_cuda/numba/cuda/tests/cudadrv/test_profiler.py +20 -0
  102. numba_cuda/numba/cuda/tests/cudadrv/test_ptds.py +149 -0
  103. numba_cuda/numba/cuda/tests/cudadrv/test_reset_device.py +36 -0
  104. numba_cuda/numba/cuda/tests/cudadrv/test_runtime.py +85 -0
  105. numba_cuda/numba/cuda/tests/cudadrv/test_select_device.py +41 -0
  106. numba_cuda/numba/cuda/tests/cudadrv/test_streams.py +122 -0
  107. numba_cuda/numba/cuda/tests/cudapy/__init__.py +8 -0
  108. numba_cuda/numba/cuda/tests/cudapy/cache_usecases.py +234 -0
  109. numba_cuda/numba/cuda/tests/cudapy/cache_with_cpu_usecases.py +41 -0
  110. numba_cuda/numba/cuda/tests/cudapy/extensions_usecases.py +58 -0
  111. numba_cuda/numba/cuda/tests/cudapy/jitlink.ptx +30 -0
  112. numba_cuda/numba/cuda/tests/cudapy/recursion_usecases.py +100 -0
  113. numba_cuda/numba/cuda/tests/cudapy/test_alignment.py +42 -0
  114. numba_cuda/numba/cuda/tests/cudapy/test_array.py +260 -0
  115. numba_cuda/numba/cuda/tests/cudapy/test_array_args.py +201 -0
  116. numba_cuda/numba/cuda/tests/cudapy/test_array_methods.py +35 -0
  117. numba_cuda/numba/cuda/tests/cudapy/test_atomics.py +1620 -0
  118. numba_cuda/numba/cuda/tests/cudapy/test_blackscholes.py +120 -0
  119. numba_cuda/numba/cuda/tests/cudapy/test_boolean.py +24 -0
  120. numba_cuda/numba/cuda/tests/cudapy/test_caching.py +545 -0
  121. numba_cuda/numba/cuda/tests/cudapy/test_casting.py +257 -0
  122. numba_cuda/numba/cuda/tests/cudapy/test_cffi.py +33 -0
  123. numba_cuda/numba/cuda/tests/cudapy/test_compiler.py +276 -0
  124. numba_cuda/numba/cuda/tests/cudapy/test_complex.py +296 -0
  125. numba_cuda/numba/cuda/tests/cudapy/test_complex_kernel.py +20 -0
  126. numba_cuda/numba/cuda/tests/cudapy/test_const_string.py +129 -0
  127. numba_cuda/numba/cuda/tests/cudapy/test_constmem.py +176 -0
  128. numba_cuda/numba/cuda/tests/cudapy/test_cooperative_groups.py +147 -0
  129. numba_cuda/numba/cuda/tests/cudapy/test_cuda_array_interface.py +435 -0
  130. numba_cuda/numba/cuda/tests/cudapy/test_cuda_jit_no_types.py +90 -0
  131. numba_cuda/numba/cuda/tests/cudapy/test_datetime.py +94 -0
  132. numba_cuda/numba/cuda/tests/cudapy/test_debug.py +101 -0
  133. numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py +221 -0
  134. numba_cuda/numba/cuda/tests/cudapy/test_device_func.py +222 -0
  135. numba_cuda/numba/cuda/tests/cudapy/test_dispatcher.py +700 -0
  136. numba_cuda/numba/cuda/tests/cudapy/test_enums.py +121 -0
  137. numba_cuda/numba/cuda/tests/cudapy/test_errors.py +79 -0
  138. numba_cuda/numba/cuda/tests/cudapy/test_exception.py +174 -0
  139. numba_cuda/numba/cuda/tests/cudapy/test_extending.py +155 -0
  140. numba_cuda/numba/cuda/tests/cudapy/test_fastmath.py +244 -0
  141. numba_cuda/numba/cuda/tests/cudapy/test_forall.py +52 -0
  142. numba_cuda/numba/cuda/tests/cudapy/test_freevar.py +29 -0
  143. numba_cuda/numba/cuda/tests/cudapy/test_frexp_ldexp.py +66 -0
  144. numba_cuda/numba/cuda/tests/cudapy/test_globals.py +60 -0
  145. numba_cuda/numba/cuda/tests/cudapy/test_gufunc.py +456 -0
  146. numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scalar.py +159 -0
  147. numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scheduling.py +95 -0
  148. numba_cuda/numba/cuda/tests/cudapy/test_idiv.py +37 -0
  149. numba_cuda/numba/cuda/tests/cudapy/test_inspect.py +165 -0
  150. numba_cuda/numba/cuda/tests/cudapy/test_intrinsics.py +1106 -0
  151. numba_cuda/numba/cuda/tests/cudapy/test_ipc.py +318 -0
  152. numba_cuda/numba/cuda/tests/cudapy/test_iterators.py +99 -0
  153. numba_cuda/numba/cuda/tests/cudapy/test_lang.py +64 -0
  154. numba_cuda/numba/cuda/tests/cudapy/test_laplace.py +119 -0
  155. numba_cuda/numba/cuda/tests/cudapy/test_libdevice.py +187 -0
  156. numba_cuda/numba/cuda/tests/cudapy/test_lineinfo.py +199 -0
  157. numba_cuda/numba/cuda/tests/cudapy/test_localmem.py +164 -0
  158. numba_cuda/numba/cuda/tests/cudapy/test_mandel.py +37 -0
  159. numba_cuda/numba/cuda/tests/cudapy/test_math.py +786 -0
  160. numba_cuda/numba/cuda/tests/cudapy/test_matmul.py +74 -0
  161. numba_cuda/numba/cuda/tests/cudapy/test_minmax.py +113 -0
  162. numba_cuda/numba/cuda/tests/cudapy/test_montecarlo.py +22 -0
  163. numba_cuda/numba/cuda/tests/cudapy/test_multigpu.py +140 -0
  164. numba_cuda/numba/cuda/tests/cudapy/test_multiprocessing.py +46 -0
  165. numba_cuda/numba/cuda/tests/cudapy/test_multithreads.py +101 -0
  166. numba_cuda/numba/cuda/tests/cudapy/test_nondet.py +49 -0
  167. numba_cuda/numba/cuda/tests/cudapy/test_operator.py +401 -0
  168. numba_cuda/numba/cuda/tests/cudapy/test_optimization.py +86 -0
  169. numba_cuda/numba/cuda/tests/cudapy/test_overload.py +335 -0
  170. numba_cuda/numba/cuda/tests/cudapy/test_powi.py +124 -0
  171. numba_cuda/numba/cuda/tests/cudapy/test_print.py +128 -0
  172. numba_cuda/numba/cuda/tests/cudapy/test_py2_div_issue.py +33 -0
  173. numba_cuda/numba/cuda/tests/cudapy/test_random.py +104 -0
  174. numba_cuda/numba/cuda/tests/cudapy/test_record_dtype.py +610 -0
  175. numba_cuda/numba/cuda/tests/cudapy/test_recursion.py +125 -0
  176. numba_cuda/numba/cuda/tests/cudapy/test_reduction.py +76 -0
  177. numba_cuda/numba/cuda/tests/cudapy/test_retrieve_autoconverted_arrays.py +83 -0
  178. numba_cuda/numba/cuda/tests/cudapy/test_serialize.py +85 -0
  179. numba_cuda/numba/cuda/tests/cudapy/test_slicing.py +37 -0
  180. numba_cuda/numba/cuda/tests/cudapy/test_sm.py +444 -0
  181. numba_cuda/numba/cuda/tests/cudapy/test_sm_creation.py +205 -0
  182. numba_cuda/numba/cuda/tests/cudapy/test_sync.py +271 -0
  183. numba_cuda/numba/cuda/tests/cudapy/test_transpose.py +80 -0
  184. numba_cuda/numba/cuda/tests/cudapy/test_ufuncs.py +277 -0
  185. numba_cuda/numba/cuda/tests/cudapy/test_userexc.py +47 -0
  186. numba_cuda/numba/cuda/tests/cudapy/test_vector_type.py +307 -0
  187. numba_cuda/numba/cuda/tests/cudapy/test_vectorize.py +283 -0
  188. numba_cuda/numba/cuda/tests/cudapy/test_vectorize_complex.py +20 -0
  189. numba_cuda/numba/cuda/tests/cudapy/test_vectorize_decor.py +69 -0
  190. numba_cuda/numba/cuda/tests/cudapy/test_vectorize_device.py +36 -0
  191. numba_cuda/numba/cuda/tests/cudapy/test_vectorize_scalar_arg.py +37 -0
  192. numba_cuda/numba/cuda/tests/cudapy/test_warning.py +139 -0
  193. numba_cuda/numba/cuda/tests/cudapy/test_warp_ops.py +276 -0
  194. numba_cuda/numba/cuda/tests/cudasim/__init__.py +6 -0
  195. numba_cuda/numba/cuda/tests/cudasim/support.py +6 -0
  196. numba_cuda/numba/cuda/tests/cudasim/test_cudasim_issues.py +102 -0
  197. numba_cuda/numba/cuda/tests/data/__init__.py +0 -0
  198. numba_cuda/numba/cuda/tests/data/cuda_include.cu +5 -0
  199. numba_cuda/numba/cuda/tests/data/error.cu +7 -0
  200. numba_cuda/numba/cuda/tests/data/jitlink.cu +23 -0
  201. numba_cuda/numba/cuda/tests/data/jitlink.ptx +51 -0
  202. numba_cuda/numba/cuda/tests/data/warn.cu +7 -0
  203. numba_cuda/numba/cuda/tests/doc_examples/__init__.py +6 -0
  204. numba_cuda/numba/cuda/tests/doc_examples/ffi/__init__.py +0 -0
  205. numba_cuda/numba/cuda/tests/doc_examples/ffi/functions.cu +49 -0
  206. numba_cuda/numba/cuda/tests/doc_examples/test_cg.py +77 -0
  207. numba_cuda/numba/cuda/tests/doc_examples/test_cpu_gpu_compat.py +76 -0
  208. numba_cuda/numba/cuda/tests/doc_examples/test_ffi.py +82 -0
  209. numba_cuda/numba/cuda/tests/doc_examples/test_laplace.py +155 -0
  210. numba_cuda/numba/cuda/tests/doc_examples/test_matmul.py +173 -0
  211. numba_cuda/numba/cuda/tests/doc_examples/test_montecarlo.py +109 -0
  212. numba_cuda/numba/cuda/tests/doc_examples/test_random.py +59 -0
  213. numba_cuda/numba/cuda/tests/doc_examples/test_reduction.py +76 -0
  214. numba_cuda/numba/cuda/tests/doc_examples/test_sessionize.py +130 -0
  215. numba_cuda/numba/cuda/tests/doc_examples/test_ufunc.py +50 -0
  216. numba_cuda/numba/cuda/tests/doc_examples/test_vecadd.py +73 -0
  217. numba_cuda/numba/cuda/tests/nocuda/__init__.py +8 -0
  218. numba_cuda/numba/cuda/tests/nocuda/test_dummyarray.py +359 -0
  219. numba_cuda/numba/cuda/tests/nocuda/test_function_resolution.py +36 -0
  220. numba_cuda/numba/cuda/tests/nocuda/test_import.py +49 -0
  221. numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py +238 -0
  222. numba_cuda/numba/cuda/tests/nocuda/test_nvvm.py +54 -0
  223. numba_cuda/numba/cuda/types.py +37 -0
  224. numba_cuda/numba/cuda/ufuncs.py +662 -0
  225. numba_cuda/numba/cuda/vector_types.py +209 -0
  226. numba_cuda/numba/cuda/vectorizers.py +252 -0
  227. numba_cuda-0.0.13.dist-info/LICENSE +25 -0
  228. numba_cuda-0.0.13.dist-info/METADATA +69 -0
  229. numba_cuda-0.0.13.dist-info/RECORD +231 -0
  230. {numba_cuda-0.0.1.dist-info → numba_cuda-0.0.13.dist-info}/WHEEL +1 -1
  231. numba_cuda-0.0.1.dist-info/METADATA +0 -10
  232. numba_cuda-0.0.1.dist-info/RECORD +0 -5
  233. {numba_cuda-0.0.1.dist-info → numba_cuda-0.0.13.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,786 @@
1
+ import numpy as np
2
+ from numba.cuda.testing import (skip_unless_cc_53,
3
+ unittest,
4
+ CUDATestCase,
5
+ skip_on_cudasim)
6
+ from numba.np import numpy_support
7
+ from numba import cuda, float32, float64, int32, vectorize, void, int64
8
+ import math
9
+
10
+
11
+ def math_acos(A, B):
12
+ i = cuda.grid(1)
13
+ B[i] = math.acos(A[i])
14
+
15
+
16
+ def math_asin(A, B):
17
+ i = cuda.grid(1)
18
+ B[i] = math.asin(A[i])
19
+
20
+
21
+ def math_atan(A, B):
22
+ i = cuda.grid(1)
23
+ B[i] = math.atan(A[i])
24
+
25
+
26
+ def math_acosh(A, B):
27
+ i = cuda.grid(1)
28
+ B[i] = math.acosh(A[i])
29
+
30
+
31
+ def math_asinh(A, B):
32
+ i = cuda.grid(1)
33
+ B[i] = math.asinh(A[i])
34
+
35
+
36
+ def math_atanh(A, B):
37
+ i = cuda.grid(1)
38
+ B[i] = math.atanh(A[i])
39
+
40
+
41
+ def math_cos(A, B):
42
+ i = cuda.grid(1)
43
+ B[i] = math.cos(A[i])
44
+
45
+
46
+ def math_sin(A, B):
47
+ i = cuda.grid(1)
48
+ B[i] = math.sin(A[i])
49
+
50
+
51
+ def math_tan(A, B):
52
+ i = cuda.grid(1)
53
+ B[i] = math.tan(A[i])
54
+
55
+
56
+ def math_cosh(A, B):
57
+ i = cuda.grid(1)
58
+ B[i] = math.cosh(A[i])
59
+
60
+
61
+ def math_sinh(A, B):
62
+ i = cuda.grid(1)
63
+ B[i] = math.sinh(A[i])
64
+
65
+
66
+ def math_tanh(A, B):
67
+ i = cuda.grid(1)
68
+ B[i] = math.tanh(A[i])
69
+
70
+
71
+ def math_atan2(A, B, C):
72
+ i = cuda.grid(1)
73
+ C[i] = math.atan2(A[i], B[i])
74
+
75
+
76
+ def math_exp(A, B):
77
+ i = cuda.grid(1)
78
+ B[i] = math.exp(A[i])
79
+
80
+
81
+ def math_erf(A, B):
82
+ i = cuda.grid(1)
83
+ B[i] = math.erf(A[i])
84
+
85
+
86
+ def math_erfc(A, B):
87
+ i = cuda.grid(1)
88
+ B[i] = math.erfc(A[i])
89
+
90
+
91
+ def math_expm1(A, B):
92
+ i = cuda.grid(1)
93
+ B[i] = math.expm1(A[i])
94
+
95
+
96
+ def math_fabs(A, B):
97
+ i = cuda.grid(1)
98
+ B[i] = math.fabs(A[i])
99
+
100
+
101
+ def math_gamma(A, B):
102
+ i = cuda.grid(1)
103
+ B[i] = math.gamma(A[i])
104
+
105
+
106
+ def math_lgamma(A, B):
107
+ i = cuda.grid(1)
108
+ B[i] = math.lgamma(A[i])
109
+
110
+
111
+ def math_log(A, B):
112
+ i = cuda.grid(1)
113
+ B[i] = math.log(A[i])
114
+
115
+
116
+ def math_log2(A, B):
117
+ i = cuda.grid(1)
118
+ B[i] = math.log2(A[i])
119
+
120
+
121
+ def math_log10(A, B):
122
+ i = cuda.grid(1)
123
+ B[i] = math.log10(A[i])
124
+
125
+
126
+ def math_log1p(A, B):
127
+ i = cuda.grid(1)
128
+ B[i] = math.log1p(A[i])
129
+
130
+
131
+ def math_remainder(A, B, C):
132
+ i = cuda.grid(1)
133
+ C[i] = math.remainder(A[i], B[i])
134
+
135
+
136
+ def math_sqrt(A, B):
137
+ i = cuda.grid(1)
138
+ B[i] = math.sqrt(A[i])
139
+
140
+
141
+ def math_hypot(A, B, C):
142
+ i = cuda.grid(1)
143
+ C[i] = math.hypot(A[i], B[i])
144
+
145
+
146
+ def math_pow(A, B, C):
147
+ i = cuda.grid(1)
148
+ C[i] = math.pow(A[i], B[i])
149
+
150
+
151
+ def math_ceil(A, B):
152
+ i = cuda.grid(1)
153
+ B[i] = math.ceil(A[i])
154
+
155
+
156
+ def math_floor(A, B):
157
+ i = cuda.grid(1)
158
+ B[i] = math.floor(A[i])
159
+
160
+
161
+ def math_copysign(A, B, C):
162
+ i = cuda.grid(1)
163
+ C[i] = math.copysign(A[i], B[i])
164
+
165
+
166
+ def math_fmod(A, B, C):
167
+ i = cuda.grid(1)
168
+ C[i] = math.fmod(A[i], B[i])
169
+
170
+
171
+ def math_modf(A, B, C):
172
+ i = cuda.grid(1)
173
+ B[i], C[i] = math.modf(A[i])
174
+
175
+
176
+ def math_isnan(A, B):
177
+ i = cuda.grid(1)
178
+ B[i] = math.isnan(A[i])
179
+
180
+
181
+ def math_isinf(A, B):
182
+ i = cuda.grid(1)
183
+ B[i] = math.isinf(A[i])
184
+
185
+
186
+ def math_isfinite(A, B):
187
+ i = cuda.grid(1)
188
+ B[i] = math.isfinite(A[i])
189
+
190
+
191
+ def math_degrees(A, B):
192
+ i = cuda.grid(1)
193
+ B[i] = math.degrees(A[i])
194
+
195
+
196
+ def math_radians(A, B):
197
+ i = cuda.grid(1)
198
+ B[i] = math.radians(A[i])
199
+
200
+
201
+ def math_trunc(A, B):
202
+ i = cuda.grid(1)
203
+ B[i] = math.trunc(A[i])
204
+
205
+
206
+ def math_pow_binop(A, B, C):
207
+ i = cuda.grid(1)
208
+ C[i] = A[i] ** B[i]
209
+
210
+
211
+ def math_mod_binop(A, B, C):
212
+ i = cuda.grid(1)
213
+ C[i] = A[i] % B[i]
214
+
215
+
216
+ class TestCudaMath(CUDATestCase):
217
+ def unary_template_float16(self, func, npfunc, start=0, stop=1):
218
+ self.unary_template(func, npfunc, np.float16, np.float16, start, stop)
219
+
220
+ def unary_template_float32(self, func, npfunc, start=0, stop=1):
221
+ self.unary_template(func, npfunc, np.float32, np.float32, start, stop)
222
+
223
+ def unary_template_float64(self, func, npfunc, start=0, stop=1):
224
+ self.unary_template(func, npfunc, np.float64, np.float64, start, stop)
225
+
226
+ def unary_template_int64(self, func, npfunc, start=0, stop=50):
227
+ self.unary_template(func, npfunc, np.int64, np.float64, start, stop)
228
+
229
+ def unary_template_uint64(self, func, npfunc, start=0, stop=50):
230
+ self.unary_template(func, npfunc, np.uint64, np.float64, start, stop)
231
+
232
+ def unary_template(self, func, npfunc, npdtype, nprestype, start, stop):
233
+ nelem = 50
234
+ A = np.linspace(start, stop, nelem).astype(npdtype)
235
+ B = np.empty_like(A).astype(nprestype)
236
+ arytype = numpy_support.from_dtype(npdtype)[::1]
237
+ restype = numpy_support.from_dtype(nprestype)[::1]
238
+ cfunc = cuda.jit((arytype, restype))(func)
239
+ cfunc[1, nelem](A, B)
240
+
241
+ # When this test was originally written it used
242
+ # assertTrue(np.allclose(...), which has different default tolerance
243
+ # values to assert_allclose. The tolerance values here are chosen as
244
+ # the tightest under which the tests will pass.
245
+ if npdtype == np.float64:
246
+ rtol = 1e-13
247
+ elif npdtype == np.float32:
248
+ rtol = 1e-6
249
+ else:
250
+ rtol = 1e-3
251
+ np.testing.assert_allclose(npfunc(A), B, rtol=rtol)
252
+
253
+ def unary_bool_special_values(self, func, npfunc, npdtype, npmtype):
254
+ fi = np.finfo(npdtype)
255
+ denorm = fi.tiny / 4
256
+ A = np.array([0., denorm, fi.tiny, 0.5, 1., fi.max, np.inf, np.nan],
257
+ dtype=npdtype)
258
+ B = np.empty_like(A, dtype=np.int32)
259
+ cfunc = cuda.jit((npmtype[::1], int32[::1]))(func)
260
+
261
+ cfunc[1, A.size](A, B)
262
+ np.testing.assert_array_equal(B, npfunc(A))
263
+
264
+ cfunc[1, A.size](-A, B)
265
+ np.testing.assert_array_equal(B, npfunc(-A))
266
+
267
+ def unary_bool_special_values_float32(self, func, npfunc):
268
+ self.unary_bool_special_values(func, npfunc, np.float32, float32)
269
+
270
+ def unary_bool_special_values_float64(self, func, npfunc):
271
+ self.unary_bool_special_values(func, npfunc, np.float64, float64)
272
+
273
+ def unary_bool_template_float32(self, func, npfunc, start=0, stop=1):
274
+ self.unary_template(func, npfunc, np.float32, np.float32, start, stop)
275
+
276
+ def unary_bool_template_float64(self, func, npfunc, start=0, stop=1):
277
+ self.unary_template(func, npfunc, np.float64, np.float64, start, stop)
278
+
279
+ def unary_bool_template_int32(self, func, npfunc, start=0, stop=49):
280
+ self.unary_template(func, npfunc, np.int32, np.int32, start, stop)
281
+
282
+ def unary_bool_template_int64(self, func, npfunc, start=0, stop=49):
283
+ self.unary_template(func, npfunc, np.int64, np.int64, start, stop)
284
+
285
+ def unary_bool_template(self, func, npfunc, npdtype, npmtype, start, stop):
286
+ nelem = 50
287
+ A = np.linspace(start, stop, nelem).astype(npdtype)
288
+ B = np.empty(A.shape, dtype=np.int32)
289
+ iarytype = npmtype[::1]
290
+ oarytype = int32[::1]
291
+ cfunc = cuda.jit((iarytype, oarytype))(func)
292
+ cfunc[1, nelem](A, B)
293
+ np.testing.assert_allclose(npfunc(A), B)
294
+
295
+ def binary_template_float32(self, func, npfunc, start=0, stop=1):
296
+ self.binary_template(func, npfunc, np.float32, np.float32, start, stop)
297
+
298
+ def binary_template_float64(self, func, npfunc, start=0, stop=1):
299
+ self.binary_template(func, npfunc, np.float64, np.float64, start, stop)
300
+
301
+ def binary_template_int64(self, func, npfunc, start=0, stop=50):
302
+ self.binary_template(func, npfunc, np.int64, np.float64, start, stop)
303
+
304
+ def binary_template_uint64(self, func, npfunc, start=0, stop=50):
305
+ self.binary_template(func, npfunc, np.uint64, np.float64, start, stop)
306
+
307
+ def binary_template(self, func, npfunc, npdtype, nprestype, start, stop):
308
+ nelem = 50
309
+ A = np.linspace(start, stop, nelem).astype(npdtype)
310
+ B = np.empty_like(A).astype(nprestype)
311
+ arytype = numpy_support.from_dtype(npdtype)[::1]
312
+ restype = numpy_support.from_dtype(nprestype)[::1]
313
+ cfunc = cuda.jit((arytype, arytype, restype))(func)
314
+ cfunc[1, nelem](A, A, B)
315
+ np.testing.assert_allclose(npfunc(A, A), B)
316
+
317
+ #---------------------------------------------------------------------------
318
+ # test_math_acos
319
+
320
+ def test_math_acos(self):
321
+ self.unary_template_float32(math_acos, np.arccos)
322
+ self.unary_template_float64(math_acos, np.arccos)
323
+ # For integers we can only test with zero, since <=-1 and >=1 result in
324
+ # invalid values.
325
+ self.unary_template_int64(math_acos, np.arccos, start=0, stop=0)
326
+ self.unary_template_uint64(math_acos, np.arccos, start=0, stop=0)
327
+
328
+ #---------------------------------------------------------------------------
329
+ # test_math_asin
330
+
331
+ def test_math_asin(self):
332
+ self.unary_template_float32(math_asin, np.arcsin)
333
+ self.unary_template_float64(math_asin, np.arcsin)
334
+ # For integers we can only test with zero, since <=-1 and >=1 result in
335
+ # invalid values.
336
+ self.unary_template_int64(math_asin, np.arcsin, start=0, stop=0)
337
+ self.unary_template_uint64(math_asin, np.arcsin, start=0, stop=0)
338
+
339
+ #---------------------------------------------------------------------------
340
+ # test_math_atan
341
+
342
+ def test_math_atan(self):
343
+ self.unary_template_float32(math_atan, np.arctan)
344
+ self.unary_template_float64(math_atan, np.arctan)
345
+ self.unary_template_int64(math_atan, np.arctan)
346
+ self.unary_template_uint64(math_atan, np.arctan)
347
+
348
+ #---------------------------------------------------------------------------
349
+ # test_math_acosh
350
+
351
+ def test_math_acosh(self):
352
+ self.unary_template_float32(math_acosh, np.arccosh, start=1, stop=2)
353
+ self.unary_template_float64(math_acosh, np.arccosh, start=1, stop=2)
354
+ self.unary_template_int64(math_acosh, np.arccosh, start=1, stop=2)
355
+ self.unary_template_uint64(math_acosh, np.arccosh, start=1, stop=2)
356
+
357
+ #---------------------------------------------------------------------------
358
+ # test_math_asinh
359
+
360
+ def test_math_asinh(self):
361
+ self.unary_template_float32(math_asinh, np.arcsinh)
362
+ self.unary_template_float64(math_asinh, np.arcsinh)
363
+ self.unary_template_int64(math_asinh, np.arcsinh)
364
+ self.unary_template_uint64(math_asinh, np.arcsinh)
365
+
366
+ #---------------------------------------------------------------------------
367
+ # test_math_atanh
368
+
369
+ def test_math_atanh(self):
370
+ self.unary_template_float32(math_atanh, np.arctanh, start=0, stop=.9)
371
+ self.unary_template_float64(math_atanh, np.arctanh, start=0, stop=.9)
372
+ self.unary_template_int64(math_atanh, np.arctanh, start=0, stop=.9)
373
+ self.unary_template_uint64(math_atanh, np.arctanh, start=0, stop=.9)
374
+
375
+ #---------------------------------------------------------------------------
376
+ # test_math_cos
377
+
378
+ def test_math_cos(self):
379
+ self.unary_template_float32(math_cos, np.cos)
380
+ self.unary_template_float64(math_cos, np.cos)
381
+ self.unary_template_int64(math_cos, np.cos)
382
+ self.unary_template_uint64(math_cos, np.cos)
383
+
384
+ @skip_unless_cc_53
385
+ def test_math_fp16(self):
386
+ self.unary_template_float16(math_sin, np.sin)
387
+ self.unary_template_float16(math_cos, np.cos)
388
+ self.unary_template_float16(math_exp, np.exp)
389
+ self.unary_template_float16(math_log, np.log, start=1)
390
+ self.unary_template_float16(math_log2, np.log2, start=1)
391
+ self.unary_template_float16(math_log10, np.log10, start=1)
392
+ self.unary_template_float16(math_fabs, np.fabs, start=-1)
393
+ self.unary_template_float16(math_sqrt, np.sqrt)
394
+ self.unary_template_float16(math_ceil, np.ceil)
395
+ self.unary_template_float16(math_floor, np.floor)
396
+
397
+ @skip_on_cudasim("numpy does not support trunc for float16")
398
+ @skip_unless_cc_53
399
+ def test_math_fp16_trunc(self):
400
+ self.unary_template_float16(math_trunc, np.trunc)
401
+
402
+ #---------------------------------------------------------------------------
403
+ # test_math_sin
404
+
405
+ def test_math_sin(self):
406
+ self.unary_template_float32(math_sin, np.sin)
407
+ self.unary_template_float64(math_sin, np.sin)
408
+ self.unary_template_int64(math_sin, np.sin)
409
+ self.unary_template_uint64(math_sin, np.sin)
410
+
411
+ #---------------------------------------------------------------------------
412
+ # test_math_tan
413
+
414
+ def test_math_tan(self):
415
+ self.unary_template_float32(math_tan, np.tan)
416
+ self.unary_template_float64(math_tan, np.tan)
417
+ self.unary_template_int64(math_tan, np.tan)
418
+ self.unary_template_uint64(math_tan, np.tan)
419
+
420
+ #---------------------------------------------------------------------------
421
+ # test_math_cosh
422
+
423
+ def test_math_cosh(self):
424
+ self.unary_template_float32(math_cosh, np.cosh)
425
+ self.unary_template_float64(math_cosh, np.cosh)
426
+ self.unary_template_int64(math_cosh, np.cosh)
427
+ self.unary_template_uint64(math_cosh, np.cosh)
428
+
429
+ #---------------------------------------------------------------------------
430
+ # test_math_sinh
431
+
432
+ def test_math_sinh(self):
433
+ self.unary_template_float32(math_sinh, np.sinh)
434
+ self.unary_template_float64(math_sinh, np.sinh)
435
+ self.unary_template_int64(math_sinh, np.sinh)
436
+ self.unary_template_uint64(math_sinh, np.sinh)
437
+
438
+ #---------------------------------------------------------------------------
439
+ # test_math_tanh
440
+
441
+ def test_math_tanh(self):
442
+ self.unary_template_float32(math_tanh, np.tanh)
443
+ self.unary_template_float64(math_tanh, np.tanh)
444
+ self.unary_template_int64(math_tanh, np.tanh)
445
+ self.unary_template_uint64(math_tanh, np.tanh)
446
+
447
+ #---------------------------------------------------------------------------
448
+ # test_math_atan2
449
+
450
+ def test_math_atan2(self):
451
+ self.binary_template_float32(math_atan2, np.arctan2)
452
+ self.binary_template_float64(math_atan2, np.arctan2)
453
+ self.binary_template_int64(math_atan2, np.arctan2)
454
+ self.binary_template_uint64(math_atan2, np.arctan2)
455
+
456
+ #---------------------------------------------------------------------------
457
+ # test_math_erf
458
+
459
+ def test_math_erf(self):
460
+ @vectorize
461
+ def ufunc(x):
462
+ return math.erf(x)
463
+ self.unary_template_float32(math_erf, ufunc)
464
+ self.unary_template_float64(math_erf, ufunc)
465
+ self.unary_template_int64(math_erf, ufunc)
466
+ self.unary_template_uint64(math_erf, ufunc)
467
+
468
+ #---------------------------------------------------------------------------
469
+ # test_math_erfc
470
+
471
+ def test_math_erfc(self):
472
+ @vectorize
473
+ def ufunc(x):
474
+ return math.erfc(x)
475
+ self.unary_template_float32(math_erfc, ufunc)
476
+ self.unary_template_float64(math_erfc, ufunc)
477
+ self.unary_template_int64(math_erfc, ufunc)
478
+ self.unary_template_uint64(math_erfc, ufunc)
479
+
480
+ #---------------------------------------------------------------------------
481
+ # test_math_exp
482
+
483
+ def test_math_exp(self):
484
+ self.unary_template_float32(math_exp, np.exp)
485
+ self.unary_template_float64(math_exp, np.exp)
486
+ self.unary_template_int64(math_exp, np.exp)
487
+ self.unary_template_uint64(math_exp, np.exp)
488
+
489
+ #---------------------------------------------------------------------------
490
+ # test_math_expm1
491
+
492
+ def test_math_expm1(self):
493
+ self.unary_template_float32(math_expm1, np.expm1)
494
+ self.unary_template_float64(math_expm1, np.expm1)
495
+ self.unary_template_int64(math_expm1, np.expm1)
496
+ self.unary_template_uint64(math_expm1, np.expm1)
497
+
498
+ #---------------------------------------------------------------------------
499
+ # test_math_fabs
500
+
501
+ def test_math_fabs(self):
502
+ self.unary_template_float32(math_fabs, np.fabs, start=-1)
503
+ self.unary_template_float64(math_fabs, np.fabs, start=-1)
504
+ self.unary_template_int64(math_fabs, np.fabs, start=-1)
505
+ self.unary_template_uint64(math_fabs, np.fabs, start=-1)
506
+
507
+ #---------------------------------------------------------------------------
508
+ # test_math_gamma
509
+
510
+ def test_math_gamma(self):
511
+ @vectorize
512
+ def ufunc(x):
513
+ return math.gamma(x)
514
+ self.unary_template_float32(math_gamma, ufunc, start=0.1)
515
+ self.unary_template_float64(math_gamma, ufunc, start=0.1)
516
+ self.unary_template_int64(math_gamma, ufunc, start=1)
517
+ self.unary_template_uint64(math_gamma, ufunc, start=1)
518
+
519
+ #---------------------------------------------------------------------------
520
+ # test_math_lgamma
521
+
522
+ def test_math_lgamma(self):
523
+ @vectorize
524
+ def ufunc(x):
525
+ return math.lgamma(x)
526
+ self.unary_template_float32(math_lgamma, ufunc, start=0.1)
527
+ self.unary_template_float64(math_lgamma, ufunc, start=0.1)
528
+ self.unary_template_int64(math_lgamma, ufunc, start=1)
529
+ self.unary_template_uint64(math_lgamma, ufunc, start=1)
530
+
531
+ #---------------------------------------------------------------------------
532
+ # test_math_log
533
+
534
+ def test_math_log(self):
535
+ self.unary_template_float32(math_log, np.log, start=1)
536
+ self.unary_template_float64(math_log, np.log, start=1)
537
+ self.unary_template_int64(math_log, np.log, start=1)
538
+ self.unary_template_uint64(math_log, np.log, start=1)
539
+
540
+ #---------------------------------------------------------------------------
541
+ # test_math_log2
542
+
543
+ def test_math_log2(self):
544
+ self.unary_template_float32(math_log2, np.log2, start=1)
545
+ self.unary_template_float64(math_log2, np.log2, start=1)
546
+ self.unary_template_int64(math_log2, np.log2, start=1)
547
+ self.unary_template_uint64(math_log2, np.log2, start=1)
548
+
549
+ #---------------------------------------------------------------------------
550
+ # test_math_log10
551
+
552
+ def test_math_log10(self):
553
+ self.unary_template_float32(math_log10, np.log10, start=1)
554
+ self.unary_template_float64(math_log10, np.log10, start=1)
555
+ self.unary_template_int64(math_log10, np.log10, start=1)
556
+ self.unary_template_uint64(math_log10, np.log10, start=1)
557
+
558
+ #---------------------------------------------------------------------------
559
+ # test_math_log1p
560
+
561
+ def test_math_log1p(self):
562
+ self.unary_template_float32(math_log1p, np.log1p)
563
+ self.unary_template_float64(math_log1p, np.log1p)
564
+ self.unary_template_int64(math_log1p, np.log1p)
565
+ self.unary_template_uint64(math_log1p, np.log1p)
566
+
567
+ #---------------------------------------------------------------------------
568
+ # test_math_remainder
569
+
570
+ def test_math_remainder(self):
571
+ self.binary_template_float32(math_remainder, np.remainder, start=1e-11)
572
+ self.binary_template_float64(math_remainder, np.remainder, start=1e-11)
573
+ self.binary_template_int64(math_remainder, np.remainder, start=1)
574
+ self.binary_template_uint64(math_remainder, np.remainder, start=1)
575
+
576
+ @skip_on_cudasim('math.remainder(0, 0) raises a ValueError on CUDASim')
577
+ def test_math_remainder_0_0(self):
578
+ @cuda.jit(void(float64[::1], int64, int64))
579
+ def test_0_0(r, x, y):
580
+ r[0] = math.remainder(x, y)
581
+ r = np.zeros(1, np.float64)
582
+ test_0_0[1, 1](r, 0, 0)
583
+ self.assertTrue(np.isnan(r[0]))
584
+
585
+ #---------------------------------------------------------------------------
586
+ # test_math_sqrt
587
+
588
+ def test_math_sqrt(self):
589
+ self.unary_template_float32(math_sqrt, np.sqrt)
590
+ self.unary_template_float64(math_sqrt, np.sqrt)
591
+ self.unary_template_int64(math_sqrt, np.sqrt)
592
+ self.unary_template_uint64(math_sqrt, np.sqrt)
593
+
594
+ #---------------------------------------------------------------------------
595
+ # test_math_hypot
596
+
597
+ def test_math_hypot(self):
598
+ self.binary_template_float32(math_hypot, np.hypot)
599
+ self.binary_template_float64(math_hypot, np.hypot)
600
+ self.binary_template_int64(math_hypot, np.hypot)
601
+ self.binary_template_uint64(math_hypot, np.hypot)
602
+
603
+ #---------------------------------------------------------------------------
604
+ # test_math_pow
605
+
606
+ def pow_template_int32(self, npdtype):
607
+ nelem = 50
608
+ A = np.linspace(0, 25, nelem).astype(npdtype)
609
+ B = np.arange(nelem, dtype=np.int32)
610
+ C = np.empty_like(A)
611
+ arytype = numpy_support.from_dtype(npdtype)[::1]
612
+ cfunc = cuda.jit((arytype, int32[::1], arytype))(math_pow)
613
+ cfunc[1, nelem](A, B, C)
614
+
615
+ # NumPy casting rules result in a float64 output always, which doesn't
616
+ # match the overflow to inf of math.pow and libdevice.powi for large
617
+ # values of float32, so we compute the reference result with math.pow.
618
+ Cref = np.empty_like(A)
619
+ for i in range(len(A)):
620
+ Cref[i] = math.pow(A[i], B[i])
621
+ np.testing.assert_allclose(np.power(A, B).astype(npdtype), C, rtol=1e-6)
622
+
623
+ def test_math_pow(self):
624
+ self.binary_template_float32(math_pow, np.power)
625
+ self.binary_template_float64(math_pow, np.power)
626
+ self.pow_template_int32(np.float32)
627
+ self.pow_template_int32(np.float64)
628
+
629
+ #---------------------------------------------------------------------------
630
+ # test_math_pow_binop
631
+
632
+ def test_math_pow_binop(self):
633
+ self.binary_template_float32(math_pow_binop, np.power)
634
+ self.binary_template_float64(math_pow_binop, np.power)
635
+
636
+ #---------------------------------------------------------------------------
637
+ # test_math_ceil
638
+
639
+ def test_math_ceil(self):
640
+ self.unary_template_float32(math_ceil, np.ceil)
641
+ self.unary_template_float64(math_ceil, np.ceil)
642
+ self.unary_template_int64(math_ceil, np.ceil)
643
+ self.unary_template_uint64(math_ceil, np.ceil)
644
+
645
+ #---------------------------------------------------------------------------
646
+ # test_math_floor
647
+
648
+ def test_math_floor(self):
649
+ self.unary_template_float32(math_floor, np.floor)
650
+ self.unary_template_float64(math_floor, np.floor)
651
+ self.unary_template_int64(math_floor, np.floor)
652
+ self.unary_template_uint64(math_floor, np.floor)
653
+
654
+ #---------------------------------------------------------------------------
655
+ # test_math_trunc
656
+ #
657
+ # Note that math.trunc() is only supported on NumPy float64s, and not
658
+ # other float types or int types. See NumPy Issue #13375:
659
+ #
660
+ # - https://github.com/numpy/numpy/issues/13375 - "Add methods from the
661
+ # builtin float types to the numpy floating point types"
662
+
663
+ def test_math_trunc(self):
664
+ self.unary_template_float64(math_trunc, np.trunc)
665
+
666
+ @skip_on_cudasim('trunc only supported on NumPy float64')
667
+ def test_math_trunc_non_float64(self):
668
+ self.unary_template_float32(math_trunc, np.trunc)
669
+ self.unary_template_int64(math_trunc, np.trunc)
670
+ self.unary_template_uint64(math_trunc, np.trunc)
671
+
672
+ #---------------------------------------------------------------------------
673
+ # test_math_copysign
674
+
675
+ def test_math_copysign(self):
676
+ self.binary_template_float32(math_copysign, np.copysign, start=-1)
677
+ self.binary_template_float64(math_copysign, np.copysign, start=-1)
678
+
679
+ #---------------------------------------------------------------------------
680
+ # test_math_modf
681
+
682
+ def test_math_modf(self):
683
+ def modf_template_nan(dtype, arytype):
684
+ A = np.array([np.nan], dtype=dtype)
685
+ B = np.zeros_like(A)
686
+ C = np.zeros_like(A)
687
+ cfunc = cuda.jit((arytype, arytype, arytype))(math_modf)
688
+ cfunc[1, len(A)](A, B, C)
689
+ self.assertTrue(np.isnan(B))
690
+ self.assertTrue(np.isnan(C))
691
+
692
+ def modf_template_compare(A, dtype, arytype):
693
+ A = A.astype(dtype)
694
+ B = np.zeros_like(A)
695
+ C = np.zeros_like(A)
696
+ cfunc = cuda.jit((arytype, arytype, arytype))(math_modf)
697
+ cfunc[1, len(A)](A, B, C)
698
+ D, E = np.modf(A)
699
+ self.assertTrue(np.array_equal(B,D))
700
+ self.assertTrue(np.array_equal(C,E))
701
+
702
+ nelem = 50
703
+ #32 bit float
704
+ with self.subTest("float32 modf on simple float"):
705
+ modf_template_compare(np.linspace(0, 10, nelem), dtype=np.float32,
706
+ arytype=float32[:])
707
+ with self.subTest("float32 modf on +- infinity"):
708
+ modf_template_compare(np.array([np.inf, -np.inf]), dtype=np.float32,
709
+ arytype=float32[:])
710
+ with self.subTest("float32 modf on nan"):
711
+ modf_template_nan(dtype=np.float32, arytype=float32[:])
712
+
713
+ #64 bit float
714
+ with self.subTest("float64 modf on simple float"):
715
+ modf_template_compare(np.linspace(0, 10, nelem), dtype=np.float64,
716
+ arytype=float64[:])
717
+ with self.subTest("float64 modf on +- infinity"):
718
+ modf_template_compare(np.array([np.inf, -np.inf]), dtype=np.float64,
719
+ arytype=float64[:])
720
+ with self.subTest("float64 modf on nan"):
721
+ modf_template_nan(dtype=np.float64, arytype=float64[:])
722
+
723
+ #---------------------------------------------------------------------------
724
+ # test_math_fmod
725
+
726
+ def test_math_fmod(self):
727
+ self.binary_template_float32(math_fmod, np.fmod, start=1)
728
+ self.binary_template_float64(math_fmod, np.fmod, start=1)
729
+
730
+ #---------------------------------------------------------------------------
731
+ # test_math_mod_binop
732
+
733
+ def test_math_mod_binop(self):
734
+ self.binary_template_float32(math_mod_binop, np.fmod, start=1)
735
+ self.binary_template_float64(math_mod_binop, np.fmod, start=1)
736
+
737
+ #---------------------------------------------------------------------------
738
+ # test_math_isnan
739
+
740
+ def test_math_isnan(self):
741
+ self.unary_bool_template_float32(math_isnan, np.isnan)
742
+ self.unary_bool_template_float64(math_isnan, np.isnan)
743
+ self.unary_bool_template_int32(math_isnan, np.isnan)
744
+ self.unary_bool_template_int64(math_isnan, np.isnan)
745
+ self.unary_bool_special_values_float32(math_isnan, np.isnan)
746
+ self.unary_bool_special_values_float64(math_isnan, np.isnan)
747
+
748
+ #---------------------------------------------------------------------------
749
+ # test_math_isinf
750
+
751
+ def test_math_isinf(self):
752
+ self.unary_bool_template_float32(math_isinf, np.isinf)
753
+ self.unary_bool_template_float64(math_isinf, np.isinf)
754
+ self.unary_bool_template_int32(math_isinf, np.isinf)
755
+ self.unary_bool_template_int64(math_isinf, np.isinf)
756
+ self.unary_bool_special_values_float32(math_isinf, np.isinf)
757
+ self.unary_bool_special_values_float64(math_isinf, np.isinf)
758
+
759
+ #---------------------------------------------------------------------------
760
+ # test_math_isfinite
761
+
762
+ def test_math_isfinite(self):
763
+ self.unary_bool_template_float32(math_isfinite, np.isfinite)
764
+ self.unary_bool_template_float64(math_isfinite, np.isfinite)
765
+ self.unary_bool_template_int32(math_isfinite, np.isfinite)
766
+ self.unary_bool_template_int64(math_isfinite, np.isfinite)
767
+ self.unary_bool_special_values_float32(math_isfinite, np.isfinite)
768
+ self.unary_bool_special_values_float64(math_isfinite, np.isfinite)
769
+
770
+ #---------------------------------------------------------------------------
771
+ # test_math_degrees
772
+
773
+ def test_math_degrees(self):
774
+ self.unary_bool_template_float32(math_degrees, np.degrees)
775
+ self.unary_bool_template_float64(math_degrees, np.degrees)
776
+
777
+ #---------------------------------------------------------------------------
778
+ # test_math_radians
779
+
780
+ def test_math_radians(self):
781
+ self.unary_bool_template_float32(math_radians, np.radians)
782
+ self.unary_bool_template_float64(math_radians, np.radians)
783
+
784
+
785
+ if __name__ == '__main__':
786
+ unittest.main()