RecursiveArrayTools.jl icon indicating copy to clipboard operation
RecursiveArrayTools.jl copied to clipboard

Possible bug in any(f::Function,A::ArrayPartition)

Open SalmonLA opened this issue 3 years ago • 1 comments

julia> using RecursiveArrayTools

julia> a = ArrayPartition([NaN])
([NaN],)

julia> any(isnan,a)
false

julia> any(isnan,a[:]) #dispatches on Base.any instead
true

The responsible commit is years old, but I cannot see how this could be intended. The current implementation applies the function twice, and would probably return false in many cases, where f does not ask about booleans: Base.any(f::Function,A::ArrayPartition) = any(f,(any(f,x) for x in A.x))

Perhaps, this is what it was supposed to be: Base.any(f::Function,A::ArrayPartition) = any((any(f,x) for x in A.x))

In this case however, we might as well dispatch to the generic Base.any function, so maybe I am missing something.

SalmonLA avatar May 06 '22 10:05 SalmonLA

Base.any(f::Function,A::ArrayPartition) = any((any(f,x) for x in A.x)) is best because it would use the faster iteration.

ChrisRackauckas avatar May 06 '22 12:05 ChrisRackauckas