Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define == for same-typed fieldvectors #1954

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading