docstr: Test calculating the scaffold.
  
  We define a custom density function and make the implicit function use it
  After calculating the scaffold we compare the density of our custom
  density function with densities from the scaffold.
docstr_tok: ["Test","calculating","the","scaffold",".","We","define","a","custom","density","function","and","make","the","implicit","function","use","it","After","calculating","the","scaffold","we","compare","the","density","of","our","custom","density","function","with","densities","from","the","scaffold","."]
code: def test_scaffold_formation(self):
      """
      Test calculating the scaffold.
  
      We define a custom density function and make the implicit function use it
      After calculating the scaffold we compare the density of our custom
      density function with densities from the scaffold.
      """
      device = "cuda" if torch.cuda.is_available() else "cpu"
      func = self._get_simple_implicit_function().to(device)
      func.scaffold_max_pool_kernel_size = 1
  
      def new_density(points):
          """
          Density function which returns 1 if p>(0.5, 0.5, 0.5) or
          p < (-0.5, -0.5, -0.5) else 0
          """
          inshape = points.shape
          points = points.view(-1, 3)
          out = []
          for p in points:
              if torch.all(p > 0.5) or torch.all(p < -0.5):
                  out.append(torch.tensor([[1.0]]))
              else:
                  out.append(torch.tensor([[0.0]]))
          return torch.cat(out).view(*inshape[:-1], 1).to(device)
  
      func._get_density = new_density
      func._get_scaffold(0)
  
      points = torch.tensor(
          [
              [0, 0, 0],
              [1, 1, 1],
              [1, 0, 0],
              [0.1, 0, 0],
              [10, 1, -1],
              [-0.8, -0.7, -0.9],
          ]
      ).to(device)
      expected = new_density(points).float().to(device)
      assert torch.allclose(
          func.voxel_grid_scaffold(points), expected
      ), (
          func.voxel_grid_scaffold(points),
          expected,
      )
  
file_path: pytorch3d/tests/implicitron/test_voxel_grid_implicit_function.py
imports: import unittest
  import torch
  from omegaconf import DictConfig, OmegaConf
  from pytorch3d.implicitron.models.implicit_function.voxel_grid_implicit_function import VoxelGridImplicitFunction
  from pytorch3d.implicitron.models.renderer.base import ImplicitronRayBundle
  from pytorch3d.implicitron.tools.config import expand_args_fields, get_default_args
  from pytorch3d.renderer import ray_bundle_to_ray_points
  from tests.common_testing import TestCaseMixin
label_desc: Use image node_id 4 for calling the TestVoxelGridImplicitFunction obj's underlying member method code with example usage: obj.test_scaffold_formation() and returns: torch