Author: Hakan Ardo <ha...@debian.org>
Branch: extradoc
Changeset: r4520:c3a95500c278
Date: 2012-08-12 09:20 +0200
http://bitbucket.org/pypy/extradoc/changeset/c3a95500c278/

Log:    test for SOR

diff --git a/talk/iwtc11/benchmarks/convolution/convolution.py 
b/talk/iwtc11/benchmarks/convolution/convolution.py
--- a/talk/iwtc11/benchmarks/convolution/convolution.py
+++ b/talk/iwtc11/benchmarks/convolution/convolution.py
@@ -32,10 +32,12 @@
     return 'conv5(array(1e%d))' % log10(100000000/n)
 
 class Array2D(object):
-    def __init__(self, w, h):
+    def __init__(self, w, h, data=None):
         self.width = w
         self.height = h
         self.data = array('d', [0]) * (w*h)
+        if data is not None:
+            self.setup(data)
 
     def _idx(self, x, y):
         if 0 <= x < self.width and 0 <= y < self.height:
@@ -57,6 +59,11 @@
                 self[x, y] = data[y][x]
         return self
 
+    def indexes(self):
+        for y in xrange(self.height):
+            for x in xrange(self.width):
+                yield x, y
+
 class NumpyArray(Array2D):
     def __init__(self, w, h):
         self.width = w
diff --git a/talk/iwtc11/benchmarks/test_scimark.py 
b/talk/iwtc11/benchmarks/test_scimark.py
new file mode 100644
--- /dev/null
+++ b/talk/iwtc11/benchmarks/test_scimark.py
@@ -0,0 +1,30 @@
+from scimark import SOR_execute, Array2D
+from cffi import FFI
+import os
+
+ffi = FFI()
+ffi.cdef("""
+    typedef struct {...;} Random_struct, *Random;
+    Random new_Random_seed(int seed);
+    double **RandomMatrix(int M, int N, Random R);
+    void SOR_execute(int M, int N,double omega, double **G, int 
num_iterations);
+    """)
+C = ffi.verify("""
+    #include <SOR.h>
+    #include <Random.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']])
+
+def test_SOR():
+    width, height = 5, 7
+    rnd = C.new_Random_seed(7)
+    a = C.RandomMatrix(height, width, rnd)
+    b = Array2D(width, height, data=a)
+    C.SOR_execute(height, width, 1.25, a, 42)
+    SOR_execute(1.25, b, 42)
+    for x, y in b.indexes():
+        assert a[y][x] == b[x, y]
+
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to