forked from WegraLee/deep-learning-from-scratch-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_transpose.py
29 lines (22 loc) · 816 Bytes
/
test_transpose.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
26
27
28
29
import unittest
import numpy as np
from dezero import Variable
import dezero.functions as F
from dezero.utils import gradient_check
class TestTranspose(unittest.TestCase):
def test_forward1(self):
x = Variable(np.array([[1, 2, 3], [4, 5, 6]]))
y = F.transpose(x)
self.assertEqual(y.shape, (3, 2))
def test_backward1(self):
x = np.array([[1, 2, 3], [4, 5, 6]])
self.assertTrue(gradient_check(F.transpose, x))
def test_backward2(self):
x = np.array([1, 2, 3])
self.assertTrue(gradient_check(F.transpose, x))
def test_backward3(self):
x = np.random.randn(10, 5)
self.assertTrue(gradient_check(F.transpose, x))
def test_backward4(self):
x = np.array([1, 2])
self.assertTrue(gradient_check(F.transpose, x))