Skip to content

Commit

Permalink
speed up _is_ref check
Browse files Browse the repository at this point in the history
  • Loading branch information
skjerns committed Nov 29, 2021
1 parent d9ef540 commit e9e19f7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
9 changes: 3 additions & 6 deletions mat73/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def mat2dict(self, hdf5, only_load=None):
raise ValueError('can only unpack .mat')
return d


def unpack_mat(self, hdf5, depth=0):
"""
unpack a h5py entry: if it's a group expand,
Expand Down Expand Up @@ -115,15 +114,13 @@ def unpack_mat(self, hdf5, depth=0):
else:
raise Exception(f'Unknown hdf5 type: {key}:{type(hdf5)}')


# @profile
def _has_refs(self, dataset):
if len(dataset)==0: return False
if not isinstance(dataset[0], np.ndarray): return False
if len(dataset.shape)<2: return False
if isinstance(dataset[0][0], h5py.h5r.Reference):
return True
return False


def convert_mat(self, dataset, depth):
"""
Converts h5py.dataset into python native datatypes
Expand Down Expand Up @@ -244,5 +241,5 @@ def savemat(filename, verbose=True):
# d = loadmat('../tests/testfile5.mat', use_attrdict=True)


file = '../tests/testfile7.mat'
file = '../tests/testfile8.mat'
data = loadmat(file)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

setuptools.setup(
name='mat73',
version='0.52',
version='0.53',
author="skjerns",
author_email="[email protected]",
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/v0.52.tar.gz",
download_url="https://github.com/skjerns/mat7.3/archive/v0.53.tar.gz",
install_requires=['h5py', 'numpy'],
license='MIT',
packages=['mat73'],
Expand Down
8 changes: 6 additions & 2 deletions tests/test_mat73.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class Testing(unittest.TestCase):

def setUp(self):
for i in range(1,8):
for i in range(1,9):
file = 'testfile{}.mat'.format(i)
if not os.path.exists(file):
file = os.path.join('./tests', file)
Expand Down Expand Up @@ -337,7 +337,11 @@ def test_file6_empty_cell_array(self):
def test_file7_empty_cell_array(self):
data = mat73.loadmat(self.testfile7)


def test_file8_large(self):
import stimer
with stimer:
data = mat73.loadmat(self.testfile8)



if __name__ == '__main__':
Expand Down

0 comments on commit e9e19f7

Please sign in to comment.