slice_cached.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2017 Daniele Panozzo <[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_CACHED_H
  9. #define IGL_SLICE_CACHED_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 X(row_indices,col_indices) operator, where row_indices,
  17. /// col_indices are non-negative integer indices. This is a fast version of
  18. /// igl::slice that can analyze and store the sparsity structure. It is slower
  19. /// at the irst evaluation (slice_cached_precompute), but faster on the
  20. /// subsequent ones.
  21. ///
  22. /// @param[in] X m by n matrix
  23. /// @param[in] R list of row indices
  24. /// @param[in] C list of column indices
  25. /// @param[out] data Temporary data used by slice_cached to repeat this operation
  26. /// @param[out] Y #R by #C matrix
  27. ///
  28. /// #### Example
  29. ///
  30. /// // Construct and slice up Laplacian
  31. /// Eigen::SparseMatrix<double> L,L_sliced;
  32. /// igl::cotmatrix(V,F,L);
  33. /// // Normal igl::slice call
  34. /// igl::slice(L,in,in,L_in_in);
  35. /// …
  36. /// // Fast version
  37. /// static Eigen::VectorXi data; // static or saved in a global state
  38. /// if (data.size() == 0)
  39. /// igl::slice_cached_precompute(L,in,in,data,L_sliced);
  40. /// else
  41. /// igl::slice_cached(L,data,L_sliced);
  42. ///
  43. /// \fileinfo
  44. template <typename TX, typename TY, typename DerivedI>
  45. IGL_INLINE void slice_cached_precompute(
  46. const Eigen::SparseMatrix<TX>& X,
  47. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  48. const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
  49. Eigen::MatrixBase<DerivedI>& data,
  50. Eigen::SparseMatrix<TY>& Y);
  51. /// Slice X by cached C,R indices into Y
  52. ///
  53. /// @param[in] X m by n matrix
  54. /// @param[in] data Temporary data used by slice_cached to repeat this operation
  55. /// @param[out] Y #R by #C matrix
  56. template <typename TX, typename TY, typename DerivedI>
  57. IGL_INLINE void slice_cached(
  58. const Eigen::SparseMatrix<TX>& X,
  59. const Eigen::MatrixBase<DerivedI>& data,
  60. Eigen::SparseMatrix<TY>& Y);
  61. }
  62. #ifndef IGL_STATIC_LIBRARY
  63. # include "slice_cached.cpp"
  64. #endif
  65. #endif