From 0471ee7493576e45e926a8a8a73234d9aec2cf92 Mon Sep 17 00:00:00 2001 From: Krishna Praneet Gudipaty Date: Sun, 7 Apr 2024 16:53:40 -0400 Subject: [PATCH] Fix: fixed iterations for bp decoder and added additional tests --- src/decoders/belief_propagation.jl | 2 +- test/test_bp_decoder.jl | 31 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/decoders/belief_propagation.jl b/src/decoders/belief_propagation.jl index 741a95e..ef4e190 100644 --- a/src/decoders/belief_propagation.jl +++ b/src/decoders/belief_propagation.jl @@ -118,7 +118,7 @@ function decode!(decoder::BeliefPropagationDecoder, syndrome::AbstractVector) # end converged = false - for iter::Int in decoder.max_iters + for iter::Int in 1:decoder.max_iters for i in 1:decoder.s temp::Float64 = (-1) ^ syndrome[i] for k::Int in nzrange(decoder.sparse_HT, i) diff --git a/test/test_bp_decoder.jl b/test/test_bp_decoder.jl index d4040b9..8673945 100644 --- a/test/test_bp_decoder.jl +++ b/test/test_bp_decoder.jl @@ -55,9 +55,40 @@ using LDPCDecoders return ler end + function test_ldpcdecoder() + H = LDPCDecoders.parity_check_matrix(1000,10,9); + decoder = LDPCDecoders.BeliefPropagationDecoder(H, 0.01, 100); + count = 0 + for _ in 1:1000 + error = rand(1000) .< 0.01; + syndrome = (H * error) .% 2; + guess, success = LDPCDecoders.decode!(decoder, syndrome); + count += error == guess + end + return 1-count/1000 + end + + function test_ldpcdecoder_old() + H = LDPCDecoders.parity_check_matrix(1000,10,9); + decoder = LDPCDecoders.BeliefPropagationDecoder(H, 0.01, 100); + count = 0 + for _ in 1:1000 + error = rand(1000) .< 0.01; + syndrome = (H * error) .% 2; + LDPCDecoders.reset!(decoder) + LDPCDecoders.syndrome_decode!(decoder, decoder.scratch, syndrome) + count += error == decoder.scratch.err + end + return 1-count/1000 + end + + @test test_bp_decoder() # There is a low possibility of these tests failing @test test_bp_decoder_batch() < 0.005 @test test_deprecated_syndrome_decoder() < 0.005 + + @test test_ldpcdecoder() < 0.001 + @test test_ldpcdecoder_old() < 0.001 end