30 float& relpos,
const float eps=1e-4 )
32 int arridx = (int)farridx;
33 relpos = farridx - arridx;
35 if ( arridx==-1 &&
mIsEqual(relpos,1,1e-4) )
36 { arridx = 0; relpos = 0; }
37 else if ( arridx==arrsz-1 &&
mIsZero(relpos,1e-4) )
38 { arridx = arrsz-2; relpos = 1; }
49 template <
class T>
inline 54 if ( !val0 )
return val1;
55 if ( !val1 )
return val0;
57 while ( (val0&1)==0 && (val1&1)==0 )
68 else if ((val1 & 1) == 0)
70 else if (val0 >= val1)
71 val0 = (val0-
val1) >> 1;
73 val1 = (val1-val0) >> 1;
83 template <
class T>
inline 107 if ( val==base )
return 1;
113 if ( res )
return 1 + res;
123 while ( res<val ) res *= base;
130 iT minsz=1, iT maxsz=0 )
132 char npow = 0;
char npowextra = actsz == 1 ? 1 : 0;
136 if (
above && !npowextra && sz % 2 )
142 if ( sz<minsz ) sz = minsz;
143 if ( maxsz && sz>maxsz ) sz = maxsz;
168 inline iT
nrBlocks( iT totalsamples, iT basesize, iT overlapsize )
171 while ( totalsamples>basesize )
174 totalsamples = totalsamples - basesize + overlapsize;
197 if ( lowpos >= sz || lowpos < 0 ||
198 highpos >= sz || highpos < 0 ||
202 int pos = lowpos < highpos ? 0 : sz - 1 ;
203 int inc = lowpos < highpos ? 1 : -1 ;
205 while ( pos != lowpos )
211 int tapersz = abs( highpos - lowpos );
216 while ( pos != highpos )
218 array[pos] *= type ==
Taper::Cosine ? .5 + .5 * cos( taperfactor )
221 taperfactor += taperfactorinc;
245 {
if ( !u0 && !(um1 && u1) )
return um1 ? y1_ - y0_ : y0_ - ym1; }
247 return (y1_-ym1) * .5;
249 else if ( (um1 && u1) || (u0 && (um1 || u1)) )
250 return (y2-ym2) * .25;
251 else if ( um1 || u1 )
253 return um1 ? ((16*y1_) - 3*y2 - ym2) / 12 - y0_
254 : ((-16*ym1) + 3*ym2 + y2) / 12 + y0_;
257 return (8 * ( y1_ - ym1 ) - y2 + ym2) / 12;
263 template <
class X,
class Y,
class RT>
264 inline void getGradient(
const X& x,
const Y& y,
int sz,
int firstx,
int firsty,
265 RT* gradptr=0,
RT* interceptptr=0 )
267 RT xy_sum = 0, x_sum=0, y_sum=0, xx_sum=0;
269 for (
int idx=0; idx<sz; idx++ )
271 RT xval = x[idx+firstx];
272 RT yval = y[idx+firsty];
280 RT grad = ( sz*xy_sum - x_sum*y_sum ) / ( sz*xx_sum - x_sum*x_sum );
281 if ( gradptr ) *gradptr = grad;
283 if ( interceptptr ) *interceptptr = (y_sum - grad*x_sum)/sz;
290 if ( sz < 2 )
return mUdf(
float);
295 for (
int idx=0; idx<sz; idx++ )
303 return (sqsum - sum * sum / sz)/ (sz -1);
323 const double a2 = a*a;
324 const double q = (a2-3*b)/9;
325 const double r = (2*a2*a-9*a*b+27*c)/54;
326 const double q3 = q*q*q;
327 const double r2 = r*r;
330 const double minus_a_through_3 = -a/3;
334 const double minus_twosqrt_q = -2*
Math::Sqrt(q);
336 const double twopi =
M_2PI;
339 root0 = minus_twosqrt_q*cos(theta/3)+minus_a_through_3;
340 root1=minus_twosqrt_q*cos((theta-twopi)/3)+minus_a_through_3;
341 root2=minus_twosqrt_q*cos((theta+twopi)/3)+minus_a_through_3;
345 const double A=(r>0?-1:1)*pow(fabs(r)+
Math::Sqrt(r2-q3),1/3);
348 root0 = A+B+minus_a_through_3;
369 if (
mIsUdf(val) )
return true;
370 if ( val < -
mDefEps )
return false;
371 const int ival = (int)(val + .5);
378 const unsigned int maxclss=50,
379 const unsigned int samplesz=100 )
381 if ( sz < 1 )
return true;
382 if ( sz <= samplesz )
384 for (
int idx=0; idx<sz; idx++ )
395 for (
int idx=0; idx<samplesz; idx++ )
397 od_int64 arridx = ((1+idx) * seed) % samplesz;
411 if ( val>127 || val<-128 )
414 const int ival = (int)(val>0 ? val+.5 : val-.5);
421 const unsigned int samplesz=100 )
426 if ( sz <= samplesz )
428 for (
int idx=0; idx<sz; idx++ )
439 for (
int idx=0; idx<samplesz; idx++ )
441 od_int64 arridx = ((1+idx) * seed) % samplesz;
Definition: interpol1d.h:38
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
#define M_2PI
Definition: commondefs.h:70
bool is8BitesData(const T *vals, od_int64 sz, const unsigned int samplesz=100)
Definition: simpnumer.h:420
iT exactPower(iT val, iT base)
Definition: simpnumer.h:105
T greatestCommonDivisor(T val0, T val1)
Definition: simpnumer.h:50
Definition: i_layout.h:28
#define mIsZero(x, eps)
Definition: commondefs.h:53
#define od_int64
Definition: plftypes.h:36
#define mDefineStaticLocalObject(type, var, init)
Definition: commondefs.h:196
bool taperArray(T *array, int sz, int lowpos, int highpos, Taper::Type type)
Definition: simpnumer.h:195
Taper an indexable array from 1 to taperfactor. If lowpos is less than highpos, the samples array[0] ...
Definition: simpnumer.h:188
int nrSteps() const
Definition: ranges.h:771
void getGradient(const X &x, const Y &y, int sz, int firstx, int firsty, RT *gradptr=0, RT *interceptptr=0)
Definition: simpnumer.h:264
T sampledGradient(T ym2, T ym1, T y0_, T y1_, T y2)
Definition: simpnumer.h:237
unsigned int Abs(unsigned int i)
Definition: math2.h:80
#define mMIN(x, y)
Definition: commondefs.h:49
float variance(const X &x, int sz)
Definition: simpnumer.h:288
#define mIsEqual(x, y, eps)
Definition: commondefs.h:54
#define M_PI
Definition: commondefs.h:64
Type
Definition: simpnumer.h:190
T step
Definition: ranges.h:199
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
Interval with step.
Definition: commontypes.h:33
StepInterval< T > getCommonStepInterval(const StepInterval< T > &a, const StepInterval< T > &b)
Definition: simpnumer.h:84
iT nrBlocks(iT totalsamples, iT basesize, iT overlapsize)
Definition: simpnumer.h:168
iT nextPower2(iT nr, iT minnr, iT maxnr)
Definition: simpnumer.h:149
#define mDefEps
Definition: commondefs.h:58
iT getPow2Sz(iT actsz, const bool above=true, iT minsz=1, iT maxsz=0)
Definition: simpnumer.h:129
iT nextPower(iT val, iT base)
Definition: simpnumer.h:120
Definition: simpnumer.h:190
T start
Definition: ranges.h:92
Definition: simpnumer.h:190
bool holdsClassValues(const T *vals, od_int64 sz, const unsigned int maxclss=50, const unsigned int samplesz=100)
Definition: simpnumer.h:377
const T val1
Definition: arrayndalgo.h:1699
bool isUdf(const T &t)
Definition: undefval.h:243
int solve3DPoly(double a, double b, double c, double &root0, double &root1, double &root2)
Definition: simpnumer.h:318
iT IntPowerOf(iT i, iPOW p)
Definition: math2.h:122
#define mMAX(x, y)
Definition: commondefs.h:48
int getArrIdxPosition(const float farridx, const int arrsz, float &relpos, const float eps=1e-4)
Definition: simpnumer.h:29
bool holdsClassValue(const T val, const unsigned int maxclss=50)
Definition: simpnumer.h:367
bool isSigned8BitesValue(const T val)
Definition: simpnumer.h:409