Skip to content

Commit

Permalink
feat(modernise): replaces c-style casts with static_cast< > (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnakumarg1984 authored Jun 23, 2023
1 parent 8df0cf1 commit f35f143
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cpp/examples/forward_backward/inpainting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int main(int argc, char const **argv) {
}
// Set up random numbers for C and C++
auto const seed = std::time(0);
std::srand((unsigned int)seed);
std::srand(static_cast<unsigned int>(seed));
std::mt19937 mersenne(std::time(0));

// Initializes and sets logger (if compiled with logging)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(int argc, char const **argv) {
}
// Set up random numbers for C and C++
auto const seed = std::time(0);
std::srand((unsigned int)seed);
std::srand(static_cast<unsigned int>(seed));
std::mt19937 mersenne(std::time(0));

// Initializes and sets logger (if compiled with logging)
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/forward_backward/inpainting_joint_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(int argc, char const **argv) {
}
// Set up random numbers for C and C++
auto const seed = std::time(0);
std::srand((unsigned int)seed);
std::srand(static_cast<unsigned int>(seed));
std::mt19937 mersenne(std::time(0));

// Initializes and sets logger (if compiled with logging)
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/forward_backward/l2_inpainting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main(int argc, char const **argv) {
}
// Set up random numbers for C and C++
auto const seed = std::time(0);
std::srand((unsigned int)seed);
std::srand(static_cast<unsigned int>(seed));
std::mt19937 mersenne(std::time(0));

// Initializes and sets logger (if compiled with logging)
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/primal_dual/inpainting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(int argc, char const **argv) {
}
// Set up random numbers for C and C++
auto const seed = std::time(0);
std::srand((unsigned int)seed);
std::srand(static_cast<unsigned int>(seed));
std::mt19937 mersenne(std::time(0));

// Initializes and sets logger (if compiled with logging)
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/primal_dual/tv_inpainting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main(int argc, char const **argv) {
}
// Set up random numbers for C and C++
auto const seed = std::time(0);
std::srand((unsigned int)seed);
std::srand(static_cast<unsigned int>(seed));
std::mt19937 mersenne(std::time(0));

// Initializes and sets logger (if compiled with logging)
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/proximal_admm/inpainting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char const **argv) {
}
// Set up random numbers for C and C++
auto const seed = std::time(0);
std::srand((unsigned int)seed);
std::srand(static_cast<unsigned int>(seed));
std::mt19937 mersenne(std::time(0));

// Initializes and sets logger (if compiled with logging)
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/proximal_admm/reweighted.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main(int argc, char const **argv) {
}
// Set up random numbers for C and C++
auto const seed = std::time(0);
std::srand((unsigned int)seed);
std::srand(static_cast<unsigned int>(seed));
std::mt19937 mersenne(std::time(0));

// Initializes and sets logger (if compiled with logging)
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/sdmm/inpainting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char const **argv) {
}
// Set up random numbers for C and C++
auto const seed = std::time(0);
std::srand((unsigned int)seed);
std::srand(static_cast<unsigned int>(seed));
std::mt19937 mersenne(std::time(0));

// Initializes and sets logger (if compiled with logging)
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/sdmm/reweighted.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main(int argc, char const **argv) {
}
// Set up random numbers for C and C++
auto const seed = std::time(0);
std::srand((unsigned int)seed);
std::srand(static_cast<unsigned int>(seed));
std::mt19937 mersenne(std::time(0));

// Initializes and sets logger (if compiled with logging)
Expand Down
4 changes: 2 additions & 2 deletions cpp/sopt/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ uint32_t convert_from_greyscale(double pixel) {
auto const g = [](double p) -> uint8_t {
auto const scaled = 255e0 * p;
if (scaled < 0) return 0;
return scaled > 255 ? 255 : uint8_t(scaled);
return scaled > 255 ? 255 : static_cast<uint8_t>(scaled);
};
ptr[0] = g(pixel);
ptr[1] = g(pixel);
Expand All @@ -48,7 +48,7 @@ Image<> read_tiff(std::string const &filename) {
SOPT_LOW_LOG("- image size {}, {} ", width, height);
Image<> result = Image<>::Zero(height, width);

uint32_t *raster = (uint32_t *)_TIFFmalloc(width * height * sizeof(uint32_t));
uint32_t *raster = static_cast<uint32_t *>(_TIFFmalloc(width * height * sizeof(uint32_t)));
if (not raster) SOPT_THROW("Could not allocate memory to read file ") << filename;
if (not TIFFReadRGBAImage(tif, width, height, raster, 0))
SOPT_THROW("Could not read file ") << filename;
Expand Down
2 changes: 1 addition & 1 deletion cpp/tests/maths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ TEST_CASE("Standard deviation", "[utility]") {
sopt::t_real stddev = 0e0;
for (sopt::Vector<>::Index i(0); i < input.size(); ++i)
stddev += std::real(std::conj(input(i) - mean) * (input(i) - mean));
stddev = std::sqrt(stddev) / std::sqrt(sopt::t_real(input.size()));
stddev = std::sqrt(stddev) / std::sqrt(static_cast<sopt::t_real>(input.size()));

CHECK(std::abs(sopt::standard_deviation(input) - stddev) < 1e-8);
CHECK(std::abs(sopt::standard_deviation(input.matrix()) - stddev) < 1e-8);
Expand Down
2 changes: 1 addition & 1 deletion cpp/tests/tf_inpainting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef sopt::Image<Scalar> Image;
TEST_CASE("Inpainting"){
extern std::unique_ptr<std::mt19937_64> mersenne;
std::string const input = "cameraman256";
std::string const model_path = std::string(sopt::notinstalled::models_directory() + "/DnCNN/snr_15_model.pb/");
std::string const model_path = static_cast<std::string>(sopt::notinstalled::models_directory() + "/DnCNN/snr_15_model.pb/");

Image const image = sopt::notinstalled::read_standard_tiff(input);

Expand Down

0 comments on commit f35f143

Please sign in to comment.