Skip to content

Commit 0816a7a

Browse files
committed
Make copyless functionality default.
1 parent 32e28d5 commit 0816a7a

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Change Log
44
==========
55

6+
Release 0.4.4 (September 25, 2018)
7+
----------------------------------
8+
* Access ndarray memory view directly to slightly speed up encoding (#30).
9+
610
Release 0.4.3.2 - (September 17, 2018)
711
--------------------------------------
812
* Update classifiers to list Py3 support (#29).

msgpack_numpy.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from msgpack import Packer as _Packer, Unpacker as _Unpacker, \
1919
unpack as _unpack, unpackb as _unpackb
2020

21-
def encode(obj, chain=None, copyless=False):
21+
def encode(obj, chain=None):
2222
"""
2323
Data encoder for serializing numpy data types.
2424
"""
@@ -32,27 +32,15 @@ def encode(obj, chain=None, copyless=False):
3232
else:
3333
kind = b''
3434
descr = obj.dtype.str
35-
if copyless:
36-
return {b'nd': True,
37-
b'type': descr,
38-
b'kind': kind,
39-
b'shape': obj.shape,
40-
b'data': obj.data}
41-
else:
42-
return {b'nd': True,
43-
b'type': descr,
44-
b'kind': kind,
45-
b'shape': obj.shape,
46-
b'data': obj.tobytes()}
35+
return {b'nd': True,
36+
b'type': descr,
37+
b'kind': kind,
38+
b'shape': obj.shape,
39+
b'data': obj.data}
4740
elif isinstance(obj, (np.bool_, np.number)):
48-
if copyless:
49-
return {b'nd': False,
50-
b'type': obj.dtype.str,
51-
b'data': obj.tobytes()}
52-
else:
53-
return {b'nd': False,
54-
b'type': obj.dtype.str,
55-
b'data': obj.tobytes()}
41+
return {b'nd': False,
42+
b'type': obj.dtype.str,
43+
b'data': obj.data}
5644
elif isinstance(obj, complex):
5745
return {b'complex': True,
5846
b'data': obj.__repr__()}
@@ -104,9 +92,8 @@ def __init__(self, default=None,
10492
encoding='utf-8',
10593
unicode_errors='strict',
10694
use_single_float=False,
107-
autoreset=1,
108-
copyless=False):
109-
default = functools.partial(encode, chain=default, copyless=copyless)
95+
autoreset=1):
96+
default = functools.partial(encode, chain=default)
11097
super(Packer, self).__init__(default=default,
11198
encoding=encoding,
11299
unicode_errors=unicode_errors,
@@ -135,9 +122,8 @@ def __init__(self, default=None,
135122
unicode_errors='strict',
136123
use_single_float=False,
137124
autoreset=1,
138-
use_bin_type=0,
139-
copyless=False):
140-
default = functools.partial(encode, chain=default, copyless=copyless)
125+
use_bin_type=0):
126+
default = functools.partial(encode, chain=default)
141127
super(Packer, self).__init__(default=default,
142128
encoding=encoding,
143129
unicode_errors=unicode_errors,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from setuptools import setup
77

88
NAME = 'msgpack-numpy'
9-
VERSION = '0.4.3.2'
9+
VERSION = '0.4.4'
1010
AUTHOR = 'Lev E. Givon'
1111
AUTHOR_EMAIL = 'lev@columbia.edu'
1212
URL = 'https://github.com/lebedov/msgpack-numpy'

0 commit comments

Comments
 (0)