numcodecs 0.13.1__cp313-cp313-macosx_10_13_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of numcodecs might be problematic. Click here for more details.
- numcodecs/__init__.py +143 -0
- numcodecs/_shuffle.cpython-313-darwin.so +0 -0
- numcodecs/abc.py +126 -0
- numcodecs/astype.py +76 -0
- numcodecs/base64.py +27 -0
- numcodecs/bitround.py +79 -0
- numcodecs/blosc.cpython-313-darwin.so +0 -0
- numcodecs/bz2.py +45 -0
- numcodecs/categorize.py +101 -0
- numcodecs/checksum32.py +94 -0
- numcodecs/compat.py +208 -0
- numcodecs/compat_ext.cpython-313-darwin.so +0 -0
- numcodecs/delta.py +97 -0
- numcodecs/fixedscaleoffset.py +132 -0
- numcodecs/fletcher32.cpython-313-darwin.so +0 -0
- numcodecs/gzip.py +52 -0
- numcodecs/jenkins.cpython-313-darwin.so +0 -0
- numcodecs/json.py +107 -0
- numcodecs/lz4.cpython-313-darwin.so +0 -0
- numcodecs/lzma.py +69 -0
- numcodecs/msgpacks.py +86 -0
- numcodecs/ndarray_like.py +65 -0
- numcodecs/packbits.py +85 -0
- numcodecs/pcodec.py +89 -0
- numcodecs/pickles.py +55 -0
- numcodecs/quantize.py +100 -0
- numcodecs/registry.py +72 -0
- numcodecs/shuffle.py +61 -0
- numcodecs/tests/__init__.py +3 -0
- numcodecs/tests/common.py +354 -0
- numcodecs/tests/package_with_entrypoint/__init__.py +11 -0
- numcodecs/tests/package_with_entrypoint-0.1.dist-info/entry_points.txt +2 -0
- numcodecs/tests/test_astype.py +74 -0
- numcodecs/tests/test_base64.py +81 -0
- numcodecs/tests/test_bitround.py +81 -0
- numcodecs/tests/test_blosc.py +277 -0
- numcodecs/tests/test_bz2.py +66 -0
- numcodecs/tests/test_categorize.py +87 -0
- numcodecs/tests/test_checksum32.py +58 -0
- numcodecs/tests/test_compat.py +108 -0
- numcodecs/tests/test_delta.py +60 -0
- numcodecs/tests/test_entrypoints.py +24 -0
- numcodecs/tests/test_entrypoints_backport.py +35 -0
- numcodecs/tests/test_fixedscaleoffset.py +69 -0
- numcodecs/tests/test_fletcher32.py +56 -0
- numcodecs/tests/test_gzip.py +110 -0
- numcodecs/tests/test_jenkins.py +150 -0
- numcodecs/tests/test_json.py +85 -0
- numcodecs/tests/test_lz4.py +83 -0
- numcodecs/tests/test_lzma.py +90 -0
- numcodecs/tests/test_msgpacks.py +123 -0
- numcodecs/tests/test_ndarray_like.py +48 -0
- numcodecs/tests/test_packbits.py +39 -0
- numcodecs/tests/test_pcodec.py +80 -0
- numcodecs/tests/test_pickles.py +61 -0
- numcodecs/tests/test_quantize.py +76 -0
- numcodecs/tests/test_registry.py +40 -0
- numcodecs/tests/test_shuffle.py +168 -0
- numcodecs/tests/test_vlen_array.py +97 -0
- numcodecs/tests/test_vlen_bytes.py +93 -0
- numcodecs/tests/test_vlen_utf8.py +91 -0
- numcodecs/tests/test_zfpy.py +98 -0
- numcodecs/tests/test_zlib.py +94 -0
- numcodecs/tests/test_zstd.py +92 -0
- numcodecs/version.py +16 -0
- numcodecs/vlen.cpython-313-darwin.so +0 -0
- numcodecs/zfpy.py +111 -0
- numcodecs/zlib.py +42 -0
- numcodecs/zstd.cpython-313-darwin.so +0 -0
- numcodecs-0.13.1.dist-info/LICENSE.txt +21 -0
- numcodecs-0.13.1.dist-info/METADATA +64 -0
- numcodecs-0.13.1.dist-info/RECORD +74 -0
- numcodecs-0.13.1.dist-info/WHEEL +5 -0
- numcodecs-0.13.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from numcodecs.msgpacks import MsgPack
|
|
8
|
+
except ImportError as e: # pragma: no cover
|
|
9
|
+
raise unittest.SkipTest("msgpack not available") from e
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
from numcodecs.tests.common import (
|
|
13
|
+
check_backwards_compatibility,
|
|
14
|
+
check_config,
|
|
15
|
+
check_encode_decode_array,
|
|
16
|
+
check_repr,
|
|
17
|
+
greetings,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
# object array with strings
|
|
21
|
+
# object array with mix strings / nans
|
|
22
|
+
# object array with mix of string, int, float
|
|
23
|
+
# ...
|
|
24
|
+
arrays = [
|
|
25
|
+
np.array(['foo', 'bar', 'baz'] * 300, dtype=object),
|
|
26
|
+
np.array([['foo', 'bar', np.nan]] * 300, dtype=object),
|
|
27
|
+
np.array(['foo', 1.0, 2] * 300, dtype=object),
|
|
28
|
+
np.arange(1000, dtype='i4'),
|
|
29
|
+
np.array(['foo', 'bar', 'baz'] * 300),
|
|
30
|
+
np.array(['foo', ['bar', 1.0, 2], {'a': 'b', 'c': 42}] * 300, dtype=object),
|
|
31
|
+
np.array(greetings * 100),
|
|
32
|
+
np.array(greetings * 100, dtype=object),
|
|
33
|
+
np.array([b'foo', b'bar', b'baz'] * 300, dtype=object),
|
|
34
|
+
np.array([g.encode('utf-8') for g in greetings] * 100, dtype=object),
|
|
35
|
+
np.array([[0, 1], [2, 3]], dtype=object),
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_encode_decode():
|
|
40
|
+
for arr in arrays:
|
|
41
|
+
check_encode_decode_array(arr, MsgPack())
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_config():
|
|
45
|
+
check_config(MsgPack())
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_repr():
|
|
49
|
+
check_repr("MsgPack(raw=False, use_bin_type=True, use_single_float=False)")
|
|
50
|
+
check_repr("MsgPack(raw=True, use_bin_type=False, use_single_float=True)")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_backwards_compatibility():
|
|
54
|
+
codec = MsgPack()
|
|
55
|
+
check_backwards_compatibility(codec.codec_id, arrays, [codec])
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@pytest.mark.parametrize(
|
|
59
|
+
"input_data, dtype",
|
|
60
|
+
[
|
|
61
|
+
([0, 1], None),
|
|
62
|
+
([[0, 1], [2, 3]], None),
|
|
63
|
+
([[0], [1], [2, 3]], object),
|
|
64
|
+
([[[0, 0]], [[1, 1]], [[2, 3]]], None),
|
|
65
|
+
(["1"], None),
|
|
66
|
+
(["11", "11"], None),
|
|
67
|
+
(["11", "1", "1"], None),
|
|
68
|
+
([{}], None),
|
|
69
|
+
([{"key": "value"}, ["list", "of", "strings"]], object),
|
|
70
|
+
([b"1"], None),
|
|
71
|
+
([b"11", b"11"], None),
|
|
72
|
+
([b"11", b"1", b"1"], None),
|
|
73
|
+
([{b"key": b"value"}, [b"list", b"of", b"strings"]], object),
|
|
74
|
+
],
|
|
75
|
+
)
|
|
76
|
+
def test_non_numpy_inputs(input_data, dtype):
|
|
77
|
+
codec = MsgPack()
|
|
78
|
+
# numpy will infer a range of different shapes and dtypes for these inputs.
|
|
79
|
+
# Make sure that round-tripping through encode preserves this.
|
|
80
|
+
actual = codec.decode(codec.encode(input_data))
|
|
81
|
+
expect = np.array(input_data, dtype=dtype)
|
|
82
|
+
assert expect.shape == actual.shape
|
|
83
|
+
assert np.array_equal(expect, actual)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def test_encode_decode_shape_dtype_preserved():
|
|
87
|
+
codec = MsgPack()
|
|
88
|
+
for arr in arrays:
|
|
89
|
+
actual = codec.decode(codec.encode(arr))
|
|
90
|
+
assert arr.shape == actual.shape
|
|
91
|
+
assert arr.dtype == actual.dtype
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_bytes():
|
|
95
|
+
# test msgpack behaviour with bytes and str (unicode)
|
|
96
|
+
bytes_arr = np.array([b'foo', b'bar', b'baz'], dtype=object)
|
|
97
|
+
unicode_arr = np.array(['foo', 'bar', 'baz'], dtype=object)
|
|
98
|
+
|
|
99
|
+
# raw=False (default)
|
|
100
|
+
codec = MsgPack()
|
|
101
|
+
# works for bytes array, round-trips bytes to bytes
|
|
102
|
+
b = codec.decode(codec.encode(bytes_arr))
|
|
103
|
+
assert np.array_equal(bytes_arr, b)
|
|
104
|
+
assert isinstance(b[0], bytes)
|
|
105
|
+
assert b[0] == b'foo'
|
|
106
|
+
# works for unicode array, round-trips unicode to unicode
|
|
107
|
+
b = codec.decode(codec.encode(unicode_arr))
|
|
108
|
+
assert np.array_equal(unicode_arr, b)
|
|
109
|
+
assert isinstance(b[0], str)
|
|
110
|
+
assert b[0] == 'foo'
|
|
111
|
+
|
|
112
|
+
# raw=True
|
|
113
|
+
codec = MsgPack(raw=True)
|
|
114
|
+
# works for bytes array, round-trips bytes to bytes
|
|
115
|
+
b = codec.decode(codec.encode(bytes_arr))
|
|
116
|
+
assert np.array_equal(bytes_arr, b)
|
|
117
|
+
assert isinstance(b[0], bytes)
|
|
118
|
+
assert b[0] == b'foo'
|
|
119
|
+
# broken for unicode array, round-trips unicode to bytes
|
|
120
|
+
b = codec.decode(codec.encode(unicode_arr))
|
|
121
|
+
assert not np.array_equal(unicode_arr, b)
|
|
122
|
+
assert isinstance(b[0], bytes)
|
|
123
|
+
assert b[0] == b'foo'
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from numcodecs.ndarray_like import DType, FlagsObj, NDArrayLike
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.mark.parametrize("module", ["numpy", "cupy"])
|
|
7
|
+
def test_is_ndarray_like(module):
|
|
8
|
+
m = pytest.importorskip(module)
|
|
9
|
+
a = m.arange(10)
|
|
10
|
+
assert isinstance(a, NDArrayLike)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_is_not_ndarray_like():
|
|
14
|
+
assert not isinstance([1, 2, 3], NDArrayLike)
|
|
15
|
+
assert not isinstance(b"1,2,3", NDArrayLike)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.mark.parametrize("module", ["numpy", "cupy"])
|
|
19
|
+
def test_is_dtype_like(module):
|
|
20
|
+
m = pytest.importorskip(module)
|
|
21
|
+
d = m.dtype("u8")
|
|
22
|
+
assert isinstance(d, DType)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_is_not_dtype_like():
|
|
26
|
+
assert not isinstance([1, 2, 3], DType)
|
|
27
|
+
assert not isinstance(b"1,2,3", DType)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.mark.parametrize("module", ["numpy", "cupy"])
|
|
31
|
+
def test_is_flags_like(module):
|
|
32
|
+
m = pytest.importorskip(module)
|
|
33
|
+
d = m.arange(10).flags
|
|
34
|
+
assert isinstance(d, FlagsObj)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_is_not_flags_like():
|
|
38
|
+
assert not isinstance([1, 2, 3], FlagsObj)
|
|
39
|
+
assert not isinstance(b"1,2,3", FlagsObj)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@pytest.mark.parametrize("module", ["numpy", "cupy"])
|
|
43
|
+
def test_cached_isinstance_check(module):
|
|
44
|
+
m = pytest.importorskip(module)
|
|
45
|
+
a = m.arange(10)
|
|
46
|
+
assert isinstance(a, NDArrayLike)
|
|
47
|
+
assert not isinstance(a, DType)
|
|
48
|
+
assert not isinstance(a, FlagsObj)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from numcodecs.packbits import PackBits
|
|
4
|
+
from numcodecs.tests.common import (
|
|
5
|
+
check_backwards_compatibility,
|
|
6
|
+
check_config,
|
|
7
|
+
check_encode_decode,
|
|
8
|
+
check_repr,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
arrays = [
|
|
12
|
+
np.random.randint(0, 2, size=1000, dtype=bool),
|
|
13
|
+
np.random.randint(0, 2, size=(100, 10), dtype=bool),
|
|
14
|
+
np.random.randint(0, 2, size=(10, 10, 10), dtype=bool),
|
|
15
|
+
np.random.randint(0, 2, size=1000, dtype=bool).reshape(10, 10, 10, order='F'),
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_encode_decode():
|
|
20
|
+
codec = PackBits()
|
|
21
|
+
for arr in arrays:
|
|
22
|
+
check_encode_decode(arr, codec)
|
|
23
|
+
# check different number of left-over bits
|
|
24
|
+
arr = np.random.randint(0, 2, size=1000, dtype=bool)
|
|
25
|
+
for size in list(range(1, 17)):
|
|
26
|
+
check_encode_decode(arr[:size], codec)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_config():
|
|
30
|
+
codec = PackBits()
|
|
31
|
+
check_config(codec)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_repr():
|
|
35
|
+
check_repr("PackBits()")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_backwards_compatibility():
|
|
39
|
+
check_backwards_compatibility(PackBits.codec_id, arrays, [PackBits()])
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from numcodecs.pcodec import PCodec
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
# initializing codec triggers ImportError
|
|
8
|
+
PCodec()
|
|
9
|
+
except ImportError: # pragma: no cover
|
|
10
|
+
pytest.skip("pcodec not available", allow_module_level=True)
|
|
11
|
+
|
|
12
|
+
from numcodecs.tests.common import (
|
|
13
|
+
check_backwards_compatibility,
|
|
14
|
+
check_config,
|
|
15
|
+
check_encode_decode_array_to_bytes,
|
|
16
|
+
check_err_decode_object_buffer,
|
|
17
|
+
check_err_encode_object_buffer,
|
|
18
|
+
check_repr,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
codecs = [
|
|
22
|
+
PCodec(),
|
|
23
|
+
PCodec(level=1),
|
|
24
|
+
PCodec(level=5),
|
|
25
|
+
PCodec(level=9),
|
|
26
|
+
PCodec(mode_spec='classic'),
|
|
27
|
+
PCodec(equal_pages_up_to=300),
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# mix of dtypes: integer, float
|
|
32
|
+
# mix of shapes: 1D, 2D
|
|
33
|
+
# mix of orders: C, F
|
|
34
|
+
arrays = [
|
|
35
|
+
np.arange(1000, dtype="u4"),
|
|
36
|
+
np.arange(1000, dtype="u8"),
|
|
37
|
+
np.arange(1000, dtype="i4"),
|
|
38
|
+
np.arange(1000, dtype="i8"),
|
|
39
|
+
np.linspace(1000, 1001, 1000, dtype="f4"),
|
|
40
|
+
np.linspace(1000, 1001, 1000, dtype="f8"),
|
|
41
|
+
np.random.normal(loc=1000, scale=1, size=(100, 10)),
|
|
42
|
+
np.asfortranarray(np.random.normal(loc=1000, scale=1, size=(100, 10))),
|
|
43
|
+
np.random.randint(0, 2**60, size=1000, dtype="u8"),
|
|
44
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8"),
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@pytest.mark.parametrize("arr", arrays)
|
|
49
|
+
@pytest.mark.parametrize("codec", codecs)
|
|
50
|
+
def test_encode_decode(arr, codec):
|
|
51
|
+
check_encode_decode_array_to_bytes(arr, codec)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_config():
|
|
55
|
+
codec = PCodec(level=3)
|
|
56
|
+
check_config(codec)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_invalid_config_error():
|
|
60
|
+
with pytest.raises(ValueError):
|
|
61
|
+
codec = PCodec(mode_spec='bogus')
|
|
62
|
+
check_encode_decode_array_to_bytes(arrays[0], codec)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_repr():
|
|
66
|
+
check_repr(
|
|
67
|
+
"PCodec(delta_encoding_order=None, equal_pages_up_to=262144, level=3, mode_spec='auto')"
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_backwards_compatibility():
|
|
72
|
+
check_backwards_compatibility(PCodec.codec_id, arrays, codecs)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_err_decode_object_buffer():
|
|
76
|
+
check_err_decode_object_buffer(PCodec())
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_err_encode_object_buffer():
|
|
80
|
+
check_err_encode_object_buffer(PCodec())
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from numcodecs.pickles import Pickle
|
|
8
|
+
from numcodecs.tests.common import (
|
|
9
|
+
check_backwards_compatibility,
|
|
10
|
+
check_config,
|
|
11
|
+
check_encode_decode_array,
|
|
12
|
+
check_repr,
|
|
13
|
+
greetings,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
codecs = [Pickle(protocol=i) for i in range(5)]
|
|
17
|
+
|
|
18
|
+
# object array with strings
|
|
19
|
+
# object array with mix strings / nans
|
|
20
|
+
# object array with mix of string, int, float
|
|
21
|
+
# ...
|
|
22
|
+
arrays = [
|
|
23
|
+
np.array(['foo', 'bar', 'baz'] * 300, dtype=object),
|
|
24
|
+
np.array([['foo', 'bar', np.nan]] * 300, dtype=object),
|
|
25
|
+
np.array(['foo', 1.0, 2] * 300, dtype=object),
|
|
26
|
+
np.arange(1000, dtype='i4'),
|
|
27
|
+
np.array(['foo', 'bar', 'baz'] * 300),
|
|
28
|
+
np.array(['foo', ['bar', 1.0, 2], {'a': 'b', 'c': 42}] * 300, dtype=object),
|
|
29
|
+
np.array(greetings * 100),
|
|
30
|
+
np.array(greetings * 100, dtype=object),
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_encode_decode():
|
|
35
|
+
for arr, codec in itertools.product(arrays, codecs):
|
|
36
|
+
check_encode_decode_array(arr, codec)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_config():
|
|
40
|
+
codec = Pickle(protocol=-1)
|
|
41
|
+
check_config(codec)
|
|
42
|
+
for codec in codecs:
|
|
43
|
+
check_config(codec)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_repr():
|
|
47
|
+
check_repr("Pickle(protocol=-1)")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# Details on xfail
|
|
51
|
+
# https://stackoverflow.com/questions/58194852/modulenotfounderror-no-module-named-numpy-core-multiarray-r
|
|
52
|
+
@pytest.mark.skipif(sys.byteorder != "little", reason="Pickle does not restore byte orders")
|
|
53
|
+
@pytest.mark.xfail(
|
|
54
|
+
sys.platform == "win32",
|
|
55
|
+
reason=(
|
|
56
|
+
"Pickle fails to read w/ Windows carriage return "
|
|
57
|
+
"( https://github.com/zarr-developers/numcodecs/issues/271 )"
|
|
58
|
+
),
|
|
59
|
+
)
|
|
60
|
+
def test_backwards_compatibility():
|
|
61
|
+
check_backwards_compatibility(Pickle.codec_id, arrays, codecs)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pytest
|
|
5
|
+
from numpy.testing import assert_array_almost_equal, assert_array_equal
|
|
6
|
+
|
|
7
|
+
from numcodecs.quantize import Quantize
|
|
8
|
+
from numcodecs.tests.common import (
|
|
9
|
+
check_backwards_compatibility,
|
|
10
|
+
check_config,
|
|
11
|
+
check_encode_decode,
|
|
12
|
+
check_repr,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
arrays = [
|
|
16
|
+
np.linspace(100, 200, 1000, dtype='<f8'),
|
|
17
|
+
np.random.normal(loc=0, scale=1, size=1000).astype('<f8'),
|
|
18
|
+
np.linspace(100, 200, 1000, dtype='<f8').reshape(100, 10),
|
|
19
|
+
np.linspace(100, 200, 1000, dtype='<f8').reshape(100, 10, order='F'),
|
|
20
|
+
np.linspace(100, 200, 1000, dtype='<f8').reshape(10, 10, 10),
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
codecs = [
|
|
25
|
+
Quantize(digits=-1, dtype='<f8', astype='<f2'),
|
|
26
|
+
Quantize(digits=0, dtype='<f8', astype='<f2'),
|
|
27
|
+
Quantize(digits=1, dtype='<f8', astype='<f2'),
|
|
28
|
+
Quantize(digits=5, dtype='<f8', astype='<f4'),
|
|
29
|
+
Quantize(digits=12, dtype='<f8', astype='<f8'),
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_encode_decode():
|
|
34
|
+
for arr, codec in itertools.product(arrays, codecs):
|
|
35
|
+
check_encode_decode(arr, codec, precision=codec.digits)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_encode():
|
|
39
|
+
for arr, codec in itertools.product(arrays, codecs):
|
|
40
|
+
if arr.flags.f_contiguous:
|
|
41
|
+
order = 'F'
|
|
42
|
+
else:
|
|
43
|
+
order = 'C'
|
|
44
|
+
enc = codec.encode(arr).reshape(arr.shape, order=order)
|
|
45
|
+
assert_array_almost_equal(arr, enc, decimal=codec.digits)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_decode():
|
|
49
|
+
# decode is a no-op
|
|
50
|
+
for arr, codec in itertools.product(arrays, codecs):
|
|
51
|
+
enc = codec.encode(arr)
|
|
52
|
+
dec = codec.decode(enc)
|
|
53
|
+
assert_array_equal(enc, dec)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_config():
|
|
57
|
+
for codec in codecs:
|
|
58
|
+
check_config(codec)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_repr():
|
|
62
|
+
check_repr("Quantize(digits=2, dtype='<f8', astype='<f2')")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_errors():
|
|
66
|
+
with pytest.raises(ValueError):
|
|
67
|
+
Quantize(digits=2, dtype='i4')
|
|
68
|
+
with pytest.raises(ValueError):
|
|
69
|
+
Quantize(digits=2, dtype=object)
|
|
70
|
+
with pytest.raises(ValueError):
|
|
71
|
+
Quantize(digits=2, dtype='f8', astype=object)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_backwards_compatibility():
|
|
75
|
+
precision = [codec.digits for codec in codecs]
|
|
76
|
+
check_backwards_compatibility(Quantize.codec_id, arrays, codecs, precision=precision)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import numcodecs
|
|
6
|
+
from numcodecs.registry import get_codec
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_registry_errors():
|
|
10
|
+
with pytest.raises(ValueError):
|
|
11
|
+
get_codec({'id': 'foo'})
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_get_codec_argument():
|
|
15
|
+
# Check that get_codec doesn't modify its argument.
|
|
16
|
+
arg = {"id": "json2"}
|
|
17
|
+
before = dict(arg)
|
|
18
|
+
get_codec(arg)
|
|
19
|
+
assert before == arg
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_all_classes_registered():
|
|
23
|
+
"""
|
|
24
|
+
find all Codec subclasses in this repository and check that they
|
|
25
|
+
have been registered.
|
|
26
|
+
|
|
27
|
+
see #346 for more info
|
|
28
|
+
"""
|
|
29
|
+
missing = set()
|
|
30
|
+
for _name, submod in inspect.getmembers(numcodecs, inspect.ismodule):
|
|
31
|
+
for _name, obj in inspect.getmembers(submod):
|
|
32
|
+
if inspect.isclass(obj):
|
|
33
|
+
if issubclass(obj, numcodecs.abc.Codec):
|
|
34
|
+
if obj.codec_id not in numcodecs.registry.codec_registry:
|
|
35
|
+
missing.add(obj.codec_id)
|
|
36
|
+
|
|
37
|
+
# remove `None``
|
|
38
|
+
missing.remove(None)
|
|
39
|
+
if missing:
|
|
40
|
+
raise Exception(f"these codecs are missing: {missing}") # pragma: no cover
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
from multiprocessing import Pool
|
|
2
|
+
from multiprocessing.pool import ThreadPool
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
from numcodecs.shuffle import Shuffle
|
|
9
|
+
except ImportError: # pragma: no cover
|
|
10
|
+
pytest.skip("numcodecs.shuffle not available", allow_module_level=True)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
from numcodecs.tests.common import (
|
|
14
|
+
check_backwards_compatibility,
|
|
15
|
+
check_config,
|
|
16
|
+
check_encode_decode,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
codecs = [
|
|
20
|
+
Shuffle(),
|
|
21
|
+
Shuffle(elementsize=0),
|
|
22
|
+
Shuffle(elementsize=4),
|
|
23
|
+
Shuffle(elementsize=8),
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# mix of dtypes: integer, float, bool, string
|
|
28
|
+
# mix of shapes: 1D, 2D, 3D
|
|
29
|
+
# mix of orders: C, F
|
|
30
|
+
arrays = [
|
|
31
|
+
np.arange(1000, dtype='i4'),
|
|
32
|
+
np.linspace(1000, 1001, 1000, dtype='f8'),
|
|
33
|
+
np.random.normal(loc=1000, scale=1, size=(100, 10)),
|
|
34
|
+
np.random.randint(0, 2, size=1000, dtype=bool).reshape(100, 10, order='F'),
|
|
35
|
+
np.random.choice([b'a', b'bb', b'ccc'], size=1000).reshape(10, 10, 10),
|
|
36
|
+
np.random.randint(0, 2**60, size=1000, dtype='u8').view('M8[ns]'),
|
|
37
|
+
np.random.randint(0, 2**60, size=1000, dtype='u8').view('m8[ns]'),
|
|
38
|
+
np.random.randint(0, 2**25, size=1000, dtype='u8').view('M8[m]'),
|
|
39
|
+
np.random.randint(0, 2**25, size=1000, dtype='u8').view('m8[m]'),
|
|
40
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[ns]'),
|
|
41
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[ns]'),
|
|
42
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[m]'),
|
|
43
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[m]'),
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.mark.parametrize('array', arrays)
|
|
48
|
+
@pytest.mark.parametrize('codec', codecs)
|
|
49
|
+
def test_encode_decode(array, codec):
|
|
50
|
+
check_encode_decode(array, codec)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_config():
|
|
54
|
+
codec = Shuffle()
|
|
55
|
+
check_config(codec)
|
|
56
|
+
codec = Shuffle(elementsize=8)
|
|
57
|
+
check_config(codec)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_repr():
|
|
61
|
+
expect = "Shuffle(elementsize=0)"
|
|
62
|
+
actual = repr(Shuffle(elementsize=0))
|
|
63
|
+
assert expect == actual
|
|
64
|
+
expect = "Shuffle(elementsize=4)"
|
|
65
|
+
actual = repr(Shuffle(elementsize=4))
|
|
66
|
+
assert expect == actual
|
|
67
|
+
expect = "Shuffle(elementsize=8)"
|
|
68
|
+
actual = repr(Shuffle(elementsize=8))
|
|
69
|
+
assert expect == actual
|
|
70
|
+
expect = "Shuffle(elementsize=16)"
|
|
71
|
+
actual = repr(Shuffle(elementsize=16))
|
|
72
|
+
assert expect == actual
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_eq():
|
|
76
|
+
assert Shuffle() == Shuffle()
|
|
77
|
+
assert Shuffle(elementsize=16) != Shuffle()
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _encode_worker(data):
|
|
81
|
+
compressor = Shuffle()
|
|
82
|
+
enc = compressor.encode(data)
|
|
83
|
+
return enc
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _decode_worker(enc):
|
|
87
|
+
compressor = Shuffle()
|
|
88
|
+
data = compressor.decode(enc)
|
|
89
|
+
return data
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@pytest.mark.parametrize('pool', (Pool, ThreadPool))
|
|
93
|
+
def test_multiprocessing(pool):
|
|
94
|
+
data = np.arange(1000000)
|
|
95
|
+
enc = _encode_worker(data)
|
|
96
|
+
|
|
97
|
+
pool = pool(5)
|
|
98
|
+
|
|
99
|
+
# test with process pool and thread pool
|
|
100
|
+
|
|
101
|
+
# test encoding
|
|
102
|
+
enc_results = pool.map(_encode_worker, [data] * 5)
|
|
103
|
+
assert all(len(enc) == len(e) for e in enc_results)
|
|
104
|
+
|
|
105
|
+
# test decoding
|
|
106
|
+
dec_results = pool.map(_decode_worker, [enc] * 5)
|
|
107
|
+
assert all(data.nbytes == len(d) for d in dec_results)
|
|
108
|
+
|
|
109
|
+
# tidy up
|
|
110
|
+
pool.close()
|
|
111
|
+
pool.join()
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_backwards_compatibility():
|
|
115
|
+
check_backwards_compatibility(Shuffle.codec_id, arrays, codecs)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# def test_err_decode_object_buffer():
|
|
119
|
+
# check_err_decode_object_buffer(Shuffle())
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# def test_err_encode_object_buffer():
|
|
123
|
+
# check_err_encode_object_buffer(Shuffle())
|
|
124
|
+
|
|
125
|
+
# def test_decompression_error_handling():
|
|
126
|
+
# for codec in codecs:
|
|
127
|
+
# with pytest.raises(RuntimeError):
|
|
128
|
+
# codec.decode(bytearray())
|
|
129
|
+
# with pytest.raises(RuntimeError):
|
|
130
|
+
# codec.decode(bytearray(0))
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_expected_result():
|
|
134
|
+
# If the input is treated as a 2D byte array, with shape (size of element, number of elements),
|
|
135
|
+
# the shuffle is essentially a transpose. This can be made more apparent by using an array of
|
|
136
|
+
# big-endian integers, as below.
|
|
137
|
+
arr = np.array(
|
|
138
|
+
[
|
|
139
|
+
0x0001020304050607,
|
|
140
|
+
0x08090A0B0C0D0E0F,
|
|
141
|
+
0x1011121314151617,
|
|
142
|
+
0x18191A1B1C1D1E1F,
|
|
143
|
+
],
|
|
144
|
+
dtype='>u8',
|
|
145
|
+
)
|
|
146
|
+
expected = np.array(
|
|
147
|
+
[
|
|
148
|
+
0x00081018,
|
|
149
|
+
0x01091119,
|
|
150
|
+
0x020A121A,
|
|
151
|
+
0x030B131B,
|
|
152
|
+
0x040C141C,
|
|
153
|
+
0x050D151D,
|
|
154
|
+
0x060E161E,
|
|
155
|
+
0x070F171F,
|
|
156
|
+
],
|
|
157
|
+
dtype='u4',
|
|
158
|
+
)
|
|
159
|
+
codec = Shuffle(elementsize=arr.data.itemsize)
|
|
160
|
+
enc = codec.encode(arr)
|
|
161
|
+
np.testing.assert_array_equal(np.frombuffer(enc.data, '>u4'), expected)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def test_incompatible_elementsize():
|
|
165
|
+
with pytest.raises(ValueError):
|
|
166
|
+
arr = np.arange(1001, dtype='u1')
|
|
167
|
+
codec = Shuffle(elementsize=4)
|
|
168
|
+
codec.encode(arr)
|