docstr: Test the single directional settings for chamfer_distance
  (point reduction = "mean" and batch_reduction="mean") but with heterogeneous
  pointclouds as input. Compare with the naive implementation of chamfer
  which supports heterogeneous pointcloud objects.
docstr_tok: ["Test","the","single","directional","settings","for","chamfer_distance","(","point","reduction","=","``","mean","''","and","batch_reduction=","''","mean","''",")","but","with","heterogeneous","pointclouds","as","input",".","Compare","with","the","naive","implementation","of","chamfer","which","supports","heterogeneous","pointcloud","objects","."]
code: def test_single_directional_chamfer_vs_naive_pointcloud(self):
      """
      Test the single directional settings for chamfer_distance
      (point reduction = "mean" and batch_reduction="mean") but with heterogeneous
      pointclouds as input. Compare with the naive implementation of chamfer
      which supports heterogeneous pointcloud objects.
      """
      N, max_P1, max_P2 = 3, 70, 70
      device = get_random_cuda_device()
  
      for norm in [1, 2]:
          for abs_cosine in [True, False]:
              points_normals = TestChamfer.init_pointclouds(
                  N, max_P1, max_P2, device
              )
              weights = points_normals.weights
              x_lengths = points_normals.p1_lengths
              y_lengths = points_normals.p2_lengths
  
              # Chamfer with tensors as input for heterogeneous pointclouds.
              cham_tensor, norm_tensor = chamfer_distance(
                  points_normals.p1,
                  points_normals.p2,
                  x_normals=points_normals.n1,
                  y_normals=points_normals.n2,
                  x_lengths=points_normals.p1_lengths,
                  y_lengths=points_normals.p2_lengths,
                  weights=weights,
                  norm=norm,
                  single_directional=True,
                  abs_cosine=abs_cosine,
              )
  
              # Chamfer with pointclouds as input.
              (
                  pred_loss,
                  pred_norm_loss,
              ) = TestChamfer.chamfer_distance_naive_pointclouds(
                  points_normals.cloud1,
                  points_normals.cloud2,
                  norm=norm,
                  device=device,
                  abs_cosine=abs_cosine,
              )
  
              # Mean reduction point loss.
              pred_loss[0] *= weights.view(N, 1)
              pred_loss_mean = pred_loss[0].sum(1) / x_lengths
              pred_loss_mean = pred_loss_mean.sum()
              pred_loss_mean /= weights.sum()
  
              # Mean reduction norm loss.
              pred_norm_loss[0] *= weights.view(N, 1)
              pred_norm_loss_mean = pred_norm_loss[0].sum(1) / x_lengths
              pred_norm_loss_mean = (
                  pred_norm_loss_mean.sum() / weights.sum()
              )
  
              self.assertClose(pred_loss_mean, cham_tensor)
              self.assertClose(pred_norm_loss_mean, norm_tensor)
  
              self._check_gradients(
                  cham_tensor,
                  norm_tensor,
                  pred_loss_mean,
                  pred_norm_loss_mean,
                  points_normals.cloud1.points_list(),
                  points_normals.p1,
                  points_normals.cloud2.points_list(),
                  points_normals.p2,
                  points_normals.cloud1.normals_list(),
                  points_normals.n1,
                  points_normals.cloud2.normals_list(),
                  points_normals.n2,
                  x_lengths,
                  y_lengths,
              )
  
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 7 for calling the TestChamfer obj's underlying member method code with example usage: obj.test_single_directional_chamfer_vs_naive_pointcloud() without return types