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

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Oct 20 01:44:53 CDT 2006


Author: pearu
Date: 2006-10-20 01:44:43 -0500 (Fri, 20 Oct 2006)
New Revision: 3374

Modified:
   trunk/numpy/f2py/lib/main.py
   trunk/numpy/f2py/lib/py_wrap_subprogram.py
   trunk/numpy/f2py/lib/py_wrap_type.py
   trunk/numpy/f2py/lib/test_scalar_in_out.py
Log:
F2PY G3: started impl array support.

Modified: trunk/numpy/f2py/lib/main.py
===================================================================
--- trunk/numpy/f2py/lib/main.py	2006-10-20 06:43:31 UTC (rev 3373)
+++ trunk/numpy/f2py/lib/main.py	2006-10-20 06:44:43 UTC (rev 3374)
@@ -310,7 +310,7 @@
     libraries = get_values(sys_argv,'-l',strip_prefix=True)
     _define_macros = get_values(sys_argv,'-D',strip_prefix=True)
     undef_macros = get_values(sys_argv,'-U',strip_prefix=True)
-    extra_objects = get_values(sys_argv,'','[.](o|a|so|dll|dynlib|sl)')
+    extra_objects = get_values(sys_argv,'','[.](o|a|so|dll|dylib|sl)')
 
     define_macros = []
     for item in _define_macros:

Modified: trunk/numpy/f2py/lib/py_wrap_subprogram.py
===================================================================
--- trunk/numpy/f2py/lib/py_wrap_subprogram.py	2006-10-20 06:43:31 UTC (rev 3373)
+++ trunk/numpy/f2py/lib/py_wrap_subprogram.py	2006-10-20 06:44:43 UTC (rev 3374)
@@ -146,52 +146,54 @@
         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)
             if var.is_intent_in():
                 self.kw_list.append('"%s"' % (argname))
 
-            if isinstance(typedecl, TypeStmt):
-                if var.is_intent_in():
-                    self.pyarg_format_list.append('O&')
-                    self.pyarg_obj_list.append('\npyobj_to_%s_inplace, &%s' % (ti.ctype, argname))
+            if var.is_scalar():
+                if isinstance(typedecl, TypeStmt):
+                    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))
+                    args_f.append('%s->data' % (argname)) # is_scalar
+                    ctype_args_f.append(ti.ctype)
                 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))
-                args_f.append('%s->data' % (argname)) # is_scalar
-                ctype_args_f.append(ti.ctype)
+                    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':
+                        if not var.is_intent_in():
+                            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
+                        ctype_args_f.append('char*')
+                        extra_ctype_args_f.append('int')
+                        extra_args_f.append('%s.len' % argname)
+                        self.clean_frompyobj_list.append(\
+                        'if (%s.len) free(%s.data);' % (argname,argname))
+                    else:
+                        self.decl_list.append('%s %s;' % (ti.ctype, argname))
+                        args_f.append('&'+argname) # is_scalar
+                        ctype_args_f.append(ti.ctype+'*')
+                if var.is_intent_out(): # and is_scalar
+                    if isinstance(typedecl, TypeStmt):
+                        self.return_format_list.append('N')
+                        self.return_obj_list.append('\n%s' % (argname))
+                    else:
+                        self.return_format_list.append('O&')
+                        self.return_obj_list.append('\npyobj_from_%s, &%s' % (ti.ctype, argname))
             else:
-                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':
-                    if not var.is_intent_in():
-                        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
-                    ctype_args_f.append('char*')
-                    extra_ctype_args_f.append('int')
-                    extra_args_f.append('%s.len' % argname)
-                    self.clean_frompyobj_list.append(\
-                        'if (%s.len) free(%s.data);' % (argname,argname))
-                else:
-                    self.decl_list.append('%s %s;' % (ti.ctype, argname))
-                    args_f.append('&'+argname) # is_scalar
-                    ctype_args_f.append(ti.ctype+'*')
-            if var.is_intent_out(): # and is_scalar
-                if isinstance(typedecl, TypeStmt):
-                    self.return_format_list.append('N')
-                    self.return_obj_list.append('\n%s' % (argname))
-                else:
-                    self.return_format_list.append('O&')
-                    self.return_obj_list.append('\npyobj_from_%s, &%s' % (ti.ctype, argname))
+                print `ti,var.dimension,var.bounds`
+                assert var.is_scalar(),'array support not implemented: "%s"' % (var)
 
-
         self.call_list.append('%s_f(%s);' % (name,', '.join(args_f+extra_args_f)))
 
         self.ctype_args_f_list = ctype_args_f + extra_ctype_args_f

Modified: trunk/numpy/f2py/lib/py_wrap_type.py
===================================================================
--- trunk/numpy/f2py/lib/py_wrap_type.py	2006-10-20 06:43:31 UTC (rev 3373)
+++ trunk/numpy/f2py/lib/py_wrap_type.py	2006-10-20 06:44:43 UTC (rev 3374)
@@ -12,6 +12,7 @@
     def __init__(self, typedecl):
         if isinstance(typedecl, TypeStmt):
             typedecl = typedecl.get_type_decl(typedecl.name)
+        self._typedecl = typedecl
         if isinstance(typedecl, TypeDecl):
             self.name = name = typedecl.name
             tname = 'f2py_type_%s_' % (name)
@@ -37,7 +38,13 @@
             self.otype = '%sObject' % (ctype)
             self.ftype = 'TYPE(%s)' % (name)
         return
-    
+    def __repr__(self): return '%s(%r)' % (self.__class__.__name__, self._typedecl)
+    def __str__(self):
+        s = []
+        for k,v in self.__dict__.items():
+            if k.startswith('_'): continue
+            s.append('%s=%s' % (k,v))
+        return 'PyTypeInterface(%s)' % (', '.join(s))
 
 class PythonCAPIType(WrapperBase):
     """

Modified: trunk/numpy/f2py/lib/test_scalar_in_out.py
===================================================================
--- trunk/numpy/f2py/lib/test_scalar_in_out.py	2006-10-20 06:43:31 UTC (rev 3373)
+++ trunk/numpy/f2py/lib/test_scalar_in_out.py	2006-10-20 06:44:43 UTC (rev 3374)
@@ -16,7 +16,7 @@
 import sys
 from numpy.testing import *
 
-def build(fortran_code, rebuild=True):
+def build(fortran_code, rebuild=True, build_dir='tmp'):
     modulename = os.path.splitext(os.path.basename(__file__))[0]+'_ext'
     try:
         exec ('import %s as m' % (modulename))
@@ -25,21 +25,21 @@
             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)
+        assert str(msg)==('No module named %s' % (modulename)) \
+               or str(msg).startswith('%s is newer than' % (__file__)),str(msg)
         print msg, ', recompiling %s.' % (modulename)
-        import tempfile
-        fname = tempfile.mktemp() + '.f'
+        if not os.path.isdir(build_dir): os.makedirs(build_dir)
+        fname = os.path.join(build_dir,'%s_source.f' % (modulename))
         f = open(fname,'w')
         f.write(fortran_code)
         f.close()
-        sys_argv = ['--build-dir','foo']
+        sys_argv = ['--build-dir',build_dir]
         #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 = '''



More information about the Numpy-svn mailing list