find.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. template <
  39. typename DerivedX,
  40. typename DerivedI,
  41. typename DerivedJ,
  42. typename DerivedV>
  43. IGL_INLINE void find(
  44. const Eigen::PlainObjectBase<DerivedX>& X,
  45. Eigen::PlainObjectBase<DerivedI> & I,
  46. Eigen::PlainObjectBase<DerivedJ> & J,
  47. Eigen::PlainObjectBase<DerivedV> & V);
  48. template <
  49. typename DerivedX,
  50. typename DerivedI>
  51. IGL_INLINE void find(
  52. const Eigen::PlainObjectBase<DerivedX>& X,
  53. Eigen::PlainObjectBase<DerivedI> & I);
  54. // Find the non-zero entries and there respective indices in a sparse vector.
  55. // Similar to matlab's [I,J,V] = find(X), but instead of [I,J] being
  56. // subscripts into X, since X is a vector we just return I, a list of indices
  57. // into X
  58. //
  59. // Templates:
  60. // T should be a eigen sparse matrix primitive type like int or double
  61. // Input:
  62. // X vector whose entries are to be found
  63. // Outputs:
  64. // I nnz vector of indices of non zeros entries in X
  65. // V nnz vector of type T non-zeros entries in X
  66. template <typename T>
  67. IGL_INLINE void find(
  68. const Eigen::SparseVector<T>& X,
  69. Eigen::Matrix<int,Eigen::Dynamic,1> & I,
  70. Eigen::Matrix<T,Eigen::Dynamic,1> & V);
  71. }
  72. #ifndef IGL_STATIC_LIBRARY
  73. # include "find.cpp"
  74. #endif
  75. #endif