Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 0ea1d6d8a83327a1a7bb055f00d82862b6df92c0 1 parent eb98a5d
@matthew-brett matthew-brett authored rgommers committed
View
4 scipy/io/matlab/mio4.py
@@ -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):
View
BIN  scipy/io/matlab/tests/data/test_mat4_le_floats.mat
Binary file not shown
View
8 scipy/io/matlab/tests/test_mio.py
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.