code: def safe_mask(X, mask):
      """Return a mask which is safe to use on X.
  
      Parameters
      ----------
      X : {array-like, sparse matrix}
          Data on which to apply mask.
  
      mask: array
          Mask to be used on X.
  
      Returns
      -------
          mask
      """
      mask = np.asarray(mask)
      if np.issubdtype(mask.dtype, np.int):
          return mask
  
      if hasattr(X, "toarray"):
          ind = np.arange(mask.shape[0])
          mask = ind[mask]
      return mask
  
imports: from collections import Sequence
  import numpy
  from scipy.sparse import issparse
  import warnings
  from .murmurhash import murmurhash3_32
  from .validation import as_float_array, assert_all_finite, check_random_state, column_or_1d, check_array, check_consistent_length, check_X_y, indexable, check_symmetric
  from .deprecation import deprecated
  from .class_weight import compute_class_weight, compute_sample_weight
  from ..externals.joblib import cpu_count
  from ..exceptions import ConvergenceWarning
  from ..exceptions import DataConversionWarning
label_desc: Use image node_id 1 for calling a global function with example usage: safe_mask(X, mask) and returns: mask, mask