This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 273 - Clear row/column of a sparse matrix
Summary: Clear row/column of a sparse matrix
Status: CONFIRMED
Alias: None
Product: Eigen
Classification: Unclassified
Component: Sparse (show other bugs)
Version: unspecified
Hardware: All All
: Low Feature Request
Assignee: Nobody
URL:
Whiteboard:
Keywords: JuniorJob
Depends on:
Blocks:
 
Reported: 2011-05-18 19:45 UTC by Christopher Batty
Modified: 2019-12-04 10:46 UTC (History)
1 user (show)



Attachments

Description Christopher Batty 2011-05-18 19:45:16 UTC
Clearing a row or column of a matrix (depending on the storage format) can sometimes be a useful operation in finite element/difference computations, such as in setting up Dirichlet boundary conditions. Using this method, you can build your matrix without regard for boundary conditions, and then in a second step replace the rows corresponding to known values with the identity.

PETSC, for example, supports this operation with the MatZeroRows command.
Comment 1 Christoph Hertzberg 2011-05-18 22:25:58 UTC
(In reply to comment #0)
> Clearing a row or column of a matrix (depending on the storage format) can
> sometimes be a useful operation in finite element/difference computations, such
> as in setting up Dirichlet boundary conditions. Using this method, you can
> build your matrix without regard for boundary conditions, and then in a second
> step replace the rows corresponding to known values with the identity.
> 
> PETSC, for example, supports this operation with the MatZeroRows command.

Do you mean set a row/column to zero? That is actually already possible by

 MatrixXd m;
// ...
 m.row(i).setZero();
// or:
 m.col(j).setZero();

also available are setConstant(scalar) and setOnes().

For the problem of setting a number of (unconnected) rows to zero there was a proposal once for unconnected views of matrices (not sure whether on the list/the forum/bugzilla and to lazy to search now ...) which should do the trick. For now a simple for-loop also should work.
Comment 2 Christoph Hertzberg 2011-05-18 22:32:02 UTC
(In reply to comment #1)
> (In reply to comment #0)
> > Clearing a row or column of a matrix (depending on the storage format) can
> > sometimes be a useful operation in finite element/difference computations, such
> > as in setting up Dirichlet boundary conditions. Using this method, you can
> > build your matrix without regard for boundary conditions, and then in a second
> > step replace the rows corresponding to known values with the identity.
> > 
> > PETSC, for example, supports this operation with the MatZeroRows command.
> 
> Do you mean set a row/column to zero? That is actually already possible by

Sorry just noticed that this is about the sparse module. So I guess this does not work and sorry for the noise ...
Comment 3 Christoph Hertzberg 2014-06-20 18:20:36 UTC
A workaround is to use SparseMatrix::prune(KeepFunc) with a custom predicate.
But surely more efficient solutions are possible.
Comment 4 Nobody 2019-12-04 10:46:13 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/273.

Note You need to log in before you can comment on or make changes to this bug.