[NumPy-Tickets] [NumPy] #1532: f2py does not respect assumed size arrays of fortran 90
NumPy Trac
numpy-tickets@scipy....
Fri Feb 25 05:25:26 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: devel
Resolution: | Keywords:
--------------------------+-------------------------------------------------
Comment(by lorenz):
I'm glad that I could help, thanks for the quick response to you!
Why do you think generating a wrapper with an interface could not be done
automatically? For clarity, lets stick to a much simpler example than the
above:
test.f90
{{{
subroutine assumed_shape_test(x, res)
implicit none
real, intent(in) :: x(:)
real, intent(out) :: res
integer :: i
print *, "size(x) = ", size(x)
res = 0.0
do i = 1, size(x)
res = x(i)
enddo
end subroutine
}}}
I think it should be possible to use the parsed information about this
subroutine to generate a short wrapper subroutine ala
{{{
subroutine assumed_shape_test_wrap(x, n, res)
implicit none
real, intent(in) :: x(n)
integer :: n
real, intent(out) :: res
interface
subroutine assumed_shape_test(x, res)
implicit none
real, intent(in) :: x(:)
real, intent(out) :: res
end subroutine
end interface
call assumed_shape_test(x, res)
end subroutine
}}}
which, when wrapped with f2py, will look exactly as the original routine
was probably expected to wrap, and will make the assumed-shape arrays
behave:
{{{
~/f2py_assumed_shape_test> f2py -c -m test test.f90 >/dev/null # skipt its
stdout for this example
~/f2py_assumed_shape_test> python -c "import test; print
test.assumed_shape_test([1.0,2.0,3.0])"
size(x) = 7675552
Segmentation fault
~/f2py_assumed_shape_test> python -c "import test; print
test.assumed_shape_test_wrap([1.0,2.0,3.0])"
size(x) = 3
3.0
}}}
A recipe for generating such a fortran wrap subroutine would probably be:
* Use the declaration of the original routine as a template
* For every assumed shape array (lets call it "a") and for every of its
dimensions insert new arguments ("dim1_a", "dim2_a", ...) of type
integer
* Declare the assumed size arrays with an explicit shape (ala
"a(dim1_a, dim2_a, ...)"), to allow the f2py wrapping magic to use it
as the shape of the array to pass.
I don't know anything about the internals of f2py, so I can't say whether
the automatic generation of a fortran wrapper subroutine is something
easily done there, or whether maybe similar stuff happens already in the
background anyway :)
Regards and keep up the good work with f2py,
Lorenz
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1532#comment:4>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list