Skip to content

Commit 643e7fd

Browse files
committed
Fix is_good_array for empty input
1 parent 9177e69 commit 643e7fd

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/Utils.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ end
7676
# Fastest way to check for NaN in an array.
7777
# Thanks @mikmore https://discourse.julialang.org/t/fastest-way-to-check-for-inf-or-nan-in-an-array/76954/33?u=milescranmer
7878
is_bad_array(x) = !is_good_array(x)
79-
function is_good_array(x)
80-
IS_WINDOWS && return sum(xi -> xi * zero(xi), x) == zero(eltype(x))
81-
return isempty(x) || vmapreduce(xi -> xi * zero(xi), +, x) == zero(eltype(x))
79+
function is_good_array(x::AbstractArray{T}) where {T}
80+
isempty(x) && return true
81+
IS_WINDOWS && return sum(xi -> xi * zero(xi), x) == zero(T)
82+
return vmapreduce(xi -> xi * zero(xi), +, x) == zero(T)
8283
end
8384
const IS_WINDOWS = Sys.iswindows()
8485

test/test_nan_detection.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ end
5656
nan_location in 1:array_size,
5757
static_array in [false, true]
5858

59-
manual_nan_test(
60-
T, array_size, nan_location, static_array ? Val(true) : Val(false)
61-
)
59+
manual_nan_test(T, array_size, nan_location, static_array ? Val(true) : Val(false))
6260
end
6361
end

0 commit comments

Comments
 (0)