code: def drum_in_pattern_rate(pianoroll, beat_resolution, tolerance=0.1):
      
      if beat_resolution not in (4, 6, 8, 9, 12, 16, 18, 24):
          raise ValueError("Unsupported beat resolution. Only 4, 6, 8 ,9, 12, "
                           "16, 18, 42 are supported.")
      _validate_pianoroll(pianoroll)
  
      def _drum_pattern_mask(res, tol):
          """Return a drum pattern mask with the given tolerance."""
          if res == 24:
              drum_pattern_mask = np.tile([1., tol, 0., 0., 0., tol], 4)
          elif res == 12:
              drum_pattern_mask = np.tile([1., tol, tol], 4)
          elif res == 6:
              drum_pattern_mask = np.tile([1., tol, tol], 2)
          elif res == 18:
              drum_pattern_mask = np.tile([1., tol, 0., 0., 0., tol], 3)
          elif res == 9:
              drum_pattern_mask = np.tile([1., tol, tol], 3)
          elif res == 16:
              drum_pattern_mask = np.tile([1., tol, 0., tol], 4)
          elif res == 8:
              drum_pattern_mask = np.tile([1., tol], 4)
          elif res == 4:
              drum_pattern_mask = np.tile([1., tol], 2)
          return drum_pattern_mask
  
      drum_pattern_mask = _drum_pattern_mask(beat_resolution, tolerance)
      n_in_pattern = np.sum(drum_pattern_mask * np.count_nonzero(pianoroll, 1))
      return n_in_pattern / np.count_nonzero(pianoroll)
docs: Return the ratio of the number of drum notes that lie on the drum
      pattern (i.e., at certain time steps) to the total number of drum notes.