12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #include "invert_diag.h"
- template <typename T>
- IGL_INLINE void igl::invert_diag(
- const Eigen::SparseMatrix<T>& X,
- Eigen::SparseMatrix<T>& Y)
- {
- #ifndef NDEBUG
- typename Eigen::SparseVector<T> dX = X.diagonal().sparseView();
-
- assert(dX.nonZeros() == dX.size());
- #endif
-
- if(&Y != &X)
- {
- Y = X;
- }
-
- for(int k=0; k<Y.outerSize(); ++k)
- {
-
- for(typename Eigen::SparseMatrix<T>::InnerIterator it (Y,k); it; ++it)
- {
- if(it.col() == it.row())
- {
- T v = it.value();
- assert(v != 0);
- v = ((T)1.0)/v;
- Y.coeffRef(it.row(),it.col()) = v;
- }
- }
- }
- }
- #ifdef IGL_STATIC_LIBRARY
- template void igl::invert_diag<double>(Eigen::SparseMatrix<double, 0, int> const&, Eigen::SparseMatrix<double, 0, int>&);
- template void igl::invert_diag<float>(Eigen::SparseMatrix<float, 0, int> const&, Eigen::SparseMatrix<float, 0, int>&);
- #endif
|