def test_add_numpy_numpy_backward(self): x = np.random.randn(3, 3) y = np.random.randn(3, 1) f = lambda x, y: x + y self.assertTrue(gradient_check(f, x, y))
def test_mul_ndarray_ndarray_backward3(self): x = np.random.randn(3, 3) y = np.random.randn(3, 1) f = lambda x, y: x * y self.assertTrue(gradient_check(f, x, y))
def test_change_sign_of_numpy_when_backward(self): x = Variable(np.random.randn(5, 5)) f = lambda x: -x self.assertTrue(gradient_check(f, x))
def test_add_variable_ndarray_backward2(self): x = Variable(np.random.randn(3, 3)) y = np.random.randn(3, 1) f = lambda x, y: x + y self.assertTrue(gradient_check(f, x, y))
def test_pow_variable_backward2(self): x = Variable(np.random.randn(5, 5)) f = lambda x: x**3 self.assertTrue(gradient_check(f, x))
def test_div_variable_ndarray_backward(self): x0 = Variable(np.random.randn(3, 3)) x1 = np.random.randn(3, 3) f = lambda x, y: x / y self.assertTrue(gradient_check(f, x0, x1))
def test_sub_ndarray_variable_backward(self): x0 = np.random.randn(3, 3) x1 = Variable(np.random.randn(3, 3)) f = lambda x, y: x - y self.assertTrue(gradient_check(f, x0, x1))
def test_square_variable_backward2(self): x = Variable(np.random.randn(3)) self.assertTrue(gradient_check(F.square, x))
def test_exp_variable_backward1(self): x = Variable(np.random.randn(3, 3)) self.assertTrue(gradient_check(F.exp, x))