Skip to content

Commit

Permalink
Try #1349:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] committed Jun 26, 2023
2 parents 5d7be91 + e6d6800 commit fd6151e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Fields/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ Base.Broadcast.broadcasted(
) where {T <: Geometry.AxisTensor} =
Base.Broadcast.broadcasted(fs, (x...) -> T(x...), args...)

Base.Broadcast.broadcasted(
::typeof(Base.literal_pow),
::typeof(^),
::Field,
::Val{n},
) where {n} = Base.Broadcast.broadcasted(x -> Base.literal_pow(^, x, Val(n)), f)

# Specialize handling of +, *, muladd, so that we can support broadcasting over NamedTuple element types
# Required for ODE solvers

Expand Down
15 changes: 15 additions & 0 deletions test/Fields/field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ end
@test axes(point_field) isa Spaces.PointSpace
end

# https://github.com/CliMA/ClimaCore.jl/issues/1126
function pow_n(f)
@. f.x = f.x^2
return nothing
end
@testset "Broadcasting with ^n" begin
FT = Float32
for space in TU.all_spaces(FT)
f = fill((; x = FT(1)), space)
pow_n(f) # Compile first
p_allocated = @allocated pow_n(f)
@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 fd6151e

Please sign in to comment.