def test_getitem_numpy(shape, chunks, blocks, slices, dtype): size = int(np.prod(shape)) nparray = np.arange(size, dtype=dtype).reshape(shape) a = cat.asarray(nparray, chunks=chunks, blocks=blocks) nparray_slice = nparray[slices] a_slice = np.asarray(a[slices]).view(dtype) np.testing.assert_almost_equal(a_slice, nparray_slice)
def test_copy_numpy(shape, chunks1, blocks1, chunks2, blocks2, dtype): size = int(np.prod(shape)) nparray = np.arange(size, dtype=dtype).reshape(shape) a = cat.asarray(nparray, chunks=chunks1, blocks=blocks1) b = a.copy(chunks=chunks2, blocks=blocks2, complevel=5, filters=[cat.Filter.BITSHUFFLE]) if chunks2: b = b[...] nparray2 = np.asarray(b).view(dtype) np.testing.assert_almost_equal(nparray, nparray2)
def test_persistency(shape, chunks, blocks, urlpath, sequencial, dtype): if os.path.exists(urlpath): cat.remove(urlpath) size = int(np.prod(shape)) nparray = np.arange(size, dtype=dtype).reshape(shape) _ = cat.asarray(nparray, chunks=chunks, blocks=blocks, urlpath=urlpath, sequencial=sequencial) b = cat.open(urlpath) bc = b[:] nparray2 = np.asarray(bc).view(dtype) np.testing.assert_almost_equal(nparray, nparray2) cat.remove(urlpath)
####################################################################### # Copyright (C) 2019-present, Blosc Development team <*****@*****.**> # All rights reserved. # # This source code is licensed under a BSD-style license (found in the # LICENSE file in the root directory of this source tree) ####################################################################### import caterva as cat import numpy as np shape = (1234, 23) chunks = (253, 23) blocks = (10, 23) dtype = bool # Create a buffer nparray = np.random.choice(a=[True, False], size=np.prod(shape)).reshape(shape) # Create a caterva array from a numpy array a = cat.asarray(nparray, chunks=chunks, blocks=blocks) b = a.copy() # Convert a caterva array to a numpy array nparray2 = np.asarray(b).view(dtype) np.testing.assert_almost_equal(nparray, nparray2)
# Create a caterva array from a buffer a = cat.from_buffer(buffer, shape, dtype.itemsize, dtype=str(dtype), chunks=chunks, blocks=blocks) # Get a copy of a caterva array b = cat.copy(a) d = b.copy() aux = np.asarray(b) aux[1, 2] = 0 aux2 = cat.asarray(aux) print(np.asarray(aux2)) c = np.asarray(b) c[3:5, 2:7] = 0 print(c) del b print(c) # Convert the copy to a buffer buffer1 = a.to_buffer() buffer2 = d.to_buffer()
def test_numpy(shape, chunks, blocks, dtype): size = int(np.prod(shape)) nparray = np.arange(size, dtype=dtype).reshape(shape) a = cat.asarray(nparray, chunks=chunks, blocks=blocks) nparray2 = np.asarray(a[:]).view(dtype) np.testing.assert_almost_equal(nparray, nparray2)