Skip to content

Commit 2a4bc12

Browse files
authored
Save an "insert-sorted" batch index file alongside the current "id-sorted" batch index. (#313)
1 parent 81ad2ad commit 2a4bc12

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/hyrax/data_sets/inference_dataset.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,19 @@ def _save_batch_index(self):
319319
batch_index = np.zeros(len(self.all_ids), batch_index_dtype)
320320
batch_index["id"] = np.array(self.all_ids)
321321
batch_index["batch_num"] = np.array(self.all_batch_nums)
322-
batch_index.sort(order="id")
323322

323+
# Save the batch index in insertion order
324+
filename = "batch_index_insertion_order.npy"
325+
self._save_file(filename, batch_index)
326+
327+
# Sort the batch index by id, and save it again
328+
batch_index.sort(order="id")
324329
filename = "batch_index.npy"
330+
self._save_file(filename, batch_index)
331+
332+
def _save_file(self, filename: str, data: np.ndarray):
333+
"""Save a numpy array to a file in the result directory provided"""
325334
savepath = self.result_dir / filename
326335
if savepath.exists():
327-
RuntimeError("The path to save batch index already exists.")
328-
np.save(savepath, batch_index, allow_pickle=False)
336+
raise RuntimeError(f"The path to save {filename} already exists.")
337+
np.save(savepath, data, allow_pickle=False)

0 commit comments

Comments
 (0)