Skip to content

Commit

Permalink
add offset tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Dec 29, 2021
1 parent 593e44f commit 4559078
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2622,7 +2622,7 @@ function _typed_stack(::Colon, ::Type{T}, ::Type{S}, A, Aax=_axes(A)) where {T,
x1, _ = xit
ax1 = _axes(x1)
B = similar(_prototype(x1, A), T, ax1..., Aax...)
off = 1
off = firstindex(B)
len = length(x1)
while xit !== nothing
x, state = xit
Expand Down
15 changes: 15 additions & 0 deletions test/offsetarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,21 @@ end
@test reshape(a, (:,)) === a
end

@testset "stack" begin
nought = OffsetArray([0, 0.1, 0.01], 0:2)
ten = OffsetArray([1,10,100,1000], 10:13)

@test stack(ten) == ten
@test stack(x^2 for x in ten) == ten.^2

@test axes(stack(nought for _ in ten)) == (0:2, 10:13)
@test axes(stack([nought for _ in ten])) == (0:2, 10:13)
@test axes(stack(nought for _ in ten; dims=1)) == (10:13, 0:2)
@test axes(stack((x, x^2) for x in nought)) == 1:2, 0:2
@test axes(stack(x -> x[end-1:end], ten for _ in nought, _ in nought)) == (1:2, 0:2, 0:2)
@test axes(stack([ten[end-1:end] for _ in nought, _ in nought])) == (1:2, 0:2, 0:2)
end

@testset "issue #41630: replace_ref_begin_end!/@view on offset-like arrays" begin
x = OffsetArray([1 2; 3 4], -10:-9, 9:10) # 2×2 OffsetArray{...} with indices -10:-9×9:10

Expand Down

0 comments on commit 4559078

Please sign in to comment.