From a59286d0d4e7b35ad904fd217d87af9ee67b9402 Mon Sep 17 00:00:00 2001 From: Azzaare Date: Thu, 25 Apr 2024 15:52:36 +0900 Subject: [PATCH] Auto sciml format with JuliaFormatter --- .JuliaFormatter.toml | 1 + docs/make.jl | 28 ++++++++++++------------- perf/allocs.jl | 4 ++-- perf/bench.jl | 6 +++--- src/common.jl | 4 ++-- src/immutable_vector.jl | 36 ++++++++++++++++---------------- src/intervals.jl | 46 ++++++++++++++++++++--------------------- src/vector.jl | 40 +++++++++++++++++------------------ 8 files changed, 83 insertions(+), 82 deletions(-) create mode 100644 .JuliaFormatter.toml diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml new file mode 100644 index 0000000..453925c --- /dev/null +++ b/.JuliaFormatter.toml @@ -0,0 +1 @@ +style = "sciml" \ No newline at end of file diff --git a/docs/make.jl b/docs/make.jl index a36be8a..a23bdd2 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,24 +1,24 @@ using PatternFolds using Documenter -DocMeta.setdocmeta!(PatternFolds, :DocTestSetup, :(using PatternFolds); recursive=true) +DocMeta.setdocmeta!(PatternFolds, :DocTestSetup, :(using PatternFolds); recursive = true) makedocs(; - modules=[PatternFolds], - authors="Jean-Francois Baffier", - repo="https://github.com/Humans-of-Julia/PatternFolds.jl/blob/{commit}{path}#{line}", - sitename="PatternFolds.jl", - format=Documenter.HTML(; - prettyurls=get(ENV, "CI", "false") == "true", - canonical="https://Humans-of-Julia.github.io/PatternFolds.jl", - assets=String[], + modules = [PatternFolds], + authors = "Jean-Francois Baffier", + repo = "https://github.com/Humans-of-Julia/PatternFolds.jl/blob/{commit}{path}#{line}", + sitename = "PatternFolds.jl", + format = Documenter.HTML(; + prettyurls = get(ENV, "CI", "false") == "true", + canonical = "https://Humans-of-Julia.github.io/PatternFolds.jl", + assets = String[] ), - pages=[ - "Home" => "index.md", - ], + pages = [ + "Home" => "index.md" + ] ) deploydocs(; - repo="github.com/Humans-of-Julia/PatternFolds.jl", - devbranch="main", + repo = "github.com/Humans-of-Julia/PatternFolds.jl", + devbranch = "main" ) diff --git a/perf/allocs.jl b/perf/allocs.jl index 36acf13..2a0ea31 100644 --- a/perf/allocs.jl +++ b/perf/allocs.jl @@ -15,7 +15,7 @@ using PatternFolds function alloc() # 0.2.x # Intervals - itv = Interval{Open,Closed}(0.0, 1.0) + itv = Interval{Open, Closed}(0.0, 1.0) i = IntervalsFold(itv, 2.0, 1000) @info "Checking IntervalsFold" i pattern(i) gap(i) folds(i) size(i) length(i) @@ -62,5 +62,5 @@ using PatternFolds # end # Actual call to PerfChecker - alloc_check(title, dependencies, targets, alloc, alloc; path=@__DIR__) + alloc_check(title, dependencies, targets, alloc, alloc; path = @__DIR__) end diff --git a/perf/bench.jl b/perf/bench.jl index 6476f5f..cc4cd98 100644 --- a/perf/bench.jl +++ b/perf/bench.jl @@ -7,7 +7,7 @@ target = PatternFolds function bench() # 0.2.x # Intervals - itv = Interval{Open,Closed}(0.0, 1.0) + itv = Interval{Open, Closed}(0.0, 1.0) i = IntervalsFold(itv, 2.0, 1000) unfold(i) @@ -52,7 +52,7 @@ end # return nothing # end -t = @benchmark bench() evals = 1 samples = 1000 seconds = 3600 +t = @benchmark bench() evals=1 samples=1000 seconds=3600 # Actual call to PerfChecker -store_benchmark(t, target; path=@__DIR__) +store_benchmark(t, target; path = @__DIR__) diff --git a/src/common.jl b/src/common.jl index a833dac..8942029 100644 --- a/src/common.jl +++ b/src/common.jl @@ -79,7 +79,7 @@ function fold(v::V, depth = 0; kind = :mutable) where {T <: Real, V <: AbstractV for i in 1:(l ÷ 2) gap = v[i + 1] - v[1] fold, r = divrem(l, i) - if r == 0 && check_pattern(v, i, gap, fold) + if r == 0 && check_pattern(v, i, gap, fold) # return VectorFold(fold(v[1:i], depth + 1), gap, fold) return make_vector_fold(v[1:i], gap, fold, kind) end @@ -102,7 +102,7 @@ end function make_vector_fold(isf; kind = :mutable) vf = kind == :mutable ? "VectorFold" : "IVectorFold" str = "The pattern of the interval is not a point." * - " The IntervalsFold cannot be converted to a $vf" + " The IntervalsFold cannot be converted to a $vf" @assert is_points(isf) str return make_vector_fold([value(pattern(isf), :a)], gap(isf), folds(isf), kind) diff --git a/src/immutable_vector.jl b/src/immutable_vector.jl index 2774519..ea80d38 100644 --- a/src/immutable_vector.jl +++ b/src/immutable_vector.jl @@ -2,7 +2,7 @@ VectorFold{T,V <: AbstractVector{T}} A folded vector structure that extends the methods of AbstractVector to a folded structure. """ -struct IVectorFold{T,V <: AbstractVector{T}} <: AbstractVectorFold{T} +struct IVectorFold{T, V <: AbstractVector{T}} <: AbstractVectorFold{T} pattern::V gap::T folds::Int @@ -20,7 +20,7 @@ pattern(vf, index) = pattern(vf)[index] unfold(vf::VectorFold; from=1, to=folds(vf)) Construct the unfolded version of `vf` (with the same type as `pattern(vf)`) based. Please note that using an iterator on `vf` avoid memory allocation, which is not the case of `unfold`. """ -function unfold(vf::IVectorFold; from=1, to=folds(vf)) +function unfold(vf::IVectorFold; from = 1, to = folds(vf)) pl = pattern_length(vf) ul = (to - from + 1) * pl v = typeof(pattern(vf))(undef, ul) @@ -45,38 +45,38 @@ Base.iterate(iter::IVectorFold) = (pattern(iter, 1), 1) # Base case iterate meth function Base.iterate(iter::IVectorFold, state::Int) state ≥ length(iter) && return nothing - next_state = state + 1 + next_state = state + 1 pl = pattern_length(iter) - pattern_counter = mod1(next_state, pl) - fold_counter = state ÷ pl - elem = pattern(iter, pattern_counter) + (fold_counter * gap(iter)) + pattern_counter = mod1(next_state, pl) + fold_counter = state ÷ pl + elem = pattern(iter, pattern_counter) + (fold_counter * gap(iter)) - return elem, next_state + return elem, next_state end # Reverse iterate method -function Base.iterate(r_iter::Base.Iterators.Reverse{IVectorFold{T,V}}, - state::Int = length(r_iter.itr) -) where {T,V} - state < 1 && return nothing +function Base.iterate(r_iter::Base.Iterators.Reverse{IVectorFold{T, V}}, + state::Int = length(r_iter.itr) +) where {T, V} + state < 1 && return nothing - next_state = state - 1 - iter = r_iter.itr + next_state = state - 1 + iter = r_iter.itr pl = pattern_length(iter) - pattern_counter = mod1(state, pl) - fold_counter = next_state ÷ pl - elem = pattern(iter, pattern_counter) + (fold_counter * gap(iter)) + pattern_counter = mod1(state, pl) + fold_counter = next_state ÷ pl + elem = pattern(iter, pattern_counter) + (fold_counter * gap(iter)) - return elem, next_state + return elem, next_state end # Folding a vector to give a suitable VectorFold check_pattern(v, w, gap) = all(i -> i == gap, w - v) function check_pattern(v, i, gap, fold) - for j in 1:(fold -1) + for j in 1:(fold - 1) v_start, v_end = (j - 1) * i + 1, j * i w_start, w_end = j * i + 1, (j + 1) * i !check_pattern(v[v_start:v_end], v[w_start:w_end], gap) && return false diff --git a/src/intervals.jl b/src/intervals.jl index 81031b8..083e9bc 100644 --- a/src/intervals.jl +++ b/src/intervals.jl @@ -3,7 +3,7 @@ Base.ndims(::Interval) = 1 -function Base.rand(i::Interval{T,L,R}) where {T,L,R} +function Base.rand(i::Interval{T, L, R}) where {T, L, R} # α = max(_minfloat(T), first(i)) # β = min(_maxfloat(T), last(i)) μ = maxintfloat(T, Int) @@ -12,7 +12,7 @@ function Base.rand(i::Interval{T,L,R}) where {T,L,R} δ = β - α # if δ === Inf if δ > μ - return rand(rand() < 0.5 ? α..zero(T) : zero(T)..β) + return rand(rand() < 0.5 ? α .. zero(T) : zero(T) .. β) else # r = α + exp10(log10(δ) * rand()) r = α + δ * rand() @@ -22,14 +22,14 @@ function Base.rand(i::Interval{T,L,R}) where {T,L,R} end # TODO - Optimise the type of Intervals.Bound (currently abstract super type) -mutable struct IntervalsFold{T<:AbstractFloat,L<:Intervals.Bound,R<:Intervals.Bound} - pattern::Interval{T,L,R} +mutable struct IntervalsFold{T <: AbstractFloat, L <: Intervals.Bound, R <: Intervals.Bound} + pattern::Interval{T, L, R} gap::T folds::Int current::Int end -IntervalsFold(p, g, f, c=1) = IntervalsFold(p, g, f, c) +IntervalsFold(p, g, f, c = 1) = IntervalsFold(p, g, f, c) @forward IntervalsFold.pattern Base.isempty, Base.ndims @@ -42,16 +42,16 @@ function pattern(isf::IntervalsFold) return isf.pattern + (-distortion) end -function unfold(isf::IntervalsFold{T,L,R}) where {T,L,R} +function unfold(isf::IntervalsFold{T, L, R}) where {T, L, R} reset_pattern!(isf) x = first(pattern(isf)) y = last(pattern(isf)) g = gap(isf) f = folds(isf) - return [Interval{T,L,R}(x + g * i, y + g * i) for i in 0:(f - 1)] + return [Interval{T, L, R}(x + g * i, y + g * i) for i in 0:(f - 1)] end -function set_fold!(isf::IntervalsFold, new_fold=isf.current + 1) +function set_fold!(isf::IntervalsFold, new_fold = isf.current + 1) if new_fold != isf.current && 0 < new_fold ≤ isf.folds distortion = gap(isf) * (new_fold - isf.current) isf.pattern += distortion @@ -78,7 +78,7 @@ end # Reverse iterate method function Base.iterate( - r_iter::Base.Iterators.Reverse{<:IntervalsFold}, state::Int=length(r_iter.itr) + r_iter::Base.Iterators.Reverse{<:IntervalsFold}, state::Int = length(r_iter.itr) ) state < 1 && return nothing iter = r_iter.itr @@ -96,7 +96,7 @@ Base.size(isf::IntervalsFold) = span(isf.pattern) * folds(isf) Base.length(isf::IntervalsFold) = folds(isf) -Base.eltype(::Type{<:IntervalsFold{T,L,R}}) where {T,L,R} = Interval{T,L,R} +Base.eltype(::Type{<:IntervalsFold{T, L, R}}) where {T, L, R} = Interval{T, L, R} is_points(isf) = is_point(pattern(isf)) @@ -123,21 +123,21 @@ function Base.rand(v::V) where {V <: Set{<:IntervalsFold}} end @testitem "IntervalsFold" tags=[:intervals] begin - i01 = Interval{Open,Closed}(0.0, 1.0) - i23 = Interval{Open,Closed}(2.0, 3.0) - i45 = Interval{Open,Closed}(4.0, 5.0) - i67 = Interval{Open,Closed}(6.0, 7.0) - i89 = Interval{Open,Closed}(8.0, 9.0) + i01 = Interval{Open, Closed}(0.0, 1.0) + i23 = Interval{Open, Closed}(2.0, 3.0) + i45 = Interval{Open, Closed}(4.0, 5.0) + i67 = Interval{Open, Closed}(6.0, 7.0) + i89 = Interval{Open, Closed}(8.0, 9.0) isf_dict = Dict([ IntervalsFold(i01, 2.0, 5) => Dict( - :pattern => i01, - :gap => 2.0, - :folds => 5, - :length => 5, - :size => 5.0, - :unfold => [i01, i23, i45, i67, i89], - :reverse => reverse([i01, i23, i45, i67, i89]), - ), + :pattern => i01, + :gap => 2.0, + :folds => 5, + :length => 5, + :size => 5.0, + :unfold => [i01, i23, i45, i67, i89], + :reverse => reverse([i01, i23, i45, i67, i89]) + ) ]) for (isf, results) in isf_dict diff --git a/src/vector.jl b/src/vector.jl index bdf5832..4a5f547 100644 --- a/src/vector.jl +++ b/src/vector.jl @@ -3,14 +3,14 @@ A mutable structure for folded vector that extends the methods of AbstractVector. Compared to `IVectorFold`, this tructure is about 20% faster using iterators. Note that this structure keep an active pointer to the `current` *unfolded* pattern. However, its external behavior is similar to `IVectorFold`. """ -mutable struct VectorFold{T,V<:AbstractVector{T}} <: AbstractVectorFold{T} +mutable struct VectorFold{T, V <: AbstractVector{T}} <: AbstractVectorFold{T} pattern::V gap::T folds::Int current::Int end -VectorFold(p, g, f; c=1) = VectorFold(p, g, f, c) +VectorFold(p, g, f; c = 1) = VectorFold(p, g, f, c) pattern_length(mvf::VectorFold) = length(mvf.pattern) @@ -25,7 +25,7 @@ pattern(mvf::VectorFold, index) = pattern(mvf)[index] set_fold!(mvf::VectorFold, new_fold = mvf.current + 1) Set the *unfolded* pattern to `new_fold`. By default move the next *fold* after `current`. """ -function set_fold!(mvf, new_fold=mvf.current + 1) +function set_fold!(mvf, new_fold = mvf.current + 1) if new_fold != mvf.current && 0 < new_fold ≤ mvf.folds distortion = gap(mvf) * (new_fold - mvf.current) mvf.pattern .+= distortion @@ -55,8 +55,8 @@ end # Reverse iterate method function Base.iterate( - r_iter::Base.Iterators.Reverse{VectorFold{T,V}}, state::Int=length(r_iter.itr) -) where {T,V} + r_iter::Base.Iterators.Reverse{VectorFold{T, V}}, state::Int = length(r_iter.itr) +) where {T, V} state < 1 && return nothing iter = r_iter.itr @@ -81,7 +81,7 @@ end Base.rand(mvf::VectorFold, n::Int) = map(_ -> rand(mvf), 1:n) # Specific dispatch for MVectorFold -function unfold(mvf::VectorFold; from=1, to=folds(mvf)) +function unfold(mvf::VectorFold; from = 1, to = folds(mvf)) pl = pattern_length(mvf) ul = (to - from + 1) * pl v = typeof(mvf.pattern)(undef, ul) @@ -101,22 +101,22 @@ make_vector_fold(pattern, gap, fold, ::Val{:mutable}) = VectorFold(pattern, gap, @testitem "VectorFold" tags=[:vectors] begin vf_dict = Dict([ - make_vector_fold([1,2], 10, 5, :immutable) => Dict( - :pattern => [1,2], + make_vector_fold([1, 2], 10, 5, :immutable) => Dict( + :pattern => [1, 2], :gap => 10, :folds => 5, :length => 10, - :unfold => [1,2,11,12,21,22,31,32,41,42], - :reverse => reverse([1,2,11,12,21,22,31,32,41,42]), + :unfold => [1, 2, 11, 12, 21, 22, 31, 32, 41, 42], + :reverse => reverse([1, 2, 11, 12, 21, 22, 31, 32, 41, 42]) ), - make_vector_fold([1,2], 10, 5, :mutable) => Dict( - :pattern => [1,2], + make_vector_fold([1, 2], 10, 5, :mutable) => Dict( + :pattern => [1, 2], :gap => 10, :folds => 5, :length => 10, - :unfold => [1,2,11,12,21,22,31,32,41,42], - :reverse => reverse([1,2,11,12,21,22,31,32,41,42]), - ), + :unfold => [1, 2, 11, 12, 21, 22, 31, 32, 41, 42], + :reverse => reverse([1, 2, 11, 12, 21, 22, 31, 32, 41, 42]) + ) ]) for (vf, results) in vf_dict @@ -131,22 +131,22 @@ make_vector_fold(pattern, gap, fold, ::Val{:mutable}) = VectorFold(pattern, gap, @test collect(Iterators.reverse(vf)) == results[:reverse] @test reverse(collect(vf)) == results[:reverse] end - @test isempty(make_vector_fold(Vector(),1,1,:immutable)) - @test isempty(make_vector_fold(Vector(),1,1)) + @test isempty(make_vector_fold(Vector(), 1, 1, :immutable)) + @test isempty(make_vector_fold(Vector(), 1, 1)) - v1 = make_vector_fold([42,3,45,6],13,4) + v1 = make_vector_fold([42, 3, 45, 6], 13, 4) w1 = unfold(v1) v11 = fold(w1) @test unfold(v11) == w1 - v2 = make_vector_fold([34,34,43,43],10,3) + v2 = make_vector_fold([34, 34, 43, 43], 10, 3) w2 = unfold(v2) v22 = fold(w2) @test unfold(v22) == w2 - v3 = make_vector_fold([42,3,45,6],13,4,:immutable) + v3 = make_vector_fold([42, 3, 45, 6], 13, 4, :immutable) w3 = unfold(v3) v33 = fold(w3)