未验证 提交 0d22bd4d 编写于 作者: Z zylo117 提交者: GitHub

read tensor data as numpy array instead of python list (#1287)

* read tensor data as numpy array instead of python list

this is faster by 700 times

* apply code-format changes

* read char tensor as numpy array instead of python list
上级 3c561626
......@@ -132,10 +132,10 @@ class Tensor(object):
if ctype is ctypes.c_char:
_LIB.get_tensor_buffer.restype = ctypes.POINTER(ctype)
res = _LIB.get_tensor_buffer(ctypes.c_void_p(self.tensor))
return res[:size]
return np.ctypeslib.as_array(ctypes.cast(res, ctypes.POINTER(ctype)), (size,))
_LIB.get_tensor_buffer.restype = ctypes.POINTER(ctype)
res = _LIB.get_tensor_buffer(ctypes.c_void_p(self.tensor))
return res[:size]
return np.ctypeslib.as_array(ctypes.cast(res, ctypes.POINTER(ctype)), (size,))
def ascontiguousarray(self,value):
if self.dtype.enum == 2:
......
......@@ -462,7 +462,7 @@ void extract_feature_from_tensor_timvx(const char* comment, const char* layer_na
{
strcpy(save_dir, env_path);
if ('/' == save_dir[strlen(env_path) - 1] || '\\' == save_dir[strlen(env_path) - 1])
if ('/' == save_dir[strlen(env_path) - 1] || '\\' == save_dir[strlen(env_path) - 1])
{
#ifdef _MSC_VER
save_dir[strlen(env_path)] = '\\';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册