find.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_FIND_H
  9. #define IGL_FIND_H
  10. #include "igl_inline.h"
  11. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  12. #include <Eigen/Dense>
  13. #include <Eigen/Sparse>
  14. namespace igl
  15. {
  16. /// Find the non-zero entries and there respective indices in a sparse matrix.
  17. /// Like matlab's [I,J,V] = find(X)
  18. ///
  19. /// @tparam T should be a eigen sparse matrix primitive type like int or double
  20. /// @param[in] X m by n matrix whose entries are to be found
  21. /// @param[out] I nnz vector of row indices of non zeros entries in X
  22. /// @param[out] J nnz vector of column indices of non zeros entries in X
  23. /// @param[out] V nnz vector of type T non-zeros entries in X
  24. ///
  25. template <
  26. typename T,
  27. typename DerivedI,
  28. typename DerivedJ,
  29. typename DerivedV>
  30. IGL_INLINE void find(
  31. const Eigen::SparseMatrix<T>& X,
  32. Eigen::DenseBase<DerivedI> & I,
  33. Eigen::DenseBase<DerivedJ> & J,
  34. Eigen::DenseBase<DerivedV> & V);
  35. /// \overload
  36. template <
  37. typename DerivedX,
  38. typename DerivedI,
  39. typename DerivedJ,
  40. typename DerivedV>
  41. IGL_INLINE void find(
  42. const Eigen::DenseBase<DerivedX>& X,
  43. Eigen::PlainObjectBase<DerivedI> & I,
  44. Eigen::PlainObjectBase<DerivedJ> & J,
  45. Eigen::PlainObjectBase<DerivedV> & V);
  46. /// \overload
  47. ///
  48. /// @param[out] I nnz vector of indices into vectorization of X
  49. template <
  50. typename DerivedX,
  51. typename DerivedI>
  52. IGL_INLINE void find(
  53. const Eigen::DenseBase<DerivedX>& X,
  54. Eigen::PlainObjectBase<DerivedI> & I);
  55. /// \overload
  56. template <typename T>
  57. IGL_INLINE void find(
  58. const Eigen::SparseVector<T>& X,
  59. Eigen::Matrix<int,Eigen::Dynamic,1> & I,
  60. Eigen::Matrix<T,Eigen::Dynamic,1> & V);
  61. }
  62. #ifndef IGL_STATIC_LIBRARY
  63. # include "find.cpp"
  64. #endif
  65. #endif