slice_into.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_SLICE_INTO_H
  9. #define IGL_SLICE_INTO_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. /// Act like the matlab Y(row_indices,col_indices) = X
  17. ///
  18. /// @param[in] X xm by xn rhs matrix
  19. /// @param[in] R list of row indices
  20. /// @param[in] C list of column indices
  21. /// @param[in] Y ym by yn lhs matrix
  22. /// @param[out] Y ym by yn lhs matrix, same as input but Y(R,C) = X
  23. ///
  24. ///
  25. /// \see slice
  26. template <typename T, typename DerivedR, typename DerivedC>
  27. IGL_INLINE void slice_into(
  28. const Eigen::SparseMatrix<T>& X,
  29. const Eigen::MatrixBase<DerivedR> & R,
  30. const Eigen::MatrixBase<DerivedC> & C,
  31. Eigen::SparseMatrix<T>& Y);
  32. /// \overload
  33. /// \brief Wrapper to only slice in one direction
  34. ///
  35. /// @param[int] dim dimension to slice in 1 or 2, dim=1 --> X(R,:), dim=2 --> X(:,R)
  36. ///
  37. /// \note For now this is just a cheap wrapper.
  38. template <typename MatX, typename MatY, typename DerivedR>
  39. IGL_INLINE void slice_into(
  40. const MatX & X,
  41. const Eigen::MatrixBase<DerivedR> & R,
  42. const int dim,
  43. MatY& Y);
  44. /// \overload
  45. ///
  46. /// \deprecated
  47. ///
  48. /// See slice.h for more details
  49. template <typename DerivedX, typename DerivedY, typename DerivedR, typename DerivedC>
  50. IGL_INLINE void slice_into(
  51. const Eigen::MatrixBase<DerivedX> & X,
  52. const Eigen::MatrixBase<DerivedR> & R,
  53. const Eigen::MatrixBase<DerivedC> & C,
  54. Eigen::PlainObjectBase<DerivedY> & Y);
  55. /// \overload
  56. /// \brief Vector version
  57. template <typename DerivedX, typename DerivedR, typename DerivedY>
  58. IGL_INLINE void slice_into(
  59. const Eigen::MatrixBase<DerivedX>& X,
  60. const Eigen::MatrixBase<DerivedR>& R,
  61. Eigen::PlainObjectBase<DerivedY>& Y);
  62. }
  63. #ifndef IGL_STATIC_LIBRARY
  64. # include "slice_into.cpp"
  65. #endif
  66. #endif