[Pyrex] Sparse vectors using dicts in Pyrex.
Daniel Yarlett
yarlett at psych.stanford.edu
Sat Jan 19 23:01:54 CET 2008
Hi,
I'm having trouble finding any information on this question, so I hope
the solution isn't too obvious.
I have decided to use Python dictionaries to encode sparse vectors
that I work with (initial exploration suggested this was faster than
using the sparse vector implementation in scipy). If a vector has a
non-zero value at a given index, the integer index is used as key to
the appropriate value. E.g. if the 7th element of a vector is equal to
3.2 then I would write something like:
vector = {}
vector[7] = 3.2
This works pretty well, except that I wish to expose the dictionary
type using Pyrex so that I can hopefully improve the speed of my
implementation. I was wondering if anyone could point me to a simple
example in which a Pyrex function receives a dictionary and (a) gets
the integer keys (indices) of this dictionary, and (b) does something
simple like computes the sum of the vector (where each value is cast
as a double, say). As I said, I haven't been able to find any
documentation on this, and my knowledge of the C API for Python is too
underdeveloped to allow me to figure this out on my own.
Also, does anyone have any thoughts on the potential speed benefits of
using Pyrex in this instance as opposed to using Python's built-in
dictionary methods?
Many thanks,
Dan.
More information about the Pyrex
mailing list