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: Deprecate Array(T, dims...) #19989

Merged
merged 2 commits into from
Jan 14, 2017
Merged

Conversation

ararslan
Copy link
Member

This PR implements one of the changes mentioned in #19598: deprecate the Array(T, dims...) syntax in favor of Array{T,N}(dims...). The manual has claimed the former syntax to be deprecated ever since the latter syntax was introduced, though no formal deprecation ever happened... until now!

Thanks to @vtjnash and @JeffBezanson for their help on this.

Array{T}(::Type{T}, d::Integer...) = Array(T, convert(Tuple{Vararg{Int}}, d))
Array{T}(::Type{T}, m::Integer) = Array{T,1}(Int(m))
Array{T}(::Type{T}, m::Integer,n::Integer) = Array{T,2}(Int(m),Int(n))
Array{T}(::Type{T}, m::Integer,n::Integer,o::Integer) = Array{T,3}(Int(m),Int(n),Int(o))
Copy link
Member

Choose a reason for hiding this comment

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

move these to deprecations.jl?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, thanks.

@@ -2242,7 +2242,7 @@
,.(map (lambda (v r) `(= ,v (call (top length) ,r))) lengths rv)
(scope-block
(block
(= ,result (call (core Array) ,atype ,@lengths))
(= ,result (call (curly Array ,atype) ,@lengths))
Copy link
Member

Choose a reason for hiding this comment

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

can also add ,(length lengths) to the (curly, if I'm not mistaken, to splice in the number of dimensions also

@tkelman
Copy link
Contributor

tkelman commented Jan 12, 2017

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

@ararslan
Copy link
Member Author

ararslan commented Jan 12, 2017

...huh. Well, the fact that this works on Linux and macOS but not on Windows is rather concerning. Looks like it's failing on mmap because something in there is using the old syntax on Windows.

@quinnj
Copy link
Member

quinnj commented Jan 12, 2017

I think this line is the offender.

@ararslan
Copy link
Member Author

ararslan commented Jan 12, 2017

Excellent catch, @quinnj, thanks! I didn't even realize that Array(T) created a zero-dimensional array. Fix incoming.

Edit: Side note, may have inadvertently canceled Nanosoldier by manually squashing the fix and force pushing...

@@ -277,7 +277,7 @@ if is_windows()
const FORMAT_MESSAGE_FROM_SYSTEM = UInt32(0x1000)
const FORMAT_MESSAGE_IGNORE_INSERTS = UInt32(0x200)
const FORMAT_MESSAGE_MAX_WIDTH_MASK = UInt32(0xFF)
lpMsgBuf = Array(Ptr{UInt16})
lpMsgBuf = Array{Ptr{UInt16},0}(())
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this the same as lpMsgBuf = Array{Ptr{UInt16},0}() ?

Copy link
Member Author

@ararslan ararslan Jan 12, 2017

Choose a reason for hiding this comment

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

No, that's actually a MethodError.

julia> Array{Ptr{UInt16},0}()
ERROR: MethodError: no method matching Array{Ptr{UInt16},0}()
Closest candidates are:
  Array{Ptr{UInt16},0}{T,N}(::Tuple{Vararg{Int64,N}}) at boot.jl:310
  Array{Ptr{UInt16},0}{T}(::Any) at sysimg.jl:53

(The above is from Julia 0.5; that behavior wasn't introduced in this PR)

Copy link
Contributor

Choose a reason for hiding this comment

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

Strange I don't get a method error (Commit db4aaa3* (3 days old master))

julia> Array{Ptr{UInt16},0}()
0-dimensional Array{Ptr{UInt16},0}:
Ptr{UInt16} @0x0000000000000003

julia> versioninfo()
Julia Version 0.6.0-dev.2005
Commit db4aaa3* (2017-01-09 10:16 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-4510U CPU @ 2.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

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 yeah, looks like the behavior changed in 0.6, nice.

@nanosoldier
Copy link
Collaborator

Something went wrong when running your job:

NanosoldierError: error when preparing/pushing to report repo: ErrorException("failed process: Process(`git push`, ProcessExited(1)) [1]")

Unfortunately, the logs could not be uploaded.
cc @jrevels

@jrevels
Copy link
Member

jrevels commented Jan 12, 2017

Looks like there was a major service outage on GitHub at about the time that Nanosoldier attempted to upload the logs. Retriggering:

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

@StefanKarpinski
Copy link
Member

Unrelated Pkg test failure on one of the Windows tests. Since those tests are only run after all the other tests have already passed, this is pretty safe.

@mbauman
Copy link
Member

mbauman commented Jan 12, 2017

Looks good, thanks! Maybe remove the deprecated statement in the manual now, too? We don't typically include prose like that and it'll likely be forgotten and become outdated.

Also, SharedArrays have a constructor of the same style.

@nanosoldier
Copy link
Collaborator

Something went wrong when running your job:

NanosoldierError: error when preparing/pushing to report repo: ErrorException("failed process: Process(`git push`, ProcessExited(1)) [1]")

Unfortunately, the logs could not be uploaded.
cc @jrevels

@jrevels
Copy link
Member

jrevels commented Jan 12, 2017

Wow, Nanosoldier's push is getting rejected because the all depwarns here are causing the STDERR log to exceed GitHub's file size limit of 100 MB. That's...a lot of depwarns 😛 Mostly in HDF5 and JLD. I'll remove that big log and just upload the other (much smaller) logs and post the link here.

EDIT: Here is the benchmark report. Looks like some of the benchmarks will have to be updated.

Here's how I "confirmed" that most of the depwarns in the oversized log were this PR's depwarns:

➜  logs git:(master) awk '/^WARNING/' 459bc3a62c227c795747b217a870280ac4827e0b_primary.err | wc -l
19170
➜  logs git:(master) awk '/^WARNING\: Array/' 459bc3a62c227c795747b217a870280ac4827e0b_primary.err | wc -l
19126

@@ -25,6 +25,14 @@ typealias DenseVecOrMat{T} Union{DenseVector{T}, DenseMatrix{T}}

import Core: arraysize, arrayset, arrayref

"""
Array{T}(dims)
Copy link
Contributor

Choose a reason for hiding this comment

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

list both parameters {T,N} here?

@ararslan
Copy link
Member Author

ararslan commented Jan 12, 2017

Hm, I'm not entirely sure what to do about SharedArrays. When I make the appropriate changes, I get

sharedarray.jl
WARNING: static parameter T does not occur in signature for Type at sharedarray.jl:57.
The method will not be callable.
WARNING: static parameter T does not occur in signature for Type at sharedarray.jl:113.
The method will not be callable.
WARNING: static parameter T does not occur in signature for Type at sharedarray.jl:147.
The method will not be callable.

during the build. These are the defined methods:

julia> methods(SharedArray)
# 9 methods for generic function "(::Type)":
(::Type{SharedArray}){T}(I::Int64...; kwargs...) in Base at sharedarray.jl:113
(::Type{SharedArray}){T,N}(dims::Tuple{Vararg{Int64,N}}; init, pids) in Base at sharedarray.jl:57
(::Type{SharedArray}){N}(filename::AbstractString, dims::Tuple{Vararg{Int64,N}}) in Base at sharedarray.jl:147
(::Type{SharedArray}){T,N}(filename::AbstractString, dims::Tuple{Vararg{Int64,N}}, offset::Integer; init, mode, pids) in Base at sharedarray.jl:147
(::Type{SharedArray}){T,N}(::Type{T}, dims::Tuple{Vararg{Int64,N}}; kwargs...) in Base at deprecated.jl:49
(::Type{SharedArray}){T}(::Type{T}, dims::Int64...; kwargs...) in Base at deprecated.jl:49
(::Type{SharedArray}){T,N}(filename::AbstractString, ::Type{T}, dims::Tuple{Vararg{Int64,N}}, offset; kwargs...) in Base at deprecated.jl:49
(::Type{SharedArray}){T}(filename::AbstractString, ::Type{T}, dims::Tuple{Vararg{T<:Any,N<:Any}}, offset; kwargs...) in Base at deprecated.jl:49
(::Type{T}){T}(arg) in Base at sysimg.jl:24

Clearly I've done something wrong here, just quite sure what yet.

@kshyatt kshyatt added the deprecation This change introduces or involves a deprecation label Jan 12, 2017
@yuyichao
Copy link
Contributor

The type parameter is not used as the warning suggests. You need to replace the implementation with one of the methods above.

@ararslan
Copy link
Member Author

I'm still having a hard time figuring out what's wrong with the SharedArray changes. I've pushed the commit (but skipped CI because I'm sure it'll fail) so if anyone is willing to provide some guidance that would be much appreciated.

@@ -53,7 +53,7 @@ computation with the master process acting as a driver.
If an `init` function of the type `initfn(S::SharedArray)` is specified, it is called on all
the participating workers.
"""
function SharedArray{T,N}(::Type{T}, dims::Dims{N}; init=false, pids=Int[])
function SharedArray{T,N}(dims::Dims{N}; init=false, pids=Int[])
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the definition on line 31 and move it here. This isn't a valid method definition at all. I.e. this does NOT define a method for SharedArray{T,N}.

@@ -110,10 +110,10 @@ function SharedArray{T,N}(::Type{T}, dims::Dims{N}; init=false, pids=Int[])
S
end

SharedArray(T, I::Int...; kwargs...) = SharedArray(T, I; kwargs...)
SharedArray{T}(I::Int...; kwargs...) = SharedArray{T,length(I)}(I; kwargs...)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should become a method of ShardArray{T} too replacing the ones on line 33 to 39.

@@ -142,7 +142,7 @@ file is not writable.
`offset` allows you to skip the specified number of bytes at the
beginning of the file.
"""
function SharedArray{T,N}(filename::AbstractString, ::Type{T}, dims::NTuple{N,Int},
function SharedArray{T,N}(filename::AbstractString, dims::NTuple{N,Int},
Copy link
Contributor

Choose a reason for hiding this comment

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

This should become a new method of SharedArray{T} this also needs to go in Compat.jl since it's not available on old julia versions AFAICT.

@@ -307,21 +307,25 @@ localindexes(S::SharedArray) = S.pidx > 0 ? range_1dim(S, S.pidx) : 1:0
unsafe_convert{T}(::Type{Ptr{T}}, S::SharedArray) = unsafe_convert(Ptr{T}, sdata(S))

function convert(::Type{SharedArray}, A::Array)
S = SharedArray(eltype(A), size(A))
sz = size(A)
S = SharedArray{eltype(A),length(sz)}(sz)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that there isn't any methods defined for SharedArray{T,N} apart from the inner constructor so this won't work. You need to either not use them and use SharedArray{T} instead or check for conflict/ambiguity and define them.

@@ -1649,4 +1649,12 @@ isempty(::Task) = error("isempty not defined for Tasks")
@deprecate Array{T}(::Type{T}, m::Integer,n::Integer) Array{T,2}(Int(m),Int(n))
@deprecate Array{T}(::Type{T}, m::Integer,n::Integer,o::Integer) Array{T,3}(Int(m),Int(n),Int(o))

# Likewise for SharedArrays
@deprecate SharedArray{T,N}(::Type{T}, dims::Dims{N}; kwargs...) SharedArray{T,N}(dims; kwargs...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to comment below, these are calling non-existing methods.

@ararslan
Copy link
Member Author

I think I've addressed all of your comments, @yuyichao. Thanks so much for your help!

@ararslan ararslan force-pushed the aa/array-syntax branch 3 times, most recently from ba77c5a to 92ee7ed Compare January 13, 2017 19:24
@@ -277,7 +277,7 @@ if is_windows()
const FORMAT_MESSAGE_FROM_SYSTEM = UInt32(0x1000)
const FORMAT_MESSAGE_IGNORE_INSERTS = UInt32(0x200)
const FORMAT_MESSAGE_MAX_WIDTH_MASK = UInt32(0xFF)
lpMsgBuf = Array(Ptr{UInt16})
lpMsgBuf = Array{Ptr{UInt16},0}()
Copy link
Member

Choose a reason for hiding this comment

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

Not necessary to change in this PR since this is the exact equivalent of what was there, but shouldn't this be updated to use a Ref{Ptr{UInt16}} instead of a zero-dimensional array?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to Ref

@ararslan ararslan merged commit 50d0d5d into JuliaLang:master Jan 14, 2017
@ararslan ararslan deleted the aa/array-syntax branch January 14, 2017 17:31
@jrevels
Copy link
Member

jrevels commented Jan 14, 2017

This PR's depwarns will "break" Nanosoldier's benchmark runs against master now that it's merged. Can we merge JuliaIO/JLD.jl#116 so that I can deploy it to Nanosoldier ASAP (I would merge it but I don't have commit access to JLD)?

jrevels added a commit to JuliaCI/BaseBenchmarks.jl that referenced this pull request Jan 14, 2017
@jrevels
Copy link
Member

jrevels commented Jan 14, 2017

Also would be good to get JuliaIO/HDF5.jl#354 merged for the same reason.

tkelman added a commit to JuliaIO/JLD.jl that referenced this pull request Jan 14, 2017
Array(T, dims...) to Array{T}(dims...) (ref JuliaLang/julia#19989)
jrevels added a commit to JuliaCI/BaseBenchmarks.jl that referenced this pull request Jan 14, 2017
@ararslan
Copy link
Member Author

Very sorry, should have waited to merge!

jrevels added a commit to JuliaCI/BaseBenchmarks.jl that referenced this pull request Jan 14, 2017
martinholters added a commit to HSU-ANT/ACME.jl that referenced this pull request Jan 16, 2017
@stevengj
Copy link
Member

stevengj commented Jan 24, 2017

I have to say that I dislike the deprecation of Array{T}(dims...), oh, it seems like that has been removed already.

@stevengj
Copy link
Member

Maybe I got confused by the deprecation message. Can we change it so that Array(T, dims...) is deprecated in favor of Array{T}(dims...), so that it doesn't falsely imply that you need to write the number of dimensions manually?

maleadt added a commit to JuliaAttic/CUDArt.jl that referenced this pull request Feb 16, 2017
vchuravy pushed a commit to JuliaAttic/CUDArt.jl that referenced this pull request Feb 17, 2017
Sacha0 added a commit to Sacha0/julia that referenced this pull request May 13, 2017
@Sacha0 Sacha0 added the needs news A NEWS entry is required for this change label May 13, 2017
Sacha0 added a commit to Sacha0/julia that referenced this pull request May 14, 2017
@tkelman tkelman self-assigned this May 15, 2017
@tkelman tkelman removed their assignment May 15, 2017
@tkelman tkelman removed the needs news A NEWS entry is required for this change label May 15, 2017
tkelman pushed a commit that referenced this pull request May 15, 2017
Sacha0 added a commit to Sacha0/julia that referenced this pull request May 20, 2017
tkelman pushed a commit that referenced this pull request Jun 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation This change introduces or involves a deprecation
Projects
None yet
Development

Successfully merging this pull request may close these issues.