diag.h 998 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. // Templates:
  22. // T should be a eigen sparse matrix primitive type like int or double
  23. // Inputs:
  24. // V a m sparse vector
  25. // Outputs:
  26. // X a m by m sparse matrix
  27. template <typename T>
  28. IGL_INLINE void diag(
  29. const Eigen::SparseVector<T>& V,
  30. Eigen::SparseMatrix<T>& X);
  31. }
  32. #ifdef IGL_HEADER_ONLY
  33. # include "diag.cpp"
  34. #endif
  35. #endif