-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
deprecate {ones|zeros}(A::AbstractArray[, opts...]) methods #24656
Conversation
NEWS.md
Outdated
@@ -434,6 +434,9 @@ Deprecated or removed | |||
* `expand(ex)` and `expand(module, ex)` have been deprecated in favor of | |||
`Meta.lower(module, ex)` ([#22064, #24278]). | |||
|
|||
* `ones(A::AbstractArray[, opts...])` and `zeros(A::AbstractArray[, opts...])` methods | |||
have been deprecated ([#24656]). |
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.
in favor of fill!(similar(A[, opts...]), 0/1)
?
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.
Good call! And done! Thanks! :)
08f1352
to
bf56cac
Compare
Absent objections or requests for time, I plan to merge these changes this evening (PT) or later. Best! |
It doesn't seem clear why these methods need to be deprecated. Why remove convenience and what does this accomplish/make better? I went through the discussion in #24595, and the explanations given there (generic array types, element types) do not seem to apply here, where you just want the same array and element types. |
In short, these methods see little if any use in the wild, and triage seemingly unanimously questioned their general soundness/wisdom. Best! |
The issue is that the methods with array arguments or array type arguments are meant to be used in fairly generic code, but in generic code there are always better options than |
Thanks |
If you have an array I also still don't see problems with these methods, and thus reasons to remove them. That there are more generic methods available is an argument for using those other methods if needed, but not remove the convenient ones. I don't have strong feelings about this one, but am commenting here regarding the direction arrays have taken recently. I agree that we need methods that are more generic to generate different Thanks for the hard work. |
These methods suffer from some of the shortcomings described in #24595. Additionally, these methods are not well defined in general: Should |
For the rest, like I said already, I am not suggesting to remove |
I won't argue further, if the desire to remove those methods is strong, I'll just do the substitution in my code. |
No such ambiguity exists with
If not, then one or more of
You cannot pass a shape to |
@jebej, note that instead of |
@jebej, I think we all appreciate that this is a somewhat unintuitive change because |
That's true, thanks, as that takes care of the simple case I was worried about, although only for
Like I said above, if only the simple case is needed, then Again, this is not a major issue for me, and I appreciate the amount of thought going to having a coherent API that is both powerful/extensible and simple. |
…y[, opts...]) methods.
News item updated with other possible rewrites. Best! |
Thanks all! :) |
Great additional discussion starting #24444 (comment). Best! |
@deprecate ones(a::AbstractArray, ::Type{T}, dims...) where {T} fill!(similar(a, T, dims...), 1) | ||
@deprecate ones(a::AbstractArray, ::Type{T}) where {T} fill!(similar(a, T), 1) | ||
@deprecate ones(a::AbstractArray) fill!(similar(a), 1) | ||
@deprecate zeros(a::AbstractArray, ::Type{T}, dims::Tuple) where {T} fill!(similar(a, T, dims), 0) |
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.
For dimensionful numbers, the replacement method doesn't work. You would need zero(T)
instead of 0
since converting between dimensionful and dimensionless numbers is not allowed. Likewise for ones
, probably you want oneunit(T)
instead of 1
.
Unless there are other considerations for using the literal numbers, shall I could open a PR to address this?
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.
Likely an oversight since the methods these replace used zero(T)
and one(T)
. Feel free to submit a PR 👍
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.
A pull request fleshing out these deprecations would be lovely! Including the alternative rewrites mentioned in this pull request's news entry would be wonderful as well.
Is the plan to also deprecate |
The winds of triage most recently favored the compromise of deprecating all remaining |
This pull request deprecates
ones(A::AbstractArray[, opts...])
andzeros(A::AbstractArray[, opts...])
methods. Ref. #24595 for background. Best!(CI failures anticipated. Will remove the WIP tag after working the CI failures out.)