STYLE: Replace static_cast<T>(X) with T{ X } for any "all caps" X#5337
Conversation
|
/azp run ITK.Linux |
|
Interesting, thanks @dzenanz! This is exactly the purpose of More interestingly, it appears that I think it would be better to avoid |
| { | ||
| auto randMax = static_cast<float>(RAND_MAX); | ||
| auto randMax = float{ RAND_MAX }; | ||
| const PixelType pixel(static_cast<float>(rand()) / randMax, static_cast<float>(rand()) / randMax); |
There was a problem hiding this comment.
It does not look like anything is done with the value of the image before it is filled below. Maybe just use double, and then after division it can be reduced to float. I don't think it useful to working about system differences here.
There was a problem hiding this comment.
Thanks @blowekamp but for now I just reverted back to static_cast<float>(RAND_MAX). Eventually I think we just shouldn't use the old rand() and RAND_MAX anymore. But that's for later 😺
There was a problem hiding this comment.
I don't think this code block is a productive test. I question the usefulness of making it beautiful portable modern C++. Time may be better spent writing a replacement test.
There was a problem hiding this comment.
I don't think this code block is a productive test. I question the usefulness of making it beautiful portable modern C++. Time may be better spent writing a replacement test.
Well, I would prefer using GoogleTest, of course. But can you please be more specific on why you think the code block is not productive?
There was a problem hiding this comment.
It appears that the initial commit 75fd707 ("ENH: Added complex conjugate adaptor", Oct 26, 2011) already did so: first set a random number value for each pixel in the image, then fill the entire image buffer with PixelType( 2.0, -3.7 ):
Is that why you don't think it's a productive test?
There was a problem hiding this comment.
Yes. The values are set and nothing is done with them. I suspect the initial test may have been with the random data, but it didn't work out.
There was a problem hiding this comment.
While I think the test should work fine with arbitrary random input data, right?
@cquammen Hi Cory! Hope you're fine! We're just discussing your code from almost 14 years ago, I think 😃 I'm wondering, do you still remember why the ComplexConjugateImageAdaptor test first iteratively set the pixels of the image to random values, when it did image->FillBuffer directly afterwards anyway? What could have been the intention?
There was a problem hiding this comment.
Most likely an incomplete change in my testing methodology :-) Feel free to remove.
Replaced `static_cast<(\w+)>\(([A-Z_][A-Z_]+)\)` with `$1{ $2 }`, using regular
expressions. According to common C++ naming conventions, these all "all caps"
identifiers refer to constants, specified by preprocessor macro's, so these
conversions are evaluated at compile-time.
Excluded replacing `static_cast<float>(RAND_MAX)` (as encountered in
"itkComplexConjugateImageAdaptorTest.cxx") because this conversion is narrowing
on some platforms. Specifically, on GCC `RAND_MAX` may be 2147483647, while it
is only 32767 on MSVC2022.
- Follow-up to pull request InsightSoftwareConsortium#5324
commit 31859d3
"STYLE: Replace `static_cast<T>(Dimension)` with `T{ Dimension }`"
a7a146e to
5730a69
Compare
|
/azp run ITK.Linux |
1 similar comment
|
/azp run ITK.Linux |
Removed the `image->FillBuffer` call from this test, as it appeared to make the randomization of input pixel values useless. As noticed by Bradley Lowekamp at InsightSoftwareConsortium#5337 (comment) Cory Quammen (who originally wrote the test) also suggested removing this line of code.
|
/azp run ITK.Linux |
|
@dzenanz @thewtex Do you have any clue why the CI is broken? It says: |
|
I don't know either. |
That is a file I uploading related to DICOM and HTJ2K encoding. So it should be on the interplanetary filesystem? Maybe the problematic file can be manually uploaded to Kitware's data repo? |
|
@thewtex https://content-link-upload.itk.org/ seems to have dumbed up again. Alt link takes long to load, and has nearly no content. |
I manually uploaded it. /azp run ITK.Linux
Kitware has recommended not to use data.kitware.com, which may be taken offline.
I'll address this. |
|
/azp run ITK.Linux |
|
@thewtex I am seeing this issue on the nightly dashboard too: https://open.cdash.org/viewBuildError.php?buildid=10385473 |
|
@blowekamp thanks for the note. I added all your recent additions to the GitHub Pages resource: |
|
/azp run ITK.Linux |
1 similar comment
|
/azp run ITK.Linux |
Removed the `image->FillBuffer` call from this test, as it appeared to make the randomization of input pixel values useless. As noticed by Bradley Lowekamp at #5337 (comment) Cory Quammen (who originally wrote the test) also suggested removing this line of code.
|
A number of major updates were made, and it is now available at https://content-link-upload.netlify.app, and https://content-link-upload.itk.org/ will be available soon following a DNS fix. |
Replaced
static_cast<(\w+)>\(([A-Z_][A-Z_]+)\)with$1{ $2 }. According to common C++ naming conventions, these all "all caps" identifiers refer to constants, specified by preprocessor macro's, so these conversions are evaluated at compile-time.static_cast<T>(Dimension)withT{ Dimension }#5324 commit 31859d3