diag.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 V = X.diagonal() and
  19. // SparseVector<double> V = X.diagonal().sparseView()
  20. // SparseMatrix<double> X = V.asDiagonal().sparseView()
  21. //
  22. //
  23. // Either extracts the main diagonal of a matrix as a vector OR converts a
  24. // vector into a matrix with vector along the main diagonal. Like matlab's
  25. // diag function
  26. // Templates:
  27. // T should be a eigen sparse matrix primitive type like int or double
  28. // Inputs:
  29. // X an m by n sparse matrix
  30. // Outputs:
  31. // V a min(m,n) sparse vector
  32. template <typename T>
  33. IGL_INLINE void diag(
  34. const Eigen::SparseMatrix<T>& X,
  35. Eigen::SparseVector<T>& V);
  36. template <typename T,typename DerivedV>
  37. IGL_INLINE void diag(
  38. const Eigen::SparseMatrix<T>& X,
  39. Eigen::MatrixBase<DerivedV>& V);
  40. // Templates:
  41. // T should be a eigen sparse matrix primitive type like int or double
  42. // Inputs:
  43. // V a m sparse vector
  44. // Outputs:
  45. // X a m by m sparse matrix
  46. template <typename T>
  47. IGL_INLINE void diag(
  48. const Eigen::SparseVector<T>& V,
  49. Eigen::SparseMatrix<T>& X);
  50. template <typename T, typename DerivedV>
  51. IGL_INLINE void diag(
  52. const Eigen::MatrixBase<DerivedV>& V,
  53. Eigen::SparseMatrix<T>& X);
  54. }
  55. #ifndef IGL_STATIC_LIBRARY
  56. # include "diag.cpp"
  57. #endif
  58. #endif