[Pyrex] python dictionaries with unsigned long long keys and values

Lenard Lindstrom len-l at telus.net
Wed Mar 14 18:33:47 UTC 2007


Sam Tannous wrote:
> Hello,
>
> I'm a bit new to pyrex and am not too clear about how dictionaries
> are handled.  I'm using a number of python dictionaries where the
> indices (keys) and the values are 64 bit numbers (from 0 to (1<<64) - 1).
> (i.e. unsigned long long...U64).
> While the arrays contain (and are indexed by) U64 numbers, they do not
> contain that many values (no more then 64x256 entries). 
>
> I'd like to move the most CPU intensive portions of my code to pyrex
> modules but I'm not quite sure how to do this.  I know that one can create
> unsigned long long variables, but how should the dictionaries be 
> declared and created?
> And where are they declared and created?  In python or the pyrex 
> functions?  From what
> I can gather, any access to a dictionary (whether created in python or 
> pyrex
> code) slows everything down to pure python speeds.
>
>

All dictionaries are Python dictionaries. Pyrex automatically converts 
between U64 and Python long for the keys and values. There are no C 
integer specific Python mapping types. You might have to write your own 
or, if possible, redesign you algorithm to use arrays.

Another way to optimize, if you are using x86 machines, is with Psyco. 
It will not help with the dictionaries, but it might boost the 
performance of the rest of the code (it's not clear what Pysco does with 
U64 integers.)

-- 
Lenard Lindstrom
<len-l at telus.net>




More information about the Pyrex mailing list