|
5 | 5 | import torch |
6 | 6 |
|
7 | 7 | import spine.model.full_chain as full_chain_mod |
| 8 | +import spine.model.layer.gnn.encode.geometric as geometric_mod |
8 | 9 | from spine.constants import ( |
9 | 10 | CLUST_COL, |
10 | 11 | GHOST_SHP, |
|
16 | 17 | ) |
17 | 18 | from spine.data import IndexBatch, TensorBatch |
18 | 19 | from spine.model.full_chain import FullChain, FullChainLoss |
| 20 | +from spine.model.layer.gnn.encode.geometric import ClustGeoNodeEncoder |
19 | 21 |
|
20 | 22 |
|
21 | 23 | class RecordingLoss: |
@@ -182,7 +184,9 @@ def test_prepare_grappa_input_uses_label_points_without_ppn(monkeypatch): |
182 | 184 | full_chain = object.__new__(FullChain) |
183 | 185 | full_chain.result = {} |
184 | 186 |
|
185 | | - model = SimpleNamespace(node_encoder=SimpleNamespace(add_points=True)) |
| 187 | + model = SimpleNamespace( |
| 188 | + node_encoder=SimpleNamespace(add_points=True, random_order=False) |
| 189 | + ) |
186 | 190 | data = TensorBatch(np.zeros((3, 4), dtype=np.float32), counts=np.array([3])) |
187 | 191 | clust_label = TensorBatch( |
188 | 192 | np.zeros((3, GROUP_COL + 1), dtype=np.float32), counts=np.array([3]) |
@@ -226,15 +230,50 @@ def fake_label_points(data_arg, coord_label_arg, clusts_arg, **kwargs): |
226 | 230 | assert grappa_input["points"] is label_points |
227 | 231 | assert "coord_label" not in grappa_input |
228 | 232 | assert calls == [ |
229 | | - (clust_label, coord_label, primaries, {}), |
| 233 | + (clust_label, coord_label, primaries, {"random_order": False}), |
| 234 | + ] |
| 235 | + |
| 236 | + |
| 237 | +def test_geo_node_encoder_forwards_random_order(monkeypatch): |
| 238 | + encoder = ClustGeoNodeEncoder(use_numpy=False, add_points=True, random_order=False) |
| 239 | + data = TensorBatch(torch.zeros((1, 5), dtype=torch.float32), counts=np.array([1])) |
| 240 | + clusts = IndexBatch( |
| 241 | + [np.array([0], dtype=np.int64)], |
| 242 | + spans=np.array([1]), |
| 243 | + counts=np.array([1]), |
| 244 | + single_counts=np.array([1]), |
| 245 | + ) |
| 246 | + coord_label = TensorBatch( |
| 247 | + torch.zeros((1, 9), dtype=torch.float32), counts=np.array([1]) |
| 248 | + ) |
| 249 | + label_points = TensorBatch( |
| 250 | + torch.ones((1, 6), dtype=torch.float32), counts=np.array([1]) |
| 251 | + ) |
| 252 | + calls = [] |
| 253 | + |
| 254 | + def fake_label_points(data_arg, coord_label_arg, clusts_arg, **kwargs): |
| 255 | + calls.append((data_arg, coord_label_arg, clusts_arg, kwargs)) |
| 256 | + return label_points |
| 257 | + |
| 258 | + monkeypatch.setattr( |
| 259 | + geometric_mod, "get_cluster_points_label_batch", fake_label_points |
| 260 | + ) |
| 261 | + |
| 262 | + _, points = encoder(data, clusts, coord_label=coord_label) |
| 263 | + |
| 264 | + assert points is label_points |
| 265 | + assert calls == [ |
| 266 | + (data, coord_label, clusts, {"random_order": False}), |
230 | 267 | ] |
231 | 268 |
|
232 | 269 |
|
233 | 270 | def test_prepare_grappa_input_requires_clust_label_for_label_points(): |
234 | 271 | full_chain = object.__new__(FullChain) |
235 | 272 | full_chain.result = {} |
236 | 273 |
|
237 | | - model = SimpleNamespace(node_encoder=SimpleNamespace(add_points=True)) |
| 274 | + model = SimpleNamespace( |
| 275 | + node_encoder=SimpleNamespace(add_points=True, random_order=True) |
| 276 | + ) |
238 | 277 | data = TensorBatch(np.zeros((1, 4), dtype=np.float32), counts=np.array([1])) |
239 | 278 | clusts = IndexBatch( |
240 | 279 | [np.array([0], dtype=np.int64)], |
|
0 commit comments