@@ -70,45 +70,45 @@ enum class Status { SUCCESS = 0, FAIL = 1 };
70
70
*/
71
71
class RootCounts {
72
72
private:
73
- static constexpr int nbins_{15 };
73
+ static constexpr std:: size_t nbins_{15 };
74
74
mutable Real counts_[nbins_];
75
75
76
76
public:
77
77
PORTABLE_INLINE_FUNCTION
78
78
RootCounts () {
79
- for (int i{0 }; i < nbins_; ++i)
79
+ for (std:: size_t i{0 }; i < nbins_; ++i)
80
80
counts_[i] = 0 ;
81
81
}
82
82
PORTABLE_INLINE_FUNCTION void reset () {
83
- for (int i{0 }; i < nbins_; ++i)
83
+ for (std:: size_t i{0 }; i < nbins_; ++i)
84
84
counts_[i] = 0 ;
85
85
}
86
- PORTABLE_INLINE_FUNCTION void increment (int i) const {
86
+ PORTABLE_INLINE_FUNCTION void increment (std:: size_t i) const {
87
87
assert (i < nbins_ && i >= 0 );
88
88
#ifdef PORTABILITY_STRATEGY_NONE
89
89
counts_[i] += 1 ;
90
90
#endif // PORTABILITY_STRATEGY_NONE
91
91
}
92
92
PORTABLE_INLINE_FUNCTION Real total () const {
93
93
Real tot{1 .e -20 };
94
- for (int i{0 }; i < nbins_; ++i)
94
+ for (std:: size_t i{0 }; i < nbins_; ++i)
95
95
tot += counts_[i];
96
96
return tot;
97
97
}
98
- PORTABLE_INLINE_FUNCTION const Real &operator [](const int i) const {
98
+ PORTABLE_INLINE_FUNCTION const Real &operator [](const std:: size_t i) const {
99
99
assert (i < nbins_ && i >= 0 );
100
100
return counts_[i];
101
101
}
102
- PORTABLE_INLINE_FUNCTION Real &operator [](const int i) {
102
+ PORTABLE_INLINE_FUNCTION Real &operator [](const std:: size_t i) {
103
103
assert (i < nbins_ && i >= 0 );
104
104
return counts_[i];
105
105
}
106
106
PORTABLE_INLINE_FUNCTION void print_counts () const {
107
- for (int i{0 }; i < nbins_; ++i)
107
+ for (std:: size_t i{0 }; i < nbins_; ++i)
108
108
printf (" %e\n " , counts_[i]);
109
109
}
110
- PORTABLE_INLINE_FUNCTION int nBins () const { return nbins_; }
111
- PORTABLE_INLINE_FUNCTION int more () const { return nbins_ - 1 ; }
110
+ PORTABLE_INLINE_FUNCTION std:: size_t nBins () const { return nbins_; }
111
+ PORTABLE_INLINE_FUNCTION std:: size_t more () const { return nbins_ - 1 ; }
112
112
};
113
113
114
114
PORTABLE_INLINE_FUNCTION bool check_bracket (const Real ya, const Real yb) {
@@ -119,11 +119,11 @@ template <typename T>
119
119
PORTABLE_INLINE_FUNCTION bool set_bracket (const T &f, Real &a, const Real guess, Real &b,
120
120
Real &ya, const Real yg, Real &yb,
121
121
const bool &verbose = false ) {
122
- constexpr int max_search_depth = 6 ;
122
+ constexpr std:: size_t max_search_depth = 6 ;
123
123
Real dx = b - a;
124
- for (int level = 0 ; level < max_search_depth; level++) {
125
- const int nlev = (1 << level);
126
- for (int i = 0 ; i < nlev; i++) {
124
+ for (std:: size_t level = 0 ; level < max_search_depth; level++) {
125
+ const std:: size_t nlev = (1 << level);
126
+ for (std:: size_t i = 0 ; i < nlev; i++) {
127
127
const Real x = a + (i + 0.5 ) * dx;
128
128
const Real yx = f (x);
129
129
if (check_bracket (yx, yg)) {
@@ -158,7 +158,7 @@ PORTABLE_INLINE_FUNCTION Status regula_falsi(const T &f, const Real ytarget,
158
158
Real &xroot,
159
159
const RootCounts *counts = nullptr ,
160
160
const bool &verbose = false ) {
161
- constexpr int max_iter = SECANT_NITER_MAX;
161
+ constexpr std:: size_t max_iter = SECANT_NITER_MAX;
162
162
auto func = [&](const Real x) { return f (x) - ytarget; };
163
163
Real ya = func (a);
164
164
Real yg = func (guess);
@@ -187,9 +187,9 @@ PORTABLE_INLINE_FUNCTION Status regula_falsi(const T &f, const Real ytarget,
187
187
ya *= sign;
188
188
yb *= sign;
189
189
190
- int b1 = 0 ;
191
- int b2 = 0 ;
192
- int iteration_count = 0 ;
190
+ std:: size_t b1 = 0 ;
191
+ std:: size_t b2 = 0 ;
192
+ std:: size_t iteration_count = 0 ;
193
193
while (b - a > 2.0 * xtol && (std::abs (ya) > ytol || std::abs (yb) > ytol) &&
194
194
iteration_count < max_iter) {
195
195
Real c = (a * yb - b * ya) / (yb - ya);
@@ -251,15 +251,15 @@ PORTABLE_INLINE_FUNCTION Status newton_raphson(const T &f, const Real ytarget,
251
251
const bool &verbose = false ,
252
252
const bool &fail_on_bound_root = true ) {
253
253
254
- constexpr int max_iter = NEWTON_RAPHSON_NITER_MAX;
254
+ constexpr std:: size_t max_iter = NEWTON_RAPHSON_NITER_MAX;
255
255
Real _x = guess;
256
256
Real _xold = 0.0 ;
257
257
auto status = Status::SUCCESS;
258
258
259
259
Real yg;
260
260
Real dfunc;
261
261
262
- int iter;
262
+ std:: size_t iter;
263
263
264
264
for (iter = 0 ; iter < max_iter; iter++) {
265
265
std::tie (yg, dfunc) = f (_x); // C++11 tuple unpacking
@@ -383,7 +383,7 @@ PORTABLE_INLINE_FUNCTION Status secant(const T &f, const Real ytarget, const Rea
383
383
Real x_last, y, yp, ym, dyNum, dyDen, dy;
384
384
385
385
Real x = xguess;
386
- unsigned int iter{0 };
386
+ std:: size_t iter{0 };
387
387
for (iter = 0 ; iter < SECANT_NITER_MAX; ++iter) {
388
388
x_last = x;
389
389
dx = fabs (1 .e -7 * x) + xtol;
@@ -490,7 +490,7 @@ PORTABLE_INLINE_FUNCTION Status bisect(const T &f, const Real ytarget, const Rea
490
490
x += 2 . * xtol;
491
491
}
492
492
// do { // Try to find reasonable region for bisection
493
- for (int i{0 }; i < BISECT_REG_MAX; ++i) {
493
+ for (std:: size_t i{0 }; i < BISECT_REG_MAX; ++i) {
494
494
dx = fabs (grow * x);
495
495
xl = x - dx;
496
496
xr = x + dx;
@@ -547,10 +547,10 @@ PORTABLE_INLINE_FUNCTION Status bisect(const T &f, const Real ytarget, const Rea
547
547
" \t il = %.10e\n "
548
548
" \t ir = %.10e\n " ,
549
549
xguess, ytarget, xl, xr, fl, fr, il, ir);
550
- int nx = 300 ;
550
+ std:: size_t nx = 300 ;
551
551
Real dx = (xmax - xmin) / (nx - 1 );
552
552
fprintf (stderr, " Area map:\n x\t y\n " );
553
- for (int i = 0 ; i < nx; i++) {
553
+ for (std:: size_t i = 0 ; i < nx; i++) {
554
554
fprintf (stderr, " %.4f\t %.4e\n " , x + i * dx, f (x + i * dx));
555
555
}
556
556
#endif
@@ -559,7 +559,7 @@ PORTABLE_INLINE_FUNCTION Status bisect(const T &f, const Real ytarget, const Rea
559
559
}
560
560
}
561
561
562
- for (int i{0 }; i < BISECT_NITER_MAX; ++i) {
562
+ for (std:: size_t i{0 }; i < BISECT_NITER_MAX; ++i) {
563
563
Real xm = 0.5 * (xl + xr);
564
564
Real fm = f (xm) - ytarget;
565
565
if (fl * fm <= 0 ) {
0 commit comments