Skip to content

Commit 16bad6a

Browse files
committed
changed unsigned integer types and loop counters to size_t
1 parent 729da22 commit 16bad6a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/boot.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void mexFunction (int nlhs, mxArray* plhs[],
7070
}
7171
// First input argument (n or x)
7272
double *x = (double *) mxGetData (prhs[0]);
73-
long unsigned int n = mxGetNumberOfElements (prhs[0]);
73+
size_t n = mxGetNumberOfElements (prhs[0]);
7474
bool isvec;
7575
if ( n > 1 ) {
7676
const mwSize *sz = mxGetDimensions (prhs[0]);
@@ -83,19 +83,19 @@ void mexFunction (int nlhs, mxArray* plhs[],
8383
if ( mxIsComplex (prhs[0]) ) {
8484
mexErrMsgTxt ("The first input argument (N) cannot contain an imaginary part.");
8585
}
86-
if ( *x != static_cast<long unsigned int>(*x) ) {
86+
if ( *x != static_cast<size_t>(*x) ) {
8787
mexErrMsgTxt ("The value of the first input argument (N) must be a positive integer.");
8888
}
8989
if ( !mxIsFinite (*x) ) {
9090
mexErrMsgTxt ("The first input argument (N) cannot be NaN or Inf.");
9191
}
92-
n = static_cast<long unsigned int>(*x);
92+
n = static_cast<size_t>(*x);
9393
}
9494
if ( !mxIsClass (prhs[0], "double") ) {
9595
mexErrMsgTxt ("The first input argument (N or X) must be of type double.");
9696
}
9797
// Second input argument (nboot)
98-
const long unsigned int nboot = static_cast<const long unsigned int> ( *(mxGetPr (prhs[1])) );
98+
const size_t nboot = static_cast<size_t> ( *(mxGetPr (prhs[1])) );
9999
if ( mxGetNumberOfElements (prhs[1]) > 1 ) {
100100
mexErrMsgTxt ("The second input argument (NBOOT) must be scalar.");
101101
}
@@ -151,8 +151,8 @@ void mexFunction (int nlhs, mxArray* plhs[],
151151
plhs[0] = mxCreateNumericArray (2, dims,
152152
mxDOUBLE_CLASS,
153153
mxREAL); // Prepare array for sample indices
154-
long long unsigned int N = n * nboot; // Total counts of all sample indices
155-
long long unsigned int k; // Variable to store random number
154+
size_t N = n * nboot; // Total counts of all sample indices
155+
size_t k; // Variable to store random number
156156
long long int d; // Counter for cumulative sum calculation
157157
vector<long long int> c(n, nboot); // Counter for each of the sample indices
158158
if ( nrhs > 4 && !mxIsEmpty (prhs[4]) ) {
@@ -168,7 +168,7 @@ void mexFunction (int nlhs, mxArray* plhs[],
168168
mexErrMsgTxt ("WEIGHTS must be a vector of length N or be the same length as X.");
169169
}
170170
long long int s = 0;
171-
for ( int i = 0; i < n ; i++ ) {
171+
for ( size_t i = 0; i < n ; i++ ) {
172172
if ( !mxIsFinite (w[i]) ) {
173173
mexErrMsgTxt ("The fifth input argument (WEIGHTS) cannot contain NaN or Inf.");
174174
}
@@ -183,18 +183,18 @@ void mexFunction (int nlhs, mxArray* plhs[],
183183
}
184184
}
185185
long long int m = 0; // Counter for LOO sample index r
186-
int r = -1; // Sample index for LOO
186+
long long int r = -1; // Sample index for LOO
187187

188188
// Create pointer so that we can access elements of bootsam (i.e. plhs[0])
189189
double *ptr = (double *) mxGetData(plhs[0]);
190190

191191
// Initialize pseudo-random number generator (Mersenne Twister 19937)
192192
mt19937_64 rng (seed);
193-
uniform_int_distribution<long long unsigned int> distr (0, n - 1);
194-
uniform_int_distribution<long long unsigned int> distk (0, N - 1);
193+
uniform_int_distribution<size_t> distr (0, n - 1);
194+
uniform_int_distribution<size_t> distk (0, N - 1);
195195

196196
// Perform balanced sampling
197-
for ( int b = 0; b < nboot ; b++ ) {
197+
for ( size_t b = 0; b < nboot ; b++ ) {
198198
if ( loo == true ) {
199199
// Note that the following division operations are for integers
200200
if ( (b / n) == (nboot / n) ) {
@@ -205,7 +205,7 @@ void mexFunction (int nlhs, mxArray* plhs[],
205205
m = c[r];
206206
c[r] = 0;
207207
}
208-
for ( int i = 0; i < n ; i++ ) {
208+
for ( size_t i = 0; i < n ; i++ ) {
209209
if ( loo == true ) {
210210
// Only leave-one-out if sample index r doesn't account for all
211211
// remaining sampling counts
@@ -215,10 +215,10 @@ void mexFunction (int nlhs, mxArray* plhs[],
215215
loo = false;
216216
}
217217
}
218-
distk.param (uniform_int_distribution<long long unsigned int>::param_type (0, N - m - 1));
218+
distk.param (uniform_int_distribution<size_t>::param_type (0, N - m - 1));
219219
k = distk (rng);
220220
d = c[0];
221-
for ( int j = 0; j < n ; j++ ) {
221+
for ( size_t j = 0; j < n ; j++ ) {
222222
if ( k < d ) {
223223
if (isvec) {
224224
ptr[b * n + i] = x[j];

0 commit comments

Comments
 (0)