(src, shape)
return buf
Converts a native `src` array to a managed numpy buffer.

  Args:
    src: A ctypes pointer or array.
    shape: A tuple specifying the dimensions of the output array.

  Returns:
    A numpy array.
Converts a native `src` array to a managed numpy buffer.
Converts a native src array to a managed numpy buffer .
def _as_array(src, shape):
  """Converts a native `src` array to a managed numpy buffer.

  Args:
    src: A ctypes pointer or array.
    shape: A tuple specifying the dimensions of the output array.

  Returns:
    A numpy array.
  """

  # To work around a memory leak in numpy, we have to go through this
  # frombuffer method instead of calling ctypeslib.as_array.  See
  # https://github.com/numpy/numpy/issues/6511
  # return np.ctypeslib.as_array(src, shape)

  # This is part of the public API.  See
  # http://git.net/ml/python.ctypes/2008-02/msg00014.html
  ctype = src._type_  # pylint: disable=protected-access

  size = np.product(shape)
  ptr = ctypes.cast(src, ctypes.POINTER(ctype * size))
  buf = np.frombuffer(ptr.contents, dtype=ctype)
  buf.shape = shape

  # If we are wrapping an array of ctypes structs, return a `numpy.recarray`.
  # This allows the fields of the struct to be accessed as attributes.
  if issubclass(ctype, ctypes.Structure):
    buf = buf.view(np.recarray)

  return buf
def _as_array ( src , shape ) : # To work around a memory leak in numpy, we have to go through this # frombuffer method instead of calling ctypeslib.as_array.  See # https://github.com/numpy/numpy/issues/6511 # return np.ctypeslib.as_array(src, shape) # This is part of the public API.  See # http://git.net/ml/python.ctypes/2008-02/msg00014.html ctype = src . _type_ # pylint: disable=protected-access size = np . product ( shape ) ptr = ctypes . cast ( src , ctypes . POINTER ( ctype * size ) ) buf = np . frombuffer ( ptr . contents , dtype = ctype ) buf . shape = shape # If we are wrapping an array of ctypes structs, return a `numpy.recarray`. # This allows the fields of the struct to be accessed as attributes. if issubclass ( ctype , ctypes . Structure ) : buf = buf . view ( np . recarray ) return buf