diff --git a/NEWS.md b/NEWS.md index 6730fb3339c14..32033c1616553 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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; @@ -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]). @@ -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]). @@ -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]). diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 9bc9cd691cf1f..21be8b8670679 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -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: @@ -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 @@ -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),)) @@ -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...) @@ -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 @@ -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 @@ -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 @@ -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]]...) diff --git a/base/abstractdict.jl b/base/abstractdict.jl index d4233f95782d8..07ed4dd24fb0d 100644 --- a/base/abstractdict.jl +++ b/base/abstractdict.jl @@ -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}() diff --git a/base/array.jl b/base/array.jl index 0a7290db03990..c88510035927e 100644 --- a/base/array.jl +++ b/base/array.jl @@ -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) @@ -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} """ @@ -291,7 +291,7 @@ 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 @@ -299,12 +299,12 @@ function getindex(::Type{T}, vals...) where T 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 @@ -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...) @@ -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) @@ -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 @@ -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}() @@ -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 @@ -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) @@ -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) @@ -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 diff --git a/base/asyncmap.jl b/base/asyncmap.jl index 94098f4d06761..c8fec713bdb2f 100644 --- a/base/asyncmap.jl +++ b/base/asyncmap.jl @@ -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 diff --git a/base/bitarray.jl b/base/bitarray.jl index 2f9e48b945e9f..40902b1c0e10c 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -13,7 +13,7 @@ mutable struct BitArray{N} <: AbstractArray{Bool, N} chunks::Vector{UInt64} len::Int dims::NTuple{N,Int} - function BitArray{N}(::Uninitialized, dims::Vararg{Int,N}) where N + function BitArray{N}(::UndefInitializer, dims::Vararg{Int,N}) where N n = 1 i = 1 for d in dims @@ -22,7 +22,7 @@ mutable struct BitArray{N} <: AbstractArray{Bool, N} i += 1 end nc = num_bit_chunks(n) - chunks = Vector{UInt64}(uninitialized, nc) + chunks = Vector{UInt64}(undef, nc) nc > 0 && (chunks[end] = UInt64(0)) b = new(chunks, n) N != 1 && (b.dims = dims) @@ -34,35 +34,35 @@ end # the first one is recognized by the help system; it would be nice # to fix this. """ - BitArray(uninitialized, dims::Integer...) - BitArray{N}(uninitialized, dims::NTuple{N,Int}) + BitArray(undef, dims::Integer...) + BitArray{N}(undef, dims::NTuple{N,Int}) -Construct an uninitialized [`BitArray`](@ref) with the given dimensions. -Behaves identically to the [`Array`](@ref) constructor. See [`uninitialized`](@ref). +Construct an undef [`BitArray`](@ref) with the given dimensions. +Behaves identically to the [`Array`](@ref) constructor. See [`undef`](@ref). # Examples ```julia-repl -julia> BitArray(uninitialized, 2, 2) +julia> BitArray(undef, 2, 2) 2×2 BitArray{2}: false false false true -julia> BitArray(uninitialized, (3, 1)) +julia> BitArray(undef, (3, 1)) 3×1 BitArray{2}: false true false ``` """ -BitArray(::Uninitialized, dims::Integer...) = BitArray(uninitialized, map(Int,dims)) -BitArray{N}(::Uninitialized, dims::Integer...) where {N} = BitArray{N}(uninitialized, map(Int,dims)) -BitArray(::Uninitialized, dims::NTuple{N,Int}) where {N} = BitArray{N}(uninitialized, dims...) -BitArray{N}(::Uninitialized, dims::NTuple{N,Int}) where {N} = BitArray{N}(uninitialized, dims...) +BitArray(::UndefInitializer, dims::Integer...) = BitArray(undef, map(Int,dims)) +BitArray{N}(::UndefInitializer, dims::Integer...) where {N} = BitArray{N}(undef, map(Int,dims)) +BitArray(::UndefInitializer, dims::NTuple{N,Int}) where {N} = BitArray{N}(undef, dims...) +BitArray{N}(::UndefInitializer, dims::NTuple{N,Int}) where {N} = BitArray{N}(undef, dims...) const BitVector = BitArray{1} const BitMatrix = BitArray{2} -BitVector() = BitArray{1}(uninitialized, 0) +BitVector() = BitArray{1}(undef, 0) ## utility functions ## @@ -329,16 +329,16 @@ done(B::BitArray, i::Int) = i >= length(B) ## similar, fill!, copy! etc ## -similar(B::BitArray) = BitArray(uninitialized, size(B)) -similar(B::BitArray, dims::Int...) = BitArray(uninitialized, dims) -similar(B::BitArray, dims::Dims) = BitArray(uninitialized, dims...) +similar(B::BitArray) = BitArray(undef, size(B)) +similar(B::BitArray, dims::Int...) = BitArray(undef, dims) +similar(B::BitArray, dims::Dims) = BitArray(undef, dims...) -similar(B::BitArray, T::Type{Bool}, dims::Dims) = BitArray(uninitialized, dims) +similar(B::BitArray, T::Type{Bool}, dims::Dims) = BitArray(undef, 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}(uninitialized, dims) +similar(B::BitArray, T::Type, dims::Dims) = Array{T}(undef, dims) -similar(::Type{T}, shape::Tuple) where {T<:BitArray} = T(uninitialized, to_shape(shape)) +similar(::Type{T}, shape::Tuple) where {T<:BitArray} = T(undef, to_shape(shape)) function fill!(B::BitArray, x) y = convert(Bool, x) @@ -366,7 +366,7 @@ julia> falses(2,3) false false false ``` """ -falses(dims::Dims) = fill!(BitArray(uninitialized, dims), false) +falses(dims::Dims) = fill!(BitArray(undef, dims), false) falses(dims::Integer...) = falses(map(Int,dims)) """ @@ -382,7 +382,7 @@ julia> trues(2,3) true true true ``` """ -trues(dims::Dims) = fill!(BitArray(uninitialized, dims), true) +trues(dims::Dims) = fill!(BitArray(undef, dims), true) trues(dims::Integer...) = trues(map(Int,dims)) function one(x::BitMatrix) @@ -442,7 +442,7 @@ reshape(B::BitArray, dims::Tuple{Vararg{Int}}) = _bitreshape(B, dims) function _bitreshape(B::BitArray, dims::NTuple{N,Int}) where N prod(dims) == length(B) || throw(DimensionMismatch("new dimensions $(dims) must be consistent with array size $(length(B))")) - Br = BitArray{N}(uninitialized, ntuple(i->0,Val(N))...) + Br = BitArray{N}(undef, ntuple(i->0,Val(N))...) Br.chunks = B.chunks Br.len = prod(dims) N != 1 && (Br.dims = dims) @@ -452,7 +452,7 @@ end ## Constructors ## function Array{T,N}(B::BitArray{N}) where {T,N} - A = Array{T,N}(uninitialized, size(B)) + A = Array{T,N}(undef, size(B)) Bc = B.chunks @inbounds for i = 1:length(A) A[i] = unsafe_bitgetindex(Bc, i) @@ -462,7 +462,7 @@ end BitArray(A::AbstractArray{<:Any,N}) where {N} = BitArray{N}(A) function BitArray{N}(A::AbstractArray{T,N}) where N where T - B = BitArray(uninitialized, size(A)) + B = BitArray(undef, size(A)) Bc = B.chunks l = length(B) l == 0 && return B @@ -487,7 +487,7 @@ function BitArray{N}(A::AbstractArray{T,N}) where N where T end function BitArray{N}(A::Array{Bool,N}) where N - B = BitArray(uninitialized, size(A)) + B = BitArray(undef, size(A)) Bc = B.chunks l = length(B) l == 0 && return B @@ -540,7 +540,7 @@ gen_bitarray(isz::IteratorSize, itr) = gen_bitarray_from_itr(itr, start(itr)) # generic iterable with known shape function gen_bitarray(::HasShape, itr) - B = BitArray(uninitialized, size(itr)) + B = BitArray(undef, size(itr)) for (I,x) in zip(CartesianIndices(axes(itr)), itr) B[I] = x end @@ -549,11 +549,11 @@ end # generator with known shape or length function gen_bitarray(::HasShape, itr::Generator) - B = BitArray(uninitialized, size(itr)) + B = BitArray(undef, size(itr)) return fill_bitarray_from_itr!(B, itr, start(itr)) end function gen_bitarray(::HasLength, itr) - b = BitVector(uninitialized, length(itr)) + b = BitVector(undef, length(itr)) return fill_bitarray_from_itr!(b, itr, start(itr)) end @@ -563,8 +563,8 @@ gen_bitarray(::IsInfinite, itr) = throw(ArgumentError("infinite-size iterable u # use a Vector{Bool} cache for performance reasons function gen_bitarray_from_itr(itr, st) - B = empty!(BitVector(uninitialized, bitcache_size)) - C = Vector{Bool}(uninitialized, bitcache_size) + B = empty!(BitVector(undef, bitcache_size)) + C = Vector{Bool}(undef, bitcache_size) Bc = B.chunks ind = 1 cind = 1 @@ -589,7 +589,7 @@ end function fill_bitarray_from_itr!(B::BitArray, itr, st) n = length(B) - C = Vector{Bool}(uninitialized, bitcache_size) + C = Vector{Bool}(undef, bitcache_size) Bc = B.chunks ind = 1 cind = 1 @@ -1045,7 +1045,7 @@ function splice!(B::BitVector, r::Union{UnitRange{Int}, Integer}, ins::AbstractA end function splice!(B::BitVector, r::Union{UnitRange{Int}, Integer}, ins) - Bins = BitVector(uninitialized, length(ins)) + Bins = BitVector(undef, length(ins)) i = 1 for x in ins Bins[i] = Bool(x) @@ -1140,7 +1140,7 @@ end for f in (:+, :-) @eval function ($f)(A::BitArray, B::BitArray) - r = Array{Int}(uninitialized, promote_shape(size(A), size(B))) + r = Array{Int}(undef, promote_shape(size(A), size(B))) ai = start(A) bi = start(B) ri = 1 @@ -1172,7 +1172,7 @@ broadcast(::typeof(xor), x::Bool, B::BitArray) = broadcast(xor, B, x) for f in (:&, :|, :xor) @eval begin function broadcast(::typeof($f), A::BitArray, B::BitArray) - F = BitArray(uninitialized, promote_shape(size(A),size(B))...) + F = BitArray(undef, promote_shape(size(A),size(B))...) Fc = F.chunks Ac = A.chunks Bc = B.chunks @@ -1607,7 +1607,7 @@ function findall(B::BitArray) l = length(B) nnzB = count(B) ind = first(keys(B)) - I = Vector{typeof(ind)}(uninitialized, nnzB) + I = Vector{typeof(ind)}(undef, nnzB) nnzB == 0 && return I Bc = B.chunks Icount = 1 @@ -1741,7 +1741,7 @@ function hcat(B::BitVector...) length(B[j]) == height || throw(DimensionMismatch("dimensions must match")) end - M = BitMatrix(uninitialized, height, length(B)) + M = BitMatrix(undef, height, length(B)) for j = 1:length(B) copy_chunks!(M.chunks, (height*(j-1))+1, B[j].chunks, 1, height) end @@ -1753,7 +1753,7 @@ function vcat(V::BitVector...) for Vk in V n += length(Vk) end - B = BitVector(uninitialized, n) + B = BitVector(undef, n) j = 1 for Vk in V copy_chunks!(B.chunks, j, Vk.chunks, 1, length(Vk)) @@ -1775,7 +1775,7 @@ function hcat(A::Union{BitMatrix,BitVector}...) throw(DimensionMismatch("row lengths must match")) end - B = BitMatrix(uninitialized, nrows, ncols) + B = BitMatrix(undef, nrows, ncols) pos = 1 for k = 1:nargs @@ -1795,7 +1795,7 @@ function vcat(A::BitMatrix...) size(A[j], 2) == ncols || throw(DimensionMismatch("column lengths must match")) end - B = BitMatrix(uninitialized, nrows, ncols) + B = BitMatrix(undef, nrows, ncols) Bc = B.chunks nrowsA = [size(a, 1) for a in A] Ac = [a.chunks for a in A] diff --git a/base/boot.jl b/base/boot.jl index ce944ca9d97cf..91fa20d71d0b0 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -136,7 +136,7 @@ export AbstractArray, DenseArray, NamedTuple, # special objects Function, Method, - Module, Symbol, Task, Array, Uninitialized, uninitialized, WeakRef, VecElement, + Module, Symbol, Task, Array, UndefInitializer, undef, WeakRef, VecElement, # numeric types Number, Real, Integer, Bool, Ref, Ptr, AbstractFloat, Float16, Float32, Float64, @@ -374,29 +374,29 @@ const NTuple{N,T} = Tuple{Vararg{T,N}} ## primitive Array constructors -struct Uninitialized end -const uninitialized = Uninitialized() +struct UndefInitializer end +const undef = UndefInitializer() # type and dimensionality specified, accepting dims as series of Ints -Array{T,1}(::Uninitialized, m::Int) where {T} = +Array{T,1}(::UndefInitializer, m::Int) where {T} = ccall(:jl_alloc_array_1d, Array{T,1}, (Any, Int), Array{T,1}, m) -Array{T,2}(::Uninitialized, m::Int, n::Int) where {T} = +Array{T,2}(::UndefInitializer, m::Int, n::Int) where {T} = ccall(:jl_alloc_array_2d, Array{T,2}, (Any, Int, Int), Array{T,2}, m, n) -Array{T,3}(::Uninitialized, m::Int, n::Int, o::Int) where {T} = +Array{T,3}(::UndefInitializer, m::Int, n::Int, o::Int) where {T} = ccall(:jl_alloc_array_3d, Array{T,3}, (Any, Int, Int, Int), Array{T,3}, m, n, o) -Array{T,N}(::Uninitialized, d::Vararg{Int,N}) where {T,N} = +Array{T,N}(::UndefInitializer, d::Vararg{Int,N}) where {T,N} = ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d) # type and dimensionality specified, accepting dims as tuples of Ints -Array{T,1}(::Uninitialized, d::NTuple{1,Int}) where {T} = Array{T,1}(uninitialized, getfield(d,1)) -Array{T,2}(::Uninitialized, d::NTuple{2,Int}) where {T} = Array{T,2}(uninitialized, getfield(d,1), getfield(d,2)) -Array{T,3}(::Uninitialized, d::NTuple{3,Int}) where {T} = Array{T,3}(uninitialized, getfield(d,1), getfield(d,2), getfield(d,3)) -Array{T,N}(::Uninitialized, d::NTuple{N,Int}) where {T,N} = ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d) +Array{T,1}(::UndefInitializer, d::NTuple{1,Int}) where {T} = Array{T,1}(undef, getfield(d,1)) +Array{T,2}(::UndefInitializer, d::NTuple{2,Int}) where {T} = Array{T,2}(undef, getfield(d,1), getfield(d,2)) +Array{T,3}(::UndefInitializer, d::NTuple{3,Int}) where {T} = Array{T,3}(undef, getfield(d,1), getfield(d,2), getfield(d,3)) +Array{T,N}(::UndefInitializer, d::NTuple{N,Int}) where {T,N} = ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d) # type but not dimensionality specified -Array{T}(::Uninitialized, m::Int) where {T} = Array{T,1}(uninitialized, m) -Array{T}(::Uninitialized, m::Int, n::Int) where {T} = Array{T,2}(uninitialized, m, n) -Array{T}(::Uninitialized, m::Int, n::Int, o::Int) where {T} = Array{T,3}(uninitialized, m, n, o) -Array{T}(::Uninitialized, d::NTuple{N,Int}) where {T,N} = Array{T,N}(uninitialized, d) +Array{T}(::UndefInitializer, m::Int) where {T} = Array{T,1}(undef, m) +Array{T}(::UndefInitializer, m::Int, n::Int) where {T} = Array{T,2}(undef, m, n) +Array{T}(::UndefInitializer, m::Int, n::Int, o::Int) where {T} = Array{T,3}(undef, m, n, o) +Array{T}(::UndefInitializer, d::NTuple{N,Int}) where {T,N} = Array{T,N}(undef, d) # empty vector constructor -Array{T,1}() where {T} = Array{T,1}(uninitialized, 0) +Array{T,1}() where {T} = Array{T,1}(undef, 0) (::Type{Array{T,N} where T})(x::AbstractArray{S,N}) where {S,N} = Array{S,N}(x) @@ -519,7 +519,7 @@ end function NamedTuple{names,T}(args::T) where {names, T <: Tuple} if @generated N = nfields(names) - flds = Array{Any,1}(uninitialized, N) + flds = Array{Any,1}(undef, N) i = 1 while sle_int(i, N) arrayset(false, flds, :(getfield(args, $i)), i) @@ -529,7 +529,7 @@ function NamedTuple{names,T}(args::T) where {names, T <: Tuple} else N = nfields(names) NT = NamedTuple{names,T} - flds = Array{Any,1}(uninitialized, N) + flds = Array{Any,1}(undef, N) i = 1 while sle_int(i, N) arrayset(false, flds, getfield(args, i), i) diff --git a/base/broadcast.jl b/base/broadcast.jl index f3210fca4ae8d..3a505bf8b796c 100644 --- a/base/broadcast.jl +++ b/base/broadcast.jl @@ -406,7 +406,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}(uninitialized, bitcache_size) + C = Vector{Bool}(undef, bitcache_size) Bc = B.chunks ind = 1 cind = 1 diff --git a/base/combinatorics.jl b/base/combinatorics.jl index f08465be40e62..6a9d813b79bdd 100644 --- a/base/combinatorics.jl +++ b/base/combinatorics.jl @@ -2,13 +2,13 @@ # Factorials -const _fact_table64 = Vector{Int64}(uninitialized, 20) +const _fact_table64 = Vector{Int64}(undef, 20) _fact_table64[1] = 1 for n in 2:20 _fact_table64[n] = _fact_table64[n-1] * n end -const _fact_table128 = Vector{UInt128}(uninitialized, 34) +const _fact_table128 = Vector{UInt128}(undef, 34) _fact_table128[1] = 1 for n in 2:34 _fact_table128[n] = _fact_table128[n-1] * n diff --git a/base/compiler/inferenceresult.jl b/base/compiler/inferenceresult.jl index c7674c7948061..42146695197d3 100644 --- a/base/compiler/inferenceresult.jl +++ b/base/compiler/inferenceresult.jl @@ -23,7 +23,7 @@ function get_argtypes(result::InferenceResult) toplevel = !isa(linfo.def, Method) atypes::SimpleVector = unwrap_unionall(linfo.specTypes).parameters nargs::Int = toplevel ? 0 : linfo.def.nargs - args = Vector{Any}(uninitialized, nargs) + args = Vector{Any}(undef, nargs) if !toplevel && linfo.def.isva if linfo.specTypes == Tuple if nargs > 1 diff --git a/base/compiler/inferencestate.jl b/base/compiler/inferencestate.jl index 4ecdce5d08fcd..70c4ee0214c3c 100644 --- a/base/compiler/inferencestate.jl +++ b/base/compiler/inferencestate.jl @@ -78,8 +78,8 @@ mutable struct InferenceState argtypes = get_argtypes(result) vararg_type_container = nothing nargs = length(argtypes) - s_argtypes = VarTable(uninitialized, nslots) - src.slottypes = Vector{Any}(uninitialized, nslots) + s_argtypes = VarTable(undef, nslots) + src.slottypes = Vector{Any}(undef, nslots) for i in 1:nslots at = (i > nargs) ? Bottom : argtypes[i] if !toplevel && linfo.def.isva && i == nargs diff --git a/base/compiler/optimize.jl b/base/compiler/optimize.jl index baaf46cb146d1..8138f36d6cf71 100644 --- a/base/compiler/optimize.jl +++ b/base/compiler/optimize.jl @@ -230,7 +230,7 @@ const TOP_TUPLE = GlobalRef(Core, :tuple) const META_POP_LOC = Expr(:meta, :pop_loc) -const ENABLE_VERIFY_VALUEINFO = (tmp = Array{Bool,0}(uninitialized); tmp[] = false; tmp) +const ENABLE_VERIFY_VALUEINFO = (tmp = Array{Bool,0}(undef); tmp[] = false; tmp) # allocation optimization, must not be mutated. const EMPTY_USES = ValueUse[] @@ -753,7 +753,7 @@ function substitute!( return NewvarNode(substitute!(e.slot, na, argexprs, spsig, spvals, offset, boundscheck)) end if isa(e, PhiNode) - values = Vector{Any}(uninitialized, length(e.values)) + values = Vector{Any}(undef, length(e.values)) for i = 1:length(values) isassigned(e.values, i) || continue values[i] = substitute!(e.values[i], na, argexprs, spsig, @@ -1766,7 +1766,7 @@ function ssavalue_increment(body::Expr, incr) end ssavalue_increment(body::PiNode, incr) = PiNode(ssavalue_increment(body.val, incr), body.typ) function ssavalue_increment(body::PhiNode, incr) - values = Vector{Any}(uninitialized, length(body.values)) + values = Vector{Any}(undef, length(body.values)) for i = 1:length(values) isassigned(body.values, i) || continue values[i] = ssavalue_increment(body.values[i], incr) @@ -1925,7 +1925,7 @@ function inline_call(e::Expr, sv::OptimizationState, stmts::Vector{Any}, boundsc end =# for ninline = 1:100 - ata = Vector{Any}(uninitialized, length(e.args)) + ata = Vector{Any}(undef, length(e.args)) ata[1] = ft for i = 2:length(e.args) a = exprtype(e.args[i], sv.src, sv.mod) @@ -1954,7 +1954,7 @@ function inline_call(e::Expr, sv::OptimizationState, stmts::Vector{Any}, boundsc if f === _apply na = length(e.args) - newargs = Vector{Any}(uninitialized, na-2) + newargs = Vector{Any}(undef, na-2) newstmts = Any[] effect_free_upto = 0 for i = 3:na @@ -2857,7 +2857,7 @@ function split_disjoint_assign!(ctx::AllocOptContext, info, key) isdispatchelem(widenconst(ctx.sv.src.slottypes[key.first])) && return false # no splitting can be necessary alltypes = IdDict() ndefs = length(info.defs) - deftypes = Vector{Any}(uninitialized, ndefs) + deftypes = Vector{Any}(undef, ndefs) for i in 1:ndefs def = info.defs[i] defex = (def.assign::Expr).args[2] @@ -3040,9 +3040,9 @@ end function structinfo_constant(ctx::AllocOptContext, @nospecialize(v), vt::DataType) nf = fieldcount(vt) if vt <: Tuple - si = StructInfo(Vector{Any}(uninitialized, nf), Symbol[], vt, false, false) + si = StructInfo(Vector{Any}(undef, nf), Symbol[], vt, false, false) else - si = StructInfo(Vector{Any}(uninitialized, nf), collect(Symbol, fieldnames(vt)), + si = StructInfo(Vector{Any}(undef, nf), collect(Symbol, fieldnames(vt)), vt, false, false) end for i in 1:nf @@ -3059,7 +3059,7 @@ end structinfo_tuple(ex::Expr) = StructInfo(ex.args[2:end], Symbol[], Tuple, false, false) function structinfo_new(ctx::AllocOptContext, ex::Expr, vt::DataType) nf = fieldcount(vt) - si = StructInfo(Vector{Any}(uninitialized, nf), collect(Symbol, fieldnames(vt)), + si = StructInfo(Vector{Any}(undef, nf), collect(Symbol, fieldnames(vt)), vt, vt.mutable, true) ninit = length(ex.args) - 1 for i in 1:nf @@ -3556,9 +3556,9 @@ function split_struct_alloc_single!(ctx::AllocOptContext, info, key, nf, has_pre def = info.defs[1] si = ctx.structinfos[1] if !isempty(ctx.undef_fld) && has_setfield_undef - flag_vars = Vector{SlotNumber}(uninitialized, nf) + flag_vars = Vector{SlotNumber}(undef, nf) end - vars = Vector{Any}(uninitialized, nf) + vars = Vector{Any}(undef, nf) is_ssa = !var_has_static_undef(ctx.sv.src, key.first, key.second) def_exprs = Any[] if has_preserve diff --git a/base/compiler/ssair/ir.jl b/base/compiler/ssair/ir.jl index f8b20c0cc6c68..4f23270841a35 100644 --- a/base/compiler/ssair/ir.jl +++ b/base/compiler/ssair/ir.jl @@ -308,7 +308,7 @@ end # For bootstrapping function my_sortperm(v) - p = Vector{Int}(uninitialized, length(v)) + p = Vector{Int}(undef, length(v)) for i = 1:length(v) p[i] = i end @@ -332,9 +332,9 @@ mutable struct IncrementalCompact function IncrementalCompact(code::IRCode) perm = my_sortperm(Int[code.new_nodes[i][1] for i in 1:length(code.new_nodes)]) new_len = length(code.stmts) + length(code.new_nodes) - result = Array{Any}(uninitialized, new_len) - result_types = Array{Any}(uninitialized, new_len) - result_lines = Array{Int}(uninitialized, new_len) + result = Array{Any}(undef, new_len) + result_types = Array{Any}(undef, new_len) + result_lines = Array{Int}(undef, new_len) ssa_rename = Any[SSAValue(i) for i = 1:new_len] used_ssas = fill(0, new_len) late_fixup = Vector{Int}() @@ -420,7 +420,7 @@ function process_node!(result::Vector{Any}, result_idx::Int, ssa_rename::Vector{ result[result_idx] = renumber_ssa!(stmt, ssa_rename, true, used_ssas) result_idx += 1 elseif isa(stmt, PhiNode) - values = Vector{Any}(uninitialized, length(stmt.values)) + values = Vector{Any}(undef, length(stmt.values)) for i = 1:length(stmt.values) isassigned(stmt.values, i) || continue val = stmt.values[i] @@ -519,7 +519,7 @@ end function finish(compact::IncrementalCompact) for idx in compact.late_fixup stmt = compact.result[idx]::PhiNode - values = Vector{Any}(uninitialized, length(stmt.values)) + values = Vector{Any}(undef, length(stmt.values)) for i = 1:length(stmt.values) isassigned(stmt.values, i) || continue val = stmt.values[i] diff --git a/base/compiler/ssair/passes.jl b/base/compiler/ssair/passes.jl index 5e7f81b5b1b85..685b21582e71e 100644 --- a/base/compiler/ssair/passes.jl +++ b/base/compiler/ssair/passes.jl @@ -34,7 +34,7 @@ function type_lift_pass!(ir::IRCode) item, which, use = pop!(worklist) def = ir.stmts[item] edges = copy(def.edges) - values = Vector{Any}(uninitialized, length(edges)) + values = Vector{Any}(undef, length(edges)) new_phi = length(values) == 0 ? false : insert_node!(ir, item, Bool, PhiNode(edges, values)) processed[item] = new_phi if first diff --git a/base/compiler/ssair/slot2ssa.jl b/base/compiler/ssair/slot2ssa.jl index 478c87380c3aa..7af2e66752f95 100644 --- a/base/compiler/ssair/slot2ssa.jl +++ b/base/compiler/ssair/slot2ssa.jl @@ -350,12 +350,12 @@ function domsort_ssa!(ir, domtree) end end bb_rename = IdDict{Int,Int}(i=>x for (x, i) in pairs(result_order) if i !== 0) - new_bbs = Vector{BasicBlock}(uninitialized, length(result_order)) + new_bbs = Vector{BasicBlock}(undef, length(result_order)) nstmts = sum(length(ir.cfg.blocks[i].stmts) for i in result_order if i !== 0) - result_stmts = Vector{Any}(uninitialized, nstmts+ncritbreaks+nnewfallthroughs) + result_stmts = Vector{Any}(undef, nstmts+ncritbreaks+nnewfallthroughs) result_types = Any[Any for i = 1:length(result_stmts)] result_ltable = Int[0 for i = 1:length(result_stmts)] - inst_rename = Vector{Any}(uninitialized, length(ir.stmts)) + inst_rename = Vector{Any}(undef, length(ir.stmts)) for i = 1:length(ir.new_nodes) push!(inst_rename, SSAValue(nstmts + i + ncritbreaks + nnewfallthroughs)) end diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index 658323b444992..cf024f2161536 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -11,8 +11,8 @@ const _NAMEDTUPLE_NAME = NamedTuple.body.body.name const INT_INF = typemax(Int) # integer infinity const N_IFUNC = reinterpret(Int32, arraylen) + 1 -const T_IFUNC = Vector{Tuple{Int, Int, Any}}(uninitialized, N_IFUNC) -const T_IFUNC_COST = Vector{Int}(uninitialized, N_IFUNC) +const T_IFUNC = Vector{Tuple{Int, Int, Any}}(undef, N_IFUNC) +const T_IFUNC_COST = Vector{Int}(undef, N_IFUNC) const T_FFUNC_KEY = Vector{Any}() const T_FFUNC_VAL = Vector{Tuple{Int, Int, Any}}() const T_FFUNC_COST = Vector{Int}() diff --git a/base/deprecated.jl b/base/deprecated.jl index 0418c5a33e7ee..ba651f1d446b0 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -333,9 +333,9 @@ end @deprecate read(s::IO, x::Ref) read!(s, x) -@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)) +@deprecate read(s::IO, t::Type, d1::Int, dims::Int...) read!(s, Array{t}(undef, tuple(d1,dims...))) +@deprecate read(s::IO, t::Type, d1::Integer, dims::Integer...) read!(s, Array{t}(undef, convert(Tuple{Vararg{Int}},tuple(d1,dims...)))) +@deprecate read(s::IO, t::Type, dims::Dims) read!(s, Array{t}(undef, dims)) function CartesianIndices(start::CartesianIndex{N}, stop::CartesianIndex{N}) where N inds = map((f,l)->f:l, start.I, stop.I) @@ -687,10 +687,10 @@ end # After deprecation is removed, enable the @testset "indexing by Bool values" in test/arrayops.jl # Also un-comment the new definition in base/indices.jl -# deprecate BitArray{...}(shape...) constructors to BitArray{...}(uninitialized, shape...) equivalents -@deprecate BitArray{N}(dims::Vararg{Int,N}) where {N} BitArray{N}(uninitialized, dims) -@deprecate BitArray(dims::NTuple{N,Int}) where {N} BitArray(uninitialized, dims...) -@deprecate BitArray(dims::Integer...) BitArray(uninitialized, dims) +# deprecate BitArray{...}(shape...) constructors to BitArray{...}(undef, shape...) equivalents +@deprecate BitArray{N}(dims::Vararg{Int,N}) where {N} BitArray{N}(undef, dims) +@deprecate BitArray(dims::NTuple{N,Int}) where {N} BitArray(undef, dims...) +@deprecate BitArray(dims::Integer...) BitArray(undef, dims) ## deprecate full export full @@ -729,26 +729,26 @@ findprev(pred::Function, A, i::Integer) = invoke(findprev, Tuple{Function, Any, # issue #24006 @deprecate linearindices(s::AbstractString) eachindex(s) -# deprecate Array(shape...)-like constructors to Array(uninitialized, shape...) equivalents +# deprecate Array(shape...)-like constructors to Array(undef, shape...) equivalents # --> former primitive constructors -@deprecate Array{T,1}(m::Int) where {T} Array{T,1}(uninitialized, m) -@deprecate Array{T,2}(m::Int, n::Int) where {T} Array{T,2}(uninitialized, m, n) -@deprecate Array{T,3}(m::Int, n::Int, o::Int) where {T} Array{T,3}(uninitialized, m, n, o) -@deprecate Array{T,N}(d::Vararg{Int,N}) where {T,N} Array{T,N}(uninitialized, d) -@deprecate Array{T,N}(d::NTuple{N,Int}) where {T,N} Array{T,N}(uninitialized, d) -@deprecate Array{T}(m::Int) where {T} Array{T}(uninitialized, m) -@deprecate Array{T}(m::Int, n::Int) where {T} Array{T}(uninitialized, m, n) -@deprecate Array{T}(m::Int, n::Int, o::Int) where {T} Array{T}(uninitialized, m, n, o) -@deprecate Array{T}(d::NTuple{N,Int}) where {T,N} Array{T}(uninitialized, d) +@deprecate Array{T,1}(m::Int) where {T} Array{T,1}(undef, m) +@deprecate Array{T,2}(m::Int, n::Int) where {T} Array{T,2}(undef, m, n) +@deprecate Array{T,3}(m::Int, n::Int, o::Int) where {T} Array{T,3}(undef, m, n, o) +@deprecate Array{T,N}(d::Vararg{Int,N}) where {T,N} Array{T,N}(undef, d) +@deprecate Array{T,N}(d::NTuple{N,Int}) where {T,N} Array{T,N}(undef, d) +@deprecate Array{T}(m::Int) where {T} Array{T}(undef, m) +@deprecate Array{T}(m::Int, n::Int) where {T} Array{T}(undef, m, n) +@deprecate Array{T}(m::Int, n::Int, o::Int) where {T} Array{T}(undef, m, n, o) +@deprecate Array{T}(d::NTuple{N,Int}) where {T,N} Array{T}(undef, d) # --> former convenience constructors -@deprecate Vector{T}(m::Integer) where {T} Vector{T}(uninitialized, m) -@deprecate Matrix{T}(m::Integer, n::Integer) where {T} Matrix{T}(uninitialized, m, n) -@deprecate Array{T}(m::Integer) where {T} Array{T}(uninitialized, m) -@deprecate Array{T}(m::Integer, n::Integer) where {T} Array{T}(uninitialized, m, n) -@deprecate Array{T}(m::Integer, n::Integer, o::Integer) where {T} Array{T}(uninitialized, m, n, o) -@deprecate Array{T}(d::Integer...) where {T} Array{T}(uninitialized, d) -@deprecate Vector(m::Integer) Vector(uninitialized, m) -@deprecate Matrix(m::Integer, n::Integer) Matrix(uninitialized, m, n) +@deprecate Vector{T}(m::Integer) where {T} Vector{T}(undef, m) +@deprecate Matrix{T}(m::Integer, n::Integer) where {T} Matrix{T}(undef, m, n) +@deprecate Array{T}(m::Integer) where {T} Array{T}(undef, m) +@deprecate Array{T}(m::Integer, n::Integer) where {T} Array{T}(undef, m, n) +@deprecate Array{T}(m::Integer, n::Integer, o::Integer) where {T} Array{T}(undef, m, n, o) +@deprecate Array{T}(d::Integer...) where {T} Array{T}(undef, d) +@deprecate Vector(m::Integer) Vector(undef, m) +@deprecate Matrix(m::Integer, n::Integer) Matrix(undef, m, n) # deprecate IntSet to BitSet @deprecate_binding IntSet BitSet @@ -1496,6 +1496,10 @@ end # Issue #26248 @deprecate conj(x) x +# rename uninitialized +@deprecate_binding uninitialized undef +@deprecate_binding Uninitialized UndefInitializer + @deprecate showcompact(x) show(IOContext(stdout, :compact => true), x) @deprecate showcompact(io, x) show(IOContext(io, :compact => true), x) @deprecate sprint(::typeof(showcompact), args...) sprint(show, args...; context=:compact => true) diff --git a/base/dict.jl b/base/dict.jl index eacbbb2b0bf44..b2fd889adea0e 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -95,7 +95,7 @@ mutable struct Dict{K,V} <: AbstractDict{K,V} function Dict{K,V}() where V where K n = 16 - new(zeros(UInt8,n), Vector{K}(uninitialized, n), Vector{V}(uninitialized, n), 0, 0, 0, 1, 0) + new(zeros(UInt8,n), Vector{K}(undef, n), Vector{V}(undef, 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, @@ -191,8 +191,8 @@ function rehash!(h::Dict{K,V}, newsz = length(h.keys)) where V where K end slots = zeros(UInt8,newsz) - keys = Vector{K}(uninitialized, newsz) - vals = Vector{V}(uninitialized, newsz) + keys = Vector{K}(undef, newsz) + vals = Vector{V}(undef, newsz) age0 = h.age count = 0 maxprobe = h.maxprobe diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index 454d8fd3dbf34..3efab017ff33c 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -1310,20 +1310,20 @@ isdefined """ - Vector{T}(uninitialized, n) + Vector{T}(undef, n) -Construct an uninitialized [`Vector{T}`](@ref) of length `n`. See [`uninitialized`](@ref). +Construct an uninitialized [`Vector{T}`](@ref) of length `n`. See [`undef`](@ref). # Examples ```julia-repl -julia> Vector{Float64}(uninitialized, 3) +julia> Vector{Float64}(undef, 3) 3-element Array{Float64,1}: 6.90966e-310 6.90966e-310 6.90966e-310 ``` """ -Vector{T}(::Uninitialized, n) +Vector{T}(::UndefInitializer, n) """ Vector{T}(nothing, m) @@ -1360,19 +1360,19 @@ julia> Vector{Union{Missing, String}}(missing, 2) Vector{T}(::Missing, n) """ - Matrix{T}(uninitialized, m, n) + Matrix{T}(undef, m, n) -Construct an uninitialized [`Matrix{T}`](@ref) of size `m`×`n`. See [`uninitialized`](@ref). +Construct an uninitialized [`Matrix{T}`](@ref) of size `m`×`n`. See [`undef`](@ref). # Examples ```julia-repl -julia> Matrix{Float64}(uninitialized, 2, 3) +julia> Matrix{Float64}(undef, 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}(::Uninitialized, m, n) +Matrix{T}(::UndefInitializer, m, n) """ Matrix{T}(nothing, m, n) @@ -1409,30 +1409,30 @@ julia> Matrix{Union{Missing, String}}(missing, 2, 3) Matrix{T}(::Missing, m, n) """ - Array{T}(uninitialized, dims) - Array{T,N}(uninitialized, dims) + Array{T}(undef, dims) + Array{T,N}(undef, dims) Construct an uninitialized `N`-dimensional [`Array`](@ref) containing elements of type `T`. `N` can either be supplied explicitly, -as in `Array{T,N}(uninitialized, dims)`, or be determined by the length or number of `dims`. +as in `Array{T,N}(undef, 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`. See [`uninitialized`](@ref). +match the length or number of `dims`. See [`uninit`](@ref). # Examples ```julia-repl -julia> A = Array{Float64,2}(uninitialized, 2, 3) # N given explicitly +julia> A = Array{Float64,2}(undef, 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}(uninitialized, 2) # N determined by the input +julia> B = Array{Float64}(undef, 2) # N determined by the input 2-element Array{Float64,1}: 1.87103e-320 0.0 ``` """ -Array{T,N}(::Uninitialized, dims) +Array{T,N}(::UndefInitializer, dims) """ Array{T}(nothing, dims) @@ -1482,40 +1482,40 @@ julia> Array{Union{Missing, Int}}(missing, 2, 3) Array{T,N}(::Missing, dims) """ - Uninitialized + UndefInitializer Singleton type used in array initialization, indicating the array-constructor-caller -would like an uninitialized array. See also [`uninitialized`](@ref), -an alias for `Uninitialized()`. +would like an uninitialized array. See also [`undef`](@ref), +an alias for `UndefInitializer()`. # Examples ```julia-repl -julia> Array{Float64,1}(Uninitialized(), 3) +julia> Array{Float64,1}(UndefInitializer(), 3) 3-element Array{Float64,1}: 2.2752528595e-314 2.202942107e-314 2.275252907e-314 ``` """ -Uninitialized +UndefInitializer """ - uninitialized + undef -Alias for `Uninitialized()`, which constructs an instance of the singleton type -[`Uninitialized`](@ref), used in array initialization to indicate the +Alias for `UndefInitializer()`, which constructs an instance of the singleton type +[`UndefInitializer`](@ref), used in array initialization to indicate the array-constructor-caller would like an uninitialized array. # Examples ```julia-repl -julia> Array{Float64,1}(uninitialized, 3) +julia> Array{Float64,1}(undef, 3) 3-element Array{Float64,1}: 2.2752528595e-314 2.202942107e-314 2.275252907e-314 ``` """ -uninitialized +undef """ +(x, y...) diff --git a/base/env.jl b/base/env.jl index f79979b7b49cb..ddcb57bda182d 100644 --- a/base/env.jl +++ b/base/env.jl @@ -96,7 +96,7 @@ if Sys.iswindows() pos = block[1] blk = block[2] len = ccall(:wcslen, UInt, (Ptr{UInt16},), pos) - buf = Vector{UInt16}(uninitialized, len) + buf = Vector{UInt16}(undef, len) GC.@preserve buf unsafe_copyto!(pointer(buf), pos, len) env = transcode(String, buf) m = match(r"^(=?[^=]+)=(.*)$"s, env) diff --git a/base/essentials.jl b/base/essentials.jl index b05fb0f5cb9d4..feac4f2f38dcd 100644 --- a/base/essentials.jl +++ b/base/essentials.jl @@ -362,7 +362,7 @@ function append_any(xs...) # used by apply() and quote # must be a separate function from append(), since apply() needs this # exact function. - out = Vector{Any}(uninitialized, 4) + out = Vector{Any}(undef, 4) l = 4 i = 1 for x in xs diff --git a/base/file.jl b/base/file.jl index 7cd348e9432e9..5d30a40129417 100644 --- a/base/file.jl +++ b/base/file.jl @@ -37,7 +37,7 @@ import .Base.RefValue Get the current working directory. """ function pwd() - b = Vector{UInt8}(uninitialized, 1024) + b = Vector{UInt8}(undef, 1024) len = RefValue{Csize_t}(length(b)) uv_error(:getcwd, ccall(:uv_cwd, Cint, (Ptr{UInt8}, Ptr{Csize_t}), b, len)) String(b[1:len[]]) @@ -284,7 +284,7 @@ end if Sys.iswindows() function tempdir() - temppath = Vector{UInt16}(uninitialized, 32767) + temppath = Vector{UInt16}(undef, 32767) lentemppath = ccall(:GetTempPathW,stdcall,UInt32,(UInt32,Ptr{UInt16}),length(temppath),temppath) if lentemppath >= length(temppath) || lentemppath == 0 error("GetTempPath failed: $(Libc.FormatMessage())") @@ -296,7 +296,7 @@ end const temp_prefix = cwstring("jl_") function _win_tempname(temppath::AbstractString, uunique::UInt32) tempp = cwstring(temppath) - tname = Vector{UInt16}(uninitialized, 32767) + tname = Vector{UInt16}(undef, 32767) uunique = ccall(:GetTempFileNameW,stdcall,UInt32,(Ptr{UInt16},Ptr{UInt16},UInt32,Ptr{UInt16}), tempp,temp_prefix,uunique,tname) lentname = coalesce(findfirst(iszero,tname), 0)-1 if uunique == 0 || lentname <= 0 diff --git a/base/float.jl b/base/float.jl index 62dc732d107d5..f39d9a3679816 100644 --- a/base/float.jl +++ b/base/float.jl @@ -203,8 +203,8 @@ end # "Fast Half Float Conversion" by Jeroen van der Zijp # ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf -const basetable = Vector{UInt16}(uninitialized, 512) -const shifttable = Vector{UInt8}(uninitialized, 512) +const basetable = Vector{UInt16}(undef, 512) +const shifttable = Vector{UInt8}(undef, 512) for i = 0:255 e = i - 127 diff --git a/base/grisu/bignums.jl b/base/grisu/bignums.jl index 54a948da473e7..8898549c3cc41 100644 --- a/base/grisu/bignums.jl +++ b/base/grisu/bignums.jl @@ -54,7 +54,7 @@ mutable struct Bignum used_digits::Int32 exponent::Int32 function Bignum() - bigits = Vector{UInt32}(uninitialized, kBigitCapacity) + bigits = Vector{UInt32}(undef, kBigitCapacity) @inbounds for i = 1:kBigitCapacity bigits[i] = 0 end diff --git a/base/grisu/fastprecision.jl b/base/grisu/fastprecision.jl index b54fd2397b360..dfb7a0c46a88a 100644 --- a/base/grisu/fastprecision.jl +++ b/base/grisu/fastprecision.jl @@ -87,7 +87,7 @@ function digitgen(w,buffer,requested_digits=1000) return r, kappa, len end -function fastprecision(v, requested_digits, buffer = Vector{UInt8}(uninitialized, 100)) +function fastprecision(v, requested_digits, buffer = Vector{UInt8}(undef, 100)) f = normalize(Float64(v)) ten_mk_min_exp = kMinExp - (f.e + FloatSignificandSize) ten_mk_max_exp = kMaxExp - (f.e + FloatSignificandSize) diff --git a/base/grisu/fastshortest.jl b/base/grisu/fastshortest.jl index b619b0b56c9a6..acd810e9d8ca7 100644 --- a/base/grisu/fastshortest.jl +++ b/base/grisu/fastshortest.jl @@ -102,7 +102,7 @@ function digitgen(low,w,high,buffer) end end -function fastshortest(v, buffer = Vector{UInt8}(uninitialized, 17)) +function fastshortest(v, buffer = Vector{UInt8}(undef, 17)) f = normalize(Float64(v)) bound_minus, bound_plus = normalizedbound(v) ten_mk_min_exp = kMinExp - (f.e + FloatSignificandSize) diff --git a/base/grisu/grisu.jl b/base/grisu/grisu.jl index f72e08b2ddded..fccd11dd5376a 100644 --- a/base/grisu/grisu.jl +++ b/base/grisu/grisu.jl @@ -9,7 +9,7 @@ const SHORTEST = 1 const FIXED = 2 const PRECISION = 3 -const DIGITS = Vector{UInt8}(uninitialized, 309+17) +const DIGITS = Vector{UInt8}(undef, 309+17) include(joinpath("grisu", "float.jl")) include(joinpath("grisu", "fastshortest.jl")) diff --git a/base/io.jl b/base/io.jl index dd3dd7ab15649..2c6d656816794 100644 --- a/base/io.jl +++ b/base/io.jl @@ -829,7 +829,7 @@ Read at most `nb` bytes from `s`, returning a `Vector{UInt8}` of the bytes read. function read(s::IO, nb::Integer = typemax(Int)) # Let readbytes! grow the array progressively by default # instead of taking of risk of over-allocating - b = Vector{UInt8}(uninitialized, nb == typemax(Int) ? 1024 : nb) + b = Vector{UInt8}(undef, nb == typemax(Int) ? 1024 : nb) nr = readbytes!(s, b, nb) return resize!(b, nr) end @@ -1025,7 +1025,7 @@ julia> countlines(io, eol = '.') function countlines(io::IO; eol::AbstractChar='\n') isascii(eol) || throw(ArgumentError("only ASCII line terminators are supported")) aeol = UInt8(eol) - a = Vector{UInt8}(uninitialized, 8192) + a = Vector{UInt8}(undef, 8192) nl = nb = 0 while !eof(io) nb = readbytes!(io, a) diff --git a/base/iostream.jl b/base/iostream.jl index b8de905c101c9..58e937d055d99 100644 --- a/base/iostream.jl +++ b/base/iostream.jl @@ -387,7 +387,7 @@ end # num bytes available without blocking bytesavailable(s::IOStream) = ccall(:jl_nb_available, Int32, (Ptr{Cvoid},), s.ios) -readavailable(s::IOStream) = read!(s, Vector{UInt8}(uninitialized, bytesavailable(s))) +readavailable(s::IOStream) = read!(s, Vector{UInt8}(undef, bytesavailable(s))) function read(s::IOStream, ::Type{UInt8}) b = ccall(:ios_getc, Cint, (Ptr{Cvoid},), s.ios) @@ -502,7 +502,7 @@ requested bytes, until an error or end-of-file occurs. If `all` is `false`, at m all stream types support the `all` option. """ function read(s::IOStream, nb::Integer; all::Bool=true) - b = Vector{UInt8}(uninitialized, nb) + b = Vector{UInt8}(undef, nb) nr = readbytes!(s, b, nb, all=all) resize!(b, nr) end diff --git a/base/iterators.jl b/base/iterators.jl index d51efee82c1ae..08e3e1c432363 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -976,7 +976,7 @@ function next(itr::PartitionIterator{<:Vector}, state) end function next(itr::PartitionIterator, state) - v = Vector{eltype(itr.c)}(uninitialized, itr.n) + v = Vector{eltype(itr.c)}(undef, itr.n) i = 0 while !done(itr.c, state) && i < itr.n i += 1 diff --git a/base/libc.jl b/base/libc.jl index b269e931416f9..1f18402f70be6 100644 --- a/base/libc.jl +++ b/base/libc.jl @@ -243,7 +243,7 @@ getpid() = ccall(:jl_getpid, Int32, ()) Get the local machine's host name. """ function gethostname() - hn = Vector{UInt8}(uninitialized, 256) + hn = Vector{UInt8}(undef, 256) err = @static if Sys.iswindows() ccall(:gethostname, stdcall, Int32, (Ptr{UInt8}, UInt32), hn, length(hn)) else @@ -305,7 +305,7 @@ if Sys.iswindows() C_NULL, e, 0, lpMsgBuf, 0, C_NULL) p = lpMsgBuf[] len == 0 && return "" - buf = Vector{UInt16}(uninitialized, len) + buf = Vector{UInt16}(undef, len) GC.@preserve buf unsafe_copyto!(pointer(buf), p, len) ccall(:LocalFree, stdcall, Ptr{Cvoid}, (Ptr{Cvoid},), p) return transcode(String, buf) diff --git a/base/loading.jl b/base/loading.jl index 0723313515a32..da5048094c866 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -47,7 +47,7 @@ elseif Sys.isapple() path_basename = String(basename(path)) local casepreserved_basename header_size = 12 - buf = Vector{UInt8}(uninitialized, length(path_basename) + header_size + 1) + buf = Vector{UInt8}(undef, length(path_basename) + header_size + 1) while true ret = ccall(:getattrlist, Cint, (Cstring, Ptr{Cvoid}, Ptr{Cvoid}, Csize_t, Culong), @@ -708,7 +708,7 @@ function _require_from_serialized(path::String) close(io) end ndeps = length(depmodnames) - depmods = Vector{Any}(uninitialized, ndeps) + depmods = Vector{Any}(undef, ndeps) for i in 1:ndeps modkey, build_id = depmodnames[i] dep = _tryrequire_from_serialized(modkey, build_id, nothing) @@ -1338,7 +1338,7 @@ function stale_cachefile(modpath::String, cachefile::String) # Check if transitive dependencies can be fullfilled ndeps = length(required_modules) - depmods = Vector{Any}(uninitialized, ndeps) + depmods = Vector{Any}(undef, ndeps) for i in 1:ndeps req_key, req_build_id = required_modules[i] # Module is already loaded diff --git a/base/methodshow.jl b/base/methodshow.jl index 013246e24c54d..53c5d7bd1b465 100644 --- a/base/methodshow.jl +++ b/base/methodshow.jl @@ -46,7 +46,7 @@ function method_argnames(m::Method) if !isdefined(m, :source) && isdefined(m, :generator) return m.generator.argnames end - argnames = Vector{Any}(uninitialized, m.nargs) + argnames = Vector{Any}(undef, m.nargs) ccall(:jl_fill_argnames, Cvoid, (Any, Any), m.source, argnames) return argnames end diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 130330f67bbe3..74de375964a86 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -1193,13 +1193,13 @@ julia> fill!(A, 2.) 2.0 2.0 2.0 2.0 2.0 2.0 -julia> a = [1, 1, 1]; A = fill!(Vector{Vector{Int}}(uninitialized, 3), a); a[1] = 2; A +julia> a = [1, 1, 1]; A = fill!(Vector{Vector{Int}}(undef, 3), a); a[1] = 2; A 3-element Array{Array{Int64,1},1}: [2, 1, 1] [2, 1, 1] [2, 1, 1] -julia> x = 0; f() = (global x += 1; x); fill!(Vector{Int}(uninitialized, 3), f()) +julia> x = 0; f() = (global x += 1; x); fill!(Vector{Int}(undef, 3), f()) 3-element Array{Int64,1}: 1 1 @@ -1359,7 +1359,7 @@ julia> src = reshape(Vector(1:16), (4,4)) 3 7 11 15 4 8 12 16 -julia> dest = OffsetArray{Int}(uninitialized, (0:3,2:5)) +julia> dest = OffsetArray{Int}(undef, (0:3,2:5)) julia> circcopy!(dest, src) OffsetArrays.OffsetArray{Int64,2,Array{Int64,2}} with indices 0:3×2:5: @@ -1866,7 +1866,7 @@ julia> extrema(A, (1,2)) function extrema(A::AbstractArray, dims) sz = [size(A)...] sz[[dims...]] = 1 - B = Array{Tuple{eltype(A),eltype(A)}}(uninitialized, sz...) + B = Array{Tuple{eltype(A),eltype(A)}}(undef, sz...) return extrema!(B, A) end diff --git a/base/path.jl b/base/path.jl index 1bb777dd2377d..2b5b8f3063507 100644 --- a/base/path.jl +++ b/base/path.jl @@ -61,7 +61,7 @@ Return the current user's home directory. """ function homedir() path_max = 1024 - buf = Vector{UInt8}(uninitialized, path_max) + buf = Vector{UInt8}(undef, path_max) sz = RefValue{Csize_t}(path_max + 1) while true rc = ccall(:uv_os_homedir, Cint, (Ptr{UInt8}, Ptr{Csize_t}), buf, sz) diff --git a/base/pcre.jl b/base/pcre.jl index 0fdc486988018..0809e68199fad 100644 --- a/base/pcre.jl +++ b/base/pcre.jl @@ -122,7 +122,7 @@ free_match_context(context) = ccall((:pcre2_match_context_free_8, PCRE_LIB), Cvoid, (Ptr{Cvoid},), context) function err_message(errno) - buffer = Vector{UInt8}(uninitialized, 256) + buffer = Vector{UInt8}(undef, 256) ccall((:pcre2_get_error_message_8, PCRE_LIB), Cvoid, (Int32, Ptr{UInt8}, Csize_t), errno, buffer, sizeof(buffer)) GC.@preserve buffer unsafe_string(pointer(buffer)) diff --git a/base/precompile.jl b/base/precompile.jl index a9b3d8e177560..c688643cb73f6 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -17,7 +17,7 @@ for (_pkgid, _mod) in Base.loaded_modules end end @eval PrecompileStagingArea begin -precompile(Tuple{Type{Array{Array{UInt8, 1}, 1}}, Uninitialized, Int64}) +precompile(Tuple{Type{Array{Array{UInt8, 1}, 1}}, UndefInitializer, Int64}) precompile(Tuple{Type{Array{Float64, 1}}, Int64}) precompile(Tuple{Type{Array{UInt8, 1}}, Int64}) precompile(Tuple{Type{Base.Dict{K, V} where V where K}, Base.Generator{Base.Dict{UInt8, UInt8}, typeof(Base.reverse)}}) diff --git a/base/promotion.jl b/base/promotion.jl index 9e927572c1c25..469eb0bd8e4a8 100644 --- a/base/promotion.jl +++ b/base/promotion.jl @@ -48,26 +48,26 @@ function typejoin(@nospecialize(a), @nospecialize(b)) lbf, bfixed = full_va_len(bp) if laf < lbf if isvarargtype(ap[lar]) && !afixed - c = Vector{Any}(uninitialized, laf) + c = Vector{Any}(undef, laf) c[laf] = Vararg{typejoin(unwrapva(ap[lar]), tailjoin(bp, laf))} n = laf-1 else - c = Vector{Any}(uninitialized, laf+1) + c = Vector{Any}(undef, laf+1) c[laf+1] = Vararg{tailjoin(bp, laf+1)} n = laf end elseif lbf < laf if isvarargtype(bp[lbr]) && !bfixed - c = Vector{Any}(uninitialized, lbf) + c = Vector{Any}(undef, lbf) c[lbf] = Vararg{typejoin(unwrapva(bp[lbr]), tailjoin(ap, lbf))} n = lbf-1 else - c = Vector{Any}(uninitialized, lbf+1) + c = Vector{Any}(undef, lbf+1) c[lbf+1] = Vararg{tailjoin(ap, lbf+1)} n = lbf end else - c = Vector{Any}(uninitialized, laf) + c = Vector{Any}(undef, laf) n = laf end for i = 1:n @@ -90,7 +90,7 @@ function typejoin(@nospecialize(a), @nospecialize(b)) if n == 0 return aprimary end - p = Vector{Any}(uninitialized, n) + p = Vector{Any}(undef, n) for i = 1:n ai, bi = a.parameters[i], b.parameters[i] if ai === bi || (isa(ai,Type) && isa(bi,Type) && typeseq(ai,bi)) diff --git a/base/range.jl b/base/range.jl index 8dc3a33caec9d..69afe81d7db4a 100644 --- a/base/range.jl +++ b/base/range.jl @@ -860,7 +860,7 @@ function vcat(rs::AbstractRange{T}...) where T for ra in rs n += length(ra) end - a = Vector{T}(uninitialized, n) + a = Vector{T}(undef, n) i = 1 for ra in rs, x in ra @inbounds a[i] = x diff --git a/base/refpointer.jl b/base/refpointer.jl index bddaaaeb886a0..851c04f3f5c03 100644 --- a/base/refpointer.jl +++ b/base/refpointer.jl @@ -87,8 +87,8 @@ if is_primary_base_module # this Array already has the right memory layout for the requested Ref return RefArray(a,1,false) # root something, so that this function is type-stable else - ptrs = Vector{P}(uninitialized, length(a)+1) - roots = Vector{Any}(uninitialized, length(a)) + ptrs = Vector{P}(undef, length(a)+1) + roots = Vector{Any}(undef, length(a)) for i = 1:length(a) root = cconvert(P, a[i]) ptrs[i] = unsafe_convert(P, root)::P diff --git a/base/rounding.jl b/base/rounding.jl index f983b5bfc8b15..534f7ad043a9b 100644 --- a/base/rounding.jl +++ b/base/rounding.jl @@ -2,7 +2,7 @@ module Rounding -let fenv_consts = Vector{Cint}(uninitialized, 9) +let fenv_consts = Vector{Cint}(undef, 9) ccall(:jl_get_fenv_consts, Cvoid, (Ptr{Cint},), fenv_consts) global const JL_FE_INEXACT = fenv_consts[1] global const JL_FE_UNDERFLOW = fenv_consts[2] diff --git a/base/show.jl b/base/show.jl index 139a6280b7620..aafc73a4578cf 100644 --- a/base/show.jl +++ b/base/show.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +show(io::IO, ::UndefInitializer) = print(io, "array initializer with undefined values") + # first a few multiline show functions for types defined before the MIME type: show(io::IO, ::MIME"text/plain", r::AbstractRange) = show(io, r) # always use the compact form for printing ranges @@ -89,8 +91,8 @@ function show(io::IO, ::MIME"text/plain", t::AbstractDict{K,V}) where {K,V} rows -= 1 # Subtract the summary # determine max key width to align the output, caching the strings - ks = Vector{AbstractString}(uninitialized, min(rows, length(t))) - vs = Vector{AbstractString}(uninitialized, min(rows, length(t))) + ks = Vector{AbstractString}(undef, min(rows, length(t))) + vs = Vector{AbstractString}(undef, min(rows, length(t))) keylen = 0 vallen = 0 for (i, (k, v)) in enumerate(t) @@ -597,7 +599,7 @@ function sourceinfo_slotnames(src::CodeInfo) slotnames = src.slotnames isa(slotnames, Array) || return String[] names = Dict{String,Int}() - printnames = Vector{String}(uninitialized, length(slotnames)) + printnames = Vector{String}(undef, length(slotnames)) for i in eachindex(slotnames) name = string(slotnames[i]) idx = get!(names, name, i) @@ -1368,7 +1370,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) if prec >= 0 show_call(io, :call, args[1], args[3:end], indent) else - show_args = Vector{Any}(uninitialized, length(args) - 1) + show_args = Vector{Any}(undef, length(args) - 1) show_args[1] = args[1] show_args[2:end] = args[3:end] show_list(io, show_args, ' ', indent) diff --git a/base/sort.jl b/base/sort.jl index 8819f4c97da83..a30f8ff443178 100644 --- a/base/sort.jl +++ b/base/sort.jl @@ -834,7 +834,7 @@ function sortperm_int_range(x::Vector{<:Integer}, rangelen, minval) where[i] += where[i-1] end - P = Vector{Int}(uninitialized, n) + P = Vector{Int}(undef, n) @inbounds for i = 1:n label = x[i] + offs P[where[label]] = i diff --git a/base/stacktraces.jl b/base/stacktraces.jl index 9db1a99931ec0..a9d729e52c5f1 100644 --- a/base/stacktraces.jl +++ b/base/stacktraces.jl @@ -106,7 +106,7 @@ inlined at that point, innermost function first. function lookup(pointer::Ptr{Cvoid}) infos = ccall(:jl_lookup_code_address, Any, (Ptr{Cvoid}, Cint), pointer - 1, false) isempty(infos) && return [StackFrame(empty_sym, empty_sym, -1, nothing, true, false, convert(UInt64, pointer))] - res = Vector{StackFrame}(uninitialized, length(infos)) + res = Vector{StackFrame}(undef, length(infos)) for i in 1:length(infos) info = infos[i] @assert(length(info) == 7) diff --git a/base/statistics.jl b/base/statistics.jl index cf681b6d45fc6..3b0bbb5b9f9ac 100644 --- a/base/statistics.jl +++ b/base/statistics.jl @@ -648,7 +648,7 @@ median(v::AbstractArray; dims=:) = _median(v, dims) _median(v::AbstractArray, dims) = mapslices(median!, v, dims) -_median(v::AbstractArray{T}, ::Colon) where {T} = median!(copyto!(Array{T,1}(uninitialized, _length(v)), v)) +_median(v::AbstractArray{T}, ::Colon) where {T} = median!(copyto!(Array{T,1}(undef, _length(v)), v)) # for now, use the R/S definition of quantile; may want variants later # see ?quantile in R -- this is type 7 diff --git a/base/strings/string.jl b/base/strings/string.jl index 260d6644647ff..100364b0f8207 100644 --- a/base/strings/string.jl +++ b/base/strings/string.jl @@ -62,7 +62,7 @@ String(s::Symbol) = unsafe_string(unsafe_convert(Ptr{UInt8}, s)) unsafe_wrap(::Type{Vector{UInt8}}, s::String) = ccall(:jl_string_to_array, Ref{Vector{UInt8}}, (Any,), s) -(::Type{Vector{UInt8}})(s::CodeUnits{UInt8,String}) = copyto!(Vector{UInt8}(uninitialized, length(s)), s) +(::Type{Vector{UInt8}})(s::CodeUnits{UInt8,String}) = copyto!(Vector{UInt8}(undef, length(s)), s) String(a::AbstractVector{UInt8}) = String(copyto!(StringVector(length(a)), a)) diff --git a/base/strings/util.jl b/base/strings/util.jl index 01ca647ab275c..42a5d9efccae2 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -473,7 +473,7 @@ julia> hex2bytes(a) function hex2bytes end hex2bytes(s::AbstractString) = hex2bytes(String(s)) -hex2bytes(s::Union{String,AbstractVector{UInt8}}) = hex2bytes!(Vector{UInt8}(uninitialized, length(s) >> 1), s) +hex2bytes(s::Union{String,AbstractVector{UInt8}}) = hex2bytes!(Vector{UInt8}(undef, length(s) >> 1), s) _firstbyteidx(s::String) = 1 _firstbyteidx(s::AbstractVector{UInt8}) = first(eachindex(s)) @@ -525,7 +525,7 @@ julia> bytes2hex(b) ``` """ function bytes2hex(a::AbstractArray{UInt8}) - b = Vector{UInt8}(uninitialized, 2*length(a)) + b = Vector{UInt8}(undef, 2*length(a)) i = 0 for x in a b[i += 1] = hex_chars[1 + x >> 4] diff --git a/base/subarray.jl b/base/subarray.jl index e45c8024d1ee9..1bf1665e202ba 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -78,7 +78,7 @@ unaliascopy(A::SubArray) = typeof(A)(unaliascopy(A.parent), map(unaliascopy, A.i # When the parent is an Array we can trim the size down a bit. In the future this # could possibly be extended to any mutable array. function unaliascopy(V::SubArray{T,N,A,I,LD}) where {T,N,A<:Array,I<:Tuple{Vararg{Union{Real,AbstractRange,Array}}},LD} - dest = Array{T}(uninitialized, index_lengths(V.indices...)) + dest = Array{T}(undef, index_lengths(V.indices...)) copyto!(dest, V) SubArray{T,N,A,I,LD}(dest, map(_trimmedindex, V.indices), 0, Int(LD)) end @@ -350,7 +350,7 @@ end # deprecate? function parentdims(s::SubArray) nd = ndims(s) - dimindex = Vector{Int}(uninitialized, nd) + dimindex = Vector{Int}(undef, nd) sp = strides(s.parent) sv = strides(s) j = 1 diff --git a/base/sysimg.jl b/base/sysimg.jl index 858a4e276537c..b39850c6654eb 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -153,26 +153,26 @@ include("reinterpretarray.jl") # ## dims-type-converting Array constructors for convenience # type and dimensionality specified, accepting dims as series of Integers -Vector{T}(::Uninitialized, m::Integer) where {T} = Vector{T}(uninitialized, Int(m)) -Matrix{T}(::Uninitialized, m::Integer, n::Integer) where {T} = Matrix{T}(uninitialized, Int(m), Int(n)) +Vector{T}(::UndefInitializer, m::Integer) where {T} = Vector{T}(undef, Int(m)) +Matrix{T}(::UndefInitializer, m::Integer, n::Integer) where {T} = Matrix{T}(undef, Int(m), Int(n)) # type but not dimensionality specified, accepting dims as series of Integers -Array{T}(::Uninitialized, m::Integer) where {T} = Array{T,1}(uninitialized, Int(m)) -Array{T}(::Uninitialized, m::Integer, n::Integer) where {T} = Array{T,2}(uninitialized, Int(m), Int(n)) -Array{T}(::Uninitialized, m::Integer, n::Integer, o::Integer) where {T} = Array{T,3}(uninitialized, Int(m), Int(n), Int(o)) -Array{T}(::Uninitialized, d::Integer...) where {T} = Array{T}(uninitialized, convert(Tuple{Vararg{Int}}, d)) +Array{T}(::UndefInitializer, m::Integer) where {T} = Array{T,1}(undef, Int(m)) +Array{T}(::UndefInitializer, m::Integer, n::Integer) where {T} = Array{T,2}(undef, Int(m), Int(n)) +Array{T}(::UndefInitializer, m::Integer, n::Integer, o::Integer) where {T} = Array{T,3}(undef, Int(m), Int(n), Int(o)) +Array{T}(::UndefInitializer, d::Integer...) where {T} = Array{T}(undef, convert(Tuple{Vararg{Int}}, d)) # dimensionality but not type specified, accepting dims as series of Integers -Vector(::Uninitialized, m::Integer) = Vector{Any}(uninitialized, Int(m)) -Matrix(::Uninitialized, m::Integer, n::Integer) = Matrix{Any}(uninitialized, Int(m), Int(n)) +Vector(::UndefInitializer, m::Integer) = Vector{Any}(undef, Int(m)) +Matrix(::UndefInitializer, m::Integer, n::Integer) = Matrix{Any}(undef, Int(m), Int(n)) # empty vector constructor -Vector() = Vector{Any}(uninitialized, 0) +Vector() = Vector{Any}(undef, 0) # Array constructors for nothing and missing # type and dimensionality specified -Array{T,N}(::Nothing, d...) where {T,N} = fill!(Array{T,N}(uninitialized, d...), nothing) -Array{T,N}(::Missing, d...) where {T,N} = fill!(Array{T,N}(uninitialized, d...), missing) +Array{T,N}(::Nothing, d...) where {T,N} = fill!(Array{T,N}(undef, d...), nothing) +Array{T,N}(::Missing, d...) where {T,N} = fill!(Array{T,N}(undef, d...), missing) # type but not dimensionality specified -Array{T}(::Nothing, d...) where {T} = fill!(Array{T}(uninitialized, d...), nothing) -Array{T}(::Missing, d...) where {T} = fill!(Array{T}(uninitialized, d...), missing) +Array{T}(::Nothing, d...) where {T} = fill!(Array{T}(undef, d...), nothing) +Array{T}(::Missing, d...) where {T} = fill!(Array{T}(undef, d...), missing) include("abstractdict.jl") diff --git a/base/sysinfo.jl b/base/sysinfo.jl index 0730dd9fe1508..0fc791a946557 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -181,7 +181,7 @@ function cpu_info() UVcpus = Ref{Ptr{UV_cpu_info_t}}() count = Ref{Int32}() Base.uv_error("uv_cpu_info",ccall(:uv_cpu_info, Int32, (Ptr{Ptr{UV_cpu_info_t}}, Ptr{Int32}), UVcpus, count)) - cpus = Vector{CPUinfo}(uninitialized, count[]) + cpus = Vector{CPUinfo}(undef, count[]) for i = 1:length(cpus) cpus[i] = CPUinfo(unsafe_load(UVcpus[], i)) end @@ -206,7 +206,7 @@ end Get the load average. See: https://en.wikipedia.org/wiki/Load_(computing). """ function loadavg() - loadavg_ = Vector{Float64}(uninitialized, 3) + loadavg_ = Vector{Float64}(undef, 3) ccall(:uv_loadavg, Cvoid, (Ptr{Float64},), loadavg_) return loadavg_ end @@ -220,7 +220,7 @@ total_memory() = ccall(:uv_get_total_memory, UInt64, ()) Get the process title. On some systems, will always return an empty string. """ function get_process_title() - buf = Vector{UInt8}(uninitialized, 512) + buf = Vector{UInt8}(undef, 512) err = ccall(:uv_get_process_title, Cint, (Ptr{UInt8}, Cint), buf, 512) Base.uv_error("get_process_title", err) return unsafe_string(pointer(buf)) diff --git a/base/threadcall.jl b/base/threadcall.jl index 3f63a72a024bf..63875db389942 100644 --- a/base/threadcall.jl +++ b/base/threadcall.jl @@ -66,7 +66,7 @@ function do_threadcall(wrapper::Function, rettype::Type, argtypes::Vector, argva # cconvert, root and unsafe_convert arguments roots = Any[] args_size = isempty(argtypes) ? 0 : sum(sizeof, argtypes) - args_arr = Vector{UInt8}(uninitialized, args_size) + args_arr = Vector{UInt8}(undef, args_size) ptr = pointer(args_arr) for (T, x) in zip(argtypes, argvals) y = cconvert(T, x) @@ -76,7 +76,7 @@ function do_threadcall(wrapper::Function, rettype::Type, argtypes::Vector, argva end # create return buffer - ret_arr = Vector{UInt8}(uninitialized, sizeof(rettype)) + ret_arr = Vector{UInt8}(undef, sizeof(rettype)) # wait for a worker thread to be available acquire(threadcall_restrictor) diff --git a/base/tuple.jl b/base/tuple.jl index f85c53d8a40f3..75a657d16f019 100644 --- a/base/tuple.jl +++ b/base/tuple.jl @@ -159,7 +159,7 @@ const All16{T,N} = Tuple{T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T,Vararg{T,N}} function map(f, t::Any16) n = length(t) - A = Vector{Any}(uninitialized, n) + A = Vector{Any}(undef, n) for i=1:n A[i] = f(t[i]) end @@ -175,7 +175,7 @@ function map(f, t::Tuple, s::Tuple) end function map(f, t::Any16, s::Any16) n = length(t) - A = Vector{Any}(uninitialized, n) + A = Vector{Any}(undef, n) for i = 1:n A[i] = f(t[i], s[i]) end @@ -191,7 +191,7 @@ function map(f, t1::Tuple, t2::Tuple, ts::Tuple...) end function map(f, t1::Any16, t2::Any16, ts::Any16...) n = length(t1) - A = Vector{Any}(uninitialized, n) + A = Vector{Any}(undef, n) for i = 1:n A[i] = f(t1[i], t2[i], map(t -> t[i], ts)...) end diff --git a/base/util.jl b/base/util.jl index b8e4094cc9add..5f85bf502d9dd 100644 --- a/base/util.jl +++ b/base/util.jl @@ -386,7 +386,7 @@ if Sys.iswindows() function getpass(prompt::AbstractString) print(prompt) flush(stdout) - p = Vector{UInt8}(uninitialized, 128) # mimic Unix getpass in ignoring more than 128-char passwords + p = Vector{UInt8}(undef, 128) # mimic Unix getpass in ignoring more than 128-char passwords # (also avoids any potential memory copies arising from push!) try plen = 0 @@ -462,7 +462,7 @@ if Sys.iswindows() function winprompt(message, caption, default_username; prompt_username = true) # Step 1: Create an encrypted username/password bundle that will be used to set # the default username (in theory could also provide a default password) - credbuf = Vector{UInt8}(uninitialized, 1024) + credbuf = Vector{UInt8}(undef, 1024) credbufsize = Ref{UInt32}(sizeof(credbuf)) succeeded = ccall((:CredPackAuthenticationBufferW, "credui.dll"), stdcall, Bool, (UInt32, Cwstring, Cwstring, Ptr{UInt8}, Ptr{UInt32}), @@ -498,12 +498,12 @@ if Sys.iswindows() end # Step 3: Convert encrypted credentials back to plain text - passbuf = Vector{UInt16}(uninitialized, 1024) + passbuf = Vector{UInt16}(undef, 1024) passlen = Ref{UInt32}(length(passbuf)) - usernamebuf = Vector{UInt16}(uninitialized, 1024) + usernamebuf = Vector{UInt16}(undef, 1024) usernamelen = Ref{UInt32}(length(usernamebuf)) # Need valid buffers for domain, even though we don't care - dummybuf = Vector{UInt16}(uninitialized, 1024) + dummybuf = Vector{UInt16}(undef, 1024) succeeded = ccall((:CredUnPackAuthenticationBufferW, "credui.dll"), Bool, (UInt32, Ptr{Cvoid}, UInt32, Ptr{UInt16}, Ptr{UInt32}, Ptr{UInt16}, Ptr{UInt32}, Ptr{UInt16}, Ptr{UInt32}), 0, outbuf_data[], outbuf_size[], usernamebuf, usernamelen, dummybuf, Ref{UInt32}(1024), passbuf, passlen) @@ -539,7 +539,7 @@ function _crc32c(io::IO, nb::Integer, crc::UInt32=0x00000000) nb < 0 && throw(ArgumentError("number of bytes to checksum must be ≥ 0")) # use block size 24576=8192*3, since that is the threshold for # 3-way parallel SIMD code in the underlying jl_crc32c C function. - buf = Vector{UInt8}(uninitialized, min(nb, 24576)) + buf = Vector{UInt8}(undef, min(nb, 24576)) while !eof(io) && nb > 24576 n = readbytes!(io, buf) crc = unsafe_crc32c(buf, n, crc) diff --git a/doc/src/base/arrays.md b/doc/src/base/arrays.md index 11b3c6dbb7b2d..ee14f56a14a74 100644 --- a/doc/src/base/arrays.md +++ b/doc/src/base/arrays.md @@ -7,24 +7,24 @@ Core.AbstractArray Base.AbstractVector Base.AbstractMatrix Core.Array -Core.Array(::Uninitialized, ::Any) +Core.Array(::UndefInitializer, ::Any) Core.Array(::Nothing, ::Any) Core.Array(::Missing, ::Any) -Core.Uninitialized -Core.uninitialized +Core.UndefInitializer +Core.undef Base.Vector -Base.Vector(::Uninitialized, ::Any) +Base.Vector(::UndefInitializer, ::Any) Base.Vector(::Nothing, ::Any) Base.Vector(::Missing, ::Any) Base.Matrix -Base.Matrix(::Uninitialized, ::Any, ::Any) +Base.Matrix(::UndefInitializer, ::Any, ::Any) Base.Matrix(::Nothing, ::Any, ::Any) Base.Matrix(::Missing, ::Any, ::Any) Base.getindex(::Type, ::Any...) Base.zeros Base.ones Base.BitArray -Base.BitArray(::Uninitialized, ::Integer...) +Base.BitArray(::UndefInitializer, ::Integer...) Base.BitArray(::Any) Base.trues Base.falses diff --git a/doc/src/devdocs/offset-arrays.md b/doc/src/devdocs/offset-arrays.md index 5288f30a6d383..b5a1552cf4a3e 100644 --- a/doc/src/devdocs/offset-arrays.md +++ b/doc/src/devdocs/offset-arrays.md @@ -97,7 +97,7 @@ end ### Allocating storage using generalizations of `similar` -Storage is often allocated with `Array{Int}(uninitialized, dims)` or `similar(A, args...)`. When the result needs +Storage is often allocated with `Array{Int}(undef, dims)` or `similar(A, args...)`. When the result needs to match the indices of some other array, this may not always suffice. The generic replacement for such patterns is to use `similar(storagetype, shape)`. `storagetype` indicates the kind of underlying "conventional" behavior you'd like, e.g., `Array{Int}` or `BitArray` or even `dims->zeros(Float32, dims)` @@ -109,7 +109,7 @@ Let's walk through a couple of explicit examples. First, if `A` has conventional `similar(Array{Int}, axes(A))` would end up calling `Array{Int}(size(A))`, and thus return an array. If `A` is an `AbstractArray` type with unconventional indexing, then `similar(Array{Int}, axes(A))` should return something that "behaves like" an `Array{Int}` but with a shape (including indices) -that matches `A`. (The most obvious implementation is to allocate an `Array{Int}(uninitialized, size(A))` and +that matches `A`. (The most obvious implementation is to allocate an `Array{Int}(undef, size(A))` and then "wrap" it in a type that shifts the indices.) Note also that `similar(Array{Int}, (axes(A, 2),))` would allocate an `AbstractVector{Int}` diff --git a/doc/src/manual/arrays.md b/doc/src/manual/arrays.md index 28f2c51f17a45..211cca3284993 100644 --- a/doc/src/manual/arrays.md +++ b/doc/src/manual/arrays.md @@ -50,7 +50,7 @@ omitted it will default to [`Float64`](@ref). | Function | Description | |:---------------------------------- |:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [`Array{T}(uninitialized, dims...)`](@ref) | an uninitialized dense [`Array`](@ref) | +| [`Array{T}(undef, dims...)`](@ref) | an uninitialized dense [`Array`](@ref) | | [`zeros(T, dims...)`](@ref) | an `Array` of all zeros | | [`ones(T, dims...)`](@ref) | an `Array` of all ones | | [`trues(dims...)`](@ref) | a [`BitArray`](@ref) with all values `true` | diff --git a/doc/src/manual/interfaces.md b/doc/src/manual/interfaces.md index 2349da948f253..9a6b064a92045 100644 --- a/doc/src/manual/interfaces.md +++ b/doc/src/manual/interfaces.md @@ -235,7 +235,7 @@ ourselves, we can officially define it as a subtype of an [`AbstractArray`](@ref | `similar(A)` | `similar(A, eltype(A), size(A))` | Return a mutable array with the same shape and element type | | `similar(A, ::Type{S})` | `similar(A, S, size(A))` | Return a mutable array with the same shape and the specified element type | | `similar(A, dims::NTuple{Int})` | `similar(A, eltype(A), dims)` | Return a mutable array with the same element type and size *dims* | -| `similar(A, ::Type{S}, dims::NTuple{Int})` | `Array{S}(uninitialized, dims)` | Return a mutable array with the specified element type and size | +| `similar(A, ::Type{S}, dims::NTuple{Int})` | `Array{S}(undef, dims)` | Return a mutable array with the specified element type and size | | **Non-traditional indices** | **Default definition** | **Brief description** | | `axes(A)` | `map(OneTo, size(A))` | Return the `AbstractUnitRange` of valid indices | | `Base.similar(A, ::Type{S}, inds::NTuple{Ind})` | `similar(A, S, Base.to_shape(inds))` | Return a mutable array with the specified indices `inds` (see below) | diff --git a/doc/src/manual/performance-tips.md b/doc/src/manual/performance-tips.md index 84dd79caf4b69..bcd5abeb8c4d7 100644 --- a/doc/src/manual/performance-tips.md +++ b/doc/src/manual/performance-tips.md @@ -618,7 +618,7 @@ end ```jldoctest julia> function strange_twos(n) - a = Vector{rand(Bool) ? Int64 : Float64}(uninitialized, n) + a = Vector{rand(Bool) ? Int64 : Float64}(undef, n) for i = 1:n a[i] = 2 end @@ -644,7 +644,7 @@ julia> function fill_twos!(a) fill_twos! (generic function with 1 method) julia> function strange_twos(n) - a = Vector{rand(Bool) ? Int64 : Float64}(uninitialized, n) + a = Vector{rand(Bool) ? Int64 : Float64}(undef, n) fill_twos!(a) return a end @@ -931,7 +931,7 @@ function xinc!(ret::AbstractVector{T}, x::T) where T end function loopinc_prealloc() - ret = Vector{Int}(uninitialized, 3) + ret = Vector{Int}(undef, 3) y = 0 for i = 1:10^7 xinc!(ret, i) @@ -1282,7 +1282,7 @@ end function main() n = 2000 - u = Vector{Float64}(uninitialized, n) + u = Vector{Float64}(undef, n) init!(u) du = similar(u) diff --git a/doc/src/manual/style-guide.md b/doc/src/manual/style-guide.md index a62f853acd0d3..10355e4d2e311 100644 --- a/doc/src/manual/style-guide.md +++ b/doc/src/manual/style-guide.md @@ -145,10 +145,10 @@ some alternatives to consider: It is usually not much help to construct arrays like the following: ```julia -a = Vector{Union{Int,AbstractString,Tuple,Array}}(uninitialized, n) +a = Vector{Union{Int,AbstractString,Tuple,Array}}(undef, n) ``` -In this case `Vector{Any}(uninitialized, n)` is better. It is also more helpful to the compiler to annotate specific +In this case `Vector{Any}(undef, n)` is better. It is also more helpful to the compiler to annotate specific uses (e.g. `a[i]::Int`) than to try to pack many alternatives into one type. ## Use naming conventions consistent with Julia's `base/` @@ -204,9 +204,9 @@ as applicable: 9. **Varargs**. This refers to arguments that can be listed indefinitely at the end of a function call. - For example, in `Matrix{T}(uninitialized, dims)`, the dimensions can be given as a - [`Tuple`](@ref), e.g. `Matrix{T}(uninitialized, (1,2))`, or as [`Vararg`](@ref)s, - e.g. `Matrix{T}(uninitialized, 1, 2)`. + For example, in `Matrix{T}(undef, dims)`, the dimensions can be given as a + [`Tuple`](@ref), e.g. `Matrix{T}(undef, (1,2))`, or as [`Vararg`](@ref)s, + e.g. `Matrix{T}(undef, 1, 2)`. 10. **Keyword arguments**. In Julia keyword arguments have to come last anyway in function definitions; they're diff --git a/doc/src/manual/variables-and-scoping.md b/doc/src/manual/variables-and-scoping.md index 088aafdb19eb9..38ac858c54197 100644 --- a/doc/src/manual/variables-and-scoping.md +++ b/doc/src/manual/variables-and-scoping.md @@ -359,7 +359,7 @@ something like `let x = x` since the two `x` variables are distinct and have sep Here is an example where the behavior of `let` is needed: ```jldoctest -julia> Fs = Vector{Any}(uninitialized, 2); i = 1; +julia> Fs = Vector{Any}(undef, 2); i = 1; julia> while i <= 2 Fs[i] = ()->i @@ -378,7 +378,7 @@ variable `i`, so the two closures behave identically. We can use `let` to create for `i`: ```jldoctest -julia> Fs = Vector{Any}(uninitialized, 2); i = 1; +julia> Fs = Vector{Any}(undef, 2); i = 1; julia> while i <= 2 let i = i @@ -418,7 +418,7 @@ introduced in their body scopes are freshly allocated for each loop iteration, a were surrounded by a `let` block: ```jldoctest -julia> Fs = Vector{Any}(uninitialized, 2); +julia> Fs = Vector{Any}(undef, 2); julia> for j = 1:2 Fs[j] = ()->j diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 28df69e3949b1..bb9c590ee5df5 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -411,7 +411,7 @@ (block ,(scopenest (cdr names) (cdr vals) expr))))) -(define empty-vector-any '(call (core AnyVector) uninitialized 0)) +(define empty-vector-any '(call (core AnyVector) undef 0)) (define (keywords-method-def-expr name sparams argl body rett) (let* ((kargl (cdar argl)) ;; keyword expressions (= k v) @@ -2430,7 +2430,7 @@ ,.(map (lambda (v r) `(= ,v (call (top length) ,r))) lengths rv) (scope-block (block - (= ,result (call (curly Array ,atype ,(length lengths)) uninitialized ,@lengths)) + (= ,result (call (curly Array ,atype ,(length lengths)) undef ,@lengths)) (= ,ri 1) ,(construct-loops (reverse ranges) (reverse rv) states (reverse lengths)) ,result))))) diff --git a/stdlib/Base64/src/buffer.jl b/stdlib/Base64/src/buffer.jl index 06856a831cd0c..9daff0d1c7a54 100644 --- a/stdlib/Base64/src/buffer.jl +++ b/stdlib/Base64/src/buffer.jl @@ -7,7 +7,7 @@ mutable struct Buffer size::Int function Buffer(bufsize) - data = Vector{UInt8}(uninitialized, bufsize) + data = Vector{UInt8}(undef, bufsize) return new(data, pointer(data), 0) end end diff --git a/stdlib/CRC32c/test/runtests.jl b/stdlib/CRC32c/test/runtests.jl index 33c9c514ebbea..b385880850abc 100644 --- a/stdlib/CRC32c/test/runtests.jl +++ b/stdlib/CRC32c/test/runtests.jl @@ -51,7 +51,7 @@ crc32c_sw(a::Union{Array{UInt8},Base.FastContiguousSubArray{UInt8,N,<:Array{UInt crc32c_sw(s::String, crc::UInt32=0x00000000) = unsafe_crc32c_sw(s, sizeof(s), crc) function crc32c_sw(io::IO, nb::Integer, crc::UInt32=0x00000000) nb < 0 && throw(ArgumentError("number of bytes to checksum must be ≥ 0")) - buf = Vector{UInt8}(uninitialized, min(nb, 24576)) + buf = Vector{UInt8}(undef, min(nb, 24576)) while !eof(io) && nb > 24576 n = readbytes!(io, buf) crc = unsafe_crc32c_sw(buf, n, crc) diff --git a/stdlib/Dates/src/io.jl b/stdlib/Dates/src/io.jl index 93d3fe53431da..deed3a831a569 100644 --- a/stdlib/Dates/src/io.jl +++ b/stdlib/Dates/src/io.jl @@ -481,7 +481,7 @@ end function format(dt::TimeType, fmt::DateFormat, bufsize=12) # preallocate to reduce resizing - io = IOBuffer(Vector{UInt8}(uninitialized, bufsize), read=true, write=true) + io = IOBuffer(Vector{UInt8}(undef, bufsize), read=true, write=true) format(io, dt, fmt) String(io.data[1:io.ptr - 1]) end diff --git a/stdlib/Dates/src/parse.jl b/stdlib/Dates/src/parse.jl index 103815d6f941d..a46638fc97344 100644 --- a/stdlib/Dates/src/parse.jl +++ b/stdlib/Dates/src/parse.jl @@ -298,7 +298,7 @@ number of components may be less than the total number of `DatePart`. values, pos, num_parsed = tryparsenext_core(str, pos, len, df, true) t = values types = $(Expr(:tuple, tokens...)) - result = Vector{Any}(uninitialized, num_parsed) + result = Vector{Any}(undef, num_parsed) for (i, typ) in enumerate(types) i > num_parsed && break result[i] = typ(t[i]) # Constructing types takes most of the time diff --git a/stdlib/Dates/test/ranges.jl b/stdlib/Dates/test/ranges.jl index 4ac7d3e58ff53..5daee3aded8b7 100644 --- a/stdlib/Dates/test/ranges.jl +++ b/stdlib/Dates/test/ranges.jl @@ -309,7 +309,7 @@ end @test_throws MethodError dr .+ 1 a = Dates.DateTime(2013, 1, 1) b = Dates.DateTime(2013, 2, 1) -@test map!(x->x + Dates.Day(1), Vector{Dates.DateTime}(uninitialized, 32), dr) == [(a + Dates.Day(1)):Dates.Day(1):(b + Dates.Day(1));] +@test map!(x->x + Dates.Day(1), Vector{Dates.DateTime}(undef, 32), dr) == [(a + Dates.Day(1)):Dates.Day(1):(b + Dates.Day(1));] @test map(x->x + Dates.Day(1), dr) == [(a + Dates.Day(1)):Dates.Day(1):(b + Dates.Day(1));] @test map(x->a in x, drs[1:4]) == [true, true, false, true] @@ -387,7 +387,7 @@ end @test_throws MethodError dr .+ 1 a = Dates.Date(2013, 1, 1) b = Dates.Date(2013, 2, 1) -@test map!(x->x + Dates.Day(1), Vector{Dates.Date}(uninitialized, 32), dr) == [(a + Dates.Day(1)):Dates.Day(1):(b + Dates.Day(1));] +@test map!(x->x + Dates.Day(1), Vector{Dates.Date}(undef, 32), dr) == [(a + Dates.Day(1)):Dates.Day(1):(b + Dates.Day(1));] @test map(x->x + Dates.Day(1), dr) == [(a + Dates.Day(1)):Dates.Day(1):(b + Dates.Day(1));] @test map(x->a in x, drs[1:4]) == [true, true, false, true] diff --git a/stdlib/DelimitedFiles/src/DelimitedFiles.jl b/stdlib/DelimitedFiles/src/DelimitedFiles.jl index a7f6620fd2e9a..6a2167c1ab27e 100644 --- a/stdlib/DelimitedFiles/src/DelimitedFiles.jl +++ b/stdlib/DelimitedFiles/src/DelimitedFiles.jl @@ -268,8 +268,8 @@ mutable struct DLMOffsets <: DLMHandler bufflen::Int function DLMOffsets(sbuff::String) - offsets = Vector{Vector{Int}}(uninitialized, 1) - offsets[1] = Vector{Int}(uninitialized, offs_chunk_size) + offsets = Vector{Vector{Int}}(undef, 1) + offsets[1] = Vector{Int}(undef, offs_chunk_size) thresh = ceil(min(typemax(UInt), Base.Sys.total_memory()) / sizeof(Int) / 5) new(offsets, 1, thresh, sizeof(sbuff)) end @@ -293,7 +293,7 @@ function store_cell(dlmoffsets::DLMOffsets, row::Int, col::Int, return end end - offsets = Vector{Int}(uninitialized, offs_chunk_size) + offsets = Vector{Int}(undef, offs_chunk_size) push!(oarr, offsets) offidx = 1 end @@ -332,7 +332,7 @@ function DLMStore(::Type{T}, dims::NTuple{2,Integer}, nrows <= 0 && throw(ArgumentError("number of rows in dims must be > 0, got $nrows")) ncols <= 0 && throw(ArgumentError("number of columns in dims must be > 0, got $ncols")) hdr_offset = has_header ? 1 : 0 - DLMStore{T}(fill(SubString(sbuff,1,0), 1, ncols), Matrix{T}(uninitialized, nrows-hdr_offset, ncols), + DLMStore{T}(fill(SubString(sbuff,1,0), 1, ncols), Matrix{T}(undef, nrows-hdr_offset, ncols), nrows, ncols, 0, 0, hdr_offset, sbuff, auto, Char(eol)) end diff --git a/stdlib/DelimitedFiles/test/runtests.jl b/stdlib/DelimitedFiles/test/runtests.jl index ded0dd25bfdf9..f834fea6bc5cb 100644 --- a/stdlib/DelimitedFiles/test/runtests.jl +++ b/stdlib/DelimitedFiles/test/runtests.jl @@ -236,7 +236,7 @@ end for data in ["A B C", "A B C\n"] data,hdr = readdlm(IOBuffer(data), header=true) @test hdr == AbstractString["A" "B" "C"] - @test data == Matrix{Float64}(uninitialized, 0, 3) + @test data == Matrix{Float64}(undef, 0, 3) end end diff --git a/stdlib/Distributed/src/cluster.jl b/stdlib/Distributed/src/cluster.jl index 867b46dd3afb3..a5792ca174077 100644 --- a/stdlib/Distributed/src/cluster.jl +++ b/stdlib/Distributed/src/cluster.jl @@ -590,8 +590,8 @@ end additional_io_objs=Dict() function launch_additional(np::Integer, cmd::Cmd) - io_objs = Vector{Any}(uninitialized, np) - addresses = Vector{Any}(uninitialized, np) + io_objs = Vector{Any}(undef, np) + addresses = Vector{Any}(undef, np) for i in 1:np io = open(detach(cmd), "r+") diff --git a/stdlib/Distributed/src/macros.jl b/stdlib/Distributed/src/macros.jl index 165ed3a987ce5..6443700cc8cd6 100644 --- a/stdlib/Distributed/src/macros.jl +++ b/stdlib/Distributed/src/macros.jl @@ -221,7 +221,7 @@ function splitrange(N::Int, np::Int) each = div(N,np) extras = rem(N,np) nchunks = each > 0 ? np : extras - chunks = Vector{UnitRange{Int}}(uninitialized, nchunks) + chunks = Vector{UnitRange{Int}}(undef, nchunks) lo = 1 for i in 1:nchunks hi = lo + each - 1 diff --git a/stdlib/Distributed/src/managers.jl b/stdlib/Distributed/src/managers.jl index 8a08cfce9f4fd..7e1235a5c83b2 100644 --- a/stdlib/Distributed/src/managers.jl +++ b/stdlib/Distributed/src/managers.jl @@ -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}(uninitialized, length(manager.machines)) + launch_tasks = Vector{Any}(undef, length(manager.machines)) for (i,(machine, cnt)) in enumerate(manager.machines) let machine=machine, cnt=cnt diff --git a/stdlib/Distributed/src/pmap.jl b/stdlib/Distributed/src/pmap.jl index aec5ec9cf01ca..81b6de4e9dd52 100644 --- a/stdlib/Distributed/src/pmap.jl +++ b/stdlib/Distributed/src/pmap.jl @@ -255,7 +255,7 @@ julia> collect(c) ``` """ function head_and_tail(c, n) - head = Vector{eltype(c)}(uninitialized, n) + head = Vector{eltype(c)}(undef, n) s = start(c) i = 0 while i < n && !done(c, s) diff --git a/stdlib/FileWatching/test/runtests.jl b/stdlib/FileWatching/test/runtests.jl index 4a5988206544e..4ec3cc9546858 100644 --- a/stdlib/FileWatching/test/runtests.jl +++ b/stdlib/FileWatching/test/runtests.jl @@ -14,13 +14,13 @@ using Base: uv_error n = 20 intvls = [2, .2, .1, .005] -pipe_fds = Vector{Any}(uninitialized, n) +pipe_fds = Vector{Any}(undef, n) for i in 1:n @static if Sys.iswindows() - pipe_fds[i] = Vector{Libc.WindowsRawSocket}(uninitialized, 2) + pipe_fds[i] = Vector{Libc.WindowsRawSocket}(undef, 2) uv_error("socketpair", ccall(:uv_socketpair, Cint, (Cint, Cint, Ptr{Libc.WindowsRawSocket}, Cint, Cint), 1, 6, pipe_fds[i], 0, 0)) else - pipe_fds[i] = Vector{RawFD}(uninitialized, 2) + pipe_fds[i] = Vector{RawFD}(undef, 2) uv_error("pipe", ccall(:uv_pipe, Cint, (Ptr{RawFD}, Cint, Cint), pipe_fds[i], 0, 0)) end end @@ -43,7 +43,7 @@ function pfd_tst_reads(idx, intvl) # Disabled since this assertion fails randomly, notably on build VMs (issue #12824) # @test t_elapsed <= (intvl + 1) - dout = Vector{UInt8}(uninitialized, 1) + dout = Vector{UInt8}(undef, 1) @static if Sys.iswindows() 1 == ccall(:recv, stdcall, Cint, (Ptr{Cvoid}, Ptr{UInt8}, Cint, Cint), pipe_fds[idx][1], dout, 1, 0) || error(Libc.FormatMessage()) else @@ -78,7 +78,7 @@ for (i, intvl) in enumerate(intvls) @sync begin global ready = 0 global ready_c = Condition() - t = Vector{Task}(uninitialized, n) + t = Vector{Task}(undef, n) for idx in 1:n if isodd(idx) t[idx] = @async pfd_tst_reads(idx, intvl) diff --git a/stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl b/stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl index 64f2c4393aaa3..d21bab552441a 100644 --- a/stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl +++ b/stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl @@ -225,7 +225,7 @@ end function AtA_or_AAt(A::AbstractMatrix{T}) where T Tnew = typeof(zero(T)/sqrt(one(T))) Anew = convert(AbstractMatrix{Tnew}, A) - AtA_or_AAt{Tnew,typeof(Anew)}(Anew, Vector{Tnew}(uninitialized, max(size(A)...))) + AtA_or_AAt{Tnew,typeof(Anew)}(Anew, Vector{Tnew}(undef, max(size(A)...))) end function LinearAlgebra.mul!(y::StridedVector{T}, A::AtA_or_AAt{T}, x::StridedVector{T}) where T diff --git a/stdlib/IterativeEigensolvers/src/arpack.jl b/stdlib/IterativeEigensolvers/src/arpack.jl index 98b69c1ecdde0..359d4c730b065 100644 --- a/stdlib/IterativeEigensolvers/src/arpack.jl +++ b/stdlib/IterativeEigensolvers/src/arpack.jl @@ -14,13 +14,13 @@ function aupd_wrapper(T, matvecA!::Function, matvecB::Function, solveSI::Functio TR = cmplx ? T.types[1] : T TOL = Ref{TR}(tol) - v = Matrix{T}(uninitialized, n, ncv) - workd = Vector{T}(uninitialized, 3*n) - workl = Vector{T}(uninitialized, lworkl) - rwork = cmplx ? Vector{TR}(uninitialized, ncv) : Vector{TR}() + v = Matrix{T}(undef, n, ncv) + workd = Vector{T}(undef, 3*n) + workl = Vector{T}(undef, lworkl) + rwork = cmplx ? Vector{TR}(undef, ncv) : Vector{TR}() if isempty(v0) - resid = Vector{T}(uninitialized, n) + resid = Vector{T}(undef, n) info = Ref{BlasInt}(0) else resid = deepcopy(v0) @@ -108,7 +108,7 @@ function eupd_wrapper(T, n::Integer, sym::Bool, cmplx::Bool, bmat::String, TOL::Ref, resid, ncv::Integer, v, ldv, sigma, iparam, ipntr, workd, workl, lworkl, rwork) howmny = "A" - select = Vector{BlasInt}(uninitialized, ncv) + select = Vector{BlasInt}(undef, ncv) info = Ref{BlasInt}(0) dmap = x -> abs.(x) @@ -125,9 +125,9 @@ function eupd_wrapper(T, n::Integer, sym::Bool, cmplx::Bool, bmat::String, end if cmplx - d = Vector{T}(uninitialized, nev+1) + d = Vector{T}(undef, nev+1) sigmar = Ref{T}(sigma) - workev = Vector{T}(uninitialized, 2ncv) + workev = Vector{T}(undef, 2ncv) neupd(ritzvec, howmny, select, d, v, ldv, sigmar, workev, bmat, n, which, nev, TOL, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, rwork, info) @@ -138,7 +138,7 @@ function eupd_wrapper(T, n::Integer, sym::Bool, cmplx::Bool, bmat::String, p = sortperm(dmap(d[1:nev]), rev=true) return ritzvec ? (d[p], v[1:n, p],iparam[5],iparam[3],iparam[9],resid) : (d[p],iparam[5],iparam[3],iparam[9],resid) elseif sym - d = Vector{T}(uninitialized, nev) + d = Vector{T}(undef, nev) sigmar = Ref{T}(sigma) seupd(ritzvec, howmny, select, d, v, ldv, sigmar, bmat, n, which, nev, TOL, resid, ncv, v, ldv, @@ -150,20 +150,20 @@ function eupd_wrapper(T, n::Integer, sym::Bool, cmplx::Bool, bmat::String, p = sortperm(dmap(d), rev=true) return ritzvec ? (d[p], v[1:n, p],iparam[5],iparam[3],iparam[9],resid) : (d[p],iparam[5],iparam[3],iparam[9],resid) else - dr = Vector{T}(uninitialized, nev+1) - di = Vector{T}(uninitialized, nev+1) + dr = Vector{T}(undef, nev+1) + di = Vector{T}(undef, nev+1) fill!(dr,NaN) fill!(di,NaN) sigmar = Ref{T}(real(sigma)) sigmai = Ref{T}(imag(sigma)) - workev = Vector{T}(uninitialized, 3*ncv) + workev = Vector{T}(undef, 3*ncv) neupd(ritzvec, howmny, select, dr, di, v, ldv, sigmar, sigmai, workev, bmat, n, which, nev, TOL, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info) if info[] != 0 throw(ARPACKException(info[])) end - evec = complex.(Matrix{T}(uninitialized, n, nev+1), Matrix{T}(uninitialized, n, nev+1)) + evec = complex.(Matrix{T}(undef, n, nev+1), Matrix{T}(undef, n, nev+1)) j = 1 while j <= nev diff --git a/stdlib/LinearAlgebra/src/bidiag.jl b/stdlib/LinearAlgebra/src/bidiag.jl index f84b39a0e5109..d0a5ed25523de 100644 --- a/stdlib/LinearAlgebra/src/bidiag.jl +++ b/stdlib/LinearAlgebra/src/bidiag.jl @@ -606,7 +606,7 @@ factorize(A::Bidiagonal) = A eigvals(M::Bidiagonal) = M.dv function eigvecs(M::Bidiagonal{T}) where T n = length(M.dv) - Q = Matrix{T}(uninitialized, n,n) + Q = Matrix{T}(undef, n,n) blks = [0; findall(x -> x == 0, M.ev); n] v = zeros(T, n) if M.uplo == 'U' diff --git a/stdlib/LinearAlgebra/src/dense.jl b/stdlib/LinearAlgebra/src/dense.jl index 240f05cd29f90..819f4f8126aa5 100644 --- a/stdlib/LinearAlgebra/src/dense.jl +++ b/stdlib/LinearAlgebra/src/dense.jl @@ -376,7 +376,7 @@ julia> kron(A, B) ``` """ function kron(a::AbstractMatrix{T}, b::AbstractMatrix{S}) where {T,S} - R = Matrix{promote_op(*,T,S)}(uninitialized, size(a,1)*size(b,1), size(a,2)*size(b,2)) + R = Matrix{promote_op(*,T,S)}(undef, size(a,1)*size(b,1), size(a,2)*size(b,2)) m = 1 for j = 1:size(a,2), l = 1:size(b,2), i = 1:size(a,1) aij = a[i,j] @@ -1275,7 +1275,7 @@ function pinv(A::StridedMatrix{T}, tol::Real) where T m, n = size(A) Tout = typeof(zero(T)/sqrt(one(T) + one(T))) if m == 0 || n == 0 - return Matrix{Tout}(uninitialized, n, m) + return Matrix{Tout}(undef, n, m) end if istril(A) if istriu(A) diff --git a/stdlib/LinearAlgebra/src/deprecated.jl b/stdlib/LinearAlgebra/src/deprecated.jl index 38efdf5f06f96..8cfa45cdd25b7 100644 --- a/stdlib/LinearAlgebra/src/deprecated.jl +++ b/stdlib/LinearAlgebra/src/deprecated.jl @@ -418,22 +418,22 @@ function RowVector{T}(vec::AbstractVector{T}) where {T} end # Constructors that take a size and default to Array -function RowVector{T}(::Uninitialized, n::Int) where {T} +function RowVector{T}(::UndefInitializer, n::Int) where {T} Base.depwarn(_RowVector_depstring(), :RowVector) - return RowVector{T}(Vector{transpose_type(T)}(uninitialized, n)) + return RowVector{T}(Vector{transpose_type(T)}(undef, n)) end -function RowVector{T}(::Uninitialized, n1::Int, n2::Int) where {T} +function RowVector{T}(::UndefInitializer, n1::Int, n2::Int) where {T} Base.depwarn(_RowVector_depstring(), :RowVector) - return n1 == 1 ? RowVector{T}(Vector{transpose_type(T)}(uninitialized, n2)) : + return n1 == 1 ? RowVector{T}(Vector{transpose_type(T)}(undef, n2)) : error("RowVector expects 1×N size, got ($n1,$n2)") end -function RowVector{T}(::Uninitialized, n::Tuple{Int}) where {T} +function RowVector{T}(::UndefInitializer, n::Tuple{Int}) where {T} Base.depwarn(_RowVector_depstring(), :RowVector) - return RowVector{T}(Vector{transpose_type(T)}(uninitialized, n[1])) + return RowVector{T}(Vector{transpose_type(T)}(undef, n[1])) end -function RowVector{T}(::Uninitialized, n::Tuple{Int,Int}) where {T} +function RowVector{T}(::UndefInitializer, n::Tuple{Int,Int}) where {T} Base.depwarn(_RowVector_depstring(), :RowVector) - return n[1] == 1 ? RowVector{T}(Vector{transpose_type(T)}(uninitialized, n[2])) : + return n[1] == 1 ? RowVector{T}(Vector{transpose_type(T)}(undef, n[2])) : error("RowVector expects 1×N size, got $n") end @@ -636,11 +636,11 @@ pinv(v::RowVector, tol::Real=0) = rvadjoint(pinv(rvadjoint(v), tol)) *(A::Transpose{<:Any,<:AbstractVector}, B::Adjoint{<:Any,<:RowVector}) = transpose(A.parent) * B *(A::Transpose{<:Any,<:AbstractMatrix}, B::Adjoint{<:Any,<:RowVector}) = A * rvadjoint(B.parent) -# deprecate RowVector{T}(shape...) constructors to RowVector{T}(uninitialized, shape...) equivalents -@deprecate RowVector{T}(n::Int) where {T} RowVector{T}(uninitialized, n) -@deprecate RowVector{T}(n1::Int, n2::Int) where {T} RowVector{T}(uninitialized, n1, n2) -@deprecate RowVector{T}(n::Tuple{Int}) where {T} RowVector{T}(uninitialized, n) -@deprecate RowVector{T}(n::Tuple{Int,Int}) where {T} RowVector{T}(uninitialized, n) +# deprecate RowVector{T}(shape...) constructors to RowVector{T}(undef, shape...) equivalents +@deprecate RowVector{T}(n::Int) where {T} RowVector{T}(undef, n) +@deprecate RowVector{T}(n1::Int, n2::Int) where {T} RowVector{T}(undef, n1, n2) +@deprecate RowVector{T}(n::Tuple{Int}) where {T} RowVector{T}(undef, n) +@deprecate RowVector{T}(n::Tuple{Int,Int}) where {T} RowVector{T}(undef, n) # operations formerly exported from and imported/extended by LinearAlgebra import Base: A_mul_Bt, At_ldiv_Bt, A_rdiv_Bc, At_ldiv_B, Ac_mul_Bc, A_mul_Bc, Ac_mul_B, diff --git a/stdlib/LinearAlgebra/src/lapack.jl b/stdlib/LinearAlgebra/src/lapack.jl index 6f10121c70f43..226c7aca5d222 100644 --- a/stdlib/LinearAlgebra/src/lapack.jl +++ b/stdlib/LinearAlgebra/src/lapack.jl @@ -286,7 +286,7 @@ for (gebrd, gelqf, geqlf, geqrf, geqp3, geqrt, geqrt3, gerqf, getrf, elty, relty e = similar(A, $relty, k) tauq = similar(A, $elty, k) taup = similar(A, $elty, k) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -320,7 +320,7 @@ for (gebrd, gelqf, geqlf, geqrf, geqp3, geqrt, geqrt3, gerqf, getrf, elty, relty throw(DimensionMismatch("tau has length $(length(tau)), but needs length $(min(m,n))")) end lwork = BlasInt(-1) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($gelqf), liblapack), Cvoid, @@ -350,7 +350,7 @@ for (gebrd, gelqf, geqlf, geqrf, geqp3, geqrt, geqrt3, gerqf, getrf, elty, relty throw(DimensionMismatch("tau has length $(length(tau)), but needs length $(min(m,n))")) end lwork = BlasInt(-1) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($geqlf), liblapack), Cvoid, @@ -385,11 +385,11 @@ for (gebrd, gelqf, geqlf, geqrf, geqp3, geqrt, geqrt3, gerqf, getrf, elty, relty if lda == 0 return A, tau, jpvt end # Early exit - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) cmplx = eltype(A)<:Complex if cmplx - rwork = Vector{$relty}(uninitialized, 2n) + rwork = Vector{$relty}(undef, 2n) end info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -428,7 +428,7 @@ for (gebrd, gelqf, geqlf, geqrf, geqp3, geqrt, geqrt3, gerqf, getrf, elty, relty throw(ArgumentError("block size $nb > $minmn too large")) end lda = max(1, stride(A,2)) - work = Vector{$elty}(uninitialized, nb*n) + work = Vector{$elty}(undef, nb*n) if n > 0 info = Ref{BlasInt}() ccall((@blasfunc($geqrt), liblapack), Cvoid, @@ -478,7 +478,7 @@ for (gebrd, gelqf, geqlf, geqrf, geqp3, geqrt, geqrt3, gerqf, getrf, elty, relty if length(tau) != min(m,n) throw(DimensionMismatch("tau has length $(length(tau)), but needs length $(min(m,n))")) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -507,7 +507,7 @@ for (gebrd, gelqf, geqlf, geqrf, geqp3, geqrt, geqrt3, gerqf, getrf, elty, relty throw(DimensionMismatch("tau has length $(length(tau)), but needs length $(min(m,n))")) end lwork = BlasInt(-1) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($gerqf), liblapack), Cvoid, @@ -763,7 +763,7 @@ for (tzrzf, ormrz, elty) in end lda = max(1, stride(A,2)) tau = similar(A, $elty, m) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -800,7 +800,7 @@ for (tzrzf, ormrz, elty) in l = size(A, 2) - size(A, 1) lda = max(1, stride(A,2)) ldc = max(1, stride(C,2)) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -865,7 +865,7 @@ for (gels, gesv, getrs, getri, elty) in throw(DimensionMismatch("matrix A has dimensions ($m,$n), transposed: $btrn, but leading dimension of B is $(size(B,1))")) end info = Ref{BlasInt}() - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($gels), liblapack), Cvoid, @@ -882,7 +882,7 @@ for (gels, gesv, getrs, getri, elty) in end k = min(m, n) F = m < n ? tril(A[1:k, 1:k]) : triu(A[1:k, 1:k]) - ssr = Vector{$elty}(uninitialized, size(B, 2)) + ssr = Vector{$elty}(undef, size(B, 2)) for i = 1:size(B,2) x = zero($elty) for j = k+1:size(B,1) @@ -954,7 +954,7 @@ for (gels, gesv, getrs, getri, elty) in end lda = max(1,stride(A, 2)) lwork = BlasInt(-1) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($getri), liblapack), Cvoid, @@ -1048,8 +1048,8 @@ for (gesvx, elty) in rcond = Ref{$elty}() ferr = similar(A, $elty, nrhs) berr = similar(A, $elty, nrhs) - work = Vector{$elty}(uninitialized, 4n) - iwork = Vector{BlasInt}(uninitialized, n) + work = Vector{$elty}(undef, 4n) + iwork = Vector{BlasInt}(undef, n) info = Ref{BlasInt}() X = similar(A, $elty, n, nrhs) ccall((@blasfunc($gesvx), liblapack), Cvoid, @@ -1117,8 +1117,8 @@ for (gesvx, elty, relty) in rcond = Ref{$relty}() ferr = similar(A, $relty, nrhs) berr = similar(A, $relty, nrhs) - work = Vector{$elty}(uninitialized, 2n) - rwork = Vector{$relty}(uninitialized, 2n) + work = Vector{$elty}(undef, 2n) + rwork = Vector{$relty}(undef, 2n) info = Ref{BlasInt}() X = similar(A, $elty, n, nrhs) ccall((@blasfunc($gesvx), liblapack), Cvoid, @@ -1212,9 +1212,9 @@ for (gelsd, gelsy, elty) in s = similar(A, $elty, min(m, n)) rnk = Ref{BlasInt}() info = Ref{BlasInt}() - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - iwork = Vector{BlasInt}(uninitialized, 1) + iwork = Vector{BlasInt}(undef, 1) for i = 1:2 # first call returns lwork as work[1] and iwork length as iwork[1] ccall((@blasfunc($gelsd), liblapack), Cvoid, (Ref{BlasInt}, Ref{BlasInt}, Ref{BlasInt}, @@ -1257,7 +1257,7 @@ for (gelsd, gelsy, elty) in ldb = max(1, stride(newB,2)) jpvt = zeros(BlasInt, n) rnk = Ref{BlasInt}() - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -1305,10 +1305,10 @@ for (gelsd, gelsy, elty, relty) in s = similar(A, $relty, min(m, n)) rnk = Ref{BlasInt}() info = Ref{BlasInt}() - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - rwork = Vector{$relty}(uninitialized, 1) - iwork = Vector{BlasInt}(uninitialized, 1) + rwork = Vector{$relty}(undef, 1) + iwork = Vector{BlasInt}(undef, 1) for i = 1:2 # first call returns lwork as work[1], rwork length as rwork[1] and iwork length as iwork[1] ccall((@blasfunc($gelsd), liblapack), Cvoid, (Ref{BlasInt}, Ref{BlasInt}, Ref{BlasInt}, Ptr{$elty}, @@ -1352,9 +1352,9 @@ for (gelsd, gelsy, elty, relty) in ldb = max(1, m, n) jpvt = zeros(BlasInt, n) rnk = Ref{BlasInt}(1) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - rwork = Vector{$relty}(uninitialized, 2n) + rwork = Vector{$relty}(undef, 2n) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($gelsy), liblapack), Cvoid, @@ -1428,7 +1428,7 @@ for (gglse, elty) in ((:dgglse_, :Float64), end X = zeros($elty, n) info = Ref{BlasInt}() - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($gglse), liblapack), Cvoid, @@ -1489,7 +1489,7 @@ for (geev, gesvd, gesdd, ggsvd, elty, relty) in WR = similar(A, $elty, n) WI = similar(A, $elty, n) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -1546,14 +1546,14 @@ for (geev, gesvd, gesdd, ggsvd, elty, relty) in U = similar(A, $elty, (m, 0)) VT = similar(A, $elty, (n, 0)) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) S = similar(A, $relty, minmn) cmplx = eltype(A)<:Complex if cmplx - rwork = Vector{$relty}(uninitialized, job == 'N' ? 7*minmn : minmn*max(5*minmn+7, 2*max(m,n)+2*minmn+1)) + rwork = Vector{$relty}(undef, job == 'N' ? 7*minmn : minmn*max(5*minmn+7, 2*max(m,n)+2*minmn+1)) end - iwork = Vector{BlasInt}(uninitialized, 8*minmn) + iwork = Vector{BlasInt}(undef, 8*minmn) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] if cmplx @@ -1616,10 +1616,10 @@ for (geev, gesvd, gesdd, ggsvd, elty, relty) in S = similar(A, $relty, minmn) U = similar(A, $elty, jobu == 'A' ? (m, m) : (jobu == 'S' ? (m, minmn) : (m, 0))) VT = similar(A, $elty, jobvt == 'A' ? (n, n) : (jobvt == 'S' ? (minmn, n) : (n, 0))) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) cmplx = eltype(A) <: Complex if cmplx - rwork = Vector{$relty}(uninitialized, 5minmn) + rwork = Vector{$relty}(undef, 5minmn) end lwork = BlasInt(-1) info = Ref{BlasInt}() @@ -1684,8 +1684,8 @@ for (geev, gesvd, gesdd, ggsvd, elty, relty) in throw(DimensionMismatch("B has second dimension $(size(B,2)) but needs $n")) end p = size(B, 1) - k = Vector{BlasInt}(uninitialized, 1) - l = Vector{BlasInt}(uninitialized, 1) + k = Vector{BlasInt}(undef, 1) + l = Vector{BlasInt}(undef, 1) lda = max(1,stride(A, 2)) ldb = max(1,stride(B, 2)) alpha = similar(A, $relty, n) @@ -1696,12 +1696,12 @@ for (geev, gesvd, gesdd, ggsvd, elty, relty) in V = jobv == 'V' ? similar(A, $elty, ldv, p) : similar(A, $elty, 0) ldq = max(1, n) Q = jobq == 'Q' ? similar(A, $elty, ldq, n) : similar(A, $elty, 0) - work = Vector{$elty}(uninitialized, max(3n, m, p) + n) + work = Vector{$elty}(undef, max(3n, m, p) + n) cmplx = eltype(A) <: Complex if cmplx - rwork = Vector{$relty}(uninitialized, 2n) + rwork = Vector{$relty}(undef, 2n) end - iwork = Vector{BlasInt}(uninitialized, n) + iwork = Vector{BlasInt}(undef, n) info = Ref{BlasInt}() if cmplx ccall((@blasfunc($ggsvd), liblapack), Cvoid, @@ -1818,9 +1818,9 @@ for (f, elty) in ((:dggsvd3_, :Float64), V = jobv == 'V' ? similar(A, $elty, ldv, p) : similar(A, $elty, 0) ldq = max(1, n) Q = jobq == 'Q' ? similar(A, $elty, ldq, n) : similar(A, $elty, 0) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - iwork = Vector{BlasInt}(uninitialized, n) + iwork = Vector{BlasInt}(undef, n) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($f), liblapack), Cvoid, @@ -1862,8 +1862,8 @@ for (f, elty, relty) in ((:zggsvd3_, :ComplexF64, :Float64), throw(DimensionMismatch("B has second dimension $(size(B,2)) but needs $n")) end p = size(B, 1) - k = Vector{BlasInt}(uninitialized, 1) - l = Vector{BlasInt}(uninitialized, 1) + k = Vector{BlasInt}(undef, 1) + l = Vector{BlasInt}(undef, 1) lda = max(1,stride(A, 2)) ldb = max(1,stride(B, 2)) alpha = similar(A, $relty, n) @@ -1874,10 +1874,10 @@ for (f, elty, relty) in ((:zggsvd3_, :ComplexF64, :Float64), V = jobv == 'V' ? similar(A, $elty, ldv, p) : similar(A, $elty, 0) ldq = max(1, n) Q = jobq == 'Q' ? similar(A, $elty, ldq, n) : similar(A, $elty, 0) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - rwork = Vector{$relty}(uninitialized, 2n) - iwork = Vector{BlasInt}(uninitialized, n) + rwork = Vector{$relty}(undef, 2n) + iwork = Vector{BlasInt}(undef, n) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($f), liblapack), Cvoid, @@ -1975,7 +1975,7 @@ for (geevx, ggev, elty) in abnrm = Ref{$elty}() rconde = similar(A, $elty, n) rcondv = similar(A, $elty, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) iworksize = 0 if sense == 'N' || sense == 'E' @@ -1985,7 +1985,7 @@ for (geevx, ggev, elty) in else throw(ArgumentError("sense must be 'N', 'E', 'V' or 'B', but $sense was passed")) end - iwork = Vector{BlasInt}(uninitialized, iworksize) + iwork = Vector{BlasInt}(undef, iworksize) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($geevx), liblapack), Cvoid, @@ -2049,7 +2049,7 @@ for (geevx, ggev, elty) in throw(ArgumentError("jobvr must be 'V' or 'N', but $jobvr was passed")) end vr = similar(A, $elty, ldvr, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -2128,9 +2128,9 @@ for (geevx, ggev, elty, relty) in abnrm = Ref{$relty}() rconde = similar(A, $relty, n) rcondv = similar(A, $relty, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - rwork = Vector{$relty}(uninitialized, 2n) + rwork = Vector{$relty}(undef, 2n) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($geevx), liblapack), Cvoid, @@ -2194,9 +2194,9 @@ for (geevx, ggev, elty, relty) in throw(ArgumentError("jobvr must be 'V' or 'N', but $jobvr was passed")) end vr = similar(A, $elty, ldvr, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - rwork = Vector{$relty}(uninitialized, 8n) + rwork = Vector{$relty}(undef, 8n) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($ggev), liblapack), Cvoid, @@ -2269,9 +2269,9 @@ for (laic1, elty) in if j != length(w) throw(DimensionMismatch("vectors must have same length, but length of x is $j and length of w is $(length(w))")) end - sestpr = Vector{$elty}(uninitialized, 1) - s = Vector{$elty}(uninitialized, 1) - c = Vector{$elty}(uninitialized, 1) + sestpr = Vector{$elty}(undef, 1) + s = Vector{$elty}(undef, 1) + c = Vector{$elty}(undef, 1) ccall((@blasfunc($laic1), liblapack), Cvoid, (Ref{BlasInt}, Ref{BlasInt}, Ptr{$elty}, Ref{$elty}, Ptr{$elty}, Ref{$elty}, Ptr{$elty}, Ptr{$elty}, @@ -2302,9 +2302,9 @@ for (laic1, elty, relty) in if j != length(w) throw(DimensionMismatch("vectors must have same length, but length of x is $j and length of w is $(length(w))")) end - sestpr = Vector{$relty}(uninitialized, 1) - s = Vector{$elty}(uninitialized, 1) - c = Vector{$elty}(uninitialized, 1) + sestpr = Vector{$relty}(undef, 1) + s = Vector{$elty}(undef, 1) + c = Vector{$elty}(undef, 1) ccall((@blasfunc($laic1), liblapack), Cvoid, (Ref{BlasInt}, Ref{BlasInt}, Ptr{$elty}, Ref{$relty}, Ptr{$elty}, Ref{$elty}, Ptr{$relty}, Ptr{$elty}, @@ -2465,7 +2465,7 @@ for (orglq, orgqr, orgql, orgrq, ormlq, ormqr, ormql, ormrq, gemqrt, elty) in if k > m throw(DimensionMismatch("invalid number of reflectors: k = $k should be <= m = $m")) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -2498,7 +2498,7 @@ for (orglq, orgqr, orgql, orgrq, ormlq, ormqr, ormql, ormrq, gemqrt, elty) in if k > n throw(DimensionMismatch("invalid number of reflectors: k = $k should be <= n = $n")) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -2533,7 +2533,7 @@ for (orglq, orgqr, orgql, orgrq, ormlq, ormqr, ormql, ormrq, gemqrt, elty) in if k > n throw(DimensionMismatch("invalid number of reflectors: k = $k should be <= n = $n")) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -2570,7 +2570,7 @@ for (orglq, orgqr, orgql, orgrq, ormlq, ormqr, ormql, ormrq, gemqrt, elty) in if k > n throw(DimensionMismatch("invalid number of reflectors: k = $k should be <= n = $n")) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -2616,7 +2616,7 @@ for (orglq, orgqr, orgql, orgrq, ormlq, ormqr, ormql, ormrq, gemqrt, elty) in if side == 'R' && k > n throw(DimensionMismatch("invalid number of reflectors: k = $k should be <= n = $n")) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -2662,7 +2662,7 @@ for (orglq, orgqr, orgql, orgrq, ormlq, ormqr, ormql, ormrq, gemqrt, elty) in if side == 'R' && k > n throw(DimensionMismatch("invalid number of reflectors: k = $k should be <= n = $n")) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -2711,7 +2711,7 @@ for (orglq, orgqr, orgql, orgrq, ormlq, ormqr, ormql, ormrq, gemqrt, elty) in if side == 'R' && k > n throw(DimensionMismatch("invalid number of reflectors: k = $k should be <= n = $n")) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -2760,7 +2760,7 @@ for (orglq, orgqr, orgql, orgrq, ormlq, ormqr, ormql, ormrq, gemqrt, elty) in if side == 'R' && k > n throw(DimensionMismatch("invalid number of reflectors: k = $k should be <= n = $n")) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -2817,7 +2817,7 @@ for (orglq, orgqr, orgql, orgrq, ormlq, ormqr, ormql, ormrq, gemqrt, elty) in throw(DimensionMismatch("wrong value for nb = $nb, which must be between 1 and $k")) end ldc = stride(C, 2) - work = Vector{$elty}(uninitialized, wss) + work = Vector{$elty}(undef, wss) info = Ref{BlasInt}() ccall((@blasfunc($gemqrt), liblapack), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, @@ -3031,8 +3031,8 @@ for (posv, potrf, potri, potrs, pstrf, elty, rtyp) in n = checksquare(A) chkuplo(uplo) piv = similar(A, BlasInt, n) - rank = Vector{BlasInt}(uninitialized, 1) - work = Vector{$rtyp}(uninitialized, 2n) + rank = Vector{BlasInt}(undef, 1) + work = Vector{$rtyp}(undef, 2n) info = Ref{BlasInt}() ccall((@blasfunc($pstrf), liblapack), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, Ptr{BlasInt}, @@ -3337,8 +3337,8 @@ for (trcon, trevc, trrfs, elty) in n = checksquare(A) chkuplo(uplo) rcond = Ref{$elty}() - work = Vector{$elty}(uninitialized, 3n) - iwork = Vector{BlasInt}(uninitialized, n) + work = Vector{$elty}(undef, 3n) + iwork = Vector{BlasInt}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($trcon), liblapack), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, @@ -3375,7 +3375,7 @@ for (trcon, trevc, trrfs, elty) in # Allocate m = Ref{BlasInt}() - work = Vector{$elty}(uninitialized, 3n) + work = Vector{$elty}(undef, 3n) info = Ref{BlasInt}() ccall((@blasfunc($trevc), liblapack), Cvoid, @@ -3431,8 +3431,8 @@ for (trcon, trevc, trrfs, elty) in if nrhs != size(X,2) throw(DimensionMismatch("second dimensions of B, $nrhs, and X, $(size(X,2)), must match")) end - work = Vector{$elty}(uninitialized, 3n) - iwork = Vector{BlasInt}(uninitialized, n) + work = Vector{$elty}(undef, 3n) + iwork = Vector{BlasInt}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($trrfs), liblapack), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, @@ -3466,8 +3466,8 @@ for (trcon, trevc, trrfs, elty, relty) in chkuplo(uplo) chkdiag(diag) rcond = Ref{$relty}(1) - work = Vector{$elty}(uninitialized, 2n) - rwork = Vector{$relty}(uninitialized, n) + work = Vector{$elty}(undef, 2n) + rwork = Vector{$relty}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($trcon), liblapack), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, @@ -3505,8 +3505,8 @@ for (trcon, trevc, trrfs, elty, relty) in # Allocate m = Ref{BlasInt}() - work = Vector{$elty}(uninitialized, 2n) - rwork = Vector{$relty}(uninitialized, n) + work = Vector{$elty}(undef, 2n) + rwork = Vector{$relty}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($trevc), liblapack), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ptr{BlasInt}, Ref{BlasInt}, @@ -3561,8 +3561,8 @@ for (trcon, trevc, trrfs, elty, relty) in if nrhs != size(X,2) throw(DimensionMismatch("second dimensions of B, $nrhs, and X, $(size(X,2)), must match")) end - work = Vector{$elty}(uninitialized, 2n) - rwork = Vector{$relty}(uninitialized, n) + work = Vector{$elty}(undef, 2n) + rwork = Vector{$relty}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($trrfs), liblapack), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, @@ -3632,7 +3632,7 @@ for (stev, stebz, stegr, stein, elty) in throw(DimensionMismatch("ev has length $(length(ev)) but needs one less than dv's length, $n)")) end Zmat = similar(dv, $elty, (n, job != 'N' ? n : 0)) - work = Vector{$elty}(uninitialized, max(1, 2n-2)) + work = Vector{$elty}(undef, max(1, 2n-2)) info = Ref{BlasInt}() ccall((@blasfunc($stev), liblapack), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, @@ -3653,13 +3653,13 @@ for (stev, stebz, stegr, stein, elty) in throw(DimensionMismatch("ev has length $(length(ev)) but needs one less than dv's length, $n)")) end m = Ref{BlasInt}() - nsplit = Vector{BlasInt}(uninitialized, 1) + nsplit = Vector{BlasInt}(undef, 1) w = similar(dv, $elty, n) tmp = 0.0 iblock = similar(dv, BlasInt,n) isplit = similar(dv, BlasInt,n) - work = Vector{$elty}(uninitialized, 4*n) - iwork = Vector{BlasInt}(uninitialized, 3*n) + work = Vector{$elty}(undef, 4*n) + iwork = Vector{BlasInt}(undef, 3*n) info = Ref{BlasInt}() ccall((@blasfunc($stebz), liblapack), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, Ref{$elty}, @@ -3683,15 +3683,15 @@ for (stev, stebz, stegr, stein, elty) in throw(DimensionMismatch("ev has length $(length(ev)) but needs one less than dv's length, $n)")) end eev = [ev; zero($elty)] - abstol = Vector{$elty}(uninitialized, 1) + abstol = Vector{$elty}(undef, 1) m = Ref{BlasInt}() w = similar(dv, $elty, n) ldz = jobz == 'N' ? 1 : n Z = similar(dv, $elty, ldz, range == 'I' ? iu-il+1 : n) isuppz = similar(dv, BlasInt, 2*size(Z, 2)) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - iwork = Vector{BlasInt}(uninitialized, 1) + iwork = Vector{BlasInt}(undef, 1) liwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] and liwork as iwork[1] @@ -3748,9 +3748,9 @@ for (stev, stebz, stegr, stein, elty) in isplit[1:length(isplit_in)] = isplit_in end z = similar(dv, $elty,(n,m)) - work = Vector{$elty}(uninitialized, 5*n) - iwork = Vector{BlasInt}(uninitialized, n) - ifail = Vector{BlasInt}(uninitialized, m) + work = Vector{$elty}(undef, 5*n) + iwork = Vector{BlasInt}(undef, n) + ifail = Vector{BlasInt}(undef, m) info = Ref{BlasInt}() ccall((@blasfunc($stein), liblapack), Cvoid, (Ref{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ref{BlasInt}, @@ -3838,7 +3838,7 @@ for (syconv, sysv, sytrf, sytri, sytrs, elty) in chkstride1(A, ipiv) n = checksquare(A) chkuplo(uplo) - work = Vector{$elty}(uninitialized, n) + work = Vector{$elty}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($syconv), liblapack), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, @@ -3864,7 +3864,7 @@ for (syconv, sysv, sytrf, sytri, sytrs, elty) in throw(DimensionMismatch("B has first dimension $(size(B,1)), but needs $n")) end ipiv = similar(A, BlasInt, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -3898,7 +3898,7 @@ for (syconv, sysv, sytrf, sytri, sytrs, elty) in if n == 0 return A, ipiv, zero(BlasInt) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -3926,7 +3926,7 @@ for (syconv, sysv, sytrf, sytri, sytrs, elty) in # chkstride1(A) # n = checksquare(A) # chkuplo(uplo) -# work = Vector{$elty}(uninitialized, 1) +# work = Vector{$elty}(undef, 1) # lwork = BlasInt(-1) # info = Ref{BlasInt}() # for i in 1:2 @@ -3938,7 +3938,7 @@ for (syconv, sysv, sytrf, sytri, sytrs, elty) in # chknonsingular(info[]) # if lwork < 0 # lwork = BlasInt(real(work[1])) -# work = Vector{$elty}(uninitialized, lwork) +# work = Vector{$elty}(undef, lwork) # end # end # A @@ -3955,7 +3955,7 @@ for (syconv, sysv, sytrf, sytri, sytrs, elty) in chkstride1(A, ipiv) n = checksquare(A) chkuplo(uplo) - work = Vector{$elty}(uninitialized, n) + work = Vector{$elty}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($sytri), liblapack), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, @@ -4014,7 +4014,7 @@ for (sysv, sytrf, sytri, sytrs, syconvf, elty) in throw(DimensionMismatch("B has first dimension $(size(B,1)), but needs $n")) end ipiv = similar(A, BlasInt, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -4048,7 +4048,7 @@ for (sysv, sytrf, sytri, sytrs, syconvf, elty) in if n == 0 return A, ipiv, zero(BlasInt) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -4076,7 +4076,7 @@ for (sysv, sytrf, sytri, sytrs, syconvf, elty) in chkstride1(A, ipiv) n = checksquare(A) chkuplo(uplo) - work = Vector{$elty}(uninitialized, n) + work = Vector{$elty}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($sytri), liblapack), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, @@ -4123,7 +4123,7 @@ for (sysv, sytrf, sytri, sytrs, syconvf, elty) in # DOUBLE PRECISION A( LDA, * ), E( * ) function syconvf_rook!(uplo::AbstractChar, way::AbstractChar, A::AbstractMatrix{$elty}, ipiv::AbstractVector{BlasInt}, - e::AbstractVector{$elty} = Vector{$elty}(uninitialized, length(ipiv))) + e::AbstractVector{$elty} = Vector{$elty}(undef, length(ipiv))) # extract n = checksquare(A) lda = max(1, stride(A, 2)) @@ -4174,7 +4174,7 @@ for (syconv, hesv, hetrf, hetri, hetrs, elty, relty) in chkstride1(A,ipiv) n = checksquare(A) chkuplo(uplo) - work = Vector{$elty}(uninitialized, n) + work = Vector{$elty}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($syconv), liblapack), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, @@ -4200,7 +4200,7 @@ for (syconv, hesv, hetrf, hetri, hetrs, elty, relty) in throw(DimensionMismatch("B has first dimension $(size(B,1)), but needs $n")) end ipiv = similar(A, BlasInt, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -4231,7 +4231,7 @@ for (syconv, hesv, hetrf, hetri, hetrs, elty, relty) in n = checksquare(A) chkuplo(uplo) ipiv = similar(A, BlasInt, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i in 1:2 # first call returns lwork as work[1] @@ -4260,7 +4260,7 @@ for (syconv, hesv, hetrf, hetri, hetrs, elty, relty) in # chkstride1(A) # n = checksquare(A) # chkuplo(uplo) -# work = Vector{$elty}(uninitialized, 1) +# work = Vector{$elty}(undef, 1) # lwork = BlasInt(-1) # info = Ref{BlasInt}() # for i in 1:2 @@ -4271,7 +4271,7 @@ for (syconv, hesv, hetrf, hetri, hetrs, elty, relty) in # chklapackerror(info[]) # if lwork < 0 # lwork = BlasInt(real(work[1])) -# work = Vector{$elty}(uninitialized, lwork) +# work = Vector{$elty}(undef, lwork) # end # end # A @@ -4290,7 +4290,7 @@ for (syconv, hesv, hetrf, hetri, hetrs, elty, relty) in chkstride1(A, ipiv) n = checksquare(A) chkuplo(uplo) - work = Vector{$elty}(uninitialized, n) + work = Vector{$elty}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($hetri), liblapack), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, @@ -4346,7 +4346,7 @@ for (hesv, hetrf, hetri, hetrs, elty, relty) in throw(DimensionMismatch("B has first dimension $(size(B,1)), but needs $n")) end ipiv = similar(A, BlasInt, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -4377,7 +4377,7 @@ for (hesv, hetrf, hetri, hetrs, elty, relty) in n = checksquare(A) chkuplo(uplo) ipiv = similar(A, BlasInt, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i in 1:2 # first call returns lwork as work[1] @@ -4406,7 +4406,7 @@ for (hesv, hetrf, hetri, hetrs, elty, relty) in chkstride1(A,ipiv) n = checksquare(A) chkuplo(uplo) - work = Vector{$elty}(uninitialized, n) + work = Vector{$elty}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($hetri), liblapack), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, @@ -4463,7 +4463,7 @@ for (sysv, sytrf, sytri, sytrs, elty, relty) in throw(DimensionMismatch("B has first dimension $(size(B,1)), but needs $n")) end ipiv = similar(A, BlasInt, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -4498,7 +4498,7 @@ for (sysv, sytrf, sytri, sytrs, elty, relty) in if n == 0 return A, ipiv, zero(BlasInt) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -4527,7 +4527,7 @@ for (sysv, sytrf, sytri, sytrs, elty, relty) in # chkstride1(A) # n = checksquare(A) # chkuplo(uplo) -# work = Vector{$elty}(uninitialized, 1) +# work = Vector{$elty}(undef, 1) # lwork = BlasInt(-1) # info = Ref{BlasInt}() # for i in 1:2 @@ -4538,7 +4538,7 @@ for (sysv, sytrf, sytri, sytrs, elty, relty) in # chklapackerror(info[]) # if lwork < 0 # lwork = BlasInt(real(work[1])) -# work = Vector{$elty}(uninitialized, lwork) +# work = Vector{$elty}(undef, lwork) # end # end # A @@ -4556,7 +4556,7 @@ for (sysv, sytrf, sytri, sytrs, elty, relty) in chkstride1(A, ipiv) n = checksquare(A) chkuplo(uplo) - work = Vector{$elty}(uninitialized, n) + work = Vector{$elty}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($sytri), liblapack), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, @@ -4614,7 +4614,7 @@ for (sysv, sytrf, sytri, sytrs, syconvf, elty, relty) in throw(DimensionMismatch("B has first dimension $(size(B,1)), but needs $n")) end ipiv = similar(A, BlasInt, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -4649,7 +4649,7 @@ for (sysv, sytrf, sytri, sytrs, syconvf, elty, relty) in if n == 0 return A, ipiv, zero(BlasInt) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -4678,7 +4678,7 @@ for (sysv, sytrf, sytri, sytrs, syconvf, elty, relty) in chkstride1(A, ipiv) n = checksquare(A) chkuplo(uplo) - work = Vector{$elty}(uninitialized, n) + work = Vector{$elty}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($sytri), liblapack), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, @@ -4724,7 +4724,7 @@ for (sysv, sytrf, sytri, sytrs, syconvf, elty, relty) in # COMPLEX*16 A( LDA, * ), E( * ) function syconvf_rook!(uplo::AbstractChar, way::AbstractChar, A::AbstractMatrix{$elty}, ipiv::AbstractVector{BlasInt}, - e::AbstractVector{$elty} = Vector{$elty}(uninitialized, length(ipiv))) + e::AbstractVector{$elty} = Vector{$elty}(undef, length(ipiv))) chkstride1(A, ipiv, e) # extract @@ -4873,7 +4873,7 @@ for (syev, syevr, sygvd, elty) in chkstride1(A) n = checksquare(A) W = similar(A, $elty, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -4921,9 +4921,9 @@ for (syev, syevr, sygvd, elty) in Z = similar(A, $elty, ldz, n) end isuppz = similar(A, BlasInt, 2*n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - iwork = Vector{BlasInt}(uninitialized, 1) + iwork = Vector{BlasInt}(undef, 1) liwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] and liwork as iwork[1] @@ -4972,9 +4972,9 @@ for (syev, syevr, sygvd, elty) in lda = max(1, stride(A, 2)) ldb = max(1, stride(B, 2)) w = similar(A, $elty, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - iwork = Vector{BlasInt}(uninitialized, 1) + iwork = Vector{BlasInt}(undef, 1) liwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] and liwork as iwork[1] @@ -5017,9 +5017,9 @@ for (syev, syevr, sygvd, elty, relty) in chkstride1(A) n = checksquare(A) W = similar(A, $relty, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - rwork = Vector{$relty}(uninitialized, max(1, 3n-2)) + rwork = Vector{$relty}(undef, max(1, 3n-2)) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($syev), liblapack), Cvoid, @@ -5069,11 +5069,11 @@ for (syev, syevr, sygvd, elty, relty) in Z = similar(A, $elty, ldz, n) end isuppz = similar(A, BlasInt, 2*n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - rwork = Vector{$relty}(uninitialized, 1) + rwork = Vector{$relty}(undef, 1) lrwork = BlasInt(-1) - iwork = Vector{BlasInt}(uninitialized, 1) + iwork = Vector{BlasInt}(undef, 1) liwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1], lrwork as rwork[1] and liwork as iwork[1] @@ -5124,11 +5124,11 @@ for (syev, syevr, sygvd, elty, relty) in lda = max(1, stride(A, 2)) ldb = max(1, stride(B, 2)) w = similar(A, $relty, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - iwork = Vector{BlasInt}(uninitialized, 1) + iwork = Vector{BlasInt}(undef, 1) liwork = BlasInt(-1) - rwork = Vector{$relty}(uninitialized, 1) + rwork = Vector{$relty}(undef, 1) lrwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1], lrwork as rwork[1] and liwork as iwork[1] @@ -5228,7 +5228,7 @@ for (bdsqr, relty, elty) in throw(DimensionMismatch("leading dimension of C, $ldc, must be at least $n")) end # Allocate - work = Vector{$relty}(uninitialized, 4n) + work = Vector{$relty}(undef, 4n) info = Ref{BlasInt}() ccall((@blasfunc($bdsqr), liblapack), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ref{BlasInt}, @@ -5297,8 +5297,8 @@ for (bdsdc, elty) in vt = similar(d, $elty, (ldvt, n)) q = similar(d, $elty, ldq) iq = similar(d, BlasInt, ldiq) - work = Vector{$elty}(uninitialized, lwork) - iwork = Vector{BlasInt}(uninitialized, 8n) + work = Vector{$elty}(undef, lwork) + iwork = Vector{BlasInt}(undef, 8n) info = Ref{BlasInt}() ccall((@blasfunc($bdsdc), liblapack), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ptr{$elty}, @@ -5347,8 +5347,8 @@ for (gecon, elty) in n = checksquare(A) lda = max(1, stride(A, 2)) rcond = Ref{$elty}() - work = Vector{$elty}(uninitialized, 4n) - iwork = Vector{BlasInt}(uninitialized, n) + work = Vector{$elty}(undef, 4n) + iwork = Vector{BlasInt}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($gecon), liblapack), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, @@ -5381,8 +5381,8 @@ for (gecon, elty, relty) in n = checksquare(A) lda = max(1, stride(A, 2)) rcond = Ref{$relty}() - work = Vector{$elty}(uninitialized, 2n) - rwork = Vector{$relty}(uninitialized, 2n) + work = Vector{$elty}(undef, 2n) + rwork = Vector{$relty}(undef, 2n) info = Ref{BlasInt}() ccall((@blasfunc($gecon), liblapack), Cvoid, (Ref{UInt8}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt}, @@ -5423,7 +5423,7 @@ for (gehrd, elty) in n = checksquare(A) chkfinite(A) # balancing routines don't support NaNs and Infs tau = similar(A, $elty, max(0,n - 1)) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -5473,7 +5473,7 @@ for (orghr, elty) in if n - length(tau) != 1 throw(DimensionMismatch("tau has length $(length(tau)), needs $(n - 1)")) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -5529,7 +5529,7 @@ for (ormhr, elty) in throw(DimensionMismatch("A and C matrices are not conformable")) end - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -5568,12 +5568,12 @@ for (gees, gges, elty) in function gees!(jobvs::AbstractChar, A::AbstractMatrix{$elty}) chkstride1(A) n = checksquare(A) - sdim = Vector{BlasInt}(uninitialized, 1) + sdim = Vector{BlasInt}(undef, 1) wr = similar(A, $elty, n) wi = similar(A, $elty, n) vs = similar(A, $elty, jobvs == 'V' ? n : 0, n) ldvs = max(size(vs, 1), 1) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -5618,7 +5618,7 @@ for (gees, gges, elty) in vsl = similar(A, $elty, ldvsl, n) ldvsr = jobvsr == 'V' ? n : 1 vsr = similar(A, $elty, ldvsr, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] @@ -5666,9 +5666,9 @@ for (gees, gges, elty, relty) in w = similar(A, $elty, n) vs = similar(A, $elty, jobvs == 'V' ? n : 1, n) ldvs = max(size(vs, 1), 1) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - rwork = Vector{$relty}(uninitialized, n) + rwork = Vector{$relty}(undef, n) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($gees), liblapack), Cvoid, @@ -5712,9 +5712,9 @@ for (gees, gges, elty, relty) in vsl = similar(A, $elty, ldvsl, n) ldvsr = jobvsr == 'V' ? n : 1 vsr = similar(A, $elty, ldvsr, n) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - rwork = Vector{$relty}(uninitialized, 8n) + rwork = Vector{$relty}(undef, 8n) info = Ref{BlasInt}() for i = 1:2 # first call returns lwork as work[1] ccall((@blasfunc($gges), liblapack), Cvoid, @@ -5780,7 +5780,7 @@ for (trexc, trsen, tgsen, elty) in n = checksquare(T) ldt = max(1, stride(T, 2)) ldq = max(1, stride(Q, 2)) - work = Vector{$elty}(uninitialized, n) + work = Vector{$elty}(undef, n) info = Ref{BlasInt}() ccall((@blasfunc($trexc), liblapack), Cvoid, (Ref{UInt8}, Ref{BlasInt}, @@ -5815,9 +5815,9 @@ for (trexc, trsen, tgsen, elty) in wr = similar(T, $elty, n) wi = similar(T, $elty, n) m = sum(select) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) - iwork = Vector{BlasInt}(uninitialized, 1) + iwork = Vector{BlasInt}(undef, 1) liwork = BlasInt(-1) info = Ref{BlasInt}() select = convert(Array{BlasInt}, select) @@ -5883,9 +5883,9 @@ for (trexc, trsen, tgsen, elty) in alphar = similar(T, $elty, n) beta = similar(T, $elty, n) lwork = BlasInt(-1) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) liwork = BlasInt(-1) - iwork = Vector{BlasInt}(uninitialized, 1) + iwork = Vector{BlasInt}(undef, 1) info = Ref{BlasInt}() select = convert(Array{BlasInt}, select) for i = 1:2 # first call returns lwork as work[1] and liwork as iwork[1] @@ -5964,7 +5964,7 @@ for (trexc, trsen, tgsen, elty, relty) in ldq = max(1, stride(Q, 2)) w = similar(T, $elty, n) m = sum(select) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) lwork = BlasInt(-1) info = Ref{BlasInt}() select = convert(Array{BlasInt}, select) @@ -6027,9 +6027,9 @@ for (trexc, trsen, tgsen, elty, relty) in alpha = similar(T, $elty, n) beta = similar(T, $elty, n) lwork = BlasInt(-1) - work = Vector{$elty}(uninitialized, 1) + work = Vector{$elty}(undef, 1) liwork = BlasInt(-1) - iwork = Vector{BlasInt}(uninitialized, 1) + iwork = Vector{BlasInt}(undef, 1) info = Ref{BlasInt}() select = convert(Array{BlasInt}, select) for i = 1:2 # first call returns lwork as work[1] and liwork as iwork[1] @@ -6112,7 +6112,7 @@ for (fn, elty, relty) in ((:dtrsyl_, :Float64, :Float64), throw(DimensionMismatch("dimensions of A, ($m,$n), and C, ($m1,$n1), must match")) end ldc = max(1, stride(C, 2)) - scale = Vector{$relty}(uninitialized, 1) + scale = Vector{$relty}(undef, 1) info = Ref{BlasInt}() ccall((@blasfunc($fn), liblapack), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ref{BlasInt}, diff --git a/stdlib/LinearAlgebra/src/lu.jl b/stdlib/LinearAlgebra/src/lu.jl index 3dc604869305a..34b6efe660940 100644 --- a/stdlib/LinearAlgebra/src/lu.jl +++ b/stdlib/LinearAlgebra/src/lu.jl @@ -69,7 +69,7 @@ function generic_lufact!(A::StridedMatrix{T}, ::Val{Pivot} = Val(true)) where {T m, n = size(A) minmn = min(m,n) info = 0 - ipiv = Vector{BlasInt}(uninitialized, minmn) + ipiv = Vector{BlasInt}(undef, minmn) @inbounds begin for k = 1:minmn # find index max @@ -396,7 +396,7 @@ end function lufact!(A::Tridiagonal{T,V}, pivot::Union{Val{false}, Val{true}} = Val(true)) where {T,V} n = size(A, 1) info = 0 - ipiv = Vector{BlasInt}(uninitialized, n) + ipiv = Vector{BlasInt}(undef, n) dl = A.dl d = A.d du = A.du diff --git a/stdlib/LinearAlgebra/src/matmul.jl b/stdlib/LinearAlgebra/src/matmul.jl index 6b25d94dbfa53..199a4bde89b0a 100644 --- a/stdlib/LinearAlgebra/src/matmul.jl +++ b/stdlib/LinearAlgebra/src/matmul.jl @@ -344,7 +344,7 @@ function herk_wrapper!(C::Union{StridedMatrix{T}, StridedMatrix{Complex{T}}}, tA end # Result array does not need to be initialized as long as beta==0 - # C = Matrix{T}(uninitialized, mA, mA) + # C = Matrix{T}(undef, mA, mA) if stride(A, 1) == stride(C, 1) == 1 && stride(A, 2) >= size(A, 1) && stride(C, 2) >= size(C, 1) return copytri!(BLAS.herk!('U', tA, one(T), A, zero(T), C), 'U', true) @@ -491,9 +491,9 @@ function generic_matmatmul(tA, tB, A::AbstractVecOrMat{T}, B::AbstractMatrix{S}) end const tilebufsize = 10800 # Approximately 32k/3 -const Abuf = Vector{UInt8}(uninitialized, tilebufsize) -const Bbuf = Vector{UInt8}(uninitialized, tilebufsize) -const Cbuf = Vector{UInt8}(uninitialized, tilebufsize) +const Abuf = Vector{UInt8}(undef, tilebufsize) +const Bbuf = Vector{UInt8}(undef, tilebufsize) +const Cbuf = Vector{UInt8}(undef, tilebufsize) function generic_matmatmul!(C::AbstractMatrix, tA, tB, A::AbstractMatrix, B::AbstractMatrix) mA, nA = lapack_size(tA, A) diff --git a/stdlib/LinearAlgebra/src/qr.jl b/stdlib/LinearAlgebra/src/qr.jl index 543f6600e5ccd..6d944bf5ab776 100644 --- a/stdlib/LinearAlgebra/src/qr.jl +++ b/stdlib/LinearAlgebra/src/qr.jl @@ -162,7 +162,7 @@ end function qrfactPivotedUnblocked!(A::StridedMatrix) m, n = size(A) piv = Vector(UnitRange{BlasInt}(1,n)) - τ = Vector{eltype(A)}(uninitialized, min(m,n)) + τ = Vector{eltype(A)}(undef, min(m,n)) for j = 1:min(m,n) # Find column with maximum norm in trailing submatrix diff --git a/stdlib/LinearAlgebra/src/triangular.jl b/stdlib/LinearAlgebra/src/triangular.jl index d9afabfd36e7c..b6bfcb81b13ad 100644 --- a/stdlib/LinearAlgebra/src/triangular.jl +++ b/stdlib/LinearAlgebra/src/triangular.jl @@ -104,13 +104,13 @@ parent(A::AbstractTriangular) = A.data # then handle all methods that requires specific handling of upper/lower and unit diagonal function Matrix{T}(A::LowerTriangular) where T - B = Matrix{T}(uninitialized, size(A, 1), size(A, 1)) + B = Matrix{T}(undef, size(A, 1), size(A, 1)) copyto!(B, A.data) tril!(B) B end function Matrix{T}(A::UnitLowerTriangular) where T - B = Matrix{T}(uninitialized, size(A, 1), size(A, 1)) + B = Matrix{T}(undef, size(A, 1), size(A, 1)) copyto!(B, A.data) tril!(B) for i = 1:size(B,1) @@ -119,13 +119,13 @@ function Matrix{T}(A::UnitLowerTriangular) where T B end function Matrix{T}(A::UpperTriangular) where T - B = Matrix{T}(uninitialized, size(A, 1), size(A, 1)) + B = Matrix{T}(undef, size(A, 1), size(A, 1)) copyto!(B, A.data) triu!(B) B end function Matrix{T}(A::UnitUpperTriangular) where T - B = Matrix{T}(uninitialized, size(A, 1), size(A, 1)) + B = Matrix{T}(undef, size(A, 1), size(A, 1)) copyto!(B, A.data) triu!(B) for i = 1:size(B,1) @@ -2160,7 +2160,7 @@ function log(A0::UpperTriangular{T}) where T<:BlasFloat R[i+1,i] = R[i,i+1] end x,V = eig(R) - w = Vector{Float64}(uninitialized, m) + w = Vector{Float64}(undef, m) for i = 1:m x[i] = (x[i] + 1) / 2 w[i] = V[1,i]^2 diff --git a/stdlib/LinearAlgebra/src/tridiag.jl b/stdlib/LinearAlgebra/src/tridiag.jl index 74f2016b0c1c5..1baf99202c5e1 100644 --- a/stdlib/LinearAlgebra/src/tridiag.jl +++ b/stdlib/LinearAlgebra/src/tridiag.jl @@ -331,7 +331,7 @@ function inv_usmani(a::V, b::V, c::V) where {T,V<:AbstractVector{T}} for i=n-1:-1:1 φ[i] = b[i]*φ[i+1]-a[i]*c[i]*φ[i+2] end - α = Matrix{T}(uninitialized, n, n) + α = Matrix{T}(undef, n, n) for i=1:n, j=1:n sign = (i+j)%2==0 ? (+) : (-) if i dl2, -1 => dl, 0 => d, 1 => du) @test A\C ≈ D - @test_throws DimensionMismatch LAPACK.gbtrs!('N',2,1,6,AB,ipiv,Matrix{elty}(uninitialized,7,6)) + @test_throws DimensionMismatch LAPACK.gbtrs!('N',2,1,6,AB,ipiv,Matrix{elty}(undef,7,6)) @test_throws LinearAlgebra.LAPACKException LAPACK.gbtrf!(2,1,6,zeros(elty,6,6)) end end @@ -113,9 +113,9 @@ end @testset "geqp3, geqrt error handling" begin @testset for elty in (Float32, Float64, ComplexF32, ComplexF64) - x10, x11 = Vector{elty}.(uninitialized, (10, 11)) - y10, y11 = Vector{LinearAlgebra.BlasInt}.(uninitialized, (10, 11)) - A10x10, A11x10, A10x11, A11x11 = Matrix{elty}.(uninitialized, ((10,10), (11,10), (10,11), (11,11))) + x10, x11 = Vector{elty}.(undef, (10, 11)) + y10, y11 = Vector{LinearAlgebra.BlasInt}.(undef, (10, 11)) + A10x10, A11x10, A10x11, A11x11 = Matrix{elty}.(undef, ((10,10), (11,10), (10,11), (11,11))) @test_throws DimensionMismatch LAPACK.geqlf!(A10x10, x11) @test_throws DimensionMismatch LAPACK.gelqf!(A10x10, x11) @test_throws DimensionMismatch LAPACK.geqp3!(A10x10, y11, x10) @@ -130,8 +130,8 @@ end @testset "gels, gesv, getrs, getri error handling" begin @testset for elty in (Float32, Float64, ComplexF32, ComplexF64) - A10x10, B11x11 = Matrix{elty}.(uninitialized, ((10,10), (11,11))) - x10, x11 = Vector{LinearAlgebra.BlasInt}.(uninitialized, (10, 11)) + A10x10, B11x11 = Matrix{elty}.(undef, ((10,10), (11,11))) + x10, x11 = Vector{LinearAlgebra.BlasInt}.(undef, (10, 11)) @test_throws DimensionMismatch LAPACK.gels!('N',A10x10,B11x11) @test_throws DimensionMismatch LAPACK.gels!('T',A10x10,B11x11) @test_throws DimensionMismatch LAPACK.gesv!(A10x10,B11x11) @@ -259,8 +259,8 @@ end d = rand(elty,10) dl = rand(elty,9) b = rand(elty,10) - y10 = Vector{BlasInt}(uninitialized, 10) - x9, x11 = Vector{elty}.(uninitialized, (9, 11)) + y10 = Vector{BlasInt}(undef, 10) + x9, x11 = Vector{elty}.(undef, (9, 11)) @test_throws DimensionMismatch LAPACK.gttrf!(x11, d, du) @test_throws DimensionMismatch LAPACK.gttrf!(dl, d, x11) @test_throws DimensionMismatch LAPACK.gttrs!('N', x11, d, du, x9, y10, b) @@ -486,8 +486,8 @@ end B = rand(elty,10,10) C = copy(B) @test A\B ≈ LAPACK.ptsv!(rdv,ev,C) - @test_throws DimensionMismatch LAPACK.ptsv!(rdv,Vector{elty}(uninitialized,10),C) - @test_throws DimensionMismatch LAPACK.ptsv!(rdv,ev,Matrix{elty}(uninitialized,11,11)) + @test_throws DimensionMismatch LAPACK.ptsv!(rdv,Vector{elty}(undef,10),C) + @test_throws DimensionMismatch LAPACK.ptsv!(rdv,ev,Matrix{elty}(undef,11,11)) end end @@ -506,12 +506,12 @@ end C = copy(B) if elty <: Complex @test A\B ≈ LAPACK.pttrs!('U',rdv,ev,C) - @test_throws DimensionMismatch LAPACK.pttrs!('U',rdv,Vector{elty}(uninitialized,10),C) - @test_throws DimensionMismatch LAPACK.pttrs!('U',rdv,ev,Matrix{elty}(uninitialized,11,11)) + @test_throws DimensionMismatch LAPACK.pttrs!('U',rdv,Vector{elty}(undef,10),C) + @test_throws DimensionMismatch LAPACK.pttrs!('U',rdv,ev,Matrix{elty}(undef,11,11)) else @test A\B ≈ LAPACK.pttrs!(rdv,ev,C) - @test_throws DimensionMismatch LAPACK.pttrs!(rdv,Vector{elty}(uninitialized,10),C) - @test_throws DimensionMismatch LAPACK.pttrs!(rdv,ev,Matrix{elty}(uninitialized,11,11)) + @test_throws DimensionMismatch LAPACK.pttrs!(rdv,Vector{elty}(undef,10),C) + @test_throws DimensionMismatch LAPACK.pttrs!(rdv,ev,Matrix{elty}(undef,11,11)) end end end @@ -531,11 +531,11 @@ end C = copy(B) D,C = LAPACK.posv!('U',D,C) @test A\B ≈ C - offsizemat = Matrix{elty}(uninitialized, n+1, n+1) + offsizemat = Matrix{elty}(undef, n+1, n+1) @test_throws DimensionMismatch LAPACK.posv!('U', D, offsizemat) @test_throws DimensionMismatch LAPACK.potrs!('U', D, offsizemat) - @test LAPACK.potrs!('U',Matrix{elty}(uninitialized,0,0),elty[]) == elty[] + @test LAPACK.potrs!('U',Matrix{elty}(undef,0,0),elty[]) == elty[] end end diff --git a/stdlib/LinearAlgebra/test/lq.jl b/stdlib/LinearAlgebra/test/lq.jl index 9d6bb406e0964..cfa25a2ba87ab 100644 --- a/stdlib/LinearAlgebra/test/lq.jl +++ b/stdlib/LinearAlgebra/test/lq.jl @@ -78,8 +78,8 @@ rectangularQ(Q::LinearAlgebra.LQPackedQ) = convert(Array, Q) @test a'*q ≈ a'*squareQ(q) atol=100ε @test a'*q' ≈ a'*squareQ(q)' atol=100ε @test_throws DimensionMismatch q*b[1:n1 + 1] - @test_throws DimensionMismatch adjoint(q) * Matrix{eltya}(uninitialized,n+2,n+2) - @test_throws DimensionMismatch Matrix{eltyb}(uninitialized,n+2,n+2)*q + @test_throws DimensionMismatch adjoint(q) * Matrix{eltya}(undef,n+2,n+2) + @test_throws DimensionMismatch Matrix{eltyb}(undef,n+2,n+2)*q if isa(a, DenseArray) && isa(b, DenseArray) # use this to test 2nd branch in mult code pad_a = vcat(I, a) diff --git a/stdlib/LinearAlgebra/test/matmul.jl b/stdlib/LinearAlgebra/test/matmul.jl index ce3dc20c2bcae..5f3d09561bcbc 100644 --- a/stdlib/LinearAlgebra/test/matmul.jl +++ b/stdlib/LinearAlgebra/test/matmul.jl @@ -16,12 +16,12 @@ using LinearAlgebra: mul! ((0,0), (0,4), (0,4)), ((3,0), (0,0), (3,0)), ((0,0), (0,0), (0,0)) ) - @test Matrix{Float64}(uninitialized, dimsA) * Matrix{Float64}(uninitialized, dimsB) == zeros(dimsC) + @test Matrix{Float64}(undef, dimsA) * Matrix{Float64}(undef, dimsB) == zeros(dimsC) end - @test Matrix{Float64}(uninitialized, 5, 0) |> t -> t't == zeros(0,0) - @test Matrix{Float64}(uninitialized, 5, 0) |> t -> t*t' == zeros(5,5) - @test Matrix{ComplexF64}(uninitialized, 5, 0) |> t -> t't == zeros(0,0) - @test Matrix{ComplexF64}(uninitialized, 5, 0) |> t -> t*t' == zeros(5,5) + @test Matrix{Float64}(undef, 5, 0) |> t -> t't == zeros(0,0) + @test Matrix{Float64}(undef, 5, 0) |> t -> t*t' == zeros(5,5) + @test Matrix{ComplexF64}(undef, 5, 0) |> t -> t't == zeros(0,0) + @test Matrix{ComplexF64}(undef, 5, 0) |> t -> t*t' == zeros(5,5) end @testset "2x2 matmul" begin AA = [1 2; 3 4] @@ -41,7 +41,7 @@ end @test *(adjoint(Ai), adjoint(Bi)) == [-28.25-66im 9.75-58im; -26-89im 21-73im] @test_throws DimensionMismatch [1 2; 0 0; 0 0] * [1 2] end - @test_throws DimensionMismatch mul!(Matrix{Float64}(uninitialized,3,3), AA, BB) + @test_throws DimensionMismatch mul!(Matrix{Float64}(undef,3,3), AA, BB) end @testset "3x3 matmul" begin AA = [1 2 3; 4 5 6; 7 8 9].-5 @@ -61,7 +61,7 @@ end @test *(adjoint(Ai), adjoint(Bi)) == [1+2im 20.75+9im -44.75+42im; 19.5+17.5im -54-36.5im 51-14.5im; 13+7.5im 11.25+31.5im -43.25-14.5im] @test_throws DimensionMismatch [1 2 3; 0 0 0; 0 0 0] * [1 2 3] end - @test_throws DimensionMismatch mul!(Matrix{Float64}(uninitialized,4,4), AA, BB) + @test_throws DimensionMismatch mul!(Matrix{Float64}(undef,4,4), AA, BB) end # Generic AbstractArrays @@ -94,7 +94,7 @@ end end AA = rand(1:20, 5, 5) .- 10 BB = rand(1:20, 5, 5) .- 10 - CC = Matrix{Int}(uninitialized, size(AA, 1), size(BB, 2)) + CC = Matrix{Int}(undef, size(AA, 1), size(BB, 2)) for A in (copy(AA), view(AA, 1:5, 1:5)), B in (copy(BB), view(BB, 1:5, 1:5)), C in (copy(CC), view(CC, 1:5, 1:5)) @test *(transpose(A), B) == A'*B @test *(A, transpose(B)) == A*B' @@ -110,7 +110,7 @@ end @test_throws DimensionMismatch LinearAlgebra.mul!(C, adjoint(fill(1,4,4)), transpose(B)) end vv = [1,2] - CC = Matrix{Int}(uninitialized, 2, 2) + CC = Matrix{Int}(undef, 2, 2) for v in (copy(vv), view(vv, 1:2)), C in (copy(CC), view(CC, 1:2, 1:2)) @test @inferred(mul!(C, v, adjoint(v))) == [1 2; 2 4] end @@ -124,12 +124,12 @@ end @test_throws DimensionMismatch LinearAlgebra.generic_matvecmul!(B,'N',A,zeros(6)) end vv = [1,2,3] - CC = Matrix{Int}(uninitialized, 3, 3) + CC = Matrix{Int}(undef, 3, 3) for v in (copy(vv), view(vv, 1:3)), C in (copy(CC), view(CC, 1:3, 1:3)) @test mul!(C, v, transpose(v)) == v*v' end vvf = map(Float64,vv) - CC = Matrix{Float64}(uninitialized, 3, 3) + CC = Matrix{Float64}(undef, 3, 3) for vf in (copy(vvf), view(vvf, 1:3)), C in (copy(CC), view(CC, 1:3, 1:3)) @test mul!(C, vf, transpose(vf)) == vf*vf' end @@ -194,7 +194,7 @@ end Aref = Ai[1:2:2*cutoff, 1:3] @test *(adjoint(Asub), Asub) == *(adjoint(Aref), Aref) - A5x5, A6x5 = Matrix{Float64}.(uninitialized, ((5, 5), (6, 5))) + A5x5, A6x5 = Matrix{Float64}.(undef, ((5, 5), (6, 5))) @test_throws DimensionMismatch LinearAlgebra.syrk_wrapper!(A5x5,'N',A6x5) @test_throws DimensionMismatch LinearAlgebra.herk_wrapper!(A5x5,'N',A6x5) end @@ -208,7 +208,7 @@ end end @testset "mul! (scaling)" begin - A5x5, b5, C5x6 = Array{Float64}.(uninitialized,((5,5), 5, (5,6))) + A5x5, b5, C5x6 = Array{Float64}.(undef,((5,5), 5, (5,6))) for A in (A5x5, view(A5x5, :, :)), b in (b5, view(b5, :)), C in (C5x6, view(C5x6, :, :)) @test_throws DimensionMismatch mul!(A, Diagonal(b), C) end @@ -251,25 +251,25 @@ vecdot_(x,y) = invoke(vecdot, Tuple{Any,Any}, x,y) end @testset "Issue 11978" begin - A = Matrix{Matrix{Float64}}(uninitialized, 2, 2) + A = Matrix{Matrix{Float64}}(undef, 2, 2) A[1,1] = Matrix(1.0I, 3, 3) A[2,2] = Matrix(1.0I, 2, 2) A[1,2] = Matrix(1.0I, 3, 2) A[2,1] = Matrix(1.0I, 2, 3) - b = Vector{Vector{Float64}}(uninitialized, 2) + b = Vector{Vector{Float64}}(undef, 2) b[1] = fill(1., 3) b[2] = fill(1., 2) @test A*b == Vector{Float64}[[2,2,1], [2,2]] end -@test_throws ArgumentError LinearAlgebra.copytri!(Matrix{Float64}(uninitialized,10,10),'Z') +@test_throws ArgumentError LinearAlgebra.copytri!(Matrix{Float64}(undef,10,10),'Z') @testset "gemv! and gemm_wrapper for $elty" for elty in [Float32,Float64,ComplexF64,ComplexF32] - A10x10, x10, x11 = Array{elty}.(uninitialized, ((10,10), 10, 11)) + A10x10, x10, x11 = Array{elty}.(undef, ((10,10), 10, 11)) @test_throws DimensionMismatch LinearAlgebra.gemv!(x10,'N',A10x10,x11) @test_throws DimensionMismatch LinearAlgebra.gemv!(x11,'N',A10x10,x10) - @test LinearAlgebra.gemv!(elty[], 'N', Matrix{elty}(uninitialized,0,0), elty[]) == elty[] - @test LinearAlgebra.gemv!(x10, 'N', Matrix{elty}(uninitialized,10,0), elty[]) == zeros(elty,10) + @test LinearAlgebra.gemv!(elty[], 'N', Matrix{elty}(undef,0,0), elty[]) == elty[] + @test LinearAlgebra.gemv!(x10, 'N', Matrix{elty}(undef,10,0), elty[]) == zeros(elty,10) I0x0 = Matrix{elty}(I, 0, 0) I10x10 = Matrix{elty}(I, 10, 10) diff --git a/stdlib/LinearAlgebra/test/pinv.jl b/stdlib/LinearAlgebra/test/pinv.jl index c903482f806eb..42da2e1b7b791 100644 --- a/stdlib/LinearAlgebra/test/pinv.jl +++ b/stdlib/LinearAlgebra/test/pinv.jl @@ -7,7 +7,7 @@ using Test, LinearAlgebra, Random srand(12345) function hilb(T::Type, n::Integer) - a = Matrix{T}(uninitialized, n, n) + a = Matrix{T}(undef, n, n) for i=1:n for j=1:n a[j,i]=one(T)/(i+j-one(T)) @@ -18,7 +18,7 @@ end hilb(n::Integer) = hilb(Float64,n) function hilb(T::Type, m::Integer, n::Integer) - a = Matrix{T}(uninitialized, m, n) + a = Matrix{T}(undef, m, n) for i=1:n for j=1:m a[j,i]=one(T)/(i+j-one(T)) @@ -65,7 +65,7 @@ tridiag(m::Integer, n::Integer) = tridiag(Float64, m::Integer, n::Integer) function randn_float64(m::Integer, n::Integer) a=randn(m,n) - b = Matrix{Float64}(uninitialized, m, n) + b = Matrix{Float64}(undef, m, n) for i=1:n for j=1:m b[j,i]=convert(Float64,a[j,i]) @@ -76,7 +76,7 @@ end function randn_float32(m::Integer, n::Integer) a=randn(m,n) - b = Matrix{Float32}(uninitialized, m, n) + b = Matrix{Float32}(undef, m, n) for i=1:n for j=1:m b[j,i]=convert(Float32,a[j,i]) diff --git a/stdlib/LinearAlgebra/test/qr.jl b/stdlib/LinearAlgebra/test/qr.jl index 916bd8326bc07..5bd73c4ccd429 100644 --- a/stdlib/LinearAlgebra/test/qr.jl +++ b/stdlib/LinearAlgebra/test/qr.jl @@ -199,7 +199,7 @@ end end @testset "Issue 16520" begin - @test_throws DimensionMismatch Matrix{Float64}(uninitialized,3,2)\(1:5) + @test_throws DimensionMismatch Matrix{Float64}(undef,3,2)\(1:5) end @testset "Issue 22810" begin diff --git a/stdlib/LinearAlgebra/test/svd.jl b/stdlib/LinearAlgebra/test/svd.jl index 8071e604f758a..3af0a4f2e9e04 100644 --- a/stdlib/LinearAlgebra/test/svd.jl +++ b/stdlib/LinearAlgebra/test/svd.jl @@ -63,7 +63,7 @@ a2img = randn(n,n)/2 @test usv\b ≈ a\b if eltya <: BlasFloat - svdz = svdfact!(Matrix{eltya}(uninitialized,0,0)) + svdz = svdfact!(Matrix{eltya}(undef,0,0)) @test svdz.U ≈ Matrix{eltya}(I, 0, 0) @test svdz.S ≈ real(zeros(eltya,0)) @test svdz.Vt ≈ Matrix{eltya}(I, 0, 0) diff --git a/stdlib/LinearAlgebra/test/symmetric.jl b/stdlib/LinearAlgebra/test/symmetric.jl index 4a8e9a174ec20..1d5ed5d5547bc 100644 --- a/stdlib/LinearAlgebra/test/symmetric.jl +++ b/stdlib/LinearAlgebra/test/symmetric.jl @@ -308,14 +308,14 @@ end @test Hermitian(aherm) * a ≈ aherm * a @test a * Hermitian(aherm) ≈ a * aherm @test Hermitian(aherm) * Hermitian(aherm) ≈ aherm*aherm - @test_throws DimensionMismatch Hermitian(aherm) * Vector{eltya}(uninitialized, n+1) + @test_throws DimensionMismatch Hermitian(aherm) * Vector{eltya}(undef, n+1) LinearAlgebra.mul!(C,a,Hermitian(aherm)) @test C ≈ a*aherm @test Symmetric(asym) * Symmetric(asym) ≈ asym*asym @test Symmetric(asym) * a ≈ asym * a @test a * Symmetric(asym) ≈ a * asym - @test_throws DimensionMismatch Symmetric(asym) * Vector{eltya}(uninitialized, n+1) + @test_throws DimensionMismatch Symmetric(asym) * Vector{eltya}(undef, n+1) LinearAlgebra.mul!(C,a,Symmetric(asym)) @test C ≈ a*asym @@ -488,7 +488,7 @@ end end @testset "#25625 recursive transposition" begin - A = Matrix{Matrix{Int}}(uninitialized, 2, 2) + A = Matrix{Matrix{Int}}(undef, 2, 2) A[1,1] = [1 2; 2 3] A[1,2] = [4 5 6; 7 8 9] A[2,1] = [4 7; 5 8; 6 9] @@ -501,7 +501,7 @@ end @test S == transpose(S) == Matrix(S) == Matrix(transpose(S)) == transpose(Matrix(S)) end - B = Matrix{Matrix{Complex{Int}}}(uninitialized, 2, 2) + B = Matrix{Matrix{Complex{Int}}}(undef, 2, 2) B[1,1] = [1 2+im; 2-im 3] B[1,2] = [4 5+1im 6-2im; 7+3im 8-4im 9+5im] B[2,1] = [4 7-3im; 5-1im 8+4im; 6+2im 9-5im] diff --git a/stdlib/LinearAlgebra/test/triangular.jl b/stdlib/LinearAlgebra/test/triangular.jl index bcda98b9f3b3b..35e8fae0b1a9a 100644 --- a/stdlib/LinearAlgebra/test/triangular.jl +++ b/stdlib/LinearAlgebra/test/triangular.jl @@ -245,7 +245,7 @@ for elty1 in (Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFlo @test sqrt(A1) |> t -> t*t ≈ A1 # naivesub errors - @test_throws DimensionMismatch naivesub!(A1,Vector{elty1}(uninitialized,n+1)) + @test_throws DimensionMismatch naivesub!(A1,Vector{elty1}(undef,n+1)) # eigenproblems if !(elty1 in (BigFloat, Complex{BigFloat})) # Not handled yet @@ -359,7 +359,7 @@ for elty1 in (Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFlo @test mul!(similar(B1), transpose(A1), B1) ≈ transpose(A1)*B1 end #error handling - Ann, Bmm, bm = A1, Matrix{eltyB}(uninitialized, n+1, n+1), Vector{eltyB}(uninitialized, n+1) + Ann, Bmm, bm = A1, Matrix{eltyB}(undef, n+1, n+1), Vector{eltyB}(undef, n+1) @test_throws DimensionMismatch lmul!(Ann, bm) @test_throws DimensionMismatch rmul!(Bmm, Ann) @test_throws DimensionMismatch lmul!(transpose(Ann), bm) @@ -378,7 +378,7 @@ for elty1 in (Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFlo @test A1\B' ≈ Matrix(A1)\B' @test transpose(A1)\transpose(B) ≈ transpose(Matrix(A1))\transpose(B) @test A1'\B' ≈ Matrix(A1)'\B' - Ann, bm = A1, Vector{elty1}(uninitialized,n+1) + Ann, bm = A1, Vector{elty1}(undef,n+1) @test_throws DimensionMismatch Ann\bm @test_throws DimensionMismatch Ann'\bm @test_throws DimensionMismatch transpose(Ann)\bm diff --git a/stdlib/LinearAlgebra/test/tridiag.jl b/stdlib/LinearAlgebra/test/tridiag.jl index 367c0f45b7340..b880ae1386037 100644 --- a/stdlib/LinearAlgebra/test/tridiag.jl +++ b/stdlib/LinearAlgebra/test/tridiag.jl @@ -221,7 +221,7 @@ end @test A*LowerTriangular(Matrix(1.0I, n, n)) ≈ fA end @testset "mul! errors" begin - Cnn, Cnm, Cmn = Matrix{elty}.(uninitialized, ((n,n), (n,n+1), (n+1,n))) + Cnn, Cnm, Cmn = Matrix{elty}.(undef, ((n,n), (n,n+1), (n+1,n))) @test_throws DimensionMismatch LinearAlgebra.mul!(Cnn,A,Cnm) @test_throws DimensionMismatch LinearAlgebra.mul!(Cnn,A,Cmn) @test_throws DimensionMismatch LinearAlgebra.mul!(Cnn,B,Cmn) diff --git a/stdlib/Mmap/src/Mmap.jl b/stdlib/Mmap/src/Mmap.jl index 8994ea3d32ed4..9db8d0af97a4b 100644 --- a/stdlib/Mmap/src/Mmap.jl +++ b/stdlib/Mmap/src/Mmap.jl @@ -190,7 +190,7 @@ function mmap(io::IO, len = prod(dims) * sizeof(T) len >= 0 || throw(ArgumentError("requested size must be ≥ 0, got $len")) - len == 0 && return Array{T}(uninitialized, ntuple(x->0,Val(N))) + len == 0 && return Array{T}(undef, ntuple(x->0,Val(N))) len < typemax(Int) - PAGESIZE || throw(ArgumentError("requested size must be < $(typemax(Int)-PAGESIZE), got $len")) offset >= 0 || throw(ArgumentError("requested offset must be ≥ 0, got $offset")) @@ -299,7 +299,7 @@ function mmap(io::IOStream, ::Type{<:BitArray}, dims::NTuple{N,Integer}, throw(ArgumentError("the given file does not contain a valid BitArray of size $(join(dims, 'x')) (open with \"r+\" mode to override)")) end end - B = BitArray{N}(uninitialized, ntuple(i->0,Val(N))...) + B = BitArray{N}(undef, ntuple(i->0,Val(N))...) B.chunks = chunks B.len = n if N != 1 diff --git a/stdlib/Mmap/test/runtests.jl b/stdlib/Mmap/test/runtests.jl index c00c0d3b76057..c38279dee4213 100644 --- a/stdlib/Mmap/test/runtests.jl +++ b/stdlib/Mmap/test/runtests.jl @@ -11,12 +11,12 @@ GC.gc(); GC.gc() GC.gc(); GC.gc() @test Mmap.mmap(file, Array{UInt8,3}, (1,1,11)) == reshape(t,(1,1,11)) GC.gc(); GC.gc() -@test Mmap.mmap(file, Array{UInt8,3}, (11,0,1)) == Array{UInt8}(uninitialized, (0,0,0)) +@test Mmap.mmap(file, Array{UInt8,3}, (11,0,1)) == Array{UInt8}(undef, (0,0,0)) @test Mmap.mmap(file, Vector{UInt8}, (11,)) == t GC.gc(); GC.gc() @test Mmap.mmap(file, Array{UInt8,2}, (1,11)) == t' GC.gc(); GC.gc() -@test Mmap.mmap(file, Array{UInt8,2}, (0,12)) == Array{UInt8}(uninitialized, (0,0)) +@test Mmap.mmap(file, Array{UInt8,2}, (0,12)) == Array{UInt8}(undef, (0,0)) m = Mmap.mmap(file, Array{UInt8,3}, (1,2,1)) @test m == reshape(b"He",(1,2,1)) finalize(m); m=nothing; GC.gc() diff --git a/stdlib/Pkg/src/resolve/interface.jl b/stdlib/Pkg/src/resolve/interface.jl index eae90dc39b0f3..7f8093335a1ef 100644 --- a/stdlib/Pkg/src/resolve/interface.jl +++ b/stdlib/Pkg/src/resolve/interface.jl @@ -52,7 +52,7 @@ mutable struct Interface pdict = Dict{String,Int}(pkgs[i] => i for i = 1:np) # generate spp and pvers - spp = Vector{Int}(uninitialized, np) + spp = Vector{Int}(undef, np) pvers = [VersionNumber[] for i = 1:np] @@ -82,11 +82,11 @@ mutable struct Interface end ## generate wveights: - vweight = Vector{Vector{VersionWeight}}(uninitialized, np) + vweight = Vector{Vector{VersionWeight}}(undef, np) for p0 = 1:np pvers0 = pvers[p0] spp0 = spp[p0] - vweight0 = vweight[p0] = Vector{VersionWeight}(uninitialized, spp0) + vweight0 = vweight[p0] = Vector{VersionWeight}(undef, spp0) for v0 = 1:spp0-1 vweight0[v0] = VersionWeight(pvers0[v0]) end @@ -254,7 +254,7 @@ function enforce_optimality!(sol::Vector{Int}, interface::Interface) # prepare some useful structures # pdeps[p0][v0] has all dependencies of package p0 version v0 - pdeps = [Vector{Requires}(uninitialized, spp[p0]-1) for p0 = 1:np] + pdeps = [Vector{Requires}(undef, spp[p0]-1) for p0 = 1:np] # prevdeps[p1][p0][v0] is the VersionSet of package p1 which package p0 version v0 # depends upon prevdeps = [Dict{Int,Dict{Int,VersionSet}}() for p0 = 1:np] diff --git a/stdlib/Pkg/src/resolve/maxsum.jl b/stdlib/Pkg/src/resolve/maxsum.jl index d001224f85424..4b627dd341222 100644 --- a/stdlib/Pkg/src/resolve/maxsum.jl +++ b/stdlib/Pkg/src/resolve/maxsum.jl @@ -241,7 +241,7 @@ function getsolution(msgs::Messages) fld = msgs.fld np = length(fld) - sol = Vector{Int}(uninitialized, np) + sol = Vector{Int}(undef, np) for p0 = 1:np fld0 = fld[p0] s0 = argmax(fld0) diff --git a/stdlib/Pkg/src/resolve/versionweight.jl b/stdlib/Pkg/src/resolve/versionweight.jl index 60aa2ba700441..07ecfeb2eee18 100644 --- a/stdlib/Pkg/src/resolve/versionweight.jl +++ b/stdlib/Pkg/src/resolve/versionweight.jl @@ -25,7 +25,7 @@ for f in (:-, :+) l0 = min(la, lb) l1 = max(la, lb) ld = la - lb - rv = Vector{T}(uninitialized, l1) + rv = Vector{T}(undef, l1) rf = ($f)(a.rest, b.rest) @inbounds for i = 1:l0 rv[i] = ($f)(av[i], bv[i]) diff --git a/stdlib/Pkg3/src/GraphType.jl b/stdlib/Pkg3/src/GraphType.jl index 64bc1cc281aef..0ddcdb96c4ed7 100644 --- a/stdlib/Pkg3/src/GraphType.jl +++ b/stdlib/Pkg3/src/GraphType.jl @@ -259,7 +259,7 @@ mutable struct Graph local extended_deps let spp = spp # Due to https://github.com/JuliaLang/julia/issues/15276 # Type assert below to help inference - extended_deps = [Vector{Dict{Int,BitVector}}(uninitialized, spp[p0]-1) for p0 = 1:np]::Vector{Vector{Dict{Int,BitVector}}} + extended_deps = [Vector{Dict{Int,BitVector}}(undef, spp[p0]-1) for p0 = 1:np]::Vector{Vector{Dict{Int,BitVector}}} end for p0 = 1:np, v0 = 1:(spp[p0]-1) n2u = Dict{String,UUID}() @@ -294,7 +294,7 @@ mutable struct Graph req_msk = Dict{Int,BitVector}() for (p1, vs) in req pv = pvers[p1] - req_msk_p1 = BitArray(uninitialized, spp[p1] - 1) + req_msk_p1 = BitArray(undef, spp[p1] - 1) @inbounds for i in 1:spp[p1] - 1 req_msk_p1[i] = pv[i] ∈ vs end @@ -983,7 +983,7 @@ function propagate_constraints!(graph::Graph, sources::Set{Int} = Set{Int}(); lo # if an entire row of the sub-mask is false, that version of p1 # is effectively forbidden # (this is just like calling `any` row-wise) - added_constr1 = any!(BitVector(uninitialized, spp[p1]), sub_msk) + added_constr1 = any!(BitVector(undef, spp[p1]), sub_msk) # apply the new constraints, checking for contradictions # (keep the old ones for comparison) gconstr1 = gconstr[p1] diff --git a/stdlib/Pkg3/src/Types.jl b/stdlib/Pkg3/src/Types.jl index 3074494bdfbe0..741e2cb052a31 100644 --- a/stdlib/Pkg3/src/Types.jl +++ b/stdlib/Pkg3/src/Types.jl @@ -264,7 +264,7 @@ Base.isempty(s::VersionSpec) = all(isempty, s.ranges) # Hot code, measure performance before changing function Base.intersect(A::VersionSpec, B::VersionSpec) (isempty(A) || isempty(B)) && return copy(empty_versionspec) - ranges = Vector{VersionRange}(uninitialized, length(A.ranges) * length(B.ranges)) + ranges = Vector{VersionRange}(undef, length(A.ranges) * length(B.ranges)) i = 1 @inbounds for a in A.ranges, b in B.ranges ranges[i] = intersect(a, b) diff --git a/stdlib/Pkg3/src/resolve/MaxSum.jl b/stdlib/Pkg3/src/resolve/MaxSum.jl index 59cb149ced555..635b002408c46 100644 --- a/stdlib/Pkg3/src/resolve/MaxSum.jl +++ b/stdlib/Pkg3/src/resolve/MaxSum.jl @@ -72,7 +72,7 @@ mutable struct Messages initial_fld = [copy(f0) for f0 in fld] # allocate cavity messages - msg = [[Field(uninitialized, spp[p0]) for j1 = 1:length(gadj[p0])] for p0 = 1:np] + msg = [[Field(undef, spp[p0]) for j1 = 1:length(gadj[p0])] for p0 = 1:np] msgs = new(msg, fld, initial_fld) diff --git a/stdlib/Profile/src/Profile.jl b/stdlib/Profile/src/Profile.jl index 5b109d96d2105..0fe5d69f5bcd6 100644 --- a/stdlib/Profile/src/Profile.jl +++ b/stdlib/Profile/src/Profile.jl @@ -470,7 +470,7 @@ function tree_format(lilist::Vector{StackFrame}, counts::Vector{Int}, level::Int ntext = cols - nindent - ndigcounts - ndigline - 5 widthfile = floor(Integer, 0.4ntext) widthfunc = floor(Integer, 0.6ntext) - strs = Vector{String}(uninitialized, length(lilist)) + strs = Vector{String}(undef, length(lilist)) showextra = false if level > nindent nextra = level - nindent @@ -534,9 +534,9 @@ function tree(io::IO, bt::Vector{Vector{UInt64}}, counts::Vector{Int}, end # Generate counts dlen = length(d) - lilist = Vector{StackFrame}(uninitialized, dlen) - group = Vector{Vector{Int}}(uninitialized, dlen) - n = Vector{Int}(uninitialized, dlen) + lilist = Vector{StackFrame}(undef, dlen) + group = Vector{Vector{Int}}(undef, dlen) + n = Vector{Int}(undef, dlen) i = 1 for (key, v) in d lilist[i] = key @@ -557,9 +557,9 @@ function tree(io::IO, bt::Vector{Vector{UInt64}}, counts::Vector{Int}, end # Generate counts, and do the code lookup dlen = length(d) - lilist = Vector{StackFrame}(uninitialized, dlen) - group = Vector{Vector{Int}}(uninitialized, dlen) - n = Vector{Int}(uninitialized, dlen) + lilist = Vector{StackFrame}(undef, dlen) + group = Vector{Vector{Int}}(undef, dlen) + n = Vector{Int}(undef, dlen) i = 1 for (key, v) in d lilist[i] = lidict[key] @@ -662,7 +662,7 @@ truncto(str::Symbol, w::Int) = truncto(string(str), w) # Order alphabetically (file, function) and then by line number function liperm(lilist::Vector{StackFrame}) - comb = Vector{String}(uninitialized, length(lilist)) + comb = Vector{String}(undef, length(lilist)) for i = 1:length(lilist) li = lilist[i] if li != UNKNOWN diff --git a/stdlib/REPL/src/docview.jl b/stdlib/REPL/src/docview.jl index 512a0e8f31689..4db7220020bf0 100644 --- a/stdlib/REPL/src/docview.jl +++ b/stdlib/REPL/src/docview.jl @@ -393,7 +393,7 @@ function levenshtein(s1, s2) a, b = collect(s1), collect(s2) m = length(a) n = length(b) - d = Matrix{Int}(uninitialized, m+1, n+1) + d = Matrix{Int}(undef, m+1, n+1) d[1:m+1, 1] = 0:m d[1, 1:n+1] = 0:n diff --git a/stdlib/Random/src/DSFMT.jl b/stdlib/Random/src/DSFMT.jl index 28ff70fda8d62..fccbcbede6d71 100644 --- a/stdlib/Random/src/DSFMT.jl +++ b/stdlib/Random/src/DSFMT.jl @@ -190,7 +190,7 @@ function dsfmt_jump(s::DSFMT_state, jp::GF2X) index = val[nval - 1] work = zeros(Int32, JN32) rwork = reinterpret(UInt64, work) - dsfmt = Vector{UInt64}(uninitialized, nval >> 1) + dsfmt = Vector{UInt64}(undef, nval >> 1) ccall(:memcpy, Ptr{Cvoid}, (Ptr{UInt64}, Ptr{Int32}, Csize_t), dsfmt, val, (nval - 1) * sizeof(Int32)) dsfmt[end] = UInt64(N*2) diff --git a/stdlib/Random/src/RNGs.jl b/stdlib/Random/src/RNGs.jl index 75fe31d85238c..fa26d349805de 100644 --- a/stdlib/Random/src/RNGs.jl +++ b/stdlib/Random/src/RNGs.jl @@ -10,7 +10,7 @@ if Sys.iswindows() struct RandomDevice <: AbstractRNG buffer::Vector{UInt128} - RandomDevice() = new(Vector{UInt128}(uninitialized, 1)) + RandomDevice() = new(Vector{UInt128}(undef, 1)) end function rand(rd::RandomDevice, sp::SamplerBoolBitInteger) @@ -96,8 +96,8 @@ end MersenneTwister(seed::Vector{UInt32}, state::DSFMT_state) = MersenneTwister(seed, state, - Vector{Float64}(uninitialized, MT_CACHE_F), - Vector{UInt128}(uninitialized, MT_CACHE_I >> 4), + Vector{Float64}(undef, MT_CACHE_F), + Vector{UInt128}(undef, MT_CACHE_I >> 4), MT_CACHE_F, 0) """ diff --git a/stdlib/Random/src/Random.jl b/stdlib/Random/src/Random.jl index aa09b1e830d5f..72fb899d75f80 100644 --- a/stdlib/Random/src/Random.jl +++ b/stdlib/Random/src/Random.jl @@ -223,7 +223,7 @@ end rand(r::AbstractRNG, dims::Integer...) = rand(r, Float64, Dims(dims)) rand( dims::Integer...) = rand(Float64, Dims(dims)) -rand(r::AbstractRNG, X, dims::Dims) = rand!(r, Array{eltype(X)}(uninitialized, dims), X) +rand(r::AbstractRNG, X, dims::Dims) = rand!(r, Array{eltype(X)}(undef, dims), X) rand( X, dims::Dims) = rand(GLOBAL_RNG, X, dims) rand(r::AbstractRNG, X, d::Integer, dims::Integer...) = rand(r, X, Dims((d, dims...))) @@ -232,7 +232,7 @@ rand( X, d::Integer, dims::Integer...) = rand(X, Dims((d, dims... # rand(r, ()) would match both this method and rand(r, dims::Dims) # moreover, a call like rand(r, NotImplementedType()) would be an infinite loop -rand(r::AbstractRNG, ::Type{X}, dims::Dims) where {X} = rand!(r, Array{eltype(X)}(uninitialized, dims), X) +rand(r::AbstractRNG, ::Type{X}, dims::Dims) where {X} = rand!(r, Array{eltype(X)}(undef, dims), X) rand( ::Type{X}, dims::Dims) where {X} = rand(GLOBAL_RNG, X, dims) rand(r::AbstractRNG, ::Type{X}, d::Integer, dims::Integer...) where {X} = rand(r, X, Dims((d, dims...))) diff --git a/stdlib/Random/src/deprecated.jl b/stdlib/Random/src/deprecated.jl index 85a1e61a3a6e1..55cfd2d965b5d 100644 --- a/stdlib/Random/src/deprecated.jl +++ b/stdlib/Random/src/deprecated.jl @@ -5,9 +5,9 @@ Base.@deprecate_binding dSFMT DSFMT # PR #21359 -@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)))) +@deprecate srand(r::MersenneTwister, filename::AbstractString, n::Integer=4) srand(r, read!(filename, Vector{UInt32}(undef, Int(n)))) +@deprecate srand(filename::AbstractString, n::Integer=4) srand(read!(filename, Vector{UInt32}(undef, Int(n)))) +@deprecate MersenneTwister(filename::AbstractString) srand(MersenneTwister(0), read!(filename, Vector{UInt32}(undef, Int(4)))) function randjump(mt::MersenneTwister, jumps::Integer, jumppoly::AbstractString) depwarn("`randjump(rng, jumps, jumppoly::AbstractString)` is deprecated; use `randjump(rng, steps, jumps)` instead", :randjump) diff --git a/stdlib/Random/src/generation.jl b/stdlib/Random/src/generation.jl index cd5b18784ad5b..4d472db2ee63e 100644 --- a/stdlib/Random/src/generation.jl +++ b/stdlib/Random/src/generation.jl @@ -47,7 +47,7 @@ struct SamplerBigFloat{I<:FloatInterval{BigFloat}} <: Sampler{BigFloat} function SamplerBigFloat{I}(prec::Int) where I<:FloatInterval{BigFloat} nlimbs = (prec-1) ÷ bits_in_Limb + 1 - limbs = Vector{Limb}(uninitialized, nlimbs) + limbs = Vector{Limb}(undef, nlimbs) shift = nlimbs * bits_in_Limb - prec new(prec, nlimbs, limbs, shift) end diff --git a/stdlib/Random/src/misc.jl b/stdlib/Random/src/misc.jl index 5aaf8f0335795..eba84047fab6f 100644 --- a/stdlib/Random/src/misc.jl +++ b/stdlib/Random/src/misc.jl @@ -33,11 +33,11 @@ julia> bitrand(rng, 10) true ``` """ -bitrand(r::AbstractRNG, dims::Dims) = rand!(r, BitArray(uninitialized, dims)) -bitrand(r::AbstractRNG, dims::Integer...) = rand!(r, BitArray(uninitialized, convert(Dims, dims))) +bitrand(r::AbstractRNG, dims::Dims) = rand!(r, BitArray(undef, dims)) +bitrand(r::AbstractRNG, dims::Integer...) = rand!(r, BitArray(undef, convert(Dims, dims))) -bitrand(dims::Dims) = rand!(BitArray(uninitialized, dims)) -bitrand(dims::Integer...) = rand!(BitArray(uninitialized, convert(Dims, dims))) +bitrand(dims::Dims) = rand!(BitArray(undef, dims)) +bitrand(dims::Integer...) = rand!(BitArray(undef, convert(Dims, dims))) ## randstring (often useful for temporary filenames/dirnames) @@ -242,7 +242,7 @@ julia> randperm(MersenneTwister(1234), 4) 3 ``` """ -randperm(r::AbstractRNG, n::Integer) = randperm!(r, Vector{Int}(uninitialized, n)) +randperm(r::AbstractRNG, n::Integer) = randperm!(r, Vector{Int}(undef, n)) randperm(n::Integer) = randperm(GLOBAL_RNG, n) """ @@ -255,7 +255,7 @@ optional `rng` argument specifies a random number generator (see # Examples ```jldoctest -julia> randperm!(MersenneTwister(1234), Vector{Int}(uninitialized, 4)) +julia> randperm!(MersenneTwister(1234), Vector{Int}(undef, 4)) 4-element Array{Int64,1}: 2 1 @@ -271,7 +271,7 @@ function randperm!(r::AbstractRNG, a::Array{<:Integer}) mask = 3 @inbounds for i = 2:n j = 1 + rand(r, ltm52(i, mask)) - if i != j # a[i] is uninitialized (and could be #undef) + if i != j # a[i] is undef (and could be #undef) a[i] = a[j] end a[j] = i @@ -303,7 +303,7 @@ julia> randcycle(MersenneTwister(1234), 6) 2 ``` """ -randcycle(r::AbstractRNG, n::Integer) = randcycle!(r, Vector{Int}(uninitialized, n)) +randcycle(r::AbstractRNG, n::Integer) = randcycle!(r, Vector{Int}(undef, n)) randcycle(n::Integer) = randcycle(GLOBAL_RNG, n) """ @@ -315,7 +315,7 @@ The optional `rng` argument specifies a random number generator, see # Examples ```jldoctest -julia> randcycle!(MersenneTwister(1234), Vector{Int}(uninitialized, 6)) +julia> randcycle!(MersenneTwister(1234), Vector{Int}(undef, 6)) 6-element Array{Int64,1}: 3 5 diff --git a/stdlib/Random/src/normal.jl b/stdlib/Random/src/normal.jl index d1d6540be6d6c..f1d5272f38ebe 100644 --- a/stdlib/Random/src/normal.jl +++ b/stdlib/Random/src/normal.jl @@ -176,10 +176,10 @@ for randfun in [:randn, :randexp] $randfun!(A::AbstractArray) = $randfun!(GLOBAL_RNG, A) # generating arrays - $randfun(rng::AbstractRNG, ::Type{T}, dims::Dims ) where {T} = $randfun!(rng, Array{T}(uninitialized, dims)) + $randfun(rng::AbstractRNG, ::Type{T}, dims::Dims ) where {T} = $randfun!(rng, Array{T}(undef, dims)) # Note that this method explicitly does not define $randfun(rng, T), # in order to prevent an infinite recursion. - $randfun(rng::AbstractRNG, ::Type{T}, dim1::Integer, dims::Integer...) where {T} = $randfun!(rng, Array{T}(uninitialized, dim1, dims...)) + $randfun(rng::AbstractRNG, ::Type{T}, dim1::Integer, dims::Integer...) where {T} = $randfun!(rng, Array{T}(undef, dim1, dims...)) $randfun( ::Type{T}, dims::Dims ) where {T} = $randfun(GLOBAL_RNG, T, dims) $randfun( ::Type{T}, dims::Integer... ) where {T} = $randfun(GLOBAL_RNG, T, dims...) $randfun(rng::AbstractRNG, dims::Dims ) = $randfun(rng, Float64, dims) diff --git a/stdlib/Random/test/runtests.jl b/stdlib/Random/test/runtests.jl index 6e738b62e350c..bba4395081e93 100644 --- a/stdlib/Random/test/runtests.jl +++ b/stdlib/Random/test/runtests.jl @@ -55,14 +55,14 @@ end # rand from AbstractArray let mt = MersenneTwister() @test rand(mt, 0:3:1000) in 0:3:1000 - @test issubset(rand!(mt, Vector{Int}(uninitialized, 100), 0:3:1000), 0:3:1000) + @test issubset(rand!(mt, Vector{Int}(undef, 100), 0:3:1000), 0:3:1000) coll = Any[2, UInt128(128), big(619), "string"] @test rand(mt, coll) in coll @test issubset(rand(mt, coll, 2, 3), coll) # check API with default RNG: rand(0:3:1000) - rand!(Vector{Int}(uninitialized, 100), 0:3:1000) + rand!(Vector{Int}(undef, 100), 0:3:1000) rand(coll) rand(coll, 2, 3) end @@ -143,13 +143,13 @@ emantissa = Int64(2)^52 ziggurat_exp_r = parse(BigFloat,"7.69711747013104971404462804811408952334296818528283253278834867283241051210533") exp_section_area = (ziggurat_exp_r + 1)*exp(-ziggurat_exp_r) -ki = Vector{UInt64}(uninitialized, ziggurat_table_size) -wi = Vector{Float64}(uninitialized, ziggurat_table_size) -fi = Vector{Float64}(uninitialized, ziggurat_table_size) +ki = Vector{UInt64}(undef, ziggurat_table_size) +wi = Vector{Float64}(undef, ziggurat_table_size) +fi = Vector{Float64}(undef, ziggurat_table_size) # Tables for exponential variates -ke = Vector{UInt64}(uninitialized, ziggurat_table_size) -we = Vector{Float64}(uninitialized, ziggurat_table_size) -fe = Vector{Float64}(uninitialized, ziggurat_table_size) +ke = Vector{UInt64}(undef, ziggurat_table_size) +we = Vector{Float64}(undef, ziggurat_table_size) +fe = Vector{Float64}(undef, ziggurat_table_size) function randmtzig_fill_ziggurat_tables() # Operates on the global arrays wib = big.(wi) fib = big.(fi) @@ -263,8 +263,8 @@ let mt = MersenneTwister(0) srand(mt, 0) for (i,T) in enumerate([Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, Float16, Float32]) - A = Vector{T}(uninitialized, 16) - B = Vector{T}(uninitialized, 31) + A = Vector{T}(undef, 16) + B = Vector{T}(undef, 31) rand!(mt, A) rand!(mt, B) @test A[end] == Any[21, 0x7b, 17385, 0x3086, -1574090021, 0xadcb4460, 6797283068698303107, 0xc8e6453e139271f3, @@ -274,7 +274,7 @@ let mt = MersenneTwister(0) end srand(mt, 0) - AF64 = Vector{Float64}(uninitialized, Random.dsfmt_get_min_array_size()-1) + AF64 = Vector{Float64}(undef, Random.dsfmt_get_min_array_size()-1) @test rand!(mt, AF64)[end] == 0.957735065345398 @test rand!(mt, AF64)[end] == 0.6492481059865669 resize!(AF64, 2*length(mt.vals)) @@ -286,8 +286,8 @@ end let mt = MersenneTwister(0) a = Vector{Float64}() resize!(a, 1000) # could be 8-byte aligned - b = Vector{Float64}(uninitialized, 1000) # should be 16-byte aligned - c8 = Vector{UInt64}(uninitialized, 1001) + b = Vector{Float64}(undef, 1000) # should be 16-byte aligned + c8 = Vector{UInt64}(undef, 1001) pc8 = pointer(c8) if Int(pc8) % 16 == 0 # Make sure pc8 is not 16-byte aligned since that's what we want to test. @@ -359,12 +359,12 @@ for rng in ([], [MersenneTwister(0)], [RandomDevice()]) a2 = rand(rng..., C, 2, 3) ::Array{T, 2} a3 = rand(rng..., C, (2, 3)) ::Array{T, 2} a4 = rand(rng..., C, b2, u3) ::Array{T, 2} - a5 = rand!(rng..., Array{T}(uninitialized, 5), C) ::Vector{T} - a6 = rand!(rng..., Array{T}(uninitialized, 2, 3), C) ::Array{T, 2} - a7 = rand!(rng..., GenericArray{T}(uninitialized, 5), C) ::GenericArray{T, 1} - a8 = rand!(rng..., GenericArray{T}(uninitialized, 2, 3), C) ::GenericArray{T, 2} - a9 = rand!(rng..., OffsetArray(Array{T}(uninitialized, 5), 9), C) ::OffsetArray{T, 1} - a10 = rand!(rng..., OffsetArray(Array{T}(uninitialized, 2, 3), (-2, 4)), C) ::OffsetArray{T, 2} + a5 = rand!(rng..., Array{T}(undef, 5), C) ::Vector{T} + a6 = rand!(rng..., Array{T}(undef, 2, 3), C) ::Array{T, 2} + a7 = rand!(rng..., GenericArray{T}(undef, 5), C) ::GenericArray{T, 1} + a8 = rand!(rng..., GenericArray{T}(undef, 2, 3), C) ::GenericArray{T, 2} + a9 = rand!(rng..., OffsetArray(Array{T}(undef, 5), 9), C) ::OffsetArray{T, 1} + a10 = rand!(rng..., OffsetArray(Array{T}(undef, 2, 3), (-2, 4)), C) ::OffsetArray{T, 2} @test size(a1) == (5,) @test size(a2) == size(a3) == (2, 3) for a in [a0, a1..., a2..., a3..., a4..., a5..., a6..., a7..., a8..., a9..., a10...] @@ -384,12 +384,12 @@ for rng in ([], [MersenneTwister(0)], [RandomDevice()]) for f! in [rand!, randn!, randexp!] for T in functypes[f!] X = T == Bool ? T[0,1] : T[0,1,2] - for A in (Vector{T}(uninitialized, 5), - Matrix{T}(uninitialized, 2, 3), - GenericArray{T}(uninitialized, 5), - GenericArray{T}(uninitialized, 2, 3), - OffsetArray(Array{T}(uninitialized, 5), -3), - OffsetArray(Array{T}(uninitialized, 2, 3), (4, 5))) + for A in (Vector{T}(undef, 5), + Matrix{T}(undef, 2, 3), + GenericArray{T}(undef, 5), + GenericArray{T}(undef, 2, 3), + OffsetArray(Array{T}(undef, 5), -3), + OffsetArray(Array{T}(undef, 2, 3), (4, 5))) local A f!(rng..., A) ::typeof(A) if f! === rand! @@ -406,8 +406,8 @@ for rng in ([], [MersenneTwister(0)], [RandomDevice()]) bitrand(rng..., 5) ::BitArray{1} bitrand(rng..., 2, 3) ::BitArray{2} bitrand(rng..., b2, u3) ::BitArray{2} - rand!(rng..., BitVector(uninitialized, 5)) ::BitArray{1} - rand!(rng..., BitMatrix(uninitialized, 2, 3)) ::BitArray{2} + rand!(rng..., BitVector(undef, 5)) ::BitArray{1} + rand!(rng..., BitMatrix(undef, 2, 3)) ::BitArray{2} # Test that you cannot call randn or randexp with non-Float types. for r in [randn, randexp, randn!, randexp!] @@ -483,7 +483,7 @@ let mta = MersenneTwister(42), mtb = MersenneTwister(42) @test eltype(randperm(UInt(1))) === Int @test_throws ErrorException randperm(-1) - A, B = Vector{Int}(uninitialized, 10), Vector{Int}(uninitialized, 10) + A, B = Vector{Int}(undef, 10), Vector{Int}(undef, 10) @test randperm!(mta, A) == randperm!(mtb, B) @test randperm!(A) === A diff --git a/stdlib/SHA/src/SHA.jl b/stdlib/SHA/src/SHA.jl index 37c5b5c1cdf88..00296effd28a2 100644 --- a/stdlib/SHA/src/SHA.jl +++ b/stdlib/SHA/src/SHA.jl @@ -64,7 +64,7 @@ for (f, ctx) in [(:sha1, :SHA1_CTX), # done function $f(io::IO, chunk_size=4*1024) ctx = $ctx() - buff = Vector{UInt8}(uninitialized, chunk_size) + buff = Vector{UInt8}(undef, chunk_size) while !eof(io) num_read = readbytes!(io, buff) update!(ctx, buff[1:num_read]) diff --git a/stdlib/SHA/src/types.jl b/stdlib/SHA/src/types.jl index e5bf01760edbc..2bacc4aea5301 100644 --- a/stdlib/SHA/src/types.jl +++ b/stdlib/SHA/src/types.jl @@ -115,10 +115,10 @@ SHA2_256_CTX() = SHA2_256_CTX(copy(SHA2_256_initial_hash_value), 0, zeros(UInt8, SHA2_384_CTX() = SHA2_384_CTX(copy(SHA2_384_initial_hash_value), 0, zeros(UInt8, blocklen(SHA2_384_CTX))) SHA2_512_CTX() = SHA2_512_CTX(copy(SHA2_512_initial_hash_value), 0, zeros(UInt8, blocklen(SHA2_512_CTX))) -SHA3_224_CTX() = SHA3_224_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_224_CTX)), Vector{UInt64}(uninitialized, 5)) -SHA3_256_CTX() = SHA3_256_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_256_CTX)), Vector{UInt64}(uninitialized, 5)) -SHA3_384_CTX() = SHA3_384_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_384_CTX)), Vector{UInt64}(uninitialized, 5)) -SHA3_512_CTX() = SHA3_512_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_512_CTX)), Vector{UInt64}(uninitialized, 5)) +SHA3_224_CTX() = SHA3_224_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_224_CTX)), Vector{UInt64}(undef, 5)) +SHA3_256_CTX() = SHA3_256_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_256_CTX)), Vector{UInt64}(undef, 5)) +SHA3_384_CTX() = SHA3_384_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_384_CTX)), Vector{UInt64}(undef, 5)) +SHA3_512_CTX() = SHA3_512_CTX(zeros(UInt64, 25), 0, zeros(UInt8, blocklen(SHA3_512_CTX)), Vector{UInt64}(undef, 5)) # Nickname'd outer constructor methods for SHA2 const SHA224_CTX = SHA2_224_CTX @@ -127,13 +127,13 @@ const SHA384_CTX = SHA2_384_CTX const SHA512_CTX = SHA2_512_CTX # SHA1 is special; he needs extra workspace -SHA1_CTX() = SHA1_CTX(copy(SHA1_initial_hash_value), 0, zeros(UInt8, blocklen(SHA1_CTX)), Vector{UInt32}(uninitialized, 80)) +SHA1_CTX() = SHA1_CTX(copy(SHA1_initial_hash_value), 0, zeros(UInt8, blocklen(SHA1_CTX)), Vector{UInt32}(undef, 80)) # Copy functions copy(ctx::T) where {T<:SHA1_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), copy(ctx.W)) copy(ctx::T) where {T<:SHA2_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer)) -copy(ctx::T) where {T<:SHA3_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), Vector{UInt64}(uninitialized, 5)) +copy(ctx::T) where {T<:SHA3_CTX} = T(copy(ctx.state), ctx.bytecount, copy(ctx.buffer), Vector{UInt64}(undef, 5)) # Make printing these types a little friendlier diff --git a/stdlib/Serialization/src/Serialization.jl b/stdlib/Serialization/src/Serialization.jl index 6b2e423e9a8c6..062fdccf93a68 100644 --- a/stdlib/Serialization/src/Serialization.jl +++ b/stdlib/Serialization/src/Serialization.jl @@ -919,7 +919,7 @@ function deserialize_array(s::AbstractSerializer) end if isa(d1, Integer) if elty !== Bool && isbits(elty) - a = Vector{elty}(uninitialized, d1) + a = Vector{elty}(undef, d1) s.table[slot] = a return read!(s.io, a) end @@ -930,7 +930,7 @@ function deserialize_array(s::AbstractSerializer) if isbits(elty) n = prod(dims)::Int if elty === Bool && n > 0 - A = Array{Bool, length(dims)}(uninitialized, dims) + A = Array{Bool, length(dims)}(undef, dims) i = 1 while i <= n b = read(s.io, UInt8)::UInt8 @@ -943,12 +943,12 @@ function deserialize_array(s::AbstractSerializer) end end else - A = read!(s.io, Array{elty}(uninitialized, dims)) + A = read!(s.io, Array{elty}(undef, dims)) end s.table[slot] = A return A end - A = Array{elty, length(dims)}(uninitialized, dims) + A = Array{elty, length(dims)}(undef, dims) s.table[slot] = A sizehint!(s.table, s.counter + div(length(A),4)) for i = eachindex(A) diff --git a/stdlib/Serialization/test/runtests.jl b/stdlib/Serialization/test/runtests.jl index 0a3e66dadf0db..2de895658cc69 100644 --- a/stdlib/Serialization/test/runtests.jl +++ b/stdlib/Serialization/test/runtests.jl @@ -235,7 +235,7 @@ create_serialization_stream() do s # small 1d array arr4 = reshape([true, false, false, false, true, false, false, false, true], 3, 3) serialize(s, arr4) # boolean array - arr5 = Vector{TA1}(uninitialized, 3) + arr5 = Vector{TA1}(undef, 3) arr5[2] = TA1(0x01) serialize(s, arr5) diff --git a/stdlib/SharedArrays/src/SharedArrays.jl b/stdlib/SharedArrays/src/SharedArrays.jl index 38171c6e11c82..20cbdb7afd101 100644 --- a/stdlib/SharedArrays/src/SharedArrays.jl +++ b/stdlib/SharedArrays/src/SharedArrays.jl @@ -43,7 +43,7 @@ mutable struct SharedArray{T,N} <: DenseArray{T,N} loc_subarr_1d::SubArray{T,1,Array{T,1},Tuple{UnitRange{Int}},true} function SharedArray{T,N}(d,p,r,sn,s) where {T,N} - S = new(RRID(),d,p,r,sn,s,0,view(Array{T}(uninitialized, ntuple(d->0,N)), 1:0)) + S = new(RRID(),d,p,r,sn,s,0,view(Array{T}(undef, ntuple(d->0,N)), 1:0)) sa_refs[S.id] = WeakRef(S) S end @@ -109,7 +109,7 @@ function SharedArray{T,N}(dims::Dims{N}; init=false, pids=Int[]) where {T,N} pids, onlocalhost = shared_pids(pids) local shm_seg_name = "" - local s = Array{T}(uninitialized, ntuple(d->0,N)) + local s = Array{T}(undef, ntuple(d->0,N)) local S local shmmem_create_pid try @@ -129,7 +129,7 @@ function SharedArray{T,N}(dims::Dims{N}; init=false, pids=Int[]) where {T,N} func_mapshmem = () -> shm_mmap_array(T, dims, shm_seg_name, JL_O_RDWR) - refs = Vector{Future}(uninitialized, length(pids)) + refs = Vector{Future}(undef, length(pids)) for (i, p) in enumerate(pids) refs[i] = remotecall(func_mapshmem, p) end @@ -206,11 +206,11 @@ function SharedArray{T,N}(filename::AbstractString, dims::NTuple{N,Int}, offset: end # Create the file if it doesn't exist, map it if it does - refs = Vector{Future}(uninitialized, length(pids)) + refs = Vector{Future}(undef, length(pids)) func_mmap = mode -> open(filename, mode) do io Mmap.mmap(io, Array{T,N}, dims, offset; shared=true) end - s = Array{T}(uninitialized, ntuple(d->0,N)) + s = Array{T}(undef, ntuple(d->0,N)) if onlocalhost s = func_mmap(mode) refs[1] = remotecall(pids[1]) do @@ -271,7 +271,7 @@ function finalize_refs(S::SharedArray{T,N}) where T where N empty!(S.pids) empty!(S.refs) init_loc_flds(S) - S.s = Array{T}(uninitialized, ntuple(d->0,N)) + S.s = Array{T}(undef, ntuple(d->0,N)) delete!(sa_refs, S.id) end S @@ -290,7 +290,7 @@ function reshape(a::SharedArray{T}, dims::NTuple{N,Int}) where {T,N} if length(a) != prod(dims) throw(DimensionMismatch("dimensions must be consistent with array size")) end - refs = Vector{Future}(uninitialized, length(a.pids)) + refs = Vector{Future}(undef, length(a.pids)) for (i, p) in enumerate(a.pids) refs[i] = remotecall(p, a.refs[i], dims) do r,d reshape(fetch(r),d) @@ -421,9 +421,9 @@ function init_loc_flds(S::SharedArray{T,N}, empty_local=false) where T where N else S.pidx = 0 if empty_local - S.s = Array{T}(uninitialized, ntuple(d->0,N)) + S.s = Array{T}(undef, ntuple(d->0,N)) end - S.loc_subarr_1d = view(Array{T}(uninitialized, ntuple(d->0,N)), 1:0) + S.loc_subarr_1d = view(Array{T}(undef, ntuple(d->0,N)), 1:0) end end @@ -632,7 +632,7 @@ function shm_mmap_array(T, dims, shm_seg_name, mode) local A = nothing if (prod(dims) == 0) || (sizeof(T) == 0) - return Array{T}(uninitialized, dims) + return Array{T}(undef, dims) end try diff --git a/stdlib/SharedArrays/test/runtests.jl b/stdlib/SharedArrays/test/runtests.jl index d29c6fc78a9b3..f71494f7945ed 100644 --- a/stdlib/SharedArrays/test/runtests.jl +++ b/stdlib/SharedArrays/test/runtests.jl @@ -42,7 +42,7 @@ end d = SharedArrays.shmem_rand(1:100, dims) a = convert(Array, d) -partsums = Vector{Int}(uninitialized, length(procs(d))) +partsums = Vector{Int}(undef, length(procs(d))) @sync begin for (i, p) in enumerate(procs(d)) @async partsums[i] = remotecall_fetch(p, d) do D @@ -137,7 +137,7 @@ write(fn3, fill(0x1, 4)) S = SharedArray{UInt8}(fn3, sz, 4, mode="a+", init=D->D[localindices(D)]=0x02) len = prod(sz)+4 @test filesize(fn3) == len -filedata = Vector{UInt8}(uninitialized, len) +filedata = Vector{UInt8}(undef, len) read!(fn3, filedata) @test all(filedata[1:4] .== 0x01) @test all(filedata[5:end] .== 0x02) diff --git a/stdlib/Sockets/src/addrinfo.jl b/stdlib/Sockets/src/addrinfo.jl index ccd607618ba02..dc4c8e1f8edad 100644 --- a/stdlib/Sockets/src/addrinfo.jl +++ b/stdlib/Sockets/src/addrinfo.jl @@ -224,7 +224,7 @@ function getipaddr() return rv # Uncomment to enbable IPv6 #elseif ccall(:jl_sockaddr_in_is_ip6, Int32, (Ptr{Cvoid},), sockaddr) == 1 - # host = Vector{UInt128}(uninitialized, 1) + # host = Vector{UInt128}(undef, 1) # ccall(:jl_sockaddr_host6, UInt32, (Ptr{Cvoid}, Ptr{UInt128}), sockaddrr, host) # return IPv6(ntoh(host[1])) end diff --git a/stdlib/SparseArrays/src/abstractsparse.jl b/stdlib/SparseArrays/src/abstractsparse.jl index 30f28a3b4bc59..2a50f98dc7797 100644 --- a/stdlib/SparseArrays/src/abstractsparse.jl +++ b/stdlib/SparseArrays/src/abstractsparse.jl @@ -86,7 +86,7 @@ function findnz(A::AbstractMatrix{T}) where T nnzA = count(t -> t != 0, A) I = zeros(Int, nnzA) J = zeros(Int, nnzA) - NZs = Vector{T}(uninitialized, nnzA) + NZs = Vector{T}(undef, nnzA) cnt = 1 if nnzA > 0 for j=axes(A,2), i=axes(A,1) @@ -104,8 +104,8 @@ end function findnz(B::BitMatrix) nnzB = count(B) - I = Vector{Int}(uninitialized, nnzB) - J = Vector{Int}(uninitialized, nnzB) + I = Vector{Int}(undef, nnzB) + J = Vector{Int}(undef, nnzB) cnt = 1 for j = 1:size(B,2), i = 1:size(B,1) if B[i,j] diff --git a/stdlib/SparseArrays/src/higherorderfns.jl b/stdlib/SparseArrays/src/higherorderfns.jl index abbbd9dfb92df..c8dd1c14f58ab 100644 --- a/stdlib/SparseArrays/src/higherorderfns.jl +++ b/stdlib/SparseArrays/src/higherorderfns.jl @@ -153,14 +153,14 @@ _maxnnzfrom(shape::NTuple{2}, A::SparseMatrixCSC) = nnz(A) * div(shape[1], A.m) @inline _checked_maxnnzbcres(shape::NTuple{1}, As...) = shape[1] != 0 ? _unchecked_maxnnzbcres(shape, As) : 0 @inline _checked_maxnnzbcres(shape::NTuple{2}, As...) = shape[1] != 0 && shape[2] != 0 ? _unchecked_maxnnzbcres(shape, As) : 0 @inline function _allocres(shape::NTuple{1}, indextype, entrytype, maxnnz) - storedinds = Vector{indextype}(uninitialized, maxnnz) - storedvals = Vector{entrytype}(uninitialized, maxnnz) + storedinds = Vector{indextype}(undef, maxnnz) + storedvals = Vector{entrytype}(undef, maxnnz) return SparseVector(shape..., storedinds, storedvals) end @inline function _allocres(shape::NTuple{2}, indextype, entrytype, maxnnz) - pointers = Vector{indextype}(uninitialized, shape[2] + 1) - storedinds = Vector{indextype}(uninitialized, maxnnz) - storedvals = Vector{entrytype}(uninitialized, maxnnz) + pointers = Vector{indextype}(undef, shape[2] + 1) + storedinds = Vector{indextype}(undef, maxnnz) + storedvals = Vector{entrytype}(undef, maxnnz) return SparseMatrixCSC(shape..., pointers, storedinds, storedvals) end # Ambiguity killers, TODO: nix conflicting specializations diff --git a/stdlib/SparseArrays/src/linalg.jl b/stdlib/SparseArrays/src/linalg.jl index 4e143c571c8e5..5cfba0ee64157 100644 --- a/stdlib/SparseArrays/src/linalg.jl +++ b/stdlib/SparseArrays/src/linalg.jl @@ -156,9 +156,9 @@ function spmatmul(A::SparseMatrixCSC{Tv,Ti}, B::SparseMatrixCSC{Tv,Ti}; colptrB = B.colptr; rowvalB = B.rowval; nzvalB = B.nzval # TODO: Need better estimation of result space nnzC = min(mA*nB, length(nzvalA) + length(nzvalB)) - colptrC = Vector{Ti}(uninitialized, nB+1) - rowvalC = Vector{Ti}(uninitialized, nnzC) - nzvalC = Vector{Tv}(uninitialized, nnzC) + colptrC = Vector{Ti}(undef, nB+1) + rowvalC = Vector{Ti}(undef, nnzC) + nzvalC = Vector{Tv}(undef, nnzC) @inbounds begin ip = 1 @@ -334,7 +334,7 @@ function triu(S::SparseMatrixCSC{Tv,Ti}, k::Integer=0) where {Tv,Ti} throw(ArgumentError(string("the requested diagonal, $k, must be at least ", "$(-m + 1) and at most $(n + 1) in an $m-by-$n matrix"))) end - colptr = Vector{Ti}(uninitialized, n+1) + colptr = Vector{Ti}(undef, n+1) nnz = 0 for col = 1 : min(max(k+1,1), n+1) colptr[col] = 1 @@ -346,8 +346,8 @@ function triu(S::SparseMatrixCSC{Tv,Ti}, k::Integer=0) where {Tv,Ti} end colptr[col+1] = nnz+1 end - rowval = Vector{Ti}(uninitialized, nnz) - nzval = Vector{Tv}(uninitialized, nnz) + rowval = Vector{Ti}(undef, nnz) + nzval = Vector{Tv}(undef, nnz) A = SparseMatrixCSC(m, n, colptr, rowval, nzval) for col = max(k+1,1) : n c1 = S.colptr[col] @@ -366,7 +366,7 @@ function tril(S::SparseMatrixCSC{Tv,Ti}, k::Integer=0) where {Tv,Ti} throw(ArgumentError(string("the requested diagonal, $k, must be at least ", "$(-m - 1) and at most $(n - 1) in an $m-by-$n matrix"))) end - colptr = Vector{Ti}(uninitialized, n+1) + colptr = Vector{Ti}(undef, n+1) nnz = 0 colptr[1] = 1 for col = 1 : min(n, m+k) @@ -380,8 +380,8 @@ function tril(S::SparseMatrixCSC{Tv,Ti}, k::Integer=0) where {Tv,Ti} for col = max(min(n, m+k)+2,1) : n+1 colptr[col] = nnz+1 end - rowval = Vector{Ti}(uninitialized, nnz) - nzval = Vector{Tv}(uninitialized, nnz) + rowval = Vector{Ti}(undef, nnz) + nzval = Vector{Tv}(undef, nnz) A = SparseMatrixCSC(m, n, colptr, rowval, nzval) for col = 1 : min(n, m+k) c1 = S.colptr[col+1]-1 @@ -400,10 +400,10 @@ end function sparse_diff1(S::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} m,n = size(S) m > 1 || return SparseMatrixCSC(0, n, fill(one(Ti),n+1), Ti[], Tv[]) - colptr = Vector{Ti}(uninitialized, n+1) + colptr = Vector{Ti}(undef, n+1) numnz = 2 * nnz(S) # upper bound; will shrink later - rowval = Vector{Ti}(uninitialized, numnz) - nzval = Vector{Tv}(uninitialized, numnz) + rowval = Vector{Ti}(undef, numnz) + nzval = Vector{Tv}(undef, numnz) numnz = 0 colptr[1] = 1 for col = 1 : n @@ -439,10 +439,10 @@ end function sparse_diff2(a::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} m,n = size(a) - colptr = Vector{Ti}(uninitialized, max(n,1)) + colptr = Vector{Ti}(undef, max(n,1)) numnz = 2 * nnz(a) # upper bound; will shrink later - rowval = Vector{Ti}(uninitialized, numnz) - nzval = Vector{Tv}(uninitialized, numnz) + rowval = Vector{Ti}(undef, numnz) + nzval = Vector{Tv}(undef, numnz) z = zero(Tv) @@ -594,8 +594,8 @@ function normestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A)))) if t > n throw(ArgumentError("number of blocks must not be greater than $n")) end - ind = Vector{Int64}(uninitialized, n) - ind_hist = Vector{Int64}(uninitialized, maxiter * t) + ind = Vector{Int64}(undef, n) + ind_hist = Vector{Int64}(undef, maxiter * t) Ti = typeof(float(zero(T))) @@ -617,7 +617,7 @@ function normestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A)))) end # Generate the block matrix - X = Matrix{Ti}(uninitialized, n, t) + X = Matrix{Ti}(undef, n, t) X[1:n,1] = 1 for j = 2:t while true @@ -767,9 +767,9 @@ function kron(a::SparseMatrixCSC{Tv,Ti}, b::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti m,n = mA*mB, nA*nB - colptr = Vector{Ti}(uninitialized, n+1) - rowval = Vector{Ti}(uninitialized, numnz) - nzval = Vector{Tv}(uninitialized, numnz) + colptr = Vector{Ti}(undef, n+1) + rowval = Vector{Ti}(undef, numnz) + nzval = Vector{Tv}(undef, numnz) colptr[1] = 1 @@ -826,8 +826,8 @@ function kron(x::SparseVector{Tv,Ti},y::SparseVector{Tv,Ti}) where {Tv,Ti} nnzx = nnz(x) nnzy = nnz(y) nnzz = nnzx*nnzy # number of nonzeros in new vector - nzind = Vector{Ti}(uninitialized, nnzz) # the indices of nonzeros - nzval = Vector{Tv}(uninitialized, nnzz) # the values of nonzeros + nzind = Vector{Ti}(undef, nnzz) # the indices of nonzeros + nzval = Vector{Tv}(undef, nnzz) # the values of nonzeros @inbounds for i = 1:nnzx, j = 1:nnzy this_ind = (i-1)*nnzy+j nzind[this_ind] = (x.nzind[i]-1)*y.n + y.nzind[j] diff --git a/stdlib/SparseArrays/src/sparsematrix.jl b/stdlib/SparseArrays/src/sparsematrix.jl index 0a0cd6fa2ccb5..ec02d78518289 100644 --- a/stdlib/SparseArrays/src/sparsematrix.jl +++ b/stdlib/SparseArrays/src/sparsematrix.jl @@ -379,8 +379,8 @@ end function SparseMatrixCSC{Tv,Ti}(M::StridedMatrix) where {Tv,Ti} nz = count(t -> t != 0, M) colptr = zeros(Ti, size(M, 2) + 1) - nzval = Vector{Tv}(uninitialized, nz) - rowval = Vector{Ti}(uninitialized, nz) + nzval = Vector{Tv}(undef, nz) + rowval = Vector{Ti}(undef, nz) colptr[1] = 1 cnt = 1 @inbounds for j in 1:size(M, 2) @@ -400,7 +400,7 @@ end # converting from SparseMatrixCSC to other matrix types function Matrix(S::SparseMatrixCSC{Tv}) where Tv # Handle cases where zero(Tv) is not defined but the array is dense. - A = length(S) == nnz(S) ? Matrix{Tv}(uninitialized, S.m, S.n) : zeros(Tv, S.m, S.n) + A = length(S) == nnz(S) ? Matrix{Tv}(undef, S.m, S.n) : zeros(Tv, S.m, S.n) for Sj in 1:S.n for Sk in nzrange(S, Sj) Si = S.rowval[Sk] @@ -537,13 +537,13 @@ function sparse(I::AbstractVector{Ti}, J::AbstractVector{Ti}, V::AbstractVector{ SparseMatrixCSC(m, n, fill(one(Ti), n+1), Vector{Ti}(), Vector{Tv}()) else # Allocate storage for CSR form - csrrowptr = Vector{Ti}(uninitialized, m+1) - csrcolval = Vector{Ti}(uninitialized, coolen) - csrnzval = Vector{Tv}(uninitialized, coolen) + csrrowptr = Vector{Ti}(undef, m+1) + csrcolval = Vector{Ti}(undef, coolen) + csrnzval = Vector{Tv}(undef, coolen) # Allocate storage for the CSC form's column pointers and a necessary workspace - csccolptr = Vector{Ti}(uninitialized, n+1) - klasttouch = Vector{Ti}(uninitialized, n) + csccolptr = Vector{Ti}(undef, n+1) + klasttouch = Vector{Ti}(undef, n) # Allocate empty arrays for the CSC form's row and nonzero value arrays # The parent method called below automagically resizes these arrays @@ -722,7 +722,7 @@ function sparse!(I::AbstractVector{Ti}, J::AbstractVector{Ti}, csrrowptr::Vector{Ti}, csrcolval::Vector{Ti}, csrnzval::Vector{Tv}) where {Tv,Ti<:Integer} sparse!(I, J, V, m, n, combine, klasttouch, csrrowptr, csrcolval, csrnzval, - Vector{Ti}(uninitialized, n+1), Vector{Ti}(), Vector{Tv}()) + Vector{Ti}(undef, n+1), Vector{Ti}(), Vector{Tv}()) end dimlub(I) = isempty(I) ? 0 : Int(maximum(I)) #least upper bound on required sparse matrix dimension @@ -853,9 +853,9 @@ adjoint!(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} = f function ftranspose(A::SparseMatrixCSC{Tv,Ti}, f::Function) where {Tv,Ti} X = SparseMatrixCSC(A.n, A.m, - Vector{Ti}(uninitialized, A.m+1), - Vector{Ti}(uninitialized, nnz(A)), - Vector{Tv}(uninitialized, nnz(A))) + Vector{Ti}(undef, A.m+1), + Vector{Ti}(undef, nnz(A)), + Vector{Tv}(undef, nnz(A))) halfperm!(X, A, 1:A.n, f) end adjoint(A::SparseMatrixCSC) = Adjoint(A) @@ -1065,9 +1065,9 @@ function permute!(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, _checkargs_sourcecompatdest_permute!(A, X) _checkargs_sourcecompatperms_permute!(A, p, q) C = SparseMatrixCSC(A.n, A.m, - Vector{Ti}(uninitialized, A.m + 1), - Vector{Ti}(uninitialized, nnz(A)), - Vector{Tv}(uninitialized, nnz(A))) + Vector{Ti}(undef, A.m + 1), + Vector{Ti}(undef, nnz(A)), + Vector{Tv}(undef, nnz(A))) _checkargs_permutationsvalid_permute!(p, C.colptr, q, X.colptr) unchecked_noalias_permute!(X, A, p, q, C) end @@ -1084,10 +1084,10 @@ function permute!(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, q::AbstractVector{<:Integer}) where {Tv,Ti} _checkargs_sourcecompatperms_permute!(A, p, q) C = SparseMatrixCSC(A.n, A.m, - Vector{Ti}(uninitialized, A.m + 1), - Vector{Ti}(uninitialized, nnz(A)), - Vector{Tv}(uninitialized, nnz(A))) - workcolptr = Vector{Ti}(uninitialized, A.n + 1) + Vector{Ti}(undef, A.m + 1), + Vector{Ti}(undef, nnz(A)), + Vector{Tv}(undef, nnz(A))) + workcolptr = Vector{Ti}(undef, A.n + 1) _checkargs_permutationsvalid_permute!(p, C.colptr, q, workcolptr) unchecked_aliasing_permute!(A, p, q, C, workcolptr) end @@ -1095,7 +1095,7 @@ function permute!(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, q::AbstractVector{<:Integer}, C::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} _checkargs_sourcecompatperms_permute!(A, p, q) _checkargs_sourcecompatworkmat_permute!(A, C) - workcolptr = Vector{Ti}(uninitialized, A.n + 1) + workcolptr = Vector{Ti}(undef, A.n + 1) _checkargs_permutationsvalid_permute!(p, C.colptr, q, workcolptr) unchecked_aliasing_permute!(A, p, q, C, workcolptr) end @@ -1155,13 +1155,13 @@ function permute(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, q::AbstractVector{<:Integer}) where {Tv,Ti} _checkargs_sourcecompatperms_permute!(A, p, q) X = SparseMatrixCSC(A.m, A.n, - Vector{Ti}(uninitialized, A.n + 1), - Vector{Ti}(uninitialized, nnz(A)), - Vector{Tv}(uninitialized, nnz(A))) + Vector{Ti}(undef, A.n + 1), + Vector{Ti}(undef, nnz(A)), + Vector{Tv}(undef, nnz(A))) C = SparseMatrixCSC(A.n, A.m, - Vector{Ti}(uninitialized, A.m + 1), - Vector{Ti}(uninitialized, nnz(A)), - Vector{Tv}(uninitialized, nnz(A))) + Vector{Ti}(undef, A.m + 1), + Vector{Ti}(undef, nnz(A)), + Vector{Tv}(undef, nnz(A))) _checkargs_permutationsvalid_permute!(p, C.colptr, q, X.colptr) unchecked_noalias_permute!(X, A, p, q, C) end @@ -1304,7 +1304,7 @@ function findall(p::Function, S::SparseMatrixCSC) end numnz = nnz(S) - inds = Vector{CartesianIndex{2}}(uninitialized, numnz) + inds = Vector{CartesianIndex{2}}(undef, numnz) count = 1 @inbounds for col = 1 : S.n, k = S.colptr[col] : (S.colptr[col+1]-1) @@ -1321,9 +1321,9 @@ findall(p::Base.OccursIn, x::SparseMatrixCSC) = function findnz(S::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} numnz = nnz(S) - I = Vector{Ti}(uninitialized, numnz) - J = Vector{Ti}(uninitialized, numnz) - V = Vector{Tv}(uninitialized, numnz) + I = Vector{Ti}(undef, numnz) + J = Vector{Ti}(undef, numnz) + V = Vector{Tv}(undef, numnz) count = 1 @inbounds for col = 1 : S.n, k = S.colptr[col] : (S.colptr[col+1]-1) @@ -1521,9 +1521,9 @@ function SparseMatrixCSC{Tv,Ti}(s::UniformScaling, dims::Dims{2}) where {Tv,Ti} @boundscheck last(dims) < 0 && throw(ArgumentError("second dimension invalid ($(last(dims)) < 0)")) iszero(s.λ) && return spzeros(Tv, Ti, dims...) m, n, k = dims..., min(dims...) - nzval = fill!(Vector{Tv}(uninitialized, k), Tv(s.λ)) - rowval = copyto!(Vector{Ti}(uninitialized, k), 1:k) - colptr = copyto!(Vector{Ti}(uninitialized, n + 1), 1:(k + 1)) + nzval = fill!(Vector{Tv}(undef, k), Tv(s.λ)) + rowval = copyto!(Vector{Ti}(undef, k), 1:k) + colptr = copyto!(Vector{Ti}(undef, n + 1), 1:(k + 1)) for i in (k + 2):(n + 1) colptr[i] = (k + 1) end SparseMatrixCSC{Tv,Ti}(dims..., colptr, rowval, nzval) end @@ -1604,9 +1604,9 @@ end # and computing reductions along columns into SparseMatrixCSC is # non-trivial, so use Arrays for output Base.reducedim_initarray(A::SparseMatrixCSC, region, v0, ::Type{R}) where {R} = - fill!(similar(dims->Array{R}(uninitialized, dims), Base.reduced_indices(A,region)), v0) + fill!(similar(dims->Array{R}(undef, dims), Base.reduced_indices(A,region)), v0) Base.reducedim_initarray0(A::SparseMatrixCSC, region, v0, ::Type{R}) where {R} = - fill!(similar(dims->Array{R}(uninitialized, dims), Base.reduced_indices0(A,region)), v0) + fill!(similar(dims->Array{R}(undef, dims), Base.reduced_indices0(A,region)), v0) # General mapreduce function _mapreducezeros(f, op, ::Type{T}, nzeros::Int, v0) where T @@ -1830,7 +1830,7 @@ function _findr(op, A, region, Tv) if region == 1 || region == (1,) (N == 0) && (return (fill(zval,1,n), fill(i1,1,n))) - S = Vector{Tv}(uninitialized, n); I = Vector{Ti}(uninitialized, n) + S = Vector{Tv}(undef, n); I = Vector{Ti}(undef, n) @inbounds for i = 1 : n Sc = zval; Ic = _findz(A, 1:m, i:i) if Ic == CartesianIndex(0, 0) @@ -1849,8 +1849,8 @@ function _findr(op, A, region, Tv) return(reshape(S,1,n), reshape(I,1,n)) elseif region == 2 || region == (2,) (N == 0) && (return (fill(zval,m,1), fill(i1,m,1))) - S = Vector{Tv}(uninitialized, m) - I = Vector{Ti}(uninitialized, m) + S = Vector{Tv}(undef, m) + I = Vector{Ti}(undef, m) @inbounds for row in 1:m S[row] = zval; I[row] = _findz(A, row:row, 1:n) if I[row] == CartesianIndex(0, 0) @@ -1923,7 +1923,7 @@ function getindex_cols(A::SparseMatrixCSC{Tv,Ti}, J::AbstractVector) where {Tv,T colptrA = A.colptr; rowvalA = A.rowval; nzvalA = A.nzval - colptrS = Vector{Ti}(uninitialized, nJ+1) + colptrS = Vector{Ti}(undef, nJ+1) colptrS[1] = 1 nnzS = 0 @@ -1934,8 +1934,8 @@ function getindex_cols(A::SparseMatrixCSC{Tv,Ti}, J::AbstractVector) where {Tv,T colptrS[j+1] = nnzS + 1 end - rowvalS = Vector{Ti}(uninitialized, nnzS) - nzvalS = Vector{Tv}(uninitialized, nnzS) + rowvalS = Vector{Ti}(undef, nnzS) + nzvalS = Vector{Tv}(undef, nnzS) ptrS = 0 @inbounds for j = 1:nJ @@ -1964,7 +1964,7 @@ function getindex(A::SparseMatrixCSC{Tv,Ti}, I::AbstractRange, J::AbstractVector nI == 0 || (minimum(I) >= 1 && maximum(I) <= m) || throw(BoundsError()) nJ = length(J) colptrA = A.colptr; rowvalA = A.rowval; nzvalA = A.nzval - colptrS = Vector{Ti}(uninitialized, nJ+1) + colptrS = Vector{Ti}(undef, nJ+1) colptrS[1] = 1 nnzS = 0 @@ -1979,8 +1979,8 @@ function getindex(A::SparseMatrixCSC{Tv,Ti}, I::AbstractRange, J::AbstractVector end # Populate the values in the result - rowvalS = Vector{Ti}(uninitialized, nnzS) - nzvalS = Vector{Tv}(uninitialized, nnzS) + rowvalS = Vector{Ti}(undef, nnzS) + nzvalS = Vector{Tv}(undef, nnzS) ptrS = 1 @inbounds for j = 1:nJ @@ -2024,7 +2024,7 @@ function getindex_I_sorted_bsearch_A(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVecto nJ = length(J) colptrA = A.colptr; rowvalA = A.rowval; nzvalA = A.nzval - colptrS = Vector{Ti}(uninitialized, nJ+1) + colptrS = Vector{Ti}(undef, nJ+1) colptrS[1] = 1 ptrS = 1 @@ -2049,8 +2049,8 @@ function getindex_I_sorted_bsearch_A(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVecto colptrS[j+1] = ptrS end - rowvalS = Vector{Ti}(uninitialized, ptrS-1) - nzvalS = Vector{Tv}(uninitialized, ptrS-1) + rowvalS = Vector{Ti}(undef, ptrS-1) + nzvalS = Vector{Tv}(undef, ptrS-1) # fill the values ptrS = 1 @@ -2083,7 +2083,7 @@ function getindex_I_sorted_linear(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVector, nJ = length(J) colptrA = A.colptr; rowvalA = A.rowval; nzvalA = A.nzval - colptrS = Vector{Ti}(uninitialized, nJ+1) + colptrS = Vector{Ti}(undef, nJ+1) colptrS[1] = 1 cacheI = zeros(Int, A.m) @@ -2111,8 +2111,8 @@ function getindex_I_sorted_linear(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVector, colptrS[j+1] = ptrS end - rowvalS = Vector{Ti}(uninitialized, ptrS-1) - nzvalS = Vector{Tv}(uninitialized, ptrS-1) + rowvalS = Vector{Ti}(undef, ptrS-1) + nzvalS = Vector{Tv}(undef, ptrS-1) # fill the values ptrS = 1 @@ -2142,7 +2142,7 @@ function getindex_I_sorted_bsearch_I(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVecto nJ = length(J) colptrA = A.colptr; rowvalA = A.rowval; nzvalA = A.nzval - colptrS = Vector{Ti}(uninitialized, nJ+1) + colptrS = Vector{Ti}(undef, nJ+1) colptrS[1] = 1 m = A.m @@ -2176,8 +2176,8 @@ function getindex_I_sorted_bsearch_I(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVecto break end end - rowvalS = Vector{Ti}(uninitialized, ptrS) - nzvalS = Vector{Tv}(uninitialized, ptrS) + rowvalS = Vector{Ti}(undef, ptrS) + nzvalS = Vector{Tv}(undef, ptrS) colptrS[nJ+1] = ptrS+1 # fill the values @@ -2211,9 +2211,9 @@ function permute_rows!(S::SparseMatrixCSC{Tv,Ti}, pI::Vector{Int}) where {Tv,Ti} colptrS = S.colptr; rowvalS = S.rowval; nzvalS = S.nzval # preallocate temporary sort space nr = min(nnz(S), m) - rowperm = Vector{Int}(uninitialized, nr) - rowvalTemp = Vector{Ti}(uninitialized, nr) - nzvalTemp = Vector{Tv}(uninitialized, nr) + rowperm = Vector{Int}(undef, nr) + rowvalTemp = Vector{Ti}(undef, nr) + nzvalTemp = Vector{Tv}(undef, nr) @inbounds for j in 1:n rowrange = colptrS[j]:(colptrS[j+1]-1) @@ -2281,8 +2281,8 @@ function getindex(A::SparseMatrixCSC{Tv,Ti}, I::AbstractArray) where {Tv,Ti} outn = size(I,2) szB = (outm, outn) colptrB = zeros(Ti, outn+1) - rowvalB = Vector{Ti}(uninitialized, n) - nzvalB = Vector{Tv}(uninitialized, n) + rowvalB = Vector{Ti}(undef, n) + nzvalB = Vector{Tv}(undef, n) colB = 1 rowB = 1 @@ -3029,9 +3029,9 @@ function vcat(X::SparseMatrixCSC...) nnzX = Int[ nnz(x) for x in X ] nnz_res = sum(nnzX) - colptr = Vector{Ti}(uninitialized, n+1) - rowval = Vector{Ti}(uninitialized, nnz_res) - nzval = Vector{Tv}(uninitialized, nnz_res) + colptr = Vector{Ti}(undef, n+1) + rowval = Vector{Ti}(undef, nnz_res) + nzval = Vector{Tv}(undef, nnz_res) colptr[1] = 1 for c = 1:n @@ -3079,11 +3079,11 @@ function hcat(X::SparseMatrixCSC...) Tv = promote_eltype(X...) Ti = promote_eltype(map(x->x.rowval, X)...) - colptr = Vector{Ti}(uninitialized, n+1) + colptr = Vector{Ti}(undef, n+1) nnzX = Int[ nnz(x) for x in X ] nnz_res = sum(nnzX) - rowval = Vector{Ti}(uninitialized, nnz_res) - nzval = Vector{Tv}(uninitialized, nnz_res) + rowval = Vector{Ti}(undef, nnz_res) + nzval = Vector{Tv}(undef, nnz_res) nnz_sofar = 0 nX_sofar = 0 @@ -3130,11 +3130,11 @@ function blockdiag(X::SparseMatrixCSC...) Tv = promote_type(map(x->eltype(x.nzval), X)...) Ti = promote_type(map(x->eltype(x.rowval), X)...) - colptr = Vector{Ti}(uninitialized, n+1) + colptr = Vector{Ti}(undef, n+1) nnzX = Int[ nnz(x) for x in X ] nnz_res = sum(nnzX) - rowval = Vector{Ti}(uninitialized, nnz_res) - nzval = Vector{Tv}(uninitialized, nnz_res) + rowval = Vector{Ti}(undef, nnz_res) + nzval = Vector{Tv}(undef, nnz_res) nnz_sofar = 0 nX_sofar = 0 @@ -3276,9 +3276,9 @@ function spdiagm_internal(kv::Pair{<:Integer,<:AbstractVector}...) for p in kv ncoeffs += length(p.second) end - I = Vector{Int}(uninitialized, ncoeffs) - J = Vector{Int}(uninitialized, ncoeffs) - V = Vector{promote_type(map(x -> eltype(x.second), kv)...)}(uninitialized, ncoeffs) + I = Vector{Int}(undef, ncoeffs) + J = Vector{Int}(undef, ncoeffs) + V = Vector{promote_type(map(x -> eltype(x.second), kv)...)}(undef, ncoeffs) i = 0 for p in kv dia = p.first @@ -3378,7 +3378,7 @@ end function sortSparseMatrixCSC!(A::SparseMatrixCSC{Tv,Ti}; sortindices::Symbol = :sortcols) where {Tv,Ti} if sortindices == :doubletranspose nB, mB = size(A) - B = SparseMatrixCSC(mB, nB, Vector{Ti}(uninitialized, nB+1), similar(A.rowval), similar(A.nzval)) + B = SparseMatrixCSC(mB, nB, Vector{Ti}(undef, nB+1), similar(A.rowval), similar(A.nzval)) transpose!(B, A) transpose!(A, B) return A diff --git a/stdlib/SparseArrays/src/sparsevector.jl b/stdlib/SparseArrays/src/sparsevector.jl index b683a86596e71..93fd8c912c1f9 100644 --- a/stdlib/SparseArrays/src/sparsevector.jl +++ b/stdlib/SparseArrays/src/sparsevector.jl @@ -242,8 +242,8 @@ julia> sparsevec(Dict(1 => 3, 2 => 2)) """ function sparsevec(dict::AbstractDict{Ti,Tv}) where {Tv,Ti<:Integer} m = length(dict) - nzind = Vector{Ti}(uninitialized, m) - nzval = Vector{Tv}(uninitialized, m) + nzind = Vector{Ti}(undef, m) + nzval = Vector{Tv}(undef, m) cnt = 0 len = zero(Ti) @@ -263,8 +263,8 @@ end function sparsevec(dict::AbstractDict{Ti,Tv}, len::Integer) where {Tv,Ti<:Integer} m = length(dict) - nzind = Vector{Ti}(uninitialized, m) - nzval = Vector{Tv}(uninitialized, m) + nzind = Vector{Ti}(undef, m) + nzval = Vector{Tv}(undef, m) cnt = 0 maxk = convert(Ti, len) @@ -380,8 +380,8 @@ function _dense2sparsevec(s::AbstractArray{Tv}, initcap::Ti) where {Tv,Ti} # pre-condition: initcap > 0; the initcap determines the index type n = length(s) cap = initcap - nzind = Vector{Ti}(uninitialized, cap) - nzval = Vector{Tv}(uninitialized, cap) + nzind = Vector{Ti}(undef, cap) + nzval = Vector{Tv}(undef, cap) c = 0 @inbounds for i = 1:n v = s[i] @@ -572,8 +572,8 @@ function _logical_index(A::SparseMatrixCSC{Tv}, I::AbstractArray{Bool}) where Tv nnzB = min(n, nnz(A)) colptrA = A.colptr; rowvalA = A.rowval; nzvalA = A.nzval - rowvalB = Vector{Int}(uninitialized, nnzB) - nzvalB = Vector{Tv}(uninitialized, nnzB) + rowvalB = Vector{Int}(undef, nnzB) + nzvalB = Vector{Tv}(undef, nnzB) c = 1 rowB = 1 @@ -617,8 +617,8 @@ function getindex(A::SparseMatrixCSC{Tv}, I::AbstractUnitRange) where Tv n = length(I) nnzB = min(n, nnz(A)) - rowvalB = Vector{Int}(uninitialized, nnzB) - nzvalB = Vector{Tv}(uninitialized, nnzB) + rowvalB = Vector{Int}(undef, nnzB) + nzvalB = Vector{Tv}(undef, nnzB) rowstart,colstart = Base._ind2sub(szA, first(I)) rowend,colend = Base._ind2sub(szA, last(I)) @@ -652,8 +652,8 @@ function getindex(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVector) where {Tv,Ti} n = length(I) nnzB = min(n, nnz(A)) - rowvalB = Vector{Ti}(uninitialized, nnzB) - nzvalB = Vector{Tv}(uninitialized, nnzB) + rowvalB = Vector{Ti}(undef, nnzB) + nzvalB = Vector{Tv}(undef, nnzB) idxB = 1 for i in 1:n @@ -692,7 +692,7 @@ function findall(p::Function, x::SparseVector{<:Any,Ti}) where Ti return invoke(findall, Tuple{Function, Any}, p, x) end numnz = nnz(x) - I = Vector{Ti}(uninitialized, numnz) + I = Vector{Ti}(undef, numnz) nzind = x.nzind nzval = x.nzval @@ -718,8 +718,8 @@ findall(p::Base.OccursIn, x::SparseVector{<:Any,Ti}) where {Ti} = function findnz(x::SparseVector{Tv,Ti}) where {Tv,Ti} numnz = nnz(x) - I = Vector{Ti}(uninitialized, numnz) - V = Vector{Tv}(uninitialized, numnz) + I = Vector{Ti}(undef, numnz) + V = Vector{Tv}(undef, numnz) nzind = x.nzind nzval = x.nzval @@ -782,8 +782,8 @@ function getindex(x::AbstractSparseVector{Tv,Ti}, I::AbstractUnitRange) where {T # compute the number of non-zeros jrgn = j0:j1 mr = length(jrgn) - rind = Vector{Ti}(uninitialized, mr) - rval = Vector{Tv}(uninitialized, mr) + rind = Vector{Ti}(undef, mr) + rval = Vector{Tv}(undef, mr) if mr > 0 c = 0 for j in jrgn @@ -923,9 +923,9 @@ function _absspvec_hcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti} end # construction - colptr = Vector{Ti}(uninitialized, n+1) - nzrow = Vector{Ti}(uninitialized, tnnz) - nzval = Vector{Tv}(uninitialized, tnnz) + colptr = Vector{Ti}(undef, n+1) + nzrow = Vector{Ti}(undef, tnnz) + nzval = Vector{Tv}(undef, tnnz) roff = 1 @inbounds for j = 1:n xj = X[j] @@ -960,8 +960,8 @@ function _absspvec_vcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti} end # construction - rnzind = Vector{Ti}(uninitialized, tnnz) - rnzval = Vector{Tv}(uninitialized, tnnz) + rnzind = Vector{Ti}(undef, tnnz) + rnzval = Vector{Tv}(undef, tnnz) ir = 0 len = 0 @inbounds for j = 1:n @@ -1033,7 +1033,7 @@ end function hvcat(rows::Tuple{Vararg{Int}}, X::_SparseConcatGroup...) nbr = length(rows) # number of block rows - tmp_rows = Vector{SparseMatrixCSC}(uninitialized, nbr) + tmp_rows = Vector{SparseMatrixCSC}(undef, nbr) k = 0 @inbounds for i = 1 : nbr tmp_rows[i] = hcat(X[(1 : rows[i]) .+ k]...) @@ -1080,8 +1080,8 @@ macro unarymap_nz2z_z2z(op, TF) xnzval = nonzeros(x) m = length(xnzind) - ynzind = Vector{Ti}(uninitialized, m) - ynzval = Vector{R}(uninitialized, m) + ynzind = Vector{Ti}(undef, m) + ynzval = Vector{R}(undef, m) ir = 0 @inbounds for j = 1:m i = xnzind[j] @@ -1149,8 +1149,8 @@ function _binarymap(f::Function, my = length(ynzind) cap = (mode == 0 ? min(mx, my) : mx + my)::Int - rind = Vector{Int}(uninitialized, cap) - rval = Vector{R}(uninitialized, cap) + rind = Vector{Int}(undef, cap) + rval = Vector{R}(undef, cap) ir = 0 ix = 1 iy = 1 @@ -1286,7 +1286,7 @@ function _binarymap(f::Function, ynzval = nonzeros(y) m = length(ynzind) - dst = Vector{R}(uninitialized, n) + dst = Vector{R}(undef, n) if mode == 0 ii = 1 @inbounds for i = 1:m @@ -1328,7 +1328,7 @@ function _binarymap(f::Function, xnzval = nonzeros(x) m = length(xnzind) - dst = Vector{R}(uninitialized, n) + dst = Vector{R}(undef, n) if mode == 0 ii = 1 @inbounds for i = 1:m @@ -1584,7 +1584,7 @@ function (*)(A::StridedMatrix{Ta}, x::AbstractSparseVector{Tx}) where {Ta,Tx} m, n = size(A) length(x) == n || throw(DimensionMismatch()) Ty = promote_type(Ta, Tx) - y = Vector{Ty}(uninitialized, m) + y = Vector{Ty}(undef, m) mul!(y, A, x) end @@ -1622,7 +1622,7 @@ function *(transA::Transpose{<:Any,<:StridedMatrix{Ta}}, x::AbstractSparseVector m, n = size(A) length(x) == m || throw(DimensionMismatch()) Ty = promote_type(Ta, Tx) - y = Vector{Ty}(uninitialized, n) + y = Vector{Ty}(undef, n) mul!(y, transpose(A), x) end @@ -1670,7 +1670,7 @@ function densemv(A::SparseMatrixCSC, x::AbstractSparseVector; trans::AbstractCha end xlen == length(x) || throw(DimensionMismatch()) T = promote_type(eltype(A), eltype(x)) - y = Vector{T}(uninitialized, ylen) + y = Vector{T}(undef, ylen) if trans == 'N' || trans == 'N' mul!(y, A, x) elseif trans == 'T' || trans == 't' @@ -1785,8 +1785,8 @@ function _At_or_Ac_mul_B(tfun::Function, A::SparseMatrixCSC{TvA,TiA}, x::Abstrac Anzval = A.nzval mx = length(xnzind) - ynzind = Vector{Ti}(uninitialized, n) - ynzval = Vector{Tv}(uninitialized, n) + ynzind = Vector{Ti}(undef, n) + ynzval = Vector{Tv}(undef, n) jr = 0 for j = 1:n diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index 39be7e4467bf8..a85c3c00bc188 100644 --- a/stdlib/SparseArrays/test/sparse.jl +++ b/stdlib/SparseArrays/test/sparse.jl @@ -434,7 +434,7 @@ end @test_throws ArgumentError permute!(X, A, p, q, (D = copy(C); resize!(D.nzval, nnz(A) - 1); D)) end @testset "common error checking of permute[!] methods / source-workcolptr compat" begin - @test_throws DimensionMismatch permute!(A, p, q, C, Vector{eltype(A.rowval)}(uninitialized, length(A.colptr) - 1)) + @test_throws DimensionMismatch permute!(A, p, q, C, Vector{eltype(A.rowval)}(undef, length(A.colptr) - 1)) end @testset "common error checking of permute[!] methods / permutation validity" begin @test_throws ArgumentError permute!(A, (r = copy(p); r[2] = r[1]; r), q) diff --git a/stdlib/SparseArrays/test/sparsevector.jl b/stdlib/SparseArrays/test/sparsevector.jl index 268263191cb78..f0005b6801c68 100644 --- a/stdlib/SparseArrays/test/sparsevector.jl +++ b/stdlib/SparseArrays/test/sparsevector.jl @@ -432,7 +432,7 @@ end @testset "Concatenation" begin let m = 80, n = 100 - A = Vector{SparseVector{Float64,Int}}(uninitialized, n) + A = Vector{SparseVector{Float64,Int}}(undef, n) tnnz = 0 for i = 1:length(A) A[i] = sprand(m, 0.3) diff --git a/stdlib/SuiteSparse/src/cholmod.jl b/stdlib/SuiteSparse/src/cholmod.jl index ae6e54af493d2..6f7963a209690 100644 --- a/stdlib/SuiteSparse/src/cholmod.jl +++ b/stdlib/SuiteSparse/src/cholmod.jl @@ -43,7 +43,7 @@ const common_postorder = Ref{Ptr{Cint}}() ### These offsets are defined in SuiteSparse_wrapper.c const common_size = ccall((:jl_cholmod_common_size,:libsuitesparse_wrapper),Int,()) -const cholmod_com_offsets = Vector{Csize_t}(uninitialized, 19) +const cholmod_com_offsets = Vector{Csize_t}(undef, 19) ccall((:jl_cholmod_common_offsets, :libsuitesparse_wrapper), Nothing, (Ptr{Csize_t},), cholmod_com_offsets) @@ -70,7 +70,7 @@ function defaults(a::Vector{UInt8}) return a end -const build_version_array = Vector{Cint}(uninitialized, 3) +const build_version_array = Vector{Cint}(undef, 3) ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), build_version_array) const build_version = VersionNumber(build_version_array...) @@ -78,7 +78,7 @@ function __init__() try ### Check if the linked library is compatible with the Julia code if Libdl.dlsym_e(Libdl.dlopen("libcholmod"), :cholmod_version) != C_NULL - current_version_array = Vector{Cint}(uninitialized, 3) + current_version_array = Vector{Cint}(undef, 3) ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), current_version_array) current_version = VersionNumber(current_version_array...) else # CHOLMOD < 2.1.1 does not include cholmod_version() @@ -1029,7 +1029,7 @@ end ## convertion back to base Julia types function Matrix{T}(D::Dense{T}) where T s = unsafe_load(pointer(D)) - a = Matrix{T}(uninitialized, s.nrow, s.ncol) + a = Matrix{T}(undef, s.nrow, s.ncol) copyto!(a, D) end @@ -1060,7 +1060,7 @@ function Vector{T}(D::Dense{T}) where T if size(D, 2) > 1 throw(DimensionMismatch("input must be a vector but had $(size(D, 2)) columns")) end - copyto!(Vector{T}(uninitialized, size(D, 1)), D) + copyto!(Vector{T}(undef, size(D, 1)), D) end Vector(D::Dense{T}) where {T} = Vector{T}(D) @@ -1148,7 +1148,7 @@ function sparse(F::Factor) SparseArrays.sortSparseMatrixCSC!(A) p = get_perm(F) if p != [1:s.n;] - pinv = Vector{Int}(uninitialized, length(p)) + pinv = Vector{Int}(undef, length(p)) for k = 1:length(p) pinv[p[k]] = k end @@ -1285,7 +1285,7 @@ end end function getLd!(S::SparseMatrixCSC) - d = Vector{eltype(S)}(uninitialized, size(S, 1)) + d = Vector{eltype(S)}(undef, size(S, 1)) fill!(d, 0) col = 1 for k = 1:nnz(S) diff --git a/stdlib/SuiteSparse/src/spqr.jl b/stdlib/SuiteSparse/src/spqr.jl index 1686a5bc84381..c4fae7be5ef11 100644 --- a/stdlib/SuiteSparse/src/spqr.jl +++ b/stdlib/SuiteSparse/src/spqr.jl @@ -71,7 +71,7 @@ function _qr!(ordering::Integer, tol::Real, econ::Integer, getCTX::Integer, if e == C_NULL _E = Vector{CHOLMOD.SuiteSparse_long}() else - _E = Vector{CHOLMOD.SuiteSparse_long}(uninitialized, n) + _E = Vector{CHOLMOD.SuiteSparse_long}(undef, n) for i in 1:n @inbounds _E[i] = unsafe_load(e, i) + 1 end @@ -86,7 +86,7 @@ function _qr!(ordering::Integer, tol::Real, econ::Integer, getCTX::Integer, if hpinv == C_NULL _HPinv = Vector{CHOLMOD.SuiteSparse_long}() else - _HPinv = Vector{CHOLMOD.SuiteSparse_long}(uninitialized, m) + _HPinv = Vector{CHOLMOD.SuiteSparse_long}(undef, m) for i in 1:m @inbounds _HPinv[i] = unsafe_load(hpinv, i) + 1 end diff --git a/stdlib/SuiteSparse/src/umfpack.jl b/stdlib/SuiteSparse/src/umfpack.jl index fc5da11d52a99..8b4f82a60b3e2 100644 --- a/stdlib/SuiteSparse/src/umfpack.jl +++ b/stdlib/SuiteSparse/src/umfpack.jl @@ -74,9 +74,9 @@ const UMFVTypes = Union{Float64,ComplexF64} ## UMFPACK # the control and info arrays -const umf_ctrl = Vector{Float64}(uninitialized, UMFPACK_CONTROL) +const umf_ctrl = Vector{Float64}(undef, UMFPACK_CONTROL) ccall((:umfpack_dl_defaults,:libumfpack), Cvoid, (Ptr{Float64},), umf_ctrl) -const umf_info = Vector{Float64}(uninitialized, UMFPACK_INFO) +const umf_info = Vector{Float64}(undef, UMFPACK_INFO) function show_umf_ctrl(level::Real = 2.0) old_prt::Float64 = umf_ctrl[1] @@ -203,7 +203,7 @@ for itype in UmfpackIndexTypes @eval begin function umfpack_symbolic!(U::UmfpackLU{Float64,$itype}) if U.symbolic != C_NULL return U end - tmp = Vector{Ptr{Cvoid}}(uninitialized, 1) + tmp = Vector{Ptr{Cvoid}}(undef, 1) @isok ccall(($sym_r, :libumfpack), $itype, ($itype, $itype, Ptr{$itype}, Ptr{$itype}, Ptr{Float64}, Ptr{Cvoid}, Ptr{Float64}, Ptr{Float64}), @@ -214,7 +214,7 @@ for itype in UmfpackIndexTypes end function umfpack_symbolic!(U::UmfpackLU{ComplexF64,$itype}) if U.symbolic != C_NULL return U end - tmp = Vector{Ptr{Cvoid}}(uninitialized, 1) + tmp = Vector{Ptr{Cvoid}}(undef, 1) @isok ccall(($sym_c, :libumfpack), $itype, ($itype, $itype, Ptr{$itype}, Ptr{$itype}, Ptr{Float64}, Ptr{Float64}, Ptr{Cvoid}, Ptr{Float64}, Ptr{Float64}), @@ -226,7 +226,7 @@ for itype in UmfpackIndexTypes function umfpack_numeric!(U::UmfpackLU{Float64,$itype}) if U.numeric != C_NULL return U end if U.symbolic == C_NULL umfpack_symbolic!(U) end - tmp = Vector{Ptr{Cvoid}}(uninitialized, 1) + tmp = Vector{Ptr{Cvoid}}(undef, 1) status = ccall(($num_r, :libumfpack), $itype, (Ptr{$itype}, Ptr{$itype}, Ptr{Float64}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Float64}, Ptr{Float64}), @@ -241,7 +241,7 @@ for itype in UmfpackIndexTypes function umfpack_numeric!(U::UmfpackLU{ComplexF64,$itype}) if U.numeric != C_NULL return U end if U.symbolic == C_NULL umfpack_symbolic!(U) end - tmp = Vector{Ptr{Cvoid}}(uninitialized, 1) + tmp = Vector{Ptr{Cvoid}}(undef, 1) status = ccall(($num_c, :libumfpack), $itype, (Ptr{$itype}, Ptr{$itype}, Ptr{Float64}, Ptr{Float64}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Float64}, Ptr{Float64}), @@ -330,15 +330,15 @@ for itype in UmfpackIndexTypes function umf_extract(lu::UmfpackLU{Float64,$itype}) umfpack_numeric!(lu) # ensure the numeric decomposition exists (lnz, unz, n_row, n_col, nz_diag) = umf_lunz(lu) - Lp = Vector{$itype}(uninitialized, n_row + 1) - Lj = Vector{$itype}(uninitialized, lnz) # L is returned in CSR (compressed sparse row) format - Lx = Vector{Float64}(uninitialized, lnz) - Up = Vector{$itype}(uninitialized, n_col + 1) - Ui = Vector{$itype}(uninitialized, unz) - Ux = Vector{Float64}(uninitialized, unz) - P = Vector{$itype}(uninitialized, n_row) - Q = Vector{$itype}(uninitialized, n_col) - Rs = Vector{Float64}(uninitialized, n_row) + Lp = Vector{$itype}(undef, n_row + 1) + Lj = Vector{$itype}(undef, lnz) # L is returned in CSR (compressed sparse row) format + Lx = Vector{Float64}(undef, lnz) + Up = Vector{$itype}(undef, n_col + 1) + Ui = Vector{$itype}(undef, unz) + Ux = Vector{Float64}(undef, unz) + P = Vector{$itype}(undef, n_row) + Q = Vector{$itype}(undef, n_col) + Rs = Vector{Float64}(undef, n_row) @isok ccall(($get_num_r,:libumfpack), $itype, (Ptr{$itype},Ptr{$itype},Ptr{Float64}, Ptr{$itype},Ptr{$itype},Ptr{Float64}, @@ -355,17 +355,17 @@ for itype in UmfpackIndexTypes function umf_extract(lu::UmfpackLU{ComplexF64,$itype}) umfpack_numeric!(lu) # ensure the numeric decomposition exists (lnz, unz, n_row, n_col, nz_diag) = umf_lunz(lu) - Lp = Vector{$itype}(uninitialized, n_row + 1) - Lj = Vector{$itype}(uninitialized, lnz) # L is returned in CSR (compressed sparse row) format - Lx = Vector{Float64}(uninitialized, lnz) - Lz = Vector{Float64}(uninitialized, lnz) - Up = Vector{$itype}(uninitialized, n_col + 1) - Ui = Vector{$itype}(uninitialized, unz) - Ux = Vector{Float64}(uninitialized, unz) - Uz = Vector{Float64}(uninitialized, unz) - P = Vector{$itype}(uninitialized, n_row) - Q = Vector{$itype}(uninitialized, n_col) - Rs = Vector{Float64}(uninitialized, n_row) + Lp = Vector{$itype}(undef, n_row + 1) + Lj = Vector{$itype}(undef, lnz) # L is returned in CSR (compressed sparse row) format + Lx = Vector{Float64}(undef, lnz) + Lz = Vector{Float64}(undef, lnz) + Up = Vector{$itype}(undef, n_col + 1) + Ui = Vector{$itype}(undef, unz) + Ux = Vector{Float64}(undef, unz) + Uz = Vector{Float64}(undef, unz) + P = Vector{$itype}(undef, n_row) + Q = Vector{$itype}(undef, n_col) + Rs = Vector{Float64}(undef, n_row) @isok ccall(($get_num_z,:libumfpack), $itype, (Ptr{$itype},Ptr{$itype},Ptr{Float64},Ptr{Float64}, Ptr{$itype},Ptr{$itype},Ptr{Float64},Ptr{Float64}, diff --git a/stdlib/Test/test/runtests.jl b/stdlib/Test/test/runtests.jl index e661a6bcb7736..832562e32f9b5 100644 --- a/stdlib/Test/test/runtests.jl +++ b/stdlib/Test/test/runtests.jl @@ -61,7 +61,7 @@ end end end @testset "@test and elements of an array" begin - a = Array{Float64, 5}(uninitialized, 2, 2, 2, 2, 2) + a = Array{Float64, 5}(undef, 2, 2, 2, 2, 2) a[1, 1, 1, 1, 1] = 10 @test a[1, 1, 1, 1, 1] == 10 @test a[1, 1, 1, 1, 1] != 2 diff --git a/test/TestHelpers.jl b/test/TestHelpers.jl index 2aa01119c6d3e..f44c81b93e39c 100644 --- a/test/TestHelpers.jl +++ b/test/TestHelpers.jl @@ -61,10 +61,10 @@ OffsetVector{T,AA<:AbstractArray} = OffsetArray{T,1,AA} OffsetArray(A::AbstractArray{T,N}, offsets::NTuple{N,Int}) where {T,N} = OffsetArray{T,N,typeof(A)}(A, offsets) OffsetArray(A::AbstractArray{T,N}, offsets::Vararg{Int,N}) where {T,N} = OffsetArray(A, offsets) -OffsetArray{T,N}(::Uninitialized, inds::Indices{N}) where {T,N} = - OffsetArray{T,N,Array{T,N}}(Array{T,N}(uninitialized, map(length, inds)), map(indsoffset, inds)) -OffsetArray{T}(::Uninitialized, inds::Indices{N}) where {T,N} = - OffsetArray{T,N}(uninitialized, inds) +OffsetArray{T,N}(::UndefInitializer, inds::Indices{N}) where {T,N} = + OffsetArray{T,N,Array{T,N}}(Array{T,N}(undef, map(length, inds)), map(indsoffset, inds)) +OffsetArray{T}(::UndefInitializer, inds::Indices{N}) where {T,N} = + OffsetArray{T,N}(undef, inds) Base.IndexStyle(::Type{T}) where {T<:OffsetArray} = Base.IndexStyle(parenttype(T)) parenttype(::Type{OffsetArray{T,N,AA}}) where {T,N,AA} = AA @@ -98,9 +98,9 @@ end Base.similar(f::Union{Function,Type}, shape::Tuple{UnitRange,Vararg{UnitRange}}) = OffsetArray(f(map(length, shape)), map(indsoffset, shape)) Base.similar(::Type{T}, shape::Tuple{UnitRange,Vararg{UnitRange}}) where {T<:Array} = - OffsetArray(T(uninitialized, map(length, shape)), map(indsoffset, shape)) + OffsetArray(T(undef, map(length, shape)), map(indsoffset, shape)) Base.similar(::Type{T}, shape::Tuple{UnitRange,Vararg{UnitRange}}) where {T<:BitArray} = - OffsetArray(T(uninitialized, map(length, shape)), map(indsoffset, shape)) + OffsetArray(T(undef, map(length, shape)), map(indsoffset, shape)) Base.reshape(A::AbstractArray, inds::Tuple{UnitRange,Vararg{UnitRange}}) = OffsetArray(reshape(A, map(length, inds)), map(indsoffset, inds)) diff --git a/test/abstractarray.jl b/test/abstractarray.jl index b52fe31768d0d..92bdab8360b9c 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -475,7 +475,7 @@ function test_primitives(::Type{T}, shape, ::Type{TestAbstractArray}) where T @test_throws DimensionMismatch reshape(B, (0, 1)) # copyto!(dest::AbstractArray, src::AbstractArray) - @test_throws BoundsError copyto!(Vector{Int}(uninitialized, 10), [1:11...]) + @test_throws BoundsError copyto!(Vector{Int}(undef, 10), [1:11...]) # convert{T, N}(::Type{Array}, A::AbstractArray{T, N}) X = [1:10...] @@ -570,14 +570,14 @@ function test_cat(::Type{TestAbstractArray}) A = T24Linear([1:24...]) b_int = reshape([1:27...], 3, 3, 3) b_float = reshape(Float64[1:27...], 3, 3, 3) - b2hcat = Array{Float64}(uninitialized, 3, 6, 3) + b2hcat = Array{Float64}(undef, 3, 6, 3) b1 = reshape([1:9...], 3, 3) b2 = reshape([10:18...], 3, 3) b3 = reshape([19:27...], 3, 3) b2hcat[:, :, 1] = hcat(b1, b1) b2hcat[:, :, 2] = hcat(b2, b2) b2hcat[:, :, 3] = hcat(b3, b3) - b3hcat = Array{Float64}(uninitialized, 3, 9, 3) + b3hcat = Array{Float64}(undef, 3, 9, 3) b3hcat[:, :, 1] = hcat(b1, b1, b1) b3hcat[:, :, 2] = hcat(b2, b2, b2) b3hcat[:, :, 3] = hcat(b3, b3, b3) @@ -835,12 +835,12 @@ end @testset "ImageCore #40" begin Base.convert(::Type{Array{T,n}}, a::Array{T,n}) where {T<:Number,n} = a Base.convert(::Type{Array{T,n}}, a::Array) where {T<:Number,n} = - copyto!(Array{T,n}(uninitialized, size(a)), a) + copyto!(Array{T,n}(undef, size(a)), a) @test isa(empty(Dict(:a=>1, :b=>2.0), Union{}, Union{}), Dict{Union{}, Union{}}) end @testset "zero-dimensional copy" begin - Z = Array{Int,0}(uninitialized); Z[] = 17 + Z = Array{Int,0}(undef); Z[] = 17 @test Z == Array(Z) == copy(Z) end diff --git a/test/ambiguous.jl b/test/ambiguous.jl index e1835de6d6944..674f549ce3ba8 100644 --- a/test/ambiguous.jl +++ b/test/ambiguous.jl @@ -217,9 +217,9 @@ end foo(::Type{Array{T,N}}, A::MyArray{T,N}) where {T,N} = A.data foo(::Type{Array{T,N}}, A::MyArray{T,N}) where {T<:AbstractFloat,N} = A.data foo(::Type{Array{S,N}}, A::MyArray{T,N}) where {S<:AbstractFloat,N,T<:AbstractFloat} = - copyto!(Array{S}(uninitialized, unsize(A)), A.data) + copyto!(Array{S}(undef, unsize(A)), A.data) foo(::Type{Array{S,N}}, A::AbstractArray{T,N}) where {S<:AbstractFloat,N,T<:AbstractFloat} = - copyto!(Array{S}(uninitialized, size(A)), A) + copyto!(Array{S}(undef, size(A)), A) end @test isempty(detect_ambiguities(Ambig17648)) diff --git a/test/arrayops.jl b/test/arrayops.jl index 1afdf7dc21c0f..a460a5ec52493 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -63,7 +63,7 @@ using Random, LinearAlgebra a[:, [1 2]] = 2 @test a == fill(2.,2,2) - a = Array{Float64}(uninitialized, 2, 2, 2, 2, 2) + a = Array{Float64}(undef, 2, 2, 2, 2, 2) a[1,1,1,1,1] = 10 a[1,2,1,1,2] = 20 a[1,1,2,2,1] = 30 @@ -324,19 +324,19 @@ end @test length(rt) == 1 && rt[1] == Array{Int32, 3} end @testset "construction" begin - @test typeof(Vector{Int}(uninitialized, 3)) == Vector{Int} + @test typeof(Vector{Int}(undef, 3)) == Vector{Int} @test typeof(Vector{Int}()) == Vector{Int} - @test typeof(Vector(uninitialized, 3)) == Vector{Any} + @test typeof(Vector(undef, 3)) == Vector{Any} @test typeof(Vector()) == Vector{Any} - @test typeof(Matrix{Int}(uninitialized, 2,3)) == Matrix{Int} - @test typeof(Matrix(uninitialized, 2,3)) == Matrix{Any} + @test typeof(Matrix{Int}(undef, 2,3)) == Matrix{Int} + @test typeof(Matrix(undef, 2,3)) == Matrix{Any} - @test size(Vector{Int}(uninitialized, 3)) == (3,) + @test size(Vector{Int}(undef, 3)) == (3,) @test size(Vector{Int}()) == (0,) - @test size(Vector(uninitialized, 3)) == (3,) + @test size(Vector(undef, 3)) == (3,) @test size(Vector()) == (0,) - @test size(Matrix{Int}(uninitialized, 2,3)) == (2,3) - @test size(Matrix(uninitialized, 2,3)) == (2,3) + @test size(Matrix{Int}(undef, 2,3)) == (2,3) + @test size(Matrix(undef, 2,3)) == (2,3) @test_throws MethodError Matrix() @test_throws MethodError Matrix{Int}() @@ -416,9 +416,9 @@ end @test_throws MethodError UInt8[1:3] @test_throws MethodError UInt8[1:3,] @test_throws MethodError UInt8[1:3,4:6] - a = Vector{UnitRange{Int}}(uninitialized, 1); a[1] = 1:3 + a = Vector{UnitRange{Int}}(undef, 1); a[1] = 1:3 @test _array_equiv([1:3,], a) - a = Vector{UnitRange{Int}}(uninitialized, 2); a[1] = 1:3; a[2] = 4:6 + a = Vector{UnitRange{Int}}(undef, 2); a[1] = 1:3; a[2] = 4:6 @test _array_equiv([1:3,4:6], a) end @@ -832,7 +832,7 @@ end R = repeat(A, inner = (1, 1, 2), outer = (1, 1, 1)) T = reshape([1:4; 1:4; 5:8; 5:8], 2, 2, 4) @test R == T - A = Array{Int}(uninitialized, 2, 2, 2) + A = Array{Int}(undef, 2, 2, 2) A[:, :, 1] = [1 2; 3 4] A[:, :, 2] = [5 6; @@ -1197,11 +1197,11 @@ end @test A == [1 1 3; 2 2 3; 1 1 1] rt = Base.return_types(fill!, Tuple{Array{Int32, 3}, UInt8}) @test length(rt) == 1 && rt[1] == Array{Int32, 3} - A = Vector{Union{UInt8,Int8}}(uninitialized, 3) + A = Vector{Union{UInt8,Int8}}(undef, 3) fill!(A, UInt8(3)) @test A == [0x03, 0x03, 0x03] # Issue #9964 - A = Array{Vector{Float64}}(uninitialized, 2) + A = Array{Vector{Float64}}(undef, 2) fill!(A, [1, 2]) @test A[1] == [1, 2] @test A[1] === A[2] @@ -1346,7 +1346,7 @@ end @test isequal(flipdim(1:10, 1), 10:-1:1) @test_throws ArgumentError flipdim(1:10, 2) @test_throws ArgumentError flipdim(1:10, -1) - @test isequal(flipdim(Matrix{Int}(uninitialized, 0,0),1), Matrix{Int}(uninitialized, 0,0)) # issue #5872 + @test isequal(flipdim(Matrix{Int}(undef, 0,0),1), Matrix{Int}(undef, 0,0)) # issue #5872 a = rand(5,3) @test flipdim(flipdim(a,2),2) == a @@ -1474,25 +1474,25 @@ end @test indexin([3.0], 2:5) == [2] #6828 - size of specific dimensions -let a = Array{Float64}(uninitialized, 10) +let a = Array{Float64}(undef, 10) @test size(a) == (10,) @test size(a, 1) == 10 @test size(a,2,1) == (1,10) - aa = Array{Float64}(uninitialized, 2,3) + aa = Array{Float64}(undef, 2,3) @test size(aa) == (2,3) @test size(aa,4,3,2,1) == (1,1,3,2) @test size(aa,1,2) == (2,3) - aaa = Array{Float64}(uninitialized, 9,8,7,6,5,4,3,2,1) + aaa = Array{Float64}(undef, 9,8,7,6,5,4,3,2,1) @test size(aaa,1,1) == (9,9) @test size(aaa,4) == 6 @test size(aaa,9,8,7,6,5,4,3,2,19,8,7,6,5,4,3,2,1) == (1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9) #18459 Test Array{T, N} constructor - b = Vector{Float64}(uninitialized, 10) + b = Vector{Float64}(undef, 10) @test size(a) == size(b) - bb = Matrix{Float64}(uninitialized, 2,3) + bb = Matrix{Float64}(undef, 2,3) @test size(aa) == size(bb) - bbb = Array{Float64,9}(uninitialized, 9,8,7,6,5,4,3,2,1) + bbb = Array{Float64,9}(undef, 9,8,7,6,5,4,3,2,1) @test size(aaa) == size(bbb) end @@ -1572,10 +1572,10 @@ end @test mdsum(a) == 2 @test mdsum2(a) == 2 - a = Matrix{Float64}(uninitialized,0,5) + a = Matrix{Float64}(undef,0,5) b = view(a, :, :) @test mdsum(b) == 0 - a = Matrix{Float64}(uninitialized,5,0) + a = Matrix{Float64}(undef,5,0) b = view(a, :, :) @test mdsum(b) == 0 end @@ -2166,21 +2166,21 @@ end # module AutoRetType @test isa(cat((1,2), densevec, densemat), Array) end -@testset "type constructor Array{T, N}(uninitialized, d...) works (especially for N>3)" begin - a = Array{Float64}(uninitialized, 10) - b = Vector{Float64}(uninitialized, 10) +@testset "type constructor Array{T, N}(undef, d...) works (especially for N>3)" begin + a = Array{Float64}(undef, 10) + b = Vector{Float64}(undef, 10) @test size(a) == (10,) @test size(a, 1) == 10 @test size(a,2,1) == (1,10) @test size(a) == size(b) - a = Array{Float64}(uninitialized, 2,3) - b = Matrix{Float64}(uninitialized, 2,3) + a = Array{Float64}(undef, 2,3) + b = Matrix{Float64}(undef, 2,3) @test size(a) == (2,3) @test size(a,4,3,2,1) == (1,1,3,2) @test size(a,1,2) == (2,3) @test size(a) == size(b) - a = Array{Float64}(uninitialized, 9,8,7,6,5,4,3,2,1) - b = Array{Float64,9}(uninitialized, 9,8,7,6,5,4,3,2,1) + a = Array{Float64}(undef, 9,8,7,6,5,4,3,2,1) + b = Array{Float64,9}(undef, 9,8,7,6,5,4,3,2,1) @test size(a,1,1) == (9,9) @test size(a,4) == 6 @test size(a,9,8,7,6,5,4,3,2,19,8,7,6,5,4,3,2,1) == (1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9) @@ -2329,7 +2329,7 @@ Base.:(==)(a::T11053, b::T11053) = a.a == b.a @test [T11053(1)] * 5 == [T11053(1)] .* 5 == [T11053(5.0)] #15907 -@test typeof(Array{Int,0}(uninitialized)) == Array{Int,0} +@test typeof(Array{Int,0}(undef)) == Array{Int,0} # check a == b for arrays of Union type (#22403) let TT = Union{UInt8, Int8} diff --git a/test/bigint.jl b/test/bigint.jl index c1372afea4f52..e38e7f861b8fc 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -252,7 +252,7 @@ end # from Bill Hart, https://groups.google.com/group/julia-dev/browse_frm/thread/798e2d1322daf633 function mul(a::Vector{BigInt}, b::Vector{BigInt}) x = a[2]*b[2] - c = Vector{BigInt}(uninitialized, 3) + c = Vector{BigInt}(undef, 3) c[1] = a[1]*b[1] + x c[2] = a[1]*b[2] + a[2]*b[3] c[3] = x + a[3]*b[3] diff --git a/test/bitarray.jl b/test/bitarray.jl index 40ce442c452fa..3947b97d60d6e 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -42,7 +42,7 @@ let t0 = time() end @testset "empty bitvector" begin - @test BitVector() == BitVector(uninitialized, 0) + @test BitVector() == BitVector(undef, 0) end # vectors size @@ -161,8 +161,8 @@ timesofar("conversions") end @testset "sizeof (issue #7515)" begin - @test sizeof(BitVector(uninitialized, 64)) == 8 - @test sizeof(BitVector(uninitialized, 65)) == 16 + @test sizeof(BitVector(undef, 64)) == 8 + @test sizeof(BitVector(undef, 65)) == 16 end end @@ -170,8 +170,8 @@ timesofar("utils") @testset "Constructors" begin @testset "non-Int dims constructors" begin - b1 = BitVector(uninitialized, Int32(v1)) - b2 = BitVector(uninitialized, Int64(v1)) + b1 = BitVector(undef, Int32(v1)) + b2 = BitVector(undef, Int64(v1)) @test size(b1) == size(b2) for c in [trues, falses] @@ -192,8 +192,8 @@ timesofar("utils") end @testset "one" begin - @test Array(one(BitMatrix(uninitialized, 2,2))) == Matrix(I, 2, 2) - @test_throws DimensionMismatch one(BitMatrix(uninitialized, 2,3)) + @test Array(one(BitMatrix(undef, 2,2))) == Matrix(I, 2, 2) + @test_throws DimensionMismatch one(BitMatrix(undef, 2,3)) end # constructors should copy @@ -1273,7 +1273,7 @@ timesofar("reductions") @test map(!=, b1, b2) == map((x,y)->x!=y, b1, b2) == (b1 .!= b2) @testset "map! for length $l" begin - b = BitVector(uninitialized, l) + b = BitVector(undef, l) @test map!(~, b, b1) == map!(x->~x, b, b1) == broadcast(~, b1) == b @test map!(!, b, b1) == map!(x->!x, b, b1) == broadcast(~, b1) == b @test map!(identity, b, b1) == map!(x->x, b, b1) == b1 == b diff --git a/test/broadcast.jl b/test/broadcast.jl index e1e4a0690f3a3..b1774c522a2e7 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -423,7 +423,7 @@ Base.getindex(A::ArrayData, i::Integer...) = A.data[i...] Base.setindex!(A::ArrayData, v::Any, i::Integer...) = setindex!(A.data, v, i...) Base.size(A::ArrayData) = size(A.data) Base.broadcast_similar(f, ::Broadcast.ArrayStyle{A}, ::Type{T}, inds::Tuple, As...) where {A,T} = - A(Array{T}(uninitialized, length.(inds))) + A(Array{T}(undef, length.(inds))) struct Array19745{T,N} <: ArrayData{T,N} data::Array{T,N} diff --git a/test/codegen.jl b/test/codegen.jl index 475d2e1abe973..4f263b5e79703 100644 --- a/test/codegen.jl +++ b/test/codegen.jl @@ -328,7 +328,7 @@ end str_22330 = """ Base.convert(::Type{Array{T,n}}, a::Array) where {T<:Number,n} = - copyto!(Array{T,n}(uninitialized, size(a)), a) + copyto!(Array{T,n}(undef, size(a)), a) empty(Dict(), Pair{Union{},Union{}}) """ diff --git a/test/compiler/compiler.jl b/test/compiler/compiler.jl index d6c107b3f669b..97a21dda0fc0a 100644 --- a/test/compiler/compiler.jl +++ b/test/compiler/compiler.jl @@ -1091,8 +1091,8 @@ test_const_return(()->sizeof(Int), Tuple{}, sizeof(Int)) test_const_return(()->sizeof(1), Tuple{}, sizeof(Int)) test_const_return(()->sizeof(DataType), Tuple{}, sizeof(DataType)) test_const_return(()->sizeof(1 < 2), Tuple{}, 1) -@eval test_const_return(()->Core.sizeof($(Array{Int,0}(uninitialized))), Tuple{}, sizeof(Int)) -@eval test_const_return(()->Core.sizeof($(Matrix{Float32}(uninitialized, 2, 2))), Tuple{}, 4 * 2 * 2) +@eval test_const_return(()->Core.sizeof($(Array{Int,0}(undef))), Tuple{}, sizeof(Int)) +@eval test_const_return(()->Core.sizeof($(Matrix{Float32}(undef, 2, 2))), Tuple{}, 4 * 2 * 2) # Make sure Core.sizeof with a ::DataType as inferred input type is inferred but not constant. function sizeof_typeref(typeref) diff --git a/test/core.jl b/test/core.jl index f68234ca609fd..f09cef74f65ac 100644 --- a/test/core.jl +++ b/test/core.jl @@ -488,7 +488,7 @@ function const_implies_local() end @test const_implies_local() === (1, 0) -a_global_closure_vector = Vector{Any}(uninitialized, 3) +a_global_closure_vector = Vector{Any}(undef, 3) for i = 1:3 let ii = i a_global_closure_vector[i] = x -> x + ii @@ -606,11 +606,11 @@ end let local a - a = Vector{Any}(uninitialized, 2) + a = Vector{Any}(undef, 2) @test !isassigned(a,1) && !isassigned(a,2) a[1] = 1 @test isassigned(a,1) && !isassigned(a,2) - a = Vector{Float64}(uninitialized,1) + a = Vector{Float64}(undef,1) @test isassigned(a,1) @test isassigned(a) @test !isassigned(a,2) @@ -1306,7 +1306,7 @@ let # issue #1886 X = [1:4;] - r = Vector{UnitRange{Int}}(uninitialized, 1) + r = Vector{UnitRange{Int}}(undef, 1) r[1] = 2:3 X[r...] *= 2 @test X == [1,4,6,4] @@ -1371,7 +1371,7 @@ struct Foo2509; foo::Int; end # issue #2517 struct Foo2517; end @test repr(Foo2517()) == "$(curmod_prefix)Foo2517()" -@test repr(Vector{Foo2517}(uninitialized, 1)) == "$(curmod_prefix)Foo2517[$(curmod_prefix)Foo2517()]" +@test repr(Vector{Foo2517}(undef, 1)) == "$(curmod_prefix)Foo2517[$(curmod_prefix)Foo2517()]" @test Foo2517() === Foo2517() # issue #1474 @@ -1500,13 +1500,13 @@ end # issue #3167 let function foo(x) - ret=Vector{typeof(x[1])}(uninitialized, length(x)) + ret=Vector{typeof(x[1])}(undef, length(x)) for j = 1:length(x) ret[j] = x[j] end return ret end - x = Vector{Union{Dict{Int64,AbstractString},Array{Int64,3},Number,AbstractString,Nothing}}(uninitialized, 3) + x = Vector{Union{Dict{Int64,AbstractString},Array{Int64,3},Number,AbstractString,Nothing}}(undef, 3) x[1] = 1.0 x[2] = 2.0 x[3] = 3.0 @@ -1754,7 +1754,7 @@ end @test invalid_tupleref()==true # issue #5150 -f5150(T) = Vector{Rational{T}}(uninitialized, 1) +f5150(T) = Vector{Rational{T}}(undef, 1) @test typeof(f5150(Int)) === Vector{Rational{Int}} @@ -1904,7 +1904,7 @@ mutable struct Polygon5884{T<:Real} end function test5884() - star = Vector{Polygon5884}(uninitialized, (3,)) + star = Vector{Polygon5884}(undef, (3,)) star[1] = Polygon5884([Complex(1.0,1.0)]) p1 = star[1].points[1] @test p1 == Complex(1.0,1.0) @@ -2097,7 +2097,7 @@ end obj6387 = ObjMember(DateRange6387{Int64}()) function v6387(r::AbstractRange{T}) where T - a = Vector{T}(uninitialized, 1) + a = Vector{T}(undef, 1) a[1] = Core.Intrinsics.bitcast(Date6387{Int64}, Int64(1)) return a end @@ -2110,8 +2110,8 @@ end day_in(obj6387) # issue #6784 -@test ndims(Array{Array{Float64}}(uninitialized, 3,5)) == 2 -@test ndims(Array{Array}(uninitialized, 3,5)) == 2 +@test ndims(Array{Array{Float64}}(undef, 3,5)) == 2 +@test ndims(Array{Array}(undef, 3,5)) == 2 # issue #6793 function segfault6793(;gamma=1) @@ -2345,7 +2345,7 @@ end # issue #9475 module I9475 - arr = Vector{Any}(uninitialized, 1) + arr = Vector{Any}(undef, 1) @eval @eval $arr[1] = 1 end @@ -3267,7 +3267,7 @@ mutable struct D11597{T} <: C11597{T} d::T end @test_throws TypeError repr(D11597(1.0)) # issue #11772 -@test_throws UndefRefError (Vector{Any}(uninitialized, 5)...,) +@test_throws UndefRefError (Vector{Any}(undef, 5)...,) # issue #11813 let a = UInt8[1, 107, 66, 88, 2, 99, 254, 13, 0, 0, 0, 0] @@ -3494,7 +3494,7 @@ end # issue #12394 mutable struct Empty12394 end -let x = Vector{Empty12394}(uninitialized, 1), y = [Empty12394()] +let x = Vector{Empty12394}(undef, 1), y = [Empty12394()] @test_throws UndefRefError x==y @test_throws UndefRefError y==x end @@ -3633,7 +3633,7 @@ end #13433, read!(::IO, a::Vector{UInt8}) should return a mutable struct IO13433 <: IO end Base.read(::IO13433, ::Type{UInt8}) = 0x01 -@test read!(IO13433(), Array{UInt8}(uninitialized, 4)) == [0x01, 0x01, 0x01, 0x01] +@test read!(IO13433(), Array{UInt8}(undef, 4)) == [0x01, 0x01, 0x01, 0x01] # issue #13647, comparing boxed isbits immutables struct X13647 @@ -3670,7 +3670,7 @@ f11327(::Type{T},x::T) where {T} = x # issue #8487 @test [x for x in 1:3] == [x for x ∈ 1:3] == [x for x = 1:3] -let A = Matrix{Int}(uninitialized, 4,3) +let A = Matrix{Int}(undef, 4,3) for i ∈ 1:size(A,1), j ∈ 1:size(A,2) A[i,j] = 17*i + 51*j end @@ -3969,7 +3969,7 @@ end # issue #15180 function f15180(x::T) where T - X = Vector{T}(uninitialized, 1) + X = Vector{T}(undef, 1) X[1] = x @noinline ef(::J) where {J} = (J,X[1]) # Use T ef(::J, ::Int) where {J} = (T,J) @@ -3977,7 +3977,7 @@ function f15180(x::T) where T end @test map(f15180(1), [1,2]) == [(Int,1),(Int,1)] -let ary = Vector{Any}(uninitialized, 10) +let ary = Vector{Any}(undef, 10) check_undef_and_fill(ary, rng) = for i in rng @test !isassigned(ary, i) ary[i] = (Float64(i), i) # some non-cached content @@ -3995,20 +3995,20 @@ let ary = Vector{Any}(uninitialized, 10) check_undef_and_fill(ary, 16:20) # Now check grow/del_end - ary = Vector{Any}(uninitialized, 1010) + ary = Vector{Any}(undef, 1010) check_undef_and_fill(ary, 1:1010) # This del_beg should move the buffer ccall(:jl_array_del_beg, Cvoid, (Any, Csize_t), ary, 1000) ccall(:jl_array_grow_beg, Cvoid, (Any, Csize_t), ary, 1000) check_undef_and_fill(ary, 1:1000) - ary = Vector{Any}(uninitialized, 1010) + ary = Vector{Any}(undef, 1010) check_undef_and_fill(ary, 1:1010) # This del_beg should not move the buffer ccall(:jl_array_del_beg, Cvoid, (Any, Csize_t), ary, 10) ccall(:jl_array_grow_beg, Cvoid, (Any, Csize_t), ary, 10) check_undef_and_fill(ary, 1:10) - ary = Vector{Any}(uninitialized, 1010) + ary = Vector{Any}(undef, 1010) check_undef_and_fill(ary, 1:1010) ccall(:jl_array_grow_end, Cvoid, (Any, Csize_t), ary, 10) check_undef_and_fill(ary, 1011:1020) @@ -4021,7 +4021,7 @@ let ary = Vector{Any}(uninitialized, 10) # we are malloc'ing the buffer after the grow_end and malloc is not using # mmap directly (which may return a zero'd new page). for n in [50, 51, 100, 101, 200, 201, 300, 301] - ary = Vector{Any}(uninitialized, n) + ary = Vector{Any}(undef, n) # Try to free the previous buffer that was filled with random content # and to increase the chance of getting a non-zero'd buffer next time GC.gc() @@ -4034,7 +4034,7 @@ let ary = Vector{Any}(uninitialized, 10) check_undef_and_fill(ary, 1:(2n + 4)) end - ary = Vector{Any}(uninitialized, 100) + ary = Vector{Any}(undef, 100) ccall(:jl_array_grow_end, Cvoid, (Any, Csize_t), ary, 10000) ary[:] = 1:length(ary) ccall(:jl_array_del_beg, Cvoid, (Any, Csize_t), ary, 10000) @@ -4048,7 +4048,7 @@ let ary = Vector{Any}(uninitialized, 10) end end - ary = Vector{Any}(uninitialized, 100) + ary = Vector{Any}(undef, 100) ary[:] = 1:length(ary) ccall(:jl_array_grow_at, Cvoid, (Any, Csize_t, Csize_t), ary, 50, 10) for i in 51:60 @@ -4105,14 +4105,14 @@ end @test M15455.partialsort(1,2)==0 # check that medium-sized array is 64-byte aligned (#15139) -@test Int(pointer(Vector{Float64}(uninitialized, 1024))) % 64 == 0 +@test Int(pointer(Vector{Float64}(undef, 1024))) % 64 == 0 # PR #15413 # Make sure arrayset can handle `Array{T}` (where `T` is a type and not a # `TypeVar`) without crashing let function arrayset_unknown_dim(::Type{T}, n) where T - Base.arrayset(true, reshape(Vector{T}(uninitialized, 1), fill(1, n)...), 2, 1) + Base.arrayset(true, reshape(Vector{T}(undef, 1), fill(1, n)...), 2, 1) end arrayset_unknown_dim(Any, 1) arrayset_unknown_dim(Any, 2) @@ -4128,7 +4128,7 @@ using Test # not modify the original data function test_shared_array_resize(::Type{T}) where T len = 100 - a = Vector{T}(uninitialized, len) + a = Vector{T}(undef, len) function test_unshare(f) a′ = reshape(reshape(a, (len ÷ 2, 2)), len) a[:] = 1:length(a) @@ -4205,7 +4205,7 @@ f = unsafe_wrap(Array, ccall(:malloc, Ptr{UInt8}, (Csize_t,), 10), 10, own = tru end # Copy of `#undef` -copyto!(Vector{Any}(uninitialized, 10), Vector{Any}(uninitialized, 10)) +copyto!(Vector{Any}(undef, 10), Vector{Any}(undef, 10)) function test_copy_alias(::Type{T}) where T ary = T[1:100;] unsafe_copyto!(ary, 1, ary, 11, 90) @@ -5173,7 +5173,7 @@ end x::Array{T} where T<:Integer end -let a = Vector{Core.TypeofBottom}(uninitialized, 2) +let a = Vector{Core.TypeofBottom}(undef, 2) @test a[1] == Union{} @test a == [Union{}, Union{}] end @@ -5214,7 +5214,7 @@ end let ni128 = sizeof(FP128test) ÷ sizeof(Int), ns128 = sizeof(FP128align) ÷ sizeof(Int), nbit = sizeof(Int) * 8, - arr = Vector{FP128align}(uninitialized, 2), + arr = Vector{FP128align}(undef, 2), offset = Base.datatype_alignment(FP128test) ÷ sizeof(Int), little, expected, @@ -5746,11 +5746,11 @@ end for U in boxedunions local U for N in (1, 2, 3, 4) - A = Array{U}(uninitialized, ntuple(x->0, N)...) + A = Array{U}(undef, ntuple(x->0, N)...) @test isempty(A) @test sizeof(A) == 0 - A = Array{U}(uninitialized, ntuple(x->10, N)...) + A = Array{U}(undef, ntuple(x->10, N)...) @test length(A) == 10^N @test sizeof(A) == sizeof(Int) * (10^N) @test !isassigned(A, 1) @@ -5766,7 +5766,7 @@ let end # copyto! -A23567 = Vector{Union{Float64, Nothing}}(uninitialized, 5) +A23567 = Vector{Union{Float64, Nothing}}(undef, 5) B23567 = collect(Union{Float64, Nothing}, 1.0:3.0) copyto!(A23567, 2, B23567) @test A23567[1] === nothing @@ -5787,13 +5787,13 @@ using Serialization for U in unboxedunions local U for N in (1, 2, 3, 4) - A = Array{U}(uninitialized, ntuple(x->0, N)...) + A = Array{U}(undef, ntuple(x->0, N)...) @test isempty(A) @test sizeof(A) == 0 len = ntuple(x->10, N) mxsz = maximum(sizeof, Base.uniontypes(U)) - A = Array{U}(uninitialized, len) + A = Array{U}(undef, len) @test length(A) == prod(len) @test sizeof(A) == prod(len) * mxsz @test isassigned(A, 1) diff --git a/test/errorshow.jl b/test/errorshow.jl index 1841715856e0a..e28976ef47ccf 100644 --- a/test/errorshow.jl +++ b/test/errorshow.jl @@ -263,7 +263,7 @@ let undefvar err_str = @except_str mod(1,0) DivideError @test err_str == "DivideError: integer division error" - err_str = @except_str Vector{Any}(uninitialized, 1)[1] UndefRefError + err_str = @except_str Vector{Any}(undef, 1)[1] UndefRefError @test err_str == "UndefRefError: access to undefined reference" err_str = @except_str undefvar UndefVarError @test err_str == "UndefVarError: undefvar not defined" diff --git a/test/file.jl b/test/file.jl index 6f18411f3a02a..33c4ccd172cfd 100644 --- a/test/file.jl +++ b/test/file.jl @@ -816,7 +816,7 @@ end ################### function test_LibcFILE(FILEp) - buf = Vector{UInt8}(uninitialized, 8) + buf = Vector{UInt8}(undef, 8) str = ccall(:fread, Csize_t, (Ptr{Cvoid}, Csize_t, Csize_t, Ptr{Cvoid}), buf, 1, 8, FILEp) @test String(buf) == "Hello, w" @test position(FILEp) == 8 diff --git a/test/functional.jl b/test/functional.jl index 0b40087416e45..a835ec693ae0a 100644 --- a/test/functional.jl +++ b/test/functional.jl @@ -21,7 +21,7 @@ end # map over Bottom[] should return Bottom[] # issue #6719 -@test isequal(typeof(map(x -> x, Vector{Union{}}(uninitialized, 0))), Vector{Union{}}) +@test isequal(typeof(map(x -> x, Vector{Union{}}(undef, 0))), Vector{Union{}}) # maps of tuples (formerly in test/core.jl) -- tuple.jl @test map((x,y)->x+y,(1,2,3),(4,5,6)) == (5,7,9) @@ -83,10 +83,10 @@ end let gens_dims = [((i for i = 1:5), 1), ((i for i = 1:5, j = 1:5), 2), ((i for i = 1:5, j = 1:5, k = 1:5), 3), - ((i for i = Array{Int,0}(uninitialized)), 0), - ((i for i = Vector{Int}(uninitialized, 1)), 1), - ((i for i = Matrix{Int}(uninitialized, 1, 2)), 2), - ((i for i = Array{Int}(uninitialized, 1, 2, 3)), 3)] + ((i for i = Array{Int,0}(undef)), 0), + ((i for i = Vector{Int}(undef, 1)), 1), + ((i for i = Matrix{Int}(undef, 1, 2)), 2), + ((i for i = Array{Int}(undef, 1, 2, 3)), 3)] for (gen, dim) in gens_dims @test ndims(gen) == ndims(collect(gen)) == dim end diff --git a/test/generic_map_tests.jl b/test/generic_map_tests.jl index cb911bb82baa6..15c6ca8c6165d 100644 --- a/test/generic_map_tests.jl +++ b/test/generic_map_tests.jl @@ -36,7 +36,7 @@ function generic_map_tests(mapf, inplace_mapf=nothing) end # AbstractArray map for N-arg case - A = Array{Int}(uninitialized, 10) + A = Array{Int}(undef, 10) f(x, y, z) = x + y + z D = Float64[1:10...] @@ -77,7 +77,7 @@ end function run_map_equivalence_tests(mapf) testmap_equivalence(mapf, identity, (1,2,3,4)) testmap_equivalence(mapf, (x,y,z)->x+y+z, 1,2,3) - testmap_equivalence(mapf, x->x ? false : true, BitMatrix(uninitialized, 10,10)) - testmap_equivalence(mapf, x->"foobar", BitMatrix(uninitialized, 10,10)) - testmap_equivalence(mapf, (x,y,z)->string(x,y,z), BitVector(uninitialized, 10), fill(1.0, 10), "1234567890") + testmap_equivalence(mapf, x->x ? false : true, BitMatrix(undef, 10,10)) + testmap_equivalence(mapf, x->"foobar", BitMatrix(undef, 10,10)) + testmap_equivalence(mapf, (x,y,z)->string(x,y,z), BitVector(undef, 10), fill(1.0, 10), "1234567890") end diff --git a/test/grisu.jl b/test/grisu.jl index 7ab79d6815f05..f11d694225824 100644 --- a/test/grisu.jl +++ b/test/grisu.jl @@ -14,7 +14,7 @@ function trimrep(buffer) end const bufsize = 500 -buffer = Vector{UInt8}(uninitialized, bufsize) +buffer = Vector{UInt8}(undef, bufsize) fill!(buffer,0) bignums = [Grisu.Bignums.Bignum(),Grisu.Bignums.Bignum(),Grisu.Bignums.Bignum(),Grisu.Bignums.Bignum()] diff --git a/test/iobuffer.jl b/test/iobuffer.jl index 291ee36659d85..65ebdf7d9e4a7 100644 --- a/test/iobuffer.jl +++ b/test/iobuffer.jl @@ -19,7 +19,7 @@ bufcontents(io::Base.GenericIOBuffer) = unsafe_string(pointer(io.data), io.size) @test eof(io) seek(io, 0) @test read(io,UInt8) == convert(UInt8, 'a') - a = Vector{UInt8}(uninitialized, 2) + a = Vector{UInt8}(undef, 2) @test read!(io, a) == a @test a == UInt8['b','c'] @test bufcontents(io) == "abc" @@ -169,7 +169,7 @@ end @testset "issue 5453" begin io = IOBuffer("abcdef") - a = Vector{UInt8}(uninitialized, 1024) + a = Vector{UInt8}(undef, 1024) @test_throws EOFError read!(io,a) @test eof(io) end @@ -200,7 +200,7 @@ end @test read(io, Char) == 'α' @test_throws ArgumentError write(io,"!") @test_throws ArgumentError write(io,'β') - a = Vector{UInt8}(uninitialized, 10) + a = Vector{UInt8}(undef, 10) @test read!(io, a) === a @test String(a) == "helloworld" @test read(io, Char) == 'ω' diff --git a/test/iterators.jl b/test/iterators.jl index 28062bd4114ad..039e67909909d 100644 --- a/test/iterators.jl +++ b/test/iterators.jl @@ -478,7 +478,7 @@ end @testset "reverse iterators" begin squash(x::Number) = x squash(A) = reshape(A, length(A)) - Z = Array{Int,0}(uninitialized); Z[] = 17 # zero-dimensional test case + Z = Array{Int,0}(undef); Z[] = 17 # zero-dimensional test case for itr in (2:10, "∀ϵ>0", 1:0, "", (2,3,5,7,11), [2,3,5,7,11], rand(5,6), Z, 3, true, 'x', 4=>5, eachindex("∀ϵ>0"), view(Z), view(rand(5,6),2:4,2:6), (x^2 for x in 1:10), Iterators.Filter(isodd, 1:10), flatten((1:10, 50:60)), enumerate("foo"), diff --git a/test/netload/memtest.jl b/test/netload/memtest.jl index dade493720c13..1e4685d341950 100644 --- a/test/netload/memtest.jl +++ b/test/netload/memtest.jl @@ -22,7 +22,7 @@ struct RUsage end function get_vmsize() - ru = Vector{RUsage}(uninitialized, 1) + ru = Vector{RUsage}(undef, 1) ccall(:getrusage, Cint, (Cint, Ptr{Cvoid}), 0, ru) return ru[1].ru_maxrss end diff --git a/test/numbers.jl b/test/numbers.jl index 1fd4c4bb78a3a..91241e7678371 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2484,8 +2484,8 @@ end f20065(B, i) = UInt8(B[i]) @testset "issue 20065" begin # f20065 must be called from global scope to exhibit the buggy behavior - for B in (Vector{Bool}(uninitialized, 10), - Matrix{Bool}(uninitialized, 10,10), + for B in (Vector{Bool}(undef, 10), + Matrix{Bool}(undef, 10,10), reinterpret(Bool, rand(UInt8, 10))) @test all(x-> x <= 1, (f20065(B, i) for i in eachindex(B))) for i in 1:length(B) diff --git a/test/offsetarray.jl b/test/offsetarray.jl index 42e05f1d4c252..4cfdc4009407e 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -61,7 +61,7 @@ S4 = OffsetArray(view(reshape(Vector(1:4*3*2), 4, 3, 2), 1:3, 1:2, :), (-1,-2,1) @test A[1, [4,3]] == S[1, [4,3]] == [4,2] @test A[:, :] == S[:, :] == A -A_3_3 = OffsetArray(Matrix{Int}(uninitialized, 3,3), (-2,-1)) +A_3_3 = OffsetArray(Matrix{Int}(undef, 3,3), (-2,-1)) A_3_3[:, :] = reshape(1:9, 3, 3) for i = 1:9 @test A_3_3[i] == i end A_3_3[-1:1, 0:2] = reshape(1:9, 3, 3) @@ -232,7 +232,7 @@ v = view(A0, 1:1, i1) @test axes(v) === (Base.OneTo(1), -4:-3) # copyto! and fill! -a = OffsetArray{Int}(uninitialized, (-3:-1,)) +a = OffsetArray{Int}(undef, (-3:-1,)) fill!(a, -1) copyto!(a, (1,2)) # non-array iterables @test a[-3] == 1 @@ -276,7 +276,7 @@ copyto!(a, -3, b, 2) @test a[-3] == 2 @test a[-2] == a[-1] == -1 @test_throws BoundsError copyto!(a, -3, b, 1, 4) -am = OffsetArray{Int}(uninitialized, (1:1, 7:9)) # for testing linear indexing +am = OffsetArray{Int}(undef, (1:1, 7:9)) # for testing linear indexing fill!(am, -1) copyto!(am, b) @test am[1] == 1 @@ -431,7 +431,7 @@ v = OffsetArray(rand(8), (-2,)) @test circshift(A, (-1,2)) == OffsetArray(circshift(parent(A), (-1,2)), A.offsets) src = reshape(Vector(1:16), (4,4)) -dest = OffsetArray(Matrix{Int}(uninitialized, 4,4), (-1,1)) +dest = OffsetArray(Matrix{Int}(undef, 4,4), (-1,1)) circcopy!(dest, src) @test parent(dest) == [8 12 16 4; 5 9 13 1; 6 10 14 2; 7 11 15 3] @test dest[1:3,2:4] == src[1:3,2:4] @@ -448,7 +448,7 @@ module SimilarUR stop::Int end ur = MyURange(1,3) - a = Vector{Int}(uninitialized, 2) + a = Vector{Int}(undef, 2) @test_throws MethodError similar(a, ur) @test_throws MethodError similar(a, Float64, ur) @test_throws MethodError similar(a, Float64, (ur,)) diff --git a/test/read.jl b/test/read.jl index a88308d957087..e2e73fbe62e51 100644 --- a/test/read.jl +++ b/test/read.jl @@ -190,11 +190,11 @@ for (name, f) in l @test read(io(), Int) == read(filename,Int) s1 = io() s2 = IOBuffer(text) - @test read!(s1, Vector{UInt32}(uninitialized, 2)) == read!(s2, Vector{UInt32}(uninitialized, 2)) + @test read!(s1, Vector{UInt32}(undef, 2)) == read!(s2, Vector{UInt32}(undef, 2)) @test !eof(s1) - @test read!(s1, Vector{UInt8}(uninitialized, 5)) == read!(s2, Vector{UInt8}(uninitialized, 5)) + @test read!(s1, Vector{UInt8}(undef, 5)) == read!(s2, Vector{UInt8}(undef, 5)) @test !eof(s1) - @test read!(s1, Vector{UInt8}(uninitialized, 1)) == read!(s2, Vector{UInt8}(uninitialized, 1)) + @test read!(s1, Vector{UInt8}(undef, 1)) == read!(s2, Vector{UInt8}(undef, 1)) @test eof(s1) @test_throws EOFError read(s1, UInt8) @test eof(s1) @@ -203,16 +203,16 @@ for (name, f) in l verbose && println("$name eof...") n = length(text) - 1 - @test read!(io(), Vector{UInt8}(uninitialized, n)) == - read!(IOBuffer(text), Vector{UInt8}(uninitialized, n)) - @test (s = io(); read!(s, Vector{UInt8}(uninitialized, n)); !eof(s)) + @test read!(io(), Vector{UInt8}(undef, n)) == + read!(IOBuffer(text), Vector{UInt8}(undef, n)) + @test (s = io(); read!(s, Vector{UInt8}(undef, n)); !eof(s)) n = length(text) - @test read!(io(), Vector{UInt8}(uninitialized, n)) == - read!(IOBuffer(text), Vector{UInt8}(uninitialized, n)) - @test (s = io(); read!(s, Vector{UInt8}(uninitialized, n)); eof(s)) + @test read!(io(), Vector{UInt8}(undef, n)) == + read!(IOBuffer(text), Vector{UInt8}(undef, n)) + @test (s = io(); read!(s, Vector{UInt8}(undef, n)); eof(s)) n = length(text) + 1 - @test_throws EOFError read!(io(), Vector{UInt8}(uninitialized, n)) - @test_throws EOFError read!(io(), Vector{UInt8}(uninitialized, n)) + @test_throws EOFError read!(io(), Vector{UInt8}(undef, n)) + @test_throws EOFError read!(io(), Vector{UInt8}(undef, n)) old_text = text cleanup() @@ -244,8 +244,8 @@ for (name, f) in l verbose && println("$name readbytes!...") l = length(text) for n = [1, 2, l-2, l-1, l, l+1, l+2] - a1 = Vector{UInt8}(uninitialized, n) - a2 = Vector{UInt8}(uninitialized, n) + a1 = Vector{UInt8}(undef, n) + a2 = Vector{UInt8}(undef, n) s1 = io() s2 = IOBuffer(text) n1 = readbytes!(s1, a1) @@ -262,14 +262,14 @@ for (name, f) in l verbose && println("$name read!...") l = length(text) for n = [1, 2, l-2, l-1, l] - @test read!(io(), Vector{UInt8}(uninitialized, n)) == - read!(IOBuffer(text), Vector{UInt8}(uninitialized, n)) - @test read!(io(), Vector{UInt8}(uninitialized, n)) == - read!(filename, Vector{UInt8}(uninitialized, n)) + @test read!(io(), Vector{UInt8}(undef, n)) == + read!(IOBuffer(text), Vector{UInt8}(undef, n)) + @test read!(io(), Vector{UInt8}(undef, n)) == + read!(filename, Vector{UInt8}(undef, n)) cleanup() end - @test_throws EOFError read!(io(), Vector{UInt8}(uninitialized, length(text)+1)) + @test_throws EOFError read!(io(), Vector{UInt8}(undef, length(text)+1)) verbose && println("$name readuntil...") @@ -315,7 +315,7 @@ for (name, f) in l if !(typeof(io()) in [Base.PipeEndpoint, Pipe, TCPSocket]) verbose && println("$name position...") - @test (s = io(); read!(s, Vector{UInt8}(uninitialized, 4)); position(s)) == 4 + @test (s = io(); read!(s, Vector{UInt8}(undef, 4)); position(s)) == 4 verbose && println("$name seek...") for n = 0:length(text)-1 diff --git a/test/reducedim.jl b/test/reducedim.jl index e50a66ae22201..4beace3579254 100644 --- a/test/reducedim.jl +++ b/test/reducedim.jl @@ -122,7 +122,7 @@ end @test typeof(@inferred(reduce(+, 0.0, ones(3,3,3), dims=1))) == Array{Float64, 3} @testset "empty cases" begin - A = Matrix{Int}(uninitialized, 0,1) + A = Matrix{Int}(undef, 0,1) @test sum(A) === 0 @test prod(A) === 1 @test_throws ArgumentError minimum(A) diff --git a/test/show.jl b/test/show.jl index 10291439faf9a..6d0348946d5c8 100644 --- a/test/show.jl +++ b/test/show.jl @@ -22,15 +22,15 @@ showstr(x) = sprint((io,x) -> show(IOContext(io, :limit => true, :displaysize => :y => 2) end -@test replstr(Array{Any}(uninitialized, 2)) == "2-element Array{Any,1}:\n #undef\n #undef" -@test replstr(Array{Any}(uninitialized, 2,2)) == "2×2 Array{Any,2}:\n #undef #undef\n #undef #undef" -@test replstr(Array{Any}(uninitialized, 2,2,2)) == "2×2×2 Array{Any,3}:\n[:, :, 1] =\n #undef #undef\n #undef #undef\n\n[:, :, 2] =\n #undef #undef\n #undef #undef" +@test replstr(Array{Any}(undef, 2)) == "2-element Array{Any,1}:\n #undef\n #undef" +@test replstr(Array{Any}(undef, 2,2)) == "2×2 Array{Any,2}:\n #undef #undef\n #undef #undef" +@test replstr(Array{Any}(undef, 2,2,2)) == "2×2×2 Array{Any,3}:\n[:, :, 1] =\n #undef #undef\n #undef #undef\n\n[:, :, 2] =\n #undef #undef\n #undef #undef" @test replstr([1f10]) == "1-element Array{Float32,1}:\n 1.0e10" struct T5589 names::Vector{String} end -@test replstr(T5589(Vector{String}(uninitialized, 100))) == "$(curmod_prefix)T5589([#undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef … #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef])" +@test replstr(T5589(Vector{String}(undef, 100))) == "$(curmod_prefix)T5589([#undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef … #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef, #undef])" @test replstr(Meta.parse("mutable struct X end")) == ":(mutable struct X\n #= none:1 =#\n end)" @test replstr(Meta.parse("struct X end")) == ":(struct X\n #= none:1 =#\n end)" @@ -166,7 +166,7 @@ end # line meta dims::NTuple{N,Int} # line meta - function BitArray(uninitialized, dims::Int...) + function BitArray(undef, dims::Int...) # line meta if length(dims) != N # line meta @@ -187,7 +187,7 @@ end # line meta nc = num_bit_chunks(n) # line meta - chunks = Vector{UInt64}(uninitialized, nc) + chunks = Vector{UInt64}(undef, nc) # line meta if nc > 0 # line meta @@ -390,11 +390,11 @@ export D, E, F end" # issue #19840 -@test_repr "Array{Int}(uninitialized, 0)" -@test_repr "Array{Int}(uninitialized, 0,0)" -@test_repr "Array{Int}(uninitialized, 0,0,0)" -@test_repr "Array{Int}(uninitialized, 0,1)" -@test_repr "Array{Int}(uninitialized, 0,0,1)" +@test_repr "Array{Int}(undef, 0)" +@test_repr "Array{Int}(undef, 0,0)" +@test_repr "Array{Int}(undef, 0,0,0)" +@test_repr "Array{Int}(undef, 0,1)" +@test_repr "Array{Int}(undef, 0,0,1)" # issue #8994 @test_repr "get! => 2" @@ -803,7 +803,7 @@ end let repr = sprint(dump, Test) @test repr == "Module Test\n" end -let a = Vector{Any}(uninitialized, 10000) +let a = Vector{Any}(undef, 10000) a[2] = "elemA" a[4] = "elemB" a[11] = "elemC" @@ -977,7 +977,7 @@ end @testset "display arrays non-compactly when size(⋅, 2) == 1" begin # 0-dim @test replstr(zeros(Complex{Int})) == "0-dimensional Array{Complex{$Int},0}:\n0 + 0im" - A = Array{Pair,0}(uninitialized); A[] = 1=>2 + A = Array{Pair,0}(undef); A[] = 1=>2 @test replstr(A) == "0-dimensional Array{Pair,0}:\n1 => 2" # 1-dim @test replstr(zeros(Complex{Int}, 2)) == diff --git a/test/staged.jl b/test/staged.jl index 8d1cb76be7253..761b9d444a1d4 100644 --- a/test/staged.jl +++ b/test/staged.jl @@ -77,7 +77,7 @@ B = view(A, 1:3, 2, 1:3) end Ip = I.parameters NP = length(Ip) - indexexprs = Vector{Expr}(uninitialized, NP) + indexexprs = Vector{Expr}(undef, NP) j = 1 for i = 1:NP if Ip[i] == Int diff --git a/test/strings/util.jl b/test/strings/util.jl index f6e727a110f1e..9f3b2d6d00c01 100644 --- a/test/strings/util.jl +++ b/test/strings/util.jl @@ -333,7 +333,7 @@ end @testset "Issue 23161" begin arr = b"0123456789abcdefABCDEF" - arr1 = Vector{UInt8}(uninitialized, length(arr) >> 1) + arr1 = Vector{UInt8}(undef, length(arr) >> 1) @test hex2bytes!(arr1, arr) === arr1 # check in-place @test "0123456789abcdefabcdef" == bytes2hex(arr1) @test hex2bytes("0123456789abcdefABCDEF") == hex2bytes(arr) diff --git a/test/subarray.jl b/test/subarray.jl index e81b387baee07..cc57404f9b13a 100644 --- a/test/subarray.jl +++ b/test/subarray.jl @@ -33,7 +33,7 @@ _Agen(A, i1, i2, i3) = [A[j1,j2,j3] for j1 in i1, j2 in i2, j3 in i3] _Agen(A, i1, i2, i3, i4) = [A[j1,j2,j3,j4] for j1 in i1, j2 in i2, j3 in i3, j4 in i4] function replace_colon(A::AbstractArray, I) - Iout = Vector{Any}(uninitialized, length(I)) + Iout = Vector{Any}(undef, length(I)) I == (:,) && return (1:length(A),) for d = 1:length(I) Iout[d] = isa(I[d], Colon) ? (1:size(A,d)) : I[d] @@ -52,7 +52,7 @@ tup2val(::NTuple{N}) where {N} = Val(N) # it's good to copy the contents to an Array. This version protects against # `similar` ever changing its meaning. function copy_to_array(A::AbstractArray) - Ac = Array{eltype(A)}(uninitialized, size(A)) + Ac = Array{eltype(A)}(undef, size(A)) copyto!(Ac, A) end diff --git a/test/threads.jl b/test/threads.jl index a05415b4dfe9c..f41c5cf434990 100644 --- a/test/threads.jl +++ b/test/threads.jl @@ -47,8 +47,8 @@ function test_threaded_atomic_minmax(m::T,n::T) where T mid = m + (n-m)>>1 x = Atomic{T}(mid) y = Atomic{T}(mid) - oldx = Vector{T}(uninitialized, n-m+1) - oldy = Vector{T}(uninitialized, n-m+1) + oldx = Vector{T}(undef, n-m+1) + oldy = Vector{T}(undef, n-m+1) @threads for i = m:n oldx[i-m+1] = atomic_min!(x, T(i)) oldy[i-m+1] = atomic_max!(y, T(i)) diff --git a/test/vecelement.jl b/test/vecelement.jl index 30ce82cee05b9..077f608d59e03 100644 --- a/test/vecelement.jl +++ b/test/vecelement.jl @@ -65,7 +65,7 @@ struct Gr{N, T} w::T end -let a = Vector{Gr{2,Float64}}(uninitialized, 2) +let a = Vector{Gr{2,Float64}}(undef, 2) a[2] = Gr(1.0, Bunch((VecElement(2.0), VecElement(3.0))), 4.0) a[1] = Gr(5.0, Bunch((VecElement(6.0), VecElement(7.0))), 8.0) @test a[2] == Gr(1.0, Bunch((VecElement(2.0), VecElement(3.0))), 4.0)