Skip to content

Commit

Permalink
doc: force also test_sparsity
Browse files Browse the repository at this point in the history
  • Loading branch information
mrava87 committed Jul 26, 2024
1 parent 59de650 commit 85dfc1b
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions pytests/test_sparsity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from pylops.basicoperators import FirstDerivative, Identity, MatrixMult
from pylops.optimization.sparsity import fista, irls, ista, omp, spgl1, splitbregman

# currently test spgl1 only if numpy<2.0.0 is installed...
np_version = np.__version__.split(".")

par1 = {
"ny": 11,
"nx": 11,
Expand Down Expand Up @@ -359,24 +362,25 @@ def test_ISTA_FISTA_multiplerhs(par):
)
def test_SPGL1(par):
"""Invert problem with SPGL1"""
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:
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)
assert_array_almost_equal(x, xinv, decimal=1)


@pytest.mark.parametrize("par", [(par1), (par2), (par1j), (par2j)])
Expand Down

0 comments on commit 85dfc1b

Please sign in to comment.