[Numpy-discussion] f2py: variable number of arguments of variable lengths

Fabrice Silva silva@lma.cnrs-mrs...
Wed Feb 17 15:29:20 CST 2010


I previously coded a fortran function that needs a variable number of
scalar arguments. This number is not known at compile time, but at call
time. So I used to pass them within a vector, passing also the length of
this vector

              subroutine systeme(inc,t,nm,Dinc,sn)
        C
        C      evaluate the derivative of vector x at time t
        C      with complex modes (sn). Used for the calculation
        C      of auto-oscillations in resonator-valve coupled system.
        C
              integer nm,np,ny,ind 
              double precision inc(1:2*nm+2), Dinc(1:2*nm+2)
              complex*16 sn(1:nm)
              
        Cf2py double precision, intent(in) :: t
        Cf2py integer, intent(in), optional :: nm
        Cf2py double precision, intent(in), dimension(2*nm+2) :: inc
        Cf2py double precision, intent(out), dimension(2*nm+2) :: Dinc
        Cf2py complex, intent(in), dimension(nm) :: sn


I do now want to pass, not nm float values, but nm arrays of variables
lengths. I expect to pass the following objects :
- nm: number of arrays
- L : a 1d-array (dimension nm) containing the lengths of each array
- np: the sum of lengths
- X : a 1d-array (dimension np) containing the concatenated arrays.

Does anyone have an alternative to this suggestion ? any tip or example?
Regards

-- 
Fabrice Silva
LMA UPR CNRS 7051



More information about the NumPy-Discussion mailing list