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

Conversation

mbauman
Copy link
Member

@mbauman mbauman commented Feb 12, 2018

Fixes #18326.

Edit: this now couples a behavior change in with the name change. The deprecation gives us a convenient time to improve its behavior to use views instead of getindex.

@mbauman mbauman added arrays [a, r, r, a, y, s] deprecation This change introduces or involves a deprecation labels Feb 12, 2018
ararslan
ararslan previously approved these changes Feb 12, 2018
@stevengj
Copy link
Member

stevengj commented Feb 12, 2018

I didn't even know this function existed; we don't use it anywhere in Base, but it seems to be used in a dozen or so packages.

I wonder if there should be a SubArray version of this, and if so what it would be called?

@mbauman
Copy link
Member Author

mbauman commented Feb 12, 2018

Yeah, see my comments at #18326 (comment) — one package defines its own slicedim but uses views instead. Arguably that's the much more valuable behavior.

This function is so old (1041bb4) I'd bet it predates views.

@@ -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.

@mbauman
Copy link
Member Author

mbauman commented Feb 13, 2018

You know what, I think views are indeed the better functionality here… and a name change is a great time to do that. I pushed a new commit for that.

@mbauman mbauman changed the title Deprecate slicedim to selectdim Deprecate slicedim(…) to copy(selectdim(…)); always return a view Feb 13, 2018
@@ -26,7 +26,7 @@ macro deprecate(old, new, ex=true)
newname = Expr(:quote, new)
Expr(:toplevel,
ex ? Expr(:export, esc(old)) : nothing,
:(function $(esc(old))(args...)
:(@__doc__ function $(esc(old))(args...)
Copy link
Member Author

Choose a reason for hiding this comment

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

Watch out, I snuck in the ability to document deprecated functions :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, never mind, it bails on bootstrapping and I don't feel strongly enough to battle that one out.

NEWS.md Outdated
@@ -646,6 +646,10 @@ 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(A, d, i)` has been deprecated in favor of `copy(selectdim(A, d, i)`. The new
Copy link
Member

Choose a reason for hiding this comment

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

Missing closing parenthesis.

Add support for SubArrays of BitArrays in BitArray's test suite
@mbauman
Copy link
Member Author

mbauman commented Feb 13, 2018

Ok, I think I should have tests passing now. Interestingly, always returning a view and moving to a new name makes #20233 non-breaking.

@mbauman mbauman dismissed ararslan’s stale review February 13, 2018 19:43

functionality changed since review

@StefanKarpinski
Copy link
Member

Given that it always returns a view now, maybe it should be called dimview :trollface:

@JeffBezanson JeffBezanson merged commit 1934dda into master Feb 14, 2018
@JeffBezanson JeffBezanson deleted the mb/selectdim branch February 14, 2018 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] deprecation This change introduces or involves a deprecation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants