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

Robert Kern robert.kern@gmail....
Wed Feb 17 15:43:00 CST 2010

On Wed, Feb 17, 2010 at 15:29, Fabrice Silva <silva@lma.cnrs-mrs.fr> wrote:
> 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.

Yeah, that's pretty much what you would have to do.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the NumPy-Discussion mailing list