Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft PR for using the new iterator #48

Draft
wants to merge 16 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions benchmarks/iterators_bench.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using CodingTheory
using Oscar
using LinearAlgebra
using BenchmarkTools

function visit_all_subsets(mutate, g_len, v_weight, subset)
if subset
gi=CodingTheory.SubsetGrayCode(g_len, v_weight)
else
gi=CodingTheory.GrayCode(g_len, v_weight; mutate = mutate)
end
for subset in gi
# BenchmarkTools can elide simple computations so we need to do some nontrivial calculation here.
# In any realistic situation we need to look at least look at all entries of the vector.
# Ill model the task of looking at the entries using the 'all' function
Base.all(i->(i==0), subset)
end
return
end

#=
SubsetGrayCode and GrayCode appear to be in the same ballpark.
GrayCode is faster, SubsetGrayCode uses less memory.

######
# n=25, k=12, mutate=true
######
@benchmark visit_all_subsets(25, 12, false)
BenchmarkTools.Trial: 54 samples with 1 evaluation.
Range (min … max): 66.365 ms … 219.557 ms ┊ GC (min … max): 0.00% … 34.15%
Time (median): 92.912 ms ┊ GC (median): 26.24%
Time (mean ± σ): 93.526 ms ± 27.981 ms ┊ GC (mean ± σ): 19.78% ± 13.74%

▂▂ █▃
███▅▅▁▁▁▁▄▁▁█████▁▁▄▁▁▁▁▄▁▁▁▁▁▅▁▁▁▁▁▁▁▁▁▄▁▁▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄ ▁
66.4 ms Histogram: frequency by time 181 ms <

Memory estimate: 158.70 MiB, allocs estimate: 5200322.

BenchmarkTools.Trial: 65 samples with 1 evaluation.
Range (min … max): 51.159 ms … 103.931 ms ┊ GC (min … max): 0.00% … 50.88%
Time (median): 77.176 ms ┊ GC (median): 31.98%
Time (mean ± σ): 77.271 ms ± 6.824 ms ┊ GC (mean ± σ): 31.52% ± 7.35%

█ ▁
▃▃▁▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▅▆████▅▆▅▁▃▃▁▁▄▁▁▃▁▁▁▁▃ ▁
51.2 ms Histogram: frequency by time 89.3 ms <

Memory estimate: 238.05 MiB, allocs estimate: 5200308.
=#
66 changes: 66 additions & 0 deletions benchmarks/weight_dist_bench.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Oscar, CodingTheory
using Combinatorics
using LinearAlgebra
using BenchmarkTools
using Random
using Dates
# using AllocCheck
# using Profile
include("benchmark_utils.jl")
CodingTheory.Random.seed!(0)

function white_n70_k35(use_mine, terse_description)
F = Oscar.Nemo.Native.GF(2)
mat = matrix(F, [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 1 1 0 1 1 1 0 1 0 1 1 1 1 0 1 1 0 1 1 0 0 1 0 0 1 1 0 1;
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 0 1 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 1 1 1 0 0 0 1 0;
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 0 1 1 0 0 0 0 0 1 0 0 1 1 1 0 1 1 0 1 0 0 1 1 1 1 0 0;
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 1 0 0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0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 1 1 1 1 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 0 1 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 1 1 1 0 0 0 1 0 0 1 1;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 0 1 1 0 0 0 1 0 0 1 1 0 1 1 0 1 1 0 1 0 0 0 0 1 1 1])

num_thrds = Threads.nthreads()
println("Benchmarking with $num_thrds threads.")
if use_mine
function_description = "_minimum_distance_BZ(codeN70K35,:Brouwer;false)"
terse_description ? println(function_description) : println(benchmark_description(function_description))
return @benchmark CodingTheory._minimum_distance_BZ(codeN70K35, info_set_alg = :Brouwer; verbose = false) setup = (codeN70K35=LinearCode($mat, false, false))
else
function_description = "_minimum_distance_enumeration_with_matrix_multiply(codeN70K35,:Brouwer;false)"
terse_description ? println(function_description) : println(benchmark_description(function_description))
return @benchmark CodingTheory._minimum_distance_enumeration_with_matrix_multiply(codeN70K35, info_set_alg = :Brouwer; verbose = false) setup = (codeN70K35=LinearCode($mat, false, false))
end
end

use_new=false
t = white_n70_k35(use_new, true)
# t = test_white_105(use_mine)
t
8 changes: 4 additions & 4 deletions src/Classical/linear_code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ minimum_distance_upper_bound(C::AbstractLinearCode) = C.u_bound
Return `true` if code is maximum distance separable (MDS).
"""
function is_MDS(C::AbstractLinearCode)
ismissing(C.d) && minimum_distance(C)
ismissing(C.d) && minimum_distance_Gray(C)
return C.d == Singleton_bound(C.n, C.k)
end

Expand Down Expand Up @@ -671,8 +671,8 @@ end

Return the syndrome of `v` with respect to `C`.
"""
function syndrome(C::AbstractLinearCode, v::Union{CTMatrixTypes, Vector{Int}})
w = isa(v, Vector{Int}) ? matrix(C.F, length(v), 1, v) : v
function syndrome(C::AbstractLinearCode, v::Union{CTMatrixTypes, Vector{Int}, Vector{fpFieldElem}, Vector{FpFieldElem}})
w = isa(v, Union{Vector{Int}, Vector{fpFieldElem}, Vector{FpFieldElem}}) ? matrix(C.F, length(v), 1, v) : v
H = parity_check_matrix(C)
nc = ncols(H)
(size(w) != (nc, 1) && size(w) != (1, nc)) &&
Expand All @@ -693,7 +693,7 @@ end

Return whether or not `v` is a codeword of `C`.
"""
in(v::Union{CTMatrixTypes, Vector{Int}}, C::AbstractLinearCode) = iszero(syndrome(C, v))
in(v::Union{CTMatrixTypes, Vector{Int}, Vector{fpFieldElem}, Vector{FpFieldElem}}, C::AbstractLinearCode) = iszero(syndrome(C, v))

"""
⊆(C1::AbstractLinearCode, C2::AbstractLinearCode)
Expand Down
Loading
Loading