|
94 | 94 | g = MeshArray(mesh1, mesh1, mesh1, mesh1, mesh1, mesh1) |
95 | 95 | @test isconcretetype(typeof(g.mesh)) |
96 | 96 | end |
| 97 | + |
| 98 | +@testset "MeshArray Type Stability Helpers (Issue #78)" begin |
| 99 | + N1, N2 = 8, 6 |
| 100 | + mesh1 = SimpleGrid.Uniform{Float64}([0.0, 1.0], N1) |
| 101 | + mesh2 = SimpleGrid.Uniform{Float64}([0.0, 1.0], N2) |
| 102 | + |
| 103 | + mesh_tuple = (mesh1, mesh2) |
| 104 | + stabilized = MeshArrays._stabilize_mesh_type(mesh_tuple) |
| 105 | + @test isconcretetype(typeof(stabilized)) |
| 106 | + @test stabilized === mesh_tuple |
| 107 | + |
| 108 | + non_concrete_mesh = Any[mesh1, mesh2] |
| 109 | + stabilized_from_vec = MeshArrays._stabilize_mesh_type(non_concrete_mesh) |
| 110 | + @test isconcretetype(typeof(stabilized_from_vec)) |
| 111 | + |
| 112 | + data = rand(N1, N2) |
| 113 | + result = MeshArrays._create_mesharray_typed(data, mesh_tuple, Float64, 2) |
| 114 | + @test result isa MeshArray{Float64, 2} |
| 115 | + @test result.data === data |
| 116 | + |
| 117 | + data_int = ones(Int, N1, N2) |
| 118 | + result_converted = MeshArrays._create_mesharray_typed(data_int, mesh_tuple, Float64, 2) |
| 119 | + @test result_converted isa MeshArray{Float64, 2} |
| 120 | + @test eltype(result_converted.data) == Float64 |
| 121 | + |
| 122 | + MT = typeof(mesh_tuple) |
| 123 | + @test MeshArrays._infer_mesh_type(mesh_tuple) == MT |
| 124 | +end |
| 125 | + |
| 126 | +@testset "MeshArray Broadcast Type Stability" begin |
| 127 | + N1, N2 = 10, 12 |
| 128 | + mesh1 = SimpleGrid.Uniform{Float64}([0.0, 1.0], N1) |
| 129 | + mesh2 = SimpleGrid.Uniform{Float64}([0.0, 1.0], N2) |
| 130 | + |
| 131 | + g1 = MeshArray(mesh1, mesh2; data=rand(N1, N2)) |
| 132 | + g2 = MeshArray(mesh1, mesh2; data=rand(N1, N2)) |
| 133 | + |
| 134 | + g3 = similar(g1) |
| 135 | + g3 .= g1 .+ g2 |
| 136 | + @test g3.data ≈ g1.data .+ g2.data |
| 137 | + |
| 138 | + g4 = similar(g1) |
| 139 | + Base.copyto!(g4, Base.Broadcast.broadcasted(+, g1, g2)) |
| 140 | + @test g4.data ≈ g1.data .+ g2.data |
| 141 | + |
| 142 | + indices = CartesianIndices(g1.data) |
| 143 | + bcf = Base.Broadcast.flatten(Base.Broadcast.broadcasted(*, g1, 2.0)) |
| 144 | + g5 = similar(g1) |
| 145 | + MeshArrays._copyto_typed!(g5, bcf, indices) |
| 146 | + @test g5.data ≈ g1.data .* 2.0 |
| 147 | +end |
0 commit comments