Skip to content

Commit 7638e63

Browse files
src/radmeth/radmeth_utils.hcpp: removing file_progress and linting
1 parent 8a4bb12 commit 7638e63

2 files changed

Lines changed: 8 additions & 38 deletions

File tree

src/radmeth/radmeth_utils.cpp

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <sstream>
2626
#include <string>
2727

28-
// NOLINTBEGIN(*-narrowing-conversions,*-avoid-magic-numbers)
28+
// NOLINTBEGIN(*-narrowing-conversions)
2929

3030
[[nodiscard]] std::string
3131
format_duration(const std::chrono::duration<double> elapsed) {
@@ -39,32 +39,14 @@ format_duration(const std::chrono::duration<double> elapsed) {
3939
const double seconds = tot_s - (hours * s_per_h) - (minutes * s_per_m);
4040

4141
std::ostringstream oss;
42+
// NOLINTBEGIN(*-avoid-magic-numbers)
4243
oss << std::setfill('0') << std::setw(2) << hours << ":" << std::setfill('0')
4344
<< std::setw(2) << minutes << ":" << std::fixed << std::setprecision(2)
4445
<< std::setw(5) << seconds;
46+
// NOLINTEND(*-avoid-magic-numbers)
4547
return oss.str();
4648
}
4749

48-
file_progress::file_progress(const std::string &filename) :
49-
one_thousand_over_filesize{1000.0 / std::filesystem::file_size(filename)} {}
50-
51-
void
52-
file_progress::operator()(
53-
std::ifstream &in) { // cppcheck-suppress constParameterReference
54-
const std::size_t curr_offset =
55-
in.eof() ? 1000 : in.tellg() * one_thousand_over_filesize;
56-
if (curr_offset <= prev_offset)
57-
return;
58-
std::ios old_state(nullptr);
59-
old_state.copyfmt(std::cerr);
60-
std::cerr << "\r[progress: " << std::setw(5) << std::fixed
61-
<< std::setprecision(1) << (curr_offset / 10.0)
62-
<< (curr_offset == 1000 ? "%]\n" : "%]");
63-
std::cerr.copyfmt(old_state);
64-
prev_offset = (curr_offset == 1000) ? std::numeric_limits<std::size_t>::max()
65-
: curr_offset;
66-
}
67-
6850
// Series representation for the lower incomplete gamma P(a,x)
6951
[[nodiscard]] static double
7052
gamma_p_series(const double a, const double x) {
@@ -113,19 +95,15 @@ gamma_q_contfrac(const double a, const double x) {
11395
// Regularized lower incomplete gamma P(a,x)
11496
[[nodiscard]] static double
11597
gamma_p(const double a, const double x) {
116-
if (x < 0 || a <= 0)
117-
return 0.0;
118-
if (x == 0)
119-
return 0.0;
120-
if (x < a + 1.0)
121-
return gamma_p_series(a, x);
122-
return 1.0 - gamma_q_contfrac(a, x);
98+
return x <= 0.0 || a <= 0 ? 0.0
99+
: (x < a + 1.0 ? gamma_p_series(a, x)
100+
: 1.0 - gamma_q_contfrac(a, x));
123101
}
124102

125103
// chi-square CDF: P(k/2, x/2)
126104
[[nodiscard]] static double
127105
chi_square_cdf(const double x, const double k) {
128-
return gamma_p(k * 0.5, x * 0.5);
106+
return gamma_p(k / 2, x / 2);
129107
}
130108

131109
// Given the maximum likelihood estimates of the full and reduced models, the
@@ -148,4 +126,4 @@ llr_test(const double null_loglik, const double full_loglik) {
148126
return p_value;
149127
}
150128

151-
// NOLINTEND(*-narrowing-conversions,*-avoid-magic-numbers)
129+
// NOLINTEND(*-narrowing-conversions)

src/radmeth/radmeth_utils.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@
2525
[[nodiscard]] std::string
2626
format_duration(const std::chrono::duration<double> elapsed);
2727

28-
struct file_progress {
29-
double one_thousand_over_filesize{};
30-
std::size_t prev_offset{};
31-
explicit file_progress(const std::string &filename);
32-
void
33-
operator()(std::ifstream &in); // cppcheck-suppress constParameterReference
34-
};
35-
3628
[[nodiscard]] double
3729
llr_test(const double null_loglik, const double full_loglik);
3830

0 commit comments

Comments
 (0)