mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-11 02:24:38 +08:00
Use torch.where for faster contract (#1132)
use where for faster contract
This commit is contained in:
parent
d51718ec2b
commit
bc690632bb
@ -65,12 +65,8 @@ class SceneContraction(SpatialDistortion):
|
||||
|
||||
def forward(self, positions):
|
||||
def contract(x):
|
||||
mag = torch.linalg.norm(x, ord=self.order, dim=-1)
|
||||
mask = mag >= 1
|
||||
x_new = x.clone()
|
||||
x_new[mask] = (2 - (1 / mag[mask][..., None])) * (x[mask] / mag[mask][..., None])
|
||||
|
||||
return x_new
|
||||
mag = torch.linalg.norm(x, ord=self.order, dim=-1)[..., None]
|
||||
return torch.where(mag < 1, x, (2 - (1 / mag)) * (x / mag))
|
||||
|
||||
if isinstance(positions, Gaussians):
|
||||
means = contract(positions.mean.clone())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user