class_docstr: Testing the _C.points_to_volumes function through its wrapper
  _points_to_volumes.
class_docstr_tok: ["Testing","the","_C.points_to_volumes","function","through","its","wrapper","_points_to_volumes","."]
docstr: Use gradcheck to verify the gradient of _points_to_volumes
  with random input.
docstr_tok: ["Use","gradcheck","to","verify","the","gradient","of","_points_to_volumes","with","random","input","."]
code: def do_gradcheck(self, device, splat: bool, align_corners: bool):
      """
      Use gradcheck to verify the gradient of _points_to_volumes
      with random input.
      """
      N, C, D, H, W, P = 2, 4, 5, 6, 7, 5
      points_3d = (
          torch.rand((N, P, 3), device=device, dtype=torch.float64)
          * 0.8
          + 0.1
      )
      points_features = torch.rand(
          (N, P, C), device=device, dtype=torch.float64
      )
      volume_densities = torch.zeros((N, 1, D, H, W), device=device)
      volume_features = torch.zeros((N, C, D, H, W), device=device)
      volume_densities_scale = torch.rand_like(volume_densities)
      volume_features_scale = torch.rand_like(volume_features)
      grid_sizes = torch.tensor(
          [D, H, W], dtype=torch.int64, device=device
      ).expand(N, 3)
      mask = torch.ones((N, P), device=device)
      mask[:, 0] = 0
      align_corners = False
  
      def f(points_3d_, points_features_):
          (volume_densities_, volume_features_) = _points_to_volumes(
              points_3d_.to(torch.float32),
              points_features_.to(torch.float32),
              volume_densities.clone(),
              volume_features.clone(),
              grid_sizes,
              2.0,
              mask,
              align_corners,
              splat,
          )
          density = (volume_densities_ * volume_densities_scale).sum()
          features = (volume_features_ * volume_features_scale).sum()
          return density, features
  
      base = f(points_3d.clone(), points_features.clone())
      self.assertGreater(base[0], 0)
      self.assertGreater(base[1], 0)
  
      points_features.requires_grad = True
      if splat:
          points_3d.requires_grad = True
          torch.autograd.gradcheck(
              f,
              (points_3d, points_features),
              check_undefined_grad=False,
              eps=2e-4,
              atol=0.01,
          )
      else:
          torch.autograd.gradcheck(
              partial(f, points_3d),
              points_features,
              check_undefined_grad=False,
              eps=2e-3,
              atol=0.001,
          )
  
imports: import unittest
  from functools import partial
  from itertools import product
  from typing import Tuple
  import numpy
  import torch
  from pytorch3d.ops import add_pointclouds_to_volumes, add_points_features_to_volume_densities_features
  from pytorch3d.ops.points_to_volumes import _points_to_volumes
  from pytorch3d.ops.sample_points_from_meshes import sample_points_from_meshes
  from pytorch3d.structures.meshes import Meshes
  from pytorch3d.structures.pointclouds import Pointclouds
  from pytorch3d.structures.volumes import Volumes
  from pytorch3d.transforms.so3 import so3_exp_map
  from .common_testing import TestCaseMixin
label_desc: Use image node_id 10 for calling the TestRawFunction obj's underlying member method code with example usage: obj.do_gradcheck(device, splat, align_corners) and returns: density,  features