repdiag.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_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. // REPDIAG 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. // Inputs:
  23. // A m by n matrix we are repeating along the diagonal. May be dense or
  24. // sparse
  25. // d number of times to repeat A along the diagonal
  26. // Outputs:
  27. // B m*d by n*d matrix with A repeated d times along the diagonal,
  28. // will be dense or sparse to match A
  29. //
  30. // Sparse version
  31. template <typename T>
  32. IGL_INLINE void repdiag(
  33. const Eigen::SparseMatrix<T>& A,
  34. const int d,
  35. Eigen::SparseMatrix<T>& B);
  36. // Dense version
  37. template <typename T>
  38. IGL_INLINE void repdiag(
  39. const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & A,
  40. const int d,
  41. Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & B);
  42. // Wrapper with B as output
  43. template <class Mat>
  44. IGL_INLINE Mat repdiag(const Mat & A, const int d);
  45. }
  46. #ifndef IGL_STATIC_LIBRARY
  47. # include "repdiag.cpp"
  48. #endif
  49. #endif