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

scipy-svn@scip... scipy-svn@scip...
Wed Jan 7 12:25:27 CST 2009


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

Modified:
   trunk/scipy/fftpack/src/zfft.c
Log:
Put all complex fft code in zfft.c

Modified: trunk/scipy/fftpack/src/zfft.c
===================================================================
--- trunk/scipy/fftpack/src/zfft.c	2009-01-07 18:24:48 UTC (rev 5367)
+++ trunk/scipy/fftpack/src/zfft.c	2009-01-07 18:25:14 UTC (rev 5368)
@@ -6,30 +6,95 @@
 
 #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_zfft_cache(void)\
-{\
-        destroy_z##name##_caches();\
-}\
-\
-void zfft(complex_double *inout, int n, \
-        int direction, int howmany, int normalize)\
-{\
-        zfft_##name(inout, n, direction, howmany, normalize);\
-}\
-void destroy_cfft_cache(void)\
-{\
-        destroy_c##name##_caches();\
-}\
-\
-void cfft(complex_float *inout, int n, \
-        int direction, int howmany, int normalize)\
-{\
-        cfft_##name(inout, n, direction, howmany, normalize);\
+extern void F_FUNC(zfftf,ZFFTF)(int*,double*,double*);
+extern void F_FUNC(zfftb,ZFFTB)(int*,double*,double*);
+extern void F_FUNC(zffti,ZFFTI)(int*,double*);
+extern void F_FUNC(cfftf,CFFTF)(int*,float*,float*);
+extern void F_FUNC(cfftb,CFFTB)(int*,float*,float*);
+extern void F_FUNC(cffti,CFFTI)(int*,float*);
+
+GEN_CACHE(zfft,(int n)
+	  ,double* wsave;
+	  ,(caches_zfft[i].n==n)
+	  ,caches_zfft[id].wsave = (double*)malloc(sizeof(double)*(4*n+15));
+	   F_FUNC(zffti,ZFFTI)(&n,caches_zfft[id].wsave);
+	  ,free(caches_zfft[id].wsave);
+	  ,10)
+
+GEN_CACHE(cfft,(int n)
+	  ,float* wsave;
+	  ,(caches_cfft[i].n==n)
+	  ,caches_cfft[id].wsave = (float*)malloc(sizeof(float)*(4*n+15));
+	   F_FUNC(cffti,CFFTI)(&n,caches_cfft[id].wsave);
+	  ,free(caches_cfft[id].wsave);
+	  ,10)
+
+void zfft(complex_double * inout, int n, int direction, int howmany,
+		int normalize)
+{
+	int i;
+	complex_double *ptr = inout;
+	double *wsave = NULL;
+
+	wsave = caches_zfft[get_cache_id_zfft(n)].wsave;
+
+	switch (direction) {
+	case 1:
+		for (i = 0; i < howmany; ++i, ptr += n) {
+			zfftf_(&n, (double *) (ptr), wsave);
+
+		}
+		break;
+
+	case -1:
+		for (i = 0; i < howmany; ++i, ptr += n) {
+			zfftb_(&n, (double *) (ptr), wsave);
+		}
+		break;
+	default:
+		fprintf(stderr, "zfft: invalid direction=%d\n", direction);
+	}
+
+	if (normalize) {
+		ptr = inout;
+		for (i = n * howmany - 1; i >= 0; --i) {
+			*((double *) (ptr)) /= n;
+			*((double *) (ptr++) + 1) /= n;
+		}
+	}
 }
 
-#include "zfft_fftpack.c"
-#include "cfft_fftpack.c"
-GEN_PUBLIC_API(fftpack)
+void cfft(complex_float * inout, int n, int direction, int howmany,
+	int normalize)
+{
+	int i;
+	complex_float *ptr = inout;
+	float *wsave = NULL;
+
+	wsave = caches_cfft[get_cache_id_cfft(n)].wsave;
+
+	switch (direction) {
+	case 1:
+		for (i = 0; i < howmany; ++i, ptr += n) {
+			cfftf_(&n, (float *) (ptr), wsave);
+
+		}
+		break;
+
+	case -1:
+		for (i = 0; i < howmany; ++i, ptr += n) {
+			cfftb_(&n, (float *) (ptr), wsave);
+		}
+		break;
+	default:
+		fprintf(stderr, "cfft: invalid direction=%d\n", direction);
+	}
+
+	if (normalize) {
+		ptr = inout;
+		for (i = n * howmany - 1; i >= 0; --i) {
+			*((float *) (ptr)) /= n;
+			*((float *) (ptr++) + 1) /= n;
+		}
+	}
+}



More information about the Scipy-svn mailing list