Skip to content

Commit 292cfda

Browse files
committed
add offset tests
1 parent 87159c4 commit 292cfda

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

base/abstractarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2622,7 +2622,7 @@ function _typed_stack(::Colon, ::Type{T}, ::Type{S}, A, Aax=_axes(A)) where {T,
26222622
x1, _ = xit
26232623
ax1 = _axes(x1)
26242624
B = similar(_prototype(x1, A), T, ax1..., Aax...)
2625-
off = 1
2625+
off = firstindex(B)
26262626
len = length(x1)
26272627
while xit !== nothing
26282628
x, state = xit

test/offsetarray.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,21 @@ end
802802
@test reshape(a, (:,)) === a
803803
end
804804

805+
@testset "stack" begin
806+
nought = OffsetArray([0, 0.1, 0.01], 0:2)
807+
ten = OffsetArray([1,10,100,1000], 10:13)
808+
809+
@test stack(ten) == ten
810+
@test stack(x^2 for x in ten) == ten.^2
811+
812+
@test axes(stack(nought for _ in ten)) == (0:2, 10:13)
813+
@test axes(stack([nought for _ in ten])) == (0:2, 10:13)
814+
@test axes(stack(nought for _ in ten; dims=1)) == (10:13, 0:2)
815+
@test axes(stack((x, x^2) for x in nought)) == 1:2, 0:2
816+
@test axes(stack(x -> x[end-1:end], ten for _ in nought, _ in nought)) == (1:2, 0:2, 0:2)
817+
@test axes(stack([ten[end-1:end] for _ in nought, _ in nought])) == (1:2, 0:2, 0:2)
818+
end
819+
805820
@testset "issue #41630: replace_ref_begin_end!/@view on offset-like arrays" begin
806821
x = OffsetArray([1 2; 3 4], -10:-9, 9:10) # 2×2 OffsetArray{...} with indices -10:-9×9:10
807822

0 commit comments

Comments
 (0)