Skip to content

Commit 229472b

Browse files
author
Roy Li
committed
add tests
1 parent 22df924 commit 229472b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/test_nn.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4116,6 +4116,16 @@ def func(root):
41164116
gradcheck(func, [v])
41174117
gradgradcheck(func, [v])
41184118

4119+
def test_bce_loss_always_nonnegative(self):
4120+
target = torch.ones(5)
4121+
input = torch.ones(5)
4122+
assert ((nn.BCELoss()(input,target) < 0).sum() == 0)
4123+
4124+
target = torch.zeros(5)
4125+
input = torch.zeros(5)
4126+
print((nn.BCELoss()(input,target) < 0).sum)
4127+
assert ((nn.BCELoss()(input,target) < 0).sum() == 0)
4128+
41194129
def test_bce_with_logits_raises_if_target_and_input_are_different_size(self):
41204130
target = torch.rand(5)
41214131
input = torch.rand(5, 1)

0 commit comments

Comments
 (0)