Skip to content

Round to nearest in every scale_brightness(), and make the ImageScaleBrightness test a real test - #1669

Merged
Mysticial merged 2 commits into
mainfrom
test-kernels-real-images
Oct 23, 2026
Merged

Mysticial merged 2 commits into
mainfrom
test-kernels-real-images

Conversation

@Gin890

@Gin890 Gin890 commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Make every scale_brightness() implementation round each channel to the nearest integer, and make the ImageScaleBrightness kernel test a real test.

As Mysticial asked, this PR now has only the scale_brightness() part. The other two parts are in #1681 (PackedBinaryMatrix::submatrix()) and #1682 (filter_rgb32_range()).

The x86 SIMD versions already round to nearest, but Default and NEON truncated. So on Apple Silicon, ExactImageMatcher and ImageMatchDetector got channels up to 1 lower than on x86. Now Default and NEON round too. At an exact .5 tie, Default rounds up and the SIMD code rounds to even. The test accepts both.

Before, the test was debug code. It was not registered, so CI did not run it. It only timed the implementation that the dispatch picks, and did not check the result. Now it checks each implementation that the CPU supports, on real images.

The images are from the CommandLineTests repo. Their widths cover every remainder mod 4, so the test also checks the leftover pixels after the SIMD loops. #1554 also changes this test file, so it will need a small merge fix.

0 test files added, 1 test file changed:

  • SerialPrograms/Source/Kernels/ImageScaleBrightness/Kernels_ImageScaleBrightness_Tests.cpp

Test results: added when the CI of this PR finishes.

🤖 Generated with Claude Code

@Mysticial

Copy link
Copy Markdown
Collaborator

Gin, can you split this up into 3 smaller PRs? One for each kernel that you're changing:

  • scale_brightness()
  • PackedBinaryMatrix::submatrix()
  • filter_rgb32_range()

@Mysticial

Copy link
Copy Markdown
Collaborator

SSE4.1, AVX2 and AVX-512 rounded each channel to the nearest integer, but Default and NEON truncate. Now all of them truncate.

Make all of them round to nearest, including the default. So instead of changing the SIMD ones, change the default to (uint8_t)(x + 0.5) or something.

I don't care if the exact 0.5 rounding behavior differs slightly between Default and SIMD. That's considered a ULP error which is generally accepted across all our kernels.

Gin and others added 2 commits October 22, 2026 21:09
The x86 SIMD versions round each channel to the nearest integer, but Default
and NEON truncated, so results on Apple Silicon were up to 1 lower per
channel. Now Default and NEON round too. At an exact .5 tie, Default rounds
up and the SIMD code rounds to even. That 1-unit difference is accepted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The old test was debug code: it was not registered, and it only timed the
implementation that the CPU dispatch picks. Now each implementation that the
build has and the CPU supports gets a test on 4 CommandLineTests images. It
checks that each channel is rounded to nearest, and accepts either value at
an exact .5 tie.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Gin890
Gin890 force-pushed the test-kernels-real-images branch from 18c1417 to 363c543 Compare October 23, 2026 04:12
@Gin890 Gin890 changed the title Make the ImageScaleBrightness, ImageFilter and BinaryMatrix kernel tests real tests Round to nearest in every scale_brightness(), and make the ImageScaleBrightness test a real test Oct 23, 2026
@Gin890

Gin890 commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

Split into three commits as suggested and changed this PR to round to nearest for image kernel tests @Mysticial

@Mysticial
Mysticial merged commit da898d1 into main Oct 23, 2026
7 checks passed
@Mysticial
Mysticial deleted the test-kernels-real-images branch October 23, 2026 06:33
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.

2 participants