Skip to content

Commit 8f1a4ea

Browse files
committed
Improved efficiency of Fredholm1 when saveGt=False
1 parent f073e77 commit 8f1a4ea

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

pylops_distributed/signalprocessing/Fredholm1.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ def __init__(self, G, nz=1, saveGt=True, compute=(False, False),
6161
self.nz = nz
6262
self.nsl, self.nx, self.ny = G.shape
6363
self.G = G
64-
if saveGt:
65-
self.GT = G.transpose((0, 2, 1)).conj()
6664
self.shape = (self.nsl * self.nx * self.nz,
6765
self.nsl * self.ny * self.nz)
66+
if saveGt:
67+
self.GT = G.transpose((0, 2, 1)).conj().persist()
68+
else:
69+
# choose what to transpose if Gt is not saved
70+
self.transposeG = True if self.G.size < self.shape[0] else False
6871
self.dtype = np.dtype(dtype)
6972
self.compute = compute
7073
self.chunks = chunks
@@ -90,5 +93,9 @@ def _rmatvec(self, x):
9093
if hasattr(self, 'GT'):
9194
y = da.matmul(self.GT, x)
9295
else:
93-
y = da.matmul(self.G.transpose((0, 2, 1)).conj(), x)
96+
if self.transposeG:
97+
y = da.matmul(self.G.transpose((0, 2, 1)).conj(), x)
98+
else:
99+
y = da.matmul(x.transpose(0, 2, 1).conj(),
100+
self.G).transpose(0, 2, 1).conj()
94101
return y.ravel()

pylops_distributed/waveeqprocessing/marchenko.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ def apply_onepoint(self, trav, dist=None, G0=None, nfft=None,
153153
# Create window
154154
trav_off = trav - self.toff
155155
trav_off = np.round(trav_off / self.dt).astype(np.int)
156-
157-
# window
158156
w = np.zeros((self.nr, self.nt))
159157
for ir in range(self.nr):
160158
w[ir, :trav_off[ir]] = 1
@@ -392,7 +390,6 @@ def apply_multiplepoints(self, trav, dist=None, G0=None, nfft=None,
392390
f1_inv_tot = \
393391
f1_inv + da.concatenate((np.zeros((self.nt2, self.nr, nvs)),
394392
fd_plus))
395-
396393
if greens:
397394
# Create Green's functions
398395
g_inv = Gop * f1_inv_tot.flatten()

pylops_distributed/waveeqprocessing/mdd.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import logging
22
from pylops.waveeqprocessing.mdd import _MDC
33

4-
from pylops_distributed import Diagonal, Identity, Transpose
4+
from pylops_distributed import Identity, Transpose
55
from pylops_distributed.signalprocessing import FFT, Fredholm1
6-
from pylops_distributed.utils import dottest as Dottest
76

87
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.WARNING)
98

pytests/test_fredholm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
'saveGt': False, 'imag': 0, 'dtype': 'float32'} # real, unsaved Gt
1414
par3 = {'nsl': 4, 'ny': 6, 'nx': 4, 'nz': 5,
1515
'saveGt':True, 'imag': 1j, 'dtype': 'complex64'} # complex, saved Gt
16-
par4 = {'nsl': 4, 'ny': 6, 'nx': 4, 'nz': 5, 'saveGt': False,
17-
'imag': 1j, 'dtype': 'complex64'} # complex, unsaved Gt
16+
par4 = {'nsl': 4, 'ny': 6, 'nx': 4, 'nz': 5,
17+
'saveGt': False, 'imag': 1j, 'dtype': 'complex64'} # complex, unsaved Gt
1818
par5 = {'nsl': 4, 'ny': 6, 'nx': 4, 'nz': 1,
1919
'saveGt': True, 'imag': 0, 'dtype': 'float32'} # real, saved Gt, nz=1
2020
par6 = {'nsl': 4, 'ny': 6, 'nx': 4, 'nz': 1,
@@ -54,3 +54,4 @@ def test_Fredholm1(par):
5454
dy = dFop * x.ravel()
5555
y = Fop * x.ravel().compute()
5656
assert_array_almost_equal(dy, y, decimal=5)
57+

pytests/test_marchenko.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,17 @@
7575
dRtwosided_fft = da.from_zarr(inputzarr)
7676

7777

78-
def test_Marchenko():
78+
par1 = {'saveRt': True} # square real
79+
par2 = {'saveRt': False} # overdetermined real
80+
81+
82+
@pytest.mark.parametrize("par", [(par1), (par2)])
83+
def test_Marchenko(par):
7984
"""Dot-test and comparison with pylops for Marchenko.apply_onepoint
8085
"""
8186
dMarchenkoWM = dMarchenko(dRtwosided_fft, nt=nt, dt=dt, dr=dr,
82-
wav=wav, toff=toff, nsmooth=nsmooth)
83-
87+
wav=wav, toff=toff, nsmooth=nsmooth,
88+
saveRt=par['saveRt'])
8489

8590
MarchenkoWM = Marchenko(Rtwosided_fft, nt=nt, dt=dt, dr=dr,
8691
wav=wav, toff=toff, nsmooth=nsmooth)
@@ -102,11 +107,13 @@ def test_Marchenko():
102107
np.linalg.norm(gsub_norm) < 1e-1
103108

104109

105-
def test_Marchenko__multi():
110+
@pytest.mark.parametrize("par", [(par1), (par2)])
111+
def test_Marchenko__multi(par):
106112
"""Dot-test and comparison with pylops for Marchenko.apply_multiplepoints
107113
"""
108114
dMarchenkoWM = dMarchenko(dRtwosided_fft, nt=nt, dt=dt, dr=dr,
109-
wav=wav, toff=toff, nsmooth=nsmooth)
115+
wav=wav, toff=toff, nsmooth=nsmooth,
116+
saveRt=par['saveRt'])
110117

111118
MarchenkoWM = Marchenko(Rtwosided_fft, nt=nt, dt=dt, dr=dr,
112119
wav=wav, toff=toff, nsmooth=nsmooth)

0 commit comments

Comments
 (0)