[Numpy-svn] r6417 - branches/coremath/numpy/core/src

numpy-svn@scip... numpy-svn@scip...
Thu Feb 19 05:45:55 CST 2009


Author: cdavid
Date: 2009-02-19 05:45:30 -0600 (Thu, 19 Feb 2009)
New Revision: 6417

Modified:
   branches/coremath/numpy/core/src/npy_math.c.src
   branches/coremath/numpy/core/src/umath_funcs.inc.src
Log:
Move non standard, real math function from umath_funcs into npymath.

Modified: branches/coremath/numpy/core/src/npy_math.c.src
===================================================================
--- branches/coremath/numpy/core/src/npy_math.c.src	2009-02-19 11:44:22 UTC (rev 6416)
+++ branches/coremath/numpy/core/src/npy_math.c.src	2009-02-19 11:45:30 UTC (rev 6417)
@@ -285,7 +285,107 @@
 
 /**end repeat**/
 
+/* 
+ * Useful constants in three precisions: 
+ * XXX: those should really be in the header
+ */
+
+/**begin repeat
+ * #c = f, ,l#
+ * #C = F, ,L#
+ */
+#define NPY_E@c@        2.7182818284590452353602874713526625@C@ /* e */
+#define NPY_LOG2E@c@    1.4426950408889634073599246810018921@C@ /* log_2 e */
+#define NPY_LOG10E@c@   0.4342944819032518276511289189166051@C@ /* log_10 e */
+#define NPY_LOGE2@c@    0.6931471805599453094172321214581766@C@ /* log_e 2 */
+#define NPY_LOGE10@c@   2.3025850929940456840179914546843642@C@ /* log_e 10 */
+#define NPY_PI@c@       3.1415926535897932384626433832795029@C@ /* pi */
+#define NPY_PI_2@c@     1.5707963267948966192313216916397514@C@ /* pi/2 */
+#define NPY_PI_4@c@     0.7853981633974483096156608458198757@C@ /* pi/4 */
+#define NPY_1_PI@c@     0.3183098861837906715377675267450287@C@ /* 1/pi */
+#define NPY_2_PI@c@     0.6366197723675813430755350534900574@C@ /* 2/pi */
+/**end repeat**/
+
 /*
+ * Non standard functions
+ */
+
+/**begin repeat
+ * #type = float, double, npy_longdouble#
+ * #c = f, ,l#
+ * #C = F, ,L#
+ */
+
+#define LOGE2    NPY_LOGE2@c@
+#define LOG2E    NPY_LOG2E@c@
+#define RAD2DEG  (180.0@c@/NPY_PI@c@)
+#define DEG2RAD  (NPY_PI@c@/180.0@c@)
+
+static @type@ rad2deg@c@(@type@ x) 
+{
+    return x*RAD2DEG;
+}
+
+static @type@ deg2rad@c@(@type@ x) 
+{
+    return x*DEG2RAD;
+}
+
+static @type@ log2_1p@c@(@type@ x)
+{
+    @type@ u = 1 + x;
+    if (u == 1) {
+        return LOG2E*x;
+    } else {
+        return npy_log2@c@(u) * x / (u - 1);
+    }
+}
+
+static @type@ exp2_1m@c@(@type@ x)
+{
+    @type@ u = exp@c@(x);
+    if (u == 1.0) {
+        return LOGE2*x;
+    } else if (u - 1 == -1) {
+        return -LOGE2;
+    } else {
+        return (u - 1) * x/npy_log2@c@(u);
+    }
+}
+
+static @type@ logaddexp@c@(@type@ x, @type@ y)
+{
+    const @type@ tmp = x - y;
+    if (tmp > 0) {
+        return x + npy_log1p@c@(npy_exp@c@(-tmp));
+    }
+    else {
+        return y + npy_log1p@c@(npy_exp@c@(tmp));
+    }
+}
+
+static @type@ logaddexp2@c@(@type@ x, @type@ y)
+{
+    const @type@ tmp = x - y;
+    if (tmp > 0) {
+        return x + log2_1p@c@(npy_exp2@c@(-tmp));
+    }
+    else {
+        return y + log2_1p@c@(npy_exp2@c@(tmp));
+    }
+}
+
+#define degrees@c@ rad2deg@c@
+#define radians@c@ deg2rad@c@
+
+#undef LOGE2
+#undef LOG2E
+#undef RAD2DEG
+#undef DEG2RAD
+
+/**end repeat**/
+
+/*
  * Decorate all the functions: those are the public ones
  */
 
@@ -295,7 +395,8 @@
  */
 /**begin repeat1
  * #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10,
- *         log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2#
+ *         log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2,
+ *         rad2deg,deg2rad,exp2_1m#
  */
 
 @type@ npy_@kind@@c@(@type@ x)
@@ -306,7 +407,7 @@
 /**end repeat1**/
 
 /**begin repeat1
- * #kind = atan2,hypot,pow,fmod#
+ * #kind = atan2,hypot,pow,fmod,logaddexp,logaddexp2#
  */
 @type@ npy_@kind@@c@(@type@ x, @type@ y)
 {

Modified: branches/coremath/numpy/core/src/umath_funcs.inc.src
===================================================================
--- branches/coremath/numpy/core/src/umath_funcs.inc.src	2009-02-19 11:44:22 UTC (rev 6416)
+++ branches/coremath/numpy/core/src/umath_funcs.inc.src	2009-02-19 11:45:30 UTC (rev 6417)
@@ -29,91 +29,6 @@
 /**end repeat**/
 
 /*
- ******************************************************************************
- **                            FLOAT FUNCTIONS                               **
- ******************************************************************************
- */
-
-/**begin repeat
- * #type = float, double, longdouble#
- * #c = f, ,l#
- * #C = F, ,L#
- */
-
-#define LOGE2    NPY_LOGE2@c@
-#define LOG2E    NPY_LOG2E@c@
-#define RAD2DEG  (180.0@c@/NPY_PI@c@)
-#define DEG2RAD  (NPY_PI@c@/180.0@c@)
-
-static @type@
-rad2deg@c@(@type@ x) {
-    return x*RAD2DEG;
-}
-
-static @type@
-deg2rad@c@(@type@ x) {
-    return x*DEG2RAD;
-}
-
-static @type@
-log2_1p@c@(@type@ x)
-{
-    @type@ u = 1 + x;
-    if (u == 1) {
-        return LOG2E*x;
-    } else {
-        return npy_log2@c@(u) * x / (u - 1);
-    }
-}
-
-static @type@
-exp2_1m@c@(@type@ x)
-{
-    @type@ u = exp@c@(x);
-    if (u == 1.0) {
-        return LOGE2*x;
-    } else if (u - 1 == -1) {
-        return -LOGE2;
-    } else {
-        return (u - 1) * x/npy_log2@c@(u);
-    }
-}
-
-static @type@
-logaddexp@c@(@type@ x, @type@ y)
-{
-    const @type@ tmp = x - y;
-    if (tmp > 0) {
-        return x + npy_log1p@c@(npy_exp@c@(-tmp));
-    }
-    else {
-        return y + npy_log1p@c@(npy_exp@c@(tmp));
-    }
-}
-
-static @type@
-logaddexp2@c@(@type@ x, @type@ y)
-{
-    const @type@ tmp = x - y;
-    if (tmp > 0) {
-        return x + log2_1p@c@(npy_exp2@c@(-tmp));
-    }
-    else {
-        return y + log2_1p@c@(npy_exp2@c@(tmp));
-    }
-}
-
-#define degrees@c@ rad2deg@c@
-#define radians@c@ deg2rad@c@
-
-#undef LOGE2
-#undef LOG2E
-#undef RAD2DEG
-#undef DEG2RAD
-
-/**end repeat**/
-
-/*
  *****************************************************************************
  **                        PYTHON OBJECT FUNCTIONS                          **
  *****************************************************************************



More information about the Numpy-svn mailing list