Skip to content

Fingerprint numpy arrays by shape, dtype and contents - #19

Merged
LuShadowX merged 1 commit into
mainfrom
numpy-comparator
Aug 8, 2026
Merged

Fingerprint numpy arrays by shape, dtype and contents#19
LuShadowX merged 1 commit into
mainfrom
numpy-comparator

Conversation

@LuShadowX

Copy link
Copy Markdown
Owner

Arrays previously fell through to generic instance handling, which compares
by repr and so reported equal arrays as different.

Elements are routed back through fingerprint() rather than compared as raw
floats, which keeps one answer to the tolerance question whatever the
container holds, and names nan/inf the way the scalar path already does.
Comparing raw floats would make nan equality depend on json.loads returning
the same NaN singleton - true today, and a false positive on every nan array
the moment the serialiser changes.

No rounding tolerance. np.round(x, 12) is an absolute cut, so a relative
error of 1e-15 compared equal at magnitude 1 and different at 1e6 and above,
and it disagreed with how the same float is treated outside an array.
Tolerance is a policy decision for every type at once, not one container.

numpy is located through sys.modules instead of being imported, so a project
that never uses it does not pay to load it; one that does has already
imported it by the time its functions are replayed.

Closes #1

Arrays previously fell through to generic instance handling, which compares
by repr and so reported equal arrays as different.

Elements are routed back through fingerprint() rather than compared as raw
floats, which keeps one answer to the tolerance question whatever the
container holds, and names nan/inf the way the scalar path already does.
Comparing raw floats would make nan equality depend on json.loads returning
the same NaN singleton - true today, and a false positive on every nan array
the moment the serialiser changes.

No rounding tolerance. np.round(x, 12) is an absolute cut, so a relative
error of 1e-15 compared equal at magnitude 1 and different at 1e6 and above,
and it disagreed with how the same float is treated outside an array.
Tolerance is a policy decision for every type at once, not one container.

numpy is located through sys.modules instead of being imported, so a project
that never uses it does not pay to load it; one that does has already
imported it by the time its functions are replayed.

Closes #1
@LuShadowX
LuShadowX merged commit 36cb504 into main Aug 8, 2026
7 checks passed
@LuShadowX
LuShadowX deleted the numpy-comparator branch August 8, 2026 03:17
LuShadowX added a commit that referenced this pull request Aug 8, 2026
* Bring the README's platform, comparator and overhead claims up to date

Windows is tested in CI as of #20, numpy arrays are compared as of #19, and
recording has cost ~8x rather than 15-20x since the back-off work.

* Let check compare two arbitrary refs

check took one ref and always compared it against the working tree, so
reviewing someone else's branch or auditing a release meant checking it out
first. A second optional positional ref is now the candidate:

    nodrift check HEAD~1 HEAD

With no second ref the working tree is still the candidate, which is the
common case.

Closes #11

* Strip compiled bytecode from staged trees

A repository with __pycache__ committed hands the replay bytecode compiled
from other source. Python runs it in preference to the file git archive just
materialised, so both versions behave identically and check reports no
behaviour change while the code genuinely differs.

Found while testing two-ref comparison: a tree staged from a commit
containing POSITIVE replayed as positive, and check called it clean. The
one-ref path had the same hole.

Silent wrongness rather than an error, which is the worst failure this tool
has. Compiled artifacts are now removed from every staged tree, exported or
copied. The regression test commits stale bytecode deliberately and fails
without the fix.
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.

Comparator for numpy arrays

1 participant