@@ -13,8 +13,8 @@ This generic type should never be used directly: use the specific constructor co
1313
1414# Constructors
1515
16- Scenario{op,pl_op}(f, x; tang, contexts, res1, res2)
17- Scenario{op,pl_op}(f!, y, x; tang, contexts, res1, res2)
16+ Scenario{op,pl_op}(f, x; tang, contexts, res1, res2, name )
17+ Scenario{op,pl_op}(f!, y, x; tang, contexts, res1, res2, name )
1818
1919# Fields
2020
@@ -37,32 +37,57 @@ struct Scenario{op,pl_op,pl_fun,F,X,Y,T<:Union{Nothing,NTuple},C<:Tuple,R1,R2,S}
3737 res2:: R2
3838 " private field (not part of the public API) containing a variant of the scenario to test preparation resizing"
3939 smaller:: S
40+ " name of the scenario for display in test sets and dataframes"
41+ name:: Union{String,Nothing}
4042end
4143
4244function Scenario {op,pl_op,pl_fun} (
43- f:: F ; x:: X , y:: Y , tang:: T , contexts:: C , res1:: R1 , res2:: R2 , smaller:: S = nothing
45+ f:: F ;
46+ x:: X ,
47+ y:: Y ,
48+ tang:: T ,
49+ contexts:: C ,
50+ res1:: R1 ,
51+ res2:: R2 ,
52+ smaller:: S = nothing ,
53+ name= nothing ,
4454) where {op,pl_op,pl_fun,F,X,Y,T,C,R1,R2,S<: Union{Nothing,Scenario} }
4555 @assert smaller isa Union{Nothing,Scenario{op,pl_op,pl_fun,F,X,Y,T,C,R1,R2}}
4656 return Scenario {op,pl_op,pl_fun,F,X,Y,T,C,R1,R2,S} (
47- f, x, y, tang, contexts, res1, res2, smaller
57+ f, x, y, tang, contexts, res1, res2, smaller, name
4858 )
4959end
5060
5161function Scenario {op,pl_op} (
52- f, x; tang= nothing , contexts= (), res1= nothing , res2= nothing , smaller= nothing
62+ f,
63+ x;
64+ tang= nothing ,
65+ contexts= (),
66+ res1= nothing ,
67+ res2= nothing ,
68+ smaller= nothing ,
69+ name= nothing ,
5370) where {op,pl_op}
5471 @assert op in ALL_OPS
5572 @assert pl_op in (:in , :out )
5673 y = f (x, map (unwrap, contexts)... )
57- return Scenario {op,pl_op,:out} (f; x, y, tang, contexts, res1, res2, smaller)
74+ return Scenario {op,pl_op,:out} (f; x, y, tang, contexts, res1, res2, smaller, name )
5875end
5976
6077function Scenario {op,pl_op} (
61- f!, y, x; tang= nothing , contexts= (), res1= nothing , res2= nothing , smaller= nothing
78+ f!,
79+ y,
80+ x;
81+ tang= nothing ,
82+ contexts= (),
83+ res1= nothing ,
84+ res2= nothing ,
85+ smaller= nothing ,
86+ name= nothing ,
6287) where {op,pl_op}
6388 @assert op in ALL_OPS
6489 @assert pl_op in (:in , :out )
65- return Scenario {op,pl_op,:in} (f!; x, y, tang, contexts, res1, res2, smaller)
90+ return Scenario {op,pl_op,:in} (f!; x, y, tang, contexts, res1, res2, smaller, name )
6691end
6792
6893Base.:(== )(scen1:: Scenario , scen2:: Scenario ) = false
@@ -85,7 +110,8 @@ function Base.:(==)(
85110 )
86111 eq_res1 = scen1. res1 == scen2. res1
87112 eq_res2 = scen1. res2 == scen2. res2
88- return (eq_x && eq_y && eq_tang && eq_contexts && eq_res1 && eq_res2)
113+ eq_name = scen1. name == scen2. name
114+ return (eq_x && eq_y && eq_tang && eq_contexts && eq_res1 && eq_res2 && eq_name)
89115end
90116
91117operator (:: Scenario{op} ) where {op} = op
@@ -123,12 +149,16 @@ end
123149function Base. show (
124150 io:: IO , scen:: Scenario{op,pl_op,pl_fun,F,X,Y,T}
125151) where {op,pl_op,pl_fun,F,X,Y,T}
126- print (io, " Scenario{$(repr (op)) ,$(repr (pl_op)) } $(string (scen. f)) : $X -> $Y " )
127- if op in (:pushforward , :pullback , :hvp )
128- print (io, " ($(length (scen. tang)) tangents)" )
129- end
130- if length (scen. contexts) > 0
131- print (io, " ($(length (scen. contexts)) contexts)" )
152+ if isnothing (scen. name)
153+ print (io, " Scenario{$(repr (op)) ,$(repr (pl_op)) } $(string (scen. f)) : $X -> $Y " )
154+ if op in (:pushforward , :pullback , :hvp )
155+ print (io, " ($(length (scen. tang)) tangents)" )
156+ end
157+ if length (scen. contexts) > 0
158+ print (io, " ($(length (scen. contexts)) contexts)" )
159+ end
160+ else
161+ print (io, scen. name)
132162 end
133163 return nothing
134164end
0 commit comments