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,104 @@
1
+ import math
2
+
3
+ import numpy as np
4
+
5
+ from numba import cuda
6
+ from numba.cuda.testing import unittest
7
+ from numba.cuda.testing import skip_on_cudasim, CUDATestCase
8
+
9
+ from numba.cuda.random import \
10
+ xoroshiro128p_uniform_float32, xoroshiro128p_normal_float32, \
11
+ xoroshiro128p_uniform_float64, xoroshiro128p_normal_float64
12
+
13
+
14
+ # Distributions
15
+ UNIFORM = 1
16
+ NORMAL = 2
17
+
18
+
19
+ @cuda.jit
20
+ def rng_kernel_float32(states, out, count, distribution):
21
+ thread_id = cuda.grid(1)
22
+
23
+ for i in range(count):
24
+ idx = thread_id * count + i
25
+
26
+ if distribution == UNIFORM:
27
+ out[idx] = xoroshiro128p_uniform_float32(states, thread_id)
28
+ elif distribution == NORMAL:
29
+ out[idx] = xoroshiro128p_normal_float32(states, thread_id)
30
+
31
+
32
+ @cuda.jit
33
+ def rng_kernel_float64(states, out, count, distribution):
34
+ thread_id = cuda.grid(1)
35
+
36
+ for i in range(count):
37
+ idx = thread_id * count + i
38
+
39
+ if distribution == UNIFORM:
40
+ out[idx] = xoroshiro128p_uniform_float64(states, thread_id)
41
+ elif distribution == NORMAL:
42
+ out[idx] = xoroshiro128p_normal_float64(states, thread_id)
43
+
44
+
45
+ class TestCudaRandomXoroshiro128p(CUDATestCase):
46
+ def test_create(self):
47
+ states = cuda.random.create_xoroshiro128p_states(10, seed=1)
48
+ s = states.copy_to_host()
49
+ self.assertEqual(len(np.unique(s)), 10)
50
+
51
+ def test_create_subsequence_start(self):
52
+ states = cuda.random.create_xoroshiro128p_states(10, seed=1)
53
+ s1 = states.copy_to_host()
54
+
55
+ states = cuda.random.create_xoroshiro128p_states(10, seed=1,
56
+ subsequence_start=3)
57
+ s2 = states.copy_to_host()
58
+
59
+ # Starting seeds should match up with offset of 3
60
+ np.testing.assert_array_equal(s1[3:], s2[:-3])
61
+
62
+ def test_create_stream(self):
63
+ stream = cuda.stream()
64
+ states = cuda.random.create_xoroshiro128p_states(10, seed=1,
65
+ stream=stream)
66
+ s = states.copy_to_host()
67
+ self.assertEqual(len(np.unique(s)), 10)
68
+
69
+ def check_uniform(self, kernel_func, dtype):
70
+ states = cuda.random.create_xoroshiro128p_states(32 * 2, seed=1)
71
+ out = np.zeros(2 * 32 * 32, dtype=np.float32)
72
+
73
+ kernel_func[2, 32](states, out, 32, UNIFORM)
74
+ self.assertAlmostEqual(out.min(), 0.0, delta=1e-3)
75
+ self.assertAlmostEqual(out.max(), 1.0, delta=1e-3)
76
+ self.assertAlmostEqual(out.mean(), 0.5, delta=1.5e-2)
77
+ self.assertAlmostEqual(out.std(), 1.0 / (2 * math.sqrt(3)), delta=6e-3)
78
+
79
+ def test_uniform_float32(self):
80
+ self.check_uniform(rng_kernel_float32, np.float32)
81
+
82
+ @skip_on_cudasim('skip test for speed under cudasim')
83
+ def test_uniform_float64(self):
84
+ self.check_uniform(rng_kernel_float64, np.float64)
85
+
86
+ def check_normal(self, kernel_func, dtype):
87
+ states = cuda.random.create_xoroshiro128p_states(32 * 2, seed=1)
88
+ out = np.zeros(2 * 32 * 32, dtype=dtype)
89
+
90
+ kernel_func[2, 32](states, out, 32, NORMAL)
91
+
92
+ self.assertAlmostEqual(out.mean(), 0.0, delta=4e-3)
93
+ self.assertAlmostEqual(out.std(), 1.0, delta=2e-3)
94
+
95
+ def test_normal_float32(self):
96
+ self.check_normal(rng_kernel_float32, np.float32)
97
+
98
+ @skip_on_cudasim('skip test for speed under cudasim')
99
+ def test_normal_float64(self):
100
+ self.check_normal(rng_kernel_float64, np.float64)
101
+
102
+
103
+ if __name__ == '__main__':
104
+ unittest.main()
@@ -0,0 +1,610 @@
1
+ import numpy as np
2
+ from numba import cuda
3
+ from numba.core import types
4
+ from numba.cuda.testing import skip_on_cudasim, CUDATestCase
5
+ import unittest
6
+ from numba.np import numpy_support
7
+
8
+
9
+ def set_a(ary, i, v):
10
+ ary[i].a = v
11
+
12
+
13
+ def set_b(ary, i, v):
14
+ ary[i].b = v
15
+
16
+
17
+ def set_c(ary, i, v):
18
+ ary[i].c = v
19
+
20
+
21
+ def set_record(ary, i, j):
22
+ ary[i] = ary[j]
23
+
24
+
25
+ def record_set_a(r, v):
26
+ r.a = v
27
+
28
+
29
+ def record_set_b(r, v):
30
+ r.b = v
31
+
32
+
33
+ def record_set_c(r, v):
34
+ r.c = v
35
+
36
+
37
+ def record_read_a(r, arr):
38
+ arr[0] = r.a
39
+
40
+
41
+ def record_read_b(r, arr):
42
+ arr[0] = r.b
43
+
44
+
45
+ def record_read_c(r, arr):
46
+ arr[0] = r.c
47
+
48
+
49
+ def record_write_array(r):
50
+ r.g = 2
51
+ r.h[0] = 3.0
52
+ r.h[1] = 4.0
53
+
54
+
55
+ def record_write_2d_array(r):
56
+ r.i = 3
57
+ r.j[0, 0] = 5.0
58
+ r.j[0, 1] = 6.0
59
+ r.j[1, 0] = 7.0
60
+ r.j[1, 1] = 8.0
61
+ r.j[2, 0] = 9.0
62
+ r.j[2, 1] = 10.0
63
+
64
+
65
+ def record_read_array(r, a):
66
+ a[0] = r.h[0]
67
+ a[1] = r.h[1]
68
+
69
+
70
+ def record_read_2d_array(r, a):
71
+ a[0, 0] = r.j[0, 0]
72
+ a[0, 1] = r.j[0, 1]
73
+ a[1, 0] = r.j[1, 0]
74
+ a[1, 1] = r.j[1, 1]
75
+ a[2, 0] = r.j[2, 0]
76
+ a[2, 1] = r.j[2, 1]
77
+
78
+
79
+ recordtype = np.dtype(
80
+ [
81
+ ('a', np.float64),
82
+ ('b', np.int32),
83
+ ('c', np.complex64),
84
+ ('d', (np.uint8, 5))
85
+ ],
86
+ align=True
87
+ )
88
+
89
+ recordwitharray = np.dtype(
90
+ [
91
+ ('g', np.int32),
92
+ ('h', np.float32, 2)
93
+ ],
94
+ align=True
95
+ )
96
+
97
+ recordwith2darray = np.dtype([('i', np.int32),
98
+ ('j', np.float32, (3, 2))])
99
+
100
+ nested_array1_dtype = np.dtype([("array1", np.int16, (3,))], align=True)
101
+
102
+ nested_array2_dtype = np.dtype([("array2", np.int16, (3, 2))], align=True)
103
+
104
+
105
+ # Functions used for "full array" tests
106
+
107
+ def record_write_full_array(rec):
108
+ rec.j[:, :] = np.ones((3, 2))
109
+
110
+
111
+ def record_write_full_array_alt(rec):
112
+ rec['j'][:, :] = np.ones((3, 2))
113
+
114
+
115
+ def recarray_set_record(ary, rec):
116
+ ary[0] = rec
117
+
118
+
119
+ def recarray_write_array_of_nestedarray_broadcast(ary):
120
+ ary.j[:, :, :] = 1
121
+ return ary
122
+
123
+
124
+ def record_setitem_array(rec_source, rec_dest):
125
+ rec_dest['j'] = rec_source['j']
126
+
127
+
128
+ def recarray_write_array_of_nestedarray(ary):
129
+ ary.j[:, :, :] = np.ones((2, 3, 2))
130
+ return ary
131
+
132
+
133
+ def recarray_getitem_return(ary):
134
+ return ary[0]
135
+
136
+
137
+ def recarray_getitem_field_return(ary):
138
+ return ary['h']
139
+
140
+
141
+ def recarray_getitem_field_return2(ary):
142
+ return ary.h
143
+
144
+
145
+ def recarray_getitem_field_return2_2d(ary):
146
+ return ary.j
147
+
148
+
149
+ def record_read_array0(ary):
150
+ return ary.h[0]
151
+
152
+
153
+ def record_read_array1(ary):
154
+ return ary.h[1]
155
+
156
+
157
+ def record_read_whole_array(ary):
158
+ return ary.h
159
+
160
+
161
+ def record_read_2d_array00(ary):
162
+ return ary.j[0, 0]
163
+
164
+
165
+ def record_read_2d_array10(ary):
166
+ return ary.j[1, 0]
167
+
168
+
169
+ def record_read_2d_array01(ary):
170
+ return ary.j[0, 1]
171
+
172
+
173
+ def assign_array_to_nested(dest, src):
174
+ dest['array1'] = src
175
+
176
+
177
+ def assign_array_to_nested_2d(dest, src):
178
+ dest['array2'] = src
179
+
180
+
181
+ class TestRecordDtype(CUDATestCase):
182
+
183
+ def _createSampleArrays(self):
184
+ self.sample1d = np.recarray(3, dtype=recordtype)
185
+ self.samplerec1darr = np.recarray(1, dtype=recordwitharray)[0]
186
+ self.samplerec2darr = np.recarray(1, dtype=recordwith2darray)[0]
187
+
188
+ def setUp(self):
189
+ super().setUp()
190
+ self._createSampleArrays()
191
+
192
+ ary = self.sample1d
193
+ for i in range(ary.size):
194
+ x = i + 1
195
+ ary[i]['a'] = x / 2
196
+ ary[i]['b'] = x
197
+ ary[i]['c'] = x * 1j
198
+ ary[i]['d'] = "%d" % x
199
+
200
+ def get_cfunc(self, pyfunc, argspec):
201
+ return cuda.jit()(pyfunc)
202
+
203
+ def _test_set_equal(self, pyfunc, value, valuetype):
204
+ rec = numpy_support.from_dtype(recordtype)
205
+ cfunc = self.get_cfunc(pyfunc, (rec[:], types.intp, valuetype))
206
+
207
+ for i in range(self.sample1d.size):
208
+ got = self.sample1d.copy()
209
+
210
+ # Force the argument to the pure Python function to be
211
+ # a recarray, as attribute access isn't supported on
212
+ # structured arrays.
213
+ expect = got.copy().view(np.recarray)
214
+
215
+ cfunc[1, 1](got, i, value)
216
+ pyfunc(expect, i, value)
217
+
218
+ # Match the entire array to ensure no memory corruption
219
+ self.assertTrue(np.all(expect == got))
220
+
221
+ def test_set_a(self):
222
+ self._test_set_equal(set_a, 3.1415, types.float64)
223
+ # Test again to check if coercion works
224
+ self._test_set_equal(set_a, 3., types.float32)
225
+
226
+ def test_set_b(self):
227
+ self._test_set_equal(set_b, 123, types.int32)
228
+ # Test again to check if coercion works
229
+ self._test_set_equal(set_b, 123, types.float64)
230
+
231
+ def test_set_c(self):
232
+ self._test_set_equal(set_c, 43j, types.complex64)
233
+ # Test again to check if coercion works
234
+ self._test_set_equal(set_c, 43j, types.complex128)
235
+
236
+ def test_set_record(self):
237
+ pyfunc = set_record
238
+ rec = numpy_support.from_dtype(recordtype)
239
+ cfunc = self.get_cfunc(pyfunc, (rec[:], types.intp, types.intp))
240
+
241
+ test_indices = [(0, 1), (1, 2), (0, 2)]
242
+ for i, j in test_indices:
243
+ expect = self.sample1d.copy()
244
+ pyfunc(expect, i, j)
245
+
246
+ got = self.sample1d.copy()
247
+ cfunc[1, 1](got, i, j)
248
+
249
+ # Match the entire array to ensure no memory corruption
250
+ self.assertEqual(expect[i], expect[j])
251
+ self.assertEqual(got[i], got[j])
252
+ self.assertTrue(np.all(expect == got))
253
+
254
+ def _test_rec_set(self, v, pyfunc, f):
255
+ rec = self.sample1d.copy()[0]
256
+ nbrecord = numpy_support.from_dtype(recordtype)
257
+ cfunc = self.get_cfunc(pyfunc, (nbrecord,))
258
+ cfunc[1, 1](rec, v)
259
+ np.testing.assert_equal(rec[f], v)
260
+
261
+ def test_rec_set_a(self):
262
+ self._test_rec_set(np.float64(1.5), record_set_a, 'a')
263
+
264
+ def test_rec_set_b(self):
265
+ self._test_rec_set(np.int32(2), record_set_b, 'b')
266
+
267
+ def test_rec_set_c(self):
268
+ self._test_rec_set(np.complex64(4.0 + 5.0j), record_set_c, 'c')
269
+
270
+ def _test_rec_read(self, v, pyfunc, f):
271
+ rec = self.sample1d.copy()[0]
272
+ rec[f] = v
273
+ arr = np.zeros(1, v.dtype)
274
+ nbrecord = numpy_support.from_dtype(recordtype)
275
+ cfunc = self.get_cfunc(pyfunc, (nbrecord,))
276
+ cfunc[1, 1](rec, arr)
277
+ np.testing.assert_equal(arr[0], v)
278
+
279
+ def test_rec_read_a(self):
280
+ self._test_rec_read(np.float64(1.5), record_read_a, 'a')
281
+
282
+ def test_rec_read_b(self):
283
+ self._test_rec_read(np.int32(2), record_read_b, 'b')
284
+
285
+ def test_rec_read_c(self):
286
+ self._test_rec_read(np.complex64(4.0 + 5.0j), record_read_c, 'c')
287
+
288
+ def test_record_write_1d_array(self):
289
+ '''
290
+ Test writing to a 1D array within a structured type
291
+ '''
292
+ rec = self.samplerec1darr.copy()
293
+ nbrecord = numpy_support.from_dtype(recordwitharray)
294
+ cfunc = self.get_cfunc(record_write_array, (nbrecord,))
295
+
296
+ cfunc[1, 1](rec)
297
+ expected = self.samplerec1darr.copy()
298
+ expected['g'] = 2
299
+ expected['h'][0] = 3.0
300
+ expected['h'][1] = 4.0
301
+
302
+ np.testing.assert_equal(expected, rec)
303
+
304
+ def test_record_write_2d_array(self):
305
+ '''
306
+ Test writing to a 2D array within a structured type
307
+ '''
308
+ rec = self.samplerec2darr.copy()
309
+ nbrecord = numpy_support.from_dtype(recordwith2darray)
310
+ cfunc = self.get_cfunc(record_write_2d_array, (nbrecord,))
311
+ cfunc[1, 1](rec)
312
+
313
+ expected = self.samplerec2darr.copy()
314
+ expected['i'] = 3
315
+ expected['j'][:] = np.asarray([5.0, 6.0, 7.0, 8.0, 9.0, 10.0],
316
+ np.float32).reshape(3, 2)
317
+ np.testing.assert_equal(expected, rec)
318
+
319
+ def test_record_read_1d_array(self):
320
+ '''
321
+ Test reading from a 1D array within a structured type
322
+ '''
323
+ rec = self.samplerec1darr.copy()
324
+ rec['h'][0] = 4.0
325
+ rec['h'][1] = 5.0
326
+
327
+ nbrecord = numpy_support.from_dtype(recordwitharray)
328
+ cfunc = self.get_cfunc(record_read_array, (nbrecord,))
329
+ arr = np.zeros(2, dtype=rec['h'].dtype)
330
+ cfunc[1, 1](rec, arr)
331
+
332
+ np.testing.assert_equal(rec['h'], arr)
333
+
334
+ def test_record_read_2d_array(self):
335
+ '''
336
+ Test reading from a 2D array within a structured type
337
+ '''
338
+ rec = self.samplerec2darr.copy()
339
+ rec['j'][:] = np.asarray([5.0, 6.0, 7.0, 8.0, 9.0, 10.0],
340
+ np.float32).reshape(3, 2)
341
+
342
+ nbrecord = numpy_support.from_dtype(recordwith2darray)
343
+ cfunc = self.get_cfunc(record_read_2d_array, (nbrecord,))
344
+ arr = np.zeros((3,2), dtype=rec['j'].dtype)
345
+ cfunc[1, 1](rec, arr)
346
+
347
+ np.testing.assert_equal(rec['j'], arr)
348
+
349
+
350
+ @skip_on_cudasim('Structured array attr access not supported in simulator')
351
+ class TestRecordDtypeWithStructArrays(TestRecordDtype):
352
+ '''
353
+ Same as TestRecordDtype, but using structured arrays instead of recarrays.
354
+ '''
355
+
356
+ def _createSampleArrays(self):
357
+ self.sample1d = np.zeros(3, dtype=recordtype)
358
+ self.samplerec1darr = np.zeros(1, dtype=recordwitharray)[0]
359
+ self.samplerec2darr = np.zeros(1, dtype=recordwith2darray)[0]
360
+
361
+
362
+ class TestNestedArrays(CUDATestCase):
363
+
364
+ # These tests mirror those from
365
+ # numba.tests.test_record_dtype.TestNestedArrays added in PR
366
+ # #7359: https://github.com/numba/numba/pull/7359
367
+
368
+ # The code cannot be shared between the two classes without modification,
369
+ # as the CUDA test implementations need to be launched (and in some cases
370
+ # wrapped in an outer function to handle the return value). Otherwise, the
371
+ # code here is kept as similar to that in the equivalent CPU tests as
372
+ # possible.
373
+
374
+ # Reading records / recarrays
375
+
376
+ def get_cfunc(self, pyfunc, retty):
377
+ # Create a host-callable function for testing CUDA device functions
378
+ # that get a value from a record array
379
+ inner = cuda.jit(device=True)(pyfunc)
380
+
381
+ @cuda.jit
382
+ def outer(arg0, res):
383
+ res[0] = inner(arg0)
384
+
385
+ def host(arg0):
386
+ res = np.zeros(1, dtype=retty)
387
+ outer[1, 1](arg0, res)
388
+ return res[0]
389
+
390
+ return host
391
+
392
+ def test_record_read_array(self):
393
+ # Test reading from a 1D array within a structured type
394
+ nbval = np.recarray(1, dtype=recordwitharray)
395
+ nbval[0].h[0] = 15.0
396
+ nbval[0].h[1] = 25.0
397
+ cfunc = self.get_cfunc(record_read_array0, np.float32)
398
+ res = cfunc(nbval[0])
399
+ np.testing.assert_equal(res, nbval[0].h[0])
400
+
401
+ cfunc = self.get_cfunc(record_read_array1, np.float32)
402
+ res = cfunc(nbval[0])
403
+ np.testing.assert_equal(res, nbval[0].h[1])
404
+
405
+ def test_record_read_2d_array(self):
406
+ # Test reading from a 2D array within a structured type
407
+ nbval = np.recarray(1, dtype=recordwith2darray)
408
+ nbval[0].j = np.asarray([1.5, 2.5, 3.5, 4.5, 5.5, 6.5],
409
+ np.float32).reshape(3, 2)
410
+ cfunc = self.get_cfunc(record_read_2d_array00, np.float32)
411
+ res = cfunc(nbval[0])
412
+ np.testing.assert_equal(res, nbval[0].j[0, 0])
413
+
414
+ cfunc = self.get_cfunc(record_read_2d_array01, np.float32)
415
+ res = cfunc(nbval[0])
416
+ np.testing.assert_equal(res, nbval[0].j[0, 1])
417
+
418
+ cfunc = self.get_cfunc(record_read_2d_array10, np.float32)
419
+ res = cfunc(nbval[0])
420
+ np.testing.assert_equal(res, nbval[0].j[1, 0])
421
+
422
+ def test_setitem(self):
423
+ def gen():
424
+ nbarr1 = np.recarray(1, dtype=recordwith2darray)
425
+ nbarr1[0] = np.array([(1, ((1, 2), (4, 5), (2, 3)))],
426
+ dtype=recordwith2darray)[0]
427
+ nbarr2 = np.recarray(1, dtype=recordwith2darray)
428
+ nbarr2[0] = np.array([(10, ((10, 20), (40, 50), (20, 30)))],
429
+ dtype=recordwith2darray)[0]
430
+ return nbarr1[0], nbarr2[0]
431
+ pyfunc = record_setitem_array
432
+ pyargs = gen()
433
+ pyfunc(*pyargs)
434
+
435
+ cfunc = cuda.jit(pyfunc)
436
+ cuargs = gen()
437
+ cfunc[1, 1](*cuargs)
438
+ np.testing.assert_equal(pyargs, cuargs)
439
+
440
+ def test_getitem_idx(self):
441
+ # Test __getitem__ with numerical index
442
+
443
+ # This tests returning a record when passing an array and
444
+ # returning the first item when passing a record
445
+ nbarr = np.recarray(2, dtype=recordwitharray)
446
+ nbarr[0] = np.array([(1, (2, 3))], dtype=recordwitharray)[0]
447
+ for arg, retty in [(nbarr, recordwitharray), (nbarr[0], np.int32)]:
448
+ pyfunc = recarray_getitem_return
449
+ arr_expected = pyfunc(arg)
450
+ cfunc = self.get_cfunc(pyfunc, retty)
451
+ arr_res = cfunc(arg)
452
+ np.testing.assert_equal(arr_res, arr_expected)
453
+
454
+ # Writing to records / recarrays
455
+
456
+ @skip_on_cudasim('Structured array attr access not supported in simulator')
457
+ def test_set_record(self):
458
+ # Test setting an entire record
459
+ rec = np.ones(2, dtype=recordwith2darray).view(np.recarray)[0]
460
+ nbarr = np.zeros(2, dtype=recordwith2darray).view(np.recarray)
461
+ arr = np.zeros(2, dtype=recordwith2darray).view(np.recarray)
462
+ pyfunc = recarray_set_record
463
+ pyfunc(arr, rec)
464
+ kernel = cuda.jit(pyfunc)
465
+ kernel[1, 1](nbarr, rec)
466
+ np.testing.assert_equal(nbarr, arr)
467
+
468
+ def test_assign_array_to_nested(self):
469
+ src = (np.arange(3) + 1).astype(np.int16)
470
+ got = np.zeros(2, dtype=nested_array1_dtype)
471
+ expected = np.zeros(2, dtype=nested_array1_dtype)
472
+
473
+ pyfunc = assign_array_to_nested
474
+ kernel = cuda.jit(pyfunc)
475
+
476
+ kernel[1, 1](got[0], src)
477
+ pyfunc(expected[0], src)
478
+
479
+ np.testing.assert_array_equal(expected, got)
480
+
481
+ def test_assign_array_to_nested_2d(self):
482
+ src = (np.arange(6) + 1).astype(np.int16).reshape((3, 2))
483
+ got = np.zeros(2, dtype=nested_array2_dtype)
484
+ expected = np.zeros(2, dtype=nested_array2_dtype)
485
+
486
+ pyfunc = assign_array_to_nested_2d
487
+ kernel = cuda.jit(pyfunc)
488
+
489
+ kernel[1, 1](got[0], src)
490
+ pyfunc(expected[0], src)
491
+
492
+ np.testing.assert_array_equal(expected, got)
493
+
494
+ def test_issue_7693(self):
495
+ src_dtype = np.dtype([
496
+ ("user", np.float64),
497
+ ("array", np.int16, (3,))],
498
+ align=True)
499
+
500
+ dest_dtype = np.dtype([
501
+ ("user1", np.float64),
502
+ ("array1", np.int16, (3,))],
503
+ align=True)
504
+
505
+ @cuda.jit
506
+ def copy(index, src, dest):
507
+ dest['user1'] = src[index]['user']
508
+ dest['array1'] = src[index]['array']
509
+
510
+ source = np.zeros(2, dtype=src_dtype)
511
+ got = np.zeros(2, dtype=dest_dtype)
512
+ expected = np.zeros(2, dtype=dest_dtype)
513
+
514
+ source[0] = (1.2, [1, 2, 3])
515
+ copy[1, 1](0, source, got[0])
516
+ copy.py_func(0, source, expected[0])
517
+
518
+ np.testing.assert_array_equal(expected, got)
519
+
520
+ # Reading and returning arrays from recarrays - the following functions are
521
+ # all xfailed because CUDA cannot handle returning arrays from device
522
+ # functions (or creating arrays in general).
523
+
524
+ @unittest.expectedFailure
525
+ def test_getitem_idx_2darray(self):
526
+ # Test __getitem__ with numerical index
527
+ #
528
+ # This test returning a record when passing an array and
529
+ # return the first item when passing a record
530
+ nbarr = np.recarray(2, dtype=recordwith2darray)
531
+ nbarr[0] = np.array([(1, ((1,2),(4,5),(2,3)))],
532
+ dtype=recordwith2darray)[0]
533
+ for arg, retty in [(nbarr, recordwith2darray),
534
+ (nbarr[0], (np.float32, (3, 2)))]:
535
+ pyfunc = recarray_getitem_field_return2_2d
536
+ arr_expected = pyfunc(arg)
537
+ cfunc = self.get_cfunc(pyfunc, retty)
538
+ arr_res = cfunc(arg)
539
+ np.testing.assert_equal(arr_res, arr_expected)
540
+
541
+ @unittest.expectedFailure
542
+ def test_return_getattr_getitem_fieldname(self):
543
+ # Test __getitem__ with field name and getattr .field_name
544
+ #
545
+ # This tests returning a array of nestedarrays when passing an array and
546
+ # returning a nestedarray when passing a record
547
+ nbarr = np.recarray(2, dtype=recordwitharray)
548
+ nbarr[0] = np.array([(1, (2,3))], dtype=recordwitharray)[0]
549
+ for arg, retty in [(nbarr, recordwitharray), (nbarr[0], np.float32)]:
550
+ for pyfunc in [recarray_getitem_field_return,
551
+ recarray_getitem_field_return2]:
552
+ arr_expected = pyfunc(arg)
553
+ cfunc = self.get_cfunc(pyfunc, retty)
554
+ arr_res = cfunc(arg)
555
+ np.testing.assert_equal(arr_res, arr_expected)
556
+
557
+ @unittest.expectedFailure
558
+ def test_record_read_arrays(self):
559
+ # Test reading from a 1D array within a structured type
560
+ nbval = np.recarray(2, dtype=recordwitharray)
561
+ nbval[0].h[0] = 15.0
562
+ nbval[0].h[1] = 25.0
563
+ nbval[1].h[0] = 35.0
564
+ nbval[1].h[1] = 45.4
565
+ cfunc = self.get_cfunc(record_read_whole_array, np.float32)
566
+ res = cfunc(nbval)
567
+ np.testing.assert_equal(res, nbval.h)
568
+
569
+ @unittest.expectedFailure
570
+ def test_return_array(self):
571
+ # Test getitem record AND array within record and returning it
572
+ nbval = np.recarray(2, dtype=recordwitharray)
573
+ nbval[0] = np.array([(1, (2,3))], dtype=recordwitharray)[0]
574
+ pyfunc = record_read_array0
575
+ arr_expected = pyfunc(nbval)
576
+ cfunc = self.get_cfunc(pyfunc, np.float32)
577
+ arr_res = cfunc(nbval)
578
+ np.testing.assert_equal(arr_expected, arr_res)
579
+
580
+ @skip_on_cudasim('Will unexpectedly pass on cudasim')
581
+ @unittest.expectedFailure
582
+ def test_set_array(self):
583
+ #Test setting an entire array within one record
584
+ arr = np.zeros(2, dtype=recordwith2darray).view(np.recarray)
585
+ rec = arr[0]
586
+ nbarr = np.zeros(2, dtype=recordwith2darray).view(np.recarray)
587
+ nbrec = nbarr[0]
588
+ for pyfunc in (record_write_full_array, record_write_full_array_alt):
589
+ pyfunc(rec)
590
+ kernel = cuda.jit(pyfunc)
591
+ kernel[1, 1](nbrec)
592
+ np.testing.assert_equal(nbarr, arr)
593
+
594
+ @unittest.expectedFailure
595
+ def test_set_arrays(self):
596
+ # Test setting an entire array of arrays (multiple records)
597
+ arr = np.zeros(2, dtype=recordwith2darray).view(np.recarray)
598
+ nbarr = np.zeros(2, dtype=recordwith2darray).view(np.recarray)
599
+ for pyfunc in (
600
+ recarray_write_array_of_nestedarray_broadcast,
601
+ recarray_write_array_of_nestedarray,
602
+ ):
603
+ arr_expected = pyfunc(arr)
604
+ cfunc = self.get_cfunc(pyfunc, nbarr.dtype)
605
+ arr_res = cfunc(nbarr)
606
+ np.testing.assert_equal(arr_res, arr_expected)
607
+
608
+
609
+ if __name__ == '__main__':
610
+ unittest.main()