Author: Hakan Ardo <[email protected]>
Branch: extradoc
Changeset: r4579:708bb59811a7
Date: 2012-08-15 09:42 +0200
http://bitbucket.org/pypy/extradoc/changeset/708bb59811a7/
Log: add remaining fft functions and a test
diff --git a/talk/iwtc11/benchmarks/scimark.py
b/talk/iwtc11/benchmarks/scimark.py
--- a/talk/iwtc11/benchmarks/scimark.py
+++ b/talk/iwtc11/benchmarks/scimark.py
@@ -65,6 +65,10 @@
a[x, y] = self.nextDouble()
return a
+ def RandomVector(self, n):
+ return array('d', [self.nextDouble() for i in xrange(n)])
+
+
class ArrayList(Array2D):
def __init__(self, w, h, data=None):
self.width = w
@@ -217,7 +221,7 @@
while bit < logn:
w_real = 1.0
w_imag = 0.0
- theta = 2.0 * direction * math.PI / (2.0 * float(dual))
+ theta = 2.0 * direction * math.pi / (2.0 * float(dual))
s = math.sin(theta)
t = math.sin(theta / 2.0)
s2 = 2.0 * t * t
@@ -268,3 +272,24 @@
j -= k
k >>= 1
j += k
+
+def FFT_transform(N, data):
+ FFT_transform_internal(N, data, -1)
+
+def FFT_inverse(N, data):
+ n = N/2
+ norm = 0.0
+ FFT_transform_internal(N, data, +1)
+ norm = 1 / float(n)
+ for i in xrange(N):
+ data[i] *= norm
+
+def FFT(args):
+ N, cycles = map(int, args)
+ twoN = 2*N
+ x = Random(7).RandomVector(twoN)
+ for i in xrange(cycles):
+ FFT_transform(twoN, x)
+ FFT_inverse(twoN, x)
+ return 'FFT(%d, %d)' % (N, cycles)
+
diff --git a/talk/iwtc11/benchmarks/test_scimark.py
b/talk/iwtc11/benchmarks/test_scimark.py
--- a/talk/iwtc11/benchmarks/test_scimark.py
+++ b/talk/iwtc11/benchmarks/test_scimark.py
@@ -1,4 +1,5 @@
-from scimark import SOR_execute, Array2D, ArrayList, Random,
MonteCarlo_integrate, LU_factor
+from scimark import SOR_execute, Array2D, ArrayList, Random,
MonteCarlo_integrate, LU_factor, \
+ FFT_transform, FFT_inverse
from array import array
from cffi import FFI
import os
@@ -9,21 +10,25 @@
Random new_Random_seed(int seed);
double Random_nextDouble(Random R);
double **RandomMatrix(int M, int N, Random R);
+ double *RandomVector(int N, Random R);
void SOR_execute(int M, int N,double omega, double **G, int
num_iterations);
double MonteCarlo_integrate(int Num_samples);
int LU_factor(int M, int N, double **A, int *pivot);
+ void FFT_transform(int N, double *data);
+ void FFT_inverse(int N, double *data);
""")
C = ffi.verify("""
#include <SOR.h>
#include <Random.h>
#include <MonteCarlo.h>
#include <LU.h>
+ #include <FFT.h>
""",
extra_compile_args=['-I' + os.path.join(os.getcwd(), 'scimark')],
extra_link_args=['-fPIC'],
extra_objects=[os.path.join(os.getcwd(), 'scimark', f)
- for f in ['SOR.c', 'Random.c', 'MonteCarlo.c', 'LU.c']])
+ for f in ['SOR.c', 'Random.c', 'MonteCarlo.c', 'LU.c',
'FFT.c']])
class TestWithArray2D(object):
Array = Array2D
@@ -82,4 +87,20 @@
for n in [100, 200, 500, 1000]:
assert C.MonteCarlo_integrate(n) == MonteCarlo_integrate(n)
+def test_fft():
+ rnd = C.new_Random_seed(7)
+ for n in [256, 512, 1024]:
+ data_c = C.RandomVector(n, rnd)
+ data_py = array('d', [0.0]) * n
+ for i in range(n):
+ data_py[i] = data_c[i]
+ C.FFT_transform(n, data_c)
+ FFT_transform(n, data_py)
+ for i in xrange(n):
+ assert data_py[i] == data_c[i]
+ C.FFT_inverse(n, data_c)
+ FFT_inverse(n, data_py)
+ for i in xrange(n):
+ assert data_py[i] == data_c[i]
+
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit