Skip to content

Commit

Permalink
Merge pull request #65 from JuliaGaussianProcesses/nothing-flatten
Browse files Browse the repository at this point in the history
Add support for `nothing`
  • Loading branch information
simsurace authored Feb 6, 2024
2 parents 1fdb2cb + cbc5565 commit 567b070
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 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.4.7"
version = "0.4.8"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
8 changes: 7 additions & 1 deletion src/flatten.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ function flatten end

flatten(x) = flatten(Float64, x)

function flatten(::Type{T}, ::Nothing) where {T<:Real}
v = T[]
unflatten_to_Nothing(::Vector{T}) = nothing
return v, unflatten_to_Nothing
end

function flatten(::Type{T}, x::Integer) where {T<:Real}
v = T[]
unflatten_to_Integer(v::Vector{T}) = x
unflatten_to_Integer(::Vector{T}) = x
return v, unflatten_to_Integer
end

Expand Down
5 changes: 5 additions & 0 deletions test/flatten.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
end
end

@testset "Nothing" begin
test_flatten_interface(nothing)
@test isempty(first(flatten(nothing)))
end

@testset "AbstractArrays" begin
test_flatten_interface(randn(10))
test_flatten_interface(randn(5, 4))
Expand Down

2 comments on commit 567b070

@simsurace
Copy link
Member Author

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/100338

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.4.8 -m "<description of version>" 567b0709d05d1d8f6eb619248d77a2c31ff2c393
git push origin v0.4.8

Please sign in to comment.