pytorch3d/tests/test_mesh_rendering_utils.py
Patrick Labatut 3c71ab64cc Remove shebang line when not strictly required
Summary: The shebang line `#!<path to interpreter>` is only required for Python scripts, so remove it on source files for class or function definitions. Additionally explicitly mark as executable the actual Python scripts in the codebase.

Reviewed By: nikhilaravi

Differential Revision: D20095778

fbshipit-source-id: d312599fba485e978a243292f88a180d71e1b55a
2020-03-12 10:39:44 -07:00

24 lines
802 B
Python

# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import unittest
import torch
from pytorch3d.renderer.mesh.utils import _clip_barycentric_coordinates
class TestMeshRenderingUtils(unittest.TestCase):
def test_bary_clip(self):
N = 10
bary = torch.randn(size=(N, 3))
# randomly make some values negative
bary[bary < 0.3] *= -1.0
# randomly make some values be greater than 1
bary[bary > 0.8] *= 2.0
negative_mask = bary < 0.0
positive_mask = bary > 1.0
clipped = _clip_barycentric_coordinates(bary)
self.assertTrue(clipped[negative_mask].sum() == 0)
self.assertTrue(clipped[positive_mask].gt(1.0).sum() == 0)
self.assertTrue(torch.allclose(clipped.sum(dim=-1), torch.ones(N)))