From dbc86c9277baca988167e8a315f133978ac96c36 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Thu, 21 Oct 2021 21:57:36 +0200 Subject: [PATCH] fix unique over a dimension to use `isequal` over `==` (#42737) (cherry picked from commit 011fda9c7892e1bf34f22f0974aaa74fb6bcbc2a) --- base/multidimensional.jl | 4 ++-- test/arrayops.jl | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 32d66c4c54cda..0634805fe4874 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -1614,7 +1614,7 @@ _unique_dims(A::AbstractArray, dims::Colon) = invoke(unique, Tuple{Any}, A) else j_d = i_d end) begin - if (@nref $N A j) != (@nref $N A i) + if !isequal((@nref $N A j), (@nref $N A i)) collided[k] = true end end @@ -1644,7 +1644,7 @@ _unique_dims(A::AbstractArray, dims::Colon) = invoke(unique, Tuple{Any}, A) j_d = i_d end end begin - if (@nref $N A j) != (@nref $N A i) + if !isequal((@nref $N A j), (@nref $N A i)) nowcollided[k] = true end end diff --git a/test/arrayops.jl b/test/arrayops.jl index 542beffeb72a1..05a46cf5cf8e1 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -778,6 +778,10 @@ let A, B, C, D # With hash collisions @test map(x -> x.x, unique(map(HashCollision, B), dims=1)) == C + + # With NaNs: + E = [1 NaN 3; 1 NaN 3; 1 NaN 3]; + @test isequal(unique(E, dims=1), [1 NaN 3]) end @testset "large matrices transpose" begin