-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Some adjustments for dimensionful numbers #25035
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
Conversation
fredrikekre
left a comment
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.
None of the methods should call oneunit(T), the deprecations should exactly mimic the old behavior, which was to call one(T) in all the cases here.
8e6276d to
fdc9e67
Compare
|
Yes, that's right. I've updated the PR. |
|
Thanks @ajkeller34! :) I hope to have a look late this evening PT or tomorrow evening PT. Best! |
NEWS.md
Outdated
| `zero(A)`. For `ones(A)` or `zeros(A)`, consider `fill(v, size(A))` for `v` an | ||
| appropriate one or zero, `fill!(copy(A), {1|0})`, `ones(size(A))` or | ||
| `zeros(size(A))`, or any of the preceding with different element type | ||
| appropriate one or zero, `fill!(copy(A), {one(eltype(A)) | zero(eltype(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.
Perhaps leave fill!(copy(A), {1|0}) where it is, add fill!(similar(A), {1|0}) shortly thereafter, and only later suggest fill!(copy(A), {one(eltype(A)) | zero(eltype)}) for where strictly necessary? Providing the simplest possible replacements that will work in most cases first seems best.
base/deprecated.jl
Outdated
| @deprecate zeros(a::AbstractArray, ::Type{T}, dims::Tuple) where {T} fill!(similar(a, T, dims), zero(T)) | ||
| @deprecate zeros(a::AbstractArray, ::Type{T}, dims...) where {T} fill!(similar(a, T, dims...), zero(T)) | ||
| @deprecate zeros(a::AbstractArray, ::Type{T}) where {T} fill!(similar(a, T), zero(T)) | ||
| @deprecate zeros(a::AbstractArray) fill!(similar(a), zero(eltype(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.
With benefit of hindsight, ideally each of these deprecations would throw a longer depwarn, containing similar information to that in the news entry. I conjecture most users will see only the depwarn, and the suggestions in the news entry that are simpler than the depwarn are likely to be much better received than the general replacement. Thoughts? :)
Sacha0
left a comment
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.
Looks great modulo the minor review comments! Thanks @ajkeller34! :)
(The second review comment is aspirational. If you are not excited about addressing it, please do not feel obligated! I can make that change in a later pull request. Also, apologies for the slower than expected review!)
fdc9e67 to
75f80a7
Compare
|
Sorry for the delay (holidays). I rebased and tried to address the minor review comments:
|
Sacha0
left a comment
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 changes look great! Thanks @ajkeller34! :)
In an effort to restore compatibility of Unitful.jl with the nightly build, I noticed some of the tests started failing following PR #24656. In that PR, literal numbers
0and1were used instead ofzero(T)andoneunit(T), causing issues for dimensionful numbers. This PR substitutes inzero(T)andoneunit(T)and updates NEWS.md with revised guidance (although the guidance is even more verbose than before...)Cross-ref #24656 (comment)