[Numpy-svn] r3308 - trunk/numpy/f2py/lib

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Oct 11 07:26:06 EDT 2006


Author: pearu
Date: 2006-10-11 06:25:58 -0500 (Wed, 11 Oct 2006)
New Revision: 3308

Added:
   trunk/numpy/f2py/lib/test_scalar_function_in.py
Modified:
   trunk/numpy/f2py/lib/main.py
   trunk/numpy/f2py/lib/py_wrap.py
   trunk/numpy/f2py/lib/py_wrap_subprogram.py
   trunk/numpy/f2py/lib/py_wrap_type.py
   trunk/numpy/f2py/lib/test_derived_scalar.py
   trunk/numpy/f2py/lib/test_scalar_in_out.py
Log:
F2PY G3: Impl. scalar function support and tests.

Modified: trunk/numpy/f2py/lib/main.py
===================================================================
--- trunk/numpy/f2py/lib/main.py	2006-10-11 11:25:02 UTC (rev 3307)
+++ trunk/numpy/f2py/lib/main.py	2006-10-11 11:25:58 UTC (rev 3308)
@@ -297,9 +297,9 @@
             wrapper = PythonWrapperModule(block.name)
             wrapper.add(block)
             c_code = wrapper.c_code()
-            f_code = wrapper.fortran_code()
+            f_code = '! -*- f90 -*-\n' + wrapper.fortran_code()
             c_fn = os.path.join(build_dir,'%smodule.c' % (block.name))
-            f_fn = os.path.join(build_dir,'%s_f_wrappers_f2py.f' % (block.name))
+            f_fn = os.path.join(build_dir,'%s_f_wrappers_f2py.f90' % (block.name))
             f = open(c_fn,'w')
             f.write(c_code)
             f.close()
@@ -325,7 +325,13 @@
             c_code = wrapper.c_code()
             f_code = wrapper.fortran_code()
             c_fn = os.path.join(build_dir,'%smodule.c' % (modulename))
-            f_fn = os.path.join(build_dir,'%s_f_wrappers_f2py.f' % (modulename))
+            ext = '.f'
+            language = 'f77'
+            if wrapper.isf90:
+                f_code = '! -*- f90 -*-\n' + f_code
+                ext = '.f90'
+                language = 'f90'
+            f_fn = os.path.join(build_dir,'%s_f_wrappers_f2py%s' % (modulename, ext))
             f = open(c_fn,'w')
             f.write(c_code)
             f.close()
@@ -342,6 +348,7 @@
                                  undef_macros = undef_macros,
                                  include_dirs = include_dirs,
                                  extra_objects = extra_objects,
+                                 language = language
                                  )
         return config
 

Modified: trunk/numpy/f2py/lib/py_wrap.py
===================================================================
--- trunk/numpy/f2py/lib/py_wrap.py	2006-10-11 11:25:02 UTC (rev 3307)
+++ trunk/numpy/f2py/lib/py_wrap.py	2006-10-11 11:25:58 UTC (rev 3308)
@@ -78,7 +78,7 @@
         self.list_names = ['header', 'typedef', 'extern', 'objdecl',
                            'c_code','capi_code','module_method','module_init',
                            'fortran_code']
-
+        self.isf90 = False
         return
 
     def add(self, block):
@@ -87,12 +87,22 @@
                 self.add(moduleblock)
             #for name, subblock in block.a.external_subprogram.items():
             #    self.add(subblock)
-        elif isinstance(block, (Subroutine, Function)):
+        elif isinstance(block, Subroutine):
             PythonCAPISubProgram(self, block)
+        elif isinstance(block, Function):
+            fcode = block.subroutine_wrapper_code()
+            self.fortran_code_list.append(fcode)
+            wrapper_block = block.subroutine_wrapper()
+            PythonCAPISubProgram(self, wrapper_block)
         elif isinstance(block, Module):
+            self.isf90 = True
             for name,declblock in block.a.type_decls.items():
                 self.add(declblock)
+            for name,subblock in block.a.module_subprogram.items():
+                self.add(subblock)
         elif isinstance(block, tuple([TypeDecl]+declaration_type_spec)):
+            if isinstance(block, (TypeDecl, TypeStmt)):
+                self.isf90 = True
             PythonCAPIType(self, block)
         else:
             raise NotImplementedError,`block.__class__.__name__`

Modified: trunk/numpy/f2py/lib/py_wrap_subprogram.py
===================================================================
--- trunk/numpy/f2py/lib/py_wrap_subprogram.py	2006-10-11 11:25:02 UTC (rev 3307)
+++ trunk/numpy/f2py/lib/py_wrap_subprogram.py	2006-10-11 11:25:58 UTC (rev 3308)
@@ -24,7 +24,7 @@
 '''
     module_init_template = ''
     module_method_template = '''\
-{"%(name)s", (PyCFunction)%(cname)s, METH_VARARGS | METH_KEYWORDS, %(cname)s__doc},'''
+{"%(pyname)s", (PyCFunction)%(cname)s, METH_VARARGS | METH_KEYWORDS, %(cname)s__doc},'''
     c_code_template = ''
     capi_code_template = '''\
 static PyObject* %(cname)s(PyObject *capi_self, PyObject *capi_args, PyObject *capi_keywds) {
@@ -55,13 +55,16 @@
     _defined = []
     def __init__(self, parent, block):
         WrapperBase.__init__(self)
-        self.name = name = block.name
+        self.name = name = pyname = block.name
         self.cname = cname = '%s_%s' % (parent.cname,name)
         if cname in self._defined:
             return
         self._defined.append(cname)
         self.info('Generating interface for %s: %s' % (block.__class__, cname))
 
+        if pyname.startswith('f2pywrap_'):
+            pyname = pyname[9:]
+        self.pyname = pyname
 
         self.decl_list = []
         self.kw_list = []
@@ -85,20 +88,30 @@
         for argname in block.args:
             argindex += 1
             var = block.a.variables[argname]
+            assert var.is_scalar(),'array support not implemented: "%s"' % (var)
             typedecl = var.get_typedecl()
             PythonCAPIType(parent, typedecl)
             ti = PyTypeInterface(typedecl)
-            self.kw_list.append('"%s"' % (argname))
+            if var.is_intent_in():
+                self.kw_list.append('"%s"' % (argname))
 
             if isinstance(typedecl, TypeStmt):
-                self.pyarg_format_list.append('O&')
+                if var.is_intent_in():
+                    self.pyarg_format_list.append('O&')
+                    self.pyarg_obj_list.append('\npyobj_to_%s_inplace, &%s' % (ti.ctype, argname))
+                else:
+                    self.frompyobj_list.append('%s = (%s*)pyobj_from_%s(NULL);' % (argname,ti.otype,ti.ctype))
+                    if not var.is_intent_out():
+                        self.clean_frompyobj_list.append('Py_DECREF(%s);' % (argname))
                 self.decl_list.append('%s* %s = NULL;' % (ti.otype, argname))
-                self.pyarg_obj_list.append('\npyobj_to_%s_inplace, &%s' % (ti.ctype, argname))
                 args_f.append('%s->data' % (argname)) # is_scalar
             else:
-                self.pyarg_format_list.append('O&')
+                if var.is_intent_in():
+                    self.pyarg_format_list.append('O&')
+                    self.pyarg_obj_list.append('\npyobj_to_%s, &%s' % (ti.ctype, argname))
                 assert not isinstance(typedecl, TypeDecl)
                 if ti.ctype=='f2py_string0':
+                    assert not var.is_intent_out(),'intent(out) not implemented for "%s"' % (var)
                     self.decl_list.append('%s %s = {NULL,0};' % (ti.ctype, argname))
                     args_f.append('%s.data' % argname)  # is_scalar
                     extra_args_f.append('%s.len' % argname)
@@ -107,7 +120,7 @@
                 else:
                     self.decl_list.append('%s %s;' % (ti.ctype, argname))
                     args_f.append('&'+argname) # is_scalar
-                self.pyarg_obj_list.append('\npyobj_to_%s, &%s' % (ti.ctype, argname))
+
             if var.is_intent_out(): # and is_scalar
                 if isinstance(typedecl, TypeStmt):
                     self.return_format_list.append('N')

Modified: trunk/numpy/f2py/lib/py_wrap_type.py
===================================================================
--- trunk/numpy/f2py/lib/py_wrap_type.py	2006-10-11 11:25:02 UTC (rev 3307)
+++ trunk/numpy/f2py/lib/py_wrap_type.py	2006-10-11 11:25:58 UTC (rev 3308)
@@ -48,6 +48,7 @@
         if isinstance(typedecl, tuple(declaration_type_spec)):
             if isinstance(typedecl, TypeStmt):
                 type_decl = typedecl.get_type_decl(typedecl.name)
+                assert type_decl is not None,"%s %s" % (typedecl,typedecl.name)
                 PythonCAPIDerivedType(parent, type_decl)
             else:
                 PythonCAPIIntrinsicType(parent, typedecl)
@@ -584,6 +585,7 @@
             return
         self._defined.append(name)
         self.info('Generating interface for %s: %s' % (typedecl.__class__, name))
+        parent.isf90 = True
 
         self.name = name
         self.otype = otype = ti.otype

Modified: trunk/numpy/f2py/lib/test_derived_scalar.py
===================================================================
--- trunk/numpy/f2py/lib/test_derived_scalar.py	2006-10-11 11:25:02 UTC (rev 3307)
+++ trunk/numpy/f2py/lib/test_derived_scalar.py	2006-10-11 11:25:58 UTC (rev 3308)
@@ -25,6 +25,7 @@
             os.remove(m.__file__)
             raise ImportError,'%s is newer than %s' % (__file__, m.__file__)
     except ImportError,msg:
+        assert str(msg).startswith('No module named'),str(msg)
         print msg, ', recompiling %s.' % (modulename)
         import tempfile
         fname = tempfile.mktemp() + '.f90'
@@ -32,14 +33,14 @@
         f.write(fortran_code)
         f.close()
         sys_argv = []
-        sys_argv.extend(['--build-dir','dsctmp'])
+        sys_argv.extend(['--build-dir','tmp'])
         #sys_argv.extend(['-DF2PY_DEBUG_PYOBJ_TOFROM'])
         from main import build_extension
         sys_argv.extend(['-m',modulename, fname])
         build_extension(sys_argv)
         os.remove(fname)
-        os.system(' '.join([sys.executable] + sys.argv))
-        sys.exit(0)
+        status = os.system(' '.join([sys.executable] + sys.argv))
+        sys.exit(status)
     return m
 
 fortran_code = '''
@@ -51,6 +52,14 @@
 !f2py intent(in,out) a
   a % flag = a % flag + 1
 end
+function foo2(a)
+  type myt
+    integer flag
+  end type myt
+  type(myt) a
+  type(myt) foo2
+  foo2 % flag = a % flag + 2
+end
 '''
 
 # tester note: set rebuild=True when changing fortan_code and for SVN
@@ -69,6 +78,22 @@
         assert r is a
         assert_equal(r.flag,3)
         assert_equal(a.flag,3)
+
+        a.flag = 5
+        assert_equal(r.flag,5)
+
+        #s = m.foo((5,))
+
+    def check_foo2_simple(self, level=1):
+        a = m.myt(2)
+        assert_equal(a.flag,2)
+        assert isinstance(a,m.myt),`a`
+        r = m.foo2(a)
+        assert isinstance(r,m.myt),`r`
+        assert r is not a
+        assert_equal(a.flag,2)
+        assert_equal(r.flag,4)
+
         
 if __name__ == "__main__":
     NumpyTest().run()

Added: trunk/numpy/f2py/lib/test_scalar_function_in.py
===================================================================
--- trunk/numpy/f2py/lib/test_scalar_function_in.py	2006-10-11 11:25:02 UTC (rev 3307)
+++ trunk/numpy/f2py/lib/test_scalar_function_in.py	2006-10-11 11:25:58 UTC (rev 3308)
@@ -0,0 +1,554 @@
+#!/usr/bin/env python
+"""
+Tests for intent(in) arguments in subroutine-wrapped Fortran functions.
+
+-----
+Permission to use, modify, and distribute this software is given under the
+terms of the NumPy License. See http://scipy.org.
+
+NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
+Author: Pearu Peterson <pearu at cens.ioc.ee>
+Created: Oct 2006
+-----
+"""
+
+import os
+import sys
+from numpy.testing import *
+
+def build(fortran_code, rebuild=True):
+    modulename = os.path.splitext(os.path.basename(__file__))[0]+'_ext'
+    try:
+        exec ('import %s as m' % (modulename))
+        if rebuild and os.stat(m.__file__)[8] < os.stat(__file__)[8]:
+            del sys.modules[m.__name__] # soft unload extension module
+            os.remove(m.__file__)
+            raise ImportError,'%s is newer than %s' % (__file__, m.__file__)
+    except ImportError,msg:
+        assert str(msg).startswith('No module named'),str(msg)
+        print msg, ', recompiling %s.' % (modulename)
+        import tempfile
+        fname = tempfile.mktemp() + '.f'
+        f = open(fname,'w')
+        f.write(fortran_code)
+        f.close()
+        sys_argv = ['--build-dir','tmp']
+        #sys_argv.extend(['-DF2PY_DEBUG_PYOBJ_TOFROM'])
+        from main import build_extension
+        sys_argv.extend(['-m',modulename, fname])
+        build_extension(sys_argv)
+        os.remove(fname)
+        os.system(' '.join([sys.executable] + sys.argv))
+        sys.exit(0)
+    return m
+
+fortran_code = '''
+      function fooint1(a)
+      integer*1 a
+      integer*1 fooint1
+      fooint1 = a + 1
+      end
+      function fooint2(a)
+      integer*2 a
+      integer*2 fooint2
+      fooint2 = a + 1
+      end
+      function fooint4(a)
+      integer*4 a
+      integer*4 fooint4
+      fooint4 = a + 1
+      end
+      function fooint8(a)
+      integer*8 a
+      integer*8 fooint8
+      fooint8 = a + 1
+      end
+      function foofloat4(a)
+      real*4 a
+      real*4 foofloat4
+      foofloat4 = a + 1.0e0
+      end
+      function foofloat8(a)
+      real*8 a
+      real*8 foofloat8
+      foofloat8 = a + 1.0d0
+      end
+      function foocomplex8(a)
+      complex*8 a
+      complex*8 foocomplex8
+      foocomplex8 = a + 1.0e0
+      end
+      function foocomplex16(a)
+      complex*16 a
+      complex*16 foocomplex16
+      foocomplex16 = a + 1.0d0
+      end
+      function foobool1(a)
+      logical*1 a
+      logical*1 foobool1
+      foobool1 = .not. a
+      end
+      function foobool2(a)
+      logical*2 a
+      logical*2 foobool2
+      foobool2 = .not. a
+      end
+      function foobool4(a)
+      logical*4 a
+      logical*4 foobool4
+      foobool4 = .not. a
+      end
+      function foobool8(a)
+      logical*8 a
+      logical*8 foobool8
+      foobool8 = .not. a
+      end
+      function foostring1(a)
+      character*1 a
+      character*1 foostring1
+      foostring1 = "1"
+      end
+      function foostring5(a)
+      character*5 a
+      character*5 foostring5
+      foostring5 = a
+      foostring5(1:2) = "12"
+      end
+!      function foostringstar(a)
+!      character*(*) a
+!      character*(*) foostringstar
+!      if (len(a).gt.0) then
+!        foostringstar = a
+!        foostringstar(1:1) = "1"
+!      endif
+!      end
+'''
+
+# tester note: set rebuild=True when changing fortan_code and for SVN
+m = build(fortran_code, rebuild=True)
+
+from numpy import *
+
+class test_m(NumpyTestCase):
+
+    def check_foo_integer1(self, level=1):
+        i = int8(2)
+        e = int8(3)
+        func = m.fooint1
+        assert isinstance(i,int8),`type(i)`
+        r = func(i)
+        assert isinstance(r,int8),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        r = func(2)
+        assert isinstance(r,int8),`type(r)`
+        assert_equal(r,e)
+
+        for intx in [int64,int16,int32]:
+            r = func(intx(2))
+            assert isinstance(r,int8),`type(r)`
+            assert_equal(r,e)
+
+        r = func(2.0)
+        assert isinstance(r,int8),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.2)
+        assert isinstance(r,int8),`type(r)`
+        assert_equal(r,e)
+
+        r = func([2])
+        assert isinstance(r,int8),`type(r)`
+        assert_equal(r,e)
+
+        self.assertRaises(TypeError,lambda :func(2.2j))
+        self.assertRaises(TypeError,lambda :func([2,1]))
+        self.assertRaises(TypeError,lambda :func({}))
+
+    def check_foo_integer2(self, level=1):
+        i = int16(2)
+        e = int16(3)
+        func = m.fooint2
+        assert isinstance(i,int16),`type(i)`
+        r = func(i)
+        assert isinstance(r,int16),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        r = func(2)
+        assert isinstance(r,int16),`type(r)`
+        assert_equal(r,e)
+
+        for intx in [int8,int64,int32]:
+            r = func(intx(2))
+            assert isinstance(r,int16),`type(r)`
+            assert_equal(r,e)
+
+        r = func(2.0)
+        assert isinstance(r,int16),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.2)
+        assert isinstance(r,int16),`type(r)`
+        assert_equal(r,e)
+
+        r = func([2])
+        assert isinstance(r,int16),`type(r)`
+        assert_equal(r,e)
+
+        self.assertRaises(TypeError,lambda :func(2.2j))
+        self.assertRaises(TypeError,lambda :func([2,1]))
+        self.assertRaises(TypeError,lambda :func({}))
+
+    def check_foo_integer4(self, level=1):
+        i = int32(2)
+        e = int32(3)
+        func = m.fooint4
+        assert isinstance(i,int32),`type(i)`
+        r = func(i)
+        assert isinstance(r,int32),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        r = func(2)
+        assert isinstance(r,int32),`type(r)`
+        assert_equal(r,e)
+
+        for intx in [int8,int16,int64]:
+            r = func(intx(2))
+            assert isinstance(r,int32),`type(r)`
+            assert_equal(r,e)
+
+        r = func(2.0)
+        assert isinstance(r,int32),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.2)
+        assert isinstance(r,int32),`type(r)`
+        assert_equal(r,e)
+
+        r = func([2])
+        assert isinstance(r,int32),`type(r)`
+        assert_equal(r,e)
+
+        self.assertRaises(TypeError,lambda :func(2.2j))
+        self.assertRaises(TypeError,lambda :func([2,1]))
+        self.assertRaises(TypeError,lambda :func({}))
+
+    def check_foo_integer8(self, level=1):
+        i = int64(2)
+        e = int64(3)
+        func = m.fooint8
+        assert isinstance(i,int64),`type(i)`
+        r = func(i)
+        assert isinstance(r,int64),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        r = func(2)
+        assert isinstance(r,int64),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.0)
+        assert isinstance(r,int64),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.2)
+        assert isinstance(r,int64),`type(r)`
+        assert_equal(r,e)
+
+        for intx in [int8,int16,int32]:
+            r = func(intx(2))
+            assert isinstance(r,int64),`type(r)`
+            assert_equal(r,e)
+
+        r = func([2])
+        assert isinstance(r,int64),`type(r)`
+        assert_equal(r,e)
+
+        self.assertRaises(TypeError,lambda :func(2.2j))
+        self.assertRaises(TypeError,lambda :func([2,1]))
+        self.assertRaises(TypeError,lambda :func({}))
+
+    def check_foo_real4(self, level=1):
+        i = float32(2)
+        e = float32(3)
+        func = m.foofloat4
+        assert isinstance(i,float32),`type(i)`
+        r = func(i)
+        assert isinstance(r,float32),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        r = func(2)
+        assert isinstance(r,float32),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.0)
+        assert isinstance(r,float32),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.2)
+        assert isinstance(r,float32),`type(r)`
+        assert_equal(r,e+float32(0.2))
+
+        r = func(float64(2.0))
+        assert isinstance(r,float32),`type(r)`
+        assert_equal(r,e)
+
+        r = func([2])
+        assert isinstance(r,float32),`type(r)`
+        assert_equal(r,e)
+
+        self.assertRaises(TypeError,lambda :func(2.2j))
+        self.assertRaises(TypeError,lambda :func([2,1]))
+        self.assertRaises(TypeError,lambda :func({}))
+
+    def check_foo_real8(self, level=1):
+        i = float64(2)
+        e = float64(3)
+        func = m.foofloat8
+        assert isinstance(i,float64),`type(i)`
+        r = func(i)
+        assert isinstance(r,float64),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        r = func(2)
+        assert isinstance(r,float64),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.0)
+        assert isinstance(r,float64),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.2)
+        assert isinstance(r,float64),`type(r)`
+        assert_equal(r,e+float64(0.2))
+
+        r = func(float32(2.0))
+        assert isinstance(r,float64),`type(r)`
+        assert_equal(r,e)
+
+        r = func([2])
+        assert isinstance(r,float64),`type(r)`
+        assert_equal(r,e)
+
+        self.assertRaises(TypeError,lambda :func(2.2j))
+        self.assertRaises(TypeError,lambda :func([2,1]))
+        self.assertRaises(TypeError,lambda :func({}))
+
+    def check_foo_complex8(self, level=1):
+        i = complex64(2)
+        e = complex64(3)
+        func = m.foocomplex8
+        assert isinstance(i,complex64),`type(i)`
+        r = func(i)
+        assert isinstance(r,complex64),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        r = func(2)
+        assert isinstance(r,complex64),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.0)
+        assert isinstance(r,complex64),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.2)
+        assert isinstance(r,complex64),`type(r)`
+        assert_equal(r,e+complex64(0.2))
+
+        r = func(2+1j)
+        assert isinstance(r,complex64),`type(r)`
+        assert_equal(r,e+complex64(1j))
+
+        r = func(complex128(2.0))
+        assert isinstance(r,complex64),`type(r)`
+        assert_equal(r,e)
+
+        r = func([2])
+        assert isinstance(r,complex64),`type(r)`
+        assert_equal(r,e)
+
+        r = func([2,3])
+        assert isinstance(r,complex64),`type(r)`
+        assert_equal(r,e+complex64(3j))
+
+        self.assertRaises(TypeError,lambda :func([2,1,3]))
+        self.assertRaises(TypeError,lambda :func({}))
+
+    def check_foo_complex16(self, level=1):
+        i = complex128(2)
+        e = complex128(3)
+        func = m.foocomplex16
+        assert isinstance(i,complex128),`type(i)`
+        r = func(i)
+        assert isinstance(r,complex128),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        r = func(2)
+        assert isinstance(r,complex128),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.0)
+        assert isinstance(r,complex128),`type(r)`
+        assert_equal(r,e)
+
+        r = func(2.2)
+        assert isinstance(r,complex128),`type(r)`
+        assert_equal(r,e+complex128(0.2))
+
+        r = func(2+1j)
+        assert isinstance(r,complex128),`type(r)`
+        assert_equal(r,e+complex128(1j))
+
+        r = func([2])
+        assert isinstance(r,complex128),`type(r)`
+        assert_equal(r,e)
+
+        r = func([2,3])
+        assert isinstance(r,complex128),`type(r)`
+        assert_equal(r,e+complex128(3j))
+
+        r = func(complex64(2.0))
+        assert isinstance(r,complex128),`type(r)`
+        assert_equal(r,e)
+
+        self.assertRaises(TypeError,lambda :func([2,1,3]))
+        self.assertRaises(TypeError,lambda :func({}))
+
+    def check_foo_bool1(self, level=1):
+        i = bool8(True)
+        e = bool8(False)
+        func = m.foobool1
+        assert isinstance(i,bool8),`type(i)`
+        r = func(i)
+        assert isinstance(r,bool8),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        for tv in [1,2,2.1,-1j,[0],True]:
+            r = func(tv)
+            assert isinstance(r,bool8),`type(r)`
+            assert_equal(r,e)
+
+        for fv in [0,0.0,0j,False,(),{},[]]:
+            r = func(fv)
+            assert isinstance(r,bool8),`type(r)`
+            assert_equal(r,not e)
+
+    def check_foo_bool2(self, level=1):
+        i = bool8(True)
+        e = bool8(False)
+        func = m.foobool2
+        assert isinstance(i,bool8),`type(i)`
+        r = func(i)
+        assert isinstance(r,bool8),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        for tv in [1,2,2.1,-1j,[0],True]:
+            r = func(tv)
+            assert isinstance(r,bool8),`type(r)`
+            assert_equal(r,e)
+
+        for fv in [0,0.0,0j,False,(),{},[]]:
+            r = func(fv)
+            assert isinstance(r,bool8),`type(r)`
+            assert_equal(r,not e)
+
+    def check_foo_bool4(self, level=1):
+        i = bool8(True)
+        e = bool8(False)
+        func = m.foobool4
+        assert isinstance(i,bool8),`type(i)`
+        r = func(i)
+        assert isinstance(r,bool8),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        for tv in [1,2,2.1,-1j,[0],True]:
+            r = func(tv)
+            assert isinstance(r,bool8),`type(r)`
+            assert_equal(r,e)
+
+        for fv in [0,0.0,0j,False,(),{},[]]:
+            r = func(fv)
+            assert isinstance(r,bool8),`type(r)`
+            assert_equal(r,not e)
+
+    def check_foo_bool8(self, level=1):
+        i = bool8(True)
+        e = bool8(False)
+        func = m.foobool8
+        assert isinstance(i,bool8),`type(i)`
+        r = func(i)
+        assert isinstance(r,bool8),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        for tv in [1,2,2.1,-1j,[0],True]:
+            r = func(tv)
+            assert isinstance(r,bool8),`type(r)`
+            assert_equal(r,e)
+
+        for fv in [0,0.0,0j,False,(),{},[]]:
+            r = func(fv)
+            assert isinstance(r,bool8),`type(r)`
+            assert_equal(r,not e)
+
+    def check_foo_string1(self, level=1):
+        i = string0('a')
+        e = string0('1')
+        func = m.foostring1
+        assert isinstance(i,string0),`type(i)`
+        r = func(i)
+        assert isinstance(r,string0),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        r = func('ab')
+        assert isinstance(r,string0),`type(r)`
+        assert_equal(r,e)
+
+        r = func('')
+        assert isinstance(r,string0),`type(r)`
+        assert_equal(r,e)
+
+    def check_foo_string5(self, level=1):
+        i = string0('abcde')
+        e = string0('12cde')
+        func = m.foostring5
+        assert isinstance(i,string0),`type(i)`
+        r = func(i)
+        assert isinstance(r,string0),`type(r)`
+        assert i is not r,`id(i),id(r)`
+        assert_equal(r,e)
+
+        r = func('abc')
+        assert isinstance(r,string0),`type(r)`
+        assert_equal(r,'12c  ')
+
+        r = func('abcdefghi')
+        assert isinstance(r,string0),`type(r)`
+        assert_equal(r,'12cde')
+
+        r = func([1])
+        assert isinstance(r,string0),`type(r)`
+        assert_equal(r,'12]  ')
+
+    def _check_foo_string0(self, level=1):
+        i = string0('abcde')
+        e = string0('12cde')
+        func = m.foostringstar
+        r = func('abcde')
+        assert_equal(r,'1bcde')
+        r = func('')
+        assert_equal(r,'')
+        
+if __name__ == "__main__":
+    NumpyTest().run()

Modified: trunk/numpy/f2py/lib/test_scalar_in_out.py
===================================================================
--- trunk/numpy/f2py/lib/test_scalar_in_out.py	2006-10-11 11:25:02 UTC (rev 3307)
+++ trunk/numpy/f2py/lib/test_scalar_in_out.py	2006-10-11 11:25:58 UTC (rev 3308)
@@ -25,6 +25,7 @@
             os.remove(m.__file__)
             raise ImportError,'%s is newer than %s' % (__file__, m.__file__)
     except ImportError,msg:
+        assert str(msg).startswith('No module named'),str(msg)
         print msg, ', recompiling %s.' % (modulename)
         import tempfile
         fname = tempfile.mktemp() + '.f'




More information about the Numpy-svn mailing list