Skip to content

Commit c696f9f

Browse files
committed
Tune unroll based on array length
1 parent c084e17 commit c696f9f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Utils.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,15 @@ end
7575

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
78-
is_bad_array(x, ::Val{unroll}=Val(16)) where {unroll} = !is_good_array(x, Val(unroll))
79-
function is_good_array(x::AbstractArray{T}, ::Val{unroll}=Val(16)) where {unroll,T}
78+
is_bad_array(x) = !is_good_array(x)
79+
function is_good_array_mix(x::AbstractArray{T}) where {T}
80+
n = length(x)
81+
n == 0 && return true
82+
n <= 256 && return isfinite(sum(xi -> xi * zero(typeof(xi)), x))
83+
return _is_good_array(x, Val(8))
84+
end
85+
86+
function _is_good_array(x::AbstractArray{T}, ::Val{unroll}) where {T,unroll}
8087
isempty(x) && return true
8188
_zero = zero(T)
8289

0 commit comments

Comments
 (0)