Repository navigation
fix: hash 0-d NumPy arrays as scalars in the model identifier - #1785
Merged
Merged
Conversation
An instance in a model with a 0-d NumPy array attribute made Identifier raise "TypeError: iteration over a 0-d array": the array passes the Iterable check but cannot be iterated. Hash the scalar it holds instead, so it matches the equivalent Python value. No existing identifier changes. Closes #1784 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Putting a model instance whose attribute is a 0-d NumPy array into an
af.CollectionmadeIdentifierraiseTypeError: iteration over a 0-d array(autofit/mapper/identifier.py:185). A 0-d array passes theIterablecheck but cannot be iterated. It now hashes as the scalar it holds (value.item()), so it gets the same identifier as the equivalent Python value.No existing identifier changes: the new branch fires only for input that used to raise. NumPy scalars (
np.float64,np.int64) are notIterable, and JAX arrays take the earlier__dict__branch, so neither reaches the new code.Closes #1784
Decision taken (decide-and-flag)
The plan on #1784 said the fix "covers NumPy and JAX". JAX arrays never crashed: they have a
__dict__and hash as just['ArrayImpl'], whatever their value or shape. That is a separate value-blind collision bug, and fixing it would change the identifiers (output folders) of existing models that hold JAX arrays. I narrowed this PR to the NumPy crash and queued ajudgefollow-up draft:draft/bug/autofit/model_identifier_ignores_jax_array_and_numpy_scalar_values.md(it also coversnp.float32/np.int64scalars, which are left out of the hash).API Changes
None. Internal change only.
Test Plan
test_instance_with_0d_numpy_array_attribute: identifier computes, is stable across two builds, equals the Python-float model's identifier, and changes when the value changes. It fails on main and passes on the branch.test_autofit(-x): 4310 passed, 2 skipped, 1 xfailed.2903b6b80434ac99eeb2a42ec9d76684.Validation checklist (--auto run — plan was not pre-approved)
activate.sh) · review (independent Opus) CLEAN, 1 claim basis-cited (test + edge run over float/int/bool/str/None 0-d arrays) · Heart dev-ship GREEN (PyAutoFit + dependants; shown: shift-acked yellows: manifest drift x2, no release rehearsal) · adversary (Sonnet) CLEAN: Witness held across separate processes; old vs new hashes identical for np.float64/np.int64/np.bool_, 1-d arrays and JAX 0-d🤖 Generated with Claude Code