Ejemplo n.º 1
0
        /// <summary>
        /// Writes a matrix with char values in DenseAnsi format to a textWriter. Does not need to convert to DenseAnsi format.
        /// </summary>
        /// <param name="matrix">The matrix to write</param>
        /// <param name="textWriter">The stream to write to</param>
        /// <param name="parallelOptions">A ParallelOptions instance that configures the multithreaded behavior of this operation.</param>
        public static void WriteDenseAnsi(this Matrix <string, string, char> matrix, TextWriter textWriter, ParallelOptions parallelOptions, bool verbose = false)
        {
            DenseAnsi denseAnsi = matrix as DenseAnsi;

            if (null != denseAnsi)
            {
                denseAnsi.WriteDenseAnsi <char>(textWriter, parallelOptions, verbose);
                return;
            }

            var counterWithMessages = new CounterWithMessages("writeDenseAnsi {0} {1} ", 1000, matrix.RowCount, !verbose);
            var lineQuery           =
                from rowKey in matrix.RowKeys
                .AsParallel().AsOrdered().WithDegreeOfParallelism(parallelOptions.MaxDegreeOfParallelism)
                select CreateLine(matrix, rowKey, counterWithMessages);

            textWriter.WriteLine("var\t{0}", matrix.ColKeys.StringJoin("\t"));
            foreach (string line in lineQuery)
            {
                textWriter.WriteLine(line);
            }
        }