[NumPy-Tickets] [NumPy] #1532: f2py does not respect assumed size arrays of fortran 90
NumPy Trac
numpy-tickets@scipy....
Fri Feb 25 03:35:01 CST 2011
#1532: f2py does not respect assumed size arrays of fortran 90
--------------------------+-------------------------------------------------
Reporter: ozn | Owner: pearu
Type: enhancement | Status: reopened
Priority: normal | Milestone: Unscheduled
Component: numpy.f2py | Version: 1.3.0
Resolution: | Keywords:
--------------------------+-------------------------------------------------
Changes (by lorenz):
* cc: lorenz@… (added)
* status: closed => reopened
* resolution: wontfix =>
* milestone: 2.0.0 => Unscheduled
Comment:
Is this still up to date? I tried with numpy 1.4.0.
I think the realy problem is that the code in both the report and the
reply
is not proper Fortran, so it is not totally strange that gfortran fails on
the example pearu provided: Assumed-shape arrays can only be used in
subroutines with explicit interfaces!
So either put them in a module or declare the interface.
I shrunk down the convoluted example quite a bit to make clear whats going
on:
== dsum_faulty.f90 ==
{{{
subroutine dsum(b, a, n)
implicit none
integer, intent(in) :: n
real,intent(in) :: a(n)
real,intent(out) :: b
integer :: i
b=0.0d0
do i=1,n
b=b+a(i)
end do
end subroutine
subroutine locpt_wrap(x0,x,n)
implicit none
real, intent(inout) :: x0
real, intent(in) :: x(n)
integer, intent(in) :: n
print *, "locpt_wrap: size(x) = ", size(x)
! You should'nt call a subroutine with assumed-shape
! arguments without an interface! This will fail:
call locpt(x0,x,n)
end subroutine locpt_wrap
subroutine locpt(x0,x,n)
implicit none
integer, intent(in) :: n
real, intent(inout) :: x0
real, intent(in) :: x(:)
print *, "locpt: x0 = ", x0
print *, "locpt: size(x) = ", size(x)
print *, "locpt: x = ", x
print *, 'locpt: n', n
call dsum(x0,x,n)
print *, 'locpt: sum = ', x0
end subroutine locpt
}}}
== dsym_explicit_interface.f90 ==
{{{
subroutine dsum(b, a, n)
implicit none
integer, intent(in) :: n
real,intent(in) :: a(n)
real,intent(out) :: b
integer :: i
b=0.0d0
do i=1,n
b=b+a(i)
end do
end subroutine
subroutine locpt_wrap(x0,x,n)
implicit none
real, intent(inout) :: x0
real, intent(in) :: x(n)
integer, intent(in) :: n
interface
subroutine locpt(x0,x,n)
implicit none
integer, intent(in) :: n
real, intent(inout) :: x0
real, intent(in) :: x(:)
end subroutine locpt
end interface
print *, "locpt_wrap: size(x) = ", size(x)
call locpt(x0,x,n)
end subroutine locpt_wrap
subroutine locpt(x0,x,n)
implicit none
integer, intent(in) :: n
real, intent(inout) :: x0
real, intent(in) :: x(:)
print *, "locpt: x0 = ", x0
print *, "locpt: size(x) = ", size(x)
print *, "locpt: x = ", x
print *, 'locpt: n', n
call dsum(x0,x,n)
print *, 'locpt: sum = ', x0
end subroutine locpt
}}}
== dsum_module.f90 ==
{{{
module mymod
contains
subroutine dsum(b, a, n)
implicit none
integer, intent(in) :: n
real,intent(in) :: a(n)
real,intent(out) :: b
integer :: i
b=0.0d0
do i=1,n
b=b+a(i)
end do
end subroutine
subroutine locpt_wrap(x0,x,n)
implicit none
real, intent(inout) :: x0
real, intent(in) :: x(n)
integer, intent(in) :: n
print *, "locpt_wrap: size(x) = ", size(x)
call locpt(x0,x,n)
end subroutine locpt_wrap
subroutine locpt(x0,x,n)
implicit none
integer, intent(in) :: n
real, intent(inout) :: x0
real, intent(in) :: x(:)
print *, "locpt: x0 = ", x0
print *, "locpt: size(x) = ", size(x)
print *, "locpt: x = ", x
print *, 'locpt: n', n
call dsum(x0,x,n)
print *, 'locpt: sum = ', x0
end subroutine locpt
end module mymod
}}}
Compile them
{{{
f2py -c -m dsum_faulty dsum_faulty.f90
f2py -c -m dsum_explicit_interface dsum_explicit_interface.f90
f2py -c -m dsum_module dsum_module.f90
}}}
and observe how the first one fails and the other two succeed:
{{{
lorenz@nco-9:~/f2py_assumed_shape_test> python -c 'import dsum_faulty as
dsum; dsum.locpt_wrap(2.0,(2.0,1.0,3.0))'
locpt_wrap: size(x) = 3
locpt: x0 = 2.0000000
locpt: size(x) = 0
locpt: x =
locpt: n 3
Segmentation fault
~/f2py_assumed_shape_test> python -c 'import dsum_explicit_interface as
dsum; dsum.locpt_wrap(2.0,(2.0,1.0,3.0))'
locpt_wrap: size(x) = 3
locpt: x0 = 2.0000000
locpt: size(x) = 3
locpt: x = 2.0000000 1.0000000 3.0000000
locpt: n 3
locpt: sum = 6.0000000
~/f2py_assumed_shape_test> python -c 'import dsum_module as dsum; dsum =
dsum.mymod; dsum.locpt_wrap(2.0,(2.0,1.0,3.0),3)'
locpt_wrap: size(x) = 3
locpt: x0 = 2.0000000
locpt: size(x) = 3
locpt: x = 2.0000000 1.0000000 3.0000000
locpt: n 3
locpt: sum = 6.0000000
~/f2py_assumed_shape_test>
}}}
So I don't really see the problem with taking care of assumed-shape
arrays,
as they already seem to work. I boldly reopen the bug, as "wontfix" does
not seem justified for something that apparently works :)
Regards,
Lorenz
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1532#comment:2>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list