Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.1:Update
python-featureflow
fix_numpy_recarrays.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File fix_numpy_recarrays.patch of Package python-featureflow
From 450b7638118656df88db44a07744d1c47b947f74 Mon Sep 17 00:00:00 2001 From: John Vinyard <john.vinyard@gmail.com> Date: Mon, 5 Nov 2018 20:15:02 -0600 Subject: [PATCH] More correct code for packing recarrays. Addresses issue #7 --- featureflow/nmpy.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/featureflow/nmpy.py b/featureflow/nmpy.py index 165bbb3..b47ab9a 100644 --- a/featureflow/nmpy.py +++ b/featureflow/nmpy.py @@ -77,8 +77,29 @@ class PackedNumpyEncoder(NumpyEncoder): def __init__(self, needs=None): super(PackedNumpyEncoder, self).__init__(needs=needs) + def _pack_recarray(self, recarr): + fields = recarr.dtype.fields + + packed_data = dict() + new_dtype = [] + + for name in fields.iterkeys(): + view = recarr[name].copy().view(np.uint8) \ + .reshape(recarr.shape + (-1,)) + packed_data[name] = view + new_dtype.append((name, np.uint8, view.shape[1:])) + + packed_recarray = np.recarray(recarr.shape, dtype=new_dtype) + + for name, value in packed_data.iteritems(): + packed_recarray[name] = value + return packed_recarray + def _prepare_data(self, data): - return np.packbits(data.astype(np.uint8), axis=-1) + try: + return np.packbits(data.astype(np.uint8), axis=-1) + except ValueError: + return self._pack_recarray(data) def _np_from_buffer(b, shape, dtype):
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor