docstr: Test that filtering points with scaffold works.
  
  We define a scaffold and make the implicit function use it. We also
  define new density and color functions which check that all passed
  points are not in empty space (with scaffold function). In the end
  we compare the result from the implicit function with one calculated
  simple python, this checks that the points were merged correectly.
docstr_tok: ["Test","that","filtering","points","with","scaffold","works",".","We","define","a","scaffold","and","make","the","implicit","function","use","it",".","We","also","define","new","density","and","color","functions","which","check","that","all","passed","points","are","not","in","empty","space","(","with","scaffold","function",")",".","In","the","end","we","compare","the","result","from","the","implicit","function","with","one","calculated","simple","python",",","this","checks","that","the","points","were","merged","correectly","."]
code: def test_scaffold_filtering(self, n_test_points=100):
      """
      Test that filtering points with scaffold works.
  
      We define a scaffold and make the implicit function use it. We also
      define new density and color functions which check that all passed
      points are not in empty space (with scaffold function). In the end
      we compare the result from the implicit function with one calculated
      simple python, this checks that the points were merged correectly.
      """
      device = "cuda"
      func = self._get_simple_implicit_function().to(device)
  
      def scaffold(points):
          """'
          Function to deterministically and randomly enough assign a point
          to empty or occupied space.
          Return 1 if second digit of sum after 0 is odd else 0
          """
          return (
              (
                  (
                      points.sum(dim=-1, keepdim=True) * 10**2 % 10
                  ).long()
                  % 2
              )
              == 1
          ).float()
  
      def new_density(points):
          # check if all passed points should be passed here
          assert torch.all(scaffold(points)), (
              scaffold(points),
              points.shape,
          )
          return points.sum(dim=-1, keepdim=True)
  
      def new_color(
          points,
          camera,
          directions,
          non_empty_points,
          num_points_per_ray,
      ):
          # check if all passed points should be passed here
          assert torch.all(
              scaffold(points)
          )  # , (scaffold(points), points)
          return points * 2
  
      # check both computation paths that they contain only points
      # which are not in empty space
      func._get_density = new_density
      func._get_color = new_color
      func.voxel_grid_scaffold.forward = scaffold
      func._scaffold_ready = True
  
      bundle = ImplicitronRayBundle(
          origins=torch.rand((n_test_points, 2, 1, 3), device=device),
          directions=torch.rand(
              (n_test_points, 2, 1, 3), device=device
          ),
          lengths=torch.rand((n_test_points, 2, 1, 4), device=device),
          xys=None,
      )
      points = ray_bundle_to_ray_points(bundle)
      result_density, result_color, _ = func(bundle)
  
      # construct the wanted result 'by hand'
      flat_points = points.view(-1, 3)
      expected_result_density, expected_result_color = [], []
      for point in flat_points:
          if scaffold(point) == 1:
              expected_result_density.append(
                  point.sum(dim=-1, keepdim=True)
              )
              expected_result_color.append(point * 2)
          else:
              expected_result_density.append(point.new_zeros((1,)))
              expected_result_color.append(point.new_zeros((3,)))
      expected_result_density = torch.stack(
          expected_result_density, dim=0
      ).view(*points.shape[:-1], 1)
      expected_result_color = torch.stack(
          expected_result_color, dim=0
      ).view(*points.shape[:-1], 3)
  
      # check that thre result is expected
      assert torch.allclose(result_density, expected_result_density), (
          result_density,
          expected_result_density,
      )
      assert torch.allclose(result_color, expected_result_color), (
          result_color,
          expected_result_color,
      )
  
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 5 for calling the TestVoxelGridImplicitFunction obj's underlying member method code with example usage: obj.test_scaffold_filtering(n_test_points) and returns: unknown, points, unknown