class_docstr: Class to build constraints from labeled data.
  
  See more in the :ref:`User Guide <supervised_version>`.
  
  Parameters
  ----------
  partial_labels : `numpy.ndarray` of ints, shape=(n_samples,)
    Array of labels, with -1 indicating unknown label.
  
  Attributes
  ----------
  partial_labels : `numpy.ndarray` of ints, shape=(n_samples,)
    Array of labels, with -1 indicating unknown label.
class_docstr_tok: ["Class","to","build","constraints","from","labeled","data",".","See","more","in","the",":","ref",":","`","User","Guide","<","supervised_version",">","`",".","Parameters","--","--","--","--","--","partial_labels",":","`","numpy.ndarray","`","of","ints",",","shape=","(","n_samples",",",")","Array","of","labels",",","with","-1","indicating","unknown","label",".","Attributes","--","--","--","--","--","partial_labels",":","`","numpy.ndarray","`","of","ints",",","shape=","(","n_samples",",",")","Array","of","labels",",","with","-1","indicating","unknown","label","."]
code: def _pairs(
      self,
      n_constraints,
      same_label=True,
      max_iter=10,
      random_state=np.random,
  ):
      (known_label_idx,) = np.where(self.partial_labels >= 0)
      known_labels = self.partial_labels[known_label_idx]
      num_labels = len(known_labels)
      ab = set()
      it = 0
      while it < max_iter and len(ab) < n_constraints:
          nc = n_constraints - len(ab)
          for aidx in random_state.randint(num_labels, size=nc):
              if same_label:
                  mask = known_labels[aidx] == known_labels
                  mask[aidx] = False  # avoid identity pairs
              else:
                  mask = known_labels[aidx] != known_labels
              (b_choices,) = np.where(mask)
              if len(b_choices) > 0:
                  ab.add((aidx, random_state.choice(b_choices)))
          it += 1
      if len(ab) < n_constraints:
          warnings.warn(
              "Only generated %d %s constraints (requested %d)"
              % (
                  len(ab),
                  "positive" if same_label else "negative",
                  n_constraints,
              )
          )
      ab = np.array(list(ab)[:n_constraints], dtype=int)
      return known_label_idx[ab.T]
  
file_path: metric-learn/metric_learn/constraints.py
imports: import numpy
  import warnings
  from sklearn.utils import check_random_state
  from sklearn.neighbors import NearestNeighbors
label_desc: Use image node_id 4 for calling the Constraints obj's underlying member method code with example usage: obj._pairs(n_constraints, same_label, max_iter, random_state) and returns: known_label_idx