OutOfMemoryException with Matrices

(Max Medvedenko) #1

Hello! I’ve this problem with initialisation huge matrices such as 10000x10000. Asking for help or may be you know how can i keep in memory two or three this matrices without the exception. My program is working on x86 OS, so i have near 3 Gb of memory.
This is my code:

        var abMatrix = aMatrix.TransposeAndMultiply(bMatrix);

        aMatrix.MapInplace(x => x * x);
        bMatrix.MapInplace(x => x * x);

        var aParcel = aMatrix.RowSums();
        var bParcel = bMatrix.ColumnSums();
        GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;

        var rr1 = abMatrix.MapIndexed((i, j, x) => aParcel[i] + bParcel[j] - 2 * x);

        var v = rr1.EnumerateRows().Sum(x => x.Min()) / rr1.RowCount;
        var v1 = rr1.EnumerateColumns().Sum(x => x.Min()) / rr1.ColumnCount;

Thanks for help!