repdiag.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef IGL_REPDIAG_H
  2. #define IGL_REPDIAG_H
  3. #include "igl_inline.h"
  4. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  5. #include <Eigen/Dense>
  6. #include <Eigen/Sparse>
  7. namespace igl
  8. {
  9. // REPDIAG repeat a matrix along the diagonal a certain number of times, so
  10. // that if A is a m by n matrix and we want to repeat along the diagonal d
  11. // times, we get a m*d by n*d matrix B such that:
  12. // B( (k*m+1):(k*m+1+m-1), (k*n+1):(k*n+1+n-1)) = A
  13. // for k from 0 to d-1
  14. //
  15. // Inputs:
  16. // A m by n matrix we are repeating along the diagonal. May be dense or
  17. // sparse
  18. // d number of times to repeat A along the diagonal
  19. // Outputs:
  20. // B m*d by n*d matrix with A repeated d times along the diagonal,
  21. // will be dense or sparse to match A
  22. //
  23. // Sparse version
  24. template <typename T>
  25. IGL_INLINE void repdiag(
  26. const Eigen::SparseMatrix<T>& A,
  27. const int d,
  28. Eigen::SparseMatrix<T>& B);
  29. // Dense version
  30. template <typename T>
  31. IGL_INLINE void repdiag(
  32. const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & A,
  33. const int d,
  34. Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & B);
  35. // Wrapper with B as output
  36. template <class Mat>
  37. IGL_INLINE Mat repdiag(const Mat & A, const int d);
  38. }
  39. #ifdef IGL_HEADER_ONLY
  40. # include "repdiag.cpp"
  41. #endif
  42. #endif