45 return _isnan(value) != 0;
58 return _finite(value) != 0;
69 inline T
uMin3(
const T& a,
const T& b,
const T& c)
80 inline T
uMax3(
const T& a,
const T& b,
const T& c)
94 inline T
uMax(
const T * v,
unsigned int size,
unsigned int & index)
103 for(
unsigned int i=1; i<size; ++i)
122 inline T
uMax(
const std::vector<T> & v,
unsigned int & index)
124 return uMax(v.data(), v->size(), index);
134 inline T
uMax(
const T * v,
unsigned int size)
137 return uMax(v, size, index);
146 inline T
uMax(
const std::vector<T> & v)
148 return uMax(v.data(), v.size());
159 inline T
uMin(
const T * v,
unsigned int size,
unsigned int & index)
168 for(
unsigned int i=1; i<size; ++i)
187 inline T
uMin(
const std::vector<T> & v,
unsigned int & index)
189 return uMin(v.data(), v.size(), index);
199 inline T
uMin(
const T * v,
unsigned int size)
202 return uMin(v, size, index);
211 inline T
uMin(
const std::vector<T> & v)
213 return uMin(v.data(), v.size());
226 inline void uMinMax(
const T * v,
unsigned int size, T &
min, T &
max,
unsigned int & indexMin,
unsigned int & indexMax)
239 for(
unsigned int i=1; i<size; ++i)
264 inline void uMinMax(
const std::vector<T> & v, T &
min, T &
max,
unsigned int & indexMin,
unsigned int & indexMax)
279 unsigned int indexMin;
280 unsigned int indexMax;
281 uMinMax(v, size, min, max, indexMin, indexMax);
320 inline T
uSum(
const std::list<T> & list)
323 for(
typename std::list<T>::const_iterator i=list.begin(); i!=list.end(); ++i)
337 inline T
uSum(
const T * v,
unsigned int size)
342 for(
unsigned int i=0; i<size; ++i)
356 inline T
uSum(
const std::vector<T> & v)
358 return uSum(v.data(), (int)v.size());
369 inline T
uSumSquared(
const T * v,
unsigned int size, T subtract = T())
374 for(
unsigned int i=0; i<size; ++i)
376 sum += (v[i]-subtract)*(v[i]-subtract);
401 inline T
uMean(
const T * v,
unsigned int size)
406 for(
unsigned int i=0; i<size; ++i)
421 inline T
uMean(
const std::list<T> & list)
426 for(
typename std::list<T>::const_iterator i=list.begin(); i!=list.end(); ++i)
441 inline T
uMean(
const std::vector<T> & v)
443 return uMean(v.data(), v.size());
458 if(x && y && sizeX == sizeY)
460 for(
unsigned int i=0; i<sizeX; ++i)
491 inline T
uVariance(
const T * v,
unsigned int size, T meanV)
497 for(
unsigned int i=0; i<size; ++i)
499 sum += (v[i]-meanV)*(v[i]-meanV);
514 inline T
uVariance(
const std::list<T> & list,
const T & m)
520 for(
typename std::list<T>::const_iterator i=list.begin(); i!=list.end(); ++i)
522 sum += (*i-m)*(*i-m);
524 buf = sum/(list.size()-1);
538 T m =
uMean(v, size);
550 inline T
uVariance(
const std::vector<T> & v,
const T & m)
563 for(
unsigned int i=0; i<v.size(); ++i)
575 inline T
uNorm(
const std::vector<T> & v)
587 return x1*x1 + x2*x2;
595 inline T
uNorm(
const T & x1,
const T & x2)
607 return x1*x1 + x2*x2 + x3*x3;
615 inline T
uNorm(
const T & x1,
const T & x2,
const T & x3)
627 float norm =
uNorm(v);
634 std::vector<T> r(v.size());
635 for(
unsigned int i=0; i<v.size(); ++i)
647 inline std::list<unsigned int>
uLocalMaxima(
const T * v,
unsigned int size)
649 std::list<unsigned int> maxima;
652 for(
unsigned int i=0; i<size; ++i)
657 if((i+1 < size && v[i] > v[i+1]) ||
663 else if(i == size - 1)
666 if((i >= 1 && v[i] > v[i-1]) ||
675 if(v[i] > v[i-1] && v[i] > v[i+1])
710 inline std::vector<T>
uXMatch(
const T * vA,
const T * vB,
unsigned int sizeA,
unsigned int sizeB,
UXMatchMethod method)
712 if(!vA || !vB || sizeA == 0 || sizeB == 0)
714 return std::vector<T>();
717 std::vector<T> result(sizeA + sizeB - 1);
723 meanA =
uMean(vA, sizeA);
724 meanB =
uMean(vB, sizeB);
747 for(
unsigned int i=0; i<sizeA; ++i)
754 posA = sizeA - i - 1;
755 posB = sizeB - i - 1;
758 for(j=0; (j + posB) < sizeB && (j + posA) < sizeA; ++j)
760 resultA += (vA[j] - meanA) * (vB[j + posB] - meanB);
761 resultB += (vA[j + posA] - meanA) * (vB[j] - meanB);
768 result[i] = resultA / den;
769 result[result.size()-1 -i] = resultB / den;
774 for(
unsigned int i=0; i<result.size(); ++i)
781 int posB = sizeB - i - 1;
785 for(
unsigned int j=0; (j + posB) < sizeB && j < sizeA; ++j)
787 r += (vA[j] - meanA) * (vB[j + posB] - meanB);
797 for(
unsigned int i=0; (i+posA) < sizeA && i < sizeB; ++i)
799 r += (vA[i+posA] - meanA) * (vB[i] - meanB);
824 return uXMatch(vA.data(), vB.data(), vA.size(), vB.size(), method);
838 inline T
uXMatch(
const T * vA,
const T * vB,
unsigned int sizeA,
unsigned int sizeB,
unsigned int index,
UXMatchMethod method)
841 if(!vA || !vB || sizeA == 0 || sizeB == 0)
850 meanA =
uMean(vA, sizeA);
851 meanB =
uMean(vB, sizeB);
853 unsigned int size = sizeA + sizeB - 1;
871 int posB = sizeB - index - 1;
875 for(i=0; (i + posB) < sizeB && i < sizeA; ++i)
877 result += (vA[i] - meanA) * (vB[i + posB] - meanB);
887 for(i=0; (i+posA) < sizeA && i < sizeB; ++i)
889 result += (vA[i+posA] - meanA) * (vB[i] - meanB);
911 inline T
uXMatch(
const std::vector<T> & vA,
const std::vector<T> & vB,
unsigned int index,
UXMatchMethod method)
913 return uXMatch(vA.data(), vB.data(), vA.size(), vB.size(), index, method);
923 std::vector<float> w(L);
924 unsigned int N = L-1;
925 float pi = 3.14159265f;
926 for(
unsigned int n=0; n<N; ++n)
928 w[n] = 0.54f-0.46f*
std::cos(2.0
f*pi*
float(n)/
float(N));
933 template <
typename T>
936 return uIsFinite(value) && !(value < low) && !(value >= high);
T uVariance(const T *v, unsigned int size, T meanV)
T uMean(const T *v, unsigned int size)
T uNorm(const std::vector< T > &v)
GLM_FUNC_DECL bool isfinite(genType const &x)
Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)...
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
void uMinMax(const T *v, unsigned int size, T &min, T &max, unsigned int &indexMin, unsigned int &indexMax)
bool uIsInBounds(const T &value, const T &low, const T &high)
GLM_FUNC_DECL vecType< T, P > sqrt(vecType< T, P > const &x)
T uMin3(const T &a, const T &b, const T &c)
std::vector< T > uNormalize(const std::vector< T > &v)
std::vector< T > uXMatch(const T *vA, const T *vB, unsigned int sizeA, unsigned int sizeB, UXMatchMethod method)
std::list< unsigned int > uLocalMaxima(const T *v, unsigned int size)
T uMin(const T *v, unsigned int size, unsigned int &index)
bool uIsFinite(const T &value)
GLM_FUNC_DECL genType cos(genType const &angle)
std::vector< float > uHamming(unsigned int L)
T uMax3(const T &a, const T &b, const T &c)
GLM_FUNC_DECL genType pi()
T uSumSquared(const T *v, unsigned int size, T subtract=T())
T uMeanSquaredError(const T *x, unsigned int sizeX, const T *y, unsigned int sizeY)
T uMax(const T *v, unsigned int size, unsigned int &index)
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
T uNormSquared(const std::vector< T > &v)
GLM_FUNC_DECL genType::bool_type isnan(genType const &x)
bool uIsNan(const T &value)
T uSum(const std::list< T > &list)