From 6894f28de201c2d0188b73d24e7e43a8b2a4340e Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace <51025924+simsurace@users.noreply.github.com> Date: Mon, 5 Feb 2024 20:45:44 +0100 Subject: [PATCH 1/6] Add support for `nothing` I have been using this quite often to conditionally drop specific parameters. --- src/flatten.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/flatten.jl b/src/flatten.jl index 82d5b60..ce68646 100644 --- a/src/flatten.jl +++ b/src/flatten.jl @@ -19,6 +19,12 @@ function flatten end flatten(x) = flatten(Float64, x) +function ParameterHandling.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 From 0d3a1d70c25519a2a6e11e7bcdbc1fe685658c43 Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace <51025924+simsurace@users.noreply.github.com> Date: Mon, 5 Feb 2024 20:49:01 +0100 Subject: [PATCH 2/6] Drop prefix --- src/flatten.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flatten.jl b/src/flatten.jl index ce68646..a4c95a6 100644 --- a/src/flatten.jl +++ b/src/flatten.jl @@ -19,7 +19,7 @@ function flatten end flatten(x) = flatten(Float64, x) -function ParameterHandling.flatten(::Type{T}, ::Nothing) where {T<:Real} +function flatten(::Type{T}, ::Nothing) where {T<:Real} v = T[] unflatten_to_Nothing(::Vector{T}) = nothing return v, unflatten_to_Nothing From bbfee5e6870bb9a9465ee9f00618315ed4d87143 Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace <51025924+simsurace@users.noreply.github.com> Date: Mon, 5 Feb 2024 21:06:55 +0100 Subject: [PATCH 3/6] Remove whitespace Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/flatten.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flatten.jl b/src/flatten.jl index a4c95a6..3caea79 100644 --- a/src/flatten.jl +++ b/src/flatten.jl @@ -19,7 +19,7 @@ function flatten end flatten(x) = flatten(Float64, x) -function flatten(::Type{T}, ::Nothing) where {T<:Real} +function flatten(::Type{T}, ::Nothing) where {T<:Real} v = T[] unflatten_to_Nothing(::Vector{T}) = nothing return v, unflatten_to_Nothing From 48b711bcc68cd9f4db57f15e3e59019dafcf002f Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace Date: Tue, 6 Feb 2024 10:57:15 +0100 Subject: [PATCH 4/6] Add tests --- test/flatten.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/flatten.jl b/test/flatten.jl index 47f4707..6b15e42 100644 --- a/test/flatten.jl +++ b/test/flatten.jl @@ -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)) From eecf86bbd4422aaa8cf1c13444083ee634ca4e2c Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace Date: Tue, 6 Feb 2024 10:57:32 +0100 Subject: [PATCH 5/6] Remove superfluous argument --- src/flatten.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flatten.jl b/src/flatten.jl index 3caea79..1414cb0 100644 --- a/src/flatten.jl +++ b/src/flatten.jl @@ -27,7 +27,7 @@ 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 From cbc556581f961584d171bac68d305fdcfa213e1a Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace Date: Tue, 6 Feb 2024 10:59:11 +0100 Subject: [PATCH 6/6] Bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 7bfdc9d..103aae3 100644 --- a/Project.toml +++ b/Project.toml @@ -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"