mathnet / mathnet-numerics

Math.NET Numerics
http://numerics.mathdotnet.com
MIT License
3.5k stars 897 forks source link

MatlabReader gives Arithmetic overflow reading simple double matlab array #570

Open purpledawn777 opened 6 years ago

purpledawn777 commented 6 years ago

In F# 4.1 (visual f# tools 10.1), .net Standard 2.0, visual studio 15.7.1 community; in FSI reading matlab file with a single matrix (17196 x 6) with max value 1.15 e+10 gives arithmetic overflow exception despite easily fitting in a double. . .mat file loads fine in matlab (r2016a). Happens with some other matrices as well, but not all. Is this a bug, or what am I doing wrong? test data: sp500.zip [code] // read the first matrix as double let filePath = System.IO.Path.Combine( __ SOURCE_DIRECTORY __,"../path/to/sp500.mat") let m = MatlabReader.Read(filePath); [/code]

purpledawn777 commented 6 years ago

I think the issue is MatlabReader appears to read .mat v7 files, but not v7.3 files (the default since 2006??) ... and the documentation says it reads level 5 files, so I guess it is my JRTFM. It would be intuitive though that it should be able to read a (default!) file format that been around for 12 years now...

cdrnet commented 6 years ago

Yes, I'd love to support Matlab HDF5 files. Unfortunately HDF5 seems to be much more complicated than the old format, so we either need an implementation (which realistically I don't have time to contribute myself) or an existing library we can use.

purpledawn777 commented 6 years ago

I understand - here someone nicely created an f# hdf5 lib: https://rodhern.wordpress.com/2015/03/15/how-to-use-the-hdf5-type-provider/ https://rodhern.wordpress.com/2015/04/18/how-i-compile-the-hdf5-type-provider/

these leverage the dlls from the hdfgroup.org It would be great if that was incorporated into matlab reader, but if not now hopefully this comment will help others...