Fastest way to check for Inf or NaN in an array?

@mikmoore It seems like @turbo’s optimizations can break the NaN detection sometimes:

If I take your function above:

using LoopVectorization
function allfinite_turbo(x)
	z = zero(eltype(x))
	s = z
	@turbo for i in eachindex(x)
		s = muladd(z, x[i], s)
	end
	return s == z
end

and plug in a static array with size 1:

julia> using StaticArrays

julia> x = @SVector[NaN]
1-element SVector{1, Float64} with indices SOneTo(1):
 NaN

it fails to detect the NaN:

julia> allfinite_turbo(x)
true

it works when there is more than one element though, presumably because it stops some optimization from happening:

julia> x = @SVector[1, NaN]
2-element SVector{2, Float64} with indices SOneTo(2):
   1.0
 NaN

julia> allfinite_turbo(x)
false

Additional notes:

  1. I don’t see this for regular arrays; only static arrays. So when the compiler knows the size of the array, I guess it can optimize away the check.
  2. Once I remove the @turbo, this issue goes away.

I could simply patch this for size-1 arrays, but the worry is that there might be other cases where it optimizes too much, and the NaN detection breaks.