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

[Bug] Expanding VectorFold with a negative number of folds will (naturally) fail #18

Open
jakewilliami opened this issue May 5, 2021 · 1 comment

Comments

@jakewilliami
Copy link
Member

jakewilliami commented May 5, 2021

E.g.,

julia> collect(VectorFold([1, 2], 10, -5))
ERROR: ArgumentError: invalid Array dimensions

Proposed fix: create an internal constructor method for VectorFold (and maybe check PatternFold, as well?) to catch this. Would that be reasonable? Or do we...somehow want non-positive numbers of folds? E.g.:

mutable struct VectorFold{T,V <: AbstractVector{T}, I1 <: Integer, I2 <: Integer} <: PatternFold{T,V}
    pattern::V
    gap::T
    folds::I1
    current::I2
	
    function VectorFold(p::V, g::T, f::I1, c::I2) where {T,V <: AbstractVector{T}, I1 <: Integer, I2 <: Integer}
        f < 0 &&
            throw(ArgumentError("folds cannot be negative (you cannot have a negative number of folds)."))
            new{T, V, I1, I2}(p, g, f, c)
        end
end
@Azzaare
Copy link
Member

Azzaare commented May 5, 2021

I can't see a reason to have negative fold either.

You proposition is good. Another way to do it would be to have

mutable struct VectorFold{T,V <: AbstractVector{T}, I1 <: Integer, I2 <: Integer} <: PatternFold{T,V}
    pattern::V
    gap::T
    folds::I1
    current::I2
	
    function VectorFold(p::V, g::T, f::I1, c::I2) where {T,V <: AbstractVector{T}, I1 <: Integer, I2 <: Integer}
            new{T, V, I1, I2}(p, g, max(0,f), c)
        end
end

But it is prone to introduce unexpected behavior. I would rather have your solution (maybe with the following variant)

mutable struct VectorFold{T,V <: AbstractVector{T}, I1 <: Integer, I2 <: Integer} <: PatternFold{T,V}
    pattern::V
    gap::T
    folds::I1
    current::I2
	
    function VectorFold(p::V, g::T, f::I1, c::I2) where {T,V <: AbstractVector{T}, I1 <: Integer, I2 <: Integer}
            @assert f => 0
            new{T, V, I1, I2}(p, g, f, c)
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants