[SciPy-user] Finding complex roots of complex polynomials in newscipy

Robert Kern rkern at ucsd.edu
Sun Nov 13 02:36:38 CST 2005


Fernando Perez wrote:

> This is in fact how regular python works:
> 
> In [26]: isinstance(int,int)
> Out[26]: False
> 
> In [27]: isinstance(int(),int)
> Out[27]: True
> 
> However, where scipy differs from python is here:
> 
> In [28]: iarr = scipy.arange(2)
> 
> In [29]: isinstance(iarr,scipy.integer)
> Out[29]: False

The scipy.{integer,complexfloating,...} are the scalar type objects.
Full arrays are instances of scipy.ndarray, not the scalar type objects.
However, the arrays have the dtype attribute which should be one of
these scalar type objects. You can check the inheritance of the scalar
type objects using issubclass(), not isinstance().

[From other email:]

> OK, in that case the roots() call in scipy.polynomial needs fixing,

It is now.

> and  perhaps a fair bit of code out there that used isinstance is
> going to break. See my other message (which I sent as yours came in)
> for further details on this.  Before we change any code, I'd like to
> understand (and hopefully this should be clearly documented) how types
> should be handled with the new scipy.

How's that? isinstance(Numeric.ones(5), Numeric.Int) never worked. On
general arrays isinstance() can only tell if it's a scipy.ndarray or
something else. Nothing's changed so far. isinstance() works as expected
on the scalar types although issubclass(x.dtype, whatever) works, too.

Take a closer look at the actual uses of isinstance() in the old scipy.
They're all testing for ArrayType, a class, or one of the standard
types. That all works the same with scipy_core.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter



More information about the SciPy-user mailing list