# Labeled vector or vector view of nested structure

**URL:** <https://discourse.julialang.org/t/labeled-vector-or-vector-view-of-nested-structure/108031>\
**Category:** General Usage\
**Tags:** question, data\_structures\
**Created:** [December 25, 2023, 11:03am UTC](https://discourse.julialang.org/t/labeled-vector-or-vector-view-of-nested-structure/108031 "2023-12-25T11:03:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 25, 2023, 11:03am UTC](https://discourse.julialang.org/t/labeled-vector-or-vector-view-of-nested-structure/108031/1 "2023-12-25T11:03:31Z")

</div>

I am trying to organize a computation which maps a parameter vector `p` to various residuals `r = f(p)`, and then solves for the root using a multivariate rootfinder.

This part is simple. But then I want to understand and plot various residuals — effectively they are flattened and concatenated views of (nested) arrays, all coming from various functional equations evaluated at collocation nodes. An MWE for a typical `r` is

```julia
using StaticArrays, DifferentiableFlatten
R = (a = randn(5, 5), b = rand(SVector{3}, 4), c = rand(SVector{5}, 3, 4))
r = DifferentiableFlatten.flatten(R)[1]

```

Then, when I am examining the solution, I would want to reconstruct `a`, `b`, `c` etc.

I have not made up my mind about what would be best for me. I am thinking along the lines of either

1. flattening, and providing labels along with it,

2. just returning a flattening _view_, which allows extraction of the parent _as is_.

I could not find a package for either (but it would be trivial to code). I am leaning to (2). In the actual problem, `r` is about 5k long, but allocation has negligible cost compared to computation.

---

<div class="post-metadata">

**Author:** ![Pedro](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@Pedro](https://discourse.julialang.org/u/Pedro)\
**Post date:** [December 25, 2023, 11:28am UTC](https://discourse.julialang.org/t/labeled-vector-or-vector-view-of-nested-structure/108031/2 "2023-12-25T11:28:38Z")

</div>

Check `ComponentArrays.jl` package.
