Skip to content

Commit 3bf06cc

Browse files
committed
More accurate test of box subsampler
1 parent 8b656c2 commit 3bf06cc

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pycorr/tests/test_twopoint_jackknife.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ def test_subsampler():
2828
except ImportError:
2929
pass
3030

31-
boxsize = np.array([1000.] * 3)
31+
boxsize_1d = 1000.
32+
boxsize = np.array([boxsize_1d] * 3)
3233
boxcenter = np.array([100., 0., 0.])
3334
catalog = generate_catalogs(size=1000, boxsize=boxsize, offset=boxcenter - boxsize / 2.)[0]
3435
positions = catalog[:3]
3536
positions_bak = np.array(positions, copy=True)
36-
nsamples = 27
37+
nsamples_1d = 3
38+
nsamples = nsamples_1d ** 3
3739
subsampler = BoxSubsampler(boxsize=boxsize, boxcenter=boxcenter, nsamples=nsamples)
3840
assert np.allclose(subsampler.boxsize, boxsize)
3941
labels = subsampler.label(positions)
@@ -54,6 +56,16 @@ def test_subsampler():
5456
labels = subsampler.label(catalog[:3])
5557
assert np.max(labels) < nsamples
5658

59+
# more accurate test for the labeling
60+
coordinates_1d = np.linspace(0, boxsize_1d, 2 * nsamples_1d + 1)[1::2] # in the middle of the parts along each dimension, with no shift to make things easier here
61+
labels_1d = np.arange(nsamples_1d) # obvious regions along each axis
62+
coordinates_alt = [np.ravel(_) for _ in np.meshgrid(coordinates_1d, coordinates_1d, coordinates_1d, indexing = 'ij')] # arrays of all 3D coordinate combinations taken from `coordinates_1d`
63+
labels_3d = [np.ravel(_) for _ in np.meshgrid(labels_1d, labels_1d, labels_1d, indexing = 'ij')] # arrays of all 3D index combinations taken from `labels_1d`, same order as the coordinates
64+
labels_alt = sum(_ * nsamples_1d ** i for (i, _) in enumerate(labels_3d[::-1])) # more explicit conversion to the multi-dimensional index
65+
assert np.max(labels_alt) == nsamples - 1
66+
subsampler2 = BoxSubsampler(boxsize=boxsize, boxcenter=boxsize/2, nsamples=nsamples) # subsampler without shift
67+
assert np.array_equal(subsampler2.label(coordinates_alt, position_type = 'xyz'), labels_alt)
68+
5769
if mpi:
5870
mpicomm = mpi.COMM_WORLD
5971
positions_mpi = positions

0 commit comments

Comments
 (0)