[Numpy-svn] r5975 - in trunk/numpy/core: code_generators src

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Nov 5 14:40:35 EST 2008


Author: charris
Date: 2008-11-05 13:40:28 -0600 (Wed, 05 Nov 2008)
New Revision: 5975

Modified:
   trunk/numpy/core/code_generators/generate_umath.py
   trunk/numpy/core/src/math_c99.inc.src
   trunk/numpy/core/src/umathmodule.c.src
Log:
Add logsumexp ufunc and some small cleanups.

Modified: trunk/numpy/core/code_generators/generate_umath.py
===================================================================
--- trunk/numpy/core/code_generators/generate_umath.py	2008-11-05 16:59:07 UTC (rev 5974)
+++ trunk/numpy/core/code_generators/generate_umath.py	2008-11-05 19:40:28 UTC (rev 5975)
@@ -326,6 +326,11 @@
           "",
           TD(inexact)
           ),
+'logsumexp' :
+    Ufunc(2, 1, None,
+          "",
+          TD(flts, f="logsumexp")
+          ),
 'bitwise_and' :
     Ufunc(2, 1, One,
           docstrings.get('numpy.core.umath.bitwise_and'),

Modified: trunk/numpy/core/src/math_c99.inc.src
===================================================================
--- trunk/numpy/core/src/math_c99.inc.src	2008-11-05 16:59:07 UTC (rev 5974)
+++ trunk/numpy/core/src/math_c99.inc.src	2008-11-05 19:40:28 UTC (rev 5975)
@@ -33,7 +33,7 @@
     if (u == 1.0) {
         return x;
     } else {
-        return log(u) * x / (u-1.);
+        return log(u) * x / (u - 1);
     }
 }
 #endif
@@ -187,78 +187,56 @@
  * instead test for the macro, but I am lazy to do that for now.
  */
 
-/*
- * One value argument function
- */
-
 /**begin repeat
-
-   #kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10,log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p)*2#
-   #KIND=(SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10,LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P)*2#
-   #typ=longdouble*23, float*23#
-   #c=l*23,f*23#
-   #C=L*23,F*23#
-   #TYPE=LONGDOUBLE*23, FLOAT*23#
+ * #type = longdouble, float#
+ * #TYPE = LONGDOUBLE, FLOAT#
+ * #c = l,f#
+ * #C = L,F#
 */
 
+/**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#
+ * #KIND = SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10,
+ *         LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P#
+ */
 #ifndef HAVE_ at KIND@@C@
 #ifdef @kind@@c@
 #undef @kind@@c@
 #endif
- at typ@ @kind@@c@(@typ@ x)
+ at type@ @kind@@c@(@type@ x)
 {
-    return (@typ@) @kind@((double)x);
+    return (@type@) @kind@((double)x);
 }
 #endif
-/**end repeat**/
+/**end repeat1**/
 
-/*
- * Two values arguments function
+/**begin repeat1
+ * #kind = atan2,hypot,pow,fmod#
+ * #KIND = ATAN2,HYPOT,POW,FMOD#
  */
-
-/**begin repeat
-
-   #kind=(atan2,hypot,pow,fmod)*2#
-   #KIND=(ATAN2,HYPOT,POW,FMOD)*2#
-   #typ=longdouble*4, float*4#
-   #c=l*4,f*4#
-   #C=L*4,F*4#
-   #TYPE=LONGDOUBLE*4,FLOAT*4#
-*/
 #ifndef HAVE_ at KIND@@C@
 #ifdef @kind@@c@
 #undef @kind@@c@
 #endif
- at typ@ @kind@@c@(@typ@ x, @typ@ y)
+ at type@ @kind@@c@(@type@ x, @type@ y)
 {
-    return (@typ@) @kind@((double)x, (double) y);
+    return (@type@) @kind@((double)x, (double) y);
 }
 #endif
-/**end repeat**/
+/**end repeat1**/
 
-/*
- * One value - one pointer argument function
- */
-
-/**begin repeat
-   #kind=modf*2#
-   #KIND=MODF*2#
-   #c=l,f#
-   #C=L,F#
-   #typ=longdouble, float#
-   #TYPE=LONGDOUBLE, FLOAT#
-*/
-#ifndef HAVE_ at KIND@@C@
+#ifndef HAVE_MODF at C@
 #ifdef modf at c@
 #undef modf at c@
 #endif
- at typ@ modf at c@(@typ@ x, @typ@ *iptr)
+ at type@ modf at c@(@type@ x, @type@ *iptr)
 {
-    double nx, niptr, y;
-    nx = (double) x;
-    y = modf(nx, &niptr);
-    *iptr = (@typ@) niptr;
-    return (@typ@) y;
+    double niptr;
+    double y = modf((double)x, &niptr);
+    *iptr = (@type@) niptr;
+    return (@type@) y;
 }
 #endif
+
 /**end repeat**/

Modified: trunk/numpy/core/src/umathmodule.c.src
===================================================================
--- trunk/numpy/core/src/umathmodule.c.src	2008-11-05 16:59:07 UTC (rev 5974)
+++ trunk/numpy/core/src/umathmodule.c.src	2008-11-05 19:40:28 UTC (rev 5975)
@@ -23,26 +23,56 @@
 
 #include "math_c99.inc"
 
-float degreesf(float x) {
-    return x * (float)(180.0/M_PI);
+/*
+ *****************************************************************************
+ **                            FLOAT FUNCTIONS                              **
+ *****************************************************************************
+ */
+
+/**begin repeat
+ * #type = float, double, longdouble#
+ * #c = f, ,l#
+ * #C = F, ,L#
+ */
+
+#define PI 3.14159265358979323846264338328 at c@
+
+static @type@
+degrees at c@(@type@ x) {
+    return x*(180.0 at c@/PI);
 }
-double degrees(double x) {
-    return x * (180.0/M_PI);
+
+static @type@
+radians at c@(@type@ x) {
+    return x*(PI/180.0 at c@);
 }
-longdouble degreesl(longdouble x) {
-    return x * (180.0L/M_PI);
+
+static @type@
+rad2deg at c@(@type@ x) {
+    return x*(180.0 at c@/PI);
 }
 
-float radiansf(float x) {
-    return x * (float)(M_PI/180.0);
+static @type@
+deg2rad at c@(@type@ x) {
+    return x*(PI/180.0 at c@);
 }
-double radians(double x) {
-    return x * (M_PI/180.0);
+
+static @type@
+logsumexp at c@(@type@ x, @type@ y)
+{
+    const @type@ tmp = x - y;
+    if (tmp > 0) {
+        return x + log1p at c@(exp at c@(-tmp));
+    }
+    else {
+        return y + log1p at c@(exp at c@(tmp));
+    }
 }
-longdouble radiansl(longdouble x) {
-    return x * (M_PI/180.0L);
-}
 
+#undef PI
+
+/**end repeat**/
+
 /*
  *****************************************************************************
  **                        PYTHON OBJECT FUNCTIONS                          **




More information about the Numpy-svn mailing list