Skip to content
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 similar(f, …) in favor of just dispatching directly on f(…) #26733

Merged
merged 5 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add NEWS and deprecations for...
the tightening of signatures for zeros and ones.
  • Loading branch information
mbauman committed Apr 6, 2018
commit db3751d427981a575fcfb741b816577d797b3486
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,16 @@ Deprecated or removed
necessary, consider `fill!(similar(A[, opts...]), {one(eltype(A)) | zero(eltype(A))})`.
For an algebraic multiplicative identity, consider `one(A)` ([#24656]).

* The `similar(dims->f(..., dims...), [T], axes...)` method to add offset array support
to a function `f` that would otherwise create a non-offset array has been deprecated.
Instead, call `f(..., axes...)` directly and, if needed, the offset array implementation
should add offset axis support to the function `f` directly ([#26733]).

* The functions `ones` and `zeros` used to accept any objects as dimensional arguments,
implicitly converting them to `Int`s. This is now deprecated; only `Integer`s or
`AbstractUnitRange`s are accepted as arguments. Instead, convert the arguments before
calling `ones` or `zeros` ([#26733]).

* The `Operators` module is deprecated. Instead, import required operators explicitly
from `Base`, e.g. `import Base: +, -, *, /` ([#22251]).

Expand Down
12 changes: 11 additions & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ end
@deprecate Crand Libc.rand false
@deprecate Csrand Libc.srand false

# Deprecate `similar(f, axes)`
# Deprecate `similar(f, axes)` (PR #26733)
@noinline function similar(f, shape::Tuple)
depwarn("using similar(f, shape) to call `f` with axes `shape` is deprecated; call `f` directly and/or add methods such that it supports axes", :similar)
f(to_shape(shape))
Expand All @@ -1566,6 +1566,16 @@ end
depwarn("using similar(f, shape...) to call `f` with axes `shape` is deprecated; call `f` directly and/or add methods such that it supports axes", :similar)
f(to_shape(dims))
end
# Deprecate non-integer/axis arguments to zeros/ones to match fill/trues/falses
@deprecate zeros(::Type{T}, dims...) where {T} zeros(T, convert(Dims, dims)...)
@deprecate zeros(dims...) zeros(convert(Dims, dims)...)
@deprecate zeros(::Type{T}, dims::NTuple{N, Any}) where {T, N} zeros(T, convert(Dims, dims))
@deprecate zeros(dims::Tuple) zeros(convert(Dims, dims))
@deprecate ones(::Type{T}, dims...) where {T} ones(T, convert(Dims, dims)...)
@deprecate ones(dims...) ones(convert(Dims, dims)...)
@deprecate ones(::Type{T}, dims::NTuple{N, Any}) where {T, N} ones(T, convert(Dims, dims))
@deprecate ones(dims::Tuple) ones(convert(Dims, dims))


@deprecate showcompact(x) show(IOContext(stdout, :compact => true), x)
@deprecate showcompact(io, x) show(IOContext(io, :compact => true), x)
Expand Down
2 changes: 1 addition & 1 deletion test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2322,7 +2322,7 @@ end
test_zeros(zeros(Int, (2, 3)), Matrix{Int}, (2,3))

# #19265"
@test_throws MethodError zeros(Float64, [1.])
@test_throws Any zeros(Float64, [1.]) # TODO: Tighten back up to MethodError once 0.7 deprecations are removed
end

# issue #11053
Expand Down