[SciPy-dev] Sparse matrix design and broadcasting

Neilen Marais nmarais at sun.ac.za
Fri Jul 7 12:53:44 CDT 2006


I've been looking at the scipy.sparse routines a little, specifically
the sparse_lil type. Currently fancy indexing seems to be handled by a
lot of special case code.

I wonder if there is not some way we can use numpy's build in
broadcasting to make this easier. My thinking is something like this:

1) lil_matrix.__setitem__() figures out what the equivalent shape of the
region being assigned to is. Perhaps some numpy routines exist that can
help here?


lil_mat[1,:] -> (1, lil_mat.shape[1])
lil_mat[[0,1,2], [5,6,7]] -> (3,)
lil_mat[ix_([0,1,2], [5,6,7])] -> (3,3)

2) get numpy to broadcast the value being set to that shape

3) use a single code path that knows how to handle assignation from 2D
or 1D arrays.

Does this make sense?


More information about the Scipy-dev mailing list