Skip to content

Commit

Permalink
Replace Array{...}(shape...)-like calls in base/[b-d]*.jl.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha0 committed Nov 24, 2017
1 parent 2b326d3 commit 4e76658
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 57 deletions.
18 changes: 9 additions & 9 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mutable struct BitArray{N} <: DenseArray{Bool, N}
i += 1
end
nc = num_bit_chunks(n)
chunks = Vector{UInt64}(nc)
chunks = Vector{UInt64}(uninitialized, nc)
nc > 0 && (chunks[end] = UInt64(0))
b = new(chunks, n)
N != 1 && (b.dims = dims)
Expand Down Expand Up @@ -348,7 +348,7 @@ similar(B::BitArray, dims::Dims) = BitArray(dims...)
similar(B::BitArray, T::Type{Bool}, dims::Dims) = BitArray(dims)
# changing type to a non-Bool returns an Array
# (this triggers conversions like float(bitvector) etc.)
similar(B::BitArray, T::Type, dims::Dims) = Array{T}(dims)
similar(B::BitArray, T::Type, dims::Dims) = Array{T}(uninitialized, dims)

function fill!(B::BitArray, x)
y = convert(Bool, x)
Expand Down Expand Up @@ -502,7 +502,7 @@ end
convert(::Type{Array{T}}, B::BitArray{N}) where {T,N} = convert(Array{T,N}, B)
convert(::Type{Array{T,N}}, B::BitArray{N}) where {T,N} = _convert(Array{T,N}, B) # see #15801
function _convert(::Type{Array{T,N}}, B::BitArray{N}) where {T,N}
A = Array{T}(size(B))
A = Array{T}(uninitialized, size(B))
Bc = B.chunks
@inbounds for i = 1:length(A)
A[i] = unsafe_bitgetindex(Bc, i)
Expand Down Expand Up @@ -620,7 +620,7 @@ gen_bitarray(::IsInfinite, itr) = throw(ArgumentError("infinite-size iterable u

function gen_bitarray_from_itr(itr, st)
B = empty!(BitArray(bitcache_size))
C = Vector{Bool}(bitcache_size)
C = Vector{Bool}(uninitialized, bitcache_size)
Bc = B.chunks
ind = 1
cind = 1
Expand All @@ -645,7 +645,7 @@ end

function fill_bitarray_from_itr!(B::BitArray, itr, st)
n = length(B)
C = Vector{Bool}(bitcache_size)
C = Vector{Bool}(uninitialized, bitcache_size)
Bc = B.chunks
ind = 1
cind = 1
Expand Down Expand Up @@ -1189,7 +1189,7 @@ end

for f in (:+, :-)
@eval function ($f)(A::BitArray, B::BitArray)
r = Array{Int}(promote_shape(size(A), size(B)))
r = Array{Int}(uninitialized, promote_shape(size(A), size(B)))
ai = start(A)
bi = start(B)
ri = 1
Expand Down Expand Up @@ -1649,7 +1649,7 @@ end
function find(B::BitArray)
l = length(B)
nnzB = count(B)
I = Vector{Int}(nnzB)
I = Vector{Int}(uninitialized, nnzB)
nnzB == 0 && return I
Bc = B.chunks
Bcount = 1
Expand Down Expand Up @@ -1683,8 +1683,8 @@ findn(B::BitVector) = find(B)

function findn(B::BitMatrix)
nnzB = count(B)
I = Vector{Int}(nnzB)
J = Vector{Int}(nnzB)
I = Vector{Int}(uninitialized, nnzB)
J = Vector{Int}(uninitialized, nnzB)
cnt = 1
for j = 1:size(B,2), i = 1:size(B,1)
if B[i,j]
Expand Down
2 changes: 1 addition & 1 deletion base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ end
@nexprs $N i->(A_{i+1} = Bs[i])
@nexprs $nargs i->(keep_i = keeps[i])
@nexprs $nargs i->(Idefault_i = Idefaults[i])
C = Vector{Bool}(bitcache_size)
C = Vector{Bool}(uninitialized, bitcache_size)
Bc = B.chunks
ind = 1
cind = 1
Expand Down
2 changes: 1 addition & 1 deletion base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function transcode(::Type{UInt8}, src::Vector{<:Union{Int32,UInt32}})
take!(buf)
end
transcode(::Type{String}, src::String) = src
transcode(T, src::String) = transcode(T, Vector{UInt8}(src))
transcode(T, src::String) = transcode(T, Vector{UInt8}(uninitialized, src))
transcode(::Type{String}, src) = String(transcode(UInt8, src))

function transcode(::Type{UInt16}, src::Vector{UInt8})
Expand Down
6 changes: 3 additions & 3 deletions base/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ mutable struct Channel{T} <: AbstractChannel
if sz < 0
throw(ArgumentError("Channel size must be either 0, a positive integer or Inf"))
end
ch = new(Condition(), Condition(), :open, Nullable{Exception}(), Vector{T}(0), sz, 0)
ch = new(Condition(), Condition(), :open, Nullable{Exception}(), Vector{T}(), sz, 0)
if sz == 0
ch.takers = Vector{Task}(0)
ch.putters = Vector{Task}(0)
ch.takers = Vector{Task}()
ch.putters = Vector{Task}()
end
return ch
end
Expand Down
4 changes: 2 additions & 2 deletions base/combinatorics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

# Factorials

const _fact_table64 = Vector{Int64}(20)
const _fact_table64 = Vector{Int64}(uninitialized, 20)
_fact_table64[1] = 1
for n in 2:20
_fact_table64[n] = _fact_table64[n-1] * n
end

const _fact_table128 = Vector{UInt128}(34)
const _fact_table128 = Vector{UInt128}(uninitialized, 34)
_fact_table128[1] = 1
for n in 2:34
_fact_table128[n] = _fact_table128[n-1] * n
Expand Down
38 changes: 19 additions & 19 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ function Math.frexp(A::Array{<:AbstractFloat})
"consider using dot-syntax to `broadcast` scalar `frexp` over `Array`s ",
"instead, for example `frexp.(rand(4))`."), :frexp)
F = similar(A)
E = Array{Int}(size(A))
E = Array{Int}(uninitialized, size(A))
for (iF, iE, iA) in zip(eachindex(F), eachindex(E), eachindex(A))
F[iF], E[iE] = frexp(A[iA])
end
Expand Down Expand Up @@ -931,15 +931,15 @@ iteratoreltype(::Type{Task}) = EltypeUnknown()
isempty(::Task) = error("isempty not defined for Tasks")

# Deprecate Array(T, dims...) in favor of proper type constructors
@deprecate Array(::Type{T}, d::NTuple{N,Int}) where {T,N} Array{T}(d)
@deprecate Array(::Type{T}, d::Int...) where {T} Array{T}(d...)
@deprecate Array(::Type{T}, m::Int) where {T} Array{T}(m)
@deprecate Array(::Type{T}, m::Int,n::Int) where {T} Array{T}(m,n)
@deprecate Array(::Type{T}, m::Int,n::Int,o::Int) where {T} Array{T}(m,n,o)
@deprecate Array(::Type{T}, d::Integer...) where {T} Array{T}(convert(Tuple{Vararg{Int}}, d))
@deprecate Array(::Type{T}, m::Integer) where {T} Array{T}(Int(m))
@deprecate Array(::Type{T}, m::Integer,n::Integer) where {T} Array{T}(Int(m),Int(n))
@deprecate Array(::Type{T}, m::Integer,n::Integer,o::Integer) where {T} Array{T}(Int(m),Int(n),Int(o))
@deprecate Array(::Type{T}, d::NTuple{N,Int}) where {T,N} Array{T}(uninitialized, d)
@deprecate Array(::Type{T}, d::Int...) where {T} Array{T}(uninitialized, d...)
@deprecate Array(::Type{T}, m::Int) where {T} Array{T}(uninitialized, m)
@deprecate Array(::Type{T}, m::Int,n::Int) where {T} Array{T}(uninitialized, m,n)
@deprecate Array(::Type{T}, m::Int,n::Int,o::Int) where {T} Array{T}(uninitialized, m,n,o)
@deprecate Array(::Type{T}, d::Integer...) where {T} Array{T}(uninitialized, convert(Tuple{Vararg{Int}}, d))
@deprecate Array(::Type{T}, m::Integer) where {T} Array{T}(uninitialized, Int(m))
@deprecate Array(::Type{T}, m::Integer,n::Integer) where {T} Array{T}(uninitialized, Int(m),Int(n))
@deprecate Array(::Type{T}, m::Integer,n::Integer,o::Integer) where {T} Array{T}(uninitialized, Int(m),Int(n),Int(o))

@noinline function is_intrinsic_expr(@nospecialize(x))
Base.depwarn("is_intrinsic_expr is deprecated. There are no intrinsic functions anymore.", :is_intrinsic_expr)
Expand Down Expand Up @@ -1062,14 +1062,14 @@ end
## end of FloatRange

@noinline zero_arg_matrix_constructor(prefix::String) =
depwarn("$prefix() is deprecated, use $prefix(0, 0) instead.", :zero_arg_matrix_constructor)
depwarn("$prefix() is deprecated, use $prefix(uninitialized, 0, 0) instead.", :zero_arg_matrix_constructor)
function Matrix{T}() where T
zero_arg_matrix_constructor("Matrix{T}")
return Matrix{T}(0, 0)
return Matrix{T}(uninitialized 0, 0)
end
function Matrix()
zero_arg_matrix_constructor("Matrix")
return Matrix(0, 0)
return Matrix(uninitialized, 0, 0)
end

for name in ("alnum", "alpha", "cntrl", "digit", "number", "graph",
Expand Down Expand Up @@ -1129,9 +1129,9 @@ import .LinAlg: cond

# PR #21359
import .Random: srand
@deprecate srand(r::MersenneTwister, filename::AbstractString, n::Integer=4) srand(r, read!(filename, Array{UInt32}(Int(n))))
@deprecate srand(filename::AbstractString, n::Integer=4) srand(read!(filename, Array{UInt32}(Int(n))))
@deprecate MersenneTwister(filename::AbstractString) srand(MersenneTwister(0), read!(filename, Array{UInt32}(Int(4))))
@deprecate srand(r::MersenneTwister, filename::AbstractString, n::Integer=4) srand(r, read!(filename, Vector{UInt32}(uninitialized, Ints(n))))
@deprecate srand(filename::AbstractString, n::Integer=4) srand(read!(filename, Vector{UInt32}(uninitialized, Int(n))))
@deprecate MersenneTwister(filename::AbstractString) srand(MersenneTwister(0), read!(filename, Vector{UInt32}(uninitialized, Int(4))))

# PR #21974
@deprecate versioninfo(verbose::Bool) versioninfo(verbose=verbose)
Expand Down Expand Up @@ -1343,9 +1343,9 @@ import .LinAlg: lufact, lufact!, qrfact, qrfact!, cholfact, cholfact!

@deprecate read(s::IO, x::Ref) read!(s, x)

@deprecate read(s::IO, t::Type, d1::Int, dims::Int...) read!(s, Array{t}(tuple(d1,dims...)))
@deprecate read(s::IO, t::Type, d1::Integer, dims::Integer...) read!(s, Array{t}(convert(Tuple{Vararg{Int}},tuple(d1,dims...))))
@deprecate read(s::IO, t::Type, dims::Dims) read!(s, Array{t}(dims))
@deprecate read(s::IO, t::Type, d1::Int, dims::Int...) read!(s, Array{t}(uninitialized, tuple(d1,dims...)))
@deprecate read(s::IO, t::Type, d1::Integer, dims::Integer...) read!(s, Array{t}(uninitialized, convert(Tuple{Vararg{Int}},tuple(d1,dims...))))
@deprecate read(s::IO, t::Type, dims::Dims) read!(s, Array{t}(uninitialized, dims))

function CartesianRange(start::CartesianIndex{N}, stop::CartesianIndex{N}) where N
inds = map((f,l)->f:l, start.I, stop.I)
Expand Down
6 changes: 3 additions & 3 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mutable struct Dict{K,V} <: Associative{K,V}

function Dict{K,V}() where V where K
n = 16
new(zeros(UInt8,n), Array{K,1}(n), Array{V,1}(n), 0, 0, 0, 1, 0)
new(zeros(UInt8,n), Vector{K}(uninitialized, n), Vector{V}(uninitialized, n), 0, 0, 0, 1, 0)
end
function Dict{K,V}(d::Dict{K,V}) where V where K
new(copy(d.slots), copy(d.keys), copy(d.vals), d.ndel, d.count, d.age,
Expand Down Expand Up @@ -227,8 +227,8 @@ function rehash!(h::Dict{K,V}, newsz = length(h.keys)) where V where K
end

slots = zeros(UInt8,newsz)
keys = Array{K,1}(newsz)
vals = Array{V,1}(newsz)
keys = Vector{K}(uninitialized, newsz)
vals = Vector{V}(uninitialized, newsz)
age0 = h.age
count = 0
maxprobe = h.maxprobe
Expand Down
4 changes: 2 additions & 2 deletions base/distributed/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ end

additional_io_objs=Dict()
function launch_additional(np::Integer, cmd::Cmd)
io_objs = Vector{Any}(np)
addresses = Vector{Any}(np)
io_objs = Vector{Any}(uninitialized, np)
addresses = Vector{Any}(uninitialized, np)

for i in 1:np
io = open(detach(cmd), "r+")
Expand Down
2 changes: 1 addition & 1 deletion base/distributed/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function splitrange(N::Int, np::Int)
each = div(N,np)
extras = rem(N,np)
nchunks = each > 0 ? np : extras
chunks = Vector{UnitRange{Int}}(nchunks)
chunks = Vector{UnitRange{Int}}(uninitialized, nchunks)
lo = 1
for i in 1:nchunks
hi = lo + each - 1
Expand Down
2 changes: 1 addition & 1 deletion base/distributed/managers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ end
function launch(manager::SSHManager, params::Dict, launched::Array, launch_ntfy::Condition)
# Launch one worker on each unique host in parallel. Additional workers are launched later.
# Wait for all launches to complete.
launch_tasks = Vector{Any}(length(manager.machines))
launch_tasks = Vector{Any}(uninitialized, length(manager.machines))

for (i,(machine, cnt)) in enumerate(manager.machines)
let machine=machine, cnt=cnt
Expand Down
2 changes: 1 addition & 1 deletion base/distributed/pmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ julia> collect(c)
```
"""
function head_and_tail(c, n)
head = Vector{eltype(c)}(n)
head = Vector{eltype(c)}(uninitializd, n)
s = start(c)
i = 0
while i < n && !done(c, s)
Expand Down
24 changes: 12 additions & 12 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1300,61 +1300,61 @@ isdefined


"""
Vector{T}(n)
Vector{T}(uninitialized, n)
Construct an uninitialized [`Vector{T}`](@ref) of length `n`.
# Examples
```julia-repl
julia> Vector{Float64}(3)
julia> Vector{Float64}(uninitialized, 3)
3-element Array{Float64,1}:
6.90966e-310
6.90966e-310
6.90966e-310
```
"""
Vector{T}(n)
Vector{T}(uninitialized, n)

"""
Matrix{T}(m, n)
Matrix{T}(uninitialized, m, n)
Construct an uninitialized [`Matrix{T}`](@ref) of size `m`×`n`.
# Examples
```julia-repl
julia> Matrix{Float64}(2, 3)
julia> Matrix{Float64}(uninitialized, 2, 3)
2×3 Array{Float64,2}:
6.93517e-310 6.93517e-310 6.93517e-310
6.93517e-310 6.93517e-310 1.29396e-320
```
"""
Matrix{T}(m, n)
Matrix{T}(uninitialized, m, n)

"""
Array{T}(dims)
Array{T,N}(dims)
Array{T}(uninitialized, dims)
Array{T,N}(uninitialized, dims)
Construct an uninitialized `N`-dimensional [`Array`](@ref)
containing elements of type `T`. `N` can either be supplied explicitly,
as in `Array{T,N}(dims)`, or be determined by the length or number of `dims`.
as in `Array{T,N}(uninitialized, dims)`, or be determined by the length or number of `dims`.
`dims` may be a tuple or a series of integer arguments corresponding to the lengths
in each dimension. If the rank `N` is supplied explicitly, then it must
match the length or number of `dims`.
# Examples
```julia-repl
julia> A = Array{Float64,2}(2, 3) # N given explicitly
julia> A = Array{Float64,2}(uninitialized, 2, 3) # N given explicitly
2×3 Array{Float64,2}:
6.90198e-310 6.90198e-310 6.90198e-310
6.90198e-310 6.90198e-310 0.0
julia> B = Array{Float64}(2) # N determined by the input
julia> B = Array{Float64}(uninitialized, 2) # N determined by the input
2-element Array{Float64,1}:
1.87103e-320
0.0
```
"""
Array{T,N}(dims)
Array{T,N}(uninitialized, dims)

"""
Uninitialized
Expand Down
2 changes: 1 addition & 1 deletion base/docs/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ..esc, ..push!, ..getindex, ..unsafe_load, ..Csize_t
function doc!(source::LineNumberNode, mod::Module, str, ex)
push!(DOCS, (mod, ex, str, source.file, source.line))
end
const DOCS = Array{Any, 1}()
const DOCS = Array{Any,1}()

isexpr(x, h) = isa(x, Expr) && x.head === h

Expand Down
2 changes: 1 addition & 1 deletion base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function levenshtein(s1, s2)
a, b = collect(s1), collect(s2)
m = length(a)
n = length(b)
d = Matrix{Int}(m+1, n+1)
d = Matrix{Int}(uninitialized, m+1, n+1)

d[1:m+1, 1] = 0:m
d[1, 1:n+1] = 0:n
Expand Down

0 comments on commit 4e76658

Please sign in to comment.