Skip to content

Commit

Permalink
Try #1352:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] committed Jun 28, 2023
2 parents a7ae37d + 5088409 commit cf7e36d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/Fields/field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,50 @@ end
end
end

function ifelse_broadcast_allocating(a, b, c)
FT = eltype(a)
@. a = ifelse(true || c < b * FT(1), FT(0), c)
return nothing
end

function ifelse_broadcast_or(a, b, c)
FT = eltype(a)
val = FT(1)
@. a = ifelse(true || c < b * val, FT(0), c)
return nothing
end

function ifelse_broadcast_simple(a, b, c)
FT = eltype(a)
@. a = ifelse(c < b * FT(1), FT(0), c)
return nothing
end

@testset "Broadcasting ifelse" begin
FT = Float32
for space in (
TU.CenterExtrudedFiniteDifferenceSpace(FT),
TU.ColumnCenterFiniteDifferenceSpace(FT),
)
a = Fields.level(fill(FT(0), space), 1)
b = Fields.level(fill(FT(2), space), 1)
c = Fields.level(fill(FT(3), space), 1)

ifelse_broadcast_allocating(a, b, c)
p_allocated =
@allocated ifelse_broadcast_allocating(a, b, c)
@test_broken p_allocated == 0

ifelse_broadcast_or(a, b, c)
p_allocated = @allocated ifelse_broadcast_or(a, b, c)
@test p_allocated == 0

ifelse_broadcast_simple(a, b, c)
p_allocated = @allocated ifelse_broadcast_simple(a, b, c)
@test p_allocated == 0
end
end

# Requires `--check-bounds=yes`
@testset "Constructing & broadcasting over empty fields" begin
FT = Float32
Expand Down

0 comments on commit cf7e36d

Please sign in to comment.