()
| 328 | |
| 329 | |
| 330 | def test_reshape_blockwise(): |
| 331 | x = np.arange(0, 54).reshape(6, 3, 3) |
| 332 | arr = from_array(x, chunks=(3, 2, (2, 1))) |
| 333 | assert arr.chunks == ((3, 3), (2, 1), (2, 1)) |
| 334 | result = reshape_blockwise(arr, (18, 3)) |
| 335 | assert result.chunks == ((6, 3, 6, 3), (2, 1)) |
| 336 | expected = [ |
| 337 | np.concatenate( |
| 338 | [x[:3, :2, :2].reshape(6, 2), x[:3, :2, 2:].reshape(6, 1)], axis=1 |
| 339 | ), |
| 340 | np.concatenate( |
| 341 | [x[:3, 2:, :2].reshape(3, 2), x[:3, 2:, 2:].reshape(3, 1)], axis=1 |
| 342 | ), |
| 343 | np.concatenate( |
| 344 | [x[3:, :2, :2].reshape(6, 2), x[3:, :2, 2:].reshape(6, 1)], axis=1 |
| 345 | ), |
| 346 | np.concatenate( |
| 347 | [x[3:, 2:, :2].reshape(3, 2), x[3:, 2:, 2:].reshape(3, 1)], axis=1 |
| 348 | ), |
| 349 | ] |
| 350 | expected = np.concatenate(expected, axis=0) |
| 351 | assert_eq(result, expected) |
| 352 | result2 = reshape_blockwise(result, (6, 3, 3), chunks=arr.chunks) |
| 353 | assert_eq(arr, result2) |
| 354 | assert result2.chunks == arr.chunks |
| 355 | |
| 356 | result = reshape_blockwise(arr, (6, 9)) |
| 357 | assert result.chunks == ((3, 3), (4, 2, 2, 1)) |
| 358 | expected = [ |
| 359 | np.concatenate( |
| 360 | [ |
| 361 | x[:3, :2, :2].reshape(3, 4), |
| 362 | x[:3, :2, 2:].reshape(3, 2), |
| 363 | x[:3, 2:, :2].reshape(3, 2), |
| 364 | x[:3, 2:, 2:].reshape(3, 1), |
| 365 | ], |
| 366 | axis=1, |
| 367 | ), |
| 368 | np.concatenate( |
| 369 | [ |
| 370 | x[3:, :2, :2].reshape(3, 4), |
| 371 | x[3:, :2, 2:].reshape(3, 2), |
| 372 | x[3:, 2:, :2].reshape(3, 2), |
| 373 | x[3:, 2:, 2:].reshape(3, 1), |
| 374 | ], |
| 375 | axis=1, |
| 376 | ), |
| 377 | ] |
| 378 | |
| 379 | # chunks of first half of the array, i.e. arr[:3, :, :]: |
| 380 | # [[[0, 1], [3, 4]], [[9, 10], [12, 13]], [[18, 19], [21, 22]]] |
| 381 | # [[[2], [5]], [[11], [14]], [[20], [23]]] |
| 382 | # [[[6, 7], [15, 16]], [[24, 25]]] |
| 383 | # [[[8], [17]], [[26]]] |
| 384 | # The inner dimensions are squashed, i.e. |
| 385 | # [[ 0 1 3 4 2 5 6 7 8] |
| 386 | # [ 9 10 12 13 11 14 15 16 17] |
| 387 | # [18 19 21 22 20 23 24 25 26]] |
nothing calls this directly
no test coverage detected