# Concatenation on matrix-like types on 0.7

**URL:** <https://discourse.julialang.org/t/concatenation-on-matrix-like-types-on-0-7/10251>\
**Category:** General Usage\
**Created:** [April 9, 2018, 7:44pm UTC](https://discourse.julialang.org/t/concatenation-on-matrix-like-types-on-0-7/10251 "2018-04-09T19:44:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abelsiqueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abelsiqueira/32/47269_2.png) [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Post date:** [April 9, 2018, 7:44pm UTC](https://discourse.julialang.org/t/concatenation-on-matrix-like-types-on-0-7/10251/1 "2018-04-09T19:44:57Z")

</div>

I think [this commit](https://github.com/JuliaLang/julia/pull/24017/commits) broke [LinearOperators here](https://github.com/JuliaSmoothOptimizers/LinearOperators.jl/pull/45). 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:

```julia
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()

```

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [April 10, 2018, 4:23am UTC](https://discourse.julialang.org/t/concatenation-on-matrix-like-types-on-0-7/10251/2 "2018-04-10T04:23:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![abelsiqueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abelsiqueira/32/47269_2.png) [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Post date:** [April 10, 2018, 11:29am UTC](https://discourse.julialang.org/t/concatenation-on-matrix-like-types-on-0-7/10251/3 "2018-04-10T11:29:26Z")

</div>

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](https://github.com/JuliaLang/julia/pull/24017/files)) was very useful here.

Does this affect anyone else?
