[Numpy-discussion] f2py: variable number of arguments of variable lengths
Wed Feb 17 16:21:37 CST 2010
On Wed, Feb 17, 2010 at 15:55, Fabrice Silva <firstname.lastname@example.org> wrote:
> Le mercredi 17 février 2010 à 15:43 -0600, Robert Kern a écrit :
>> On Wed, Feb 17, 2010 at 15:29, Fabrice Silva <email@example.com> 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.
> What about the next step: a variable number of arguments that are
> 2d-arrays with different shapes ?
- nm: number of arrays
- ncols : a 1d-array (dimension nm) containing the number of columns
in each array
- nrows : a 1d-array (dimension nm) containing the number of rows in each array
- np: the sum of array sizes [(ncols * nrows).sum() in numpy terms]
- X : a 1d-array (dimension np) containing the concatenated arrays.
"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