Skip to content

Commit 48c552c

Browse files
committed
Error on duplicate symbols for Axis. Fixes #130
1 parent 4836c19 commit 48c552c

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ComponentArrays"
22
uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
33
authors = ["Jonnie Diegelman <47193959+jonniedie@users.noreply.github.com>"]
4-
version = "0.11.16"
4+
version = "0.11.17"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/axis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct Axis{IdxMap} <: AbstractAxis{IdxMap} end
4848
@inline Axis(IdxMap::NamedTuple) = Axis{IdxMap}()
4949
Axis(;kwargs...) = Axis((;kwargs...))
5050
function Axis(symbols::Union{AbstractVector{Symbol}, NTuple{N,Symbol}}) where {N}
51-
return Axis((;(symbols .=> eachindex(symbols))...))
51+
return Axis(NamedTuple{(symbols...,)}((eachindex(symbols)...,)))
5252
end
5353
Axis(symbols::Symbol...) = Axis(symbols)
5454

src/componentarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function make_idx(data, nt::NamedTuple, last_val)
152152
len = recursive_length(nt)
153153
kvs = []
154154
lv = 0
155-
for (k,v) in zip(keys(nt), nt)
155+
for (k,v) in zip(keys(nt), values(nt))
156156
(_,val) = make_idx(data, v, lv)
157157
push!(kvs, k => val)
158158
lv = val

test/autodiff_tests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,19 @@ truth = ComponentArray(a = [32, 48], x = 156)
4444
end[1]
4545
end
4646
end
47+
48+
49+
# # This is commented out because the gradient operation itself is broken due to Zygote's inability
50+
# # to support mutation and ComponentArray's use of mutation for contstuction from a NamedTuple.
51+
# # It would be nice to support this eventually, so I'll just leave this commented (because @test_broken
52+
# # wouldn't work here because the error happens before the test)
53+
# @testset "Issues" begin
54+
# function mysum(x::AbstractVector)
55+
# y = ComponentVector(x=x)
56+
# return sum(y)
57+
# end
58+
59+
# Δ = Zygote.gradient(mysum, rand(10))
60+
61+
# @test Δ isa Vector{Float64}
62+
# end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ end
7373
@test Axis([:a, :b, :c]) == Axis(a = 1, b = 2, c = 3)
7474
@test Axis((:a, :b, :c)) == Axis(a = 1, b = 2, c = 3)
7575
@test Axis(:a, :b, :c) == Axis(a = 1, b = 2, c = 3)
76+
@test_throws ErrorException Axis(:a, :a)
7677

7778
# Issue #24
7879
@test ComponentVector(a = 1, b = 2.0f0) == ComponentVector{Float32}(a = 1.0, b = 2.0)

0 commit comments

Comments
 (0)