diff --git a/mat73/__init__.py b/mat73/__init__.py index 50a5ca4..2c65873 100644 --- a/mat73/__init__.py +++ b/mat73/__init__.py @@ -112,7 +112,13 @@ def convert_mat(self, dataset): return None # complex numbers need to be filtered out separately elif 'imag' in str(dataset.dtype): - return np.array(dataset, np.complex).T.squeeze() + if dataset.attrs['MATLAB_class']==b'single': + dtype = np.complex64 + else: + dtype = np.complex128 + arr = np.array(dataset) + arr = (arr['real'] + arr['imag']*1j).astype(dtype) + return arr.T.squeeze() # if it is none of the above, we can convert to numpy array elif mtype in ('double', 'single', 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64'): diff --git a/setup.py b/setup.py index 67f9159..51e0db1 100644 --- a/setup.py +++ b/setup.py @@ -4,14 +4,14 @@ setuptools.setup( name='mat73', - version='0.39', + version='0.40', author="skjerns", author_email="nomail@nomail.com", description="Load MATLAB .mat 7.3 into Python native data types", long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/skjerns/mat7.3", - download_url="https://github.com/skjerns/mat7.3/archive/v.039.tar.gz", + download_url="https://github.com/skjerns/mat7.3/archive/v.040.tar.gz", install_requires=['h5py', 'numpy'], license='GNU 2.0', packages=['mat73'], diff --git a/tests/test_mat73.py b/tests/test_mat73.py index 08182d5..69cfa0b 100644 --- a/tests/test_mat73.py +++ b/tests/test_mat73.py @@ -70,7 +70,6 @@ def test_file1(self): np.testing.assert_array_equal(data['struct_']['test'],[1,2,3,4]) assert len(data['struct2_'])==3 - def test_file2(self): d = mat73.loadmat('testfile2.mat') raw1 = d['raw1'] @@ -78,6 +77,19 @@ def test_file2(self): assert raw1.speakerType == ['main']*5 np.testing.assert_array_equal(raw1.channel,[1,2,3,4,5]) np.testing.assert_allclose(raw1.measGain,[-1.0160217,-0.70729065,-1.2158508,0.68839645,2.464653]) + for i in range(5): + assert np.isclose(np.sum(raw1.h[i]),-0.0007341067459898744) + + np.testing.assert_array_almost_equal(raw1.HSmooth[0][2], [ 0.001139-4.233492e-04j, 0.00068 +8.927040e-06j, + 0.002382-7.647651e-04j, -0.012677+3.767829e-03j]) + + def test_file3(self): + d = mat73.loadmat('testfile3.mat') + raw1 = d['raw1'] + assert raw1.label == ['']*5 + assert raw1.speakerType == ['main']*5 + np.testing.assert_array_equal(raw1.channel,[1,2,3,4,5]) + np.testing.assert_allclose(raw1.measGain,[-1.0160217,-0.70729065,-1.2158508,0.68839645,2.464653]) for i in range(5): assert np.isclose(np.sum(raw1.h[i]),-0.019355850366449) for i in range(5): diff --git a/tests/testfile2.mat b/tests/testfile2.mat index 9f1bcef..f0d04bc 100644 Binary files a/tests/testfile2.mat and b/tests/testfile2.mat differ diff --git a/tests/testfile3.mat b/tests/testfile3.mat new file mode 100644 index 0000000..9f1bcef Binary files /dev/null and b/tests/testfile3.mat differ