Skip to content

Commit

Permalink
Attempt to test for #4
Browse files Browse the repository at this point in the history
PyTorch's boolean comparison crap isn't useful and makes
  it a pain to test exact tensor values.
* Will resume later
  • Loading branch information
stephenjfox committed Feb 18, 2019
1 parent 24bb995 commit 76e101d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions morph/layers/sparse_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from unittest import main as test_main, TestCase

from .sparse import sparsify, torch

class TestSparseFunctions(TestCase):

def test_sparsify_selected_indices_should_have_sub_threshold_values(self):
test_threshold = 0.1
test_tensor = torch.randn(3, 2)
expected = torch.where(test_tensor > test_threshold, test_tensor, torch.zeros(3, 2))
self.assertEqual(expected, sparsify(test_tensor, test_threshold))


if __name__ == "__main__":
test_main()

0 comments on commit 76e101d

Please sign in to comment.