Commit 120b6769 authored by Philipp Arras's avatar Philipp Arras
Browse files

Split into precompute and apply

parent 01cb0e3f
......@@ -360,8 +360,24 @@ def test_holo_from_correlations(nxdirty, nydirty, nchan, nrow, epsilon):
grid = np.random.randn(nx, ny) + 1.0j*np.random.randn(nx, ny)
W = conf.W()
res0 = np.zeros_like(grid)
for du, dv in product(*(2*(range(-W + 1, W),))):
d = ng.get_correlations(bl, conf, idx, du=du, dv=dv)
res0 += d*np.roll(np.roll(grid, -du, axis=0), -dv, axis=1)
# Precompute 2*W**2-2*W+1 images (naive: 4*W**2-4*W+1)
d0, d1 = [], []
for du, dv in product(range(-W + 1, W), range(1, W)):
d0.append(ng.get_correlations(bl, conf, idx, du=du, dv=dv))
for du in range(1, W):
d1.append(ng.get_correlations(bl, conf, idx, du=du, dv=0))
d2 = ng.get_correlations(bl, conf, idx, du=0, dv=0)
# Apply
for ii, (du, dv) in enumerate(product(range(-W + 1, W), range(1, W))):
tmp = np.roll(grid, -du, axis=0)
res0 += d0[ii]*np.roll(tmp, -dv, axis=1)
res0 += np.roll(d0[ii]*tmp, dv, axis=1)
for ii, du in enumerate(range(1, W)):
res0 += d1[ii]*np.roll(grid, -du, axis=0)
res0 += np.roll(d1[ii]*grid, du, axis=0)
res0 += d2*grid
res1 = ng.apply_holo(bl, conf, idx, grid)
assert_allclose(res0, res1, rtol=1e-13)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment