Skip to content

lexicographic order for AbstractVector is inconsistent #48916

@matthias314

Description

@matthias314

According to the documentation for isless,

If isless(x, y) is defined, then so is isless(y, x) and isequal(x, y), and exactly one of those three yields true.

My understanding is that this should hold for all possible arguments. However, on 1.9.0-beta4 and master,

julia> using OffsetArrays
julia> x = [1,2,3]; y = OffsetVector(x, -1);
julia> (isless(x,y), isless(y,x), isequal(x,y))
(false, false, false)

This is because isequal(x,y) gives false if x and y have different index ranges. This is also inconsistent with cmp,

julia> cmp(x,y)
0

since according to the documentation cmp(x,y) == 0 should imply isequal(x,y).

Would it be a solution to define isless(x,y) and cmp(x,y) for AbstractVector only if firstindex(x) == firstindex(y) and to raise an error otherwise? Or would that be breaking?

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]correctness bug ⚠Bugs that are likely to lead to incorrect results in user code without throwingequalityIssues relating to equality relations: ==, ===, isequalsortingPut things in order

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions