|
| 1 | +####################################################################### |
| 2 | +# Copyright (c) 2019-present, Blosc Development Team <[email protected]> |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under a BSD-style license (found in the |
| 6 | +# LICENSE file in the root directory of this source tree) |
| 7 | +####################################################################### |
| 8 | + |
| 9 | +import numpy as np |
| 10 | +import pytest |
| 11 | + |
| 12 | +import blosc2 |
| 13 | + |
| 14 | + |
| 15 | +@pytest.mark.parametrize( |
| 16 | + "contiguous, urlpath, cparams, nchunks, start, stop", |
| 17 | + [ |
| 18 | + (True, None, {"typesize": 4}, 10, 0, 100), |
| 19 | + (True, "b2frame", {"typesize": 4}, 1, 7, 23), |
| 20 | + ( |
| 21 | + False, |
| 22 | + None, |
| 23 | + {"splitmode": blosc2.SplitMode.ALWAYS_SPLIT, "nthreads": 5, "typesize": 4}, |
| 24 | + 5, |
| 25 | + 21, |
| 26 | + 200 * 2 * 100, |
| 27 | + ), |
| 28 | + (False, "b2frame", {"codec": blosc2.Codec.LZ4HC, "typesize": 4}, 7, None, None), |
| 29 | + (True, None, {"blocksize": 200 * 100, "typesize": 4}, 5, -2456, -234), |
| 30 | + (True, "b2frame", {"blocksize": 200 * 100, "typesize": 4}, 4, 2456, -234), |
| 31 | + (False, None, {"blocksize": 100 * 100, "typesize": 4}, 2, -200 * 100 + 234, 40000), |
| 32 | + ], |
| 33 | +) |
| 34 | +def test_schunk_get_slice(contiguous, urlpath, cparams, nchunks, start, stop): |
| 35 | + storage = {"contiguous": contiguous, "urlpath": urlpath, "cparams": cparams} |
| 36 | + schunk = blosc2.SChunk(chunksize=200 * 100 * 4, mode="w", **storage) |
| 37 | + for i in range(nchunks): |
| 38 | + chunk = np.full(schunk.chunksize // schunk.typesize, i, dtype=np.int32) |
| 39 | + schunk.append_data(chunk) |
| 40 | + |
| 41 | + aux = np.empty(200 * 100 * nchunks, dtype=np.int32) |
| 42 | + res = aux[start:stop] |
| 43 | + sl = schunk.get_slice(start, stop, res) |
| 44 | + np.array_equal(np.unique(res), blosc2.get_slice_nchunks(schunk, (start, stop))) |
| 45 | + |
| 46 | + blosc2.remove_urlpath(urlpath) |
0 commit comments