[cctbxbb] sparse matrix

David Waterman dgwaterman at gmail.com
Fri Jun 6 04:35:36 PDT 2014


Hi,

I have a problem where the use of a sparse matrix is appropriate, so I
was pretty happy to grep cctbx for "sparse" and discover the code in
scitbx/sparse. I'm just browsing through the code and tests to get a
feel for how to use these types. In my existing Python code I set the
values for some columns using flex.double vectors, then ultimately
fill a flex.double(flex.grid(n,m)) by these columns using
matrix_paste_column_in_place. It seems to me I can use a very similar
pattern by replacing the flex.doubles with sparse.matrix_columns and
setting columns in the sparse.matrix using slice notation: mat[:,0] =
column.

So far so good. The issue is that I'm not sure how best to go about
setting the values in the matrix_column in the first place. At the
moment I'm making a lot of use of flex.size_t selections and the
set_selected method of flex.double to efficiently (from Python) set
elements of one flex.double from another. It appears that there is no
similar functionality for sparse.matrix_column. Am I right? Possibly
the best I can do is construct a Python dictionary consisting of the
indices from my size_t selection and the values from my flex.double
array and use these to construct the matrix_column, as done in
tst_sparse, e.g. sparse.matrix_column(m, {1:0.1, 2:0.2}).

Without having tried this, I sense it might be a burden. I have a lot
of values to set and don't really want to convert from flex.double via
a dictionary. Are there any philosophical/technical/other reasons for
not writing a set_selected method for sparse.vector? If not, I might
try to do this.

Thanks

-- David


More information about the cctbxbb mailing list