mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-01 13:28:59 +08:00
Use torch.where for faster contract (#1132)
use where for faster contract
This commit is contained in:
1 file changed
+2
-6
@@ -65,12 +65,8 @@ class SceneContraction(SpatialDistortion):
|
|||||||
|
|
||||||
def forward(self, positions):
|
def forward(self, positions):
|
||||||
def contract(x):
|
def contract(x):
|
||||||
mag = torch.linalg.norm(x, ord=self.order, dim=-1)
|
mag = torch.linalg.norm(x, ord=self.order, dim=-1)[..., None]
|
||||||
mask = mag >= 1
|
return torch.where(mag < 1, x, (2 - (1 / mag)) * (x / mag))
|
||||||
x_new = x.clone()
|
|
||||||
x_new[mask] = (2 - (1 / mag[mask][..., None])) * (x[mask] / mag[mask][..., None])
|
|
||||||
|
|
||||||
return x_new
|
|
||||||
|
|
||||||
if isinstance(positions, Gaussians):
|
if isinstance(positions, Gaussians):
|
||||||
means = contract(positions.mean.clone())
|
means = contract(positions.mean.clone())
|
||||||
|
|||||||
Reference in new issue
Block a user