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
This commit is contained in:
Jeremy Reizenstein 2021-04-22 07:08:52 -07:00 committed by Facebook GitHub Bot
parent 04d318d88f
commit b538f10796

View File

@ -177,12 +177,12 @@ def _check_density_bounds(
Checks whether the elements of `rays_densities` range within `bounds`. Checks whether the elements of `rays_densities` range within `bounds`.
If not issues a warning. If not issues a warning.
""" """
# pyre-fixme[16]: `ByteTensor` has no attribute `any`. with torch.no_grad():
if ((rays_densities > bounds[1]) | (rays_densities < bounds[0])).any(): if (rays_densities.max() > bounds[1]) or (rays_densities.min() < bounds[0]):
warnings.warn( warnings.warn(
"One or more elements of rays_densities are outside of valid" "One or more elements of rays_densities are outside of valid"
+ f"range {str(bounds)}" + f"range {str(bounds)}"
) )
def _check_raymarcher_inputs( def _check_raymarcher_inputs(