parameters: (device: HalDevice,
                    a,
                    dtype=None,
                    *,
                    implicit_host_transfer: bool = False,
                    memory_type=MemoryType.DEVICE_LOCAL |
                    MemoryType.DEVICE_VISIBLE,
                    allowed_usage=BufferUsage.ALL,
                    element_type: Optional[HalElementType] = None)
return_statement: return DeviceArray(device,
                       buffer_view,
                       implicit_host_transfer=implicit_host_transfer,
                       override_dtype=a.dtype)
docstring: Helper to create a DeviceArray from an arbitrary array like.
  
    This is similar in purpose and usage to np.asarray, except that it takes
    a device as the first argument. This may not be the best mechanism for
    getting a DeviceArray, depending on your use case, but it is reliable
    and simple. This function may make a defensive copy or cause implicit
    transfers to satisfy the request. If this is important to you, then a lower
    level API is likely more appropriate.
  
    Note that additional flags `memory_type`, `allowed_usage` and `element_type`
    are only hints if creating a new DeviceArray. If `a` is already a DeviceArray,
    they are ignored.
docstring_summary: Helper to create a DeviceArray from an arbitrary array like.
docstring_tokens: Helper to create a DeviceArray from an arbitrary array like .
function: def asdevicearray(device: HalDevice,
                    a,
                    dtype=None,
                    *,
                    implicit_host_transfer: bool = False,
                    memory_type=MemoryType.DEVICE_LOCAL |
                    MemoryType.DEVICE_VISIBLE,
                    allowed_usage=BufferUsage.ALL,
                    element_type: Optional[HalElementType] = None) -> DeviceArray:
    """Helper to create a DeviceArray from an arbitrary array like.
  
    This is similar in purpose and usage to np.asarray, except that it takes
    a device as the first argument. This may not be the best mechanism for
    getting a DeviceArray, depending on your use case, but it is reliable
    and simple. This function may make a defensive copy or cause implicit
    transfers to satisfy the request. If this is important to you, then a lower
    level API is likely more appropriate.
  
    Note that additional flags `memory_type`, `allowed_usage` and `element_type`
    are only hints if creating a new DeviceArray. If `a` is already a DeviceArray,
    they are ignored.
    """
    if isinstance(a, DeviceArray):
      if dtype is None:
        return a
      # Need to do a conversion, which we currently do not support on the
      # device, so transfer back to the host.
      logging.warn(
          "Implicit dtype conversion of a DeviceArray forces a host transfer")
    # First get an ndarray.
    a = np.asarray(a, dtype=dtype)
    element_type = map_dtype_to_element_type(a.dtype)
    if element_type is None:
      raise ValueError(f"Could not map dtype {a.dtype} to IREE element type")
    buffer_view = device.allocator.allocate_buffer_copy(
        memory_type=memory_type,
        allowed_usage=allowed_usage,
        buffer=a,
        element_type=element_type)
    return DeviceArray(device,
                       buffer_view,
                       implicit_host_transfer=implicit_host_transfer,
                       override_dtype=a.dtype)
function_tokens: def asdevicearray ( device : HalDevice , a , dtype = None , * , implicit_host_transfer : bool = False , memory_type = MemoryType . DEVICE_LOCAL | MemoryType . DEVICE_VISIBLE , allowed_usage = BufferUsage . ALL , element_type : Optional [ HalElementType ] = None ) -> DeviceArray : if isinstance ( a , DeviceArray ) : if dtype is None : return a # Need to do a conversion, which we currently do not support on the # device, so transfer back to the host. logging . warn ( "Implicit dtype conversion of a DeviceArray forces a host transfer" ) # First get an ndarray. a = np . asarray ( a , dtype = dtype ) element_type = map_dtype_to_element_type ( a . dtype ) if element_type is None : raise ValueError ( f"Could not map dtype {a.dtype} to IREE element type" ) buffer_view = device . allocator . allocate_buffer_copy ( memory_type = memory_type , allowed_usage = allowed_usage , buffer = a , element_type = element_type ) return DeviceArray ( device , buffer_view , implicit_host_transfer = implicit_host_transfer , override_dtype = a . dtype )