Permalink
Browse files

BUG: io.matlab: fix byte-order detection. Closes ticket 1173.

There was an error in the logic for detecthing byte order for
little-endian matlab 4 mat files on big-endian machines.
  • Loading branch information...
1 parent eb98a5d commit 0ea1d6d8a83327a1a7bb055f00d82862b6df92c0 @matthew-brett matthew-brett committed with rgommers Jun 10, 2012
View
@@ -225,8 +225,12 @@ def guess_byte_order(self):
self.mat_stream.seek(0)
mopt = read_dtype(self.mat_stream, np.dtype('i4'))
self.mat_stream.seek(0)
+ if mopt == 0:
+ return '<'
if mopt < 0 or mopt > 5000:
+ # Number must have been byteswapped
return SYS_LITTLE_ENDIAN and '>' or '<'
+ # Not byteswapped
return SYS_LITTLE_ENDIAN and '<' or '>'
def initialize_read(self):
Binary file not shown.
@@ -924,5 +924,13 @@ def test_one_by_zero():
assert_equal(d['var'].shape, (0,))
+def test_load_mat4_le():
+ # We were getting byte order wrong when reading little-endian floa64 dense
+ # matrices on big-endian platforms
+ mat4_fname = pjoin(test_data_path, 'test_mat4_le_floats.mat')
+ vars = loadmat(mat4_fname)
+ assert_array_equal(vars['a'], [[0.1, 1.2]])
+
+
if __name__ == "__main__":
run_module_suite()

0 comments on commit 0ea1d6d

Please sign in to comment.