slice_cached.h 2.0 KB

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