0

While debugging a code, I came across something I couldn't explain; There was a method call without any name, only instance's name. Somewhere in the code instance is defined:

model = RadianceFieldRenderer(...)

The RadianceFieldRenderer class has two public methods:

def precache_rays(
        self,
        cache_cameras: List[CamerasBase],
        cache_camera_hashes: List[str],
    ):

and

def forward(
        self,
        camera_hash: Optional[str],
        camera: CamerasBase,
        image: torch.Tensor,
    ) -> Tuple[dict, dict]:

Here there is a call to forward() method without it's name:

nerf_out, metrics = model(
                camera_idx if cfg.data.precache_rays else None,
                camera,
                image,
            )

Does python infer which method I wish to call given the the number of arguments and returns?

Parham
  • 21
  • 2
  • 6
  • *"Does python infer which method I wish to call"* — Nope. `model(...)` calls `RadianceFieldRenderer.__call__`. Whatever *it* does depends on its implementation. – deceze Nov 30 '22 at 11:13

0 Answers0