Skip to content

Commit 0ba4bb1

Browse files
committed
Restrict stack tests to Julia >=1.9
1 parent 6d20899 commit 0ba4bb1

File tree

1 file changed

+126
-123
lines changed

1 file changed

+126
-123
lines changed

test/runtests.jl

Lines changed: 126 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -714,129 +714,132 @@ end
714714
# Make sure we aren't doing type piracy on `reshape`
715715
@test ndims(dropdims(ones(1,1), dims=(1,2))) == 0
716716

717-
# Issue #254
718-
x = ComponentVector(a=[1, 2])
719-
y = ComponentVector(a=[3, 4])
720-
xy = stack([x, y])
721-
# The data in `xy` should be the same as what we'd get if we used plain Vectors:
722-
@test getdata(xy) == stack(getdata.([x, y]))
723-
# Check the axes.
724-
xy_ax = getaxes(xy)
725-
# Should have two axes since xy should be a ComponentMatrix.
726-
@test length(xy_ax) == 2
727-
# First axis should be the same as x.
728-
@test xy_ax[1] == only(getaxes(x))
729-
# Second axis should be a FlatAxis.
730-
@test xy_ax[2] == FlatAxis()
731-
732-
# Does the dims argument to stack work?
733-
# Using `dims=2` should be the same as the default value.
734-
xy2 = stack([x, y]; dims=2)
735-
@test xy2 == xy
736-
# Using `dims=1` should stack things vertically.
737-
xy3 = stack([x, y]; dims=1)
738-
@test all(xy3[1, :a] .== xy[:a, 1])
739-
@test all(xy3[2, :a] .== xy[:a, 2])
740-
741-
# But can we stack 2D arrays?
742-
x = ComponentVector(a=[1, 2])
743-
y = ComponentVector(b=[3, 4])
744-
X = x .* y'
745-
Y = x .* y' .+ 4
746-
XY = stack([X, Y])
747-
# The data in `XY` should be the same as what we'd get if we used plain Vectors:
748-
@test getdata(XY) == stack(getdata.([X, Y]))
749-
# Check the axes.
750-
XY_ax = getaxes(XY)
751-
# Should have three axes since XY should be a 3D ComponentArray.
752-
@test length(XY_ax) == 3
753-
# First two axes should be the same as XY.
754-
@test XY_ax[1] == getaxes(XY)[1]
755-
@test XY_ax[2] == getaxes(XY)[2]
756-
# Third should be a FlatAxis.
757-
@test XY_ax[3] == FlatAxis()
758-
# Should test indexing too.
759-
@test all(XY[:a, :b, 1] .== X)
760-
@test all(XY[:a, :b, 2] .== Y)
761-
762-
# Make sure the dims argument works.
763-
# Using `dims=3` should be the same as the default value.
764-
XY_d3 = stack([X, Y]; dims=3)
765-
@test XY_d3 == XY
766-
# Using `dims=2` stacks along the second axis.
767-
XY_d2 = stack([X, Y]; dims=2)
768-
@test all(XY_d2[:a, 1, :b] .== XY[:a, :b, 1])
769-
@test all(XY_d2[:a, 2, :b] .== XY[:a, :b, 2])
770-
# Using `dims=1` stacks along the first axis.
771-
XY_d1 = stack([X, Y]; dims=1)
772-
@test all(XY_d1[1, :a, :b] .== XY[:a, :b, 1])
773-
@test all(XY_d1[2, :a, :b] .== XY[:a, :b, 2])
774-
775-
# Issue #254, tuple of arrays:
776-
x = ComponentVector(a=[1, 2])
777-
y = ComponentVector(b=[3, 4])
778-
Xstack1 = stack((x, y, x); dims=1)
779-
Xstack1_noca = stack((getdata(x), getdata(y), getdata(x)); dims=1)
780-
@test all(Xstack1 .== Xstack1_noca)
781-
@test all(Xstack1[1, :a] .== Xstack1_noca[1, :])
782-
@test all(Xstack1[2, :a] .== Xstack1_noca[2, :])
783-
784-
# Issue #254, Array of tuples.
785-
Xstack2 = stack(ComponentArray(a=(1,2,3), b=(4,5,6)))
786-
Xstack2_noca = stack([(1,2,3), (4,5,6)])
787-
@test all(Xstack2 .== Xstack2_noca)
788-
@test all(Xstack2[:, :a] .== Xstack2_noca[:, 1])
789-
@test all(Xstack2[:, :b] .== Xstack2_noca[:, 2])
790-
791-
Xstack2_d1 = stack(ComponentArray(a=(1,2,3), b=(4,5,6)); dims=1)
792-
Xstack2_noca_d1 = stack([(1,2,3), (4,5,6)]; dims=1)
793-
@test all(Xstack2_d1 .== Xstack2_noca_d1)
794-
@test all(Xstack2_d1[:a, :] .== Xstack2_noca_d1[1, :])
795-
@test all(Xstack2_d1[:b, :] .== Xstack2_noca_d1[2, :])
796-
797-
# Issue #254, generator of arrays.
798-
Xstack3 = stack(ComponentArray(z=[x,x]) for x in 1:4)
799-
Xstack3_noca = stack([x, x] for x in 1:4)
800-
# That should give me
801-
# [1 2 3 4;
802-
# 1 2 3 4]
803-
@test all(Xstack3 .== Xstack3_noca)
804-
@test all(Xstack3[:z, 1] .== Xstack3_noca[:, 1])
805-
@test all(Xstack3[:z, 2] .== Xstack3_noca[:, 2])
806-
@test all(Xstack3[:z, 3] .== Xstack3_noca[:, 3])
807-
@test all(Xstack3[:z, 4] .== Xstack3_noca[:, 4])
808-
809-
Xstack3_d1 = stack(ComponentArray(z=[x,x]) for x in 1:4; dims=1)
810-
Xstack3_noca_d1 = stack([x, x] for x in 1:4; dims=1)
811-
# That should give me
812-
# [1 1;
813-
# 2 2;
814-
# 3 3;
815-
# 4 4;]
816-
@test all(Xstack3_d1 .== Xstack3_noca_d1)
817-
@test all(Xstack3_d1[1, :z] .== Xstack3_noca_d1[1, :])
818-
@test all(Xstack3_d1[2, :z] .== Xstack3_noca_d1[2, :])
819-
@test all(Xstack3_d1[3, :z] .== Xstack3_noca_d1[3, :])
820-
@test all(Xstack3_d1[4, :z] .== Xstack3_noca_d1[4, :])
821-
822-
# Issue #254, map then stack.
823-
Xstack4_d1 = stack(x -> ComponentArray(a=x, b=[x+1,x+2]), [5 6; 7 8]; dims=1) # map then stack
824-
Xstack4_noca_d1 = stack(x -> [x, x+1, x+2], [5 6; 7 8]; dims=1) # map then stack
825-
@test all(Xstack4_d1 .== Xstack4_noca_d1)
826-
@test all(Xstack4_d1[:, :a] .== Xstack4_noca_d1[:, 1])
827-
@test all(Xstack4_d1[:, :b] .== Xstack4_noca_d1[:, 2:3])
828-
829-
Xstack4_d2 = stack(x -> ComponentArray(a=x, b=[x+1,x+2]), [5 6; 7 8]; dims=2) # map then stack
830-
Xstack4_noca_d2 = stack(x -> [x, x+1, x+2], [5 6; 7 8]; dims=2) # map then stack
831-
@test all(Xstack4_d2 .== Xstack4_noca_d2)
832-
@test all(Xstack4_d2[:a, :] .== Xstack4_noca_d2[1, :])
833-
@test all(Xstack4_d2[:b, :] .== Xstack4_noca_d2[2:3, :])
834-
835-
Xstack4_dcolon = stack(x -> ComponentArray(a=x, b=[x+1,x+2]), [5 6; 7 8]; dims=:) # map then stack
836-
Xstack4_noca_dcolon = stack(x -> [x, x+1, x+2], [5 6; 7 8]; dims=:) # map then stack
837-
@test all(Xstack4_dcolon .== Xstack4_noca_dcolon)
838-
@test all(Xstack4_dcolon[:a, :, :] .== Xstack4_noca_dcolon[1, :, :])
839-
@test all(Xstack4_dcolon[:b, :, :] .== Xstack4_noca_dcolon[2:3, :, :])
717+
if VERSION >= v"1.9"
718+
# `stack` was introduced in Julia 1.9
719+
# Issue #254
720+
x = ComponentVector(a=[1, 2])
721+
y = ComponentVector(a=[3, 4])
722+
xy = stack([x, y])
723+
# The data in `xy` should be the same as what we'd get if we used plain Vectors:
724+
@test getdata(xy) == stack(getdata.([x, y]))
725+
# Check the axes.
726+
xy_ax = getaxes(xy)
727+
# Should have two axes since xy should be a ComponentMatrix.
728+
@test length(xy_ax) == 2
729+
# First axis should be the same as x.
730+
@test xy_ax[1] == only(getaxes(x))
731+
# Second axis should be a FlatAxis.
732+
@test xy_ax[2] == FlatAxis()
733+
734+
# Does the dims argument to stack work?
735+
# Using `dims=2` should be the same as the default value.
736+
xy2 = stack([x, y]; dims=2)
737+
@test xy2 == xy
738+
# Using `dims=1` should stack things vertically.
739+
xy3 = stack([x, y]; dims=1)
740+
@test all(xy3[1, :a] .== xy[:a, 1])
741+
@test all(xy3[2, :a] .== xy[:a, 2])
742+
743+
# But can we stack 2D arrays?
744+
x = ComponentVector(a=[1, 2])
745+
y = ComponentVector(b=[3, 4])
746+
X = x .* y'
747+
Y = x .* y' .+ 4
748+
XY = stack([X, Y])
749+
# The data in `XY` should be the same as what we'd get if we used plain Vectors:
750+
@test getdata(XY) == stack(getdata.([X, Y]))
751+
# Check the axes.
752+
XY_ax = getaxes(XY)
753+
# Should have three axes since XY should be a 3D ComponentArray.
754+
@test length(XY_ax) == 3
755+
# First two axes should be the same as XY.
756+
@test XY_ax[1] == getaxes(XY)[1]
757+
@test XY_ax[2] == getaxes(XY)[2]
758+
# Third should be a FlatAxis.
759+
@test XY_ax[3] == FlatAxis()
760+
# Should test indexing too.
761+
@test all(XY[:a, :b, 1] .== X)
762+
@test all(XY[:a, :b, 2] .== Y)
763+
764+
# Make sure the dims argument works.
765+
# Using `dims=3` should be the same as the default value.
766+
XY_d3 = stack([X, Y]; dims=3)
767+
@test XY_d3 == XY
768+
# Using `dims=2` stacks along the second axis.
769+
XY_d2 = stack([X, Y]; dims=2)
770+
@test all(XY_d2[:a, 1, :b] .== XY[:a, :b, 1])
771+
@test all(XY_d2[:a, 2, :b] .== XY[:a, :b, 2])
772+
# Using `dims=1` stacks along the first axis.
773+
XY_d1 = stack([X, Y]; dims=1)
774+
@test all(XY_d1[1, :a, :b] .== XY[:a, :b, 1])
775+
@test all(XY_d1[2, :a, :b] .== XY[:a, :b, 2])
776+
777+
# Issue #254, tuple of arrays:
778+
x = ComponentVector(a=[1, 2])
779+
y = ComponentVector(b=[3, 4])
780+
Xstack1 = stack((x, y, x); dims=1)
781+
Xstack1_noca = stack((getdata(x), getdata(y), getdata(x)); dims=1)
782+
@test all(Xstack1 .== Xstack1_noca)
783+
@test all(Xstack1[1, :a] .== Xstack1_noca[1, :])
784+
@test all(Xstack1[2, :a] .== Xstack1_noca[2, :])
785+
786+
# Issue #254, Array of tuples.
787+
Xstack2 = stack(ComponentArray(a=(1,2,3), b=(4,5,6)))
788+
Xstack2_noca = stack([(1,2,3), (4,5,6)])
789+
@test all(Xstack2 .== Xstack2_noca)
790+
@test all(Xstack2[:, :a] .== Xstack2_noca[:, 1])
791+
@test all(Xstack2[:, :b] .== Xstack2_noca[:, 2])
792+
793+
Xstack2_d1 = stack(ComponentArray(a=(1,2,3), b=(4,5,6)); dims=1)
794+
Xstack2_noca_d1 = stack([(1,2,3), (4,5,6)]; dims=1)
795+
@test all(Xstack2_d1 .== Xstack2_noca_d1)
796+
@test all(Xstack2_d1[:a, :] .== Xstack2_noca_d1[1, :])
797+
@test all(Xstack2_d1[:b, :] .== Xstack2_noca_d1[2, :])
798+
799+
# Issue #254, generator of arrays.
800+
Xstack3 = stack(ComponentArray(z=[x,x]) for x in 1:4)
801+
Xstack3_noca = stack([x, x] for x in 1:4)
802+
# That should give me
803+
# [1 2 3 4;
804+
# 1 2 3 4]
805+
@test all(Xstack3 .== Xstack3_noca)
806+
@test all(Xstack3[:z, 1] .== Xstack3_noca[:, 1])
807+
@test all(Xstack3[:z, 2] .== Xstack3_noca[:, 2])
808+
@test all(Xstack3[:z, 3] .== Xstack3_noca[:, 3])
809+
@test all(Xstack3[:z, 4] .== Xstack3_noca[:, 4])
810+
811+
Xstack3_d1 = stack(ComponentArray(z=[x,x]) for x in 1:4; dims=1)
812+
Xstack3_noca_d1 = stack([x, x] for x in 1:4; dims=1)
813+
# That should give me
814+
# [1 1;
815+
# 2 2;
816+
# 3 3;
817+
# 4 4;]
818+
@test all(Xstack3_d1 .== Xstack3_noca_d1)
819+
@test all(Xstack3_d1[1, :z] .== Xstack3_noca_d1[1, :])
820+
@test all(Xstack3_d1[2, :z] .== Xstack3_noca_d1[2, :])
821+
@test all(Xstack3_d1[3, :z] .== Xstack3_noca_d1[3, :])
822+
@test all(Xstack3_d1[4, :z] .== Xstack3_noca_d1[4, :])
823+
824+
# Issue #254, map then stack.
825+
Xstack4_d1 = stack(x -> ComponentArray(a=x, b=[x+1,x+2]), [5 6; 7 8]; dims=1) # map then stack
826+
Xstack4_noca_d1 = stack(x -> [x, x+1, x+2], [5 6; 7 8]; dims=1) # map then stack
827+
@test all(Xstack4_d1 .== Xstack4_noca_d1)
828+
@test all(Xstack4_d1[:, :a] .== Xstack4_noca_d1[:, 1])
829+
@test all(Xstack4_d1[:, :b] .== Xstack4_noca_d1[:, 2:3])
830+
831+
Xstack4_d2 = stack(x -> ComponentArray(a=x, b=[x+1,x+2]), [5 6; 7 8]; dims=2) # map then stack
832+
Xstack4_noca_d2 = stack(x -> [x, x+1, x+2], [5 6; 7 8]; dims=2) # map then stack
833+
@test all(Xstack4_d2 .== Xstack4_noca_d2)
834+
@test all(Xstack4_d2[:a, :] .== Xstack4_noca_d2[1, :])
835+
@test all(Xstack4_d2[:b, :] .== Xstack4_noca_d2[2:3, :])
836+
837+
Xstack4_dcolon = stack(x -> ComponentArray(a=x, b=[x+1,x+2]), [5 6; 7 8]; dims=:) # map then stack
838+
Xstack4_noca_dcolon = stack(x -> [x, x+1, x+2], [5 6; 7 8]; dims=:) # map then stack
839+
@test all(Xstack4_dcolon .== Xstack4_noca_dcolon)
840+
@test all(Xstack4_dcolon[:a, :, :] .== Xstack4_noca_dcolon[1, :, :])
841+
@test all(Xstack4_dcolon[:b, :, :] .== Xstack4_noca_dcolon[2:3, :, :])
842+
end
840843
end
841844

842845
@testset "axpy! / axpby!" begin

0 commit comments

Comments
 (0)