Skip to content

Use more buffers (redux) #128

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
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ Release notes
* Corrects handling of ``NaT`` in ``datetime64`` and ``timedelta64`` in various
compressors (by :user:`John Kirkham <jakirkham>`; :issue:`127`, :issue:`131`).

* Improvements to the compatibility layer used for normalising inputs to encode
and decode methods in most codecs. This removes unnecessary memory copies for
some codecs, and also simplifies the implementation of some codecs, improving
code readability and maintainability. By :user:`John Kirkham <jakirkham>` and
:user:`Alistair Miles <alimanfoo>`; :issue:`119`, :issue:`121`, :issue:`128`.

.. _release_0.5.5:

0.5.5
Expand Down
12 changes: 6 additions & 6 deletions numcodecs/astype.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np

from .abc import Codec
from .compat import buffer_copy, ndarray_from_buffer
from .compat import ndarray_copy, ensure_ndarray


class AsType(Codec):
Expand Down Expand Up @@ -49,8 +49,8 @@ def __init__(self, encode_dtype, decode_dtype):

def encode(self, buf):

# view input data as 1D array
arr = ndarray_from_buffer(buf, self.decode_dtype)
# normalise input
arr = ensure_ndarray(buf).view(self.decode_dtype)

# convert and copy
enc = arr.astype(self.encode_dtype)
Expand All @@ -59,14 +59,14 @@ def encode(self, buf):

def decode(self, buf, out=None):

# view encoded data as 1D array
enc = ndarray_from_buffer(buf, self.encode_dtype)
# normalise input
enc = ensure_ndarray(buf).view(self.encode_dtype)

# convert and copy
dec = enc.astype(self.decode_dtype)

# handle output
out = buffer_copy(dec, out)
out = ndarray_copy(dec, out)

return out

Expand Down
Loading