code: def _num_samples(x):
      """Return number of samples in array-like x."""
      if hasattr(x, "fit") and callable(x.fit):
          # Don't get num_samples from an ensembles length!
          raise TypeError(
              f"Expected sequence or array-like, got estimator {x}"
          )
      if not hasattr(x, "__len__") and not hasattr(x, "shape"):
          if hasattr(x, "__array__"):
              x = mt.asarray(x)
          else:
              raise TypeError(
                  f"Expected sequence or array-like, got {type(x)}"
              )
      if hasattr(x, "shape"):
          if len(x.shape) == 0:
              if isinstance(x.op, AssertAllFinite):
                  x = x.op.x
              if hasattr(x.op, "data") and x.op.data is not None:
                  x = np.asarray(x.op.data)
              raise TypeError(
                  f"Singleton array {x!r} cannot be considered a valid collection."
              )
          # Check that shape is returning an integer or default to len
          if isinstance(x.shape[0], numbers.Integral):
              return x.shape[0]
          elif np.isnan(x.shape[0]):
              return x.shape[0]
          else:
              return len(x)
      else:
          return len(x)
  
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 1 for calling a global function with example usage: _num_samples(x) and returns: len, x, x, len