This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

# Bug 273

Summary: Product: Clear row/column of a sparse matrix Eigen Christopher Batty Sparse Nobody CONFIRMED --- Feature Request chtz Low JuniorJob unspecified All All

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