|
13 | 13 | import pytest |
14 | 14 |
|
15 | 15 | from pylops.basicoperators import MatrixMult |
| 16 | +from pylops.optimization.basic import cgls |
16 | 17 | from pylops.signalprocessing import Patch2D, Patch3D |
17 | 18 | from pylops.signalprocessing.patch2d import patch2d_design |
18 | 19 | from pylops.signalprocessing.patch3d import patch3d_design |
@@ -166,14 +167,14 @@ def test_Patch2D(par, dtype): |
166 | 167 | rtol=1e-3 if dtype == np.float32 else 1e-6, |
167 | 168 | backend=backend, |
168 | 169 | ) |
169 | | - x = np.ones(par["ny"] * nwins[0] * par["nt"] * nwins[1], dtype=dtype) |
| 170 | + x = np.ones((nwins[0], nwins[1], par["ny"], par["nt"]), dtype=dtype) |
170 | 171 | y = Pop * x.ravel() |
171 | 172 | xadj = Pop.H * y |
172 | | - xinv = Pop / y |
| 173 | + xinv = cgls(Pop, y, niter=50)[0] |
173 | 174 |
|
174 | 175 | assert y.dtype == dtype |
175 | 176 | assert xadj.dtype == dtype |
176 | | - assert_array_almost_equal(x.ravel(), xinv, decimal=3 if dtype == np.float32 else 8) |
| 177 | + assert_array_almost_equal(x, xinv, decimal=3 if dtype == np.float32 else 8) |
177 | 178 |
|
178 | 179 |
|
179 | 180 | @pytest.mark.parametrize("par", [(par1), (par4)]) |
@@ -210,14 +211,14 @@ def test_Patch2D_scalings(par, dtype): |
210 | 211 | rtol=1e-3 if dtype == np.float32 else 1e-6, |
211 | 212 | backend=backend, |
212 | 213 | ) |
213 | | - x = np.ones(par["ny"] * nwins[0] * par["nt"] * nwins[1], dtype=dtype) |
| 214 | + x = np.ones((nwins[0], nwins[1], par["ny"], par["nt"]), dtype=dtype) |
214 | 215 | y = Pop * x.ravel() |
215 | 216 | xadj = Pop.H * y |
216 | | - xinv = Pop / y |
| 217 | + xinv = cgls(Pop, y, niter=50)[0] |
217 | 218 |
|
218 | 219 | assert y.dtype == dtype |
219 | 220 | assert xadj.dtype == dtype |
220 | | - assert_array_almost_equal(x.ravel(), xinv, decimal=3 if dtype == np.float32 else 8) |
| 221 | + assert_array_almost_equal(x, xinv, decimal=3 if dtype == np.float32 else 8) |
221 | 222 |
|
222 | 223 |
|
223 | 224 | @pytest.mark.parametrize("par", [(par1), (par4)]) |
@@ -254,14 +255,14 @@ def test_Patch2D_singlepatch1(par, dtype): |
254 | 255 | rtol=1e-3 if dtype == np.float32 else 1e-6, |
255 | 256 | backend=backend, |
256 | 257 | ) |
257 | | - x = np.ones(par["npy"] * nwins[0] * par["nt"] * nwins[1], dtype=dtype) |
| 258 | + x = np.ones((nwins[0], nwins[1], par["npy"], par["nt"]), dtype=dtype) |
258 | 259 | y = Pop * x.ravel() |
259 | 260 | xadj = Pop.H * y |
260 | | - xinv = Pop / y |
| 261 | + xinv = cgls(Pop, y, niter=50)[0] |
261 | 262 |
|
262 | 263 | assert y.dtype == dtype |
263 | 264 | assert xadj.dtype == dtype |
264 | | - assert_array_almost_equal(x.ravel(), xinv, decimal=3 if dtype == np.float32 else 8) |
| 265 | + assert_array_almost_equal(x, xinv, decimal=3 if dtype == np.float32 else 8) |
265 | 266 |
|
266 | 267 |
|
267 | 268 | @pytest.mark.parametrize("par", [(par1), (par2), (par3), (par4), (par5), (par6)]) |
@@ -297,14 +298,14 @@ def test_Patch2D_singlepatch2(par, dtype): |
297 | 298 | rtol=1e-3 if dtype == np.float32 else 1e-6, |
298 | 299 | backend=backend, |
299 | 300 | ) |
300 | | - x = np.ones(par["ny"] * nwins[0] * par["npt"] * nwins[1], dtype=dtype) |
| 301 | + x = np.ones((nwins[0], nwins[1], par["ny"], par["nt"]), dtype=dtype) |
301 | 302 | y = Pop * x.ravel() |
302 | 303 | xadj = Pop.H * y |
303 | | - xinv = Pop / y |
| 304 | + xinv = cgls(Pop, y, niter=50)[0] |
304 | 305 |
|
305 | 306 | assert y.dtype == dtype |
306 | 307 | assert xadj.dtype == dtype |
307 | | - assert_array_almost_equal(x.ravel(), xinv, decimal=3 if dtype == np.float32 else 8) |
| 308 | + assert_array_almost_equal(x, xinv, decimal=3 if dtype == np.float32 else 8) |
308 | 309 |
|
309 | 310 |
|
310 | 311 | @pytest.mark.parametrize("par", [(par1), (par2), (par3), (par4), (par5), (par6)]) |
@@ -351,15 +352,15 @@ def test_Patch3D(par, dtype): |
351 | 352 | backend=backend, |
352 | 353 | ) |
353 | 354 | x = np.ones( |
354 | | - (par["ny"] * nwins[0], par["nx"] * nwins[1], par["nt"] * nwins[2]), dtype=dtype |
| 355 | + (nwins[0], nwins[1], nwins[2], par["ny"], par["nx"], par["nt"]), |
355 | 356 | ) |
356 | 357 | y = Pop * x.ravel() |
357 | 358 | xadj = Pop.H * y |
358 | | - xinv = Pop / y |
| 359 | + xinv = cgls(Pop, y, niter=50)[0] |
359 | 360 |
|
360 | 361 | assert y.dtype == dtype |
361 | 362 | assert xadj.dtype == dtype |
362 | | - assert_array_almost_equal(x.ravel(), xinv, decimal=3 if dtype == np.float32 else 8) |
| 363 | + assert_array_almost_equal(x, xinv, decimal=3 if dtype == np.float32 else 8) |
363 | 364 |
|
364 | 365 |
|
365 | 366 | @pytest.mark.parametrize("par", [(par1), (par2), (par3), (par4), (par5), (par6)]) |
@@ -403,15 +404,15 @@ def test_Patch3D_singlepatch1(par, dtype): |
403 | 404 | backend=backend, |
404 | 405 | ) |
405 | 406 | x = np.ones( |
406 | | - (par["npy"] * nwins[0], par["nx"] * nwins[1], par["nt"] * nwins[2]), dtype=dtype |
| 407 | + (nwins[0], nwins[1], nwins[2], par["npy"], par["nx"], par["nt"]), |
407 | 408 | ) |
408 | 409 | y = Pop * x.ravel() |
409 | 410 | xadj = Pop.H * y |
410 | | - xinv = Pop / y |
| 411 | + xinv = cgls(Pop, y, niter=50)[0] |
411 | 412 |
|
412 | 413 | assert y.dtype == dtype |
413 | 414 | assert xadj.dtype == dtype |
414 | | - assert_array_almost_equal(x.ravel(), xinv, decimal=3 if dtype == np.float32 else 8) |
| 415 | + assert_array_almost_equal(x, xinv, decimal=3 if dtype == np.float32 else 8) |
415 | 416 |
|
416 | 417 |
|
417 | 418 | @pytest.mark.parametrize("par", [(par1), (par2), (par3), (par4), (par5), (par6)]) |
@@ -455,15 +456,15 @@ def test_Patch3D_singlepatch2(par, dtype): |
455 | 456 | backend=backend, |
456 | 457 | ) |
457 | 458 | x = np.ones( |
458 | | - (par["ny"] * nwins[0], par["npx"] * nwins[1], par["nt"] * nwins[2]), dtype=dtype |
| 459 | + (nwins[0], nwins[1], nwins[2], par["ny"], par["npx"], par["nt"]), |
459 | 460 | ) |
460 | 461 | y = Pop * x.ravel() |
461 | 462 | xadj = Pop.H * y |
462 | | - xinv = Pop / y |
| 463 | + xinv = cgls(Pop, y, niter=50)[0] |
463 | 464 |
|
464 | 465 | assert y.dtype == dtype |
465 | 466 | assert xadj.dtype == dtype |
466 | | - assert_array_almost_equal(x.ravel(), xinv, decimal=3 if dtype == np.float32 else 8) |
| 467 | + assert_array_almost_equal(x, xinv, decimal=3 if dtype == np.float32 else 8) |
467 | 468 |
|
468 | 469 |
|
469 | 470 | @pytest.mark.parametrize("par", [(par1), (par2), (par3), (par4), (par5), (par6)]) |
@@ -509,16 +510,16 @@ def test_Patch3D_singlepatch12(par, dtype): |
509 | 510 | backend=backend, |
510 | 511 | ) |
511 | 512 | x = np.ones( |
512 | | - (par["npy"] * nwins[0], par["npx"] * nwins[1], par["nt"] * nwins[2]), |
| 513 | + (nwins[0], nwins[1], nwins[2], par["npy"], par["npx"], par["nt"]), |
513 | 514 | dtype=dtype, |
514 | 515 | ) |
515 | 516 | y = Pop * x.ravel() |
516 | 517 | xadj = Pop.H * y |
517 | | - xinv = Pop / y |
| 518 | + xinv = cgls(Pop, y, niter=50)[0] |
518 | 519 |
|
519 | 520 | assert y.dtype == dtype |
520 | 521 | assert xadj.dtype == dtype |
521 | | - assert_array_almost_equal(x.ravel(), xinv, decimal=3 if dtype == np.float32 else 8) |
| 522 | + assert_array_almost_equal(x, xinv, decimal=3 if dtype == np.float32 else 8) |
522 | 523 |
|
523 | 524 |
|
524 | 525 | @pytest.mark.parametrize("par", [(par1), (par2), (par3), (par4), (par5), (par6)]) |
@@ -561,12 +562,12 @@ def test_Patch3D_singlepatch3(par, dtype): |
561 | 562 | backend=backend, |
562 | 563 | ) |
563 | 564 | x = np.ones( |
564 | | - (par["ny"] * nwins[0], par["nx"] * nwins[1], par["npt"] * nwins[2]), dtype=dtype |
| 565 | + (nwins[0], nwins[1], nwins[2], par["ny"], par["nx"], par["npt"]), |
565 | 566 | ) |
566 | 567 | y = Pop * x.ravel() |
567 | 568 | xadj = Pop.H * y |
568 | | - xinv = Pop / y |
| 569 | + xinv = cgls(Pop, y, niter=50)[0] |
569 | 570 |
|
570 | 571 | assert y.dtype == dtype |
571 | 572 | assert xadj.dtype == dtype |
572 | | - assert_array_almost_equal(x.ravel(), xinv, decimal=3 if dtype == np.float32 else 8) |
| 573 | + assert_array_almost_equal(x, xinv, decimal=3 if dtype == np.float32 else 8) |
0 commit comments