Skip to content

Improve parameter scaling - #8451

Draft
Jens Hedegaard Nielsen (jenshnielsen) wants to merge 3 commits into
microsoft:mainfrom
jenshnielsen:parameter_list_testing
Draft

Improve parameter scaling#8451
Jens Hedegaard Nielsen (jenshnielsen) wants to merge 3 commits into
microsoft:mainfrom
jenshnielsen:parameter_list_testing

Conversation

@jenshnielsen

Copy link
Copy Markdown
Collaborator

No description provided.

The scale and offset conversions assume a numeric data type and rely on
catching TypeError, which does not fit the generic parameter data type.
They were expressed inline, so the working variable was repeatedly
narrowed to whatever the last branch assigned, and each step needed a
suppression.

Move them into four module level helpers that take and return Any. This
keeps the arithmetic out of the generic class, deduplicates the iterable
and scalar branches, and drops the suppressions in this file from 15 to
3.

Also stop routing issuperset through __contains__, which ty cannot
resolve on Self when the class type parameter has a bound.
Cover the iterable branches of the set path helpers, the TypeError
fallbacks and re-raise of the get path helpers, and add direct unit
tests for the four module level helpers. Also add the missing tests
for ParameterSet.issubset/issuperset.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e8c5964a-6418-4d35-b69c-bb44dd727a3c
Multiplying a sequence by a number repeats it rather than scaling its
elements, so setting a parameter to a list with a scalar scale silently
set a repeated raw value, and a scalar offset raised a TypeError. The
get path already falls back on element wise arithmetic; do the same on
the set path so that sequences round trip.

See microsoft#8450 for the remaining silent truncation on length mismatch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e8c5964a-6418-4d35-b69c-bb44dd727a3c
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