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 slicedim(…) to copy(selectdim(…)); always return a view #26009

Merged
merged 5 commits into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
8 changes: 5 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ This section lists changes that do not have deprecation warnings.
longer the case; now bindings will only exist for packages brought into scope by
typing `using Package` or `import Package` ([#17997]).

* `slicedim(b::BitVector, 1, x)` now consistently returns the same thing that `b[x]` would,
consistent with its documentation. Previously it would return a `BitArray{0}` for scalar
`x` ([#20233]).
* `selectdim(b::BitVector, 1, x)` (previously known as `slicedim`) now consistently returns
the same thing that `b[x]` would, consistent with its documentation. Previously it would
return a `BitArray{0}` for scalar `x` ([#20233]).

* The rules for mixed-signedness integer arithmetic (e.g. `Int32(1) + UInt64(1)`) have been
simplified: if the arguments have different sizes (in bits), then the type of the larger
Expand Down Expand Up @@ -646,6 +646,8 @@ Deprecated or removed
* Using Bool values directly as indices is now deprecated and will be an error in the future. Convert
them to `Int` before indexing if you intend to access index `1` for `true` and `0` for `false`.

* `slicedim` has been deprecated in favor of `selectdim` ([#26009]).

* `whos` has been renamed `varinfo`, and now returns a markdown table instead of printing
output ([#12131]).

Expand Down
8 changes: 4 additions & 4 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ imag(x::AbstractArray{<:Real}) = zero(x)
# index A[:,:,...,i,:,:,...] where "i" is in dimension "d"

"""
slicedim(A, d::Integer, i)
selectdim(A, d::Integer, i)

Return all the data of `A` where the index for dimension `d` equals `i`. Equivalent to
`A[:,:,...,i,:,:,...]` where `i` is in position `d`.
Expand All @@ -110,13 +110,13 @@ julia> A = [1 2 3 4; 5 6 7 8]
1 2 3 4
5 6 7 8

julia> slicedim(A,2,3)
julia> selectdim(A,2,3)
2-element Array{Int64,1}:
3
7
```
"""
function slicedim(A::AbstractArray, d::Integer, i)
function selectdim(A::AbstractArray, d::Integer, i)
d >= 1 || throw(ArgumentError("dimension must be ≥ 1"))
nd = ndims(A)
d > nd && (i == 1 || throw_boundserror(A, (ntuple(k->Colon(),nd)..., ntuple(k->1,d-1-nd)..., i)))
Expand Down Expand Up @@ -167,7 +167,7 @@ function flipdim(A::AbstractArray, d::Integer)
let B=B # workaround #15276
alli = [ axes(B,n) for n in 1:nd ]
for i in indsd
B[[ n==d ? sd-i : alli[n] for n in 1:nd ]...] = slicedim(A, d, i)
B[[ n==d ? sd-i : alli[n] for n in 1:nd ]...] = selectdim(A, d, i)
end
end
return B
Expand Down
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,9 @@ end
# issue #25928
@deprecate wait(t::Task) fetch(t)

# PR #26008
@deprecate slicedim(A::AbstractArray, d::Integer, i) selectdim(A, d, i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's a straight renaming of one to the other you can just use @deprecate slicedim selectdim

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I suppose it's effectively the same — that would define and export a broader signature, but it'd still hit a method error later on.


# PR 25062
@deprecate(link_pipe(pipe; julia_only_read = true, julia_only_write = true),
link_pipe!(pipe, reader_supports_async = julia_only_read, writer_supports_async = julia_only_write),
Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export
shuffle,
shuffle!,
size,
slicedim,
selectdim,
sort!,
sort,
sortcols,
Expand Down
2 changes: 1 addition & 1 deletion doc/src/base/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Base.@view
Base.@views
Base.parent
Base.parentindices
Base.slicedim
Base.selectdim
Base.reinterpret
Base.reshape
Base.squeeze
Expand Down
6 changes: 3 additions & 3 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ timesofar("binary comparison")
for d = 1:4
j = rand(1:size(b1, d))
#for j = 1 : size(b1, d)
@check_bit_operation slicedim(b1, d, j) BitArray{3}
@check_bit_operation selectdim(b1, d, j) BitArray{3}
#end
@check_bit_operation flipdim(b1, d) BitArray{4}
end
Expand Down Expand Up @@ -1071,9 +1071,9 @@ timesofar("binary comparison")
i2 = circshift!(b1, -j)
@test b2 == i2

@check_bit_operation slicedim(b1, 1, m) Bool
@check_bit_operation selectdim(b1, 1, m) Bool
end
@check_bit_operation slicedim(b1, 1, :) BitVector
@check_bit_operation selectdim(b1, 1, :) BitVector
end

timesofar("datamove")
Expand Down