Skip to content

Commit

Permalink
chore: simplify testing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cako committed Aug 5, 2024
1 parent b9618f5 commit 734776d
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions pytests/test_sparsity.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,25 +362,27 @@ def test_ISTA_FISTA_multiplerhs(par):
)
def test_SPGL1(par):
"""Invert problem with SPGL1"""
if int(np_version[0]) < 2:
np.random.seed(42)
Aop = MatrixMult(np.random.randn(par["ny"], par["nx"]))

x = np.zeros(par["nx"])
x[par["nx"] // 2] = 1
x[3] = 1
x[par["nx"] - 4] = -1

x0 = (
np.random.normal(0, 10, par["nx"])
+ par["imag"] * np.random.normal(0, 10, par["nx"])
if par["x0"]
else None
)
y = Aop * x
xinv = spgl1(Aop, y, x0=x0, iter_lim=5000)[0]
if int(np_version[0]) >= 2:
return

assert_array_almost_equal(x, xinv, decimal=1)
np.random.seed(42)
Aop = MatrixMult(np.random.randn(par["ny"], par["nx"]))

x = np.zeros(par["nx"])
x[par["nx"] // 2] = 1
x[3] = 1
x[par["nx"] - 4] = -1

x0 = (
np.random.normal(0, 10, par["nx"])
+ par["imag"] * np.random.normal(0, 10, par["nx"])
if par["x0"]
else None
)
y = Aop * x
xinv = spgl1(Aop, y, x0=x0, iter_lim=5000)[0]

assert_array_almost_equal(x, xinv, decimal=1)


@pytest.mark.parametrize("par", [(par1), (par2), (par1j), (par2j)])
Expand Down Expand Up @@ -416,6 +418,6 @@ def test_SplitBregman(par):
x0=x0 if par["x0"] else None,
restart=False,
show=False,
**dict(iter_lim=5, damp=1e-3)
**dict(iter_lim=5, damp=1e-3),
)
assert (np.linalg.norm(x - xinv) / np.linalg.norm(x)) < 1e-1

0 comments on commit 734776d

Please sign in to comment.