Skip to content

Commit 12cdb57

Browse files
committed
make pep happy
1 parent 3d350b7 commit 12cdb57

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

bnn/layers/conv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(
3535
def forward(self, input: torch.Tensor) -> torch.Tensor:
3636
input_proc = self.activation_pre_process(input)
3737
input_proc = self._conv_forward(input_proc, self.weight_pre_process(self.weight), bias=self.bias)
38-
38+
3939
return self.activation_post_process(
4040
input_proc,
4141
input
@@ -90,7 +90,7 @@ def __init__(
9090
def forward(self, input: torch.Tensor) -> torch.Tensor:
9191
input_proc = self.activation_pre_process(input)
9292
input_proc = self._conv_forward(input_proc, self.weight_pre_process(self.weight), bias=self.bias)
93-
93+
9494
return self.activation_post_process(
9595
input_proc,
9696
input

bnn/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.1.1'
1+
__version__ = '0.1.1'

test/smoke_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
import torch
2-
import bnn
2+
import bnn

test/test_layers.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
XNORWeightBinarizer
1212
)
1313

14+
1415
class BinaryLayersTestCase(unittest.TestCase):
1516
def setUp(self) -> None:
1617
self.test_bconfig = BConfig(
1718
activation_pre_process=BasicInputBinarizer,
1819
activation_post_process=BasicScaleBinarizer,
1920
weight_pre_process=XNORWeightBinarizer
2021
)
21-
self.data = torch.tensor([-0.05263, -0.05068, -0.03849, 0.03104, 0.0772, 0.03038, -0.06640, 0.05894,
22-
0.13059, 0.03433, -0.25811, 0.13785]).view(1, 3, 2, 2)
23-
self.weights = torch.tensor([-0.0252, 0.0084, -0.0676, 0.0891, -0.0010, 0.0518, 0.0380, 0.2866,
24-
-0.0050])
22+
self.data = torch.tensor([-0.05263, -0.05068, -0.03849, 0.03104, 0.0772, 0.03038, -0.06640, 0.05894,
23+
0.13059, 0.03433, -0.25811, 0.13785]).view(1, 3, 2, 2)
24+
self.weights = torch.tensor([-0.0252, 0.0084, -0.0676, 0.0891, -0.0010, 0.0518, 0.0380, 0.2866,
25+
-0.0050])
2526

2627
def tearDown(self) -> None:
2728
pass
@@ -31,38 +32,38 @@ def test_linear_layer(self):
3132
layer.weight.data.copy_(self.weights.view(3, 3))
3233
x = self.data[:, :, 0, 0].view(1, 3)
3334
layer = prepare_binary_model(layer, bconfig=self.test_bconfig)
34-
35+
3536
output = layer(x)
3637
expected = torch.tensor([[0.0337, -0.0473, -0.1099]])
3738
self.assertTrue(torch.allclose(expected, output, atol=1e-4))
38-
39+
3940
def test_conv1d_layer(self):
4041
layer = nn.Conv1d(3, 3, 1, bias=False)
4142
layer.weight.data.copy_(self.weights.view(3, 3, 1))
42-
x = self.data[:,:,:,0].view(1, 3, 2)
43+
x = self.data[:, :, :, 0].view(1, 3, 2)
4344
layer = prepare_binary_model(layer, bconfig=self.test_bconfig)
44-
45+
4546
output = layer(x)
46-
expected = torch.tensor([[[ 0.0337, 0.0337],
47-
[-0.0473, -0.0473],
48-
[-0.1099, -0.1099]]])
47+
expected = torch.tensor([[[0.0337, 0.0337],
48+
[-0.0473, -0.0473],
49+
[-0.1099, -0.1099]]])
4950
self.assertTrue(torch.allclose(expected, output, atol=1e-4))
50-
51+
5152
def test_conv2d_layer(self):
5253
layer = nn.Conv2d(3, 3, 1, bias=False)
5354
layer.weight.data.copy_(self.weights.view(3, 3, 1, 1))
5455
x = self.data
5556
layer = prepare_binary_model(layer, bconfig=self.test_bconfig)
56-
57+
5758
output = layer(x)
58-
expected = torch.tensor([[[[ 0.0337, 0.0337],
59-
[ 0.0337, -0.0337]],
59+
expected = torch.tensor([[[[0.0337, 0.0337],
60+
[0.0337, -0.0337]],
6061

61-
[[-0.0473, -0.0473],
62-
[-0.0473, 0.0473]],
62+
[[-0.0473, -0.0473],
63+
[-0.0473, 0.0473]],
6364

64-
[[-0.1099, -0.1099],
65-
[-0.1099, 0.1099]]]])
65+
[[-0.1099, -0.1099],
66+
[-0.1099, 0.1099]]]])
6667
self.assertTrue(torch.allclose(expected, output, atol=1e-4))
6768

6869

0 commit comments

Comments
 (0)