[Pyrex] Sparse vectors using dicts in Pyrex.
Andrew Straw
strawman at astraw.com
Sun Jan 20 23:35:42 CET 2008
You write " the sparse vector implementation in scipy". I just wanted to
make sure that you are aware that there actually are more than one
format? (csc, csr, dok, at least)
Daniel Yarlett wrote:
> 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.
>
>
>
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex
>
More information about the Pyrex
mailing list