[Numpy-svn] r8273 - in trunk/numpy/f2py: . tests tests/array_from_pyobj tests/array_from_pyobj/tests tests/c tests/f77 tests/f90 tests/mixed tests/src tests/src/array_from_pyobj tests/src/mixed
numpy-svn at scipy.org
numpy-svn at scipy.org
Sat Mar 6 14:10:14 EST 2010
Author: ptvirtan
Date: 2010-03-06 13:10:14 -0600 (Sat, 06 Mar 2010)
New Revision: 8273
Added:
trunk/numpy/f2py/tests/src/
trunk/numpy/f2py/tests/src/array_from_pyobj/
trunk/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c
trunk/numpy/f2py/tests/src/mixed/
trunk/numpy/f2py/tests/src/mixed/foo.f
trunk/numpy/f2py/tests/src/mixed/foo_fixed.f90
trunk/numpy/f2py/tests/src/mixed/foo_free.f90
trunk/numpy/f2py/tests/test_array_from_pyobj.py
trunk/numpy/f2py/tests/test_callback.py
trunk/numpy/f2py/tests/test_mixed.py
trunk/numpy/f2py/tests/test_return_character.py
trunk/numpy/f2py/tests/test_return_complex.py
trunk/numpy/f2py/tests/test_return_integer.py
trunk/numpy/f2py/tests/test_return_logical.py
trunk/numpy/f2py/tests/test_return_real.py
trunk/numpy/f2py/tests/util.py
Removed:
trunk/numpy/f2py/tests/array_from_pyobj/__init__.py
trunk/numpy/f2py/tests/array_from_pyobj/setup.py
trunk/numpy/f2py/tests/array_from_pyobj/tests/test_array_from_pyobj.py
trunk/numpy/f2py/tests/array_from_pyobj/wrapmodule.c
trunk/numpy/f2py/tests/c/return_real.py
trunk/numpy/f2py/tests/f77/callback.py
trunk/numpy/f2py/tests/f77/return_character.py
trunk/numpy/f2py/tests/f77/return_complex.py
trunk/numpy/f2py/tests/f77/return_integer.py
trunk/numpy/f2py/tests/f77/return_logical.py
trunk/numpy/f2py/tests/f77/return_real.py
trunk/numpy/f2py/tests/f90/return_character.py
trunk/numpy/f2py/tests/f90/return_complex.py
trunk/numpy/f2py/tests/f90/return_integer.py
trunk/numpy/f2py/tests/f90/return_logical.py
trunk/numpy/f2py/tests/f90/return_real.py
trunk/numpy/f2py/tests/mixed/foo.f
trunk/numpy/f2py/tests/mixed/foo_fixed.f90
trunk/numpy/f2py/tests/mixed/foo_free.f90
trunk/numpy/f2py/tests/mixed/run.py
trunk/numpy/f2py/tests/run_all.py
Modified:
trunk/numpy/f2py/setup.py
Log:
ENH: f2py: convert test suite to Nose form
Rewrite F2Py's test suite, so that it is run as a part of Numpy's tests.
These tests require compiling extension modules on-the-fly, so I added
a small helper module for that.
Modified: trunk/numpy/f2py/setup.py
===================================================================
--- trunk/numpy/f2py/setup.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/setup.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -31,6 +31,7 @@
config = Configuration('f2py', parent_package, top_path)
config.add_data_dir('docs')
+ config.add_data_dir('tests')
config.add_data_files('src/fortranobject.c',
'src/fortranobject.h',
Deleted: trunk/numpy/f2py/tests/array_from_pyobj/__init__.py
===================================================================
Deleted: trunk/numpy/f2py/tests/array_from_pyobj/setup.py
===================================================================
--- trunk/numpy/f2py/tests/array_from_pyobj/setup.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/array_from_pyobj/setup.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,25 +0,0 @@
-import os
-def configuration(parent_name='',top_path=None):
- from numpy.distutils.misc_util import Configuration
-
- config = Configuration('array_from_pyobj',parent_name,top_path)
- #import numpy.f2py as f2py
- #f2pydir=os.path.dirname(os.path.abspath(f2py.__file__))
- f2pydir=os.path.join(config.local_path,'..','..')
- fobjhsrc = os.path.join(f2pydir,'src','fortranobject.h')
- fobjcsrc = os.path.join(f2pydir,'src','fortranobject.c')
- config.add_extension('wrap',
- sources = ['wrapmodule.c',fobjcsrc],
- include_dirs = [os.path.dirname(fobjhsrc)],
- depends = [fobjhsrc,fobjcsrc],
- define_macros = [('DEBUG_COPY_ND_ARRAY',1),
- #('F2PY_REPORT_ON_ARRAY_COPY',1),
- #('F2PY_REPORT_ATEXIT',1)
- ]
- )
-
- return config
-
-if __name__ == "__main__":
- from numpy.distutils.core import setup
- setup(configuration=configuration)
Deleted: trunk/numpy/f2py/tests/array_from_pyobj/tests/test_array_from_pyobj.py
===================================================================
--- trunk/numpy/f2py/tests/array_from_pyobj/tests/test_array_from_pyobj.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/array_from_pyobj/tests/test_array_from_pyobj.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,513 +0,0 @@
-import unittest
-import sys
-import copy
-
-from numpy.testing import *
-from numpy import array, alltrue, ndarray, asarray, can_cast,zeros, dtype
-from numpy.core.multiarray import typeinfo
-from array_from_pyobj import wrap
-
-def flags_info(arr):
- flags = wrap.array_attrs(arr)[6]
- return flags2names(flags)
-
-def flags2names(flags):
- info = []
- for flagname in ['CONTIGUOUS','FORTRAN','OWNDATA','ENSURECOPY',
- 'ENSUREARRAY','ALIGNED','NOTSWAPPED','WRITEABLE',
- 'UPDATEIFCOPY','BEHAVED','BEHAVED_RO',
- 'CARRAY','FARRAY'
- ]:
- if abs(flags) & getattr(wrap,flagname):
- info.append(flagname)
- return info
-
-class Intent:
- def __init__(self,intent_list=[]):
- self.intent_list = intent_list[:]
- flags = 0
- for i in intent_list:
- if i=='optional':
- flags |= wrap.F2PY_OPTIONAL
- else:
- flags |= getattr(wrap,'F2PY_INTENT_'+i.upper())
- self.flags = flags
- def __getattr__(self,name):
- name = name.lower()
- if name=='in_': name='in'
- return self.__class__(self.intent_list+[name])
- def __str__(self):
- return 'intent(%s)' % (','.join(self.intent_list))
- def __repr__(self):
- return 'Intent(%r)' % (self.intent_list)
- def is_intent(self,*names):
- for name in names:
- if name not in self.intent_list:
- return False
- return True
- def is_intent_exact(self,*names):
- return len(self.intent_list)==len(names) and self.is_intent(*names)
-
-intent = Intent()
-
-class Type(object):
-
- _type_names = ['BOOL','BYTE','UBYTE','SHORT','USHORT','INT','UINT',
- 'LONG','ULONG','LONGLONG','ULONGLONG',
- 'FLOAT','DOUBLE','LONGDOUBLE','CFLOAT','CDOUBLE',
- 'CLONGDOUBLE']
- _type_cache = {}
-
- _cast_dict = {'BOOL':['BOOL']}
- _cast_dict['BYTE'] = _cast_dict['BOOL'] + ['BYTE']
- _cast_dict['UBYTE'] = _cast_dict['BOOL'] + ['UBYTE']
- _cast_dict['BYTE'] = ['BYTE']
- _cast_dict['UBYTE'] = ['UBYTE']
- _cast_dict['SHORT'] = _cast_dict['BYTE'] + ['UBYTE','SHORT']
- _cast_dict['USHORT'] = _cast_dict['UBYTE'] + ['BYTE','USHORT']
- _cast_dict['INT'] = _cast_dict['SHORT'] + ['USHORT','INT']
- _cast_dict['UINT'] = _cast_dict['USHORT'] + ['SHORT','UINT']
-
- _cast_dict['LONG'] = _cast_dict['INT'] + ['LONG']
- _cast_dict['ULONG'] = _cast_dict['UINT'] + ['ULONG']
-
- _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['LONGLONG']
- _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['ULONGLONG']
-
- _cast_dict['FLOAT'] = _cast_dict['SHORT'] + ['USHORT','FLOAT']
- _cast_dict['DOUBLE'] = _cast_dict['INT'] + ['UINT','FLOAT','DOUBLE']
- _cast_dict['LONGDOUBLE'] = _cast_dict['LONG'] + ['ULONG','FLOAT','DOUBLE','LONGDOUBLE']
-
- _cast_dict['CFLOAT'] = _cast_dict['FLOAT'] + ['CFLOAT']
- _cast_dict['CDOUBLE'] = _cast_dict['DOUBLE'] + ['CFLOAT','CDOUBLE']
- _cast_dict['CLONGDOUBLE'] = _cast_dict['LONGDOUBLE'] + ['CFLOAT','CDOUBLE','CLONGDOUBLE']
-
-
- def __new__(cls,name):
- if isinstance(name,dtype):
- dtype0 = name
- name = None
- for n,i in typeinfo.items():
- if isinstance(i,tuple) and dtype0.type is i[-1]:
- name = n
- break
- obj = cls._type_cache.get(name.upper(),None)
- if obj is not None:
- return obj
- obj = object.__new__(cls)
- obj._init(name)
- cls._type_cache[name.upper()] = obj
- return obj
-
- def _init(self,name):
- self.NAME = name.upper()
- self.type_num = getattr(wrap,'PyArray_'+self.NAME)
- assert_equal(self.type_num,typeinfo[self.NAME][1])
- self.dtype = typeinfo[self.NAME][-1]
- self.elsize = typeinfo[self.NAME][2] / 8
- self.dtypechar = typeinfo[self.NAME][0]
-
- def cast_types(self):
- return map(self.__class__,self._cast_dict[self.NAME])
-
- def all_types(self):
- return map(self.__class__,self._type_names)
-
- def smaller_types(self):
- bits = typeinfo[self.NAME][3]
- types = []
- for name in self._type_names:
- if typeinfo[name][3]<bits:
- types.append(Type(name))
- return types
-
- def equal_types(self):
- bits = typeinfo[self.NAME][3]
- types = []
- for name in self._type_names:
- if name==self.NAME: continue
- if typeinfo[name][3]==bits:
- types.append(Type(name))
- return types
-
- def larger_types(self):
- bits = typeinfo[self.NAME][3]
- types = []
- for name in self._type_names:
- if typeinfo[name][3]>bits:
- types.append(Type(name))
- return types
-
-class Array:
- def __init__(self,typ,dims,intent,obj):
- self.type = typ
- self.dims = dims
- self.intent = intent
- self.obj_copy = copy.deepcopy(obj)
- self.obj = obj
-
- # arr.dtypechar may be different from typ.dtypechar
- self.arr = wrap.call(typ.type_num,dims,intent.flags,obj)
-
- self.arr_attr = wrap.array_attrs(self.arr)
-
- if len(dims)>1:
- if self.intent.is_intent('c'):
- assert intent.flags & wrap.F2PY_INTENT_C
- assert not self.arr.flags['FORTRAN'],`self.arr.flags,obj.flags`
- assert self.arr.flags['CONTIGUOUS']
- assert not self.arr_attr[6] & wrap.FORTRAN
- else:
- assert not intent.flags & wrap.F2PY_INTENT_C
- assert self.arr.flags['FORTRAN']
- assert not self.arr.flags['CONTIGUOUS']
- assert self.arr_attr[6] & wrap.FORTRAN
-
- if obj is None:
- self.pyarr = None
- self.pyarr_attr = None
- return
-
- if intent.is_intent('cache'):
- assert isinstance(obj,ndarray),`type(obj)`
- self.pyarr = array(obj).reshape(*dims)
-
- else:
- self.pyarr = array(array(obj,
- dtype = typ.dtypechar).reshape(*dims),
- fortran=not self.intent.is_intent('c'))
- assert self.pyarr.dtype.char==typ.dtypechar,\
- `self.pyarr.dtype.char,typ.dtypechar`
- assert self.pyarr.flags['OWNDATA']
- self.pyarr_attr = wrap.array_attrs(self.pyarr)
-
- if len(dims)>1:
- if self.intent.is_intent('c'):
- assert not self.pyarr.flags['FORTRAN']
- assert self.pyarr.flags['CONTIGUOUS']
- assert not self.pyarr_attr[6] & wrap.FORTRAN
- else:
- assert self.pyarr.flags['FORTRAN']
- assert not self.pyarr.flags['CONTIGUOUS']
- assert self.pyarr_attr[6] & wrap.FORTRAN
-
-
- assert self.arr_attr[1]==self.pyarr_attr[1] # nd
- assert self.arr_attr[2]==self.pyarr_attr[2] # dimensions
- if self.arr_attr[1]<=1:
- assert self.arr_attr[3]==self.pyarr_attr[3],\
- `self.arr_attr[3],self.pyarr_attr[3],self.arr.tostring(),self.pyarr.tostring()` # strides
- assert self.arr_attr[5][-2:]==self.pyarr_attr[5][-2:],\
- `self.arr_attr[5],self.pyarr_attr[5]` # descr
- assert self.arr_attr[6]==self.pyarr_attr[6],\
- `self.arr_attr[6],self.pyarr_attr[6],flags2names(0*self.arr_attr[6]-self.pyarr_attr[6]),flags2names(self.arr_attr[6]),intent` # flags
-
- if intent.is_intent('cache'):
- assert self.arr_attr[5][3]>=self.type.elsize,\
- `self.arr_attr[5][3],self.type.elsize`
- else:
- assert self.arr_attr[5][3]==self.type.elsize,\
- `self.arr_attr[5][3],self.type.elsize`
- assert self.arr_equal(self.pyarr,self.arr)
-
- if isinstance(self.obj,ndarray):
- if typ.elsize==Type(obj.dtype).elsize:
- if not intent.is_intent('copy') and self.arr_attr[1]<=1:
- assert self.has_shared_memory()
-
- def arr_equal(self,arr1,arr2):
- if arr1.shape != arr2.shape:
- return False
- s = arr1==arr2
- return alltrue(s.flatten())
-
- def __str__(self):
- return str(self.arr)
-
- def has_shared_memory(self):
- """Check that created array shares data with input array.
- """
- if self.obj is self.arr:
- return True
- if not isinstance(self.obj,ndarray):
- return False
- obj_attr = wrap.array_attrs(self.obj)
- return obj_attr[0]==self.arr_attr[0]
-
-##################################################
-
-class test_intent(unittest.TestCase):
- def test_in_out(self):
- assert_equal(str(intent.in_.out),'intent(in,out)')
- assert intent.in_.c.is_intent('c')
- assert not intent.in_.c.is_intent_exact('c')
- assert intent.in_.c.is_intent_exact('c','in')
- assert intent.in_.c.is_intent_exact('in','c')
- assert not intent.in_.is_intent('c')
-
-class _test_shared_memory:
- num2seq = [1,2]
- num23seq = [[1,2,3],[4,5,6]]
- def test_in_from_2seq(self):
- a = self.array([2],intent.in_,self.num2seq)
- assert not a.has_shared_memory()
-
- def test_in_from_2casttype(self):
- for t in self.type.cast_types():
- obj = array(self.num2seq,dtype=t.dtype)
- a = self.array([len(self.num2seq)],intent.in_,obj)
- if t.elsize==self.type.elsize:
- assert a.has_shared_memory(),`self.type.dtype,t.dtype`
- else:
- assert not a.has_shared_memory(),`t.dtype`
-
- def test_inout_2seq(self):
- obj = array(self.num2seq,dtype=self.type.dtype)
- a = self.array([len(self.num2seq)],intent.inout,obj)
- assert a.has_shared_memory()
-
- try:
- a = self.array([2],intent.in_.inout,self.num2seq)
- except TypeError,msg:
- if not str(msg).startswith('failed to initialize intent(inout|inplace|cache) array'):
- raise
- else:
- raise SystemError,'intent(inout) should have failed on sequence'
-
- def test_f_inout_23seq(self):
- obj = array(self.num23seq,dtype=self.type.dtype,fortran=1)
- shape = (len(self.num23seq),len(self.num23seq[0]))
- a = self.array(shape,intent.in_.inout,obj)
- assert a.has_shared_memory()
-
- obj = array(self.num23seq,dtype=self.type.dtype,fortran=0)
- shape = (len(self.num23seq),len(self.num23seq[0]))
- try:
- a = self.array(shape,intent.in_.inout,obj)
- except ValueError,msg:
- if not str(msg).startswith('failed to initialize intent(inout) array'):
- raise
- else:
- raise SystemError,'intent(inout) should have failed on improper array'
-
- def test_c_inout_23seq(self):
- obj = array(self.num23seq,dtype=self.type.dtype)
- shape = (len(self.num23seq),len(self.num23seq[0]))
- a = self.array(shape,intent.in_.c.inout,obj)
- assert a.has_shared_memory()
-
- def test_in_copy_from_2casttype(self):
- for t in self.type.cast_types():
- obj = array(self.num2seq,dtype=t.dtype)
- a = self.array([len(self.num2seq)],intent.in_.copy,obj)
- assert not a.has_shared_memory(),`t.dtype`
-
- def test_c_in_from_23seq(self):
- a = self.array([len(self.num23seq),len(self.num23seq[0])],
- intent.in_,self.num23seq)
- assert not a.has_shared_memory()
-
- def test_in_from_23casttype(self):
- for t in self.type.cast_types():
- obj = array(self.num23seq,dtype=t.dtype)
- a = self.array([len(self.num23seq),len(self.num23seq[0])],
- intent.in_,obj)
- assert not a.has_shared_memory(),`t.dtype`
-
- def test_f_in_from_23casttype(self):
- for t in self.type.cast_types():
- obj = array(self.num23seq,dtype=t.dtype,fortran=1)
- a = self.array([len(self.num23seq),len(self.num23seq[0])],
- intent.in_,obj)
- if t.elsize==self.type.elsize:
- assert a.has_shared_memory(),`t.dtype`
- else:
- assert not a.has_shared_memory(),`t.dtype`
-
- def test_c_in_from_23casttype(self):
- for t in self.type.cast_types():
- obj = array(self.num23seq,dtype=t.dtype)
- a = self.array([len(self.num23seq),len(self.num23seq[0])],
- intent.in_.c,obj)
- if t.elsize==self.type.elsize:
- assert a.has_shared_memory(),`t.dtype`
- else:
- assert not a.has_shared_memory(),`t.dtype`
-
- def test_f_copy_in_from_23casttype(self):
- for t in self.type.cast_types():
- obj = array(self.num23seq,dtype=t.dtype,fortran=1)
- a = self.array([len(self.num23seq),len(self.num23seq[0])],
- intent.in_.copy,obj)
- assert not a.has_shared_memory(),`t.dtype`
-
- def test_c_copy_in_from_23casttype(self):
- for t in self.type.cast_types():
- obj = array(self.num23seq,dtype=t.dtype)
- a = self.array([len(self.num23seq),len(self.num23seq[0])],
- intent.in_.c.copy,obj)
- assert not a.has_shared_memory(),`t.dtype`
-
- def test_in_cache_from_2casttype(self):
- for t in self.type.all_types():
- if t.elsize != self.type.elsize:
- continue
- obj = array(self.num2seq,dtype=t.dtype)
- shape = (len(self.num2seq),)
- a = self.array(shape,intent.in_.c.cache,obj)
- assert a.has_shared_memory(),`t.dtype`
-
- a = self.array(shape,intent.in_.cache,obj)
- assert a.has_shared_memory(),`t.dtype`
-
- obj = array(self.num2seq,dtype=t.dtype,fortran=1)
- a = self.array(shape,intent.in_.c.cache,obj)
- assert a.has_shared_memory(),`t.dtype`
-
- a = self.array(shape,intent.in_.cache,obj)
- assert a.has_shared_memory(),`t.dtype`
-
- try:
- a = self.array(shape,intent.in_.cache,obj[::-1])
- except ValueError,msg:
- if not str(msg).startswith('failed to initialize intent(cache) array'):
- raise
- else:
- raise SystemError,'intent(cache) should have failed on multisegmented array'
- def test_in_cache_from_2casttype_failure(self):
- for t in self.type.all_types():
- if t.elsize >= self.type.elsize:
- continue
- obj = array(self.num2seq,dtype=t.dtype)
- shape = (len(self.num2seq),)
- try:
- a = self.array(shape,intent.in_.cache,obj)
- except ValueError,msg:
- if not str(msg).startswith('failed to initialize intent(cache) array'):
- raise
- else:
- raise SystemError,'intent(cache) should have failed on smaller array'
-
- def test_cache_hidden(self):
- shape = (2,)
- a = self.array(shape,intent.cache.hide,None)
- assert a.arr.shape==shape
-
- shape = (2,3)
- a = self.array(shape,intent.cache.hide,None)
- assert a.arr.shape==shape
-
- shape = (-1,3)
- try:
- a = self.array(shape,intent.cache.hide,None)
- except ValueError,msg:
- if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):
- raise
- else:
- raise SystemError,'intent(cache) should have failed on undefined dimensions'
-
- def test_hidden(self):
- shape = (2,)
- a = self.array(shape,intent.hide,None)
- assert a.arr.shape==shape
- assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))
-
- shape = (2,3)
- a = self.array(shape,intent.hide,None)
- assert a.arr.shape==shape
- assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))
- assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']
-
- shape = (2,3)
- a = self.array(shape,intent.c.hide,None)
- assert a.arr.shape==shape
- assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))
- assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']
-
- shape = (-1,3)
- try:
- a = self.array(shape,intent.hide,None)
- except ValueError,msg:
- if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):
- raise
- else:
- raise SystemError,'intent(hide) should have failed on undefined dimensions'
-
- def test_optional_none(self):
- shape = (2,)
- a = self.array(shape,intent.optional,None)
- assert a.arr.shape==shape
- assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))
-
- shape = (2,3)
- a = self.array(shape,intent.optional,None)
- assert a.arr.shape==shape
- assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))
- assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']
-
- shape = (2,3)
- a = self.array(shape,intent.c.optional,None)
- assert a.arr.shape==shape
- assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))
- assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']
-
- def test_optional_from_2seq(self):
- obj = self.num2seq
- shape = (len(obj),)
- a = self.array(shape,intent.optional,obj)
- assert a.arr.shape==shape
- assert not a.has_shared_memory()
-
- def test_optional_from_23seq(self):
- obj = self.num23seq
- shape = (len(obj),len(obj[0]))
- a = self.array(shape,intent.optional,obj)
- assert a.arr.shape==shape
- assert not a.has_shared_memory()
-
- a = self.array(shape,intent.optional.c,obj)
- assert a.arr.shape==shape
- assert not a.has_shared_memory()
-
- def test_inplace(self):
- obj = array(self.num23seq,dtype=self.type.dtype)
- assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']
- shape = obj.shape
- a = self.array(shape,intent.inplace,obj)
- assert obj[1][2]==a.arr[1][2],`obj,a.arr`
- a.arr[1][2]=54
- assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`
- assert a.arr is obj
- assert obj.flags['FORTRAN'] # obj attributes are changed inplace!
- assert not obj.flags['CONTIGUOUS']
-
- def test_inplace_from_casttype(self):
- for t in self.type.cast_types():
- if t is self.type:
- continue
- obj = array(self.num23seq,dtype=t.dtype)
- assert obj.dtype.type==t.dtype
- assert obj.dtype.type is not self.type.dtype
- assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']
- shape = obj.shape
- a = self.array(shape,intent.inplace,obj)
- assert obj[1][2]==a.arr[1][2],`obj,a.arr`
- a.arr[1][2]=54
- assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`
- assert a.arr is obj
- assert obj.flags['FORTRAN'] # obj attributes are changed inplace!
- assert not obj.flags['CONTIGUOUS']
- assert obj.dtype.type is self.type.dtype # obj type is changed inplace!
-
-
-for t in Type._type_names:
- exec '''\
-class test_%s_gen(unittest.TestCase,
- _test_shared_memory
- ):
- type = Type(%r)
- array = lambda self,dims,intent,obj: Array(Type(%r),dims,intent,obj)
-''' % (t,t,t)
-
-if __name__ == "__main__":
- run_module_suite()
Deleted: trunk/numpy/f2py/tests/array_from_pyobj/wrapmodule.c
===================================================================
--- trunk/numpy/f2py/tests/array_from_pyobj/wrapmodule.c 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/array_from_pyobj/wrapmodule.c 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,196 +0,0 @@
-/* File: wrapmodule.c
- * This file is auto-generated with f2py (version:2_1330).
- * Hand edited by Pearu.
- * f2py is a Fortran to Python Interface Generator (FPIG), Second Edition,
- * written by Pearu Peterson <pearu at cens.ioc.ee>.
- * See http://cens.ioc.ee/projects/f2py2e/
- * Generation date: Fri Oct 21 22:41:12 2005
- * $Revision:$
- * $Date:$
- * Do not edit this file directly unless you know what you are doing!!!
- */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*********************** See f2py2e/cfuncs.py: includes ***********************/
-#include "Python.h"
-#include "fortranobject.h"
-#include <math.h>
-
-static PyObject *wrap_error;
-static PyObject *wrap_module;
-
-/************************************ call ************************************/
-static char doc_f2py_rout_wrap_call[] = "\
-Function signature:\n\
- arr = call(type_num,dims,intent,obj)\n\
-Required arguments:\n"
-" type_num : input int\n"
-" dims : input int-sequence\n"
-" intent : input int\n"
-" obj : input python object\n"
-"Return objects:\n"
-" arr : array";
-static PyObject *f2py_rout_wrap_call(PyObject *capi_self,
- PyObject *capi_args) {
- PyObject * volatile capi_buildvalue = NULL;
- int type_num = 0;
- intp *dims = NULL;
- PyObject *dims_capi = Py_None;
- int rank = 0;
- int intent = 0;
- PyArrayObject *capi_arr_tmp = NULL;
- PyObject *arr_capi = Py_None;
- int i;
-
- if (!PyArg_ParseTuple(capi_args,"iOiO|:wrap.call",\
- &type_num,&dims_capi,&intent,&arr_capi))
- return NULL;
- rank = PySequence_Length(dims_capi);
- dims = malloc(rank*sizeof(intp));
- for (i=0;i<rank;++i)
- dims[i] = (intp)PyInt_AsLong(PySequence_GetItem(dims_capi,i));
-
- capi_arr_tmp = array_from_pyobj(type_num,dims,rank,intent|F2PY_INTENT_OUT,arr_capi);
- if (capi_arr_tmp == NULL)
- return NULL;
- capi_buildvalue = Py_BuildValue("N",capi_arr_tmp);
- free(dims);
- return capi_buildvalue;
-}
-
-static char doc_f2py_rout_wrap_attrs[] = "\
-Function signature:\n\
- arr = array_attrs(arr)\n\
-Required arguments:\n"
-" arr : input array object\n"
-"Return objects:\n"
-" data : data address in hex\n"
-" nd : int\n"
-" dimensions : tuple\n"
-" strides : tuple\n"
-" base : python object\n"
-" (kind,type,type_num,elsize,alignment) : 4-tuple\n"
-" flags : int\n"
-" itemsize : int\n"
-;
-static PyObject *f2py_rout_wrap_attrs(PyObject *capi_self,
- PyObject *capi_args) {
- PyObject *arr_capi = Py_None;
- PyArrayObject *arr = NULL;
- PyObject *dimensions = NULL;
- PyObject *strides = NULL;
- char s[100];
- int i;
- memset(s,0,100*sizeof(char));
- if (!PyArg_ParseTuple(capi_args,"O!|:wrap.attrs",
- &PyArray_Type,&arr_capi))
- return NULL;
- arr = (PyArrayObject *)arr_capi;
- sprintf(s,"%p",arr->data);
- dimensions = PyTuple_New(arr->nd);
- strides = PyTuple_New(arr->nd);
- for (i=0;i<arr->nd;++i) {
- PyTuple_SetItem(dimensions,i,PyInt_FromLong(arr->dimensions[i]));
- PyTuple_SetItem(strides,i,PyInt_FromLong(arr->strides[i]));
- }
- return Py_BuildValue("siOOO(cciii)ii",s,arr->nd,
- dimensions,strides,
- (arr->base==NULL?Py_None:arr->base),
- arr->descr->kind,
- arr->descr->type,
- arr->descr->type_num,
- arr->descr->elsize,
- arr->descr->alignment,
- arr->flags,
- PyArray_ITEMSIZE(arr));
-}
-
-static PyMethodDef f2py_module_methods[] = {
-
- {"call",f2py_rout_wrap_call,METH_VARARGS,doc_f2py_rout_wrap_call},
- {"array_attrs",f2py_rout_wrap_attrs,METH_VARARGS,doc_f2py_rout_wrap_attrs},
- {NULL,NULL}
-};
-
-PyMODINIT_FUNC initwrap(void) {
- PyObject *m,*d, *s;
- m = wrap_module = Py_InitModule("wrap", f2py_module_methods);
- PyFortran_Type.ob_type = &PyType_Type;
- import_array();
- if (PyErr_Occurred())
- Py_FatalError("can't initialize module wrap (failed to import numpy)");
- d = PyModule_GetDict(m);
- s = PyString_FromString("This module 'wrap' is auto-generated with f2py (version:2_1330).\nFunctions:\n"
-" arr = call(type_num,dims,intent,obj)\n"
-".");
- PyDict_SetItemString(d, "__doc__", s);
- wrap_error = PyErr_NewException ("wrap.error", NULL, NULL);
- Py_DECREF(s);
- PyDict_SetItemString(d, "F2PY_INTENT_IN", PyInt_FromLong(F2PY_INTENT_IN));
- PyDict_SetItemString(d, "F2PY_INTENT_INOUT", PyInt_FromLong(F2PY_INTENT_INOUT));
- PyDict_SetItemString(d, "F2PY_INTENT_OUT", PyInt_FromLong(F2PY_INTENT_OUT));
- PyDict_SetItemString(d, "F2PY_INTENT_HIDE", PyInt_FromLong(F2PY_INTENT_HIDE));
- PyDict_SetItemString(d, "F2PY_INTENT_CACHE", PyInt_FromLong(F2PY_INTENT_CACHE));
- PyDict_SetItemString(d, "F2PY_INTENT_COPY", PyInt_FromLong(F2PY_INTENT_COPY));
- PyDict_SetItemString(d, "F2PY_INTENT_C", PyInt_FromLong(F2PY_INTENT_C));
- PyDict_SetItemString(d, "F2PY_OPTIONAL", PyInt_FromLong(F2PY_OPTIONAL));
- PyDict_SetItemString(d, "F2PY_INTENT_INPLACE", PyInt_FromLong(F2PY_INTENT_INPLACE));
- PyDict_SetItemString(d, "PyArray_BOOL", PyInt_FromLong(PyArray_BOOL));
- PyDict_SetItemString(d, "PyArray_BYTE", PyInt_FromLong(PyArray_BYTE));
- PyDict_SetItemString(d, "PyArray_UBYTE", PyInt_FromLong(PyArray_UBYTE));
- PyDict_SetItemString(d, "PyArray_SHORT", PyInt_FromLong(PyArray_SHORT));
- PyDict_SetItemString(d, "PyArray_USHORT", PyInt_FromLong(PyArray_USHORT));
- PyDict_SetItemString(d, "PyArray_INT", PyInt_FromLong(PyArray_INT));
- PyDict_SetItemString(d, "PyArray_UINT", PyInt_FromLong(PyArray_UINT));
- PyDict_SetItemString(d, "PyArray_INTP", PyInt_FromLong(PyArray_INTP));
- PyDict_SetItemString(d, "PyArray_UINTP", PyInt_FromLong(PyArray_UINTP));
- PyDict_SetItemString(d, "PyArray_LONG", PyInt_FromLong(PyArray_LONG));
- PyDict_SetItemString(d, "PyArray_ULONG", PyInt_FromLong(PyArray_ULONG));
- PyDict_SetItemString(d, "PyArray_LONGLONG", PyInt_FromLong(PyArray_LONGLONG));
- PyDict_SetItemString(d, "PyArray_ULONGLONG", PyInt_FromLong(PyArray_ULONGLONG));
- PyDict_SetItemString(d, "PyArray_FLOAT", PyInt_FromLong(PyArray_FLOAT));
- PyDict_SetItemString(d, "PyArray_DOUBLE", PyInt_FromLong(PyArray_DOUBLE));
- PyDict_SetItemString(d, "PyArray_LONGDOUBLE", PyInt_FromLong(PyArray_LONGDOUBLE));
- PyDict_SetItemString(d, "PyArray_CFLOAT", PyInt_FromLong(PyArray_CFLOAT));
- PyDict_SetItemString(d, "PyArray_CDOUBLE", PyInt_FromLong(PyArray_CDOUBLE));
- PyDict_SetItemString(d, "PyArray_CLONGDOUBLE", PyInt_FromLong(PyArray_CLONGDOUBLE));
- PyDict_SetItemString(d, "PyArray_OBJECT", PyInt_FromLong(PyArray_OBJECT));
- PyDict_SetItemString(d, "PyArray_STRING", PyInt_FromLong(PyArray_STRING));
- PyDict_SetItemString(d, "PyArray_UNICODE", PyInt_FromLong(PyArray_UNICODE));
- PyDict_SetItemString(d, "PyArray_VOID", PyInt_FromLong(PyArray_VOID));
- PyDict_SetItemString(d, "PyArray_NTYPES", PyInt_FromLong(PyArray_NTYPES));
- PyDict_SetItemString(d, "PyArray_NOTYPE", PyInt_FromLong(PyArray_NOTYPE));
- PyDict_SetItemString(d, "PyArray_UDERDEF", PyInt_FromLong(PyArray_USERDEF));
-
- PyDict_SetItemString(d, "CONTIGUOUS", PyInt_FromLong(CONTIGUOUS));
- PyDict_SetItemString(d, "FORTRAN", PyInt_FromLong(FORTRAN));
- PyDict_SetItemString(d, "OWNDATA", PyInt_FromLong(OWNDATA));
- PyDict_SetItemString(d, "FORCECAST", PyInt_FromLong(FORCECAST));
- PyDict_SetItemString(d, "ENSURECOPY", PyInt_FromLong(ENSURECOPY));
- PyDict_SetItemString(d, "ENSUREARRAY", PyInt_FromLong(ENSUREARRAY));
- PyDict_SetItemString(d, "ALIGNED", PyInt_FromLong(ALIGNED));
- PyDict_SetItemString(d, "WRITEABLE", PyInt_FromLong(WRITEABLE));
- PyDict_SetItemString(d, "UPDATEIFCOPY", PyInt_FromLong(UPDATEIFCOPY));
-
- PyDict_SetItemString(d, "BEHAVED", PyInt_FromLong(NPY_BEHAVED));
- PyDict_SetItemString(d, "BEHAVED_NS", PyInt_FromLong(NPY_BEHAVED_NS));
- PyDict_SetItemString(d, "CARRAY", PyInt_FromLong(NPY_CARRAY));
- PyDict_SetItemString(d, "FARRAY", PyInt_FromLong(NPY_FARRAY));
- PyDict_SetItemString(d, "CARRAY_RO", PyInt_FromLong(NPY_CARRAY_RO));
- PyDict_SetItemString(d, "FARRAY_RO", PyInt_FromLong(NPY_FARRAY_RO));
- PyDict_SetItemString(d, "DEFAULT", PyInt_FromLong(NPY_DEFAULT));
- PyDict_SetItemString(d, "UPDATE_ALL", PyInt_FromLong(NPY_UPDATE_ALL));
-
- if (PyErr_Occurred())
- Py_FatalError("can't initialize module wrap");
-
-#ifdef F2PY_REPORT_ATEXIT
- on_exit(f2py_report_on_exit,(void*)"array_from_pyobj.wrap.call");
-#endif
-
-}
-#ifdef __cplusplus
-}
-#endif
Deleted: trunk/numpy/f2py/tests/c/return_real.py
===================================================================
--- trunk/numpy/f2py/tests/c/return_real.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/c/return_real.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,107 +0,0 @@
-__usage__ = """
-Run:
- python return_real.py [<f2py options>]
-Examples:
- python return_real.py --fcompiler=Gnu --no-wrap-functions
- python return_real.py --quiet
-"""
-
-import f2py2e
-from Numeric import array
-
-def build(f2py_opts):
- try:
- import c_ext_return_real
- except ImportError:
- assert not f2py2e.compile('''\
-python module c_ext_return_real
-usercode \'\'\'
-float t4(float value) { return value; }
-void s4(float *t4, float value) { *t4 = value; }
-double t8(double value) { return value; }
-void s8(double *t8, double value) { *t8 = value; }
-\'\'\'
-interface
- function t4(value)
- real*4 intent(c) :: t4,value
- end
- function t8(value)
- real*8 intent(c) :: t8,value
- end
- subroutine s4(t4,value)
- intent(c) s4
- real*4 intent(out) :: t4
- real*4 intent(c) :: value
- end
- subroutine s8(t8,value)
- intent(c) s8
- real*8 intent(out) :: t8
- real*8 intent(c) :: value
- end
-end interface
-end python module c_ext_return_real
-''','c_ext_return_real',f2py_opts,source_fn='c_ret_real.pyf')
-
- from c_ext_return_real import t4,t8,s4,s8
- test_functions = [t4,t8,s4,s8]
- return test_functions
-
-def runtest(t):
- import sys
- if t.__doc__.split()[0] in ['t0','t4','s0','s4']:
- err = 1e-5
- else:
- err = 0.0
- assert abs(t(234)-234.0)<=err
- assert abs(t(234.6)-234.6)<=err
- assert abs(t(234l)-234.0)<=err
- if sys.version[:3]<'2.3':
- assert abs(t(234.6+3j)-234.6)<=err
- assert abs(t('234')-234)<=err
- assert abs(t('234.6')-234.6)<=err
- assert abs(t(-234)+234)<=err
- assert abs(t([234])-234)<=err
- assert abs(t((234,))-234.)<=err
- assert abs(t(array(234))-234.)<=err
- assert abs(t(array([234]))-234.)<=err
- assert abs(t(array([[234]]))-234.)<=err
- assert abs(t(array([234],'1'))+22)<=err
- assert abs(t(array([234],'s'))-234.)<=err
- assert abs(t(array([234],'i'))-234.)<=err
- assert abs(t(array([234],'l'))-234.)<=err
- assert abs(t(array([234],'b'))-234.)<=err
- assert abs(t(array([234],'f'))-234.)<=err
- assert abs(t(array([234],'d'))-234.)<=err
- if sys.version[:3]<'2.3':
- assert abs(t(array([234+3j],'F'))-234.)<=err
- assert abs(t(array([234],'D'))-234.)<=err
- if t.__doc__.split()[0] in ['t0','t4','s0','s4']:
- assert t(1e200)==t(1e300) # inf
-
- try: raise RuntimeError,`t(array([234],'c'))`
- except ValueError: pass
- try: raise RuntimeError,`t('abc')`
- except ValueError: pass
-
- try: raise RuntimeError,`t([])`
- except IndexError: pass
- try: raise RuntimeError,`t(())`
- except IndexError: pass
-
- try: raise RuntimeError,`t(t)`
- except TypeError: pass
- try: raise RuntimeError,`t({})`
- except TypeError: pass
-
- try:
- try: raise RuntimeError,`t(10l**400)`
- except OverflowError: pass
- except RuntimeError:
- r = t(10l**400); assert `r` in ['inf','Infinity'],`r`
-
-if __name__=='__main__':
- #import libwadpy
- repeat,f2py_opts = f2py2e.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py2e.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
Deleted: trunk/numpy/f2py/tests/f77/callback.py
===================================================================
--- trunk/numpy/f2py/tests/f77/callback.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/f77/callback.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,98 +0,0 @@
-__usage__ = """
-Run:
- python callback.py [<f2py options>]
-Examples:
- python callback.py --fcompiler=Gnu --no-wrap-functions
- python callback.py --quiet
-"""
-
-import f2py2e
-import math
-import sys
-from Numeric import array
-
-def build(f2py_opts):
- try:
- import f77_ext_callback
- except ImportError:
- assert not f2py2e.compile('''\
- subroutine t(fun,a)
- integer a
-cf2py intent(out) a
- external fun
- call fun(a)
- end
-
- subroutine func(a)
-cf2py intent(in,out) a
- integer a
- a = a + 11
- end
-
- subroutine func0(a)
-cf2py intent(out) a
- integer a
- a = 11
- end
-
- subroutine t2(a)
-cf2py intent(callback) fun
- integer a
-cf2py intent(out) a
- external fun
- call fun(a)
- end
-
-''','f77_ext_callback',f2py_opts,source_fn='f77_callback.f')
-
- from f77_ext_callback import t,t2
- test_functions = [t,t2]
- return test_functions
-
-def runtest(t):
- r = t(lambda : 4)
- assert r==4,`r`
- r = t(lambda a:5,fun_extra_args=(6,))
- assert r==5,`r`
- r = t(lambda a:a,fun_extra_args=(6,))
- assert r==6,`r`
- r = t(lambda a:5+a,fun_extra_args=(7,))
- assert r==12,`r`
- if sys.version[:3]>='2.3':
- r = t(lambda a:math.degrees(a),fun_extra_args=(math.pi,))
- assert r==180,`r`
- r = t(math.degrees,fun_extra_args=(math.pi,))
- assert r==180,`r`
- from f77_ext_callback import func,func0
- r = t(func,fun_extra_args=(6,))
- assert r==17,`r`
- r = t(func0)
- assert r==11,`r`
- r = t(func0._cpointer)
- assert r==11,`r`
- class A:
- def __call__(self):
- return 7
- def mth(self):
- return 9
- a = A()
- r = t(a)
- assert r==7,`r`
- r = t(a.mth)
- assert r==9,`r`
-
-if __name__=='__main__':
- #import libwadpy
- status = 1
- try:
- repeat,f2py_opts = f2py2e.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py2e.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
- status = 0
- finally:
- if status:
- print '*'*20
- print 'Running f2py2e.diagnose'
- import f2py2e.diagnose
- f2py2e.diagnose.run()
Deleted: trunk/numpy/f2py/tests/f77/return_character.py
===================================================================
--- trunk/numpy/f2py/tests/f77/return_character.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/f77/return_character.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,99 +0,0 @@
-__usage__ = """
-Run:
- python return_character.py [<f2py options>]
-Examples:
- python return_character.py --fcompiler=Gnu --no-wrap-functions
- python return_character.py --quiet
-"""
-
-import sys
-import f2py2e
-from Numeric import array
-
-def build(f2py_opts):
- try:
- import f77_ext_return_character
- except ImportError:
- assert not f2py2e.compile('''\
- function t0(value)
- character value
- character t0
- t0 = value
- end
- function t1(value)
- character*1 value
- character*1 t1
- t1 = value
- end
- function t5(value)
- character*5 value
- character*5 t5
- t5 = value
- end
- function ts(value)
- character*(*) value
- character*(*) ts
- ts = value
- end
-
- subroutine s0(t0,value)
- character value
- character t0
-cf2py intent(out) t0
- t0 = value
- end
- subroutine s1(t1,value)
- character*1 value
- character*1 t1
-cf2py intent(out) t1
- t1 = value
- end
- subroutine s5(t5,value)
- character*5 value
- character*5 t5
-cf2py intent(out) t5
- t5 = value
- end
- subroutine ss(ts,value)
- character*(*) value
- character*10 ts
-cf2py intent(out) ts
- ts = value
- end
-''','f77_ext_return_character',f2py_opts,source_fn='f77_ret_char.f')
-
- from f77_ext_return_character import t0,t1,t5,s0,s1,s5,ss
- test_functions = [t0,t1,t5,s0,s1,s5,ss]
- if sys.platform!='win32': # this is acctually compiler dependent case
- from f77_ext_return_character import ts
- test_functions.append(ts)
-
- return test_functions
-
-def runtest(t):
- tname = t.__doc__.split()[0]
- if tname in ['t0','t1','s0','s1']:
- assert t(23)=='2'
- r = t('ab');assert r=='a',`r`
- r = t(array('ab'));assert r=='a',`r`
- r = t(array(77,'1'));assert r=='M',`r`
- try: raise RuntimeError,`t(array([77,87]))`
- except ValueError: pass
- try: raise RuntimeError,`t(array(77))`
- except ValueError: pass
- elif tname in ['ts','ss']:
- assert t(23)=='23 ',`t(23)`
- assert t('123456789abcdef')=='123456789a'
- elif tname in ['t5','s5']:
- assert t(23)=='23 ',`t(23)`
- assert t('ab')=='ab ',`t('ab')`
- assert t('123456789abcdef')=='12345'
- else:
- raise NotImplementedError
-
-if __name__=='__main__':
- #import libwadpy
- repeat,f2py_opts = f2py2e.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py2e.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
Deleted: trunk/numpy/f2py/tests/f77/return_complex.py
===================================================================
--- trunk/numpy/f2py/tests/f77/return_complex.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/f77/return_complex.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,124 +0,0 @@
-__usage__ = """
-Run:
- python return_complex.py [<f2py options>]
-Examples:
- python return_complex.py --fcompiler=Gnu --no-wrap-functions
- python return_complex.py --quiet
-"""
-
-import f2py2e
-from Numeric import array
-
-def build(f2py_opts):
- try:
- import f77_ext_return_complex
- except ImportError:
- assert not f2py2e.compile('''\
- function t0(value)
- complex value
- complex t0
- t0 = value
- end
- function t8(value)
- complex*8 value
- complex*8 t8
- t8 = value
- end
- function t16(value)
- complex*16 value
- complex*16 t16
- t16 = value
- end
- function td(value)
- double complex value
- double complex td
- td = value
- end
-
- subroutine s0(t0,value)
- complex value
- complex t0
-cf2py intent(out) t0
- t0 = value
- end
- subroutine s8(t8,value)
- complex*8 value
- complex*8 t8
-cf2py intent(out) t8
- t8 = value
- end
- subroutine s16(t16,value)
- complex*16 value
- complex*16 t16
-cf2py intent(out) t16
- t16 = value
- end
- subroutine sd(td,value)
- double complex value
- double complex td
-cf2py intent(out) td
- td = value
- end
-''','f77_ext_return_complex',f2py_opts)
-
- from f77_ext_return_complex import t0,t8,t16,td,s0,s8,s16,sd
- test_functions = [t0,t8,t16,td,s0,s8,s16,sd]
- return test_functions
-
-
-def runtest(t):
- tname = t.__doc__.split()[0]
- if tname in ['t0','t8','s0','s8']:
- err = 1e-5
- else:
- err = 0.0
- assert abs(t(234j)-234.0j)<=err
- assert abs(t(234.6)-234.6)<=err
- assert abs(t(234l)-234.0)<=err
- assert abs(t(234.6+3j)-(234.6+3j))<=err
- #assert abs(t('234')-234.)<=err
- #assert abs(t('234.6')-234.6)<=err
- assert abs(t(-234)+234.)<=err
- assert abs(t([234])-234.)<=err
- assert abs(t((234,))-234.)<=err
- assert abs(t(array(234))-234.)<=err
- assert abs(t(array(23+4j,'F'))-(23+4j))<=err
- assert abs(t(array([234]))-234.)<=err
- assert abs(t(array([[234]]))-234.)<=err
- assert abs(t(array([234],'1'))+22.)<=err
- assert abs(t(array([234],'s'))-234.)<=err
- assert abs(t(array([234],'i'))-234.)<=err
- assert abs(t(array([234],'l'))-234.)<=err
- assert abs(t(array([234],'b'))-234.)<=err
- assert abs(t(array([234],'f'))-234.)<=err
- assert abs(t(array([234],'d'))-234.)<=err
- assert abs(t(array([234+3j],'F'))-(234+3j))<=err
- assert abs(t(array([234],'D'))-234.)<=err
-
- try: raise RuntimeError,`t(array([234],'c'))`
- except TypeError: pass
- try: raise RuntimeError,`t('abc')`
- except TypeError: pass
-
- try: raise RuntimeError,`t([])`
- except IndexError: pass
- try: raise RuntimeError,`t(())`
- except IndexError: pass
-
- try: raise RuntimeError,`t(t)`
- except TypeError: pass
- try: raise RuntimeError,`t({})`
- except TypeError: pass
-
- try:
- try: raise RuntimeError,`t(10l**400)`
- except OverflowError: pass
- except RuntimeError:
- r = t(10l**400); assert `r` in ['(inf+0j)','(Infinity+0j)'],`r`
-
-if __name__=='__main__':
- #import libwadpy
- repeat,f2py_opts = f2py2e.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py2e.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
Deleted: trunk/numpy/f2py/tests/f77/return_integer.py
===================================================================
--- trunk/numpy/f2py/tests/f77/return_integer.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/f77/return_integer.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,147 +0,0 @@
-__usage__ = """
-Run:
- python return_integer.py [<f2py options>]
-Examples:
- python return_integer.py --fcompiler=Gnu --no-wrap-functions
- python return_integer.py --quiet
-"""
-
-import numpy.f2py as f2py2e
-from numpy import array
-
-def build(f2py_opts):
- try:
- import f77_ext_return_integer
- except ImportError:
- assert not f2py2e.compile('''\
- function t0(value)
- integer value
- integer t0
- t0 = value
- end
- function t1(value)
- integer*1 value
- integer*1 t1
- t1 = value
- end
- function t2(value)
- integer*2 value
- integer*2 t2
- t2 = value
- end
- function t4(value)
- integer*4 value
- integer*4 t4
- t4 = value
- end
- function t8(value)
- integer*8 value
- integer*8 t8
- t8 = value
- end
-
- subroutine s0(t0,value)
- integer value
- integer t0
-cf2py intent(out) t0
- t0 = value
- end
- subroutine s1(t1,value)
- integer*1 value
- integer*1 t1
-cf2py intent(out) t1
- t1 = value
- end
- subroutine s2(t2,value)
- integer*2 value
- integer*2 t2
-cf2py intent(out) t2
- t2 = value
- end
- subroutine s4(t4,value)
- integer*4 value
- integer*4 t4
-cf2py intent(out) t4
- t4 = value
- end
- subroutine s8(t8,value)
- integer*8 value
- integer*8 t8
-cf2py intent(out) t8
- t8 = value
- end
-
-''','f77_ext_return_integer',f2py_opts,source_fn='f77_ret_int.f')
-
- from f77_ext_return_integer import t0,t1,t2,t4,t8,s0,s1,s2,s4,s8
- test_functions = [t0,t1,t2,t4,t8,s0,s1,s2,s4,s8]
- return test_functions
-
-def runtest(t):
- import sys
- assert t(123)==123,`t(123)`
- assert t(123.6)==123
- assert t(123l)==123
- if sys.version[:3]<'2.3':
- assert t(123.6+3j)==123
- assert t('123')==123
- assert t(-123)==-123
- assert t([123])==123
- assert t((123,))==123
- assert t(array(123))==123
- assert t(array([123]))==123
- assert t(array([[123]]))==123
- assert t(array([123],'b'))==123
- assert t(array([123],'h'))==123
- assert t(array([123],'i'))==123
- assert t(array([123],'l'))==123
- assert t(array([123],'B'))==123
- assert t(array([123],'f'))==123
- assert t(array([123],'d'))==123
- if sys.version[:3]<'2.3':
- assert t(array([123+3j],'F'))==123
- assert t(array([123],'D'))==123
-
-
- try: raise RuntimeError,`t(array([123],'c'))`
- except ValueError: pass
- try: raise RuntimeError,`t('abc')`
- except ValueError: pass
-
- try: raise RuntimeError,`t([])`
- except IndexError: pass
- try: raise RuntimeError,`t(())`
- except IndexError: pass
-
- try: raise RuntimeError,`t(t)`
- except TypeError: pass
- try: raise RuntimeError,`t({})`
- except TypeError: pass
-
- if t.__doc__.split()[0] in ['t8','s8']:
- try: raise RuntimeError,`t(100000000000000000000000l)`
- except OverflowError: pass
- try: raise RuntimeError,`t(10000000011111111111111.23)`
- except OverflowError: pass
- else:
- if sys.version[:3]<'2.3':
- try: raise RuntimeError,`t(10000000000000l)`
- except OverflowError: pass
- try: raise RuntimeError,`t(10000000000.23)`
- except OverflowError: pass
-
-if __name__=='__main__':
- #import libwadpy
- status = 1
- try:
- repeat,f2py_opts = f2py2e.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py2e.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
- status = 0
- finally:
- if status:
- print '*'*20
- print 'Running f2py2e.diagnose'
- import numpy.f2py.diagnose as diagnose
- #diagnose.run()
Deleted: trunk/numpy/f2py/tests/f77/return_logical.py
===================================================================
--- trunk/numpy/f2py/tests/f77/return_logical.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/f77/return_logical.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,133 +0,0 @@
-__usage__ = """
-Run:
- python return_logical.py [<f2py options>]
-Examples:
- python return_logical.py --fcompiler=Gnu --no-wrap-functions
- python return_logical.py --quiet
-"""
-
-import f2py2e
-from Numeric import array
-try: True
-except NameError:
- True = 1
- False = 0
-
-def build(f2py_opts):
- try:
- import f77_ext_return_logical
- except ImportError:
- assert not f2py2e.compile('''\
- function t0(value)
- logical value
- logical t0
- t0 = value
- end
- function t1(value)
- logical*1 value
- logical*1 t1
- t1 = value
- end
- function t2(value)
- logical*2 value
- logical*2 t2
- t2 = value
- end
- function t4(value)
- logical*4 value
- logical*4 t4
- t4 = value
- end
-c function t8(value)
-c logical*8 value
-c logical*8 t8
-c t8 = value
-c end
-
- subroutine s0(t0,value)
- logical value
- logical t0
-cf2py intent(out) t0
- t0 = value
- end
- subroutine s1(t1,value)
- logical*1 value
- logical*1 t1
-cf2py intent(out) t1
- t1 = value
- end
- subroutine s2(t2,value)
- logical*2 value
- logical*2 t2
-cf2py intent(out) t2
- t2 = value
- end
- subroutine s4(t4,value)
- logical*4 value
- logical*4 t4
-cf2py intent(out) t4
- t4 = value
- end
-c subroutine s8(t8,value)
-c logical*8 value
-c logical*8 t8
-cf2py intent(out) t8
-c t8 = value
-c end
-''','f77_ext_return_logical',f2py_opts)
-
- #from f77_ext_return_logical import t0,t1,t2,t4,t8,s0,s1,s2,s4,s8
- #test_functions = [t0,t1,t2,t4,t8,s0,s1,s2,s4,s8]
- from f77_ext_return_logical import t0,t1,t2,t4,s0,s1,s2,s4
- test_functions = [t0,t1,t2,t4,s0,s1,s2,s4]
- return test_functions
-
-def runtest(t):
- assert t(True)==1,`t(True)`
- assert t(False)==0,`t(False)`
- assert t(0)==0
- assert t(None)==0
- assert t(0.0)==0
- assert t(0j)==0
- assert t(1j)==1
- assert t(234)==1
- assert t(234.6)==1
- assert t(234l)==1
- assert t(234.6+3j)==1
- assert t('234')==1
- assert t('aaa')==1
- assert t('')==0
- assert t([])==0
- assert t(())==0
- assert t({})==0
- assert t(t)==1
- assert t(-234)==1
- assert t(10l**100)==1
- assert t([234])==1
- assert t((234,))==1
- assert t(array(234))==1
- assert t(array([234]))==1
- assert t(array([[234]]))==1
- assert t(array([234],'1'))==1
- assert t(array([234],'s'))==1
- assert t(array([234],'i'))==1
- assert t(array([234],'l'))==1
- assert t(array([234],'b'))==1
- assert t(array([234],'f'))==1
- assert t(array([234],'d'))==1
- assert t(array([234+3j],'F'))==1
- assert t(array([234],'D'))==1
- assert t(array(0))==0
- assert t(array([0]))==0
- assert t(array([[0]]))==0
- assert t(array([0j]))==0
- assert t(array([1]))==1
- assert t(array([0,0]))==0
- assert t(array([0,1]))==1 #XXX: is this expected?
-
-if __name__=='__main__':
- #import libwadpy
- repeat,f2py_opts = f2py2e.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py2e.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
Deleted: trunk/numpy/f2py/tests/f77/return_real.py
===================================================================
--- trunk/numpy/f2py/tests/f77/return_real.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/f77/return_real.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,126 +0,0 @@
-__usage__ = """
-Run:
- python return_real.py [<f2py options>]
-Examples:
- python return_real.py --fcompiler=Gnu --no-wrap-functions
- python return_real.py --quiet
-"""
-
-import numpy.f2py as f2py2e
-from numpy import array
-
-def build(f2py_opts):
- try:
- import f77_ext_return_real
- except ImportError:
- assert not f2py2e.compile('''\
- function t0(value)
- real value
- real t0
- t0 = value
- end
- function t4(value)
- real*4 value
- real*4 t4
- t4 = value
- end
- function t8(value)
- real*8 value
- real*8 t8
- t8 = value
- end
- function td(value)
- double precision value
- double precision td
- td = value
- end
-
- subroutine s0(t0,value)
- real value
- real t0
-cf2py intent(out) t0
- t0 = value
- end
- subroutine s4(t4,value)
- real*4 value
- real*4 t4
-cf2py intent(out) t4
- t4 = value
- end
- subroutine s8(t8,value)
- real*8 value
- real*8 t8
-cf2py intent(out) t8
- t8 = value
- end
- subroutine sd(td,value)
- double precision value
- double precision td
-cf2py intent(out) td
- td = value
- end
-''','f77_ext_return_real',f2py_opts,source_fn='f77_ret_real.f')
-
- from f77_ext_return_real import t0,t4,t8,td,s0,s4,s8,sd
- test_functions = [t0,t4,t8,td,s0,s4,s8,sd]
- return test_functions
-
-def runtest(t):
- import sys
- if t.__doc__.split()[0] in ['t0','t4','s0','s4']:
- err = 1e-5
- else:
- err = 0.0
- assert abs(t(234)-234.0)<=err
- assert abs(t(234.6)-234.6)<=err
- assert abs(t(234l)-234.0)<=err
- if sys.version[:3]<'2.3':
- assert abs(t(234.6+3j)-234.6)<=err
- assert abs(t('234')-234)<=err
- assert abs(t('234.6')-234.6)<=err
- assert abs(t(-234)+234)<=err
- assert abs(t([234])-234)<=err
- assert abs(t((234,))-234.)<=err
- assert abs(t(array(234))-234.)<=err
- assert abs(t(array([234]))-234.)<=err
- assert abs(t(array([[234]]))-234.)<=err
- assert abs(t(array([234],'b'))+22)<=err
- assert abs(t(array([234],'h'))-234.)<=err
- assert abs(t(array([234],'i'))-234.)<=err
- assert abs(t(array([234],'l'))-234.)<=err
- assert abs(t(array([234],'B'))-234.)<=err
- assert abs(t(array([234],'f'))-234.)<=err
- assert abs(t(array([234],'d'))-234.)<=err
- if sys.version[:3]<'2.3':
- assert abs(t(array([234+3j],'F'))-234.)<=err
- assert abs(t(array([234],'D'))-234.)<=err
- if t.__doc__.split()[0] in ['t0','t4','s0','s4']:
- assert t(1e200)==t(1e300) # inf
-
- try: raise RuntimeError,`t(array([234],'c'))`
- except ValueError: pass
- try: raise RuntimeError,`t('abc')`
- except ValueError: pass
-
- try: raise RuntimeError,`t([])`
- except IndexError: pass
- try: raise RuntimeError,`t(())`
- except IndexError: pass
-
- try: raise RuntimeError,`t(t)`
- except TypeError: pass
- try: raise RuntimeError,`t({})`
- except TypeError: pass
-
- try:
- try: raise RuntimeError,`t(10l**400)`
- except OverflowError: pass
- except RuntimeError:
- r = t(10l**400); assert `r` in ['inf','Infinity'],`r`
-
-if __name__=='__main__':
- #import libwadpy
- repeat,f2py_opts = f2py2e.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py2e.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
Deleted: trunk/numpy/f2py/tests/f90/return_character.py
===================================================================
--- trunk/numpy/f2py/tests/f90/return_character.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/f90/return_character.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,105 +0,0 @@
-__usage__ = """
-Run:
- python return_character.py [<f2py options>]
-Examples:
- python return_character.py --fcompiler=Gnu --no-wrap-functions
- python return_character.py --quiet
-"""
-
-import numpy.f2py as f2py
-from numpy import array
-
-def build(f2py_opts):
- try:
- import f90_ext_return_character
- except ImportError:
- assert not f2py.compile('''\
-module f90_return_char
- contains
- function t0(value)
- character :: value
- character :: t0
- t0 = value
- end function t0
- function t1(value)
- character(len=1) :: value
- character(len=1) :: t1
- t1 = value
- end function t1
- function t5(value)
- character(len=5) :: value
- character(len=5) :: t5
- t5 = value
- end function t5
- function ts(value)
- character(len=*) :: value
- character(len=10) :: ts
- ts = value
- end function ts
-
- subroutine s0(t0,value)
- character :: value
- character :: t0
-!f2py intent(out) t0
- t0 = value
- end subroutine s0
- subroutine s1(t1,value)
- character(len=1) :: value
- character(len=1) :: t1
-!f2py intent(out) t1
- t1 = value
- end subroutine s1
- subroutine s5(t5,value)
- character(len=5) :: value
- character(len=5) :: t5
-!f2py intent(out) t5
- t5 = value
- end subroutine s5
- subroutine ss(ts,value)
- character(len=*) :: value
- character(len=10) :: ts
-!f2py intent(out) ts
- ts = value
- end subroutine ss
-end module f90_return_char
-''','f90_ext_return_character',f2py_opts,source_fn='f90_ret_char.f90')
-
- from f90_ext_return_character import f90_return_char as m
- test_functions = [m.t0,m.t1,m.t5,m.ts,m.s0,m.s1,m.s5,m.ss]
- return test_functions
-
-
-def runtest(t):
- tname = t.__doc__.split()[0]
- if tname in ['t0','t1','s0','s1']:
- assert t(23)=='2'
- r = t('ab');assert r=='a',`r`
- r = t(array('ab'));assert r=='a',`r`
- r = t(array(77,'l'));assert r=='M',`r`
-
- try: raise RuntimeError,`t(array([77,87]))`
- except ValueError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 1"
-
- try: raise RuntimeError,`t(array(77))`
- except ValueError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 2"
-
- elif tname in ['ts','ss']:
- assert t(23)=='23 ',`t(23)`
- assert t('123456789abcdef')=='123456789a',`t('123456789abcdef')`
- elif tname in ['t5','s5']:
- assert t(23)=='23 '
- assert t('ab')=='ab '
- assert t('123456789abcdef')=='12345'
- else:
- raise NotImplementedError
-
-if __name__=='__main__':
- #import libwadpy
- repeat,f2py_opts = f2py.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
Deleted: trunk/numpy/f2py/tests/f90/return_complex.py
===================================================================
--- trunk/numpy/f2py/tests/f90/return_complex.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/f90/return_complex.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,141 +0,0 @@
-__usage__ = """
-Run:
- python return_complex.py [<f2py options>]
-Examples:
- python return_complex.py --quiet
-"""
-
-import numpy.f2py as f2py
-from numpy import array
-
-def build(f2py_opts):
- try:
- import f90_ext_return_complex
- except ImportError:
- assert not f2py.compile('''\
-module f90_return_complex
- contains
- function t0(value)
- complex :: value
- complex :: t0
- t0 = value
- end function t0
- function t8(value)
- complex(kind=4) :: value
- complex(kind=4) :: t8
- t8 = value
- end function t8
- function t16(value)
- complex(kind=8) :: value
- complex(kind=8) :: t16
- t16 = value
- end function t16
- function td(value)
- double complex :: value
- double complex :: td
- td = value
- end function td
-
- subroutine s0(t0,value)
- complex :: value
- complex :: t0
-!f2py intent(out) t0
- t0 = value
- end subroutine s0
- subroutine s8(t8,value)
- complex(kind=4) :: value
- complex(kind=4) :: t8
-!f2py intent(out) t8
- t8 = value
- end subroutine s8
- subroutine s16(t16,value)
- complex(kind=8) :: value
- complex(kind=8) :: t16
-!f2py intent(out) t16
- t16 = value
- end subroutine s16
- subroutine sd(td,value)
- double complex :: value
- double complex :: td
-!f2py intent(out) td
- td = value
- end subroutine sd
-end module f90_return_complex
-''','f90_ext_return_complex',f2py_opts,source_fn='f90_ret_cmlx.f90')
-
- from f90_ext_return_complex import f90_return_complex as m
- test_functions = [m.t0,m.t8,m.t16,m.td,m.s0,m.s8,m.s16,m.sd]
- return test_functions
-
-
-def runtest(t):
- tname = t.__doc__.split()[0]
- if tname in ['t0','t8','s0','s8']:
- err = 1e-5
- else:
- err = 0.0
- #assert abs(t(234j)-234.0j)<=err
- assert abs(t(234.6)-234.6)<=err
- assert abs(t(234l)-234.0)<=err
- assert abs(t(234.6+3j)-(234.6+3j))<=err
- #assert abs(t('234')-234.)<=err
- #assert abs(t('234.6')-234.6)<=err
- assert abs(t(-234)+234.)<=err
- assert abs(t([234])-234.)<=err
- assert abs(t((234,))-234.)<=err
- assert abs(t(array(234))-234.)<=err
- assert abs(t(array(23+4j,'F'))-(23+4j))<=err
- assert abs(t(array([234]))-234.)<=err
- assert abs(t(array([[234]]))-234.)<=err
- assert abs(t(array([234],'b'))+22.)<=err
- assert abs(t(array([234],'h'))-234.)<=err
- assert abs(t(array([234],'i'))-234.)<=err
- assert abs(t(array([234],'l'))-234.)<=err
- assert abs(t(array([234],'q'))-234.)<=err
- assert abs(t(array([234],'f'))-234.)<=err
- assert abs(t(array([234],'d'))-234.)<=err
- assert abs(t(array([234+3j],'F'))-(234+3j))<=err
- assert abs(t(array([234],'D'))-234.)<=err
-
- try: raise RuntimeError,`t(array([234],'c'))`
- except TypeError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 1"
-
- try: raise RuntimeError,`t('abc')`
- except TypeError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 2"
-
- try: raise RuntimeError,`t([])`
- except IndexError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 3"
-
- try: raise RuntimeError,`t(())`
- except IndexError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 4"
-
- try: raise RuntimeError,`t(t)`
- except TypeError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 5"
-
- try: raise RuntimeError,`t({})`
- except TypeError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 6"
-
- try:
- try: raise RuntimeError,`t(10l**400)`
- except OverflowError: pass
- except RuntimeError:
- r = t(10l**400); assert `r` in ['(inf+0j)','(Infinity+0j)'],`r`
-
-if __name__=='__main__':
- #import libwadpy
- repeat,f2py_opts = f2py.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
Deleted: trunk/numpy/f2py/tests/f90/return_integer.py
===================================================================
--- trunk/numpy/f2py/tests/f90/return_integer.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/f90/return_integer.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,165 +0,0 @@
-# XXX: investigate cases that are disabled under win32
-#
-
-__usage__ = """
-Run:
- python return_integer.py [<f2py options>]
-Examples:
- python return_integer.py --quiet
-"""
-
-import sys
-import numpy.f2py as f2py
-from numpy import array
-
-def build(f2py_opts):
- try:
- import f90_ext_return_integer
- except ImportError:
- assert not f2py.compile('''\
-module f90_return_integer
- contains
- function t0(value)
- integer :: value
- integer :: t0
- t0 = value
- end function t0
- function t1(value)
- integer(kind=1) :: value
- integer(kind=1) :: t1
- t1 = value
- end function t1
- function t2(value)
- integer(kind=2) :: value
- integer(kind=2) :: t2
- t2 = value
- end function t2
- function t4(value)
- integer(kind=4) :: value
- integer(kind=4) :: t4
- t4 = value
- end function t4
- function t8(value)
- integer(kind=8) :: value
- integer(kind=8) :: t8
- t8 = value
- end function t8
-
- subroutine s0(t0,value)
- integer :: value
- integer :: t0
-!f2py intent(out) t0
- t0 = value
- end subroutine s0
- subroutine s1(t1,value)
- integer(kind=1) :: value
- integer(kind=1) :: t1
-!f2py intent(out) t1
- t1 = value
- end subroutine s1
- subroutine s2(t2,value)
- integer(kind=2) :: value
- integer(kind=2) :: t2
-!f2py intent(out) t2
- t2 = value
- end subroutine s2
- subroutine s4(t4,value)
- integer(kind=4) :: value
- integer(kind=4) :: t4
-!f2py intent(out) t4
- t4 = value
- end subroutine s4
- subroutine s8(t8,value)
- integer(kind=8) :: value
- integer(kind=8) :: t8
-!f2py intent(out) t8
- t8 = value
- end subroutine s8
-end module f90_return_integer
-''','f90_ext_return_integer',f2py_opts,source_fn='f90_ret_int.f90')
-
- from f90_ext_return_integer import f90_return_integer as m
- test_functions = [m.t0,m.t1,m.t2,m.t4,m.t8,m.s0,m.s1,m.s2,m.s4,m.s8]
- return test_functions
-
-def runtest(t):
- tname = t.__doc__.split()[0]
- assert t(123)==123
- assert t(123.6)==123
- assert t(123l)==123
- if sys.version[:3]<='2.2':
- assert t(123.6+3j)==123
- assert t('123')==123
- assert t(-123)==-123
- assert t([123])==123
- assert t((123,))==123
- assert t(array(123))==123
- assert t(array([123]))==123
- assert t(array([[123]]))==123
- assert t(array([123],'b'))==123
- assert t(array([123],'h'))==123
- assert t(array([123],'i'))==123
- assert t(array([123],'l'))==123
- assert t(array([123],'q'))==123
- assert t(array([123],'f'))==123
- assert t(array([123],'d'))==123
- if sys.version[:3]<='2.2':
- assert t(array([123+3j],'F'))==123
- assert t(array([123],'D'))==123
-
- try: raise RuntimeError,`t(array([123],'c'))`
- except ValueError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 1"
-
- try: raise RuntimeError,`t('abc')`
- except ValueError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 2"
-
- try: raise RuntimeError,`t([])`
- except IndexError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 3"
-
- try: raise RuntimeError,`t(())`
- except IndexError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 4"
-
- try: raise RuntimeError,`t(t)`
- except TypeError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 5"
-
- try: raise RuntimeError,`t({})`
- except TypeError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 6"
-
- if tname in ['t8','s8']:
- try: raise RuntimeError,`t(100000000000000000000000l)`
- except OverflowError: pass
- try: raise RuntimeError,`t(10000000011111111111111.23)`
- except OverflowError: pass
- else:
- if sys.version[:3]<='2.2':
- try: raise RuntimeError,`t(10000000000000l)`
- except OverflowError: pass
- try: raise RuntimeError,`t(10000000000.23)`
- except OverflowError: pass
-
-if __name__=='__main__':
- #import libwadpy
- status = 1
- try:
- repeat,f2py_opts = f2py.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
- status = 0
- finally:
- if status:
- print '*'*20
- print 'Running f2py.diagnose'
- f2py.diagnose.run()
Deleted: trunk/numpy/f2py/tests/f90/return_logical.py
===================================================================
--- trunk/numpy/f2py/tests/f90/return_logical.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/f90/return_logical.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,138 +0,0 @@
-__usage__ = """
-Run:
- python return_logical.py [<f2py options>]
-Examples:
- python return_logical.py --quiet
-"""
-
-import numpy.f2py as f2py
-from numpy import array
-
-try: True
-except NameError:
- True = 1
- False = 0
-
-def build(f2py_opts):
- try:
- import f90_ext_return_logical
- except ImportError:
- assert not f2py.compile('''\
-module f90_return_logical
- contains
- function t0(value)
- logical :: value
- logical :: t0
- t0 = value
- end function t0
- function t1(value)
- logical(kind=1) :: value
- logical(kind=1) :: t1
- t1 = value
- end function t1
- function t2(value)
- logical(kind=2) :: value
- logical(kind=2) :: t2
- t2 = value
- end function t2
- function t4(value)
- logical(kind=4) :: value
- logical(kind=4) :: t4
- t4 = value
- end function t4
- function t8(value)
- logical(kind=8) :: value
- logical(kind=8) :: t8
- t8 = value
- end function t8
-
- subroutine s0(t0,value)
- logical :: value
- logical :: t0
-!f2py intent(out) t0
- t0 = value
- end subroutine s0
- subroutine s1(t1,value)
- logical(kind=1) :: value
- logical(kind=1) :: t1
-!f2py intent(out) t1
- t1 = value
- end subroutine s1
- subroutine s2(t2,value)
- logical(kind=2) :: value
- logical(kind=2) :: t2
-!f2py intent(out) t2
- t2 = value
- end subroutine s2
- subroutine s4(t4,value)
- logical(kind=4) :: value
- logical(kind=4) :: t4
-!f2py intent(out) t4
- t4 = value
- end subroutine s4
- subroutine s8(t8,value)
- logical(kind=8) :: value
- logical(kind=8) :: t8
-!f2py intent(out) t8
- t8 = value
- end subroutine s8
-end module f90_return_logical
-''','f90_ext_return_logical',f2py_opts,source_fn='f90_ret_log.f90')
-
- from f90_ext_return_logical import f90_return_logical as m
- test_functions = [m.t0,m.t1,m.t2,m.t4,m.t8,m.s0,m.s1,m.s2,m.s4,m.s8]
- return test_functions
-
-
-
-
-def runtest(t):
- assert t(True)==1,`t(True)`
- assert t(False)==0,`t(False)`
- assert t(0)==0
- assert t(None)==0
- assert t(0.0)==0
- assert t(0j)==0
- assert t(1j)==1
- assert t(234)==1
- assert t(234.6)==1
- assert t(234l)==1
- assert t(234.6+3j)==1
- assert t('234')==1
- assert t('aaa')==1
- assert t('')==0
- assert t([])==0
- assert t(())==0
- assert t({})==0
- assert t(t)==1
- assert t(-234)==1
- assert t(10l**100)==1
- assert t([234])==1
- assert t((234,))==1
- assert t(array(234))==1
- assert t(array([234]))==1
- assert t(array([[234]]))==1
- assert t(array([234],'b'))==1
- assert t(array([234],'h'))==1
- assert t(array([234],'i'))==1
- assert t(array([234],'l'))==1
- assert t(array([234],'q'))==1
- assert t(array([234],'f'))==1
- assert t(array([234],'d'))==1
- assert t(array([234+3j],'F'))==1
- assert t(array([234],'D'))==1
- assert t(array(0))==0
- assert t(array([0]))==0
- assert t(array([[0]]))==0
- assert t(array([0j]))==0
- assert t(array([1]))==1
- # The call itself raises an error.
- #assert t(array([0,0])) == 0 # fails
- #assert t(array([1,1])) == 1 # fails
-
-if __name__=='__main__':
- #import libwadpy
- repeat,f2py_opts = f2py.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
Deleted: trunk/numpy/f2py/tests/f90/return_real.py
===================================================================
--- trunk/numpy/f2py/tests/f90/return_real.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/f90/return_real.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,144 +0,0 @@
-__usage__ = """
-Run:
- python return_real.py [<f2py options>]
-Examples:
- python return_real.py --quiet
-"""
-
-import sys
-import numpy.f2py as f2py
-from numpy import array
-
-def build(f2py_opts):
- try:
- import f90_ext_return_real
- except ImportError:
- assert not f2py.compile('''\
-module f90_return_real
- contains
- function t0(value)
- real :: value
- real :: t0
- t0 = value
- end function t0
- function t4(value)
- real(kind=4) :: value
- real(kind=4) :: t4
- t4 = value
- end function t4
- function t8(value)
- real(kind=8) :: value
- real(kind=8) :: t8
- t8 = value
- end function t8
- function td(value)
- double precision :: value
- double precision :: td
- td = value
- end function td
-
- subroutine s0(t0,value)
- real :: value
- real :: t0
-!f2py intent(out) t0
- t0 = value
- end subroutine s0
- subroutine s4(t4,value)
- real(kind=4) :: value
- real(kind=4) :: t4
-!f2py intent(out) t4
- t4 = value
- end subroutine s4
- subroutine s8(t8,value)
- real(kind=8) :: value
- real(kind=8) :: t8
-!f2py intent(out) t8
- t8 = value
- end subroutine s8
- subroutine sd(td,value)
- double precision :: value
- double precision :: td
-!f2py intent(out) td
- td = value
- end subroutine sd
-end module f90_return_real
-''','f90_ext_return_real',f2py_opts,source_fn='f90_ret_real.f90')
-
- from f90_ext_return_real import f90_return_real as m
- test_functions = [m.t0,m.t4,m.t8,m.td,m.s0,m.s4,m.s8,m.sd]
- return test_functions
-
-def runtest(t):
- tname = t.__doc__.split()[0]
- if tname in ['t0','t4','s0','s4']:
- err = 1e-5
- else:
- err = 0.0
- assert abs(t(234)-234.0)<=err
- assert abs(t(234.6)-234.6)<=err
- assert abs(t(234l)-234.0)<=err
- if sys.version[:3]<='2.2':
- assert abs(t(234.6+3j)-234.6)<=err,`t(234.6+3j)`
- assert abs(t('234')-234)<=err
- assert abs(t('234.6')-234.6)<=err
- assert abs(t(-234)+234)<=err
- assert abs(t([234])-234)<=err
- assert abs(t((234,))-234.)<=err
- assert abs(t(array(234))-234.)<=err
- assert abs(t(array([234]))-234.)<=err
- assert abs(t(array([[234]]))-234.)<=err
- assert abs(t(array([234],'b'))+22)<=err
- assert abs(t(array([234],'h'))-234.)<=err
- assert abs(t(array([234],'i'))-234.)<=err
- assert abs(t(array([234],'l'))-234.)<=err
- assert abs(t(array([234],'q'))-234.)<=err
- assert abs(t(array([234],'f'))-234.)<=err
- assert abs(t(array([234],'d'))-234.)<=err
- if sys.version[:3]<='2.2':
- assert abs(t(array([234+3j],'F'))-234.)<=err,`t(array([234+3j],'F'))`
- assert abs(t(array([234],'D'))-234.)<=err,`t(array([234],'D'))`
- if tname in ['t0','t4','s0','s4']:
- assert t(1e200)==t(1e300) # inf
-
- try: raise RuntimeError,`t(array([234],'c'))`
- except ValueError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 1"
-
- try: raise RuntimeError,`t('abc')`
- except ValueError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 2"
-
- try: raise RuntimeError,`t([])`
- except IndexError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 3"
-
- try: raise RuntimeError,`t(())`
- except IndexError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 4"
-
- try: raise RuntimeError,`t(t)`
- except TypeError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 5"
-
- try: raise RuntimeError,`t({})`
- except TypeError: pass
- except RuntimeError: print "Failed Error"
- except: print "Wrong Error Type 6"
-
- try:
- try: raise RuntimeError,`t(10l**400)`
- except OverflowError: pass
- except RuntimeError:
- r = t(10l**400); assert `r` in ['inf','Infinity'],`r`
-
-if __name__=='__main__':
- #import libwadpy
- repeat,f2py_opts = f2py.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
Deleted: trunk/numpy/f2py/tests/mixed/foo.f
===================================================================
--- trunk/numpy/f2py/tests/mixed/foo.f 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/mixed/foo.f 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,5 +0,0 @@
- subroutine bar11(a)
-cf2py intent(out) a
- integer a
- a = 11
- end
Deleted: trunk/numpy/f2py/tests/mixed/foo_fixed.f90
===================================================================
--- trunk/numpy/f2py/tests/mixed/foo_fixed.f90 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/mixed/foo_fixed.f90 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,8 +0,0 @@
- module foo_fixed
- contains
- subroutine bar12(a)
-!f2py intent(out) a
- integer a
- a = 12
- end subroutine bar12
- end module foo_fixed
Deleted: trunk/numpy/f2py/tests/mixed/foo_free.f90
===================================================================
--- trunk/numpy/f2py/tests/mixed/foo_free.f90 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/mixed/foo_free.f90 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,8 +0,0 @@
-module foo_free
-contains
- subroutine bar13(a)
- !f2py intent(out) a
- integer a
- a = 13
- end subroutine bar13
-end module foo_free
Deleted: trunk/numpy/f2py/tests/mixed/run.py
===================================================================
--- trunk/numpy/f2py/tests/mixed/run.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/mixed/run.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,49 +0,0 @@
-#!/usr/bin/env python
-__usage__ = """
-Run:
- python run.py [<f2py options>]
-Examples:
- python run.py --quiet
-"""
-
-import os
-import sys
-import f2py2e
-from Numeric import array
-
-def build(f2py_opts):
- try:
- import mixed_f77_f90
- except:
- d,b=os.path.split(sys.argv[0])
- files = ['foo.f','foo_fixed.f90','foo_free.f90']
- files = [os.path.join(d,f) for f in files]
- files = ' '.join(files)
- args = ' -c -m mixed_f77_f90 %s %s'%(files,f2py_opts)
- c = '%s -c "import f2py2e;f2py2e.main()" %s' %(sys.executable,args)
- s = os.system(c)
- assert not s
- from mixed_f77_f90 import bar11
- test_functions = [bar11]
- from mixed_f77_f90 import foo_fixed as m
- test_functions.append(m.bar12)
- from mixed_f77_f90 import foo_free as m
- test_functions.append(m.bar13)
- return test_functions
-
-def runtest(t):
- tname = t.__doc__.split()[0]
- if tname=='bar11':
- assert t()==11
- elif tname=='bar12':
- assert t()==12
- elif tname=='bar13':
- assert t()==13
- else:
- raise NotImplementedError
-
-if __name__=='__main__':
- repeat,f2py_opts = f2py2e.f2py_testing.cmdline()
- test_functions = build(f2py_opts)
- f2py2e.f2py_testing.run(runtest,test_functions,repeat)
- print 'ok'
Deleted: trunk/numpy/f2py/tests/run_all.py
===================================================================
--- trunk/numpy/f2py/tests/run_all.py 2010-03-04 00:45:44 UTC (rev 8272)
+++ trunk/numpy/f2py/tests/run_all.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -1,55 +0,0 @@
-#!/usr/bin/env python
-
-import os,sys
-
-opts = sys.argv[1:]
-if not opts:
- opts = ['10','--quiet']
-
-NUMARRAY = "-DNUMARRAY" in sys.argv
-
-test_f77_files = [\
- 'f77/return_integer.py',
- 'f77/return_logical.py',
- 'f77/return_real.py',
- 'f77/return_complex.py',
- 'f77/callback.py',
- ]
-
-if not NUMARRAY: # no support for character yet in numarray
- test_f77_files.append('f77/return_character.py')
-
-test_f90_files = [\
- 'f90/return_integer.py',
- 'f90/return_logical.py',
- 'f90/return_real.py',
- 'f90/return_complex.py',
- 'f90/return_character.py',
- 'mixed/run.py',
- ]
-
-test_files = test_f77_files
-
-if NUMARRAY:
- print >>sys.stderr,"NOTE: f2py for numarray does not support"\
- " f90 or character arrays."
-else:
- test_files += test_f90_files
-
-py_path = os.environ.get('PYTHONPATH')
-if py_path is None:
- py_path = '.'
-else:
- py_path = os.pathsep.join(['.',py_path])
-os.environ['PYTHONPATH'] = py_path
-
-for f in test_files:
- print "**********************************************"
- ff = os.path.join(sys.path[0],f)
- args = [sys.executable,ff]+opts
- print "Running",' '.join(args)
- status = os.spawnve(os.P_WAIT,sys.executable,args,os.environ)
- if status:
- print 'TEST FAILURE (status=%s)' % (status)
- if f=='f90/return_integer.py':
- sys.exit()
Copied: trunk/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c (from rev 8271, trunk/numpy/f2py/tests/array_from_pyobj/wrapmodule.c)
===================================================================
--- trunk/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c (rev 0)
+++ trunk/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,196 @@
+/* File: wrapmodule.c
+ * This file is auto-generated with f2py (version:2_1330).
+ * Hand edited by Pearu.
+ * f2py is a Fortran to Python Interface Generator (FPIG), Second Edition,
+ * written by Pearu Peterson <pearu at cens.ioc.ee>.
+ * See http://cens.ioc.ee/projects/f2py2e/
+ * Generation date: Fri Oct 21 22:41:12 2005
+ * $Revision:$
+ * $Date:$
+ * Do not edit this file directly unless you know what you are doing!!!
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*********************** See f2py2e/cfuncs.py: includes ***********************/
+#include "Python.h"
+#include "fortranobject.h"
+#include <math.h>
+
+static PyObject *wrap_error;
+static PyObject *wrap_module;
+
+/************************************ call ************************************/
+static char doc_f2py_rout_wrap_call[] = "\
+Function signature:\n\
+ arr = call(type_num,dims,intent,obj)\n\
+Required arguments:\n"
+" type_num : input int\n"
+" dims : input int-sequence\n"
+" intent : input int\n"
+" obj : input python object\n"
+"Return objects:\n"
+" arr : array";
+static PyObject *f2py_rout_wrap_call(PyObject *capi_self,
+ PyObject *capi_args) {
+ PyObject * volatile capi_buildvalue = NULL;
+ int type_num = 0;
+ npy_intp *dims = NULL;
+ PyObject *dims_capi = Py_None;
+ int rank = 0;
+ int intent = 0;
+ PyArrayObject *capi_arr_tmp = NULL;
+ PyObject *arr_capi = Py_None;
+ int i;
+
+ if (!PyArg_ParseTuple(capi_args,"iOiO|:wrap.call",\
+ &type_num,&dims_capi,&intent,&arr_capi))
+ return NULL;
+ rank = PySequence_Length(dims_capi);
+ dims = malloc(rank*sizeof(npy_intp));
+ for (i=0;i<rank;++i)
+ dims[i] = (npy_intp)PyInt_AsLong(PySequence_GetItem(dims_capi,i));
+
+ capi_arr_tmp = array_from_pyobj(type_num,dims,rank,intent|F2PY_INTENT_OUT,arr_capi);
+ if (capi_arr_tmp == NULL)
+ return NULL;
+ capi_buildvalue = Py_BuildValue("N",capi_arr_tmp);
+ free(dims);
+ return capi_buildvalue;
+}
+
+static char doc_f2py_rout_wrap_attrs[] = "\
+Function signature:\n\
+ arr = array_attrs(arr)\n\
+Required arguments:\n"
+" arr : input array object\n"
+"Return objects:\n"
+" data : data address in hex\n"
+" nd : int\n"
+" dimensions : tuple\n"
+" strides : tuple\n"
+" base : python object\n"
+" (kind,type,type_num,elsize,alignment) : 4-tuple\n"
+" flags : int\n"
+" itemsize : int\n"
+;
+static PyObject *f2py_rout_wrap_attrs(PyObject *capi_self,
+ PyObject *capi_args) {
+ PyObject *arr_capi = Py_None;
+ PyArrayObject *arr = NULL;
+ PyObject *dimensions = NULL;
+ PyObject *strides = NULL;
+ char s[100];
+ int i;
+ memset(s,0,100*sizeof(char));
+ if (!PyArg_ParseTuple(capi_args,"O!|:wrap.attrs",
+ &PyArray_Type,&arr_capi))
+ return NULL;
+ arr = (PyArrayObject *)arr_capi;
+ sprintf(s,"%p",arr->data);
+ dimensions = PyTuple_New(arr->nd);
+ strides = PyTuple_New(arr->nd);
+ for (i=0;i<arr->nd;++i) {
+ PyTuple_SetItem(dimensions,i,PyInt_FromLong(arr->dimensions[i]));
+ PyTuple_SetItem(strides,i,PyInt_FromLong(arr->strides[i]));
+ }
+ return Py_BuildValue("siOOO(cciii)ii",s,arr->nd,
+ dimensions,strides,
+ (arr->base==NULL?Py_None:arr->base),
+ arr->descr->kind,
+ arr->descr->type,
+ arr->descr->type_num,
+ arr->descr->elsize,
+ arr->descr->alignment,
+ arr->flags,
+ PyArray_ITEMSIZE(arr));
+}
+
+static PyMethodDef f2py_module_methods[] = {
+
+ {"call",f2py_rout_wrap_call,METH_VARARGS,doc_f2py_rout_wrap_call},
+ {"array_attrs",f2py_rout_wrap_attrs,METH_VARARGS,doc_f2py_rout_wrap_attrs},
+ {NULL,NULL}
+};
+
+PyMODINIT_FUNC inittest_array_from_pyobj_ext(void) {
+ PyObject *m,*d, *s;
+ m = wrap_module = Py_InitModule("test_array_from_pyobj_ext", f2py_module_methods);
+ PyFortran_Type.ob_type = &PyType_Type;
+ import_array();
+ if (PyErr_Occurred())
+ Py_FatalError("can't initialize module wrap (failed to import numpy)");
+ d = PyModule_GetDict(m);
+ s = PyString_FromString("This module 'wrap' is auto-generated with f2py (version:2_1330).\nFunctions:\n"
+" arr = call(type_num,dims,intent,obj)\n"
+".");
+ PyDict_SetItemString(d, "__doc__", s);
+ wrap_error = PyErr_NewException ("wrap.error", NULL, NULL);
+ Py_DECREF(s);
+ PyDict_SetItemString(d, "F2PY_INTENT_IN", PyInt_FromLong(F2PY_INTENT_IN));
+ PyDict_SetItemString(d, "F2PY_INTENT_INOUT", PyInt_FromLong(F2PY_INTENT_INOUT));
+ PyDict_SetItemString(d, "F2PY_INTENT_OUT", PyInt_FromLong(F2PY_INTENT_OUT));
+ PyDict_SetItemString(d, "F2PY_INTENT_HIDE", PyInt_FromLong(F2PY_INTENT_HIDE));
+ PyDict_SetItemString(d, "F2PY_INTENT_CACHE", PyInt_FromLong(F2PY_INTENT_CACHE));
+ PyDict_SetItemString(d, "F2PY_INTENT_COPY", PyInt_FromLong(F2PY_INTENT_COPY));
+ PyDict_SetItemString(d, "F2PY_INTENT_C", PyInt_FromLong(F2PY_INTENT_C));
+ PyDict_SetItemString(d, "F2PY_OPTIONAL", PyInt_FromLong(F2PY_OPTIONAL));
+ PyDict_SetItemString(d, "F2PY_INTENT_INPLACE", PyInt_FromLong(F2PY_INTENT_INPLACE));
+ PyDict_SetItemString(d, "PyArray_BOOL", PyInt_FromLong(PyArray_BOOL));
+ PyDict_SetItemString(d, "PyArray_BYTE", PyInt_FromLong(PyArray_BYTE));
+ PyDict_SetItemString(d, "PyArray_UBYTE", PyInt_FromLong(PyArray_UBYTE));
+ PyDict_SetItemString(d, "PyArray_SHORT", PyInt_FromLong(PyArray_SHORT));
+ PyDict_SetItemString(d, "PyArray_USHORT", PyInt_FromLong(PyArray_USHORT));
+ PyDict_SetItemString(d, "PyArray_INT", PyInt_FromLong(PyArray_INT));
+ PyDict_SetItemString(d, "PyArray_UINT", PyInt_FromLong(PyArray_UINT));
+ PyDict_SetItemString(d, "PyArray_INTP", PyInt_FromLong(PyArray_INTP));
+ PyDict_SetItemString(d, "PyArray_UINTP", PyInt_FromLong(PyArray_UINTP));
+ PyDict_SetItemString(d, "PyArray_LONG", PyInt_FromLong(PyArray_LONG));
+ PyDict_SetItemString(d, "PyArray_ULONG", PyInt_FromLong(PyArray_ULONG));
+ PyDict_SetItemString(d, "PyArray_LONGLONG", PyInt_FromLong(PyArray_LONGLONG));
+ PyDict_SetItemString(d, "PyArray_ULONGLONG", PyInt_FromLong(PyArray_ULONGLONG));
+ PyDict_SetItemString(d, "PyArray_FLOAT", PyInt_FromLong(PyArray_FLOAT));
+ PyDict_SetItemString(d, "PyArray_DOUBLE", PyInt_FromLong(PyArray_DOUBLE));
+ PyDict_SetItemString(d, "PyArray_LONGDOUBLE", PyInt_FromLong(PyArray_LONGDOUBLE));
+ PyDict_SetItemString(d, "PyArray_CFLOAT", PyInt_FromLong(PyArray_CFLOAT));
+ PyDict_SetItemString(d, "PyArray_CDOUBLE", PyInt_FromLong(PyArray_CDOUBLE));
+ PyDict_SetItemString(d, "PyArray_CLONGDOUBLE", PyInt_FromLong(PyArray_CLONGDOUBLE));
+ PyDict_SetItemString(d, "PyArray_OBJECT", PyInt_FromLong(PyArray_OBJECT));
+ PyDict_SetItemString(d, "PyArray_STRING", PyInt_FromLong(PyArray_STRING));
+ PyDict_SetItemString(d, "PyArray_UNICODE", PyInt_FromLong(PyArray_UNICODE));
+ PyDict_SetItemString(d, "PyArray_VOID", PyInt_FromLong(PyArray_VOID));
+ PyDict_SetItemString(d, "PyArray_NTYPES", PyInt_FromLong(PyArray_NTYPES));
+ PyDict_SetItemString(d, "PyArray_NOTYPE", PyInt_FromLong(PyArray_NOTYPE));
+ PyDict_SetItemString(d, "PyArray_UDERDEF", PyInt_FromLong(PyArray_USERDEF));
+
+ PyDict_SetItemString(d, "CONTIGUOUS", PyInt_FromLong(NPY_CONTIGUOUS));
+ PyDict_SetItemString(d, "FORTRAN", PyInt_FromLong(NPY_FORTRAN));
+ PyDict_SetItemString(d, "OWNDATA", PyInt_FromLong(NPY_OWNDATA));
+ PyDict_SetItemString(d, "FORCECAST", PyInt_FromLong(NPY_FORCECAST));
+ PyDict_SetItemString(d, "ENSURECOPY", PyInt_FromLong(NPY_ENSURECOPY));
+ PyDict_SetItemString(d, "ENSUREARRAY", PyInt_FromLong(NPY_ENSUREARRAY));
+ PyDict_SetItemString(d, "ALIGNED", PyInt_FromLong(NPY_ALIGNED));
+ PyDict_SetItemString(d, "WRITEABLE", PyInt_FromLong(NPY_WRITEABLE));
+ PyDict_SetItemString(d, "UPDATEIFCOPY", PyInt_FromLong(NPY_UPDATEIFCOPY));
+
+ PyDict_SetItemString(d, "BEHAVED", PyInt_FromLong(NPY_BEHAVED));
+ PyDict_SetItemString(d, "BEHAVED_NS", PyInt_FromLong(NPY_BEHAVED_NS));
+ PyDict_SetItemString(d, "CARRAY", PyInt_FromLong(NPY_CARRAY));
+ PyDict_SetItemString(d, "FARRAY", PyInt_FromLong(NPY_FARRAY));
+ PyDict_SetItemString(d, "CARRAY_RO", PyInt_FromLong(NPY_CARRAY_RO));
+ PyDict_SetItemString(d, "FARRAY_RO", PyInt_FromLong(NPY_FARRAY_RO));
+ PyDict_SetItemString(d, "DEFAULT", PyInt_FromLong(NPY_DEFAULT));
+ PyDict_SetItemString(d, "UPDATE_ALL", PyInt_FromLong(NPY_UPDATE_ALL));
+
+ if (PyErr_Occurred())
+ Py_FatalError("can't initialize module wrap");
+
+#ifdef F2PY_REPORT_ATEXIT
+ on_exit(f2py_report_on_exit,(void*)"array_from_pyobj.wrap.call");
+#endif
+
+}
+#ifdef __cplusplus
+}
+#endif
Property changes on: trunk/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c
___________________________________________________________________
Name: svn:keywords
+ Id Author
Name: svn:eol-style
+ native
Copied: trunk/numpy/f2py/tests/src/mixed/foo.f (from rev 8271, trunk/numpy/f2py/tests/mixed/foo.f)
===================================================================
--- trunk/numpy/f2py/tests/src/mixed/foo.f (rev 0)
+++ trunk/numpy/f2py/tests/src/mixed/foo.f 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,5 @@
+ subroutine bar11(a)
+cf2py intent(out) a
+ integer a
+ a = 11
+ end
Copied: trunk/numpy/f2py/tests/src/mixed/foo_fixed.f90 (from rev 8271, trunk/numpy/f2py/tests/mixed/foo_fixed.f90)
===================================================================
--- trunk/numpy/f2py/tests/src/mixed/foo_fixed.f90 (rev 0)
+++ trunk/numpy/f2py/tests/src/mixed/foo_fixed.f90 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,8 @@
+ module foo_fixed
+ contains
+ subroutine bar12(a)
+!f2py intent(out) a
+ integer a
+ a = 12
+ end subroutine bar12
+ end module foo_fixed
Copied: trunk/numpy/f2py/tests/src/mixed/foo_free.f90 (from rev 8271, trunk/numpy/f2py/tests/mixed/foo_free.f90)
===================================================================
--- trunk/numpy/f2py/tests/src/mixed/foo_free.f90 (rev 0)
+++ trunk/numpy/f2py/tests/src/mixed/foo_free.f90 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,8 @@
+module foo_free
+contains
+ subroutine bar13(a)
+ !f2py intent(out) a
+ integer a
+ a = 13
+ end subroutine bar13
+end module foo_free
Copied: trunk/numpy/f2py/tests/test_array_from_pyobj.py (from rev 8271, trunk/numpy/f2py/tests/array_from_pyobj/tests/test_array_from_pyobj.py)
===================================================================
--- trunk/numpy/f2py/tests/test_array_from_pyobj.py (rev 0)
+++ trunk/numpy/f2py/tests/test_array_from_pyobj.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,535 @@
+import unittest
+import os
+import sys
+import copy
+
+from numpy.testing import *
+from numpy import array, alltrue, ndarray, asarray, can_cast,zeros, dtype
+from numpy.core.multiarray import typeinfo
+
+import util
+
+wrap = None
+def setup():
+ """
+ Build the required testing extension module
+
+ """
+ global wrap
+ if wrap is None:
+ config_code = """
+ config.add_extension('test_array_from_pyobj_ext',
+ sources=['wrapmodule.c', 'fortranobject.c'],
+ define_macros=[])
+ """
+ d = os.path.dirname(__file__)
+ src = [os.path.join(d, 'src', 'array_from_pyobj', 'wrapmodule.c'),
+ os.path.join(d, '..', 'src', 'fortranobject.c'),
+ os.path.join(d, '..', 'src', 'fortranobject.h')]
+ wrap = util.build_module_distutils(src, config_code,
+ 'test_array_from_pyobj_ext')
+
+def flags_info(arr):
+ flags = wrap.array_attrs(arr)[6]
+ return flags2names(flags)
+
+def flags2names(flags):
+ info = []
+ for flagname in ['CONTIGUOUS','FORTRAN','OWNDATA','ENSURECOPY',
+ 'ENSUREARRAY','ALIGNED','NOTSWAPPED','WRITEABLE',
+ 'UPDATEIFCOPY','BEHAVED','BEHAVED_RO',
+ 'CARRAY','FARRAY'
+ ]:
+ if abs(flags) & getattr(wrap,flagname):
+ info.append(flagname)
+ return info
+
+class Intent:
+ def __init__(self,intent_list=[]):
+ self.intent_list = intent_list[:]
+ flags = 0
+ for i in intent_list:
+ if i=='optional':
+ flags |= wrap.F2PY_OPTIONAL
+ else:
+ flags |= getattr(wrap,'F2PY_INTENT_'+i.upper())
+ self.flags = flags
+ def __getattr__(self,name):
+ name = name.lower()
+ if name=='in_': name='in'
+ return self.__class__(self.intent_list+[name])
+ def __str__(self):
+ return 'intent(%s)' % (','.join(self.intent_list))
+ def __repr__(self):
+ return 'Intent(%r)' % (self.intent_list)
+ def is_intent(self,*names):
+ for name in names:
+ if name not in self.intent_list:
+ return False
+ return True
+ def is_intent_exact(self,*names):
+ return len(self.intent_list)==len(names) and self.is_intent(*names)
+
+intent = Intent()
+
+class Type(object):
+ _type_names = ['BOOL','BYTE','UBYTE','SHORT','USHORT','INT','UINT',
+ 'LONG','ULONG','LONGLONG','ULONGLONG',
+ 'FLOAT','DOUBLE','LONGDOUBLE','CFLOAT','CDOUBLE',
+ 'CLONGDOUBLE']
+ _type_cache = {}
+
+ _cast_dict = {'BOOL':['BOOL']}
+ _cast_dict['BYTE'] = _cast_dict['BOOL'] + ['BYTE']
+ _cast_dict['UBYTE'] = _cast_dict['BOOL'] + ['UBYTE']
+ _cast_dict['BYTE'] = ['BYTE']
+ _cast_dict['UBYTE'] = ['UBYTE']
+ _cast_dict['SHORT'] = _cast_dict['BYTE'] + ['UBYTE','SHORT']
+ _cast_dict['USHORT'] = _cast_dict['UBYTE'] + ['BYTE','USHORT']
+ _cast_dict['INT'] = _cast_dict['SHORT'] + ['USHORT','INT']
+ _cast_dict['UINT'] = _cast_dict['USHORT'] + ['SHORT','UINT']
+
+ _cast_dict['LONG'] = _cast_dict['INT'] + ['LONG']
+ _cast_dict['ULONG'] = _cast_dict['UINT'] + ['ULONG']
+
+ _cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['LONGLONG']
+ _cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['ULONGLONG']
+
+ _cast_dict['FLOAT'] = _cast_dict['SHORT'] + ['USHORT','FLOAT']
+ _cast_dict['DOUBLE'] = _cast_dict['INT'] + ['UINT','FLOAT','DOUBLE']
+ _cast_dict['LONGDOUBLE'] = _cast_dict['LONG'] + ['ULONG','FLOAT','DOUBLE','LONGDOUBLE']
+
+ _cast_dict['CFLOAT'] = _cast_dict['FLOAT'] + ['CFLOAT']
+ _cast_dict['CDOUBLE'] = _cast_dict['DOUBLE'] + ['CFLOAT','CDOUBLE']
+ _cast_dict['CLONGDOUBLE'] = _cast_dict['LONGDOUBLE'] + ['CFLOAT','CDOUBLE','CLONGDOUBLE']
+
+
+ def __new__(cls,name):
+ if isinstance(name,dtype):
+ dtype0 = name
+ name = None
+ for n,i in typeinfo.items():
+ if isinstance(i,tuple) and dtype0.type is i[-1]:
+ name = n
+ break
+ obj = cls._type_cache.get(name.upper(),None)
+ if obj is not None:
+ return obj
+ obj = object.__new__(cls)
+ obj._init(name)
+ cls._type_cache[name.upper()] = obj
+ return obj
+
+ def _init(self,name):
+ self.NAME = name.upper()
+ self.type_num = getattr(wrap,'PyArray_'+self.NAME)
+ assert_equal(self.type_num,typeinfo[self.NAME][1])
+ self.dtype = typeinfo[self.NAME][-1]
+ self.elsize = typeinfo[self.NAME][2] / 8
+ self.dtypechar = typeinfo[self.NAME][0]
+
+ def cast_types(self):
+ return map(self.__class__,self._cast_dict[self.NAME])
+
+ def all_types(self):
+ return map(self.__class__,self._type_names)
+
+ def smaller_types(self):
+ bits = typeinfo[self.NAME][3]
+ types = []
+ for name in self._type_names:
+ if typeinfo[name][3]<bits:
+ types.append(Type(name))
+ return types
+
+ def equal_types(self):
+ bits = typeinfo[self.NAME][3]
+ types = []
+ for name in self._type_names:
+ if name==self.NAME: continue
+ if typeinfo[name][3]==bits:
+ types.append(Type(name))
+ return types
+
+ def larger_types(self):
+ bits = typeinfo[self.NAME][3]
+ types = []
+ for name in self._type_names:
+ if typeinfo[name][3]>bits:
+ types.append(Type(name))
+ return types
+
+class Array:
+ def __init__(self,typ,dims,intent,obj):
+ self.type = typ
+ self.dims = dims
+ self.intent = intent
+ self.obj_copy = copy.deepcopy(obj)
+ self.obj = obj
+
+ # arr.dtypechar may be different from typ.dtypechar
+ self.arr = wrap.call(typ.type_num,dims,intent.flags,obj)
+
+ self.arr_attr = wrap.array_attrs(self.arr)
+
+ if len(dims)>1:
+ if self.intent.is_intent('c'):
+ assert intent.flags & wrap.F2PY_INTENT_C
+ assert not self.arr.flags['FORTRAN'],`self.arr.flags,obj.flags`
+ assert self.arr.flags['CONTIGUOUS']
+ assert not self.arr_attr[6] & wrap.FORTRAN
+ else:
+ assert not intent.flags & wrap.F2PY_INTENT_C
+ assert self.arr.flags['FORTRAN']
+ assert not self.arr.flags['CONTIGUOUS']
+ assert self.arr_attr[6] & wrap.FORTRAN
+
+ if obj is None:
+ self.pyarr = None
+ self.pyarr_attr = None
+ return
+
+ if intent.is_intent('cache'):
+ assert isinstance(obj,ndarray),`type(obj)`
+ self.pyarr = array(obj).reshape(*dims).copy()
+ else:
+ self.pyarr = array(array(obj,
+ dtype = typ.dtypechar).reshape(*dims),
+ order=self.intent.is_intent('c') and 'C' or 'F')
+ assert self.pyarr.dtype == typ, \
+ `self.pyarr.dtype,typ`
+ assert self.pyarr.flags['OWNDATA'], (obj, intent)
+ self.pyarr_attr = wrap.array_attrs(self.pyarr)
+
+ if len(dims)>1:
+ if self.intent.is_intent('c'):
+ assert not self.pyarr.flags['FORTRAN']
+ assert self.pyarr.flags['CONTIGUOUS']
+ assert not self.pyarr_attr[6] & wrap.FORTRAN
+ else:
+ assert self.pyarr.flags['FORTRAN']
+ assert not self.pyarr.flags['CONTIGUOUS']
+ assert self.pyarr_attr[6] & wrap.FORTRAN
+
+
+ assert self.arr_attr[1]==self.pyarr_attr[1] # nd
+ assert self.arr_attr[2]==self.pyarr_attr[2] # dimensions
+ if self.arr_attr[1]<=1:
+ assert self.arr_attr[3]==self.pyarr_attr[3],\
+ `self.arr_attr[3],self.pyarr_attr[3],self.arr.tostring(),self.pyarr.tostring()` # strides
+ assert self.arr_attr[5][-2:]==self.pyarr_attr[5][-2:],\
+ `self.arr_attr[5],self.pyarr_attr[5]` # descr
+ assert self.arr_attr[6]==self.pyarr_attr[6],\
+ `self.arr_attr[6],self.pyarr_attr[6],flags2names(0*self.arr_attr[6]-self.pyarr_attr[6]),flags2names(self.arr_attr[6]),intent` # flags
+
+ if intent.is_intent('cache'):
+ assert self.arr_attr[5][3]>=self.type.elsize,\
+ `self.arr_attr[5][3],self.type.elsize`
+ else:
+ assert self.arr_attr[5][3]==self.type.elsize,\
+ `self.arr_attr[5][3],self.type.elsize`
+ assert self.arr_equal(self.pyarr,self.arr)
+
+ if isinstance(self.obj,ndarray):
+ if typ.elsize==Type(obj.dtype).elsize:
+ if not intent.is_intent('copy') and self.arr_attr[1]<=1:
+ assert self.has_shared_memory()
+
+ def arr_equal(self,arr1,arr2):
+ if arr1.shape != arr2.shape:
+ return False
+ s = arr1==arr2
+ return alltrue(s.flatten())
+
+ def __str__(self):
+ return str(self.arr)
+
+ def has_shared_memory(self):
+ """Check that created array shares data with input array.
+ """
+ if self.obj is self.arr:
+ return True
+ if not isinstance(self.obj,ndarray):
+ return False
+ obj_attr = wrap.array_attrs(self.obj)
+ return obj_attr[0]==self.arr_attr[0]
+
+##################################################
+
+class test_intent(unittest.TestCase):
+ def test_in_out(self):
+ assert_equal(str(intent.in_.out),'intent(in,out)')
+ assert intent.in_.c.is_intent('c')
+ assert not intent.in_.c.is_intent_exact('c')
+ assert intent.in_.c.is_intent_exact('c','in')
+ assert intent.in_.c.is_intent_exact('in','c')
+ assert not intent.in_.is_intent('c')
+
+class _test_shared_memory:
+ num2seq = [1,2]
+ num23seq = [[1,2,3],[4,5,6]]
+ def test_in_from_2seq(self):
+ a = self.array([2],intent.in_,self.num2seq)
+ assert not a.has_shared_memory()
+
+ def test_in_from_2casttype(self):
+ for t in self.type.cast_types():
+ obj = array(self.num2seq,dtype=t.dtype)
+ a = self.array([len(self.num2seq)],intent.in_,obj)
+ if t.elsize==self.type.elsize:
+ assert a.has_shared_memory(),`self.type.dtype,t.dtype`
+ else:
+ assert not a.has_shared_memory(),`t.dtype`
+
+ def test_inout_2seq(self):
+ obj = array(self.num2seq,dtype=self.type.dtype)
+ a = self.array([len(self.num2seq)],intent.inout,obj)
+ assert a.has_shared_memory()
+
+ try:
+ a = self.array([2],intent.in_.inout,self.num2seq)
+ except TypeError,msg:
+ if not str(msg).startswith('failed to initialize intent(inout|inplace|cache) array'):
+ raise
+ else:
+ raise SystemError,'intent(inout) should have failed on sequence'
+
+ def test_f_inout_23seq(self):
+ obj = array(self.num23seq,dtype=self.type.dtype,order='F')
+ shape = (len(self.num23seq),len(self.num23seq[0]))
+ a = self.array(shape,intent.in_.inout,obj)
+ assert a.has_shared_memory()
+
+ obj = array(self.num23seq,dtype=self.type.dtype,order='C')
+ shape = (len(self.num23seq),len(self.num23seq[0]))
+ try:
+ a = self.array(shape,intent.in_.inout,obj)
+ except ValueError,msg:
+ if not str(msg).startswith('failed to initialize intent(inout) array'):
+ raise
+ else:
+ raise SystemError,'intent(inout) should have failed on improper array'
+
+ def test_c_inout_23seq(self):
+ obj = array(self.num23seq,dtype=self.type.dtype)
+ shape = (len(self.num23seq),len(self.num23seq[0]))
+ a = self.array(shape,intent.in_.c.inout,obj)
+ assert a.has_shared_memory()
+
+ def test_in_copy_from_2casttype(self):
+ for t in self.type.cast_types():
+ obj = array(self.num2seq,dtype=t.dtype)
+ a = self.array([len(self.num2seq)],intent.in_.copy,obj)
+ assert not a.has_shared_memory(),`t.dtype`
+
+ def test_c_in_from_23seq(self):
+ a = self.array([len(self.num23seq),len(self.num23seq[0])],
+ intent.in_,self.num23seq)
+ assert not a.has_shared_memory()
+
+ def test_in_from_23casttype(self):
+ for t in self.type.cast_types():
+ obj = array(self.num23seq,dtype=t.dtype)
+ a = self.array([len(self.num23seq),len(self.num23seq[0])],
+ intent.in_,obj)
+ assert not a.has_shared_memory(),`t.dtype`
+
+ def test_f_in_from_23casttype(self):
+ for t in self.type.cast_types():
+ obj = array(self.num23seq,dtype=t.dtype,order='F')
+ a = self.array([len(self.num23seq),len(self.num23seq[0])],
+ intent.in_,obj)
+ if t.elsize==self.type.elsize:
+ assert a.has_shared_memory(),`t.dtype`
+ else:
+ assert not a.has_shared_memory(),`t.dtype`
+
+ def test_c_in_from_23casttype(self):
+ for t in self.type.cast_types():
+ obj = array(self.num23seq,dtype=t.dtype)
+ a = self.array([len(self.num23seq),len(self.num23seq[0])],
+ intent.in_.c,obj)
+ if t.elsize==self.type.elsize:
+ assert a.has_shared_memory(),`t.dtype`
+ else:
+ assert not a.has_shared_memory(),`t.dtype`
+
+ def test_f_copy_in_from_23casttype(self):
+ for t in self.type.cast_types():
+ obj = array(self.num23seq,dtype=t.dtype,order='F')
+ a = self.array([len(self.num23seq),len(self.num23seq[0])],
+ intent.in_.copy,obj)
+ assert not a.has_shared_memory(),`t.dtype`
+
+ def test_c_copy_in_from_23casttype(self):
+ for t in self.type.cast_types():
+ obj = array(self.num23seq,dtype=t.dtype)
+ a = self.array([len(self.num23seq),len(self.num23seq[0])],
+ intent.in_.c.copy,obj)
+ assert not a.has_shared_memory(),`t.dtype`
+
+ def test_in_cache_from_2casttype(self):
+ for t in self.type.all_types():
+ if t.elsize != self.type.elsize:
+ continue
+ obj = array(self.num2seq,dtype=t.dtype)
+ shape = (len(self.num2seq),)
+ a = self.array(shape,intent.in_.c.cache,obj)
+ assert a.has_shared_memory(),`t.dtype`
+
+ a = self.array(shape,intent.in_.cache,obj)
+ assert a.has_shared_memory(),`t.dtype`
+
+ obj = array(self.num2seq,dtype=t.dtype,order='F')
+ a = self.array(shape,intent.in_.c.cache,obj)
+ assert a.has_shared_memory(),`t.dtype`
+
+ a = self.array(shape,intent.in_.cache,obj)
+ assert a.has_shared_memory(),`t.dtype`
+
+ try:
+ a = self.array(shape,intent.in_.cache,obj[::-1])
+ except ValueError,msg:
+ if not str(msg).startswith('failed to initialize intent(cache) array'):
+ raise
+ else:
+ raise SystemError,'intent(cache) should have failed on multisegmented array'
+ def test_in_cache_from_2casttype_failure(self):
+ for t in self.type.all_types():
+ if t.elsize >= self.type.elsize:
+ continue
+ obj = array(self.num2seq,dtype=t.dtype)
+ shape = (len(self.num2seq),)
+ try:
+ a = self.array(shape,intent.in_.cache,obj)
+ except ValueError,msg:
+ if not str(msg).startswith('failed to initialize intent(cache) array'):
+ raise
+ else:
+ raise SystemError,'intent(cache) should have failed on smaller array'
+
+ def test_cache_hidden(self):
+ shape = (2,)
+ a = self.array(shape,intent.cache.hide,None)
+ assert a.arr.shape==shape
+
+ shape = (2,3)
+ a = self.array(shape,intent.cache.hide,None)
+ assert a.arr.shape==shape
+
+ shape = (-1,3)
+ try:
+ a = self.array(shape,intent.cache.hide,None)
+ except ValueError,msg:
+ if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):
+ raise
+ else:
+ raise SystemError,'intent(cache) should have failed on undefined dimensions'
+
+ def test_hidden(self):
+ shape = (2,)
+ a = self.array(shape,intent.hide,None)
+ assert a.arr.shape==shape
+ assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))
+
+ shape = (2,3)
+ a = self.array(shape,intent.hide,None)
+ assert a.arr.shape==shape
+ assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))
+ assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']
+
+ shape = (2,3)
+ a = self.array(shape,intent.c.hide,None)
+ assert a.arr.shape==shape
+ assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))
+ assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']
+
+ shape = (-1,3)
+ try:
+ a = self.array(shape,intent.hide,None)
+ except ValueError,msg:
+ if not str(msg).startswith('failed to create intent(cache|hide)|optional array'):
+ raise
+ else:
+ raise SystemError,'intent(hide) should have failed on undefined dimensions'
+
+ def test_optional_none(self):
+ shape = (2,)
+ a = self.array(shape,intent.optional,None)
+ assert a.arr.shape==shape
+ assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))
+
+ shape = (2,3)
+ a = self.array(shape,intent.optional,None)
+ assert a.arr.shape==shape
+ assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))
+ assert a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS']
+
+ shape = (2,3)
+ a = self.array(shape,intent.c.optional,None)
+ assert a.arr.shape==shape
+ assert a.arr_equal(a.arr,zeros(shape,dtype=self.type.dtype))
+ assert not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS']
+
+ def test_optional_from_2seq(self):
+ obj = self.num2seq
+ shape = (len(obj),)
+ a = self.array(shape,intent.optional,obj)
+ assert a.arr.shape==shape
+ assert not a.has_shared_memory()
+
+ def test_optional_from_23seq(self):
+ obj = self.num23seq
+ shape = (len(obj),len(obj[0]))
+ a = self.array(shape,intent.optional,obj)
+ assert a.arr.shape==shape
+ assert not a.has_shared_memory()
+
+ a = self.array(shape,intent.optional.c,obj)
+ assert a.arr.shape==shape
+ assert not a.has_shared_memory()
+
+ def test_inplace(self):
+ obj = array(self.num23seq,dtype=self.type.dtype)
+ assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']
+ shape = obj.shape
+ a = self.array(shape,intent.inplace,obj)
+ assert obj[1][2]==a.arr[1][2],`obj,a.arr`
+ a.arr[1][2]=54
+ assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`
+ assert a.arr is obj
+ assert obj.flags['FORTRAN'] # obj attributes are changed inplace!
+ assert not obj.flags['CONTIGUOUS']
+
+ def test_inplace_from_casttype(self):
+ for t in self.type.cast_types():
+ if t is self.type:
+ continue
+ obj = array(self.num23seq,dtype=t.dtype)
+ assert obj.dtype.type==t.dtype
+ assert obj.dtype.type is not self.type.dtype
+ assert not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS']
+ shape = obj.shape
+ a = self.array(shape,intent.inplace,obj)
+ assert obj[1][2]==a.arr[1][2],`obj,a.arr`
+ a.arr[1][2]=54
+ assert obj[1][2]==a.arr[1][2]==array(54,dtype=self.type.dtype),`obj,a.arr`
+ assert a.arr is obj
+ assert obj.flags['FORTRAN'] # obj attributes are changed inplace!
+ assert not obj.flags['CONTIGUOUS']
+ assert obj.dtype.type is self.type.dtype # obj type is changed inplace!
+
+
+for t in Type._type_names:
+ exec '''\
+class test_%s_gen(unittest.TestCase,
+ _test_shared_memory
+ ):
+ def setUp(self):
+ self.type = Type(%r)
+ array = lambda self,dims,intent,obj: Array(Type(%r),dims,intent,obj)
+''' % (t,t,t)
+
+if __name__ == "__main__":
+ import nose
+ nose.runmodule()
Added: trunk/numpy/f2py/tests/test_callback.py
===================================================================
--- trunk/numpy/f2py/tests/test_callback.py (rev 0)
+++ trunk/numpy/f2py/tests/test_callback.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,74 @@
+from numpy.testing import *
+from numpy import array
+import math
+import util
+
+class TestF77Callback(util.F2PyTest):
+ code = """
+ subroutine t(fun,a)
+ integer a
+cf2py intent(out) a
+ external fun
+ call fun(a)
+ end
+
+ subroutine func(a)
+cf2py intent(in,out) a
+ integer a
+ a = a + 11
+ end
+
+ subroutine func0(a)
+cf2py intent(out) a
+ integer a
+ a = 11
+ end
+
+ subroutine t2(a)
+cf2py intent(callback) fun
+ integer a
+cf2py intent(out) a
+ external fun
+ call fun(a)
+ end
+ """
+
+ def test_all(self):
+ for name in "t,t2".split(","):
+ yield self.check_function, name
+
+ def check_function(self, name):
+ t = getattr(self.module, name)
+ r = t(lambda : 4)
+ assert r==4,`r`
+ r = t(lambda a:5,fun_extra_args=(6,))
+ assert r==5,`r`
+ r = t(lambda a:a,fun_extra_args=(6,))
+ assert r==6,`r`
+ r = t(lambda a:5+a,fun_extra_args=(7,))
+ assert r==12,`r`
+ r = t(lambda a:math.degrees(a),fun_extra_args=(math.pi,))
+ assert r==180,`r`
+ r = t(math.degrees,fun_extra_args=(math.pi,))
+ assert r==180,`r`
+
+ r = t(self.module.func, fun_extra_args=(6,))
+ assert r==17,`r`
+ r = t(self.module.func0)
+ assert r==11,`r`
+ r = t(self.module.func0._cpointer)
+ assert r==11,`r`
+ class A:
+ def __call__(self):
+ return 7
+ def mth(self):
+ return 9
+ a = A()
+ r = t(a)
+ assert r==7,`r`
+ r = t(a.mth)
+ assert r==9,`r`
+
+if __name__ == "__main__":
+ import nose
+ nose.runmodule()
Added: trunk/numpy/f2py/tests/test_mixed.py
===================================================================
--- trunk/numpy/f2py/tests/test_mixed.py (rev 0)
+++ trunk/numpy/f2py/tests/test_mixed.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,24 @@
+import os
+import math
+
+from numpy.testing import *
+from numpy import array
+
+import util
+
+def _path(*a):
+ return os.path.join(*((os.path.dirname(__file__),) + a))
+
+class TestMixed(util.F2PyTest):
+ sources = [_path('src', 'mixed', 'foo.f'),
+ _path('src', 'mixed', 'foo_fixed.f90'),
+ _path('src', 'mixed', 'foo_free.f90')]
+
+ def test_all(self):
+ assert self.module.bar11() == 11
+ assert self.module.foo_fixed.bar12() == 12
+ assert self.module.foo_free.bar13() == 13
+
+if __name__ == "__main__":
+ import nose
+ nose.runmodule()
Added: trunk/numpy/f2py/tests/test_return_character.py
===================================================================
--- trunk/numpy/f2py/tests/test_return_character.py (rev 0)
+++ trunk/numpy/f2py/tests/test_return_character.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,146 @@
+from numpy.testing import *
+from numpy import array
+import util
+
+class TestReturnCharacter(util.F2PyTest):
+ def _check_function(self, t):
+ tname = t.__doc__.split()[0]
+ if tname in ['t0','t1','s0','s1']:
+ assert t(23)=='2'
+ r = t('ab');assert r=='a',`r`
+ r = t(array('ab'));assert r=='a',`r`
+ r = t(array(77,'u1'));assert r=='M',`r`
+ #assert_raises(ValueError, t, array([77,87]))
+ #assert_raises(ValueError, t, array(77))
+ elif tname in ['ts','ss']:
+ assert t(23)=='23 ',`t(23)`
+ assert t('123456789abcdef')=='123456789a'
+ elif tname in ['t5','s5']:
+ assert t(23)=='23 ',`t(23)`
+ assert t('ab')=='ab ',`t('ab')`
+ assert t('123456789abcdef')=='12345'
+ else:
+ raise NotImplementedError
+
+class TestF77ReturnCharacter(TestReturnCharacter):
+ code = """
+ function t0(value)
+ character value
+ character t0
+ t0 = value
+ end
+ function t1(value)
+ character*1 value
+ character*1 t1
+ t1 = value
+ end
+ function t5(value)
+ character*5 value
+ character*5 t5
+ t5 = value
+ end
+ function ts(value)
+ character*(*) value
+ character*(*) ts
+ ts = value
+ end
+
+ subroutine s0(t0,value)
+ character value
+ character t0
+cf2py intent(out) t0
+ t0 = value
+ end
+ subroutine s1(t1,value)
+ character*1 value
+ character*1 t1
+cf2py intent(out) t1
+ t1 = value
+ end
+ subroutine s5(t5,value)
+ character*5 value
+ character*5 t5
+cf2py intent(out) t5
+ t5 = value
+ end
+ subroutine ss(ts,value)
+ character*(*) value
+ character*10 ts
+cf2py intent(out) ts
+ ts = value
+ end
+ """
+
+ def test_all(self):
+ for name in "t0,t1,t5,s0,s1,s5,ss".split(","):
+ yield self.check_function, name
+
+ def check_function(self, name):
+ t = getattr(self.module, name)
+ self._check_function(t)
+
+
+class TestF90ReturnCharacter(TestReturnCharacter):
+ suffix = ".f90"
+ code = """
+module f90_return_char
+ contains
+ function t0(value)
+ character :: value
+ character :: t0
+ t0 = value
+ end function t0
+ function t1(value)
+ character(len=1) :: value
+ character(len=1) :: t1
+ t1 = value
+ end function t1
+ function t5(value)
+ character(len=5) :: value
+ character(len=5) :: t5
+ t5 = value
+ end function t5
+ function ts(value)
+ character(len=*) :: value
+ character(len=10) :: ts
+ ts = value
+ end function ts
+
+ subroutine s0(t0,value)
+ character :: value
+ character :: t0
+!f2py intent(out) t0
+ t0 = value
+ end subroutine s0
+ subroutine s1(t1,value)
+ character(len=1) :: value
+ character(len=1) :: t1
+!f2py intent(out) t1
+ t1 = value
+ end subroutine s1
+ subroutine s5(t5,value)
+ character(len=5) :: value
+ character(len=5) :: t5
+!f2py intent(out) t5
+ t5 = value
+ end subroutine s5
+ subroutine ss(ts,value)
+ character(len=*) :: value
+ character(len=10) :: ts
+!f2py intent(out) ts
+ ts = value
+ end subroutine ss
+end module f90_return_char
+ """
+
+ def test_all(self):
+ for name in "t0,t1,t5,ts,s0,s1,s5,ss".split(","):
+ yield self.check_function, name
+
+ def check_function(self, name):
+ t = getattr(self.module.f90_return_char, name)
+ self._check_function(t)
+
+if __name__ == "__main__":
+ import nose
+ nose.runmodule()
Added: trunk/numpy/f2py/tests/test_return_complex.py
===================================================================
--- trunk/numpy/f2py/tests/test_return_complex.py (rev 0)
+++ trunk/numpy/f2py/tests/test_return_complex.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,172 @@
+from numpy.testing import *
+from numpy import array
+import util
+
+class TestReturnComplex(util.F2PyTest):
+ def _check_function(self, t):
+ tname = t.__doc__.split()[0]
+ if tname in ['t0','t8','s0','s8']:
+ err = 1e-5
+ else:
+ err = 0.0
+ assert abs(t(234j)-234.0j)<=err
+ assert abs(t(234.6)-234.6)<=err
+ assert abs(t(234l)-234.0)<=err
+ assert abs(t(234.6+3j)-(234.6+3j))<=err
+ #assert abs(t('234')-234.)<=err
+ #assert abs(t('234.6')-234.6)<=err
+ assert abs(t(-234)+234.)<=err
+ assert abs(t([234])-234.)<=err
+ assert abs(t((234,))-234.)<=err
+ assert abs(t(array(234))-234.)<=err
+ assert abs(t(array(23+4j,'F'))-(23+4j))<=err
+ assert abs(t(array([234]))-234.)<=err
+ assert abs(t(array([[234]]))-234.)<=err
+ assert abs(t(array([234],'b'))+22.)<=err
+ assert abs(t(array([234],'h'))-234.)<=err
+ assert abs(t(array([234],'i'))-234.)<=err
+ assert abs(t(array([234],'l'))-234.)<=err
+ assert abs(t(array([234],'q'))-234.)<=err
+ assert abs(t(array([234],'f'))-234.)<=err
+ assert abs(t(array([234],'d'))-234.)<=err
+ assert abs(t(array([234+3j],'F'))-(234+3j))<=err
+ assert abs(t(array([234],'D'))-234.)<=err
+
+ #assert_raises(TypeError, t, array([234], 'a1'))
+ assert_raises(TypeError, t, 'abc')
+
+ assert_raises(IndexError, t, [])
+ assert_raises(IndexError, t, ())
+
+ assert_raises(TypeError, t, t)
+ assert_raises(TypeError, t, {})
+
+ try:
+ r = t(10l**400)
+ assert `r` in ['(inf+0j)','(Infinity+0j)'],`r`
+ except OverflowError:
+ pass
+
+
+class TestF77ReturnComplex(TestReturnComplex):
+ code = """
+ function t0(value)
+ complex value
+ complex t0
+ t0 = value
+ end
+ function t8(value)
+ complex*8 value
+ complex*8 t8
+ t8 = value
+ end
+ function t16(value)
+ complex*16 value
+ complex*16 t16
+ t16 = value
+ end
+ function td(value)
+ double complex value
+ double complex td
+ td = value
+ end
+
+ subroutine s0(t0,value)
+ complex value
+ complex t0
+cf2py intent(out) t0
+ t0 = value
+ end
+ subroutine s8(t8,value)
+ complex*8 value
+ complex*8 t8
+cf2py intent(out) t8
+ t8 = value
+ end
+ subroutine s16(t16,value)
+ complex*16 value
+ complex*16 t16
+cf2py intent(out) t16
+ t16 = value
+ end
+ subroutine sd(td,value)
+ double complex value
+ double complex td
+cf2py intent(out) td
+ td = value
+ end
+ """
+
+ def test_all(self):
+ for name in "t0,t8,t16,td,s0,s8,s16,sd".split(","):
+ yield self.check_function, name
+
+ def check_function(self, name):
+ t = getattr(self.module, name)
+ self._check_function(t)
+
+
+class TestF90ReturnComplex(TestReturnComplex):
+ suffix = ".f90"
+ code = """
+module f90_return_complex
+ contains
+ function t0(value)
+ complex :: value
+ complex :: t0
+ t0 = value
+ end function t0
+ function t8(value)
+ complex(kind=4) :: value
+ complex(kind=4) :: t8
+ t8 = value
+ end function t8
+ function t16(value)
+ complex(kind=8) :: value
+ complex(kind=8) :: t16
+ t16 = value
+ end function t16
+ function td(value)
+ double complex :: value
+ double complex :: td
+ td = value
+ end function td
+
+ subroutine s0(t0,value)
+ complex :: value
+ complex :: t0
+!f2py intent(out) t0
+ t0 = value
+ end subroutine s0
+ subroutine s8(t8,value)
+ complex(kind=4) :: value
+ complex(kind=4) :: t8
+!f2py intent(out) t8
+ t8 = value
+ end subroutine s8
+ subroutine s16(t16,value)
+ complex(kind=8) :: value
+ complex(kind=8) :: t16
+!f2py intent(out) t16
+ t16 = value
+ end subroutine s16
+ subroutine sd(td,value)
+ double complex :: value
+ double complex :: td
+!f2py intent(out) td
+ td = value
+ end subroutine sd
+end module f90_return_complex
+ """
+
+ def test_all(self):
+ for name in "t0,t8,t16,td,s0,s8,s16,sd".split(","):
+ yield self.check_function, name
+
+ def check_function(self, name):
+ t = getattr(self.module.f90_return_complex, name)
+ self._check_function(t)
+
+if __name__ == "__main__":
+ import nose
+ nose.runmodule()
Added: trunk/numpy/f2py/tests/test_return_integer.py
===================================================================
--- trunk/numpy/f2py/tests/test_return_integer.py (rev 0)
+++ trunk/numpy/f2py/tests/test_return_integer.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,181 @@
+from numpy.testing import *
+from numpy import array
+import util
+
+class TestReturnInteger(util.F2PyTest):
+ def _check_function(self, t):
+ assert t(123)==123,`t(123)`
+ assert t(123.6)==123
+ assert t(123l)==123
+ assert t('123')==123
+ assert t(-123)==-123
+ assert t([123])==123
+ assert t((123,))==123
+ assert t(array(123))==123
+ assert t(array([123]))==123
+ assert t(array([[123]]))==123
+ assert t(array([123],'b'))==123
+ assert t(array([123],'h'))==123
+ assert t(array([123],'i'))==123
+ assert t(array([123],'l'))==123
+ assert t(array([123],'B'))==123
+ assert t(array([123],'f'))==123
+ assert t(array([123],'d'))==123
+
+ #assert_raises(ValueError, t, array([123],'S3'))
+ assert_raises(ValueError, t, 'abc')
+
+ assert_raises(IndexError, t, [])
+ assert_raises(IndexError, t, ())
+
+ assert_raises(Exception, t, t)
+ assert_raises(Exception, t, {})
+
+ if t.__doc__.split()[0] in ['t8','s8']:
+ assert_raises(OverflowError, t, 100000000000000000000000l)
+ assert_raises(OverflowError, t, 10000000011111111111111.23)
+
+class TestF77ReturnInteger(TestReturnInteger):
+ code = """
+ function t0(value)
+ integer value
+ integer t0
+ t0 = value
+ end
+ function t1(value)
+ integer*1 value
+ integer*1 t1
+ t1 = value
+ end
+ function t2(value)
+ integer*2 value
+ integer*2 t2
+ t2 = value
+ end
+ function t4(value)
+ integer*4 value
+ integer*4 t4
+ t4 = value
+ end
+ function t8(value)
+ integer*8 value
+ integer*8 t8
+ t8 = value
+ end
+
+ subroutine s0(t0,value)
+ integer value
+ integer t0
+cf2py intent(out) t0
+ t0 = value
+ end
+ subroutine s1(t1,value)
+ integer*1 value
+ integer*1 t1
+cf2py intent(out) t1
+ t1 = value
+ end
+ subroutine s2(t2,value)
+ integer*2 value
+ integer*2 t2
+cf2py intent(out) t2
+ t2 = value
+ end
+ subroutine s4(t4,value)
+ integer*4 value
+ integer*4 t4
+cf2py intent(out) t4
+ t4 = value
+ end
+ subroutine s8(t8,value)
+ integer*8 value
+ integer*8 t8
+cf2py intent(out) t8
+ t8 = value
+ end
+ """
+
+ def test_all(self):
+ for name in "t0,t1,t2,t4,t8,s0,s1,s2,s4,s8".split(","):
+ yield self.check_function, name
+
+ def check_function(self, name):
+ t = getattr(self.module, name)
+ self._check_function(t)
+
+
+class TestF90ReturnInteger(TestReturnInteger):
+ suffix = ".f90"
+ code = """
+module f90_return_integer
+ contains
+ function t0(value)
+ integer :: value
+ integer :: t0
+ t0 = value
+ end function t0
+ function t1(value)
+ integer(kind=1) :: value
+ integer(kind=1) :: t1
+ t1 = value
+ end function t1
+ function t2(value)
+ integer(kind=2) :: value
+ integer(kind=2) :: t2
+ t2 = value
+ end function t2
+ function t4(value)
+ integer(kind=4) :: value
+ integer(kind=4) :: t4
+ t4 = value
+ end function t4
+ function t8(value)
+ integer(kind=8) :: value
+ integer(kind=8) :: t8
+ t8 = value
+ end function t8
+
+ subroutine s0(t0,value)
+ integer :: value
+ integer :: t0
+!f2py intent(out) t0
+ t0 = value
+ end subroutine s0
+ subroutine s1(t1,value)
+ integer(kind=1) :: value
+ integer(kind=1) :: t1
+!f2py intent(out) t1
+ t1 = value
+ end subroutine s1
+ subroutine s2(t2,value)
+ integer(kind=2) :: value
+ integer(kind=2) :: t2
+!f2py intent(out) t2
+ t2 = value
+ end subroutine s2
+ subroutine s4(t4,value)
+ integer(kind=4) :: value
+ integer(kind=4) :: t4
+!f2py intent(out) t4
+ t4 = value
+ end subroutine s4
+ subroutine s8(t8,value)
+ integer(kind=8) :: value
+ integer(kind=8) :: t8
+!f2py intent(out) t8
+ t8 = value
+ end subroutine s8
+end module f90_return_integer
+ """
+
+ def test_all(self):
+ for name in "t0,t1,t2,t4,t8,s0,s1,s2,s4,s8".split(","):
+ yield self.check_function, name
+
+ def check_function(self, name):
+ t = getattr(self.module.f90_return_integer, name)
+ self._check_function(t)
+
+if __name__ == "__main__":
+ import nose
+ nose.runmodule()
Added: trunk/numpy/f2py/tests/test_return_logical.py
===================================================================
--- trunk/numpy/f2py/tests/test_return_logical.py (rev 0)
+++ trunk/numpy/f2py/tests/test_return_logical.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,190 @@
+from numpy.testing import *
+from numpy import array
+import util
+
+class TestReturnLogical(util.F2PyTest):
+ def _check_function(self, t):
+ assert t(True)==1,`t(True)`
+ assert t(False)==0,`t(False)`
+ assert t(0)==0
+ assert t(None)==0
+ assert t(0.0)==0
+ assert t(0j)==0
+ assert t(1j)==1
+ assert t(234)==1
+ assert t(234.6)==1
+ assert t(234l)==1
+ assert t(234.6+3j)==1
+ assert t('234')==1
+ assert t('aaa')==1
+ assert t('')==0
+ assert t([])==0
+ assert t(())==0
+ assert t({})==0
+ assert t(t)==1
+ assert t(-234)==1
+ assert t(10l**100)==1
+ assert t([234])==1
+ assert t((234,))==1
+ assert t(array(234))==1
+ assert t(array([234]))==1
+ assert t(array([[234]]))==1
+ assert t(array([234],'b'))==1
+ assert t(array([234],'h'))==1
+ assert t(array([234],'i'))==1
+ assert t(array([234],'l'))==1
+ assert t(array([234],'f'))==1
+ assert t(array([234],'d'))==1
+ assert t(array([234+3j],'F'))==1
+ assert t(array([234],'D'))==1
+ assert t(array(0))==0
+ assert t(array([0]))==0
+ assert t(array([[0]]))==0
+ assert t(array([0j]))==0
+ assert t(array([1]))==1
+ assert_raises(ValueError, t, array([0,0]))
+
+
+class TestF77ReturnLogical(TestReturnLogical):
+ code = """
+ function t0(value)
+ logical value
+ logical t0
+ t0 = value
+ end
+ function t1(value)
+ logical*1 value
+ logical*1 t1
+ t1 = value
+ end
+ function t2(value)
+ logical*2 value
+ logical*2 t2
+ t2 = value
+ end
+ function t4(value)
+ logical*4 value
+ logical*4 t4
+ t4 = value
+ end
+c function t8(value)
+c logical*8 value
+c logical*8 t8
+c t8 = value
+c end
+
+ subroutine s0(t0,value)
+ logical value
+ logical t0
+cf2py intent(out) t0
+ t0 = value
+ end
+ subroutine s1(t1,value)
+ logical*1 value
+ logical*1 t1
+cf2py intent(out) t1
+ t1 = value
+ end
+ subroutine s2(t2,value)
+ logical*2 value
+ logical*2 t2
+cf2py intent(out) t2
+ t2 = value
+ end
+ subroutine s4(t4,value)
+ logical*4 value
+ logical*4 t4
+cf2py intent(out) t4
+ t4 = value
+ end
+c subroutine s8(t8,value)
+c logical*8 value
+c logical*8 t8
+cf2py intent(out) t8
+c t8 = value
+c end
+ """
+
+ def test_all(self):
+ for name in "t0,t1,t2,t4,s0,s1,s2,s4".split(","):
+ yield self.check_function, name
+
+ def check_function(self, name):
+ t = getattr(self.module, name)
+ self._check_function(t)
+
+class TestF90ReturnLogical(TestReturnLogical):
+ suffix = ".f90"
+ code = """
+module f90_return_logical
+ contains
+ function t0(value)
+ logical :: value
+ logical :: t0
+ t0 = value
+ end function t0
+ function t1(value)
+ logical(kind=1) :: value
+ logical(kind=1) :: t1
+ t1 = value
+ end function t1
+ function t2(value)
+ logical(kind=2) :: value
+ logical(kind=2) :: t2
+ t2 = value
+ end function t2
+ function t4(value)
+ logical(kind=4) :: value
+ logical(kind=4) :: t4
+ t4 = value
+ end function t4
+ function t8(value)
+ logical(kind=8) :: value
+ logical(kind=8) :: t8
+ t8 = value
+ end function t8
+
+ subroutine s0(t0,value)
+ logical :: value
+ logical :: t0
+!f2py intent(out) t0
+ t0 = value
+ end subroutine s0
+ subroutine s1(t1,value)
+ logical(kind=1) :: value
+ logical(kind=1) :: t1
+!f2py intent(out) t1
+ t1 = value
+ end subroutine s1
+ subroutine s2(t2,value)
+ logical(kind=2) :: value
+ logical(kind=2) :: t2
+!f2py intent(out) t2
+ t2 = value
+ end subroutine s2
+ subroutine s4(t4,value)
+ logical(kind=4) :: value
+ logical(kind=4) :: t4
+!f2py intent(out) t4
+ t4 = value
+ end subroutine s4
+ subroutine s8(t8,value)
+ logical(kind=8) :: value
+ logical(kind=8) :: t8
+!f2py intent(out) t8
+ t8 = value
+ end subroutine s8
+end module f90_return_logical
+ """
+
+ def test_all(self):
+ for name in "t0,t1,t2,t4,t8,s0,s1,s2,s4,s8".split(","):
+ yield self.check_function, name
+
+ def check_function(self, name):
+ t = getattr(self.module.f90_return_logical, name)
+ self._check_function(t)
+
+if __name__ == "__main__":
+ import nose
+ nose.runmodule()
Added: trunk/numpy/f2py/tests/test_return_real.py
===================================================================
--- trunk/numpy/f2py/tests/test_return_real.py (rev 0)
+++ trunk/numpy/f2py/tests/test_return_real.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,206 @@
+from numpy.testing import *
+from numpy import array
+import math
+import util
+
+class TestReturnReal(util.F2PyTest):
+ def _check_function(self, t):
+ if t.__doc__.split()[0] in ['t0','t4','s0','s4']:
+ err = 1e-5
+ else:
+ err = 0.0
+ assert abs(t(234)-234.0)<=err
+ assert abs(t(234.6)-234.6)<=err
+ assert abs(t(234l)-234.0)<=err
+ assert abs(t('234')-234)<=err
+ assert abs(t('234.6')-234.6)<=err
+ assert abs(t(-234)+234)<=err
+ assert abs(t([234])-234)<=err
+ assert abs(t((234,))-234.)<=err
+ assert abs(t(array(234))-234.)<=err
+ assert abs(t(array([234]))-234.)<=err
+ assert abs(t(array([[234]]))-234.)<=err
+ assert abs(t(array([234],'b'))+22)<=err
+ assert abs(t(array([234],'h'))-234.)<=err
+ assert abs(t(array([234],'i'))-234.)<=err
+ assert abs(t(array([234],'l'))-234.)<=err
+ assert abs(t(array([234],'B'))-234.)<=err
+ assert abs(t(array([234],'f'))-234.)<=err
+ assert abs(t(array([234],'d'))-234.)<=err
+ if t.__doc__.split()[0] in ['t0','t4','s0','s4']:
+ assert t(1e200)==t(1e300) # inf
+
+ #assert_raises(ValueError, t, array([234], 'S1'))
+ assert_raises(ValueError, t, 'abc')
+
+ assert_raises(IndexError, t, [])
+ assert_raises(IndexError, t, ())
+
+ assert_raises(Exception, t, t)
+ assert_raises(Exception, t, {})
+
+ try:
+ r = t(10l**400)
+ assert `r` in ['inf','Infinity'],`r`
+ except OverflowError:
+ pass
+
+class TestCReturnReal(TestReturnReal):
+ suffix = ".pyf"
+ module_name = "c_ext_return_real"
+ code = """
+python module c_ext_return_real
+usercode \'\'\'
+float t4(float value) { return value; }
+void s4(float *t4, float value) { *t4 = value; }
+double t8(double value) { return value; }
+void s8(double *t8, double value) { *t8 = value; }
+\'\'\'
+interface
+ function t4(value)
+ real*4 intent(c) :: t4,value
+ end
+ function t8(value)
+ real*8 intent(c) :: t8,value
+ end
+ subroutine s4(t4,value)
+ intent(c) s4
+ real*4 intent(out) :: t4
+ real*4 intent(c) :: value
+ end
+ subroutine s8(t8,value)
+ intent(c) s8
+ real*8 intent(out) :: t8
+ real*8 intent(c) :: value
+ end
+end interface
+end python module c_ext_return_real
+ """
+
+ def test_all(self):
+ for name in "t4,t8,s4,s8".split(","):
+ yield self.check_function, name
+
+ def check_function(self, name):
+ self._check_function(getattr(self.module, name))
+
+class TestF77ReturnReal(TestReturnReal):
+ code = """
+ function t0(value)
+ real value
+ real t0
+ t0 = value
+ end
+ function t4(value)
+ real*4 value
+ real*4 t4
+ t4 = value
+ end
+ function t8(value)
+ real*8 value
+ real*8 t8
+ t8 = value
+ end
+ function td(value)
+ double precision value
+ double precision td
+ td = value
+ end
+
+ subroutine s0(t0,value)
+ real value
+ real t0
+cf2py intent(out) t0
+ t0 = value
+ end
+ subroutine s4(t4,value)
+ real*4 value
+ real*4 t4
+cf2py intent(out) t4
+ t4 = value
+ end
+ subroutine s8(t8,value)
+ real*8 value
+ real*8 t8
+cf2py intent(out) t8
+ t8 = value
+ end
+ subroutine sd(td,value)
+ double precision value
+ double precision td
+cf2py intent(out) td
+ td = value
+ end
+ """
+
+ def test_all(self):
+ for name in "t0,t4,t8,td,s0,s4,s8,sd".split(","):
+ yield self.check_function, name
+
+ def check_function(self, name):
+ self._check_function(getattr(self.module, name))
+
+class TestF90ReturnReal(TestReturnReal):
+ suffix = ".f90"
+ code = """
+module f90_return_real
+ contains
+ function t0(value)
+ real :: value
+ real :: t0
+ t0 = value
+ end function t0
+ function t4(value)
+ real(kind=4) :: value
+ real(kind=4) :: t4
+ t4 = value
+ end function t4
+ function t8(value)
+ real(kind=8) :: value
+ real(kind=8) :: t8
+ t8 = value
+ end function t8
+ function td(value)
+ double precision :: value
+ double precision :: td
+ td = value
+ end function td
+
+ subroutine s0(t0,value)
+ real :: value
+ real :: t0
+!f2py intent(out) t0
+ t0 = value
+ end subroutine s0
+ subroutine s4(t4,value)
+ real(kind=4) :: value
+ real(kind=4) :: t4
+!f2py intent(out) t4
+ t4 = value
+ end subroutine s4
+ subroutine s8(t8,value)
+ real(kind=8) :: value
+ real(kind=8) :: t8
+!f2py intent(out) t8
+ t8 = value
+ end subroutine s8
+ subroutine sd(td,value)
+ double precision :: value
+ double precision :: td
+!f2py intent(out) td
+ td = value
+ end subroutine sd
+end module f90_return_real
+ """
+
+ def test_all(self):
+ for name in "t0,t4,t8,td,s0,s4,s8,sd".split(","):
+ yield self.check_function, name
+
+ def check_function(self, name):
+ self._check_function(getattr(self.module.f90_return_real, name))
+
+
+if __name__ == "__main__":
+ import nose
+ nose.runmodule()
Added: trunk/numpy/f2py/tests/util.py
===================================================================
--- trunk/numpy/f2py/tests/util.py (rev 0)
+++ trunk/numpy/f2py/tests/util.py 2010-03-06 19:10:14 UTC (rev 8273)
@@ -0,0 +1,346 @@
+"""
+Utility functions for
+
+- building and importing modules on test time, using a temporary location
+- detecting if compilers are present
+
+"""
+
+import os
+import sys
+import subprocess
+import tempfile
+import shutil
+import atexit
+import textwrap
+import re
+import random
+
+import nose
+
+from numpy.compat import asbytes
+import numpy.f2py
+
+try:
+ from hashlib import md5
+except ImportError:
+ from md5 import new as md5
+
+#
+# Maintaining a temporary module directory
+#
+
+_module_dir = None
+
+def _cleanup():
+ global _module_dir
+ if _module_dir is not None:
+ try:
+ sys.path.remove(_module_dir)
+ except ValueError:
+ pass
+ try:
+ shutil.rmtree(_module_dir)
+ except (IOError, OSError):
+ pass
+ _module_dir = None
+
+def get_module_dir():
+ global _module_dir
+ if _module_dir is None:
+ _module_dir = tempfile.mkdtemp()
+ atexit.register(_cleanup)
+ if _module_dir not in sys.path:
+ sys.path.insert(0, _module_dir)
+ return _module_dir
+
+def get_temp_module_name():
+ # Assume single-threaded, and the module dir usable only by this thread
+ d = get_module_dir()
+ for j in xrange(5403, 9999999):
+ name = "_test_ext_module_%d" % j
+ fn = os.path.join(d, name)
+ if name not in sys.modules and not os.path.isfile(fn+'.py'):
+ return name
+ raise RuntimeError("Failed to create a temporary module name")
+
+def _memoize(func):
+ memo = {}
+ def wrapper(*a, **kw):
+ key = repr((a, kw))
+ if key not in memo:
+ try:
+ memo[key] = func(*a, **kw)
+ except Exception, e:
+ memo[key] = e
+ raise
+ ret = memo[key]
+ if isinstance(ret, Exception):
+ raise ret
+ return ret
+ wrapper.__name__ = func.__name__
+ return wrapper
+
+#
+# Building modules
+#
+
+ at _memoize
+def build_module(source_files, options=[], skip=[], only=[], module_name=None):
+ """
+ Compile and import a f2py module, built from the given files.
+
+ """
+
+ code = ("import sys; sys.path = %s; import numpy.f2py as f2py2e; "
+ "f2py2e.main()" % repr(sys.path))
+
+ d = get_module_dir()
+
+ # Copy files
+ dst_sources = []
+ for fn in source_files:
+ if not os.path.isfile(fn):
+ raise RuntimeError("%s is not a file" % fn)
+ dst = os.path.join(d, os.path.basename(fn))
+ shutil.copyfile(fn, dst)
+ dst_sources.append(dst)
+
+ # Prepare options
+ if module_name is None:
+ module_name = get_temp_module_name()
+ f2py_opts = ['-c', '-m', module_name] + options + dst_sources
+ if skip:
+ f2py_opts += ['skip:'] + skip
+ if only:
+ f2py_opts += ['only:'] + only
+
+ # Build
+ cwd = os.getcwd()
+ try:
+ os.chdir(d)
+ cmd = [sys.executable, '-c', code] + f2py_opts
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ out, err = p.communicate()
+ if p.returncode != 0:
+ raise RuntimeError("Running f2py failed: %s\n%s"
+ % (cmd[4:], out))
+ finally:
+ os.chdir(cwd)
+
+ # Partial cleanup
+ for fn in dst_sources:
+ os.unlink(fn)
+
+ # Import
+ __import__(module_name)
+ return sys.modules[module_name]
+
+ at _memoize
+def build_code(source_code, options=[], skip=[], only=[], suffix=None,
+ module_name=None):
+ """
+ Compile and import Fortran code using f2py.
+
+ """
+ if suffix is None:
+ suffix = '.f'
+
+ fd, tmp_fn = tempfile.mkstemp(suffix=suffix)
+ os.write(fd, asbytes(source_code))
+ os.close(fd)
+
+ try:
+ return build_module([tmp_fn], options=options, skip=skip, only=only,
+ module_name=module_name)
+ finally:
+ os.unlink(tmp_fn)
+
+#
+# Check if compilers are available at all...
+#
+
+_compiler_status = None
+def _get_compiler_status():
+ global _compiler_status
+ if _compiler_status is not None:
+ return _compiler_status
+
+ _compiler_status = (False, False, False)
+
+ # XXX: this is really ugly. But I don't know how to invoke Distutils
+ # in a safer way...
+ code = """
+import os
+import sys
+sys.path = %(syspath)s
+
+def configuration(parent_name='',top_path=None):
+ global config
+ from numpy.distutils.misc_util import Configuration
+ config = Configuration('', parent_name, top_path)
+ return config
+
+from numpy.distutils.core import setup
+setup(configuration=configuration)
+
+config_cmd = config.get_config_cmd()
+have_c = config_cmd.try_compile('void foo() {}')
+print('COMPILERS:%%d,%%d,%%d' %% (have_c,
+ config.have_f77c(),
+ config.have_f90c()))
+sys.exit(99)
+"""
+ code = code % dict(syspath=repr(sys.path))
+
+ fd, script = tempfile.mkstemp(suffix='.py')
+ os.write(fd, asbytes(code))
+ os.close(fd)
+
+ try:
+ cmd = [sys.executable, script, 'config']
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ out, err = p.communicate()
+ m = re.search(r'COMPILERS:(\d+),(\d+),(\d+)', out)
+ if m:
+ _compiler_status = (bool(m.group(1)), bool(m.group(2)),
+ bool(m.group(3)))
+ finally:
+ os.unlink(script)
+
+ # Finished
+ return _compiler_status
+
+def has_c_compiler():
+ return _get_compiler_status()[0]
+
+def has_f77_compiler():
+ return _get_compiler_status()[1]
+
+def has_f90_compiler():
+ return _get_compiler_status()[2]
+
+#
+# Building with distutils
+#
+
+ at _memoize
+def build_module_distutils(source_files, config_code, module_name, **kw):
+ """
+ Build a module via distutils and import it.
+
+ """
+ from numpy.distutils.misc_util import Configuration
+ from numpy.distutils.core import setup
+
+ d = get_module_dir()
+
+ # Copy files
+ dst_sources = []
+ for fn in source_files:
+ if not os.path.isfile(fn):
+ raise RuntimeError("%s is not a file" % fn)
+ dst = os.path.join(d, os.path.basename(fn))
+ shutil.copyfile(fn, dst)
+ dst_sources.append(dst)
+
+ # Build script
+ config_code = textwrap.dedent(config_code).replace("\n", "\n ")
+
+ code = """\
+import os
+import sys
+sys.path = %(syspath)s
+
+def configuration(parent_name='',top_path=None):
+ from numpy.distutils.misc_util import Configuration
+ config = Configuration('', parent_name, top_path)
+ %(config_code)s
+ return config
+
+if __name__ == "__main__":
+ from numpy.distutils.core import setup
+ setup(configuration=configuration)
+""" % dict(config_code=config_code, syspath = repr(sys.path))
+
+ script = os.path.join(d, get_temp_module_name() + '.py')
+ dst_sources.append(script)
+ f = open(script, 'wb')
+ f.write(asbytes(code))
+ f.close()
+
+ # Build
+ cwd = os.getcwd()
+ try:
+ os.chdir(d)
+ cmd = [sys.executable, script, 'build_ext', '-i']
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ out, err = p.communicate()
+ if p.returncode != 0:
+ raise RuntimeError("Running distutils build failed: %s\n%s"
+ % (cmd[4:], out))
+ finally:
+ os.chdir(cwd)
+
+ # Partial cleanup
+ for fn in dst_sources:
+ os.unlink(fn)
+
+ # Import
+ __import__(module_name)
+ return sys.modules[module_name]
+
+#
+# Unittest convenience
+#
+
+class F2PyTest(object):
+ code = None
+ sources = None
+ options = []
+ skip = []
+ only = []
+ suffix = '.f'
+ module = None
+ module_name = None
+
+ def setUp(self):
+ if self.module is not None:
+ return
+
+ # Check compiler availability first
+ if not has_c_compiler():
+ raise nose.SkipTest("No C compiler available")
+
+ codes = []
+ if self.sources:
+ codes.extend(self.sources)
+ if self.code is not None:
+ codes.append(self.suffix)
+
+ needs_f77 = False
+ needs_f90 = False
+ for fn in codes:
+ if fn.endswith('.f'):
+ needs_f77 = True
+ elif fn.endswith('.f90'):
+ needs_f90 = True
+ if needs_f77 and not has_f77_compiler():
+ raise nose.SkipTest("No Fortran 77 compiler available")
+ if needs_f90 and not has_f90_compiler():
+ raise nose.SkipTest("No Fortran 90 compiler available")
+
+ # Build the module
+ if self.code is not None:
+ self.module = build_code(self.code, options=self.options,
+ skip=self.skip, only=self.only,
+ suffix=self.suffix,
+ module_name=self.module_name)
+
+ if self.sources is not None:
+ self.module = build_module(self.sources, options=self.options,
+ skip=self.skip, only=self.only,
+ module_name=self.module_name)
More information about the Numpy-svn
mailing list