35 int sz,
const T* weights = 0)
37 { setValues(data,sz,weights); }
39 :
BaseCalc<T>(s) { setValues(0,0,0); }
41 inline void setValues(
const T* inp,
int sz,
const T* wght=0);
42 inline void setEmpty();
46 virtual inline double variance()
const;
54 inline bool doPrepare(
int);
56 inline bool doFinish(
bool);
92 nradded_ = 0; data_ = 0; weights_ = 0;
112 "No data given to compute statistics");
118 "Data array is empty");
122 const int nradded = nradded_;
125 variance_ = variance_w_ =0;
127 barrier_.setNrThreads( nrthreads );
145 for ( ; start<=stop &&
mIsUdf(data_[start] ); start++ )
148 int idx =
mCast(
int, start );
149 const T* dataptr = data_ + start;
150 const T* stopptr = dataptr + (stop-start+1);
156 while ( dataptr < stopptr )
168 { tmin = val; minidx = idx; }
170 { tmax = val; maxidx = idx; }
175 if ( setup_.weighted_ && weights_ )
177 dataptr = data_ + start;
178 const T* weightptr = weights_ ? weights_ + start : 0;
179 while ( dataptr < stopptr )
181 const T weight = *weightptr;
191 sum_wx += weight * val;
192 sum_wxx += weight * val * val;
196 barrier_.waitForAll(
false );
200 sum_xx_ += (T)sum_xx;
201 if ( setup_.weighted_ )
204 sum_wx_ += (T)sum_wx;
205 sum_wxx_ += (T)sum_wxx;
208 if ( (
mIsUdf(minval_) || minval_ > tmin ) && !
mIsUdf(tmin ) )
209 { minval_ = tmin; minidx_ = minidx; }
210 if ( (
mIsUdf(maxval_) || maxval_ < tmax ) && !
mIsUdf(tmax) )
211 { maxval_ = tmax; maxidx_ = maxidx; }
213 barrier_.mutex().unLock();
215 barrier_.waitForAll(
false );
219 meanval_ = sum_x_ / nrused_;
220 meanval_w_ = sum_wx_ / nrused_;
223 barrier_.mutex().unLock();
225 barrier_.waitForAll(
true );
229 if ( setup_.needvariance_ )
233 const int nrthreads = barrier_.nrThreads();
234 const int nrperthread = nradded_/nrthreads;
235 const int startidx = thread*nrperthread;
236 const int stopidx =
mMIN( startidx + nrperthread, nradded_)-1;
238 dataptr = data_ + startidx;
239 stopptr = dataptr + ( stopidx-startidx + 1 );
241 if ( setup_.weighted_ && weights_ )
243 const T* weightptr = weights_ ? weights_ + startidx : 0;
244 while ( dataptr < stopptr )
246 const T weight = *weightptr;
254 T varval = val*weight - meanval_w_;
256 tvariance_w += varval;
261 while ( dataptr < stopptr )
269 T varval = val - meanval_;
274 barrier_.waitForAll(
false );
276 variance_ += tvariance / (nrused_-1);
277 variance_w_ += tvariance_w / (nrused_-1);
279 barrier_.mutex().unLock();
289 pErrMsg(
"Undefined operation for float_complex in template");
300 if ( setup_.needmostfreq_ )
302 clss_.setSize( nrused_ );
303 clsswt_.setSize( nrused_ );
306 for (
int idx=0; idx<nradded_; idx++ )
308 const T val = data_[idx];
312 const T wt = weights_[idx];
314 int setidx = clss_.indexOf( ival );
317 { clss_[idx] = ival; clsswt_[idx] = wt; }
319 clsswt_[setidx] = wt;
323 if ( setup_.needmed_ )
325 for (
int idx=0; idx<nradded_; idx++ )
327 const T val = data_[idx];
340 pErrMsg(
"Undefined operation for float_complex in template");
348 return setup_.weighted_ ? variance_w_ : variance_ ;
355 pErrMsg(
"Undefined operation for float_complex in template");
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:285
const T * data_
Definition: statparallelcalc.h:62
Setup for the Stats::RunCalc and Stats::ParallelCalc objects.
Definition: statruncalc.h:35
bool doFinish(bool)
Definition: statparallelcalc.h:295
#define mODTextTranslationClass(clss)
Definition: uistring.h:37
void clear()
Definition: statruncalc.h:289
#define mCast(tp, v)
Definition: commondefs.h:120
bool doWork(od_int64, od_int64, int)
Definition: statparallelcalc.h:134
#define od_int64
Definition: plftypes.h:34
void set(T &_to, const F &fr)
template based type conversion
Definition: convert.h:27
Definition: uistring.h:88
T variance_
Definition: statparallelcalc.h:67
Stats computation running in parallel.
Definition: statparallelcalc.h:31
od_int64 nrIterations() const
Definition: statparallelcalc.h:52
#define mMIN(x, y)
Definition: commondefs.h:52
float variance(const X &x, int sz)
Definition: simpnumer.h:286
Generalization of a task that can be run in parallel.
Definition: paralleltask.h:64
ParallelCalc(const CalcSetup &s, const T *data, int sz, const T *weights=0)
Definition: statparallelcalc.h:34
void setEmpty()
Definition: statparallelcalc.h:89
bool doPrepare(int)
Definition: statparallelcalc.h:107
void setValues(const T *inp, int sz, const T *wght=0)
Definition: statparallelcalc.h:97
const T * weights_
Definition: statparallelcalc.h:63
ParallelCalc(const CalcSetup &s)
Definition: statparallelcalc.h:38
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:270
Waits for a number of threads to reach a certain point (i.e. the call to Barrier::waitForAll). Once everyone has arrived, everyone is released.
Definition: thread.h:244
Threads::Barrier barrier_
Definition: statparallelcalc.h:60
BufferString errmsg_
Definition: horizontracker.h:117
const uiString errMsg() const
Definition: statparallelcalc.h:44
Base class to calculate mean, min, max, etc.. can be used either as running values (Stats::RunCalc) o...
Definition: statruncalc.h:97
T variance_w_
Definition: statparallelcalc.h:68
Statistics.
Definition: array2dinterpol.h:27
uiString errmsg_
Definition: statparallelcalc.h:58
#define mClass(module)
Definition: commondefs.h:161
#define pErrMsg(msg)
Usual access point for programmer error messages.
Definition: errmsg.h:34
T meanval_w_
Definition: statparallelcalc.h:66
uiString od_static_tr(const char *function, const char *text, const char *disambiguation=0, int pluralnr=-1)
virtual double variance() const
Definition: statparallelcalc.h:346
T meanval_
Definition: statparallelcalc.h:65