code: def discard(samples, chains):
      
      samples = np.asarray(samples)
      if samples.ndim != 2:
          raise ValueError("expected samples to be a numpy 2D array")
  
      num_samples, num_variables = samples.shape
      num_chains = len(chains)
  
      broken = broken_chains(samples, chains)
  
      unbroken_idxs, = np.where(~broken.any(axis=1))
  
      chain_variables = np.fromiter((np.asarray(tuple(chain))[0] if isinstance(chain, set) else np.asarray(chain)[0]
                                     for chain in chains),
                                    count=num_chains, dtype=int)
  
      return samples[np.ix_(unbroken_idxs, chain_variables)], unbroken_idxs
docs: Discard broken chains.
  
      Args:
          samples (array_like):
              Samples as a nS x nV array_like object where nS is the number of samples and nV is the
              number of variables. The values should all be 0/1 or -1/+1.
  
          chains (list[array_like]):
              List of chains of length nC where nC is the number of chains.
              Each chain should be an array_like collection of column indices in samples.
  
      Returns:
          tuple: A 2-tuple containing:
  
              :obj:`numpy.ndarray`: An array of unembedded samples. Broken chains are discarded. The
              array has dtype 'int8'.
  
              :obj:`numpy.ndarray`: The indicies of the rows with unbroken chains.
  
      Examples:
          This example unembeds two samples that chains nodes 0 and 1 to represent a single source
          node. The first sample has an unbroken chain, the second a broken chain.
  
          >>> import dimod
          >>> import numpy as np
          ...
          >>> chains = [(0, 1), (2,)]
          >>> samples = np.array([[1, 1, 0], [1, 0, 0]], dtype=np.int8)
          >>> unembedded, idx = dwave.embedding.discard(samples, chains)
          >>> unembedded
          array([[1, 0]], dtype=int8)
          >>> idx
          array([0])