# \[RFC/ANN\] ComponentArrays.jl for building composable models without a modeling language

**URL:** <https://discourse.julialang.org/t/rfc-ann-componentarrays-jl-for-building-composable-models-without-a-modeling-language/38001>\
**Category:** Package Announcements\
**Tags:** diffeq, optim, componentarrays\
**Created:** [April 22, 2020, 1:57am UTC](https://discourse.julialang.org/t/rfc-ann-componentarrays-jl-for-building-composable-models-without-a-modeling-language/38001 "2020-04-22T01:57:43Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![jonniedie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonniedie/32/12842_2.png) [@jonniedie](https://discourse.julialang.org/u/jonniedie)\
**Post date:** [April 24, 2020, 3:37am UTC](https://discourse.julialang.org/t/rfc-ann-componentarrays-jl-for-building-composable-models-without-a-modeling-language/38001/21 "2020-04-24T03:37:51Z")

</div>

That’s funny because I actually slightly preferred the name `ComponentArray` to `CArray` (`CArray` sounds like it would be an array passed into a C call or something) but I ended up going with `CArray` to _follow the convention_ I’ve seen in other array type packages (`LArray` in LabelledArrays.jl, `SArray` in StaticArrays.jl, etc.). I’ll have to reconsider though before I go too much further.

The other thing that pulled me in the direction of `CArray` is that I hate that `ComponentArray` takes away easy autocompletion for `ComponentArrays` when I want to use an unexported function in the repl as I’m working on the package. But that’s not really a good reason.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 25, 2020, 3:00pm UTC](https://discourse.julialang.org/t/rfc-ann-componentarrays-jl-for-building-composable-models-without-a-modeling-language/38001/22 "2020-04-25T15:00:45Z")

</div>

Interesting. Looks like the issue is just with nesting. ArrayPartition broadcast is completely non-allocating and fast if it’s only one level:

```julia
using RecursiveArrayTools, Test

xce0 = ArrayPartition(zeros(2),[0.])
xcde0 = copy(xce0)
function foo(y, x)
	y .= y .+ x
	nothing
end
foo(xcde0, xce0)
@test 0 == @allocated foo(xcde0, xce0)
function foo(y, x)
	y .= y .+ 2 .* x
	nothing
end
foo(xcde0, xce0)
@test 0 == @allocated foo(xcde0, xce0)

```

```julia
using BenchmarkTools
@btime foo(xcde0, xce0) # 29.548 ns (0 allocations: 0 bytes)

```

but falls off if many levels are added. I wonder why. At least this doesn’t the effect the implementation of the symplectic integrators which only use one level.

---

<div class="post-metadata">

**Author:** ![jonniedie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonniedie/32/12842_2.png) [@jonniedie](https://discourse.julialang.org/u/jonniedie)\
**Post date:** [April 25, 2020, 8:59pm UTC](https://discourse.julialang.org/t/rfc-ann-componentarrays-jl-for-building-composable-models-without-a-modeling-language/38001/23 "2020-04-25T20:59:17Z")

</div>

I wonder if it has to do with the different eltypes of the contained arrays. A couple of those in the example are `Int64`s. I didn’t really think that through when I made the example because `CArray`s promote everything to a common type and one of the things I was testing when I originally wrote that example `ca` was it’s ability to do that. But that probably makes for an unfair comparison.

When I can get to a computer I’ll try it out with all `Float64[...]` inner arrays.

[Previous page](https://discourse.julialang.org/t/rfc-ann-componentarrays-jl-for-building-composable-models-without-a-modeling-language/38001.md?page=1)
