Skip to content

Commit 17c2264

Browse files
committed
Make sure == and hash work for TaylorBundles
1 parent b3e4ee0 commit 17c2264

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/tangent.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ end
9494
coeffs::C
9595
TaylorTangent(coeffs) = $(Expr(:new, :(TaylorTangent{typeof(coeffs)}), :coeffs))
9696
end
97+
Base.:(==)(a::TaylorTangent, b::TaylorTangent) = a.coeffs == b.coeffs
98+
Base.hash(tt::TaylorTangent, h::UInt64) = hash(tt.coeffs, h)
9799

98100
"""
99101
struct TaylorTangent{C}
@@ -159,6 +161,9 @@ TangentBundle
159161
TangentBundle{N}(primal::B, tangent::P) where {N, B, P<:AbstractTangentSpace} =
160162
_TangentBundle(Val{N}(), primal, tangent)
161163

164+
Base.hash(tb::TangentBundle, h::UInt64) = hash(tb.primal, h)
165+
Base.:(==)(a::TangentBundle, b::TangentBundle) = (a.primal == b.primal) && (a.tangent == b.tangent)
166+
162167
const ExplicitTangentBundle{N, B, P} = TangentBundle{N, B, ExplicitTangent{P}}
163168

164169
check_tangent_invariant(lp, N) = @assert lp == 2^N - 1

test/tangent.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ end
4646
end
4747
end
4848

49+
@testset "== and hash" begin
50+
@test TaylorBundle{1}([2.0, 4.0], ([20.0, 200.0],)) == TaylorBundle{1}([2.0, 4.0], ([20.0, 200.0],))
51+
@test hash(TaylorBundle{1}(0.0, (0.0,))) == hash(0)
52+
end
53+
4954
@testset "truncate" begin
5055
tt = TaylorTangent((1.0,2.0,3.0,4.0,5.0,6.0,7.0))
5156
@test truncate(tt, Val(2)) == TaylorTangent((1.0,2.0))

0 commit comments

Comments
 (0)