28 float& relpos,
const float eps=1e-4 )
30 int arridx = (int)farridx;
31 relpos = farridx - arridx;
33 if ( arridx==-1 &&
mIsEqual(relpos,1,1e-4) )
34 { arridx = 0; relpos = 0; }
35 else if ( arridx==arrsz-1 &&
mIsZero(relpos,1e-4) )
36 { arridx = arrsz-2; relpos = 1; }
47 template <
class T>
inline 52 if ( !val0 )
return val1;
53 if ( !val1 )
return val0;
55 while ( (val0&1)==0 && (val1&1)==0 )
66 else if ((val1 & 1) == 0)
68 else if (val0 >= val1)
69 val0 = (val0-val1) >> 1;
71 val1 = (val1-val0) >> 1;
81 template <
class T>
inline 105 if ( val==base )
return 1;
111 if ( res )
return 1 + res;
121 while ( res<val ) res *= base;
128 iT minsz=1, iT maxsz=0 )
130 char npow = 0;
char npowextra = actsz == 1 ? 1 : 0;
134 if (
above && !npowextra && sz % 2 )
140 if ( sz<minsz ) sz = minsz;
141 if ( maxsz && sz>maxsz ) sz = maxsz;
166 inline iT
nrBlocks( iT totalsamples, iT basesize, iT overlapsize )
169 while ( totalsamples>basesize )
172 totalsamples = totalsamples - basesize + overlapsize;
195 if ( lowpos >= sz || lowpos < 0 ||
196 highpos >= sz || highpos < 0 ||
200 int pos = lowpos < highpos ? 0 : sz - 1 ;
201 int inc = lowpos < highpos ? 1 : -1 ;
203 while ( pos != lowpos )
209 int tapersz = abs( highpos - lowpos );
214 while ( pos != highpos )
216 array[pos] *= type ==
Taper::Cosine ? .5 + .5 * cos( taperfactor )
219 taperfactor += taperfactorinc;
243 {
if ( !u0 && !(um1 && u1) )
return um1 ? y1_ - y0_ : y0_ - ym1; }
245 return (y1_-ym1) * .5;
247 else if ( (um1 && u1) || (u0 && (um1 || u1)) )
248 return (y2-ym2) * .25;
249 else if ( um1 || u1 )
251 return um1 ? ((16*y1_) - 3*y2 - ym2) / 12 - y0_
252 : ((-16*ym1) + 3*ym2 + y2) / 12 + y0_;
255 return (8 * ( y1_ - ym1 ) - y2 + ym2) / 12;
261 template <
class X,
class Y,
class RT>
262 inline void getGradient(
const X& x,
const Y& y,
int sz,
int firstx,
int firsty,
263 RT* gradptr=0,
RT* interceptptr=0 )
265 RT xy_sum = 0, x_sum=0, y_sum=0, xx_sum=0;
267 for (
int idx=0; idx<sz; idx++ )
269 RT xval = x[idx+firstx];
270 RT yval = y[idx+firsty];
278 RT grad = ( sz*xy_sum - x_sum*y_sum ) / ( sz*xx_sum - x_sum*x_sum );
279 if ( gradptr ) *gradptr = grad;
281 if ( interceptptr ) *interceptptr = (y_sum - grad*x_sum)/sz;
288 if ( sz < 2 )
return mUdf(
float);
293 for (
int idx=0; idx<sz; idx++ )
301 return (sqsum - sum * sum / sz)/ (sz -1);
321 const double a2 = a*a;
322 const double q = (a2-3*b)/9;
323 const double r = (2*a2*a-9*a*b+27*c)/54;
324 const double q3 = q*q*q;
325 const double r2 = r*r;
328 const double minus_a_through_3 = -a/3;
332 const double minus_twosqrt_q = -2*
Math::Sqrt(q);
334 const double twopi =
M_2PI;
337 root0 = minus_twosqrt_q*cos(theta/3)+minus_a_through_3;
338 root1=minus_twosqrt_q*cos((theta-twopi)/3)+minus_a_through_3;
339 root2=minus_twosqrt_q*cos((theta+twopi)/3)+minus_a_through_3;
343 const double A=(r>0?-1:1)*pow(fabs(r)+
Math::Sqrt(r2-q3),1/3);
346 root0 = A+B+minus_a_through_3;
367 if (
mIsUdf(val) )
return true;
368 if ( val < -
mDefEps )
return false;
369 const int ival = (int)(val + .5);
376 const unsigned int maxclss=50,
377 const unsigned int samplesz=100 )
379 if ( sz < 1 )
return true;
380 if ( sz <= samplesz )
382 for (
int idx=0; idx<sz; idx++ )
393 for (
int idx=0; idx<samplesz; idx++ )
395 od_int64 arridx = ((1+idx) * seed) % samplesz;
409 if ( val>127 || val<-128 )
412 const int ival = (int)(val>0 ? val+.5 : val-.5);
419 const unsigned int samplesz=100 )
424 if ( sz <= samplesz )
426 for (
int idx=0; idx<sz; idx++ )
437 for (
int idx=0; idx<samplesz; idx++ )
439 od_int64 arridx = ((1+idx) * seed) % samplesz;
Definition: interpol1d.h:36
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:285
#define M_2PI
Definition: commondefs.h:72
bool is8BitesData(const T *vals, od_int64 sz, const unsigned int samplesz=100)
Definition: simpnumer.h:418
iT exactPower(iT val, iT base)
Definition: simpnumer.h:103
T greatestCommonDivisor(T val0, T val1)
Definition: simpnumer.h:48
Definition: i_layout.h:26
#define mIsZero(x, eps)
Definition: commondefs.h:55
#define od_int64
Definition: plftypes.h:34
#define mDefineStaticLocalObject(type, var, init)
Definition: commondefs.h:199
bool taperArray(T *array, int sz, int lowpos, int highpos, Taper::Type type)
Definition: simpnumer.h:193
Taper an indexable array from 1 to taperfactor. If lowpos is less than highpos, the samples array[0] ...
Definition: simpnumer.h:186
int nrSteps() const
Definition: ranges.h:758
void getGradient(const X &x, const Y &y, int sz, int firstx, int firsty, RT *gradptr=0, RT *interceptptr=0)
Definition: simpnumer.h:262
T sampledGradient(T ym2, T ym1, T y0_, T y1_, T y2)
Definition: simpnumer.h:235
unsigned int Abs(unsigned int i)
Definition: math2.h:78
#define mMIN(x, y)
Definition: commondefs.h:52
float variance(const X &x, int sz)
Definition: simpnumer.h:286
#define mIsEqual(x, y, eps)
Definition: commondefs.h:56
#define M_PI
Definition: commondefs.h:66
Type
Definition: simpnumer.h:188
T step
Definition: ranges.h:195
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:270
Interval with step.
Definition: commontypes.h:29
StepInterval< T > getCommonStepInterval(const StepInterval< T > &a, const StepInterval< T > &b)
Definition: simpnumer.h:82
iT nrBlocks(iT totalsamples, iT basesize, iT overlapsize)
Definition: simpnumer.h:166
iT nextPower2(iT nr, iT minnr, iT maxnr)
Definition: simpnumer.h:147
#define mDefEps
Definition: commondefs.h:60
iT getPow2Sz(iT actsz, const bool above=true, iT minsz=1, iT maxsz=0)
Definition: simpnumer.h:127
iT nextPower(iT val, iT base)
Definition: simpnumer.h:118
Definition: simpnumer.h:188
T start
Definition: ranges.h:90
Definition: simpnumer.h:188
bool holdsClassValues(const T *vals, od_int64 sz, const unsigned int maxclss=50, const unsigned int samplesz=100)
Definition: simpnumer.h:375
bool isUdf(const T &t)
Definition: undefval.h:241
int solve3DPoly(double a, double b, double c, double &root0, double &root1, double &root2)
Definition: simpnumer.h:316
iT IntPowerOf(iT i, iPOW p)
Definition: math2.h:126
#define mMAX(x, y)
Definition: commondefs.h:51
int getArrIdxPosition(const float farridx, const int arrsz, float &relpos, const float eps=1e-4)
Definition: simpnumer.h:27
bool holdsClassValue(const T val, const unsigned int maxclss=50)
Definition: simpnumer.h:365
bool isSigned8BitesValue(const T val)
Definition: simpnumer.h:407