Skip to content

Commit 55da844

Browse files
kshyattKatharine Hyatt
andauthored
Handle case in EnzymeTestUtils of reduction over empties (#3131)
* Handle case in EnzymeTestUtils of reduction over empties * Use zeros for type stability * Add test for jvp * use similar not zeros --------- Co-authored-by: Katharine Hyatt <katharine.s.hyatt@gmail.com>
1 parent f9fdef3 commit 55da844

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/EnzymeTestUtils/src/finite_difference_calls.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function j′vp(fdm, f_vec, ȳ, x)
7171
end
7272
end
7373
end
74-
mat = transpose(reduce(hcat, ẏs))
74+
mat = isempty(ẏs) ? similar(x, 0) : transpose(reduce(hcat, ẏs))
7575
result = zero(x)
7676
for i in 1:length(ȳ)
7777
tp = @inbounds ȳ[i]

lib/EnzymeTestUtils/test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ Random.seed!(0)
1212
include("generate_tangent.jl")
1313
include("test_forward.jl")
1414
include("test_reverse.jl")
15+
include("test_fd.jl")
1516
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Test
2+
using EnzymeTestUtils
3+
using EnzymeTestUtils: j′vp
4+
using FiniteDifferences
5+
6+
@testset "j′vp with empty inputs" begin
7+
# we can make f_vec here identity since it cannot be
8+
# reached if x is itself empty
9+
@test isempty(j′vp(FiniteDifferences.central_fdm(5, 1), identity, Float32[], Float32[]))
10+
end

0 commit comments

Comments
 (0)