Skip to content

Commit

Permalink
Merge pull request #2014 from CliMA/dy/number_methods
Browse files Browse the repository at this point in the history
Remove unnecessary method specializations for Numbers
  • Loading branch information
charleskawczynski authored Sep 27, 2024
2 parents de5552c + cbfb3df commit 846edd8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
14 changes: 14 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,11 @@ steps:
key: unit_matrix_field_broadcasting_cpu_non_scalar_4
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/MatrixFields/matrix_fields_broadcasting/test_non_scalar_4.jl"

- label: "Unit: matrix field broadcasting (CPU)"
key: unit_matrix_field_broadcasting_cpu_non_scalar_5
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/MatrixFields/matrix_fields_broadcasting/test_non_scalar_5.jl"
soft_fail: true

- group: "Unit: MatrixFields - broadcasting (GPU)"
steps:

Expand Down Expand Up @@ -1084,6 +1089,15 @@ steps:
slurm_gpus: 1
slurm_mem: 10GB

- label: "Unit: matrix field broadcasting (GPU)"
key: unit_matrix_field_broadcasting_gpu_non_scalar_5
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/MatrixFields/matrix_fields_broadcasting/test_non_scalar_5.jl"
env:
CLIMACOMMS_DEVICE: "CUDA"
agents:
slurm_gpus: 1
slurm_mem: 10GB

- group: "Unit: Hypsography"
steps:

Expand Down
12 changes: 1 addition & 11 deletions src/RecursiveApply/RecursiveApply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ Recursively add elements of `X` and `Y`.
"""
radd(X) = X
radd(X, Y) = rmap(+, X, Y)
radd(w::Number, X) = rmap(x -> w + x, X)
radd(X, w::Number) = rmap(x -> x + w, X)
radd(w1::Number, w2::Number) = w1 + w2
const = radd

# Adapted from Base/operators.jl for general nary operator fallbacks
Expand All @@ -187,9 +184,6 @@ Recursively subtract elements of `Y` from `X`.
"""
rsub(X) = rmap(-, X)
rsub(X, Y) = rmap(-, X, Y)
rsub(X, w::Number) = rmap(x -> x - w, X)
rsub(w::Number, X) = rmap(x -> w - x, X)
rsub(w1::Number, w2::Number) = w1 - w2
const = rsub

"""
Expand All @@ -198,9 +192,6 @@ const ⊟ = rsub
Recursively divide each element of `X` by `Y`
"""
rdiv(X, Y) = rmap(/, X, Y)
rdiv(X, w::Number) = rmap(x -> x / w, X)
rdiv(w::Number, X) = rmap(x -> w / x, X)
rdiv(w1::Number, w2::Number) = w1 / w2

"""
rmuladd(w, X, Y)
Expand All @@ -209,7 +200,6 @@ Recursively add elements of `w * X + Y`.
"""
rmuladd(w::Number, X, Y) = rmap((x, y) -> muladd(w, x, y), X, Y)
rmuladd(X, w::Number, Y) = rmap((x, y) -> muladd(x, w, y), X, Y)
rmuladd(X::Number, w::Number, Y) = rmap((x, y) -> muladd(x, w, y), X, Y)
rmuladd(w::Number, x::Number, y::Number) = muladd(w, x, y)
rmuladd(x::Number, w::Number, Y) = rmap(y -> muladd(x, w, y), Y)

end # module
1 change: 1 addition & 0 deletions test/MatrixFields/matrix_field_broadcasting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ end
GC.gc(); include(joinpath("matrix_fields_broadcasting", "test_non_scalar_2.jl")); print_mem && @info "mem usage: rss = $(Sys.maxrss() / 2^30)"
GC.gc(); include(joinpath("matrix_fields_broadcasting", "test_non_scalar_3.jl")); print_mem && @info "mem usage: rss = $(Sys.maxrss() / 2^30)"
GC.gc(); include(joinpath("matrix_fields_broadcasting", "test_non_scalar_4.jl")); print_mem && @info "mem usage: rss = $(Sys.maxrss() / 2^30)"
GC.gc(); include(joinpath("matrix_fields_broadcasting", "test_non_scalar_5.jl")); print_mem && @info "mem usage: rss = $(Sys.maxrss() / 2^30)"
GC.gc()
end
#! format: on
Expand Down
30 changes: 30 additions & 0 deletions test/MatrixFields/matrix_fields_broadcasting/test_non_scalar_5.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#=
julia --project
using Revise; include(joinpath("test", "MatrixFields", "matrix_fields_broadcasting", "test_non_scalar_1.jl"))
=#
import ClimaCore
#! format: off
if !(@isdefined(unit_test_field_broadcast))
include(joinpath(pkgdir(ClimaCore),"test","MatrixFields","matrix_fields_broadcasting","test_non_scalar_utils.jl"))
end
#! format: on
test_opt = get(ENV, "BUILDKITE", "") == "true"
@testset "matrix of vectors divided by scalar" begin

bc = @lazy @. ᶜᶠmat_C12 / 2
result = materialize(bc)

ref_set_result! =
result -> (@. result =
map(Geometry.Covariant12Vector, ᶜᶠmat2 / 2, ᶜᶠmat3 / 2))

unit_test_field_broadcast(
result,
bc;
ref_set_result!,
allowed_max_eps_error = 0,
)

test_opt && opt_test_field_broadcast(result, bc; ref_set_result!)
test_opt && !using_cuda && perf_getidx(bc)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ UnitTest("MatrixFields - non-scalar broadcasting (1)" ,"MatrixFields/matrix_fiel
UnitTest("MatrixFields - non-scalar broadcasting (2)" ,"MatrixFields/matrix_fields_broadcasting/test_non_scalar_2.jl"),
UnitTest("MatrixFields - non-scalar broadcasting (3)" ,"MatrixFields/matrix_fields_broadcasting/test_non_scalar_3.jl"),
UnitTest("MatrixFields - non-scalar broadcasting (4)" ,"MatrixFields/matrix_fields_broadcasting/test_non_scalar_4.jl"),
UnitTest("MatrixFields - non-scalar broadcasting (5)" ,"MatrixFields/matrix_fields_broadcasting/test_non_scalar_5.jl"),
UnitTest("MatrixFields - flat spaces" ,"MatrixFields/flat_spaces.jl"),

# UnitTest("MatrixFields - matrix field broadcast" ,"MatrixFields/matrix_field_broadcasting.jl"), # too long
Expand Down

0 comments on commit 846edd8

Please sign in to comment.