code: def sample(self, ctrs, rstate=None, return_q=False, kdtree=None):
          
  
          if rstate is None:
              rstate = np.random
  
          nctrs = len(ctrs)  # number of cubes
  
          # If there is only one cube, sample from it.
          if nctrs == 1:
              dx = self.hside * (2. * rstate.rand(self.n) - 1.)
              x = ctrs[0] + dx
              if return_q:
                  return x, 1
              else:
                  return x
  
          # Select a cube at random.
          idx = rstate.randint(nctrs)
  
          # Select a point from the chosen cube.
          dx = self.hside * (2. * rstate.rand(self.n) - 1.)
          x = ctrs[idx] + dx
  
          # Check how many cubes the point lies within, passing over
          # the `idx`-th cube `x` was sampled from.
          q = self.overlap(x, ctrs, kdtree=kdtree)
  
          if return_q:
              # If `q` is being returned, assume the user wants to
              # explicitly apply the `1. / q` acceptance criterion to
              # properly sample from the union of balls.
              return x, q
          else:
              # If `q` is not being returned, assume the user wants this
              # done internally.
              while rstate.rand() > (1. / q):
                  idx = rstate.randint(nctrs)
                  dx = self.hside * (2. * rstate.rand(self.n) - 1.)
                  x = ctrs[idx] + dx
                  q = self.overlap(x, ctrs, kdtree=kdtree)
              return x
docs: Sample a point uniformly distributed within the *union* of cubes.
          Uses a K-D Tree to perform the search if provided.
  
          Returns
          -------
          x : `~numpy.ndarray` with shape (ndim,)
              A coordinate within the set of cubes.
  
          q : int, optional
              The number of cubes `x` falls within.