import math


def _get_burst_docids(dtd_matrix, burst_loc, burst_scale):
    """
    Given a burst and width of an event burst, retrieve all documents published within that burst, regardless of
    whether they actually concern any event.
    :param dtd_matrix: document-to-day matrix
    :param burst_loc: location of the burst
    :param burst_scale: scale of the burst
    :return: start day of the burst, end day of the burst, indices of documents within the burst
    """
    n_days = dtd_matrix.shape[1]

    # If an event burst starts right at day 0, this would get negative.
    burst_start = max(math.floor(burst_loc - burst_scale), 0)
    # If an event burst ends at stream length, this would exceed the boundary.
    burst_end = min(math.ceil(burst_loc + burst_scale), n_days - 1)

    # All documents published on burst days. There is exactly one '1' in every row.
    burst_docs, _ = dtd_matrix[:, burst_start:burst_end + 1].nonzero()

    return burst_start, burst_end, burst_docs