def greedy_feedback(distmat, q_pids, g_pids, positive_indices, negative_indices, inplace=True):
    '\n    Update positive_indices, negative_indices with one round of feedback. Provide feedback for top-ranked gallery.\n    Note that distmat is corrupted if inplace=True.\n\n    :param distmat: q x g Tensor (adjusted query to gallery)\n    :param q_pids: q\n    :param g_pids: g\n    :param positive_indices: q x g\n    :param negative_indices: q x g\n    :return:\n    (positive_indices, negative_indices, matches)\n    '
    (q, g) = tuple(distmat.shape)
    if (not inplace):
        distmat = distmat.clone().detach()
        positive_indices = positive_indices.copy()
        negative_indices = negative_indices.copy()
    distmat[positive_indices] = float('inf')
    distmat[negative_indices] = float('inf')
    indices = distmat.argmin(dim=1)
    pmap = (g_pids[indices] == q_pids)
    positive_q = torch.arange(0, q)[pmap]
    negative_q = torch.arange(0, q)[(pmap == False)]
    positive_g = indices[pmap]
    negative_g = indices[(pmap == False)]
    existing = positive_indices[(positive_q, positive_g)]
    assert (not existing.any())
    positive_indices[(positive_q, positive_g)] = True
    existing = negative_indices[(negative_q, negative_g)]
    assert (not existing.any())
    negative_indices[(negative_q, negative_g)] = True
    return (positive_indices, negative_indices, pmap)
Update positive_indices, negative_indices with one round of feedback. Provide feedback for top-ranked gallery.
Note that distmat is corrupted if inplace=True.

:param distmat: q x g Tensor (adjusted query to gallery)
:param q_pids: q
:param g_pids: g
:param positive_indices: q x g
:param negative_indices: q x g
:return:
(positive_indices, negative_indices, matches)
def greedy_feedback(distmat, q_pids, g_pids, positive_indices, negative_indices, inplace=True):
    '\n    Update positive_indices, negative_indices with one round of feedback. Provide feedback for top-ranked gallery.\n    Note that distmat is corrupted if inplace=True.\n\n    :param distmat: q x g Tensor (adjusted query to gallery)\n    :param q_pids: q\n    :param g_pids: g\n    :param positive_indices: q x g\n    :param negative_indices: q x g\n    :return:\n    (positive_indices, negative_indices, matches)\n    '
    (q, g) = tuple(distmat.shape)
    if (not inplace):
        distmat = distmat.clone().detach()
        positive_indices = positive_indices.copy()
        negative_indices = negative_indices.copy()
    distmat[positive_indices] = float('inf')
    distmat[negative_indices] = float('inf')
    indices = distmat.argmin(dim=1)
    pmap = (g_pids[indices] == q_pids)
    positive_q = torch.arange(0, q)[pmap]
    negative_q = torch.arange(0, q)[(pmap == False)]
    positive_g = indices[pmap]
    negative_g = indices[(pmap == False)]
    existing = positive_indices[(positive_q, positive_g)]
    assert (not existing.any())
    positive_indices[(positive_q, positive_g)] = True
    existing = negative_indices[(negative_q, negative_g)]
    assert (not existing.any())
    negative_indices[(negative_q, negative_g)] = True
    return (positive_indices, negative_indices, pmap)