code: def check_array(
      array,
      accept_sparse=False,
      accept_large_sparse=True,
      dtype="numeric",
      order=None,
      copy=False,
      force_all_finite=True,
      ensure_2d=True,
      allow_nd=False,
      ensure_min_samples=1,
      ensure_min_features=1,
      estimator=None,
  ) -> Tensor:
      """Input validation on a tensor, list, sparse matrix or similar.
  
      By default, the input is checked to be a non-empty 2D array containing
      only finite values. If the dtype of the tensor is object, attempt
      converting to float, raising on failure.
  
      Parameters
      ----------
      array : object
          Input object to check / convert.
  
      accept_sparse : string, boolean or list/tuple of strings (default=False)
          String[s] representing allowed sparse matrix formats, such as 'csc',
          'csr', etc. If the input is sparse but not in the allowed format,
          it will be converted to the first listed format. True allows the input
          to be any format. False means that a sparse matrix input will
          raise an error.
  
      accept_large_sparse : bool (default=True)
          If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by
          accept_sparse, accept_large_sparse=False will cause it to be accepted
          only if its indices are stored with a 32-bit dtype.
  
      dtype : string, type, list of types or None (default="numeric")
          Data type of result. If None, the dtype of the input is preserved.
          If "numeric", dtype is preserved unless array.dtype is object.
          If dtype is a list of types, conversion on the first type is only
          performed if the dtype of the input is not in the list.
  
      order : 'F', 'C' or None (default=None)
          Whether a tenor will be forced to be fortran or c-style.
          When order is None (default), then if copy=False, nothing is ensured
          about the memory layout of the output tensor; otherwise (copy=True)
          the memory layout of the returned tensor is kept as close as possible
          to the original tensor.
  
      copy : boolean (default=False)
          Whether a forced copy will be triggered. If copy=False, a copy might
          be triggered by a conversion.
  
      force_all_finite : boolean or 'allow-nan', (default=True)
          Whether to raise an error on np.inf and np.nan in tensor. The
          possibilities are:
  
          - True: Force all values of tensor to be finite.
          - False: accept both np.inf and np.nan in tensor.
          - 'allow-nan': accept only np.nan values in tensor. Values cannot
            be infinite.
  
          For object dtyped data, only np.nan is checked and not np.inf.
  
      ensure_2d : boolean (default=True)
          Whether to raise a value error if tensor is not 2D.
  
      allow_nd : boolean (default=False)
          Whether to allow tensor.ndim > 2.
  
      ensure_min_samples : int (default=1)
          Make sure that the tensor has a minimum number of samples in its first
          axis (rows for a 2D tensor). Setting to 0 disables this check.
  
      ensure_min_features : int (default=1)
          Make sure that the 2D tensor has some minimum number of features
          (columns). The default value of 1 rejects empty datasets.
          This check is only enforced when the input data has effectively 2
          dimensions or is originally 1D and ``ensure_2d`` is True. Setting to 0
          disables this check.
  
      estimator : str or estimator instance (default=None)
          If passed, include the name of the estimator in warning messages.
  
      Returns
      -------
      array_converted : object
          The converted and validated tensor.
      """
  
      # store whether originally we wanted numeric dtype
      dtype_numeric = isinstance(dtype, str) and dtype == "numeric"
  
      dtype_orig = getattr(array, "dtype", None)
      if not hasattr(dtype_orig, "kind"):
          # not a data type (e.g. a column named dtype in a pandas DataFrame)
          dtype_orig = None
  
      if dtype_numeric:
          if dtype_orig is not None and dtype_orig.kind == "O":
              # if input is object, convert to float.
              dtype = np.float64
          else:
              dtype = None
  
      if isinstance(dtype, (list, tuple)):
          if dtype_orig is not None and dtype_orig in dtype:
              # no dtype conversion required
              dtype = None
          else:
              # dtype conversion required. Let's select the first element of the
              # list of accepted types.
              dtype = dtype[0]
  
      if force_all_finite not in (True, False, "allow-nan"):
          raise ValueError(
              'force_all_finite should be a bool or "allow-nan"'
              f". Got {force_all_finite!r} instead"
          )
  
      if estimator is not None:
          if isinstance(estimator, str):
              estimator_name = estimator
          else:
              estimator_name = estimator.__class__.__name__
      else:
          estimator_name = "Estimator"
      context = f" by {estimator_name}" if estimator is not None else ""
  
      if (hasattr(array, "issparse") and array.issparse()) or issparse(
          array
      ):
          _ensure_no_complex_data(array)
          array = mt.asarray(array)
          array = _ensure_sparse_format(
              array,
              accept_sparse=accept_sparse,
              dtype=dtype,
              copy=copy,
              force_all_finite=force_all_finite,
              accept_large_sparse=accept_large_sparse,
          )
      else:
          # If np.array(..) gives ComplexWarning, then we convert the warning
          # to an error. This is needed because specifying a non complex
          # dtype to the function converts complex to real dtype,
          # thereby passing the test made in the lines following the scope
          # of warnings context manager.
          with warnings.catch_warnings():
              try:
                  warnings.simplefilter("error", ComplexWarning)
                  array = mt.asarray(array, dtype=dtype, order=order)
              except ComplexWarning:
                  raise ValueError(
                      f"Complex data not supported\n{array}\n"
                  )
  
          # It is possible that the np.array(..) gave no warning. This happens
          # when no dtype conversion happened, for example dtype = None. The
          # result is that np.array(..) produces an array of complex dtype
          # and we need to catch and raise exception for such cases.
          _ensure_no_complex_data(array)
  
          if ensure_2d:
              # If input is scalar raise error
              if array.ndim == 0:
                  raise ValueError(
                      f"Expected 2D array, got scalar array instead:\narray={array}.\n"
                      "Reshape your data either using array.reshape(-1, 1) if "
                      "your data has a single feature or array.reshape(1, -1) "
                      "if it contains a single sample."
                  )
              # If input is 1D raise error
              if array.ndim == 1:
                  raise ValueError(
                      f"Expected 2D array, got 1D array instead:\narray={array}.\n"
                      "Reshape your data either using array.reshape(-1, 1) if "
                      "your data has a single feature or array.reshape(1, -1) "
                      "if it contains a single sample."
                  )
  
          # in the future np.flexible dtypes will be handled like object dtypes
          if dtype_numeric and np.issubdtype(array.dtype, np.flexible):
              warnings.warn(
                  "Beginning in version 0.22, arrays of bytes/strings will be "
                  "converted to decimal numbers if dtype='numeric'. "
                  "It is recommended that you convert the array to "
                  "a float dtype before using it in scikit-learn, "
                  "for example by using "
                  "your_array = your_array.astype(np.float64).",
                  FutureWarning,
              )
  
          # make sure we actually converted to numeric:
          if dtype_numeric and array.dtype.kind == "O":
              array = array.astype(np.float64)
          if not allow_nd and array.ndim >= 3:
              raise ValueError(
                  "Found array with dim %d. %s expected <= 2."
                  % (array.ndim, estimator_name)
              )
          if force_all_finite:
              array = _assert_all_finite(
                  array,
                  allow_nan=force_all_finite == "allow-nan",
                  check_only=False,
              )
  
      if ensure_min_samples > 0:
          n_samples = _num_samples(array)
          if n_samples < ensure_min_samples:
              raise ValueError(
                  "Found array with %d sample(s) (shape=%s) while a"
                  " minimum of %d is required%s."
                  % (
                      n_samples,
                      array.shape,
                      ensure_min_samples,
                      context,
                  )
              )
  
      if ensure_min_features > 0 and array.ndim == 2:
          n_features = array.shape[1]
          if n_features < ensure_min_features:
              raise ValueError(
                  "Found array with %d feature(s) (shape=%s) while"
                  " a minimum of %d is required%s."
                  % (
                      n_features,
                      array.shape,
                      ensure_min_features,
                      context,
                  )
              )
  
      if copy:
          array = mt.array(array, dtype=dtype, order=order)
  
      return array
  
imports: import warnings
  import numbers
  import numpy
  from numpy.core.numeric import ComplexWarning
  from ...None import dataframe
  from ...None import tensor
  from ...core import ExecutableTuple
  from ...lib.sparse import issparse
  from ...tensor import Tensor
  from .checks import check_non_negative_then_return_value, assert_all_finite, AssertAllFinite
label_desc: Use image node_id 7 for calling a global function with example usage: check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator) and returns: array