Skip to content

Commit afa411c

Browse files
committed
2 parents 37b4b4f + 94836c5 commit afa411c

File tree

4 files changed

+29
-50
lines changed

4 files changed

+29
-50
lines changed

src/componentarray.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ Base.propertynames(x::ComponentVector) = propertynames(indexmap(getaxes(x)[1]))
284284

285285
Base.keys(x::ComponentVector) = keys(indexmap(getaxes(x)[1]))
286286

287-
Base.hash(x::ComponentArray, h::UInt) = hash(getdata(x), h)
287+
Base.hash(x::ComponentArray, h::UInt) = hash(keys(x), hash(getdata(x), h))
288+
289+
Base.:(==)(x::ComponentArray, y::ComponentArray) = getdata(x)==getdata(y) && getaxes(x)==getaxes(y)
290+
Base.:(==)(x::ComponentArray, y::AbstractArray) = getdata(x)==y && keys(x)==keys(y) # For equality with LabelledArrays
291+
Base.:(==)(x::AbstractArray, y::ComponentArray) = y==x
288292

289293
"""
290294
valkeys(x::ComponentVector)

test/Manifest.toml

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
# This file is machine-generated - editing it directly is not advised
22

3-
[[AbstractFFTs]]
4-
deps = ["LinearAlgebra"]
5-
git-tree-sha1 = "485ee0867925449198280d4af84bdb46a2a404d0"
6-
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
7-
version = "1.0.1"
8-
93
[[Adapt]]
104
deps = ["LinearAlgebra"]
115
git-tree-sha1 = "f1b523983a58802c4695851926203b36e28f09db"
@@ -27,12 +21,6 @@ uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
2721
[[Base64]]
2822
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
2923

30-
[[ChainRules]]
31-
deps = ["ChainRulesCore", "Compat", "LinearAlgebra", "Random", "Reexport", "Requires", "Statistics"]
32-
git-tree-sha1 = "1f410fba5c04d03ab712f348f1542e6059376547"
33-
uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2"
34-
version = "0.7.61"
35-
3624
[[ChainRulesCore]]
3725
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
3826
git-tree-sha1 = "42e3c181483fbd2c416087a0a93838803e358358"
@@ -95,12 +83,6 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
9583
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
9684
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
9785

98-
[[FillArrays]]
99-
deps = ["LinearAlgebra", "Random", "SparseArrays"]
100-
git-tree-sha1 = "31939159aeb8ffad1d4d8ee44d07f8558273120a"
101-
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
102-
version = "0.11.7"
103-
10486
[[FiniteDiff]]
10587
deps = ["ArrayInterface", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays"]
10688
git-tree-sha1 = "f6f80c8f934efd49a286bb5315360be66956dfc4"
@@ -124,12 +106,6 @@ git-tree-sha1 = "241552bc2209f0fa068b6415b1942cc0aa486bcc"
124106
uuid = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
125107
version = "1.1.2"
126108

127-
[[IRTools]]
128-
deps = ["InteractiveUtils", "MacroTools", "Test"]
129-
git-tree-sha1 = "c67e7515a11f726f44083e74f218d134396d6510"
130-
uuid = "7869d1d1-7146-5819-86e3-90919afe41df"
131-
version = "0.4.2"
132-
133109
[[IfElse]]
134110
git-tree-sha1 = "28e837ff3e7a6c3cdb252ce49fb412c8eb3caeef"
135111
uuid = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
@@ -145,6 +121,12 @@ git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e"
145121
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
146122
version = "1.3.0"
147123

124+
[[LabelledArrays]]
125+
deps = ["ArrayInterface", "LinearAlgebra", "MacroTools", "StaticArrays"]
126+
git-tree-sha1 = "df09e970c816637191ef8794ef5c5c9f8950db88"
127+
uuid = "2ee39098-c373-598a-b85f-a56591580800"
128+
version = "1.6.0"
129+
148130
[[LibCURL]]
149131
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
150132
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
@@ -233,11 +215,6 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
233215
deps = ["Serialization"]
234216
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
235217

236-
[[Reexport]]
237-
git-tree-sha1 = "57d8440b0c7d98fc4f889e478e80f268d534c9d5"
238-
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
239-
version = "1.0.0"
240-
241218
[[Requires]]
242219
deps = ["UUIDs"]
243220
git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621"
@@ -324,18 +301,6 @@ version = "1.7.0"
324301
deps = ["Libdl"]
325302
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
326303

327-
[[Zygote]]
328-
deps = ["AbstractFFTs", "ChainRules", "ChainRulesCore", "DiffRules", "Distributed", "FillArrays", "ForwardDiff", "IRTools", "InteractiveUtils", "LinearAlgebra", "MacroTools", "NaNMath", "Random", "Requires", "SpecialFunctions", "Statistics", "ZygoteRules"]
329-
git-tree-sha1 = "927209c83efa62256788a9880c191774c07c5b51"
330-
uuid = "e88e6eb3-aa80-5325-afca-941959d7151f"
331-
version = "0.6.10"
332-
333-
[[ZygoteRules]]
334-
deps = ["MacroTools"]
335-
git-tree-sha1 = "9e7a1e8ca60b742e508a315c17eef5211e7fbfd7"
336-
uuid = "700de1a5-db45-46bc-99cf-38207098b444"
337-
version = "0.2.1"
338-
339304
[[nghttp2_jll]]
340305
deps = ["Artifacts", "Libdl"]
341306
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
33
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
44
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
5+
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
56
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
67
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
78
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
89
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
910
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1011
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
11-
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

test/runtests.jl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ComponentArrays
22
using ForwardDiff
3+
using LabelledArrays
34
using LinearAlgebra
45
using StaticArrays
56
using OffsetArrays
@@ -108,9 +109,18 @@ end
108109
@test keys(ca) == (:a, :b, :c)
109110
@test valkeys(ca) == Val.((:a, :b, :c))
110111

111-
@test ca == getdata(ca)
112-
@test hash(ca) == hash(getdata(ca))
113-
@test hash(ca, zero(UInt)) == hash(getdata(ca), zero(UInt))
112+
@test ca != getdata(ca)
113+
@test getdata(ca) != ca
114+
@test hash(ca) != hash(getdata(ca))
115+
@test hash(ca, zero(UInt)) != hash(getdata(ca), zero(UInt))
116+
117+
ab = ComponentArray(a=1, b=2)
118+
xy = ComponentArray(x=1, y=2)
119+
@test ab != xy
120+
@test hash(ab) != hash(xy)
121+
@test hash(ab, zero(UInt)) != hash(xy, zero(UInt))
122+
123+
@test ab == LVector(a=1, b=2)
114124
end
115125

116126
@testset "Get" begin
@@ -229,7 +239,7 @@ end
229239

230240
A = ComponentArray(zeros(Int,4,4), Axis(x=1:4), Axis(x=1:4))
231241
A[1,:] .= 1
232-
@test A[1,:] == ones(Int,4)
242+
@test A[1,:] == ComponentVector(x=ones(Int,4))
233243
end
234244

235245
@testset "Similar" begin
@@ -258,7 +268,7 @@ end
258268
temp = deepcopy(ca)
259269
@test eltype(Float32.(ca)) == Float32
260270
@test ca .* ca' == cmat
261-
@test 1 .* (ca .+ ca) == ComponentArray(a .+ a)
271+
@test 1 .* (ca .+ ca) == ComponentArray(a .+ a, getaxes(ca))
262272
@test typeof(ca .+ cmat) == typeof(cmat)
263273
@test getaxes(false .* ca .* ca') == (ax, ax)
264274
@test getaxes(false .* ca' .* ca) == (ax, ax)
@@ -313,7 +323,7 @@ end
313323
@test ca * ca' == collect(cmat)
314324
@test ca * ca' == a * a'
315325
@test ca' * ca == a' * a
316-
@test cmat * ca == cmat * a
326+
@test cmat * ca == ComponentArray(cmat * a, getaxes(ca))
317327
@test cmat' * ca isa AbstractArray
318328
@test a' * ca isa Number
319329
@test cmat'' == cmat
@@ -333,7 +343,7 @@ end
333343
@test ca * transpose(ca) == collect(cmat)
334344
@test ca * transpose(ca) == a * transpose(a)
335345
@test transpose(ca) * ca == transpose(a) * a
336-
@test cmat * ca == cmat * a
346+
@test ca' * cmat == ComponentArray(a' * getdata(cmat), getaxes(ca))
337347
@test transpose(transpose(cmat)) == cmat
338348
@test transpose(transpose(ca)) == ca
339349
@test transpose(ca.c) * cmat[:c,:c] * ca.c isa Number

0 commit comments

Comments
 (0)