Skip to content

Conversation

@ajkeller34
Copy link
Contributor

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 0 and 1 were used instead of zero(T) and oneunit(T), causing issues for dimensionful numbers. This PR substitutes in zero(T) and oneunit(T) and updates NEWS.md with revised guidance (although the guidance is even more verbose than before...)

Cross-ref #24656 (comment)

Copy link
Member

@fredrikekre fredrikekre left a 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.

@ajkeller34
Copy link
Contributor Author

Yes, that's right. I've updated the PR.

@Sacha0
Copy link
Member

Sacha0 commented Dec 12, 2017

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))})`,
Copy link
Member

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.

@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)))
Copy link
Member

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? :)

Copy link
Member

@Sacha0 Sacha0 left a 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!)

@ajkeller34
Copy link
Contributor Author

ajkeller34 commented Dec 31, 2017

Sorry for the delay (holidays). I rebased and tried to address the minor review comments:

  • Commit 75f80a7 addresses Sacha0's first minor review comment.
  • Commit c36809d attempts to address Sacha0's second minor review comment.
  • Commit 02112fd corrects deprecations that I missed for zeros(D::Diagonal[, opts...]). It changes the deprecations to use zero(T) instead of 0, as before, and is also done in the spirit of Sacha0's second minor review comment.

Copy link
Member

@Sacha0 Sacha0 left a 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! :)

@andreasnoack andreasnoack merged commit c3c0964 into JuliaLang:master Jan 2, 2018
@ajkeller34 ajkeller34 deleted the dimensionsfix branch January 2, 2018 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants