find.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "find.h"
  2. #include "verbose.h"
  3. template <typename T>
  4. IGL_INLINE void igl::find(
  5. const Eigen::SparseMatrix<T>& X,
  6. Eigen::Matrix<int,Eigen::Dynamic,1> & I,
  7. Eigen::Matrix<int,Eigen::Dynamic,1> & J,
  8. Eigen::Matrix<T,Eigen::Dynamic,1> & V)
  9. {
  10. // Resize outputs to fit nonzeros
  11. I.resize(X.nonZeros());
  12. J.resize(X.nonZeros());
  13. V.resize(X.nonZeros());
  14. int i = 0;
  15. // Iterate over outside
  16. for(int k=0; k<X.outerSize(); ++k)
  17. {
  18. // Iterate over inside
  19. for(typename Eigen::SparseMatrix<T>::InnerIterator it (X,k); it; ++it)
  20. {
  21. V(i) = it.value();
  22. I(i) = it.row();
  23. J(i) = it.col();
  24. i++;
  25. }
  26. }
  27. }
  28. template <typename T>
  29. IGL_INLINE void igl::find(
  30. const Eigen::SparseVector<T>& X,
  31. Eigen::Matrix<int,Eigen::Dynamic,1> & I,
  32. Eigen::Matrix<T,Eigen::Dynamic,1> & V)
  33. {
  34. // Resize outputs to fit nonzeros
  35. I.resize(X.nonZeros());
  36. V.resize(X.nonZeros());
  37. int i = 0;
  38. // loop over non-zeros
  39. for(typename Eigen::SparseVector<T>::InnerIterator it(X); it; ++it)
  40. {
  41. I(i) = it.index();
  42. V(i) = it.value();
  43. i++;
  44. }
  45. }
  46. #ifndef IGL_HEADER_ONLY
  47. // Explicit template specialization
  48. // generated by autoexplicit.sh
  49. template void igl::find<double>(Eigen::SparseMatrix<double, 0, int> const&, Eigen::Matrix<int, -1, 1, 0, -1, 1>&, Eigen::Matrix<int, -1, 1, 0, -1, 1>&, Eigen::Matrix<double, -1, 1, 0, -1, 1>&);
  50. #endif