find.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef IGL_FIND_H
  2. #define IGL_FIND_H
  3. #include "igl_inline.h"
  4. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  5. #include <Eigen/Dense>
  6. #include <Eigen/Sparse>
  7. namespace igl
  8. {
  9. // Find the non-zero entries and there respective indices in a sparse matrix.
  10. // Like matlab's [I,J,V] = find(X)
  11. //
  12. // Templates:
  13. // T should be a eigen sparse matrix primitive type like int or double
  14. // Input:
  15. // X m by n matrix whose entries are to be found
  16. // Outputs:
  17. // I nnz vector of row indices of non zeros entries in X
  18. // J nnz vector of column indices of non zeros entries in X
  19. // V nnz vector of type T non-zeros entries in X
  20. //
  21. template <
  22. typename T,
  23. typename DerivedI,
  24. typename DerivedJ,
  25. typename DerivedV>
  26. IGL_INLINE void find(
  27. const Eigen::SparseMatrix<T>& X,
  28. Eigen::MatrixBase<DerivedI> & I,
  29. Eigen::MatrixBase<DerivedJ> & J,
  30. Eigen::MatrixBase<DerivedV> & V);
  31. // Find the non-zero entries and there respective indices in a sparse vector.
  32. // Similar to matlab's [I,J,V] = find(X), but instead of [I,J] being
  33. // subscripts into X, since X is a vector we just return I, a list of indices
  34. // into X
  35. //
  36. // Templates:
  37. // T should be a eigen sparse matrix primitive type like int or double
  38. // Input:
  39. // X vector whose entries are to be found
  40. // Outputs:
  41. // I nnz vector of indices of non zeros entries in X
  42. // V nnz vector of type T non-zeros entries in X
  43. template <typename T>
  44. IGL_INLINE void find(
  45. const Eigen::SparseVector<T>& X,
  46. Eigen::Matrix<int,Eigen::Dynamic,1> & I,
  47. Eigen::Matrix<T,Eigen::Dynamic,1> & V);
  48. }
  49. #ifdef IGL_HEADER_ONLY
  50. # include "find.cpp"
  51. #endif
  52. #endif