Skip to content

Commit 93814d3

Browse files
committed
Support indexed graph serialization
1 parent 58d99b5 commit 93814d3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

cfpq_model/label_decomposed_graph.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,19 @@ def write_to_pocr_graph_file(self, path: Union[Path, str]):
140140
for symbol, matrix in self.matrices.items():
141141
edge_label = symbol.label
142142
(rows, columns, _) = matrix.to_coo()
143-
edges_df = pd.DataFrame({
144-
'source': rows,
145-
'destination': columns,
146-
'label': edge_label
147-
})
143+
if matrix.shape[0] == self.vertex_count:
144+
edges_df = pd.DataFrame({
145+
'source': rows,
146+
'destination': columns,
147+
'label': edge_label
148+
})
149+
else:
150+
edges_df = pd.DataFrame({
151+
'source': rows % self.vertex_count,
152+
'destination': columns,
153+
'label': edge_label,
154+
'label_index': rows // self.vertex_count
155+
})
148156
csv_string = edges_df.to_csv(sep='\t', index=False, header=False)
149157
output_file.write(csv_string)
150158

0 commit comments

Comments
 (0)