Hello,<br><br>I&#39;m a bit new to pyrex and am not too clear about how dictionaries<br>are handled.&nbsp; I&#39;m using a number of python dictionaries where the<br>indices (keys) and the values are 64 bit numbers (from 0 to (1&lt;&lt;64) - 1).
<br>(i.e. unsigned long long...U64).<br>While the arrays contain (and are indexed by) U64 numbers, they do not<br>contain that many values (no more then 64x256 entries).&nbsp; <br><br>I&#39;d like to move the most CPU intensive portions of my code to pyrex
<br>modules but I&#39;m not quite sure how to do this.&nbsp; I know that one can create<br>unsigned long long variables, but how should the dictionaries be declared and created?<br>And where are they declared and created?&nbsp; In python or the pyrex functions?&nbsp; From what
<br>I can gather, any access to a dictionary (whether created in python or pyrex<br>code) slows everything down to pure python speeds.<br><br>This is a small sample of what I&#39;m trying to do:<br>Most of the time is spent in functions like get_move
<br>and these functions need to access dictionaries made up of<br>these 64 bit numbers.<br><br>Any help would be appreciated.<br><br>Thanks,<br>Sam<br><br>---------------------------<br>Python<br>=====<br>rank = {}<br>rank_mask = {}
<br>count = 0<br>rank[0] = 0<br>rank_mask[0] = 0<br>for i in range(1,9):<br>&nbsp;&nbsp;&nbsp; for j in range(8,0,-1):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rank[1L&lt;&lt;count]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = i<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rank_mask[1L&lt;&lt;count] = (255L&lt;&lt;8*(i-1))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count = count + 1
<br><br>rank_attacks = {}&nbsp;&nbsp; # long complicated definition...<br>rank_attacks[1&lt;&lt;45] = {}<br>rank_attacks[1&lt;&lt;45][0] = 0<br><br><br>piece = 1&lt;&lt;45 <br>all_pieces = 1&lt;&lt;35 | 1&lt;&lt;33<br>other_pieces = 1&lt;&lt;62
<br><br>print sample1.get_move(piece,all_pieces,other_pieces,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rank_mask,rank_attacks)<br><br><br>Pyrex<br>====<br>def get_move(unsigned long long piece, unsigned long long all_pieces,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long long other_pieces, rank_mask, rank_attacks):
<br><br>&nbsp;&nbsp;&nbsp; cdef unsigned long long from_square<br>&nbsp;&nbsp;&nbsp; cdef unsigned long long rank_pieces<br>&nbsp;&nbsp;&nbsp; cdef unsigned long long to_square<br><br>&nbsp;&nbsp;&nbsp; mymoves = []<br><br>&nbsp;&nbsp;&nbsp; while (piece):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from_square = piece &amp; -piece
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # handle the rank attacks<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rank_pieces = rank_mask[from_square] &amp; all_pieces<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # this produces all moves including our own piece attacks<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; moves = (rank_attacks[from_square][rank_pieces] &amp; other_pieces) | \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (rank_attacks[from_square][rank_pieces] &amp; ~all_pieces) <br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(moves):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to_square = moves &amp; -moves<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mymoves.append[(from_square,to_square)]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; moves = moves &amp; (moves - 1)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; piece = piece &amp; (piece - 1)<br><br>&nbsp;&nbsp;&nbsp; return moves<br><br><br>---------------------------------------<br>