|
| 1 | +from types import SimpleNamespace |
| 2 | + |
1 | 3 | import numpy as np |
2 | 4 | import torch |
3 | 5 |
|
| 6 | +import spine.model.full_chain as full_chain_mod |
4 | 7 | from spine.constants import GHOST_SHP, GROUP_COL, PRGRP_COL, SHAPE_COL, SHOWR_SHP |
5 | 8 | from spine.data import IndexBatch, TensorBatch |
6 | 9 | from spine.model.full_chain import FullChain, FullChainLoss |
@@ -107,3 +110,49 @@ def test_group_labels_accepts_shape_restriction_without_model(): |
107 | 110 | assert np.array_equal(groups.index_list[0], [0, 1]) |
108 | 111 | assert group_shapes.tensor.tolist() == [SHOWR_SHP] |
109 | 112 | assert group_primaries is groups |
| 113 | + |
| 114 | + |
| 115 | +def test_prepare_grappa_input_uses_label_points_without_ppn(monkeypatch): |
| 116 | + full_chain = object.__new__(FullChain) |
| 117 | + full_chain.result = {} |
| 118 | + |
| 119 | + model = SimpleNamespace(node_encoder=SimpleNamespace(add_points=True)) |
| 120 | + data = TensorBatch(np.zeros((3, 4), dtype=np.float32), counts=np.array([3])) |
| 121 | + clusts = IndexBatch( |
| 122 | + [np.array([0], dtype=np.int64), np.array([1, 2], dtype=np.int64)], |
| 123 | + spans=np.array([3]), |
| 124 | + counts=np.array([2]), |
| 125 | + single_counts=np.array([1, 2]), |
| 126 | + ) |
| 127 | + primaries = IndexBatch( |
| 128 | + [np.array([1], dtype=np.int64), np.array([2], dtype=np.int64)], |
| 129 | + spans=np.array([3]), |
| 130 | + counts=np.array([2]), |
| 131 | + single_counts=np.array([1, 1]), |
| 132 | + ) |
| 133 | + clust_shapes = TensorBatch(np.array([SHOWR_SHP, SHOWR_SHP]), counts=np.array([2])) |
| 134 | + coord_label = TensorBatch(np.zeros((2, 9), dtype=np.float32), counts=np.array([2])) |
| 135 | + label_points = TensorBatch(np.ones((2, 6), dtype=np.float32), counts=np.array([2])) |
| 136 | + calls = [] |
| 137 | + |
| 138 | + def fake_label_points(data_arg, coord_label_arg, clusts_arg): |
| 139 | + calls.append((data_arg, coord_label_arg, clusts_arg)) |
| 140 | + return label_points |
| 141 | + |
| 142 | + monkeypatch.setattr( |
| 143 | + full_chain_mod, "get_cluster_points_label_batch", fake_label_points |
| 144 | + ) |
| 145 | + |
| 146 | + grappa_input = full_chain.prepare_grappa_input( |
| 147 | + model, |
| 148 | + data, |
| 149 | + clusts, |
| 150 | + clust_shapes, |
| 151 | + clust_primaries=primaries, |
| 152 | + coord_label=coord_label, |
| 153 | + point_use_primaries=True, |
| 154 | + ) |
| 155 | + |
| 156 | + assert grappa_input["points"] is label_points |
| 157 | + assert "coord_label" not in grappa_input |
| 158 | + assert calls == [(data, coord_label, primaries)] |
0 commit comments