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 serialize(value): if not value.array.dtype == np.float64: value = DLPythonDoubleBuffer(value.array.astype(np.float64)) buffer = BytesIO(bytes()) buffer.write(value.array.tobytes()) return buffer.getvalue()
def deserialize(bytes): return DLPythonDoubleBuffer(np.frombuffer(bytes, dtype=np.float64))
# -*- coding: utf-8 -*- import numpy as np from DLPythonDataBuffers import DLPythonDoubleBuffer global test_out_data test_out_data = test_in_data.iloc[:, 0].map(lambda buff: DLPythonDoubleBuffer( np.vectorize(lambda x: x * 5)(buff.array))).to_frame('test_out_data')