[SciPy-user] operations on int8 arrays

Travis Oliphant oliphant at ee.byu.edu
Wed Oct 19 18:35:06 CDT 2005


Fernando Perez wrote:

>Travis Oliphant wrote:
>  
>
>>One issue, though.  Upcasting to a different type will be slower.
>>    
>>
>
>It may be slower, but for the very small types, (8-bit), not upcasting is 
>almost guaranteed to be wrong.  That's why I think that the case of 
>accumulators deserves special treatment: without it, the functions are 
>time-bombs waiting to go off (and they have in the past, as we've seen on this 
>list multiple times).  For wider types you are obviously less likely to hit 
>the problem, but for small ones it is very acute.
>
>People who know that they are adding less than 256 unsigned 8-bit integers, 
>all so small that their sum can't be > 255 (and I don't know how they can know 
>this in advance) could always call the routine with rtype=uint8.  Most people 
>would rather get the numerically correct answer, rather than the mysterious 
>'sum() % 255', which is effectively what the code does today.
>
>  
>
By the way,

the sum, prod, cumsum, and cumprod functions already upcast by default 
for 8-bit and 16-bit integer types and bool types (as of SVN check in).

-Travis



More information about the SciPy-user mailing list