Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/vector_of_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,12 @@ end
) where {T}
return similar(Array{T}, dims)
end
# Disambiguates against Base's integer-dimension similar fallback on Julia ≤ 1.11.
@inline function Base.similar(
VA::AbstractVectorOfArray, ::Type{T}, dims::Tuple{Integer, Vararg{Integer}}
) where {T}
return similar(Array{T}, dims)
end


# fill!
Expand Down
22 changes: 22 additions & 0 deletions test/Core/similar_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using RecursiveArrayTools, Test

@testset "similar with explicit dimensions" begin
data = [[1, 2], [3, 4]]
for A in (VectorOfArray(data), DiffEqArray(data, [0, 1]))
@testset "$(nameof(typeof(A))) $dims" for (dims, expected_size) in (
((Int32(2), Int32(3)), (2, 3)),
((UInt8(2), UInt8(3)), (2, 3)),
((big(2), big(3)), (2, 3)),
((true, false), (1, 0)),
((2, 3), (2, 3)),
((), ()),
((Base.OneTo(2), Base.OneTo(3)), (2, 3)),
((2, Base.OneTo(3)), (2, 3)),
)
result = similar(A, Float64, dims)
@test result isa Array
@test size(result) == expected_size
@test eltype(result) === Float64
end
end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ run_tests(;
@time @safetestset "Partitions and StaticArrays Tests" include("Core/partitions_and_static_arrays.jl")
@time @safetestset "VecOfArr Indexing Tests" include("Core/basic_indexing.jl")
@time @safetestset "VecOfArr Interface Tests" include("Core/interface_tests.jl")
@time @safetestset "VecOfArr Similar Tests" include("Core/similar_tests.jl")
@time @safetestset "Public API Tests" include("Core/public_api_test.jl")
@time @safetestset "Table traits" include("Core/tabletraits.jl")
@time @safetestset "StaticArrays Tests" include("Core/copy_static_array_test.jl")
Expand Down
Loading