libidx
|
00001 /*************************************************************************** 00002 * Copyright (C) 2008 by Yann LeCun and Pierre Sermanet * 00003 * yann@cs.nyu.edu, pierre.sermanet@gmail.com * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Redistribution under a license not approved by the Open Source 00014 * Initiative (http://www.opensource.org) must display the 00015 * following acknowledgement in all advertising material: 00016 * This product includes software developed at the Courant 00017 * Institute of Mathematical Sciences (http://cims.nyu.edu). 00018 * * The names of the authors may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY 00025 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00028 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 ***************************************************************************/ 00032 00033 #ifndef NUMERICS_H 00034 #define NUMERICS_H 00035 00036 #include "defines.h" 00037 #include "stl.h" 00038 00039 #ifndef __NOSTL__ 00040 #include <limits> 00041 #endif 00042 00043 #ifdef __ANDROID__ 00044 #include <math.h> 00045 #include <float.h> 00046 #else 00047 #include <cfloat> 00048 #include <cmath> 00049 #endif 00050 00051 #ifdef __WINDOWS__ 00052 #define isinf(a) (!_finite(a)) 00053 #endif 00054 00055 #define TWOPI 6.283185308 00056 #define PI 3.141592654 00057 #define PI_OVER2 1.570796327 00058 00059 namespace ebl { 00060 00062 EXPORT double dtanh(double x); 00063 00065 EXPORT double arccot(double x); 00066 00069 EXPORT float stdsigmoid(float x); 00071 EXPORT float dstdsigmoid(float x); 00072 00075 EXPORT double stdsigmoid(double x); 00077 EXPORT double dstdsigmoid(double x); 00078 00080 00085 #ifdef LIBIDX // declared from inside this library 00086 extern EXPORT bool drand_ini; 00087 #else // declared from outside 00088 extern IMPORT bool drand_ini; 00089 #endif 00090 00092 EXPORT void init_drand(int x); 00099 EXPORT int dynamic_init_drand(int argc = 0, char **argv = NULL); 00102 EXPORT int fixed_init_drand(); 00108 EXPORT void dseed(int x); 00111 EXPORT double drand(void); 00114 EXPORT double drand(double v); 00117 EXPORT double drand(double v0, double v1); 00120 EXPORT double dgauss(void); 00123 EXPORT double dgauss(double sigma); 00126 EXPORT double dgauss(double m, double sigma); 00128 EXPORT double gaussian(double x, double m, double sigma); 00130 EXPORT int choose(int n, int k); 00133 template <typename T> EXPORT T angle_distance(T a1, T a2); 00134 00135 // limits //////////////////////////////////////////////////////////////////// 00136 00137 template <typename T> class limits { 00138 public: 00139 static inline T max (); 00140 static inline T min (); 00141 }; 00142 00143 template <> class limits<uint32> { 00144 public: 00145 static inline uint32 max () { return UINT_MAX; } 00146 static inline uint32 min () { return 0; } 00147 }; 00148 00149 template <> class limits<float32> { 00150 public: 00151 static inline float32 max () { return FLT_MAX; } 00152 static inline float32 min () { return FLT_MIN; } 00153 }; 00154 00155 template <> class limits<float64> { 00156 public: 00157 static inline float64 max () { return DBL_MAX; } 00158 static inline float64 min () { return - DBL_MAX; } 00159 }; 00160 00161 template <> class limits<long double> { 00162 public: 00163 static inline long double max () { return LDBL_MAX; } 00164 static inline long double min () { return - LDBL_MAX; } 00165 }; 00166 00167 template <typename T> class saturator { 00168 public: 00169 template <typename T2> inline static T saturate (T2 in); 00170 }; 00171 00172 #ifdef __WINDOWS__ 00173 // Windows replacements for missing functions 00174 00176 EXPORT double rint(double x); 00177 00178 #endif 00179 00180 } // end namespace ebl 00181 00182 #include "numerics.hpp" 00183 00184 #endif /* NUMERICS_H */