Skip to content

Commit b5130e2

Browse files
s390x: fix parsing dimensions for mnist data
This change fixes multiple tests like MNISTTestCase::test_feature_types in test/test_datasets.py
1 parent c072dcb commit b5130e2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

torchvision/datasets/mnist.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ def read_sn3_pascalvincent_tensor(path: str, strict: bool = True) -> torch.Tenso
525525
torch_type = SN3_PASCALVINCENT_TYPEMAP[ty]
526526
s = [get_int(data[4 * (i + 1) : 4 * (i + 2)]) for i in range(nd)]
527527

528+
if sys.byteorder == "big":
529+
for i in range(len(s)):
530+
s[i] = int.from_bytes(s[i].to_bytes(4, byteorder="little"), byteorder="big", signed=False)
531+
528532
parsed = torch.frombuffer(bytearray(data), dtype=torch_type, offset=(4 * (nd + 1)))
529533

530534
# The MNIST format uses the big endian byte order, while `torch.frombuffer` uses whatever the system uses. In case

0 commit comments

Comments
 (0)