def METHOD_NAME(labels, embedding, margin):
    num_data = embedding.shape[0]
    # Reshape labels to compute adjacency matrix.
    labels_reshaped = np.reshape(labels, (labels.shape[0], 1))
    adjacency = np.equal(labels_reshaped, labels_reshaped.T)
    pdist_matrix = pairwise_distance_np(embedding)
    loss_np = 0.0
    num_constraints = 0.0
    for i in range(num_data):
        for j in range(num_data):
            if adjacency[i][j] > 0.0 and i != j:
                d_pos = pdist_matrix[i][j]
                negs = []
                for k in range(num_data):
                    if not adjacency[i][k]:
                        negs.append(margin - pdist_matrix[i][k])
                for m in range(num_data):
                    if not adjacency[j][m]:
                        negs.append(margin - pdist_matrix[j][m])
                negs = np.array(negs)
                max_elem = np.max(negs)
                negs -= max_elem
                negs = np.exp(negs)
                soft_maximum = np.log(np.sum(negs)) + max_elem
                num_constraints += 1.0
                this_loss = max(soft_maximum + d_pos, 0)
                loss_np += this_loss * this_loss
    loss_np = loss_np / num_constraints / 2.0
    return loss_np