use assertClose

Summary: use assertClose in some tests, which enforces shape equality. Fixes some small problems, including graph_conv on an empty graph.

Reviewed By: nikhilaravi

Differential Revision: D20556912

fbshipit-source-id: 60a61eafe3c03ce0f6c9c1a842685708fb10ac5b
This commit is contained in:
Jeremy Reizenstein
2020-03-23 11:33:10 -07:00
committed by Facebook GitHub Bot
parent 744ef0c2c8
commit 595aca27ea
13 changed files with 216 additions and 241 deletions

View File

@@ -6,10 +6,11 @@ import torch
from pytorch3d.loss import mesh_edge_loss
from pytorch3d.structures import Meshes
from common_testing import TestCaseMixin
from test_sample_points_from_meshes import TestSamplePoints
class TestMeshEdgeLoss(unittest.TestCase):
class TestMeshEdgeLoss(TestCaseMixin, unittest.TestCase):
def test_empty_meshes(self):
device = torch.device("cuda:0")
target_length = 0
@@ -26,10 +27,8 @@ class TestMeshEdgeLoss(unittest.TestCase):
mesh = Meshes(verts=verts_list, faces=faces_list)
loss = mesh_edge_loss(mesh, target_length=target_length)
self.assertTrue(
torch.allclose(
loss, torch.tensor([0.0], dtype=torch.float32, device=device)
)
self.assertClose(
loss, torch.tensor([0.0], dtype=torch.float32, device=device)
)
self.assertTrue(loss.requires_grad)
@@ -94,7 +93,7 @@ class TestMeshEdgeLoss(unittest.TestCase):
loss = mesh_edge_loss(meshes, target_length=target_length)
predloss = TestMeshEdgeLoss.mesh_edge_loss_naive(meshes, target_length)
self.assertTrue(torch.allclose(loss, predloss))
self.assertClose(loss, predloss)
@staticmethod
def mesh_edge_loss(