Skip to content

Commit

Permalink
Fix simliar to allocate new memory and add a test to ensure this. (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiede authored Nov 18, 2024
1 parent 910efa3 commit 49b1b10
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/array/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function Base.similar(A::AbstractDimArray;
data=similar(parent(A)),
dims=dims(A), refdims=refdims(A), name=_noname(A), metadata=metadata(A), kw...
)
rebuild(A; dims=format(dims, data), refdims, name, metadata, kw...)
rebuild(A; data, dims=format(dims, data), refdims, name, metadata, kw...)
end
function Base.similar(A::AbstractDimArray, ::Type{T};
data=similar(parent(A), T),
Expand Down
2 changes: 2 additions & 0 deletions test/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ end
@testset "similar" begin
@testset "similar with no args" begin
da_sim = similar(da)
@test parent(da_sim) !== parent(da) # check if the same memory
@test eltype(da_sim) == eltype(da)
@test size(da_sim) == size(da)
@test dims(da_sim) === dims(da)
Expand All @@ -152,6 +153,7 @@ end

@testset "similar with a type" begin
da_float = @inferred similar(da, Float64)
@test parent(da_float) !== parent(da) # check if the same memory
@test eltype(da_float) == Float64
@test size(da_float) == size(da)
@test dims(da_float) === dims(da)
Expand Down

0 comments on commit 49b1b10

Please sign in to comment.