Repository navigation
BUG: Produce Float64 math results for integer images - #2016
jmarquisbq wants to merge 2 commits into
Conversation
ad7051d to
c1cc6ec
Compare
There was a problem hiding this comment.
Review of PR #2016: Produce Float64 math results for integer images
Reviewed commit: c1cc6ec66, one commit on develop 8c25e4251. All 22 changed files were reviewed.
Verdict: Request Changes. The code is correct and I found no wrong result. The request is for item 1.1: I want your answer on the Float32 and Float64 difference between this PR and #2008 before this merges. The rebase in item 1.2 is also needed.
Each item has a number, so you can answer "fixed 1.3, 3.1 left as is because ..." in a reply.
Labels: Blocking = must change before merge; Needs justification = needs your answer, and "it stays, because ..." is a valid answer; Optional = you may ignore it without a reply.
1. Does the PR solve the problem with good C++ practice and good design?
Yes. All five filters pass the same IntegerToFloat64Type map to preflight and to execute, so the created array and the written array cannot disagree. Float32 and Float64 input behave as before, and the ITK comparison tests still pass. Exp Negative negates after the conversion to Float64, so the minimum signed integer and unsigned values are safe.
-
1.1 Needs justification
[XXX, needs an answer]: integer input gives Float64 here and Float32 in #2008- Acos, Asin and Tan (#2008) map integer input to Float32. Exp, Exp Negative, Log, Log10 and Sqrt map integer input to Float64.
- Effect for a user: a UInt8 volume grows 8 times through Log and 4 times through Tan. Two math filters from the same group give different output types for the same input.
- The #1888 review settled that integer input gives floating-point output. It did not settle the width, and neither PR says why the two families differ.
- Question: why is the output Float64 for these five filters and Float32 for the three trigonometric filters? Should the two families use the same type? If the difference stays, please state the reason in the PR description and in the help pages.
-
1.2 Blocking for merge, not for the code: rebase after #2008 merges
- This PR carries its own copies of the shared files of #2008. Two of them differ from the current head of #2008 (
1c2f2a424), so the rebase will conflict:src/simplnx/Utilities/ImageProcessing/TerminalImageConversion.hpphas an extraNOLINTNEXTLINEline here.src/simplnx/Utilities/ImageProcessing/ImageProcessingConstants.hppaddsIntegerToFloat64Typeat the place where #2008 addsIntegerToFloat32Type.
- The PR description says the prerequisite files are byte-identical to #2008. That is no longer true. Please correct the description after the rebase.
- The direct test of
NarrowFloatingImageValue(test/ImageNumericContractsTest.cpp) arrives with #2008, so the merge order in the description must hold. - CI must be green on the rebased head before approval.
- This PR carries its own copies of the shared files of #2008. Two of them differ from the current head of #2008 (
-
1.3 Optional: the new test namespace and its lint comments
src/Plugins/NXImageProcessing/test/Float64MathConsumerTest.hpp:5opensnx::core::UnitTest, and its comment says that it reopens the shared test namespace. The shared namespace ondevelopisnx::core::unit_test. NoUnitTestnamespace exists there.- The
NOLINTon that line and theNOLINTNEXTLINEinTerminalImageConversion.hpp:9suppress nothing:.clang-tidyondevelopignores namespace names (NamespaceIgnoredRegexp: .*). - Fix: declare the helper in
nx::core::unit_testand remove both comments. The matching change is needed in BlueQuartzSoftware/SimplnxOoc#61.
2. Error handling and defensive programming
No findings. The change adds no failure branch, so it needs no new error code. Domain results (negative infinity for the logarithm of zero, NaN for the root of a negative value) follow IEEE arithmetic. This agrees with the knowledge base rule for element-wise results and with #2002. The Float32 narrowing uses the helper from #2008.
3. Does the PR go beyond the issue?
No. The copies of the #2008 header, CMake line and test helper are explained in the description, and the rebase removes them.
- 3.1 Optional: location of the consumer test
- The test of all five filters through thresholding and component labeling is in
ExpNegativeImageFilterTest.cppand has only the[ExpNegativeImageFilter]filter tag. A run that selectsLogImageFilter, for example, does not include it. - Fix: move it to a file with a neutral name, or add the tags of all five filters.
- The test of all five filters through thresholding and component labeling is in
4. Behavior change and documentation
The five help pages are updated and agree with the code. The Log figure agrees with its data: each gray level in both panels matches the 0 to 4 scale. The Radiography Intensity Calibration pipeline does use all five filters.
-
4.1 Optional: memory use in the help pages
- The pages do not give the memory cost of the Float64 output. One sentence is sufficient: the output uses 8 bytes for each component, which is 8 times the size of a UInt8 input. Item 1.1 can change this number.
-
4.2 Optional: stale example in the knowledge base
docs/Coding_Knowledge_Base.md, entry "Write floating-point output through a saturating cast", still namesExpImageFilterandLogImageFilteras filters that cast straight to integer output. #2008 updates that sentence forTanImageFilter. After the rebase, please update it for these filters also.
Evidence
| Check | Result |
|---|---|
| Local build, macOS arm64 Release, full tree | Passed |
ctest -R "NXImageProcessing::(Exp|ExpNegative|Log|Log10|Sqrt)ImageFilter" -j 1 |
72 of 72 passed |
| Expected values in the tests | Independent. I calculated the logarithm, root and exponential constants separately, and they agree. |
| Test fails without the fix | By inspection only. develop returns the input type, and the preflight assertion requires Float64. I did not run the tests on develop. |
CI on c1cc6ec66 |
Passed: clang-format, clang-tidy, and Azure on Linux, Windows and macOS |
| Out-of-core | Not run by me. It needs BlueQuartzSoftware/SimplnxOoc#61. |
| Debug build, local clang-format and clang-tidy | Not run by me |
* COMP: Carry the shared conversion prerequisites from simplnx BlueQuartzSoftware#2008 * BUG: Produce Float64 math results for integer images
Document the output width and storage cost. Update the shared math consumer test and its selection for each covered filter. Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
c1cc6ec to
d4f0188
Compare
|
@imikejackson, the review updates are published. Review 1.1 — Float64 math and Float32 trig. I kept the five filters on Float64 for integer input. For example, Float64 keeps 1.2 — Rebase after #2008. The public PR is rebased onto simplnx 1.3 — Shared test namespace and lint comments. The declaration, definition, and both callers use 3.1 — Consumer test selection. Both shared cases carry all five filter tags and name all five filters in their registered test names. A CTest search for any of those filter names includes the consumer case. 4.1 — Output storage. The five help pages give the Float64 cost of 8 bytes per component and the eightfold storage for UInt8 input. 4.2 — Knowledge base. The saturating-cast example now names Exp and Log as historical integer-output cases and states their current promotion, alongside Tan. On the published pair |
imikejackson
left a comment
There was a problem hiding this comment.
Round two of PR #2016: Approve
Reviewed commit: d4f018879, the commits since round one at c1cc6ec66.
Verdict: Approve. Every item from round one is resolved. The approval holds when Azure CI on d4f018879 passes. A failing CI blocks the merge in any case.
- 1.1 Answer accepted. Float64 keeps
exp(100)finite andexp(-120)nonzero, where Float32 gives infinity and zero. Log, Log10 and Sqrt share the policy of the exponential filters. All five help pages and the description state the difference from Acos, Asin and Tan. - 1.2 Rebased onto
developwith #2008. The copied header, CMake line and test helper are gone, and the code uses the mergedimage_processinghelpers. The description is corrected. - 1.3 The helper is in
nx::core::unit_test, and the unneeded suppressions are removed. - 3.1 The consumer test carries the names and tags of all five filters.
- 4.1 All five help pages give the Float64 storage cost.
- 4.2 The knowledge base example is updated.
Evidence
| Check | Result |
|---|---|
Range-diff of the rebased commit against c1cc6ec66 |
Only the prerequisite copies removed and the namespace rename to image_processing |
Review commit d4f018879 |
Help pages, knowledge base, test names and tags, and identifier names. No change to filter code |
| clang-format, clang-tidy, Azure macOS | Passed |
| Azure Linux and Windows | Running when this review was posted |
| Local build and tests in this round | Not run by me |
| Out-of-core | Not run by me. Needs BlueQuartzSoftware/SimplnxOoc#61 |
Merge order. #2008 has merged. Merge this change before BlueQuartzSoftware/SimplnxOoc#61.
Summary
Exp, Exp Negative, Log, Log10 and Sqrt now produce Float64 arrays for integer input. Each filter keeps Float32 input as Float32 and Float64 input as Float64. Preflight and execution use the same element type, tuple dimensions and component dimensions.
An integer input of 2 gives approximately 0.693147 in Log and 1.414214 in Sqrt. Previously saved pipelines retain their parameter settings. An integer-only downstream filter may need an explicit conversion, and thresholds tuned to quantized values may need adjustment. A Float64 output uses eight bytes per component before storage metadata or compression. 20 files changed, including 1 binary image. Text changes total +1354 / −44 lines.
Related PRs
Design
Integer input uses Float64 for these five filters. Float64 keeps
exp(100)finite andexp(-120)nonzero. Float32 rounds those values to infinity and zero, respectively. Log, Log10, and Sqrt retain the precision of their Float64 computation and share the same output type with the exponential filters. Acos, Asin, and Tan keep their existing Float32 output for integer input, which uses 4 bytes per component. These five filters use 8 bytes per component. Floating-point inputs keep their original output type in both groups.Compute each image component in Float64, then round to its selected output type with the same helper used for Tan. This preserves fractional results on integer inputs and shares one Float32 narrowing rule. A 64-bit input beyond 2^53 in magnitude can round when converted to Float64. Exp Negative converts its input before negation, including for the minimum signed integer.
The Float32 overflow-midpoint tests and mixed-type first-transfer checks live with their first consumer in simplnx #2008. They address review items 1.6 and 5.1.
The Log guide now shows a UInt8 input beside the saved Float64 output from the actual filter. The two panels use a common grayscale scale. Domain results, including negative infinity at zero in Log and Log10 and NaN for a negative Sqrt input, follow floating-point arithmetic. Any future policy for issuing warnings about nonfinite data is tracked in simplnx #2002.
Test plan
Verified on simplnx
d4f018879with SimplnxOocc753d9b2eand DREAM3D-NX209d77790.Earlier checks and review ledger
-O0 -g1with noNDEBUG.Earlier review ledger
Body checked at:
ad7051d6bdbfb59d2c9effaf45d5f3de7abf41ebOriginal size: eight production/build files and 108 changed production lines, excluding documentation and tests. The full public and private changes were reviewed together. Risk comes from the output element type and its downstream consumers.
Finder tier: strongest available
Verifier: same family
Problem: #1874, ExpImageFilter#1, ExpNegativeImageFilter#1, LogImageFilter#1, Log10ImageFilter#1 and SqrtImageFilter#1. Writing an integer result lost fractional values and could require an invalid numeric conversion.
Parts and design (C2, C3): The five filters use one type map for preflight and execution. The pointwise engine already handles mixed input and output types. Each filter computes its own mathematical operation. The conversion and shared test helper are byte-identical to the named #2008 prerequisite. The grouped tests follow the values into downstream threshold and labeling filters.
Related Issue
Related to #1874