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
@@ -7,15 +7,16 @@ import pytest
|
||||
|
||||
def eq1(input_, output_):
|
||||
u_grad = grad(output_, input_)
|
||||
u1_xx = grad(u_grad, input_, components=['du1dx'], d=['x'])
|
||||
u2_xy = grad(u_grad, input_, components=['du2dx'], d=['y'])
|
||||
u1_xx = grad(u_grad, input_, components=["du1dx"], d=["x"])
|
||||
u2_xy = grad(u_grad, input_, components=["du2dx"], d=["y"])
|
||||
return torch.hstack([u1_xx, u2_xy])
|
||||
|
||||
|
||||
def eq2(input_, output_):
|
||||
force_term = (torch.sin(input_.extract(['x']) * torch.pi) *
|
||||
torch.sin(input_.extract(['y']) * torch.pi))
|
||||
delta_u = laplacian(output_.extract(['u1']), input_)
|
||||
force_term = torch.sin(input_.extract(["x"]) * torch.pi) * torch.sin(
|
||||
input_.extract(["y"]) * torch.pi
|
||||
)
|
||||
delta_u = laplacian(output_.extract(["u1"]), input_)
|
||||
return delta_u - force_term
|
||||
|
||||
|
||||
@@ -36,10 +37,10 @@ def test_residual():
|
||||
eq_1 = Equation(eq1)
|
||||
eq_2 = Equation(eq2)
|
||||
|
||||
pts = LabelTensor(torch.rand(10, 2), labels=['x', 'y'])
|
||||
pts = LabelTensor(torch.rand(10, 2), labels=["x", "y"])
|
||||
pts.requires_grad = True
|
||||
u = torch.pow(pts, 2)
|
||||
u.labels = ['u1', 'u2']
|
||||
u.labels = ["u1", "u2"]
|
||||
|
||||
eq_1_res = eq_1.residual(pts, u)
|
||||
eq_2_res = eq_2.residual(pts, u)
|
||||
|
||||
@@ -7,15 +7,16 @@ import pytest
|
||||
|
||||
def eq1(input_, output_):
|
||||
u_grad = grad(output_, input_)
|
||||
u1_xx = grad(u_grad, input_, components=['du1dx'], d=['x'])
|
||||
u2_xy = grad(u_grad, input_, components=['du2dx'], d=['y'])
|
||||
u1_xx = grad(u_grad, input_, components=["du1dx"], d=["x"])
|
||||
u2_xy = grad(u_grad, input_, components=["du2dx"], d=["y"])
|
||||
return torch.hstack([u1_xx, u2_xy])
|
||||
|
||||
|
||||
def eq2(input_, output_):
|
||||
force_term = (torch.sin(input_.extract(['x']) * torch.pi) *
|
||||
torch.sin(input_.extract(['y']) * torch.pi))
|
||||
delta_u = laplacian(output_.extract(['u1']), input_)
|
||||
force_term = torch.sin(input_.extract(["x"]) * torch.pi) * torch.sin(
|
||||
input_.extract(["y"]) * torch.pi
|
||||
)
|
||||
delta_u = laplacian(output_.extract(["u1"]), input_)
|
||||
return delta_u - force_term
|
||||
|
||||
|
||||
@@ -25,25 +26,25 @@ def foo():
|
||||
|
||||
def test_constructor():
|
||||
SystemEquation([eq1, eq2])
|
||||
SystemEquation([eq1, eq2], reduction='sum')
|
||||
SystemEquation([eq1, eq2], reduction="sum")
|
||||
with pytest.raises(NotImplementedError):
|
||||
SystemEquation([eq1, eq2], reduction='foo')
|
||||
SystemEquation([eq1, eq2], reduction="foo")
|
||||
with pytest.raises(ValueError):
|
||||
SystemEquation(foo)
|
||||
|
||||
|
||||
def test_residual():
|
||||
|
||||
pts = LabelTensor(torch.rand(10, 2), labels=['x', 'y'])
|
||||
pts = LabelTensor(torch.rand(10, 2), labels=["x", "y"])
|
||||
pts.requires_grad = True
|
||||
u = torch.pow(pts, 2)
|
||||
u.labels = ['u1', 'u2']
|
||||
u.labels = ["u1", "u2"]
|
||||
|
||||
eq_1 = SystemEquation([eq1, eq2], reduction='mean')
|
||||
eq_1 = SystemEquation([eq1, eq2], reduction="mean")
|
||||
res = eq_1.residual(pts, u)
|
||||
assert res.shape == torch.Size([10])
|
||||
|
||||
eq_1 = SystemEquation([eq1, eq2], reduction='sum')
|
||||
eq_1 = SystemEquation([eq1, eq2], reduction="sum")
|
||||
res = eq_1.residual(pts, u)
|
||||
assert res.shape == torch.Size([10])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user