parameters: (self, data, data_length=0, layout=None)
docstring: copy the data to the tensor
          param data: the data to copy to tensor, it should be list,
          numpy.ndarraya or ctypes with length
docstring_summary: copy the data to the tensor
          param data: the data to copy to tensor, it should be list,
          numpy.ndarraya or ctypes with length
docstring_tokens: copy the data to the tensor param data : the data to copy to tensor it should be list numpy . ndarraya or ctypes with length
function: def set_data_by_copy(self, data, data_length=0, layout=None):
          """
          copy the data to the tensor
          param data: the data to copy to tensor, it should be list,
          numpy.ndarraya or ctypes with length
          """
          if layout is not None:
              self.layout = layout
  
          assert self.is_continue, "set_data_by_copy can only apply in continue tensor."
          assert (
              self.is_pinned_host or self.device_type == LiteDeviceType.LITE_CPU
          ), "set_data_by_copy can only apply in cpu tensor or pinned tensor."
  
          c_type = _lite_dtypes_to_ctype[LiteDataType(self._layout.data_type)]
  
          tensor_memory = c_void_p()
  
          if type(data) == list:
              length = len(data)
              self._api.LITE_get_tensor_memory(self._tensor, byref(tensor_memory))
              tensor_length = self.nbytes
              assert (
                  length * sizeof(c_type) <= tensor_length
              ), "the length of input data to set to the tensor is too large."
              arr = (c_type * length)(*data)
              memmove(tensor_memory, arr, sizeof(c_type) * length)
  
          elif type(data) == np.ndarray:
              if self.nbytes != data.nbytes:
                  self.layout = LiteLayout(data.shape, data.dtype)
              arr = data.ctypes.data_as(POINTER(c_type))
              self._api.LITE_get_tensor_memory(self._tensor, byref(tensor_memory))
              assert self.nbytes == data.nbytes
              memmove(tensor_memory, arr, self.nbytes)
          else:
              assert (
                  data_length == self.nbytes or layout is not None
              ), "when input data is ctypes, the length of input data or layout must set"
              self._api.LITE_get_tensor_memory(self._tensor, byref(tensor_memory))
              memmove(tensor_memory, data, data_length)
function_tokens: def set_data_by_copy ( self , data , data_length = 0 , layout = None ) : if layout is not None : self . layout = layout assert self . is_continue , "set_data_by_copy can only apply in continue tensor." assert ( self . is_pinned_host or self . device_type == LiteDeviceType . LITE_CPU ) , "set_data_by_copy can only apply in cpu tensor or pinned tensor." c_type = _lite_dtypes_to_ctype [ LiteDataType ( self . _layout . data_type ) ] tensor_memory = c_void_p ( ) if type ( data ) == list : length = len ( data ) self . _api . LITE_get_tensor_memory ( self . _tensor , byref ( tensor_memory ) ) tensor_length = self . nbytes assert ( length * sizeof ( c_type ) <= tensor_length ) , "the length of input data to set to the tensor is too large." arr = ( c_type * length ) ( * data ) memmove ( tensor_memory , arr , sizeof ( c_type ) * length ) elif type ( data ) == np . ndarray : if self . nbytes != data . nbytes : self . layout = LiteLayout ( data . shape , data . dtype ) arr = data . ctypes . data_as ( POINTER ( c_type ) ) self . _api . LITE_get_tensor_memory ( self . _tensor , byref ( tensor_memory ) ) assert self . nbytes == data . nbytes memmove ( tensor_memory , arr , self . nbytes ) else : assert ( data_length == self . nbytes or layout is not None ) , "when input data is ctypes, the length of input data or layout must set" self . _api . LITE_get_tensor_memory ( self . _tensor , byref ( tensor_memory ) ) memmove ( tensor_memory , data , data_length )