From dc1167b3b823108ef218af00afc5117d477a37d5 Mon Sep 17 00:00:00 2001 From: Andy Dienes Date: Sat, 6 Sep 2025 15:56:48 -0400 Subject: [PATCH 1/2] max vector `cmp` match axes --- base/abstractarray.jl | 2 ++ test/arrayops.jl | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index d4d430a5a1811..bab04cc0e3ea4 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -3016,6 +3016,8 @@ function isequal(A::AbstractArray, B::AbstractArray) end function cmp(A::AbstractVector, B::AbstractVector) + firstindex(A) == firstindex(B) || + throw(ArgumentError("axes must match in vector comparison")) for (a, b) in zip(A, B) if !isequal(a, b) return isless(a, b) ? -1 : 1 diff --git a/test/arrayops.jl b/test/arrayops.jl index e6f8e9ec6756d..a4df08436613b 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -1465,6 +1465,18 @@ end @test cmp([UInt8(1), UInt8(0)], [UInt8(0), UInt8(0)]) == 1 @test cmp([UInt8(1), UInt8(0)], [UInt8(1), UInt8(0)]) == 0 @test cmp([UInt8(0), UInt8(0)], [UInt8(1), UInt8(1)]) == -1 + + x = [1, 2, 3] + y = OffsetVector(x, -1) + @test_throws ArgumentError cmp(x, y) + @test_throws ArgumentError cmp(y, x) + @test_throws ArgumentError isless(x, y) + @test_throws ArgumentError isless(y, x) + + y2 = OffsetVector([1, 2, 3], 0) + @test cmp(x, y2) == 0 + @test !isless(x, y2) + @test !isless(y2, x) end @testset "sort on arrays" begin From 3d6b49688dd378f3e452b900b3163f2bbeec970d Mon Sep 17 00:00:00 2001 From: Andy Dienes Date: Fri, 12 Sep 2025 08:59:34 -0400 Subject: [PATCH 2/2] oops --- base/abstractarray.jl | 4 ++-- test/arrayops.jl | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index bab04cc0e3ea4..d5bc3459419ad 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -3016,8 +3016,8 @@ function isequal(A::AbstractArray, B::AbstractArray) end function cmp(A::AbstractVector, B::AbstractVector) - firstindex(A) == firstindex(B) || - throw(ArgumentError("axes must match in vector comparison")) + ai1, bi1 = firstindex(A), firstindex(B) + isequal(ai1, bi1) || return cmp(ai1, bi1) for (a, b) in zip(A, B) if !isequal(a, b) return isless(a, b) ? -1 : 1 diff --git a/test/arrayops.jl b/test/arrayops.jl index a4df08436613b..d4b401152d7ef 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -1468,10 +1468,10 @@ end x = [1, 2, 3] y = OffsetVector(x, -1) - @test_throws ArgumentError cmp(x, y) - @test_throws ArgumentError cmp(y, x) - @test_throws ArgumentError isless(x, y) - @test_throws ArgumentError isless(y, x) + @test cmp(x, y) == 1 + @test cmp(y, x) == -1 + @test !isless(x, y) + @test isless(y, x) y2 = OffsetVector([1, 2, 3], 0) @test cmp(x, y2) == 0