[SciPy-Dev] Indexing sparse matrices
Thu Jun 24 10:25:29 CDT 2010
Thu, 24 Jun 2010 09:39:30 -0500, Bruce Southey wrote:
> On 06/23/2010 11:43 PM, Jason Grout wrote:
>> The thing is that the index object may not be a scalar, but it may have
>> an __index__ method that is supposed to be used when the object is used
>> as an index. So the call to isscalar may rightfully return False, but
>> the __index__ method should still be called to see if there is a value
>> to act as an index. For example, according to Python>=2.5, this should
> Remember (as given below) that numpy officially supports Python 2.4 so
> any Python 2.5+ features are not allowed (at least until some one
> notices them).
> If you just look at the numpy's isscalar function you can see why it
> fails - so file a bug report on it.
I believe Jason is correct here: since sparse matrices are an indexable
container type, they should support the __index__ protocol. So it's a
Scipy issue, and I don't see any reasons why not to add support for that.
Supporting Python 2.4 at the same time should not be a problem.
This is a separate issue from numpy.isscalar. In that case it is not
clear whether an object supporting the __int__ / __float__ / __complex__
number protocols should be treated as a scalar. Most likely not, since
that is not enough to make them work like scalars in arithmetic.
More information about the SciPy-Dev