Skip to content

Commit

Permalink
Replace Array{...}(shape...)-like calls in base/[b-d]* (less base/doc…
Browse files Browse the repository at this point in the history
…s/basedocs.jl and base/distributed/*). (#24756)
  • Loading branch information
Sacha0 authored and fredrikekre committed Nov 26, 2017
1 parent e64ad77 commit 3c1e9d0
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 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
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, Int(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
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 3c1e9d0

Please sign in to comment.