[SciPy-dev] are arrays hashable?

Travis Oliphant oliphant at ee.byu.edu
Tue Sep 20 18:55:27 EDT 2005


Robert Kern wrote:

>Travis Oliphant wrote:
>
>  
>
>>Yes, the new array scalars should be hashable (because they are
>>immutable).  I've probably overlooked something.  I'll look into it.
>>    
>>
>
>You need to implement tp_hash functions for all of the scalar types. It
>looks like it shouldn't be too bad. I think that except for the
>extra-long types, you can just piggyback on the implementations for
>int(), float(), and complex() objects. For the unsigned integer types,
>just cast to a long. For the signed, cast to a long (and if the casted
>version == -1, return -2 since -1 signals an error). For the float
>types, I think it's going to be acceptable to cast to a double and use
>_Py_HashDouble(). I have not the slightest idea what void objects should
>do. Possibly just return the hash of the pointer itself.
>
>For the extra long types ("long long", "unsigned long long", "long
>double", "complex long double"), you have to check if they are within
>the range of the regular types ("long", "unsigned long", etc.) and be
>sure to return the same hash value. I'm not sure what the right answer
>is for the other values, though.
>
>  
>

I'll do this, it shouldn't be too hard.  In fact, I just now, added code 
to inherit the
hash function from the Python builtins for those array scalars that can 
(int, intc-depending on platform, float, complex, string, and unicode):

In particular, it solves the problem Alan had. 

I'll look into the others...

-Travis






More information about the SciPy-Dev mailing list