tools/bc_feature: validate block dtype and guard smoothness mip-tail edge shapes #1861

Open
github-bot wants to merge 1 commit from github-bot/gh-1861 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-25 13:22 UTC · original
kirigayakazima:fix/bc-feature-safety → main · +61 −2 · 2 files · 1 commits · open

Claimed in the coordination issue as: BC-FEATURE-SMOOTHNESS-EDGE-AND-DTYPE-SAFETY (#1608)

What and why

  • Enforce dtype == np.uint8 in bc1_average() and block_average() in tools/bc_feature.py so wider integer or floating-point arrays fail fast with ValueError instead of misinterpreting byte bit-patterns.
  • Validate img.ndim >= 2 and img.size > 0 in smoothness(), reject 1D and empty inputs with ValueError, guard axis differences when height or width is 1 (1-row, 1-col, and 1x1 mip tails) so no RuntimeWarning or NaN is produced, and cast non-floating arrays to np.float32 before np.diff to avoid unsigned integer underflow wraparound.
  • Expand tests/test_bc_feature_validation.py with regression tests covering non-uint8 block inputs, 1D/empty rejection, degenerate mip-tail warning-free finiteness, and uint8 step parity with float32.

Tested

  • Patched: 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).
  • Baseline check (upstream/main 98c2f777 with updated tests/test_bc_feature_validation.py copied into detached worktree): Ran 8 tests in 0.016s (FAILED (failures=11)).
  • Repo gates: 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

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
**@⁠kirigayakazima** on GitHub · 2026-11-25 13:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1861) `kirigayakazima:fix/bc-feature-safety` → `main` · +61 −2 · 2 files · 1 commits · open Claimed in the coordination issue as: BC-FEATURE-SMOOTHNESS-EDGE-AND-DTYPE-SAFETY (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Enforce `dtype == np.uint8` in `bc1_average()` and `block_average()` in `tools/bc_feature.py` so wider integer or floating-point arrays fail fast with `ValueError` instead of misinterpreting byte bit-patterns. - Validate `img.ndim >= 2` and `img.size > 0` in `smoothness()`, reject 1D and empty inputs with `ValueError`, guard axis differences when height or width is `1` (1-row, 1-col, and 1x1 mip tails) so no `RuntimeWarning` or `NaN` is produced, and cast non-floating arrays to `np.float32` before `np.diff` to avoid unsigned integer underflow wraparound. - Expand `tests/test_bc_feature_validation.py` with regression tests covering non-`uint8` block inputs, 1D/empty rejection, degenerate mip-tail warning-free finiteness, and `uint8` step parity with `float32`. ### Tested - Patched: `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`). - Baseline check (`upstream/main` `98c2f777` with updated `tests/test_bc_feature_validation.py` copied into detached worktree): `Ran 8 tests in 0.016s` (`FAILED (failures=11)`). - Repo gates: `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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:09:09 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 14:05 UTC · original

Tested 4e6a9c419 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 71a769d7d (Python texture tool; no GPU):

  • pytest 9.2.0 on tests/test_bc_feature_validation.py: 8 passed, 20 subtests passed at this head.
  • The same file on main: 11 failed, 8 passed (10 warnings), 9 subtests — the uint8 dtype enforcement, img.ndim validation and the smoothness mip-tail guard are new.
  • Not run: real BC-packed textures; the tests use synthetic arrays.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 14:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1861#issuecomment-7164748183) Tested `4e6a9c419` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `71a769d7d` (Python texture tool; no GPU): - pytest 9.2.0 on `tests/test_bc_feature_validation.py`: **8 passed, 20 subtests passed** at this head. - The same file on `main`: **11 failed**, 8 passed (10 warnings), 9 subtests — the `uint8` dtype enforcement, `img.ndim` validation and the smoothness mip-tail guard are new. - Not run: real BC-packed textures; the tests use synthetic arrays. AI-assisted; synthetic fixtures only, no game data.
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-25 15:32 UTC · original

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:

  • PR: 8 passed, 20 subtests passed. main: 4 passed, 8 subtests passed. The new tests pass on Windows.

(AI-assisted test run; output checked by hand.)

**@⁠DeadlyChirp** on GitHub · 2026-11-25 15:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1861#issuecomment-7166995660) 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`: - PR: 8 passed, 20 subtests passed. main: 4 passed, 8 subtests passed. The new tests pass on Windows. (AI-assisted test run; output checked by hand.)
Author
Owner

@⁠MSedgeMC on GitHub · 2026-11-25 17:22 UTC · original · approved these changes

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.

**@⁠MSedgeMC** on GitHub · 2026-11-25 17:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1861#pullrequestreview-6061980183) · **approved these changes** 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1861/head:github-bot/gh-1861'
git switch 'github-bot/gh-1861'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1861'
git switch 'github-bot/gh-1861'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1861'
git switch 'github-bot/gh-1861'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1861'
git switch 'main'
git merge --squash 'github-bot/gh-1861'
git switch 'main'
git merge --ff-only 'github-bot/gh-1861'
git switch 'main'
git merge 'github-bot/gh-1861'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.