slice.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef IGL_SLICE_H
  2. #define IGL_SLICE_H
  3. #include "igl_inline.h"
  4. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  5. #include <Eigen/Sparse>
  6. namespace igl
  7. {
  8. // THIS MAY HAVE BEEN SUPERSEDED BY EIGEN'S select FUNCTION
  9. //
  10. // Act like the matlab X(row_indices,col_indices) operator
  11. //
  12. // Inputs:
  13. // X m by n matrix
  14. // R list of row indices
  15. // C list of column indices
  16. // Output:
  17. // Y #R by #C matrix
  18. template <typename T>
  19. IGL_INLINE void slice(
  20. const Eigen::SparseMatrix<T>& X,
  21. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  22. const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
  23. Eigen::SparseMatrix<T>& Y);
  24. // Wrapper to only slice in one direction
  25. //
  26. // Inputs:
  27. // dim dimension to slice in 1 or 2, dim=1 --> X(R,:), dim=2 --> X(:,R)
  28. //
  29. // Note: For now this is just a cheap wrapper.
  30. template <typename Mat>
  31. IGL_INLINE void slice(
  32. const Mat& X,
  33. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  34. const int dim,
  35. Mat& Y);
  36. template <typename DerivedX>
  37. IGL_INLINE void slice(
  38. const Eigen::PlainObjectBase<DerivedX> & X,
  39. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  40. const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
  41. Eigen::PlainObjectBase<DerivedX> & Y);
  42. template <typename DerivedX>
  43. IGL_INLINE void slice(
  44. const Eigen::PlainObjectBase<DerivedX> & X,
  45. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  46. Eigen::PlainObjectBase<DerivedX> & Y);
  47. // VectorXi Y = slice(X,R);
  48. template <typename DerivedX>
  49. IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice(
  50. const Eigen::PlainObjectBase<DerivedX> & X,
  51. const Eigen::Matrix<int,Eigen::Dynamic,1> & R);
  52. }
  53. #ifdef IGL_HEADER_ONLY
  54. # include "slice.cpp"
  55. #endif
  56. #endif