Skip to content
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

Add docstrings for compress/decompress. #34

Merged
merged 2 commits into from
Jul 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 76 additions & 4 deletions pyzfp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,37 @@ cdef zfp_field* init_field(np.ndarray indata):
raise ValueError("Invalid number of dimensions (valid: 1-4)")

def compress(indata, tolerance=None, precision=None, rate=None, parallel=True):
"""
Compress a numpy array using zfp.

Parameters
----------
indata : numpy.ndarray
The data to compress.
tolerance : float, optional
The tolerance for the compressed data.
This will use ZFP in fixed-accuracy mode.
https://zfp.readthedocs.io/en/latest/modes.html#mode-fixed-accuracy
One of tolerance, precision, or rate must be specified.
precision : int, optional
The precision of the compressed data.
This will use ZFP in fixed-precision mode.
https://zfp.readthedocs.io/en/latest/modes.html#fixed-precision-mode
One of tolerance, precision, or rate must be specified.
rate : float, optional
The rate of the compressed data.
This will use ZFP in fixed-rate mode.
https://zfp.readthedocs.io/en/latest/modes.html#fixed-rate-mode
One of tolerance, precision, or rate must be specified.
parallel : bool, optional, default True
Whether to use parallel compression.
This will use ZFP in parallel mode.

Returns
-------
outdata : Cython.memoryview
The compressed data.
"""
assert(tolerance or precision or rate)
assert(not(tolerance is not None and precision is not None))
assert(not(tolerance is not None and rate is not None))
Expand Down Expand Up @@ -204,7 +235,45 @@ def compress(indata, tolerance=None, precision=None, rate=None, parallel=True):


def decompress(const unsigned char[::1] compressed, shape, dtype, tolerance=None, precision=None,
rate=None, parallel=True, order='C'):
rate=None, parallel=False, order='C'):
navjotk marked this conversation as resolved.
Show resolved Hide resolved
"""
Decompress a numpy array using zfp.

Parameters
----------
compressed : Cython.memoryview
The compressed data.
shape : tuple
The shape of the decompressed data.
dtype : numpy.dtype
The dtype of the decompressed data.
tolerance : float, optional
The tolerance for the compressed data.
This will use ZFP in fixed-accuracy mode.
https://zfp.readthedocs.io/en/latest/modes.html#mode-fixed-accuracy
One of tolerance, precision, or rate must be specified.
precision : int, optional
The precision of the compressed data.
This will use ZFP in fixed-precision mode.
https://zfp.readthedocs.io/en/latest/modes.html#fixed-precision-mode
One of tolerance, precision, or rate must be specified.
rate : float, optional
The rate of the compressed data.
This will use ZFP in fixed-rate mode.
https://zfp.readthedocs.io/en/latest/modes.html#fixed-rate-mode
One of tolerance, precision, or rate must be specified.
parallel : bool, optional, default False
Whether to use parallel decompression.
This will use ZFP in parallel mode.
order : str, optional, default 'C'
The order of the decompressed data.
Must be either C or F(ortran).

Returns
-------
outdata : numpy.ndarray
The decompressed data.
"""
assert(tolerance or precision or rate)
assert(not(tolerance is not None and precision is not None))
assert(not(tolerance is not None and rate is not None))
Expand All @@ -222,9 +291,12 @@ def decompress(const unsigned char[::1] compressed, shape, dtype, tolerance=None
zfp_stream_set_precision(stream, precision)
elif rate is not None:
zfp_stream_set_rate(stream, rate, data_type, len(shape), 0)
# Try multithreaded
#if(parallel):
# zfp_stream_set_execution(stream, zfp_exec_omp)

if(parallel):
try:
zfp_stream_set_execution(stream, zfp_exec_omp)
except:
raise ValueError("Parallel decompression not supported on this platform")
bitstream = stream_open(<void*>&compressed[0], len(compressed))
zfp_stream_set_bit_stream(stream, bitstream)
zfp_stream_rewind(stream)
Expand Down