Skip to content

Commit 15d35ae

Browse files
committed
Apply formatting suggestions
1 parent 97fd5e9 commit 15d35ae

26 files changed

+2186
-1589
lines changed

.JuliaFormatter.toml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
indent = 4
2+
margin = 92
3+
always_for_in = true
4+
for_in_replacement = "in"
5+
whitespace_typedefs = true
6+
whitespace_ops_in_indices = true
7+
remove_extra_newlines = true
8+
import_to_using = true
9+
pipe_to_function_call = true
10+
short_to_long_function_def = false
11+
force_long_function_def = false
12+
long_to_short_function_def = false
13+
always_use_return = true
14+
whitespace_in_kwargs = true
15+
annotate_untyped_fields_with_any = false
16+
format_docstrings = false
17+
conditional_to_if = false
18+
normalize_line_endings = "unix"
19+
trailing_comma = true
20+
trailing_zero = true # TODO
21+
join_lines_based_on_source = false
22+
indent_submodule = false
23+
separate_kwargs_with_semicolon = false
24+
surround_whereop_typeparameters = true
25+
short_circuit_to_if = false
26+
disallow_single_arg_nesting = true

dev/.JuliaFormatter.toml

Whitespace-only changes.

docs/make.jl

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
using CodingTheory, Documenter
22

3-
Documenter.makedocs(
3+
Documenter.makedocs(;
44
clean = true,
55
doctest = true,
66
modules = Module[CodingTheory],
77
repo = "",
88
highlightsig = true,
99
sitename = "CodingTheory Documentation",
1010
expandfirst = [],
11-
pages = [
12-
"Index" => "index.md",
13-
]
11+
pages = ["Index" => "index.md"],
1412
)
1513

16-
deploydocs(;
17-
repo = "github.com/jakewilliami/CodingTheory.jl.git",
18-
)
14+
deploydocs(; repo = "github.com/jakewilliami/CodingTheory.jl.git")
1915

2016
# deploydocs(
2117
# target = "build",

examples/bounds.jl

+69-59
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#!/usr/bin/env bash
2-
#=
3-
exec julia -tauto --project="$(realpath $(dirname $0))" --color=yes --startup-file=no -e "include(popfirst!(ARGS))" \
4-
"${BASH_SOURCE[0]}" "$@"
5-
=#
6-
71
using CSV, DataFrames, StatsPlots, ProgressMeter
82

93
include(joinpath(dirname(dirname(@__FILE__)), "src", "CodingTheory.jl"))
@@ -16,29 +10,29 @@ function integer_search(stop_at::Integer)::Array{Array{Number, 1}}
1610
A = []
1711
upper_bound = 10
1812
increment_bound = 10
19-
processed = []
20-
i = 0
13+
processed = []
14+
i = 0
2115
p = Progress(stop_at, 1) # minimum update interval: 1 second
22-
16+
2317
while true
2418
for q in 1:upper_bound, n in 1:upper_bound, d in 1:upper_bound
25-
# skip configurations that have already been processed
26-
# arelessthan(upper_bound - increment_bound, q, n, d) && continue
27-
(q, n, d) ∈ processed && continue
19+
# skip configurations that have already been processed
20+
# arelessthan(upper_bound - increment_bound, q, n, d) && continue
21+
(q, n, d) processed && continue
2822
# note that we actually don't want to filter out non-linear codes
29-
# distance shouldn't be larger than the block length; filter trivial distances of one; we filter out combinations when all are equal; filter out codes that are generalised hamming codes; filter out even distances
30-
# if d < n && ! isone(q) #&& ! CodingTheory.allequal(q, n, d) && ! ishammingperfect(q, n, d) && ! iseven(d) && ! isprimepower(q)
31-
q, n, d = big(q), big(n), big(d)
32-
hb = hamming_bound(q, n, d, no_round)
33-
sb = singleton_bound(q, n, d, no_round)
34-
35-
# if isinteger(hb) #&& ! isone(hb) && ! isone(sb) && hb ≤ sb
36-
push!(processed, (q, n, d))
37-
# i += 1; println("$i:\t$q, $n, $d")
38-
push!(A, [q, n, d, hb, sb])
39-
isequal(length(A), stop_at) && return A
40-
next!(p)
41-
# end
23+
# distance shouldn't be larger than the block length; filter trivial distances of one; we filter out combinations when all are equal; filter out codes that are generalised hamming codes; filter out even distances
24+
# if d < n && ! isone(q) #&& ! CodingTheory.allequal(q, n, d) && ! ishammingperfect(q, n, d) && ! iseven(d) && ! isprimepower(q)
25+
q, n, d = big(q), big(n), big(d)
26+
hb = hamming_bound(q, n, d, no_round)
27+
sb = singleton_bound(q, n, d, no_round)
28+
29+
# if isinteger(hb) #&& ! isone(hb) && ! isone(sb) && hb ≤ sb
30+
push!(processed, (q, n, d))
31+
# i += 1; println("$i:\t$q, $n, $d")
32+
push!(A, [q, n, d, hb, sb])
33+
isequal(length(A), stop_at) && return A
34+
next!(p)
35+
# end
4236
# end
4337
end
4438
upper_bound += increment_bound
@@ -47,41 +41,52 @@ end
4741

4842
function make_integer_csv(stop_at::Integer)
4943
A = integer_search(stop_at)
50-
D = DataFrame(q = Number[], n = Number[], d = Number[], hamming_bound = Number[], singleton_bound = Number[])
44+
D = DataFrame(;
45+
q = Number[],
46+
n = Number[],
47+
d = Number[],
48+
hamming_bound = Number[],
49+
singleton_bound = Number[],
50+
)
5151

5252
for i in A
5353
push!(D, i)
5454
end
55-
56-
data_file_desktop = joinpath(homedir(), "Desktop", "bound_integers_$(stop_at).csv")
57-
data_file_other = joinpath(dirname(dirname(@__FILE__)), "other", "bound_integers_$(stop_at).csv")
55+
56+
data_file_desktop = joinpath(homedir(), "Desktop", "bound_integers_$(stop_at).csv")
57+
data_file_other = joinpath(
58+
dirname(dirname(@__FILE__)), "other", "bound_integers_$(stop_at).csv"
59+
)
5860

5961
CSV.write(data_file_desktop, D)
6062
CSV.write(data_file_other, D)
61-
println("\nWrote data to $(data_file_other).")
63+
return println("\nWrote data to $(data_file_other).")
6264
end
6365

6466
function bound_comparison(stop_at::Integer)::Tuple{Int, Array{Array{Number, 1}}}
6567
A = Array{AbstractFloat}[]
66-
processed = []
68+
processed = []
6769
upper_bound = 10
6870
increment_bound = 10
69-
i = 0
70-
71+
i = 0
72+
7173
while true
7274
@showprogress for q in 1:upper_bound, n in 1:upper_bound, d in 1:upper_bound
73-
# skip configurations that have already been processed
74-
# arelessthan(upper_bound - increment_bound, q, n, d) && continue
75-
(q, n, d) ∈ processed && continue
76-
# remove q non prime powers
75+
# skip configurations that have already been processed
76+
# arelessthan(upper_bound - increment_bound, q, n, d) && continue
77+
(q, n, d) processed && continue
78+
# remove q non prime powers
7779
if isprimepower(big(q))
7880
hb = hamming_bound(q, n, d)
7981
sb = singleton_bound(q, n, d)
80-
# filter out the more trivial bounds that are one (or if distance is one); filter out distances that are more than or equal to the block length, as they don't make sense in our context; filter out even distances
81-
# if d < n || 1 ∉ (hb, sb, d)
82-
if d < n && ! isone(d) && ! CodingTheory.allequal(q, n, d) && ! iszero(mod(d, 2))
83-
push!(processed, (q, n, d))
84-
# i += 1; println("$i:\t$q, $n, $d")
82+
# filter out the more trivial bounds that are one (or if distance is one); filter out distances that are more than or equal to the block length, as they don't make sense in our context; filter out even distances
83+
# if d < n || 1 ∉ (hb, sb, d)
84+
if d < n &&
85+
!isone(d) &&
86+
!CodingTheory.allequal(q, n, d) &&
87+
!iszero(mod(d, 2))
88+
push!(processed, (q, n, d))
89+
# i += 1; println("$i:\t$q, $n, $d")
8590
comparison = hb > sb ? 1 : (sb > hb ? -1 : 0)
8691
push!(A, [q, n, d, hb, sb, comparison])
8792
isequal(length(A), stop_at) && return stop_at, A
@@ -93,27 +98,32 @@ function bound_comparison(stop_at::Integer)::Tuple{Int, Array{Array{Number, 1}}}
9398
end
9499

95100
function plot_bound_comparison(stop_at::Integer)
96-
number_of_bounds, A = bound_comparison(stop_at)
97-
D = DataFrame(q = Number[], n = Number[], d = Number[], hamming_bound = Number[], singleton_bound = Number[], comparison = Number[])
98-
99-
for i in A
100-
push!(D, i)
101-
end
102-
103-
data_file_desktop = joinpath(homedir(), "Desktop", "bound_comparison_$(stop_at).csv")
104-
data_file_other = joinpath(dirname(dirname(@__FILE__)), "other", "bound_comparison_$(stop_at).csv")
105-
106-
CSV.write(data_file_desktop, D)
107-
CSV.write(data_file_other, D)
108-
println("Data written to $(data_file_desktop) and $(data_file_other)")
109-
110-
`Rscript --vanilla "~"/projects/CodingTheory.jl/other/regression-tree.R $data_file_other $stop_at`
111-
println("Regression tree saved at $(joinpath(dirname(dirname(@__FILE__)), "other", "Rplots_$(stop_at).pdf"))")
112-
end
101+
number_of_bounds, A = bound_comparison(stop_at)
102+
D = DataFrame(;
103+
q = Number[],
104+
n = Number[],
105+
d = Number[],
106+
hamming_bound = Number[],
107+
singleton_bound = Number[],
108+
comparison = Number[],
109+
)
113110

111+
for i in A
112+
push!(D, i)
113+
end
114114

115+
data_file_desktop = joinpath(homedir(), "Desktop", "bound_comparison_$(stop_at).csv")
116+
data_file_other = joinpath(
117+
dirname(dirname(@__FILE__)), "other", "bound_comparison_$(stop_at).csv"
118+
)
115119

120+
CSV.write(data_file_desktop, D)
121+
CSV.write(data_file_other, D)
122+
println("Data written to $(data_file_desktop) and $(data_file_other)")
116123

124+
`Rscript --vanilla "~"/projects/CodingTheory.jl/other/regression-tree.R $data_file_other $stop_at`
125+
return println("Regression tree saved at $(joinpath(dirname(dirname(@__FILE__)), "other", "Rplots_$(stop_at).pdf"))",)
126+
end
117127

118128
# make_integer_csv constructs a csv file which looks for hamming bounds (given certain conditions) that are integers before rounding
119129
make_integer_csv(stop_at) # takes a command line argument
+31-17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#!/usr/bin/env bash
2-
#=
3-
exec julia --project="$(realpath $(dirname $0))" --color=yes --startup-file=no -e "include(popfirst!(ARGS))" \
4-
"${BASH_SOURCE[0]}" "$@"
5-
=#
6-
71
using StatsPlots, ProgressMeter, CSV, DataFrames
82

93
include(joinpath(dirname(dirname(@__FILE__)), "src", "CodingTheory.jl"))
@@ -16,34 +10,54 @@ function graphing_time(stop_at::Integer)
1610
stop_n_at = 8
1711
num_of_datapoints = stop_at
1812
data = Matrix{Float64}(undef, num_of_datapoints, 3) # needs 3 columns: q, n, and time
19-
13+
2014
@showprogress for i in 1:num_of_datapoints
2115
q = rand(1:stop_q_at)
2216
n = rand(1:stop_n_at)
2317
time_took = @elapsed get_all_words(q, n)
2418
data[i, :] .= [q, n, time_took]
2519
end
2620

27-
save_path = joinpath(dirname(@__DIR__), "other", "get_codewords_time_analysis,n=$stop_n_at,m=$stop_q_at,i=$num_of_datapoints.pdf")
21+
save_path = joinpath(
22+
dirname(@__DIR__),
23+
"other",
24+
"get_codewords_time_analysis,n=$stop_n_at,m=$stop_q_at,i=$num_of_datapoints.pdf",
25+
)
2826
theme(:solarized)
29-
30-
plot_points = scatter(data[:,1:2], data[:,3], fontfamily = font("Times"), ylabel = "Time elapsed during calculation [seconds]", clabel = "Value of q or n", label = ["q" "n"], smooth = true)#, xlims = (0, stop_n_at)) # smooth = true
31-
27+
28+
plot_points = scatter(
29+
data[:, 1:2],
30+
data[:, 3];
31+
fontfamily = font("Times"),
32+
ylabel = "Time elapsed during calculation [seconds]",
33+
clabel = "Value of q or n",
34+
label = ["q" "n"],
35+
smooth = true,
36+
)#, xlims = (0, stop_n_at)) # smooth = true
37+
3238
savefig(plot_points, save_path)
3339
println("Plot saved at $save_path.")
34-
35-
D = DataFrame(q = Number[], n = Number[], time = Number[])
40+
41+
D = DataFrame(; q = Number[], n = Number[], time = Number[])
3642

3743
for i in eachrow(data)
3844
push!(D, i)
3945
end
40-
41-
data_file_desktop = joinpath(homedir(), "Desktop", "get_codewords_time_analysis,n=$stop_n_at,m=$stop_q_at,i=$num_of_datapoints.csv")
42-
data_file_other = joinpath(dirname(dirname(@__FILE__)), "other", "get_codewords_time_analysis,n=$stop_n_at,m=$stop_q_at,i=$num_of_datapoints.csv")
46+
47+
data_file_desktop = joinpath(
48+
homedir(),
49+
"Desktop",
50+
"get_codewords_time_analysis,n=$stop_n_at,m=$stop_q_at,i=$num_of_datapoints.csv",
51+
)
52+
data_file_other = joinpath(
53+
dirname(dirname(@__FILE__)),
54+
"other",
55+
"get_codewords_time_analysis,n=$stop_n_at,m=$stop_q_at,i=$num_of_datapoints.csv",
56+
)
4357

4458
CSV.write(data_file_desktop, D)
4559
CSV.write(data_file_other, D)
46-
println("Wrote data to $(data_file_other).")
60+
return println("Wrote data to $(data_file_other).")
4761
end
4862

4963
graphing_time(stop_at)

examples/plot_random.jl

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
#!/usr/bin/env bash
2-
#=
3-
exec julia -tauto --project="$(realpath $(dirname $0))" --color=yes --startup-file=no -e "include(popfirst!(ARGS))" \
4-
"${BASH_SOURCE[0]}" "$@"
5-
=#
6-
71
include("plot_random_core.jl")
82

93
if isempty(ARGS) || length(ARGS) < 4
10-
throw(error("""
11-
Please specify the number of datapoints you want to calculate from the command line, along with q, n, and d. For example
12-
./examples/plot_random.jl 6 7 3 1000 10000 # q, n, d, num_data_points, selection_set_size
13-
That is respectively: the size of the alphabet; the block length of the words; the distance of the code; the number of datapoints in the code; and the selection set size of each "random" sample.
14-
"""))
4+
throw(error("""
5+
Please specify the number of datapoints you want to calculate from the command line, along with q, n, and d. For example
6+
./examples/plot_random.jl 6 7 3 1000 10000 # q, n, d, num_data_points, selection_set_size
7+
That is respectively: the size of the alphabet; the block length of the words; the distance of the code; the number of datapoints in the code; and the selection set size of each "random" sample.
8+
""",),)
159
end
1610

1711
global q = parse(Int, ARGS[1])
@@ -24,4 +18,4 @@ global upper_bound_adjustment = 10
2418
global 🐖 = length(get_codewords_greedy(q, n, d))
2519
global 🍖 = hamming_bound(q, n, d)
2620
global 🐺 = singleton_bound(q, n, d)
27-
graphing(q, n, d, stop_at, m = m)
21+
graphing(q, n, d, stop_at; m = m)

0 commit comments

Comments
 (0)