 |
OpendTect
6.6
|
Go to the documentation of this file.
42 size_type sz,
const T* weights = 0)
44 { setValues(data,sz,weights); }
46 :
BaseCalc<T>(s) { setValues(0,0,0); }
66 virtual const T*
sort(idx_type* index_of_median =
nullptr);
72 const T* data_ =
nullptr;
73 const T* weights_ =
nullptr;
74 bool* udfarr_ =
nullptr;
103 nradded_ = 0; data_ =
nullptr; weights_ =
nullptr;
124 errmsg_ = tr(
"No data given to compute statistics");
129 errmsg_ = tr(
"Data array is empty");
133 const size_type nradded = nradded_;
136 meanval_ = meanval_w_ = 0.;
137 variance_ = variance_w_ = 0.;
146 barrier_.setNrThreads( nrthreads );
164 bool* udfptr = udfarr_ + start;
165 for ( ; start<=stop &&
mIsUdf(data_[start] ); start++ )
168 idx_type idx = start;
169 const T* dataptr = data_ + start;
170 const T* stopptr = dataptr + (stop-start+1);
176 while ( dataptr < stopptr )
187 { tmin = val; minidx = idx; }
189 { tmax = val; maxidx = idx; }
194 if ( setup_.weighted_ && weights_ )
196 dataptr = data_ + start;
197 udfptr = udfarr_ + start;
198 const T* weightptr = weights_ ? weights_ + start : 0;
199 while ( dataptr < stopptr )
201 const T weight = *weightptr;
211 sum_wx += weight * val;
212 sum_wxx += weight * val * val;
216 barrier_.waitForAll(
false );
220 sum_xx_ += (T)sum_xx;
221 if ( setup_.weighted_ )
224 sum_wx_ += (T)sum_wx;
225 sum_wxx_ += (T)sum_wxx;
228 if ( (
mIsUdf(minval_) || minval_ > tmin ) && !
mIsUdf(tmin ) )
229 { minval_ = tmin; minidx_ = minidx; }
230 if ( (
mIsUdf(maxval_) || maxval_ < tmax ) && !
mIsUdf(tmax) )
231 { maxval_ = tmax; maxidx_ = maxidx; }
233 barrier_.mutex().unLock();
235 barrier_.waitForAll(
false );
239 meanval_ = sum_x_ / nrused_;
240 meanval_w_ = sum_wx_ / nrused_;
243 barrier_.mutex().unLock();
245 barrier_.waitForAll(
true );
248 if ( setup_.needvariance_ )
252 const int nrthreads = barrier_.nrThreads();
253 const int nrperthread = nradded_/nrthreads;
254 const idx_type startidx = thread*nrperthread;
255 const idx_type stopidx =
mMIN( startidx + nrperthread, nradded_)-1;
257 dataptr = data_ + startidx;
258 stopptr = dataptr + ( stopidx-startidx + 1 );
259 udfptr = udfarr_ + startidx;
261 if ( setup_.weighted_ && weights_ )
263 const T* weightptr = weights_ ? weights_ + startidx : 0;
264 while ( dataptr < stopptr )
266 const T weight = *weightptr++;
271 T varval = val*weight - meanval_w_;
273 tvariance_w += varval;
278 while ( dataptr < stopptr )
284 T varval = val - meanval_;
289 barrier_.waitForAll(
false );
291 variance_ += tvariance / (nrused_-1);
292 variance_w_ += tvariance_w / (nrused_-1);
294 barrier_.mutex().unLock();
304 pErrMsg(
"Undefined operation for float_complex in template");
315 if ( setup_.needmostfreq_ )
317 clss_.setSize( nrused_ );
318 clsswt_.setSize( nrused_ );
321 const bool* udfptr = udfarr_;
322 for ( idx_type idx=0; idx<nradded_; idx++ )
327 const T val = data_[idx];
328 const T wt = weights_[idx];
330 idx_type setidx = clss_.indexOf( ival );
333 { clss_[idx] = ival; clsswt_[idx] = wt; }
335 clsswt_[setidx] = wt;
339 if ( setup_.needmed_ || setup_.needsorted_ )
341 medvals_.setSize( nrused_,
mUdf(
float) );
342 T* medvalsarr = medvals_.arr();
343 const bool* udfptr = udfarr_;
344 for ( idx_type idx=0; idx<nradded_; idx++ )
349 *medvalsarr++ = data_[idx];
360 pErrMsg(
"Undefined operation for float_complex in template");
365 template <
class T>
inline
404 pErrMsg(
"Undefined operation for float_complex in template");
412 return setup_.weighted_ ? variance_w_ : variance_ ;
419 pErrMsg(
"Undefined operation for float_complex in template");
virtual double variance() const
Definition: statparallelcalc.h:410
ParallelCalc(const CalcSetup &s, const T *data, size_type sz, const T *weights=0)
Definition: statparallelcalc.h:41
T variance_w_
Definition: statparallelcalc.h:79
std::complex< float > float_complex
Definition: odcomplex.h:17
const uiString errMsg() const
Definition: statparallelcalc.h:52
bool doPrepare(int)
Definition: statparallelcalc.h:120
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:289
#define od_int64
Definition: plftypes.h:35
T meanval_
Definition: statparallelcalc.h:76
void clear()
Definition: statruncalc.h:317
Base class to calculate mean, min, max, etc.. can be used either as running values (Stats::RunCalc) o...
Definition: statruncalc.h:108
virtual const T * sort(idx_type *index_of_median=nullptr)
Definition: statruncalc.h:502
Threads::Barrier barrier_
Definition: statparallelcalc.h:70
static uiString phrCannotAllocateMemory(int64_t reqsz=-1)
mODTextTranslationClass(ParallelCalc)
bool doFinish(bool)
Definition: statparallelcalc.h:310
void deleteAndZeroPtr(T *&ptr, bool isowner=true)
Definition: ptrman.h:27
od_int64 nrIterations() const
Definition: statparallelcalc.h:60
bool doWork(od_int64, od_int64, int)
Definition: statparallelcalc.h:153
void setEmpty()
Definition: statparallelcalc.h:100
Stats computation running in parallel.
Definition: statparallelcalc.h:35
#define mClass(module)
Definition: commondefs.h:181
T variance_
Definition: statparallelcalc.h:78
#define mTryAlloc(var, stmt)
Catches bad_alloc and sets ptr to null as normal.
Definition: commondefs.h:246
mUseType(CalcSetup, size_type)
#define pErrMsg(msg)
Usual access point for programmer error messages.
Definition: errmsg.h:37
void set(T &_to, const F &fr)
template based type conversion
Definition: convert.h:27
mUseType(CalcSetup, idx_type)
Generalization of a task that can be run in parallel.
Definition: paralleltask.h:66
ParallelCalc(const CalcSetup &s)
Definition: statparallelcalc.h:45
Waits for a number of threads to reach a certain point (i.e. the call to Barrier::waitForAll)....
Definition: thread.h:239
String that is able to hold international (UTF-8) strings for the user interface.
Definition: uistring.h:121
#define mMIN(x, y)
Definition: commondefs.h:62
BufferString errmsg_
Definition: horizontracker.h:118
Setup for the Stats::RunCalc and Stats::ParallelCalc objects.
Definition: statruncalc.h:38
void setValues(const T *inp, size_type sz, const T *wght=0)
Definition: statparallelcalc.h:109
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:274
Statistics.
Definition: array2dinterpol.h:27
uiString errmsg_
Definition: statparallelcalc.h:68
virtual const T * sort(idx_type *index_of_median=nullptr)
Definition: statparallelcalc.h:366
T meanval_w_
Definition: statparallelcalc.h:77
Generated at
for the OpendTect
seismic interpretation project.
Copyright (C): dGB Beheer B.V. 1995-2021