public Matrix <string, string, double> ToKernel(Matrix <string, string, double> unnormalizedInput, int?cidInBatchCountOrNull = null) { if (null == cidInBatchCountOrNull) { return(ToKernel(unnormalizedInput)); } var input = RowNormalizer.Normalize(unnormalizedInput); var cidListList = SpecialFunctions.DivideListIntoEqualChunksFromChunkSize <string>(input.ColKeys, cidInBatchCountOrNull.Value); Console.WriteLine("cids divided into {0} batches of about {1}", cidListList.Count, cidInBatchCountOrNull); Helper.CheckCondition(cidListList.Sum(l => l.Count) == input.ColCount, "real assert"); var counterWithMessages = new CounterWithMessages("kernel combintations ", 1, (cidListList.Count * cidListList.Count + cidListList.Count) / 2); var kernelPieces2D = new Matrix <string, string, double> [cidListList.Count, cidListList.Count]; for (int i = 0; i < cidListList.Count; ++i) { Console.WriteLine("Loading batch {0}, size {1}x{2}", i, cidListList[i].Count, unnormalizedInput.RowCount); var matrixI = input.SelectColsView(cidListList[i]).ToShoMatrix(verbose: true); Parallel.For(i, cidListList.Count, ParallelOptionsScope.Current, j => { Console.WriteLine("Loading batch {0}, size {1}x{2}", j, cidListList[j].Count, unnormalizedInput.RowCount); if (i == j) { ShoMatrix kii = JustKernel(matrixI); kernelPieces2D[i, i] = kii; } else { var matrixJ = input.SelectColsView(cidListList[j]).ToShoMatrix(verbose: true); ShoMatrix kij = JustKernel(matrixI, matrixJ); kernelPieces2D[i, j] = kij; kernelPieces2D[j, i] = kij.TransposeView().ToShoMatrix(); } counterWithMessages.Increment(); }); } counterWithMessages.Finished(); var output = MatrixExtensions.MergeRowsAndColsView(kernelPieces2D); Helper.CheckCondition(output.RowKeys.SequenceEqual(output.ColKeys) && output.ColKeys.SequenceEqual(unnormalizedInput.ColKeys), "Assert: MergeRows isn't working as expected"); KernelNormalizeInPlace(ref output); return(output); }