Skip to content

Commit a8525ae

Browse files
oxinaboxKeno
andauthored
Compact show for ZeroBundle etc (#136)
* Compact show for ZeroBundle etc * Also overload show for types themselves * Fix test --------- Co-authored-by: Keno Fischer <[email protected]>
1 parent f6f7cc1 commit a8525ae

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/tangent.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,34 @@ UniformBundle{N}(primal, partial::U) where {N,U} = _TangentBundle(Val{N}(), prim
250250
UniformBundle{N, <:Any, U}(primal, partial::U) where {N, U} = _TangentBundle(Val{N}(), primal, UniformTangent{U}(U.instance))
251251
UniformBundle{N, <:Any, U}(primal) where {N, U} = _TangentBundle(Val{N}(), primal, UniformTangent{U}(U.instance))
252252

253+
253254
const ZeroBundle{N, B} = UniformBundle{N, B, ZeroTangent}
254255
const DNEBundle{N, B} = UniformBundle{N, B, NoTangent}
256+
const AbstractZeroBundle{N, B} = UniformBundle{N, B, <:AbstractZero}
257+
258+
wrapper_name(::Type{<:ZeroBundle}) = "ZeroBundle"
259+
wrapper_name(::Type{<:DNEBundle}) = "DNEBundle"
260+
wrapper_name(::Type{<:AbstractZeroBundle}) = "AbstractZeroBundle"
261+
262+
function Base.show(io::IO, T::Type{<:AbstractZeroBundle{N, B}}) where {N,B}
263+
print(io, wrapper_name(T))
264+
print(io, "{$N, ")
265+
show(io, B)
266+
print(io, "}")
267+
end
268+
269+
function Base.show(io::IO, T::Type{<:AbstractZeroBundle{N}}) where {N}
270+
print(io, wrapper_name(T))
271+
print(io, "{$N}")
272+
end
273+
274+
function Base.show(io::IO, t::AbstractZeroBundle{N}) where N
275+
print(io, wrapper_name(typeof(t)))
276+
print(io, "{$N}(")
277+
show(io, t.primal)
278+
print(io, ")")
279+
end
280+
255281

256282
Base.getindex(u::UniformBundle, ::TaylorTangentIndex) = u.tangent.val
257283

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const bwd = Diffractor.PrimeDerivativeBack
1313

1414
@testset verbose=true "Diffractor.jl" begin # overall testset, ensures all tests run
1515

16-
include("stage2_fwd.jl")
16+
@testset "$file" for file in ("stage2_fwd.jl", "tangent.jl")
17+
include(file)
18+
end
1719

1820
# Unit tests
1921
function tup2(f)

test/tangent.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module tagent
2+
using Diffractor
3+
using Diffractor: AbstractZeroBundle, ZeroBundle, DNEBundle
4+
using Test
5+
6+
@testset "AbstractZeroBundle" begin
7+
@testset "Hierachy" begin
8+
@test ZeroBundle <: AbstractZeroBundle
9+
@test DNEBundle <: AbstractZeroBundle
10+
@test ZeroBundle{1} <: AbstractZeroBundle{1}
11+
@test ZeroBundle{1,typeof(getfield)} <: AbstractZeroBundle{1,typeof(getfield)}
12+
end
13+
14+
@testset "Display" begin
15+
@test repr(ZeroBundle{1}(2.0)) == "ZeroBundle{1}(2.0)"
16+
@test repr(DNEBundle{1}(getfield)) == "DNEBundle{1}(getfield)"
17+
18+
@test repr(ZeroBundle{1}) == "ZeroBundle{1}"
19+
@test repr(ZeroBundle{1, Float64}) == "ZeroBundle{1, Float64}"
20+
21+
@test repr(typeof(DNEBundle{1}(getfield))) == "DNEBundle{1, typeof(getfield)}"
22+
end
23+
end
24+
25+
end # module

0 commit comments

Comments
 (0)