[Scipy-svn] r5369 - trunk/scipy/fftpack/src

scipy-svn@scip... scipy-svn@scip...
Wed Jan 7 12:26:00 CST 2009


Author: cdavid
Date: 2009-01-07 12:25:47 -0600 (Wed, 07 Jan 2009)
New Revision: 5369

Modified:
   trunk/scipy/fftpack/src/drfft.c
Log:
Put all real input fft code in one file.

Modified: trunk/scipy/fftpack/src/drfft.c
===================================================================
--- trunk/scipy/fftpack/src/drfft.c	2009-01-07 18:25:14 UTC (rev 5368)
+++ trunk/scipy/fftpack/src/drfft.c	2009-01-07 18:25:47 UTC (rev 5369)
@@ -6,31 +6,98 @@
 
 #include "fftpack.h"
 
-/* The following macro convert private backend specific function to the public
- * functions exported by the module  */
-#define GEN_PUBLIC_API(name) \
-void destroy_drfft_cache(void)\
-{\
-        destroy_dr##name##_caches();\
-}\
-\
-void drfft(double *inout, int n, \
-        int direction, int howmany, int normalize)\
-{\
-        drfft_##name(inout, n, direction, howmany, normalize);\
-}\
-void destroy_rfft_cache(void)\
-{\
-        destroy_r##name##_caches();\
-}\
-\
-void rfft(float *inout, int n, \
-        int direction, int howmany, int normalize)\
-{\
-        rfft_##name(inout, n, direction, howmany, normalize);\
+extern void F_FUNC(dfftf, DFFTF) (int *, double *, double *);
+extern void F_FUNC(dfftb, DFFTB) (int *, double *, double *);
+extern void F_FUNC(dffti, DFFTI) (int *, double *);
+extern void F_FUNC(rfftf, RFFTF) (int *, float *, float *);
+extern void F_FUNC(rfftb, RFFTB) (int *, float *, float *);
+extern void F_FUNC(rffti, RFFTI) (int *, float *);
+
+
+GEN_CACHE(drfftpack, (int n)
+	  , double *wsave;
+	  , (caches_drfftpack[i].n == n)
+	  , caches_drfftpack[id].wsave =
+	  (double *) malloc(sizeof(double) * (2 * n + 15));
+	  F_FUNC(dffti, DFFTI) (&n, caches_drfftpack[id].wsave);
+	  , free(caches_drfftpack[id].wsave);
+	  , 10)
+
+GEN_CACHE(rfftpack, (int n)
+	  , float *wsave;
+	  , (caches_rfftpack[i].n == n)
+	  , caches_rfftpack[id].wsave =
+	  (float *) malloc(sizeof(float) * (2 * n + 15));
+	  F_FUNC(rffti, RFFTI) (&n, caches_rfftpack[id].wsave);
+	  , free(caches_rfftpack[id].wsave);
+	  , 10)
+
+void drfft_fftpack(double *inout, int n, int direction, int howmany,
+			  int normalize)
+{
+    int i;
+    double *ptr = inout;
+    double *wsave = NULL;
+    wsave = caches_drfftpack[get_cache_id_drfftpack(n)].wsave;
+
+
+    switch (direction) {
+        case 1:
+        for (i = 0; i < howmany; ++i, ptr += n) {
+            dfftf_(&n, ptr, wsave);
+        }
+        break;
+
+    case -1:
+        for (i = 0; i < howmany; ++i, ptr += n) {
+            dfftb_(&n, ptr, wsave);
+        }
+        break;
+
+    default:
+        fprintf(stderr, "drfft: invalid direction=%d\n", direction);
+    }
+
+    if (normalize) {
+        double d = 1.0 / n;
+        ptr = inout;
+        for (i = n * howmany - 1; i >= 0; --i) {
+            (*(ptr++)) *= d;
+        }
+    }
 }
 
+void rfft_fftpack(float *inout, int n, int direction, int howmany,
+			 int normalize)
+{
+    int i;
+    float *ptr = inout;
+    float *wsave = NULL;
+    wsave = caches_rfftpack[get_cache_id_rfftpack(n)].wsave;
 
-#include "drfft_fftpack.c"
-#include "rfft_fftpack.c"
-GEN_PUBLIC_API(fftpack)
+
+    switch (direction) {
+        case 1:
+        for (i = 0; i < howmany; ++i, ptr += n) {
+            rfftf_(&n, ptr, wsave);
+        }
+        break;
+
+    case -1:
+        for (i = 0; i < howmany; ++i, ptr += n) {
+            rfftb_(&n, ptr, wsave);
+        }
+        break;
+
+    default:
+        fprintf(stderr, "rfft: invalid direction=%d\n", direction);
+    }
+
+    if (normalize) {
+        float d = 1.0 / n;
+        ptr = inout;
+        for (i = n * howmany - 1; i >= 0; --i) {
+            (*(ptr++)) *= d;
+        }
+    }
+}



More information about the Scipy-svn mailing list