00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __lfeat_math_h
00022 #define __lfeat_math_h
00023
00024 #include <vector>
00025
00026 #define PI 3.14159
00027
00028 namespace lfeat
00029 {
00030 struct Math
00031 {
00032
00033 static bool SolveLinearSystem33(double* solution, double sq[3][3]);
00034 static inline double Abs(const double iD)
00035 {
00036 return (iD > 0.0 ? iD : -iD);
00037 }
00038 static inline int Round(const double iD)
00039 {
00040 return (int)(iD + 0.5);
00041 }
00042 static bool Normalize(double* iVec, int iLen);
00043
00044
00045 };
00046
00047 template <int LBound = -128, int UBound = 127, class TResult = double, class TArg = double>
00048 class LUT
00049 {
00050 public:
00051 explicit LUT (TResult (*f) (TArg), double coeffadd = 0, double coeffmul = 1)
00052 {
00053 lut = lut_array - LBound;
00054 for (int i = LBound; i <= UBound; i++)
00055 {
00056 lut[i] = f(coeffmul * (i+coeffadd));
00057 }
00058 }
00059
00060 const TResult& operator()(int i) const
00061 {
00062 return lut[i];
00063 }
00064 private:
00065 TResult lut_array[UBound - LBound + 1];
00066 TResult* lut;
00067 };
00068
00069 }
00070
00071 #endif //__lfeat_math_h