Skip to content

Commit 40bd2df

Browse files
handle 0-sized chunk case (#399) (#400)
Co-authored-by: Kristoffer Carlsson <kcarlsson89@gmail.com>
1 parent 3314011 commit 40bd2df

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/prelude.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const CHUNKS = [Chunk{i}() for i in 1:DEFAULT_CHUNK_THRESHOLD]
1414

1515
function Chunk(input_length::Integer, threshold::Integer = DEFAULT_CHUNK_THRESHOLD)
1616
N = pickchunksize(input_length, threshold)
17-
N <= DEFAULT_CHUNK_THRESHOLD && return CHUNKS[N]
17+
0 < N <= DEFAULT_CHUNK_THRESHOLD && return CHUNKS[N]
1818
return Chunk{N}()
1919
end
2020

test/GradientTest.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,12 @@ end
148148
@test isequal(ForwardDiff.gradient(t -> t[1]^t[2], [0.0, 1.5]), [0.0, 0.0])
149149
end
150150

151+
# Issue 399
152+
@testset "chunk size zero" begin
153+
f_const(x) = 1.0
154+
g_grad_const = x -> ForwardDiff.gradient(f_const, x)
155+
@test g_grad_const([1.0]) == [0.0]
156+
@test isempty(g_grad_const(zeros(Float64, 0)))
157+
end
158+
151159
end # module

0 commit comments

Comments
 (0)