Open
Description
Motivation
In fitting or optimization workflows, it’s common to work with a structured ComponentArray
template and update only a subset of its parameters during each iteration. While manual assignment is always possible using field names or indices, it’s often verbose and error-prone.
I'd like to have a utility function that enables updating parameters by name using existing axis metadata, without reconstructing the structure or altering types.
Proposed Functionality
Introduce update_component_array(default, update)
that:
- Updates a
ComponentArray
default with values from anotherComponentArray
update - Modifies only matching entries (partial updates supported)
- Preserves structure, type, and axis information of the original array
Example Usage
default = ComponentArray(sig = (mu = 1.0, sigma = 2.0), bg = 3.0)
update = ComponentArray(sig = (mu = 1.1,), bg = 3.3)
result = update_component_array(default, update)
result.sig.mu # 1.1
result.sig.sigma # 2.0
result.bg # 3.3
Btw
Originally, I tried to implement deep_merge
, but it's really hard to make it type stable. I'd be happy to have the update
solution
Metadata
Metadata
Assignees
Labels
No labels