diag.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // Either extracts the main diagonal of a matrix as a vector OR converts a
  9. // vector into a matrix with vector along the main diagonal. Like matlab's
  10. // diag function
  11. // Templates:
  12. // T should be a eigen sparse matrix primitive type like int or double
  13. // Inputs:
  14. // X an m by n sparse matrix
  15. // Outputs:
  16. // V a min(m,n) sparse vector
  17. template <typename T>
  18. IGL_INLINE void diag(
  19. const Eigen::SparseMatrix<T>& X,
  20. Eigen::SparseVector<T>& V);
  21. template <typename T,typename DerivedV>
  22. IGL_INLINE void diag(
  23. const Eigen::SparseMatrix<T>& X,
  24. Eigen::MatrixBase<DerivedV>& V);
  25. // Templates:
  26. // T should be a eigen sparse matrix primitive type like int or double
  27. // Inputs:
  28. // V a m sparse vector
  29. // Outputs:
  30. // X a m by m sparse matrix
  31. template <typename T>
  32. IGL_INLINE void diag(
  33. const Eigen::SparseVector<T>& V,
  34. Eigen::SparseMatrix<T>& X);
  35. template <typename T, typename DerivedV>
  36. IGL_INLINE void diag(
  37. const Eigen::MatrixBase<DerivedV>& V,
  38. Eigen::SparseMatrix<T>& X);
  39. }
  40. #ifdef IGL_HEADER_ONLY
  41. # include "diag.cpp"
  42. #endif
  43. #endif