Skip to content

Commit

Permalink
Fix Vector-of-Integers bug (#33)
Browse files Browse the repository at this point in the history
* Flatten Vector{<:Integer} is empty

* Bump patch version

* Fix method specificity problem

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
willtebbutt and github-actions[bot] authored Aug 26, 2021
1 parent 3786deb commit eb0d4ca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ParameterHandling"
uuid = "2412ca09-6db7-441c-8e3a-88d5709968c5"
authors = ["Invenia Technical Computing Corporation"]
version = "0.3.3"
version = "0.3.4"

[deps]
Bijectors = "76274a88-744f-5084-9051-94815aaf08c4"
Expand Down
15 changes: 13 additions & 2 deletions src/flatten.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,20 @@ function flatten(::Type{T}, x::R) where {T<:Real, R<:Real}
return v, unflatten_to_Real
end

flatten(::Type{T}, x::Vector{R}) where {T<:Real, R<:Real} = (Vector{T}(x), Vector{R})
flatten(::Type{T}, x::Vector{R}) where {T<:Real,R<:Real} = (Vector{T}(x), Vector{R})

function flatten(::Type{T}, x::AbstractVector) where T<:Real
function _flatten_vector_integer(::Type{T}, x::AbstractVector{<:Integer}) where {T<:Real}
unflatten_to_Vector_Integer(x_vec) = x
return T[], unflatten_to_Vector_Integer
end

flatten(::Type{T}, x::Vector{<:Integer}) where {T<:Real} = _flatten_vector_integer(T, x)

function flatten(::Type{T}, x::AbstractVector{<:Integer}) where {T<:Real}
return _flatten_vector_integer(T, x)
end

function flatten(::Type{T}, x::AbstractVector) where {T<:Real}
x_vecs_and_backs = map(val -> flatten(T, val), x)
x_vecs, backs = first.(x_vecs_and_backs), last.(x_vecs_and_backs)
function Vector_from_vec(x_vec)
Expand Down
6 changes: 6 additions & 0 deletions test/flatten.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
test_flatten_interface(randn(10))
test_flatten_interface(randn(5, 4))
test_flatten_interface([randn(5) for _ in 1:3])

# Prevent regression of https://github.com/invenia/ParameterHandling.jl/issues/31
@testset for v in [[1, 2, 3], sparse([1, 0, 3])]
test_flatten_interface(v)
@test length(first(flatten(v))) == 0
end
end

@testset "SparseMatrixCSC" begin
Expand Down

2 comments on commit eb0d4ca

@willtebbutt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/43565

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.4 -m "<description of version>" eb0d4ca10b9d48c3f0c91670c00950d03f12c48d
git push origin v0.3.4

Please sign in to comment.