Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernise: replaces C-style casts with static_cast< > #374

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -49,7 +49,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