File size: 1,482 Bytes
c011401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
>>> import pytest
>>> import f2pytest
>>> import pyforttest
>>> print f2pytest.foo.__doc__
foo - Function signature:
  a = foo(a)
Required arguments:
  a : input rank-2 array('f') with bounds (m,n)
Return objects:
  a : rank-2 array('f') with bounds (m,n)

>>> print pyforttest.foo.__doc__
foo(a)

>>> pytest.foo([[1,2],[3,4]])
array([[12, 14],
       [24, 26]])
>>> f2pytest.foo([[1,2],[3,4]])  # F2PY can handle arbitrary input sequences
array([[ 12.,  14.],
       [ 24.,  26.]],'f')
>>> pyforttest.foo([[1,2],[3,4]])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
pyforttest.error: foo, argument A: Argument intent(inout) must be an array.

>>> import Numeric
>>> a=Numeric.array([[1,2],[3,4]],'f')
>>> f2pytest.foo(a)
array([[ 12.,  14.],
       [ 24.,  26.]],'f')
>>> a   # F2PY makes a copy when input array is not Fortran contiguous
array([[ 1.,  2.],
       [ 3.,  4.]],'f')
>>> a=Numeric.transpose(Numeric.array([[1,3],[2,4]],'f'))
>>> a
array([[ 1.,  2.],
       [ 3.,  4.]],'f')
>>> f2pytest.foo(a)
array([[ 12.,  14.],
       [ 24.,  26.]],'f')
>>> a   # F2PY passes Fortran contiguous input array directly to Fortran
array([[ 12.,  14.],
       [ 24.,  26.]],'f')
# See intent(copy), intent(overwrite), intent(inplace), intent(inout)
# attributes documentation to enhance the above behavior.

>>> a=Numeric.array([[1,2],[3,4]],'f')
>>> pyforttest.foo(a)
>>> a   # Huh? Pyfort 8.5 gives wrong results..
array([[ 12.,  23.],
       [ 15.,  26.]],'f')