any(f::Function, a::AbstractArray; dims)

is defined (reducedim.jl:729, Julia 1.5.0-rc1.0), but not documented.

Also, its behaviour is slightly different from any(a;dims), For instance,
any([1 2].>0,dims=2) gives a BitArray, while any(i->i>0,[1 2],dims=2) gives an array of Bools.

I would prefer to use the any(f, a; dims) method to avoid allocations (when a is large), but I wonder whether I can rely on it?

I imagine you mean that in the any(f, array) signature f is required to be a function, but I couldn’t figure out why that’s needed. What would any(f, array::AbstractArray) be ambiguous with? Maybe that’s just a leftover from when dims was a positional argument.

Sorry, I was thinking of something else; please disregard.

Ah, no problem!

It is a bit hard to keep in mind which functions have a method where the first element is any callable object or just ::Function. I would definitely prefer to have good syntax for a lazy broadcasted object and just do any(for f.(x)) (as in this PR) or whichever other syntax gets chosen.

Do you recommend to stay away from any(f,a;dims) for now?

I don’t have any special insight, but I think it should be fine: IMO it would be breaking to change the behavior of an exported function. Just in case, you could open an issue or PR to mention that it needs docs.

3 Likes

It would be breaking to change the behavior of the public API, and I am not sure if the public API is defined by the body of the exported functions or by the body of the documented functions. I would advise opening a PR asking for documentation, and then get the answer if it is intended to be part of the public API or not.

2 Likes

submitted https://github.com/JuliaLang/julia/pull/36559

2 Likes

@piever and @Henrique_Becker: the PR is now merged

2 Likes

Oh, good news. Thanks for pinging back. Good contribution.