|
331 | 331 | @test size(s) == (3, 5)
|
332 | 332 | @test s isa StructArray
|
333 | 333 |
|
| 334 | + for ET in ( |
| 335 | + NamedTuple{(:x,)}, |
| 336 | + NamedTuple{(:x,), Tuple{NamedTuple{(:y,)}}}, |
| 337 | + NamedTuple{(:x, :y), Tuple{Int, S}} where S |
| 338 | + ) |
| 339 | + s = similar(t, ET, (3, 5)) |
| 340 | + @test eltype(s) === ET |
| 341 | + @test size(s) == (3, 5) |
| 342 | + @test s isa StructArray |
| 343 | + end |
| 344 | + |
| 345 | + s = similar(t, Any, (3, 5)) |
| 346 | + @test eltype(s) == Any |
| 347 | + @test size(s) == (3, 5) |
| 348 | + @test s isa Array |
| 349 | + |
334 | 350 | s = similar(t, (0:2, 5))
|
335 | 351 | @test eltype(s) == NamedTuple{(:a, :b), Tuple{Float64, Bool}}
|
336 | 352 | @test axes(s) == (0:2, 1:5)
|
|
413 | 429 | @test size(t) == (5,)
|
414 | 430 | @test t == convert(StructVector, v)
|
415 | 431 | @test t == convert(StructVector, t)
|
| 432 | + |
| 433 | + t = StructVector([(a=1,), (a=missing,)])::StructVector |
| 434 | + @test isequal(t.a, [1, missing]) |
| 435 | + @test eltype(t) <: NamedTuple{(:a,)} |
416 | 436 | end
|
417 | 437 |
|
418 | 438 | @testset "tuple case" begin
|
@@ -1118,6 +1138,12 @@ end
|
1118 | 1138 | @test t isa Vector
|
1119 | 1139 | @test t == [1, 2, 3]
|
1120 | 1140 |
|
| 1141 | + t = map(x -> (a=x.a,), StructVector(a=[1, missing]))::StructVector |
| 1142 | + @test isequal(t.a, [1, missing]) |
| 1143 | + @test eltype(t) <: NamedTuple{(:a,)} |
| 1144 | + t = map(x -> (a=rand(["", 1, nothing]),), StructVector(a=1:10))::StructVector |
| 1145 | + @test eltype(t) <: NamedTuple{(:a,)} |
| 1146 | + |
1121 | 1147 | t = VERSION >= v"1.7" ? @inferred(map(x -> (a=x.a, b=2), s)) : map(x -> (a=x.a, b=2), s)
|
1122 | 1148 | @test t isa StructArray
|
1123 | 1149 | @test map(x -> (a=x.a, b=2), s) == [(a=1, b=2), (a=2, b=2), (a=3, b=2)]
|
@@ -1182,19 +1208,37 @@ end
|
1182 | 1208 | @testset "map_params" begin
|
1183 | 1209 | v = StructArray(rand(ComplexF64, 2, 2))
|
1184 | 1210 | f(T) = similar(v, T)
|
| 1211 | + |
1185 | 1212 | types = Tuple{Int, Float64, ComplexF32, String}
|
1186 |
| - A = @inferred StructArrays.map_params(f, types) |
1187 |
| - B = StructArrays.map_params_fallback(f, types) |
1188 |
| - @test typeof(A) === typeof(B) |
| 1213 | + namedtypes = NamedTuple{(:a, :b, :c, :d), types} |
| 1214 | + A = @inferred StructArrays.map_params_as_tuple(f, types) |
| 1215 | + B = StructArrays.map_params_as_tuple_fallback(f, types) |
| 1216 | + C = @inferred StructArrays.map_params_as_tuple(f, namedtypes) |
| 1217 | + D = StructArrays.map_params_as_tuple_fallback(f, namedtypes) |
| 1218 | + @test typeof(A) === typeof(B) === typeof(C) === typeof(D) |
| 1219 | + |
1189 | 1220 | types = Tuple{Int, Float64, ComplexF32}
|
1190 |
| - A = @inferred StructArrays.map_params(zero, types) |
1191 |
| - B = StructArrays.map_params_fallback(zero, types) |
1192 |
| - C = map(zero, fieldtypes(types)) |
1193 |
| - @test A === B === C |
| 1221 | + A = map(zero, fieldtypes(types)) |
| 1222 | + B = @inferred StructArrays.map_params(zero, types) |
| 1223 | + C = StructArrays.map_params_as_tuple(zero, types) |
| 1224 | + D = StructArrays.map_params_as_tuple_fallback(zero, types) |
| 1225 | + @test A === B === C === D |
| 1226 | + |
1194 | 1227 | namedtypes = NamedTuple{(:a, :b, :c), types}
|
1195 |
| - A = @inferred StructArrays.map_params(zero, namedtypes) |
1196 |
| - C = map(zero, NamedTuple{(:a, :b, :c)}(map(zero, fieldtypes(types)))) |
1197 |
| - @test A === C |
| 1228 | + A = map(zero, NamedTuple{(:a, :b, :c)}(map(zero, fieldtypes(types)))) |
| 1229 | + B = @inferred StructArrays.map_params(zero, namedtypes) |
| 1230 | + C = StructArrays.map_params_as_tuple(zero, types) |
| 1231 | + D = StructArrays.map_params_as_tuple_fallback(zero, types) |
| 1232 | + @test A === B |
| 1233 | + @test Tuple(A) === C === D |
| 1234 | + |
| 1235 | + nonconcretenamedtypes = NamedTuple{(:a, :b, :c)} |
| 1236 | + A = map(f, NamedTuple{(:a, :b, :c)}((Any, Any, Any))) |
| 1237 | + B = @inferred StructArrays.map_params(f, nonconcretenamedtypes) |
| 1238 | + C = StructArrays.map_params_as_tuple(f, nonconcretenamedtypes) |
| 1239 | + D = StructArrays.map_params_as_tuple_fallback(f, nonconcretenamedtypes) |
| 1240 | + @test typeof(A) === typeof(B) |
| 1241 | + @test typeof(Tuple(A)) === typeof(C) === typeof(D) |
1198 | 1242 | end
|
1199 | 1243 |
|
1200 | 1244 | @testset "OffsetArray zero" begin
|
|
0 commit comments