-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vectorized float() deprecations #22966
Conversation
Remove various float() methods, replacing with broadcast optimizations where appropriate. Some of the previous optimized versions (eg, for sparse matrices and vectors) are unnecessary, as the broadcast implementation has an optimization for the zero-preserving case.
I think there was a concern about the extra copy when the element type is already floating point like, i.e. julia> x = randn(1);
julia> float(x) === x
true as a feature. I'm not sure how much it is used, though. The problem is that converting to a floating point type via |
LinSpace(float(r.start), float(r.stop), length(r)) | ||
end | ||
# Optimizations for broadcasting float() | ||
broadcast(::typeof(float), A::AbstractArray{<:AbstractFloat}) = A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, @andreasnoack do you mean we should or should not have this optimization?
At the moment I left it in here to duplicate the old behavior of avoiding the copy. A counter argument might be that people usually expect broadcast
to make a copy of the data, and optimizing that away in particular cases is too confusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry. I missed that "adding a few broadcast specializations" was exactly about this issue. I'm not sure what my opinion is. Always getting a copy is easy to reason about but avoiding an unnecessary copy is also a good thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, I'm not sure what's better here either. At the moment I went for the faster version, as it allows broadcast to be a drop in replacement for vectorized float()
.
Do we have any precedent for not returning a copy of the data in broadcast()
? I had a quick look through Base
, and all I found was was that broadcast(::typeof(xor), B::BitArray, x::Bool)
takes the opposite stance and calls copy()
when it wouldn't otherwise be required.
base/deprecated.jl
Outdated
@dep_vectorize_1arg Complex float | ||
# float(A) -> float.(A) | ||
@dep_vectorize_1arg Number float | ||
@dep_vectorize_1arg AbstractString float |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these aren't in the right section since these lines are scheduled to be deleted before 0.7 rc's, but newly modified deprecations should stay until 1.0-pre
Deprecating the remaining vectorized |
Oh dear, I hope I'm not the only one who has trouble finding old discussions on github :-/ I thought I'd just jump in and fix this as a small and obvious inconsistency with a PR, rather than opening an issue! So obviously there's some prior opinion expressed in #18495 that There's also evidence that code is now already relying on broadcast to create a copy: the main test failures here are in So I think on the whole, that I'm going to back away from this specific solution slowly with arms where you can see them ;-) However, there's a few issues unaddressed:
I can update this PR to be more minimal and just address these few issues (unless anybody thinks I should make a separate PR for that). |
You are not the only one I assure you! :)
Good question! My recollection is hazy. But IIRC, those methods were vectorized via (FWIW, I would support deprecating vectorized Best! |
|
Unfortunately that and similar incantations won't work IIRC; see the discussion beginning #18495 (comment). Instead incantations like |
Note the |
To be clear, I'm not saying this works right now; but there is no reason we can't specialize that particular |
Yes, sorry I missed the |
What about the following deprecations:
|
Looks like we are not doing this. |
Vectorized
float()
is currently deprecated only forAbstractArray{<:Complex}
, but not for other types of numbers or strings.This PR deprecates all vectorized versions of float, replacing uses of such with
broadcast()
, and adding a few broadcast specializations where necessary to maintain the efficiency of a few specialized vectorized versions.This came up over at JuliaArrays/StaticArrays.jl#247