tools/bc_feature: validate block dtype and guard smoothness mip-tail edge shapes #1861
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!1861
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/bc-feature-safety"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Claimed in the coordination issue as: BC-FEATURE-SMOOTHNESS-EDGE-AND-DTYPE-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163663715)
What and why
dtype == np.uint8inbc1_average()andblock_average()intools/bc_feature.pyso wider integer or floating-point arrays fail fast withValueErrorinstead of misinterpreting byte bit-patterns.img.ndim >= 2andimg.size > 0insmoothness(), reject 1D and empty inputs withValueError, guard axis differences when height or width is1(1-row, 1-col, and 1x1 mip tails) so noRuntimeWarningorNaNis produced, and cast non-floating arrays tonp.float32beforenp.diffto avoid unsigned integer underflow wraparound.tests/test_bc_feature_validation.pywith regression tests covering non-uint8block inputs, 1D/empty rejection, degenerate mip-tail warning-free finiteness, anduint8step parity withfloat32.Tested
python -I tests/test_bc_feature_validation.py -v->Ran 8 tests in 0.002s(OK);python -I tests/test_bc_feature.py -v->Ran 15 tests in 0.082s(OK).upstream/main98c2f777with updatedtests/test_bc_feature_validation.pycopied into detached worktree):Ran 8 tests in 0.016s(FAILED (failures=11)).python -I tests/test_ci_registration.py(Ran 16 tests in 4.628s,OK),python -I tests/test_text_write_line_endings.py(Ran 3 tests in 12.538s,OK),python -I scripts/check_no_game_data.py(exit 0),python -I -m compileall -q(exit 0),git diff --check(exit 0).GPUs tested: n/a (numpy array validation and feature-metric unit tests)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.Tested
4e6a9c419on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), againstmain71a769d7d(Python texture tool; no GPU):tests/test_bc_feature_validation.py: 8 passed, 20 subtests passed at this head.main: 11 failed, 8 passed (10 warnings), 9 subtests — theuint8dtype enforcement,img.ndimvalidation and the smoothness mip-tail guard are new.AI-assisted; synthetic fixtures only, no game data.
Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.
python -m pytest -q tests/test_bc_feature_validation.py:(AI-assisted test run; output checked by hand.)
Verified on the PR branch: python3 -m unittest tests.test_bc_feature_validation -v -> 8 tests OK, including the new non-uint8 dtype rejection, 1d/empty smoothness rejection, and degenerate mip-shape cases without RuntimeWarnings. These guards prevent silent garbage from malformed inputs in a texture-feature tool. Python/numpy only, no game data.
Red/green: tests/test_bc_feature_validation.py fails 11 assertions on main (non-uint8 dtype accepted, 1-D/empty smoothness input, degenerate mip-tail shapes) and passes with the PR.
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main cb7a239cc in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)