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

replace bytes of compressed stream with uint8_t #106

Merged
merged 21 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from 20 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
29 changes: 15 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ matrix:
- g++-6
- gfortran-6
- libpython3.5-dev
- cython3
- python3-numpy
- python3-pip
env: CC='gcc-6' CXX='g++-6' FC='gfortran-6' FORTRAN_STANDARD='2003' PYTHON_VERSION='3.5' COVERAGE='ON'

- os: linux
Expand All @@ -29,8 +29,8 @@ matrix:
- g++-7
- gfortran-6
- libpython3.5-dev
- cython3
- python3-numpy
- python3-pip
env: CC='clang-3.6' CXX='clang++-3.6' FC='gfortran-6' FORTRAN_STANDARD='2003' PYTHON_VERSION='3.5'

- os: linux
Expand All @@ -46,8 +46,8 @@ matrix:
- g++-7
- gfortran-6
- libpython3.5-dev
- cython3
- python3-numpy
- python3-pip
env: CC='clang-4.0' CXX='clang++-4.0' FC='gfortran-6' FORTRAN_STANDARD='2003' PYTHON_VERSION='3.5'

- os: linux
Expand All @@ -61,8 +61,8 @@ matrix:
- g++-4.4
- gfortran-4.4
- libpython3.5-dev
- cython3
- python3-numpy
- python3-pip
env: CC='gcc-4.4' CXX='g++-4.4' FC='gfortran-4.4' FORTRAN_STANDARD='2003' PYTHON_VERSION='3.5'

- os: linux
Expand All @@ -76,8 +76,8 @@ matrix:
- g++-4.7
- gfortran-4.7
- libpython3.5-dev
- cython3
- python3-numpy
- python3-pip
env: CC='gcc-4.7' CXX='g++-4.7' FC='gfortran-4.7' FORTRAN_STANDARD='2003' PYTHON_VERSION='3.5'

- os: linux
Expand All @@ -91,8 +91,8 @@ matrix:
- g++-4.8
- gfortran-4.8
- libpython3.5-dev
- cython3
- python3-numpy
- python3-pip
env: CC='gcc-4.8' CXX='g++-4.8' FC='gfortran-4.8' FORTRAN_STANDARD='2003' PYTHON_VERSION='3.5'

- os: linux
Expand All @@ -106,8 +106,8 @@ matrix:
- g++-4.9
- gfortran-4.9
- libpython3.5-dev
- cython3
- python3-numpy
- python3-pip
env: CC='gcc-4.9' CXX='g++-4.9' FC='gfortran-4.9' FORTRAN_STANDARD='2003' PYTHON_VERSION='3.5'

- os: linux
Expand Down Expand Up @@ -135,7 +135,6 @@ matrix:
- g++-6
- gfortran-6
- libpython2.7
- python-pip
env: CC='gcc-6' CXX='g++-6' FC='gfortran-6' FORTRAN_STANDARD='2003' PYTHON_VERSION='2.7'

- os: linux
Expand All @@ -149,8 +148,8 @@ matrix:
- g++-6
- gfortran-6
- libpython3.5-dev
- cython3
- python3-numpy
- python3-pip
env: CC='gcc-6' CXX='g++-6' FC='gfortran-6' FORTRAN_STANDARD='2003' PYTHON_VERSION='3.5' C_STANDARD='90'

- os: linux
Expand All @@ -164,8 +163,8 @@ matrix:
- g++-6
- gfortran-6
- libpython3.5-dev
- cython3
- python3-numpy
- python3-pip
env: CC='gcc-6' CXX='g++-6' FC='gfortran-6' FORTRAN_STANDARD='2003' PYTHON_VERSION='3.5' C_STANDARD='11'

- os: linux
Expand All @@ -179,8 +178,8 @@ matrix:
- g++-6
- gfortran-6
- libpython3.5-dev
- cython3
- python3-numpy
- python3-pip
env: CC='gcc-6' CXX='g++-6' FC='gfortran-6' FORTRAN_STANDARD='2003' PYTHON_VERSION='3.5' CXX_STANDARD='11'

- os: linux
Expand All @@ -194,8 +193,8 @@ matrix:
- g++-6
- gfortran-6
- libpython3.5
- cython3
- python3-numpy
- python3-pip
env: CC='gcc-6' CXX='g++-6' FC='gfortran-6' FORTRAN_STANDARD='2003' PYTHON_VERSION='3.5' CXX_STANDARD='14'

- os: linux
Expand All @@ -209,8 +208,8 @@ matrix:
- g++-6
- gfortran-6
- libpython3.5
- cython3
- python3-numpy
- python3-pip
env: CC='gcc-6' CXX='g++-6' FC='gfortran-6' FORTRAN_STANDARD='2008' PYTHON_VERSION='3.5'

- os: linux
Expand All @@ -224,8 +223,8 @@ matrix:
- g++-7
- gfortran-7
- libpython3.5
- cython3
- python3-numpy
- python3-pip
env: CC='gcc-7' CXX='g++-7' FC='gfortran-7' FORTRAN_STANDARD='2008' PYTHON_VERSION='3.5'

- os: osx
Expand Down Expand Up @@ -284,6 +283,8 @@ script:
if [ "$TRAVIS_OS_NAME" = "linux" ] && [ "$PYTHON_VERSION" = "3.5" ]; then
export PYTHON_INCLUDE_DIR=/usr/include/python3.5m;
export PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so;
sudo $PYTHON_EXECUTABLE -m pip install --upgrade pip;
sudo $PYTHON_EXECUTABLE -m pip install --upgrade cython;
fi
- |
if [ "$TRAVIS_OS_NAME" = "linux" ] && [ "$DISTRIB_CODENAME" = "trusty" ] && [ "$PYTHON_VERSION" = "2.7" ]; then
Expand Down
14 changes: 7 additions & 7 deletions python/zfpy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import cython
from libc.stdlib cimport malloc, free
from cython cimport view
from cpython cimport array
from libc.stdint cimport uint8_t
import array

import itertools
Expand Down Expand Up @@ -245,25 +246,24 @@ cdef _validate_4d_list(in_list, list_name):
)

cpdef np.ndarray _decompress(
bytes compressed_data,
const uint8_t[::1] compressed_data,
zfp_type ztype,
shape,
out=None,
double tolerance = -1,
double rate = -1,
int precision = -1,
):

if compressed_data is None:
raise TypeError("compressed_data cannot be None")
if compressed_data is out:
raise ValueError("Cannot decompress in-place")
_validate_4d_list(shape, "shape")

cdef char* comp_data_pointer = compressed_data
cdef const void* comp_data_pointer = <const void*>&compressed_data[0]
cdef zfp_field* field = zfp_field_alloc()
cdef bitstream* bstream = stream_open(
comp_data_pointer,
<void *>comp_data_pointer,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this second cast from const void* to void* necessary, or can comp_data_pointer be declared as void*?

len(compressed_data)
)
cdef zfp_stream* stream = zfp_stream_open(bstream)
Expand Down Expand Up @@ -329,15 +329,15 @@ cpdef np.ndarray _decompress(
return output

cpdef np.ndarray decompress_numpy(
bytes compressed_data,
const uint8_t[::1] compressed_data,
):
if compressed_data is None:
raise TypeError("compressed_data cannot be None")

cdef char* comp_data_pointer = compressed_data
cdef const void* comp_data_pointer = <const void *>&compressed_data[0]
cdef zfp_field* field = zfp_field_alloc()
cdef bitstream* bstream = stream_open(
comp_data_pointer,
<void *>comp_data_pointer,
len(compressed_data)
)
cdef zfp_stream* stream = zfp_stream_open(bstream)
Expand Down
15 changes: 12 additions & 3 deletions tests/python/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ def test_advanced_decompression_checksum(self):
compress_param_num
),
}
compressed_array = zfpy.compress_numpy(
compressed_array_t = zfpy.compress_numpy(
random_array,
write_header=False,
**compression_kwargs
)

if isinstance(compressed_array_t, np.ndarray):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the intent here. compressed_array_t is by definition a bytes object, so this conditional should always be false.

Wouldn't the appropriate test be to ensure that we can pass both a bytes object and an ndarray to zfpy.decompress_numpy? What other array-like objects are we trying to support here?

Minor nit: As a C/C++ programmer, I think compressed_array_t is a confusing name as the _t suffix makes it look like a type.

compressed_array = compressed_array_t
else:
mem = memoryview(compressed_array_t)
compressed_array = np.array(mem, copy=False)
# Decompression using the "advanced" interface which enforces no header,
# and the user must provide all the metadata
decompressed_array = np.empty_like(random_array)
Expand Down Expand Up @@ -177,11 +181,16 @@ def test_utils(self):
# Decompression using the "public" interface
# requires a header, so re-compress with the header
# included in the stream
compressed_array = zfpy.compress_numpy(
compressed_array_t = zfpy.compress_numpy(
random_array,
write_header=True,
**compression_kwargs
)
if isinstance(compressed_array_t, np.ndarray):
compressed_array = compressed_array_t
else:
mem = memoryview(compressed_array_t)
compressed_array = np.array(mem, copy=False)
decompressed_array = zfpy.decompress_numpy(
compressed_array,
)
Expand Down