[Scipy-svn] r4491 - trunk/scipy/sandbox/mkufunc

scipy-svn@scip... scipy-svn@scip...
Sat Jun 28 10:40:19 CDT 2008


Author: ilan
Date: 2008-06-28 10:40:16 -0500 (Sat, 28 Jun 2008)
New Revision: 4491

Modified:
   trunk/scipy/sandbox/mkufunc/mkufunc.py
   trunk/scipy/sandbox/mkufunc/test_mkufunc.py
Log:
Moved some tests

Modified: trunk/scipy/sandbox/mkufunc/mkufunc.py
===================================================================
--- trunk/scipy/sandbox/mkufunc/mkufunc.py	2008-06-28 14:36:29 UTC (rev 4490)
+++ trunk/scipy/sandbox/mkufunc/mkufunc.py	2008-06-28 15:40:16 UTC (rev 4491)
@@ -32,6 +32,7 @@
     
     compilation is done upon initialization
     >>> x = Cfunc(sqr, signature)
+    <IGNORE_OUTPUT>
     >>> x.nin # number of input arguments
     1
     >>> x.nout # number of output arguments (must be 1 for now)
@@ -136,18 +137,6 @@
 ''' % locals()
 
 
-def test1():    
-    def sqr(x):
-        return x * x
-    #verbose = True
-    for argtypes in ([int, int], [float, float]):
-        x = Cfunc(sqr, argtypes)
-        print x.cname, x.nin, x.nout, x.sig
-        print x.cfunc()
-        print '{{{%s}}}' % x.decl()
-        print x.support_code()
-
-
 def write_pypyc(cfuncs):
     """ Given a list of Cfunc instances, write the C code containing the
     functions into a file.
@@ -248,28 +237,6 @@
                         sources=['pypy.c'])
 
 
-def test2():
-    from numpy import array
-
-    def sqr(x):
-        return x * x
-    
-    ufunc = genufunc(sqr, [
-        (float, float),
-        (int, int),
-        ])
-    
-    x = array([0.0, 1.0, 2.5, 12.0])
-    print "x =", x, x.dtype
-    y = ufunc(x)
-    print "y =", y, y.dtype
-    
-    x = array([0, 1, 2, 15])
-    print "x =", x, x.dtype
-    y = ufunc(x)
-    print "y =", y, y.dtype
-
-
 def mkufunc(arg0=[float]):
     """ The actual API function, to be used as decorator function.
         
@@ -324,19 +291,4 @@
 
 if __name__ == '__main__':
     import doctest
-    #doctest.testmod()
-    
-    test2()
-
-    exit()
-    
-
-    def sqr(x):
-        return x * x
-    
-    #sqr = mkufunc({})(sqr)
-    sqr = mkufunc([(float, float)])(sqr)
-    #sqr = mkufunc(int)(sqr)
-    #sqr = mkufunc(sqr)
-    
-    print sqr(8)
+    doctest.testmod()

Modified: trunk/scipy/sandbox/mkufunc/test_mkufunc.py
===================================================================
--- trunk/scipy/sandbox/mkufunc/test_mkufunc.py	2008-06-28 14:36:29 UTC (rev 4490)
+++ trunk/scipy/sandbox/mkufunc/test_mkufunc.py	2008-06-28 15:40:16 UTC (rev 4491)
@@ -5,13 +5,38 @@
 
 from mkufunc import Cfunc, genufunc, mkufunc
 
-def f(x):
-    return 3.2 * x * x - 18.3 * x + sin(x)
+class Internal_Tests(unittest.TestCase):
+    
+    def test_Cfunc(self):
+        def sqr(x):
+            return x * x
+        cf = Cfunc(sqr, [int, int], 42)
+        self.assertEqual(cf.nin, 1)
+        self.assertEqual(cf.nout, 1)
+        self.assertEqual(cf.cname, 'f42_pypy_g_sqr')
 
+    def test_genufunc(self):
+        def foo(x):
+            return x + 17
+        uf = genufunc(foo, [
+                (float, float),
+                (int, int),
+                ])
+        self.assertEqual(uf(4), 21)
+        x = array([1.1, 2.3])
+        y = uf(x)
+        self.assert_(allclose(y, [18.1, 19.3]))
+        self.assert_(str(y.dtype).startswith('float'))
+        
+        x = array([1, 4])
+        y = uf(x)
+        self.assertEqual(list(y), [18, 21])
+        self.assert_(str(y.dtype).startswith('int'))
+
+
 class Arg_Tests(unittest.TestCase):
     
     def check_ufunc(self, f):
-        #self.assert_(f.__type__
         for arg in (array([0.0, 1.0, 2.5]),
                     [0.0, 1.0, 2.5],
                     (0.0, 1.0, 2.5)):



More information about the Scipy-svn mailing list