Function: ptr_to_numpy
NOTE
This API will be deprecated. Use acl.util.ptr_to_bytes instead.
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Function
Obtains the memory data pointer address of the numpy.ndarray array.
If the input numpy.ndarray array is non-contiguous in the memory, convert the non-contiguous memory into contiguous one and then obtain the memory data pointer address of the converted numpy.ndarray array.
Prototype
output = acl.util.ptr_to_numpy(ptr, shape, type)
Parameters
| Parameter | Description |
|---|---|
| ptr | Int, pointer address in the C language. It is the start address of the data that can be accessed. |
| shape | Tuple, shape of the NumPy to be constructed. |
| type | Int, data type of the data in ptr. Some common types are provided below: 0: NPY_BOOL1: NPY_BYTE, NPY_INT82: NPY_UINT83: NPY_SHORT, NPY_INT164: NPY_USHORT, NPY_UINT165: NPY_INT, NPY_INT326: NPY_UINT, NPY_UINT327: NPY_INT648: NPY_UINT649: NPY_LONGLONG10: NPY_ULONGLONG11: NPY_FLOAT3212: NPY_DOUBLE23: NPY_HALF, NPY_FLOAT16 |
Return Values
| Return Value | Description |
|---|---|
| output | NumPy type. |
Precautions
-
Example modification:
np_arr_out = acl.util.ptr_to_numpy(host_ptr, np_arr_in.shape, NPY_INT32)After modification:
bytes_out = acl.util.ptr_to_bytes(ptr, size) np_arr_out = np.frombuffer(bytes_out, dtype=np.int32).reshape(np_arr_in.shape) -
To continue to use this API, ensure that the operating environment uses Python 3.8 or later and NumPy 1.22.0 or later.