Skip to content

Commit

Permalink
Update JuliaFormatter to not require return statement
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewilliami committed Nov 5, 2024
1 parent 4f6c7c0 commit 52554f8
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pipe_to_function_call = true
short_to_long_function_def = false
force_long_function_def = false
long_to_short_function_def = false
always_use_return = true
always_use_return = false
whitespace_in_kwargs = true
annotate_untyped_fields_with_any = false
format_docstrings = false
Expand Down
4 changes: 2 additions & 2 deletions examples/bounds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function make_integer_csv(stop_at::Integer)

CSV.write(data_file_desktop, D)
CSV.write(data_file_other, D)
return println("\nWrote data to $(data_file_other).")
println("\nWrote data to $(data_file_other).")
end

function bound_comparison(stop_at::Integer)::Tuple{Int, Array{Array{Number, 1}}}
Expand Down Expand Up @@ -119,7 +119,7 @@ function plot_bound_comparison(stop_at::Integer)
println("Data written to $(data_file_desktop) and $(data_file_other)")

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

# make_integer_csv constructs a csv file which looks for hamming bounds (given certain conditions) that are integers before rounding
Expand Down
2 changes: 1 addition & 1 deletion examples/get_codewords_time_analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function graphing_time(stop_at::Integer)

CSV.write(data_file_desktop, D)
CSV.write(data_file_other, D)
return println("Wrote data to $(data_file_other).")
println("Wrote data to $(data_file_other).")
end

graphing_time(stop_at)
4 changes: 2 additions & 2 deletions examples/plot_random_core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function add_plot_info(
factor2 = y > 1 ? 4 : 2.5
# plot!(annotations = (max(x * 2, x+100), (y - 10 * counter) / factor1,
# text(extra, :left, 13)))
return annotate!(plt, max(x * 2, x + 100), ((y - 10 * counter) / factor1), extra)
annotate!(plt, max(x * 2, x + 100), ((y - 10 * counter) / factor1), extra)
end

function graphing(
Expand Down Expand Up @@ -170,5 +170,5 @@ function graphing(
end

function graphing(q::Integer, n::Integer, d::Integer, stop_at::Integer; m::Integer = 10_000)
return graphing(q, n, d, obtain_data(q, n, d, stop_at; m = m), stop_at; m = m)
graphing(q, n, d, obtain_data(q, n, d, stop_at; m = m), stop_at; m = m)
end
7 changes: 4 additions & 3 deletions src/abstract_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ mutable struct Word{N, T}

Word(w::NTuple{N, T}) where {N, T} = new{N, T}(MVector{N, T}(w))
function Word(w::AbstractVector{T}) where {T}
return (len = length(w); new{len, T}(MVector{len, T}(w)))
len = length(w)
return new{len, T}(MVector{len, T}(w))
end
Word(w::AbstractString) = MVector{length(w), eltype(w)}(collect(w))
Word(i::T...) where {T} = (len = length(i); new{len, T}(MVector{len, T}(i)))
Expand Down Expand Up @@ -103,8 +104,8 @@ struct Alphabet{N} <: AbstractVector{Symbol} where {N}
Σ::AbstractVector{Symbol}

function Alphabet::Union{Vector{T}, String}) where {T}
return (Σ_unique = Set(Σ);
new{length(Σ_unique)}(ensure_symbolic(Σ_unique)))
Σ_unique = Set(Σ)
return new{length(Σ_unique)}(ensure_symbolic(Σ_unique))
end
end # end struct

Expand Down
56 changes: 28 additions & 28 deletions src/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ end
```julia
mod(p::Polynomial, n::Int) -> Polynomial
```
Uses the `FinitePolynomial` constructor to return a polynomial `p` under modulus `n`.
Parameters:
- `p::Polynomial`: The input polynomial.
- `n::Int`: The modulus of the field.
Returns
- Polynomial: A polynomial modulo n.
"""
Expand All @@ -43,13 +43,13 @@ Base.mod(p::Polynomial, n::Int) = FinitePolynomial(p, n).p
```julia
Polynomial(A::Union{NTuple{N, T}, Vector{T}}, n::Int) -> Polynomial
```
Constructs a polynomial under modulo `n`.
Parameters:
- `A::Union{Tuple, AbstractArray}`: The polynomial coefficients.
- `n::Int`: The modulus of the field.
Returns
- `Polynomial`: A polynomial modulo n.
"""
Expand All @@ -59,13 +59,13 @@ Polynomial(A::Union{NTuple{N, T}, Vector{T}}, n::Int) where {N, T} = mod(Polynom
```julia
list_polys(n::Int, m::Int) -> Array
```
Lists all polynomials of degree less than to `n` under modulo `m`.
Parameters:
- `n::Int`: Highest degree of polynomial.
- `m::Int`: The modulus of the field.
Returns:
- `Array`: An array of polynomials of degree less than n, under modulo m.
"""
Expand All @@ -78,13 +78,13 @@ end
```julia
multiplication_table(degree::Int, modulo::Int) -> Matrix
```
Returns a table (matrix) of the multiplication of all combinations of polynomials for degree less than `degree`, under modulo `modulo`.
Parameters:
- `degree::Int`: Highest degree of polynomial.
- `modulo::Int`: The modulus of the field.
Returns:
- `Matrix`: A multiplication table of all polynomials with degree less than n, under modulus.
Expand Down Expand Up @@ -148,7 +148,7 @@ Parameters:
- `v̲::Vector`: Another vector.
- `...`: Other vectors.
- `modulo::Int`: The modulus of the field.
Returns:
- `Array`: All vectors in the span of u̲ and v̲, under modulo.
Expand Down Expand Up @@ -176,14 +176,14 @@ list_span(args...) = __list_span_inner(last(args), args[1:(end - 1)]...)
```julia
islinear(C::Vector, modulo::Int; verbose::Bool = false) -> Bool
```
Determines whether a code `C` is a linear code (i.e., if it is closed under addition, scalar multiplication, and has the zero vector in it).
Parameters:
- `C::Vector`: A code, typically consisting of multiple vectors or strings.
- `modulo::Int`: The modulus of the field under which you are working.
- `verbose::Bool` (kwarg): print the point at which C fails, if it does.
Returns:
- `Bool`: Whether or not the code `C` is linear (true or false).
Expand Down Expand Up @@ -235,13 +235,13 @@ end
```julia
isirreducible(f::AbstractPolynomial, modulo::Int) -> Bool
```
Checks if a polynomial is irreducible.
Parameters:
- `f::Polynomial`: The polynomial you need to check.
- `modulo::Int`: The modulus under which you are working.
Returns:
- `Bool`: Whether or not the polynomial is irreducible (true or false).
Expand Down Expand Up @@ -276,7 +276,7 @@ Convert a matrix M into normal form under modulo n via Gauss-Jordan elimination.
Parameters:
- `M::AbstractArray{Int}`: A matrix of Ints.
- `n::Int`: The modulus of the finite field.
Returns:
- `Matrix{Int}`: A matrix in normal form from Gauss-Jordan elimination.
Expand Down Expand Up @@ -308,7 +308,7 @@ Convert a matrix M into normal form under modulo n via Gauss-Jordan elimination.
Parameters:
- `M::AbstractArray{Int}`: A matrix of Ints.
- `n::Int`: The modulus of the finite field.
Returns:
- `Matrix{Int}`: A matrix in normal form from Gauss-Jordan elimination.
Expand Down Expand Up @@ -340,7 +340,7 @@ Peforms Gauss-Jordan elimination on a matrix M, but allows for column swapping.
Parameters:
- `M::AbstractArray{Int}`: A matrix of Ints.
- `n::Int`: The modulus of the finite field.
Returns:
- `Matrix{Int}`: A which represents an "equivalent" code to that of the matrix M.
Expand Down Expand Up @@ -372,7 +372,7 @@ Peforms Gauss-Jordan elimination on a matrix M, but allows for column swapping.
Parameters:
- `M::AbstractArray{Int}`: A matrix of Ints.
- `n::Int`: The modulus of the finite field.
Returns:
- `Matrix{Int}`: A which represents an "equivalent" code to that of the matrix M.
Expand Down Expand Up @@ -404,12 +404,12 @@ Parameters:
- `M::AbstractArray{Int}`: A matrix of Ints.
- `n::Int`: The modulus of the finite field.
- `colswap::Bool` (kwarg): A boolean flag indicating whether or not you allow for swapping of columns when constructing the generating matrix.
Returns:
- `Matrix{Int}`: A generating matrix.
"""
function generator!(M::AbstractArray{Int}, n::Int; colswap::Bool = false)
return ifelse(colswap, equivalent_code!(M, n), normal_form!(M, n))
return colswap ? equivalent_code!(M, n) : normal_form!(M, n)
end

"""
Expand All @@ -423,7 +423,7 @@ Parameters:
- `M::AbstractArray{Int}`: A matrix of Ints.
- `n::Int`: The modulus of the finite field.
- `colswap::Bool` (kwarg): A boolean flag indicating whether or not you allow for swapping of columns when constructing the generating matrix.
Returns:
- `Matrix{Int}`: A generating matrix.
"""
Expand All @@ -435,13 +435,13 @@ end
```julia
parity_check(M::AbstractArray{Int}, n::Int) -> Matrix{Int}
```
Constructs a parity check matrix. This is calculated from taking the non-identity part of a matrix in normal form (or equivalent &mdash; see `generator`), transposing it, multiplying it by negative one, and appending to it an appropriate sized identity matrix.
Parameters:
- `M::AbstractArray{Int}`: A matrix of Ints.
- `n::Int`: The modulus of the finite field.
Returns:
- `Matrix{Int}`: A parity check matrix.
"""
Expand All @@ -457,16 +457,16 @@ end
```julia
syndrome(v̲::Vector, Hᵀ::AbstractArray{Int}, n::Int) -> Matrix{Int}
```
Calculates the syndrome of a given word v̲ and a parity check matrix, transposed (Hᵀ), under modulo n.
Parameters:
- `v̲::Vector`: A word in the code.
- `Hᵀ::AbstractArray{Int}`: The transpose of a parity check matrix.
Returns:
- `Vector`: The syndrome of a word in the code.
---
### Examples
Expand Down Expand Up @@ -495,7 +495,7 @@ If the syndrome of a code is the zero vector, then the word used to calculate th
Parameters:
- `v̲::Vector`: A word.
- `Hᵀ::AbstractArray{Int}`: The transpose of a parity check matrix.
Returns:
- `Bool`: If the word is in the code or not (true or false).
Expand Down
3 changes: 1 addition & 2 deletions src/bounds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ function ishammingperfect(r::Int, q::Int)

isequal(n, (q^r - 1) / (q - 1)) && \
isequal(d, 3) && \
isequal(M, q^(((q^r - 1) / (q - 1)) - r)) && \
return true
isequal(M, q^(((q^r - 1) / (q - 1)) - r)) && return true
return false
end

Expand Down
Loading

0 comments on commit 52554f8

Please sign in to comment.