diff options
author | Ailing Zhang <ailzhang@fb.com> | 2019-03-19 20:02:29 -0700 |
---|---|---|
committer | Facebook Github Bot <facebook-github-bot@users.noreply.github.com> | 2019-03-19 20:09:17 -0700 |
commit | 8895bfba6aac8ca99c6d4483fa9b8b32c8a95c83 (patch) | |
tree | 1a2a2f2f4fc8c4c2a1e67ae7faaea21a92ce3802 /test/test_nn.py | |
parent | 3baf99bea7d66e03cacf6280de8e18cca9bfbdda (diff) | |
download | pytorch-8895bfba6aac8ca99c6d4483fa9b8b32c8a95c83.tar.gz pytorch-8895bfba6aac8ca99c6d4483fa9b8b32c8a95c83.tar.bz2 pytorch-8895bfba6aac8ca99c6d4483fa9b8b32c8a95c83.zip |
fix cosine_similarity (#18168)
Summary:
fixes #18057 according to colesbury 's suggestion. Thanks!
cc: ezyang
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18168
Differential Revision: D14520953
Pulled By: ailzhang
fbshipit-source-id: 970e6cfb482d857a81721ec1d0ee4a4df84a0450
Diffstat (limited to 'test/test_nn.py')
-rw-r--r-- | test/test_nn.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/test/test_nn.py b/test/test_nn.py index eafeddbe28..7965663883 100644 --- a/test/test_nn.py +++ b/test/test_nn.py @@ -5964,6 +5964,12 @@ class TestNN(NNTestCase): input2 = torch.randn(input_size, requires_grad=True) self.assertEqual(F.cosine_similarity(input1, input2, dim=1).size(), expected_size) + # Check numerical precision, issue #18057 + vv1 = torch.tensor(list([float(i) for i in range(84)])).unsqueeze(0) + vv2 = torch.tensor(list([float(i) for i in range(84)])).unsqueeze(0) + out = F.cosine_similarity(vv1, vv2) + self.assertLessEqual(out, 1.0) + def test_grid_sample_error_checking(self): input = torch.empty(1, 1, 2, 2) grid = torch.empty(1, 1, 1, 2) |