docstr: Compare output of vectorized chamfer loss with naive implementation
  for point_reduction = "mean" and batch_reduction = None.
docstr_tok: ["Compare","output","of","vectorized","chamfer","loss","with","naive","implementation","for","point_reduction","=","``","mean","''","and","batch_reduction","=","None","."]
code: def test_chamfer_point_reduction_mean(self):
      """
      Compare output of vectorized chamfer loss with naive implementation
      for point_reduction = "mean" and batch_reduction = None.
      """
      N, max_P1, max_P2 = 7, 10, 18
      device = get_random_cuda_device()
      points_normals = TestChamfer.init_pointclouds(
          N, max_P1, max_P2, device
      )
      p1 = points_normals.p1
      p2 = points_normals.p2
      p1_normals = points_normals.n1
      p2_normals = points_normals.n2
      weights = points_normals.weights
      p11 = p1.detach().clone()
      p22 = p2.detach().clone()
      p11.requires_grad = True
      p22.requires_grad = True
      P1 = p1.shape[1]
      P2 = p2.shape[1]
  
      pred_loss, pred_loss_norm = TestChamfer.chamfer_distance_naive(
          p1, p2, x_normals=p1_normals, y_normals=p2_normals
      )
  
      # point_reduction = "mean".
      loss, loss_norm = chamfer_distance(
          p11,
          p22,
          x_normals=p1_normals,
          y_normals=p2_normals,
          weights=weights,
          batch_reduction=None,
          point_reduction="mean",
      )
      pred_loss_mean = (
          pred_loss[0].sum(1) / P1 + pred_loss[1].sum(1) / P2
      )
      pred_loss_mean *= weights
      self.assertClose(loss, pred_loss_mean)
  
      pred_loss_norm_mean = (
          pred_loss_norm[0].sum(1) / P1 + pred_loss_norm[1].sum(1) / P2
      )
      pred_loss_norm_mean *= weights
      self.assertClose(loss_norm, pred_loss_norm_mean)
  
      # Check gradients
      self._check_gradients(
          loss,
          loss_norm,
          pred_loss_mean,
          pred_loss_norm_mean,
          p1,
          p11,
          p2,
          p22,
      )
  
imports: import unittest
  from collections import namedtuple
  import numpy
  import torch
  import torch.nn.functional
  from pytorch3d.loss import chamfer_distance
  from pytorch3d.structures.pointclouds import Pointclouds
  from .common_testing import get_random_cuda_device, TestCaseMixin
label_desc: Use image node_id 10 for calling the TestChamfer obj's underlying member method code with example usage: obj.test_chamfer_point_reduction_mean() without return types