AtA_cached.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_ATA_CACHED_H
  9. #define IGL_ATA_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. struct AtA_cached_data
  17. {
  18. // Weights
  19. Eigen::VectorXd W;
  20. // Flatten composition rules
  21. std::vector<int> I_row;
  22. std::vector<int> I_col;
  23. std::vector<int> I_w;
  24. // For each entry of AtA, points to the beginning
  25. // of the composition rules
  26. std::vector<int> I_outer;
  27. };
  28. // Computes At * W * A, where A is sparse and W is diagonal. Divides the
  29. // construction in two phases, one
  30. // for fixing the sparsity pattern, and one to populate it with values. Compared to
  31. // evaluating it directly, this version is slower for the first time (since it requires a
  32. // precomputation), but faster to the subsequent evaluations.
  33. //
  34. // Input:
  35. // A m x n sparse matrix
  36. // data stores the precomputed sparsity pattern, data.W contains the optional diagonal weights (stored as a dense vector). If W is not provided, it is replaced by the identity.
  37. // Outputs:
  38. // AtA m by m matrix computed as AtA * W * A
  39. //
  40. // Example:
  41. // AtA_data = igl::AtA_cached_data();
  42. // AtA_data.W = W;
  43. // if (s.AtA.rows() == 0)
  44. // igl::AtA_cached_precompute(s.A,s.AtA_data,s.AtA);
  45. // else
  46. // igl::AtA_cached(s.A,s.AtA_data,s.AtA);
  47. template <typename Scalar>
  48. IGL_INLINE void AtA_cached_precompute(
  49. const Eigen::SparseMatrix<Scalar>& A,
  50. AtA_cached_data& data,
  51. Eigen::SparseMatrix<Scalar>& AtA
  52. );
  53. template <typename Scalar>
  54. IGL_INLINE void AtA_cached(
  55. const Eigen::SparseMatrix<Scalar>& A,
  56. const AtA_cached_data& data,
  57. Eigen::SparseMatrix<Scalar>& AtA
  58. );
  59. }
  60. #ifndef IGL_STATIC_LIBRARY
  61. # include "AtA_cached.cpp"
  62. #endif
  63. #endif