Repository navigation
Preserve minimum signed integers during hard thresholding - #889
Open
AHMETHAKANBEZIR1 wants to merge 2 commits into
Open
AHMETHAKANBEZIR1 wants to merge 2 commits into
AHMETHAKANBEZIR1 wants to merge 2 commits into
Conversation
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.
Hard thresholding silently discards the minimum signed integer because
abswraps in the original dtype. For example,threshold(np.array([-128,-127,0,127], dtype=np.int8), 64, mode='hard')returns[0,-127,0,127], although the magnitude of -128 is 128 and that sample should be preserved.View signed integer absolute values as the corresponding unsigned dtype before comparison. Ordinary absolute values retain the same bits, while the wrapped minimum becomes its exact positive magnitude. This adds no floating-point conversion or magnitude-array copy, and the returned data still uses the existing
np.wherepath.Validation:
Thirty-four new cases cover int8/int16/int32/int64, default/custom substitutes, thresholds equal to and above the minimum's magnitude, scalar inputs, large int64 comparison controls, byte orders, and Python/NumPy scalar/zero-dimensional thresholds. Reference decisions use Python integer arithmetic. Unmodified main wheel: 20 failures and 14 passing controls.
Rebuilt the Windows MSVC/Cython wheel and checked that its source and test files match the final working tree. Full installed package tests on NumPy 2.5.4: 1,086 passed, 2 skipped.
Thresholding tests on NumPy 2.0.2: 38 passed. The older NumPy was loaded from an isolated target rather than replacing the main validation environment.
Real-input example: the built-in camera image centered by subtracting128 and cast to int8, hard threshold64. Its one -128 pixel is incorrectly removed on main; the fixed output has zero differences from an int16 magnitude reference and retains int8 output. This is a locally constructed preprocessing workflow, not a claimed production incident.
Applicable configured prek hooks and
git diff --checkpass.CI follow-up: the AppVeyor Python 3.13 job also completed the full suite with 1,086 passed and 2 skipped. The Python 3.12 job log stops immediately after NumPy installation with process exit -1073740791, before building or testing PyWavelets. Its underlying cause has not been established; no workflow or check was weakened. Local Python 3.12 validation above passed.
Other threshold modes and other platforms were not tested for minimum-integer behavior. Codex investigated and validated this AI-assisted contribution autonomously; no independent human review is claimed.
Current-head CI triage: the AppVeyor Python 3.12 job stops immediately after installing NumPy 2.5.4, with Windows process exit code -1073740791, before package build or test execution. The Python 3.13 job of the same build succeeds. This is an installation-stage failure, not evidence of a thresholding regression; no environment pins, test gates, or workflow files were changed. Log: https://ci.appveyor.com/api/buildjobs/bg9l7cpsxpqws5p9/log (build 1.0.1271, 54888084).
Revalidation on main
8ff0679(Windows CPU, Python 3.13.3, NumPy 2.5.5): the installed baseline wheel reproduced 20 failures in the 34 signed-integer cases. The installed wheel containing this PR passed all 38 thresholding tests and the full package suite (1,086 passed, 2 skipped). The patch is unchanged after merging current main.The AppVeyor matrix passed on Windows with Python 3.12 and 3.13 (1,086 passed, 2 skipped on each). A separate local wheel built with NumPy 2.0.0 passed all 38 thresholding tests. GitHub Actions reports approval required for the fork workflows.