Skip to content

Compute Katz distances without integer wraparound - #59

Draft
AHMETHAKANBEZIR1 wants to merge 1 commit into
raphaelvallat:masterfrom
AHMETHAKANBEZIR1:fix/katz-integer-distances
Draft

AHMETHAKANBEZIR1 wants to merge 1 commit into
raphaelvallat:masterfrom
AHMETHAKANBEZIR1:fix/katz-integer-distances

Conversation

@AHMETHAKANBEZIR1

Copy link
Copy Markdown

katz_fd computes successive and origin-relative distances in the input integer dtype. Falling unsigned steps wrap, narrow signed differences overflow, and the total path length can overflow as well. For example, [1, 5, 2, 8, 3] as uint8 returns about -0.4764 instead of the floating-reference value 3.1376. Boolean inputs also fail during subtraction.

Compute ordered integer distance magnitudes using uint64 subtraction, then convert the magnitudes to float64 for the existing Katz formula. This handles the full signed/unsigned 64-bit distance range. Casting samples to float64 first would lose differences between nearby large integers, so the tests explicitly protect that case. The floating-point path and the definition of Katz FD are retained. This changes only Katz; #56 and #57 address different features.

Validation on Windows CPU, Python 3.12.14:

  • 31 new cases: unmodified master 6843920 gives 24 failures and 7 passing controls; the patch passes all 31. References calculate distances with Python integers before evaluating the existing formula. Cases include unsigned ADC values, signed/unsigned extrema, close large 64-bit integers, booleans, vectors and both matrix axes, read-only inputs, and bit-identical fractional float controls.
  • Full suite: 65 passed with NumPy 2.5.4 and 65 passed with NumPy 1.26.4; NumPy overflow/invalid/divide exceptions were also enabled for an integer-extrema smoke check.
  • Full Ruff lint/format and whitespace checks passed. Strict Sphinx HTML build (-W) passed, including the updated Katz notes.

This does not change the mathematical formula's degenerate/infinite cases. Other operating systems, doctests, performance benchmarks and downstream classification/clinical effects were not tested.

AI disclosure: OpenAI Codex autonomously investigated and implemented this patch/tests, wrote the description and ran the reported checks. No independent human pre-submission review has been performed.

@raphaelvallat

Copy link
Copy Markdown
Owner

Thank you for your contribution!

AntroPy now has guidelines for pull requests, including specific steps for AI-assisted PRs: #61

Before I review this PR, could you please go through those steps and update the PR accordingly? In particular: state the user-impact rating (P1-P3) with a short justification, start the description with a summary in your own words, report the exact AI model used (if any), and run an AI review and post a summary of it as a comment. Thanks!

@AHMETHAKANBEZIR1
AHMETHAKANBEZIR1 marked this pull request as draft October 24, 2026 12:27

This branch has not been deployed

No deployments
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.

2 participants