2

It is known that Numpy basic matrix slicing will generate a view, whereas advanced slicing a copy. Is this true in cvxopt? I tried

from cvxopt import spmatrix
import numpy as np
A = spmatrix([2,-1,2,-2,1,4,3], [1,2,0,2,3,2,0], [0,0,1,1,2,3,4])
A_view = A[0:3,0:3]           # basic slicing
A_cp = A[[0,1,2],[0,1,2]]     # advanced slicing
np.may_share_memory(A,A_view) # returned false
np.may_share_memory(A,A_cp)   # returned false
zhh210
  • 123
  • 2

1 Answers1

2

That is a sparse matrix. Numpy doesn't have sparse matrices, and I think neither scipy.sparse nor cvxopt use memoryviews for sparse matrices.

Even for dense matrices it appears that cvxopt uses a low level Python API instead of something like Cython. I don't see any references to memoryview interfaces so perhaps even dense matrices in cvxopt use copying instead of views.

This might be the relevant function for sparse matrix indexing in the cvxopt source, where you will find a lot of copying. https://github.com/cvxopt/cvxopt/blob/master/src/C/sparse.c#L2791

k20
  • 772
  • 3
  • 3
  • Thanks, this really helps. I need a package that can retrieve sparse submatrix view and armadillo looks suitable for my purpose: http://arma.sourceforge.net/docs.html#SpMat. – zhh210 Dec 28 '13 at 03:53