change numpy to bytearray as buffer
This commit is contained in:
parent
6942980ebb
commit
a4de0ebcd4
@ -97,11 +97,12 @@ def ctypes2numpy(cptr, length, dtype):
|
|||||||
def ctypes2buffer(cptr, length):
|
def ctypes2buffer(cptr, length):
|
||||||
if not isinstance(cptr, ctypes.POINTER(ctypes.c_char)):
|
if not isinstance(cptr, ctypes.POINTER(ctypes.c_char)):
|
||||||
raise RuntimeError('expected char pointer')
|
raise RuntimeError('expected char pointer')
|
||||||
res = np.zeros(length, dtype='uint8')
|
res = bytearray(length)
|
||||||
if not ctypes.memmove(res.ctypes.data, cptr, length * res.strides[0]):
|
rptr = (ctypes.c_char * length).from_buffer(res)
|
||||||
|
if not ctypes.memmove(rptr, cptr, length):
|
||||||
raise RuntimeError('memmove failed')
|
raise RuntimeError('memmove failed')
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def c_str(string):
|
def c_str(string):
|
||||||
return ctypes.c_char_p(string.encode('utf-8'))
|
return ctypes.c_char_p(string.encode('utf-8'))
|
||||||
|
|
||||||
@ -886,7 +887,7 @@ class XGBModel(XGBModelBase):
|
|||||||
def __setstate__(self, state):
|
def __setstate__(self, state):
|
||||||
bst = state["_Booster"]
|
bst = state["_Booster"]
|
||||||
if bst is not None:
|
if bst is not None:
|
||||||
state["_Booster"] = Booster(model_file=booster)
|
state["_Booster"] = Booster(model_file=bst)
|
||||||
self.__dict__.update(state)
|
self.__dict__.update(state)
|
||||||
|
|
||||||
def booster(self):
|
def booster(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user