Skip to content

Commit 2795872

Browse files
committed
overload show for mutable tangent
1 parent 780ed05 commit 2795872

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/tangent_types/structural_tangent.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,10 @@ Base.:(==)(a::Tangent{P}, b::Tangent{Q}) where {P,Q} = false
334334

335335
Base.hash(a::Tangent, h::UInt) = Base.hash(backing(canonicalize(a)), h)
336336

337-
function Base.show(io::IO, tangent::Tangent{P}) where {P}
337+
function Base.show(io::IO, tangent::StructuralTangent{P}) where {P}
338+
if tangent isa MutableTangent
339+
print(io, "Mutable")
340+
end
338341
print(io, "Tangent{")
339342
str = sprint(show, P, context = io)
340343
i = findfirst('{', str)

test/tangent_types/structural_tangent.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ end
398398
)
399399

400400
@test repr(Tangent{Foo}()) == "Tangent{Foo}()"
401+
402+
@test ==(
403+
repr(MutableTangent{MFoo}((;x=1.5, y=[1.0, 2.0]))),
404+
"MutableTangent{MFoo}(x = 1.5, y = [1.0, 2.0])"
405+
)
401406
end
402407

403408
@testset "internals" begin

0 commit comments

Comments
 (0)