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

presently possible rewrites for potential collect deprecation #25450

Merged
merged 4 commits into from
Jan 10, 2018

Conversation

Sacha0
Copy link
Member

@Sacha0 Sacha0 commented Jan 7, 2018

This pull request rewrites (all?) collect calls that can presently be rewritten as Vector|Matrix|Array, constituting a head start on the potential collect deprecation between 0.7 and 1.0. (For the latest re. the potential collect deprecation, ref. #16029 (comment).) Best!

Copy link
Member

@nalimilan nalimilan left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good, though I've noted a few places where Vector could be removed.

@@ -791,7 +791,7 @@ for A in (rand(2), rand(2,3))
for (i, v) in pairs(A)
@test A[i] == v
end
@test collect(values(A)) == collect(A)
@test Array(values(A)) == Array(A)
Copy link
Member

Choose a reason for hiding this comment

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

Array doesn't seem needed on the RHS?

test/arrayops.jl Outdated
@@ -468,7 +468,7 @@ end
@test find(c -> c == 'l', s) == [3]
g = Base.Unicode.graphemes("日本語")
@test find(isascii, g) == Int[]
@test find(!iszero, (i % 2 for i in 1:10)) == collect(1:2:9)
@test find(!iszero, (i % 2 for i in 1:10)) == Vector(1:2:9)
Copy link
Member

Choose a reason for hiding this comment

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

Vector shouldn't be needed now.

test/arrayops.jl Outdated
@@ -1631,7 +1631,7 @@ end
val, state = next(itr, state)
@test done(itr, state)
@test r[val] == 3
r = sparse(collect(2:3:8))
r = sparse(Vector(2:3:8))
Copy link
Member

Choose a reason for hiding this comment

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

Vector doesn't seem to be needed.

gv = view(g, -1:2)
@test axes(gv, 1) === Base.OneTo(4)
@test collect(gv) == collect(-1:2)
@test collect(gv) == Vector(-1:2)
Copy link
Member

Choose a reason for hiding this comment

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

Not needed here not below.

test/random.jl Outdated
@test shuffle(mta,collect(1:10)) == shuffle(mtb,collect(1:10))
@test shuffle!(mta,collect(1:10)) == shuffle!(mtb,collect(1:10))
@test shuffle(mta,collect(2:11)) == shuffle(mtb,2:11)
@test shuffle(mta,Vector(1:10)) == shuffle(mtb,collect(1:10))
Copy link
Member

Choose a reason for hiding this comment

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

Also change collect on the RHS.

@@ -1864,7 +1864,7 @@ end
# are called. (Issue #18705.) EDIT: #19239 unified broadcast over a single sparse matrix,
# eliminating the former operation classes.
@testset "issue #18705" begin
S = sparse(Diagonal(collect(1.0:5.0)))
S = sparse(Diagonal(Vector(1.0:5.0)))
Copy link
Member

Choose a reason for hiding this comment

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

Vector not needed, nor below.

@test quantile(100.0:-1.0:0.0, 0.0:0.1:1.0) == collect(0.0:10.0:100.0)
@test quantile(0.0:100.0, 0.0:0.1:1.0, sorted=true) == collect(0.0:10.0:100.0)
@test quantile(100f0:-1f0:0.0, 0.0:0.1:1.0) == collect(0f0:10f0:100f0)
@test quantile(100.0:-1.0:0.0, 0.0:0.1:1.0) == Vector(0.0:10.0:100.0)
Copy link
Member

Choose a reason for hiding this comment

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

Vector not needed.

@Sacha0
Copy link
Member Author

Sacha0 commented Jan 7, 2018

Thanks for the thorough review @nalimilan! Comments addressed :).

@timholy
Copy link
Member

timholy commented Jan 8, 2018

I'm still a little bit worried about #16029 (comment). Is the idea that we've made a stronger distinction between convert(T, x) and T(x)? (Sorry, I haven't had time to follow all the issues.) convert(Vector, x) should definitely fail if x doesn't start indexing with 1, but if we're being clearer about the distinction then I can see Vector(x) being justified.

@StefanKarpinski
Copy link
Member

@JeffBezanson: can you clarify the new relationship between T(x) and convert(T, x)?

@JeffBezanson
Copy link
Member

The differences between convert and constructors are:

  1. The one we've always had: convert should only be for "sufficiently similar" things.
  2. convert(::Type{T}, x::T) can and should just return x, it doesn't need to copy.

So it is still the case that constructors have more leeway than convert. However, we would need to be careful that convert in those cases does extra checks before calling the constructor.

@Sacha0
Copy link
Member Author

Sacha0 commented Jan 9, 2018

(Marking triage for a decision re. #16029 (comment) / this pull request. Best!)

@Sacha0 Sacha0 added the triage This should be discussed on a triage call label Jan 9, 2018
@mschauer
Copy link
Contributor

mschauer commented Jan 9, 2018

I think these changes are meaningful even if collect is kept and do not need to wait for a decision.

@Sacha0
Copy link
Member Author

Sacha0 commented Jan 9, 2018

I think these changes are meaningful even if collect is kept and do not need to wait for a decision.

After reviewing these changes again, I tend to agree :). So absent objections or requests for time, I plan to merge these changes tomorrow midday PT or later. Best!

@Sacha0 Sacha0 removed the triage This should be discussed on a triage call label Jan 9, 2018
@Sacha0
Copy link
Member Author

Sacha0 commented Jan 10, 2018

(AV i686 timed out without apparent issue prior, Travis i686 hit an unrelated libgit2 failure without other apparent issues, and Travis macOS hit an unrelated spawn failure without other apparent issues.)

@Sacha0 Sacha0 merged commit bc56748 into JuliaLang:master Jan 10, 2018
@Sacha0 Sacha0 deleted the decollect branch January 10, 2018 19:10
@Sacha0
Copy link
Member Author

Sacha0 commented Jan 10, 2018

Thanks all! :)

Keno pushed a commit that referenced this pull request Jun 5, 2024
presently possible rewrites for potential collect deprecation
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.

6 participants