Skip to content

Commit 2c5fcce

Browse files
committed
Fix NamedArrayPartition similar when size is passed
1 parent 6a66fc8 commit 2c5fcce

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
@@ -33,8 +33,12 @@ end
3333

3434
# return ArrayPartition when possible, otherwise next best thing of the correct size
3535
function Base.similar(A::NamedArrayPartition, dims::NTuple{N, Int}) where {N}
36-
NamedArrayPartition(
37-
similar(getfield(A, :array_partition), dims), getfield(A, :names_to_indices))
36+
similar_array_partition = similar(getfield(A, :array_partition), dims)
37+
if similar_array_partition isa ArrayPartition
38+
NamedArrayPartition(similar_array_partition, getfield(A, :names_to_indices))
39+
else
40+
similar_array_partition
41+
end
3842
end
3943

4044
# similar array partition of common type

test/named_array_partition_tests.jl

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

0 commit comments

Comments
 (0)