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

scipy-svn@scip... scipy-svn@scip...
Fri Jun 27 08:24:25 CDT 2008


Author: ilan
Date: 2008-06-27 08:24:23 -0500 (Fri, 27 Jun 2008)
New Revision: 4485

Added:
   trunk/scipy/sandbox/mkufunc/test_mkufunc.py
Modified:
   trunk/scipy/sandbox/mkufunc/mkufunc.py
Log:
Started unittest suite and other small changes

Modified: trunk/scipy/sandbox/mkufunc/mkufunc.py
===================================================================
--- trunk/scipy/sandbox/mkufunc/mkufunc.py	2008-06-27 03:04:21 UTC (rev 4484)
+++ trunk/scipy/sandbox/mkufunc/mkufunc.py	2008-06-27 13:24:23 UTC (rev 4485)
@@ -49,12 +49,11 @@
 
     Methods:
 
-        decl()          -- returns the C declaration for the function
-        cfunc()         -- returns the C function (as string)
-        support_code()  -- generate the C support code to make this
-                           function part work with PyUFuncGenericFunction
-        
-    
+        decl()      -- returns the C declaration for the function
+        cfunc()     -- returns the C function (as string)
+        ufunc_support_code()
+                    -- generate the C support code to make this
+                       function part work with PyUFuncGenericFunction
     """
     def __init__(self, f, signature):
         global _cnt
@@ -66,7 +65,7 @@
         assert self.nout == 1                  # for now
         
         if not verbose:
-            rem = sys.stderr
+            tmp = sys.stderr
             sys.stderr = cStringIO.StringIO()
             
         t = Translation(f, backend='c')
@@ -74,8 +73,8 @@
         t.source()
     
         if not verbose:
-            sys.stderr = rem
-    
+            sys.stderr = tmp
+        
         c_source_filename = t.driver.c_source_filename
         assert c_source_filename.endswith('.c')
         src = open(c_source_filename, 'r').read()
@@ -105,7 +104,7 @@
         return found[0]
 
 
-    def support_code(self):
+    def ufunc_support_code(self):
         arg0type = typedict[self.sig[0]][1]
         rettype = typedict[self.sig[-1]][1]
         n = self.n
@@ -186,7 +185,7 @@
     
     declarations = ''.join('\t%s\n' % cf.decl() for cf in cfuncs)
 
-    func_support = ''.join(cf.support_code() for cf in cfuncs)
+    func_support = ''.join(cf.ufunc_support_code() for cf in cfuncs)
 
     pyufuncs = ''.join('\tPyUFunc_%i,\n' % cf.n for cf in cfuncs)
     
@@ -276,7 +275,7 @@
     """ The actual API function, to be used as decorator function.
         
     """
-    print 'signatures', signatures
+    #print 'signatures', signatures
     
     class Compile(object):
         

Added: trunk/scipy/sandbox/mkufunc/test_mkufunc.py
===================================================================
--- trunk/scipy/sandbox/mkufunc/test_mkufunc.py	2008-06-27 03:04:21 UTC (rev 4484)
+++ trunk/scipy/sandbox/mkufunc/test_mkufunc.py	2008-06-27 13:24:23 UTC (rev 4485)
@@ -0,0 +1,22 @@
+import math
+from math import sin, cos, pi
+import unittest
+
+from numpy import array, arange, allclose
+
+from mkufunc import Cfunc, genufunc, mkufunc
+
+
+class Math_Tests(unittest.TestCase):
+    
+    def test_sin(self):
+        @mkufunc([(float, float)])
+        def u_sin(x):
+            return sin(x)
+
+        x = 1.23
+        self.assert_(u_sin(x), sin(x))
+
+
+if __name__ == '__main__':
+    unittest.main()



More information about the Scipy-svn mailing list