Fix Codacy Warnings (#477)
--------- Co-authored-by: Dario Coscia <dariocos99@gmail.com>
This commit is contained in:
committed by
Nicola Demo
parent
e3790e049a
commit
4177bfbb50
@@ -8,10 +8,11 @@ list_matrices = [
|
||||
torch.randn(10, 3),
|
||||
torch.rand(100, 5),
|
||||
torch.randn(5, 5),
|
||||
]
|
||||
]
|
||||
|
||||
list_prohibited_matrices_dim0 = list_matrices[:-1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("dim", [-1, 0, 1, None])
|
||||
@pytest.mark.parametrize("requires_grad", [True, False, None])
|
||||
def test_constructor(dim, requires_grad):
|
||||
@@ -29,11 +30,13 @@ def test_constructor(dim, requires_grad):
|
||||
if requires_grad is not None:
|
||||
assert block.requires_grad == requires_grad
|
||||
|
||||
|
||||
def test_wrong_constructor():
|
||||
with pytest.raises(IndexError):
|
||||
OrthogonalBlock(2)
|
||||
OrthogonalBlock(2)
|
||||
with pytest.raises(ValueError):
|
||||
OrthogonalBlock('a')
|
||||
OrthogonalBlock("a")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("V", list_matrices)
|
||||
def test_forward(V):
|
||||
@@ -42,7 +45,10 @@ def test_forward(V):
|
||||
V_orth = orth(V)
|
||||
V_orth_row = orth_row(V.T)
|
||||
assert torch.allclose(V_orth.T @ V_orth, torch.eye(V.shape[1]), atol=1e-6)
|
||||
assert torch.allclose(V_orth_row @ V_orth_row.T, torch.eye(V.shape[1]), atol=1e-6)
|
||||
assert torch.allclose(
|
||||
V_orth_row @ V_orth_row.T, torch.eye(V.shape[1]), atol=1e-6
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("V", list_matrices)
|
||||
def test_backward(V):
|
||||
@@ -51,6 +57,7 @@ def test_backward(V):
|
||||
loss = V_orth.mean()
|
||||
loss.backward()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("V", list_matrices)
|
||||
def test_wrong_backward(V):
|
||||
orth = OrthogonalBlock(requires_grad=False)
|
||||
@@ -59,10 +66,10 @@ def test_wrong_backward(V):
|
||||
with pytest.raises(RuntimeError):
|
||||
loss.backward()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("V", list_prohibited_matrices_dim0)
|
||||
def test_forward_prohibited(V):
|
||||
orth = OrthogonalBlock(0)
|
||||
with pytest.raises(Warning):
|
||||
V_orth = orth(V)
|
||||
assert V.shape[0] > V.shape[1]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user