@@ -381,7 +381,7 @@ function ones end
381381
382382for (fname, felt) in ((:zeros , :zero ), (:ones , :one ))
383383 @eval begin
384- $ fname (:: Type{T} , dims:: NTuple{N, Any} ) where {T, N} = fill! (Array {T,N} (uninitialized, Dims ( dims)), $ felt (T))
384+ $ fname (:: Type{T} , dims:: NTuple{N, Any} ) where {T, N} = fill! (Array {T,N} (uninitialized, convert (Dims, dims):: Dims ), $ felt (T))
385385 $ fname (dims:: Tuple ) = ($ fname)(Float64, dims)
386386 $ fname (:: Type{T} , dims... ) where {T} = $ fname (T, dims)
387387 $ fname (dims... ) = $ fname (dims)
@@ -402,21 +402,14 @@ oneunit(x::AbstractMatrix{T}) where {T} = _one(oneunit(T), x)
402402# arises in similar(dest, Pair{Union{},Union{}}) where dest::Dict:
403403convert (:: Type{Vector{Union{}}} , a:: Vector{Union{}} ) = a
404404
405- convert (:: Type{Vector} , x:: AbstractVector{T} ) where {T} = convert (Vector{T}, x)
406- convert (:: Type{Matrix} , x:: AbstractMatrix{T} ) where {T} = convert (Matrix{T}, x)
407-
408- convert (:: Type{Array{T}} , x:: Array{T,n} ) where {T,n} = x
409- convert (:: Type{Array{T,n}} , x:: Array{T,n} ) where {T,n} = x
410-
411- convert (:: Type{Array{T}} , x:: AbstractArray{S,n} ) where {T,n,S} = convert (Array{T,n}, x)
412- convert (:: Type{Array{T,n}} , x:: AbstractArray{S,n} ) where {T,n,S} = copyto! (Array {T,n} (uninitialized, size (x)), x)
413-
414405promote_rule (a:: Type{Array{T,n}} , b:: Type{Array{S,n}} ) where {T,n,S} = el_same (promote_type (T,S), a, b)
415406
416- # constructors should make copies
407+ # # Constructors ##
417408
418409if module_name (@__MODULE__ ) === :Base # avoid method overwrite
419- (:: Type{T} )(x:: T ) where {T<: Array } = copy (x)
410+ # constructors should make copies
411+ Array {T,N} (x:: AbstractArray{S,N} ) where {T,N,S} = copyto! (Array {T,N} (uninitialized, size (x)), x)
412+ AbstractArray {T,N} (A:: AbstractArray{S,N} ) where {T,N,S} = copyto! (similar (A,T), A)
420413end
421414
422415# # copying iterators to containers
@@ -504,14 +497,26 @@ end
504497# gets a chance to see it, so that recursive calls to the caller
505498# don't trigger the inference limiter
506499if isdefined (Core, :Inference )
507- macro default_eltype (itrt)
500+ macro default_eltype (itr)
501+ I = esc (itr)
508502 return quote
509- Core. Inference. return_type (first, Tuple{$ (esc (itrt))})
503+ if $ I isa Generator && ($ I). f isa Type
504+ ($ I). f
505+ else
506+ Core. Inference. return_type (first, Tuple{typeof ($ I)})
507+ end
510508 end
511509 end
512510else
513- macro default_eltype (itrt)
514- return :(Any)
511+ macro default_eltype (itr)
512+ I = esc (itr)
513+ return quote
514+ if $ I isa Generator && ($ I). f isa Type
515+ ($ I). f
516+ else
517+ Any
518+ end
519+ end
515520 end
516521end
517522
@@ -520,7 +525,7 @@ _array_for(::Type{T}, itr, ::HasShape) where {T} = similar(Array{T}, axes(itr)):
520525
521526function collect (itr:: Generator )
522527 isz = iteratorsize (itr. iter)
523- et = @default_eltype (typeof ( itr) )
528+ et = @default_eltype (itr)
524529 if isa (isz, SizeUnknown)
525530 return grow_to! (Vector {et} (), itr)
526531 else
@@ -534,12 +539,12 @@ function collect(itr::Generator)
534539end
535540
536541_collect (c, itr, :: EltypeUnknown , isz:: SizeUnknown ) =
537- grow_to! (_similar_for (c, @default_eltype (typeof ( itr) ), itr, isz), itr)
542+ grow_to! (_similar_for (c, @default_eltype (itr), itr, isz), itr)
538543
539544function _collect (c, itr, :: EltypeUnknown , isz:: Union{HasLength,HasShape} )
540545 st = start (itr)
541546 if done (itr,st)
542- return _similar_for (c, @default_eltype (typeof ( itr) ), itr, isz)
547+ return _similar_for (c, @default_eltype (itr), itr, isz)
543548 end
544549 v1, st = next (itr, st)
545550 collect_to_with_first! (_similar_for (c, typeof (v1), itr, isz), v1, itr, st)
0 commit comments