-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.py
25 lines (19 loc) · 803 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import torch
import torch.cuda
from torch.autograd import Variable, gradcheck
import unittest
from functions.beta import Beta
from functions.digamma import Digamma
tensorType = torch.cuda.DoubleTensor
class TestDigammaGrads(unittest.TestCase):
def test_many_times(self):
input = (Variable(tensorType(50, 100).uniform_(), requires_grad=True),)
self.assertTrue(gradcheck(Digamma(), input, eps=1e-6, atol=1e-3))
class TestBetaGrads(unittest.TestCase):
def test_many_times(self):
a = Variable(tensorType(71, 23).uniform_() * 10, requires_grad=True)
b = Variable(tensorType(71, 23).uniform_() * 10, requires_grad=True)
result = gradcheck(Beta(), (a, b), eps=1e-6, atol=1e-3)
self.assertTrue(result)
if __name__ == '__main__':
unittest.main()