[SciPy-dev] Fancy indexing curiosity

Pearu Peterson pearu at scipy.org
Sun Jan 8 03:58:08 EST 2006



On Sun, 8 Jan 2006, Travis Oliphant wrote:

>> Thanks for this corner case.  Actually, it's getting whatever is in the
>> memory allocated.
>>
>> Try
>>
>> b = array('',x.dtype)
>>
>> b should be a size-0 array,  (there is actually 1 elementsize of memory
>> allocated for it though).
>>
>> The mapping code is iterating over b and resetting b whenever it runs
>> out of elements of b (every time in this case), except the data pointed
>> to by the iterator is never valid so this should not be allowed....
>>
>> I suppose instead, creating an iterator from a size-0 array could raise
>> an error.  This would be a great and simple place to catch this in the
>> code as well.
>>
> This now raises an error....

I guess the following behaviour is related to recent changes on svn, as 
well as causing some of the unittests to fail:

In [1]: from numpy import *

In [2]: a=array([])

In [3]: equal(a,a)
---------------------------------------------------------------------------
exceptions.ValueError                                Traceback (most 
recent call last)

/home/pearu/<console>

ValueError: Cannot iterate over a size-0 array

In [5]: a==a
Out[5]: False

In [6]: a is a
Out[6]: True

I would expect that empty sets are always equal to each other.

Pearu




More information about the SciPy-Dev mailing list