Re: [f2py] problems with array

Al Niessner <[email protected]> Wed, 11 Aug 2010 11:41:08 -0700
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
Very good. It is what I was going to do. Thanks so much for your help on
this problem as well as all the others.

On Wed, 2010-08-11 at 11:29 -0700, Pearu Peterson wrote:
> On Wed, Aug 11, 2010 at 8:56 PM, Al Niessner <[email protected]> wrote:
> >
> > I have a function that returns an array but it crashes when I call the
> > function.
> >
> > f2py -c kinds.f90 mathsub.f90 -m mathsub
> >
> > n [1]: import mathsub
> >
> > In [2]: i = mathsub.math_mod.eye(3)
> > ---------------------------------------------------------------------------
> > ValueError                                Traceback (most recent call
> > last)
> >
> > /home/niessner/Scratch/Example/<ipython console> in <module>()
> >
> > ValueError: failed to create intent(cache|hide)|optional array-- must
> > have defined dimensions but got (-1,-1,)
> 
> Currently f2py does not support wrapping functions that return
> arrays. There is simple workaround to this problem: write a wrapper
> subroutine that calls such functions. For example, for your case
> add the following subroutine to math_mod module
> 
>         subroutine weye(r, n)
>           real(8), dimension(n,n) :: r
>           integer n
>           !f2py intent(out) r
>           r = eye(n)
>         end subroutine weye
> 
> and use weye to call eye function from python:
> 
>   f2py -c kinds.f90 mathsub.f90 -m mathsub skip: eye
> 
> >>> import mathsub
> >>> mathsub.math_mod.weye(3)
> 
> array([[ 1.,  0.,  0.],
>        [ 0.,  1.,  0.],
>        [ 0.,  0.,  1.]])
> 
> Pearu
> 
> _______________________________________________
> f2py-users mailing list
> f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
> http://cens.ioc.ee/mailman/listinfo/f2py-users

-- 
Al Niessner
818.354.0859

--------
|  dS  | >= 0
--------