Skip to content

Commit 229c8a4

Browse files
committed
handle 0-sized chunk case (#399)
1 parent 958711d commit 229c8a4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,13 @@ for T in (StaticArrays.SArray, StaticArrays.MArray)
141141
@test DiffResults.gradient(sresult3) == DiffResults.gradient(result)
142142
end
143143

144+
# Issue 399
145+
146+
let
147+
f_const(x) = 1.0
148+
g_grad_const = x -> ForwardDiff.gradient(f_const, x)
149+
@test g_grad_const([1.0]) == [0.0]
150+
@test isempty(g_grad_const(zeros(Float64, 0)))
151+
end
152+
144153
end # module

0 commit comments

Comments
 (0)