[SciPy-user] scipy.f2py and Numeric arrays

Chris Fonnesbeck fonnesbeck at gmail.com
Thu Nov 10 14:05:29 CST 2005


On 11/10/05, Travis Oliphant <oliphant at ee.byu.edu> wrote:
> Chris Fonnesbeck wrote:
>
> >On 11/9/05, Travis Oliphant <oliphant at ee.byu.edu> wrote:
> >
> >
> >>Chris Fonnesbeck wrote:
> >>
> >>
> >>
> >>>It appears that passing Numeric arrays to extensions built with
> >>>scipy.f2py do not work.
> >>>
> >>>(Pdb) _poisson(x,mu)          <==== These arguments are Numeric arrays
> >>>Out[2]: nan
> >>>(Pdb) _poisson(scipy.array(x),scipy.array(mu))
> >>>Out[2]: -146.43360900878906
> >>>(Pdb) _poisson(x.tolist(),mu.tolist())
> >>>Out[2]: -146.43360900878906
> >>>
> >>>Is this intended behaviour? I still need to be able to use Numeric
> >>>arrays until scipy_core becomes more stable.
> >>>
> >>>
> >>>
> >>>
> >>This was a bug in the new array_struct  array interface that was just
> >>recently added.   It has been fixed now in SciPy SVN.
> >>
> >>
> >>
> >
> >Just updated from svn. When I try and pass Numeric arrays I get a type error:
> >
> >TypeError: array cannot be safely cast to required type
> >
> >
> >
> And  you didn't get this with Numeric?   That would be surprising,
> unless f2py used to FORCE CAST the results --- I can look into that.
>
> It looks like your generated Fortran code is expecting float32.  If you
> try and pass in float64 you get the type error as the cast tries to get
> made.
>
> The behavior of f2py should not have changed, but looking at the old
> code seems to indicate that you would have received this error
> previously as well.
>

This absolutely worked before. PyMC was originally based around
Numeric, and f2py statistical likelihood functions received Numeric
array arguments regularly.

--
Chris Fonnesbeck
Atlanta, GA



More information about the SciPy-user mailing list