diag.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef IGL_DIAG_H
  2. #define IGL_DIAG_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. // http://forum.kde.org/viewtopic.php?f=74&t=117476&p=292388#p292388
  9. //
  10. // This is superceded by
  11. // VectorXd d = X.diagonal() and
  12. // SparseVector<double> d = X.diagonal().sparseView()
  13. //
  14. //
  15. // Either extracts the main diagonal of a matrix as a vector OR converts a
  16. // vector into a matrix with vector along the main diagonal. Like matlab's
  17. // diag function
  18. // Templates:
  19. // T should be a eigen sparse matrix primitive type like int or double
  20. // Inputs:
  21. // X an m by n sparse matrix
  22. // Outputs:
  23. // V a min(m,n) sparse vector
  24. template <typename T>
  25. IGL_INLINE void diag(
  26. const Eigen::SparseMatrix<T>& X,
  27. Eigen::SparseVector<T>& V);
  28. template <typename T,typename DerivedV>
  29. IGL_INLINE void diag(
  30. const Eigen::SparseMatrix<T>& X,
  31. Eigen::MatrixBase<DerivedV>& V);
  32. // Templates:
  33. // T should be a eigen sparse matrix primitive type like int or double
  34. // Inputs:
  35. // V a m sparse vector
  36. // Outputs:
  37. // X a m by m sparse matrix
  38. template <typename T>
  39. IGL_INLINE void diag(
  40. const Eigen::SparseVector<T>& V,
  41. Eigen::SparseMatrix<T>& X);
  42. template <typename T, typename DerivedV>
  43. IGL_INLINE void diag(
  44. const Eigen::MatrixBase<DerivedV>& V,
  45. Eigen::SparseMatrix<T>& X);
  46. }
  47. #ifdef IGL_HEADER_ONLY
  48. # include "diag.cpp"
  49. #endif
  50. #endif