import torch


def monte_carlo_pose_loss(pose_sample_logweights, cost_target):
    """
    Args:
        pose_sample_logweights: Shape (mc_samples, num_obj)
        cost_target: Shape (num_obj, )

    Returns:
        Tensor: Shape (num_obj, )
    """
    loss_tgt = cost_target
    loss_pred = torch.logsumexp(pose_sample_logweights, dim=0)  # (num_obj, )

    loss_pose = loss_tgt + loss_pred  # (num_obj, )
    loss_pose[loss_pose.isnan()] = 0
    return loss_pose