Skip to content

(Row)Vector equality with Matrices #21998

@staticfloat

Description

@staticfloat

Right now, RowVectors are implicitly embedded within Matrices, but not so for Vectors. This leads to funky behaviors such as:

julia> a = Vector(1:2)
2-element Array{Int64,1}:
 1
 2

julia> am = Matrix(2, 1); am[:] = 1:2; am
2×1 Array{Any,2}:
 1
 2

julia> a == am
false

julia> a' == am'
true

There are many ways we could try to fix this. Two take two extremal approaches, we could:

  • On the conservative side, we could just define ==(Matrix, Vector) and be done with it

  • Personally I'd rather push for automatic "do what makes sense" equality checking for types that have natural isomorphisms. E.g. if I have an Array{T,N}, I think it makes sense to define equality with an Array{T,N+1} that has a trailing singleton dimension, as the former is naturally embedded within the space of the second.

I'd be happy to submit a PR implementing whatever we reach consensus on. Hopefully this is a small change to just equality and doesn't get sidetracked into anything more fundamental.

Pinging a random subset of the LinAlg posse @stevengj @jiahao @mbauman

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions