First of all, thanks to all who contribute to this package! It's
generally fantastic, and very flexible for sparse matrix
manipulation. I'm doing some gaussian process regression with it.
I'm trying to get the diagonal of the product of two very large,
sparse matrices.
Since there is no function to sum by axes, I'm first using cvxopt.mul
and then I'm slicing by the unique indices of the columns of the
result and summing up the results.
This works fine for small matrices, but on large matrices, I'm getting
a memory error, on the slice. It just says "Memory Error:" with no
further message (on Ubuntu 9.0.x).
Also, the sum function doesn't seem to actually do anything (the docs
say it should sum all the non-zero values in the matrix), so I have to
using __reduce__() to get the data values and sum them.
Here's the code:
def product_diagonal(A,B):
assert(A.size[0] == B.size[1])
M = cvxopt.mul(A.T,B)
M_r = M.__reduce__()
I = unique(M_r[1][2])
if len(I)==0:
return cvxopt.spmatrix([0.],[0],[0], (1,A.size[0] ))
return cvxopt.spmatrix([ sum(M[:,i].__reduce__()[1][0]) for i in
I],
cvxopt.matrix(0, (1,I.shape[0])),
I,
(1,A.size[0] ))
Any ideas?
rj