<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def calc_rr(qrs_locs, fs=None, min_rr=None, max_rr=None, qrs_units='samples', rr_units='samples'):
 """ Compute rr intervals from qrs indices by extracting the time differences. Parameters qrs_locs : numpy array 1d array of qrs locations. fs : float, optional Sampling frequency of the original signal. Needed if `qrs_units` does not match `rr_units`. min_rr : float, optional The minimum allowed rr interval. Values below this are excluded from the returned rr intervals. Units are in `rr_units`. max_rr : float, optional The maximum allowed rr interval. Values above this are excluded from the returned rr intervals. Units are in `rr_units`. qrs_units : str, optional The time unit of `qrs_locs`. Must be one of: 'samples', 'seconds'. rr_units : str, optional The desired time unit of the returned rr intervals in. Must be one of: 'samples', 'seconds'. Returns ------- rr : numpy array Array of rr intervals. """

    rr = np.diff(qrs_locs)

    # Empty input qrs_locs
    if not len(rr):
        return rr

    # Convert to desired output rr units if needed
    if qrs_units == 'samples' and rr_units == 'seconds':
        rr = rr / fs
    elif qrs_units == 'seconds' and rr_units == 'samples':
        rr = rr * fs

    # Apply rr interval filters
    if min_rr is not None:
        rr = rr[rr > min_rr]

    if max_rr is not None:
        rr = rr[rr < max_rr]

    return rr