Skip to content

Commit 7498ffe

Browse files
committed
Avoid batch size of 0 for empty inputs
1 parent b985eb5 commit 7498ffe

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

DifferentiationInterface/src/utils/batchsize.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct BatchSizeSettings{B,singlebatch,aligned}
2222
end
2323

2424
function BatchSizeSettings{B,singlebatch,aligned}(N::Integer) where {B,singlebatch,aligned}
25-
B > N && throw(ArgumentError("Batch size $B larger than input size $N"))
25+
B > N > 0 && throw(ArgumentError("Batch size $B larger than input size $N"))
2626
A = div(N, B, RoundUp)
2727
B_last = N % B
2828
return BatchSizeSettings{B,singlebatch,aligned}(N, A, B_last)
@@ -123,7 +123,9 @@ Reproduces the heuristic from ForwardDiff to minimize
123123
Source: https://github.com/JuliaDiff/ForwardDiff.jl/blob/ec74fbc32b10bbf60b3c527d8961666310733728/src/prelude.jl#L19-L29
124124
"""
125125
function reasonable_batchsize(N::Integer, Bmax::Integer)
126-
if N <= Bmax
126+
if N == 0
127+
return 1
128+
elseif N <= Bmax
127129
return N
128130
else
129131
A = div(N, Bmax, RoundUp)

0 commit comments

Comments
 (0)