class_docstr: Array represents an abstracted array allocation. It can be instantiated by
  itself or can be instantiated by ``__cuda_array_interface__`` or
  ``__array_interface__`` compliant arrays, in which case it'll keep a
  reference to that data underneath. Also can be created from a pointer,
  specifying the characteristics of the array, in that case the owner of the
  data referred to by the pointer should be specified explicitly.
  
  Parameters
  ----------
  
  data : rmm.DeviceBuffer, cudf.Buffer, array_like, int, bytes, bytearray or           memoryview
      An array-like object or integer representing a
      device or host pointer to pre-allocated memory.
  owner : object, optional
      Python object to which the lifetime of the memory
      allocation is tied. If provided, a reference to this
      object is kept in this Buffer.
  dtype : data-type, optional
      Any object that can be interpreted as a numpy or cupy data type.
  shape : int or tuple of ints, optional
      Shape of created array.
  order: string, optional
      Whether to create a F-major or C-major array.
  mem_type: {'host', 'device'}, optional
      Whether data are on host or device.
  validate: bool, default=None
      Whether or not to check final array attributes against input options.
      If None, validation will occur only for CumlArray input and input that
      does not implement the array interface protocol and for which
      additional options were explicitly specified.
  
  Attributes
  ----------
  
  ptr : int
      Pointer to the data
  size : int
      Size of the array data in bytes
  _owner : Python Object
      Object that owns the data of the array
  shape : tuple of ints
      Shape of the array
  order : {'F', 'C'}
      'F' or 'C' to indicate Fortran-major or C-major order of the array
  strides : tuple of ints
      Strides of the data
  mem_type : MemoryType
      Memory type for how data are stored
  __array_interface__ : dictionary
      ``__array_interface__`` to interop with other libraries. This
      attribute is only present if data are host-accessible.
  __cuda_array_interface__ : dictionary
      ``__cuda_array_interface__`` to interop with other libraries. This
      attribute is only present if data are device-accessible.
  
  Notes
  -----
  
  cuml Array is not meant as an end-user array library. It is meant for
  cuML/RAPIDS developer consumption. Therefore it contains the minimum
  functionality. Its functionality is hidden by base.pyx to provide
  automatic output format conversion so that the users see the important
  attributes in whatever format they prefer.
  
  Todo: support cuda streams in the constructor. See:
  https://github.com/rapidsai/cuml/issues/1712
  https://github.com/rapidsai/cuml/pull/1396
class_docstr_tok: ["Array","represents","an","abstracted","array","allocation",".","It","can","be","instantiated","by","itself","or","can","be","instantiated","by","``","__cuda_array_interface__","``","or","``","__array_interface__","``","compliant","arrays",",","in","which","case","it","'ll","keep","a","reference","to","that","data","underneath",".","Also","can","be","created","from","a","pointer",",","specifying","the","characteristics","of","the","array",",","in","that","case","the","owner","of","the","data","referred","to","by","the","pointer","should","be","specified","explicitly",".","Parameters","--","--","--","--","--","data",":","rmm.DeviceBuffer",",","cudf.Buffer",",","array_like",",","int",",","bytes",",","bytearray","or","memoryview","An","array-like","object","or","integer","representing","a","device","or","host","pointer","to","pre-allocated","memory",".","owner",":","object",",","optional","Python","object","to","which","the","lifetime","of","the","memory","allocation","is","tied",".","If","provided",",","a","reference","to","this","object","is","kept","in","this","Buffer",".","dtype",":","data-type",",","optional","Any","object","that","can","be","interpreted","as","a","numpy","or","cupy","data","type",".","shape",":","int","or","tuple","of","ints",",","optional","Shape","of","created","array",".","order",":","string",",","optional","Whether","to","create","a","F-major","or","C-major","array",".","mem_type",":","{","'host","'",",","'device","'","}",",","optional","Whether","data","are","on","host","or","device",".","validate",":","bool",",","default=None","Whether","or","not","to","check","final","array","attributes","against","input","options",".","If","None",",","validation","will","occur","only","for","CumlArray","input","and","input","that","does","not","implement","the","array","interface","protocol","and","for","which","additional","options","were","explicitly","specified",".","Attributes","--","--","--","--","--","ptr",":","int","Pointer","to","the","data","size",":","int","Size","of","the","array","data","in","bytes","_owner",":","Python","Object","Object","that","owns","the","data","of","the","array","shape",":","tuple","of","ints","Shape","of","the","array","order",":","{","'","F","'",",","'","C","'","}","'","F","'","or","'","C","'","to","indicate","Fortran-major","or","C-major","order","of","the","array","strides",":","tuple","of","ints","Strides","of","the","data","mem_type",":","MemoryType","Memory","type","for","how","data","are","stored","__array_interface__",":","dictionary","``","__array_interface__","``","to","interop","with","other","libraries",".","This","attribute","is","only","present","if","data","are","host-accessible",".","__cuda_array_interface__",":","dictionary","``","__cuda_array_interface__","``","to","interop","with","other","libraries",".","This","attribute","is","only","present","if","data","are","device-accessible",".","Notes","--","--","-","cuml","Array","is","not","meant","as","an","end-user","array","library",".","It","is","meant","for","cuML\/RAPIDS","developer","consumption",".","Therefore","it","contains","the","minimum","functionality",".","Its","functionality","is","hidden","by","base.pyx","to","provide","automatic","output","format","conversion","so","that","the","users","see","the","important","attributes","in","whatever","format","they","prefer",".","Todo",":","support","cuda","streams","in","the","constructor",".","See",":","https",":","\/\/github.com\/rapidsai\/cuml\/issues\/1712","https",":","\/\/github.com\/rapidsai\/cuml\/pull\/1396"]
docstr: Convert input X to CumlArray.
  
  Acceptable input formats:
  
  * cuDF Dataframe - returns a deep copy always.
  * cuDF Series - returns by reference or a deep copy depending on
      `deepcopy`.
  * Numpy array - returns a copy in device always
  * cuda array interface compliant array (like Cupy) - returns a
      reference unless `deepcopy`=True.
  * numba device array - returns a reference unless deepcopy=True
  
  Parameters
  ----------
  
  X : cuDF.DataFrame, cuDF.Series, NumPy array, Pandas DataFrame, Pandas
      Series or any cuda_array_interface (CAI) compliant array like CuPy,
      Numba or pytorch.
  
  order: 'F', 'C' or 'K' (default: 'F')
      Whether to return a F-major ('F'),  C-major ('C') array or Keep
      ('K') the order of X. Used to check the order of the input. If
      fail_on_order=True, the method will raise ValueError, otherwise it
      will convert X to be of order `order` if needed.
  
  deepcopy: boolean (default: False)
      Set to True to always return a deep copy of X.
  
  check_dtype: np.dtype (default: False)
      Set to a np.dtype to throw an error if X is not of dtype
      `check_dtype`.
  
  convert_to_dtype: np.dtype (default: False)
      Set to a dtype if you want X to be converted to that dtype if it is
      not that dtype already.
  
  check_mem_type: {'host', 'device'} (default: False)
      Set to a value to throw an error if X is not of memory type
      `check_mem_type`.
  
  convert_to_mem_type: {'host', 'device'} (default: None)
      Set to a value if you want X to be converted to that memory type if
      it is not that memory type already. Set to False if you do not want
      any memory conversion. Set to None to use
      `cuml.global_settings.memory_type`.
  
  safe_convert_to_dtype: bool (default: True)
      Set to True to check whether a typecasting performed when
      convert_to_dtype is True will cause information loss. This has a
      performance implication that might be significant for very fast
      methods like FIL and linear models inference.
  
  check_cols: int (default: False)
      Set to an int `i` to check that input X has `i` columns. Set to
      False (default) to not check at all.
  
  check_rows: boolean (default: False)
      Set to an int `i` to check that input X has `i` columns. Set to
      False (default) to not check at all.
  
  fail_on_order: boolean (default: False)
      Set to True if you want the method to raise a ValueError if X is
      not of order `order`.
  
  force_contiguous: boolean (default: True)
      Set to True to force CumlArray produced to be contiguous. If `X` is
      non contiguous then a contiguous copy will be done.
      If False, and `X` doesn't need to be converted and is not
      contiguous, the underlying memory underneath the CumlArray will be
      non contiguous.  Only affects CAI inputs. Only affects CuPy and
      Numba device array views, all other input methods produce
      contiguous CumlArrays.
  
  Returns
  -------
  arr: CumlArray
  
      A new CumlArray
code: def from_input(
      cls,
      X,
      order="F",
      deepcopy=False,
      check_dtype=False,
      convert_to_dtype=False,
      check_mem_type=False,
      convert_to_mem_type=None,
      safe_dtype_conversion=True,
      check_cols=False,
      check_rows=False,
      fail_on_order=False,
      force_contiguous=True,
  ):
      """
      Convert input X to CumlArray.
  
      Acceptable input formats:
  
      * cuDF Dataframe - returns a deep copy always.
      * cuDF Series - returns by reference or a deep copy depending on
          `deepcopy`.
      * Numpy array - returns a copy in device always
      * cuda array interface compliant array (like Cupy) - returns a
          reference unless `deepcopy`=True.
      * numba device array - returns a reference unless deepcopy=True
  
      Parameters
      ----------
  
      X : cuDF.DataFrame, cuDF.Series, NumPy array, Pandas DataFrame, Pandas
          Series or any cuda_array_interface (CAI) compliant array like CuPy,
          Numba or pytorch.
  
      order: 'F', 'C' or 'K' (default: 'F')
          Whether to return a F-major ('F'),  C-major ('C') array or Keep
          ('K') the order of X. Used to check the order of the input. If
          fail_on_order=True, the method will raise ValueError, otherwise it
          will convert X to be of order `order` if needed.
  
      deepcopy: boolean (default: False)
          Set to True to always return a deep copy of X.
  
      check_dtype: np.dtype (default: False)
          Set to a np.dtype to throw an error if X is not of dtype
          `check_dtype`.
  
      convert_to_dtype: np.dtype (default: False)
          Set to a dtype if you want X to be converted to that dtype if it is
          not that dtype already.
  
      check_mem_type: {'host', 'device'} (default: False)
          Set to a value to throw an error if X is not of memory type
          `check_mem_type`.
  
      convert_to_mem_type: {'host', 'device'} (default: None)
          Set to a value if you want X to be converted to that memory type if
          it is not that memory type already. Set to False if you do not want
          any memory conversion. Set to None to use
          `cuml.global_settings.memory_type`.
  
      safe_convert_to_dtype: bool (default: True)
          Set to True to check whether a typecasting performed when
          convert_to_dtype is True will cause information loss. This has a
          performance implication that might be significant for very fast
          methods like FIL and linear models inference.
  
      check_cols: int (default: False)
          Set to an int `i` to check that input X has `i` columns. Set to
          False (default) to not check at all.
  
      check_rows: boolean (default: False)
          Set to an int `i` to check that input X has `i` columns. Set to
          False (default) to not check at all.
  
      fail_on_order: boolean (default: False)
          Set to True if you want the method to raise a ValueError if X is
          not of order `order`.
  
      force_contiguous: boolean (default: True)
          Set to True to force CumlArray produced to be contiguous. If `X` is
          non contiguous then a contiguous copy will be done.
          If False, and `X` doesn't need to be converted and is not
          contiguous, the underlying memory underneath the CumlArray will be
          non contiguous.  Only affects CAI inputs. Only affects CuPy and
          Numba device array views, all other input methods produce
          contiguous CumlArrays.
  
      Returns
      -------
      arr: CumlArray
  
          A new CumlArray
  
      """
      if convert_to_mem_type is None:
          convert_to_mem_type = GlobalSettings().memory_type
      else:
          convert_to_mem_type = (
              MemoryType.from_str(convert_to_mem_type)
              if convert_to_mem_type
              else convert_to_mem_type
          )
      if convert_to_dtype:
          convert_to_dtype = host_xpy.dtype(convert_to_dtype)
      # Provide fast-path for CumlArray input
      if (
          isinstance(X, CumlArray)
          and (
              not convert_to_mem_type
              or convert_to_mem_type == MemoryType.mirror
              or convert_to_mem_type == X.mem_type
          )
          and (not convert_to_dtype or convert_to_dtype == X.dtype)
          and (not force_contiguous or X.is_contiguous)
          and (order in ("K", None) or X.order == order)
          and not check_dtype
          and not check_mem_type
          and not check_cols
          and not check_rows
      ):
          if deepcopy:
              return copy.deepcopy(X)
          else:
              return X
  
      if isinstance(
          X,
          (
              DaskCudfSeries,
              DaskCudfDataFrame,
              DaskSeries,
              DaskDataFrame,
          ),
      ):
          # TODO: Warn, but not when using dask_sql
          X = X.compute()
  
      index = getattr(X, "index", None)
      if index is not None:
          if convert_to_mem_type is MemoryType.host and isinstance(
              index, CudfIndex
          ):
              index = index.to_pandas()
          elif convert_to_mem_type is MemoryType.device and isinstance(
              index, PandasIndex
          ):
              try:
                  index = CudfIndex.from_pandas(index)
              except TypeError:
                  index = CudfIndex(index)
  
      if isinstance(X, CudfSeries):
          if X.null_count != 0:
              raise ValueError(
                  "Error: cuDF Series has missing/null values, "
                  "which are not supported by cuML."
              )
  
      if isinstance(X, CudfDataFrame):
          X = X.to_cupy(copy=False)
      elif isinstance(X, (PandasDataFrame, PandasSeries)):
          X = X.to_numpy(copy=False)
      elif hasattr(X, "__dataframe__"):
          # temporarily use this codepath to avoid errors, substitute
          # usage of dataframe interchange protocol once ready.
          X = X.to_numpy()
          deepcopy = False
  
      requested_order = (order, None)[fail_on_order]
      arr = cls(X, index=index, order=requested_order, validate=False)
      if deepcopy:
          arr = copy.deepcopy(arr)
  
      if convert_to_mem_type == MemoryType.mirror:
          convert_to_mem_type = arr.mem_type
      if convert_to_dtype:
          convert_to_dtype = arr.mem_type.xpy.dtype(convert_to_dtype)
  
      conversion_required = (
          convert_to_dtype and (convert_to_dtype != arr.dtype)
      ) or (
          convert_to_mem_type and (convert_to_mem_type != arr.mem_type)
      )
  
      make_copy = False
      if conversion_required:
          convert_to_dtype = convert_to_dtype or None
          convert_to_mem_type = convert_to_mem_type or None
          if (
              safe_dtype_conversion
              and convert_to_dtype is not None
              and not arr.mem_type.xpy.can_cast(
                  arr.dtype, convert_to_dtype, casting="safe"
              )
          ):
              try:
                  target_dtype_range = arr.mem_type.xpy.iinfo(
                      convert_to_dtype
                  )
              except ValueError:
                  target_dtype_range = arr.mem_type.xpy.finfo(
                      convert_to_dtype
                  )
              if is_numba_array(X):
                  X = cp.asarray(X)
              if (
                  (X < target_dtype_range.min)
                  | (X > target_dtype_range.max)
              ).any():
                  raise TypeError(
                      "Data type conversion on values outside"
                      " representable range of target dtype"
                  )
          arr = cls(
              arr.to_output(
                  output_dtype=convert_to_dtype,
                  output_mem_type=convert_to_mem_type,
              ),
              order=requested_order,
              index=index,
              validate=False,
          )
  
      make_copy = force_contiguous and not arr.is_contiguous
  
      if (
          not fail_on_order and order != arr.order and order != "K"
      ) or make_copy:
          arr = cls(
              arr.mem_type.xpy.array(
                  arr.to_output("array"), order=order, copy=make_copy
              ),
              index=index,
          )
  
      n_rows = arr.shape[0]
  
      if len(arr.shape) > 1:
          n_cols = arr.shape[1]
      else:
          n_cols = 1
  
      if (n_cols == 1 or n_rows == 1) and len(arr.shape) == 2:
          order = "K"
  
      if order != "K" and arr.order != order:
          if order == "F":
              order_str = "column ('F')"
          elif order == "C":
              order_str = "row ('C')"
          else:
              order_str = f"UNKNOWN ('{order}')"
          if fail_on_order:
              raise ValueError(
                  f"Expected {order_str} major order but got something else."
              )
          else:
              debug(
                  f"Expected {order_str} major order but got something else."
                  " Converting data; this will result in additional memory"
                  " utilization."
              )
  
      if check_dtype:
          try:
              check_dtype = [
                  arr.mem_type.xpy.dtype(dtype) for dtype in check_dtype
              ]
          except TypeError:
              check_dtype = [arr.mem_type.xpy.dtype(check_dtype)]
  
          if arr.dtype not in check_dtype:
              raise TypeError(
                  f"Expected input to be of type in {check_dtype} but got"
                  f" {arr.dtype}"
              )
  
      if check_cols:
          if n_cols != check_cols:
              raise ValueError(
                  f"Expected {check_cols} columns but got {n_cols}"
                  " columns."
              )
  
      if check_rows:
          if n_rows != check_rows:
              raise ValueError(
                  f"Expected {check_rows} rows but got {n_rows}"
                  " rows."
              )
      return arr
  
imports: import copy
  import operator
  import pickle
  from cuml.internals.global_settings import GlobalSettings
  from cuml.internals.logger import debug
  from cuml.internals.mem_type import MemoryType, MemoryTypeError
  from cuml.internals.memory_utils import class_with_cupy_rmm, with_cupy_rmm
  from cuml.internals.safe_imports import cpu_only_import, cpu_only_import_from, gpu_only_import, gpu_only_import_from, null_decorator, return_false, safe_import, safe_import_from
  from typing import Tuple
label_desc: Use image node_id 48 for calling the CumlArray obj's underlying member method code with example usage: obj.from_input(cls, X, order, deepcopy, check_dtype, convert_to_dtype, check_mem_type, convert_to_mem_type, safe_dtype_conversion, check_cols, check_rows, fail_on_order, force_contiguous) and returns: arr, copy, X