private static void AnalyzeCode(ICode code, int errorsCount, int?decodingThreadsCount = null) { var informationWord = Enumerable.Repeat(code.Field.Zero(), code.InformationWordLength).ToArray(); var codeword = code.Encode(informationWord); var processedNoises = 0; Parallel.ForEach( NoiseGenerator.VariatePositionsAndValues(code.Field, code.CodewordLength, errorsCount), new ParallelOptions { MaxDegreeOfParallelism = decodingThreadsCount ?? (int)(Environment.ProcessorCount * 1.5d) }, x => { var decodingResults = code.DecodeViaList(codeword.AddNoise(x), errorsCount); if (decodingResults.Contains(informationWord, WordsComparer) == false) { throw new InvalidOperationException($"Failed to process noise {string.Join<FieldElement>(",", x)}"); } if (Interlocked.Increment(ref processedNoises) % 50 == 0) { Logger.LogInformation($"[{Thread.CurrentThread.ManagedThreadId}]: Current noise value ({string.Join<FieldElement>(",", x)})"); } if (TelemetryCollector.ProcessedSamplesCount % 100 == 0) { Logger.LogInformation(TelemetryCollector.ToString()); } } ); }
public AnalyzingSample(ICode code, FieldElement[] informationWord = null) { Code = code; InformationWord = informationWord ?? Enumerable.Repeat(Code.Field.Zero(), Code.InformationWordLength).ToArray(); Codeword = code.Encode(InformationWord); }