diag.h 1.8 KB

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