Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ Language changes
* `global const` declarations may no longer appear inside functions ([#12010]).

* Uninitialized `BitArray` constructors of the form `BitArray[{N}](shape...)` have been
deprecated in favor of equivalents accepting `uninitialized` (an alias for
`Uninitialized()`) as their first argument, as in
`BitArray[{N}](uninitialized, shape...)`. For example, `BitVector(3)` is now
`BitVector(uninitialized, 3)`, `BitMatrix((2, 4))` is now
`BitMatrix(uninitialized, (2, 4))`, and `BitArray{3}(11, 13, 17)` is now
`BitArray{3}(uninitialized, 11, 14, 17)` ([#24785]).
deprecated in favor of equivalents accepting `undef` (an alias for
`UndefInitializer()`) as their first argument, as in
`BitArray[{N}](undef, shape...)`. For example, `BitVector(3)` is now
`BitVector(undef, 3)`, `BitMatrix((2, 4))` is now
`BitMatrix(undef, (2, 4))`, and `BitArray{3}(11, 13, 17)` is now
`BitArray{3}(undef, 11, 14, 17)` ([#24785]).

* Dispatch rules have been simplified:
method matching is now determined exclusively by subtyping;
Expand Down Expand Up @@ -662,11 +662,11 @@ Deprecated or removed

* Uninitialized `Array` constructors of the form
`Array[{T,N}](shape...)` have been deprecated in favor of equivalents
accepting `uninitialized` (an alias for `Uninitialized()`) as their first argument,
as in `Array[{T,N}](uninitialized, shape...)`. For example,
`Vector(3)` is now `Vector(uninitialized, 3)`, `Matrix{Int}((2, 4))` is now,
`Matrix{Int}(uninitialized, (2, 4))`, and `Array{Float32,3}(11, 13, 17)` is now
`Array{Float32,3}(uninitialized, 11, 13, 17)` ([#24781]).
accepting `uninit` (an alias for `UndefInitializer()`) as their first argument,
as in `Array[{T,N}](undef, shape...)`. For example,
`Vector(3)` is now `Vector(undef, 3)`, `Matrix{Int}((2, 4))` is now,
`Matrix{Int}(undef, (2, 4))`, and `Array{Float32,3}(11, 13, 17)` is now
`Array{Float32,3}(undef, 11, 13, 17)` ([#24781]).

* `LinAlg.fillslots!` has been renamed `LinAlg.fillstored!` ([#25030]).

Expand All @@ -692,11 +692,11 @@ Deprecated or removed
output ([#12131]).

* Uninitialized `RowVector` constructors of the form `RowVector{T}(shape...)` have been
deprecated in favor of equivalents accepting `uninitialized` (an alias for
`Uninitialized()`) as their first argument, as in
`RowVector{T}(uninitialized, shape...)`. For example, `RowVector{Int}(3)` is now
`RowVector{Int}(uninitialized, 3)`, and `RowVector{Float32}((1, 4))` is now
`RowVector{Float32}(uninitialized, (1, 4))` ([#24786]).
deprecated in favor of equivalents accepting `uninit` (an alias for
`UndefInitializer()`) as their first argument, as in
`RowVector{T}(undef, shape...)`. For example, `RowVector{Int}(3)` is now
`RowVector{Int}(undef, 3)`, and `RowVector{Float32}((1, 4))` is now
`RowVector{Float32}(undef, (1, 4))` ([#24786]).

* `writecsv(io, a; opts...)` has been deprecated in favor of
`writedlm(io, a, ','; opts...)` ([#23529]).
Expand Down Expand Up @@ -759,7 +759,7 @@ Deprecated or removed
in favor of `replace(s::AbstractString, pat => r; [count])` ([#25165]).
Moreover, `count` cannot be negative anymore (use `typemax(Int)` instead ([#22325]).

* `read(io, type, dims)` is deprecated to `read!(io, Array{type}(uninitialized, dims))` ([#21450]).
* `read(io, type, dims)` is deprecated to `read!(io, Array{type}(undef, dims))` ([#21450]).

* `read(::IO, ::Ref)` is now a method of `read!`, since it mutates its `Ref` argument ([#21592]).

Expand Down
24 changes: 12 additions & 12 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ argument or as a series of integer arguments.

Custom AbstractArray subtypes may choose which specific array type is best-suited to return
for the given element type and dimensionality. If they do not specialize this method, the
default is an `Array{element_type}(uninitialized, dims...)`.
default is an `Array{element_type}(undef, dims...)`.

For example, `similar(1:10, 1, 4)` returns an uninitialized `Array{Int,2}` since ranges are
neither mutable nor support 2 dimensions:
Expand Down Expand Up @@ -558,7 +558,7 @@ similar(a::AbstractArray{T}, dims::DimOrInd...) where {T} = similar(a,
similar(a::AbstractArray, ::Type{T}, dims::DimOrInd...) where {T} = similar(a, T, to_shape(dims))
similar(a::AbstractArray, ::Type{T}, dims::NeedsShaping) where {T} = similar(a, T, to_shape(dims))
# similar creates an Array by default
similar(a::AbstractArray, ::Type{T}, dims::Dims{N}) where {T,N} = Array{T,N}(uninitialized, dims)
similar(a::AbstractArray, ::Type{T}, dims::Dims{N}) where {T,N} = Array{T,N}(undef, dims)

to_shape(::Tuple{}) = ()
to_shape(dims::Dims) = dims
Expand All @@ -583,7 +583,7 @@ argument. `storagetype` might be a type or a function.
creates an array that "acts like" an `Array{Int}` (and might indeed be
backed by one), but which is indexed identically to `A`. If `A` has
conventional indexing, this will be identical to
`Array{Int}(uninitialized, size(A))`, but if `A` has unconventional indexing then the
`Array{Int}(undef, size(A))`, but if `A` has unconventional indexing then the
indices of the result will match `A`.

similar(BitArray, (axes(A, 2),))
Expand Down Expand Up @@ -1233,10 +1233,10 @@ vcat(X::T...) where {T<:Number} = T[ X[i] for i=1:length(X) ]
hcat(X::T...) where {T} = T[ X[j] for i=1:1, j=1:length(X) ]
hcat(X::T...) where {T<:Number} = T[ X[j] for i=1:1, j=1:length(X) ]

vcat(X::Number...) = hvcat_fill(Vector{promote_typeof(X...)}(uninitialized, length(X)), X)
hcat(X::Number...) = hvcat_fill(Matrix{promote_typeof(X...)}(uninitialized, 1,length(X)), X)
typed_vcat(::Type{T}, X::Number...) where {T} = hvcat_fill(Vector{T}(uninitialized, length(X)), X)
typed_hcat(::Type{T}, X::Number...) where {T} = hvcat_fill(Matrix{T}(uninitialized, 1,length(X)), X)
vcat(X::Number...) = hvcat_fill(Vector{promote_typeof(X...)}(undef, length(X)), X)
hcat(X::Number...) = hvcat_fill(Matrix{promote_typeof(X...)}(undef, 1,length(X)), X)
typed_vcat(::Type{T}, X::Number...) where {T} = hvcat_fill(Vector{T}(undef, length(X)), X)
typed_hcat(::Type{T}, X::Number...) where {T} = hvcat_fill(Matrix{T}(undef, 1,length(X)), X)

vcat(V::AbstractVector...) = typed_vcat(promote_eltype(V...), V...)
vcat(V::AbstractVector{T}...) where {T} = typed_vcat(T, V...)
Expand Down Expand Up @@ -1328,7 +1328,7 @@ cat_size(A::AbstractArray, d) = size(A, d)
cat_indices(A, d) = OneTo(1)
cat_indices(A::AbstractArray, d) = axes(A, d)

cat_similar(A, T, shape) = Array{T}(uninitialized, shape)
cat_similar(A, T, shape) = Array{T}(undef, shape)
cat_similar(A::AbstractArray, T, shape) = similar(A, T, shape)

cat_shape(dims, shape::Tuple) = shape
Expand Down Expand Up @@ -1377,7 +1377,7 @@ end

function _cat(A, shape::NTuple{N}, catdims, X...) where N
offsets = zeros(Int, N)
inds = Vector{UnitRange{Int}}(uninitialized, N)
inds = Vector{UnitRange{Int}}(undef, N)
concat = copyto!(zeros(Bool, N), catdims)
for x in X
for i = 1:N
Expand Down Expand Up @@ -1607,7 +1607,7 @@ function hvcat(rows::Tuple{Vararg{Int}}, xs::T...) where T<:Number
nr = length(rows)
nc = rows[1]

a = Matrix{T}(uninitialized, nr, nc)
a = Matrix{T}(undef, nr, nc)
if length(a) != length(xs)
throw(ArgumentError("argument count does not match specified shape (expected $(length(a)), got $(length(xs)))"))
end
Expand Down Expand Up @@ -1651,12 +1651,12 @@ function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, xs::Number...) where T
if nr*nc != len
throw(ArgumentError("argument count $(len) does not match specified shape $((nr,nc))"))
end
hvcat_fill(Matrix{T}(uninitialized, nr, nc), xs)
hvcat_fill(Matrix{T}(undef, nr, nc), xs)
end

function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, as...) where T
nbr = length(rows) # number of block rows
rs = Vector{Any}(uninitialized, nbr)
rs = Vector{Any}(undef, nbr)
a = 1
for i = 1:nbr
rs[i] = typed_hcat(T, as[a:a-1+rows[i]]...)
Expand Down
2 changes: 1 addition & 1 deletion base/abstractdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ mutable struct IdDict{K,V} <: AbstractDict{K,V}
ht::Vector{Any}
count::Int
ndel::Int
IdDict{K,V}() where {K, V} = new{K,V}(Vector{Any}(uninitialized, 32), 0, 0)
IdDict{K,V}() where {K, V} = new{K,V}(Vector{Any}(undef, 32), 0, 0)

function IdDict{K,V}(itr) where {K, V}
d = IdDict{K,V}()
Expand Down
50 changes: 25 additions & 25 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function vect(X...)
T = promote_typeof(X...)
#T[ X[i] for i=1:length(X) ]
# TODO: this is currently much faster. should figure out why. not clear.
return copyto!(Vector{T}(uninitialized, length(X)), X)
return copyto!(Vector{T}(undef, length(X)), X)
end

size(a::Array, d) = arraysize(a, d)
Expand Down Expand Up @@ -259,14 +259,14 @@ end

## Constructors ##

similar(a::Array{T,1}) where {T} = Vector{T}(uninitialized, size(a,1))
similar(a::Array{T,2}) where {T} = Matrix{T}(uninitialized, size(a,1), size(a,2))
similar(a::Array{T,1}, S::Type) where {T} = Vector{S}(uninitialized, size(a,1))
similar(a::Array{T,2}, S::Type) where {T} = Matrix{S}(uninitialized, size(a,1), size(a,2))
similar(a::Array{T}, m::Int) where {T} = Vector{T}(uninitialized, m)
similar(a::Array, T::Type, dims::Dims{N}) where {N} = Array{T,N}(uninitialized, dims)
similar(a::Array{T}, dims::Dims{N}) where {T,N} = Array{T,N}(uninitialized, dims)
similar(::Type{T}, shape::Tuple) where {T<:Array} = T(uninitialized, to_shape(shape))
similar(a::Array{T,1}) where {T} = Vector{T}(undef, size(a,1))
similar(a::Array{T,2}) where {T} = Matrix{T}(undef, size(a,1), size(a,2))
similar(a::Array{T,1}, S::Type) where {T} = Vector{S}(undef, size(a,1))
similar(a::Array{T,2}, S::Type) where {T} = Matrix{S}(undef, size(a,1), size(a,2))
similar(a::Array{T}, m::Int) where {T} = Vector{T}(undef, m)
similar(a::Array, T::Type, dims::Dims{N}) where {N} = Array{T,N}(undef, dims)
similar(a::Array{T}, dims::Dims{N}) where {T,N} = Array{T,N}(undef, dims)
similar(::Type{T}, shape::Tuple) where {T<:Array} = T(undef, to_shape(shape))

# T[x...] constructs Array{T,1}
"""
Expand All @@ -291,20 +291,20 @@ julia> getindex(Int8, 1, 2, 3)
```
"""
function getindex(::Type{T}, vals...) where T
a = Vector{T}(uninitialized, length(vals))
a = Vector{T}(undef, length(vals))
@inbounds for i = 1:length(vals)
a[i] = vals[i]
end
return a
end

getindex(::Type{T}) where {T} = (@_inline_meta; Vector{T}())
getindex(::Type{T}, x) where {T} = (@_inline_meta; a = Vector{T}(uninitialized, 1); @inbounds a[1] = x; a)
getindex(::Type{T}, x, y) where {T} = (@_inline_meta; a = Vector{T}(uninitialized, 2); @inbounds (a[1] = x; a[2] = y); a)
getindex(::Type{T}, x, y, z) where {T} = (@_inline_meta; a = Vector{T}(uninitialized, 3); @inbounds (a[1] = x; a[2] = y; a[3] = z); a)
getindex(::Type{T}, x) where {T} = (@_inline_meta; a = Vector{T}(undef, 1); @inbounds a[1] = x; a)
getindex(::Type{T}, x, y) where {T} = (@_inline_meta; a = Vector{T}(undef, 2); @inbounds (a[1] = x; a[2] = y); a)
getindex(::Type{T}, x, y, z) where {T} = (@_inline_meta; a = Vector{T}(undef, 3); @inbounds (a[1] = x; a[2] = y; a[3] = z); a)

function getindex(::Type{Any}, @nospecialize vals...)
a = Vector{Any}(uninitialized, length(vals))
a = Vector{Any}(undef, length(vals))
@inbounds for i = 1:length(vals)
a[i] = vals[i]
end
Expand Down Expand Up @@ -345,8 +345,8 @@ julia> fill(1.0, (5,5))
If `x` is an object reference, all elements will refer to the same object. `fill(Foo(),
dims)` will return an array filled with the result of evaluating `Foo()` once.
"""
fill(v, dims::Dims) = fill!(Array{typeof(v)}(uninitialized, dims), v)
fill(v, dims::Integer...) = fill!(Array{typeof(v)}(uninitialized, dims...), v)
fill(v, dims::Dims) = fill!(Array{typeof(v)}(undef, dims), v)
fill(v, dims::Integer...) = fill!(Array{typeof(v)}(undef, dims...), v)

"""
zeros([T=Float64,] dims...)
Expand Down Expand Up @@ -390,7 +390,7 @@ function ones end

for (fname, felt) in ((:zeros, :zero), (:ones, :one))
@eval begin
$fname(::Type{T}, dims::NTuple{N, Any}) where {T, N} = fill!(Array{T,N}(uninitialized, convert(Dims, dims)::Dims), $felt(T))
$fname(::Type{T}, dims::NTuple{N, Any}) where {T, N} = fill!(Array{T,N}(undef, convert(Dims, dims)::Dims), $felt(T))
$fname(dims::Tuple) = ($fname)(Float64, dims)
$fname(::Type{T}, dims...) where {T} = $fname(T, dims)
$fname(dims...) = $fname(dims)
Expand Down Expand Up @@ -421,7 +421,7 @@ promote_rule(a::Type{Array{T,n}}, b::Type{Array{S,n}}) where {T,n,S} = el_same(p

if nameof(@__MODULE__) === :Base # avoid method overwrite
# constructors should make copies
Array{T,N}(x::AbstractArray{S,N}) where {T,N,S} = copyto!(Array{T,N}(uninitialized, size(x)), x)
Array{T,N}(x::AbstractArray{S,N}) where {T,N,S} = copyto!(Array{T,N}(undef, size(x)), x)
AbstractArray{T,N}(A::AbstractArray{S,N}) where {T,N,S} = copyto!(similar(A,T), A)
end

Expand All @@ -444,7 +444,7 @@ julia> collect(Float64, 1:2:5)
"""
collect(::Type{T}, itr) where {T} = _collect(T, itr, IteratorSize(itr))

_collect(::Type{T}, itr, isz::HasLength) where {T} = copyto!(Vector{T}(uninitialized, Int(length(itr)::Integer)), itr)
_collect(::Type{T}, itr, isz::HasLength) where {T} = copyto!(Vector{T}(undef, Int(length(itr)::Integer)), itr)
_collect(::Type{T}, itr, isz::HasShape) where {T} = copyto!(similar(Array{T}, axes(itr)), itr)
function _collect(::Type{T}, itr, isz::SizeUnknown) where T
a = Vector{T}()
Expand Down Expand Up @@ -498,11 +498,11 @@ function _collect(cont, itr, ::HasEltype, isz::SizeUnknown)
return a
end

_collect_indices(::Tuple{}, A) = copyto!(Array{eltype(A),0}(uninitialized), A)
_collect_indices(::Tuple{}, A) = copyto!(Array{eltype(A),0}(undef), A)
_collect_indices(indsA::Tuple{Vararg{OneTo}}, A) =
copyto!(Array{eltype(A)}(uninitialized, length.(indsA)), A)
copyto!(Array{eltype(A)}(undef, length.(indsA)), A)
function _collect_indices(indsA, A)
B = Array{eltype(A)}(uninitialized, length.(indsA))
B = Array{eltype(A)}(undef, length.(indsA))
copyto!(B, CartesianIndices(axes(B)), A, CartesianIndices(indsA))
end

Expand Down Expand Up @@ -534,7 +534,7 @@ else
end
end

_array_for(::Type{T}, itr, ::HasLength) where {T} = Vector{T}(uninitialized, Int(length(itr)::Integer))
_array_for(::Type{T}, itr, ::HasLength) where {T} = Vector{T}(undef, Int(length(itr)::Integer))
_array_for(::Type{T}, itr, ::HasShape) where {T} = similar(Array{T}, axes(itr))::Array{T}

function collect(itr::Generator)
Expand Down Expand Up @@ -1463,7 +1463,7 @@ function vcat(arrays::Vector{T}...) where T
for a in arrays
n += length(a)
end
arr = Vector{T}(uninitialized, n)
arr = Vector{T}(undef, n)
ptr = pointer(arr)
if isbits(T)
elsz = Core.sizeof(T)
Expand Down Expand Up @@ -1965,7 +1965,7 @@ end
# Allocating result upfront is faster (possible only when collection can be iterated twice)
function findall(A::AbstractArray{Bool})
n = count(A)
I = Vector{eltype(keys(A))}(uninitialized, n)
I = Vector{eltype(keys(A))}(undef, n)
cnt = 1
for (i,a) in pairs(A)
if a
Expand Down
2 changes: 1 addition & 1 deletion base/asyncmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ end

# Special handling for some types.
function asyncmap(f, s::AbstractString; kwargs...)
s2 = Vector{Char}(uninitialized, length(s))
s2 = Vector{Char}(undef, length(s))
asyncmap!(f, s2, s; kwargs...)
return String(s2)
end
Expand Down
Loading