code: def _check_sample_weight(sample_weight, X, dtype=None):
      """Validate sample weights.
  
      Note that passing sample_weight=None will output an array of ones.
      Therefore, in some cases, you may want to protect the call with:
      if sample_weight is not None:
          sample_weight = _check_sample_weight(...)
  
      Parameters
      ----------
      sample_weight : {ndarray, Number or None}, shape (n_samples,)
         Input sample weights.
  
      X : nd-array, list or sparse matrix
          Input data.
  
      dtype: dtype
         dtype of the validated `sample_weight`.
         If None, and the input `sample_weight` is an array, the dtype of the
         input is preserved; otherwise an array with the default numpy dtype
         is be allocated.  If `dtype` is not one of `float32`, `float64`,
         `None`, the output will be of dtype `float64`.
  
      Returns
      -------
      sample_weight : ndarray, shape (n_samples,)
         Validated sample weight. It is guaranteed to be "C" contiguous.
      """
      n_samples = _num_samples(X)
  
      if dtype is not None and dtype not in [np.float32, np.float64]:
          dtype = np.float64
  
      if sample_weight is None or isinstance(
          sample_weight, numbers.Number
      ):
          if sample_weight is None:
              sample_weight = mt.ones(n_samples, dtype=dtype)
          else:
              sample_weight = mt.full(
                  n_samples, sample_weight, dtype=dtype
              )
      else:
          if dtype is None:
              dtype = [np.float64, np.float32]
          sample_weight = check_array(
              sample_weight,
              accept_sparse=False,
              ensure_2d=False,
              dtype=dtype,
              order="C",
          )
          if sample_weight.ndim != 1:
              raise ValueError(
                  "Sample weights must be 1D array or scalar"
              )
  
          if sample_weight.shape != (n_samples,):
              raise ValueError(
                  f"sample_weight.shape == {sample_weight.shape}, "
                  f"expected {(n_samples,)}!"
              )
      return sample_weight
  
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 11 for calling a global function with example usage: _check_sample_weight(sample_weight, X, dtype) and returns: sample_weight