Labeled vector or vector view of nested structure

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

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.

Check ComponentArrays.jl package.

1 Like