Skip to content

Commit

Permalink
Merge pull request #13 from tfjgeorge/pvector_nobias
Browse files Browse the repository at this point in the history
fixes PVector bug when no bias, adds test
  • Loading branch information
tfjgeorge committed Mar 5, 2021
2 parents bf1fca3 + 965efc7 commit 911e55f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions nngeometry/object/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def random_pvector_dict(layer_collection, device=None):
v_dict[layer_id] = (torch.normal(0, 1, layer.weight.size, device=device),
torch.normal(0, 1, layer.bias.size, device=device))
else:
v_dict[layer_id] = (torch.normal(0, 1, layer.weight.size, device=device))
v_dict[layer_id] = (torch.normal(0, 1, layer.weight.size, device=device),)
return PVector(layer_collection, dict_repr=v_dict)


Expand Down Expand Up @@ -216,7 +216,7 @@ def norm(self, p=2):
sum_p = 0
for l_id, l in self.layer_collection.layers.items():
sum_p += (self.dict_repr[l_id][0]**p).sum()
if l.bias:
if l.bias is not None:
sum_p += (self.dict_repr[l_id][1]**p).sum()
return sum_p ** (1/p)
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ConvNet(nn.Module):
def __init__(self):
super(ConvNet, self).__init__()
self.conv1 = nn.Conv2d(1, 5, 3, 1)
self.conv2 = nn.Conv2d(5, 6, 4, 1)
self.conv2 = nn.Conv2d(5, 6, 4, 1, bias=False)
self.conv3 = nn.Conv2d(6, 7, 3, 1)
self.fc1 = nn.Linear(1*1*7, 10)

Expand Down

0 comments on commit 911e55f

Please sign in to comment.