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

Update CI, format, tests, doc, etc. #36

Merged
merged 2 commits into from
Apr 27, 2024
Merged
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
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "sciml"
69 changes: 57 additions & 12 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,81 @@
name: CI
on:
- push
- pull_request
pull_request:
branches:
- main
- dev
paths-ignore:
- "docs/**"
push:
branches:
- main
paths-ignore:
- "docs/**"
jobs:
formatter:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1]
julia-arch: [x86]
os: [ubuntu-latest]
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}

- uses: actions/checkout@v4
- name: Install JuliaFormatter and format
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="1.0.50"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
run: |
julia -e '
out = Cmd(`git diff`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- "1.8"
- 'nightly'
- "1.6"
- "1" # automatically expands to the latest stable 1.x release of Julia
- nightly
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
- x86
exclude:
include:
# test macOS and Windows with latest Julia only
- os: macOS-latest
arch: x86
arch: x64
version: 1
- os: windows-latest
arch: x64
version: 1
- os: windows-latest
arch: x86
version: 1
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
Expand All @@ -43,14 +88,14 @@ jobs:
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v4
with:
file: lcov.info
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: "1"
Expand Down
37 changes: 32 additions & 5 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
name: CompatHelper
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
- name: Check if Julia is already available in the PATH
id: julia_in_path
run: which julia
continue-on-error: true
- name: Install Julia, but only if it is not already available in the PATH
uses: julia-actions/setup-julia@v1
with:
version: "1"
arch: ${{ runner.arch }}
if: steps.julia_in_path.outcome != 'success'
- name: "Add the General registry via Git"
run: |
import Pkg
ENV["JULIA_PKG_SERVER"] = ""
Pkg.Registry.add("General")
shell: julia --color=yes {0}
- name: "Install CompatHelper"
run: |
import Pkg
name = "CompatHelper"
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
version = "3"
Pkg.add(; name, uuid, version)
shell: julia --color=yes {0}
- name: "Run CompatHelper"
run: |
import CompatHelper
CompatHelper.main()
shell: julia --color=yes {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
13 changes: 13 additions & 0 deletions .github/workflows/SpellCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Spell Check

on: [pull_request]

jobs:
typos-check:
name: Spell Check with Typos
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4
- name: Check spelling
uses: crate-ci/typos@v1.18.0
16 changes: 16 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ on:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: "3"
permissions:
actions: read
checks: read
contents: write
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
Expand Down
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ Lazy = "0.15"
Reexport = "1"
TestItemRunner = "0.2"
TestItems = "0.1"
julia = "1.8"
julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Aqua", "Test"]
28 changes: 14 additions & 14 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -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"
)
4 changes: 2 additions & 2 deletions perf/allocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions perf/bench.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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__)
3 changes: 2 additions & 1 deletion src/PatternFolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ using Reexport
# Import
@reexport using Intervals
using Lazy
using Random
# using Random
using TestItems
using TestItemRunner

# exports
export IntervalsFold
Expand Down
6 changes: 3 additions & 3 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ PatternFold = Union{AbstractVectorFold, IntervalsFold}

"""
pattern(<:PatternFold)
Return the *pattern* of any `PatternFold`. The pattern defines the occurences of the first fold.
Return the *pattern* of any `PatternFold`. The pattern defines the occurrences of the first fold.
"""
pattern(pf) = pf.pattern

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
36 changes: 18 additions & 18 deletions src/immutable_vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
Loading
Loading