Skip to content

Commit

Permalink
Refactoring and cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Azzaare committed Mar 16, 2021
1 parent 9e8f77c commit bb96577
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
exclude:
- os: macOS-latest
arch: x86
- os: windows-latest
arch: x86
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
Expand Down Expand Up @@ -51,7 +53,7 @@ jobs:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1'
version: "^1.6.0-0"
- run: |
julia --project=docs -e '
using Pkg
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PatternFolds"
uuid = "c18a7f1d-76ad-4ce4-950d-5419b888513b"
authors = ["Jean-Francois Baffier"]
version = "0.1.1"
version = "0.1.2"

[deps]
Lazy = "50d2b5c4-7a5e-59d5-8109-a42b560f39c0"
Expand Down
12 changes: 8 additions & 4 deletions src/PatternFolds.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
module PatternFolds

import Base: length, rand, iterate, isempty, ndims, +, in, size
import Lazy: @forward
# usings
using Lazy

# exports
export PatternFold, IVectorFold, VectorFold, Interval, IntervalsFold
export PatternFold
export IVectorFold, VectorFold
export Interval, IntervalsFold
export pattern, gap, folds
export length, unfold
export length
export unfold
export value

# includes
include("common.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Return the number of *folds*. An infinite folded pattern returns `0`.
folds(pf) = pf.folds

# Forwards isempty, ndims
@forward PatternFold.pattern isempty, ndims
@forward PatternFold.pattern Base.isempty, Base.ndims

# TODO - look if another name is more appropriate
"""
Expand Down Expand Up @@ -59,4 +59,4 @@ end
reset_pattern!(<:PatternFold)
Reset the *unfolded* pattern to the first fold.
"""
reset_pattern!(mvf) = set_fold!(mvf, 1)
reset_pattern!(mvf) = set_fold!(mvf, 1)
10 changes: 5 additions & 5 deletions src/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Interval(a, b) = Interval{typeof(a[1])}(a,b)

a(i) = i.a
b(i) = i.b
+(bound::Tuple{T, Bool}, gap::T) where T = bound[1]+gap, bound[2]
+(i::Interval, gap) = Interval(a(i) + gap, b(i) + gap)
Base.:+(bound::Tuple{T, Bool}, gap::T) where T = bound[1]+gap, bound[2]
Base.:+(i::Interval, gap) = Interval(a(i) + gap, b(i) + gap)

value(i, ::Val{:a}) = i.a[1]
value(i, ::Val{:b}) = i.b[1]
Expand Down Expand Up @@ -45,7 +45,7 @@ end

IntervalsFold(p, g, f, c = 1) = IntervalsFold(p, g, f, c)

@forward IntervalsFold.pattern a, b, isempty
@forward IntervalsFold.pattern a, b, Base.isempty

function pattern(isf::IntervalsFold)
distortion = gap(isf) * (isf.current - 1)
Expand All @@ -66,7 +66,7 @@ function set_fold!(isf::IntervalsFold, new_fold = isf.current + 1)
isf.pattern += distortion
isf.current = new_fold
end
end
end

function Base.iterate(iter::IntervalsFold)
reset_pattern!(iter)
Expand Down Expand Up @@ -97,4 +97,4 @@ end

Base.size(isf::IntervalsFold) = size(isf.pattern) * folds(isf)

Base.eltype(::Type{<:IntervalsFold{T}}) where {T} = Interval{T}
Base.eltype(::Type{<:IntervalsFold{T}}) where {T} = Interval{T}
4 changes: 2 additions & 2 deletions src/vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function set_fold!(mvf, new_fold = mvf.current + 1)
mvf.pattern .+= distortion
mvf.current = new_fold
end
end
end

# Base case iterate method
function Base.iterate(iter::VectorFold)
Expand Down Expand Up @@ -92,4 +92,4 @@ function unfold(mvf::VectorFold; from=1, to=folds(mvf))
count += 1
end
return v
end
end

0 comments on commit bb96577

Please sign in to comment.