# Hcat without copy and stack overflow in type inference

**URL:** https://discourse.julialang.org/t/hcat-without-copy-and-stack-overflow-in-type-inference/101671
**Category:** General Usage
**Tags:** array, lazy-evaluation
**Created:** [July 16, 2023, 9:00am UTC](https://discourse.julialang.org/t/hcat-without-copy-and-stack-overflow-in-type-inference/101671 "2023-07-16T09:00:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![xgdgsc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xgdgsc/32/608_2.png) [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)
#### Post date: [July 16, 2023, 9:00am UTC](https://discourse.julialang.org/t/hcat-without-copy-and-stack-overflow-in-type-inference/101671/1 "2023-07-16T09:00:39Z")

</div>

When using packages like `ArrayPartition` in [GitHub - SciML/RecursiveArrayTools.jl: Tools for easily handling objects like arrays of arrays and deeper nestings in scientific machine learning (SciML) and other applications](https://github.com/SciML/RecursiveArrayTools.jl) and `Hcat` in [GitHub - JuliaArrays/LazyArrays.jl: Lazy arrays and linear algebra in Julia](https://github.com/JuliaArrays/LazyArrays.jl) . I encounter a lot of errors like:

 ![图片](https://global.discourse-cdn.com/julialang/original/3X/6/0/60ae5ff8d2653bdadf1a372de62e22a1ba68f5c0.png)

What’ s the recommended way to do hcat without copy for now?

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [July 16, 2023, 9:54am UTC](https://discourse.julialang.org/t/hcat-without-copy-and-stack-overflow-in-type-inference/101671/2 "2023-07-16T09:54:43Z")

</div>

Can you create a minimal reproducer? It could be useful to report a bug on the Julia Github.

EDIT: that said, I don’t think your issue can be fixed at that end, considering your tuples are truly huge.

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [July 16, 2023, 10:04am UTC](https://discourse.julialang.org/t/hcat-without-copy-and-stack-overflow-in-type-inference/101671/3 "2023-07-16T10:04:29Z")

</div>

> [@xgdgsc](#):
>
> What’ s the recommended way to do hcat without copy for now?

Can you try to materialize the lazy array every so often, before the tuples become so huge? I think it simply doesn’t make sense to create tuples so large.

---

<div class="post-metadata">

### Author: ![xgdgsc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xgdgsc/32/608_2.png) [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)
#### Post date: [July 16, 2023, 10:11am UTC](https://discourse.julialang.org/t/hcat-without-copy-and-stack-overflow-in-type-inference/101671/4 "2023-07-16T10:11:48Z")

</div>

```julia
using RecursiveArrayTools
using ShiftedArrays
ap = ArrayPartition([randn(3641) for i in 1:1000]...)

function procArr(arr1::AbstractArray)
     s = ShiftedArray(arr1, (1, 0))
     s./arr1
end

```

Something like this. It seems [LazyStack](https://github.com/mcabbott/LazyStack.jl) works for this. Would it be better if those packages give an error on long input instead?
