Skip to content

Handle 0-sized chunk case (#399) #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/prelude.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CHUNKS = [Chunk{i}() for i in 1:DEFAULT_CHUNK_THRESHOLD]

function Chunk(input_length::Integer, threshold::Integer = DEFAULT_CHUNK_THRESHOLD)
N = pickchunksize(input_length, threshold)
N <= DEFAULT_CHUNK_THRESHOLD && return CHUNKS[N]
0 < N <= DEFAULT_CHUNK_THRESHOLD && return CHUNKS[N]
return Chunk{N}()
end

Expand Down
8 changes: 8 additions & 0 deletions test/GradientTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,12 @@ end
@test isequal(ForwardDiff.gradient(t -> t[1]^t[2], [0.0, 1.5]), [0.0, 0.0])
end

# Issue 399
@testset "chunk size zero" begin
f_const(x) = 1.0
g_grad_const = x -> ForwardDiff.gradient(f_const, x)
@test g_grad_const([1.0]) == [0.0]
@test isempty(g_grad_const(zeros(Float64, 0)))
end

end # module