[Numpy-discussion] Numeric/numarray compatibility issue

Perry Greenfield perry at stsci.edu
Fri Mar 4 10:51:33 CST 2005


On Mar 4, 2005, at 1:24 PM, konrad.hinsen at laposte.net wrote:

> On 04.03.2005, at 16:44, Perry Greenfield wrote:
>
>> First of all, isn't the current behavior a little similar to Python 
>> in that Python Booleans aren't pure either (for backward 
>> compatibility purposes)?
>
> Possibly, but the use of boolean scalars and boolean arrays is very 
> different, so that's not necessarily the model to follow.
>
No, but that some people know that arithmetic can be done with Python 
Booleans may lead them to think the same should be possible with 
Boolean arrays (not that should be the sole criteria).

>> for both). Using .astype(Int32)
>
> Right, because it doesn't work with Numeric.
>
>>  should work for both, right? (or is that too much of a speed hit?) 
>> But it is a
>
> Yes, but it costs both time and memory.  I am more worried about the 
> memory, since this is one of the few operations that I do mostly with 
> big arrays. Under Numeric, this doubles memory use, costs time, and 
> makes no difference for the result. I am not sure that numarray 
> compatibility is worth that much for me (OK, there is a dose of 
> laziness in that argument as well).
>
Hmmm, I'm a little confused here. If the overflow issue is what you are 
worried about, then use of Int8 for boolean results would still be a 
problem here. Since Numeric is already likely generating Int32 from 
logical ufuncs (Int actually), the use of astype(Int) is little 
different than many of the temporaries that Numeric creates in 
expressions. I find it hard to believe that this is a make or break 
issue for Numeric users since it typically generates more temporaries 
than does numarray.

>>  fair question to ask if arithmetic operations should be allowed on 
>> booleans without explicit casts.
>>
> What is actually the difference between Bool and Int8?
>
I'm not sure I remember all the differences (Todd can add to this if he 
remembers better). Booleans are treated differently as array indices 
than Int8 arrays are. The machinery of generating Boolean results is 
different in that it forces results to be either 0 or 1. In other 
words, Boolean arrays should only have 0 or 1 values in those bytes 
(not that it isn't possible for someone to break this in C code or 
though undiscovered bugs. Ufuncs that generate different values such as 
arithmetic operators result in a different type.

Perry





More information about the Numpy-discussion mailing list