fix: use fabsf() consistently for float symmetry checks - #238
fix: use fabsf() consistently for float symmetry checks#238andrewwhitecdw wants to merge 1 commit into
Conversation
|
👋 Thank you for your contribution! This pull request is from a forked repository so GitHub Actions will not be able to run CI. A maintainer will review your changes shortly and manually trigger the CI. @maintainers Please review this PR when you have a chance and follow the instructions in the CONTRIBUTING.md file to trigger the CI. |
|
/ok to test a96f6f0 |
❌ Git Signature Check FailedFound 1 unsigned commit(s): Unsigned commits
How to fix:
|
robobryce
left a comment
There was a problem hiding this comment.
Changes requested for the format regression below. The floating-point change also needs to be applied consistently to the code the notebooks generate and to the closely related row-symmetry examples, rather than only to one linked solution.
Separately, the required git-signature check currently fails because commit 5a641d4 is unsigned.
| if (abs(temp(row, column) - temp(temp.extent(0) - 1 - row, column)) > 0.1) { | ||
| printf("Error: asymmetry in %d / %d\n", column, temp.extent(1)); | ||
| if (fabsf(temp(row, column) - temp(temp.extent(0) - 1 - row, column)) > 0.1) { | ||
| printf("Error: asymmetry in %d / %zu\n", column, temp.extent(1)); |
There was a problem hiding this comment.
temperature_grid_f is declared as cuda::std::mdspan<float, cuda::std::dextents<int, 2>> in Sources/ach.cuh, so its index_type—and therefore the return type of temp.extent(1)—is int, not size_t. %zu expects a size_t; passing an int through variadic printf is a format/argument mismatch and undefined behavior. Please retain %d here (or explicitly cast to size_t, though that is unnecessary).
|
|
||
| if (abs(temp(row, column) - temp(temp.extent(0) - 1 - row, column)) > 0.1) { | ||
| printf("Error: asymmetry in %d / %d\n", column, temp.extent(1)); | ||
| if (fabsf(temp(row, column) - temp(temp.extent(0) - 1 - row, column)) > 0.1) { |
There was a problem hiding this comment.
Please apply this correctness fix to the code learners actually generate and to the related examples as well. 03.02.02-Exercise-Symmetry.ipynb still emits abs(...) in all three symmetry-check code cells, while Solutions/row-symmetry-check.cpp, Sources/row-symmetry-check-assertions.cpp, and the fixed-code cell in 03.02.04-Dev-Tools.ipynb retain the same expression. As written, the exercise continues teaching/executing the form this PR says is incorrect, and the linked solution silently differs. Keep the extent format as %d in those locations because the mdspan index type is int.
a96f6f0 to
642490d
Compare
642490d to
0e915f1
Compare
The review pointed out that temp.extent(1) returns int because the mdspan index type is int, so the original %zu change was a format/argument mismatch. Revert to %d and apply fabsf() across all symmetry-check examples, starter sources, row-symmetry sources/solutions, and the Dev-Tools fixed-code cell. Signed-off-by: Andrew White <andrewh@cdw.com>
|
👋 Thank you for your contribution! This pull request is from a forked repository so GitHub Actions will not be able to run CI. A maintainer will review your changes shortly and manually trigger the CI. @maintainers Please review this PR when you have a chance and follow the instructions in the CONTRIBUTING.md file to trigger the CI. |
Use
fabsf()instead ofabs()for the floating-point symmetry difference in all learner-facing locations.abs()selects the integer overload, which truncates/rounds the float before comparing it against the 0.1 threshold. That can hide real asymmetry or report false positives.The format specifier stays
%deverywhere becausetemperature_grid_fusescuda::std::dextents<int, 2>, sotemp.extent(1)returnsint, notsize_t.Files updated:
Solutions/symmetry-check.cppSources/symmetry-check.cppSolutions/row-symmetry-check.cppSources/row-symmetry-check.cppSources/row-symmetry-check-assertions.cppSources/row-symmetry-check-fixed.cpp03.02.02-Exercise-Symmetry.ipynb03.02.03-Exercise-Row-Symmetry.ipynb03.02.04-Dev-Tools.ipynb