julia> function findNaNmax(x::AbstractArray{T}) where T<:AbstractFloat
result = convert(eltype(x), NaN)
indmax = 0
for (i,v) in enumerate(x)
if !isnan(v)
if (isnan(result) || v > result)
result = v
indmax = i
end
end
end
return (indmax,result)
end
findNaNmax (generic function with 1 method)
julia> Y1 = rand(10_000_000);
julia> Y3 = ifelse.(rand(length(Y1)) .< 0.9, Y1, NaN);
julia> @btime NaNMath.maximum(Y3);
21.103 ms (1 allocation: 16 bytes)
julia> @btime findNaNmax(Y3);
23.513 ms (1 allocation: 32 bytes)
?
or maybe even
function findNaNmax2(x::AbstractArray{T}) where T<:AbstractFloat
result = convert(eltype(x), NaN)
indmax = 0
@inbounds @simd for i in eachindex(x)
v = x[i]
if !isnan(v)
if (isnan(result) || v > result)
result = v
indmax = i
end
end
end
return (indmax,result)
end
julia> @btime findNaNmax2(Y3);
22.294 ms (1 allocation: 32 bytes)
how do people feel about a PR with
?
or maybe even