NeuroJSON / easyh5

EasyH5 Toolbox - An easy-to-use HDF5 data interface (loadh5 and saveh5) for MATLAB
BSD 3-Clause "New" or "Revised" License
12 stars 10 forks source link

Unable to save real sparse matrix #14

Closed abrahamzv closed 1 year ago

abrahamzv commented 1 year ago

I ran into an error when trying to save a sparse matrix in the example scripts. Are sparse matrices not supported? Command:

data2hdf=sprand(10,10,0.1)
saveh5(data2hdf,'test.h5', 'RootName', 'test')

Returns:

Error using hdf5lib2
Sparse arrays are not supported. Before writing convert any sparse data to non-sparse data using FULL.

Error in H5D.write (line 100)
H5ML.hdf5lib2('H5Dwrite', varargin{:});

Error in saveh5>sparse2h5 (line 374)
H5D.write(oid,'H5ML_DEFAULT','H5S_ALL','H5S_ALL','H5P_DEFAULT',item);

Error in saveh5>mat2h5 (line 281)
        oid=sparse2h5(name,struct('Size',size(item),'SparseIndex',idx,'Real',item(idx)),handle,level,varargin{:});

Error in saveh5>obj2h5 (line 137)
    oid=mat2h5(name,item,handle,level,varargin{:});

Error in saveh5 (line 111)
    obj2h5(rootname,data,fid,1,opt);

Matlab version: 2022a

fangq commented 1 year ago

@abrahamzv, I confirm I can reproduce this issue on MATLAB R2020. However, the same code works fine for R2018a or earlier. So I suppose it is related to MATLAB library changes. Let me see if I can find a fix.

fangq commented 1 year ago

should be fixed by the above commit.