Skip to content

Copy Parameter values on assignment - #39

Merged
dance858 merged 1 commit into
mainfrom
copy-parameter-value
Nov 13, 2026
Merged

dance858 merged 1 commit into
mainfrom
copy-parameter-value

Conversation

@dance858

Copy link
Copy Markdown
Collaborator

Parameter.value = arr kept a view of arr when no conversion was needed (1-D, (n, 1)/(1, n) and F-ordered float64 input). Editing arr in place then changed p.value without bumping the parameter version, so the engine kept the old values until some unrelated Parameter was assigned:

arr = np.ones(2); p = s.Parameter(2, 1, value=arr)
f = sp.compile(sp.sum(p * x)); x.value = [1., 2.]
arr[:] = 10; x.value = [1., 2.]
f.forward()  # 3.0, while p.value implies 30

The same in-place edit could also make a quad_form Q non-symmetric after it had passed the symmetry check.

The fix copies the flattened value in the Parameter.value setter. It adds test_parameter_value_is_copied, which fails on main.

Part of #37 (item 4).

🤖 Generated with Claude Code

Parameter.value = arr kept a view of arr for 1-D, vector and F-ordered
float64 input. Editing arr in place then changed p.value without bumping
the parameter version, so the engine kept the old values until some other
Parameter was assigned.

Part of #37 (item 4).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dance858
dance858 merged commit 156ef57 into main Nov 13, 2026
17 of 25 checks passed
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 this pull request may close these issues.

1 participant