44
44
// corresponding index is represented in bootsam. Therefore, the sum of WEIGHTS
45
45
// should equal N * NBOOT.
46
46
//
47
- // Note that the mex function compiled from this source code is not thread-safe.
48
- // Below is an example of a line of code one can run in Octave/Matlab before
49
- // attempting parallel operation of boot.mex in order to ensure that the initial
50
- // random seeds of each thread are unique:
51
- //
52
- // In Octave:
53
- // >> pararrayfun(nproc, @boot, 1, 1, false, 1:nproc)
54
- //
55
- // In Matlab:
56
- // >> ncpus = feature('numcores'); parfor i = 1:ncpus; boot (1, 1, false, i); end;
47
+ // Compared to previous versions (in package versions <=5.6.0), the boot.mex
48
+ // function is now thread safe.
57
49
//
58
50
// Requirements: Compilation requires C++11
59
51
//
@@ -78,7 +70,7 @@ void mexFunction (int nlhs, mxArray* plhs[],
78
70
}
79
71
// First input argument (n or x)
80
72
double *x = (double *) mxGetData (prhs[0 ]);
81
- int n = mxGetNumberOfElements (prhs[0 ]); // 32-bit int
73
+ long unsigned int n = mxGetNumberOfElements (prhs[0 ]);
82
74
bool isvec;
83
75
if ( n > 1 ) {
84
76
const mwSize *sz = mxGetDimensions (prhs[0 ]);
@@ -91,19 +83,19 @@ void mexFunction (int nlhs, mxArray* plhs[],
91
83
if ( mxIsComplex (prhs[0 ]) ) {
92
84
mexErrMsgTxt (" The first input argument (N) cannot contain an imaginary part." );
93
85
}
94
- if ( *x != static_cast <int >(*x) ) {
86
+ if ( *x != static_cast <long unsigned int >(*x) ) {
95
87
mexErrMsgTxt (" The value of the first input argument (N) must be a positive integer." );
96
88
}
97
89
if ( !mxIsFinite (*x) ) {
98
90
mexErrMsgTxt (" The first input argument (N) cannot be NaN or Inf." );
99
91
}
100
- n = static_cast <int >(*x);
92
+ n = static_cast <long unsigned int >(*x);
101
93
}
102
94
if ( !mxIsClass (prhs[0 ], " double" ) ) {
103
95
mexErrMsgTxt (" The first input argument (N or X) must be of type double." );
104
96
}
105
97
// Second input argument (nboot)
106
- const int nboot = static_cast <const int > ( *(mxGetPr (prhs[1 ])) ); // 32-bit int
98
+ const long unsigned int nboot = static_cast <const long unsigned int > ( *(mxGetPr (prhs[1 ])) );
107
99
if ( mxGetNumberOfElements (prhs[1 ]) > 1 ) {
108
100
mexErrMsgTxt (" The second input argument (NBOOT) must be scalar." );
109
101
}
@@ -138,7 +130,7 @@ void mexFunction (int nlhs, mxArray* plhs[],
138
130
if ( !mxIsClass (prhs[3 ], " double" ) ) {
139
131
mexErrMsgTxt (" The fourth input argument (SEED) must be of type double." );
140
132
}
141
- seed = static_cast <unsigned long int > ( *(mxGetPr (prhs[3 ])) );
133
+ seed = static_cast <unsigned int > ( *(mxGetPr (prhs[3 ])) );
142
134
if ( !mxIsFinite (seed) ) {
143
135
mexErrMsgTxt (" The fourth input argument (SEED) cannot be NaN or Inf." );
144
136
}
@@ -161,7 +153,7 @@ void mexFunction (int nlhs, mxArray* plhs[],
161
153
mxREAL); // Prepare array for sample indices
162
154
long long unsigned int N = n * nboot; // Total counts of all sample indices
163
155
long long unsigned int k; // Variable to store random number
164
- long long unsigned int d; // Counter for cumulative sum calculation
156
+ long long int d; // Counter for cumulative sum calculation
165
157
vector<long long int > c (n, nboot); // Counter for each of the sample indices
166
158
if ( nrhs > 4 && !mxIsEmpty (prhs[4 ]) ) {
167
159
// Assign user defined weights (counts)
0 commit comments