未验证 提交 e87af068 编写于 作者: H Huang Zhengjie 提交者: GitHub

Merge pull request #126 from Yelrose/master

fixed mp_reader for list
...@@ -38,17 +38,20 @@ def serialize_data(data): ...@@ -38,17 +38,20 @@ def serialize_data(data):
return None return None
return numpy_serialize_data(data) #, ensure_ascii=False) return numpy_serialize_data(data) #, ensure_ascii=False)
def index_iter(data):
"""return indexing iter"""
if isinstance(data, list):
return range(len(data))
elif isinstance(data, dict):
return data.keys()
def numpy_serialize_data(data): def numpy_serialize_data(data):
"""serialize_data""" """serialize_data"""
ret_data = copy.deepcopy(data) ret_data = copy.deepcopy(data)
if isinstance(ret_data, list):
for key, value in enumerate(ret_data): if isinstance(ret_data, (dict, list)):
if isinstance(ret_data[key], np.ndarray): for key in index_iter(ret_data):
ret_data[key] = _np_serialized_data(value=ret_data[key].tobytes(),
shape=list(ret_data[key].shape), dtype="%s" % ret_data[key].dtype)
elif isinstance(ret_data, dict):
for key in ret_data:
if isinstance(ret_data[key], np.ndarray): if isinstance(ret_data[key], np.ndarray):
ret_data[key] = _np_serialized_data(value=ret_data[key].tobytes(), ret_data[key] = _np_serialized_data(value=ret_data[key].tobytes(),
shape=list(ret_data[key].shape), dtype="%s" % ret_data[key].dtype) shape=list(ret_data[key].shape), dtype="%s" % ret_data[key].dtype)
...@@ -60,14 +63,8 @@ def numpy_deserialize_data(data): ...@@ -60,14 +63,8 @@ def numpy_deserialize_data(data):
if data is None: if data is None:
return None return None
if isinstance(data, list): if isinstance(data, (dict, list)):
for key, value in enumerate(data): for key in index_iter(data):
if isinstance(value, _np_serialized_data):
data[key] = np.frombuffer(buffer=data[key].value,
dtype=data[key].dtype).reshape(data[key].shape)
elif isinstance(data, dict):
for key in data:
if isinstance(data[key], _np_serialized_data): if isinstance(data[key], _np_serialized_data):
data[key] = np.frombuffer(buffer=data[key].value, data[key] = np.frombuffer(buffer=data[key].value,
dtype=data[key].dtype).reshape(data[key].shape) dtype=data[key].dtype).reshape(data[key].shape)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册