[pypy-svn] pypy numpy-exp: Add a standalone numpy target

fijal commits-noreply at bitbucket.org
Sun Feb 13 16:16:12 CET 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-exp
Changeset: r41882:3f25b6bccdd4
Date: 2011-02-12 20:46 +0200
http://bitbucket.org/pypy/pypy/changeset/3f25b6bccdd4/

Log:	Add a standalone numpy target

diff --git a/pypy/translator/goal/targetnumpystandalone.py b/pypy/translator/goal/targetnumpystandalone.py
new file mode 100644
--- /dev/null
+++ b/pypy/translator/goal/targetnumpystandalone.py
@@ -0,0 +1,55 @@
+
+""" Usage:
+
+./targetnumpystandalone-c <bytecode> array_size
+
+Will execute a give numpy bytecode. Arrays will be ranges (in float) modulo 10,
+constants would be consecutive starting from one.
+
+Bytecode should contain letters 'a' 'l' and 'f' so far and be correct
+"""
+
+import time
+from pypy.module.micronumpy.numarray import SingleDimArray, compute
+from pypy.jit.codewriter.policy import JitPolicy
+
+def create_array(size):
+    a = SingleDimArray(size)
+    for i in range(size):
+        a.storage[i] = float(i % 10)
+    return a
+
+def entry_point(argv):
+    if len(argv) == 2:
+        print __doc__
+        return 1
+    bytecode = argv[1]
+    for b in bytecode:
+        if b not in 'alf':
+            print "WRONG BYTECODE"
+            print __doc__
+            return 2
+    try:
+        size = int(argv[2])
+    except ValueError:
+        print "INVALID LITERAL FOR INT:", argv[2]
+        print __doc__
+        return 3
+    no_arrays = bytecode.count('l')
+    no_floats = bytecode.count('f')
+    arrays = []
+    floats = []
+    for i in range(no_arrays):
+        arrays.append(create_array(size))
+    for i in range(no_floats):
+        floats.append(float(i + 1))
+    t0 = time.time()
+    compute(bytecode, arrays)
+    print "TOOK:", time.time() - t0
+    return 0
+
+def target(*args):
+    return entry_point, None
+
+def jitpolicy(driver):
+    return JitPolicy()


More information about the Pypy-commit mailing list