@@ -126,27 +126,22 @@ def test_filter(tmp_path: Path):
126126# ws,
127127# name="test-points",
128128# vertices=choices[inds],
129- # )
130- # tiles = tile_locations(pts.vertices[:, :2], n_tiles=8)
131- #
132- # values = np.zeros(pts.n_vertices)
133- # pop = []
134- # for ind, tile in enumerate(tiles):
135- # values[tile] = ind
136- # pop.append(len(tile))
137- #
138- # pts.add_data(
139- # {
140- # "values": {
141- # "values": values,
142- # }
143- # }
144- # )
145- # assert np.std(pop) / np.mean(pop) < 0.02, (
146- # "Population of tiles are not almost equal {}."
147- # )
148129
130+ def test_tile_locations ():
131+ n_points = 1000
132+ rng = np .random .default_rng (0 )
133+ locations = rng .standard_normal ((n_points , 2 ))
149134
135+ tiles = tile_locations (locations , n_tiles = 8 )
136+
137+ # All indices should be covered exactly once across tiles
138+ all_indices = np .concatenate (tiles )
139+ assert np .array_equal (np .sort (all_indices ), np .arange (n_points ))
140+
141+ # Tiles should be reasonably balanced in population
142+ pop = np .array ([len (tile ) for tile in tiles ])
143+ assert pop .min () > 0
144+ assert np .std (pop ) / np .mean (pop ) < 0.5
150145def test_tile_locations_labels (tmp_path : Path ):
151146 stn = np .arange (0 , 10000 , 1000 )
152147 x_locs = np .kron (stn , np .ones (100 )) + np .random .randn (1000 ) * 10
0 commit comments