Skip to content

Commit 5c3489c

Browse files
committed
Also fix when dims + T are passed
1 parent 2c5fcce commit 5c3489c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/named_array_partition.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ end
4949

5050
# return ArrayPartition when possible, otherwise next best thing of the correct size
5151
function Base.similar(A::NamedArrayPartition, ::Type{T}, dims::NTuple{N, Int}) where {T, N}
52-
NamedArrayPartition(
53-
similar(getfield(A, :array_partition), T, dims), getfield(A, :names_to_indices))
52+
similar_array_partition = similar(getfield(A, :array_partition), T, dims)
53+
if similar_array_partition isa ArrayPartition
54+
NamedArrayPartition(similar_array_partition, getfield(A, :names_to_indices))
55+
else
56+
similar_array_partition
57+
end
5458
end
5559

5660
# similar array partition with different types

test/named_array_partition_tests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using RecursiveArrayTools, Test
77
@test typeof(similar(x)) <: NamedArrayPartition
88
@test typeof(similar(x, Int)) <: NamedArrayPartition
99
@test typeof(similar(x, (5, 5))) <: Matrix
10+
@test typeof(similar(x, Int, (5, 5))) <: Matrix
1011
@test x.a ones(10)
1112
@test typeof(x .+ x[1:end]) <: Vector # test broadcast precedence
1213
@test all(x .== x[1:end])

0 commit comments

Comments
 (0)