New user self-registration is disabled due to spam. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Before reporting a bug, please make sure that your Eigen version is up-to-date!
Bug 273 - Clear row/column of a sparse matrix
Clear row/column of a sparse matrix
 Status: CONFIRMED None Eigen Unclassified Sparse (show other bugs) unspecified All All Low Feature Request Nobody JuniorJob

 Reported: 2011-05-18 19:45 UTC by Christopher Batty 2014-06-20 18:20 UTC (History) 1 user (show) chtz

Attachments

 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.``` 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.``` 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 ...``` 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.```

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