-
Notifications
You must be signed in to change notification settings - Fork 97
numcodecs.zfpy is ready #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
80a571c
added zfp compressor
halehawk 50cfdb5
modified zfp in setup.py for new zfp054 directory
halehawk 8b40523
changed print statement to raise,also changed zfp source path
halehawk dbc2b64
Merge remote-tracking branch 'upstream/master'
halehawk 33de949
added set_stride, changed zfp source path
halehawk 035f90d
added zfp source as a submodule
halehawk 1adcf4b
removed zfp source as a submodule
halehawk a33e947
added zfp module
halehawk 6acb24d
added zfp docs
halehawk 812441a
used zfp submodule and define type by _type
halehawk 5972e09
removed blanked lines
halehawk 1a7c105
added white space after mode
halehawk 161cbca
modified comments to meet numpy docstring
halehawk d44f308
updated c-blosc
halehawk a1674da
format setup.py
halehawk 27676f4
added zfp.c
halehawk 785547f
add path to bitstream.h
halehawk f0361cb
updated include path
halehawk 8cfad3e
update zfp.c with include path
halehawk e205381
changed include path again
halehawk fce55da
Merge branch 'master' into master
halehawk fa33fa4
sync with latest numcodecs master
halehawk 4f90933
Removed zfp submodule
halehawk dc37e5d
Removed zfp_extension
halehawk 6ef6096
Remove test_zfp.py
halehawk fffc757
added zfp.py
halehawk fcf92fa
removed zfp.py
halehawk e896edf
added zfpy.py
halehawk ec63632
add pip install zfpy
halehawk 1bd37da
add pip install modified
halehawk ec3b548
add pip install modified 2
halehawk 58337ff
add pip install modified 3
halehawk eab0541
add zfpy.py
halehawk 9f508f1
add zfpy in requirements_dev
halehawk eba81c6
add zfpy finxture
halehawk 9d7ce65
add zfpy with index-url
halehawk 92826fc
remove zfp.rst
halehawk 2dd10db
get 100% coverage
halehawk 7e1fc71
change for coverage
halehawk 0ba8be0
change for PEP 8
halehawk 5c4029c
add ensure_contiguous_ndarray(buf)
halehawk baa2821
skip tests at py38 and osx
halehawk 548bad8
fixed format issue
halehawk 995dab5
skip tests at py38
halehawk b99da10
remove variable comp_arr
halehawk a96ae56
skip test on darwin
halehawk dca2c58
remove extra blank line
halehawk 01b0870
removed import sys
halehawk fbe0778
removed zfp.pyx
halehawk 0cd7622
change zfpy repr
halehawk 80249e0
change the zfpy repr test
halehawk 6cd85b7
Merge remote-tracking branch 'upstream/master' into zfpy
halehawk b2bbc4e
use zfpy at PyPI
halehawk dea4fdf
update zfpy in release.rst
halehawk a8ea612
Merge branch 'master' into zfpy
halehawk 6fcf53e
Merge branch 'master' into zfpy
halehawk 04ddd98
Merge branch 'master' into zfpy
halehawk 0d5e320
updating submodule to latest
halehawk 0eab0ff
Revert "updating submodule to latest"
halehawk 2f4fe41
Revert "Revert "updating submodule to latest""
halehawk 032b0dc
Revert "Revert "Revert "updating submodule to latest"""
halehawk 0321bf1
update c-blosc to 1.18.1
halehawk 1650d42
Merge branch 'master' into zfpy
halehawk 509b9a9
Merge branch 'master' into zfpy
halehawk 12108a0
Update release.rst
halehawk 2e6757f
Revert unrelated C file changes
jakirkham 7b45cf6
Use `pytest.skip` to skip testing
jakirkham 5c1cbcb
Run `black` on zfpy
jakirkham db76330
Merge branch 'master' into zfpy
halehawk e9c786c
Merge branch 'master' into zfpy
halehawk c34f99d
Merge branch 'master' into zfpy
halehawk a2fcb0f
Merge branch 'master' into zfpy
halehawk ce4be10
Update requirements_rtfd.txt
halehawk 3e6bd38
Update requirements_dev.txt
halehawk 97abde3
Update requirements_dev.txt
halehawk 3669bd5
Update requirements_rtfd.txt
halehawk d561587
Update requirements_rtfd.txt
halehawk c7b699a
Update requirements_dev.txt
halehawk 97848a0
Update conf.py
halehawk bd5d835
Update conf.py
halehawk fa34826
Update conf.py
halehawk 7e96469
Merge branch 'master' into zfpy
halehawk 0c44788
Update conf.py
halehawk 44dde11
Update conf.py
halehawk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,4 @@ jobs: | |
run: | | ||
conda activate env | ||
pytest -v --pyargs numcodecs | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ Contents | |
registry | ||
blosc | ||
lz4 | ||
zfpy | ||
zstd | ||
zlib | ||
gzip | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ZFPY | ||
==== | ||
.. automodule:: numcodecs.zfpy | ||
|
||
.. autoclass:: ZFPY | ||
|
||
.. autoattribute:: codec_id | ||
.. automethod:: encode | ||
.. automethod:: decode | ||
.. automethod:: get_config | ||
.. automethod:: from_config |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compression_kwargs": { | ||
"rate": -1 | ||
}, | ||
"id": "zfpy", | ||
"mode": 2, | ||
"precision": -1, | ||
"rate": -1, | ||
"tolerance": -1 | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compression_kwargs": { | ||
"tolerance": -1 | ||
}, | ||
"id": "zfpy", | ||
"mode": 4, | ||
"precision": -1, | ||
"rate": -1, | ||
"tolerance": -1 | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compression_kwargs": { | ||
"tolerance": -1 | ||
}, | ||
"id": "zfpy", | ||
"mode": 4, | ||
"precision": -1, | ||
"rate": -1, | ||
"tolerance": -1 | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compression_kwargs": { | ||
"precision": -1 | ||
}, | ||
"id": "zfpy", | ||
"mode": 3, | ||
"precision": -1, | ||
"rate": -1, | ||
"tolerance": -1 | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import pytest | ||
|
||
|
||
import numpy as np | ||
|
||
|
||
try: | ||
# noinspection PyProtectedMember | ||
from numcodecs.zfpy import ZFPY, _zfpy | ||
except ImportError: # pragma: no cover | ||
pytest.skip("ZFPY not available", allow_module_level=True) | ||
|
||
|
||
from numcodecs.tests.common import ( | ||
check_encode_decode_array, | ||
check_config, | ||
check_repr, | ||
check_backwards_compatibility, | ||
check_err_decode_object_buffer, | ||
check_err_encode_object_buffer, | ||
) | ||
|
||
|
||
codecs = [ | ||
ZFPY(mode=_zfpy.mode_fixed_rate, rate=-1), | ||
ZFPY(), | ||
ZFPY(mode=_zfpy.mode_fixed_accuracy, tolerance=-1), | ||
ZFPY(mode=_zfpy.mode_fixed_precision, precision=-1), | ||
] | ||
|
||
|
||
# mix of dtypes: integer, float, bool, string | ||
# mix of shapes: 1D, 2D, 3D | ||
# mix of orders: C, F | ||
arrays = [ | ||
np.linspace(1000, 1001, 1000, dtype="f4"), | ||
np.linspace(1000, 1001, 1000, dtype="f8"), | ||
np.random.normal(loc=1000, scale=1, size=(100, 10)), | ||
np.random.normal(loc=1000, scale=1, size=(10, 10, 10)), | ||
np.random.normal(loc=1000, scale=1, size=(2, 5, 10, 10)), | ||
np.asfortranarray(np.random.normal(loc=1000, scale=1, size=(5, 10, 20))), | ||
np.random.randint(-(2 ** 31), -(2 ** 31) + 20, size=1000, dtype="i4").reshape( | ||
100, 10 | ||
), | ||
np.random.randint(-(2 ** 63), -(2 ** 63) + 20, size=1000, dtype="i8").reshape( | ||
10, 10, 10 | ||
), | ||
] | ||
|
||
|
||
def test_encode_decode(): | ||
for arr in arrays: | ||
if arr.dtype == np.int32 or arr.dtype == np.int64: | ||
codec = [codecs[-1]] | ||
else: | ||
codec = codecs | ||
for code in codec: | ||
check_encode_decode_array(arr, code) | ||
|
||
|
||
def test_config(): | ||
for codec in codecs: | ||
check_config(codec) | ||
|
||
|
||
def test_repr(): | ||
check_repr("ZFPY(mode=4, tolerance=0.001, rate=-1, precision=-1)") | ||
|
||
|
||
def test_backwards_compatibility(): | ||
for i, code in enumerate(codecs): | ||
if code.mode == _zfpy.mode_fixed_rate: | ||
codec = [code] | ||
check_backwards_compatibility(ZFPY.codec_id, arrays, codec) | ||
else: | ||
check_backwards_compatibility( | ||
ZFPY.codec_id, arrays[: len(arrays) - 2], codecs | ||
) | ||
|
||
|
||
def test_err_decode_object_buffer(): | ||
check_err_decode_object_buffer(ZFPY()) | ||
|
||
|
||
def test_err_encode_object_buffer(): | ||
check_err_encode_object_buffer(ZFPY()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
_zfpy = None | ||
try: | ||
import zfpy as _zfpy | ||
except ImportError: # pragma: no cover | ||
pass | ||
|
||
|
||
if _zfpy: | ||
|
||
from .abc import Codec | ||
from .compat import ndarray_copy, ensure_contiguous_ndarray, ensure_bytes | ||
|
||
# noinspection PyShadowingBuiltins | ||
class ZFPY(Codec): | ||
"""Codec providing compression using zfpy via the Python standard | ||
library. | ||
|
||
Parameters | ||
---------- | ||
mode : integer | ||
One of the zfpy mode choice, e.g., ``zfpy.mode_fixed_accuracy``. | ||
tolerance : double, optional | ||
A double-precision number, specifying the compression accuracy needed. | ||
rate : double, optional | ||
A double-precision number, specifying the compression rate needed. | ||
precision : int, optional | ||
A integer number, specifying the compression precision needed. | ||
|
||
""" | ||
|
||
codec_id = "zfpy" | ||
|
||
def __init__( | ||
self, | ||
mode=_zfpy.mode_fixed_accuracy, | ||
tolerance=-1, | ||
rate=-1, | ||
precision=-1, | ||
compression_kwargs=None, | ||
): | ||
self.mode = mode | ||
if mode == _zfpy.mode_fixed_accuracy: | ||
self.compression_kwargs = {"tolerance": tolerance} | ||
elif mode == _zfpy.mode_fixed_rate: | ||
self.compression_kwargs = {"rate": rate} | ||
elif mode == _zfpy.mode_fixed_precision: | ||
self.compression_kwargs = {"precision": precision} | ||
else: | ||
pass | ||
|
||
self.tolerance = tolerance | ||
self.rate = rate | ||
self.precision = precision | ||
|
||
def encode(self, buf): | ||
|
||
# normalise inputs | ||
buf = ensure_contiguous_ndarray(buf) | ||
|
||
# do compression | ||
return _zfpy.compress_numpy( | ||
buf, write_header=True, **self.compression_kwargs | ||
) | ||
|
||
def decode(self, buf, out=None): | ||
|
||
# normalise inputs | ||
buf = ensure_bytes(buf) | ||
if out is not None: | ||
out = ensure_contiguous_ndarray(out) | ||
|
||
# do decompression | ||
dec = _zfpy.decompress_numpy(buf) | ||
halehawk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# handle destination | ||
if out is not None: | ||
return ndarray_copy(dec, out) | ||
else: | ||
return dec | ||
|
||
def __repr__(self): | ||
r = "%s(mode=%r, tolerance=%s, rate=%s, precision=%s)" % ( | ||
type(self).__name__, | ||
self.mode, | ||
self.tolerance, | ||
self.rate, | ||
self.precision, | ||
) | ||
return r | ||
halehawk marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
Cython==0.29.21 | ||
msgpack==1.0.2 | ||
numpy==1.19.0 | ||
zfpy==0.5.5; python_version < '3.9' | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ numpydoc | |
mock | ||
numpy | ||
cython | ||
zfpy==0.5.5; python_version < '3.9' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need
bytes
? This will copy the data unlikeensure_contiguous_ndarray
orensure_ndarray
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
John, can you clarify this. I am confused why the input to
decode
will be an array? The numcodecs API docs describebuf
as follows:Should we open an issue in zfpy to inquire whether they could accept an array instead of bytes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like zfpy could easily be modified to accept a buffer rather than bytes:
https://github.com/LLNL/zfp/blob/079c409fcb53de5a06fa4336972c04869e33c48d/python/zfpy.pyx#L331-L343
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am asking Peter for a py38 build on linux and windows. It may take a while to get it. In the mean time, can I skip py38 testing and osx testing? I cannot find a way to skip py38 testing for numcodecs.zfpy only. Do you know how to do it? @rabernat @jakirkham
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rabernat @halehawk,
ensure_ndarray
takes a view onto anything that is a new-style buffer and returns it as a NumPy array (also a new-style buffer). Though it is just the same compressed 1-Duint8
array of data. Mainly it acts as a type checker as it raises on anything that is not a new-style buffer. It also gives us something easier to manipulate. That said, we could cast it to amemoryview
after if you prefer. The main point isensure_ndarray
is basically free whereasensure_bytes
always copies (unless it is actually abytes
object). Would be better not to copy if we can avoid it both for performance and memory usage reasons.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conversation does not seem resolved. Have we decided to keep
ensure_bytes
? Have we discussed this choice with the zfp devs?