|
94 | 94 | @test axes(point_field) isa Spaces.PointSpace
|
95 | 95 | end
|
96 | 96 |
|
| 97 | +# Requires `--check-bounds=yes` |
| 98 | +@testset "Constructing & broadcasting over empty fields" begin |
| 99 | + FT = Float32 |
| 100 | + for space in TU.all_spaces(FT) |
| 101 | + f = TU.FieldFromNamedTuple(space, (;)) |
| 102 | + @. f += f |
| 103 | + end |
| 104 | + |
| 105 | + function test_broken_throws(f) |
| 106 | + try |
| 107 | + @. f += 1 |
| 108 | + # we want to throw exception, test is broken |
| 109 | + @test_broken false |
| 110 | + catch |
| 111 | + # we want to throw exception, unexpected pass |
| 112 | + @test_broken true |
| 113 | + end |
| 114 | + end |
| 115 | + empty_field(space) = TU.FieldFromNamedTuple(space, (;)) |
| 116 | + |
| 117 | + # Broadcasting over the wrong size should error |
| 118 | + test_broken_throws(empty_field(TU.PointSpace(FT))) |
| 119 | + test_broken_throws(empty_field(TU.SpectralElementSpace1D(FT))) |
| 120 | + test_broken_throws(empty_field(TU.SpectralElementSpace2D(FT))) |
| 121 | + test_broken_throws(empty_field(TU.ColumnCenterFiniteDifferenceSpace(FT))) |
| 122 | + test_broken_throws(empty_field(TU.ColumnFaceFiniteDifferenceSpace(FT))) |
| 123 | + test_broken_throws(empty_field(TU.SphereSpectralElementSpace(FT))) |
| 124 | + test_broken_throws(empty_field(TU.CenterExtrudedFiniteDifferenceSpace(FT))) |
| 125 | + test_broken_throws(empty_field(TU.FaceExtrudedFiniteDifferenceSpace(FT))) |
| 126 | + |
| 127 | + # TODO: performance optimization: shouldn't we do |
| 128 | + # nothing when broadcasting over empty fields? |
| 129 | + # This is otherwise a performance penalty if |
| 130 | + # users regularly rely on empty fields. In particular: |
| 131 | + # - does iterating over empty fields load data? |
| 132 | + # - what is the overhead in iterating over empty fields? |
| 133 | + # - what is the use case of anything useful that can be |
| 134 | + # done by iterating over empty fields? |
| 135 | +end |
| 136 | + |
97 | 137 | @testset "Broadcasting interception for tuple-valued fields" begin
|
98 | 138 | n1 = n2 = 1
|
99 | 139 | Nij = 4
|
|
0 commit comments