INNER CODE UNIT · Python
array
onnx/onnx-tensorrt · onnx_tensorrt/tensorrt_engine.py:76
def array(self) -> np.ndarray:
# Create view with proper memory ownership
pointer_type = ctypes.POINTER(np.ctypeslib.as_ctypes_type(self._dtype))
host_array = np.ctypeslib.as_array(ctypes.cast(self._host_ptr, pointer_type), (self._host_size,))
return ArrayWithOwner(host_array, self)
@array.setter
def array(self, data: Union[np.ndarray, bytes]):
"""Set the array data with proper bounds checking"""
host_array = self.array # Get the numpy array view
if isinstance(data, np.ndarray):
if data.size > self._host_size:
raise ValueError(
f"Tried to fit an array of size {data.size} into host memory of size {self._host_size}"
)
np.copyto(host_array[:data.size], data.flat, casting='safe')
else:
assert self._dtype == np.uint8