# Is there a faster alternative to \`hcat(xx...)\`?

**URL:** <https://discourse.julialang.org/t/is-there-a-faster-alternative-to-hcat-xx/98112>\
**Category:** Performance\
**Tags:** question\
**Created:** [April 30, 2023, 5:46am UTC](https://discourse.julialang.org/t/is-there-a-faster-alternative-to-hcat-xx/98112 "2023-04-30T05:46:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [April 30, 2023, 6:04am UTC](https://discourse.julialang.org/t/is-there-a-faster-alternative-to-hcat-xx/98112/2 "2023-04-30T06:04:42Z")

</div>

You could use `reduce(hcat,xx)'` (see [How to convert Vector of Vectors to Matrix - #6 by rafael.guerra](https://discourse.julialang.org/t/how-to-convert-vector-of-vectors-to-matrix/72609/6) ), or in Julia 1.9 you can use `stack`.

To improve speed further, you could maybe post a minimal working example so that people can run the code. (Not visible here, but just a guess: Make sure that you don’t use globals by accident.)

There might also be a way to write the code differently, like

```julia
function filter_triangles(triangles, tokeep)
    counts = map(t -> tokeep[t[1]] + tokeep[t[2]] + tokeep[t[3]], triangles)
    keep = counts .> 0
    new_triangles = triangles[keep]
    return (counts = counts[keep], 
            triangles = new_triangles, 
            connec = connect.(new_triangles))  
end

```

(This uses more memory, but depending on your setting, it might even be faster.)

* * *

EDIT: As @fatteneder pointed out, I removed my wrong comment that `Int` is an abstract type…

---

_[View the full topic](https://discourse.julialang.org/t/is-there-a-faster-alternative-to-hcat-xx/98112)._
