[Cython] FW: cython and hash tables / dictionary
Hi mailing,
I’ve been writing a complex program in python, which I am currently scaling up. I find myself in the position now, where I run out of memory or out of time. I have been looking at alternatives like cython and ctypes. I implemented ctypes which fixes the memory problem but doubles the time problem.
Currently I am implementing a cython version and ran into a problem. I hope someone can help me out.
The main bottleneck in my code is a large dictionary / hash table which I would like to optimize. Since a dictionary is a python datatype I have no idea how to make this cython.
Currently I have tried to keep the ‘keys’ intact and store the ‘values’ as ctypes floats, but I think it might be better to do something else. Do I need to make the entire hash table c? Or is there a more simple solution like combining the python dict with cython? If so, how do I do this?
Thanks in advance.
Additional details: I use a double dict where the key of the first dict stores another dict as value.
S.
<div> <div class="Section1"> <p class="MsoNormal"><span lang="EN-US">Hi mailing,<p></p></span></p> <p class="MsoNormal"><span lang="EN-US"><p> </p></span></p> <p class="MsoNormal"><span lang="EN-US">I’ve been writing a complex program in python, which I am currently scaling up. I find myself in the position now, where I run out of memory or out of time. I have been looking at alternatives like cython and ctypes. I implemented ctypes which fixes the memory problem but doubles the time problem.<p></p></span></p> <p class="MsoNormal"><span lang="EN-US"><p> </p></span></p> <p class="MsoNormal"><span lang="EN-US">Currently I am implementing a cython version and ran into a problem. I hope someone can help me out.<p></p></span></p> <p class="MsoNormal"><span lang="EN-US"><p> </p></span></p> <p class="MsoNormal"><span lang="EN-US">The main bottleneck in my code is a large dictionary / hash table which I would like to optimize. Since a dictionary is a python datatype I have no idea how to make this cython.<p></p></span></p> <p class="MsoNormal"><span lang="EN-US"><p> </p></span></p> <p class="MsoNormal"><span lang="EN-US">Currently I have tried to<span> keep the ‘keys’ intact and</span> store the <span>‘</span>values<span>’</span> as ctypes floats, but I think it might be better to do something else. Do I need to make the entire hash table c? Or is there a more simple solution like combining the python dict with cython?<span> If so, how do I do this?</span><p></p></span></p> <p class="MsoNormal"><span lang="EN-US"><p> </p></span></p> <p class="MsoNormal"><span lang="EN-US">Thanks in advance.<p></p></span></p> <p class="MsoNormal"><span lang="EN-US"><p> </p></span></p> <p class="MsoNormal"><span lang="EN-US">Additional details: I use a double dict where the key of the first dict stores another dict as value.<p></p></span></p> <p class="MsoNormal"><span lang="EN-US"><p> </p></span></p> <p class="MsoNormal"><span lang="EN-US">S.<p></p></span></p> </div> </div>
Floating point and hashes
don't seem like a good idea.
(Just a note, I believe the OP was talking about floats in the values so
we're good.)
> (3) actually do the lookup
> (4) unwrap the result back into a float.
>
> Python does have a highly optimized (3), but the overhead for the rest
> will probably overwhelm it speedwise, so I bet a simple, unwrapped
> implementation would still be quite a win.
>
> - Robert
> _______________________________________________
> Cython-dev mailing list
>
RSS Feed