This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Deleting Sparse Matrix Entry

Tags: None
(comma "," separated)
baltcode
Registered Member
Posts
12
Karma
0

Deleting Sparse Matrix Entry

Fri Jan 22, 2010 4:54 am
Is there a way to randomly delete a previous non-zero entry in a sparse matrix. I understand that this is not possible in a simple sparse matrix. How about a dynamic sparse matrix? If I say M.coeffref(i,j)=0, does it delete the (i,j)th element, or simply store it as a zero value. If its the second case, over time the dynamic matrix may become cluttered with these zero values. Is there another way than to manually copy the whole matrix other than the element in question?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Deleting Sparse Matrix Entry

Fri Jan 22, 2010 1:31 pm
You can already do that with all sparse objects (SparseMatrix, DynamicSparseMatrix and SparseVector):
* set all the elements you want to delete to zero: m.coeffRef(i,j) = 0;
* call m.prune(0); that will delete all elements x_i,j <= 0
The complexity is O(nnz) regardless of the number of deletion. That's much faster than deleting elements per elements (unless you want to delete a single element).
User avatar
yaniell
Registered Member
Posts
9
Karma
0

Re: Deleting Sparse Matrix Entry

Tue Apr 19, 2016 3:51 am
What if m is a complex type?

ggael wrote:You can already do that with all sparse objects (SparseMatrix, DynamicSparseMatrix and SparseVector):
* set all the elements you want to delete to zero: m.coeffRef(i,j) = 0;
* call m.prune(0); that will delete all elements x_i,j <= 0
The complexity is O(nnz) regardless of the number of deletion. That's much faster than deleting elements per elements (unless you want to delete a single element).
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Deleting Sparse Matrix Entry

Thu Apr 21, 2016 9:49 pm
this should not make any difference.


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient