Skip to content

Add utility for structured updates in ComponentArrays #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mmikhasenko opened this issue Apr 12, 2025 · 0 comments · May be fixed by #304
Open

Add utility for structured updates in ComponentArrays #303

mmikhasenko opened this issue Apr 12, 2025 · 0 comments · May be fixed by #304

Comments

@mmikhasenko
Copy link

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 another ComponentArray 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

@mmikhasenko mmikhasenko changed the title Add utility for structured updates in ComponentArrays Add utility for structured updates in ComponentArrays Apr 12, 2025
@mmikhasenko mmikhasenko linked a pull request Apr 12, 2025 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant