Repository navigation
test(gfx): pin where P7's RGBW hue divergence comes from — a clamped drive - #4304
Conversation
…drive "RGBW mapper preserves hue while compressing chroma" measured 0.026 of OKLab hue divergence on one target and said it could not tell whether the four-emitter allocation or the Q16 quantisation produced it, because every target in that corpus needs compressing first. Its note names the experiment that would settle it: an in-gamut target, where `mapAndAllocateRgbwQ16` returns the plain allocation untouched. Run. It is the allocation, and the mechanism is exact. At (0.55, 0.41), Y = 0.5 -- one step in y from the outlier, and inside the four-emitter hull -- `solveRgbDrivesQ16` returns blue = **-62 raw**. `allocateEmitterDrivesQ16` accepts a drive down to `-kWhiteSlack` (64) as a rounding allowance, reports the target reachable, and clamps blue to 0. | reproduced from | XYZ error | hue divergence | |---|---:|---:| | the solve's own drives (blue = -62) | 5.3e-05 | 0 | | what the allocator returns (blue = 0) | 0.0158 | 0.026 | So neither the matrix nor the quantisation is the source; the solve is essentially exact. The clamp is the whole anomaly, and it is the same 0.026 the existing case records. Why 62 raw units of drive cost that much colour: this device's blue primary sits at xy = (0.15, 0.06) normalised to Y = 1, so its Z column is 13.17 and one drive unit of blue is thirteen units of Z. The clamp is worth 0.0125 in Z against a target Z of 0.0488. `kWhiteSlack`'s own comment sizes it as "a quarter of one code at 8-bit output", which is true in drive space and is not the space the cost is paid in. Extent, so this is read as neither a coincidence nor a pervasive fault: over the 291 in-gamut targets on a coarse grid of the xy plane at Y = 0.5, the worst divergence is 0.0197 at (0.56, 0.40), the median is 6.9e-05, and only 6 exceed 0.005. The allocator is accurate nearly everywhere and wrong in a small orange-yellow region -- where blue solves just below zero. Both cases carry vacuity guards: the in-gamut count is pinned at 291, and the mechanism case fails if the clamped and honest reproductions ever agree. Mutation-checked: - Removing the clamp fails both new cases and the existing hue case. - `kWhiteSlack` 64 -> 0 makes the target rejected outright, so the new case's `FL_REQUIRE` fails -- it does depend on the slack accepting it. The slack being sized in the wrong space is a defect in its own right and is filed separately; this only establishes what P7 asked. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe RGBW gamut tests now identify negative blue-drive clamping as the source of the 0.026 OKLab hue divergence. They add a focused reproduction and a grid sweep that bounds the affected in-gamut region. ChangesRGBW allocator divergence characterization
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This test-only change documents and bounds the RGBW hue divergence without changing production behavior. It is mergeable with normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…fect (#4303) (#4314) * fix(gfx): size the allocator's feasibility slack in colour, not in drive units (#4303) `allocateEmitterDrivesQ16` let each RGB drive fall 64 raw units outside [0, 1] before refusing, then clamped it -- returning "reachable" and an allocation that reproduces a different colour. The constant's own comment sized it as "a quarter of one code at 8-bit output", which is true in drive space and is not the space the cost is paid in. One drive unit of an emitter is that emitter's XYZ column. The corpus device's blue sits at xy = (0.15, 0.06), putting its Z at 13.17, so the same 64 units bought thirteen times the colour error there as on green. At (0.55, 0.41) -- inside the hull, needing no compression -- blue solved to -62 and was clamped to 0: 0.0125 off in Z against a target Z of 0.0488, 26%, and 0.026 of OKLab hue. Direction 2 of the four the issue lists, implemented and measured. The slack is divided by each column's peak component at bind time, so the colour cost of the allowance is the same on every channel: green keeps 64, red gets 33, blue gets 5. No per-pixel work and no new matrix. Measured over 291 in-gamut targets on the xy plane at Y = 0.5: | | before | after | |---|---:|---:| | worst OKLab hue divergence | 0.0197 | **0.0034** | | targets above 0.005 | 6 | **0** | | targets above 0.010 | 2 | **0** | | targets reported reachable | 291 | 283 | The 8 are the cost, and they are not lost: the gamut mapper compresses them into the hull instead of the allocator answering them wrongly. Pinned, so that cost is visible and cannot grow unnoticed. Three cases change, which is what they were built for. The RGBW hue case bracketed its outlier from below with a message saying that if the anomaly vanished, someone should find out why and re-pin -- it fired, and this is that. It now holds one bound for all five targets. The mechanism case #4304 added becomes a regression guard on the mechanism rather than a record of the defect. The extent case measures the absence with the same grid that measured the presence. The two-white RGBWW path is deliberately untouched. Its slack is still uniform, because the defect was measured on the single-white allocation and RGBWW holds hue under 0.02 on the same five targets that gave RGBW its 0.026 -- so it may not have the same problem, and scaling on a guess would be changing a shipped colour path without evidence. 303/303 unit + 84/84 examples, `bash lint` clean. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9 * fix(gfx): cap the scaled slack, and make four headers self-contained Review on #4313 asked whether `scaled` could overflow an i32 for a tiny emitter luminance. It cannot -- `buildRgbSolveMatrixQ16`'s coefficient guard refuses the profile first, measured at a luminance of 4.6e-5 and below, and UBSan is silent on everything it accepts. Chasing that found something the review did not name and I had missed. The scaling *divides* by the column peak, so a dim emitter -- small column -- wants a **larger** slack. At a luminance of 1e-4 the three channels came out at 330000, 640000 and 48608 raw units. 640000 is nearly ten in drive space, so `drive > 65536 + 640000` accepts any drive at all and clamps it: the exact defect this change exists to remove, an order of magnitude worse, for every dim profile. The slack now only ever narrows. 64 is the ceiling and the column decides how far below it each channel sits. The corpus device is unaffected -- green sits exactly at 64 and the others below -- so every measurement in this PR stands. A case pins it, with a guard that dim profiles actually reach the slack rather than all being refused earlier, and mutation-checked by removing the ceiling: 66, 128 and 3300 against a bound of 64. Also, from trying to write a standalone probe: `white_allocation.h` did not compile as a translation unit's only include, spelling `EmitterProfile` unqualified so it resolved only after some other header pulled in the `using`. `gamut_map.h` had it too, and `colorimetric_response.h` was already fine. That is the second and third instance after `device_solve.h`, so the self-containment test now lists the group rather than taking them one incident at a time -- which is how `gamut_map.h` turned up. 303/303 unit + 84/84 examples, `bash lint` clean. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9 * test(gfx): the two-white allocator does not share the single-white defect (#4303) The question #4303 was left with after #4313 fixed the single-white path. It does not. The defect is accepting a target whose RGB solve wants a drive outside [0, 1], clamping it, and reporting the target reachable. `allocateTwoWhiteDrivesQ16` never accepts one, so its uniform slack never decides feasibility and cannot buy a colour error. The vacuity guard is the part that makes that worth saying. On the same grid, 670 targets *do* have a solve wanting an out-of-range drive -- all 670 are refused. Without pinning that, "never accepts one" would hold just as well over an empty set and would be a property of the corpus rather than of the allocator. Worst OKLab hue divergence over the 283 it accepts is 0.00096, against the single-white path's 0.0197 before #4313 and 0.0034 after. Why it holds is measured, not reasoned, because the first explanation was wrong. `kTwoWhiteBoundSlack` is half the final check's tolerance, so the bounds admit less than the check accepts -- true, and not the reason: making them equal changes nothing. Raising the slack instead: 64 (shipped) 0 accepted with an out-of-range solve 128 0 256 0 512 0 1024 3 2048 5 4096 11 So 64 sits a factor of eight below where the behaviour changes. A comfortable margin rather than a structural guarantee, which is the useful thing to know before widening it. 303/303 unit + 84/84 examples, `bash lint` clean. Test-only; the src change this builds on is #4313. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9 --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Closes the last open question on P7 (#4041). Defect it uncovered: #4303.
What was open
RGBW mapper preserves hue while compressing chromameasured 0.026 of OKLab huedivergence on one target and said plainly that it could not tell whether the
four-emitter allocation or the Q16 quantisation produced it — every target in that
corpus is outside the hull, so the chroma-halving search always runs first. Its own note
names the experiment that would settle it: an in-gamut target, where
mapAndAllocateRgbwQ16returns the plain allocation untouched.This runs it.
The answer
It is the allocation, and the mechanism is exact.
At (0.55, 0.41), Y = 0.5 — one step in y from the outlier, and inside the four-emitter
hull —
solveRgbDrivesQ16returns blue = −62 raw.allocateEmitterDrivesQ16acceptsa drive down to
-kWhiteSlack(64) as a rounding allowance, reports the target reachable,and clamps blue to 0.
The solve is essentially exact, so neither the matrix nor the quantisation is the source.
The clamp is the whole anomaly — the same 0.026 the existing case records on its own
target.
Why 62 drive units cost that much colour: this device's blue primary sits at
xy = (0.15, 0.06) normalised to Y = 1, so its Z column is 13.17 — one drive unit of
blue is thirteen units of Z. The clamp is worth 0.0125 in Z against a target Z of 0.0488.
kWhiteSlack's comment sizes it as "a quarter of one code at 8-bit output", which is truein drive space and is not the space the cost is paid in. That mismatch is #4303.
Extent
Over the 291 in-gamut targets on a coarse grid of the xy plane at Y = 0.5: worst 0.0197 at
(0.56, 0.40), median 6.9e-05, only 6 of 291 above 0.005. Accurate nearly everywhere,
wrong in a small orange-yellow region — where blue solves just below zero. Neither a
coincidence nor a pervasive fault.
Guards
Both cases carry vacuity guards, because both could otherwise pass by measuring nothing:
the in-gamut count is pinned at 291 (a grid that found none would satisfy every bound
below it), and the mechanism case fails if the clamped and honest reproductions ever
converge.
Mutation-checked:
rgb[i] = driveunclamped below zero)kWhiteSlack64 → 0FL_REQUIREfails — it really does depend on the slack accepting itScope
Test-only. No
src/change: fixing the slack means either carrying the forward matrix inWhiteAllocationQ16or choosing a new tolerance for a shipped colour path, and that is adesign call with four candidate directions — written up on #4303 rather than picked here.
This establishes what P7 asked and leaves a baseline for whichever is taken.
The note in the existing case that said the source was undetermined is now wrong, so it is
corrected to point at the new case.
303/303 unit + 84/84 examples,
bash lintclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
Summary by CodeRabbit