| 254 | |
| 255 | |
| 256 | def test_npyiter_api(install_temp): |
| 257 | import checks |
| 258 | arr = np.random.rand(3, 2) |
| 259 | |
| 260 | it = np.nditer(arr) |
| 261 | assert checks.get_npyiter_size(it) == it.itersize == np.prod(arr.shape) |
| 262 | assert checks.get_npyiter_ndim(it) == it.ndim == 1 |
| 263 | assert checks.npyiter_has_index(it) == it.has_index == False |
| 264 | |
| 265 | it = np.nditer(arr, flags=["c_index"]) |
| 266 | assert checks.npyiter_has_index(it) == it.has_index == True |
| 267 | assert ( |
| 268 | checks.npyiter_has_delayed_bufalloc(it) |
| 269 | == it.has_delayed_bufalloc |
| 270 | == False |
| 271 | ) |
| 272 | |
| 273 | it = np.nditer(arr, flags=["buffered", "delay_bufalloc"]) |
| 274 | assert ( |
| 275 | checks.npyiter_has_delayed_bufalloc(it) |
| 276 | == it.has_delayed_bufalloc |
| 277 | == True |
| 278 | ) |
| 279 | |
| 280 | it = np.nditer(arr, flags=["multi_index"]) |
| 281 | assert checks.get_npyiter_size(it) == it.itersize == np.prod(arr.shape) |
| 282 | assert checks.npyiter_has_multi_index(it) == it.has_multi_index == True |
| 283 | assert checks.get_npyiter_ndim(it) == it.ndim == 2 |
| 284 | assert checks.test_get_multi_index_iter_next(it, arr) |
| 285 | |
| 286 | arr2 = np.random.rand(2, 1, 2) |
| 287 | it = np.nditer([arr, arr2]) |
| 288 | assert checks.get_npyiter_nop(it) == it.nop == 2 |
| 289 | assert checks.get_npyiter_size(it) == it.itersize == 12 |
| 290 | assert checks.get_npyiter_ndim(it) == it.ndim == 3 |
| 291 | assert all( |
| 292 | x is y for x, y in zip(checks.get_npyiter_operands(it), it.operands) |
| 293 | ) |
| 294 | assert all( |
| 295 | np.allclose(x, y) |
| 296 | for x, y in zip(checks.get_npyiter_itviews(it), it.itviews) |
| 297 | ) |
| 298 | |
| 299 | |
| 300 | def test_fillwithbytes(install_temp): |