-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconv2D_winograd_test.py
51 lines (43 loc) · 1.62 KB
/
conv2D_winograd_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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from log_utils import get_logger
from log_utils import set_up_logging
import logging
import unittest
import numpy as np
import torch
from torch import tensor
from conv2D_winograd import Winograd
"""
author: Adam Dziedzic [email protected]
"""
class TestPyTorchConv1d(unittest.TestCase):
def setUp(self):
log_file = "pytorch_conv2D_winograd.log"
is_debug = True
set_up_logging(log_file=log_file, is_debug=is_debug)
self.logger = get_logger(name=__name__)
self.logger.setLevel(logging.DEBUG)
self.logger.info("Set up test")
def testSimpleWinograd(self):
x = tensor([[[[1.0, 2.0, 3.0, -1.0],
[3.0, 4.0, 1.0, 2.0],
[1.0, 2.0, 1.0, -2.0],
[2.0, 1.0, -1.0, 2.0]]]])
# A single filter.
y = tensor([[[[1.0, 2.0, -1.0],
[3.0, 2.0, 1.0],
[4.0, 1.0, -2.0]]]])
expect = torch.nn.functional.conv2d(x, y)
result = Winograd.winograd_F_2_3(x, y)
np.testing.assert_array_almost_equal(
x=expect, y=result,
err_msg="The expected array x and computed y are not almost equal.")
def testWinograd(self):
x = torch.randint(-3, 3, (2, 3, 6, 6), dtype=torch.float)
y = torch.randint(-3, 3, (3, 3, 3, 3), dtype=torch.float)
expect = torch.nn.functional.conv2d(x, y)
result = Winograd.forward(x, y)
np.testing.assert_array_almost_equal(
x=expect, y=result,
err_msg="The expected array x and computed y are not almost equal.")
if __name__ == '__main__':
unittest.main()