Skip to content

Commit f12e23a

Browse files
committed
Correctly handle the case when the value array is empty.
Unfortunately, torch.asarray crashes on a buffer-protocol input with zero size; however, passing an empty list works fine.
1 parent 83b3425 commit f12e23a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

labs/npfl138/datasets/tfrecord_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def get_value_of_kind(kind: int) -> np.int64:
9393

9494
typecode_to_dtype = {"B": torch.uint8, "f": torch.float32, "q": torch.int64, "Q": torch.uint64}
9595
for key, value in arrays.items():
96-
arrays[key] = torch.asarray(value, dtype=typecode_to_dtype[value.typecode], copy=True)
96+
arrays[key] = torch.asarray(value or [], dtype=typecode_to_dtype[value.typecode], copy=True)
9797
for key, value in indices.items():
98-
indices[key] = torch.asarray(value, dtype=typecode_to_dtype[value.typecode], copy=True)
98+
indices[key] = torch.asarray(value or [], dtype=typecode_to_dtype[value.typecode], copy=True)
9999
return arrays, indices

0 commit comments

Comments
 (0)