← Back to team overview

dolfin team mailing list archive

Re: [Merge] lp:~jobh/dolfin/python into lp:dolfin

 

On Friday January 28 2011 15:51:59 Joachim Berdal Haga wrote:
> Hi,
> 
> > Thanks for the numpy.isscalar patch. I wonder if you know if this is
> > related
> > to a bug in Python2.6 together with numpy? As there really should not be
> > a reason for
> > 
> >  isinstance(float128(1.), float)
> > 
> > to be False. I have implemented our own IsInteger function in the SWIG
> > layer
> > (not exposed to Python) for checking integer types in typemaps for this
> > particular reason.
> 
> I have no idea, to be honest -- I only have 2.6 installed. But: even
> without bug, only the native python sizes (float64 and int32/int64) are
> subclasses of the python types, yet all of them are coercible to floats.
> 
> What I wanted was to prevent this:
>   >>> v = dolfin.Vector(1)
>   >>> print type(numpy.float64(1) * v)
> 
>   <type 'numpy.ndarray'>
> 
> ... but it didn't achieve that due to float64.__mul__ being called before
> Vector.__rmul__. So this still needs looking at, to ensure the Vector isn't
> implicitly converted to an ndarray (so that Vector.__rmul__ is called as it
> should).

Yes I recall having the same problem. These numpy types are really greedy wrt 
what you can multiply them with...

Johan



Follow ups

References