code: def convert_dtype(
      X, to_dtype=np.float32, legacy=True, safe_dtype=True
  ):
      """
      Convert X to be of dtype `dtype`, raising a TypeError
      if the conversion would lose information.
      """
  
      if isinstance(X, (DaskCudfSeries, DaskCudfDataFrame)):
          # TODO: Warn, but not when using dask_sql
          X = X.compute()
  
      if safe_dtype:
          cur_dtype = determine_array_dtype(X)
          if not global_settings.xpy.can_cast(cur_dtype, to_dtype):
              try:
                  target_dtype_range = global_settings.xpy.iinfo(
                      to_dtype
                  )
              except ValueError:
                  target_dtype_range = global_settings.xpy.finfo(
                      to_dtype
                  )
              out_of_range = (
                  (X < target_dtype_range.min)
                  | (X > target_dtype_range.max)
              ).any()
              try:
                  out_of_range = out_of_range.any()
              except AttributeError:
                  pass
  
              if out_of_range:
                  raise TypeError(
                      "Data type conversion would lose information."
                  )
      try:
          if numba_cuda.is_cuda_array(X):
              arr = cp.asarray(X, dtype=to_dtype)
              if legacy:
                  return numba_cuda.as_cuda_array(arr)
              else:
                  return CumlArray(data=arr)
      except UnavailableError:
          pass
  
      try:
          return X.astype(to_dtype, copy=False)
      except AttributeError:
          raise TypeError(
              "Received unsupported input type: %s" % type(X)
          )
  
file_path: cuml/python/cuml/internals/input_utils.py
imports: from collections import namedtuple
  from cuml.internals.array import CumlArray
  from cuml.internals.array_sparse import SparseCumlArray
  from cuml.internals.global_settings import GlobalSettings
  from cuml.internals.mem_type import MemoryType
  from cuml.internals.safe_imports import cpu_only_import, cpu_only_import_from, gpu_only_import, gpu_only_import_from, safe_import, safe_import_from, null_decorator, return_false, UnavailableError
label_desc: Use image node_id 10 for calling a global function with example usage: convert_dtype(X, to_dtype, legacy, safe_dtype) and returns: X, numba_cuda, CumlArray