repdiag.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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_REPDIAG_H
  9. #define IGL_REPDIAG_H
  10. #include "igl_inline.h"
  11. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  12. #include <Eigen/Dense>
  13. #include <Eigen/Sparse>
  14. namespace igl
  15. {
  16. /// Repeat a matrix along the diagonal a certain number of times, so
  17. /// that if A is a m by n matrix and we want to repeat along the diagonal d
  18. /// times, we get a m*d by n*d matrix B such that:
  19. /// B( (k*m+1):(k*m+1+m-1), (k*n+1):(k*n+1+n-1)) = A
  20. /// for k from 0 to d-1
  21. ///
  22. /// @param[in] A m by n matrix we are repeating along the diagonal.
  23. /// @param[in] d number of times to repeat A along the diagonal
  24. /// @param[out] B m*d by n*d matrix with A repeated d times along the diagonal,
  25. /// will be dense or sparse to match A
  26. ///
  27. template <typename T>
  28. IGL_INLINE void repdiag(
  29. const Eigen::SparseMatrix<T>& A,
  30. const int d,
  31. Eigen::SparseMatrix<T>& B);
  32. /// \overload
  33. template <typename T>
  34. IGL_INLINE void repdiag(
  35. const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & A,
  36. const int d,
  37. Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & B);
  38. /// \overload
  39. template <class Mat>
  40. IGL_INLINE Mat repdiag(const Mat & A, const int d);
  41. }
  42. #ifndef IGL_STATIC_LIBRARY
  43. # include "repdiag.cpp"
  44. #endif
  45. #endif