From b538f107964964d7e5c67f81dcc9e42b13acbc25 Mon Sep 17 00:00:00 2001 From: Jeremy Reizenstein Date: Thu, 22 Apr 2021 07:08:52 -0700 Subject: [PATCH] Avoid temporary arrays in _check_density_bounds Summary: We can check the bounds without using extra memory. This produces a small speedup in NeRF training (like 0.5%). Reviewed By: nikhilaravi Differential Revision: D27859691 fbshipit-source-id: d566420c465f51231f4a57438084c98b73253046 --- pytorch3d/renderer/implicit/raymarching.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pytorch3d/renderer/implicit/raymarching.py b/pytorch3d/renderer/implicit/raymarching.py index bafb7da9..2163c816 100644 --- a/pytorch3d/renderer/implicit/raymarching.py +++ b/pytorch3d/renderer/implicit/raymarching.py @@ -177,12 +177,12 @@ def _check_density_bounds( Checks whether the elements of `rays_densities` range within `bounds`. If not issues a warning. """ - # pyre-fixme[16]: `ByteTensor` has no attribute `any`. - if ((rays_densities > bounds[1]) | (rays_densities < bounds[0])).any(): - warnings.warn( - "One or more elements of rays_densities are outside of valid" - + f"range {str(bounds)}" - ) + with torch.no_grad(): + if (rays_densities.max() > bounds[1]) or (rays_densities.min() < bounds[0]): + warnings.warn( + "One or more elements of rays_densities are outside of valid" + + f"range {str(bounds)}" + ) def _check_raymarcher_inputs(