[Numpy-svn] r6417 - branches/coremath/numpy/core/src
numpy-svn at scipy.org
numpy-svn at scipy.org
Thu Feb 19 06:45:55 EST 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 at c@ 2.7182818284590452353602874713526625 at C@ /* e */
+#define NPY_LOG2E at c@ 1.4426950408889634073599246810018921 at C@ /* log_2 e */
+#define NPY_LOG10E at c@ 0.4342944819032518276511289189166051 at C@ /* log_10 e */
+#define NPY_LOGE2 at c@ 0.6931471805599453094172321214581766 at C@ /* log_e 2 */
+#define NPY_LOGE10 at c@ 2.3025850929940456840179914546843642 at C@ /* log_e 10 */
+#define NPY_PI at c@ 3.1415926535897932384626433832795029 at C@ /* pi */
+#define NPY_PI_2 at c@ 1.5707963267948966192313216916397514 at C@ /* pi/2 */
+#define NPY_PI_4 at c@ 0.7853981633974483096156608458198757 at C@ /* pi/4 */
+#define NPY_1_PI at c@ 0.3183098861837906715377675267450287 at C@ /* 1/pi */
+#define NPY_2_PI at c@ 0.6366197723675813430755350534900574 at 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 at c@
+#define LOG2E NPY_LOG2E at c@
+#define RAD2DEG (180.0 at c@/NPY_PI at c@)
+#define DEG2RAD (NPY_PI at c@/180.0 at c@)
+
+static @type@ rad2deg at c@(@type@ x)
+{
+ return x*RAD2DEG;
+}
+
+static @type@ deg2rad at c@(@type@ x)
+{
+ return x*DEG2RAD;
+}
+
+static @type@ log2_1p at c@(@type@ x)
+{
+ @type@ u = 1 + x;
+ if (u == 1) {
+ return LOG2E*x;
+ } else {
+ return npy_log2 at c@(u) * x / (u - 1);
+ }
+}
+
+static @type@ exp2_1m at c@(@type@ x)
+{
+ @type@ u = exp at c@(x);
+ if (u == 1.0) {
+ return LOGE2*x;
+ } else if (u - 1 == -1) {
+ return -LOGE2;
+ } else {
+ return (u - 1) * x/npy_log2 at c@(u);
+ }
+}
+
+static @type@ logaddexp at c@(@type@ x, @type@ y)
+{
+ const @type@ tmp = x - y;
+ if (tmp > 0) {
+ return x + npy_log1p at c@(npy_exp at c@(-tmp));
+ }
+ else {
+ return y + npy_log1p at c@(npy_exp at c@(tmp));
+ }
+}
+
+static @type@ logaddexp2 at c@(@type@ x, @type@ y)
+{
+ const @type@ tmp = x - y;
+ if (tmp > 0) {
+ return x + log2_1p at c@(npy_exp2 at c@(-tmp));
+ }
+ else {
+ return y + log2_1p at c@(npy_exp2 at c@(tmp));
+ }
+}
+
+#define degrees at c@ rad2deg at c@
+#define radians at c@ deg2rad at 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_ at 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_ at 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 at c@
-#define LOG2E NPY_LOG2E at c@
-#define RAD2DEG (180.0 at c@/NPY_PI at c@)
-#define DEG2RAD (NPY_PI at c@/180.0 at c@)
-
-static @type@
-rad2deg at c@(@type@ x) {
- return x*RAD2DEG;
-}
-
-static @type@
-deg2rad at c@(@type@ x) {
- return x*DEG2RAD;
-}
-
-static @type@
-log2_1p at c@(@type@ x)
-{
- @type@ u = 1 + x;
- if (u == 1) {
- return LOG2E*x;
- } else {
- return npy_log2 at c@(u) * x / (u - 1);
- }
-}
-
-static @type@
-exp2_1m at c@(@type@ x)
-{
- @type@ u = exp at c@(x);
- if (u == 1.0) {
- return LOGE2*x;
- } else if (u - 1 == -1) {
- return -LOGE2;
- } else {
- return (u - 1) * x/npy_log2 at c@(u);
- }
-}
-
-static @type@
-logaddexp at c@(@type@ x, @type@ y)
-{
- const @type@ tmp = x - y;
- if (tmp > 0) {
- return x + npy_log1p at c@(npy_exp at c@(-tmp));
- }
- else {
- return y + npy_log1p at c@(npy_exp at c@(tmp));
- }
-}
-
-static @type@
-logaddexp2 at c@(@type@ x, @type@ y)
-{
- const @type@ tmp = x - y;
- if (tmp > 0) {
- return x + log2_1p at c@(npy_exp2 at c@(-tmp));
- }
- else {
- return y + log2_1p at c@(npy_exp2 at c@(tmp));
- }
-}
-
-#define degrees at c@ rad2deg at c@
-#define radians at c@ deg2rad at c@
-
-#undef LOGE2
-#undef LOG2E
-#undef RAD2DEG
-#undef DEG2RAD
-
-/**end repeat**/
-
-/*
*****************************************************************************
** PYTHON OBJECT FUNCTIONS **
*****************************************************************************
More information about the Numpy-svn
mailing list