Skip to content

Commit d2a7871

Browse files
committed
re-name prototype
1 parent 4559078 commit d2a7871

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

base/abstractarray.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,7 +2621,7 @@ function _typed_stack(::Colon, ::Type{T}, ::Type{S}, A, Aax=_axes(A)) where {T,
26212621
nothing === xit && return _empty_stack(:, T, S, A)
26222622
x1, _ = xit
26232623
ax1 = _axes(x1)
2624-
B = similar(_prototype(x1, A), T, ax1..., Aax...)
2624+
B = similar(_first_array(x1, A), T, ax1..., Aax...)
26252625
off = firstindex(B)
26262626
len = length(x1)
26272627
while xit !== nothing
@@ -2665,7 +2665,7 @@ function _dim_stack(dims::Integer, ::Type{T}, ::Type{S}, A) where {T,S}
26652665

26662666
newaxis = _vec_axis(A)
26672667
outax = ntuple(d -> d==dims ? newaxis : _axes(x1)[d - (d>dims)], N1)
2668-
B = similar(_prototype(x1, A), T, outax...)
2668+
B = similar(_first_array(x1, A), T, outax...)
26692669

26702670
iit = iterate(newaxis)
26712671
while xit !== nothing
@@ -2704,33 +2704,32 @@ end
27042704
end
27052705

27062706
# For `similar`, the goal is to stack an Array of CuArrays to a CuArray:
2707-
_prototype(x::AbstractArray, A::AbstractArray) = x
2708-
_prototype(x::AbstractArray, A) = x
2709-
_prototype(x, A::AbstractArray) = A
2710-
_prototype(x, A) = 1:0
2707+
_first_array(x::AbstractArray, ys...) = x
2708+
_first_array(x, ys...) = _first_array(ys...)
2709+
_first_array() = 1:0
27112710

27122711
# With tuple elements, we can make the empty array the right size:
27132712
function _empty_stack(::Colon, ::Type{T}, ::Type{S}, A) where {T, S<:Tuple}
2714-
similar(_prototype(nothing, A), T, OneTo(length(fieldtypes(S))), axes(A)...)
2713+
similar(_first_array(A), T, OneTo(length(fieldtypes(S))), axes(A)...)
27152714
end
27162715
function _empty_stack(dims::Integer, ::Type{T}, ::Type{S}, A) where {T, S<:Tuple}
27172716
ax1 = OneTo(length(fieldtypes(S)))
27182717
dims in 1:2 || throw(ArgumentError("cannot stack tuples along dims = $dims"))
2719-
similar(_prototype(nothing, A), T, ntuple(d -> d==dims ? OneTo(0) : ax1, 2))
2718+
similar(_first_array(A), T, ntuple(d -> d==dims ? OneTo(0) : ax1, 2))
27202719
end
27212720
# but with arrays of arrays, we must settle for the right ndims:
27222721
_empty_stack(dims, ::Type{T}, ::Type{S}, A) where {T,S} = _empty_stack(dims, T, IteratorSize(S), A)
27232722
_empty_stack(dims, ::Type{T}, ::HasLength, A) where {T} = _empty_stack(dims, T, HasShape{1}(), A)
27242723
_empty_stack(dims, ::Type{T}, ::IteratorSize, A) where {T} = _empty_stack(dims, T, HasShape{0}(), A)
27252724

27262725
function _empty_stack(::Colon, ::Type{T}, ::HasShape{N}, A) where {T,N}
2727-
similar(_prototype(nothing, A), T, ntuple(_->OneTo(1), N)..., _axes(A)...)
2726+
similar(_first_array(A), T, ntuple(_->OneTo(1), N)..., _axes(A)...)
27282727
end
27292728
function _empty_stack(dims::Integer, ::Type{T}, ::HasShape{N}, A) where {T,N}
27302729
# Not sure we should check dims here, e.g. stack(Vector[]; dims=2) is an error
27312730
dims in 1:N+1 || throw(ArgumentError("cannot stack slices ndims(x) = $N along dims = $dims"))
27322731
ax = ntuple(d -> d==dims ? _vec_axis(A) : OneTo(1), N+1)
2733-
similar(_prototype(nothing, A), T, ax...)
2732+
similar(_first_array(A), T, ax...)
27342733
end
27352734

27362735
# These make stack(()) work like stack([])

0 commit comments

Comments
 (0)