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

RFC: Change Array(T, dims) to Array{T}(dims) #17583

Merged
merged 5 commits into from Jul 24, 2016

Conversation

ararslan
Copy link
Member

In the documentation for Array in base/docs/helpdb/Base.jl, it's claimed that the syntax Array(T, dims) is available but deprecated. (Though there's no actual deprecation warning or anything for it.) I figured that if we're claiming that Array(T, dims) shouldn't be used, then we shouldn't be using it ourselves. 😉

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jul 23, 2016

This was seen to have performance implications if not done carefully. In particular, it's best to add the N parameter also so that it becomes a leaf type. (The two in the deprecation set don't need to change, esp. since the N isn't available for them)

@tkelman
Copy link
Contributor

tkelman commented Jul 23, 2016

Apparently which form you use makes a performance difference, sometimes. See #16851 which reverted a handful of instances that #16498 changed.

@ararslan
Copy link
Member Author

Sorry, I wasn't aware of the performance regressions! I'll go through and add the N parameter as @vtjnash mentioned, unless you guys think that this idea should just be abandoned.

@ararslan
Copy link
Member Author

Is it the array changes here that broke everything? I can't really tell.

@ararslan
Copy link
Member Author

I think the answer there is "yes." I'll leave stuff like this to the experts.

@ararslan ararslan closed this Jul 23, 2016
@ararslan ararslan deleted the aa/array-brackets branch July 23, 2016 20:47
_array_for(T, itr, ::HasLength) = Array(T, Int(length(itr)::Integer))
_array_for(T, itr, ::HasShape) = Array(T, convert(Dims,size(itr)))
_array_for(T, itr, ::HasLength) = Array{T,1}(Int(length(itr)::Integer))
_array_for(T, itr, ::HasShape) = Array{T,1}(convert(Dims,size(itr)))
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This has N=ndims(iter)

@ararslan ararslan restored the aa/array-brackets branch July 23, 2016 21:29
@ararslan ararslan reopened this Jul 23, 2016
@StefanKarpinski
Copy link
Sponsor Member

I'll leave stuff like this to the experts.

Carry on – you don't become an expert without trying stuff like this!

_array_for(T, itr, ::HasLength) = Array(T, Int(length(itr)::Integer))
_array_for(T, itr, ::HasShape) = Array(T, convert(Dims,size(itr)))
_array_for(T, itr, ::HasLength) = Array{T,ndims(itr)}(Int(length(itr)::Integer))
_array_for(T, itr, ::HasShape) = Array{T,ndims(itr)}(convert(Dims,size(itr)))

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd leave the first one as Array{T,1} (it is the only Array{T,N} that can have a single Int as argument). The second one is probably better just as Array{T} since the ndims(itr) will make it non inferable.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had no idea that the ndims(itr) would ruin the type inference. @vtjnash Is there a way to specify the N in this case that preserves inferability?

Copy link
Contributor

@pabloferz pabloferz Jul 24, 2016

Choose a reason for hiding this comment

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

I might have expressed a bit wrong. The problem is that since ndims(itr) is not inferable the compiler cannot inline the constructor where it might help speed something.

But don't worry. I believe this got you covered here: https://github.com/JuliaLang/julia/pull/16851/files#diff-4cbc8eb916240b8a07540daa4316d1c5R319

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, I see. I changed it to Array{Int} per your suggestion and so far the CI hasn't failed. Thanks for your help! 👍

@ararslan
Copy link
Member Author

Woo, thanks to @pabloferz things are passing! Since @tkelman and @vtjnash cited performance concerns, should we check for performance regressions here using nanosoldier?

@tkelman
Copy link
Contributor

tkelman commented Jul 24, 2016

go team
@nanosoldier runbenchmarks(ALL, vs = ":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jul 24, 2016

That string-join improvement might be real, the rest is random testing noise. The PR lgtm.

@ararslan
Copy link
Member Author

What did I change that would affect string joins?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jul 24, 2016

perhaps _array_for? It might be testing a comprehension. Although it's also just as possible that it's a measurement fluke.

@ararslan
Copy link
Member Author

Ah, okay. Thanks for all of your help here, everyone. And thanks for the encouragement, @StefanKarpinski.

@JeffBezanson JeffBezanson merged commit 0d7c014 into JuliaLang:master Jul 24, 2016
@ararslan ararslan deleted the aa/array-brackets branch July 24, 2016 18:35
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.

None yet

7 participants