Commit 2e91f517 authored by Philipp Arras's avatar Philipp Arras
Browse files

Do not build sparse matrix

parent 797490b0
......@@ -354,27 +354,14 @@ def test_against_wdft(nxdirty, nydirty, nchan, nrow, fov):
@pmp("nchan", (1, 5))
@pmp('epsilon', (1e-3, 1e-6))
def test_holo_from_correlations(nxdirty, nydirty, nchan, nrow, epsilon):
# This function is not production-ready. Its memory footprint can be
# reduced by a factor of ~6.
pytest.importorskip("scipy")
from scipy.sparse import coo_matrix
np.random.seed(42)
bl, conf, idx = _init_gridder(nxdirty, nydirty, epsilon, nchan, nrow)
nx, ny, gridsize = 2*nxdirty, 2*nydirty, 4*nxdirty*nydirty
nx, ny = 2*nxdirty, 2*nydirty
grid = np.random.randn(nx, ny) + 1.0j*np.random.randn(nx, ny)
W = conf.W()
n = gridsize*(2*W-1)**2
row, col, data = np.empty((n,)), np.empty((n,)), np.empty((n,))
ind = np.arange(0, gridsize)
y0 = ind % ny
x0 = ind - y0
for ii, (du, dv) in enumerate(product(*(2*(range(-W+1, W),)))):
slc = slice(ii*gridsize, (ii+1)*gridsize)
foo = (y0+dv) % ny + x0
yy = foo % ny
col[slc] = (foo-yy+du*ny) % gridsize + yy
row[slc] = ind
data[slc] = ng.get_correlations(bl, conf, idx, du=du, dv=dv).ravel()
res0 = coo_matrix((data, (row, col)), shape=2*(gridsize,)).dot(grid.ravel()).reshape(nx, ny)
res0 = np.zeros_like(grid)
for ii, (du, dv) in enumerate(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)
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