1from __future__ import absolute_import, print_function, division
2from theano.tensor.xlogx import xlogx, xlogy0
3
4import unittest
5
6import theano
7from theano.tensor import as_tensor_variable
8from . import test_basic as TT
9
10import random
11import numpy.random
12from theano.tests import unittest_tools as utt
13
14
15class T_XlogX(unittest.TestCase):
16    def setUp(self):
17        utt.seed_rng()
18
19    def test0(self):
20        x = as_tensor_variable([1, 0])
21        y = xlogx(x)
22        f = theano.function([], [y])
23        self.assertTrue(numpy.all(f() == numpy.asarray([0, 0.])))
24
25    def test1(self):
26        # class Dummy(object):
27        #     def make_node(self, a):
28        #         return [xlogx(a)[:,2]]
29        utt.verify_grad(xlogx, [numpy.random.rand(3, 4)])
30
31
32class T_XlogY0(unittest.TestCase):
33    def setUp(self):
34        utt.seed_rng()
35
36    def test2(self):
37        utt.verify_grad(xlogy0, [numpy.random.rand(3, 4), numpy.random.rand(3, 4)])
38
39    def test3(self):
40        x = as_tensor_variable([1, 0])
41        y = as_tensor_variable([1, 0])
42        z = xlogy0(x, y)
43        f = theano.function([], z)
44        self.assertTrue(numpy.all(f() == numpy.asarray([0, 0.])))
45
46
47if __name__ == '__main__':
48    unittest.main()
49