def aggregate_multiview_features(self, multiview_features, multiview_masks):
        """
        aggregate mutli-view features by compute their cost variance
        :param multiview_features: (num of voxels, num_of_views, c)
        :param multiview_masks: (num of voxels, num_of_views)
        :return:
        """
        num_pts, n_views, C = multiview_features.shape

        counts = torch.sum(multiview_masks, dim=1, keepdim=False)  # [num_pts]

        assert torch.all(counts > 0)  # the point is visible for at least 1 view

        volume_sum = torch.sum(multiview_features, dim=1, keepdim=False)  # [num_pts, C]
        volume_sq_sum = torch.sum(multiview_features ** 2, dim=1, keepdim=False)

        if volume_sum.isnan().sum() > 0:
            import ipdb; ipdb.set_trace()

        del multiview_features

        counts = 1. / (counts + 1e-5)
        costvar = volume_sq_sum * counts[:, None] - (volume_sum * counts[:, None]) ** 2

        costvar_mean = torch.cat([costvar, volume_sum * counts[:, None]], dim=1)
        del volume_sum, volume_sq_sum, counts



        return costvar_mean

        aggregate mutli-view features by compute their cost variance
        :param multiview_features: (num of voxels, num_of_views, c)
        :param multiview_masks: (num of voxels, num_of_views)
        :return:
        
mv-diffusion/One-2-3-45-by-view/reconstruction/models/sparse_sdf_network.py