Skip to content

fix(cube): validate finite LUT values and enforce uint8/uint16 pixels - #4

Merged
joepetjr merged 2 commits into
mainfrom
fix/lut-finite-values-and-scaling
Oct 1, 2026
Merged

joepetjr merged 2 commits into
mainfrom
fix/lut-finite-values-and-scaling

Conversation

@joepetjr

Copy link
Copy Markdown
Contributor

Summary

  • LUT-1. load_cube() and Cube now raise CubeError on NaN, infinity, or a value that overflows float32, in the domain, the 3D table or the 1D curves. A directly constructed Cube with an inverted domain is rejected too. Before, these values reached the final cast as undefined pixels.
  • LUT-2. apply_cube() accepts only uint8 and uint16 pixels. Any other dtype raises CubeError. Before, every dtype that was not uint16 was divided by 255, so a float image in [0, 1] was silently crushed.
  • README and CHANGELOG updated.

Plan units: LUT-1, LUT-2 (portfolio remediation 2026-09-29).

Behavior change to review

A caller that passed float or signed arrays to apply_cube() used to get a wrong image. It now gets an error that names the dtype and says to convert. No normalized-float API is added.

Finite table values outside [0, 1] are still accepted, as the format allows.

Test plan

  • LUT-1: nan, inf, -inf, 1e999 and 1e39 in table, domain and 1D curve; direct construction. Seventeen cases were red before the change (DID NOT RAISE CubeError).
  • LUT-2: nine unsupported dtypes plus a float [0, 1] image. Ten were red before the change.
  • Valid 1D and 3D fixtures apply with warnings treated as errors and keep their known output.
  • Full suite locally: 71 passed. ruff check . clean.

Acceptance

  • A NaN cube fails before application: test_non_finite_table_entry_raises_before_apply, test_non_finite_domain_raises, test_non_finite_1d_entry_raises.
  • Valid fixtures keep known output with no cast warnings: test_valid_fixtures_apply_without_runtime_warnings.
  • Float and signed arrays cannot silently use 255 scaling: test_unsupported_pixel_dtype_is_rejected_not_scaled.
  • Supported dtypes keep precision: test_uint16_precision_is_kept_beyond_8_bits, test_uint8_known_output_is_unchanged.

@joepetjr
joepetjr merged commit 54cc640 into main Oct 1, 2026
6 checks passed
@joepetjr
joepetjr deleted the fix/lut-finite-values-and-scaling branch October 1, 2026 22:20
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.

1 participant