Thanks for the link.

But I'm a little confused again. I thought cython is used when you do not
want to write c yourself. But use it to write 'pythonic' c.

In this case, the c code is ready and needs to be included in my python
program.

What I need is simplicity and c. Should I use cython to extend my main
python program with this c datatype? If so, how? Or is there a better/faster
way to let these two communicate?

I basically need a fast way of accessing the hash table from python. If
someone can refer me to some of the many docs, I would be very happy.

To summarize this is when my python program needs to read or write to the
hash table.

Main python program does:

-some preprocessing
-loop over a large data file
        -1) count and calculate and do some tricks (read from hash table)
        -2) return a float, with two indices
        -3) store this output (write to hash table)
-write final hash table to output

Thanks.



-----Original Message-----
From: Sebastien Binet [mailto:[email protected]] 
Sent: woensdag 2 september 2009 19:01
To: [email protected]
Cc: Robert Bradshaw; [email protected]
Subject: Re: [Cython] FW: cython and hash tables / dictionary

On Wednesday 02 September 2009 18:01:43 Robert Bradshaw wrote:
> On Sep 2, 2009, at 5:34 AM, Sanne Korzec wrote:
> > 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.
>
> The short answer is yes, to avoid using the Python dictionary (which
> can only hold Python objects), you need to write your own hashtable.
> That's not very hard though--I bet only a hundred or two lines in
> Cython would be sufficient (and very fast). You could also look into
> using an external C or C++ library, though C++ support is still a
> work in progress.

I'd recommand using this C library:
http://c-algorithms.sourceforge.net/

having a cython-stl sounds nice though :)

cheers,
sebastien.
-- 
#########################################
# Dr. Sebastien Binet
# Laboratoire de l'Accelerateur Lineaire
# Universite Paris-Sud XI
# Batiment 200
# 91898 Orsay
#########################################

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to