Skip to content

Commit d16d1ea

Browse files
halehawkjakirkham
andauthored
numcodecs.zfpy is ready (#229)
* added zfp compressor * modified zfp in setup.py for new zfp054 directory * changed print statement to raise,also changed zfp source path * added set_stride, changed zfp source path * added zfp source as a submodule * removed zfp source as a submodule * added zfp module * added zfp docs * used zfp submodule and define type by _type * removed blanked lines * added white space after mode * modified comments to meet numpy docstring * format setup.py * added zfp.c * add path to bitstream.h * updated include path * update zfp.c with include path * changed include path again * Removed zfp submodule * Removed zfp_extension * Remove test_zfp.py * added zfp.py * removed zfp.py * added zfpy.py * add pip install zfpy * add pip install modified * add pip install modified 2 * add pip install modified 3 * add zfpy.py * add zfpy in requirements_dev * add zfpy finxture * add zfpy with index-url * remove zfp.rst * get 100% coverage * change for coverage * change for PEP 8 * add ensure_contiguous_ndarray(buf) * skip tests at py38 and osx * fixed format issue * skip tests at py38 * remove variable comp_arr * skip test on darwin * remove extra blank line * removed import sys * removed zfp.pyx * change zfpy repr * change the zfpy repr test * use zfpy at PyPI * update zfpy in release.rst * updating submodule to latest * Revert "updating submodule to latest" This reverts commit 0d5e320. * Revert "Revert "updating submodule to latest"" This reverts commit 0eab0ff. * Revert "Revert "Revert "updating submodule to latest""" This reverts commit 2f4fe41. * update c-blosc to 1.18.1 * Update release.rst * Revert unrelated C file changes * Use `pytest.skip` to skip testing * Run `black` on zfpy * Update requirements_rtfd.txt * Update requirements_dev.txt * Update requirements_dev.txt * Update requirements_rtfd.txt * Update requirements_rtfd.txt * Update requirements_dev.txt * Update conf.py * Update conf.py * Update conf.py * Update conf.py * Update conf.py Co-authored-by: John Kirkham <[email protected]>
1 parent f946d7d commit d16d1ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+252
-5
lines changed

.github/workflows/ci-osx.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ jobs:
4646
run: |
4747
conda activate env
4848
pytest -v --pyargs numcodecs
49+

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __getattr__(cls, name):
2424
return Mock()
2525

2626

27-
MOCK_MODULES = ['msgpack']
27+
MOCK_MODULES = ['msgpack', 'zfpy']
2828
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
2929

3030

docs/index.rst

Lines changed: 1 addition & 0 deletions

docs/release.rst

Lines changed: 10 additions & 0 deletions

docs/zfpy.rst

Lines changed: 11 additions & 0 deletions

fixture/zfpy/array.00.npy

4.03 KB
Binary file not shown.

fixture/zfpy/array.01.npy

7.94 KB
Binary file not shown.

fixture/zfpy/array.02.npy

7.94 KB
Binary file not shown.

fixture/zfpy/array.03.npy

7.94 KB
Binary file not shown.

fixture/zfpy/array.04.npy

7.94 KB
Binary file not shown.

fixture/zfpy/array.05.npy

7.94 KB
Binary file not shown.

fixture/zfpy/array.06.npy

4.03 KB
Binary file not shown.

fixture/zfpy/array.07.npy

7.94 KB
Binary file not shown.

fixture/zfpy/codec.00/config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compression_kwargs": {
3+
"rate": -1
4+
},
5+
"id": "zfpy",
6+
"mode": 2,
7+
"precision": -1,
8+
"rate": -1,
9+
"tolerance": -1
10+
}

fixture/zfpy/codec.00/encoded.00.dat

2.31 KB
Binary file not shown.

fixture/zfpy/codec.00/encoded.01.dat

4.98 KB
Binary file not shown.

fixture/zfpy/codec.00/encoded.02.dat

6.77 KB
Binary file not shown.

fixture/zfpy/codec.00/encoded.03.dat

6.78 KB
Binary file not shown.

fixture/zfpy/codec.00/encoded.04.dat

6.78 KB
Binary file not shown.

fixture/zfpy/codec.00/encoded.05.dat

6.77 KB
Binary file not shown.

fixture/zfpy/codec.00/encoded.06.dat

2.51 KB
Binary file not shown.

fixture/zfpy/codec.00/encoded.07.dat

4.49 KB
Binary file not shown.

fixture/zfpy/codec.01/config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compression_kwargs": {
3+
"tolerance": -1
4+
},
5+
"id": "zfpy",
6+
"mode": 4,
7+
"precision": -1,
8+
"rate": -1,
9+
"tolerance": -1
10+
}

fixture/zfpy/codec.01/encoded.00.dat

2.31 KB
Binary file not shown.

fixture/zfpy/codec.01/encoded.01.dat

4.98 KB
Binary file not shown.

fixture/zfpy/codec.01/encoded.02.dat

6.77 KB
Binary file not shown.

fixture/zfpy/codec.01/encoded.03.dat

6.78 KB
Binary file not shown.

fixture/zfpy/codec.01/encoded.04.dat

6.78 KB
Binary file not shown.

fixture/zfpy/codec.01/encoded.05.dat

6.77 KB
Binary file not shown.

fixture/zfpy/codec.01/encoded.06.dat

2.51 KB
Binary file not shown.

fixture/zfpy/codec.01/encoded.07.dat

4.49 KB
Binary file not shown.

fixture/zfpy/codec.02/config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compression_kwargs": {
3+
"tolerance": -1
4+
},
5+
"id": "zfpy",
6+
"mode": 4,
7+
"precision": -1,
8+
"rate": -1,
9+
"tolerance": -1
10+
}

fixture/zfpy/codec.02/encoded.00.dat

2.31 KB
Binary file not shown.

fixture/zfpy/codec.02/encoded.01.dat

4.98 KB
Binary file not shown.

fixture/zfpy/codec.02/encoded.02.dat

6.77 KB
Binary file not shown.

fixture/zfpy/codec.02/encoded.03.dat

6.78 KB
Binary file not shown.

fixture/zfpy/codec.02/encoded.04.dat

6.78 KB
Binary file not shown.

fixture/zfpy/codec.02/encoded.05.dat

6.77 KB
Binary file not shown.

fixture/zfpy/codec.02/encoded.06.dat

2.51 KB
Binary file not shown.

fixture/zfpy/codec.02/encoded.07.dat

4.49 KB
Binary file not shown.

fixture/zfpy/codec.03/config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compression_kwargs": {
3+
"precision": -1
4+
},
5+
"id": "zfpy",
6+
"mode": 3,
7+
"precision": -1,
8+
"rate": -1,
9+
"tolerance": -1
10+
}

fixture/zfpy/codec.03/encoded.00.dat

2.31 KB
Binary file not shown.

fixture/zfpy/codec.03/encoded.01.dat

4.98 KB
Binary file not shown.

fixture/zfpy/codec.03/encoded.02.dat

6.77 KB
Binary file not shown.

fixture/zfpy/codec.03/encoded.03.dat

6.78 KB
Binary file not shown.

fixture/zfpy/codec.03/encoded.04.dat

6.78 KB
Binary file not shown.

fixture/zfpy/codec.03/encoded.05.dat

6.77 KB
Binary file not shown.

fixture/zfpy/codec.03/encoded.06.dat

2.51 KB
Binary file not shown.

fixture/zfpy/codec.03/encoded.07.dat

4.49 KB
Binary file not shown.

numcodecs/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
transformation codecs for use in data storage and communication
44
applications. These include:
55
6-
* Compression codecs, e.g., Zlib, BZ2, LZMA and Blosc.
6+
* Compression codecs, e.g., Zlib, BZ2, LZMA, ZFPY and Blosc.
77
* Pre-compression filters, e.g., Delta, Quantize, FixedScaleOffset,
88
PackBits, Categorize.
99
* Integrity checks, e.g., CRC32, Adler32.
@@ -16,7 +16,6 @@
1616
<https://github.com/alimanfoo/numcodecs/issues>`_.
1717
1818
"""
19-
2019
import multiprocessing
2120
import atexit
2221

@@ -68,6 +67,12 @@
6867
except ImportError: # pragma: no cover
6968
pass
7069

70+
try:
71+
from numcodecs.zfpy import ZFPY
72+
register_codec(ZFPY)
73+
except ImportError: # pragma: no cover
74+
pass
75+
7176
from numcodecs.astype import AsType
7277
register_codec(AsType)
7378

numcodecs/tests/common.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,10 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref
268268

269269
# file with codec configuration information
270270
codec_fn = os.path.join(codec_dir, 'config.json')
271-
272271
# one time save config
273272
if not os.path.exists(codec_fn): # pragma: no cover
274273
with open(codec_fn, mode='w') as cf:
275274
_json.dump(codec.get_config(), cf, sort_keys=True, indent=4)
276-
277275
# load config and compare with expectation
278276
with open(codec_fn, mode='r') as cf:
279277
config = _json.load(cf)

numcodecs/tests/test_zfpy.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import pytest
2+
3+
4+
import numpy as np
5+
6+
7+
try:
8+
# noinspection PyProtectedMember
9+
from numcodecs.zfpy import ZFPY, _zfpy
10+
except ImportError: # pragma: no cover
11+
pytest.skip("ZFPY not available", allow_module_level=True)
12+
13+
14+
from numcodecs.tests.common import (
15+
check_encode_decode_array,
16+
check_config,
17+
check_repr,
18+
check_backwards_compatibility,
19+
check_err_decode_object_buffer,
20+
check_err_encode_object_buffer,
21+
)
22+
23+
24+
codecs = [
25+
ZFPY(mode=_zfpy.mode_fixed_rate, rate=-1),
26+
ZFPY(),
27+
ZFPY(mode=_zfpy.mode_fixed_accuracy, tolerance=-1),
28+
ZFPY(mode=_zfpy.mode_fixed_precision, precision=-1),
29+
]
30+
31+
32+
# mix of dtypes: integer, float, bool, string
33+
# mix of shapes: 1D, 2D, 3D
34+
# mix of orders: C, F
35+
arrays = [
36+
np.linspace(1000, 1001, 1000, dtype="f4"),
37+
np.linspace(1000, 1001, 1000, dtype="f8"),
38+
np.random.normal(loc=1000, scale=1, size=(100, 10)),
39+
np.random.normal(loc=1000, scale=1, size=(10, 10, 10)),
40+
np.random.normal(loc=1000, scale=1, size=(2, 5, 10, 10)),
41+
np.asfortranarray(np.random.normal(loc=1000, scale=1, size=(5, 10, 20))),
42+
np.random.randint(-(2 ** 31), -(2 ** 31) + 20, size=1000, dtype="i4").reshape(
43+
100, 10
44+
),
45+
np.random.randint(-(2 ** 63), -(2 ** 63) + 20, size=1000, dtype="i8").reshape(
46+
10, 10, 10
47+
),
48+
]
49+
50+
51+
def test_encode_decode():
52+
for arr in arrays:
53+
if arr.dtype == np.int32 or arr.dtype == np.int64:
54+
codec = [codecs[-1]]
55+
else:
56+
codec = codecs
57+
for code in codec:
58+
check_encode_decode_array(arr, code)
59+
60+
61+
def test_config():
62+
for codec in codecs:
63+
check_config(codec)
64+
65+
66+
def test_repr():
67+
check_repr("ZFPY(mode=4, tolerance=0.001, rate=-1, precision=-1)")
68+
69+
70+
def test_backwards_compatibility():
71+
for i, code in enumerate(codecs):
72+
if code.mode == _zfpy.mode_fixed_rate:
73+
codec = [code]
74+
check_backwards_compatibility(ZFPY.codec_id, arrays, codec)
75+
else:
76+
check_backwards_compatibility(
77+
ZFPY.codec_id, arrays[: len(arrays) - 2], codecs
78+
)
79+
80+
81+
def test_err_decode_object_buffer():
82+
check_err_decode_object_buffer(ZFPY())
83+
84+
85+
def test_err_encode_object_buffer():
86+
check_err_encode_object_buffer(ZFPY())

numcodecs/zfpy.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
_zfpy = None
2+
try:
3+
import zfpy as _zfpy
4+
except ImportError: # pragma: no cover
5+
pass
6+
7+
8+
if _zfpy:
9+
10+
from .abc import Codec
11+
from .compat import ndarray_copy, ensure_contiguous_ndarray, ensure_bytes
12+
13+
# noinspection PyShadowingBuiltins
14+
class ZFPY(Codec):
15+
"""Codec providing compression using zfpy via the Python standard
16+
library.
17+
18+
Parameters
19+
----------
20+
mode : integer
21+
One of the zfpy mode choice, e.g., ``zfpy.mode_fixed_accuracy``.
22+
tolerance : double, optional
23+
A double-precision number, specifying the compression accuracy needed.
24+
rate : double, optional
25+
A double-precision number, specifying the compression rate needed.
26+
precision : int, optional
27+
A integer number, specifying the compression precision needed.
28+
29+
"""
30+
31+
codec_id = "zfpy"
32+
33+
def __init__(
34+
self,
35+
mode=_zfpy.mode_fixed_accuracy,
36+
tolerance=-1,
37+
rate=-1,
38+
precision=-1,
39+
compression_kwargs=None,
40+
):
41+
self.mode = mode
42+
if mode == _zfpy.mode_fixed_accuracy:
43+
self.compression_kwargs = {"tolerance": tolerance}
44+
elif mode == _zfpy.mode_fixed_rate:
45+
self.compression_kwargs = {"rate": rate}
46+
elif mode == _zfpy.mode_fixed_precision:
47+
self.compression_kwargs = {"precision": precision}
48+
else:
49+
pass
50+
51+
self.tolerance = tolerance
52+
self.rate = rate
53+
self.precision = precision
54+
55+
def encode(self, buf):
56+
57+
# normalise inputs
58+
buf = ensure_contiguous_ndarray(buf)
59+
60+
# do compression
61+
return _zfpy.compress_numpy(
62+
buf, write_header=True, **self.compression_kwargs
63+
)
64+
65+
def decode(self, buf, out=None):
66+
67+
# normalise inputs
68+
buf = ensure_bytes(buf)
69+
if out is not None:
70+
out = ensure_contiguous_ndarray(out)
71+
72+
# do decompression
73+
dec = _zfpy.decompress_numpy(buf)
74+
75+
# handle destination
76+
if out is not None:
77+
return ndarray_copy(dec, out)
78+
else:
79+
return dec
80+
81+
def __repr__(self):
82+
r = "%s(mode=%r, tolerance=%s, rate=%s, precision=%s)" % (
83+
type(self).__name__,
84+
self.mode,
85+
self.tolerance,
86+
self.rate,
87+
self.precision,
88+
)
89+
return r

requirements_dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Cython==0.29.21
22
msgpack==1.0.2
33
numpy==1.19.0
4+
zfpy==0.5.5; python_version < '3.9'
5+

requirements_rtfd.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ numpydoc
66
mock
77
numpy
88
cython
9+
zfpy==0.5.5; python_version < '3.9'

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def blosc_extension():
7676
if os.path.isdir(d)]
7777
include_dirs += [d for d in glob('c-blosc/internal-complibs/*/*')
7878
if os.path.isdir(d)]
79+
include_dirs += [d for d in glob('c-blosc/internal-complibs/*/*/*')
80+
if os.path.isdir(d)]
7981
define_macros += [('HAVE_LZ4', 1),
8082
('HAVE_SNAPPY', 1),
8183
('HAVE_ZLIB', 1),
@@ -315,6 +317,7 @@ def run_setup(with_extensions):
315317
if with_extensions:
316318
ext_modules = (blosc_extension() + zstd_extension() + lz4_extension() +
317319
compat_extension() + shuffle_extension() + vlen_extension())
320+
318321
cmdclass = dict(build_ext=ve_build_ext)
319322
else:
320323
ext_modules = []

0 commit comments

Comments
 (0)