Skip to content

Commit 1786bfe

Browse files
Merge pull request #1031 from FluxML/cl/params
construct Params with empty tuple
2 parents 4d22edf + a2a0393 commit 1786bfe

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Zygote"
22
uuid = "e88e6eb3-aa80-5325-afca-941959d7151f"
3-
version = "0.6.16"
3+
version = "0.6.17"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/tools/idset.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ struct IdSet{T} <: AbstractSet{T}
33
IdSet{T}() where T = new(IdDict{T,Nothing}())
44
end
55

6-
Base.eltype(::IdSet{T}) where T = T
6+
IdSet(xs) = IdSet{eltype(xs)}(xs)
77

88
IdSet() = IdSet{Any}()
99

10+
IdSet{T}(xs) where T = isempty(xs) ? IdSet{T}() : push!(IdSet{T}(), xs...)
11+
1012
Base.push!(s::IdSet{T}, x::T) where T = (s.dict[x] = nothing; s)
1113
Base.delete!(s::IdSet{T}, x::T) where T = (delete!(s.dict, x); s)
1214
Base.in(x, s::IdSet) = haskey(s.dict, x)
13-
14-
IdSet{T}(xs) where T = push!(IdSet{T}(), xs...)
15-
16-
IdSet(xs) = IdSet{eltype(xs)}(xs)
17-
15+
Base.eltype(::IdSet{T}) where T = T
1816
Base.collect(s::IdSet) = Base.collect(keys(s.dict))
1917
Base.similar(s::IdSet, T::Type) = IdSet{T}()
2018

test/interface.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ using Zygote: Grads
8282
@test ps isa Params
8383
@test issetequal(ps, Set([y]))
8484
end
85+
86+
@testset "constructor with empty args" begin
87+
@test length(Params()) == 0
88+
@test length(Params(())) == 0
89+
@test length(Params([])) == 0
90+
end
8591
end
8692

8793
@testset "Grads" begin

0 commit comments

Comments
 (0)