|
354 | 354 | s = similar(t, Float32, 0:1, 2)
|
355 | 355 | @test s isa OffsetMatrix{Float32, Matrix{Float32}}
|
356 | 356 | @test axes(s) == (0:1, 1:2)
|
| 357 | + |
| 358 | + s = similar(t, ComplexF64, (Base.OneTo(2),)) |
| 359 | + @test s isa StructArray |
| 360 | + @test s.re isa Vector{Float64} |
| 361 | + @test axes(s) == (1:2,) |
| 362 | + |
| 363 | + s = similar(t, Int, (Base.OneTo(2),)) |
| 364 | + @test s isa Vector{Int} |
| 365 | + @test axes(s) == (1:2,) |
| 366 | + |
| 367 | + s = similar(t, ComplexF64, (Base.IdentityUnitRange(5:7),)) |
| 368 | + @test s isa StructArray |
| 369 | + @test s.re isa OffsetVector{Float64} |
| 370 | + @test axes(s) == (5:7,) |
| 371 | + |
| 372 | + s = similar(t, Int, (Base.IdentityUnitRange(5:7),)) |
| 373 | + @test s isa OffsetVector{Int} |
| 374 | + @test axes(s) == (5:7,) |
357 | 375 | end
|
358 | 376 |
|
359 | 377 | @testset "similar type" begin
|
@@ -844,13 +862,30 @@ end
|
844 | 862 |
|
845 | 863 | @testset "reshape" begin
|
846 | 864 | s = StructArray(a=[1,2,3,4], b=["a","b","c","d"])
|
| 865 | + |
847 | 866 | rs = reshape(s, (2, 2))
|
848 | 867 | @test rs.a == [1 3; 2 4]
|
849 | 868 | @test rs.b == ["a" "c"; "b" "d"]
|
850 | 869 |
|
| 870 | + rs = reshape(s, (:,)) |
| 871 | + @test rs.a == s.a |
| 872 | + @test rs.b == s.b |
| 873 | + |
| 874 | + rs = reshape(s, (2, :)) |
| 875 | + @test rs.a == [1 3; 2 4] |
| 876 | + @test rs.b == ["a" "c"; "b" "d"] |
| 877 | + |
| 878 | + rs = reshape(s, (2, Base.OneTo(2))) |
| 879 | + @test rs.a == [1 3; 2 4] |
| 880 | + @test rs.b == ["a" "c"; "b" "d"] |
| 881 | + |
851 | 882 | rs = reshape(s, (0:1, :))
|
852 | 883 | @test rs.a == OffsetArray([1 3; 2 4], (-1, 0))
|
853 | 884 | @test rs.b == OffsetArray(["a" "c"; "b" "d"], (-1, 0))
|
| 885 | + |
| 886 | + rs = reshape(s, (0:1, 1:2)) |
| 887 | + @test rs.a == OffsetArray([1 3; 2 4], (-1, 0)) |
| 888 | + @test rs.b == OffsetArray(["a" "c"; "b" "d"], (-1, 0)) |
854 | 889 | end
|
855 | 890 |
|
856 | 891 | @testset "lazy" begin
|
@@ -1072,6 +1107,28 @@ Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{MyArray}}, ::Type{El
|
1072 | 1107 | @test @inferred(broadcast(el -> el.a, v)) == ["s1", "s2"]
|
1073 | 1108 | end
|
1074 | 1109 |
|
| 1110 | +@testset "map" begin |
| 1111 | + s = StructArray(a=[1, 2, 3]) |
| 1112 | + |
| 1113 | + t = @inferred(map(x -> x, s)) |
| 1114 | + @test t isa StructArray |
| 1115 | + @test t == s |
| 1116 | + |
| 1117 | + t = @inferred(map(x -> x.a, s)) |
| 1118 | + @test t isa Vector |
| 1119 | + @test t == [1, 2, 3] |
| 1120 | + |
| 1121 | + t = VERSION >= v"1.7" ? @inferred(map(x -> (a=x.a, b=2), s)) : map(x -> (a=x.a, b=2), s) |
| 1122 | + @test t isa StructArray |
| 1123 | + @test map(x -> (a=x.a, b=2), s) == [(a=1, b=2), (a=2, b=2), (a=3, b=2)] |
| 1124 | + |
| 1125 | + so = reshape(s, Base.IdentityUnitRange(11:13)) |
| 1126 | + to = @inferred(map(x -> x, so)) |
| 1127 | + @test to isa StructArray |
| 1128 | + @test axes(to) == axes(so) |
| 1129 | + @test to == so |
| 1130 | +end |
| 1131 | + |
1075 | 1132 | @testset "staticarrays" begin
|
1076 | 1133 | # test that staticschema returns the right things
|
1077 | 1134 | for StaticVectorType = [SVector, MVector, SizedVector]
|
|
0 commit comments