Skip to content

Commit

Permalink
Merge pull request #1954 from CliMA/ck/field_vector_equals
Browse files Browse the repository at this point in the history
Define == for same-typed fieldvectors
  • Loading branch information
charleskawczynski authored Aug 23, 2024
2 parents 5f6b477 + d8a6ef0 commit 18475e5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Fields/fieldvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,7 @@ Returns `true` if `x == y` recursively.
"""
rcompare(x::T, y::T) where {T <: Union{FieldVector, NamedTuple}} =
_rcompare(true, x, y)

# Define == to call rcompare for two fieldvectors of the same
# exact type.
Base.:(==)(x::T, y::T) where {T <: FieldVector} = rcompare(x, y)
4 changes: 2 additions & 2 deletions test/Fields/unit_field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ end
Y.k.z = 3.0
@test Y.k.z === 3.0

@test Fields.rcompare(Y, Y)
@test Y == Y
Ydc = deepcopy(Y)
Ydc.k.z += 1
@test !Fields.rcompare(Ydc, Y)
@test !(Ydc == Y)
# Fields.@rprint_diff(Ydc, Y)
s = sprint(
Fields._rprint_diff,
Expand Down
4 changes: 2 additions & 2 deletions test/Fields/utils_field_multi_broadcast_fusion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ function test_kernel!(; fused!, unfused!, X, Y)
@testset "Test correctness of $(nameof(typeof(fused!)))" begin
Fields.@rprint_diff(X_fused, X_unfused)
Fields.@rprint_diff(Y_fused, Y_unfused)
@test Fields.rcompare(X_fused, X_unfused)
@test Fields.rcompare(Y_fused, Y_unfused)
@test X_fused == X_unfused
@test Y_fused == Y_unfused
end
end

Expand Down

0 comments on commit 18475e5

Please sign in to comment.