|
19 | 19 |
|
20 | 20 | Base.similar(A::ArrayPartition{T,S}) where {T,S} = ArrayPartition{T,S}(similar.(A.x)) |
21 | 21 |
|
22 | | -# ignore dims since array partitions are vectors |
23 | | -Base.similar(A::ArrayPartition, dims::NTuple{N,Int}) where {N} = similar(A) |
| 22 | +# return ArrayPartition when possible, otherwise next best thing of the correct size |
| 23 | +function Base.similar(A::ArrayPartition, dims::NTuple{N,Int}) where {N} |
| 24 | + if dims == size(A) |
| 25 | + return similar(A) |
| 26 | + else |
| 27 | + return similar(A.x[1], eltype(A), dims) |
| 28 | + end |
| 29 | +end |
24 | 30 |
|
25 | 31 | # similar array partition of common type |
26 | 32 | @inline function Base.similar(A::ArrayPartition, ::Type{T}) where {T} |
27 | 33 | N = npartitions(A) |
28 | 34 | ArrayPartition(i->similar(A.x[i], T), N) |
29 | 35 | end |
30 | 36 |
|
31 | | -# ignore dims since array partitions are vectors |
32 | | -Base.similar(A::ArrayPartition, ::Type{T}, dims::NTuple{N,Int}) where {T,N} = similar(A, T) |
| 37 | +# return ArrayPartition when possible, otherwise next best thing of the correct size |
| 38 | +function Base.similar(A::ArrayPartition, ::Type{T}, dims::NTuple{N,Int}) where {T,N} |
| 39 | + if dims == size(A) |
| 40 | + return similar(A, T) |
| 41 | + else |
| 42 | + return similar(A.x[1], T, dims) |
| 43 | + end |
| 44 | +end |
33 | 45 |
|
34 | 46 | # similar array partition with different types |
35 | 47 | function Base.similar(A::ArrayPartition, ::Type{T}, ::Type{S}, R::DataType...) where {T, S} |
|
0 commit comments