[NumPy-Tickets] [NumPy] #2047: f2py needs to be updated to use non-deprecated macros/functions
NumPy Trac
numpy-tickets@scipy....
Fri Apr 20 08:44:46 CDT 2012
#2047: f2py needs to be updated to use non-deprecated macros/functions
------------------------+---------------------------------------------------
Reporter: charris | Owner: pearu
Type: task | Status: needs_decision
Priority: normal | Milestone: 1.7.0
Component: numpy.f2py | Version: devel
Keywords: |
------------------------+---------------------------------------------------
Changes (by pearu):
* status: new => needs_decision
Comment:
There is one gotcha with fixing this issue.
Consider the following example:
{{{
!file foo.f90
subroutine foo (a)
integer, dimension (2) :: a
!f2py intent (inplace) a
a(1) = 7
end subroutine foo
}}}
and compile it with f2py: {{{f2py -c -m foo foo.f90}}}.
The gotcha is illustrated with the following test:
{{{
$ python -c 'import foo, numpy; a=numpy.array([1,2], dtype=numpy.int16);
print id(a),a,a.dtype;foo.foo(a); print id(a),a,a.dtype'
45223856 [1 2] int16
45223856 [7 2] int32
}}}
Notice that initially 16-bit numpy array is turned to 32-bit array *in
place* while the id's of arrays are *not* changed. This non-pythonic
"feature" is achieved by using swap_arrays function (in fortranobject.c).
Regarding non-pythonic: while this is generally bad idea for Python
programmers, Fortran programmers use this non-pythonic feature all the
time, so swap_arrays is a compromise made many years ago when f2py was
standalone.
Since the aim of this issue is to avoid using swap_arrays, I am now stuck
with what to do as numpy API does not provide equivalent method to the
swap_arrays function.
We have multiple choices:
1) introduce swap_arrays function to numpy. Then this issue cannot be
fixed for 1.7. And, perhaps more importantly, a non-pythonic function is
introduced to numpy that probably needs a wider discussion.
2) remove swap_arrays from numpy. Again, this is not a 1.7 issue as it
will break numpy 1.6 based code that uses the swap_arrays feature.
3) keep swap_arrays as it is and try to reimplement it using non-
deprecated numpy macros/functions.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/2047#comment:7>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list