1 #ifndef statparallelcalc_h 2 #define statparallelcalc_h 37 int sz,
const T* weights = 0)
39 { setValues(data,sz,weights); }
41 :
BaseCalc<T>(s) { setValues(0,0,0); }
43 inline void setValues(
const T* inp,
int sz,
const T* wght=0);
44 inline void setEmpty();
48 virtual inline double variance()
const;
56 inline bool doPrepare(
int);
58 inline bool doFinish(
bool);
94 nradded_ = 0; data_ = 0; weights_ = 0;
114 "No data given to compute statistics");
120 "Data array is empty");
124 const int nradded = nradded_;
127 variance_ = variance_w_ =0;
129 barrier_.setNrThreads( nrthreads );
147 for ( ; start<=stop &&
mIsUdf(data_[start] ); start++ )
150 int idx =
mCast(
int, start );
151 const T* dataptr = data_ + start;
152 const T* stopptr = dataptr + (stop-start+1);
158 while ( dataptr < stopptr )
170 { tmin = val; minidx = idx; }
172 { tmax = val; maxidx = idx; }
177 if ( setup_.weighted_ && weights_ )
179 dataptr = data_ + start;
180 const T* weightptr = weights_ ? weights_ + start : 0;
181 while ( dataptr < stopptr )
183 const T weight = *weightptr;
193 sum_wx += weight * val;
194 sum_wxx += weight * val * val;
198 barrier_.waitForAll(
false );
202 sum_xx_ += (T)sum_xx;
203 if ( setup_.weighted_ )
206 sum_wx_ += (T)sum_wx;
207 sum_wxx_ += (T)sum_wxx;
210 if ( (
mIsUdf(minval_) || minval_ > tmin ) && !
mIsUdf(tmin ) )
211 { minval_ = tmin; minidx_ = minidx; }
212 if ( (
mIsUdf(maxval_) || maxval_ < tmax ) && !
mIsUdf(tmax) )
213 { maxval_ = tmax; maxidx_ = maxidx; }
215 barrier_.mutex().unLock();
217 barrier_.waitForAll(
false );
221 meanval_ = sum_x_ / nrused_;
222 meanval_w_ = sum_wx_ / nrused_;
225 barrier_.mutex().unLock();
227 barrier_.waitForAll(
true );
231 if ( setup_.needvariance_ )
235 const int nrthreads = barrier_.nrThreads();
236 const int nrperthread = nradded_/nrthreads;
237 const int startidx = thread*nrperthread;
238 const int stopidx =
mMIN( startidx + nrperthread, nradded_)-1;
240 dataptr = data_ + startidx;
241 stopptr = dataptr + ( stopidx-startidx + 1 );
243 if ( setup_.weighted_ && weights_ )
245 const T* weightptr = weights_ ? weights_ + startidx : 0;
246 while ( dataptr < stopptr )
248 const T weight = *weightptr;
256 T varval = val*weight - meanval_w_;
258 tvariance_w += varval;
263 while ( dataptr < stopptr )
271 T varval = val - meanval_;
276 barrier_.waitForAll(
false );
278 variance_ += tvariance / (nrused_-1);
279 variance_w_ += tvariance_w / (nrused_-1);
281 barrier_.mutex().unLock();
291 pErrMsg(
"Undefined operation for float_complex in template");
302 if ( setup_.needmostfreq_ )
304 clss_.setSize( nrused_ );
305 clsswt_.setSize( nrused_ );
308 for (
int idx=0; idx<nradded_; idx++ )
310 const T val = data_[idx];
314 const T wt = weights_[idx];
316 int setidx = clss_.indexOf( ival );
319 { clss_[idx] = ival; clsswt_[idx] = wt; }
321 clsswt_[setidx] = wt;
325 if ( setup_.needmed_ )
327 for (
int idx=0; idx<nradded_; idx++ )
329 const T val = data_[idx];
342 pErrMsg(
"Undefined operation for float_complex in template");
350 return setup_.weighted_ ? variance_w_ : variance_ ;
357 pErrMsg(
"Undefined operation for float_complex in template");
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
const T * data_
Definition: statparallelcalc.h:64
Setup for the Stats::RunCalc and Stats::ParallelCalc objects.
Definition: statruncalc.h:38
bool doFinish(bool)
Definition: statparallelcalc.h:297
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
void clear()
Definition: statruncalc.h:292
#define mCast(tp, v)
Definition: commondefs.h:124
bool doWork(od_int64, od_int64, int)
Definition: statparallelcalc.h:136
#define od_int64
Definition: plftypes.h:36
void set(T &_to, const F &fr)
template based type conversion
Definition: convert.h:29
Definition: uistring.h:89
T variance_
Definition: statparallelcalc.h:69
Stats computation running in parallel.
Definition: statparallelcalc.h:33
od_int64 nrIterations() const
Definition: statparallelcalc.h:54
#define mMIN(x, y)
Definition: commondefs.h:49
float variance(const X &x, int sz)
Definition: simpnumer.h:288
Generalization of a task that can be run in parallel.
Definition: paralleltask.h:66
ParallelCalc(const CalcSetup &s, const T *data, int sz, const T *weights=0)
Definition: statparallelcalc.h:36
void setEmpty()
Definition: statparallelcalc.h:91
bool doPrepare(int)
Definition: statparallelcalc.h:109
void setValues(const T *inp, int sz, const T *wght=0)
Definition: statparallelcalc.h:99
const T * weights_
Definition: statparallelcalc.h:65
ParallelCalc(const CalcSetup &s)
Definition: statparallelcalc.h:40
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
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:240
Threads::Barrier barrier_
Definition: statparallelcalc.h:62
BufferString errmsg_
Definition: horizontracker.h:119
const uiString errMsg() const
Definition: statparallelcalc.h:46
Base class to calculate mean, min, max, etc.. can be used either as running values (Stats::RunCalc) o...
Definition: statruncalc.h:100
T variance_w_
Definition: statparallelcalc.h:70
Statistics.
Definition: array2dinterpol.h:28
uiString errmsg_
Definition: statparallelcalc.h:60
#define mClass(module)
Definition: commondefs.h:164
#define pErrMsg(msg)
Definition: errmsg.h:60
T meanval_w_
Definition: statparallelcalc.h:68
uiString od_static_tr(const char *function, const char *text, const char *disambiguation=0, int pluralnr=-1)
virtual double variance() const
Definition: statparallelcalc.h:348
T meanval_
Definition: statparallelcalc.h:67