[f2py] Create array in Python, deallocate in Fortran
Ben Forbes <[email protected]> Fri, 29 Apr 2011 16:19:09 +1000
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <[email protected]> |
When I create an array in Python, then deallocate it in Fortran, it
doesn't appear to do anything to the original Python array. Here is
the code:
helloworld.f90:
module mymodule
real(8),allocatable,dimension(:,:)::b
subroutine foo()
deallocate(b)
write(*,*) allocated(b)
end subroutine foo2
end module mymodule
Python:
import helloworld
arr=np.array([[1,2],[3,4]],dtype=np.float64,order='F')
Out[2]:
array([[ 1., 2.],
[ 3., 4.]])
helloworld.mymodule.b=arr
Out[6]:
array([[ 1., 2.],
[ 3., 4.]])
helloworld.mymodule.foo()
Out: F
arr
Out[2]:
array([[ 1., 2.],
[ 3., 4.]])
Fortran thinks it has deallocated b, but Python still has the original
array. I've included the directive -DF2PY_REPORT_ON_ARRAY_COPY=2, and
it doesn't give any array copy warnings.
How can I understand this behaviour? Is it potentially dangerous to
deallocate from Fortran?
--
Benjamin D. Forbes
School of Physics
The University of Melbourne
Parkville, VIC 3010, Australia