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

use the compact f(x::AbstractVector{<:Number}) syntax

Open mkborregaard opened this issue 8 years ago • 8 comments

I have

ignorenan_minimum{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.minimum(x)

the bot suggests

ignorenan_minimum(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.minimum(x)

but I'd prefer

ignorenan_minimum(x::AbstractArray{<:AbstractFloat}) = NaNMath.minimum(x)

here: https://github.com/JuliaPlots/Plots.jl/pull/1036#discussion_r134702647

mkborregaard avatar Aug 23 '17 09:08 mkborregaard

Those do actually mean different things to the system. I guess @JeffBezanson should judge whether or not this rewrite would be ok.

Keno avatar Aug 24 '17 19:08 Keno

Yeah I guess it requires F to never appear in the function body. If there are other important differences that would also be really useful to know :-)

mkborregaard avatar Aug 25 '17 06:08 mkborregaard

Fortunately (on master) those should dispatch exactly the same (or else we'd now consider it a bug). However, @mkborregaard is right that this transformation is only safe if F is not a free variable of the body, which is pretty difficult to compute. But it should certainly be safe if F doesn't appear at all in the body.

This variation would also be good to support:

f(x::T) where T<:Real = ...

to

f(x::Real) = ...

(also, of course, where T doesn't appear in the body).

JeffBezanson avatar Aug 25 '17 17:08 JeffBezanson

Ok, can do. Just making sure we don't rely on this in specialization heuristics, etc.

Keno avatar Aug 25 '17 17:08 Keno

Yes, I think it still affects specialization, but the cases where that's needed should be very rare. We can deal with those cases individually as they arise. I might even suggest that if you think you need such specialization but don't have the benchmarks to prove it, then you don't really :)

JeffBezanson avatar Aug 25 '17 18:08 JeffBezanson

Should we have some sort of macro that people can use to indicate that they really do want the specialization behavior (similar to what we did with what used to be ::ANY).

Keno avatar Aug 25 '17 18:08 Keno

At that point, wouldn't it be better to let them just directly ask for the specialization, instead of having it be coupled with the way you write the method signature and telling the bot not to undo it?

StefanKarpinski avatar Aug 25 '17 20:08 StefanKarpinski

Just to hear if I'm understanding this correctly - my impression is that at some point this will be implemented, when that happens the femtocleaner PR will be automatically updated, and I should just hold on merging that until then?

mkborregaard avatar Sep 29 '17 05:09 mkborregaard