Concatenation on matrix-like types on 0.7

I think this commit broke LinearOperators here. Essentially, making [A B; C] calls something different on 0.7, and doesn’t work with the default hcat and vcat.

A workaround would be to define hvcat for LinearOperators, but I’m wondering if this problem may affect other people, and if there is a better workaround.

MWE:

mutable struct DummyMatrix
  rows :: Int
  cols :: Int
end

import Base.size
function size(A :: DummyMatrix)
  return (A.rows, A.cols)
end

import Base.hcat
function hcat(As :: DummyMatrix...)
  A = As[1]
  for i = 2:length(As)
    A = hcat(A, As[i])
  end
  return A
end

function hcat(A :: DummyMatrix, B :: DummyMatrix)
  @assert A.rows == B.rows
  DummyMatrix(A.rows, A.cols + B.cols)
end

import Base.vcat
function vcat(As :: DummyMatrix...)
  A = As[1]
  for i = 2:length(As)
    A = vcat(A, As[i])
  end
  return A
end

function vcat(A :: DummyMatrix, B :: DummyMatrix)
  @assert A.cols == B.cols
  DummyMatrix(A.rows + B.rows, A.cols)
end

function foo()
  A = DummyMatrix(2,2)
  B = DummyMatrix(2,2)
  C = DummyMatrix(2,4)
  println([A B; C])
end

foo()

There appears to be a detour through a Vector{Any} which doesn’t propagate the size information as you might hope.

Can you use [[A B]; C] instead?

Yes, [[A B]; C] results in the correct LinearOperator, but we want LinearOperator to closely resemble matrices when possible, and the “fallback definition of hvcat in terms of hcat and vcat” (Line 1532) was very useful here.

Does this affect anyone else?