Skip to content

Commit 85dfc1b

Browse files
committed
doc: force also test_sparsity
1 parent 59de650 commit 85dfc1b

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

pytests/test_sparsity.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
from pylops.basicoperators import FirstDerivative, Identity, MatrixMult
66
from pylops.optimization.sparsity import fista, irls, ista, omp, spgl1, splitbregman
77

8+
# currently test spgl1 only if numpy<2.0.0 is installed...
9+
np_version = np.__version__.split(".")
10+
811
par1 = {
912
"ny": 11,
1013
"nx": 11,
@@ -359,24 +362,25 @@ def test_ISTA_FISTA_multiplerhs(par):
359362
)
360363
def test_SPGL1(par):
361364
"""Invert problem with SPGL1"""
362-
np.random.seed(42)
363-
Aop = MatrixMult(np.random.randn(par["ny"], par["nx"]))
364-
365-
x = np.zeros(par["nx"])
366-
x[par["nx"] // 2] = 1
367-
x[3] = 1
368-
x[par["nx"] - 4] = -1
369-
370-
x0 = (
371-
np.random.normal(0, 10, par["nx"])
372-
+ par["imag"] * np.random.normal(0, 10, par["nx"])
373-
if par["x0"]
374-
else None
375-
)
376-
y = Aop * x
377-
xinv = spgl1(Aop, y, x0=x0, iter_lim=5000)[0]
365+
if int(np_version[0]) < 2:
366+
np.random.seed(42)
367+
Aop = MatrixMult(np.random.randn(par["ny"], par["nx"]))
368+
369+
x = np.zeros(par["nx"])
370+
x[par["nx"] // 2] = 1
371+
x[3] = 1
372+
x[par["nx"] - 4] = -1
373+
374+
x0 = (
375+
np.random.normal(0, 10, par["nx"])
376+
+ par["imag"] * np.random.normal(0, 10, par["nx"])
377+
if par["x0"]
378+
else None
379+
)
380+
y = Aop * x
381+
xinv = spgl1(Aop, y, x0=x0, iter_lim=5000)[0]
378382

379-
assert_array_almost_equal(x, xinv, decimal=1)
383+
assert_array_almost_equal(x, xinv, decimal=1)
380384

381385

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

0 commit comments

Comments
 (0)