Skip to content

Commit df60e2f

Browse files
authored
Merge pull request #128 from alimanfoo/use-buffers-redux-alimanfoo-20181122
Use more buffers (redux)
2 parents 4f62e09 + 5938937 commit df60e2f

35 files changed

+3509
-8424
lines changed

docs/release.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ Release notes
3232
* Corrects handling of ``NaT`` in ``datetime64`` and ``timedelta64`` in various
3333
compressors (by :user:`John Kirkham <jakirkham>`; :issue:`127`, :issue:`131`).
3434

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

3743
0.5.5

numcodecs/astype.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numpy as np
55

66
from .abc import Codec
7-
from .compat import buffer_copy, ndarray_from_buffer
7+
from .compat import ndarray_copy, ensure_ndarray
88

99

1010
class AsType(Codec):
@@ -49,8 +49,8 @@ def __init__(self, encode_dtype, decode_dtype):
4949

5050
def encode(self, buf):
5151

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

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

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

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

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

6868
# handle output
69-
out = buffer_copy(dec, out)
69+
out = ndarray_copy(dec, out)
7070

7171
return out
7272

0 commit comments

Comments
 (0)