| 2320 | ], |
| 2321 | ) |
| 2322 | def test_aligned_coarsen_chunks(chunks, divisor): |
| 2323 | from dask.array.routines import aligned_coarsen_chunks as acc |
| 2324 | |
| 2325 | aligned_chunks = acc(chunks, divisor) |
| 2326 | any_remainders = (np.array(aligned_chunks) % divisor) != 0 |
| 2327 | valid_chunks = np.where((np.array(chunks) % divisor) == 0)[0] |
| 2328 | |
| 2329 | # check that total number of elements is conserved |
| 2330 | assert sum(aligned_chunks) == sum(chunks) |
| 2331 | # check that valid chunks are not modified |
| 2332 | assert [chunks[idx] for idx in valid_chunks] == [ |
| 2333 | aligned_chunks[idx] for idx in valid_chunks |
| 2334 | ] |
| 2335 | # check that no chunks are 0 |
| 2336 | assert (np.array(aligned_chunks) > 0).all() |
| 2337 | # check that at most one chunk was added |
| 2338 | assert len(aligned_chunks) <= len(chunks) + 1 |
| 2339 | # check that either 0 or 1 chunks are not divisible by divisor |
| 2340 | assert any_remainders.sum() in (0, 1) |
| 2341 | # check that the only indivisible chunk is the last |
| 2342 | if any_remainders.sum() == 1: |
| 2343 | assert any_remainders[-1] == 1 |
| 2344 | |
| 2345 | |
| 2346 | def test_insert(): |