def _put_in_matching_buffer(self, y): t = y.dtype if t == np.float64: return DLPythonDoubleBuffer(y) elif t == np.float32: return DLPythonFloatBuffer(y) elif t == np.bool_: return DLPythonBitBuffer(y) elif t == np.int8: return DLPythonByteBuffer(y) elif t == np.uint8: return DLPythonUnsignedByteBuffer(y) elif t == np.int16: return DLPythonShortBuffer(y) elif t == np.int32: return DLPythonIntBuffer(y) elif t == np.int64: return DLPythonLongBuffer(y) elif t == np.object: return DLPythonStringBuffer(y) # TODO: support more types else: raise ValueError( 'Output type of the network \'{}\' is not supported.'.format( y.dtype))
def _put_in_matching_buffer(self, y): t = y.dtype if t == np.float64: return DLPythonDoubleBuffer(y) elif t == np.float32: return DLPythonFloatBuffer(y) elif t == np.bool_: return DLPythonBitBuffer(y) elif t == np.int8: return DLPythonByteBuffer(y) elif t == np.uint8: return DLPythonUnsignedByteBuffer(y) elif t == np.int16: return DLPythonShortBuffer(y) elif t == np.int32: return DLPythonIntBuffer(y) elif t == np.int64: return DLPythonLongBuffer(y) elif t == np.object: return DLPythonStringBuffer(y) # TODO: support more types else: # TODO: warning to stderr? fail? return DLPythonDoubleBuffer(y)
def deserialize(bytes): return DLPythonLongBuffer(np.frombuffer(bytes, dtype=np.int64))
# -*- coding: utf-8 -*- import numpy as np from DLPythonDataBuffers import DLPythonLongBuffer global test_out_data test_out_data = test_in_data.iloc[:, 0].map(lambda buff: DLPythonLongBuffer( np.vectorize(lambda x: x * 5)(buff.array))).to_frame('test_out_data')
def serialize(value): if not value.array.dtype == np.int64: value = DLPythonLongBuffer(value.array.astype(np.int64)) buffer = BytesIO(bytes()) buffer.write(value.array.tobytes()) return buffer.getvalue()