I have an array
A. I want to test if there are any values in
A satisfying some test:
julia> f1(x) = any(x .> 99)
Easy code to read, but inefficient since we allocate the whole boolean array.
We could also define the following:
julia> function f2(xs) for x in xs if x > 99 return true end end false end
which will be faster, but we have to write a new for loop for every boolean expression.
Has anyone explored macros / tricks to get the syntactical lightness of the first with the performance of the second? i.e. to somehow get short-circuited broadcast fusion of elementwise boolean expressions? This should extend naturally to more complex expressions e.g.
any((A .> 0) .& (A .< 1) .| (B .== 5)). The same pattern applies to
all - i.e. return
false as soon as the first
false is encountered.