@@ -87,128 +87,6 @@ mutable struct MInts{A, B}
8787 q:: Int
8888end
8989
90- @testset " Internal tests" begin
91- @static if VERSION < v " 1.11-"
92- else
93- @assert Enzyme. Compiler. active_reg_inner (Memory{Float64}, (), nothing ) == Enzyme. Compiler. DupState
94- end
95- @assert Enzyme. Compiler. active_reg_inner (Type{Array}, (), nothing ) == Enzyme. Compiler. AnyState
96- @assert Enzyme. Compiler. active_reg_inner (Ints{<: Any , Integer}, (), nothing ) == Enzyme. Compiler. AnyState
97- @assert Enzyme. Compiler. active_reg_inner (Ints{<: Any , Float64}, (), nothing ) == Enzyme. Compiler. DupState
98- @assert Enzyme. Compiler. active_reg_inner (Ints{Integer, <: Any }, (), nothing ) == Enzyme. Compiler. DupState
99- @assert Enzyme. Compiler. active_reg_inner (Ints{Integer, <: Integer }, (), nothing ) == Enzyme. Compiler. AnyState
100- @assert Enzyme. Compiler. active_reg_inner (Ints{Integer, <: AbstractFloat }, (), nothing ) == Enzyme. Compiler. DupState
101- @assert Enzyme. Compiler. active_reg_inner (Ints{Integer, Float64}, (), nothing ) == Enzyme. Compiler. ActiveState
102- @assert Enzyme. Compiler. active_reg_inner (MInts{Integer, Float64}, (), nothing ) == Enzyme. Compiler. DupState
103-
104- @assert Enzyme. Compiler. active_reg (Tuple{Float32,Float32,Int})
105- @assert ! Enzyme. Compiler. active_reg (Tuple{NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}})
106- @assert ! Enzyme. Compiler. active_reg (Base. RefValue{Float32})
107- @assert Enzyme. Compiler. active_reg_inner (Ptr, (), nothing ) == Enzyme. Compiler. DupState
108- @assert Enzyme. Compiler. active_reg_inner (Base. RefValue{Float32}, (), nothing ) == Enzyme. Compiler. DupState
109- @assert Enzyme. Compiler. active_reg_inner (Colon, (), nothing ) == Enzyme. Compiler. AnyState
110- @assert Enzyme. Compiler. active_reg_inner (Symbol, (), nothing ) == Enzyme. Compiler. AnyState
111- @assert Enzyme. Compiler. active_reg_inner (String, (), nothing ) == Enzyme. Compiler. AnyState
112- @assert Enzyme. Compiler. active_reg_inner (Tuple{Any,Int64}, (), nothing ) == Enzyme. Compiler. DupState
113- @assert Enzyme. Compiler. active_reg_inner (Tuple{S,Int64} where S, (), Base. get_world_counter ()) == Enzyme. Compiler. DupState
114- @assert Enzyme. Compiler. active_reg_inner (Union{Float64,Nothing}, (), nothing ) == Enzyme. Compiler. DupState
115- @assert Enzyme. Compiler. active_reg_inner (Union{Float64,Nothing}, (), nothing , #= justActive=# Val (false ), #= unionSret=# Val (true )) == Enzyme. Compiler. ActiveState
116- @test Enzyme. Compiler. active_reg_inner (Tuple, (), nothing ) == Enzyme. Compiler. DupState
117- @test Enzyme. Compiler. active_reg_inner (Tuple, (), nothing , #= justactive=# Val (false ), #= unionsret=# Val (false ), #= abstractismixed=# Val (true )) == Enzyme. Compiler. MixedState
118- @test Enzyme. Compiler. active_reg_inner (Tuple{A,A} where A, (), nothing , #= justactive=# Val (false ), #= unionsret=# Val (false ), #= abstractismixed=# Val (true )) == Enzyme. Compiler. MixedState
119-
120- # issue #1935
121- struct Incomplete
122- x:: Float64
123- y
124- Incomplete (x) = new (x)
125- # incomplete constructor & non-bitstype field => !Base.allocatedinline(Incomplete)
126- end
127- @test Enzyme. Compiler. active_reg_inner (Tuple{Incomplete}, (), nothing , #= justActive=# Val (false )) == Enzyme. Compiler. MixedState
128- @test Enzyme. Compiler. active_reg_inner (Tuple{Incomplete}, (), nothing , #= justActive=# Val (true )) == Enzyme. Compiler. ActiveState
129-
130- thunk_a = Enzyme. Compiler. thunk (Val (0 ), Const{typeof (f0)}, Active, Tuple{Active{Float64}}, Val (API. DEM_ReverseModeCombined), Val (1 ), Val ((false , false )), Val (false ), Val (false ), DefaultABI, Val (false ), Val (false ), Val (false ))
131- thunk_b = Enzyme. Compiler. thunk (Val (0 ), Const{typeof (f0)}, Const, Tuple{Const{Float64}}, Val (API. DEM_ReverseModeCombined), Val (1 ), Val ((false , false )), Val (false ), Val (false ), DefaultABI, Val (false ), Val (false ), Val (false ))
132- thunk_c = Enzyme. Compiler. thunk (Val (0 ), Const{typeof (f0)}, Active{Float64}, Tuple{Active{Float64}}, Val (API. DEM_ReverseModeCombined), Val (1 ), Val ((false , false )), Val (false ), Val (false ), DefaultABI, Val (false ), Val (false ), Val (false ))
133- thunk_d = Enzyme. Compiler. thunk (Val (0 ), Const{typeof (f0)}, Active{Float64}, Tuple{Active{Float64}}, Val (API. DEM_ReverseModeCombined), Val (1 ), Val ((false , false )), Val (false ), Val (false ), DefaultABI, Val (false ), Val (false ), Val (false ))
134- @test thunk_a. adjoint != = thunk_b. adjoint
135- @test thunk_c. adjoint === thunk_a. adjoint
136- @test thunk_c. adjoint === thunk_d. adjoint
137-
138- @test thunk_a (Const (f0), Active (2.0 ), 1.0 ) == ((1.0 ,),)
139- @test thunk_a (Const (f0), Active (2.0 ), 2.0 ) == ((2.0 ,),)
140- @test thunk_b (Const (f0), Const (2.0 )) === ((nothing ,),)
141-
142- forward, pullback = Enzyme. Compiler. thunk (Val (0 ), Const{typeof (f0)}, Active, Tuple{Active{Float64}}, Val (Enzyme. API. DEM_ReverseModeGradient), Val (1 ), Val ((false , false )), Val (false ), Val (false ), DefaultABI, Val (false ), Val (false ), Val (false ))
143-
144- @test forward (Const (f0), Active (2.0 )) == (nothing ,nothing ,nothing )
145- @test pullback (Const (f0), Active (2.0 ), 1.0 , nothing ) == ((1.0 ,),)
146-
147- function mul2 (x)
148- x[1 ] * x[2 ]
149- end
150- d = Duplicated ([3.0 , 5.0 ], [0.0 , 0.0 ])
151-
152- forward, pullback = Enzyme. Compiler. thunk (Val (0 ), Const{typeof (mul2)}, Active, Tuple{Duplicated{Vector{Float64}}}, Val (Enzyme. API. DEM_ReverseModeGradient), Val (1 ), Val ((false , true )), Val (false ), Val (false ), DefaultABI, Val (false ), Val (false ), Val (false ))
153- res = forward (Const (mul2), d)
154-
155- @static if VERSION < v " 1.11-"
156- @test typeof (res[1 ]) == Tuple{Float64, Float64}
157- else
158- @test typeof (res[1 ]) == NamedTuple{(Symbol (" 1" ),Symbol (" 2" ),Symbol (" 3" )), Tuple{Any, Float64, Float64}}
159- end
160-
161- pullback (Const (mul2), d, 1.0 , res[1 ])
162- @test d. dval[1 ] ≈ 5.0
163- @test d. dval[2 ] ≈ 3.0
164-
165- d = Duplicated ([3.0 , 5.0 ], [0.0 , 0.0 ])
166- forward, pullback = Enzyme. Compiler. thunk (Val (0 ), Const{typeof (vrec)}, Active, Tuple{Const{Int}, Duplicated{Vector{Float64}}}, Val (Enzyme. API. DEM_ReverseModeGradient), Val (1 ), Val ((false , false , true )), Val (false ), Val (false ), DefaultABI, Val (false ), Val (false ), Val (false ))
167- res = forward (Const (vrec), Const (Int (1 )), d)
168- pullback (Const (vrec), Const (1 ), d, 1.0 , res[1 ])
169- @test d. dval[1 ] ≈ 5.0
170- @test d. dval[2 ] ≈ 3.0
171-
172- # @test thunk_split.primal !== C_NULL
173- # @test thunk_split.primal !== thunk_split.adjoint
174- # @test thunk_a.adjoint !== thunk_split.adjoint
175- #
176- z = ([3.14 , 21.5 , 16.7 ], [0 ,1 ], [5.6 , 8.9 ])
177- Enzyme. make_zero! (z)
178- @test z[1 ] ≈ [0.0 , 0.0 , 0.0 ]
179- @test z[2 ][1 ] == 0
180- @test z[2 ][2 ] == 1
181- @test z[3 ] ≈ [0.0 , 0.0 ]
182-
183- z2 = ([3.14 , 21.5 , 16.7 ], [0 ,1 ], [5.6 , 8.9 ])
184- Enzyme. make_zero! (z2)
185- @test z2[1 ] ≈ [0.0 , 0.0 , 0.0 ]
186- @test z2[2 ][1 ] == 0
187- @test z2[2 ][2 ] == 1
188- @test z2[3 ] ≈ [0.0 , 0.0 ]
189-
190- z3 = [3.4 , " foo" ]
191- Enzyme. make_zero! (z3)
192- @test z3[1 ] ≈ 0.0
193- @test z3[2 ] == " foo"
194-
195- z4 = sin
196- Enzyme. make_zero! (z4)
197-
198- struct Dense
199- n_inp:: Int
200- b:: Vector{Float64}
201- end
202-
203- function Dense (n)
204- Dense (n, rand (n))
205- end
206-
207- nn = Dense (4 )
208- Enzyme. make_zero! (nn)
209- @test nn. b ≈ [0.0 , 0.0 , 0.0 , 0.0 ]
210- end
211-
21290@testset " Reflection" begin
21391 Enzyme. Compiler. enzyme_code_typed (Active, Tuple{Active{Float64}}) do x
21492 x ^ 2
0 commit comments