find.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  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. // Templates:
  20. // T should be a eigen sparse matrix primitive type like int or double
  21. // Input:
  22. // X m by n matrix whose entries are to be found
  23. // Outputs:
  24. // I nnz vector of row indices of non zeros entries in X
  25. // J nnz vector of column indices of non zeros entries in X
  26. // V nnz vector of type T non-zeros entries in X
  27. //
  28. template <
  29. typename T,
  30. typename DerivedI,
  31. typename DerivedJ,
  32. typename DerivedV>
  33. IGL_INLINE void find(
  34. const Eigen::SparseMatrix<T>& X,
  35. Eigen::MatrixBase<DerivedI> & I,
  36. Eigen::MatrixBase<DerivedJ> & J,
  37. Eigen::MatrixBase<DerivedV> & V);
  38. // Find the non-zero entries and there respective indices in a sparse vector.
  39. // Similar to matlab's [I,J,V] = find(X), but instead of [I,J] being
  40. // subscripts into X, since X is a vector we just return I, a list of indices
  41. // into X
  42. //
  43. // Templates:
  44. // T should be a eigen sparse matrix primitive type like int or double
  45. // Input:
  46. // X vector whose entries are to be found
  47. // Outputs:
  48. // I nnz vector of indices of non zeros entries in X
  49. // V nnz vector of type T non-zeros entries in X
  50. template <typename T>
  51. IGL_INLINE void find(
  52. const Eigen::SparseVector<T>& X,
  53. Eigen::Matrix<int,Eigen::Dynamic,1> & I,
  54. Eigen::Matrix<T,Eigen::Dynamic,1> & V);
  55. }
  56. #ifdef IGL_HEADER_ONLY
  57. # include "find.cpp"
  58. #endif
  59. #endif