mathnet / mathnet-numerics

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

Svd fails for dense matrix if number of rows or columns is greater than 16383. #736

Open eoner opened 4 years ago

eoner commented 4 years ago

Hi,

I'm getting System.OutOfMemoryExceptions when trying to call Svd() on dense matrices with nRows or nCols > 16383.

This is with MathNet.Numerics version 4.12.0 and MathNetNumerics.MKL-Win-x64 version 2.4.0.

// the following two calls fail
CreateMatrix.Random<double>(16384, 1, 1).Svd(true);
CreateMatrix.Random<double>(1, 16384, 1).Svd(true);

// this succeeds (no OutOfMemoryException)
CreateMatrix.Dense<double>(16383, 16383, 1).Svd(true);
wo80 commented 4 years ago

One of your SVD factors will be of size 16384 x 16384 and 16384 = 2^14, so the memory needed for a matrix of type double is 2^28 * 8 bytes = 2GB. This shouldn't be a problem on x64, but I guess if .NET is throwing an OutOfMemoryException you're out of memory and there's nothing MathNet can do about it.

EDIT: https://stackoverflow.com/questions/2415434/the-limitation-on-the-size-of-net-array

I just tested this running as netcoreapp3.1 x64. No OutOfMemoryException there.