def compute_z_diff(self, xyz, w2cs, intrinsics, pred_depth_values):
        """
        compute the depth difference of query pts projected on the image and the predicted depth values of the image
        :param xyz:  [N_rays, n_samples,3 ]
        :param w2cs:  [N_views, 4, 4]
        :param intrinsics: [N_views, 3, 3]
        :param pred_depth_values: [N_views, N_rays, n_samples,1 ]
        :param pred_depth_masks: [N_views, N_rays, n_samples]
        :return:
        """
        device = xyz.device
        N_views = w2cs.shape[0]
        N_rays, n_samples, _ = xyz.shape
        proj_matrix = torch.matmul(intrinsics, w2cs[:, :3, :])

        proj_rot = proj_matrix[:, :3, :3]
        proj_trans = proj_matrix[:, :3, 3:]

        batch_xyz = xyz.permute(2, 0, 1).contiguous().view(1, 3, N_rays * n_samples).repeat(N_views, 1, 1)

        proj_xyz = proj_rot.bmm(batch_xyz) + proj_trans

        # X = proj_xyz[:, 0]
        # Y = proj_xyz[:, 1]
        Z = proj_xyz[:, 2].clamp(min=1e-3)  # [N_views, N_rays*n_samples]
        proj_z = Z.view(N_views, N_rays, n_samples, 1)

        z_diff = proj_z - pred_depth_values  # [N_views, N_rays, n_samples,1 ]

        return z_diff

        compute the depth difference of query pts projected on the image and the predicted depth values of the image
        :param xyz:  [N_rays, n_samples,3 ]
        :param w2cs:  [N_views, 4, 4]
        :param intrinsics: [N_views, 3, 3]
        :param pred_depth_values: [N_views, N_rays, n_samples,1 ]
        :param pred_depth_masks: [N_views, N_rays, n_samples]
        :return:
        
mv-diffusion/One-2-3-45-by-view/reconstruction/models/projector.py