Skip to content

Commit

Permalink
Fix equality for FieldVectors with different type
Browse files Browse the repository at this point in the history
Before this commit, == for FieldVectors with different types was falling
back to the AbstractArray ==, resulting in false positives. Now
FieldVectors with different types are always considered different.
  • Loading branch information
Sbozzolo committed Oct 2, 2024
1 parent 28f7504 commit 12f7746
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ v0.14.17
- Fixed some type instabilities PR [#2004](https://github.com/CliMA/ClimaCore.jl/pull/2004)
- More fixes to higher resolution column cases for the GPU [#1854](https://github.com/CliMA/ClimaCore.jl/pull/1854)

### ![][badge-🐛bugfix] Fix equality for `FieldVector`s with different type

Due to a bug, `==` was not recursively checking `FieldVector`s with different
types, which resulted in false positives. This is now fixed and `FieldVector`s
with different types are always considered different.

PR [#2021](https://github.com/CliMA/ClimaCore.jl/pull/2021).

v0.14.16
-------

Expand Down
14 changes: 11 additions & 3 deletions src/Fields/fieldvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,18 @@ end
Recursively compare given fieldvectors via `==`.
Returns `true` if `x == y` recursively.
FieldVectors with different types are considered different.
"""
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)
rcompare(x::T, y::T) where {T <: FieldVector} = _rcompare(true, x, y)

rcompare(x::T, y::T) where {T <: NamedTuple} = _rcompare(true, x, y)

# FieldVectors with different types are always different
rcompare(x::FieldVector, y::FieldVector) = false

# Define == to call rcompare for two fieldvectors
Base.:(==)(x::FieldVector, y::FieldVector) = rcompare(x, y)

0 comments on commit 12f7746

Please sign in to comment.